A basic makefile for Hello is: |
make is the program that reads Makefile and executes instructions in it. GNU make has several implicit rules, so all need not be written. Rules have overall form of:
1 2
|
target : dependencies
commands
|
kooth had a slight typo on his example.
The first rule says that in order to create file named 'Hello', one has to have a file named 'Hello.o', and that the command to run is 'gcc -c Hello.c'. The -c flag to gcc says not to run linker. Therefore, 'gcc -c Hello.c' will produce an object file named 'Hello.o'.
The second rule supposedly tells how to convert Hello.c into Hello.o. It's proper command was on line 3.
'gcc Hello.c -o Hello' makes gcc both compile Hello.c into object file and then link that object file into binary named 'Hello'. That is how you would call it from command line. Thus, try 2:
1 2 3 4 5 6 7 8
|
Hello: Hello.o
gcc -o Hello Hello.o
Hello.o: Hello.c
gcc -c Hello.c
clean:
rm *.o
|
The nice thing about make is that when you have multiple source files, it will recompile only the ones that have changed since previous compilation.
Recommended commands:
(Not sure if Ubuntu has the latter.)