The Makefile The previous section described dependencies between files. This section describes the make program in more detail by describing the file it uses, called makefile or Makefile. This file determines the relationships between the source, object and executable files. Translating the dependency graph
Each dependency shown in the graph is circled with a corresponding color in the Makefile, and each uses the following format:
Listing dependenciesproject1: data.o main.o io.o Using the Makefile with makeOnce you have created your Makefile and your corresponding source files, you are ready to use make. If you have named your Makefile either Makefile or makefile, make will recognize it. If you do not wish to call your Makefile one of these names, you can use make -f mymakefile. The order in which dependencies are listed is important. If you simply type make and then return, make will attempt to create or update the first dependency listed. You can also specify one of the other targets listed in the Makefile, and only that target (and its corresponding source files) would be made. For example, if we typed make, the output of make would look as follows: % make cc -c data.c cc -c main.c cc -c io.c cc data.o main.o io.o -o project1 % When making its targets, make first checks the source files and attempts to create or update the source files. That is why data.o, main.o and io.o were created before attempting to create the target: project1.
Note that in the Makefile shown above, the .h files are listed, but there are no references in their corresponding commands. This is because the .h files are referred within the corresponding .c files through the #include "file.h". If you do not explicitly include these in your Makefile, your program will not be updated if you make a change to your header (.h) files. Note: Comments can be placed in a Makefile by placing a pound s ign (#) in front of it. |
RSS Feed
Twitter
Orkut![[Image unavailable]](http://www.eng.hawaii.edu/Tutor/Make/Img/makemake.gif)
