home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / make-3.70-bin.lha / info / make.info-6 (.txt) < prev    next >
GNU Info File  |  1994-02-21  |  48KB  |  870 lines

  1. This is Info file make.info, produced by Makeinfo-1.54 from the input
  2. file ./make.texinfo.
  3.    This file documents the GNU Make utility, which determines
  4. automatically which pieces of a large program need to be recompiled,
  5. and issues the commands to recompile them.
  6.    This is Edition 0.45, last updated 14 December 1993, of `The GNU
  7. Make Manual', for `make', Version 3.70 Beta.
  8.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  9. Foundation, Inc.
  10.    Permission is granted to make and distribute verbatim copies of this
  11. manual provided the copyright notice and this permission notice are
  12. preserved on all copies.
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that this permission notice may be stated in a
  20. translation approved by the Free Software Foundation.
  21. File: make.info,  Node: Suffix Rules,  Next: Search Algorithm,  Prev: Last Resort,  Up: Implicit Rules
  22. Old-Fashioned Suffix Rules
  23. ==========================
  24.    "Suffix rules" are the old-fashioned way of defining implicit rules
  25. for `make'.  Suffix rules are obsolete because pattern rules are more
  26. general and clearer.  They are supported in GNU `make' for
  27. compatibility with old makefiles.  They come in two kinds:
  28. "double-suffix" and "single-suffix".
  29.    A double-suffix rule is defined by a pair of suffixes: the target
  30. suffix and the source suffix.  It matches any file whose name ends with
  31. the target suffix.  The corresponding implicit dependency is made by
  32. replacing the target suffix with the source suffix in the file name.  A
  33. two-suffix rule whose target and source suffixes are `.o' and `.c' is
  34. equivalent to the pattern rule `%.o : %.c'.
  35.    A single-suffix rule is defined by a single suffix, which is the
  36. source suffix.  It matches any file name, and the corresponding implicit
  37. dependency name is made by appending the source suffix.  A single-suffix
  38. rule whose source suffix is `.c' is equivalent to the pattern rule `% :
  39. %.c'.
  40.    Suffix rule definitions are recognized by comparing each rule's
  41. target against a defined list of known suffixes.  When `make' sees a
  42. rule whose target is a known suffix, this rule is considered a
  43. single-suffix rule.  When `make' sees a rule whose target is two known
  44. suffixes concatenated, this rule is taken as a double-suffix rule.
  45.    For example, `.c' and `.o' are both on the default list of known
  46. suffixes.  Therefore, if you define a rule whose target is `.c.o',
  47. `make' takes it to be a double-suffix rule with source suffix `.c' and
  48. target suffix `.o'.  Here is the old-fashioned way to define the rule
  49. for compiling a C source file:
  50.      .c.o:
  51.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  52.    Suffix rules cannot have any dependencies of their own.  If they
  53. have any, they are treated as normal files with funny names, not as
  54. suffix rules.  Thus, the rule:
  55.      .c.o: foo.h
  56.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  57. tells how to make the file `.c.o' from the dependency file `foo.h', and
  58. is not at all like the pattern rule:
  59.      %.o: %.c foo.h
  60.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  61. which tells how to make `.o' files from `.c' files, and makes all `.o'
  62. files using this pattern rule also depend on `foo.h'.
  63.    Suffix rules with no commands are also meaningless.  They do not
  64. remove previous rules as do pattern rules with no commands (*note
  65. Canceling Implicit Rules: Canceling Rules.).  They simply enter the
  66. suffix or pair of suffixes concatenated as a target in the data base.
  67.    The known suffixes are simply the names of the dependencies of the
  68. special target `.SUFFIXES'.  You can add your own suffixes by writing a
  69. rule for `.SUFFIXES' that adds more dependencies, as in:
  70.      .SUFFIXES: .hack .win
  71. which adds `.hack' and `.win' to the end of the list of suffixes.
  72.    If you wish to eliminate the default known suffixes instead of just
  73. adding to them, write a rule for `.SUFFIXES' with no dependencies.  By
  74. special dispensation, this eliminates all existing dependencies of
  75. `.SUFFIXES'.  You can then write another rule to add the suffixes you
  76. want.  For example,
  77.      .SUFFIXES:            # Delete the default suffixes
  78.      .SUFFIXES: .c .o .h   # Define our suffix list
  79.    The `-r' or `--no-builtin-rules' flag causes the default list of
  80. suffixes to be empty.
  81.    The variable `SUFFIXES' is defined to the default list of suffixes
  82. before `make' reads any makefiles.  You can change the list of suffixes
  83. with a rule for the special target `.SUFFIXES', but that does not alter
  84. this variable.
  85. File: make.info,  Node: Search Algorithm,  Prev: Suffix Rules,  Up: Implicit Rules
  86. Implicit Rule Search Algorithm
  87. ==============================
  88.    Here is the procedure `make' uses for searching for an implicit rule
  89. for a target T.  This procedure is followed for each double-colon rule
  90. with no commands, for each target of ordinary rules none of which have
  91. commands, and for each dependency that is not the target of any rule.
  92. It is also followed recursively for dependencies that come from implicit
  93. rules, in the search for a chain of rules.
  94.    Suffix rules are not mentioned in this algorithm because suffix
  95. rules are converted to equivalent pattern rules once the makefiles have
  96. been read in.
  97.    For an archive member target of the form `ARCHIVE(MEMBER)', the
  98. following algorithm is run twice, first using the entire target name T,
  99. and second using `(MEMBER)' as the target T if the first run found no
  100. rule.
  101.   1. Split T into a directory part, called D, and the rest, called N.
  102.      For example, if T is `src/foo.o', then D is `src/' and N is
  103.      `foo.o'.
  104.   2. Make a list of all the pattern rules one of whose targets matches
  105.      T or N.  If the target pattern contains a slash, it is matched
  106.      against T; otherwise, against N.
  107.   3. If any rule in that list is *not* a match-anything rule, then
  108.      remove all nonterminal match-anything rules from the list.
  109.   4. Remove from the list all rules with no commands.
  110.   5. For each pattern rule in the list:
  111.        a. Find the stem S, which is the nonempty part of T or N matched
  112.           by the `%' in the target pattern.
  113.        b. Compute the dependency names by substituting S for `%'; if
  114.           the target pattern does not contain a slash, append D to the
  115.           front of each dependency name.
  116.        c. Test whether all the dependencies exist or ought to exist.
  117.           (If a file name is mentioned in the makefile as a target or
  118.           as an explicit dependency, then we say it ought to exist.)
  119.           If all dependencies exist or ought to exist, or there are no
  120.           dependencies, then this rule applies.
  121.   6. If no pattern rule has been found so far, try harder.  For each
  122.      pattern rule in the list:
  123.        a. If the rule is terminal, ignore it and go on to the next rule.
  124.        b. Compute the dependency names as before.
  125.        c. Test whether all the dependencies exist or ought to exist.
  126.        d. For each dependency that does not exist, follow this algorithm
  127.           recursively to see if the dependency can be made by an
  128.           implicit rule.
  129.        e. If all dependencies exist, ought to exist, or can be made by
  130.           implicit rules, then this rule applies.
  131.   7. If no implicit rule applies, the rule for `.DEFAULT', if any,
  132.      applies.  In that case, give T the same commands that `.DEFAULT'
  133.      has.  Otherwise, there are no commands for T.
  134.    Once a rule that applies has been found, for each target pattern of
  135. the rule other than the one that matched T or N, the `%' in the pattern
  136. is replaced with S and the resultant file name is stored until the
  137. commands to remake the target file T are executed.  After these
  138. commands are executed, each of these stored file names are entered into
  139. the data base and marked as having been updated and having the same
  140. update status as the file T.
  141.    When the commands of a pattern rule are executed for T, the automatic
  142. variables are set corresponding to the target and dependencies.  *Note
  143. Automatic Variables: Automatic.
  144. File: make.info,  Node: Archives,  Next: Features,  Prev: Implicit Rules,  Up: Top
  145. Using `make' to Update Archive Files
  146. ************************************
  147.    "Archive files" are files containing named subfiles called
  148. "members"; they are maintained with the program `ar' and their main use
  149. is as subroutine libraries for linking.
  150. * Menu:
  151. * Archive Members::             Archive members as targets.
  152. * Archive Update::              The implicit rule for archive member targets.
  153. * Archive Suffix Rules::        You can write a special kind of suffix rule
  154.                                   for updating archives.
  155. File: make.info,  Node: Archive Members,  Next: Archive Update,  Up: Archives
  156. Archive Members as Targets
  157. ==========================
  158.    An individual member of an archive file can be used as a target or
  159. dependency in `make'.  The archive file must already exist, but the
  160. member need not exist.  You specify the member named MEMBER in archive
  161. file ARCHIVE as follows:
  162.      ARCHIVE(MEMBER)
  163. This construct is available only in targets and dependencies, not in
  164. commands!  Most programs that you might use in commands do not support
  165. this syntax and cannot act directly on archive members.  Only `ar' and
  166. other programs specifically designed to operate on archives can do so.
  167. Therefore, valid commands to update an archive member target probably
  168. must use `ar'.  For example, this rule says to create a member `hack.o'
  169. in archive `foolib' by copying the file `hack.o':
  170.      foolib(hack.o) : hack.o
  171.              ar r foolib hack.o
  172.    In fact, nearly all archive member targets are updated in just this
  173. way and there is an implicit rule to do it for you.
  174.    To specify several members in the same archive, you can write all the
  175. member names together between the parentheses.  For example:
  176.      foolib(hack.o kludge.o)
  177. is equivalent to:
  178.      foolib(hack.o) foolib(kludge.o)
  179.    You can also use shell-style wildcards in an archive member
  180. reference.  *Note Using Wildcard Characters in File Names: Wildcards.
  181. For example, `foolib(*.o)' expands to all existing members of the
  182. `foolib' archive whose names end in `.o'; perhaps `foolib(hack.o)
  183. foolib(kludge.o)'.
  184. File: make.info,  Node: Archive Update,  Next: Archive Suffix Rules,  Prev: Archive Members,  Up: Archives
  185. Implicit Rule for Archive Member Targets
  186. ========================================
  187.    Recall that a target that looks like `A(M)' stands for the member
  188. named M in the archive file A.
  189.    When `make' looks for an implicit rule for such a target, as a
  190. special feature it considers implicit rules that match `(M)', as well as
  191. those that match the actual target `A(M)'.
  192.    This causes one special rule whose target is `(%)' to match.  This
  193. rule updates the target `A(M)' by copying the file M into the archive.
  194. For example, it will update the archive member target `foo.a(bar.o)' by
  195. copying the *file* `bar.o' into the archive `foo.a' as a *member* named
  196. `bar.o'.
  197.    When this rule is chained with others, the result is very powerful.
  198. Thus, `make "foo.a(bar.o)"' (the quotes are needed to protect the `('
  199. and `)' from being interpreted specially by the shell) in the presence
  200. of a file `bar.c' is enough to cause the following commands to be run,
  201. even without a makefile:
  202.      cc -c bar.c -o bar.o
  203.      ar r foo.a bar.o
  204.      rm -f bar.o
  205. Here `make' has envisioned the file `bar.o' as an intermediate file.
  206. *Note Chains of Implicit Rules: Chained Rules.
  207.    Implicit rules such as this one are written using the automatic
  208. variable `$%'.  *Note Automatic Variables: Automatic.
  209.    An archive member name in an archive cannot contain a directory
  210. name, but it may be useful in a makefile to pretend that it does.  If
  211. you write an archive member target `foo.a(dir/file.o)', `make' will
  212. perform automatic updating with this command:
  213.      ar r foo.a dir/file.o
  214. which has the effect of copying the file `dir/foo.o' into a member
  215. named `foo.o'.  In connection with such usage, the automatic variables
  216. `%D' and `%F' may be useful.
  217. * Menu:
  218. * Archive Symbols::             How to update archive symbol directories.
  219. File: make.info,  Node: Archive Symbols,  Up: Archive Update
  220. Updating Archive Symbol Directories
  221. -----------------------------------
  222.    An archive file that is used as a library usually contains a special
  223. member named `__.SYMDEF' that contains a directory of the external
  224. symbol names defined by all the other members.  After you update any
  225. other members, you need to update `__.SYMDEF' so that it will summarize
  226. the other members properly.  This is done by running the `ranlib'
  227. program:
  228.      ranlib ARCHIVEFILE
  229.    Normally you would put this command in the rule for the archive file,
  230. and make all the members of the archive file dependencies of that rule.
  231. For example,
  232.      libfoo.a: libfoo.a(x.o) libfoo.a(y.o) ...
  233.              ranlib libfoo.a
  234. The effect of this is to update archive members `x.o', `y.o', etc., and
  235. then update the symbol directory member `__.SYMDEF' by running
  236. `ranlib'.  The rules for updating the members are not shown here; most
  237. likely you can omit them and use the implicit rule which copies files
  238. into the archive, as described in the preceding section.
  239.    This is not necessary when using the GNU `ar' program, which updates
  240. the `__.SYMDEF' member automatically.
  241. File: make.info,  Node: Archive Suffix Rules,  Prev: Archive Update,  Up: Archives
  242. Suffix Rules for Archive Files
  243. ==============================
  244.    You can write a special kind of suffix rule for dealing with archive
  245. files.  *Note Suffix Rules::, for a full explanation of suffix rules.
  246. Archive suffix rules are obsolete in GNU `make', because pattern rules
  247. for archives are a more general mechanism (*note Archive Update::.).
  248. But they are retained for compatibility with other `make's.
  249.    To write a suffix rule for archives, you simply write a suffix rule
  250. using the target suffix `.a' (the usual suffix for archive files).  For
  251. example, here is the old-fashioned suffix rule to update a library
  252. archive from C source files:
  253.      .c.a:
  254.              $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  255.              $(AR) r $@ $*.o
  256.              $(RM) $*.o
  257. This works just as if you had written the pattern rule:
  258.      (%.o): %.c
  259.              $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  260.              $(AR) r $@ $*.o
  261.              $(RM) $*.o
  262.    In fact, this is just what `make' does when it sees a suffix rule
  263. with `.a' as the target suffix.  Any double-suffix rule `.X.a' is
  264. converted to a pattern rule with the target pattern `(%.o)' and a
  265. dependency pattern of `%.X'.
  266.    Since you might want to use `.a' as the suffix for some other kind
  267. of file, `make' also converts archive suffix rules to pattern rules in
  268. the normal way (*note Suffix Rules::.).  Thus a double-suffix rule
  269. `.X.a' produces two pattern rules: `(%.o): %.X' and `%.a: %.X'.
  270. File: make.info,  Node: Features,  Next: Missing,  Prev: Archives,  Up: Top
  271. Features of GNU `make'
  272. **********************
  273.    Here is a summary of the features of GNU `make', for comparison with
  274. and credit to other versions of `make'.  We consider the features of
  275. `make' in 4.2 BSD systems as a baseline.  If you are concerned with
  276. writing portable makefiles, you should use only the features of `make'
  277. *not* listed here or in *Note Missing::.
  278.    Many features come from the version of `make' in System V.
  279.    * The `VPATH' variable and its special meaning.  *Note Searching
  280.      Directories for Dependencies: Directory Search.  This feature
  281.      exists in System V `make', but is undocumented.  It is documented
  282.      in 4.3 BSD `make' (which says it mimics System V's `VPATH'
  283.      feature).
  284.    * Included makefiles.  *Note Including Other Makefiles: Include.
  285.      Allowing multiple files to be included with a single directive is
  286.      a GNU extension.
  287.    * Variables are read from and communicated via the environment.
  288.      *Note Variables from the Environment: Environment.
  289.    * Options passed through the variable `MAKEFLAGS' to recursive
  290.      invocations of `make'.  *Note Communicating Options to a
  291.      Sub-`make': Options/Recursion.
  292.    * The automatic variable `$%' is set to the member name in an
  293.      archive reference.  *Note Automatic Variables: Automatic.
  294.    * The automatic variables `$@', `$*', `$<', `$%', and `$?' have
  295.      corresponding forms like `$(@F)' and `$(@D)'.  We have generalized
  296.      this to `$^' as an obvious extension.  *Note Automatic Variables:
  297.      Automatic.
  298.    * Substitution variable references.  *Note Basics of Variable
  299.      References: Reference.
  300.    * The command-line options `-b' and `-m', accepted and ignored.  In
  301.      System V `make', these options actually do something.
  302.    * Execution of recursive commands to run `make' via the variable
  303.      `MAKE' even if `-n', `-q' or `-t' is specified.  *Note Recursive
  304.      Use of `make': Recursion.
  305.    * Support for suffix `.a' in suffix rules.  *Note Archive Suffix
  306.      Rules::.  This feature is obsolete in GNU `make', because the
  307.      general feature of rule chaining (*note Chains of Implicit Rules:
  308.      Chained Rules.) allows one pattern rule for installing members in
  309.      an archive (*note Archive Update::.) to be sufficient.
  310.    * The arrangement of lines and backslash-newline combinations in
  311.      commands is retained when the commands are printed, so they appear
  312.      as they do in the makefile, except for the stripping of initial
  313.      whitespace.
  314.    The following features were inspired by various other versions of
  315. `make'.  In some cases it is unclear exactly which versions inspired
  316. which others.
  317.    * Pattern rules using `%'.  This has been implemented in several
  318.      versions of `make'.  We're not sure who invented it first, but
  319.      it's been spread around a bit.  *Note Defining and Redefining
  320.      Pattern Rules: Pattern Rules.
  321.    * Rule chaining and implicit intermediate files.  This was
  322.      implemented by Stu Feldman in his version of `make' for AT&T
  323.      Eighth Edition Research Unix, and later by Andrew Hume of AT&T
  324.      Bell Labs in his `mk' program (where he terms it "transitive
  325.      closure").  We do not really know if we got this from either of
  326.      them or thought it up ourselves at the same time.  *Note Chains of
  327.      Implicit Rules: Chained Rules.
  328.    * The automatic variable `$^' containing a list of all dependencies
  329.      of the current target.  We did not invent this, but we have no
  330.      idea who did.  *Note Automatic Variables: Automatic.
  331.    * The "what if" flag (`-W' in GNU `make') was (as far as we know)
  332.      invented by Andrew Hume in `mk'.  *Note Instead of Executing the
  333.      Commands: Instead of Execution.
  334.    * The concept of doing several things at once (parallelism) exists in
  335.      many incarnations of `make' and similar programs, though not in the
  336.      System V or BSD implementations.  *Note Command Execution:
  337.      Execution.
  338.    * Modified variable references using pattern substitution come from
  339.      SunOS 4.  *Note Basics of Variable References: Reference.  This
  340.      functionality was provided in GNU `make' by the `patsubst'
  341.      function before the alternate syntax was implemented for
  342.      compatibility with SunOS 4.  It is not altogether clear who
  343.      inspired whom, since GNU `make' had `patsubst' before SunOS 4 was
  344.      released.
  345.    * The special significance of `+' characters preceding command lines
  346.      (*note Instead of Executing the Commands: Instead of Execution.) is
  347.      mandated by `IEEE Standard 1003.2-1992' (POSIX.2).
  348.    * The `+=' syntax to append to the value of a variable comes from
  349.      SunOS 4 `make'.  *Note Appending More Text to Variables: Appending.
  350.    * The syntax `ARCHIVE(MEM1 MEM2...)' to list multiple members in a
  351.      single archive file comes from SunOS 4 `make'.  *Note Archive
  352.      Members::.
  353.    * The `-include' directive to include makefiles with no error for a
  354.      nonexistent file comes from SunOS 4 `make'.  (But note that SunOS 4
  355.      `make' does not allow multiple makefiles to be specified in one
  356.      `-include' directive.)
  357.    The remaining features are inventions new in GNU `make':
  358.    * Use the `-v' or `--version' option to print version and copyright
  359.      information.
  360.    * Use the `-h' or `--help' option to summarize the options to `make'.
  361.    * Simply-expanded variables.  *Note The Two Flavors of Variables:
  362.      Flavors.
  363.    * Pass command-line variable assignments automatically through the
  364.      variable `MAKE' to recursive `make' invocations.  *Note Recursive
  365.      Use of `make': Recursion.
  366.    * Use the `-C' or `--directory' command option to change directory.
  367.      *Note Summary of Options: Options Summary.
  368.    * Make verbatim variable definitions with `define'.  *Note Defining
  369.      Variables Verbatim: Defining.
  370.    * Declare phony targets with the special target `.PHONY'.
  371.      Andrew Hume of AT&T Bell Labs implemented a similar feature with a
  372.      different syntax in his `mk' program.  This seems to be a case of
  373.      parallel discovery.  *Note Phony Targets: Phony Targets.
  374.    * Manipulate text by calling functions.  *Note Functions for
  375.      Transforming Text: Functions.
  376.    * Use the `-o' or `--old-file' option to pretend a file's
  377.      modification-time is old.  *Note Avoiding Recompilation of Some
  378.      Files: Avoiding Compilation.
  379.    * Conditional execution.
  380.      This feature has been implemented numerous times in various
  381.      versions of `make'; it seems a natural extension derived from the
  382.      features of the C preprocessor and similar macro languages and is
  383.      not a revolutionary concept.  *Note Conditional Parts of
  384.      Makefiles: Conditionals.
  385.    * Specify a search path for included makefiles.  *Note Including
  386.      Other Makefiles: Include.
  387.    * Specify extra makefiles to read with an environment variable.
  388.      *Note The Variable `MAKEFILES': MAKEFILES Variable.
  389.    * Strip leading sequences of `./' from file names, so that `./FILE'
  390.      and `FILE' are considered to be the same file.
  391.    * Use a special search method for library dependencies written in the
  392.      form `-lNAME'.  *Note Directory Search for Link Libraries:
  393.      Libraries/Search.
  394.    * Allow suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
  395.      Suffix Rules.) to contain any characters.  In other versions of
  396.      `make', they must begin with `.' and not contain any `/'
  397.      characters.
  398.    * Keep track of the current level of `make' recursion using the
  399.      variable `MAKELEVEL'.  *Note Recursive Use of `make': Recursion.
  400.    * Specify static pattern rules.  *Note Static Pattern Rules: Static
  401.      Pattern.
  402.    * Provide selective `vpath' search.  *Note Searching Directories for
  403.      Dependencies: Directory Search.
  404.    * Provide computed variable references.  *Note Basics of Variable
  405.      References: Reference.
  406.    * Update makefiles.  *Note How Makefiles Are Remade: Remaking
  407.      Makefiles.  System V `make' has a very, very limited form of this
  408.      functionality in that it will check out SCCS files for makefiles.
  409.    * Various new built-in implicit rules.  *Note Catalogue of Implicit
  410.      Rules: Catalogue of Rules.
  411.    * The built-in variable `MAKE_VERSION' gives the version number of
  412.      `make'.
  413. File: make.info,  Node: Missing,  Next: Makefile Conventions,  Prev: Features,  Up: Top
  414. Incompatibilities and Missing Features
  415. **************************************
  416.    The `make' programs in various other systems support a few features
  417. that are not implemented in GNU `make'.  The POSIX.2 standard (`IEEE
  418. Standard 1003.2-1992') which specifies `make' does not require any of
  419. these features.
  420.    * A target of the form `FILE((ENTRY))' stands for a member of
  421.      archive file FILE.  The member is chosen, not by name, but by
  422.      being an object file which defines the linker symbol ENTRY.
  423.      This feature was not put into GNU `make' because of the
  424.      nonmodularity of putting knowledge into `make' of the internal
  425.      format of archive file symbol tables.  *Note Updating Archive
  426.      Symbol Directories: Archive Symbols.
  427.    * Suffixes (used in suffix rules) that end with the character `~'
  428.      have a special meaning to System V `make'; they refer to the SCCS
  429.      file that corresponds to the file one would get without the `~'.
  430.      For example, the suffix rule `.c~.o' would make the file `N.o' from
  431.      the SCCS file `s.N.c'.  For complete coverage, a whole series of
  432.      such suffix rules is required.  *Note Old-Fashioned Suffix Rules:
  433.      Suffix Rules.
  434.      In GNU `make', this entire series of cases is handled by two
  435.      pattern rules for extraction from SCCS, in combination with the
  436.      general feature of rule chaining.  *Note Chains of Implicit Rules:
  437.      Chained Rules.
  438.    * In System V `make', the string `$$@' has the strange meaning that,
  439.      in the dependencies of a rule with multiple targets, it stands for
  440.      the particular target that is being processed.
  441.      This is not defined in GNU `make' because `$$' should always stand
  442.      for an ordinary `$'.
  443.      It is possible to get this functionality through the use of static
  444.      pattern rules (*note Static Pattern Rules: Static Pattern.).  The
  445.      System V `make' rule:
  446.           $(targets): $$@.o lib.a
  447.      can be replaced with the GNU `make' static pattern rule:
  448.           $(targets): %: %.o lib.a
  449.    * In System V and 4.3 BSD `make', files found by `VPATH' search
  450.      (*note Searching Directories for Dependencies: Directory Search.)
  451.      have their names changed inside command strings.  We feel it is
  452.      much cleaner to always use automatic variables and thus make this
  453.      feature obsolete.
  454.    * In some Unix `make's, the automatic variable `$*' appearing in the
  455.      dependencies of a rule has the amazingly strange "feature" of
  456.      expanding to the full name of the *target of that rule*.  We cannot
  457.      imagine what went on in the minds of Unix `make' developers to do
  458.      this; it is utterly inconsistent with the normal definition of
  459.      `$*'.
  460.    * In some Unix `make's, implicit rule search (*note Using Implicit
  461.      Rules: Implicit Rules.) is apparently done for *all* targets, not
  462.      just those without commands.  This means you can do:
  463.           foo.o:
  464.                   cc -c foo.c
  465.      and Unix `make' will intuit that `foo.o' depends on `foo.c'.
  466.      We feel that such usage is broken.  The dependency properties of
  467.      `make' are well-defined (for GNU `make', at least), and doing such
  468.      a thing simply does not fit the model.
  469.    * GNU `make' does not include any built-in implicit rules for
  470.      compiling or preprocessing EFL programs.  If we hear of anyone who
  471.      is using EFL, we will gladly add them.
  472.    * It appears that in SVR4 `make', a suffix rule can be specified with
  473.      no commands, and it is treated as if it had empty commands (*note
  474.      Empty Commands::.).  For example:
  475.           .c.a:
  476.      will override the built-in `.c.a' suffix rule.
  477.      We feel that it is cleaner for a rule without commands to always
  478.      simply add to the dependency list for the target.  The above
  479.      example can be easily rewritten to get the desired behavior in GNU
  480.      `make':
  481.           .c.a: ;
  482.    * Some versions of `make' invoke the shell with the `-e' flag,
  483.      except under `-k' (*note Testing the Compilation of a Program:
  484.      Testing.).  The `-e' flag tells the shell to exit as soon as any
  485.      program it runs returns a nonzero status.  We feel it is cleaner to
  486.      write each shell command line to stand on its own and not require
  487.      this special treatment.
  488. File: make.info,  Node: Makefile Conventions,  Next: Quick Reference,  Prev: Missing,  Up: Top
  489. Makefile Conventions
  490. ********************
  491.    This chapter describes conventions for writing the Makefiles for GNU
  492. programs.
  493. * Menu:
  494. * Makefile Basics::
  495. * Utilities in Makefiles::
  496. * Standard Targets::
  497. * Command Variables::
  498. * Directory Variables::
  499. File: make.info,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
  500. General Conventions for Makefiles
  501. =================================
  502.    Every Makefile should contain this line:
  503.      SHELL = /bin/sh
  504. to avoid trouble on systems where the `SHELL' variable might be
  505. inherited from the environment.  (This is never a problem with GNU
  506. `make'.)
  507.    Don't assume that `.' is in the path for command execution.  When
  508. you need to run programs that are a part of your package during the
  509. make, please make sure that it uses `./' if the program is built as
  510. part of the make or `$(srcdir)/' if the file is an unchanging part of
  511. the source code.  Without one of these prefixes, the current search
  512. path is used.
  513.    The distinction between `./' and `$(srcdir)/' is important when
  514. using the `--srcdir' option to `configure'.  A rule of the form:
  515.      foo.1 : foo.man sedscript
  516.              sed -e sedscript foo.man > foo.1
  517. will fail when the current directory is not the source directory,
  518. because `foo.man' and `sedscript' are not in the current directory.
  519.    When using GNU `make', relying on `VPATH' to find the source file
  520. will work in the case where there is a single dependency file, since
  521. the `make' automatic variable `$<' will represent the source file
  522. wherever it is.  (Many versions of `make' set `$<' only in implicit
  523. rules.)  A makefile target like
  524.      foo.o : bar.c
  525.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  526. should instead be written as
  527.      foo.o : bar.c
  528.              $(CC) $(CFLAGS) $< -o $@
  529. in order to allow `VPATH' to work correctly.  When the target has
  530. multiple dependencies, using an explicit `$(srcdir)' is the easiest way
  531. to make the rule work well.  For example, the target above for `foo.1'
  532. is best written as:
  533.      foo.1 : foo.man sedscript
  534.              sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1
  535. File: make.info,  Node: Utilities in Makefiles,  Next: Standard Targets,  Prev: Makefile Basics,  Up: Makefile Conventions
  536. Utilities in Makefiles
  537. ======================
  538.    Write the Makefile commands (and any shell scripts, such as
  539. `configure') to run in `sh', not in `csh'.  Don't use any special
  540. features of `ksh' or `bash'.
  541.    The `configure' script and the Makefile rules for building and
  542. installation should not use any utilities directly except these:
  543.      cat cmp cp echo egrep expr grep
  544.      ln mkdir mv pwd rm rmdir sed test touch
  545.    Stick to the generally supported options for these programs.  For
  546. example, don't use `mkdir -p', convenient as it may be, because most
  547. systems don't support it.
  548.    The Makefile rules for building and installation can also use
  549. compilers and related programs, but should do so via `make' variables
  550. so that the user can substitute alternatives.  Here are some of the
  551. programs we mean:
  552.      ar bison cc flex install ld lex
  553.      make makeinfo ranlib texi2dvi yacc
  554.    When you use `ranlib', you should test whether it exists, and run it
  555. only if it exists, so that the distribution will work on systems that
  556. don't have `ranlib'.
  557.    If you use symbolic links, you should implement a fallback for
  558. systems that don't have symbolic links.
  559.    It is ok to use other utilities in Makefile portions (or scripts)
  560. intended only for particular systems where you know those utilities to
  561. exist.
  562. File: make.info,  Node: Standard Targets,  Next: Command Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
  563. Standard Targets for Users
  564. ==========================
  565.    All GNU programs should have the following targets in their
  566. Makefiles:
  567. `all'
  568.      Compile the entire program.  This should be the default target.
  569.      This target need not rebuild any documentation files; Info files
  570.      should normally be included in the distribution, and DVI files
  571.      should be made only when explicitly asked for.
  572. `install'
  573.      Compile the program and copy the executables, libraries, and so on
  574.      to the file names where they should reside for actual use.  If
  575.      there is a simple test to verify that a program is properly
  576.      installed, this target should run that test.
  577.      The commands should create all the directories in which files are
  578.      to be installed, if they don't already exist.  This includes the
  579.      directories specified as the values of the variables `prefix' and
  580.      `exec_prefix', as well as all subdirectories that are needed.  One
  581.      way to do this is by means of an `installdirs' target as described
  582.      below.
  583.      Use `-' before any command for installing a man page, so that
  584.      `make' will ignore any errors.  This is in case there are systems
  585.      that don't have the Unix man page documentation system installed.
  586.      The way to install Info files is to copy them into `$(infodir)'
  587.      with `$(INSTALL_DATA)' (*note Command Variables::.), and then run
  588.      the `install-info' program if it is present.  `install-info' is a
  589.      script that edits the Info `dir' file to add or update the menu
  590.      entry for the given Info file; it will be part of the Texinfo
  591.      package.  Here is a sample rule to install an Info file:
  592.           $(infodir)/foo.info: foo.info
  593.           # There may be a newer info file in . than in srcdir.
  594.                   -if test -f foo.info; then d=.; \
  595.                    else d=$(srcdir); fi; \
  596.                   $(INSTALL_DATA) $$d/foo.info $@; \
  597.           # Run install-info only if it exists.
  598.           # Use `if' instead of just prepending `-' to the
  599.           # line so we notice real errors from install-info.
  600.           # We use `$(SHELL) -c' because some shells do not
  601.           # fail gracefully when there is an unknown command.
  602.                   if $(SHELL) -c 'install-info --version' \
  603.                      >/dev/null 2>&1; then \
  604.                     install-info --infodir=$(infodir) $$d/foo.info; \
  605.                   else true; fi
  606. `uninstall'
  607.      Delete all the installed files that the `install' target would
  608.      create (but not the noninstalled files such as `make all' would
  609.      create).
  610. `clean'
  611.      Delete all files from the current directory that are normally
  612.      created by building the program.  Don't delete the files that
  613.      record the configuration.  Also preserve files that could be made
  614.      by building, but normally aren't because the distribution comes
  615.      with them.
  616.      Delete `.dvi' files here if they are not part of the distribution.
  617. `distclean'
  618.      Delete all files from the current directory that are created by
  619.      configuring or building the program.  If you have unpacked the
  620.      source and built the program without creating any other files,
  621.      `make distclean' should leave only the files that were in the
  622.      distribution.
  623. `mostlyclean'
  624.      Like `clean', but may refrain from deleting a few files that people
  625.      normally don't want to recompile.  For example, the `mostlyclean'
  626.      target for GCC does not delete `libgcc.a', because recompiling it
  627.      is rarely necessary and takes a lot of time.
  628. `realclean'
  629.      Delete everything from the current directory that can be
  630.      reconstructed with this Makefile.  This typically includes
  631.      everything deleted by `distclean', plus more: C source files
  632.      produced by Bison, tags tables, Info files, and so on.
  633.      One exception, however: `make realclean' should not delete
  634.      `configure' even if `configure' can be remade using a rule in the
  635.      Makefile.  More generally, `make realclean' should not delete
  636.      anything that needs to exist in order to run `configure' and then
  637.      begin to build the program.
  638. `TAGS'
  639.      Update a tags table for this program.
  640. `info'
  641.      Generate any Info files needed.  The best way to write the rules
  642.      is as follows:
  643.           info: foo.info
  644.           
  645.           foo.info: foo.texi chap1.texi chap2.texi
  646.                   $(MAKEINFO) $(srcdir)/foo.texi
  647.      You must define the variable `MAKEINFO' in the Makefile.  It should
  648.      run the `makeinfo' program, which is part of the Texinfo
  649.      distribution.
  650. `dvi'
  651.      Generate DVI files for all TeXinfo documentation.  For example:
  652.           dvi: foo.dvi
  653.           
  654.           foo.dvi: foo.texi chap1.texi chap2.texi
  655.                   $(TEXI2DVI) $(srcdir)/foo.texi
  656.      You must define the variable `TEXI2DVI' in the Makefile.  It should
  657.      run the program `texi2dvi', which is part of the Texinfo
  658.      distribution.  Alternatively, write just the dependencies, and
  659.      allow GNU Make to provide the command.
  660. `dist'
  661.      Create a distribution tar file for this program.  The tar file
  662.      should be set up so that the file names in the tar file start with
  663.      a subdirectory name which is the name of the package it is a
  664.      distribution for.  This name can include the version number.
  665.      For example, the distribution tar file of GCC version 1.40 unpacks
  666.      into a subdirectory named `gcc-1.40'.
  667.      The easiest way to do this is to create a subdirectory
  668.      appropriately named, use `ln' or `cp' to install the proper files
  669.      in it, and then `tar' that subdirectory.
  670.      The `dist' target should explicitly depend on all non-source files
  671.      that are in the distribution, to make sure they are up to date in
  672.      the distribution.  *Note Making Releases: (standards)Releases.
  673. `check'
  674.      Perform self-tests (if any).  The user must build the program
  675.      before running the tests, but need not install the program; you
  676.      should write the self-tests so that they work when the program is
  677.      built but not installed.
  678.    The following targets are suggested as conventional names, for
  679. programs in which they are useful.
  680. `installcheck'
  681.      Perform installation tests (if any).  The user must build and
  682.      install the program before running the tests.  You should not
  683.      assume that `$(bindir)' is in the search path.
  684. `installdirs'
  685.      It's useful to add a target named `installdirs' to create the
  686.      directories where files are installed, and their parent
  687.      directories.  There is a script called `mkinstalldirs' which is
  688.      convenient for this; find it in the Texinfo package.You can use a
  689.      rule like this:
  690.           # Make sure all installation directories (e.g. $(bindir))
  691.           # actually exist by making them if necessary.
  692.           installdirs: mkinstalldirs
  693.                   $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
  694.                                           $(libdir) $(infodir) \
  695.                                           $(mandir)
  696. File: make.info,  Node: Command Variables,  Next: Directory Variables,  Prev: Standard Targets,  Up: Makefile Conventions
  697. Variables for Specifying Commands
  698. =================================
  699.    Makefiles should provide variables for overriding certain commands,
  700. options, and so on.
  701.    In particular, you should run most utility programs via variables.
  702. Thus, if you use Bison, have a variable named `BISON' whose default
  703. value is set with `BISON = bison', and refer to it with `$(BISON)'
  704. whenever you need to use Bison.
  705.    File management utilities such as `ln', `rm', `mv', and so on, need
  706. not be referred to through variables in this way, since users don't
  707. need to replace them with other programs.
  708.    Each program-name variable should come with an options variable that
  709. is used to supply options to the program.  Append `FLAGS' to the
  710. program-name variable name to get the options variable name--for
  711. example, `BISONFLAGS'.  (The name `CFLAGS' is an exception to this
  712. rule, but we keep it because it is standard.)  Use `CPPFLAGS' in any
  713. compilation command that runs the preprocessor, and use `LDFLAGS' in
  714. any compilation command that does linking as well as in any direct use
  715. of `ld'.
  716.    If there are C compiler options that *must* be used for proper
  717. compilation of certain files, do not include them in `CFLAGS'.  Users
  718. expect to be able to specify `CFLAGS' freely themselves.  Instead,
  719. arrange to pass the necessary options to the C compiler independently
  720. of `CFLAGS', by writing them explicitly in the compilation commands or
  721. by defining an implicit rule, like this:
  722.      CFLAGS = -g
  723.      ALL_CFLAGS = -I. $(CFLAGS)
  724.      .c.o:
  725.              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  726.    Do include the `-g' option in `CFLAGS', because that is not
  727. *required* for proper compilation.  You can consider it a default that
  728. is only recommended.  If the package is set up so that it is compiled
  729. with GCC by default, then you might as well include `-O' in the default
  730. value of `CFLAGS' as well.
  731.    Put `CFLAGS' last in the compilation command, after other variables
  732. containing compiler options, so the user can use `CFLAGS' to override
  733. the others.
  734.    Every Makefile should define the variable `INSTALL', which is the
  735. basic command for installing a file into the system.
  736.    Every Makefile should also define the variables `INSTALL_PROGRAM'
  737. and `INSTALL_DATA'.  (The default for each of these should be
  738. `$(INSTALL)'.)  Then it should use those variables as the commands for
  739. actual installation, for executables and nonexecutables respectively.
  740. Use these variables as follows:
  741.      $(INSTALL_PROGRAM) foo $(bindir)/foo
  742.      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  743. Always use a file name, not a directory name, as the second argument of
  744. the installation commands.  Use a separate command for each file to be
  745. installed.
  746. File: make.info,  Node: Directory Variables,  Prev: Command Variables,  Up: Makefile Conventions
  747. Variables for Installation Directories
  748. ======================================
  749.    Installation directories should always be named by variables, so it
  750. is easy to install in a nonstandard place.  The standard names for these
  751. variables are:
  752. `prefix'
  753.      A prefix used in constructing the default values of the variables
  754.      listed below.  The default value of `prefix' should be `/usr/local'
  755.      (at least for now).
  756. `exec_prefix'
  757.      A prefix used in constructing the default values of some of the
  758.      variables listed below.  The default value of `exec_prefix' should
  759.      be `$(prefix)'.
  760.      Generally, `$(exec_prefix)' is used for directories that contain
  761.      machine-specific files (such as executables and subroutine
  762.      libraries), while `$(prefix)' is used directly for other
  763.      directories.
  764. `bindir'
  765.      The directory for installing executable programs that users can
  766.      run.  This should normally be `/usr/local/bin', but write it as
  767.      `$(exec_prefix)/bin'.
  768. `libdir'
  769.      The directory for installing executable files to be run by the
  770.      program rather than by users.  Object files and libraries of
  771.      object code should also go in this directory.  The idea is that
  772.      this directory is used for files that pertain to a specific
  773.      machine architecture, but need not be in the path for commands.
  774.      The value of `libdir' should normally be `/usr/local/lib', but
  775.      write it as `$(exec_prefix)/lib'.
  776. `datadir'
  777.      The directory for installing read-only data files which the
  778.      programs refer to while they run.  This directory is used for
  779.      files which are independent of the type of machine being used.
  780.      This should normally be `/usr/local/lib', but write it as
  781.      `$(prefix)/lib'.
  782. `statedir'
  783.      The directory for installing data files which the programs modify
  784.      while they run.  These files should be independent of the type of
  785.      machine being used, and it should be possible to share them among
  786.      machines at a network installation.  This should normally be
  787.      `/usr/local/lib', but write it as `$(prefix)/lib'.
  788. `includedir'
  789.      The directory for installing header files to be included by user
  790.      programs with the C `#include' preprocessor directive.  This
  791.      should normally be `/usr/local/include', but write it as
  792.      `$(prefix)/include'.
  793.      Most compilers other than GCC do not look for header files in
  794.      `/usr/local/include'.  So installing the header files this way is
  795.      only useful with GCC.  Sometimes this is not a problem because some
  796.      libraries are only really intended to work with GCC.  But some
  797.      libraries are intended to work with other compilers.  They should
  798.      install their header files in two places, one specified by
  799.      `includedir' and one specified by `oldincludedir'.
  800. `oldincludedir'
  801.      The directory for installing `#include' header files for use with
  802.      compilers other than GCC.  This should normally be `/usr/include'.
  803.      The Makefile commands should check whether the value of
  804.      `oldincludedir' is empty.  If it is, they should not try to use
  805.      it; they should cancel the second installation of the header files.
  806.      A package should not replace an existing header in this directory
  807.      unless the header came from the same package.  Thus, if your Foo
  808.      package provides a header file `foo.h', then it should install the
  809.      header file in the `oldincludedir' directory if either (1) there
  810.      is no `foo.h' there or (2) the `foo.h' that exists came from the
  811.      Foo package.
  812.      To tell whether `foo.h' came from the Foo package, put a magic
  813.      string in the file--part of a comment--and grep for that string.
  814. `mandir'
  815.      The directory for installing the man pages (if any) for this
  816.      package.  It should include the suffix for the proper section of
  817.      the manual--usually `1' for a utility.  It will normally be
  818.      `/usr/local/man/man1', but you should write it as
  819.      `$(prefix)/man/man1'.
  820. `man1dir'
  821.      The directory for installing section 1 man pages.
  822. `man2dir'
  823.      The directory for installing section 2 man pages.
  824. `...'
  825.      Use these names instead of `mandir' if the package needs to
  826.      install man pages in more than one section of the manual.
  827.      *Don't make the primary documentation for any GNU software be a
  828.      man page.  Write a manual in Texinfo instead.  Man pages are just
  829.      for the sake of people running GNU software on Unix, which is a
  830.      secondary application only.*
  831. `manext'
  832.      The file name extension for the installed man page.  This should
  833.      contain a period followed by the appropriate digit; it should
  834.      normally be `.1'.
  835. `man1ext'
  836.      The file name extension for installed section 1 man pages.
  837. `man2ext'
  838.      The file name extension for installed section 2 man pages.
  839. `...'
  840.      Use these names instead of `manext' if the package needs to
  841.      install man pages in more than one section of the manual.
  842. `infodir'
  843.      The directory for installing the Info files for this package.  By
  844.      default, it should be `/usr/local/info', but it should be written
  845.      as `$(prefix)/info'.
  846. `srcdir'
  847.      The directory for the sources being compiled.  The value of this
  848.      variable is normally inserted by the `configure' shell script.
  849.    For example:
  850.      # Common prefix for installation directories.
  851.      # NOTE: This directory must exist when you start the install.
  852.      prefix = /usr/local
  853.      exec_prefix = $(prefix)
  854.      # Where to put the executable for the command `gcc'.
  855.      bindir = $(exec_prefix)/bin
  856.      # Where to put the directories used by the compiler.
  857.      libdir = $(exec_prefix)/lib
  858.      # Where to put the Info files.
  859.      infodir = $(prefix)/info
  860.    If your program installs a large number of files into one of the
  861. standard user-specified directories, it might be useful to group them
  862. into a subdirectory particular to that program.  If you do this, you
  863. should write the `install' rule to create these subdirectories.
  864.    Do not expect the user to include the subdirectory name in the value
  865. of any of the variables listed above.  The idea of having a uniform set
  866. of variable names for installation directories is to enable the user to
  867. specify the exact same values for several different GNU packages.  In
  868. order for this to be useful, all the packages must be designed so that
  869. they will work sensibly when the user does so.
  870.