home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-bin / info / make.info-6 < prev    next >
Encoding:
GNU Info File  |  1996-10-12  |  41.8 KB  |  1,030 lines

  1. This is Info file make.info, produced by Makeinfo-1.64 from the input
  2. file /ade-src/fsf/make/make.texinfo.
  3.  
  4.    This file documents the GNU Make utility, which determines
  5. automatically which pieces of a large program need to be recompiled,
  6. and issues the commands to recompile them.
  7.  
  8.    This is Edition 0.51, last updated 9 May 1996, of `The GNU Make
  9. Manual', for `make', Version 3.75 Beta.
  10.  
  11.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95, '96
  12. Free Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Free Software Foundation.
  27.  
  28. 
  29. File: make.info,  Node: Match-Anything Rules,  Next: Canceling Rules,  Prev: Pattern Match,  Up: Pattern Rules
  30.  
  31. Match-Anything Pattern Rules
  32. ----------------------------
  33.  
  34.    When a pattern rule's target is just `%', it matches any file name
  35. whatever.  We call these rules "match-anything" rules.  They are very
  36. useful, but it can take a lot of time for `make' to think about them,
  37. because it must consider every such rule for each file name listed
  38. either as a target or as a dependency.
  39.  
  40.    Suppose the makefile mentions `foo.c'.  For this target, `make'
  41. would have to consider making it by linking an object file `foo.c.o',
  42. or by C compilation-and-linking in one step from `foo.c.c', or by
  43. Pascal compilation-and-linking from `foo.c.p', and many other
  44. possibilities.
  45.  
  46.    We know these possibilities are ridiculous since `foo.c' is a C
  47. source file, not an executable.  If `make' did consider these
  48. possibilities, it would ultimately reject them, because files such as
  49. `foo.c.o' and `foo.c.p' would not exist.  But these possibilities are so
  50. numerous that `make' would run very slowly if it had to consider them.
  51.  
  52.    To gain speed, we have put various constraints on the way `make'
  53. considers match-anything rules.  There are two different constraints
  54. that can be applied, and each time you define a match-anything rule you
  55. must choose one or the other for that rule.
  56.  
  57.    One choice is to mark the match-anything rule as "terminal" by
  58. defining it with a double colon.  When a rule is terminal, it does not
  59. apply unless its dependencies actually exist.  Dependencies that could
  60. be made with other implicit rules are not good enough.  In other words,
  61. no further chaining is allowed beyond a terminal rule.
  62.  
  63.    For example, the built-in implicit rules for extracting sources from
  64. RCS and SCCS files are terminal; as a result, if the file `foo.c,v' does
  65. not exist, `make' will not even consider trying to make it as an
  66. intermediate file from `foo.c,v.o' or from `RCS/SCCS/s.foo.c,v'.  RCS
  67. and SCCS files are generally ultimate source files, which should not be
  68. remade from any other files; therefore, `make' can save time by not
  69. looking for ways to remake them.
  70.  
  71.    If you do not mark the match-anything rule as terminal, then it is
  72. nonterminal.  A nonterminal match-anything rule cannot apply to a file
  73. name that indicates a specific type of data.  A file name indicates a
  74. specific type of data if some non-match-anything implicit rule target
  75. matches it.
  76.  
  77.    For example, the file name `foo.c' matches the target for the pattern
  78. rule `%.c : %.y' (the rule to run Yacc).  Regardless of whether this
  79. rule is actually applicable (which happens only if there is a file
  80. `foo.y'), the fact that its target matches is enough to prevent
  81. consideration of any nonterminal match-anything rules for the file
  82. `foo.c'.  Thus, `make' will not even consider trying to make `foo.c' as
  83. an executable file from `foo.c.o', `foo.c.c', `foo.c.p', etc.
  84.  
  85.    The motivation for this constraint is that nonterminal match-anything
  86. rules are used for making files containing specific types of data (such
  87. as executable files) and a file name with a recognized suffix indicates
  88. some other specific type of data (such as a C source file).
  89.  
  90.    Special built-in dummy pattern rules are provided solely to recognize
  91. certain file names so that nonterminal match-anything rules will not be
  92. considered.  These dummy rules have no dependencies and no commands, and
  93. they are ignored for all other purposes.  For example, the built-in
  94. implicit rule
  95.  
  96.      %.p :
  97.  
  98. exists to make sure that Pascal source files such as `foo.p' match a
  99. specific target pattern and thereby prevent time from being wasted
  100. looking for `foo.p.o' or `foo.p.c'.
  101.  
  102.    Dummy pattern rules such as the one for `%.p' are made for every
  103. suffix listed as valid for use in suffix rules (*note Old-Fashioned
  104. Suffix Rules: Suffix Rules.).
  105.  
  106. 
  107. File: make.info,  Node: Canceling Rules,  Prev: Match-Anything Rules,  Up: Pattern Rules
  108.  
  109. Canceling Implicit Rules
  110. ------------------------
  111.  
  112.    You can override a built-in implicit rule (or one you have defined
  113. yourself) by defining a new pattern rule with the same target and
  114. dependencies, but different commands.  When the new rule is defined, the
  115. built-in one is replaced.  The new rule's position in the sequence of
  116. implicit rules is determined by where you write the new rule.
  117.  
  118.    You can cancel a built-in implicit rule by defining a pattern rule
  119. with the same target and dependencies, but no commands.  For example,
  120. the following would cancel the rule that runs the assembler:
  121.  
  122.      %.o : %.s
  123.  
  124. 
  125. File: make.info,  Node: Last Resort,  Next: Suffix Rules,  Prev: Pattern Rules,  Up: Implicit Rules
  126.  
  127. Defining Last-Resort Default Rules
  128. ==================================
  129.  
  130.    You can define a last-resort implicit rule by writing a terminal
  131. match-anything pattern rule with no dependencies (*note Match-Anything
  132. Rules::.).  This is just like any other pattern rule; the only thing
  133. special about it is that it will match any target.  So such a rule's
  134. commands are used for all targets and dependencies that have no commands
  135. of their own and for which no other implicit rule applies.
  136.  
  137.    For example, when testing a makefile, you might not care if the
  138. source files contain real data, only that they exist.  Then you might
  139. do this:
  140.  
  141.      %::
  142.              touch $@
  143.  
  144. to cause all the source files needed (as dependencies) to be created
  145. automatically.
  146.  
  147.    You can instead define commands to be used for targets for which
  148. there are no rules at all, even ones which don't specify commands.  You
  149. do this by writing a rule for the target `.DEFAULT'.  Such a rule's
  150. commands are used for all dependencies which do not appear as targets in
  151. any explicit rule, and for which no implicit rule applies.  Naturally,
  152. there is no `.DEFAULT' rule unless you write one.
  153.  
  154.    If you use `.DEFAULT' with no commands or dependencies:
  155.  
  156.      .DEFAULT:
  157.  
  158. the commands previously stored for `.DEFAULT' are cleared.  Then `make'
  159. acts as if you had never defined `.DEFAULT' at all.
  160.  
  161.    If you do not want a target to get the commands from a match-anything
  162. pattern rule or `.DEFAULT', but you also do not want any commands to be
  163. run for the target, you can give it empty commands (*note Defining
  164. Empty Commands: Empty Commands.).
  165.  
  166.    You can use a last-resort rule to override part of another makefile.
  167. *Note Overriding Part of Another Makefile: Overriding Makefiles.
  168.  
  169. 
  170. File: make.info,  Node: Suffix Rules,  Next: Search Algorithm,  Prev: Last Resort,  Up: Implicit Rules
  171.  
  172. Old-Fashioned Suffix Rules
  173. ==========================
  174.  
  175.    "Suffix rules" are the old-fashioned way of defining implicit rules
  176. for `make'.  Suffix rules are obsolete because pattern rules are more
  177. general and clearer.  They are supported in GNU `make' for
  178. compatibility with old makefiles.  They come in two kinds:
  179. "double-suffix" and "single-suffix".
  180.  
  181.    A double-suffix rule is defined by a pair of suffixes: the target
  182. suffix and the source suffix.  It matches any file whose name ends with
  183. the target suffix.  The corresponding implicit dependency is made by
  184. replacing the target suffix with the source suffix in the file name.  A
  185. two-suffix rule whose target and source suffixes are `.o' and `.c' is
  186. equivalent to the pattern rule `%.o : %.c'.
  187.  
  188.    A single-suffix rule is defined by a single suffix, which is the
  189. source suffix.  It matches any file name, and the corresponding implicit
  190. dependency name is made by appending the source suffix.  A single-suffix
  191. rule whose source suffix is `.c' is equivalent to the pattern rule `% :
  192. %.c'.
  193.  
  194.    Suffix rule definitions are recognized by comparing each rule's
  195. target against a defined list of known suffixes.  When `make' sees a
  196. rule whose target is a known suffix, this rule is considered a
  197. single-suffix rule.  When `make' sees a rule whose target is two known
  198. suffixes concatenated, this rule is taken as a double-suffix rule.
  199.  
  200.    For example, `.c' and `.o' are both on the default list of known
  201. suffixes.  Therefore, if you define a rule whose target is `.c.o',
  202. `make' takes it to be a double-suffix rule with source suffix `.c' and
  203. target suffix `.o'.  Here is the old-fashioned way to define the rule
  204. for compiling a C source file:
  205.  
  206.      .c.o:
  207.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  208.  
  209.    Suffix rules cannot have any dependencies of their own.  If they
  210. have any, they are treated as normal files with funny names, not as
  211. suffix rules.  Thus, the rule:
  212.  
  213.      .c.o: foo.h
  214.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  215.  
  216. tells how to make the file `.c.o' from the dependency file `foo.h', and
  217. is not at all like the pattern rule:
  218.  
  219.      %.o: %.c foo.h
  220.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  221.  
  222. which tells how to make `.o' files from `.c' files, and makes all `.o'
  223. files using this pattern rule also depend on `foo.h'.
  224.  
  225.    Suffix rules with no commands are also meaningless.  They do not
  226. remove previous rules as do pattern rules with no commands (*note
  227. Canceling Implicit Rules: Canceling Rules.).  They simply enter the
  228. suffix or pair of suffixes concatenated as a target in the data base.
  229.  
  230.    The known suffixes are simply the names of the dependencies of the
  231. special target `.SUFFIXES'.  You can add your own suffixes by writing a
  232. rule for `.SUFFIXES' that adds more dependencies, as in:
  233.  
  234.      .SUFFIXES: .hack .win
  235.  
  236. which adds `.hack' and `.win' to the end of the list of suffixes.
  237.  
  238.    If you wish to eliminate the default known suffixes instead of just
  239. adding to them, write a rule for `.SUFFIXES' with no dependencies.  By
  240. special dispensation, this eliminates all existing dependencies of
  241. `.SUFFIXES'.  You can then write another rule to add the suffixes you
  242. want.  For example,
  243.  
  244.      .SUFFIXES:            # Delete the default suffixes
  245.      .SUFFIXES: .c .o .h   # Define our suffix list
  246.  
  247.    The `-r' or `--no-builtin-rules' flag causes the default list of
  248. suffixes to be empty.
  249.  
  250.    The variable `SUFFIXES' is defined to the default list of suffixes
  251. before `make' reads any makefiles.  You can change the list of suffixes
  252. with a rule for the special target `.SUFFIXES', but that does not alter
  253. this variable.
  254.  
  255. 
  256. File: make.info,  Node: Search Algorithm,  Prev: Suffix Rules,  Up: Implicit Rules
  257.  
  258. Implicit Rule Search Algorithm
  259. ==============================
  260.  
  261.    Here is the procedure `make' uses for searching for an implicit rule
  262. for a target T.  This procedure is followed for each double-colon rule
  263. with no commands, for each target of ordinary rules none of which have
  264. commands, and for each dependency that is not the target of any rule.
  265. It is also followed recursively for dependencies that come from implicit
  266. rules, in the search for a chain of rules.
  267.  
  268.    Suffix rules are not mentioned in this algorithm because suffix
  269. rules are converted to equivalent pattern rules once the makefiles have
  270. been read in.
  271.  
  272.    For an archive member target of the form `ARCHIVE(MEMBER)', the
  273. following algorithm is run twice, first using the entire target name T,
  274. and second using `(MEMBER)' as the target T if the first run found no
  275. rule.
  276.  
  277.   1. Split T into a directory part, called D, and the rest, called N.
  278.      For example, if T is `src/foo.o', then D is `src/' and N is
  279.      `foo.o'.
  280.  
  281.   2. Make a list of all the pattern rules one of whose targets matches
  282.      T or N.  If the target pattern contains a slash, it is matched
  283.      against T; otherwise, against N.
  284.  
  285.   3. If any rule in that list is *not* a match-anything rule, then
  286.      remove all nonterminal match-anything rules from the list.
  287.  
  288.   4. Remove from the list all rules with no commands.
  289.  
  290.   5. For each pattern rule in the list:
  291.  
  292.        a. Find the stem S, which is the nonempty part of T or N matched
  293.           by the `%' in the target pattern.
  294.  
  295.        b. Compute the dependency names by substituting S for `%'; if
  296.           the target pattern does not contain a slash, append D to the
  297.           front of each dependency name.
  298.  
  299.        c. Test whether all the dependencies exist or ought to exist.
  300.           (If a file name is mentioned in the makefile as a target or
  301.           as an explicit dependency, then we say it ought to exist.)
  302.  
  303.           If all dependencies exist or ought to exist, or there are no
  304.           dependencies, then this rule applies.
  305.  
  306.   6. If no pattern rule has been found so far, try harder.  For each
  307.      pattern rule in the list:
  308.  
  309.        a. If the rule is terminal, ignore it and go on to the next rule.
  310.  
  311.        b. Compute the dependency names as before.
  312.  
  313.        c. Test whether all the dependencies exist or ought to exist.
  314.  
  315.        d. For each dependency that does not exist, follow this algorithm
  316.           recursively to see if the dependency can be made by an
  317.           implicit rule.
  318.  
  319.        e. If all dependencies exist, ought to exist, or can be made by
  320.           implicit rules, then this rule applies.
  321.  
  322.   7. If no implicit rule applies, the rule for `.DEFAULT', if any,
  323.      applies.  In that case, give T the same commands that `.DEFAULT'
  324.      has.  Otherwise, there are no commands for T.
  325.  
  326.    Once a rule that applies has been found, for each target pattern of
  327. the rule other than the one that matched T or N, the `%' in the pattern
  328. is replaced with S and the resultant file name is stored until the
  329. commands to remake the target file T are executed.  After these
  330. commands are executed, each of these stored file names are entered into
  331. the data base and marked as having been updated and having the same
  332. update status as the file T.
  333.  
  334.    When the commands of a pattern rule are executed for T, the automatic
  335. variables are set corresponding to the target and dependencies.  *Note
  336. Automatic Variables: Automatic.
  337.  
  338. 
  339. File: make.info,  Node: Archives,  Next: Features,  Prev: Implicit Rules,  Up: Top
  340.  
  341. Using `make' to Update Archive Files
  342. ************************************
  343.  
  344.    "Archive files" are files containing named subfiles called
  345. "members"; they are maintained with the program `ar' and their main use
  346. is as subroutine libraries for linking.
  347.  
  348. * Menu:
  349.  
  350. * Archive Members::             Archive members as targets.
  351. * Archive Update::              The implicit rule for archive member targets.
  352. * Archive Pitfalls::            Dangers to watch out for when using archives.
  353. * Archive Suffix Rules::        You can write a special kind of suffix rule
  354.                                   for updating archives.
  355.  
  356. 
  357. File: make.info,  Node: Archive Members,  Next: Archive Update,  Up: Archives
  358.  
  359. Archive Members as Targets
  360. ==========================
  361.  
  362.    An individual member of an archive file can be used as a target or
  363. dependency in `make'.  You specify the member named MEMBER in archive
  364. file ARCHIVE as follows:
  365.  
  366.      ARCHIVE(MEMBER)
  367.  
  368. This construct is available only in targets and dependencies, not in
  369. commands!  Most programs that you might use in commands do not support
  370. this syntax and cannot act directly on archive members.  Only `ar' and
  371. other programs specifically designed to operate on archives can do so.
  372. Therefore, valid commands to update an archive member target probably
  373. must use `ar'.  For example, this rule says to create a member `hack.o'
  374. in archive `foolib' by copying the file `hack.o':
  375.  
  376.      foolib(hack.o) : hack.o
  377.              ar cr foolib hack.o
  378.  
  379.    In fact, nearly all archive member targets are updated in just this
  380. way and there is an implicit rule to do it for you.  *Note:* The `c'
  381. flag to `ar' is required if the archive file does not already exist.
  382.  
  383.    To specify several members in the same archive, you can write all the
  384. member names together between the parentheses.  For example:
  385.  
  386.      foolib(hack.o kludge.o)
  387.  
  388. is equivalent to:
  389.  
  390.      foolib(hack.o) foolib(kludge.o)
  391.  
  392.    You can also use shell-style wildcards in an archive member
  393. reference.  *Note Using Wildcard Characters in File Names: Wildcards.
  394. For example, `foolib(*.o)' expands to all existing members of the
  395. `foolib' archive whose names end in `.o'; perhaps `foolib(hack.o)
  396. foolib(kludge.o)'.
  397.  
  398. 
  399. File: make.info,  Node: Archive Update,  Next: Archive Pitfalls,  Prev: Archive Members,  Up: Archives
  400.  
  401. Implicit Rule for Archive Member Targets
  402. ========================================
  403.  
  404.    Recall that a target that looks like `A(M)' stands for the member
  405. named M in the archive file A.
  406.  
  407.    When `make' looks for an implicit rule for such a target, as a
  408. special feature it considers implicit rules that match `(M)', as well as
  409. those that match the actual target `A(M)'.
  410.  
  411.    This causes one special rule whose target is `(%)' to match.  This
  412. rule updates the target `A(M)' by copying the file M into the archive.
  413. For example, it will update the archive member target `foo.a(bar.o)' by
  414. copying the *file* `bar.o' into the archive `foo.a' as a *member* named
  415. `bar.o'.
  416.  
  417.    When this rule is chained with others, the result is very powerful.
  418. Thus, `make "foo.a(bar.o)"' (the quotes are needed to protect the `('
  419. and `)' from being interpreted specially by the shell) in the presence
  420. of a file `bar.c' is enough to cause the following commands to be run,
  421. even without a makefile:
  422.  
  423.      cc -c bar.c -o bar.o
  424.      ar r foo.a bar.o
  425.      rm -f bar.o
  426.  
  427. Here `make' has envisioned the file `bar.o' as an intermediate file.
  428. *Note Chains of Implicit Rules: Chained Rules.
  429.  
  430.    Implicit rules such as this one are written using the automatic
  431. variable `$%'.  *Note Automatic Variables: Automatic.
  432.  
  433.    An archive member name in an archive cannot contain a directory
  434. name, but it may be useful in a makefile to pretend that it does.  If
  435. you write an archive member target `foo.a(dir/file.o)', `make' will
  436. perform automatic updating with this command:
  437.  
  438.      ar r foo.a dir/file.o
  439.  
  440. which has the effect of copying the file `dir/file.o' into a member
  441. named `file.o'.  In connection with such usage, the automatic variables
  442. `%D' and `%F' may be useful.
  443.  
  444. * Menu:
  445.  
  446. * Archive Symbols::             How to update archive symbol directories.
  447.  
  448. 
  449. File: make.info,  Node: Archive Symbols,  Up: Archive Update
  450.  
  451. Updating Archive Symbol Directories
  452. -----------------------------------
  453.  
  454.    An archive file that is used as a library usually contains a special
  455. member named `__.SYMDEF' that contains a directory of the external
  456. symbol names defined by all the other members.  After you update any
  457. other members, you need to update `__.SYMDEF' so that it will summarize
  458. the other members properly.  This is done by running the `ranlib'
  459. program:
  460.  
  461.      ranlib ARCHIVEFILE
  462.  
  463.    Normally you would put this command in the rule for the archive file,
  464. and make all the members of the archive file dependencies of that rule.
  465. For example,
  466.  
  467.      libfoo.a: libfoo.a(x.o) libfoo.a(y.o) ...
  468.              ranlib libfoo.a
  469.  
  470. The effect of this is to update archive members `x.o', `y.o', etc., and
  471. then update the symbol directory member `__.SYMDEF' by running
  472. `ranlib'.  The rules for updating the members are not shown here; most
  473. likely you can omit them and use the implicit rule which copies files
  474. into the archive, as described in the preceding section.
  475.  
  476.    This is not necessary when using the GNU `ar' program, which updates
  477. the `__.SYMDEF' member automatically.
  478.  
  479. 
  480. File: make.info,  Node: Archive Pitfalls,  Next: Archive Suffix Rules,  Prev: Archive Update,  Up: Archives
  481.  
  482. Dangers When Using Archives
  483. ===========================
  484.  
  485.    It is important to be careful when using parallel execution (the
  486. `-j' switch; *note Parallel Execution: Parallel.) and archives.  If
  487. multiple `ar' commands run at the same time on the same archive file,
  488. they will not know about each other and can corrupt the file.
  489.  
  490.    Possibly a future version of `make' will provide a mechanism to
  491. circumvent this problem by serializing all commands that operate on the
  492. same archive file.  But for the time being, you must either write your
  493. makefiles to avoid this problem in some other way, or not use `-j'.
  494.  
  495. 
  496. File: make.info,  Node: Archive Suffix Rules,  Prev: Archive Pitfalls,  Up: Archives
  497.  
  498. Suffix Rules for Archive Files
  499. ==============================
  500.  
  501.    You can write a special kind of suffix rule for dealing with archive
  502. files.  *Note Suffix Rules::, for a full explanation of suffix rules.
  503. Archive suffix rules are obsolete in GNU `make', because pattern rules
  504. for archives are a more general mechanism (*note Archive Update::.).
  505. But they are retained for compatibility with other `make's.
  506.  
  507.    To write a suffix rule for archives, you simply write a suffix rule
  508. using the target suffix `.a' (the usual suffix for archive files).  For
  509. example, here is the old-fashioned suffix rule to update a library
  510. archive from C source files:
  511.  
  512.      .c.a:
  513.              $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  514.              $(AR) r $@ $*.o
  515.              $(RM) $*.o
  516.  
  517. This works just as if you had written the pattern rule:
  518.  
  519.      (%.o): %.c
  520.              $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  521.              $(AR) r $@ $*.o
  522.              $(RM) $*.o
  523.  
  524.    In fact, this is just what `make' does when it sees a suffix rule
  525. with `.a' as the target suffix.  Any double-suffix rule `.X.a' is
  526. converted to a pattern rule with the target pattern `(%.o)' and a
  527. dependency pattern of `%.X'.
  528.  
  529.    Since you might want to use `.a' as the suffix for some other kind
  530. of file, `make' also converts archive suffix rules to pattern rules in
  531. the normal way (*note Suffix Rules::.).  Thus a double-suffix rule
  532. `.X.a' produces two pattern rules: `(%.o): %.X' and `%.a: %.X'.
  533.  
  534. 
  535. File: make.info,  Node: Features,  Next: Missing,  Prev: Archives,  Up: Top
  536.  
  537. Features of GNU `make'
  538. **********************
  539.  
  540.    Here is a summary of the features of GNU `make', for comparison with
  541. and credit to other versions of `make'.  We consider the features of
  542. `make' in 4.2 BSD systems as a baseline.  If you are concerned with
  543. writing portable makefiles, you should use only the features of `make'
  544. *not* listed here or in *Note Missing::.
  545.  
  546.    Many features come from the version of `make' in System V.
  547.  
  548.    * The `VPATH' variable and its special meaning.  *Note Searching
  549.      Directories for Dependencies: Directory Search.  This feature
  550.      exists in System V `make', but is undocumented.  It is documented
  551.      in 4.3 BSD `make' (which says it mimics System V's `VPATH'
  552.      feature).
  553.  
  554.    * Included makefiles.  *Note Including Other Makefiles: Include.
  555.      Allowing multiple files to be included with a single directive is
  556.      a GNU extension.
  557.  
  558.    * Variables are read from and communicated via the environment.
  559.      *Note Variables from the Environment: Environment.
  560.  
  561.    * Options passed through the variable `MAKEFLAGS' to recursive
  562.      invocations of `make'.  *Note Communicating Options to a
  563.      Sub-`make': Options/Recursion.
  564.  
  565.    * The automatic variable `$%' is set to the member name in an
  566.      archive reference.  *Note Automatic Variables: Automatic.
  567.  
  568.    * The automatic variables `$@', `$*', `$<', `$%', and `$?' have
  569.      corresponding forms like `$(@F)' and `$(@D)'.  We have generalized
  570.      this to `$^' as an obvious extension.  *Note Automatic Variables:
  571.      Automatic.
  572.  
  573.    * Substitution variable references.  *Note Basics of Variable
  574.      References: Reference.
  575.  
  576.    * The command-line options `-b' and `-m', accepted and ignored.  In
  577.      System V `make', these options actually do something.
  578.  
  579.    * Execution of recursive commands to run `make' via the variable
  580.      `MAKE' even if `-n', `-q' or `-t' is specified.  *Note Recursive
  581.      Use of `make': Recursion.
  582.  
  583.    * Support for suffix `.a' in suffix rules.  *Note Archive Suffix
  584.      Rules::.  This feature is obsolete in GNU `make', because the
  585.      general feature of rule chaining (*note Chains of Implicit Rules:
  586.      Chained Rules.) allows one pattern rule for installing members in
  587.      an archive (*note Archive Update::.) to be sufficient.
  588.  
  589.    * The arrangement of lines and backslash-newline combinations in
  590.      commands is retained when the commands are printed, so they appear
  591.      as they do in the makefile, except for the stripping of initial
  592.      whitespace.
  593.  
  594.    The following features were inspired by various other versions of
  595. `make'.  In some cases it is unclear exactly which versions inspired
  596. which others.
  597.  
  598.    * Pattern rules using `%'.  This has been implemented in several
  599.      versions of `make'.  We're not sure who invented it first, but
  600.      it's been spread around a bit.  *Note Defining and Redefining
  601.      Pattern Rules: Pattern Rules.
  602.  
  603.    * Rule chaining and implicit intermediate files.  This was
  604.      implemented by Stu Feldman in his version of `make' for AT&T
  605.      Eighth Edition Research Unix, and later by Andrew Hume of AT&T
  606.      Bell Labs in his `mk' program (where he terms it "transitive
  607.      closure").  We do not really know if we got this from either of
  608.      them or thought it up ourselves at the same time.  *Note Chains of
  609.      Implicit Rules: Chained Rules.
  610.  
  611.    * The automatic variable `$^' containing a list of all dependencies
  612.      of the current target.  We did not invent this, but we have no
  613.      idea who did.  *Note Automatic Variables: Automatic.  The
  614.      automatic variable `$+' is a simple extension of `$^'.
  615.  
  616.    * The "what if" flag (`-W' in GNU `make') was (as far as we know)
  617.      invented by Andrew Hume in `mk'.  *Note Instead of Executing the
  618.      Commands: Instead of Execution.
  619.  
  620.    * The concept of doing several things at once (parallelism) exists in
  621.      many incarnations of `make' and similar programs, though not in the
  622.      System V or BSD implementations.  *Note Command Execution:
  623.      Execution.
  624.  
  625.    * Modified variable references using pattern substitution come from
  626.      SunOS 4.  *Note Basics of Variable References: Reference.  This
  627.      functionality was provided in GNU `make' by the `patsubst'
  628.      function before the alternate syntax was implemented for
  629.      compatibility with SunOS 4.  It is not altogether clear who
  630.      inspired whom, since GNU `make' had `patsubst' before SunOS 4 was
  631.      released.
  632.  
  633.    * The special significance of `+' characters preceding command lines
  634.      (*note Instead of Executing the Commands: Instead of Execution.) is
  635.      mandated by `IEEE Standard 1003.2-1992' (POSIX.2).
  636.  
  637.    * The `+=' syntax to append to the value of a variable comes from
  638.      SunOS 4 `make'.  *Note Appending More Text to Variables: Appending.
  639.  
  640.    * The syntax `ARCHIVE(MEM1 MEM2...)' to list multiple members in a
  641.      single archive file comes from SunOS 4 `make'.  *Note Archive
  642.      Members::.
  643.  
  644.    * The `-include' directive to include makefiles with no error for a
  645.      nonexistent file comes from SunOS 4 `make'.  (But note that SunOS 4
  646.      `make' does not allow multiple makefiles to be specified in one
  647.      `-include' directive.)  The same feature appears with the name
  648.      `sinclude' in SGI `make' and perhaps others.
  649.  
  650.    The remaining features are inventions new in GNU `make':
  651.  
  652.    * Use the `-v' or `--version' option to print version and copyright
  653.      information.
  654.  
  655.    * Use the `-h' or `--help' option to summarize the options to `make'.
  656.  
  657.    * Simply-expanded variables.  *Note The Two Flavors of Variables:
  658.      Flavors.
  659.  
  660.    * Pass command-line variable assignments automatically through the
  661.      variable `MAKE' to recursive `make' invocations.  *Note Recursive
  662.      Use of `make': Recursion.
  663.  
  664.    * Use the `-C' or `--directory' command option to change directory.
  665.      *Note Summary of Options: Options Summary.
  666.  
  667.    * Make verbatim variable definitions with `define'.  *Note Defining
  668.      Variables Verbatim: Defining.
  669.  
  670.    * Declare phony targets with the special target `.PHONY'.
  671.  
  672.      Andrew Hume of AT&T Bell Labs implemented a similar feature with a
  673.      different syntax in his `mk' program.  This seems to be a case of
  674.      parallel discovery.  *Note Phony Targets: Phony Targets.
  675.  
  676.    * Manipulate text by calling functions.  *Note Functions for
  677.      Transforming Text: Functions.
  678.  
  679.    * Use the `-o' or `--old-file' option to pretend a file's
  680.      modification-time is old.  *Note Avoiding Recompilation of Some
  681.      Files: Avoiding Compilation.
  682.  
  683.    * Conditional execution.
  684.  
  685.      This feature has been implemented numerous times in various
  686.      versions of `make'; it seems a natural extension derived from the
  687.      features of the C preprocessor and similar macro languages and is
  688.      not a revolutionary concept.  *Note Conditional Parts of
  689.      Makefiles: Conditionals.
  690.  
  691.    * Specify a search path for included makefiles.  *Note Including
  692.      Other Makefiles: Include.
  693.  
  694.    * Specify extra makefiles to read with an environment variable.
  695.      *Note The Variable `MAKEFILES': MAKEFILES Variable.
  696.  
  697.    * Strip leading sequences of `./' from file names, so that `./FILE'
  698.      and `FILE' are considered to be the same file.
  699.  
  700.    * Use a special search method for library dependencies written in the
  701.      form `-lNAME'.  *Note Directory Search for Link Libraries:
  702.      Libraries/Search.
  703.  
  704.    * Allow suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
  705.      Suffix Rules.) to contain any characters.  In other versions of
  706.      `make', they must begin with `.' and not contain any `/'
  707.      characters.
  708.  
  709.    * Keep track of the current level of `make' recursion using the
  710.      variable `MAKELEVEL'.  *Note Recursive Use of `make': Recursion.
  711.  
  712.    * Specify static pattern rules.  *Note Static Pattern Rules: Static
  713.      Pattern.
  714.  
  715.    * Provide selective `vpath' search.  *Note Searching Directories for
  716.      Dependencies: Directory Search.
  717.  
  718.    * Provide computed variable references.  *Note Basics of Variable
  719.      References: Reference.
  720.  
  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.
  724.  
  725.    * Various new built-in implicit rules.  *Note Catalogue of Implicit
  726.      Rules: Catalogue of Rules.
  727.  
  728.    * The built-in variable `MAKE_VERSION' gives the version number of
  729.      `make'.
  730.  
  731. 
  732. File: make.info,  Node: Missing,  Next: Makefile Conventions,  Prev: Features,  Up: Top
  733.  
  734. Incompatibilities and Missing Features
  735. **************************************
  736.  
  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
  740. these features.
  741.  
  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.
  745.  
  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.
  750.  
  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:
  757.      Suffix Rules.
  758.  
  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:
  762.      Chained Rules.
  763.  
  764.    * In System V `make', the string `$$@' has the strange meaning that,
  765.      in the dependencies of a rule with multiple targets, it stands for
  766.      the particular target that is being processed.
  767.  
  768.      This is not defined in GNU `make' because `$$' should always stand
  769.      for an ordinary `$'.
  770.  
  771.      It is possible to get this functionality through the use of static
  772.      pattern rules (*note Static Pattern Rules: Static Pattern.).  The
  773.      System V `make' rule:
  774.  
  775.           $(targets): $$@.o lib.a
  776.  
  777.      can be replaced with the GNU `make' static pattern rule:
  778.  
  779.           $(targets): %: %.o lib.a
  780.  
  781.    * In System V and 4.3 BSD `make', files found by `VPATH' search
  782.      (*note Searching Directories for Dependencies: Directory Search.)
  783.      have their names changed inside command strings.  We feel it is
  784.      much cleaner to always use automatic variables and thus make this
  785.      feature obsolete.
  786.  
  787.    * In some Unix `make's, the automatic variable `$*' appearing in the
  788.      dependencies of a rule has the amazingly strange "feature" of
  789.      expanding to the full name of the *target of that rule*.  We cannot
  790.      imagine what went on in the minds of Unix `make' developers to do
  791.      this; it is utterly inconsistent with the normal definition of
  792.      `$*'.
  793.  
  794.    * In some Unix `make's, implicit rule search (*note Using Implicit
  795.      Rules: Implicit Rules.) is apparently done for *all* targets, not
  796.      just those without commands.  This means you can do:
  797.  
  798.           foo.o:
  799.                   cc -c foo.c
  800.  
  801.      and Unix `make' will intuit that `foo.o' depends on `foo.c'.
  802.  
  803.      We feel that such usage is broken.  The dependency properties of
  804.      `make' are well-defined (for GNU `make', at least), and doing such
  805.      a thing simply does not fit the model.
  806.  
  807.    * GNU `make' does not include any built-in implicit rules for
  808.      compiling or preprocessing EFL programs.  If we hear of anyone who
  809.      is using EFL, we will gladly add them.
  810.  
  811.    * It appears that in SVR4 `make', a suffix rule can be specified with
  812.      no commands, and it is treated as if it had empty commands (*note
  813.      Empty Commands::.).  For example:
  814.  
  815.           .c.a:
  816.  
  817.      will override the built-in `.c.a' suffix rule.
  818.  
  819.      We feel that it is cleaner for a rule without commands to always
  820.      simply add to the dependency list for the target.  The above
  821.      example can be easily rewritten to get the desired behavior in GNU
  822.      `make':
  823.  
  824.           .c.a: ;
  825.  
  826.    * Some versions of `make' invoke the shell with the `-e' flag,
  827.      except under `-k' (*note Testing the Compilation of a Program:
  828.      Testing.).  The `-e' flag tells the shell to exit as soon as any
  829.      program it runs returns a nonzero status.  We feel it is cleaner to
  830.      write each shell command line to stand on its own and not require
  831.      this special treatment.
  832.  
  833. 
  834. File: make.info,  Node: Makefile Conventions,  Next: Quick Reference,  Prev: Missing,  Up: Top
  835.  
  836. Makefile Conventions
  837. ********************
  838.  
  839.    This node describes conventions for writing the Makefiles for GNU
  840. programs.
  841.  
  842. * Menu:
  843.  
  844. * Makefile Basics::        General Conventions for Makefiles
  845. * Utilities in Makefiles::    Utilities in Makefiles
  846. * Command Variables::        Variables for Specifying Commands
  847. * Directory Variables::        Variables for Installation Directories
  848. * Standard Targets::        Standard Targets for Users
  849.  
  850. 
  851. File: make.info,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
  852.  
  853. General Conventions for Makefiles
  854. =================================
  855.  
  856.    Every Makefile should contain this line:
  857.  
  858.      SHELL = /bin/sh
  859.  
  860. to avoid trouble on systems where the `SHELL' variable might be
  861. inherited from the environment.  (This is never a problem with GNU
  862. `make'.)
  863.  
  864.    Different `make' programs have incompatible suffix lists and
  865. implicit rules, and this sometimes creates confusion or misbehavior.  So
  866. it is a good idea to set the suffix list explicitly using only the
  867. suffixes you need in the particular Makefile, like this:
  868.  
  869.      .SUFFIXES:
  870.      .SUFFIXES: .c .o
  871.  
  872. The first line clears out the suffix list, the second introduces all
  873. suffixes which may be subject to implicit rules in this Makefile.
  874.  
  875.    Don't assume that `.' is in the path for command execution.  When
  876. you need to run programs that are a part of your package during the
  877. make, please make sure that it uses `./' if the program is built as
  878. part of the make or `$(srcdir)/' if the file is an unchanging part of
  879. the source code.  Without one of these prefixes, the current search
  880. path is used.
  881.  
  882.    The distinction between `./' and `$(srcdir)/' is important when
  883. using the `--srcdir' option to `configure'.  A rule of the form:
  884.  
  885.      foo.1 : foo.man sedscript
  886.              sed -e sedscript foo.man > foo.1
  887.  
  888. will fail when the current directory is not the source directory,
  889. because `foo.man' and `sedscript' are not in the current directory.
  890.  
  891.    When using GNU `make', relying on `VPATH' to find the source file
  892. will work in the case where there is a single dependency file, since
  893. the `make' automatic variable `$<' will represent the source file
  894. wherever it is.  (Many versions of `make' set `$<' only in implicit
  895. rules.)  A Makefile target like
  896.  
  897.      foo.o : bar.c
  898.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  899.  
  900. should instead be written as
  901.  
  902.      foo.o : bar.c
  903.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@
  904.  
  905. in order to allow `VPATH' to work correctly.  When the target has
  906. multiple dependencies, using an explicit `$(srcdir)' is the easiest way
  907. to make the rule work well.  For example, the target above for `foo.1'
  908. is best written as:
  909.  
  910.      foo.1 : foo.man sedscript
  911.              sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@
  912.  
  913.    Try to make the build and installation targets, at least (and all
  914. their subtargets) work correctly with a parallel `make'.
  915.  
  916. 
  917. File: make.info,  Node: Utilities in Makefiles,  Next: Command Variables,  Prev: Makefile Basics,  Up: Makefile Conventions
  918.  
  919. Utilities in Makefiles
  920. ======================
  921.  
  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'.
  925.  
  926.    The `configure' script and the Makefile rules for building and
  927. installation should not use any utilities directly except these:
  928.  
  929.      cat cmp cp echo egrep expr false grep
  930.      ln mkdir mv pwd rm rmdir sed test touch true
  931.  
  932.    Stick to the generally supported options for these programs.  For
  933. example, don't use `mkdir -p', convenient as it may be, because most
  934. systems don't support it.
  935.  
  936.    It is a good idea to avoid creating symbolic links in makefiles,
  937. since a few systems don't support them.
  938.  
  939.    The Makefile rules for building and installation can also use
  940. compilers and related programs, but should do so via `make' variables
  941. so that the user can substitute alternatives.  Here are some of the
  942. programs we mean:
  943.  
  944.      ar bison cc flex install ld lex
  945.      make makeinfo ranlib texi2dvi yacc
  946.  
  947.    Use the following `make' variables:
  948.  
  949.      $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LEX)
  950.      $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
  951.  
  952.    When you use `ranlib', you should make sure nothing bad happens if
  953. the system does not have `ranlib'.  Arrange to ignore an error from
  954. that command, and print a message before the command to tell the user
  955. that failure of the `ranlib' command does not mean a problem.  (The
  956. Autoconf `AC_PROG_RANLIB' macro can help with this.)
  957.  
  958.    If you use symbolic links, you should implement a fallback for
  959. systems that don't have symbolic links.
  960.  
  961.    It is ok to use other utilities in Makefile portions (or scripts)
  962. intended only for particular systems where you know those utilities
  963. exist.
  964.  
  965. 
  966. File: make.info,  Node: Command Variables,  Next: Directory Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
  967.  
  968. Variables for Specifying Commands
  969. =================================
  970.  
  971.    Makefiles should provide variables for overriding certain commands,
  972. options, and so on.
  973.  
  974.    In particular, you should run most utility programs via variables.
  975. Thus, if you use Bison, have a variable named `BISON' whose default
  976. value is set with `BISON = bison', and refer to it with `$(BISON)'
  977. whenever you need to use Bison.
  978.  
  979.    File management utilities such as `ln', `rm', `mv', and so on, need
  980. not be referred to through variables in this way, since users don't
  981. need to replace them with other programs.
  982.  
  983.    Each program-name variable should come with an options variable that
  984. is used to supply options to the program.  Append `FLAGS' to the
  985. program-name variable name to get the options variable name--for
  986. example, `BISONFLAGS'.  (The name `CFLAGS' is an exception to this
  987. rule, but we keep it because it is standard.)  Use `CPPFLAGS' in any
  988. compilation command that runs the preprocessor, and use `LDFLAGS' in
  989. any compilation command that does linking as well as in any direct use
  990. of `ld'.
  991.  
  992.    If there are C compiler options that *must* be used for proper
  993. compilation of certain files, do not include them in `CFLAGS'.  Users
  994. expect to be able to specify `CFLAGS' freely themselves.  Instead,
  995. arrange to pass the necessary options to the C compiler independently
  996. of `CFLAGS', by writing them explicitly in the compilation commands or
  997. by defining an implicit rule, like this:
  998.  
  999.      CFLAGS = -g
  1000.      ALL_CFLAGS = -I. $(CFLAGS)
  1001.      .c.o:
  1002.              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  1003.  
  1004.    Do include the `-g' option in `CFLAGS', because that is not
  1005. *required* for proper compilation.  You can consider it a default that
  1006. is only recommended.  If the package is set up so that it is compiled
  1007. with GCC by default, then you might as well include `-O' in the default
  1008. value of `CFLAGS' as well.
  1009.  
  1010.    Put `CFLAGS' last in the compilation command, after other variables
  1011. containing compiler options, so the user can use `CFLAGS' to override
  1012. the others.
  1013.  
  1014.    Every Makefile should define the variable `INSTALL', which is the
  1015. basic command for installing a file into the system.
  1016.  
  1017.    Every Makefile should also define the variables `INSTALL_PROGRAM'
  1018. and `INSTALL_DATA'.  (The default for each of these should be
  1019. `$(INSTALL)'.)  Then it should use those variables as the commands for
  1020. actual installation, for executables and nonexecutables respectively.
  1021. Use these variables as follows:
  1022.  
  1023.      $(INSTALL_PROGRAM) foo $(bindir)/foo
  1024.      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  1025.  
  1026. Always use a file name, not a directory name, as the second argument of
  1027. the installation commands.  Use a separate command for each file to be
  1028. installed.
  1029.  
  1030.