1 This is make.info, produced by makeinfo version 4.2 from make.texi.
3 INFO-DIR-SECTION GNU Packages
5 * Make: (make). Remake files automatically.
8 This file documents the GNU Make utility, which determines
9 automatically which pieces of a large program need to be recompiled,
10 and issues the commands to recompile them.
12 This is Edition 0.60, last updated 08 July 2002, of `The GNU Make
13 Manual', for `make', Version 3.80.
15 Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
16 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
18 Permission is granted to copy, distribute and/or modify this document
19 under the terms of the GNU Free Documentation License, Version 1.1 or
20 any later version published by the Free Software Foundation; with no
21 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
22 Texts. A copy of the license is included in the section entitled "GNU
23 Free Documentation License".
26 File: make.info, Node: Multiple Targets, Next: Multiple Rules, Prev: Special Targets, Up: Rules
28 Multiple Targets in a Rule
29 ==========================
31 A rule with multiple targets is equivalent to writing many rules,
32 each with one target, and all identical aside from that. The same
33 commands apply to all the targets, but their effects may vary because
34 you can substitute the actual target name into the command using `$@'.
35 The rule contributes the same prerequisites to all the targets also.
37 This is useful in two cases.
39 * You want just prerequisites, no commands. For example:
41 kbd.o command.o files.o: command.h
43 gives an additional prerequisite to each of the three object files
46 * Similar commands work for all the targets. The commands do not
47 need to be absolutely identical, since the automatic variable `$@'
48 can be used to substitute the particular target to be remade into
49 the commands (*note Automatic Variables: Automatic.). For example:
51 bigoutput littleoutput : text.g
52 generate text.g -$(subst output,,$@) > $@
57 generate text.g -big > bigoutput
59 generate text.g -little > littleoutput
61 Here we assume the hypothetical program `generate' makes two types
62 of output, one if given `-big' and one if given `-little'. *Note
63 Functions for String Substitution and Analysis: Text Functions,
64 for an explanation of the `subst' function.
66 Suppose you would like to vary the prerequisites according to the
67 target, much as the variable `$@' allows you to vary the commands. You
68 cannot do this with multiple targets in an ordinary rule, but you can
69 do it with a "static pattern rule". *Note Static Pattern Rules: Static
73 File: make.info, Node: Multiple Rules, Next: Static Pattern, Prev: Multiple Targets, Up: Rules
75 Multiple Rules for One Target
76 =============================
78 One file can be the target of several rules. All the prerequisites
79 mentioned in all the rules are merged into one list of prerequisites for
80 the target. If the target is older than any prerequisite from any rule,
81 the commands are executed.
83 There can only be one set of commands to be executed for a file. If
84 more than one rule gives commands for the same file, `make' uses the
85 last set given and prints an error message. (As a special case, if the
86 file's name begins with a dot, no error message is printed. This odd
87 behavior is only for compatibility with other implementations of
88 `make'... you should avoid using it). Occasionally it is useful to
89 have the same target invoke multiple commands which are defined in
90 different parts of your makefile; you can use "double-colon rules"
91 (*note Double-Colon::) for this.
93 An extra rule with just prerequisites can be used to give a few extra
94 prerequisites to many files at once. For example, makefiles often have
95 a variable, such as `objects', containing a list of all the compiler
96 output files in the system being made. An easy way to say that all of
97 them must be recompiled if `config.h' changes is to write the following:
101 bar.o : defs.h test.h
102 $(objects) : config.h
104 This could be inserted or taken out without changing the rules that
105 really specify how to make the object files, making it a convenient
106 form to use if you wish to add the additional prerequisite
109 Another wrinkle is that the additional prerequisites could be
110 specified with a variable that you set with a command argument to `make'
111 (*note Overriding Variables: Overriding.). For example,
114 $(objects) : $(extradeps)
116 means that the command `make extradeps=foo.h' will consider `foo.h' as
117 a prerequisite of each object file, but plain `make' will not.
119 If none of the explicit rules for a target has commands, then `make'
120 searches for an applicable implicit rule to find some commands *note
121 Using Implicit Rules: Implicit Rules.).
124 File: make.info, Node: Static Pattern, Next: Double-Colon, Prev: Multiple Rules, Up: Rules
129 "Static pattern rules" are rules which specify multiple targets and
130 construct the prerequisite names for each target based on the target
131 name. They are more general than ordinary rules with multiple targets
132 because the targets do not have to have identical prerequisites. Their
133 prerequisites must be _analogous_, but not necessarily _identical_.
137 * Static Usage:: The syntax of static pattern rules.
138 * Static versus Implicit:: When are they better than implicit rules?
141 File: make.info, Node: Static Usage, Next: Static versus Implicit, Prev: Static Pattern, Up: Static Pattern
143 Syntax of Static Pattern Rules
144 ------------------------------
146 Here is the syntax of a static pattern rule:
148 TARGETS ...: TARGET-PATTERN: PREREQ-PATTERNS ...
152 The TARGETS list specifies the targets that the rule applies to. The
153 targets can contain wildcard characters, just like the targets of
154 ordinary rules (*note Using Wildcard Characters in File Names:
157 The TARGET-PATTERN and PREREQ-PATTERNS say how to compute the
158 prerequisites of each target. Each target is matched against the
159 TARGET-PATTERN to extract a part of the target name, called the "stem".
160 This stem is substituted into each of the PREREQ-PATTERNS to make the
161 prerequisite names (one from each PREREQ-PATTERN).
163 Each pattern normally contains the character `%' just once. When the
164 TARGET-PATTERN matches a target, the `%' can match any part of the
165 target name; this part is called the "stem". The rest of the pattern
166 must match exactly. For example, the target `foo.o' matches the
167 pattern `%.o', with `foo' as the stem. The targets `foo.c' and
168 `foo.out' do not match that pattern.
170 The prerequisite names for each target are made by substituting the
171 stem for the `%' in each prerequisite pattern. For example, if one
172 prerequisite pattern is `%.c', then substitution of the stem `foo'
173 gives the prerequisite name `foo.c'. It is legitimate to write a
174 prerequisite pattern that does not contain `%'; then this prerequisite
175 is the same for all targets.
177 `%' characters in pattern rules can be quoted with preceding
178 backslashes (`\'). Backslashes that would otherwise quote `%'
179 characters can be quoted with more backslashes. Backslashes that quote
180 `%' characters or other backslashes are removed from the pattern before
181 it is compared to file names or has a stem substituted into it.
182 Backslashes that are not in danger of quoting `%' characters go
183 unmolested. For example, the pattern `the\%weird\\%pattern\\' has
184 `the%weird\' preceding the operative `%' character, and `pattern\\'
185 following it. The final two backslashes are left alone because they
186 cannot affect any `%' character.
188 Here is an example, which compiles each of `foo.o' and `bar.o' from
189 the corresponding `.c' file:
191 objects = foo.o bar.o
196 $(CC) -c $(CFLAGS) $< -o $@
198 Here `$<' is the automatic variable that holds the name of the
199 prerequisite and `$@' is the automatic variable that holds the name of
200 the target; see *Note Automatic Variables: Automatic.
202 Each target specified must match the target pattern; a warning is
203 issued for each target that does not. If you have a list of files,
204 only some of which will match the pattern, you can use the `filter'
205 function to remove nonmatching file names (*note Functions for String
206 Substitution and Analysis: Text Functions.):
208 files = foo.elc bar.o lose.o
210 $(filter %.o,$(files)): %.o: %.c
211 $(CC) -c $(CFLAGS) $< -o $@
212 $(filter %.elc,$(files)): %.elc: %.el
213 emacs -f batch-byte-compile $<
215 In this example the result of `$(filter %.o,$(files))' is `bar.o
216 lose.o', and the first static pattern rule causes each of these object
217 files to be updated by compiling the corresponding C source file. The
218 result of `$(filter %.elc,$(files))' is `foo.elc', so that file is made
221 Another example shows how to use `$*' in static pattern rules:
223 bigoutput littleoutput : %output : text.g
224 generate text.g -$* > $@
226 When the `generate' command is run, `$*' will expand to the stem,
227 either `big' or `little'.
230 File: make.info, Node: Static versus Implicit, Prev: Static Usage, Up: Static Pattern
232 Static Pattern Rules versus Implicit Rules
233 ------------------------------------------
235 A static pattern rule has much in common with an implicit rule
236 defined as a pattern rule (*note Defining and Redefining Pattern Rules:
237 Pattern Rules.). Both have a pattern for the target and patterns for
238 constructing the names of prerequisites. The difference is in how
239 `make' decides _when_ the rule applies.
241 An implicit rule _can_ apply to any target that matches its pattern,
242 but it _does_ apply only when the target has no commands otherwise
243 specified, and only when the prerequisites can be found. If more than
244 one implicit rule appears applicable, only one applies; the choice
245 depends on the order of rules.
247 By contrast, a static pattern rule applies to the precise list of
248 targets that you specify in the rule. It cannot apply to any other
249 target and it invariably does apply to each of the targets specified.
250 If two conflicting rules apply, and both have commands, that's an error.
252 The static pattern rule can be better than an implicit rule for these
255 * You may wish to override the usual implicit rule for a few files
256 whose names cannot be categorized syntactically but can be given
259 * If you cannot be sure of the precise contents of the directories
260 you are using, you may not be sure which other irrelevant files
261 might lead `make' to use the wrong implicit rule. The choice
262 might depend on the order in which the implicit rule search is
263 done. With static pattern rules, there is no uncertainty: each
264 rule applies to precisely the targets specified.
267 File: make.info, Node: Double-Colon, Next: Automatic Prerequisites, Prev: Static Pattern, Up: Rules
272 "Double-colon" rules are rules written with `::' instead of `:'
273 after the target names. They are handled differently from ordinary
274 rules when the same target appears in more than one rule.
276 When a target appears in multiple rules, all the rules must be the
277 same type: all ordinary, or all double-colon. If they are
278 double-colon, each of them is independent of the others. Each
279 double-colon rule's commands are executed if the target is older than
280 any prerequisites of that rule. If there are no prerequisites for that
281 rule, its commands are always executed (even if the target already
282 exists). This can result in executing none, any, or all of the
285 Double-colon rules with the same target are in fact completely
286 separate from one another. Each double-colon rule is processed
287 individually, just as rules with different targets are processed.
289 The double-colon rules for a target are executed in the order they
290 appear in the makefile. However, the cases where double-colon rules
291 really make sense are those where the order of executing the commands
294 Double-colon rules are somewhat obscure and not often very useful;
295 they provide a mechanism for cases in which the method used to update a
296 target differs depending on which prerequisite files caused the update,
297 and such cases are rare.
299 Each double-colon rule should specify commands; if it does not, an
300 implicit rule will be used if one applies. *Note Using Implicit Rules:
304 File: make.info, Node: Automatic Prerequisites, Prev: Double-Colon, Up: Rules
306 Generating Prerequisites Automatically
307 ======================================
309 In the makefile for a program, many of the rules you need to write
310 often say only that some object file depends on some header file. For
311 example, if `main.c' uses `defs.h' via an `#include', you would write:
315 You need this rule so that `make' knows that it must remake `main.o'
316 whenever `defs.h' changes. You can see that for a large program you
317 would have to write dozens of such rules in your makefile. And, you
318 must always be very careful to update the makefile every time you add
319 or remove an `#include'.
321 To avoid this hassle, most modern C compilers can write these rules
322 for you, by looking at the `#include' lines in the source files.
323 Usually this is done with the `-M' option to the compiler. For
324 example, the command:
328 generates the output:
330 main.o : main.c defs.h
332 Thus you no longer have to write all those rules yourself. The
333 compiler will do it for you.
335 Note that such a prerequisite constitutes mentioning `main.o' in a
336 makefile, so it can never be considered an intermediate file by implicit
337 rule search. This means that `make' won't ever remove the file after
338 using it; *note Chains of Implicit Rules: Chained Rules..
340 With old `make' programs, it was traditional practice to use this
341 compiler feature to generate prerequisites on demand with a command like
342 `make depend'. That command would create a file `depend' containing
343 all the automatically-generated prerequisites; then the makefile could
344 use `include' to read them in (*note Include::).
346 In GNU `make', the feature of remaking makefiles makes this practice
347 obsolete--you need never tell `make' explicitly to regenerate the
348 prerequisites, because it always regenerates any makefile that is out
349 of date. *Note Remaking Makefiles::.
351 The practice we recommend for automatic prerequisite generation is
352 to have one makefile corresponding to each source file. For each
353 source file `NAME.c' there is a makefile `NAME.d' which lists what
354 files the object file `NAME.o' depends on. That way only the source
355 files that have changed need to be rescanned to produce the new
358 Here is the pattern rule to generate a file of prerequisites (i.e.,
359 a makefile) called `NAME.d' from a C source file called `NAME.c':
363 $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
364 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
367 *Note Pattern Rules::, for information on defining pattern rules. The
368 `-e' flag to the shell causes it to exit immediately if the `$(CC)'
369 command (or any other command) fails (exits with a nonzero status).
371 With the GNU C compiler, you may wish to use the `-MM' flag instead
372 of `-M'. This omits prerequisites on system header files. *Note
373 Options Controlling the Preprocessor: (gcc.info)Preprocessor Options,
376 The purpose of the `sed' command is to translate (for example):
378 main.o : main.c defs.h
382 main.o main.d : main.c defs.h
384 This makes each `.d' file depend on all the source and header files
385 that the corresponding `.o' file depends on. `make' then knows it must
386 regenerate the prerequisites whenever any of the source or header files
389 Once you've defined the rule to remake the `.d' files, you then use
390 the `include' directive to read them all in. *Note Include::. For
393 sources = foo.c bar.c
395 include $(sources:.c=.d)
397 (This example uses a substitution variable reference to translate the
398 list of source files `foo.c bar.c' into a list of prerequisite
399 makefiles, `foo.d bar.d'. *Note Substitution Refs::, for full
400 information on substitution references.) Since the `.d' files are
401 makefiles like any others, `make' will remake them as necessary with no
402 further work from you. *Note Remaking Makefiles::.
404 Note that the `.d' files contain target definitions; you should be
405 sure to place the `include' directive _after_ the first, default target
406 in your makefiles or run the risk of having a random object file become
407 the default target. *Note How Make Works::.
410 File: make.info, Node: Commands, Next: Using Variables, Prev: Rules, Up: Top
412 Writing the Commands in Rules
413 *****************************
415 The commands of a rule consist of shell command lines to be executed
416 one by one. Each command line must start with a tab, except that the
417 first command line may be attached to the target-and-prerequisites line
418 with a semicolon in between. Blank lines and lines of just comments
419 may appear among the command lines; they are ignored. (But beware, an
420 apparently "blank" line that begins with a tab is _not_ blank! It is an
421 empty command; *note Empty Commands::.)
423 Users use many different shell programs, but commands in makefiles
424 are always interpreted by `/bin/sh' unless the makefile specifies
425 otherwise. *Note Command Execution: Execution.
427 The shell that is in use determines whether comments can be written
428 on command lines, and what syntax they use. When the shell is
429 `/bin/sh', a `#' starts a comment that extends to the end of the line.
430 The `#' does not have to be at the beginning of a line. Text on a line
431 before a `#' is not part of the comment.
435 * Echoing:: How to control when commands are echoed.
436 * Execution:: How commands are executed.
437 * Parallel:: How commands can be executed in parallel.
438 * Errors:: What happens after a command execution error.
439 * Interrupts:: What happens when a command is interrupted.
440 * Recursion:: Invoking `make' from makefiles.
441 * Sequences:: Defining canned sequences of commands.
442 * Empty Commands:: Defining useful, do-nothing commands.
445 File: make.info, Node: Echoing, Next: Execution, Prev: Commands, Up: Commands
450 Normally `make' prints each command line before it is executed. We
451 call this "echoing" because it gives the appearance that you are typing
452 the commands yourself.
454 When a line starts with `@', the echoing of that line is suppressed.
455 The `@' is discarded before the command is passed to the shell.
456 Typically you would use this for a command whose only effect is to print
457 something, such as an `echo' command to indicate progress through the
460 @echo About to make distribution files
462 When `make' is given the flag `-n' or `--just-print' it only echoes
463 commands, it won't execute them. *Note Summary of Options: Options
464 Summary. In this case and only this case, even the commands starting
465 with `@' are printed. This flag is useful for finding out which
466 commands `make' thinks are necessary without actually doing them.
468 The `-s' or `--silent' flag to `make' prevents all echoing, as if
469 all commands started with `@'. A rule in the makefile for the special
470 target `.SILENT' without prerequisites has the same effect (*note
471 Special Built-in Target Names: Special Targets.). `.SILENT' is
472 essentially obsolete since `@' is more flexible.
475 File: make.info, Node: Execution, Next: Parallel, Prev: Echoing, Up: Commands
480 When it is time to execute commands to update a target, they are
481 executed by making a new subshell for each line. (In practice, `make'
482 may take shortcuts that do not affect the results.)
484 *Please note:* this implies that shell commands such as `cd' that
485 set variables local to each process will not affect the following
486 command lines. (1) If you want to use `cd' to affect the next command,
487 put the two on a single line with a semicolon between them. Then
488 `make' will consider them a single command and pass them, together, to
489 a shell which will execute them in sequence. For example:
492 cd bar; gobble lose > ../foo
494 If you would like to split a single shell command into multiple
495 lines of text, you must use a backslash at the end of all but the last
496 subline. Such a sequence of lines is combined into a single line, by
497 deleting the backslash-newline sequences, before passing it to the
498 shell. Thus, the following is equivalent to the preceding example:
504 The program used as the shell is taken from the variable `SHELL'.
505 By default, the program `/bin/sh' is used.
507 On MS-DOS, if `SHELL' is not set, the value of the variable
508 `COMSPEC' (which is always set) is used instead.
510 The processing of lines that set the variable `SHELL' in Makefiles
511 is different on MS-DOS. The stock shell, `command.com', is
512 ridiculously limited in its functionality and many users of `make' tend
513 to install a replacement shell. Therefore, on MS-DOS, `make' examines
514 the value of `SHELL', and changes its behavior based on whether it
515 points to a Unix-style or DOS-style shell. This allows reasonable
516 functionality even if `SHELL' points to `command.com'.
518 If `SHELL' points to a Unix-style shell, `make' on MS-DOS
519 additionally checks whether that shell can indeed be found; if not, it
520 ignores the line that sets `SHELL'. In MS-DOS, GNU `make' searches for
521 the shell in the following places:
523 1. In the precise place pointed to by the value of `SHELL'. For
524 example, if the makefile specifies `SHELL = /bin/sh', `make' will
525 look in the directory `/bin' on the current drive.
527 2. In the current directory.
529 3. In each of the directories in the `PATH' variable, in order.
532 In every directory it examines, `make' will first look for the
533 specific file (`sh' in the example above). If this is not found, it
534 will also look in that directory for that file with one of the known
535 extensions which identify executable files. For example `.exe',
536 `.com', `.bat', `.btm', `.sh', and some others.
538 If any of these attempts is successful, the value of `SHELL' will be
539 set to the full pathname of the shell as found. However, if none of
540 these is found, the value of `SHELL' will not be changed, and thus the
541 line that sets it will be effectively ignored. This is so `make' will
542 only support features specific to a Unix-style shell if such a shell is
543 actually installed on the system where `make' runs.
545 Note that this extended search for the shell is limited to the cases
546 where `SHELL' is set from the Makefile; if it is set in the environment
547 or command line, you are expected to set it to the full pathname of the
548 shell, exactly as things are on Unix.
550 The effect of the above DOS-specific processing is that a Makefile
551 that says `SHELL = /bin/sh' (as many Unix makefiles do), will work on
552 MS-DOS unaltered if you have e.g. `sh.exe' installed in some directory
555 Unlike most variables, the variable `SHELL' is never set from the
556 environment. This is because the `SHELL' environment variable is used
557 to specify your personal choice of shell program for interactive use.
558 It would be very bad for personal choices like this to affect the
559 functioning of makefiles. *Note Variables from the Environment:
560 Environment. However, on MS-DOS and MS-Windows the value of `SHELL' in
561 the environment *is* used, since on those systems most users do not set
562 this variable, and therefore it is most likely set specifically to be
563 used by `make'. On MS-DOS, if the setting of `SHELL' is not suitable
564 for `make', you can set the variable `MAKESHELL' to the shell that
565 `make' should use; this will override the value of `SHELL'.
567 ---------- Footnotes ----------
569 (1) On MS-DOS, the value of current working directory is *global*,
570 so changing it _will_ affect the following command lines on those
574 File: make.info, Node: Parallel, Next: Errors, Prev: Execution, Up: Commands
579 GNU `make' knows how to execute several commands at once. Normally,
580 `make' will execute only one command at a time, waiting for it to
581 finish before executing the next. However, the `-j' or `--jobs' option
582 tells `make' to execute many commands simultaneously.
584 On MS-DOS, the `-j' option has no effect, since that system doesn't
585 support multi-processing.
587 If the `-j' option is followed by an integer, this is the number of
588 commands to execute at once; this is called the number of "job slots".
589 If there is nothing looking like an integer after the `-j' option,
590 there is no limit on the number of job slots. The default number of job
591 slots is one, which means serial execution (one thing at a time).
593 One unpleasant consequence of running several commands
594 simultaneously is that output generated by the commands appears
595 whenever each command sends it, so messages from different commands may
598 Another problem is that two processes cannot both take input from the
599 same device; so to make sure that only one command tries to take input
600 from the terminal at once, `make' will invalidate the standard input
601 streams of all but one running command. This means that attempting to
602 read from standard input will usually be a fatal error (a `Broken pipe'
603 signal) for most child processes if there are several.
605 It is unpredictable which command will have a valid standard input
606 stream (which will come from the terminal, or wherever you redirect the
607 standard input of `make'). The first command run will always get it
608 first, and the first command started after that one finishes will get
611 We will change how this aspect of `make' works if we find a better
612 alternative. In the mean time, you should not rely on any command using
613 standard input at all if you are using the parallel execution feature;
614 but if you are not using this feature, then standard input works
615 normally in all commands.
617 Finally, handling recursive `make' invocations raises issues. For
618 more information on this, see *Note Communicating Options to a
619 Sub-`make': Options/Recursion.
621 If a command fails (is killed by a signal or exits with a nonzero
622 status), and errors are not ignored for that command (*note Errors in
623 Commands: Errors.), the remaining command lines to remake the same
624 target will not be run. If a command fails and the `-k' or
625 `--keep-going' option was not given (*note Summary of Options: Options
626 Summary.), `make' aborts execution. If make terminates for any reason
627 (including a signal) with child processes running, it waits for them to
628 finish before actually exiting.
630 When the system is heavily loaded, you will probably want to run
631 fewer jobs than when it is lightly loaded. You can use the `-l' option
632 to tell `make' to limit the number of jobs to run at once, based on the
633 load average. The `-l' or `--max-load' option is followed by a
634 floating-point number. For example,
638 will not let `make' start more than one job if the load average is
639 above 2.5. The `-l' option with no following number removes the load
640 limit, if one was given with a previous `-l' option.
642 More precisely, when `make' goes to start up a job, and it already
643 has at least one job running, it checks the current load average; if it
644 is not lower than the limit given with `-l', `make' waits until the load
645 average goes below that limit, or until all the other jobs finish.
647 By default, there is no load limit.
650 File: make.info, Node: Errors, Next: Interrupts, Prev: Parallel, Up: Commands
655 After each shell command returns, `make' looks at its exit status.
656 If the command completed successfully, the next command line is executed
657 in a new shell; after the last command line is finished, the rule is
660 If there is an error (the exit status is nonzero), `make' gives up on
661 the current rule, and perhaps on all rules.
663 Sometimes the failure of a certain command does not indicate a
664 problem. For example, you may use the `mkdir' command to ensure that a
665 directory exists. If the directory already exists, `mkdir' will report
666 an error, but you probably want `make' to continue regardless.
668 To ignore errors in a command line, write a `-' at the beginning of
669 the line's text (after the initial tab). The `-' is discarded before
670 the command is passed to the shell for execution.
677 This causes `rm' to continue even if it is unable to remove a file.
679 When you run `make' with the `-i' or `--ignore-errors' flag, errors
680 are ignored in all commands of all rules. A rule in the makefile for
681 the special target `.IGNORE' has the same effect, if there are no
682 prerequisites. These ways of ignoring errors are obsolete because `-'
685 When errors are to be ignored, because of either a `-' or the `-i'
686 flag, `make' treats an error return just like success, except that it
687 prints out a message that tells you the status code the command exited
688 with, and says that the error has been ignored.
690 When an error happens that `make' has not been told to ignore, it
691 implies that the current target cannot be correctly remade, and neither
692 can any other that depends on it either directly or indirectly. No
693 further commands will be executed for these targets, since their
694 preconditions have not been achieved.
696 Normally `make' gives up immediately in this circumstance, returning
697 a nonzero status. However, if the `-k' or `--keep-going' flag is
698 specified, `make' continues to consider the other prerequisites of the
699 pending targets, remaking them if necessary, before it gives up and
700 returns nonzero status. For example, after an error in compiling one
701 object file, `make -k' will continue compiling other object files even
702 though it already knows that linking them will be impossible. *Note
703 Summary of Options: Options Summary.
705 The usual behavior assumes that your purpose is to get the specified
706 targets up to date; once `make' learns that this is impossible, it
707 might as well report the failure immediately. The `-k' option says
708 that the real purpose is to test as many of the changes made in the
709 program as possible, perhaps to find several independent problems so
710 that you can correct them all before the next attempt to compile. This
711 is why Emacs' `compile' command passes the `-k' flag by default.
713 Usually when a command fails, if it has changed the target file at
714 all, the file is corrupted and cannot be used--or at least it is not
715 completely updated. Yet the file's time stamp says that it is now up to
716 date, so the next time `make' runs, it will not try to update that
717 file. The situation is just the same as when the command is killed by a
718 signal; *note Interrupts::. So generally the right thing to do is to
719 delete the target file if the command fails after beginning to change
720 the file. `make' will do this if `.DELETE_ON_ERROR' appears as a
721 target. This is almost always what you want `make' to do, but it is
722 not historical practice; so for compatibility, you must explicitly
726 File: make.info, Node: Interrupts, Next: Recursion, Prev: Errors, Up: Commands
728 Interrupting or Killing `make'
729 ==============================
731 If `make' gets a fatal signal while a command is executing, it may
732 delete the target file that the command was supposed to update. This is
733 done if the target file's last-modification time has changed since
734 `make' first checked it.
736 The purpose of deleting the target is to make sure that it is remade
737 from scratch when `make' is next run. Why is this? Suppose you type
738 `Ctrl-c' while a compiler is running, and it has begun to write an
739 object file `foo.o'. The `Ctrl-c' kills the compiler, resulting in an
740 incomplete file whose last-modification time is newer than the source
741 file `foo.c'. But `make' also receives the `Ctrl-c' signal and deletes
742 this incomplete file. If `make' did not do this, the next invocation
743 of `make' would think that `foo.o' did not require updating--resulting
744 in a strange error message from the linker when it tries to link an
745 object file half of which is missing.
747 You can prevent the deletion of a target file in this way by making
748 the special target `.PRECIOUS' depend on it. Before remaking a target,
749 `make' checks to see whether it appears on the prerequisites of
750 `.PRECIOUS', and thereby decides whether the target should be deleted
751 if a signal happens. Some reasons why you might do this are that the
752 target is updated in some atomic fashion, or exists only to record a
753 modification-time (its contents do not matter), or must exist at all
754 times to prevent other sorts of trouble.
757 File: make.info, Node: Recursion, Next: Sequences, Prev: Interrupts, Up: Commands
759 Recursive Use of `make'
760 =======================
762 Recursive use of `make' means using `make' as a command in a
763 makefile. This technique is useful when you want separate makefiles for
764 various subsystems that compose a larger system. For example, suppose
765 you have a subdirectory `subdir' which has its own makefile, and you
766 would like the containing directory's makefile to run `make' on the
767 subdirectory. You can do it by writing this:
772 or, equivalently, this (*note Summary of Options: Options Summary.):
777 You can write recursive `make' commands just by copying this example,
778 but there are many things to know about how they work and why, and about
779 how the sub-`make' relates to the top-level `make'. You may also find
780 it useful to declare targets that invoke recursive `make' commands as
781 `.PHONY' (for more discussion on when this is useful, see *Note Phony
784 For your convenience, GNU `make' sets the variable `CURDIR' to the
785 pathname of the current working directory for you. If `-C' is in
786 effect, it will contain the path of the new directory, not the
787 original. The value has the same precedence it would have if it were
788 set in the makefile (by default, an environment variable `CURDIR' will
789 not override this value). Note that setting this variable has no
790 effect on the operation of `make'
794 * MAKE Variable:: The special effects of using `$(MAKE)'.
795 * Variables/Recursion:: How to communicate variables to a sub-`make'.
796 * Options/Recursion:: How to communicate options to a sub-`make'.
797 * -w Option:: How the `-w' or `--print-directory' option
798 helps debug use of recursive `make' commands.
801 File: make.info, Node: MAKE Variable, Next: Variables/Recursion, Prev: Recursion, Up: Recursion
803 How the `MAKE' Variable Works
804 -----------------------------
806 Recursive `make' commands should always use the variable `MAKE', not
807 the explicit command name `make', as shown here:
812 The value of this variable is the file name with which `make' was
813 invoked. If this file name was `/bin/make', then the command executed
814 is `cd subdir && /bin/make'. If you use a special version of `make' to
815 run the top-level makefile, the same special version will be executed
816 for recursive invocations.
818 As a special feature, using the variable `MAKE' in the commands of a
819 rule alters the effects of the `-t' (`--touch'), `-n' (`--just-print'),
820 or `-q' (`--question') option. Using the `MAKE' variable has the same
821 effect as using a `+' character at the beginning of the command line.
822 *Note Instead of Executing the Commands: Instead of Execution.
824 Consider the command `make -t' in the above example. (The `-t'
825 option marks targets as up to date without actually running any
826 commands; see *Note Instead of Execution::.) Following the usual
827 definition of `-t', a `make -t' command in the example would create a
828 file named `subsystem' and do nothing else. What you really want it to
829 do is run `cd subdir && make -t'; but that would require executing the
830 command, and `-t' says not to execute commands.
832 The special feature makes this do what you want: whenever a command
833 line of a rule contains the variable `MAKE', the flags `-t', `-n' and
834 `-q' do not apply to that line. Command lines containing `MAKE' are
835 executed normally despite the presence of a flag that causes most
836 commands not to be run. The usual `MAKEFLAGS' mechanism passes the
837 flags to the sub-`make' (*note Communicating Options to a Sub-`make':
838 Options/Recursion.), so your request to touch the files, or print the
839 commands, is propagated to the subsystem.
842 File: make.info, Node: Variables/Recursion, Next: Options/Recursion, Prev: MAKE Variable, Up: Recursion
844 Communicating Variables to a Sub-`make'
845 ---------------------------------------
847 Variable values of the top-level `make' can be passed to the
848 sub-`make' through the environment by explicit request. These
849 variables are defined in the sub-`make' as defaults, but do not
850 override what is specified in the makefile used by the sub-`make'
851 makefile unless you use the `-e' switch (*note Summary of Options:
854 To pass down, or "export", a variable, `make' adds the variable and
855 its value to the environment for running each command. The sub-`make',
856 in turn, uses the environment to initialize its table of variable
857 values. *Note Variables from the Environment: Environment.
859 Except by explicit request, `make' exports a variable only if it is
860 either defined in the environment initially or set on the command line,
861 and if its name consists only of letters, numbers, and underscores.
862 Some shells cannot cope with environment variable names consisting of
863 characters other than letters, numbers, and underscores.
865 The special variables `SHELL' and `MAKEFLAGS' are always exported
866 (unless you unexport them). `MAKEFILES' is exported if you set it to
869 `make' automatically passes down variable values that were defined
870 on the command line, by putting them in the `MAKEFLAGS' variable.
871 *Note Options/Recursion::.
873 Variables are _not_ normally passed down if they were created by
874 default by `make' (*note Variables Used by Implicit Rules: Implicit
875 Variables.). The sub-`make' will define these for itself.
877 If you want to export specific variables to a sub-`make', use the
878 `export' directive, like this:
882 If you want to _prevent_ a variable from being exported, use the
883 `unexport' directive, like this:
885 unexport VARIABLE ...
887 In both of these forms, the arguments to `export' and `unexport' are
888 expanded, and so could be variables or functions which expand to a
889 (list of) variable names to be (un)exported.
891 As a convenience, you can define a variable and export it at the same
894 export VARIABLE = value
896 has the same result as:
903 export VARIABLE := value
905 has the same result as:
912 export VARIABLE += value
919 *Note Appending More Text to Variables: Appending.
921 You may notice that the `export' and `unexport' directives work in
922 `make' in the same way they work in the shell, `sh'.
924 If you want all variables to be exported by default, you can use
929 This tells `make' that variables which are not explicitly mentioned in
930 an `export' or `unexport' directive should be exported. Any variable
931 given in an `unexport' directive will still _not_ be exported. If you
932 use `export' by itself to export variables by default, variables whose
933 names contain characters other than alphanumerics and underscores will
934 not be exported unless specifically mentioned in an `export' directive.
936 The behavior elicited by an `export' directive by itself was the
937 default in older versions of GNU `make'. If your makefiles depend on
938 this behavior and you want to be compatible with old versions of
939 `make', you can write a rule for the special target
940 `.EXPORT_ALL_VARIABLES' instead of using the `export' directive. This
941 will be ignored by old `make's, while the `export' directive will cause
944 Likewise, you can use `unexport' by itself to tell `make' _not_ to
945 export variables by default. Since this is the default behavior, you
946 would only need to do this if `export' had been used by itself earlier
947 (in an included makefile, perhaps). You *cannot* use `export' and
948 `unexport' by themselves to have variables exported for some commands
949 and not for others. The last `export' or `unexport' directive that
950 appears by itself determines the behavior for the entire run of `make'.
952 As a special feature, the variable `MAKELEVEL' is changed when it is
953 passed down from level to level. This variable's value is a string
954 which is the depth of the level as a decimal number. The value is `0'
955 for the top-level `make'; `1' for a sub-`make', `2' for a
956 sub-sub-`make', and so on. The incrementation happens when `make' sets
957 up the environment for a command.
959 The main use of `MAKELEVEL' is to test it in a conditional directive
960 (*note Conditional Parts of Makefiles: Conditionals.); this way you can
961 write a makefile that behaves one way if run recursively and another
962 way if run directly by you.
964 You can use the variable `MAKEFILES' to cause all sub-`make'
965 commands to use additional makefiles. The value of `MAKEFILES' is a
966 whitespace-separated list of file names. This variable, if defined in
967 the outer-level makefile, is passed down through the environment; then
968 it serves as a list of extra makefiles for the sub-`make' to read
969 before the usual or specified ones. *Note The Variable `MAKEFILES':
973 File: make.info, Node: Options/Recursion, Next: -w Option, Prev: Variables/Recursion, Up: Recursion
975 Communicating Options to a Sub-`make'
976 -------------------------------------
978 Flags such as `-s' and `-k' are passed automatically to the
979 sub-`make' through the variable `MAKEFLAGS'. This variable is set up
980 automatically by `make' to contain the flag letters that `make'
981 received. Thus, if you do `make -ks' then `MAKEFLAGS' gets the value
984 As a consequence, every sub-`make' gets a value for `MAKEFLAGS' in
985 its environment. In response, it takes the flags from that value and
986 processes them as if they had been given as arguments. *Note Summary
987 of Options: Options Summary.
989 Likewise variables defined on the command line are passed to the
990 sub-`make' through `MAKEFLAGS'. Words in the value of `MAKEFLAGS' that
991 contain `=', `make' treats as variable definitions just as if they
992 appeared on the command line. *Note Overriding Variables: Overriding.
994 The options `-C', `-f', `-o', and `-W' are not put into `MAKEFLAGS';
995 these options are not passed down.
997 The `-j' option is a special case (*note Parallel Execution:
998 Parallel.). If you set it to some numeric value `N' and your operating
999 system supports it (most any UNIX system will; others typically won't),
1000 the parent `make' and all the sub-`make's will communicate to ensure
1001 that there are only `N' jobs running at the same time between them all.
1002 Note that any job that is marked recursive (*note Instead of Executing
1003 the Commands: Instead of Execution.) doesn't count against the total
1004 jobs (otherwise we could get `N' sub-`make's running and have no slots
1005 left over for any real work!)
1007 If your operating system doesn't support the above communication,
1008 then `-j 1' is always put into `MAKEFLAGS' instead of the value you
1009 specified. This is because if the `-j' option were passed down to
1010 sub-`make's, you would get many more jobs running in parallel than you
1011 asked for. If you give `-j' with no numeric argument, meaning to run
1012 as many jobs as possible in parallel, this is passed down, since
1013 multiple infinities are no more than one.
1015 If you do not want to pass the other flags down, you must change the
1016 value of `MAKEFLAGS', like this:
1019 cd subdir && $(MAKE) MAKEFLAGS=
1021 The command line variable definitions really appear in the variable
1022 `MAKEOVERRIDES', and `MAKEFLAGS' contains a reference to this variable.
1023 If you do want to pass flags down normally, but don't want to pass
1024 down the command line variable definitions, you can reset
1025 `MAKEOVERRIDES' to empty, like this:
1029 This is not usually useful to do. However, some systems have a small
1030 fixed limit on the size of the environment, and putting so much
1031 information into the value of `MAKEFLAGS' can exceed it. If you see
1032 the error message `Arg list too long', this may be the problem. (For
1033 strict compliance with POSIX.2, changing `MAKEOVERRIDES' does not
1034 affect `MAKEFLAGS' if the special target `.POSIX' appears in the
1035 makefile. You probably do not care about this.)
1037 A similar variable `MFLAGS' exists also, for historical
1038 compatibility. It has the same value as `MAKEFLAGS' except that it
1039 does not contain the command line variable definitions, and it always
1040 begins with a hyphen unless it is empty (`MAKEFLAGS' begins with a
1041 hyphen only when it begins with an option that has no single-letter
1042 version, such as `--warn-undefined-variables'). `MFLAGS' was
1043 traditionally used explicitly in the recursive `make' command, like
1047 cd subdir && $(MAKE) $(MFLAGS)
1049 but now `MAKEFLAGS' makes this usage redundant. If you want your
1050 makefiles to be compatible with old `make' programs, use this
1051 technique; it will work fine with more modern `make' versions too.
1053 The `MAKEFLAGS' variable can also be useful if you want to have
1054 certain options, such as `-k' (*note Summary of Options: Options
1055 Summary.), set each time you run `make'. You simply put a value for
1056 `MAKEFLAGS' in your environment. You can also set `MAKEFLAGS' in a
1057 makefile, to specify additional flags that should also be in effect for
1058 that makefile. (Note that you cannot use `MFLAGS' this way. That
1059 variable is set only for compatibility; `make' does not interpret a
1060 value you set for it in any way.)
1062 When `make' interprets the value of `MAKEFLAGS' (either from the
1063 environment or from a makefile), it first prepends a hyphen if the value
1064 does not already begin with one. Then it chops the value into words
1065 separated by blanks, and parses these words as if they were options
1066 given on the command line (except that `-C', `-f', `-h', `-o', `-W',
1067 and their long-named versions are ignored; and there is no error for an
1070 If you do put `MAKEFLAGS' in your environment, you should be sure not
1071 to include any options that will drastically affect the actions of
1072 `make' and undermine the purpose of makefiles and of `make' itself.
1073 For instance, the `-t', `-n', and `-q' options, if put in one of these
1074 variables, could have disastrous consequences and would certainly have
1075 at least surprising and probably annoying effects.
1078 File: make.info, Node: -w Option, Prev: Options/Recursion, Up: Recursion
1080 The `--print-directory' Option
1081 ------------------------------
1083 If you use several levels of recursive `make' invocations, the `-w'
1084 or `--print-directory' option can make the output a lot easier to
1085 understand by showing each directory as `make' starts processing it and
1086 as `make' finishes processing it. For example, if `make -w' is run in
1087 the directory `/u/gnu/make', `make' will print a line of the form:
1089 make: Entering directory `/u/gnu/make'.
1091 before doing anything else, and a line of the form:
1093 make: Leaving directory `/u/gnu/make'.
1095 when processing is completed.
1097 Normally, you do not need to specify this option because `make' does
1098 it for you: `-w' is turned on automatically when you use the `-C'
1099 option, and in sub-`make's. `make' will not automatically turn on `-w'
1100 if you also use `-s', which says to be silent, or if you use
1101 `--no-print-directory' to explicitly disable it.