hello: hello.c
make
returns:
cc hello.c -o hello
NOTE: This compiles the C program.
Most distributions will have cc pointing to the default C compiler.
make
returns:
make: 'hello' is up to date.
NOTE: As nothing has changed, there is no need for Make to recompile the C program.
To have the program be recompiled:
Use variables within the Makefile:
CC=gcc CFLAGS=-g hello : hello.c
returns:
gcc -g hello.c -o hello
CC=gcc CFLAGS=-g # Comment next line to turn off optimization CFLAGS+=-O hello : hello.c
NOTE: The implicit rule being used is:
$(CC) $(CFLAGS) $(CPPFLAGS) hello.c -o hello
Besides compiling, the Makefile can also link the object files:
hello : hello.o mylib.o hello.o : hello.c hello.h mylib.h mylib.o : mylib.c mylib.h
NOTE: Thanks to the default rules, this is all that is needed by Make.
The make program is smart enough to see that it needs hello.o, it will go find the rule for hello.o and so on.
Of course, additional lines can be added to control further what happens for the build process.