Unix Makefile Tutorial on Makefile Example

this is an example of the makefile for compiling the hello program. this program consists of three files main.cpp, factorial.cpp and hello.cpp.

# define required macros here
shell = /bin/sh

objs =  main.o factorial.o hello.o
cflag = -wall -g
cc = gcc
include =
libs = -lm

hello:${obj}
   ${cc} ${cflags} ${includes} -o $@ ${objs} ${libs}

clean:
   -rm -f *.o core *.core

.cpp.o:
   ${cc} ${cflags} ${includes} -c $<

now you can build your program hello using the make. if you will issue a command make clean then it removes all the object files and core files available in the current directory.