home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / gnu / info / make.info-2 (.txt) < prev    next >
GNU Info File  |  1994-11-12  |  49KB  |  885 lines

  1. This is Info file make.info, produced by Makeinfo-1.55 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.47, last updated 1 November 1994, of `The GNU Make
  7. Manual', for `make', Version 3.72 Beta.
  8.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94 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: Rule Example,  Next: Rule Syntax,  Up: Rules
  22. Rule Example
  23. ============
  24.    Here is an example of a rule:
  25.      foo.o : foo.c defs.h       # module for twiddling the frobs
  26.              cc -c -g foo.c
  27.    Its target is `foo.o' and its dependencies are `foo.c' and `defs.h'.
  28. It has one command, which is `cc -c -g foo.c'.  The command line
  29. starts with a tab to identify it as a command.
  30.    This rule says two things:
  31.    * How to decide whether `foo.o' is out of date: it is out of date if
  32.      it does not exist, or if either `foo.c' or `defs.h' is more recent
  33.      than it.
  34.    * How to update the file `foo.o': by running `cc' as stated.  The
  35.      command does not explicitly mention `defs.h', but we presume that
  36.      `foo.c' includes it, and that that is why `defs.h' was added to
  37.      the dependencies.
  38. File: make.info,  Node: Rule Syntax,  Next: Wildcards,  Prev: Rule Example,  Up: Rules
  39. Rule Syntax
  40. ===========
  41.    In general, a rule looks like this:
  42.      TARGETS : DEPENDENCIES
  43.              COMMAND
  44.              ...
  45. or like this:
  46.      TARGETS : DEPENDENCIES ; COMMAND
  47.              COMMAND
  48.              ...
  49.    The TARGETS are file names, separated by spaces.  Wildcard
  50. characters may be used (*note Using Wildcard Characters in File Names:
  51. Wildcards.) and a name of the form `A(M)' represents member M in
  52. archive file A (*note Archive Members as Targets: Archive Members.).
  53. Usually there is only one target per rule, but occasionally there is a
  54. reason to have more (*note Multiple Targets in a Rule: Multiple
  55. Targets.).
  56.    The COMMAND lines start with a tab character.  The first command may
  57. appear on the line after the dependencies, with a tab character, or may
  58. appear on the same line, with a semicolon.  Either way, the effect is
  59. the same.  *Note Writing the Commands in Rules: Commands.
  60.    Because dollar signs are used to start variable references, if you
  61. really want a dollar sign in a rule you must write two of them, `$$'
  62. (*note How to Use Variables: Using Variables.).  You may split a long
  63. line by inserting a backslash followed by a newline, but this is not
  64. required, as `make' places no limit on the length of a line in a
  65. makefile.
  66.    A rule tells `make' two things: when the targets are out of date,
  67. and how to update them when necessary.
  68.    The criterion for being out of date is specified in terms of the
  69. DEPENDENCIES, which consist of file names separated by spaces.
  70. (Wildcards and archive members (*note Archives::.) are allowed here
  71. too.) A target is out of date if it does not exist or if it is older
  72. than any of the dependencies (by comparison of last-modification
  73. times).  The idea is that the contents of the target file are computed
  74. based on information in the dependencies, so if any of the dependencies
  75. changes, the contents of the existing target file are no longer
  76. necessarily valid.
  77.    How to update is specified by COMMANDS.  These are lines to be
  78. executed by the shell (normally `sh'), but with some extra features
  79. (*note Writing the Commands in Rules: Commands.).
  80. File: make.info,  Node: Wildcards,  Next: Directory Search,  Prev: Rule Syntax,  Up: Rules
  81. Using Wildcard Characters in File Names
  82. =======================================
  83.    A single file name can specify many files using "wildcard
  84. characters".  The wildcard characters in `make' are `*', `?' and
  85. `[...]', the same as in the Bourne shell.  For example, `*.c' specifies
  86. a list of all the files (in the working directory) whose names end in
  87. `.c'.
  88.    The character `~' at the beginning of a file name also has special
  89. significance.  If alone, or followed by a slash, it represents your home
  90. directory.  For example `~/bin' expands to `/home/you/bin'.  If the `~'
  91. is followed by a word, the string represents the home directory of the
  92. user named by that word.  For example `~john/bin' expands to
  93. `/home/john/bin'.
  94.    Wildcard expansion happens automatically in targets, in dependencies,
  95. and in commands (where the shell does the expansion).  In other
  96. contexts, wildcard expansion happens only if you request it explicitly
  97. with the `wildcard' function.
  98.    The special significance of a wildcard character can be turned off by
  99. preceding it with a backslash.  Thus, `foo\*bar' would refer to a
  100. specific file whose name consists of `foo', an asterisk, and `bar'.
  101. * Menu:
  102. * Wildcard Examples::           Several examples
  103. * Wildcard Pitfall::            Problems to avoid.
  104. * Wildcard Function::           How to cause wildcard expansion where
  105.                                   it does not normally take place.
  106. File: make.info,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Up: Wildcards
  107. Wildcard Examples
  108. -----------------
  109.    Wildcards can be used in the commands of a rule, where they are
  110. expanded by the shell.  For example, here is a rule to delete all the
  111. object files:
  112.      clean:
  113.              rm -f *.o
  114.    Wildcards are also useful in the dependencies of a rule.  With the
  115. following rule in the makefile, `make print' will print all the `.c'
  116. files that have changed since the last time you printed them:
  117.      print: *.c
  118.              lpr -p $?
  119.              touch print
  120. This rule uses `print' as an empty target file; see *Note Empty Target
  121. Files to Record Events: Empty Targets.  (The automatic variable `$?' is
  122. used to print only those files that have changed; see *Note Automatic
  123. Variables: Automatic.)
  124.    Wildcard expansion does not happen when you define a variable.
  125. Thus, if you write this:
  126.      objects = *.o
  127. then the value of the variable `objects' is the actual string `*.o'.
  128. However, if you use the value of `objects' in a target, dependency or
  129. command, wildcard expansion will take place at that time.  To set
  130. `objects' to the expansion, instead use:
  131.      objects := $(wildcard *.o)
  132. *Note Wildcard Function::.
  133. File: make.info,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
  134. Pitfalls of Using Wildcards
  135. ---------------------------
  136.    Now here is an example of a naive way of using wildcard expansion,
  137. that does not do what you would intend.  Suppose you would like to say
  138. that the executable file `foo' is made from all the object files in the
  139. directory, and you write this:
  140.      objects = *.o
  141.      
  142.      foo : $(objects)
  143.              cc -o foo $(CFLAGS) $(objects)
  144. The value of `objects' is the actual string `*.o'.  Wildcard expansion
  145. happens in the rule for `foo', so that each *existing* `.o' file
  146. becomes a dependency of `foo' and will be recompiled if necessary.
  147.    But what if you delete all the `.o' files?  When a wildcard matches
  148. no files, it is left as it is, so then `foo' will depend on the
  149. oddly-named file `*.o'.  Since no such file is likely to exist, `make'
  150. will give you an error saying it cannot figure out how to make `*.o'.
  151. This is not what you want!
  152.    Actually it is possible to obtain the desired result with wildcard
  153. expansion, but you need more sophisticated techniques, including the
  154. `wildcard' function and string substitution.  *Note The Function
  155. `wildcard': Wildcard Function.
  156. File: make.info,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildca