home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / make-3.75-bin.lha / info / make.info-5 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  49KB  |  881 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.    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.51, last updated 9 May 1996, of `The GNU Make
  7. Manual', for `make', Version 3.75 Beta.
  8.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95, '96
  9. Free Software 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: Overriding,  Next: Testing,  Prev: Avoiding Compilation,  Up: Running
  22. Overriding Variables
  23. ====================
  24.    An argument that contains `=' specifies the value of a variable:
  25. `V=X' sets the value of the variable V to X.  If you specify a value in
  26. this way, all ordinary assignments of the same variable in the makefile
  27. are ignored; we say they have been "overridden" by the command line
  28. argument.
  29.    The most common way to use this facility is to pass extra flags to
  30. compilers.  For example, in a properly written makefile, the variable
  31. `CFLAGS' is included in each command that runs the C compiler, so a
  32. file `foo.c' would be compiled something like this:
  33.      cc -c $(CFLAGS) foo.c
  34.    Thus, whatever value you set for `CFLAGS' affects each compilation
  35. that occurs.  The makefile probably specifies the usual value for
  36. `CFLAGS', like this:
  37.      CFLAGS=-g
  38.    Each time you run `make', you can override this value if you wish.
  39. For example, if you say `make CFLAGS='-g -O'', each C compilation will
  40. be done with `cc -c -g -O'.  (This illustrates how you can use quoting
  41. in the shell to enclose spaces and other special characters in the
  42. value of a variable when you override it.)
  43.    The variable `CFLAGS' is only one of many standard variables that
  44. exist just so that you can change them this way.  *Note Variables Used
  45. by Implicit Rules: Implicit Variables, for a complete list.
  46.    You can also program the makefile to look at additional variables of
  47. your own, giving the user the ability to control other aspects of how
  48. the makefile works by changing the variables.
  49.    When you override a variable with a command argument, you can define
  50. either a recursively-expanded variable or a simply-expanded variable.
  51. The examples shown above make a recursively-expanded variable; to make a
  52. simply-expanded variable, write `:=' instead of `='.  But, unless you
  53. want to include a variable reference or function call in the *value*
  54. that you specify, it makes no difference which kind of variable you
  55. create.
  56.    There is one way that the makefile can change a variable that you
  57. have overridden.  This is to use the `override' directive, which is a
  58. line that looks like this: `override VARIABLE = VALUE' (*note The
  59. `override' Directive: Override Directive.).
  60. File: make.info,  Node: Testing,  Next: Options Summary,  Prev: Overriding,  Up: Running
  61. Testing the Compilation of a Program
  62. ====================================
  63.    Normally, when an error happens in executing a shell command, `make'
  64. gives up immediately, returning a nonzero status.  No further commands
  65. are executed for any target.  The error implies that the goal cannot be
  66. correctly remade, and `make' reports this as soon as it knows.
  67.    When you are compiling a program that you have just changed, this is
  68. not what you want.  Instead, you would rather that `make' try compiling
  69. every file that can be tried, to show you as many compilation errors as
  70. possible.
  71.    On these occasions, you should use the `-k' or `--keep-going' flag.
  72. This tells `make' to continue to consider the other dependencies of the
  73. pending targets, remaking them if necessary, before it gives up and
  74. returns nonzero status.  For example, after an error in compiling one
  75. object file, `make -k' will continue compiling other object files even
  76. though it already knows that linking them will be impossible.  In
  77. addition to continuing after failed shell commands, `make -k' will
  78. continue as much as possible after discovering that it does not know
  79. how to make a target or dependency file.  This will always cause an
  80. error message, but without `-k', it is a fatal error (*note Summary of
  81. Options: Options Summary.).
  82.    The usual behavior of `make' assumes that your purpose is to get the
  83. goals up to date; once `make' learns that this is impossible, it might
  84. as well report the failure immediately.  The `-k' flag says that the
  85. real purpose is to test as much as possible of the changes made in the
  86. program, perhaps to find several independent problems so that you can
  87. correct them all before the next attempt to compile.  This is why Emacs'
  88. `M-x compile' command passes the `-k' flag by default.
  89. File: make.info,  Node: Options Summary,  Prev: Testing,  Up: Running
  90. Summary of Options
  91. ==================
  92.    Here is a table of all the options `make' understands:
  93.      These options are ignored for compatibility with other versions of
  94.      `make'.
  95. `-C DIR'
  96. `--directory=DIR'
  97.      Change to directory DIR before reading the makefiles.  If multiple
  98.      `-C' options are specified, each is interpreted relative to the
  99.      previous one: `-C / -C etc' is equivalent to `-C /etc'.  This is
  100.      typically used with recursive invocations of `make' (*note
  101.      Recursive Use of `make': Recursion.).
  102. `--debug'
  103.      Print debugging information in addition to normal processing.  The
  104.      debugging information says which files are being considered for
  105.      remaking, which file-times are being compared and with what
  106.      results, which files actually need to be remade, which implicit
  107.      rules are considered and which are applied--everything interesting
  108.      about how `make' decides what to do.
  109. `--environment-overrides'
  110.      Give variables taken from the environment precedence over
  111.      variables from makefiles.  *Note Variables from the Environment:
  112.      Environment.
  113. `-f FILE'
  114. `--file=FILE'
  115. `--makefile=FILE'
  116.      Read the file named FILE as a makefile.  *Note Writing Makefiles:
  117.      Makefiles.
  118. `--help'
  119.      Remind you of the options that `make' understands and then exit.
  120. `--ignore-errors'
  121.      Ignore all errors in commands executed to remake files.  *Note
  122.      Errors in Commands: Errors.
  123. `-I DIR'
  124. `--include-dir=DIR'
  125.      Specifies a directory DIR to search for included makefiles.  *Note
  126.      Including Other Makefiles: Include.  If several `-I' options are
  127.      used to specify several directories, the directories are searched
  128.      in the order specified.
  129. `-j [JOBS]'
  130. `--jobs=[JOBS]'
  131.      Specifies the number of jobs (commands) to run simultaneously.
  132.      With no argument, `make' runs as many jobs simultaneously as
  133.      possible.  If there is more than one `-j' option, the last one is
  134.      effective.  *Note Parallel Execution: Parallel, for more
  135.      information on how commands are run.
  136. `--keep-going'
  137.      Continue as much as possible after an error.  While the target that
  138.      failed, and those that depend on it, cannot be remade, the other
  139.      dependencies of these targets can be processed all the same.
  140.      *Note Testing the Compilation of a Program: Testing.
  141. `-l [LOAD]'
  142. `--load-average[=LOAD]'
  143. `--max-load[=LOAD]'
  144.      Specifies that no new jobs (commands) should be started if there
  145.      are other jobs running and the load average is at least LOAD (a
  146.      floating-point number).  With no argument, removes a previous load
  147.      limit.  *Note Parallel Execution: Parallel.
  148. `--just-print'
  149. `--dry-run'
  150. `--recon'
  151.      Print the commands that would be executed, but do not execute them.
  152.      *Note Instead of Executing the Commands: Instead of Execution.
  153. `-o FILE'
  154. `--old-file=FILE'
  155. `--assume-old=FILE'
  156.      Do not remake the file FILE even if it is older than its
  157.      dependencies, and do not remake anything on account of changes in
  158.      FILE.  Essentially the file is treated as very old and its rules
  159.      are ignored.  *Note Avoiding Recompilation of Some Files: Avoiding
  160.      Compilation.
  161. `--print-data-base'
  162.      Print the data base (rules and variable values) that results from
  163.      reading the makefiles; then execute as usual or as otherwise
  164.      specified.  This also prints the version information given by the
  165.      `-v' switch (see below).  To print the data base without trying to
  166.      remake any files, use `make -p -f /dev/null'.
  167. `--question'
  168.      "Question mode".  Do not run any commands, or print anything; just
  169.      return an exit status that is zero if the specified targets are
  170.      already up to date, one if any remaking is required, or two if an
  171.      error is encountered.  *Note Instead of Executing the Commands:
  172.      Instead of Execution.
  173. `--no-builtin-rules'
  174.      Eliminate use of the built-in implicit rules (*note Using Implicit
  175.      Rules: Implicit Rules.).  You can still define your own by writing
  176.      pattern rules (*note Defining and Redefining Pattern Rules:
  177.      Pattern Rules.).  The `-r' option also clears out the default list
  178.      of suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
  179.      Suffix Rules.).  But you can still define your own suffixes with a
  180.      rule for `.SUFFIXES', and then define your own suffix rules.
  181. `--silent'
  182. `--quiet'
  183.      Silent operation; do not print the commands as they are executed.
  184.      *Note Command Echoing: Echoing.
  185. `--no-keep-going'
  186. `--stop'
  187.      Cancel the effect of the `-k' option.  This is never necessary
  188.      except in a recursive `make' where `-k' might be inherited from
  189.      the top-level `make' via `MAKEFLAGS' (*note Recursive Use of
  190.      `make': Recursion.) or if you set `-k' in `MAKEFLAGS' in your
  191.      environment.
  192. `--touch'
  193.      Touch files (mark them up to date without really changing them)
  194.      instead of running their commands.  This is used to pretend that
  195.      the commands were done, in order to fool future invocations of
  196.      `make'.  *Note Instead of Executing the Commands: Instead of
  197.      Execution.
  198. `--version'
  199.      Print the version of the `make' program plus a copyright, a list
  200.      of authors, and a notice that there is no warranty; then exit.
  201. `--print-directory'
  202.      Print a message containing the working directory both before and
  203.      after executing the makefile.  This may be useful for tracking
  204.      down errors from complicated nests of recursive `make' commands.
  205.      *Note Recursive Use of `make': Recursion.  (In practice, you
  206.      rarely need to specify this option since `make' does it for you;
  207.      see *Note The `--print-directory' Option: -w Option.)
  208. `--no-print-directory'
  209.      Disable printing of the working directory under `-w'.  This option
  210.      is useful when `-w' is turned on automatically, but you do not
  211.      want to see the extra messages.  *Note The `--print-directory'
  212.      Option: -w Option.
  213. `-W FILE'
  214. `--what-if=FILE'
  215. `--new-file=FILE'
  216. `--assume-new=FILE'
  217.      Pretend that the target FILE has just been modified.  When used
  218.      with the `-n' flag, this shows you what would happen if you were
  219.      to modify that file.  Without `-n', it is almost the same as
  220.      running a `touch' command on the given file before running `make',
  221.      except that the modification time is changed only in the
  222.      imagination of `make'.  *Note Instead of Executing the Commands:
  223.      Instead of Execution.
  224. `--warn-undefined-variables'
  225.      Issue a warning message whenever `make' sees a reference to an
  226.      undefined variable.  This can be helpful when you are trying to
  227.      debug makefiles which use variables in complex ways.
  228. File: make.info,  Node: Implicit Rules,  Next: Archives,  Prev: Running,  Up: Top
  229. Using Implicit Rules
  230. ********************
  231.    Certain standard ways of remaking target files are used very often.
  232. For example, one customary way to make an object file is from a C
  233. source file using the C compiler, `cc'.
  234.    "Implicit rules" tell `make' how to use customary techniques so that
  235. you do not have to specify them in detail when you want to use them.
  236. For example, there is an implicit rule for C compilation.  File names
  237. determine which implicit rules are run.  For example, C compilation
  238. typically takes a `.c' file and makes a `.o' file.  So `make' applies
  239. the implicit rule for C compilation when it sees this combination of
  240. file name endings.
  241.    A chain of implicit rules can apply in sequence; for example, `make'
  242. will remake a `.o' file from a `.y' file by way of a `.c' file.
  243.    The built-in implicit rules use several variables in their commands
  244. so that, by changing the values of the variables, you can change the
  245. way the implicit rule works.  For example, the variable `CFLAGS'
  246. controls the flags given to the C compiler by the implicit rule for C
  247. compilation.
  248.    You can define your own implicit rules by writing "pattern rules".
  249.    "Suffix rules" are a more limited way to define implicit rules.
  250. Pattern rules are more general and clearer, but suffix rules are
  251. retained for compatibility.
  252. * Menu:
  253. * Using Implicit::              How to use an existing implicit rule
  254.                                   to get the commands for updating a file.
  255. * Catalogue of Rules::          A list of built-in implicit rules.
  256. * Implicit Variables::          How to change what predefined rules do.
  257. * Chained Rules::               How to use a chain of implicit rules.
  258. * Pattern Rules::               How to define new implicit rules.
  259. * Last Resort::                 How to defining commands for rules
  260.                                   which cannot find any.
  261. * Suffix Rules::                The old-fashioned style of implicit rule.
  262. * Search Algorithm::            The precise algorithm for applying
  263.                                   implicit rules.
  264. File: make.info,  Node: Using Implicit,  Next: Catalogue of Rules,  Up: Implicit Rules
  265. Using Implicit Rules
  266. ====================
  267.    To allow `make' to find a customary method for updating a target
  268. file, all you have to do is refrain from specifying commands yourself.
  269. Either write a rule with no command lines, or don't write a rule at
  270. all.  Then `make' will figure out which implicit rule to use based on
  271. which kind of source file exists or can be made.
  272.    For example, suppose the makefile looks like this:
  273.      foo : foo.o bar.o
  274.              cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
  275. Because you mention `foo.o' but do not give a rule for it, `make' will
  276. automatically look for an implicit rule that tells how to update it.
  277. This happens whether or not the file `foo.o' currently exists.
  278.    If an implicit rule is found, it can supply both commands and one or
  279. more dependencies (the source files).  You would want to write a rule
  280. for `foo.o' with no command lines if you need to specify additional
  281. dependencies, such as header files, that the implicit rule cannot
  282. supply.
  283.    Each implicit rule has a target pattern and dependency patterns.
  284. There may be many implicit rules with the same target pattern.  For
  285. example, numerous rules make `.o' files: one, from a `.c' file with the
  286. C compiler; another, from a `.p' file with the Pascal compiler; and so
  287. on.  The rule that actually applies is the one whose dependencies exist
  288. or can be made.  So, if you have a file `foo.c', `make' will run the C
  289. compiler; otherwise, if you have a file `foo.p', `make' will run the
  290. Pascal compiler; and so on.
  291.    Of course, when you write the makefile, you know which implicit rule
  292. you want `make' to use, and you know it will choose that one because you
  293. know which possible dependency files are supposed to exist.  *Note
  294. Catalogue of Implicit Rules: Catalogue of Rules, for a catalogue of all
  295. the predefined implicit rules.
  296.    Above, we said an implicit rule applies if the required dependencies
  297. "exist or can be made".  A file "can be made" if it is mentioned
  298. explicitly in the makefile as a target or a dependency, or if an
  299. implicit rule can be recursively found for how to make it.  When an
  300. implicit dependency is the result of another implicit rule, we say that
  301. "chaining" is occurring.  *Note Chains of Implicit Rules: Chained Rules.
  302.    In general, `make' searches for an implicit rule for each target, and
  303. for each double-colon rule, that has no commands.  A file that is
  304. mentioned only as a dependency is considered a target whose rule
  305. specifies nothing, so implicit rule search happens for it.  *Note
  306. Implicit Rule Search Algorithm: Search Algorithm, for the details of
  307. how the search is done.
  308.    Note that explicit dependencies do not influence implicit rule
  309. search.  For example, consider this explicit rule:
  310.      foo.o: foo.p
  311. The dependency on `foo.p' does not necessarily mean that `make' will
  312. remake `foo.o' according to the implicit rule to make an object file, a
  313. `.o' file, from a Pascal source file, a `.p' file.  For example, if
  314. `foo.c' also exists, the implicit rule to make an object file from a C
  315. source file is used instead, because it appears before the Pascal rule
  316. in the list of predefined implicit rules (*note Catalogue of Implicit
  317. Rules: Catalogue of Rules.).
  318.    If you do not want an implicit rule to be used for a target that has
  319. no commands, you can give that target empty commands by writing a
  320. semicolon (*note Defining Empty Commands: Empty Commands.).
  321. File: make.info,  Node: Catalogue of Rules,  Next: Implicit Variables,  Prev: Using Implicit,  Up: Implicit Rules
  322. Catalogue of Implicit Rules
  323. ===========================
  324.    Here is a catalogue of predefined implicit rules which are always
  325. available unless the makefile explicitly overrides or cancels them.
  326. *Note Canceling Implicit Rules: Canceling Rules, for information on
  327. canceling or overriding an implicit rule.  The `-r' or
  328. `--no-builtin-rules' option cancels all predefined rules.
  329.    Not all of these rules will always be defined, even when the `-r'
  330. option is not given.  Many of the predefined implicit rules are
  331. implemented in `make' as suffix rules, so which ones will be defined
  332. depends on the "suffix list" (the list of dependencies of the special
  333. target `.SUFFIXES').  The default suffix list is: `.out', `.a', `.ln',
  334. `.o', `.c', `.cc', `.C', `.p', `.f', `.F', `.r', `.y', `.l', `.s',
  335. `.S', `.mod', `.sym', `.def', `.h', `.info', `.dvi', `.tex', `.texinfo',
  336. `.texi', `.txinfo', `.w', `.ch' `.web', `.sh', `.elc', `.el'.  All of
  337. the implicit rules described below whose dependencies have one of these
  338. suffixes are actually suffix rules.  If you modify the suffix list, the
  339. only predefined suffix rules in effect will be those named by one or
  340. two of the suffixes that are on the list you specify; rules whose
  341. suffixes fail to be on the list are disabled.  *Note Old-Fashioned
  342. Suffix Rules: Suffix Rules, for full details on suffix rules.
  343. Compiling C programs
  344.      `N.o' is made automatically from `N.c' with a command of the form
  345.      `$(CC) -c $(CPPFLAGS) $(CFLAGS)'.
  346. Compiling C++ programs
  347.      `N.o' is made automatically from `N.cc' or `N.C' with a command of
  348.      the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'.  We encourage you to
  349.      use the suffix `.cc' for C++ source files instead of `.C'.
  350. Compiling Pascal programs
  351.      `N.o' is made automatically from `N.p' with the command `$(PC) -c
  352.      $(PFLAGS)'.
  353. Compiling Fortran and Ratfor programs
  354.      `N.o' is made automatically from `N.r', `N.F' or `N.f' by running
  355.      the Fortran compiler.  The precise command used is as follows:
  356.     `.f'
  357.           `$(FC) -c $(FFLAGS)'.
  358.     `.F'
  359.           `$(FC) -c $(FFLAGS) $(CPPFLAGS)'.
  360.     `.r'
  361.           `$(FC) -c $(FFLAGS) $(RFLAGS)'.
  362. Preprocessing Fortran and Ratfor programs
  363.      `N.f' is made automatically from `N.r' or `N.F'.  This rule runs
  364.      just the preprocessor to convert a Ratfor or preprocessable
  365.      Fortran program into a strict Fortran program.  The precise
  366.      command used is as follows:
  367.     `.F'
  368.           `$(FC) -F $(CPPFLAGS) $(FFLAGS)'.
  369.     `.r'
  370.           `$(FC) -F $(FFLAGS) $(RFLAGS)'.
  371. Compiling Modula-2 programs
  372.      `N.sym' is made from `N.def' with a command of the form `$(M2C)
  373.      $(M2FLAGS) $(DEFFLAGS)'.  `N.o' is made from `N.mod'; the form is:
  374.      `$(M2C) $(M2FLAGS) $(MODFLAGS)'.
  375. Assembling and preprocessing assembler programs
  376.      `N.o' is made automatically from `N.s' by running the assembler,
  377.      `as'.  The precise command is `$(AS) $(ASFLAGS)'.
  378.      `N.s' is made automatically from `N.S' by running the C
  379.      preprocessor, `cpp'.  The precise command is `$(CPP) $(CPPFLAGS)'.
  380. Linking a single object file
  381.      `N' is made automatically from `N.o' by running the linker
  382.      (usually called `ld') via the C compiler.  The precise command
  383.      used is `$(CC) $(LDFLAGS) N.o $(LOADLIBES)'.
  384.      This rule does the right thing for a simple program with only one
  385.      source file.  It will also do the right thing if there are multiple
  386.      object files (presumably coming from various other source files),
  387.      one of which has a name matching that of the executable file.
  388.      Thus,
  389.           x: y.o z.o
  390.      when `x.c', `y.c' and `z.c' all exist will execute:
  391.           cc -c x.c -o x.o
  392.           cc -c y.c -o y.o
  393.           cc -c z.c -o z.o
  394.           cc x.o y.o z.o -o x
  395.           rm -f x.o
  396.           rm -f y.o
  397.           rm -f z.o
  398.      In more complicated cases, such as when there is no object file
  399.      whose name derives from the executable file name, you must write
  400.      an explicit command for linking.
  401.      Each kind of file automatically made into `.o' object files will
  402.      be automatically linked by using the compiler (`$(CC)', `$(FC)' or
  403.      `$(PC)'; the C compiler `$(CC)' is used to assemble `.s' files)
  404.      without the `-c' option.  This could be done by using the `.o'
  405.      object files as intermediates, but it is faster to do the
  406.      compiling and linking in one step, so that's how it's done.
  407. Yacc for C programs
  408.      `N.c' is made automatically from `N.y' by running Yacc with the
  409.      command `$(YACC) $(YFLAGS)'.
  410. Lex for C programs
  411.      `N.c' is made automatically from `N.l' by by running Lex.  The
  412.      actual command is `$(LEX) $(LFLAGS)'.
  413. Lex for Ratfor programs
  414.      `N.r' is made automatically from `N.l' by by running Lex.  The
  415.      actual command is `$(LEX) $(LFLAGS)'.
  416.      The convention of using the same suffix `.l' for all Lex files
  417.      regardless of whether they produce C code or Ratfor code makes it
  418.      impossible for `make' to determine automatically which of the two
  419.      languages you are using in any particular case.  If `make' is
  420.      called upon to remake an object file from a `.l' file, it must
  421.      guess which compiler to use.  It will guess the C compiler, because
  422.      that is more common.  If you are using Ratfor, make sure `make'
  423.      knows this by mentioning `N.r' in the makefile.  Or, if you are
  424.      using Ratfor exclusively, with no C files, remove `.c' from the
  425.      list of implicit rule suffixes with:
  426.           .SUFFIXES:
  427.           .SUFFIXES: .o .r .f .l ...
  428. Making Lint Libraries from C, Yacc, or Lex programs
  429.      `N.ln' is made from `N.c' by running `lint'.  The precise command
  430.      is `$(LINT) $(LINTFLAGS) $(CPPFLAGS) -i'.  The same command is
  431.      used on the C code produced from `N.y' or `N.l'.
  432. TeX and Web
  433.      `N.dvi' is made from `N.tex' with the command `$(TEX)'.  `N.tex'
  434.      is made from `N.web' with `$(WEAVE)', or from `N.w' (and from
  435.      `N.ch' if it exists or can be made) with `$(CWEAVE)'.  `N.p' is
  436.      made from `N.web' with `$(TANGLE)' and `N.c' is made from `N.w'
  437.      (and from `N.ch' if it exists or can be made) with `$(CTANGLE)'.
  438. Texinfo and Info
  439.      `N.dvi' is made from `N.texinfo', `N.texi', or `N.txinfo', with
  440.      the command `$(TEXI2DVI) $(TEXI2DVI_FLAGS)'.  `N.info' is made from
  441.      `N.texinfo', `N.texi', or `N.txinfo', with the command
  442.      `$(MAKEINFO) $(MAKEINFO_FLAGS)'.
  443.      Any file `N' is extracted if necessary from an RCS file named
  444.      either `N,v' or `RCS/N,v'.  The precise command used is
  445.      `$(CO) $(COFLAGS)'.  `N' will not be extracted from RCS if it
  446.      already exists, even if the RCS file is newer.  The rules for RCS
  447.      are terminal (*note Match-Anything Pattern Rules: Match-Anything
  448.      Rules.), so RCS files cannot be generated from another source;
  449.      they must actually exist.
  450.      Any file `N' is extracted if necessary from an SCCS file named
  451.      either `s.N' or `SCCS/s.N'.  The precise command used is
  452.      `$(GET) $(GFLAGS)'.  The rules for SCCS are terminal (*note
  453.      Match-Anything Pattern Rules: Match-Anything Rules.), so SCCS
  454.      files cannot be generated from another source; they must actually
  455.      exist.
  456.      For the benefit of SCCS, a file `N' is copied from `N.sh' and made
  457.      executable (by everyone).  This is for shell scripts that are
  458.      checked into SCCS.  Since RCS preserves the execution permission
  459.      of a file, you do not need to use this feature with RCS.
  460.      We recommend that you avoid using of SCCS.  RCS is widely held to
  461.      be superior, and is also free.  By choosing free software in place
  462.      of comparable (or inferior) proprietary software, you support the
  463.      free software movement.
  464.    Usually, you want to change only the variables listed in the table
  465. above, which are documented in the following section.
  466.    However, the commands in built-in implicit rules actually use
  467. variables such as `COMPILE.c', `LINK.p', and `PREPROCESS.S', whose
  468. values contain the commands listed above.
  469.    `make' follows the convention that the rule to compile a `.X' source
  470. file uses the variable `COMPILE.X'.  Similarly, the rule to produce an
  471. executable from a `.X' file uses `LINK.X'; and the rule to preprocess a
  472. `.X' file uses `PREPROCESS.X'.
  473.    Every rule that produces an object file uses the variable
  474. `OUTPUT_OPTION'.  `make' defines this variable either to contain `-o
  475. $@', or to be empty, depending on a compile-time option.  You need the
  476. `-o' option to ensure that the output goes into the right file when the
  477. source file is in a different directory, as when using `VPATH' (*note
  478. Directory Search::.).  However, compilers on some systems do not accept
  479. a `-o' switch for object files.  If you use such a system, and use
  480. `VPATH', some compilations will put their output in the wrong place.  A
  481. possible workaround for this problem is to give `OUTPUT_OPTION' the
  482. value `; mv $*.o $@'.
  483. File: make.info,  Node: Implicit Variables,  Next: Chained Rules,  Prev: Catalogue of Rules,  Up: Implicit Rules
  484. Variables Used by Implicit Rules
  485. ================================
  486.    The commands in built-in implicit rules make liberal use of certain
  487. predefined variables.  You can alter these variables in the makefile,
  488. with arguments to `make', or in the environment to alter how the
  489. implicit rules work without redefining the rules themselves.
  490.    For example, the command used to compile a C source file actually
  491. says `$(CC) -c $(CFLAGS) $(CPPFLAGS)'.  The default values of the
  492. variables used are `cc' and nothing, resulting in the command `cc -c'.
  493. By redefining `CC' to `ncc', you could cause `ncc' to be used for all C
  494. compilations performed by the implicit rule.  By redefining `CFLAGS' to
  495. be `-g', you could pass the `-g' option to each compilation.  *All*
  496. implicit rules that do C compilation use `$(CC)' to get the program
  497. name for the compiler and *all* include `$(CFLAGS)' among the arguments
  498. given to the compiler.
  499.    The variables used in implicit rules fall into two classes: those
  500. that are names of programs (like `CC') and those that contain arguments
  501. for the programs (like `CFLAGS').  (The "name of a program" may also
  502. contain some command arguments, but it must start with an actual
  503. executable program name.)  If a variable value contains more than one
  504. argument, separate them with spaces.
  505.    Here is a table of variables used as names of programs in built-in
  506. rules:
  507.      Archive-maintaining program; default `ar'.
  508.      Program for doing assembly; default `as'.
  509.      Program for compiling C programs; default `cc'.
  510. `CXX'
  511.      Program for compiling C++ programs; default `g++'.
  512.      Program for extracting a file from RCS; default `co'.
  513. `CPP'
  514.      Program for running the C preprocessor, with results to standard
  515.      output; default `$(CC) -E'.
  516.      Program for compiling or preprocessing Fortran and Ratfor programs;
  517.      default `f77'.
  518. `GET'
  519.      Program for extracting a file from SCCS; default `get'.
  520. `LEX'
  521.      Program to use to turn Lex grammars into C programs or Ratfor
  522.      programs; default `lex'.
  523.      Program for compiling Pascal programs; default `pc'.
  524. `YACC'
  525.      Program to use to turn Yacc grammars into C programs; default
  526.      `yacc'.
  527. `YACCR'
  528.      Program to use to turn Yacc grammars into Ratfor programs; default
  529.      `yacc -r'.
  530. `MAKEINFO'
  531.      Program to convert a Texinfo source file into an Info file; default
  532.      `makeinfo'.
  533. `TEX'
  534.      Program to make TeX DVI files from TeX source; default `tex'.
  535. `TEXI2DVI'
  536.      Program to make TeX DVI files from Texinfo source; default
  537.      `texi2dvi'.
  538. `WEAVE'
  539.      Program to translate Web into TeX; default `weave'.
  540. `CWEAVE'
  541.      Program to translate C Web into TeX; default `cweave'.
  542. `TANGLE'
  543.      Program to translate Web into Pascal; default `tangle'.
  544. `CTANGLE'
  545.      Program to translate C Web into C; default `ctangle'.
  546.      Command to remove a file; default `rm -f'.
  547.    Here is a table of variables whose values are additional arguments
  548. for the programs above.  The default values for all of these is the
  549. empty string, unless otherwise noted.
  550. `ARFLAGS'
  551.      Flags to give the archive-maintaining program; default `rv'.
  552. `ASFLAGS'
  553.      Extra flags to give to the assembler (when explicitly invoked on a
  554.      `.s' or `.S' file).
  555. `CFLAGS'
  556.      Extra flags to give to the C compiler.
  557. `CXXFLAGS'
  558.      Extra flags to give to the C++ compiler.
  559. `COFLAGS'
  560.      Extra flags to give to the RCS `co' program.
  561. `CPPFLAGS'
  562.      Extra flags to give to the C preprocessor and programs that use it
  563.      (the C and Fortran compilers).
  564. `FFLAGS'
  565.      Extra flags to give to the Fortran compiler.
  566. `GFLAGS'
  567.      Extra flags to give to the SCCS `get' program.
  568. `LDFLAGS'
  569.      Extra flags to give to compilers when they are supposed to invoke
  570.      the linker, `ld'.
  571. `LFLAGS'
  572.      Extra flags to give to Lex.
  573. `PFLAGS'
  574.      Extra flags to give to the Pascal compiler.
  575. `RFLAGS'
  576.      Extra flags to give to the Fortran compiler for Ratfor programs.
  577. `YFLAGS'
  578.      Extra flags to give to Yacc.
  579. File: make.info,  Node: Chained Rules,  Next: Pattern Rules,  Prev: Implicit Variables,  Up: Implicit Rules
  580. Chains of Implicit Rules
  581. ========================
  582.    Sometimes a file can be made by a sequence of implicit rules.  For
  583. example, a file `N.o' could be made from `N.y' by running first Yacc
  584. and then `cc'.  Such a sequence is called a "chain".
  585.    If the file `N.c' exists, or is mentioned in the makefile, no
  586. special searching is required: `make' finds that the object file can be
  587. made by C compilation from `N.c'; later on, when considering how to
  588. make `N.c', the rule for running Yacc is used.  Ultimately both `N.c'
  589. and `N.o' are updated.
  590.    However, even if `N.c' does not exist and is not mentioned, `make'
  591. knows how to envision it as the missing link between `N.o' and `N.y'!
  592. In this case, `N.c' is called an "intermediate file".  Once `make' has
  593. decided to use the intermediate file, it is entered in the data base as
  594. if it had been mentioned in the makefile, along with the implicit rule
  595. that says how to create it.
  596.    Intermediate files are remade using their rules just like all other
  597. files.  But intermediate files are treated differently in two ways.
  598.    The first difference is what happens if the intermediate file does
  599. not exist.  If an ordinary file B does not exist, and `make' considers
  600. a target that depends on B, it invariably creates B and then updates
  601. the target from B.  But if B is an intermediate file, then `make' can
  602. leave well enough alone.  It won't bother updating B, or the ultimate
  603. target, unless some dependency of B is newer than that target or there
  604. is some other reason to update that target.
  605.    The second difference is that if `make' *does* create B in order to
  606. update something else, it deletes B later on after it is no longer
  607. needed.  Therefore, an intermediate file which did not exist before
  608. `make' also does not exist after `make'.  `make' reports the deletion
  609. to you by printing a `rm -f' command showing which file it is deleting.
  610.    Ordinarily, a file cannot be intermediate if it is mentioned in the
  611. makefile as a target or dependency.  However, you can explicitly mark a
  612. file as intermediate by listing it as a dependency of the special target
  613. `.INTERMEDIATE'.  This takes effect even if the file is mentioned
  614. explicitly in some other way.
  615.    You can prevent automatic deletion of an intermediate file by
  616. marking it as a "secondary" file.  To do this, list it as a dependency
  617. of the special target `.SECONDARY'.  When a file is secondary, `make'
  618. will not create the file merely because it does not already exist, but
  619. `make' does not automatically delete the file.  Marking a file as
  620. secondary also marks it as intermediate.
  621.    You can list the target pattern of an implicit rule (such as `%.o')
  622. as a dependency of the special target `.PRECIOUS' to preserve
  623. intermediate files made by implicit rules whose target patterns match
  624. that file's name; see *Note Interrupts::.
  625.    A chain can involve more than two implicit rules.  For example, it is
  626. possible to make a file `foo' from `RCS/foo.y,v' by running RCS, Yacc
  627. and `cc'.  Then both `foo.y' and `foo.c' are intermediate files that
  628. are deleted at the end.
  629.    No single implicit rule can appear more than once in a chain.  This
  630. means that `make' will not even consider such a ridiculous thing as
  631. making `foo' from `foo.o.o' by running the linker twice.  This
  632. constraint has the added benefit of preventing any infinite loop in the
  633. search for an implicit rule chain.
  634.    There are some special implicit rules to optimize certain cases that
  635. would otherwise be handled by rule chains.  For example, making `foo'
  636. from `foo.c' could be handled by compiling and linking with separate
  637. chained rules, using `foo.o' as an intermediate file.  But what
  638. actually happens is that a special rule for this case does the
  639. compilation and linking with a single `cc' command.  The optimized rule
  640. is used in preference to the step-by-step chain because it comes
  641. earlier in the ordering of rules.
  642. File: make.info,  Node: Pattern Rules,  Next: Last Resort,  Prev: Chained Rules,  Up: Implicit Rules
  643. Defining and Redefining Pattern Rules
  644. =====================================
  645.    You define an implicit rule by writing a "pattern rule".  A pattern
  646. rule looks like an ordinary rule, except that its target contains the
  647. character `%' (exactly one of them).  The target is considered a
  648. pattern for matching file names; the `%' can match any nonempty
  649. substring, while other characters match only themselves.  The
  650. dependencies likewise use `%' to show how their names relate to the
  651. target name.
  652.    Thus, a pattern rule `%.o : %.c' says how to make any file `STEM.o'
  653. from another file `STEM.c'.
  654.    Note that expansion using `%' in pattern rules occurs *after* any
  655. variable or function expansions, which take place when the makefile is
  656. read.  *Note How to Use Variables: Using Variables, and *Note Functions
  657. for Transforming Text: Functions.
  658. * Menu:
  659. * Pattern Intro::               An introduction to pattern rules.
  660. * Pattern Examples::            Examples of pattern rules.
  661. * Automatic::                   How to use automatic variables in the
  662.                                   commands of implicit rules.
  663. * Pattern Match::               How patterns match.
  664. * Match-Anything Rules::        Precautions you should take prior to
  665.                                   defining rules that can match any
  666.                                   target file whatever.
  667. * Canceling Rules::             How to override or cancel built-in rules.
  668. File: make.info,  Node: Pattern Intro,  Next: Pattern Examples,  Up: Pattern Rules
  669. Introduction to Pattern Rules
  670. -----------------------------
  671.    A pattern rule contains the character `%' (exactly one of them) in
  672. the target; otherwise, it looks exactly like an ordinary rule.  The
  673. target is a pattern for matching file names; the `%' matches any
  674. nonempty substring, while other characters match only themselves.
  675.    For example, `%.c' as a pattern matches any file name that ends in
  676. `.c'.  `s.%.c' as a pattern matches any file name that starts with
  677. `s.', ends in `.c' and is at least five characters long.  (There must
  678. be at least one character to match the `%'.)  The substring that the
  679. `%' matches is called the "stem".
  680.    `%' in a dependency of a pattern rule stands for the same stem that
  681. was matched by the `%' in the target.  In order for the pattern rule to
  682. apply, its target pattern must match the file name under consideration,
  683. and its dependency patterns must name files that exist or can be made.
  684. These files become dependencies of the target.
  685.    Thus, a rule of the form
  686.      %.o : %.c ; COMMAND...
  687. specifies how to make a file `N.o', with another file `N.c' as its
  688. dependency, provided that `N.c' exists or can be made.
  689.    There may also be dependencies that do not use `%'; such a dependency
  690. attaches to every file made by this pattern rule.  These unvarying
  691. dependencies are useful occasionally.
  692.    A pattern rule need not have any dependencies that contain `%', or
  693. in fact any dependencies at all.  Such a rule is effectively a general
  694. wildcard.  It provides a way to make any file that matches the target
  695. pattern.  *Note Last Resort::.
  696.    Pattern rules may have more than one target.  Unlike normal rules,
  697. this does not act as many different rules with the same dependencies and
  698. commands.  If a pattern rule has multiple targets, `make' knows that
  699. the rule's commands are responsible for making all of the targets.  The
  700. commands are executed only once to make all the targets.  When searching
  701. for a pattern rule to match a target, the target patterns of a rule
  702. other than the one that matches the target in need of a rule are
  703. incidental: `make' worries only about giving commands and dependencies
  704. to the file presently in question.  However, when this file's commands
  705. are run, the other targets are marked as having been updated themselves.
  706.    The order in which pattern rules appear in the makefile is important
  707. since this is the order in which they are considered.  Of equally
  708. applicable rules, only the first one found is used.  The rules you
  709. write take precedence over those that are built in.  Note however, that
  710. a rule whose dependencies actually exist or are mentioned always takes
  711. priority over a rule with dependencies that must be made by chaining
  712. other implicit rules.
  713. File: make.info,  Node: Pattern Examples,  Next: Automatic,  Prev: Pattern Intro,  Up: Pattern Rules
  714. Pattern Rule Examples
  715. ---------------------
  716.    Here are some examples of pattern rules actually predefined in
  717. `make'.  First, the rule that compiles `.c' files into `.o' files:
  718.      %.o : %.c
  719.              $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
  720. defines a rule that can make any file `X.o' from `X.c'.  The command
  721. uses the automatic variables `$@' and `$<' to substitute the names of
  722. the target file and the source file in each case where the rule applies
  723. (*note Automatic Variables: Automatic.).
  724.    Here is a second built-in rule:
  725.      % :: RCS/%,v
  726.              $(CO) $(COFLAGS) $<
  727. defines a rule that can make any file `X' whatsoever from a
  728. corresponding file `X,v' in the subdirectory `RCS'.  Since the target
  729. is `%', this rule will apply to any file whatever, provided the
  730. appropriate dependency file exists.  The double colon makes the rule
  731. "terminal", which means that its dependency may not be an intermediate
  732. file (*note Match-Anything Pattern Rules: Match-Anything Rules.).
  733.    This pattern rule has two targets:
  734.      %.tab.c %.tab.h: %.y
  735.              bison -d $<
  736. This tells `make' that the command `bison -d X.y' will make both
  737. `X.tab.c' and `X.tab.h'.  If the file `foo' depends on the files
  738. `parse.tab.o' and `scan.o' and the file `scan.o' depends on the file
  739. `parse.tab.h', when `parse.y' is changed, the command `bison -d parse.y'
  740. will be executed only once, and the dependencies of both `parse.tab.o'
  741. and `scan.o' will be satisfied.  (Presumably the file `parse.tab.o'
  742. will be recompiled from `parse.tab.c' and the file `scan.o' from
  743. `scan.c', while `foo' is linked from `parse.tab.o', `scan.o', and its
  744. other dependencies, and it will execute happily ever after.)
  745. File: make.info,  Node: Automatic,  Next: Pattern Match,  Prev: Pattern Examples,  Up: Pattern Rules
  746. Automatic Variables
  747. -------------------
  748.    Suppose you are writing a pattern rule to compile a `.c' file into a
  749. `.o' file: how do you write the `cc' command so that it operates on the
  750. right source file name?  You cannot write the name in the command,
  751. because the name is different each time the implicit rule is applied.
  752.    What you do is use a special feature of `make', the "automatic
  753. variables".  These variables have values computed afresh for each rule
  754. that is executed, based on the target and dependencies of the rule.  In
  755. this example, you would use `$@' for the object file name and `$<' for
  756. the source file name.
  757.    Here is a table of automatic variables:
  758.      The file name of the target of the rule.  If the target is an
  759.      archive member, then `$@' is the name of the archive file.  In a
  760.      pattern rule that has multiple targets (*note Introduction to
  761.      Pattern Rules: Pattern Intro.), `$@' is the name of whichever
  762.      target caused the rule's commands to be run.
  763.      The target member name, when the target is an archive member.
  764.      *Note Archives::.  For example, if the target is `foo.a(bar.o)'
  765.      then `$%' is `bar.o' and `$@' is `foo.a'.  `$%' is empty when the
  766.      target is not an archive member.
  767.      The name of the first dependency.  If the target got its commands
  768.      from an implicit rule, this will be the first dependency added by
  769.      the implicit rule (*note Implicit Rules::.).
  770.      The names of all the dependencies that are newer than the target,
  771.      with spaces between them.  For dependencies which are archive
  772.      members, only the member named is used (*note Archives::.).
  773.      The names of all the dependencies, with spaces between them.  For
  774.      dependencies which are archive members, only the member named is
  775.      used (*note Archives::.).  A target has only one dependency on
  776.      each other file it depends on, no matter how many times each file
  777.      is listed as a dependency.  So if you list a dependency more than
  778.      once for a target, the value of `$^' contains just one copy of the
  779.      name.
  780.      This is like `$^', but dependencies listed more than once are
  781.      duplicated in the order they were listed in the makefile.  This is
  782.      primarily useful for use in linking commands where it is
  783.      meaningful to repeat library file names in a particular order.
  784.      The stem with which an implicit rule matches (*note How Patterns
  785.      Match: Pattern Match.).  If the target is `dir/a.foo.b' and the
  786.      target pattern is `a.%.b' then the stem is `dir/foo'.  The stem is
  787.      useful for constructing names of related files.
  788.      In a static pattern rule, the stem is part of the file name that
  789.      matched the `%' in the target pattern.
  790.      In an explicit rule, there is no stem; so `$*' cannot be determined
  791.      in that way.  Instead, if the target name ends with a recognized
  792.      suffix (*note Old-Fashioned Suffix Rules: Suffix Rules.), `$*' is
  793.      set to the target name minus the suffix.  For example, if the
  794.      target name is `foo.c', then `$*' is set to `foo', since `.c' is a
  795.      suffix.  GNU `make' does this bizarre thing only for compatibility
  796.      with other implementations of `make'.  You should generally avoid
  797.      using `$*' except in implicit rules or static pattern rules.
  798.      If the target name in an explicit rule does not end with a
  799.      recognized suffix, `$*' is set to the empty string for that rule.
  800.    `$?' is useful even in explicit rules when you wish to operate on
  801. only the dependencies that have changed.  For example, suppose that an
  802. archive named `lib' is supposed to contain copies of several object
  803. files.  This rule copies just the changed object files into the archive:
  804.      lib: foo.o bar.o lose.o win.o
  805.              ar r lib $?
  806.    Of the variables listed above, four have values that are single file
  807. names, and two have values that are lists of file names.  These six have
  808. variants that get just the file's directory name or just the file name
  809. within the directory.  The variant variables' names are formed by
  810. appending `D' or `F', respectively.  These variants are semi-obsolete
  811. in GNU `make' since the functions `dir' and `notdir' can be used to get
  812. a similar effect (*note Functions for File Names: Filename Functions.).
  813. Note, however, that the `F' variants all omit the trailing slash which
  814. always appears in the output of the `dir' function.  Here is a table of
  815. the variants:
  816. `$(@D)'
  817.      The directory part of the file name of the target, with the
  818.      trailing slash removed.  If the value of `$@' is `dir/foo.o' then
  819.      `$(@D)' is `dir'.  This value is `.' if `$@' does not contain a
  820.      slash.
  821. `$(@F)'
  822.      The file-within-directory part of the file name of the target.  If
  823.      the value of `$@' is `dir/foo.o' then `$(@F)' is `foo.o'.  `$(@F)'
  824.      is equivalent to `$(notdir $@)'.
  825. `$(*D)'
  826. `$(*F)'
  827.      The directory part and the file-within-directory part of the stem;
  828.      `dir' and `foo' in this example.
  829. `$(%D)'
  830. `$(%F)'
  831.      The directory part and the file-within-directory part of the target
  832.      archive member name.  This makes sense only for archive member
  833.      targets of the form `ARCHIVE(MEMBER)' and is useful only when
  834.      MEMBER may contain a directory name.  (*Note Archive Members as
  835.      Targets: Archive Members.)
  836. `$(<D)'
  837. `$(<F)'
  838.      The directory part and the file-within-directory part of the first
  839.      dependency.
  840. `$(^D)'
  841. `$(^F)'
  842.      Lists of the directory parts and the file-within-directory parts
  843.      of all dependencies.
  844. `$(?D)'
  845. `$(?F)'
  846.      Lists of the directory parts and the file-within-directory parts of
  847.      all dependencies that are newer than the target.
  848.    Note that we use a special stylistic convention when we talk about
  849. these automatic variables; we write "the value of `$<'", rather than
  850. "the variable `<'" as we would write for ordinary variables such as
  851. `objects' and `CFLAGS'.  We think this convention looks more natural in
  852. this special case.  Please do not assume it has a deep significance;
  853. `$<' refers to the variable named `<' just as `$(CFLAGS)' refers to the
  854. variable named `CFLAGS'.  You could just as well use `$(<)' in place of
  855. `$<'.
  856. File: make.info,  Node: Pattern Match,  Next: Match-Anything Rules,  Prev: Automatic,  Up: Pattern Rules
  857. How Patterns Match
  858. ------------------
  859.    A target pattern is composed of a `%' between a prefix and a suffix,
  860. either or both of which may be empty.  The pattern matches a file name
  861. only if the file name starts with the prefix and ends with the suffix,
  862. without overlap.  The text between the prefix and the suffix is called
  863. the "stem".  Thus, when the pattern `%.o' matches the file name
  864. `test.o', the stem is `test'.  The pattern rule dependencies are turned
  865. into actual file names by substituting the stem for the character `%'.
  866. Thus, if in the same example one of the dependencies is written as
  867. `%.c', it expands to `test.c'.
  868.    When the target pattern does not contain a slash (and it usually does
  869. not), directory names in the file names are removed from the file name
  870. before it is compared with the target prefix and suffix.  After the
  871. comparison of the file name to the target pattern, the directory names,
  872. along with the slash that ends them, are added on to the dependency
  873. file names generated from the pattern rule's dependency patterns and
  874. the file name. The directories are ignored only for the purpose of
  875. finding an implicit rule to use, not in the application of that rule.
  876. Thus, `e%t' matches the file name `src/eat', with `src/a' as the stem.
  877. When dependencies are turned into file names, the directories from the
  878. stem are added at the front, while the rest of the stem is substituted
  879. for the `%'.  The stem `src/a' with a dependency pattern `c%r' gives
  880. the file name `src/car'.
  881.