The 'make' program is normally controlled by a file called 'Makefile'. Think of a Makefile as a computerized cook-book:
popcorn: raw_popcorn
put raw_popcorn in microwave
push popcorn button and wait
push open button and remove popcorn
clean:
wipe inside of microwave
put empty bag in trash
snack: popcorn
eat popcorn
make popcornwill check to see that there is some raw_popcorn and if so puts it in the oven and pushes the button for us.
If we try the command
make snackthe make program first looks to see if we have popcorn, and if needed makes it for us... then we eat the popcorn. Notice that the recipes can be in any order and the make program selects the right ones to follow.
(Recipe):
thing_to_be_made : raw_materials
<TAB> step to make the thing from the raw materials
<TAB> step to make the thing from the raw materialsThe thing_to_be_made is called the target of the rule(recipe) and the raw_materials are called the input.
something_to_do:
<TAB> step to do it
<TAB> step to do itNotice the <TAB> character. This must be the real Tab character. Spaces do not work.
memo : memo.cpp
g++ -w -O -o memo memo.cpp
memo : memo.cpp reminder.cpp
g++ -w -O -o memo memo.cpp
memo : memo.cpp reminder.h
g++ -w -O -o memo memo.cpp reminder.o
reminder.o : reminder.cpp reminder.h
g++ -w -O -c reminder.cpp
clean:
rm *.omeans that the command make clean removes all the .o files.
You can define a short name for something:
CC=g++ -w -omeans that $(CC) can be used to replace g++ -w -o in any command. Note. Error in Horstmann: When CC is in a command it has to be written $(CC) not CC.
We can generate large numbers of recipes by using implicit rules. They are hard to understand but easy to use:
.cpp.o
$(CC) -c $<has the effect of creating an infinite number of similar rules: they will take any .cpp file and make a .o file from it.
. . . . . . . . . ( end of section Make) <<Contents | End>>
Abreviations