Noeud:Invoking Make, Noeud « Next »:, Noeud « Previous »:Multiple Directories, Noeud « Up »:GNU Make



Invoking Make

The majority of the time, with the hard work already expended in creating a Makefile, employing that file to refresh build targets is no more complicated than this:

     $ make target
     

This being the GNU system though, you can of course do so much more. There are many command line options that affect the way that GNU Make behaves, which you can always get a summary of by running make --help from the command line. We will describe a useful subset in this section, but you can find comprehensive details in The Gnu Make Manual that ships with GNU Make.

-I directory
You can specify this option as many times as you like to list various directories that you want Make to search for additional Makefile fragments that are pulled in to the effective Makefile with the include directive.
-f file-name
This option allows you to specify an alternative Makefile by name. Instead of reading from the default Makefile, file-name will be read instead.
-n
If you need to see what Make would do, without actually running any of the command rules, use the -n option to have Make display those commands but not execute them.
-k
Occasionally, you might be missing one of the tools that a shell command early in the sequence tries to run, but which is not critical to the correct operation of the package, but even so Make will give up and report an error message. This option tells Make to just keep going in the face of errors from shell commands, so that you can snatch victory from the jaws of defeat.

One of the most useful facilities is being able to override Make variable values from the command line: With this feature you can set your Makefile variable to perform a production build of your project (say, maximum optimisation, create shared libraries, minimum debug code enabled), but specify more appropriate values on the command line during development. So, in our Makefile we would specify the following:

     CFLAGS   = -O6
     CPPFLAGS =
     
     Example 5.31: Production build values for compilation flags
     

But during development, by invoking Make as follows, change the values of those Make variables for the current build:

     $ make CFLAGS='-ggdb3 -Wall' CPPFLAGS='-DDEBUG=9' m4
     

Do be aware that it is easy to end up with a set of mismatched objects, compiled with different flags if you keep changing the override values without performing a complete build. To avoid doing this accidentally, you should probably run make clean between changes to the override settings. Unless you really do want to compile just a few objects with different build options for some reason...