GNU Make
GNU Make A Program for Directing Recompilation GNU make Version 4.1 September 2014 Richard M. Stallman, Roland McGrath, Paul D.
This file documents the GNU make utility, which determines automatically which pieces of a large program need to be recompiled, and issues the commands to recompile them. This is Edition 0.73, last updated 30 September 2014, of The GNU Make Manual, for GNU make version 4.1. Copyright c 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
i Short Contents 1 Overview of make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 An Introduction to Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 Writing Makefiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 4 Writing Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 5 Writing Recipes in Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 6 How to Use Variables . . .
iii Table of Contents 1 Overview of make . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 1.2 2 An Introduction to Makefiles . . . . . . . . . . . . . . . . . . 3 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3 How to Read This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Problems and Bugs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 What a Rule Looks Like . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
iv GNU make 4.9 Multiple Targets in a Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.10 Multiple Rules for One Target. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.11 Static Pattern Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.11.1 Syntax of Static Pattern Rules . . . . . . . . . . . . . . . . . . . . . . . . . . 4.11.2 Static Pattern Rules versus Implicit Rules . . . . . . . . . . . . . . . 4.
v 7 Conditional Parts of Makefiles . . . . . . . . . . . . . . . 77 7.1 7.2 7.3 8 Example of a Conditional . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Syntax of Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 Conditionals that Test Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Functions for Transforming Text . . . . . . . . . . . . . 83 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 8.
vi GNU make 11 Using make to Update Archive Files . . . . . . . 129 11.1 Archive Members as Targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Implicit Rule for Archive Member Targets . . . . . . . . . . . . . . . . . . . 11.2.1 Updating Archive Symbol Directories. . . . . . . . . . . . . . . . . . . 11.3 Dangers When Using Archives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.4 Suffix Rules for Archive Files. . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 1: Overview of make 1 1 Overview of make The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. This manual describes GNU make, which was implemented by Richard Stallman and Roland McGrath. Development since Version 3.76 has been handled by Paul D. Smith. GNU make conforms to section 6.2 of IEEE Standard 1003.2-1992 (POSIX.2).
2 GNU make Before reporting a bug or trying to fix it yourself, try to isolate it to the smallest possible makefile that reproduces the problem. Then send us the makefile and the exact results make gave you, including any error or warning messages. Please don’t paraphrase these messages: it’s best to cut and paste them into your report.
Chapter 2: An Introduction to Makefiles 3 2 An Introduction to Makefiles You need a file called a makefile to tell make what to do. Most often, the makefile tells make how to compile and link a program. In this chapter, we will discuss a simple makefile that describes how to compile and link a text editor which consists of eight C source files and three header files.
4 GNU make 2.2 A Simple Makefile Here is a straightforward makefile that describes the way an executable file called edit depends on eight object files which, in turn, depend on eight C source and three header files. In this example, all the C files include defs.h, but only those defining editing commands include command.h, and only low level files that change the editor buffer include buffer.h. edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.
Chapter 2: An Introduction to Makefiles 5 A recipe may follow each line that contains a target and prerequisites. These recipes say how to update the target file. A tab character (or whatever character is specified by the .RECIPEPREFIX variable; see Section 6.14 [Special Variables], page 73) must come at the beginning of every line in the recipe to distinguish recipes from other lines in the makefile. (Bear in mind that make does not know anything about how the recipes work.
6 GNU make Thus, if we change the file insert.c and run make, make will compile that file to update insert.o, and then link edit. If we change the file command.h and run make, make will recompile the object files kbd.o, command.o and files.o and then link the file edit. 2.4 Variables Make Makefiles Simpler In our example, we had to list all the object files twice in the rule for edit (repeated here): edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.
Chapter 2: An Introduction to Makefiles 7 objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects) main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command.c display.o : display.c defs.h buffer.h cc -c display.c insert.o : insert.c defs.h buffer.h cc -c insert.c search.o : search.c defs.h buffer.h cc -c search.c files.o : files.c defs.h buffer.h command.h cc -c files.
8 GNU make objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects) main.o : defs.h kbd.o : defs.h command.h command.o : defs.h command.h display.o : defs.h buffer.h insert.o : defs.h buffer.h search.o : defs.h buffer.h files.o : defs.h buffer.h command.h utils.o : defs.h .PHONY : clean clean : rm edit $(objects) This is how we would write the makefile in actual practice. (The complications associated with ‘clean’ are described elsewhere.
Chapter 2: An Introduction to Makefiles 9 2.7 Rules for Cleaning the Directory Compiling a program is not the only thing you might want to write rules for. Makefiles commonly tell how to do a few other things besides compiling a program: for example, how to delete all the object files and executables so that the directory is ‘clean’.
Chapter 3: Writing Makefiles 11 3 Writing Makefiles The information that tells make how to recompile a system comes from reading a data base called the makefile. 3.1 What Makefiles Contain Makefiles contain five kinds of things: explicit rules, implicit rules, variable definitions, directives, and comments. Rules, variables, and directives are described at length in later chapters. • An explicit rule says when and how to remake one or more files, called the rule’s targets.
12 GNU make 3.1.1 Splitting Long Lines Makefiles use a “line-based” syntax in which the newline character is special and marks the end of a statement. GNU make has no limit on the length of a statement line, up to the amount of memory in your computer. However, it is difficult to read lines which are too long to display without wrapping or scrolling.
Chapter 3: Writing Makefiles 13 3.3 Including Other Makefiles The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: include filenames... filenames can contain shell file name patterns. If filenames is empty, nothing is included and no error is printed.
14 GNU make Only after it has tried to find a way to remake a makefile and failed, will make diagnose the missing makefile as a fatal error. If you want make to simply ignore a makefile which does not exist or cannot be remade, with no error message, use the -include directive instead of include, like this: -include filenames...
Chapter 3: Writing Makefiles 15 you can write an explicit rule with the makefile as the target, and an empty recipe (see Section 5.9 [Using Empty Recipes], page 57). If the makefiles specify a double-colon rule to remake a file with a recipe but no prerequisites, that file will always be remade (see Section 4.12 [Double-Colon], page 38).
16 GNU make the information in the containing makefile, make should look in another makefile. See Section 10.5 [Pattern Rules], page 118, for more information on pattern rules.
Chapter 3: Writing Makefiles 17 immediate != immediate define immediate deferred endef define immediate = deferred endef define immediate ?= deferred endef define immediate := immediate endef define immediate ::= immediate endef define immediate += deferred or immediate endef define immediate != immediate endef For the append operator, ‘+=’, the right-hand side is considered immediate if the variable was previously set as a simple variable (‘:=’ or ‘::=’), and deferred otherwise.
18 GNU make That is, the target and prerequisite sections are expanded immediately, and the recipe used to construct the target is always deferred. This general rule is true for explicit rules, pattern rules, suffix rules, static pattern rules, and simple prerequisite definitions. 3.8 Secondary Expansion In the previous section we learned that GNU make works in two distinct phases: a read-in phase and a target-update phase (see Section 3.7 [How make Reads a Makefile], page 16).
Chapter 3: Writing Makefiles 19 $*, etc. during the second expansion and they will have their expected values, just as in the recipe. All you have to do is defer the expansion by escaping the $. Also, secondary expansion occurs for both explicit and implicit (pattern) rules. Knowing this, the possible uses for this feature increase dramatically. For example: .SECONDEXPANSION: main_OBJS := main.o try.o test.o lib_OBJS := lib.o api.
20 GNU make tively. In the third they will have values foo.1, foo.1 bar.1 foo.2 bar.2, and foo.1 bar.1 foo.2 bar.2 foo.1 foo.1 bar.1 foo.1 bar.1 respectively. Rules undergo secondary expansion in makefile order, except that the rule with the recipe is always evaluated last. The variables $$? and $$* are not available and expand to the empty string.
Chapter 4: Writing Rules 21 4 Writing Rules A rule appears in the makefile and says when and how to remake certain files, called the rule’s targets (most often only one per rule). It lists the other files that are the prerequisites of the target, and the recipe to use to create or update the target. The order of rules is not significant, except for determining the default goal: the target for make to consider, if you do not otherwise specify one.
22 GNU make The criterion for being out of date is specified in terms of the prerequisites, which consist of file names separated by spaces. (Wildcards and archive members (see Chapter 11 [Archives], page 129) are allowed here too.) A target is out of date if it does not exist or if it is older than any of the prerequisites (by comparison of last-modification times).
Chapter 4: Writing Rules 23 $(OBJS): | $(OBJDIR) $(OBJDIR): mkdir $(OBJDIR) Now the rule to create the objdir directory will be run, if needed, before any ‘.o’ is built, but no ‘.o’ will be built because the objdir directory timestamp changed. 4.3 Using Wildcard Characters in File Names A single file name can specify many files using wildcard characters. The wildcard characters in make are ‘*’, ‘?’ and ‘[...]’, the same as in the Bourne shell. For example, *.
24 GNU make you use the value of objects in a recipe, the shell may perform wildcard expansion when the recipe runs. To set objects to the expansion, instead use: objects := $(wildcard *.o) See Section 4.3.3 [Wildcard Function], page 24. 4.3.2 Pitfalls of Using Wildcards Now here is an example of a naive way of using wildcard expansion, that does not do what you would intend.
Chapter 4: Writing Rules 25 $(wildcard *.c) We can change the list of C source files into a list of object files by replacing the ‘.c’ suffix with ‘.o’ in the result, like this: $(patsubst %.c,%.o,$(wildcard *.c)) (Here we have used another function, patsubst. See Section 8.2 [Functions for String Substitution and Analysis], page 84.) Thus, a makefile to compile all C source files in the directory and then link them together could be written as follows: objects := $(patsubst %.c,%.o,$(wildcard *.
26 GNU make foo.o : src/foo.c assuming the file foo.c does not exist in the current directory but is found in the directory src. 4.4.2 The vpath Directive Similar to the VPATH variable, but more selective, is the vpath directive (note lower case), which allows you to specify a search path for a particular class of file names: those that match a particular pattern. Thus you can supply certain search directories for one class of file names and other directories (or none) for other file names.
Chapter 4: Writing Rules vpath vpath vpath will look for vpath vpath will look for 27 %.c foo % blish %.c bar a file ending in ‘.c’ in foo, then blish, then bar, while %.c foo:bar % blish a file ending in ‘.c’ in foo, then bar, then blish. 4.4.3 How Directory Searches are Performed When a prerequisite is found through directory search, regardless of type (general or selective), the pathname located may not be the one that make actually provides you in the prerequisite list.
28 GNU make This is done with the automatic variables such as ‘$^’ (see Section 10.5.3 [Automatic Variables], page 120). For instance, the value of ‘$^’ is a list of all the prerequisites of the rule, including the names of the directories in which they were found, and the value of ‘$@’ is the target. Thus: foo.o : foo.
Chapter 4: Writing Rules 29 a pattern string. When a prerequisite like ‘-lname’ is seen, make will replace the percent in each pattern in the list with name and perform the above directory searches using each library file name. The default value for .LIBPATTERNS is ‘lib%.so lib%.a’, which provides the default behavior described above. You can turn off link library expansion completely by setting this variable to an empty value. 4.
30 GNU make By declaring the sub-directories as .PHONY targets (you must do this as the sub-directory obviously always exists; otherwise it won’t be built) you can remove these problems: SUBDIRS = foo bar baz .PHONY: subdirs $(SUBDIRS) subdirs: $(SUBDIRS) $(SUBDIRS): $(MAKE) -C $@ foo: baz Here we’ve also declared that the foo sub-directory cannot be built until after the baz sub-directory is complete; this kind of relationship declaration is particularly important when attempting parallel builds.
Chapter 4: Writing Rules 31 cleanall : cleanobj cleandiff rm program cleanobj : rm *.o cleandiff : rm *.diff 4.6 Rules without Recipes or Prerequisites If a rule has no prerequisites or recipe, and the target of the rule is a nonexistent file, then make imagines this target to have been updated whenever its rule is run. This implies that all targets depending on this one will always have their recipe run.
32 GNU make 4.8 Special Built-in Target Names Certain names have special meanings if they appear as targets. .PHONY The prerequisites of the special target .PHONY are considered to be phony targets. When it is time to consider such a target, make will run its recipe unconditionally, regardless of whether a file with that name exists or what its last-modification time is. See Section 4.5 [Phony Targets], page 29. .SUFFIXES The prerequisites of the special target .
Chapter 4: Writing Rules 33 .DELETE_ON_ERROR If .DELETE_ON_ERROR is mentioned as a target anywhere in the makefile, then make will delete the target of a rule if it has changed and its recipe exits with a nonzero exit status, just as it does when it receives a signal. See Section 5.5 [Errors in Recipes], page 49. .IGNORE If you specify prerequisites for .IGNORE, then make will ignore errors in execution of the recipe for those particular files. The recipe for .IGNORE (if any) is ignored.
34 GNU make .EXPORT_ALL_VARIABLES Simply by being mentioned as a target, this tells make to export all variables to child processes by default. See Section 5.7.2 [Communicating Variables to a Sub-make], page 52. .NOTPARALLEL If .NOTPARALLEL is mentioned as a target, then this invocation of make will be run serially, even if the ‘-j’ option is given. Any recursively invoked make command will still run recipes in parallel (unless its makefile also contains this target).
Chapter 4: Writing Rules 35 bigoutput littleoutput : text.g generate text.g -$(subst output,,$@) > $@ is equivalent to bigoutput : text.g generate text.g -big > bigoutput littleoutput : text.g generate text.g -little > littleoutput Here we assume the hypothetical program generate makes two types of output, one if given ‘-big’ and one if given ‘-little’. See Section 8.2 [Functions for String Substitution and Analysis], page 84, for an explanation of the subst function.
36 GNU make If none of the explicit rules for a target has a recipe, then make searches for an applicable implicit rule to find one see Chapter 10 [Using Implicit Rules], page 111). 4.11 Static Pattern Rules Static pattern rules are rules which specify multiple targets and construct the prerequisite names for each target based on the target name. They are more general than ordinary rules with multiple targets because the targets do not have to have identical prerequisites.
Chapter 4: Writing Rules 37 objects = foo.o bar.o all: $(objects) $(objects): %.o: %.c $(CC) -c $(CFLAGS) $< -o $@ Here ‘$<’ is the automatic variable that holds the name of the prerequisite and ‘$@’ is the automatic variable that holds the name of the target; see Section 10.5.3 [Automatic Variables], page 120. Each target specified must match the target pattern; a warning is issued for each target that does not.
38 GNU make • If you cannot be sure of the precise contents of the directories you are using, you may not be sure which other irrelevant files might lead make to use the wrong implicit rule. The choice might depend on the order in which the implicit rule search is done. With static pattern rules, there is no uncertainty: each rule applies to precisely the targets specified. 4.12 Double-Colon Rules Double-colon rules are explicit rules written with ‘::’ instead of ‘:’ after the target names.
Chapter 4: Writing Rules 39 main.o : main.c defs.h Thus you no longer have to write all those rules yourself. The compiler will do it for you. Note that such a rule constitutes mentioning main.o in a makefile, so it can never be considered an intermediate file by implicit rule search. This means that make won’t ever remove the file after using it; see Section 10.4 [Chains of Implicit Rules], page 117.
40 GNU make makefiles like any others, make will remake them as necessary with no further work from you. See Section 3.5 [Remaking Makefiles], page 14. Note that the ‘.d’ files contain target definitions; you should be sure to place the include directive after the first, default goal in your makefiles or run the risk of having a random object file become the default goal. See Section 2.3 [How Make Works], page 5.
Chapter 5: Writing Recipes in Rules 41 5 Writing Recipes in Rules The recipe of a rule consists of one or more shell command lines to be executed, one at a time, in the order they appear. Typically, the result of executing these commands is that the target of the rule is brought up to date. Users use many different shell programs, but recipes in makefiles are always interpreted by /bin/sh unless the makefile specifies otherwise. See Section 5.3 [Recipe Execution], page 44. 5.
42 GNU make character of the next line after the backslash/newline is the recipe prefix character (a tab by default; see Section 6.14 [Special Variables], page 73), then that character (and only that character) is removed. Whitespace is never added to the recipe.
Chapter 5: Writing Recipes in Rules 43 we will get output like this: hello world If you like, you can also use target-specific variables (see Section 6.11 [Target-specific Variable Values], page 71) to obtain a tighter correspondence between the variable and the recipe that uses it. 5.1.2 Using Variables in Recipes The other way in which make processes recipes is by expanding any variable references in them (see Section 6.1 [Reference], page 59).
44 GNU make The ‘-s’ or ‘--silent’ flag to make prevents all echoing, as if all recipes started with ‘@’. A rule in the makefile for the special target .SILENT without prerequisites has the same effect (see Section 4.8 [Special Built-in Target Names], page 32). .SILENT is essentially obsolete since ‘@’ is more flexible. 5.3 Recipe Execution When it is time to execute recipes to update a target, they are executed by invoking a new sub-shell for each line of the recipe, unless the .
Chapter 5: Writing Recipes in Rules 45 .ONESHELL: SHELL = /usr/bin/perl .SHELLFLAGS = -e show : @f = qw(a b c); print "@f\n"; However, either of these alternatives would work properly: .ONESHELL: SHELL = /usr/bin/perl .SHELLFLAGS = -e show : # Make sure "@" is not the first character on the first line @f = qw(a b c); print "@f\n"; or .ONESHELL: SHELL = /usr/bin/perl .
46 GNU make Unlike most variables, the variable SHELL is never set from the environment. This is because the SHELL environment variable is used to specify your personal choice of shell program for interactive use. It would be very bad for personal choices like this to affect the functioning of makefiles. See Section 6.10 [Variables from the Environment], page 70. Furthermore, when you do set SHELL in your makefile that value is not exported in the environment to recipe lines that make invokes.
Chapter 5: Writing Recipes in Rules 47 The effect of the above DOS-specific processing is that a Makefile that contains ‘SHELL = /bin/sh’ (as many Unix makefiles do), will work on MS-DOS unaltered if you have e.g. sh.exe installed in some directory along your PATH. 5.4 Parallel Execution GNU make knows how to execute several recipes at once. Normally, make will execute only one recipe at a time, waiting for it to finish before executing the next.
48 GNU make completed. Additionally, if there are multiple recursive make invocations running in parallel, they will communicate so that only one of them is generating output at a time. If working directory printing is enabled (see Section 5.7.4 [The ‘--print-directory’ Option], page 55), the enter/leave messages are printed around each output grouping. If you prefer not to see these messages add the ‘--no-print-directory’ option to MAKEFLAGS.
Chapter 5: Writing Recipes in Rules 49 modes). For example, many programs that can display colorized output will not do so if they determine they are not writing to a terminal. If your makefile invokes a program like this then using the output synchronization options will cause the program to believe it’s running in “non-interactive” mode even though the output will ultimately go to the terminal. 5.4.
50 GNU make either directly or indirectly. No further recipes will be executed for these targets, since their preconditions have not been achieved. Normally make gives up immediately in this circumstance, returning a nonzero status. However, if the ‘-k’ or ‘--keep-going’ flag is specified, make continues to consider the other prerequisites of the pending targets, remaking them if necessary, before it gives up and returns nonzero status.
Chapter 5: Writing Recipes in Rules 51 system. For example, suppose you have a sub-directory subdir which has its own makefile, and you would like the containing directory’s makefile to run make on the sub-directory. You can do it by writing this: subsystem: cd subdir && $(MAKE) or, equivalently, this (see Section 9.
52 GNU make lines containing MAKE are executed normally despite the presence of a flag that causes most recipes not to be run. The usual MAKEFLAGS mechanism passes the flags to the sub-make (see Section 5.7.3 [Communicating Options to a Sub-make], page 54), so your request to touch the files, or print the recipes, is propagated to the subsystem. 5.7.2 Communicating Variables to a Sub-make Variable values of the top-level make can be passed to the sub-make through the environment by explicit request.
Chapter 5: Writing Recipes in Rules 53 variable := value export variable Likewise, export variable += value is just like: variable += value export variable See Section 6.6 [Appending More Text to Variables], page 66. You may notice that the export and unexport directives work in make in the same way they work in the shell, sh.
54 GNU make 5.7.3 Communicating Options to a Sub-make Flags such as ‘-s’ and ‘-k’ are passed automatically to the sub-make through the variable MAKEFLAGS. This variable is set up automatically by make to contain the flag letters that make received. Thus, if you do ‘make -ks’ then MAKEFLAGS gets the value ‘ks’. As a consequence, every sub-make gets a value for MAKEFLAGS in its environment. In response, it takes the flags from that value and processes them as if they had been given as arguments.
Chapter 5: Writing Recipes in Rules 55 ‘--warn-undefined-variables’). MFLAGS was traditionally used explicitly in the recursive make command, like this: subsystem: cd subdir && $(MAKE) $(MFLAGS) but now MAKEFLAGS makes this usage redundant. If you want your makefiles to be compatible with old make programs, use this technique; it will work fine with more modern make versions too. The MAKEFLAGS variable can also be useful if you want to have certain options, such as ‘-k’ (see Section 9.
56 GNU make Normally, you do not need to specify this option because ‘make’ does it for you: ‘-w’ is turned on automatically when you use the ‘-C’ option, and in sub-makes. make will not automatically turn on ‘-w’ if you also use ‘-s’, which says to be silent, or if you use ‘--no-print-directory’ to explicitly disable it. 5.
Chapter 5: Writing Recipes in Rules 57 make will not echo the first line, the echo command. But it will echo the following two recipe lines. On the other hand, prefix characters on the recipe line that refers to a canned sequence apply to every line in the sequence. So the rule: frob.out: frob.in @$(frobnicate) does not echo any recipe lines. (See Section 5.2 [Recipe Echoing], page 43, for a full explanation of ‘@’.) 5.9 Using Empty Recipes It is sometimes useful to define recipes which do nothing.
Chapter 6: How to Use Variables 59 6 How to Use Variables A variable is a name defined in a makefile to represent a string of text, called the variable’s value. These values are substituted by explicit request into targets, prerequisites, recipes, and other parts of the makefile. (In some other versions of make, variables are called macros.
60 GNU make could be used to compile a C program prog.c. Since spaces before the variable value are ignored in variable assignments, the value of foo is precisely ‘c’. (Don’t actually write your makefiles this way!) A dollar sign followed by a character other than a dollar sign, open-parenthesis or openbrace treats that single character as the variable name. Thus, you could reference the variable x with ‘$x’.
Chapter 6: How to Use Variables 61 Simply expanded variables are defined by lines using ‘:=’ or ‘::=’ (see Section 6.5 [Setting Variables], page 65). Both forms are equivalent in GNU make; however only the ‘::=’ form is described by the POSIX standard (support for ‘::=’ was added to the POSIX standard in 2012, so older versions of make won’t accept this form either).
62 GNU make effect (but be rather hard to read). If you put whitespace at the end of a variable value, it is a good idea to put a comment like that at the end of the line to make your intent clear.
Chapter 6: How to Use Variables 63 For example: foo := a.o b.o c.o bar := $(foo:%.o=%.c) sets ‘bar’ to ‘a.c b.c c.c’. 6.3.2 Computed Variable Names Computed variable names are a complicated concept needed only for sophisticated makefile programming. For most purposes you need not consider them, except to know that making a variable with a dollar sign in its name might have strange results.
64 GNU make x = variable1 variable2 := Hello y = $(subst 1,2,$(x)) z = y a := $($($(z))) eventually defines a as ‘Hello’. It is doubtful that anyone would ever want to write a nested reference as convoluted as this one, but it works: ‘$($($(z)))’ expands to ‘$($(y))’ which becomes ‘$($(subst 1,2,$(x)))’. This gets the value ‘variable1’ from x and changes it by substitution to ‘variable2’, so that the entire string becomes ‘$(variable2)’, a simple variable reference whose value is ‘Hello’.
Chapter 6: How to Use Variables 65 ifdef do_sort func := sort else func := strip endif bar := a d b g q c foo := $($(func) $(bar)) attempts to give ‘foo’ the value of the variable ‘sort a d b g q c’ or ‘strip a d b g q c’, rather than giving ‘a d b g q c’ as the argument to either the sort or the strip function. This restriction could be removed in the future if that change is shown to be a good idea.
66 GNU make defines a variable named objects. Whitespace around the variable name and immediately after the ‘=’ is ignored. Variables defined with ‘=’ are recursively expanded variables. Variables defined with ‘:=’ or ‘::=’ are simply expanded variables; these definitions can contain variable references which will be expanded before the definition is made. See Section 6.2 [The Two Flavors of Variables], page 60.
Chapter 6: How to Use Variables 67 This takes the value of the variable objects, and adds the text ‘another.o’ to it (preceded by a single space). Thus: objects = main.o foo.o bar.o utils.o objects += another.o sets objects to ‘main.o foo.o bar.o utils.o another.o’. Using ‘+=’ is similar to: objects = main.o foo.o bar.o utils.o objects := $(objects) another.o but differs in ways that become important when you use more complex values.
68 GNU make The first line defines the CFLAGS variable with a reference to another variable, includes. (CFLAGS is used by the rules for C compilation; see Section 10.2 [Catalogue of Built-In Rules], page 112.) Using ‘=’ for the definition makes CFLAGS a recursively-expanded variable, meaning ‘$(includes) -O’ is not expanded when make processes the definition of CFLAGS. Thus, includes need not be defined yet for its value to take effect. It only has to be defined before any reference to CFLAGS.
Chapter 6: How to Use Variables 69 6.8 Defining Multi-Line Variables Another way to set the value of a variable is to use the define directive. This directive has an unusual syntax which allows newline characters to be included in the value, which is convenient for defining both canned sequences of commands (see Section 5.8 [Defining Canned Recipes], page 56), and also sections of makefile syntax to use with eval (see Section 8.9 [Eval Function], page 93).
70 GNU make not. However, if you are using the flavor (see Section 8.11 [Flavor Function], page 95) and origin (see Section 8.10 [Origin Function], page 94) functions, there is a difference between a variable that was never set and a variable with an empty value. In such situations you may want to use the undefine directive to make a variable appear as if it was never set.
Chapter 6: How to Use Variables 71 6.11 Target-specific Variable Values Variable values in make are usually global; that is, they are the same regardless of where they are evaluated (unless they’re reset, of course). One exception to that is automatic variables (see Section 10.5.3 [Automatic Variables], page 120). The other exception is target-specific variable values. This feature allows you to define different values for the same variable, based on the target that make is currently building.
72 GNU make pattern ... : variable-assignment where pattern is a %-pattern. As with target-specific variable values, multiple pattern values create a pattern-specific variable value for each pattern individually. The variableassignment can be any valid form of assignment. Any command line variable setting will take precedence, unless override is specified. For example: %.o : CFLAGS = -O will assign CFLAGS the value of ‘-O’ for all targets matching the pattern %.o.
Chapter 6: How to Use Variables 73 6.14 Other Special Variables GNU make supports some variables that have special properties. MAKEFILE_LIST Contains the name of each makefile that is parsed by make, in the order in which it was parsed. The name is appended just before make begins to parse the makefile. Thus, if the first thing a makefile does is examine the last word in this variable, it will be the name of the current makefile.
74 GNU make # Query the default goal. ifeq ($(.DEFAULT_GOAL),) $(warning no default goal is set) endif .PHONY: foo foo: ; @echo $@ $(warning default goal is $(.DEFAULT_GOAL)) # Reset the default goal. .DEFAULT_GOAL := .PHONY: bar bar: ; @echo $@ $(warning default goal is $(.DEFAULT_GOAL)) # Set our own. .DEFAULT_GOAL := foo This makefile prints: no default goal is set default goal is foo default goal is bar foo Note that assigning more than one target name to .
Chapter 6: How to Use Variables 75 .RECIPEPREFIX The first character of the value of this variable is used as the character make assumes is introducing a recipe line. If the variable is empty (as it is by default) that character is the standard tab character. For example, this is a valid makefile: .RECIPEPREFIX = > all: > @echo Hello, world The value of .RECIPEPREFIX can be changed multiple times; once set it stays in effect for all rules parsed until it is modified. .
76 GNU make ‘target-specific’ Supports target-specific and pattern-specific variable assignments. See Section 6.11 [Target-specific Variable Values], page 71. ‘undefine’ Supports the undefine directive. See Section 6.9 [Undefine Directive], page 69. ‘guile’ Has GNU Guile available as an embedded extension language. See Section 12.1 [GNU Guile Integration], page 133. ‘load’ Supports dynamically loadable objects for creating custom extensions. See Section 12.2 [Loading Dynamic Objects], page 135. .
Chapter 7: Conditional Parts of Makefiles 77 7 Conditional Parts of Makefiles A conditional directive causes part of a makefile to be obeyed or ignored depending on the values of variables. Conditionals can compare the value of one variable to another, or the value of a variable to a constant string. Conditionals control what make actually “sees” in the makefile, so they cannot be used to control recipes at the time of execution. 7.
78 GNU make libs_for_gcc = -lgnu normal_libs = ifeq ($(CC),gcc) libs=$(libs_for_gcc) else libs=$(normal_libs) endif foo: $(objects) $(CC) -o foo $(objects) $(libs) 7.2 Syntax of Conditionals The syntax of a simple conditional with no else is as follows: conditional-directive text-if-true endif The text-if-true may be any lines of text, to be considered as part of the makefile if the condition is true. If the condition is false, no text is used instead.
Chapter 7: Conditional Parts of Makefiles ifeq ifeq ifeq ifeq ifeq 79 (arg1, arg2) ’arg1’ ’arg2’ "arg1" "arg2" "arg1" ’arg2’ ’arg1’ "arg2" Expand all variable references in arg1 and arg2 and compare them. If they are identical, the text-if-true is effective; otherwise, the text-if-false, if any, is effective. Often you want to test if a variable has a non-empty value.
80 GNU make return true for all definitions except those like foo =. To test for an empty value, use ifeq ($(foo),). For example, bar = foo = $(bar) ifdef foo frobozz = yes else frobozz = no endif sets ‘frobozz’ to ‘yes’, while: foo = ifdef foo frobozz = yes else frobozz = no endif sets ‘frobozz’ to ‘no’. ifndef variable-name If the variable variable-name has an empty value, the text-if-true is effective; otherwise, the text-if-false, if any, is effective.
Chapter 7: Conditional Parts of Makefiles 81 Substitution and Analysis], page 84). This is useful when touch is not enough to make a file appear up to date. The findstring function determines whether one string appears as a substring of another. If you want to test for the ‘-t’ flag, use ‘t’ as the first string and the value of MAKEFLAGS as the other. For example, here is how to arrange to use ‘ranlib -t’ to finish marking an archive file up to date: archive.a: ...
Chapter 8: Functions for Transforming Text 83 8 Functions for Transforming Text Functions allow you to do text processing in the makefile to compute the files to operate on or the commands to use in recipes. You use a function in a function call, where you give the name of the function and some text (the arguments) for the function to operate on. The result of the function’s processing is substituted into the makefile at the point of the call, just as a variable might be substituted. 8.
84 GNU make 8.2 Functions for String Substitution and Analysis Here are some functions that operate on strings: $(subst from,to,text) Performs a textual replacement on the text text: each occurrence of from is replaced by to. The result is substituted for the function call. For example, $(subst ee,EE,feet on the street) substitutes the string ‘fEEt on the strEEt’. $(patsubst pattern,replacement,text) Finds whitespace-separated words in text that match pattern and replaces them with replacement.
Chapter 8: Functions for Transforming Text 85 $(objects:.o=.c) instead of using the general form: $(patsubst %.o,%.c,$(objects)) $(strip string) Removes leading and trailing whitespace from string and replaces each internal sequence of one or more whitespace characters with a single space. Thus, ‘$(strip a b c )’ results in ‘a b c’. The function strip can be very useful when used in conjunction with conditionals.
86 GNU make For example, given: objects=main1.o foo.o main2.o bar.o mains=main1.o main2.o the following generates a list which contains all the object files not in ‘mains’: $(filter-out $(mains),$(objects)) $(sort list) Sorts the words of list in lexical order, removing duplicate words. The output is a list of words separated by single spaces. Thus, $(sort foo bar lose) returns the value ‘bar foo lose’.
Chapter 8: Functions for Transforming Text 87 produces the result ‘bar’. Although $(lastword text) is the same as $(word $(words text),text), the lastword function was added for its simplicity and better performance. Here is a realistic example of the use of subst and patsubst. Suppose that a makefile uses the VPATH variable to specify a list of directories that make should search for prerequisite files (see Section 4.4.1 [VPATH Search Path for All Prerequisites], page 25).
88 GNU make $(suffix names...) Extracts the suffix of each file name in names. If the file name contains a period, the suffix is everything starting with the last period. Otherwise, the suffix is the empty string. This frequently means that the result will be empty when names is not, and if names contains multiple file names, the result may contain fewer file names. For example, $(suffix src/foo.c src-1.0/bar.c hacks) produces the result ‘.c .c’. $(basename names...
Chapter 8: Functions for Transforming Text 89 $(wildcard pattern) The argument pattern is a file name pattern, typically containing wildcard characters (as in shell file name patterns). The result of wildcard is a space-separated list of the names of existing files that match the pattern. See Section 4.3 [Using Wildcard Characters in File Names], page 23. $(realpath names...) For each file name in names return the canonical absolute name. A canonical name does not contain any . or ..
90 GNU make $(and condition1[,condition2[,condition3...]]) The and function provides a “short-circuiting” AND operation. Each argument is expanded, in order. If an argument expands to an empty string the processing stops and the result of the expansion is the empty string. If all arguments expand to a non-empty string then the result of the expansion is the expansion of the last argument. 8.5 The foreach Function The foreach function is very different from other functions.
Chapter 8: Functions for Transforming Text 91 undefined before the foreach function call, it is undefined after the call. See Section 6.2 [The Two Flavors of Variables], page 60. You must take care when using complex variable expressions that result in variable names because many strange things are valid variable names, but are probably not what you intended.
92 GNU make 8.7 The call Function The call function is unique in that it can be used to create new parameterized functions. You can write a complex expression as the value of a variable, then use call to expand it with different values. The syntax of the call function is: $(call variable,param,param,...) When make expands this function, it assigns each param to temporary variables $(1), $(2), etc. The variable $(0) will contain variable. There is no maximum number of parameter arguments.
Chapter 8: Functions for Transforming Text 93 8.8 The value Function The value function provides a way for you to use the value of a variable without having it expanded. Please note that this does not undo expansions which have already occurred; for example if you create a simply expanded variable its value is expanded during the definition; in that case the value function will return the same result as using the variable directly.
94 GNU make PROGRAMS = server client server_OBJS = server.o server_priv.o server_access.o server_LIBS = priv protocol client_OBJS = client.o client_api.o client_mem.o client_LIBS = protocol # Everything after this is generic .PHONY: all all: $(PROGRAMS) define PROGRAM_template = $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%) ALL_OBJS += $$($(1)_OBJS) endef $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog)))) $(PROGRAMS): $(LINK.o) $^ $(LDLIBS) -o $@ clean: rm -f $(ALL_OBJS) $(PROGRAMS) 8.
Chapter 8: Functions for Transforming Text 95 ‘environment’ if variable was inherited from the environment provided to make. ‘environment override’ if variable was inherited from the environment provided to make, and is overriding a setting for variable in the makefile as a result of the ‘-e’ option (see Section 9.7 [Summary of Options], page 104). ‘file’ if variable was defined in a makefile. ‘command line’ if variable was defined on the command line.
96 GNU make The syntax of the flavor function is: $(flavor variable) Note that variable is the name of a variable to inquire about, not a reference to that variable. Therefore you would not normally use a ‘$’ or parentheses when writing it. (You can, however, use a variable reference in the name if you want the name not to be a constant.) The result of this function is a string that identifies the flavor of the variable variable: ‘undefined’ if variable was never defined.
Chapter 8: Functions for Transforming Text 97 8.13 The shell Function The shell function is unlike any other function other than the wildcard function (see Section 4.3.3 [The Function wildcard], page 24) in that it communicates with the world outside of make. The shell function performs the same function that backquotes (‘‘’) perform in most shells: it does command expansion. This means that it takes as an argument a shell command and evaluates to the output of the command.
Chapter 9: How to Run make 99 9 How to Run make A makefile that says how to recompile a program can be used in more than one way. The simplest use is to recompile every file that is out of date. Usually, makefiles are written so that if you run make with no arguments, it does just that. But you might want to update only some of the files; you might want to use a different compiler or different compiler options; you might want just to find out which files are out of date without changing them.
100 GNU make targets not in the makefile may be specified, if make can find implicit rules that say how to make them. Make will set the special variable MAKECMDGOALS to the list of goals you specified on the command line. If no goals were given on the command line, this variable is empty. Note that this variable should be used only in special circumstances. An example of appropriate use is to avoid including .d files during clean rules (see Section 4.
Chapter 9: How to Run make 101 install Copy the executable file into a directory that users typically search for commands; copy any auxiliary files that the executable uses into the directories where it will look for them. print Print listings of the source files that have changed. tar Create a tar file of the source files. shar Create a shell archive (shar file) of the source files. dist Create a distribution file of the source files.
102 GNU make modification times remain the same. You can use the ‘-W’ flag in conjunction with the ‘-n’ flag to see what would happen if you were to modify specific files. With the ‘-n’ flag, make prints the recipe that it would normally execute but usually does not execute it. With the ‘-t’ flag, make ignores the recipes in the rules and uses (in effect) the command touch for each target that needs to be remade. The touch command is also printed, unless ‘-s’ or .SILENT is used.
Chapter 9: How to Run make 103 3. Use the command ‘make -t’ to mark all the object files as up to date. The next time you run make, the changes in the header files will not cause any recompilation. If you have already changed the header file at a time when some files do need recompilation, it is too late to do this. Instead, you can use the ‘-o file’ flag, which marks a specified file as “old” (see Section 9.7 [Summary of Options], page 104).
104 GNU make 9.6 Testing the Compilation of a Program Normally, when an error happens in executing a shell command, make gives up immediately, returning a nonzero status. No further recipes are executed for any target. The error implies that the goal cannot be correctly remade, and make reports this as soon as it knows. When you are compiling a program that you have just changed, this is not what you want.
Chapter 9: How to Run make 105 are being compared and with what results, which files actually need to be remade, which implicit rules are considered and which are applied—everything interesting about how make decides what to do. The -d option is equivalent to ‘--debug=a’ (see below). ‘--debug[=options]’ Print debugging information in addition to normal processing. Various levels and types of output can be chosen. With no arguments, print the “basic” level of debugging.
106 GNU make ‘-h’ ‘--help’ Remind you of the options that make understands and then exit. ‘-i’ ‘--ignore-errors’ Ignore all errors in recipes executed to remake files. See Section 5.5 [Errors in Recipes], page 49. ‘-I dir’ ‘--include-dir=dir’ Specifies a directory dir to search for included makefiles. See Section 3.3 [Including Other Makefiles], page 13. If several ‘-I’ options are used to specify several directories, the directories are searched in the order specified.
Chapter 9: How to Run make 107 Print the recipe that would be executed, but do not execute it (except in certain circumstances). See Section 9.3 [Instead of Executing Recipes], page 101. ‘-o file’ ‘--old-file=file’ ‘--assume-old=file’ Do not remake the file file even if it is older than its prerequisites, and do not remake anything on account of changes in file. Essentially the file is treated as very old and its rules are ignored. See Section 9.4 [Avoiding Recompilation of Some Files], page 102.
108 GNU make (see Section 10.3 [Variables Used by Implicit Rules], page 115); see the ‘-R’ option below. ‘-R’ ‘--no-builtin-variables’ Eliminate use of the built-in rule-specific variables (see Section 10.3 [Variables Used by Implicit Rules], page 115). You can still define your own, of course. The ‘-R’ option also automatically enables the ‘-r’ option (see above), since it doesn’t make sense to have implicit rules without any definitions for the variables that they use.
Chapter 9: How to Run make 109 ‘--no-print-directory’ Disable printing of the working directory under -w. This option is useful when -w is turned on automatically, but you do not want to see the extra messages. See Section 5.7.4 [The ‘--print-directory’ Option], page 55. ‘-W file’ ‘--what-if=file’ ‘--new-file=file’ ‘--assume-new=file’ Pretend that the target file has just been modified. When used with the ‘-n’ flag, this shows you what would happen if you were to modify that file.
Chapter 10: Using Implicit Rules 111 10 Using Implicit Rules Certain standard ways of remaking target files are used very often. For example, one customary way to make an object file is from a C source file using the C compiler, cc. Implicit rules tell make how to use customary techniques so that you do not have to specify them in detail when you want to use them. For example, there is an implicit rule for C compilation. File names determine which implicit rules are run.
112 GNU make files are supposed to exist. See Section 10.2 [Catalogue of Built-In Rules], page 112, for a catalogue of all the predefined implicit rules. Above, we said an implicit rule applies if the required prerequisites “exist or can be made”. A file “can be made” if it is mentioned explicitly in the makefile as a target or a prerequisite, or if an implicit rule can be recursively found for how to make it.
Chapter 10: Using Implicit Rules 113 Compiling C++ programs n.o is made automatically from n.cc, n.cpp, or n.C with a recipe of the form ‘$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c’. We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’. Compiling Pascal programs n.o is made automatically from n.p with the recipe ‘$(PC) $(PFLAGS) -c’. Compiling Fortran and Ratfor programs n.o is made automatically from n.r, n.F or n.f by running the Fortran compiler.
114 GNU make cc cc cc cc rm rm rm -c x.c -o x.o -c y.c -o y.o -c z.c -o z.o x.o y.o z.o -o x -f x.o -f y.o -f z.o In more complicated cases, such as when there is no object file whose name derives from the executable file name, you must write an explicit recipe for linking. Each kind of file automatically made into ‘.o’ object files will be automatically linked by using the compiler (‘$(CC)’, ‘$(FC)’ or ‘$(PC)’; the C compiler ‘$(CC)’ is used to assemble ‘.s’ files) without the ‘-c’ option.
Chapter 10: Using Implicit Rules 115 Texinfo and Info n.dvi is made from n.texinfo, n.texi, or n.txinfo, with the recipe ‘$(TEXI2DVI) $(TEXI2DVI_FLAGS)’. n.info is made from n.texinfo, n.texi, or n.txinfo, with the recipe ‘$(MAKEINFO) $(MAKEINFO_FLAGS)’. RCS Any file n is extracted if necessary from an RCS file named either n,v or RCS/n,v. The precise recipe used is ‘$(CO) $(COFLAGS)’. n will not be extracted from RCS if it already exists, even if the RCS file is newer.
116 GNU make For example, the recipe used to compile a C source file actually says ‘$(CC) -c $(CFLAGS) $(CPPFLAGS)’. The default values of the variables used are ‘cc’ and nothing, resulting in the command ‘cc -c’. By redefining ‘CC’ to ‘ncc’, you could cause ‘ncc’ to be used for all C compilations performed by the implicit rule. By redefining ‘CFLAGS’ to be ‘-g’, you could pass the ‘-g’ option to each compilation.
Chapter 10: Using Implicit Rules TANGLE Program to translate Web into Pascal; default ‘tangle’. CTANGLE Program to translate C Web into C; default ‘ctangle’. RM Command to remove a file; default ‘rm -f’. 117 Here is a table of variables whose values are additional arguments for the programs above. The default values for all of these is the empty string, unless otherwise noted. ARFLAGS Flags to give the archive-maintaining program; default ‘rv’.
118 GNU make Once make has decided to use the intermediate file, it is entered in the data base as if it had been mentioned in the makefile, along with the implicit rule that says how to create it. Intermediate files are remade using their rules just like all other files. But intermediate files are treated differently in two ways. The first difference is what happens if the intermediate file does not exist.
Chapter 10: Using Implicit Rules 119 Thus, a pattern rule ‘%.o : %.c’ says how to make any file stem.o from another file stem.c. Note that expansion using ‘%’ in pattern rules occurs after any variable or function expansions, which take place when the makefile is read. See Chapter 6 [How to Use Variables], page 59, and Chapter 8 [Functions for Transforming Text], page 83. 10.5.
120 GNU make defines a rule that can make any file x.o from x.c. The recipe uses the automatic variables ‘$@’ and ‘$<’ to substitute the names of the target file and the source file in each case where the rule applies (see Section 10.5.3 [Automatic Variables], page 120). Here is a second built-in rule: % :: RCS/%,v $(CO) $(COFLAGS) $< defines a rule that can make any file x whatsoever from a corresponding file x,v in the subdirectory RCS.
Chapter 10: Using Implicit Rules 121 $% The target member name, when the target is an archive member. See Chapter 11 [Archives], page 129. For example, if the target is foo.a(bar.o) then ‘$%’ is bar.o and ‘$@’ is foo.a. ‘$%’ is empty when the target is not an archive member. $< The name of the first prerequisite. If the target got its recipe from an implicit rule, this will be the first prerequisite added by the implicit rule (see Chapter 10 [Implicit Rules], page 111).
122 GNU make Of the variables listed above, four have values that are single file names, and three have values that are lists of file names. These seven have variants that get just the file’s directory name or just the file name within the directory. The variant variables’ names are formed by appending ‘D’ or ‘F’, respectively. These variants are semi-obsolete in GNU make since the functions dir and notdir can be used to get a similar effect (see Section 8.3 [Functions for File Names], page 87).
Chapter 10: Using Implicit Rules 123 ‘test’. The pattern rule prerequisites are turned into actual file names by substituting the stem for the character ‘%’. Thus, if in the same example one of the prerequisites is written as ‘%.c’, it expands to ‘test.c’. When the target pattern does not contain a slash (and it usually does not), directory names in the file names are removed from the file name before it is compared with the target prefix and suffix.
124 GNU make Suppose the makefile mentions foo.c. For this target, make would have to consider making it by linking an object file foo.c.o, or by C compilation-and-linking in one step from foo.c.c, or by Pascal compilation-and-linking from foo.c.p, and many other possibilities. We know these possibilities are ridiculous since foo.c is a C source file, not an executable. If make did consider these possibilities, it would ultimately reject them, because files such as foo.c.o and foo.c.p would not exist.
Chapter 10: Using Implicit Rules 125 new rule is defined, the built-in one is replaced. The new rule’s position in the sequence of implicit rules is determined by where you write the new rule. You can cancel a built-in implicit rule by defining a pattern rule with the same target and prerequisites, but no recipe. For example, the following would cancel the rule that runs the assembler: %.o : %.s 10.
126 GNU make A single-suffix rule is defined by a single suffix, which is the source suffix. It matches any file name, and the corresponding implicit prerequisite name is made by appending the source suffix. A single-suffix rule whose source suffix is ‘.c’ is equivalent to the pattern rule ‘% : %.c’. Suffix rule definitions are recognized by comparing each rule’s target against a defined list of known suffixes.
Chapter 10: Using Implicit Rules 127 10.8 Implicit Rule Search Algorithm Here is the procedure make uses for searching for an implicit rule for a target t. This procedure is followed for each double-colon rule with no recipe, for each target of ordinary rules none of which have a recipe, and for each prerequisite that is not the target of any rule. It is also followed recursively for prerequisites that come from implicit rules, in the search for a chain of rules.
128 GNU make is executed, each of these stored file names are entered into the data base and marked as having been updated and having the same update status as the file t. When the recipe of a pattern rule is executed for t, the automatic variables are set corresponding to the target and prerequisites. See Section 10.5.3 [Automatic Variables], page 120.
Chapter 11: Using make to Update Archive Files 129 11 Using make to Update Archive Files Archive files are files containing named sub-files called members; they are maintained with the program ar and their main use is as subroutine libraries for linking. 11.1 Archive Members as Targets An individual member of an archive file can be used as a target or prerequisite in make.
130 GNU make cc -c bar.c -o bar.o ar r foo.a bar.o rm -f bar.o Here make has envisioned the file bar.o as an intermediate file. See Section 10.4 [Chains of Implicit Rules], page 117. Implicit rules such as this one are written using the automatic variable ‘$%’. See Section 10.5.3 [Automatic Variables], page 120. An archive member name in an archive cannot contain a directory name, but it may be useful in a makefile to pretend that it does. If you write an archive member target foo.a(dir/file.
Chapter 11: Using make to Update Archive Files 131 (see Section 11.2 [Archive Update], page 129). But they are retained for compatibility with other makes. To write a suffix rule for archives, you simply write a suffix rule using the target suffix ‘.a’ (the usual suffix for archive files). For example, here is the old-fashioned suffix rule to update a library archive from C source files: .c.a: $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o $(AR) r $@ $*.o $(RM) $*.
Chapter 12: Extending GNU make 133 12 Extending GNU make GNU make provides many advanced capabilities, including many useful functions. However, it does not contain a complete programming language and so it has limitations. Sometimes these limitations can be overcome through use of the shell function to invoke a separate program, although this can be inefficient. In cases where the built-in capabilities of GNU make are insufficient to your requirements there are two options for extending make.
134 GNU make character A printable character is converted to the same character. string A string containing only printable characters is converted to the same string. list A list is converted recursively according to the above rules. This implies that any structured list will be flattened (that is, a result of ‘’(a b (c d) e)’ will be converted to the make string ‘a b c d e’). other Any other Guile type results in an error. In future versions of make, other Guile types may be converted.
Chapter 12: Extending GNU make 135 define GUILEIO ;; A simple Guile IO library for GNU make (define MKPORT #f) (define (mkopen name mode) (set! MKPORT (open-file name mode)) #f) (define (mkwrite s) (display s MKPORT) (newline MKPORT) #f) (define (mkclose) (close-port MKPORT) #f) #f endef # Internalize the Guile IO functions $(guile $(GUILEIO)) If you have a significant amount of Guile support code, you might consider keeping it in a different file (e.g., guileio.
136 GNU make Warning: The load directive and extension capability is considered a “technology preview” in this release of GNU make. We encourage you to experiment with this feature and we appreciate any feedback on it. However we cannot guarantee to maintain backward-compatibility in the next release. Consider using GNU Guile instead for extending GNU make (see Section 8.14 [The guile Function], page 97). Many operating systems provide a facility for dynamically loading compiled objects.
Chapter 12: Extending GNU make 137 Regardless of how many times an object file appears in a load directive, it will only be loaded (and its setup function will only be invoked) once. After an object has been successfully loaded, its file name is appended to the .LOADED variable. If you would prefer that failure to load a dynamic object not be reported as an error, you can use the -load directive instead of load. GNU make will not fail and no message will be generated if an object fails to load.
138 GNU make Data Structures gmk_floc This structure represents a filename/location pair. It is provided when defining items, so GNU make can inform the user later where the definition occurred if necessary. Registering Functions There is currently one way for makefiles to invoke operations provided by the loaded object: through the make function call interface.
Chapter 12: Extending GNU make 139 gmk_expand This function takes a string and expands it using make expansion rules. The result of the expansion is returned in a nil-terminated string buffer. The caller is responsible for calling gmk_free with a pointer to the returned buffer when done. gmk_eval This function takes a buffer and evaluates it as a segment of makefile syntax. This function can be used to define new variables, new rules, etc. It is equivalent to using the eval make function.
140 GNU make #include #include #include #include #include #include #include int plugin_is_GPL_compatible; char * gen_tmpfile(const char *nm, int argc, char **argv) { int fd; /* Compute the size of the filename and allocate space for it. int len = strlen (argv[0]) + 6 + 1; char *buf = gmk_alloc (len); */ strcpy (buf, argv[0]); strcat (buf, "XXXXXX"); fd = mkstemp(buf); if (fd >= 0) { /* Don’t leak the file descriptor.
Chapter 12: Extending GNU make 141 all: @echo Temporary file: $(mk-temp tmpfile.) load mk_temp.so mk_temp.so: mk_temp.c $(CC) -shared -fPIC -o $ $< On MS-Windows, due to peculiarities of how shared objects are produced, the compiler needs to scan the import library produced when building make, typically called libgnumake-version.dll.a, where version is the version of the load object API. So the recipe to produce a shared object will look on Windows like this (assuming the API version is 1): mk_temp.
Chapter 13: Features of GNU make 143 13 Features of GNU make Here is a summary of the features of GNU make, for comparison with and credit to other versions of make. We consider the features of make in 4.2 BSD systems as a baseline. If you are concerned with writing portable makefiles, you should not use the features of make listed here, nor the ones in Chapter 14 [Missing], page 147. Many features come from the version of make in System V. • The VPATH variable and its special meaning. See Section 4.
144 GNU make • The automatic variable $^ containing a list of all prerequisites of the current target. We did not invent this, but we have no idea who did. See Section 10.5.3 [Automatic Variables], page 120. The automatic variable $+ is a simple extension of $^. • The “what if” flag (‘-W’ in GNU make) was (as far as we know) invented by Andrew Hume in mk. See Section 9.3 [Instead of Executing Recipes], page 101.
Chapter 13: Features of GNU make 145 • Declare phony targets with the special target .PHONY. Andrew Hume of AT&T Bell Labs implemented a similar feature with a different syntax in his mk program. This seems to be a case of parallel discovery. See Section 4.5 [Phony Targets], page 29. • Manipulate text by calling functions. See Chapter 8 [Functions for Transforming Text], page 83. • Use the ‘-o’ or ‘--old-file’ option to pretend a file’s modification-time is old. See Section 9.
Chapter 14: Incompatibilities and Missing Features 147 14 Incompatibilities and Missing Features The make programs in various other systems support a few features that are not implemented in GNU make. The POSIX.2 standard (IEEE Standard 1003.2-1992) which specifies make does not require any of these features. • A target of the form ‘file((entry))’ stands for a member of archive file file. The member is chosen, not by name, but by being an object file which defines the linker symbol entry.
148 GNU make We feel that it is cleaner for a rule without a recipe to always simply add to the prerequisite list for the target. The above example can be easily rewritten to get the desired behavior in GNU make: .c.a: ; • Some versions of make invoke the shell with the ‘-e’ flag, except under ‘-k’ (see Section 9.6 [Testing the Compilation of a Program], page 104). The ‘-e’ flag tells the shell to exit as soon as any program it runs returns a nonzero status.
Chapter 15: Makefile Conventions 149 15 Makefile Conventions This chapter describes conventions for writing the Makefiles for GNU programs. Using Automake will help you write a Makefile that follows these conventions. For more information on portable Makefiles, see posix and Section “Portable Make” in Autoconf . 15.1 General Conventions for Makefiles Every Makefile should contain this line: SHELL = /bin/sh to avoid trouble on systems where the SHELL variable might be inherited from the environment.
150 GNU make appear in the source directory, they should always appear in the source directory, not in the build directory. So Makefile rules to update them should put the updated files in the source directory. However, if a file does not appear in the distribution, then the Makefile should not put it in the source directory, because building a program in ordinary circumstances should not modify the source directory in any way.
Chapter 15: Makefile Conventions 151 15.3 Variables for Specifying Commands Makefiles should provide variables for overriding certain commands, options, and so on. In particular, you should run most utility programs via variables. Thus, if you use Bison, have a variable named BISON whose default value is set with ‘BISON = bison’, and refer to it with $(BISON) whenever you need to use Bison.
152 GNU make 15.4 DESTDIR: Support for Staged Installs DESTDIR is a variable prepended to each installed target file, like this: $(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo $(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a The DESTDIR variable is specified by the user on the make command line as an absolute file name. For example: make DESTDIR=/tmp/stage install DESTDIR should be supported only in the install* and uninstall* targets, as those are the only targets where it is useful.
Chapter 15: Makefile Conventions prefix 153 A prefix used in constructing the default values of the variables listed below. The default value of prefix should be /usr/local. When building the complete GNU system, the prefix will be empty and /usr will be a symbolic link to /. (If you are using Autoconf, write it as ‘@prefix@’.) Running ‘make install’ with a different value of prefix from the one used to build the program should not recompile the program.
154 GNU make Here are the variables Makefiles should use to specify directories to put these various kinds of files in: ‘datarootdir’ The root of the directory tree for read-only architecture-independent data files. This should normally be /usr/local/share, but write it as $(prefix)/share. (If you are using Autoconf, write it as ‘@datarootdir@’.) ‘datadir’’s default value is based on this variable; so are ‘infodir’, ‘mandir’, and others.
Chapter 15: Makefile Conventions 155 the next reboot. PID files for system daemons are a typical use. In addition, this directory should not be cleaned except perhaps at reboot, while the general /tmp (TMPDIR) may be cleaned arbitrarily. This should normally be /var/run, but write it as $(localstatedir)/run. Having it as a separate variable allows the use of /run if desired, for example. (If you are using Autoconf 2.70 or later, write it as ‘@runstatedir@’.
156 ‘htmldir’ ‘dvidir’ ‘pdfdir’ ‘psdir’ GNU make Directories for installing documentation files in the particular format. They should all be set to $(docdir) by default. (If you are using Autoconf, write them as ‘@htmldir@’, ‘@dvidir@’, etc.) Packages which supply several translations of their documentation should install them in ‘$(htmldir)/’ll, ‘$(pdfdir)/’ll, etc. where ll is a locale abbreviation such as ‘en’ or ‘pt_BR’. ‘libdir’ The directory for object files and libraries of object code.
Chapter 15: Makefile Conventions ‘srcdir’ 157 The directory for the sources being compiled. The value of this variable is normally inserted by the configure shell script. (If you are using Autoconf, use ‘srcdir = @srcdir@’.) For example: # Common prefix for installation directories. # NOTE: This directory must exist when you start the install. prefix = /usr/local datarootdir = $(prefix)/share datadir = $(datarootdir) exec_prefix = $(prefix) # Where to put the executable for the command ‘gcc’.
158 GNU make If possible, write the install target rule so that it does not modify anything in the directory where the program was built, provided ‘make all’ has just been done. This is convenient for building the program under one user name and installing it under another. The commands should create all the directories in which files are to be installed, if they don’t already exist.
Chapter 15: Makefile Conventions 159 When you have many documentation files to install, we recommend that you avoid collisions and clutter by arranging for these targets to install in subdirectories of the appropriate installation directory, such as htmldir.
160 GNU make ‘mostlyclean’ Like ‘clean’, but may refrain from deleting a few files that people normally don’t want to recompile. For example, the ‘mostlyclean’ target for GCC does not delete libgcc.a, because recompiling it is rarely necessary and takes a lot of time. ‘maintainer-clean’ Delete almost everything that can be reconstructed with this Makefile. This typically includes everything deleted by distclean, plus more: C source files produced by Bison, tags tables, Info files, and so on.
Chapter 15: Makefile Conventions 161 generated. These targets should not be dependencies of the all target; the user must manually invoke them. Here’s an example rule for generating DVI files from Texinfo: dvi: foo.dvi foo.dvi: foo.texi chap1.texi chap2.texi $(TEXI2DVI) $(srcdir)/foo.texi You must define the variable TEXI2DVI in the Makefile. It should run the program texi2dvi, which is part of the Texinfo distribution. (texi2dvi uses TEX to do the real work of formatting.
162 GNU make installdirs It’s useful to add a target named ‘installdirs’ to create the directories where files are installed, and their parent directories. There is a script called mkinstalldirs which is convenient for this; you can find it in the Gnulib package. You can use a rule like this: # Make sure all installation directories (e.g. $(bindir)) # actually exist by making them if necessary.
Chapter 15: Makefile Conventions $(PRE_INSTALL) $(POST_INSTALL) $(NORMAL_INSTALL) 163 # Pre-install commands follow. # Post-install commands follow. # Normal commands follow. If you don’t use a category line at the beginning of the install rule, all the commands are classified as normal until the first category line. If you don’t use any category lines, all the commands are classified as normal.
Appendix A: Quick Reference 165 Appendix A Quick Reference This appendix summarizes the directives, text manipulation functions, and special variables which GNU make understands. See Section 4.8 [Special Targets], page 32, Section 10.2 [Catalogue of Built-In Rules], page 112, and Section 9.7 [Summary of Options], page 104, for other summaries.
166 GNU make export variable export variable-assignment unexport variable Tell make whether or not to export a particular variable to child processes. See Section 5.7.2 [Communicating Variables to a Sub-make], page 52. private variable-assignment Do not allow this variable assignment to be inherited by prerequisites. See Section 6.13 [Suppressing Inheritance], page 72. vpath pattern path Specify a search path for files matching a ‘%’ pattern. See Section 4.4.2 [The vpath Directive], page 26.
Appendix A: Quick Reference 167 $(wordlist s,e,text) Returns the list of words in text from s to e. See Section 8.2 [Functions for String Substitution and Analysis], page 84. $(firstword names...) Extract the first word of names. See Section 8.2 [Functions for String Substitution and Analysis], page 84. $(lastword names...) Extract the last word of names. See Section 8.2 [Functions for String Substitution and Analysis], page 84. $(dir names...) Extract the directory part of each file name. See Section 8.
168 GNU make $(error text...) When this function is evaluated, make generates a fatal error with the message text. See Section 8.12 [Functions That Control Make], page 96. $(warning text...) When this function is evaluated, make generates a warning with the message text. See Section 8.12 [Functions That Control Make], page 96. $(shell command) Execute a shell command and return its output. See Section 8.13 [The shell Function], page 97.
Appendix A: Quick Reference 169 $(file op filename,text) Expand the arguments, then open the file filename using mode op and write text to that file. See Section 8.6 [The file Function], page 91. $(value var) Evaluates to the contents of the variable var, with no expansion performed on it. See Section 8.8 [The value Function], page 93. Here is a summary of the automatic variables. See Section 10.5.3 [Automatic Variables], page 120, for full information. $@ The file name of the target.
170 GNU make MAKEFILES Makefiles to be read on every invocation of make. See Section 3.4 [The Variable MAKEFILES], page 14. VPATH Directory search path for files not found in the current directory. See Section 4.4.1 [VPATH Search Path for All Prerequisites], page 25. SHELL The name of the system default command interpreter, usually /bin/sh. You can set SHELL in the makefile to change the shell used to run recipes. See Section 5.3 [Recipe Execution], page 44.
Appendix A: Quick Reference 171 MAKECMDGOALS The targets given to make on the command line. Setting this variable has no effect on the operation of make. See Section 9.2 [Arguments to Specify the Goals], page 99. CURDIR Set to the pathname of the current working directory (after all -C options are processed, if any). Setting this variable has no effect on the operation of make. See Section 5.7 [Recursive Use of make], page 50. SUFFIXES The default list of suffixes before make reads any makefiles. .
Appendix B: Errors Generated by Make 173 Appendix B Errors Generated by Make Here is a list of the more common errors you might see generated by make, and some information about what they mean and how to fix them. Sometimes make errors are not fatal, especially in the presence of a - prefix on a recipe line, or the -k command line option. Errors that are fatal are prefixed with the string ***.
174 GNU make ‘No rule to make target ‘xxx’.’ ‘No rule to make target ‘xxx’, needed by ‘yyy’.’ This means that make decided it needed to build a target, but then couldn’t find any instructions in the makefile on how to do that, either explicit or implicit (including in the default rules database). If you want that file to be built, you will need to add a rule to your makefile describing how that target can be built.
Appendix B: Errors Generated by Make 175 ‘missing target pattern. Stop.’ ‘multiple target patterns. Stop.’ ‘target pattern contains no ‘%’. Stop.’ ‘mixed implicit and static pattern rules. Stop.’ These are generated for malformed static pattern rules.
Appendix C: Complex Makefile Example 177 Appendix C Complex Makefile Example Here is the makefile for the GNU tar program. This is a moderately complex makefile. The first line uses a #! setting to allow the makefile to be executed directly. Because it is the first target, the default goal is ‘all’. An interesting feature of this makefile is that testpad.h is a source file automatically created by the testpad program, itself compiled from testpad.c.
178 GNU make # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # Things you might add to DEFS: -DSTDC_HEADERS If you have ANSI C headers and libraries. -DPOSIX If you have POSIX.1 headers and libraries. -DBSD42 If you have sys/dir.h (unless you use -DPOSIX), sys/file.h, and st_blocks in ‘struct stat’. -DUSG If you have System V/ANSI C string and memory functions and headers, sys/sysmacros.h, fcntl.h, getcwd, no valloc, and ndir.h (unless you use -DDIRENT).
Appendix C: Complex Makefile Example # # # -DXENIX # and want to disable the tar -k option instead of emulating open. If you have sys/inode.h and need it 94 to be included. DEFS = -DSIGTYPE=int -DDIRENT -DSTRSTR_MISSING \ -DVPRINTF_MISSING -DBSD42 # Set this to rtapelib.o unless you defined NO_REMOTE, # in which case make it empty. RTAPELIB = rtapelib.o LIBS = DEF_AR_FILE = /dev/rmt8 DEFBLOCKING = 20 CDEBUG = -g CFLAGS = $(CDEBUG) -I.
180 GNU make AUX = README COPYING ChangeLog Makefile.in \ makefile.pc configure configure.in \ tar.texinfo tar.info* texinfo.tex \ tar.h port.h open3.h getopt.h regex.h \ rmt.h rmt.c rtapelib.c alloca.c \ msd_dir.h msd_dir.c tcexparg.c \ level-0 level-1 backup-specs testpad.c .PHONY: all all: tar rmt tar.info tar: $(OBJS) $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) rmt: rmt.c $(CC) $(CFLAGS) $(LDFLAGS) -o $@ rmt.c tar.info: tar.texinfo makeinfo tar.texinfo .
Appendix C: Complex Makefile Example 181 .PHONY: realclean realclean: distclean rm -f tar.info* .PHONY: shar shar: $(SRCS) $(AUX) shar $(SRCS) $(AUX) | compress \ > tar-‘sed -e ’/version_string/!d’ \ -e ’s/[^0-9.]*\([0-9.]*\).*/\1/’ \ -e q version.c‘.shar.Z .PHONY: dist dist: $(SRCS) $(AUX) echo tar-‘sed \ -e ’/version_string/!d’ \ -e ’s/[^0-9.]*\([0-9.]*\).*/\1/’ \ -e q version.c‘ > .fname -rm -rf ‘cat .fname‘ mkdir ‘cat .fname‘ ln $(SRCS) $(AUX) ‘cat .fname‘ tar chZf ‘cat .fname‘.tar.Z ‘cat .
182 GNU make to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of “copyleft”, which means that derivative works of the document must themselves be free in the same sense.
Appendix C: Complex Makefile Example 183 editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not “Transparent” is called “Opaque”.
184 GNU make If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document’s license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies.
Appendix C: Complex Makefile Example 185 F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document’s license notice. H. Include an unaltered copy of this License. I.
186 GNU make you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. 5.
Appendix C: Complex Makefile Example 187 8. TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections.
188 GNU make versions of this License can be used, that proxy’s public statement of acceptance of a version permanently authorizes you to choose that version for the Document. 11. RELICENSING “Massive Multiauthor Collaboration Site” (or “MMC Site”) means any World Wide Web server that publishes copyrightable works and also provides prominent facilities for anybody to edit those works. A public wiki that anybody can edit is an example of such a server.
Appendix C: Complex Makefile Example 189 ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (C) year your name. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.
Index of Concepts 191 Index of Concepts ! != . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 !=, expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 # # (comments), in makefile . . . . . . . . . . . . . . . . . . . . . . 11 # (comments), in recipes . . . . . . . . . . . . . . . . . . . . . . . 41 #include . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 $ $, $, $, $, in in in in function call . . .
192 -I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13, 106 -j . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47, 106 -j, and archive update . . . . . . . . . . . . . . . . . . . . . . . 130 -j, and recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 -k . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50, 104, 106 -l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index of Concepts archive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 archive member targets . . . . . . . . . . . . . . . . . . . . . . . 129 archive symbol directory updating . . . . . . . . . . . . 130 archive, and -j . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 archive, and parallel execution . . . . . . . . . . . . . . . . 130 archive, suffix rule for . . . . . . . . . . . . . . . . . . . . . . . . 130 Arg list too long . . . . . . . . . . . .
194 GNU make execution, of recipes . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 exit status (errors). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 exit status of make . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 expansion, secondary . . . . . . . . . . . . . . . . . . . . . . . . . . 18 explicit rule, definition of . . . . . . . . . . . . . . . . . . . . . . 11 explicit rule, expansion . . . . . . . . . . . . . . . . . . . . . . . .
Index of Concepts L last-resort default rules . . . . . . . . . . . . . . . . . . . . . . . 125 ld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 lex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114, 116 Lex, rule to run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 libraries for linking, directory search . . . . . . . . . . . 28 library archive, suffix rule for . . . . . . . . . . . . . . . . .
196 portability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 POSIX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1, 54 POSIX-conforming mode, setting . . . . . . . . . . . . . . 34 post-installation commands . . . . . . . . . . . . . . . . . . . 162 pre-installation commands . . . . . . . . . . . . . . . . . . . . 162 precious targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 predefined rules and variables, printing . . . . .
Index of Concepts rule, implicit, definition of . . . . . . . . . . . . . . . . . . . . . 11 rule, implicit, how to use . . . . . . . . . . . . . . . . . . . . . 111 rule, implicit, introduction to . . . . . . . . . . . . . . . . . . . 7 rule, implicit, predefined . . . . . . . . . . . . . . . . . . . . . . 112 rule, introduction to . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 rule, multiple for one target . . . . . . . . . . . . . . . . . . . . 35 rule, no recipe or prerequisites . . . . . .
198 targets, phony . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 terminal rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 test (standard target). . . . . . . . . . . . . . . . . . . . . . . . 101 testing compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114, 116 TEX, rule to run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 texi2dvi . . . .
Index of Functions, Variables, & Directives 199 Index of Functions, Variables, & Directives $ $% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 $(%D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 $(%F) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 $(*D) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 $(*F) . . . . . . . . . . . . . . . . . . . . . . .
200 | | (automatic variable) . . . . . . . . . . . . . . . . . . . . . . . . 121 GNU make findstring. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . firstword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . flavor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . foreach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 86 95 90 A abspath . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Index of Functions, Variables, & Directives 201 MAKECMDGOALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Makefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 MAKEFILE_LIST (list of parsed makefiles) . . . . . . . 73 MAKEFILES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14, 53 MAKEFLAGS . . . . . . . . . . . . . . . . . . . . . . . . . . .