Lines Matching refs:code

9 @settitle GNU @code{make}
21 This file documents the GNU @code{make} utility, which determines
26 of @cite{The GNU Make Manual}, for GNU @code{make} version @value{VERSION}.
64 @subtitle GNU @code{make} Version @value{VERSION}
84 @top GNU @code{make}
90 * Overview:: Overview of @code{make}.
91 * Introduction:: An introduction to @code{make}.
92 * Makefiles:: Makefiles tell @code{make} what to do.
99 * Invoking make: Running. How to invoke @code{make} on the command line.
102 * Archives:: How @code{make} can update library archives.
103 * Features:: Features GNU @code{make} has over other @code{make}s.
104 * Missing:: What GNU @code{make} lacks from other @code{make}s.
108 * Error Messages:: A list of common errors generated by @code{make}.
119 Overview of @code{make}
129 * How Make Works:: How @code{make} Processes This Makefile
131 * make Deduces:: Letting @code{make} Deduce the Commands
205 * Recursion:: Invoking @code{make} from makefiles.
212 * Variables in Commands:: Using @code{make} variables in commands.
216 * Choosing the Shell:: How @code{make} chooses the shell used
219 Recursive Use of @code{make}
222 * Variables/Recursion:: How to communicate variables to a sub-@code{make}.
223 * Options/Recursion:: How to communicate options to a sub-@code{make}.
225 helps debug use of recursive @code{make} commands.
273 How to Run @code{make}
315 Using @code{make} to Update Archive Files
332 @chapter Overview of @code{make}
334 The @code{make} utility automatically determines which pieces of a large
336 This manual describes GNU @code{make}, which was implemented by Richard
340 GNU @code{make} conforms to section 6.2 of @cite{IEEE Standard
347 @code{make} with any programming language whose compiler can be run with a
348 shell command. Indeed, @code{make} is not limited to programs. You can
363 To prepare to use @code{make}, you must write a file called
377 suffices to perform all necessary recompilations. The @code{make} program
382 You can provide command line arguments to @code{make} to control which
384 @code{make}}.
389 If you are new to @code{make}, or are looking for a general
403 If you are familiar with other @code{make} programs, see @ref{Features,
404 ,Features of GNU @code{make}}, which lists the enhancements GNU
405 @code{make} has, and @ref{Missing, ,Incompatibilities and Missing
406 Features}, which explains the few things GNU @code{make} lacks that
418 If you have problems with GNU @code{make} or think you've found a bug,
430 send us the makefile and the exact results @code{make} gave you,
455 version number of @code{make} you are using. You can get this
465 You need a file called a @dfn{makefile} to tell @code{make} what to do.
466 Most often, the makefile tells @code{make} how to compile and link a
472 and three header files. The makefile can also tell @code{make} how to
477 When @code{make} recompiles the editor, each changed C source file
490 * How Make Works:: How @code{make} Processes This Makefile
492 * make Deduces:: Letting @code{make} Deduce the Commands
527 A @dfn{command} is an action that @code{make} carries out.
539 which are the targets of the particular rule. @code{make} carries out
554 executable file called @code{edit} depends on eight object files
594 @cindex @code{\} (backslash), for continuation lines
595 @cindex backslash (@code{\}), for continuation lines
630 mind that @code{make} does not know anything about how the commands
632 file properly. All @code{make} does is execute the commands in the rule
640 Consequently, @code{make} never does anything with it unless you tell
646 Errors in Commands}, to see how to cause @code{make} to ignore errors
647 from @code{rm} or any other command.
648 @cindex @code{clean} target
649 @cindex @code{rm} (shell command)
653 @section How @code{make} Processes a Makefile
655 @cindex makefile, how @code{make} processes
657 By default, @code{make} starts with the first target (not targets whose
659 (@dfn{Goals} are the targets that @code{make} strives ultimately to
662 @code{.DEFAULT_GOAL} special variable (@pxref{Special Variables, ,
679 @code{make} reads the makefile in the current directory and begins by
681 @file{edit}; but before @code{make} can fully process this rule, it
693 unless you tell @code{make} to do so (with a command such as
694 @w{@code{make clean}}).
696 Before recompiling an object file, @code{make} considers updating its
699 are not the targets of any rules---so @code{make} does nothing for these
700 files. But @code{make} would update automatically generated C programs,
703 After recompiling whichever object files need it, @code{make} decides
710 Thus, if we change the file @file{insert.c} and run @code{make},
711 @code{make} will compile that file to update @file{insert.o}, and then
713 @code{make}, @code{make} will recompile the object files @file{kbd.o},
733 @cindex @code{objects}
740 @cindex @code{OBJECTS}
741 @cindex @code{objs}
742 @cindex @code{OBJS}
743 @cindex @code{obj}
744 @cindex @code{OBJ}
746 @code{objects}, @code{OBJECTS}, @code{objs}, @code{OBJS}, @code{obj},
747 or @code{OBJ} which is a list of all object file names. We would
748 define such a variable @code{objects} with a line like this in the
795 @section Letting @code{make} Deduce the Commands
801 C source files, because @code{make} can figure them out: it has an
813 @code{objects} as suggested above:
888 @cindex @code{clean} target
890 could write a @code{make} rule for cleaning our example editor:
911 This prevents @code{make} from getting confused by an actual file
913 @code{rm}. (See @ref{Phony Targets}, and @ref{Errors, ,Errors in
919 example makefile, we want the rule for @code{edit}, which recompiles
922 Since @code{clean} is not a prerequisite of @code{edit}, this rule will not
925 @xref{Running, ,How to Run @code{make}}.
931 The information that tells @code{make} how to recompile a system comes from
978 simple makefile example shows a variable definition for @code{objects}
984 A @dfn{directive} is a command for @code{make} to do something special while
1001 @cindex @code{#} (comments), in makefile
1008 @code{#}, escape it with a backslash (e.g., @code{\#}). Comments may
1017 Within a @code{define} directive, comments are not ignored during the
1020 as @code{make} comments or as command script text, depending on the
1032 By default, when @code{make} looks for the makefile, it tries the
1039 @cindex @code{README}
1046 @code{make}, and will not be understood by other versions of
1047 @code{make}. Other @code{make} programs look for @file{makefile} and
1050 If @code{make} finds none of these names, it does not use any makefile.
1051 Then you must specify a goal with a command argument, and @code{make}
1055 @cindex @code{-f}
1056 @cindex @code{--file}
1057 @cindex @code{--makefile}
1061 @code{make} to read the file @var{name} as the makefile. If you use
1078 The @code{include} directive tells @code{make} to suspend reading the
1089 @cindex shell file name pattern (in @code{include})
1090 @cindex shell wildcards (in @code{include})
1091 @cindex wildcard, in @code{include}
1096 @code{include} and the file names, and between file names; extra
1103 @file{b.mk}, and @file{c.mk}, and @code{$(bar)} expands to
1104 @code{bish bash}, then the following expression
1116 When @code{make} processes an @code{include} directive, it suspends
1118 turn. When that is finished, @code{make} resumes reading the
1121 One occasion for using @code{include} directives is when several programs,
1132 @code{make}. @xref{Automatic Prerequisites}.
1137 @cindex @code{-I}
1138 @cindex @code{--include-dir}
1160 processing of the makefile containing the @code{include} continues.
1161 Once it has finished reading makefiles, @code{make} will try to remake
1165 will @code{make} diagnose the missing makefile as a fatal error.
1167 If you want @code{make} to simply ignore a makefile which does not exist
1168 and cannot be remade, with no error message, use the @w{@code{-include}}
1169 directive instead of @code{include}, like this:
1175 This acts like @code{include} in every way except that there is no
1177 For compatibility with some other @code{make} implementations,
1178 @code{sinclude} is another name for @w{@code{-include}}.
1181 @section The Variable @code{MAKEFILES}
1182 @cindex makefile, and @code{MAKEFILES} variable
1183 @cindex including (@code{MAKEFILES} variable)
1186 If the environment variable @code{MAKEFILES} is defined, @code{make}
1189 the @code{include} directive: various directories are searched for those
1192 error if the files listed in @code{MAKEFILES} are not found.@refill
1194 @cindex recursion, and @code{MAKEFILES} variable
1195 The main use of @code{MAKEFILES} is in communication between recursive
1196 invocations of @code{make} (@pxref{Recursion, ,Recursive Use of
1197 @code{make}}). It usually is not desirable to set the environment
1198 variable before a top-level invocation of @code{make}, because it is
1200 you are running @code{make} without a specific makefile, a makefile in
1201 @code{MAKEFILES} can do useful things to help the built-in implicit
1204 Some users are tempted to set @code{MAKEFILES} in the environment
1207 anyone else. It is much better to write explicit @code{include} directives
1212 @section The Variable @code{MAKEFILE_LIST}
1213 @cindex makefiles, and @code{MAKEFILE_LIST} variable
1214 @cindex including (@code{MAKEFILE_LIST} variable)
1217 As @code{make} reads various makefiles, including any obtained from the
1218 @code{MAKEFILES} variable, the command line, the default files, or
1219 from @code{include} directives, their names will be automatically
1220 appended to the @code{MAKEFILE_LIST} variable. They are added right
1221 before @code{make} begins to parse them.
1225 Once the current makefile has used @code{include}, however, the last
1228 If a makefile named @code{Makefile} has this content:
1254 @xref{Text Functions}, for more information on the @code{word} and
1255 @code{words} functions used above. @xref{Flavors, The Two Flavors of
1256 Variables}, for more information on simply-expanded (@code{:=})
1265 GNU @code{make} also supports other special variables. Unless
1269 @table @code
1275 @code{.DEFAULT_GOAL} variable allows you to discover the current
1316 Note that assigning more than one target name to @code{.DEFAULT_GOAL} is
1319 @vindex MAKE_RESTARTS @r{(number of times @code{make} has restarted)}
1321 This variable is set only if this instance of @code{make} has
1324 this is not the same as recursion (counted by the @code{MAKELEVEL}
1339 @c The second special variable is @code{.TARGETS}. When expanded, the
1350 @code{make}. Possible values include:
1355 Supports @code{ar} (archive) files using special filename syntax.
1356 @xref{Archives, ,Using @code{make} to Update Archive Files}.
1359 Supports the @code{-L} (@code{--check-symlink-times}) flag.
1385 Expands to a list of directories that @code{make} searches for
1398 @code{make} to get an up-to-date version of the makefile to read in.
1400 To this end, after reading in all makefiles, @code{make} will consider
1406 @code{make} starts with a clean slate and reads all the makefiles over
1412 want to keep @code{make} from performing an implicit rule search on
1422 time @code{make} is run, and then again after @code{make} starts over
1424 @code{make} would constantly remake the makefile, and never do anything
1425 else. So, to avoid this, @code{make} will @strong{not} attempt to
1430 @samp{--file} options, @code{make} will try the default makefile names;
1433 @code{make} is not certain that these makefiles should exist. However,
1435 @code{make} rules, you probably want the rules to be run so that the
1438 Therefore, if none of the default makefiles exists, @code{make} will try
1442 that it is not an error if @code{make} cannot find or make any makefile;
1479 target, @code{make} will not let you just do this. But there is another way.
1485 makefile, @code{make} should look in another makefile.
1501 If you say @samp{make foo}, @code{make} will find @file{GNUmakefile},
1503 @samp{frobnicate > foo}. If you say @samp{make bar}, @code{make} will
1506 @file{Makefile} provides a rule for updating @file{bar}, @code{make}
1514 commands to prevent @code{make} from searching for an implicit rule to
1519 @section How @code{make} Reads a Makefile
1523 GNU @code{make} does its work in two distinct phases. During the first
1527 prerequisites. During the second phase, @code{make} uses these internal
1537 @code{make} will expand any variables or functions in that section of a
1578 entirety; this includes the @code{ifdef}, @code{ifeq}, @code{ifndef},
1579 and @code{ifneq} forms. Of course this means that automatic variables
1584 tests, not @code{make} conditionals.
1611 In the previous section we learned that GNU @code{make} works in two
1613 (@pxref{Reading Makefiles, , How @code{make} Reads a Makefile}). GNU
1617 @code{.SECONDEXPANSION} must be defined before the first prerequisite
1641 @file{myfile} target will be @code{onefile} and @code{$(TWOVAR)}; the
1673 target. This means that you can use variables such as @code{$@@},
1674 @code{$*}, etc. during the second expansion and they will have their
1676 defer the expansion by escaping the @code{$}. Also, secondary
1690 @file{main} and @file{lib} targets will be @code{$($@@_OBJS)}. During
1691 the secondary expansion, the @code{$@@} variable is set to the name of
1693 @code{$(main_OBJS)}, or @code{main.o try.o test.o}, while the
1695 @code{$(lib_OBJS)}, or @code{lib.o api.o}.
1712 phase, especially of the target name variable @code{$$@@}, behaves
1715 the different types of rule definitions that @code{make} understands.
1723 During the secondary expansion of explicit rules, @code{$$@@} and
1724 @code{$$%} evaluate, respectively, to the file name of the target and,
1726 @code{$$<} variable evaluates to the first prerequisite in the first
1727 rule for this target. @code{$$^} and @code{$$+} evaluate to the list
1729 the same target (@code{$$+} with repetitions and @code{$$^}
1742 In the first prerequisite list, all three variables (@code{$$<},
1743 @code{$$^}, and @code{$$+}) expand to the empty string. In the
1744 second, they will have values @code{foo.1}, @code{foo.1 bar.1}, and
1745 @code{foo.1 bar.1} respectively. In the third they will have values
1746 @code{foo.1}, @code{foo.1 bar.1 foo.2 bar.2}, and @code{foo.1 bar.1
1752 The variables @code{$$?} and @code{$$*} are not available and expand
1761 pattern rules the @code{$$*} variable is set to the pattern stem. As
1762 with explicit rules, @code{$$?} is not available and expands to the
1769 As @code{make} searches for an implicit rule, it substitutes the stem
1784 When the implicit rule is tried for target @file{foo}, @code{$$<}
1785 expands to @file{bar}, @code{$$^} expands to @file{bar boo},
1786 @code{$$+} also expands to @file{bar boo}, and @code{$$*} expands to
1805 @code{$$*} instead of @code{%} in the prerequisites list.
1822 @dfn{default goal}: the target for @code{make} to consider, if you do
1884 How to update the file @file{foo.o}: by running @code{cc} as stated.
1932 @cindex dollar sign (@code{$}), in rules
1933 @cindex @code{$}, in rules
1934 @cindex rules, and @code{$}
1935 Because dollar signs are used to start @code{make} variable
1944 newline, but this is not required, as @code{make} places no limit on
1947 A rule tells @code{make} two things: when the targets are out of date,
1977 GNU @code{make}: normal prerequisites such as described in the
1993 prerequisites can be specified by placing a pipe symbol (@code{|})
2014 @cindex @code{*} (wildcard character)
2015 @cindex @code{?} (wildcard character)
2016 @cindex @code{[@dots{}]} (wildcard characters)
2018 The wildcard characters in @code{make} are @samp{*}, @samp{?} and
2023 @cindex @code{~} (tilde)
2024 @cindex tilde (@code{~})
2036 Wildcard expansion is performed by @code{make} automatically in
2039 only if you request it explicitly with the @code{wildcard} function.
2065 @cindex @code{rm} (shell command)
2077 @cindex @code{print} target
2078 @cindex @code{lpr} (shell command)
2079 @cindex @code{touch} (shell command)
2094 then the value of the variable @code{objects} is the actual string
2095 @samp{*.o}. However, if you use the value of @code{objects} in a target,
2097 To set @code{objects} to the expansion, instead use:
2127 The value of @code{objects} is the actual string @samp{*.o}. Wildcard
2135 @code{make} will give you an error saying it cannot figure out how to
2140 @code{wildcard} function and string substitution.
2142 @xref{Wildcard Function, ,The Function @code{wildcard}}.
2159 @file{c:} part is the so-called drive letter). When @code{make} runs on
2167 @subsection The Function @code{wildcard}
2173 places, you need to use the @code{wildcard} function, like this:
2183 then that pattern is omitted from the output of the @code{wildcard}
2188 One use of the @code{wildcard} function is to get a list of all the C source
2203 (Here we have used another function, @code{patsubst}.
2227 @cindex search path for prerequisites (@code{VPATH})
2228 @cindex directory search (@code{VPATH})
2232 @code{make} facilitate this by searching several directories
2250 @subsection @code{VPATH}: Search Path for All Prerequisites
2253 The value of the @code{make} variable @code{VPATH} specifies a list of
2254 directories that @code{make} should search. Most often, the
2256 current directory; however, @code{make} uses @code{VPATH} as a search
2260 in the current directory, @code{make} searches the directories listed in
2261 @code{VPATH} for a file with that name. If a file is found in one of
2267 In the @code{VPATH} variable, directory names are separated by colons or
2269 by @code{make} in its search. (On MS-DOS and MS-Windows, semi-colons
2270 are used as separators of directory names in @code{VPATH}, since the
2281 @file{../headers}, which @code{make} searches in that order.
2283 With this value of @code{VPATH}, the following rule,
2301 @subsection The @code{vpath} Directive
2304 Similar to the @code{VPATH} variable, but more selective, is the
2305 @code{vpath} directive (note lower case), which allows you to specify a
2311 There are three forms of the @code{vpath} directive:
2313 @table @code
2320 blanks, just like the search path used in the @code{VPATH} variable.
2328 Clear all search paths previously specified with @code{vpath} directives.
2331 A @code{vpath} pattern is a string containing a @samp{%} character. The
2335 Redefining Pattern Rules}). For example, @code{%.h} matches files that
2336 end in @code{.h}. (If there is no @samp{%}, the pattern must match the
2339 @cindex @code{%}, quoting in @code{vpath}
2340 @cindex @code{%}, quoting with @code{\} (backslash)
2341 @cindex @code{\} (backslash), to quote @code{%}
2342 @cindex backslash (@code{\}), to quote @code{%}
2343 @cindex quoting @code{%}, in @code{vpath}
2344 @samp{%} characters in a @code{vpath} directive's pattern can be quoted
2352 @var{pattern} in a @code{vpath} directive matches the name of the
2354 just like (and before) the directories in the @code{VPATH} variable.
2363 tells @code{make} to look for any prerequisite whose name ends in @file{.h}
2367 If several @code{vpath} patterns match the prerequisite file's name, then
2368 @code{make} processes each matching @code{vpath} directive one by one,
2369 searching all the directories mentioned in each directive. @code{make}
2370 handles multiple @code{vpath} directives in the order in which they
2407 @code{make} actually provides you in the prerequisite list. Sometimes
2410 The algorithm @code{make} uses to decide whether to keep or abandon a
2433 contain this target. In short, if @code{make} doesn't need to rebuild
2440 short, if @code{make} must rebuild, then the target is rebuilt locally,
2450 Other versions of @code{make} use a simpler algorithm: if the file does
2458 directories, you can use the @code{GPATH} variable to indicate this to
2459 @code{make}.
2461 @code{GPATH} has the same syntax and format as @code{VPATH} (that is, a
2464 @code{GPATH}, then that pathname is not thrown away. The target is
2470 @cindex directory search (@code{VPATH}), and shell commands
2475 the prerequisite in the directory where @code{make} finds it.
2490 (The variable @code{CFLAGS} exists so you can specify flags for C
2507 @cindex @code{VPATH}, and implicit rules
2508 @cindex directory search (@code{VPATH}), and implicit rules
2509 @cindex search path for prerequisites (@code{VPATH}), and implicit rules
2511 @cindex implicit rule, and @code{VPATH}
2513 @cindex rule, implicit, and @code{VPATH}
2515 The search through the directories specified in @code{VPATH} or with
2516 @code{vpath} also happens during consideration of implicit rules
2519 For example, when a file @file{foo.o} has no explicit rule, @code{make}
2534 @cindex directory search (@code{VPATH}), and link libraries
2535 @cindex @code{VPATH}, and link libraries
2536 @cindex search path for prerequisites (@code{VPATH}), and link libraries
2537 @cindex @code{-l} (library search)
2539 @cindex @code{.LIBPATTERNS}, and link libraries
2549 When a prerequisite's name has the form @samp{-l@var{name}}, @code{make}
2551 the current directory, in directories specified by matching @code{vpath}
2552 search paths and the @code{VPATH} search path, and then in the
2555 @code{make} behave as if @var{prefix} is defined to be the root of the
2578 via the @code{.LIBPATTERNS} variable. Each word in the value of this
2580 @samp{-l@var{name}} is seen, @code{make} will replace the percent in
2585 The default value for @code{.LIBPATTERNS} is @samp{lib%.so lib%.a},
2614 Because the @code{rm} command does not create a file named @file{clean},
2615 probably no such file will ever exist. Therefore, the @code{rm} command
2617 @cindex @code{rm} (shell command)
2624 declare the target to be phony, using the special target @code{.PHONY}
2636 remade from other files, @code{make} skips the implicit rule search for
2641 Thus, you first write the line that states that @code{clean} is a
2653 with recursive invocations of @code{make} (for more information, see
2654 @ref{Recursion, ,Recursive Use of @code{make}}). In this case the
2674 it will do so even if @code{make} is invoked with the @code{-k} option,
2676 take advantage of @code{make}'s ability to build targets in parallel
2704 is, its commands are run every time @code{make} goes to update that
2758 @cindex @code{FORCE}
2762 is a nonexistent file, then @code{make} imagines this target to have
2785 other versions of @code{make} do not support @samp{.PHONY}; thus
2801 does so because one of the commands is a @code{touch} command to update the
2815 @cindex @code{print} target
2816 @cindex @code{lpr} (shell command)
2817 @cindex @code{touch} (shell command)
2820 With this rule, @samp{make print} will execute the @code{lpr} command if
2833 @table @code
2837 The prerequisites of the special target @code{.PHONY} are considered to
2839 @code{make} will run its commands unconditionally, regardless of
2846 The prerequisites of the special target @code{.SUFFIXES} are the list
2853 The commands specified for @code{.DEFAULT} are used for any target for
2855 @xref{Last Resort}. If @code{.DEFAULT} commands are specified, every
2863 @cindex preserving with @code{.PRECIOUS}
2865 The targets which @code{.PRECIOUS} depends on are given the following
2866 special treatment: if @code{make} is killed or interrupted during the
2868 @xref{Interrupts, ,Interrupting or Killing @code{make}}. Also, if the
2872 @code{.SECONDARY} special target.
2875 @samp{%.o}) as a prerequisite file of the special target @code{.PRECIOUS}
2883 The targets which @code{.INTERMEDIATE} depends on are treated as
2885 @code{.INTERMEDIATE} with no prerequisites has no effect.
2890 @cindex preserving with @code{.SECONDARY}
2892 The targets which @code{.SECONDARY} depends on are treated as
2896 @code{.SECONDARY} with no prerequisites causes all targets to be treated
2903 If @code{.SECONDEXPANSION} is mentioned as a target anywhere in the
2908 The prerequisites of the special target @code{.SUFFIXES} are the list
2916 If @code{.DELETE_ON_ERROR} is mentioned as a target anywhere in the
2917 makefile, then @code{make} will delete the target of a rule if it has
2924 If you specify prerequisites for @code{.IGNORE}, then @code{make} will
2926 files. The commands for @code{.IGNORE} are not meaningful.
2928 If mentioned as a target with no prerequisites, @code{.IGNORE} says to
2938 If you specify prerequisites for @code{.LOW_RESOLUTION_TIME},
2941 @code{.LOW_RESOLUTION_TIME} are not meaningful.
2949 prerequisite of @code{.LOW_RESOLUTION_TIME} so that @command{make} does
2962 it is up to date. The @code{.LOW_RESOLUTION_TIME} line causes
2968 prerequisites of @code{.LOW_RESOLUTION_TIME}, as @command{make} does this
2974 If you specify prerequisites for @code{.SILENT}, then @code{make} will
2976 them. The commands for @code{.SILENT} are not meaningful.
2978 If mentioned as a target with no prerequisites, @code{.SILENT} says not
2983 for a particular run of @code{make}, use the @samp{-s} or
2989 Simply by being mentioned as a target, this tells @code{make} to
2992 Sub-@code{make}}.
2998 If @code{.NOTPARALLEL} is mentioned as a target, then this invocation of
2999 @code{make} will be run serially, even if the @samp{-j} option is
3000 given. Any recursively invoked @code{make} command will still be run in
3066 Here we assume the hypothetical program @code{generate} makes two
3070 for an explanation of the @code{subst} function.
3092 more than one rule gives commands for the same file, @code{make} uses
3096 of @code{make}... you should avoid using it). Occasionally it is
3103 have a variable, such as @code{objects}, containing a list of all the
3120 a variable that you set with a command argument to @code{make}
3135 If none of the explicit rules for a target has commands, then @code{make}
3200 @cindex @code{%}, quoting in static pattern
3201 @cindex @code{%}, quoting with @code{\} (backslash)
3202 @cindex @code{\} (backslash), to quote @code{%}
3203 @cindex backslash (@code{\}), to quote @code{%}
3204 @cindex quoting @code{%}, in static pattern
3237 which will match the pattern, you can use the @code{filter} function to
3256 Another example shows how to use @code{$*} in static pattern rules:
3267 When the @code{generate} command is run, @code{$*} will expand to the
3278 names of prerequisites. The difference is in how @code{make} decides
3304 might lead @code{make} to use the wrong implicit rule. The choice
3313 @cindex rule, double-colon (@code{::})
3314 @cindex multiple rules for one target (@code{::})
3315 @cindex @code{::} rules (double-colon)
3355 @code{#include}, you would write:
3362 You need this rule so that @code{make} knows that it must remake
3366 every time you add or remove an @code{#include}.
3367 @cindex @code{#include}
3369 @cindex @code{-M} (to compiler)
3371 you, by looking at the @code{#include} lines in the source files.
3392 rule search. This means that @code{make} won't ever remove the file
3395 @cindex @code{make depend}
3396 With old @code{make} programs, it was traditional practice to use this
3400 makefile could use @code{include} to read them in (@pxref{Include}).
3402 In GNU @code{make}, the feature of remaking makefiles makes this
3403 practice obsolete---you need never tell @code{make} explicitly to
3430 @code{$(CC)} command (or any other command) fails (exits with a
3432 @cindex @code{-e} (shell flag)
3434 @cindex @code{-MM} (to GNU compiler)
3440 @cindex @code{sed} (shell command)
3441 The purpose of the @code{sed} command is to translate (for example):
3455 @cindex @code{.d}
3457 that the corresponding @samp{.o} file depends on. @code{make} then
3462 you then use the @code{include} directive to read them all in.
3478 makefiles like any others, @code{make} will remake them as necessary
3482 be sure to place the @code{include} directive @emph{after} the first,
3509 * Recursion:: Invoking @code{make} from makefiles.
3520 syntaxes in one file. Most of the makefile uses @code{make} syntax
3523 The @code{make} program does not try to understand shell syntax: it
3544 @cindex @code{#} (comments), in commands
3546 A comment in a command line is not a @code{make} comment; it will be
3553 not a @code{make} variable definition, and passed to the shell.
3556 A conditional expression (@code{ifdef}, @code{ifeq},
3565 * Variables in Commands:: Using @code{make} variables in commands.
3572 @cindex commands, backslash (@code{\}) in
3574 @cindex backslash (@code{\}), in commands
3575 @cindex @code{\} (backslash), in commands
3579 One of the few ways in which @code{make} does interpret command lines
3656 with double quotes (@code{"..."}), but not from the string quoted with single
3657 quotes (@code{'...'}). This is the way the default shell (@file{/bin/sh})
3667 @code{make} variable then use the variable in the command. In this
3700 The other way in which @code{make} processes commands is by expanding
3712 a @code{make} variable (use a single dollar sign) or a shell variable
3751 @cindex @code{@@} (in commands)
3755 Normally @code{make} prints each command line before it is executed.
3762 something, such as an @code{echo} command to indicate progress through
3769 @cindex @code{-n}
3770 @cindex @code{--just-print}
3771 @cindex @code{--dry-run}
3772 @cindex @code{--recon}
3773 When @code{make} is given the flag @samp{-n} or @samp{--just-print}
3777 finding out which commands @code{make} thinks are necessary without
3780 @cindex @code{-s}
3781 @cindex @code{--silent}
3782 @cindex @code{--quiet}
3785 flag to @code{make} prevents all echoing, as if all commands
3787 @code{.SILENT} without prerequisites has the same effect
3789 @code{.SILENT} is essentially obsolete since @samp{@@} is more flexible.@refill
3796 @vindex @code{SHELL} @r{(command execution)}
3800 practice, @code{make} may take shortcuts that do not affect the
3803 @cindex @code{cd} (shell command)
3807 invoking shell commands such as @code{cd} that set a context local to
3811 systems.} If you want to use @code{cd} to affect the next statement,
3812 put both statements in a single command line. Then @code{make} will
3822 Here we use the shell AND operator (@code{&&}) so that if the
3823 @code{cd} command fails, the script will fail without trying to invoke
3824 the @code{gobble} command in the wrong directory, which could cause
3829 * Choosing the Shell:: How @code{make} chooses the shell used
3836 @cindex @code{SHELL}, value of
3839 The program used as the shell is taken from the variable @code{SHELL}.
3843 @cindex environment, @code{SHELL} in
3844 Unlike most variables, the variable @code{SHELL} is never set from the
3845 environment. This is because the @code{SHELL} environment variable is
3851 Furthermore, when you do set @code{SHELL} in your makefile that value
3852 is @emph{not} exported in the environment to commands that @code{make}
3855 exporting @code{SHELL} (@pxref{Variables/Recursion, ,Communicating
3856 Variables to a Sub-@code{make}}), forcing it to be passed in the
3859 @vindex @code{MAKESHELL} @r{(MS-DOS alternative to @code{SHELL})}
3860 However, on MS-DOS and MS-Windows the value of @code{SHELL} in the
3863 be used by @code{make}. On MS-DOS, if the setting of @code{SHELL} is
3864 not suitable for @code{make}, you can set the variable
3865 @code{MAKESHELL} to the shell that @code{make} should use; if set it
3866 will be used as the shell instead of the value of @code{SHELL}.
3877 On MS-DOS, if @code{SHELL} is not set, the value of the variable
3878 @code{COMSPEC} (which is always set) is used instead.
3880 @cindex @code{SHELL}, MS-DOS specifics
3881 The processing of lines that set the variable @code{SHELL} in Makefiles
3883 ridiculously limited in its functionality and many users of @code{make}
3884 tend to install a replacement shell. Therefore, on MS-DOS, @code{make}
3885 examines the value of @code{SHELL}, and changes its behavior based on
3887 reasonable functionality even if @code{SHELL} points to
3890 If @code{SHELL} points to a Unix-style shell, @code{make} on MS-DOS
3892 ignores the line that sets @code{SHELL}. In MS-DOS, GNU @code{make}
3897 In the precise place pointed to by the value of @code{SHELL}. For
3898 example, if the makefile specifies @samp{SHELL = /bin/sh}, @code{make}
3905 In each of the directories in the @code{PATH} variable, in order.
3909 In every directory it examines, @code{make} will first look for the
3915 If any of these attempts is successful, the value of @code{SHELL} will
3917 these is found, the value of @code{SHELL} will not be changed, and thus
3919 @code{make} will only support features specific to a Unix-style shell if
3920 such a shell is actually installed on the system where @code{make} runs.
3923 where @code{SHELL} is set from the Makefile; if it is set in the
3930 directory along your @code{PATH}.
3938 @cindex @code{-j}
3939 @cindex @code{--jobs}
3941 GNU @code{make} knows how to execute several commands at once.
3942 Normally, @code{make} will execute only one command at a time, waiting
3944 @samp{--jobs} option tells @code{make} to execute many commands
3962 from the terminal at once, @code{make} will invalidate the standard
3972 input of @code{make}). The first command run will always get it first, and
3976 We will change how this aspect of @code{make} works if we find a better
3982 Finally, handling recursive @code{make} invocations raises issues. For
3984 @ref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}.
3993 @code{make} aborts execution. If make
4000 @cindex @code{-l} (load average)
4001 @cindex @code{--max-load}
4002 @cindex @code{--load-average}
4005 @code{make} to limit the number of jobs to run at once, based on the load
4015 will not let @code{make} start more than one job if the load average is
4019 More precisely, when @code{make} goes to start up a job, and it already has
4021 lower than the limit given with @samp{-l}, @code{make} waits until the load
4032 After each shell command returns, @code{make} looks at its exit status.
4037 If there is an error (the exit status is nonzero), @code{make} gives up on
4041 For example, you may use the @code{mkdir} command to ensure that a
4042 directory exists. If the directory already exists, @code{mkdir} will
4043 report an error, but you probably want @code{make} to continue regardless.
4045 @cindex @code{-} (in commands)
4058 @cindex @code{rm} (shell command)
4061 This causes @code{rm} to continue even if it is unable to remove a file.
4063 @cindex @code{-i}
4064 @cindex @code{--ignore-errors}
4066 When you run @code{make} with the @samp{-i} or @samp{--ignore-errors}
4068 makefile for the special target @code{.IGNORE} has the same effect, if
4073 @samp{-i} flag, @code{make} treats an error return just like success,
4074 except that it prints out a message that tells you the status code
4077 When an error happens that @code{make} has not been told to ignore,
4084 @cindex @code{-k}
4085 @cindex @code{--keep-going}
4086 Normally @code{make} gives up immediately in this circumstance, returning a
4088 flag is specified, @code{make}
4096 targets up to date; once @code{make} learns that this is impossible, it
4101 is why Emacs' @code{compile} command passes the @samp{-k} flag by
4103 @cindex Emacs (@code{M-x compile})
4112 date, so the next time @code{make} runs, it will not try to update that
4116 the file. @code{make} will do this if @code{.DELETE_ON_ERROR} appears
4117 as a target. This is almost always what you want @code{make} to do, but
4122 @section Interrupting or Killing @code{make}
4130 If @code{make} gets a fatal signal while a command is executing, it may
4133 @code{make} first checked it.
4136 scratch when @code{make} is next run. Why is this? Suppose you type
4140 file @file{foo.c}. But @code{make} also receives the @kbd{Ctrl-c} signal
4141 and deletes this incomplete file. If @code{make} did not do this, the next
4142 invocation of @code{make} would think that @file{foo.o} did not require
4148 special target @code{.PRECIOUS} depend on it. Before remaking a target,
4149 @code{make} checks to see whether it appears on the prerequisites of
4150 @code{.PRECIOUS}, and thereby decides whether the target should be deleted
4157 @section Recursive Use of @code{make}
4161 Recursive use of @code{make} means using @code{make} as a command in a
4165 like the containing directory's makefile to run @code{make} on the
4180 @cindex @code{-C}
4181 @cindex @code{--directory}
4183 You can write recursive @code{make} commands just by copying this example,
4185 how the sub-@code{make} relates to the top-level @code{make}. You may
4187 @code{make} commands as @samp{.PHONY} (for more discussion on when
4190 @vindex @code{CURDIR}
4191 For your convenience, when GNU @code{make} starts (after it has
4192 processed any @code{-C} options) it sets the variable @code{CURDIR} to
4194 touched by @code{make} again: in particular note that if you include
4195 files from other directories the value of @code{CURDIR} does not
4197 set in the makefile (by default, an environment variable @code{CURDIR}
4199 impact on the operation of @code{make} (it does not cause @code{make}
4204 * Variables/Recursion:: How to communicate variables to a sub-@code{make}.
4205 * Options/Recursion:: How to communicate options to a sub-@code{make}.
4207 helps debug use of recursive @code{make} commands.
4211 @subsection How the @code{MAKE} Variable Works
4213 @cindex recursion, and @code{MAKE} variable
4215 Recursive @code{make} commands should always use the variable @code{MAKE},
4225 The value of this variable is the file name with which @code{make} was
4228 @code{make} to run the top-level makefile, the same special version will be
4230 @cindex @code{cd} (shell command)
4233 As a special feature, using the variable @code{MAKE} in the commands of
4236 Using the @code{MAKE} variable has the same effect as using a @samp{+}
4239 is only enabled if the @code{MAKE} variable appears directly in the
4240 command script: it does not apply if the @code{MAKE} variable is
4252 @cindex @code{-t}, and recursion
4253 @cindex recursion, and @code{-t}
4254 @cindex @code{--touch}, and recursion
4257 line of a rule contains the variable @code{MAKE}, the flags @samp{-t},
4259 containing @code{MAKE} are executed normally despite the presence of a
4261 @code{MAKEFLAGS} mechanism passes the flags to the sub-@code{make}
4263 Sub-@code{make}}), so your request to touch the files, or print the
4267 @subsection Communicating Variables to a Sub-@code{make}
4268 @cindex sub-@code{make}
4276 Variable values of the top-level @code{make} can be passed to the
4277 sub-@code{make} through the environment by explicit request. These
4278 variables are defined in the sub-@code{make} as defaults, but do not
4279 override what is specified in the makefile used by the sub-@code{make}
4283 To pass down, or @dfn{export}, a variable, @code{make} adds the variable
4285 sub-@code{make}, in turn, uses the environment to initialize its table
4289 Except by explicit request, @code{make} exports a variable only if it
4296 The value of the @code{make} variable @code{SHELL} is not exported.
4297 Instead, the value of the @code{SHELL} variable from the invoking
4298 environment is passed to the sub-@code{make}. You can force
4299 @code{make} to export its value for @code{SHELL} by using the
4300 @code{export} directive, described below. @xref{Choosing the Shell}.
4302 The special variable @code{MAKEFLAGS} is always exported (unless you
4303 unexport it). @code{MAKEFILES} is exported if you set it to anything.
4305 @code{make} automatically passes down variable values that were defined
4306 on the command line, by putting them in the @code{MAKEFLAGS} variable.
4315 default by @code{make} (@pxref{Implicit Variables, ,Variables Used by
4316 Implicit Rules}). The sub-@code{make} will define these for
4320 If you want to export specific variables to a sub-@code{make}, use the
4321 @code{export} directive, like this:
4330 @code{unexport} directive, like this:
4337 In both of these forms, the arguments to @code{export} and
4338 @code{unexport} are expanded, and so could be variables or functions
4388 You may notice that the @code{export} and @code{unexport} directives
4389 work in @code{make} in the same way they work in the shell, @code{sh}.
4392 @code{export} by itself:
4399 This tells @code{make} that variables which are not explicitly mentioned
4400 in an @code{export} or @code{unexport} directive should be exported.
4401 Any variable given in an @code{unexport} directive will still @emph{not}
4402 be exported. If you use @code{export} by itself to export variables by
4405 mentioned in an @code{export} directive.@refill
4408 The behavior elicited by an @code{export} directive by itself was the
4409 default in older versions of GNU @code{make}. If your makefiles depend
4411 @code{make}, you can write a rule for the special target
4412 @code{.EXPORT_ALL_VARIABLES} instead of using the @code{export} directive.
4413 This will be ignored by old @code{make}s, while the @code{export}
4417 Likewise, you can use @code{unexport} by itself to tell @code{make}
4419 behavior, you would only need to do this if @code{export} had been used
4421 @strong{cannot} use @code{export} and @code{unexport} by themselves to
4423 @code{export} or @code{unexport} directive that appears by itself
4424 determines the behavior for the entire run of @code{make}.@refill
4428 As a special feature, the variable @code{MAKELEVEL} is changed when it
4431 @samp{0} for the top-level @code{make}; @samp{1} for a sub-@code{make},
4432 @samp{2} for a sub-sub-@code{make}, and so on. The incrementation
4433 happens when @code{make} sets up the environment for a command.@refill
4435 The main use of @code{MAKELEVEL} is to test it in a conditional
4441 You can use the variable @code{MAKEFILES} to cause all sub-@code{make}
4442 commands to use additional makefiles. The value of @code{MAKEFILES} is
4445 it serves as a list of extra makefiles for the sub-@code{make} to read
4447 Variable @code{MAKEFILES}}.@refill
4450 @subsection Communicating Options to a Sub-@code{make}
4456 sub-@code{make} through the variable @code{MAKEFLAGS}. This variable is
4457 set up automatically by @code{make} to contain the flag letters that
4458 @code{make} received. Thus, if you do @w{@samp{make -ks}} then
4459 @code{MAKEFLAGS} gets the value @samp{ks}.@refill
4461 As a consequence, every sub-@code{make} gets a value for @code{MAKEFLAGS}
4470 sub-@code{make} through @code{MAKEFLAGS}. Words in the value of
4471 @code{MAKEFLAGS} that contain @samp{=}, @code{make} treats as variable
4475 @cindex @code{-C}, and recursion
4476 @cindex @code{-f}, and recursion
4477 @cindex @code{-o}, and recursion
4478 @cindex @code{-W}, and recursion
4479 @cindex @code{--directory}, and recursion
4480 @cindex @code{--file}, and recursion
4481 @cindex @code{--old-file}, and recursion
4482 @cindex @code{--assume-old}, and recursion
4483 @cindex @code{--assume-new}, and recursion
4484 @cindex @code{--new-file}, and recursion
4485 @cindex recursion, and @code{-C}
4486 @cindex recursion, and @code{-f}
4487 @cindex recursion, and @code{-o}
4488 @cindex recursion, and @code{-W}
4490 into @code{MAKEFLAGS}; these options are not passed down.@refill
4492 @cindex @code{-j}, and recursion
4493 @cindex @code{--jobs}, and recursion
4494 @cindex recursion, and @code{-j}
4499 parent @code{make} and all the sub-@code{make}s will communicate to
4504 sub-@code{make}s running and have no slots left over for any real work!)
4507 @samp{-j 1} is always put into @code{MAKEFLAGS} instead of the value you
4509 to sub-@code{make}s, you would get many more jobs running in parallel
4515 value of @code{MAKEFLAGS}, like this:
4524 @code{MAKEOVERRIDES}, and @code{MAKEFLAGS} contains a reference to this
4527 @code{MAKEOVERRIDES} to empty, like this:
4538 information into the value of @code{MAKEFLAGS} can exceed it. If you
4542 (For strict compliance with POSIX.2, changing @code{MAKEOVERRIDES} does
4543 not affect @code{MAKEFLAGS} if the special target @samp{.POSIX} appears
4547 A similar variable @code{MFLAGS} exists also, for historical
4548 compatibility. It has the same value as @code{MAKEFLAGS} except that it
4550 begins with a hyphen unless it is empty (@code{MAKEFLAGS} begins with a
4552 version, such as @samp{--warn-undefined-variables}). @code{MFLAGS} was
4553 traditionally used explicitly in the recursive @code{make} command, like
4562 but now @code{MAKEFLAGS} makes this usage redundant. If you want your
4563 makefiles to be compatible with old @code{make} programs, use this
4564 technique; it will work fine with more modern @code{make} versions too.
4570 The @code{MAKEFLAGS} variable can also be useful if you want to have
4572 Options}), set each time you run @code{make}. You simply put a value for
4573 @code{MAKEFLAGS} in your environment. You can also set @code{MAKEFLAGS} in
4575 that makefile. (Note that you cannot use @code{MFLAGS} this way. That
4576 variable is set only for compatibility; @code{make} does not interpret a
4579 When @code{make} interprets the value of @code{MAKEFLAGS} (either from the
4587 If you do put @code{MAKEFLAGS} in your environment, you should be sure not
4589 @code{make} and undermine the purpose of makefiles and of @code{make}
4600 If you use several levels of recursive @code{make} invocations, the
4602 lot easier to understand by showing each directory as @code{make}
4603 starts processing it and as @code{make} finishes processing it. For
4605 @code{make} will print a line of the form:@refill
4621 @cindex @code{-C}, and @code{-w}
4622 @cindex @code{--directory}, and @code{--print-directory}
4623 @cindex recursion, and @code{-w}
4624 @cindex @code{-w}, and @code{-C}
4625 @cindex @code{-w}, and recursion
4626 @cindex @code{--print-directory}, and @code{--directory}
4627 @cindex @code{--print-directory}, and recursion
4628 @cindex @code{--no-print-directory}
4629 @cindex @code{--print-directory}, disabling
4630 @cindex @code{-w}, disabling
4633 @samp{-C} option, and in sub-@code{make}s. @code{make} will not
4644 can define it as a canned sequence with the @code{define} directive, and
4657 @cindex @code{yacc}
4660 Here @code{run-yacc} is the name of the variable being defined;
4661 @code{endef} marks the end of the definition; the lines in between are the
4662 commands. The @code{define} directive does not expand variable references
4667 for a complete explanation of @code{define}.
4677 Because variables defined by @code{define} are recursively expanded
4678 variables, all the variable references you wrote inside the @code{define}
4688 @code{run-yacc}'s value, and @samp{foo.c} for @samp{$@@}.@refill
4691 practice because @code{make} has an implicit rule to figure out these
4695 @cindex @@, and @code{define}
4696 @cindex -, and @code{define}
4697 @cindex +, and @code{define}
4700 particular, @code{make} invokes a separate subshell for each line. You
4715 @code{make} will not echo the first line, the @code{echo} command.
4752 @code{.DEFAULT} special target; @pxref{Implicit Rules} and
4781 and other parts of the makefile. (In some other versions of @code{make},
4788 definitions using the @code{define} directive.@refill
4799 sub-@code{make}
4800 (@pxref{Variables/Recursion, ,Communicating Variables to a Sub-@code{make}}).
4838 @cindex @code{$}, in variable reference
4839 @cindex dollar sign (@code{$}), in variable reference
4843 @samp{$@{foo@}} is a valid reference to the variable @code{foo}. This
4875 @code{foo} is precisely @samp{c}. (Don't actually write your makefiles
4880 variable name. Thus, you could reference the variable @code{x} with
4892 There are two ways that a variable in GNU @code{make} can have a value;
4899 (@pxref{Setting, ,Setting Variables}) or by the @code{define} directive
4921 @code{make}. It has its advantages and its disadvantages. An advantage
4940 (Actually @code{make} detects the infinite loop and reports an error.)
4947 expanded. This makes @code{make} run slower; worse, it causes the
4948 @code{wildcard} and @code{shell} functions to give unpredictable results
4985 @samp{:=} in conjunction with the @code{shell} function.
4986 (@xref{Shell Function, , The @code{shell} Function}.) This example
4987 also shows use of the variable @code{MAKELEVEL}, which is changed
4990 Sub-@code{make}}, for information about @code{MAKELEVEL}.)
5037 Here the value of the variable @code{space} is precisely one space. The
5053 Here the value of the variable @code{dir} is @w{@samp{/foo/bar }}
5070 (@pxref{Origin Function, ,The @code{origin} Function}):
5124 @code{patsubst} expansion function (@pxref{Text Functions, ,Functions for String Substitution and A…
5125 substitution references as well as @code{patsubst} for compatibility with
5126 other implementations of @code{make}.
5130 the @code{patsubst} function. It has the same form
5135 for a description of the @code{patsubst} function.@refill
5156 @cindex @code{$}, in variable name
5157 @cindex dollar sign (@code{$}), in variable name
5177 defines @code{a} as @samp{z}: the @samp{$(x)} inside @samp{$($(x))} expands
5209 defines @code{a} as @samp{Hello}: @samp{$($(x))} becomes @samp{$($(y))}
5215 For example, using the @code{subst} function
5229 eventually defines @code{a} as @samp{Hello}. It is doubtful that anyone
5233 @code{x} and changes it by substitution to @samp{variable2}, so that the
5272 will give @code{dirs} the same value as @code{a_dirs}, @code{1_dirs},
5273 @code{a_files} or @code{1_files} depending on the settings of @code{use_a}
5274 and @code{use_dirs}.@refill
5288 defines @code{sources} as either @samp{a.c b.c c.c} or @samp{1.c 2.c 3.c},
5289 depending on the value of @code{a1}.
5317 as the argument to either the @code{sort} or the @code{strip} function.
5322 variable assignment, or in a @code{define} directive, as in:
5350 You can specify an overriding value when you run @code{make}.
5359 Variables in the environment become @code{make} variables.
5389 defines a variable named @code{objects}. Whitespace around the variable
5404 affect the functioning of @code{make}, but it will make the makefile easier
5418 (@pxref{Origin Function, ,The @code{origin} Function}):
5447 This takes the value of the variable @code{objects}, and adds the text
5456 sets @code{objects} to @samp{main.o foo.o bar.o utils.o another.o}.
5475 When you add to a variable's value with @samp{+=}, @code{make} acts
5499 first to be recursively-expanded using plain @samp{=}, @code{make} does
5501 recursively-expanded variable, @code{make} does not expand the value you set
5506 it is this unexpanded text to which @code{make} appends the new text you
5527 except that of course it never defines a variable called @code{temp}.
5538 The first line defines the @code{CFLAGS} variable with a reference to another
5539 variable, @code{includes}. (@code{CFLAGS} is used by the rules for C
5541 Using @samp{=} for the definition makes @code{CFLAGS} a recursively-expanded
5543 @code{make} processes the definition of @code{CFLAGS}. Thus, @code{includes}
5545 defined before any reference to @code{CFLAGS}. If we tried to append to the
5546 value of @code{CFLAGS} without using @samp{+=}, we might do it like this:
5554 redefines @code{CFLAGS} as a simply-expanded variable; this means
5555 @code{make} expands the text @w{@samp{$(CFLAGS) -pg}} before setting the
5556 variable. If @code{includes} is not yet defined, we get @w{@samp{ -O
5557 -pg}}, and a later definition of @code{includes} will have no effect.
5558 Conversely, by using @samp{+=} we set @code{CFLAGS} to the
5560 the reference to @code{includes}, so if that variable gets defined at
5565 @section The @code{override} Directive
5567 @cindex overriding with @code{override}
5574 argument, you can use an @code{override} directive, which is a line that
5597 The @code{override} directive was not invented for escalation in the war
5604 @code{override} directive:
5610 You can also use @code{override} directives with @code{define} directives.
5621 See the next section for information about @code{define}.
5635 Another way to set the value of a variable is to use the @code{define}
5640 sections of makefile syntax to use with @code{eval} (@pxref{Eval Function}).
5642 The @code{define} directive is followed on the same line by the name of the
5645 the word @code{endef}. Aside from this difference in syntax, @code{define}
5652 You may nest @code{define} directives: @code{make} will keep track of
5654 closed with @code{endef}. Note that lines beginning with tab
5656 @code{define} or @code{endef} strings appearing on such a line will
5657 not be considered @code{make} operators.
5667 newlines that separate the lines of the value in a @code{define} become
5669 the @code{endef} and is not considered part of the value).@refill
5682 @code{make} will invoke the shell twice, running an independent subshell
5685 If you want variable definitions made with @code{define} to take
5687 @code{override} directive together with @code{define}:
5697 @xref{Override Directive, ,The @code{override} Directive}.
5704 Variables in @code{make} can come from the environment in which
5705 @code{make} is run. Every environment variable that @code{make} sees
5706 when it starts up is transformed into a @code{make} variable with the
5713 Thus, by setting the variable @code{CFLAGS} in your environment, you can
5717 this is not totally reliable; some makefiles set @code{CFLAGS} explicitly
5720 When @code{make} runs a command script, variables defined in the
5722 you to pass values to sub-@code{make} invocations (@pxref{Recursion,
5723 ,Recursive Use of @code{make}}). By default, only variables that came
5725 invocations. You can use the @code{export} directive to pass other
5727 Sub-@code{make}}, for full details.
5737 @code{SHELL}, which is normally present in the environment to specify
5739 for this choice to affect @code{make}; so, @code{make} handles the
5740 @code{SHELL} environment variable in a special way; see @ref{Choosing
5748 Variable values in @code{make} are usually global; that is, they are the
5755 based on the target that @code{make} is currently building. As with
5794 Specifying the @code{override} directive will allow the target-specific
5810 will set @code{CFLAGS} to @samp{-g} in the command script for
5811 @file{prog}, but it will also set @code{CFLAGS} to @samp{-g} in the
5831 @code{make} supports pattern-specific variable values. In this form,
5858 take precedence, unless @code{override} is specified.
5867 will assign @code{CFLAGS} the value of @samp{-O} for all targets
5868 matching the pattern @code{%.o}.
5877 a constant string. Conditionals control what @code{make} actually
5890 The following example of a conditional tells @code{make} to use one set
5891 of libraries if the @code{CC} variable is @samp{gcc}, and a different
5894 that @samp{CC=gcc} as an argument to @code{make} changes not only which
5909 This conditional uses three directives: one @code{ifeq}, one @code{else}
5910 and one @code{endif}.
5912 The @code{ifeq} directive begins the conditional, and specifies the
5916 @code{ifeq} are obeyed if the two arguments match; otherwise they are
5919 The @code{else} directive causes the following lines to be obeyed if the
5922 is not used. It is optional to have an @code{else} in a conditional.
5924 The @code{endif} directive ends the conditional. Every conditional must
5925 end with an @code{endif}. Unconditional makefile text follows.
5933 When the variable @code{CC} has the value @samp{gcc}, the above example has
5942 When the variable @code{CC} has any other value, the effect is this:
5975 The syntax of a simple conditional with no @code{else} is as follows:
6011 There can be as many ``@code{else} @var{conditional-directive}''
6019 conditional is simple or complex; after an @code{else} or not. There
6023 @table @code
6037 @code{strip} function (@pxref{Text Functions}) to avoid interpreting
6050 @code{$(foo)} contains whitespace characters.
6062 The @code{ifdef} form takes the @emph{name} of a variable as its
6078 The variable reference @code{$(foo)} is expanded, yielding @code{bar},
6080 @code{bar} is not expanded, but its value is examined to determine if
6083 Note that @code{ifdef} only tests whether a variable has a value. It
6085 Consequently, tests using @code{ifdef} return true for all definitions
6086 except those like @code{foo =}. To test for an empty value, use
6087 @w{@code{ifeq ($(foo),)}}. For example,
6118 @var{variable-name} are identical to the @code{ifdef} directive.
6128 The other two directives that play a part in a conditional are @code{else}
6129 and @code{endif}. Each of these directives is written as one word, with no
6134 Conditionals affect which lines of the makefile @code{make} uses. If
6135 the condition is true, @code{make} reads the lines of the
6137 @code{make} ignores those lines completely. It follows that syntactic
6141 @code{make} evaluates conditionals when it reads a makefile.
6148 write an @code{include} directive within a conditional, provided you do
6154 You can write a conditional that tests @code{make} command flags such as
6155 @samp{-t} by using the variable @code{MAKEFLAGS} together with the
6156 @code{findstring} function
6158 This is useful when @code{touch} is not enough to make a file appear up
6161 The @code{findstring} function determines whether one string appears as a
6163 use @samp{t} as the first string and the value of @code{MAKEFLAGS} as
6182 @xref{Recursion, ,Recursive Use of @code{make}}.
6212 @cindex @code{$}, in function call
6213 @cindex dollar sign (@code{$}), in function call
6231 that are part of @code{make}. You can also essentially create your own
6232 functions by using the @code{call} builtin function.
6255 by variable substitution. First define variables @code{comma} and
6256 @code{space} whose values are isolated comma and space characters, then
6271 Here the @code{subst} function replaces each space with a comma, through
6272 the value of @code{foo}, and substitutes the result.
6280 @table @code
6304 @cindex @code{%}, quoting in @code{patsubst}
6305 @cindex @code{%}, quoting with @code{\} (backslash)
6306 @cindex @code{\} (backslash), to quote @code{%}
6307 @cindex backslash (@code{\}), to quote @code{%}
6308 @cindex quoting @code{%}, in @code{patsubst}
6309 @samp{%} characters in @code{patsubst} function invocations can be
6334 References}) are a simpler way to get the effect of the @code{patsubst}
6349 @code{patsubst}: replacing the suffix at the end of file names.
6392 The function @code{strip} can be very useful when used in conjunction
6394 @samp{} using @code{ifeq} or @code{ifneq}, you usually want a string of
6410 function call @w{@samp{$(strip $(needs_made))}} in the @code{ifneq}
6431 @code{findstring}.@refill
6441 used in the @code{patsubst} function above.@refill
6443 The @code{filter} function can be used to separate out different types
6464 match one or more. This is the exact opposite of the @code{filter}
6502 Incidentally, since @code{sort} removes duplicate words, you can use
6545 @w{@code{$(word $(words @var{text}),@var{text})}}.@refill
6561 produces the result @samp{foo}. Although @code{$(firstword
6562 @var{text})} is the same as @code{$(word 1,@var{text})}, the
6563 @code{firstword} function is retained for its simplicity.@refill
6579 produces the result @samp{bar}. Although @code{$(lastword
6580 @var{text})} is the same as @code{$(word $(words @var{text}),@var{text})},
6581 the @code{lastword} function was added for its simplicity and better
6586 Here is a realistic example of the use of @code{subst} and
6587 @code{patsubst}. Suppose that a makefile uses the @code{VPATH} variable
6588 to specify a list of directories that @code{make} should search for
6590 (@pxref{General Search, , @code{VPATH} Search Path for All Prerequisites}).
6595 The value of @code{VPATH} is a list of directories separated by colons,
6596 such as @samp{src:../headers}. First, the @code{subst} function is used to
6604 This produces @samp{src ../headers}. Then @code{patsubst} is used to turn
6606 value of the variable @code{CFLAGS}, which is passed automatically to the C
6615 previously given value of @code{CFLAGS}. The @code{override} directive is
6617 @code{CFLAGS} was specified with a command argument (@pxref{Override
6618 Directive, , The @code{override} Directive}).
6634 @table @code
6761 This function can merge the results of the @code{dir} and
6762 @code{notdir} functions, to produce the original list of files which
6770 @code{wildcard} is a space-separated list of the names of existing files
6779 A canonical name does not contain any @code{.} or @code{..} components,
6780 nor any repeated path separators (@code{/}) or symlinks. In case of a
6781 failure the empty string is returned. Consult the @code{realpath(3)}
6789 not contain any @code{.} or @code{..} components, nor any repeated path
6790 separators (@code{/}). Note that, in contrast to @code{realpath}
6791 function, @code{abspath} does not resolve symlinks and does not require
6793 @code{wildcard} function to test for existence.
6805 @table @code
6808 The @code{if} function provides support for conditional expansion in a
6809 functional context (as opposed to the GNU @code{make} makefile
6810 conditionals such as @code{ifeq} (@pxref{Conditional Syntax, ,Syntax of
6820 @code{if} function.
6823 evaluated and this is the result of the @code{if} function. If there is
6824 no third argument, the @code{if} function evaluates to nothing (the
6829 @code{shell} function calls, etc.)
6833 The @code{or} function provides a ``short-circuiting'' OR operation.
6841 The @code{and} function provides a ``short-circuiting'' AND operation.
6850 @section The @code{foreach} Function
6854 The @code{foreach} function is very different from other functions. It
6856 substitution performed on it. It resembles the @code{for} command in the
6857 shell @code{sh} and the @code{foreach} command in the C-shell @code{csh}.
6859 The syntax of the @code{foreach} function is:
6877 of @code{foreach}.
6888 finds the value @samp{a} for @code{dir}, so it produces the same result
6909 Here we use the variable @code{find_files} this way. We use plain @samp{=}
6911 actual function call to be reexpanded under the control of @code{foreach};
6912 a simply-expanded variable would not do, since @code{wildcard} would be
6913 called only once at the time of defining @code{find_files}.
6915 The @code{foreach} function has no permanent effect on the variable
6916 @var{var}; its value and flavor after the @code{foreach} function call are
6919 @code{foreach}. The variable @var{var} is a simply-expanded variable
6920 during the execution of @code{foreach}. If @var{var} was undefined
6921 before the @code{foreach} function call, it is undefined after the call.
6933 might be useful if the value of @code{find_files} references the variable
6938 @section The @code{call} Function
6943 The @code{call} function is unique in that it can be used to create new
6945 value of a variable, then use @code{call} to expand it with different
6948 The syntax of the @code{call} function is:
6954 When @code{make} expands this function, it assigns each @var{param} to
6955 temporary variables @code{$(1)}, @code{$(2)}, etc. The variable
6956 @code{$(0)} will contain @var{variable}. There is no maximum number of
6958 sense to use @code{call} with no parameters.
6960 Then @var{variable} is expanded as a @code{make} variable in the context
6961 of these temporary assignments. Thus, any reference to @code{$(1)} in
6963 invocation of @code{call}.
6972 is always invoked (even if a @code{make} variable by that name also
6975 The @code{call} function expands the @var{param} arguments before
6978 expansion rules, like @code{foreach} or @code{if}, may not work as you
6995 the first instance of a program in @code{PATH}:
7004 Now the variable LS contains @code{/bin/ls} or similar.
7006 The @code{call} function can be nested. Each recursive invocation gets
7007 its own local values for @code{$(1)}, etc.@: that mask the values of
7008 higher-level @code{call}. For example, here is an implementation of a
7016 such as @code{origin}, to multiple values in one step:
7025 @code{call}. As with other functions, any whitespace contained in the
7028 providing parameters to @code{call}.
7032 @section The @code{value} Function
7036 The @code{value} function provides a way for you to use the value of a
7040 definition; in that case the @code{value} function will return the
7043 The syntax of the @code{value} function is:
7070 The first output line would be @code{ATH}, since the ``$P'' would be
7071 expanded as a @code{make} variable, while the second output line would
7072 be the current value of your @code{$PATH} environment variable, since
7073 the @code{value} function avoided the expansion.
7075 The @code{value} function is most often used in conjunction with the
7076 @code{eval} function (@pxref{Eval Function}).
7080 @section The @code{eval} Function
7085 The @code{eval} function is very special: it allows you to define new
7088 @code{eval} function is expanded, then the results of that expansion
7090 @code{make} variables, targets, implicit or explicit rules, etc.
7092 The result of the @code{eval} function is always the empty string;
7096 It's important to realize that the @code{eval} argument is expanded
7097 @emph{twice}; first by the @code{eval} function, then the results of
7100 for ``$'' characters when using @code{eval}. The @code{value}
7104 Here is an example of how @code{eval} can be used; this example
7106 seem overly complex to use @code{eval} in this example, rather than
7108 definition (in @code{PROGRAM_template}) could need to be much more
7145 @section The @code{origin} Function
7150 The @code{origin} function is unlike most other functions in that it does
7154 The syntax of the @code{origin} function is:
7175 if @var{variable} has a default definition, as is usual with @code{CC}
7177 Note that if you have redefined a default variable, the @code{origin}
7201 if @var{variable} was defined with an @code{override} directive in a
7202 makefile (@pxref{Override Directive, ,The @code{override} Directive}).
7214 @file{bar}. You want a variable @code{bletch} to be defined in @file{bar}
7216 a definition of @code{bletch}. However, if @file{foo} defined
7217 @code{bletch} before including @file{bar}, you do not want to override that
7218 definition. This could be done by using an @code{override} directive in
7220 @file{bar}; unfortunately, the @code{override} directive would also
7235 If @code{bletch} has been defined from the environment, this will redefine
7238 If you want to override a previous definition of @code{bletch} if it came
7254 @section The @code{flavor} Function
7259 The @code{flavor} function is unlike most other functions (and like
7260 @code{origin} function) in that it does not operate on the values of
7265 The syntax of the @code{flavor} function is:
7296 @section The @code{shell} Function
7302 The @code{shell} function is unlike any other function other than the
7303 @code{wildcard} function
7304 (@pxref{Wildcard Function, ,The Function @code{wildcard}}) in that it
7305 communicates with the world outside of @code{make}.
7307 The @code{shell} function performs the same function that backquotes
7310 to the output of the command. The only processing @code{make} does on
7315 The commands run by calls to the @code{shell} function are run when the
7317 @code{make} Reads a Makefile}). Because this function involves
7319 implications of using the @code{shell} function within recursively
7323 Here are some examples of the use of the @code{shell} function:
7330 sets @code{contents} to the contents of the file @file{foo}, with a space
7338 sets @code{files} to the expansion of @samp{*.c}. Unless @code{make} is
7352 @table @code
7373 @code{make} variable @code{ERROR1} is defined. Or,
7383 will generate a fatal error while @code{make} is running, if the
7384 @code{err} target is invoked.
7390 This function works similarly to the @code{error} function, above,
7391 except that @code{make} doesn't exit. Instead, @var{text} is expanded
7406 @chapter How to Run @code{make}
7411 @code{make} with no arguments, it does just that.
7417 By giving arguments when you run @code{make}, you can do any of these
7421 The exit status of @code{make} is always one of three values:
7422 @table @code
7424 The exit status is zero if @code{make} is successful.
7426 The exit status is two if @code{make} encounters any errors.
7429 The exit status is one if you use the @samp{-q} flag and @code{make}
7452 @cindex @code{--file}
7453 @cindex @code{--makefile}
7454 @cindex @code{-f}
7473 The @dfn{goals} are the targets that @code{make} should strive ultimately
7483 within your makefile using the @code{.DEFAULT_GOAL} variable
7487 arguments to @code{make}. Use the name of the goal as an argument.
7488 If you specify several goals, @code{make} processes each of them in
7494 targets not in the makefile may be specified, if @code{make} can find
7498 @code{Make} will set the special variable @code{MAKECMDGOALS} to the
7504 during @code{clean} rules (@pxref{Automatic Prerequisites}), so
7505 @code{make} won't create them only to immediately remove them
7528 If you are working on the program @code{size}, you might want to say
7547 @cindex @code{all} @r{(standard target)}
7551 @cindex @code{clean} @r{(standard target)}
7552 Delete all files that are normally created by running @code{make}.
7555 @cindex @code{mostlyclean} @r{(standard target)}
7562 @cindex @code{distclean} @r{(standard target)}
7564 @cindex @code{realclean} @r{(standard target)}
7566 @cindex @code{clobber} @r{(standard target)}
7573 @cindex @code{install} @r{(standard target)}
7579 @cindex @code{print} @r{(standard target)}
7583 @cindex @code{tar} @r{(standard target)}
7587 @cindex @code{shar} @r{(standard target)}
7591 @cindex @code{dist} @r{(standard target)}
7597 @cindex @code{TAGS} @r{(standard target)}
7601 @cindex @code{check} @r{(standard target)}
7603 @cindex @code{test} @r{(standard target)}
7612 The makefile tells @code{make} how to tell whether a target is up to date,
7614 what you want. Certain options specify other activities for @code{make}.
7622 @cindex @code{--just-print}
7623 @cindex @code{--dry-run}
7624 @cindex @code{--recon}
7625 @cindex @code{-n}
7632 @cindex @code{--touch}
7635 @cindex @code{-t}
7638 actually changing them. In other words, @code{make} pretends to compile
7643 @cindex @code{--question}
7644 @cindex @code{-q}
7655 @cindex @code{--what-if}
7656 @cindex @code{-W}
7657 @cindex @code{--assume-new}
7658 @cindex @code{--new-file}
7663 files' modification times are recorded by @code{make} as being the present
7669 With the @samp{-n} flag, @code{make} prints the commands that it would
7672 With the @samp{-t} flag, @code{make} ignores the commands in the rules
7673 and uses (in effect) the command @code{touch} for each target that needs to
7674 be remade. The @code{touch} command is also printed, unless @samp{-s} or
7675 @code{.SILENT} is used. For speed, @code{make} does not actually invoke
7676 the program @code{touch}. It does the work directly.
7678 With the @samp{-q} flag, @code{make} prints nothing and executes no
7679 commands, but the exit status code it returns is zero if and only if the
7681 one, then some updating needs to be done. If @code{make} encounters an
7686 invocation of @code{make}.
7695 @samp{$@{MAKE@}} (@xref{MAKE Variable, ,How the @code{MAKE} Variable Works}.)
7702 @code{make} would do if you were to modify some files.
7705 Without the @samp{-n} or @samp{-q} flag, when @code{make} is actually
7706 executing commands, the @samp{-W} flag can direct @code{make} to act
7712 information about @code{make} or about the makefiles in use
7717 @cindex @code{-o}
7718 @cindex @code{--old-file}
7719 @cindex @code{--assume-old}
7727 on. Being conservative, @code{make} assumes that any change in the
7733 use the @samp{-t} flag. This flag tells @code{make} not to run the
7748 up to date. The next time you run @code{make}, the changes in the
7785 @code{CFLAGS} is included in each command that runs the C compiler, so a
7792 Thus, whatever value you set for @code{CFLAGS} affects each compilation
7794 @code{CFLAGS}, like this:
7800 Each time you run @code{make}, you can override this value if you
7807 The variable @code{CFLAGS} is only one of many standard variables that
7824 overridden. This is to use the @code{override} directive, which is a line
7826 (@pxref{Override Directive, ,The @code{override} Directive}).
7833 Normally, when an error happens in executing a shell command, @code{make}
7836 correctly remade, and @code{make} reports this as soon as it knows.
7839 what you want. Instead, you would rather that @code{make} try compiling
7843 @cindex @code{-k}
7844 @cindex @code{--keep-going}
7846 @samp{--keep-going} flag. This tells @code{make} to continue to
7858 The usual behavior of @code{make} assumes that your purpose is to get the
7859 goals up to date; once @code{make} learns that this is impossible, it might
7872 Here is a table of all the options @code{make} understands:
7876 @cindex @code{-b}
7878 @cindex @code{-m}
7879 These options are ignored for compatibility with other versions of @code{make}.
7882 @cindex @code{-B}
7884 @cindex @code{--always-make}
7885 Consider all targets out-of-date. GNU @code{make} proceeds to
7889 @code{MAKE_RESTARTS} (@pxref{Special Variables, , Other Special
7895 @cindex @code{-C}
7897 @cindex @code{--directory}
7901 This is typically used with recursive invocations of @code{make}
7902 (@pxref{Recursion, ,Recursive Use of @code{make}}).
7905 @cindex @code{-d}
7913 @code{make} decides what to do. The @code{-d} option is equivalent to
7917 @cindex @code{--debug}
7926 @table @code
7955 @cindex @code{-e}
7957 @cindex @code{--environment-overrides}
7963 @cindex @code{-f}
7965 @cindex @code{--file}
7967 @cindex @code{--makefile}
7972 @cindex @code{-h}
7974 @cindex @code{--help}
7977 Remind you of the options that @code{make} understands and then exit.
7980 @cindex @code{-i}
7982 @cindex @code{--ignore-errors}
7987 @cindex @code{-I}
7989 @cindex @code{--include-dir}
7996 @cindex @code{-j}
7998 @cindex @code{--jobs}
8000 argument, @code{make} runs as many jobs simultaneously as possible. If
8007 @cindex @code{-k}
8009 @cindex @code{--keep-going}
8016 @cindex @code{-l}
8018 @cindex @code{--load-average}
8020 @cindex @code{--max-load}
8027 @cindex @code{-L}
8029 @cindex @code{--check-symlink-times}
8030 On systems that support symbolic links, this option causes @code{make}
8037 @cindex @code{-n}
8039 @cindex @code{--just-print}
8041 @cindex @code{--dry-run}
8043 @cindex @code{--recon}
8050 @cindex @code{-o}
8052 @cindex @code{--old-file}
8054 @cindex @code{--assume-old}
8062 @cindex @code{-p}
8064 @cindex @code{--print-data-base}
8065 @cindex data base of @code{make} rules
8077 @cindex @code{-q}
8079 @cindex @code{--question}
8087 @cindex @code{-r}
8089 @cindex @code{--no-builtin-rules}
8096 @code{.SUFFIXES}, and then define your own suffix rules. Note that only
8097 @emph{rules} are affected by the @code{-r} option; default variables
8102 @cindex @code{-R}
8104 @cindex @code{--no-builtin-variables}
8112 @cindex @code{-s}
8114 @cindex @code{--silent}
8116 @cindex @code{--quiet}
8123 @cindex @code{-S}
8125 @cindex @code{--no-keep-going}
8127 @cindex @code{--stop}
8131 except in a recursive @code{make} where @samp{-k} might be inherited
8132 from the top-level @code{make} via @code{MAKEFLAGS}
8133 (@pxref{Recursion, ,Recursive Use of @code{make}})
8134 or if you set @samp{-k} in @code{MAKEFLAGS} in your environment.@refill
8137 @cindex @code{-t}
8139 @cindex @code{--touch}
8145 @code{make}. @xref{Instead of Execution, ,Instead of Executing the Commands}.
8148 @cindex @code{-v}
8150 @cindex @code{--version}
8151 Print the version of the @code{make} program plus a copyright, a list
8155 @cindex @code{-w}
8157 @cindex @code{--print-directory}
8160 from complicated nests of recursive @code{make} commands.
8161 @xref{Recursion, ,Recursive Use of @code{make}}. (In practice, you
8166 @cindex @code{--no-print-directory}
8167 Disable printing of the working directory under @code{-w}.
8168 This option is useful when @code{-w} is turned on automatically,
8173 @cindex @code{-W}
8175 @cindex @code{--what-if}
8177 @cindex @code{--new-file}
8179 @cindex @code{--assume-new}
8183 running a @code{touch} command on the given file before running
8184 @code{make}, except that the modification time is changed only in the
8185 imagination of @code{make}.
8189 @cindex @code{--warn-undefined-variables}
8192 Issue a warning message whenever @code{make} sees a reference to an
8204 using the C compiler, @code{cc}.
8206 @dfn{Implicit rules} tell @code{make} how to use customary techniques so
8211 So @code{make} applies the implicit rule for C compilation when it sees
8214 A chain of implicit rules can apply in sequence; for example, @code{make}
8222 implicit rule works. For example, the variable @code{CFLAGS} controls the
8259 To allow @code{make} to find a customary method for updating a target file,
8262 @code{make} will figure out which implicit rule to use based on which
8273 Because you mention @file{foo.o} but do not give a rule for it, @code{make}
8288 So, if you have a file @file{foo.c}, @code{make} will run the C compiler;
8289 otherwise, if you have a file @file{foo.p}, @code{make} will run the Pascal
8293 want @code{make} to use, and you know it will choose that one because you
8305 In general, @code{make} searches for an implicit rule for each target, and
8320 @code{make} will remake @file{foo.o} according to the implicit rule to
8347 @code{make}, run @samp{make -p} in a directory with no makefile.
8351 implemented in @code{make} as suffix rules, so which ones will be
8353 the special target @code{.SUFFIXES}). The default suffix list is:
8354 @code{.out}, @code{.a}, @code{.ln}, @code{.o}, @code{.c}, @code{.cc},
8355 @code{.C}, @code{.cpp}, @code{.p}, @code{.f}, @code{.F}, @code{.r}, @code{.y},
8356 @code{.l}, @code{.s}, @code{.S}, @code{.mod}, @code{.sym}, @code{.def},
8357 @code{.h}, @code{.info}, @code{.dvi}, @code{.tex}, @code{.texinfo},
8358 @code{.texi}, @code{.txinfo}, @code{.w}, @code{.ch} @code{.web},
8359 @code{.sh}, @code{.elc}, @code{.el}. All of the implicit rules
8445 running the assembler, @code{as}. The precise command is
8450 running the C preprocessor, @code{cpp}. The precise command is
8458 the linker (usually called @code{ld}) via the C compiler. The precise
8517 regardless of whether they produce C code or Ratfor code makes it
8518 impossible for @code{make} to determine automatically which of the two
8519 languages you are using in any particular case. If @code{make} is
8522 that is more common. If you are using Ratfor, make sure @code{make}
8536 @cindex @code{lint}, rule to run
8538 @file{@var{n}.ln} is made from @file{@var{n}.c} by running @code{lint}.
8540 The same command is used on the C code produced from
8620 variables such as @code{COMPILE.c}, @code{LINK.p}, and
8621 @code{PREPROCESS.S}, whose values contain the commands listed above.
8623 @code{make} follows the convention that the rule to compile a
8624 @file{.@var{x}} source file uses the variable @code{COMPILE.@var{x}}.
8626 file uses @code{LINK.@var{x}}; and the rule to preprocess a
8627 @file{.@var{x}} file uses @code{PREPROCESS.@var{x}}.
8631 @code{OUTPUT_OPTION}. @code{make} defines this variable either to
8635 as when using @code{VPATH} (@pxref{Directory Search}). However,
8637 files. If you use such a system, and use @code{VPATH}, some
8639 A possible workaround for this problem is to give @code{OUTPUT_OPTION}
8648 the makefile, with arguments to @code{make}, or in the environment to
8664 names of programs (like @code{CC}) and those that contain arguments for the
8665 programs (like @code{CFLAGS}). (The ``name of a program'' may also contain
8672 not be what are selected by @code{make} for your environment. To see the
8673 complete list of predefined variables for your instance of GNU @code{make} you
8680 @table @code
8729 Program to use to turn Lex grammars into source code; default @samp{lex}.
8734 Program to use to turn Yacc grammars into source code; default @samp{yacc}.
8739 Program to use to run lint on source code; default @samp{lint}.
8744 Program to use to compile Modula-2 source code; default @samp{m2c}.
8800 @table @code
8820 Extra flags to give to the RCS @code{co} program.
8833 Extra flags to give to the SCCS @code{get} program.
8868 first Yacc and then @code{cc}. Such a sequence is called a @dfn{chain}.
8871 special searching is required: @code{make} finds that the object file can
8880 @code{make} knows how to envision it as the missing link between
8882 called an @dfn{intermediate file}. Once @code{make} has decided to use the
8891 exist. If an ordinary file @var{b} does not exist, and @code{make}
8894 intermediate file, then @code{make} can leave well enough alone. It
8899 The second difference is that if @code{make} @emph{does} create @var{b}
8902 exist before @code{make} also does not exist after @code{make}.
8903 @code{make} reports the deletion to you by printing a @samp{rm -f}
8909 @code{.INTERMEDIATE}. This takes effect even if the file is mentioned
8917 special target @code{.SECONDARY}. When a file is secondary, @code{make}
8919 @code{make} does not automatically delete the file. Marking a file as
8923 as a prerequisite of the special target @code{.PRECIOUS} to preserve
8926 @cindex preserving with @code{.PRECIOUS}
8927 @cindex @code{.PRECIOUS} intermediate files
8931 Yacc and @code{cc}. Then both @file{foo.y} and @file{foo.c} are
8935 that @code{make} will not even consider such a ridiculous thing as making
8945 and linking with a single @code{cc} command. The optimized rule is used in
8989 @cindex @code{%}, in pattern rules
9028 commands. If a pattern rule has multiple targets, @code{make} knows that
9033 @code{make} worries only about giving commands and prerequisites to the file
9053 @code{make}. First, the rule that compiles @samp{.c} files into @samp{.o}
9094 This tells @code{make} that the command @samp{bison -d @var{x}.y} will
9117 What you do is use a special feature of @code{make}, the @dfn{automatic
9131 attempting to use @code{$@@} within the prerequisites list; this will
9132 not work. However, there is a special feature of GNU @code{make},
9138 @table @code
9180 the value of @code{$^} contains just one copy of the name. This list
9217 suffix. GNU @code{make} does this bizarre thing only for compatibility
9218 with other implementations of @code{make}. You should generally avoid
9242 semi-obsolete in GNU @code{make} since the functions @code{dir} and
9243 @code{notdir} can be used to get a similar effect (@pxref{File Name
9246 the output of the @code{dir} function. Here is a table of the variants:
9325 @w{``the variable @code{<}''} as we would write for ordinary variables
9326 such as @code{objects} and @code{CFLAGS}. We think this convention
9328 deep significance; @samp{$<} refers to the variable named @code{<} just
9329 as @samp{$(CFLAGS)} refers to the variable named @code{CFLAGS}.
9368 useful, but it can take a lot of time for @code{make} to think about them,
9372 Suppose the makefile mentions @file{foo.c}. For this target, @code{make}
9379 file, not an executable. If @code{make} did consider these possibilities,
9382 numerous that @code{make} would run very slowly if it had to consider
9385 To gain speed, we have put various constraints on the way @code{make}
9398 not exist, @code{make} will not even consider trying to make it as an
9401 remade from any other files; therefore, @code{make} can save time by not
9414 @file{foo.c}. Thus, @code{make} will not even consider trying to make
9485 this by writing a rule for the target @code{.DEFAULT}. Such a rule's
9488 there is no @code{.DEFAULT} rule unless you write one.
9490 If you use @code{.DEFAULT} with no commands or prerequisites:
9497 the commands previously stored for @code{.DEFAULT} are cleared.
9498 Then @code{make} acts as if you had never defined @code{.DEFAULT} at all.
9501 pattern rule or @code{.DEFAULT}, but you also do not want any commands
9514 @code{make}. Suffix rules are obsolete because pattern rules are more
9515 general and clearer. They are supported in GNU @code{make} for
9533 against a defined list of known suffixes. When @code{make} sees a rule
9535 rule. When @code{make} sees a rule whose target is two known suffixes
9540 @samp{.c.o}, @code{make} takes it to be a double-suffix rule with source
9578 target @code{.SUFFIXES}. You can add your own suffixes by writing a rule
9579 for @code{.SUFFIXES} that adds more prerequisites, as in:
9589 to them, write a rule for @code{.SUFFIXES} with no prerequisites. By
9591 @code{.SUFFIXES}. You can then write another rule to add the suffixes you
9605 The variable @code{SUFFIXES} is defined to the default list of suffixes
9606 before @code{make} reads any makefiles. You can change the list of suffixes
9607 with a rule for the special target @code{.SUFFIXES}, but that does not alter
9615 Here is the procedure @code{make} uses for searching for an implicit rule
9696 If no implicit rule applies, the rule for @code{.DEFAULT}, if any,
9698 @code{.DEFAULT} has. Otherwise, there are no commands for @var{t}.
9714 @chapter Using @code{make} to Update Archive Files
9718 @dfn{members}; they are maintained with the program @code{ar} and their
9734 prerequisite in @code{make}. You specify the member named @var{member} in
9744 syntax and cannot act directly on archive members. Only @code{ar} and
9747 use @code{ar}. For example, this rule says to create a member
9757 @samp{c} flag to @code{ar} is required if the archive file does not
9787 When @code{make} looks for an implicit rule for such a target, as a special
9810 Here @code{make} has envisioned the file @file{bar.o} as an intermediate
9818 archive member target @file{foo.a(dir/file.o)}, @code{make} will perform
9828 @code{%D} and @code{%F} may be useful.
9836 @cindex @code{__.SYMDEF}
9846 other members properly. This is done by running the @code{ranlib} program:
9864 running @code{ranlib}. The rules for updating the members are not shown
9868 This is not necessary when using the GNU @code{ar} program, which
9875 @cindex archive, and @code{-j}
9876 @cindex @code{-j}, and archive update
9879 @code{-j} switch; @pxref{Parallel, ,Parallel Execution}) and archives.
9880 If multiple @code{ar} commands run at the same time on the same archive
9883 Possibly a future version of @code{make} will provide a mechanism to
9886 makefiles to avoid this problem in some other way, or not use @code{-j}.
9893 @cindex @code{.a} (archives)
9897 Archive suffix rules are obsolete in GNU @code{make}, because pattern
9900 @code{make}s.
9928 In fact, this is just what @code{make} does when it sees a suffix rule
9934 of file, @code{make} also converts archive suffix rules to pattern rules
9940 @chapter Features of GNU @code{make}
9941 @cindex features of GNU @code{make}
9945 Here is a summary of the features of GNU @code{make}, for comparison
9946 with and credit to other versions of @code{make}. We consider the
9947 features of @code{make} in 4.2 BSD systems as a baseline. If you are
9949 features of @code{make} listed here, nor the ones in @ref{Missing}.
9951 Many features come from the version of @code{make} in System V.
9955 The @code{VPATH} variable and its special meaning.
9957 This feature exists in System V @code{make}, but is undocumented.
9958 It is documented in 4.3 BSD @code{make} (which says it mimics System V's
9959 @code{VPATH} feature).@refill
9971 Options passed through the variable @code{MAKEFLAGS} to recursive
9972 invocations of @code{make}.
9973 @xref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}.
9976 The automatic variable @code{$%} is set to the member name
9980 The automatic variables @code{$@@}, @code{$*}, @code{$<}, @code{$%},
9981 and @code{$?} have corresponding forms like @code{$(@@F)} and
9982 @code{$(@@D)}. We have generalized this to @code{$^} as an obvious
9991 ignored. In System V @code{make}, these options actually do something.
9994 Execution of recursive commands to run @code{make} via the variable
9995 @code{MAKE} even if @samp{-n}, @samp{-q} or @samp{-t} is specified.
9996 @xref{Recursion, ,Recursive Use of @code{make}}.
10000 Rules}. This feature is obsolete in GNU @code{make}, because the
10013 @code{make}. In some cases it is unclear exactly which versions inspired
10019 This has been implemented in several versions of @code{make}.
10025 This was implemented by Stu Feldman in his version of @code{make}
10027 AT&T Bell Labs in his @code{mk} program (where he terms it
10033 The automatic variable @code{$^} containing a list of all prerequisites
10036 @code{$+} is a simple extension of @code{$^}.
10039 The ``what if'' flag (@samp{-W} in GNU @code{make}) was (as far as we know)
10040 invented by Andrew Hume in @code{mk}.
10045 many incarnations of @code{make} and similar programs, though not in the
10051 This functionality was provided in GNU @code{make} by the
10052 @code{patsubst} function before the alternate syntax was implemented
10054 inspired whom, since GNU @code{make} had @code{patsubst} before SunOS
10065 4 @code{make}. @xref{Appending, , Appending More Text to Variables}.
10069 multiple members in a single archive file comes from SunOS 4 @code{make}.
10073 The @code{-include} directive to include makefiles with no error for a
10074 nonexistent file comes from SunOS 4 @code{make}. (But note that SunOS 4
10075 @code{make} does not allow multiple makefiles to be specified in one
10076 @code{-include} directive.) The same feature appears with the name
10077 @code{sinclude} in SGI @code{make} and perhaps others.
10080 The remaining features are inventions new in GNU @code{make}:
10089 @code{make}.
10096 variable @code{MAKE} to recursive @code{make} invocations.
10097 @xref{Recursion, ,Recursive Use of @code{make}}.
10104 Make verbatim variable definitions with @code{define}.
10108 Declare phony targets with the special target @code{.PHONY}.
10111 different syntax in his @code{mk} program. This seems to be a case of
10127 of @code{make}; it seems a natural extension derived from the features
10137 @xref{MAKEFILES Variable, ,The Variable @code{MAKEFILES}}.
10152 characters. In other versions of @code{make}, they must begin with
10156 Keep track of the current level of @code{make} recursion using the
10157 variable @code{MAKELEVEL}. @xref{Recursion, ,Recursive Use of @code{make}}.
10161 @code{MAKECMDGOALS}. @xref{Goals, ,Arguments to Specify the Goals}.
10167 Provide selective @code{vpath} search.
10176 System V @code{make} has a very, very limited form of this
10185 @code{make}.
10195 The @code{make} programs in various other systems support a few features
10196 that are not implemented in GNU @code{make}. The POSIX.2 standard
10197 (@cite{IEEE Standard 1003.2-1992}) which specifies @code{make} does not
10206 This feature was not put into GNU @code{make} because of the
10207 nonmodularity of putting knowledge into @code{make} of the internal
10213 have a special meaning to System V @code{make};
10221 In GNU @code{make}, this entire series of cases is handled by two
10227 In System V and 4.3 BSD @code{make}, files found by @code{VPATH} search
10233 In some Unix @code{make}s, the automatic variable @code{$*} appearing in
10236 imagine what went on in the minds of Unix @code{make} developers to do
10237 this; it is utterly inconsistent with the normal definition of @code{$*}.
10241 In some Unix @code{make}s, implicit rule search
10254 and Unix @code{make} will intuit that @file{foo.o} depends on
10258 @code{make} are well-defined (for GNU @code{make}, at least),
10262 GNU @code{make} does not include any built-in implicit rules for
10267 It appears that in SVR4 @code{make}, a suffix rule can be specified with
10280 easily rewritten to get the desired behavior in GNU @code{make}:
10287 Some versions of @code{make} invoke the shell with the @samp{-e} flag,
10303 and special variables which GNU @code{make} understands.
10308 Here is a summary of the directives GNU @code{make} recognizes:
10310 @table @code
10347 @xref{Override Directive, ,The @code{override} Directive}.
10351 Tell @code{make} to export all variables to child processes by default.@*
10352 @xref{Variables/Recursion, , Communicating Variables to a Sub-@code{make}}.
10360 Tell @code{make} whether or not to export a particular variable to child
10362 @xref{Variables/Recursion, , Communicating Variables to a Sub-@code{make}}.
10366 @xref{Selective Search, , The @code{vpath} Directive}.
10372 Remove all search paths previously specified in any @code{vpath}
10378 @table @code
10458 @xref{Wildcard Function, ,The Function @code{wildcard}}.
10462 does not contain any @code{.}, @code{..}, nor symlinks.@*
10467 does not contain any @code{.} or @code{..} components, but preserves
10473 When this function is evaluated, @code{make} generates a fatal error
10479 When this function is evaluated, @code{make} generates a warning with
10486 @xref{Shell Function, , The @code{shell} Function}.
10490 Return a string describing how the @code{make} variable @var{variable} was
10492 @xref{Origin Function, , The @code{origin} Function}.
10496 Return a string describing the flavor of the @code{make} variable
10498 @xref{Flavor Function, , The @code{flavor} Function}.
10504 @xref{Foreach Function, ,The @code{foreach} Function}.
10508 Evaluate the variable @var{var} replacing any references to @code{$(1)},
10509 @code{$(2)} with the first, second, etc.@: @var{param} values.@*
10510 @xref{Call Function, ,The @code{call} Function}.
10516 @xref{Eval Function, ,The @code{eval} Function}.
10522 @xref{Value Function, ,The @code{value} Function}.
10529 @table @code
10549 (@pxref{Archives}). The value of @code{$^} omits duplicate
10550 prerequisites, while @code{$+} retains them and preserves their order.
10558 The directory part and the file-within-directory part of @code{$@@}.
10562 The directory part and the file-within-directory part of @code{$*}.
10566 The directory part and the file-within-directory part of @code{$%}.
10570 The directory part and the file-within-directory part of @code{$<}.
10574 The directory part and the file-within-directory part of @code{$^}.
10578 The directory part and the file-within-directory part of @code{$+}.
10582 The directory part and the file-within-directory part of @code{$?}.
10585 These variables are used specially by GNU @code{make}:
10587 @table @code
10590 Makefiles to be read on every invocation of @code{make}.@*
10591 @xref{MAKEFILES Variable, ,The Variable @code{MAKEFILES}}.
10596 @xref{General Search, , @code{VPATH} Search Path for All Prerequisites}.
10601 You can set @code{SHELL} in the makefile to change the shell used to run
10602 commands. @xref{Execution, ,Command Execution}. The @code{SHELL}
10609 by @code{make}. This value takes precedence over the value of
10610 @code{SHELL}. @xref{Execution, ,MAKESHELL variable}.
10614 The name with which @code{make} was invoked.
10616 @xref{MAKE Variable, ,How the @code{MAKE} Variable Works}.
10620 The number of levels of recursion (sub-@code{make}s).@*
10625 The flags given to @code{make}. You can set this in the environment or
10627 @xref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}.
10629 It is @emph{never} appropriate to use @code{MAKEFLAGS} directly on a
10631 shell. Always allow recursive @code{make}'s to obtain these values
10636 The targets given to @code{make} on the command line. Setting this
10637 variable has no effect on the operation of @code{make}.@*
10643 @code{-C} options are processed, if any). Setting this variable has no
10644 effect on the operation of @code{make}.@*
10645 @xref{Recursion, ,Recursive Use of @code{make}}.
10649 The default list of suffixes before @code{make} reads any makefiles.
10652 Defines the naming of the libraries @code{make} searches for, and their
10662 @code{make}, and some information about what they mean and how to fix
10665 Sometimes @code{make} errors are not fatal, especially in the presence
10666 of a @code{-} prefix on a command script line, or the @code{-k} command
10668 @code{***}.
10680 These errors are not really @code{make} errors at all. They mean that a
10681 program that @code{make} invoked as part of a command script returned a
10682 non-0 error code (@samp{Error @var{NN}}), which @code{make} interprets
10686 If no @code{***} is attached to the message, then the subprocess failed
10687 but the rule in the makefile was prefixed with the @code{-} special
10688 character, so @code{make} ignored the error.
10692 This means that @code{make} could not understand much of anything about
10693 the command line it just read. GNU @code{make} looks for various kinds
10694 of separators (@code{:}, @code{=}, TAB characters, etc.) to help it
10701 TAB character. In this case, @code{make} will use the second form of
10710 @code{make} command (such as a variable assignment). Command scripts
10714 non-whitespace character; @code{make} interprets this to mean you left
10719 This means that @code{make} decided it needed to build a target, but
10732 command line, and @code{make} couldn't find any makefiles to read in.
10734 default goal and none was given on the command line. GNU @code{make}
10745 GNU @code{make} allows commands to be specified only once per target
10752 This means that @code{make} detected a loop in the dependency graph:
10757 This means you've defined a normal (recursive) @code{make} variable
10759 This is not allowed; either use simply-expanded variables (@code{:=}) or
10760 use the append operator (@code{+=}). @xref{Using Variables, ,How to Use
10779 the target doesn't contain a pattern character (@code{%}); and the
10781 pattern characters (@code{%})--only the first two parts should.
10785 This warning and the next are generated if @code{make} detects error
10787 sub-@code{make}s can communicate (@pxref{Options/Recursion,
10788 ,Communicating Options to a Sub-@code{make}}). This warning is
10789 generated if a recursive invocation of a @code{make} process is forced
10791 than one). This could happen, for example, if you set the @code{MAKE}
10793 sub-@code{make} doesn't communicate with other @code{make} processes and
10797 In order for @code{make} processes to communicate, the parent will pass
10799 child process isn't actually a @code{make}, the parent will only do this
10800 if it thinks the child is a @code{make}. The parent uses the normal
10801 algorithms to determine this (@pxref{MAKE Variable, ,How the @code{MAKE}
10803 doesn't know the child is a @code{make} process, then the child will
10813 Here is the makefile for the GNU @code{tar} program. This is a
10818 source file automatically created by the @code{testpad} program,
10821 If you type @samp{make} or @samp{make all}, then @code{make} creates
10825 If you type @samp{make install}, then @code{make} not only creates
10829 If you type @samp{make clean}, then @code{make} removes the @samp{.o}
10833 If you type @samp{make distclean}, then @code{make} not only removes
10838 @code{configure} program, which is provided in the @code{tar}
10841 If you type @samp{make realclean}, then @code{make} removes the same
10845 In addition, there are targets @code{shar} and @code{dist} that create