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: Match-Anything Rules, Next: Canceling Rules, Prev: Pattern Match, Up: Pattern Rules
28 Match-Anything Pattern Rules
29 ----------------------------
31 When a pattern rule's target is just `%', it matches any file name
32 whatever. We call these rules "match-anything" rules. They are very
33 useful, but it can take a lot of time for `make' to think about them,
34 because it must consider every such rule for each file name listed
35 either as a target or as a prerequisite.
37 Suppose the makefile mentions `foo.c'. For this target, `make'
38 would have to consider making it by linking an object file `foo.c.o',
39 or by C compilation-and-linking in one step from `foo.c.c', or by
40 Pascal compilation-and-linking from `foo.c.p', and many other
43 We know these possibilities are ridiculous since `foo.c' is a C
44 source file, not an executable. If `make' did consider these
45 possibilities, it would ultimately reject them, because files such as
46 `foo.c.o' and `foo.c.p' would not exist. But these possibilities are so
47 numerous that `make' would run very slowly if it had to consider them.
49 To gain speed, we have put various constraints on the way `make'
50 considers match-anything rules. There are two different constraints
51 that can be applied, and each time you define a match-anything rule you
52 must choose one or the other for that rule.
54 One choice is to mark the match-anything rule as "terminal" by
55 defining it with a double colon. When a rule is terminal, it does not
56 apply unless its prerequisites actually exist. Prerequisites that
57 could be made with other implicit rules are not good enough. In other
58 words, no further chaining is allowed beyond a terminal rule.
60 For example, the built-in implicit rules for extracting sources from
61 RCS and SCCS files are terminal; as a result, if the file `foo.c,v' does
62 not exist, `make' will not even consider trying to make it as an
63 intermediate file from `foo.c,v.o' or from `RCS/SCCS/s.foo.c,v'. RCS
64 and SCCS files are generally ultimate source files, which should not be
65 remade from any other files; therefore, `make' can save time by not
66 looking for ways to remake them.
68 If you do not mark the match-anything rule as terminal, then it is
69 nonterminal. A nonterminal match-anything rule cannot apply to a file
70 name that indicates a specific type of data. A file name indicates a
71 specific type of data if some non-match-anything implicit rule target
74 For example, the file name `foo.c' matches the target for the pattern
75 rule `%.c : %.y' (the rule to run Yacc). Regardless of whether this
76 rule is actually applicable (which happens only if there is a file
77 `foo.y'), the fact that its target matches is enough to prevent
78 consideration of any nonterminal match-anything rules for the file
79 `foo.c'. Thus, `make' will not even consider trying to make `foo.c' as
80 an executable file from `foo.c.o', `foo.c.c', `foo.c.p', etc.
82 The motivation for this constraint is that nonterminal match-anything
83 rules are used for making files containing specific types of data (such
84 as executable files) and a file name with a recognized suffix indicates
85 some other specific type of data (such as a C source file).
87 Special built-in dummy pattern rules are provided solely to recognize
88 certain file names so that nonterminal match-anything rules will not be
89 considered. These dummy rules have no prerequisites and no commands,
90 and they are ignored for all other purposes. For example, the built-in
95 exists to make sure that Pascal source files such as `foo.p' match a
96 specific target pattern and thereby prevent time from being wasted
97 looking for `foo.p.o' or `foo.p.c'.
99 Dummy pattern rules such as the one for `%.p' are made for every
100 suffix listed as valid for use in suffix rules (*note Old-Fashioned
101 Suffix Rules: Suffix Rules.).
104 File: make.info, Node: Canceling Rules, Prev: Match-Anything Rules, Up: Pattern Rules
106 Canceling Implicit Rules
107 ------------------------
109 You can override a built-in implicit rule (or one you have defined
110 yourself) by defining a new pattern rule with the same target and
111 prerequisites, but different commands. When the new rule is defined,
112 the built-in one is replaced. The new rule's position in the sequence
113 of implicit rules is determined by where you write the new rule.
115 You can cancel a built-in implicit rule by defining a pattern rule
116 with the same target and prerequisites, but no commands. For example,
117 the following would cancel the rule that runs the assembler:
122 File: make.info, Node: Last Resort, Next: Suffix Rules, Prev: Pattern Rules, Up: Implicit Rules
124 Defining Last-Resort Default Rules
125 ==================================
127 You can define a last-resort implicit rule by writing a terminal
128 match-anything pattern rule with no prerequisites (*note Match-Anything
129 Rules::). This is just like any other pattern rule; the only thing
130 special about it is that it will match any target. So such a rule's
131 commands are used for all targets and prerequisites that have no
132 commands of their own and for which no other implicit rule applies.
134 For example, when testing a makefile, you might not care if the
135 source files contain real data, only that they exist. Then you might
141 to cause all the source files needed (as prerequisites) to be created
144 You can instead define commands to be used for targets for which
145 there are no rules at all, even ones which don't specify commands. You
146 do this by writing a rule for the target `.DEFAULT'. Such a rule's
147 commands are used for all prerequisites which do not appear as targets
148 in any explicit rule, and for which no implicit rule applies.
149 Naturally, there is no `.DEFAULT' rule unless you write one.
151 If you use `.DEFAULT' with no commands or prerequisites:
155 the commands previously stored for `.DEFAULT' are cleared. Then `make'
156 acts as if you had never defined `.DEFAULT' at all.
158 If you do not want a target to get the commands from a match-anything
159 pattern rule or `.DEFAULT', but you also do not want any commands to be
160 run for the target, you can give it empty commands (*note Defining
161 Empty Commands: Empty Commands.).
163 You can use a last-resort rule to override part of another makefile.
164 *Note Overriding Part of Another Makefile: Overriding Makefiles.
167 File: make.info, Node: Suffix Rules, Next: Implicit Rule Search, Prev: Last Resort, Up: Implicit Rules
169 Old-Fashioned Suffix Rules
170 ==========================
172 "Suffix rules" are the old-fashioned way of defining implicit rules
173 for `make'. Suffix rules are obsolete because pattern rules are more
174 general and clearer. They are supported in GNU `make' for
175 compatibility with old makefiles. They come in two kinds:
176 "double-suffix" and "single-suffix".
178 A double-suffix rule is defined by a pair of suffixes: the target
179 suffix and the source suffix. It matches any file whose name ends with
180 the target suffix. The corresponding implicit prerequisite is made by
181 replacing the target suffix with the source suffix in the file name. A
182 two-suffix rule whose target and source suffixes are `.o' and `.c' is
183 equivalent to the pattern rule `%.o : %.c'.
185 A single-suffix rule is defined by a single suffix, which is the
186 source suffix. It matches any file name, and the corresponding implicit
187 prerequisite name is made by appending the source suffix. A
188 single-suffix rule whose source suffix is `.c' is equivalent to the
189 pattern rule `% : %.c'.
191 Suffix rule definitions are recognized by comparing each rule's
192 target against a defined list of known suffixes. When `make' sees a
193 rule whose target is a known suffix, this rule is considered a
194 single-suffix rule. When `make' sees a rule whose target is two known
195 suffixes concatenated, this rule is taken as a double-suffix rule.
197 For example, `.c' and `.o' are both on the default list of known
198 suffixes. Therefore, if you define a rule whose target is `.c.o',
199 `make' takes it to be a double-suffix rule with source suffix `.c' and
200 target suffix `.o'. Here is the old-fashioned way to define the rule
201 for compiling a C source file:
204 $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
206 Suffix rules cannot have any prerequisites of their own. If they
207 have any, they are treated as normal files with funny names, not as
208 suffix rules. Thus, the rule:
211 $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
213 tells how to make the file `.c.o' from the prerequisite file `foo.h',
214 and is not at all like the pattern rule:
217 $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
219 which tells how to make `.o' files from `.c' files, and makes all `.o'
220 files using this pattern rule also depend on `foo.h'.
222 Suffix rules with no commands are also meaningless. They do not
223 remove previous rules as do pattern rules with no commands (*note
224 Canceling Implicit Rules: Canceling Rules.). They simply enter the
225 suffix or pair of suffixes concatenated as a target in the data base.
227 The known suffixes are simply the names of the prerequisites of the
228 special target `.SUFFIXES'. You can add your own suffixes by writing a
229 rule for `.SUFFIXES' that adds more prerequisites, as in:
231 .SUFFIXES: .hack .win
233 which adds `.hack' and `.win' to the end of the list of suffixes.
235 If you wish to eliminate the default known suffixes instead of just
236 adding to them, write a rule for `.SUFFIXES' with no prerequisites. By
237 special dispensation, this eliminates all existing prerequisites of
238 `.SUFFIXES'. You can then write another rule to add the suffixes you
241 .SUFFIXES: # Delete the default suffixes
242 .SUFFIXES: .c .o .h # Define our suffix list
244 The `-r' or `--no-builtin-rules' flag causes the default list of
245 suffixes to be empty.
247 The variable `SUFFIXES' is defined to the default list of suffixes
248 before `make' reads any makefiles. You can change the list of suffixes
249 with a rule for the special target `.SUFFIXES', but that does not alter
253 File: make.info, Node: Implicit Rule Search, Prev: Suffix Rules, Up: Implicit Rules
255 Implicit Rule Search Algorithm
256 ==============================
258 Here is the procedure `make' uses for searching for an implicit rule
259 for a target T. This procedure is followed for each double-colon rule
260 with no commands, for each target of ordinary rules none of which have
261 commands, and for each prerequisite that is not the target of any rule.
262 It is also followed recursively for prerequisites that come from
263 implicit rules, in the search for a chain of rules.
265 Suffix rules are not mentioned in this algorithm because suffix
266 rules are converted to equivalent pattern rules once the makefiles have
269 For an archive member target of the form `ARCHIVE(MEMBER)', the
270 following algorithm is run twice, first using the entire target name T,
271 and second using `(MEMBER)' as the target T if the first run found no
274 1. Split T into a directory part, called D, and the rest, called N.
275 For example, if T is `src/foo.o', then D is `src/' and N is
278 2. Make a list of all the pattern rules one of whose targets matches
279 T or N. If the target pattern contains a slash, it is matched
280 against T; otherwise, against N.
282 3. If any rule in that list is _not_ a match-anything rule, then
283 remove all nonterminal match-anything rules from the list.
285 4. Remove from the list all rules with no commands.
287 5. For each pattern rule in the list:
289 a. Find the stem S, which is the nonempty part of T or N matched
290 by the `%' in the target pattern.
292 b. Compute the prerequisite names by substituting S for `%'; if
293 the target pattern does not contain a slash, append D to the
294 front of each prerequisite name.
296 c. Test whether all the prerequisites exist or ought to exist.
297 (If a file name is mentioned in the makefile as a target or
298 as an explicit prerequisite, then we say it ought to exist.)
300 If all prerequisites exist or ought to exist, or there are no
301 prerequisites, then this rule applies.
303 6. If no pattern rule has been found so far, try harder. For each
304 pattern rule in the list:
306 a. If the rule is terminal, ignore it and go on to the next rule.
308 b. Compute the prerequisite names as before.
310 c. Test whether all the prerequisites exist or ought to exist.
312 d. For each prerequisite that does not exist, follow this
313 algorithm recursively to see if the prerequisite can be made
316 e. If all prerequisites exist, ought to exist, or can be made by
317 implicit rules, then this rule applies.
319 7. If no implicit rule applies, the rule for `.DEFAULT', if any,
320 applies. In that case, give T the same commands that `.DEFAULT'
321 has. Otherwise, there are no commands for T.
323 Once a rule that applies has been found, for each target pattern of
324 the rule other than the one that matched T or N, the `%' in the pattern
325 is replaced with S and the resultant file name is stored until the
326 commands to remake the target file T are executed. After these
327 commands are executed, each of these stored file names are entered into
328 the data base and marked as having been updated and having the same
329 update status as the file T.
331 When the commands of a pattern rule are executed for T, the automatic
332 variables are set corresponding to the target and prerequisites. *Note
333 Automatic Variables: Automatic.
336 File: make.info, Node: Archives, Next: Features, Prev: Implicit Rules, Up: Top
338 Using `make' to Update Archive Files
339 ************************************
341 "Archive files" are files containing named subfiles called
342 "members"; they are maintained with the program `ar' and their main use
343 is as subroutine libraries for linking.
347 * Archive Members:: Archive members as targets.
348 * Archive Update:: The implicit rule for archive member targets.
349 * Archive Pitfalls:: Dangers to watch out for when using archives.
350 * Archive Suffix Rules:: You can write a special kind of suffix rule
351 for updating archives.
354 File: make.info, Node: Archive Members, Next: Archive Update, Prev: Archives, Up: Archives
356 Archive Members as Targets
357 ==========================
359 An individual member of an archive file can be used as a target or
360 prerequisite in `make'. You specify the member named MEMBER in archive
361 file ARCHIVE as follows:
365 This construct is available only in targets and prerequisites, not in
366 commands! Most programs that you might use in commands do not support
367 this syntax and cannot act directly on archive members. Only `ar' and
368 other programs specifically designed to operate on archives can do so.
369 Therefore, valid commands to update an archive member target probably
370 must use `ar'. For example, this rule says to create a member `hack.o'
371 in archive `foolib' by copying the file `hack.o':
373 foolib(hack.o) : hack.o
376 In fact, nearly all archive member targets are updated in just this
377 way and there is an implicit rule to do it for you. *Note:* The `c'
378 flag to `ar' is required if the archive file does not already exist.
380 To specify several members in the same archive, you can write all the
381 member names together between the parentheses. For example:
383 foolib(hack.o kludge.o)
387 foolib(hack.o) foolib(kludge.o)
389 You can also use shell-style wildcards in an archive member
390 reference. *Note Using Wildcard Characters in File Names: Wildcards.
391 For example, `foolib(*.o)' expands to all existing members of the
392 `foolib' archive whose names end in `.o'; perhaps `foolib(hack.o)
396 File: make.info, Node: Archive Update, Next: Archive Pitfalls, Prev: Archive Members, Up: Archives
398 Implicit Rule for Archive Member Targets
399 ========================================
401 Recall that a target that looks like `A(M)' stands for the member
402 named M in the archive file A.
404 When `make' looks for an implicit rule for such a target, as a
405 special feature it considers implicit rules that match `(M)', as well as
406 those that match the actual target `A(M)'.
408 This causes one special rule whose target is `(%)' to match. This
409 rule updates the target `A(M)' by copying the file M into the archive.
410 For example, it will update the archive member target `foo.a(bar.o)' by
411 copying the _file_ `bar.o' into the archive `foo.a' as a _member_ named
414 When this rule is chained with others, the result is very powerful.
415 Thus, `make "foo.a(bar.o)"' (the quotes are needed to protect the `('
416 and `)' from being interpreted specially by the shell) in the presence
417 of a file `bar.c' is enough to cause the following commands to be run,
418 even without a makefile:
424 Here `make' has envisioned the file `bar.o' as an intermediate file.
425 *Note Chains of Implicit Rules: Chained Rules.
427 Implicit rules such as this one are written using the automatic
428 variable `$%'. *Note Automatic Variables: Automatic.
430 An archive member name in an archive cannot contain a directory
431 name, but it may be useful in a makefile to pretend that it does. If
432 you write an archive member target `foo.a(dir/file.o)', `make' will
433 perform automatic updating with this command:
435 ar r foo.a dir/file.o
437 which has the effect of copying the file `dir/file.o' into a member
438 named `file.o'. In connection with such usage, the automatic variables
439 `%D' and `%F' may be useful.
443 * Archive Symbols:: How to update archive symbol directories.
446 File: make.info, Node: Archive Symbols, Prev: Archive Update, Up: Archive Update
448 Updating Archive Symbol Directories
449 -----------------------------------
451 An archive file that is used as a library usually contains a special
452 member named `__.SYMDEF' that contains a directory of the external
453 symbol names defined by all the other members. After you update any
454 other members, you need to update `__.SYMDEF' so that it will summarize
455 the other members properly. This is done by running the `ranlib'
460 Normally you would put this command in the rule for the archive file,
461 and make all the members of the archive file prerequisites of that rule.
464 libfoo.a: libfoo.a(x.o) libfoo.a(y.o) ...
467 The effect of this is to update archive members `x.o', `y.o', etc., and
468 then update the symbol directory member `__.SYMDEF' by running
469 `ranlib'. The rules for updating the members are not shown here; most
470 likely you can omit them and use the implicit rule which copies files
471 into the archive, as described in the preceding section.
473 This is not necessary when using the GNU `ar' program, which updates
474 the `__.SYMDEF' member automatically.
477 File: make.info, Node: Archive Pitfalls, Next: Archive Suffix Rules, Prev: Archive Update, Up: Archives
479 Dangers When Using Archives
480 ===========================
482 It is important to be careful when using parallel execution (the
483 `-j' switch; *note Parallel Execution: Parallel.) and archives. If
484 multiple `ar' commands run at the same time on the same archive file,
485 they will not know about each other and can corrupt the file.
487 Possibly a future version of `make' will provide a mechanism to
488 circumvent this problem by serializing all commands that operate on the
489 same archive file. But for the time being, you must either write your
490 makefiles to avoid this problem in some other way, or not use `-j'.
493 File: make.info, Node: Archive Suffix Rules, Prev: Archive Pitfalls, Up: Archives
495 Suffix Rules for Archive Files
496 ==============================
498 You can write a special kind of suffix rule for dealing with archive
499 files. *Note Suffix Rules::, for a full explanation of suffix rules.
500 Archive suffix rules are obsolete in GNU `make', because pattern rules
501 for archives are a more general mechanism (*note Archive Update::).
502 But they are retained for compatibility with other `make's.
504 To write a suffix rule for archives, you simply write a suffix rule
505 using the target suffix `.a' (the usual suffix for archive files). For
506 example, here is the old-fashioned suffix rule to update a library
507 archive from C source files:
510 $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
514 This works just as if you had written the pattern rule:
517 $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
521 In fact, this is just what `make' does when it sees a suffix rule
522 with `.a' as the target suffix. Any double-suffix rule `.X.a' is
523 converted to a pattern rule with the target pattern `(%.o)' and a
524 prerequisite pattern of `%.X'.
526 Since you might want to use `.a' as the suffix for some other kind
527 of file, `make' also converts archive suffix rules to pattern rules in
528 the normal way (*note Suffix Rules::). Thus a double-suffix rule
529 `.X.a' produces two pattern rules: `(%.o): %.X' and `%.a: %.X'.
532 File: make.info, Node: Features, Next: Missing, Prev: Archives, Up: Top
534 Features of GNU `make'
535 **********************
537 Here is a summary of the features of GNU `make', for comparison with
538 and credit to other versions of `make'. We consider the features of
539 `make' in 4.2 BSD systems as a baseline. If you are concerned with
540 writing portable makefiles, you should not use the features of `make'
541 listed here, nor the ones in *Note Missing::.
543 Many features come from the version of `make' in System V.
545 * The `VPATH' variable and its special meaning. *Note Searching
546 Directories for Prerequisites: Directory Search. This feature
547 exists in System V `make', but is undocumented. It is documented
548 in 4.3 BSD `make' (which says it mimics System V's `VPATH'
551 * Included makefiles. *Note Including Other Makefiles: Include.
552 Allowing multiple files to be included with a single directive is
555 * Variables are read from and communicated via the environment.
556 *Note Variables from the Environment: Environment.
558 * Options passed through the variable `MAKEFLAGS' to recursive
559 invocations of `make'. *Note Communicating Options to a
560 Sub-`make': Options/Recursion.
562 * The automatic variable `$%' is set to the member name in an
563 archive reference. *Note Automatic Variables: Automatic.
565 * The automatic variables `$@', `$*', `$<', `$%', and `$?' have
566 corresponding forms like `$(@F)' and `$(@D)'. We have generalized
567 this to `$^' as an obvious extension. *Note Automatic Variables:
570 * Substitution variable references. *Note Basics of Variable
571 References: Reference.
573 * The command-line options `-b' and `-m', accepted and ignored. In
574 System V `make', these options actually do something.
576 * Execution of recursive commands to run `make' via the variable
577 `MAKE' even if `-n', `-q' or `-t' is specified. *Note Recursive
578 Use of `make': Recursion.
580 * Support for suffix `.a' in suffix rules. *Note Archive Suffix
581 Rules::. This feature is obsolete in GNU `make', because the
582 general feature of rule chaining (*note Chains of Implicit Rules:
583 Chained Rules.) allows one pattern rule for installing members in
584 an archive (*note Archive Update::) to be sufficient.
586 * The arrangement of lines and backslash-newline combinations in
587 commands is retained when the commands are printed, so they appear
588 as they do in the makefile, except for the stripping of initial
591 The following features were inspired by various other versions of
592 `make'. In some cases it is unclear exactly which versions inspired
595 * Pattern rules using `%'. This has been implemented in several
596 versions of `make'. We're not sure who invented it first, but
597 it's been spread around a bit. *Note Defining and Redefining
598 Pattern Rules: Pattern Rules.
600 * Rule chaining and implicit intermediate files. This was
601 implemented by Stu Feldman in his version of `make' for AT&T
602 Eighth Edition Research Unix, and later by Andrew Hume of AT&T
603 Bell Labs in his `mk' program (where he terms it "transitive
604 closure"). We do not really know if we got this from either of
605 them or thought it up ourselves at the same time. *Note Chains of
606 Implicit Rules: Chained Rules.
608 * The automatic variable `$^' containing a list of all prerequisites
609 of the current target. We did not invent this, but we have no
610 idea who did. *Note Automatic Variables: Automatic. The
611 automatic variable `$+' is a simple extension of `$^'.
613 * The "what if" flag (`-W' in GNU `make') was (as far as we know)
614 invented by Andrew Hume in `mk'. *Note Instead of Executing the
615 Commands: Instead of Execution.
617 * The concept of doing several things at once (parallelism) exists in
618 many incarnations of `make' and similar programs, though not in the
619 System V or BSD implementations. *Note Command Execution:
622 * Modified variable references using pattern substitution come from
623 SunOS 4. *Note Basics of Variable References: Reference. This
624 functionality was provided in GNU `make' by the `patsubst'
625 function before the alternate syntax was implemented for
626 compatibility with SunOS 4. It is not altogether clear who
627 inspired whom, since GNU `make' had `patsubst' before SunOS 4 was
630 * The special significance of `+' characters preceding command lines
631 (*note Instead of Executing the Commands: Instead of Execution.) is
632 mandated by `IEEE Standard 1003.2-1992' (POSIX.2).
634 * The `+=' syntax to append to the value of a variable comes from
635 SunOS 4 `make'. *Note Appending More Text to Variables: Appending.
637 * The syntax `ARCHIVE(MEM1 MEM2...)' to list multiple members in a
638 single archive file comes from SunOS 4 `make'. *Note Archive
641 * The `-include' directive to include makefiles with no error for a
642 nonexistent file comes from SunOS 4 `make'. (But note that SunOS 4
643 `make' does not allow multiple makefiles to be specified in one
644 `-include' directive.) The same feature appears with the name
645 `sinclude' in SGI `make' and perhaps others.
647 The remaining features are inventions new in GNU `make':
649 * Use the `-v' or `--version' option to print version and copyright
652 * Use the `-h' or `--help' option to summarize the options to `make'.
654 * Simply-expanded variables. *Note The Two Flavors of Variables:
657 * Pass command-line variable assignments automatically through the
658 variable `MAKE' to recursive `make' invocations. *Note Recursive
659 Use of `make': Recursion.
661 * Use the `-C' or `--directory' command option to change directory.
662 *Note Summary of Options: Options Summary.
664 * Make verbatim variable definitions with `define'. *Note Defining
665 Variables Verbatim: Defining.
667 * Declare phony targets with the special target `.PHONY'.
669 Andrew Hume of AT&T Bell Labs implemented a similar feature with a
670 different syntax in his `mk' program. This seems to be a case of
671 parallel discovery. *Note Phony Targets: Phony Targets.
673 * Manipulate text by calling functions. *Note Functions for
674 Transforming Text: Functions.
676 * Use the `-o' or `--old-file' option to pretend a file's
677 modification-time is old. *Note Avoiding Recompilation of Some
678 Files: Avoiding Compilation.
680 * Conditional execution.
682 This feature has been implemented numerous times in various
683 versions of `make'; it seems a natural extension derived from the
684 features of the C preprocessor and similar macro languages and is
685 not a revolutionary concept. *Note Conditional Parts of
686 Makefiles: Conditionals.
688 * Specify a search path for included makefiles. *Note Including
689 Other Makefiles: Include.
691 * Specify extra makefiles to read with an environment variable.
692 *Note The Variable `MAKEFILES': MAKEFILES Variable.
694 * Strip leading sequences of `./' from file names, so that `./FILE'
695 and `FILE' are considered to be the same file.
697 * Use a special search method for library prerequisites written in
698 the form `-lNAME'. *Note Directory Search for Link Libraries:
701 * Allow suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
702 Suffix Rules.) to contain any characters. In other versions of
703 `make', they must begin with `.' and not contain any `/'
706 * Keep track of the current level of `make' recursion using the
707 variable `MAKELEVEL'. *Note Recursive Use of `make': Recursion.
709 * Provide any goals given on the command line in the variable
710 `MAKECMDGOALS'. *Note Arguments to Specify the Goals: Goals.
712 * Specify static pattern rules. *Note Static Pattern Rules: Static
715 * Provide selective `vpath' search. *Note Searching Directories for
716 Prerequisites: Directory Search.
718 * Provide computed variable references. *Note Basics of Variable
719 References: Reference.
721 * Update makefiles. *Note How Makefiles Are Remade: Remaking
722 Makefiles. System V `make' has a very, very limited form of this
723 functionality in that it will check out SCCS files for makefiles.
725 * Various new built-in implicit rules. *Note Catalogue of Implicit
726 Rules: Catalogue of Rules.
728 * The built-in variable `MAKE_VERSION' gives the version number of
732 File: make.info, Node: Missing, Next: Makefile Conventions, Prev: Features, Up: Top
734 Incompatibilities and Missing Features
735 **************************************
737 The `make' programs in various other systems support a few features
738 that are not implemented in GNU `make'. The POSIX.2 standard (`IEEE
739 Standard 1003.2-1992') which specifies `make' does not require any of
742 * A target of the form `FILE((ENTRY))' stands for a member of
743 archive file FILE. The member is chosen, not by name, but by
744 being an object file which defines the linker symbol ENTRY.
746 This feature was not put into GNU `make' because of the
747 nonmodularity of putting knowledge into `make' of the internal
748 format of archive file symbol tables. *Note Updating Archive
749 Symbol Directories: Archive Symbols.
751 * Suffixes (used in suffix rules) that end with the character `~'
752 have a special meaning to System V `make'; they refer to the SCCS
753 file that corresponds to the file one would get without the `~'.
754 For example, the suffix rule `.c~.o' would make the file `N.o' from
755 the SCCS file `s.N.c'. For complete coverage, a whole series of
756 such suffix rules is required. *Note Old-Fashioned Suffix Rules:
759 In GNU `make', this entire series of cases is handled by two
760 pattern rules for extraction from SCCS, in combination with the
761 general feature of rule chaining. *Note Chains of Implicit Rules:
764 * In System V and 4.3 BSD `make', files found by `VPATH' search
765 (*note Searching Directories for Prerequisites: Directory Search.)
766 have their names changed inside command strings. We feel it is
767 much cleaner to always use automatic variables and thus make this
770 * In some Unix `make's, the automatic variable `$*' appearing in the
771 prerequisites of a rule has the amazingly strange "feature" of
772 expanding to the full name of the _target of that rule_. We cannot
773 imagine what went on in the minds of Unix `make' developers to do
774 this; it is utterly inconsistent with the normal definition of
777 * In some Unix `make's, implicit rule search (*note Using Implicit
778 Rules: Implicit Rules.) is apparently done for _all_ targets, not
779 just those without commands. This means you can do:
784 and Unix `make' will intuit that `foo.o' depends on `foo.c'.
786 We feel that such usage is broken. The prerequisite properties of
787 `make' are well-defined (for GNU `make', at least), and doing such
788 a thing simply does not fit the model.
790 * GNU `make' does not include any built-in implicit rules for
791 compiling or preprocessing EFL programs. If we hear of anyone who
792 is using EFL, we will gladly add them.
794 * It appears that in SVR4 `make', a suffix rule can be specified with
795 no commands, and it is treated as if it had empty commands (*note
796 Empty Commands::). For example:
800 will override the built-in `.c.a' suffix rule.
802 We feel that it is cleaner for a rule without commands to always
803 simply add to the prerequisite list for the target. The above
804 example can be easily rewritten to get the desired behavior in GNU
809 * Some versions of `make' invoke the shell with the `-e' flag,
810 except under `-k' (*note Testing the Compilation of a Program:
811 Testing.). The `-e' flag tells the shell to exit as soon as any
812 program it runs returns a nonzero status. We feel it is cleaner to
813 write each shell command line to stand on its own and not require
814 this special treatment.
817 File: make.info, Node: Makefile Conventions, Next: Quick Reference, Prev: Missing, Up: Top
822 This node describes conventions for writing the Makefiles for GNU
823 programs. Using Automake will help you write a Makefile that follows
828 * Makefile Basics:: General Conventions for Makefiles
829 * Utilities in Makefiles:: Utilities in Makefiles
830 * Command Variables:: Variables for Specifying Commands
831 * Directory Variables:: Variables for Installation Directories
832 * Standard Targets:: Standard Targets for Users
833 * Install Command Categories:: Three categories of commands in the `install'
834 rule: normal, pre-install and post-install.
837 File: make.info, Node: Makefile Basics, Next: Utilities in Makefiles, Up: Makefile Conventions
839 General Conventions for Makefiles
840 =================================
842 Every Makefile should contain this line:
846 to avoid trouble on systems where the `SHELL' variable might be
847 inherited from the environment. (This is never a problem with GNU
850 Different `make' programs have incompatible suffix lists and
851 implicit rules, and this sometimes creates confusion or misbehavior. So
852 it is a good idea to set the suffix list explicitly using only the
853 suffixes you need in the particular Makefile, like this:
858 The first line clears out the suffix list, the second introduces all
859 suffixes which may be subject to implicit rules in this Makefile.
861 Don't assume that `.' is in the path for command execution. When
862 you need to run programs that are a part of your package during the
863 make, please make sure that it uses `./' if the program is built as
864 part of the make or `$(srcdir)/' if the file is an unchanging part of
865 the source code. Without one of these prefixes, the current search
868 The distinction between `./' (the "build directory") and
869 `$(srcdir)/' (the "source directory") is important because users can
870 build in a separate directory using the `--srcdir' option to
871 `configure'. A rule of the form:
873 foo.1 : foo.man sedscript
874 sed -e sedscript foo.man > foo.1
876 will fail when the build directory is not the source directory, because
877 `foo.man' and `sedscript' are in the source directory.
879 When using GNU `make', relying on `VPATH' to find the source file
880 will work in the case where there is a single dependency file, since
881 the `make' automatic variable `$<' will represent the source file
882 wherever it is. (Many versions of `make' set `$<' only in implicit
883 rules.) A Makefile target like
886 $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
888 should instead be written as
891 $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@
893 in order to allow `VPATH' to work correctly. When the target has
894 multiple dependencies, using an explicit `$(srcdir)' is the easiest way
895 to make the rule work well. For example, the target above for `foo.1'
898 foo.1 : foo.man sedscript
899 sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@
901 GNU distributions usually contain some files which are not source
902 files--for example, Info files, and the output from Autoconf, Automake,
903 Bison or Flex. Since these files normally appear in the source
904 directory, they should always appear in the source directory, not in the
905 build directory. So Makefile rules to update them should put the
906 updated files in the source directory.
908 However, if a file does not appear in the distribution, then the
909 Makefile should not put it in the source directory, because building a
910 program in ordinary circumstances should not modify the source directory
913 Try to make the build and installation targets, at least (and all
914 their subtargets) work correctly with a parallel `make'.
917 File: make.info, Node: Utilities in Makefiles, Next: Command Variables, Prev: Makefile Basics, Up: Makefile Conventions
919 Utilities in Makefiles
920 ======================
922 Write the Makefile commands (and any shell scripts, such as
923 `configure') to run in `sh', not in `csh'. Don't use any special
924 features of `ksh' or `bash'.
926 The `configure' script and the Makefile rules for building and
927 installation should not use any utilities directly except these:
929 cat cmp cp diff echo egrep expr false grep install-info
930 ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
932 The compression program `gzip' can be used in the `dist' rule.
934 Stick to the generally supported options for these programs. For
935 example, don't use `mkdir -p', convenient as it may be, because most
936 systems don't support it.
938 It is a good idea to avoid creating symbolic links in makefiles,
939 since a few systems don't support them.
941 The Makefile rules for building and installation can also use
942 compilers and related programs, but should do so via `make' variables
943 so that the user can substitute alternatives. Here are some of the
946 ar bison cc flex install ld ldconfig lex
947 make makeinfo ranlib texi2dvi yacc
949 Use the following `make' variables to run those programs:
951 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
952 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
954 When you use `ranlib' or `ldconfig', you should make sure nothing
955 bad happens if the system does not have the program in question.
956 Arrange to ignore an error from that command, and print a message before
957 the command to tell the user that failure of this command does not mean
958 a problem. (The Autoconf `AC_PROG_RANLIB' macro can help with this.)
960 If you use symbolic links, you should implement a fallback for
961 systems that don't have symbolic links.
963 Additional utilities that can be used via Make variables are:
965 chgrp chmod chown mknod
967 It is ok to use other utilities in Makefile portions (or scripts)
968 intended only for particular systems where you know those utilities
972 File: make.info, Node: Command Variables, Next: Directory Variables, Prev: Utilities in Makefiles, Up: Makefile Conventions
974 Variables for Specifying Commands
975 =================================
977 Makefiles should provide variables for overriding certain commands,
980 In particular, you should run most utility programs via variables.
981 Thus, if you use Bison, have a variable named `BISON' whose default
982 value is set with `BISON = bison', and refer to it with `$(BISON)'
983 whenever you need to use Bison.
985 File management utilities such as `ln', `rm', `mv', and so on, need
986 not be referred to through variables in this way, since users don't
987 need to replace them with other programs.
989 Each program-name variable should come with an options variable that
990 is used to supply options to the program. Append `FLAGS' to the
991 program-name variable name to get the options variable name--for
992 example, `BISONFLAGS'. (The names `CFLAGS' for the C compiler,
993 `YFLAGS' for yacc, and `LFLAGS' for lex, are exceptions to this rule,
994 but we keep them because they are standard.) Use `CPPFLAGS' in any
995 compilation command that runs the preprocessor, and use `LDFLAGS' in
996 any compilation command that does linking as well as in any direct use
999 If there are C compiler options that _must_ be used for proper
1000 compilation of certain files, do not include them in `CFLAGS'. Users
1001 expect to be able to specify `CFLAGS' freely themselves. Instead,
1002 arrange to pass the necessary options to the C compiler independently
1003 of `CFLAGS', by writing them explicitly in the compilation commands or
1004 by defining an implicit rule, like this:
1007 ALL_CFLAGS = -I. $(CFLAGS)
1009 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
1011 Do include the `-g' option in `CFLAGS', because that is not
1012 _required_ for proper compilation. You can consider it a default that
1013 is only recommended. If the package is set up so that it is compiled
1014 with GCC by default, then you might as well include `-O' in the default
1015 value of `CFLAGS' as well.
1017 Put `CFLAGS' last in the compilation command, after other variables
1018 containing compiler options, so the user can use `CFLAGS' to override
1021 `CFLAGS' should be used in every invocation of the C compiler, both
1022 those which do compilation and those which do linking.
1024 Every Makefile should define the variable `INSTALL', which is the
1025 basic command for installing a file into the system.
1027 Every Makefile should also define the variables `INSTALL_PROGRAM'
1028 and `INSTALL_DATA'. (The default for `INSTALL_PROGRAM' should be
1029 `$(INSTALL)'; the default for `INSTALL_DATA' should be `${INSTALL} -m
1030 644'.) Then it should use those variables as the commands for actual
1031 installation, for executables and nonexecutables respectively. Use
1032 these variables as follows:
1034 $(INSTALL_PROGRAM) foo $(bindir)/foo
1035 $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
1037 Optionally, you may prepend the value of `DESTDIR' to the target
1038 filename. Doing this allows the installer to create a snapshot of the
1039 installation to be copied onto the real target filesystem later. Do not
1040 set the value of `DESTDIR' in your Makefile, and do not include it in
1041 any installed files. With support for `DESTDIR', the above examples
1044 $(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
1045 $(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
1047 Always use a file name, not a directory name, as the second argument of
1048 the installation commands. Use a separate command for each file to be