Programming Utilities Guide

Displaying Information About a make Run

Running make with the -n option displays the commands make is to perform, without executing them. This comes in handy when verifying that the macros in a makefile are expanded as expected. With the following makefile:

CFLAGS= -O 

.KEEP_STATE:

functions: main.o data.o 
         $(LINK.c) -o functions main.o data.o

make -n displays:

$ make -n 
cc -O -c main.c 
cc -O -c data.c 
cc -O -o functions main.o data.o

Note -

There is an exception however. make executes any command line containing a reference to the MAKE macro (such as $(MAKE) or ${MAKE}), regardless of -n. It is a bad idea to include a line such as the following in your makefile: $(MAKE) ; rm -f *



Note -

Setting an environment variable named MAKEFLAGS can lead to complications, since make adds its value to the list of options. To prevent puzzling surprises, avoid setting this variable.


make has some other options that you can use to keep abreast of what it's doing and why:

-d

Displays the criteria by which make determines that a target is be out-of-date. Unlike -n, it does process targets, as shown in the following example. This option also displays the value imported from the environment (null by default) for the MAKEFLAGS macro, which is described in detail in a later section.

$ make -d 
MAKEFLAGS value: 
    Building main.o using suffix rule for .c.o because 
it is out of date relative to main.c 
cc -O -c main.c 
    Building functions because it is out of date 
relative to main.o 
    Building data.o using suffix rule for .c.o because 
it is out of date relative to data.c 
cc -O -c data.c 
    Building functions because it is out of date 
relative to data.o 
cc -O -o functions main.o data.o
-dd

This option displays all dependencies make checks, including any hidden dependencies, in vast detail.

-D

Displays the text of the makefile as it is read.

-DD

Displays the makefile and the default makefile, the state file, and hidden dependency reports for the current make run.

-f makefile

make uses the named makefile (instead of makefile or Makefile).


Note -

Several -f options indicate the concatenation of the named makefiles.


-Kmakestatefile

If makestatefile is a directory, make writes the KEEP_STATE information into a .make.state file in that directory. If makestatefile is a file, make will write the KEEP_STATE information into the makestatefile

-p

Displays the complete set of macro definitions and target entries.

-P

Displays the complete dependency tree for the default target or the specified target.

An option that can be used to shortcut make processing is the -t option. When run with -t, make does not perform the rule for building a target. Instead it uses touch to alter the modification time for each target that it encounters in the dependency scan. It also updates the state file to reflect what it built. This often creates more problems than it solves, and it is recommended that you exercise caution if you do use it. Note that if there is no file corresponding to a target entry, touch creates it.


Note -

Due to its potentially troublesome side effects, it is recommended that you not use the -t (touch) option for make.


The following is one example of how not to use make -t. Suppose you have a target named clean that performed housekeeping in the directory by removing target files produced by make:

clean: 
         rm functions main.o data.o

Note -

clean is the conventional name for a target that removes derived files. It is useful when you want to start a build from scratch


If you give the nonsensical command:

$ make -t clean
touch clean 
$ make clean 
`clean' is up to date

you then have to remove the file clean before your housekeeping target can work again.

-q

Invokes the question mode, and returns a zero or non-zero status code, depending on whether or not the target file is up-to-date.

-r

Suppresses reading in of the default makefile, /usr/share/lib/make/make.rules.

-S

Undoes the effect of the -K option by stopping processing when a non-zero exit status is returned by a command.