make: Recipes/Search
1
1 4.5.4 Writing Recipes with Directory Search
1 -------------------------------------------
1
1 When a prerequisite is found in another directory through directory
1 search, this cannot change the recipe of the rule; they will execute as
1 written. Therefore, you must write the recipe with care so that it will
1 look for the prerequisite in the directory where 'make' finds it.
1
11 This is done with the "automatic variables" such as '$^' (⇒
Automatic Variables). For instance, the value of '$^' is a list of
1 all the prerequisites of the rule, including the names of the
1 directories in which they were found, and the value of '$@' is the
1 target. Thus:
1
1 foo.o : foo.c
1 cc -c $(CFLAGS) $^ -o $@
1
1 (The variable 'CFLAGS' exists so you can specify flags for C compilation
1 by implicit rules; we use it here for consistency so it will affect all
11 C compilations uniformly; ⇒Variables Used by Implicit Rules
Implicit Variables.)
1
1 Often the prerequisites include header files as well, which you do
1 not want to mention in the recipe. The automatic variable '$<' is just
1 the first prerequisite:
1
1 VPATH = src:../headers
1 foo.o : foo.c defs.h hack.h
1 cc -c $(CFLAGS) $< -o $@
1