Programming Utilities Guide

Dynamic Macros

Although the dynamic macros $< and $* were documented as being assigned only for implicit rules and the .DEFAULT target, in some cases they actually were assigned for explicit target entries. The assignment action is now documented properly.

The actual value assigned to each of these macros is derived by the same procedure used within implicit rules (this rule has not changed). You can receive unexpected results when you use them in explicit target entries.

Even if you supply explicit dependencies, make does not use them to derive values for these macros. Instead, it searches for an appropriate implicit rule and dependency file. For instance, if you have the explicit target entry:

test: test.f 
        	@echo $< 

and the files: test.c and test.f, you might expect that $< would be assigned the value test.f. This is not the case. It is assigned test.c, because .c is ahead of .f in the suffixes list:

$ make test 
test.c 

For explicit entries, it is best to use a strictly deterministic method for deriving a dependency name using macro references and suffix replacements. For example, you could use $@.f instead of $< to derive the dependency name. To derive the base name of a .o target file, you could use the suffix replacement macro reference: $(@:.o=) instead of $*.

When hidden dependency checking is in effect, the $? dynamic macro value includes the names of hidden dependencies, such as header files. This can lead to failed compilations when using a target entry such as:

x: x.c 
        	$(LINK.c) -o $@ $?

and the file x.c #include's header files. The workaround is to replace `$?' with `$@.<'.