home *** CD-ROM | disk | FTP | other *** search
/ Freelog 22 / freelog 22.iso / Prog / Djgpp / MAK3791B.ZIP / info / make.i2 < prev    next >
Encoding:
GNU Info File  |  2000-07-14  |  50.0 KB  |  1,248 lines

  1. This is make.info, produced by makeinfo version 4.0 from make.texinfo.
  2.  
  3. INFO-DIR-SECTION GNU Packages
  4. START-INFO-DIR-ENTRY
  5. * Make: (make).            Remake files automatically.
  6. END-INFO-DIR-ENTRY
  7.  
  8.    This file documents the GNU Make utility, which determines
  9. automatically which pieces of a large program need to be recompiled,
  10. and issues the commands to recompile them.
  11.  
  12.    This is Edition 0.55, last updated 04 April 2000, of `The GNU Make
  13. Manual', for `make', Version 3.79.
  14.  
  15.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95, '96, '97,
  16. '98, '99, 2000         Free Software Foundation, Inc.
  17.  
  18.    Permission is granted to make and distribute verbatim copies of this
  19. manual provided the copyright notice and this permission notice are
  20. preserved on all copies.
  21.  
  22.    Permission is granted to copy and distribute modified versions of
  23. this manual under the conditions for verbatim copying, provided that
  24. the entire resulting derived work is distributed under the terms of a
  25. permission notice identical to this one.
  26.  
  27.    Permission is granted to copy and distribute translations of this
  28. manual into another language, under the above conditions for modified
  29. versions, except that this permission notice may be stated in a
  30. translation approved by the Free Software Foundation.
  31.  
  32. 
  33. File: make.info,  Node: Reading Makefiles,  Prev: Overriding Makefiles,  Up: Makefiles
  34.  
  35. How `make' Reads a Makefile
  36. ===========================
  37.  
  38.    GNU `make' does its work in two distinct phases.  During the first
  39. phase it reads all the makefiles, included makefiles, etc. and
  40. internalizes all the variables and their values, implicit and explicit
  41. rules, and constructs a dependency graph of all the targets and their
  42. prerequisites.  During the second phase, `make' uses these internal
  43. structures to determine what targets will need to be rebuilt and to
  44. invoke the rules necessary to do so.
  45.  
  46.    It's important to understand this two-phase approach because it has a
  47. direct impact on how variable and function expansion happens; this is
  48. often a source of some confusion when writing makefiles.  Here we will
  49. present a summary of the phases in which expansion happens for different
  50. constructs within the makefile.  We say that expansion is "immediate"
  51. if it happens during the first phase: in this case `make' will expand
  52. any variables or functions in that section of a construct as the
  53. makefile is parsed.  We say that expansion is "deferred" if expansion
  54. is not performed immediately.  Expansion of deferred construct is not
  55. performed until either the construct appears later in an immediate
  56. context, or until the second phase.
  57.  
  58.    You may not be familiar with some of these constructs yet.  You can
  59. reference this section as you become familiar with them, in later
  60. chapters.
  61.  
  62. Variable Assignment
  63. -------------------
  64.  
  65.    Variable definitions are parsed as follows:
  66.  
  67.      IMMEDIATE = DEFERRED
  68.      IMMEDIATE ?= DEFERRED
  69.      IMMEDIATE := IMMEDIATE
  70.      IMMEDIATE += DEFERRED or IMMEDIATE
  71.      
  72.      define IMMEDIATE
  73.        DEFERRED
  74.      endef
  75.  
  76.    For the append operator, `+=', the right-hand side is considered
  77. immediate if the variable was previously set as a simple variable
  78. (`:='), and deferred otherwise.
  79.  
  80. Conditional Syntax
  81. ------------------
  82.  
  83.    All instances of conditional syntax are parsed immediately, in their
  84. entirety; this includes the `ifdef', `ifeq', `ifndef', and `ifneq'
  85. forms.
  86.  
  87. Rule Definition
  88. ---------------
  89.  
  90.    A rule is always expanded the same way, regardless of the form:
  91.  
  92.      IMMEDIATE : IMMEDIATE ; DEFERRED
  93.          DEFERRED
  94.  
  95.    That is, the target and prerequisite sections are expanded
  96. immediately, and the commands used to construct the target are always
  97. deferred.  This general rule is true for explicit rules, pattern rules,
  98. suffix rules, static pattern rules, and simple prerequisite definitions.
  99.  
  100. 
  101. File: make.info,  Node: Rules,  Next: Commands,  Prev: Makefiles,  Up: Top
  102.  
  103. Writing Rules
  104. *************
  105.  
  106.    A "rule" appears in the makefile and says when and how to remake
  107. certain files, called the rule's "targets" (most often only one per
  108. rule).  It lists the other files that are the "prerequisites" of the
  109. target, and "commands" to use to create or update the target.
  110.  
  111.    The order of rules is not significant, except for determining the
  112. "default goal": the target for `make' to consider, if you do not
  113. otherwise specify one.  The default goal is the target of the first
  114. rule in the first makefile.  If the first rule has multiple targets,
  115. only the first target is taken as the default.  There are two
  116. exceptions: a target starting with a period is not a default unless it
  117. contains one or more slashes, `/', as well; and, a target that defines
  118. a pattern rule has no effect on the default goal.  (*Note Defining and
  119. Redefining Pattern Rules: Pattern Rules.)
  120.  
  121.    Therefore, we usually write the makefile so that the first rule is
  122. the one for compiling the entire program or all the programs described
  123. by the makefile (often with a target called `all').  *Note Arguments to
  124. Specify the Goals: Goals.
  125.  
  126. * Menu:
  127.  
  128. * Rule Example::                An example explained.
  129. * Rule Syntax::                 General syntax explained.
  130. * Wildcards::                   Using wildcard characters such as `*'.
  131. * Directory Search::            Searching other directories for source files.
  132. * Phony Targets::               Using a target that is not a real file's name.
  133. * Force Targets::               You can use a target without commands
  134.                                   or prerequisites to mark other
  135.                                   targets as phony.
  136. * Empty Targets::               When only the date matters and the
  137.                                   files are empty.
  138. * Special Targets::             Targets with special built-in meanings.
  139. * Multiple Targets::            When to make use of several targets in a rule.
  140. * Multiple Rules::              How to use several rules with the same target.
  141. * Static Pattern::              Static pattern rules apply to multiple targets
  142.                                   and can vary the prerequisites according to
  143.                                   the target name.
  144. * Double-Colon::                How to use a special kind of rule to allow
  145.                                   several independent rules for one target.
  146. * Automatic Prerequisites::     How to automatically generate rules giving
  147.                                   prerequisites from source files themselves.
  148.  
  149. 
  150. File: make.info,  Node: Rule Example,  Next: Rule Syntax,  Up: Rules
  151.  
  152. Rule Example
  153. ============
  154.  
  155.    Here is an example of a rule:
  156.  
  157.      foo.o : foo.c defs.h       # module for twiddling the frobs
  158.              cc -c -g foo.c
  159.  
  160.    Its target is `foo.o' and its prerequisites are `foo.c' and
  161. `defs.h'.  It has one command, which is `cc -c -g foo.c'.  The command
  162. line starts with a tab to identify it as a command.
  163.  
  164.    This rule says two things:
  165.  
  166.    * How to decide whether `foo.o' is out of date: it is out of date if
  167.      it does not exist, or if either `foo.c' or `defs.h' is more recent
  168.      than it.
  169.  
  170.    * How to update the file `foo.o': by running `cc' as stated.  The
  171.      command does not explicitly mention `defs.h', but we presume that
  172.      `foo.c' includes it, and that that is why `defs.h' was added to
  173.      the prerequisites.
  174.  
  175. 
  176. File: make.info,  Node: Rule Syntax,  Next: Wildcards,  Prev: Rule Example,  Up: Rules
  177.  
  178. Rule Syntax
  179. ===========
  180.  
  181.    In general, a rule looks like this:
  182.  
  183.      TARGETS : PREREQUISITES
  184.              COMMAND
  185.              ...
  186.  
  187. or like this:
  188.  
  189.      TARGETS : PREREQUISITES ; COMMAND
  190.              COMMAND
  191.              ...
  192.  
  193.    The TARGETS are file names, separated by spaces.  Wildcard
  194. characters may be used (*note Using Wildcard Characters in File Names:
  195. Wildcards.) and a name of the form `A(M)' represents member M in
  196. archive file A (*note Archive Members as Targets: Archive Members.).
  197. Usually there is only one target per rule, but occasionally there is a
  198. reason to have more (*note Multiple Targets in a Rule: Multiple
  199. Targets.).
  200.  
  201.    The COMMAND lines start with a tab character.  The first command may
  202. appear on the line after the prerequisites, with a tab character, or may
  203. appear on the same line, with a semicolon.  Either way, the effect is
  204. the same.  *Note Writing the Commands in Rules: Commands.
  205.  
  206.    Because dollar signs are used to start variable references, if you
  207. really want a dollar sign in a rule you must write two of them, `$$'
  208. (*note How to Use Variables: Using Variables.).  You may split a long
  209. line by inserting a backslash followed by a newline, but this is not
  210. required, as `make' places no limit on the length of a line in a
  211. makefile.
  212.  
  213.    A rule tells `make' two things: when the targets are out of date,
  214. and how to update them when necessary.
  215.  
  216.    The criterion for being out of date is specified in terms of the
  217. PREREQUISITES, which consist of file names separated by spaces.
  218. (Wildcards and archive members (*note Archives::) are allowed here too.)
  219. A target is out of date if it does not exist or if it is older than any
  220. of the prerequisites (by comparison of last-modification times).  The
  221. idea is that the contents of the target file are computed based on
  222. information in the prerequisites, so if any of the prerequisites
  223. changes, the contents of the existing target file are no longer
  224. necessarily valid.
  225.  
  226.    How to update is specified by COMMANDS.  These are lines to be
  227. executed by the shell (normally `sh'), but with some extra features
  228. (*note Writing the Commands in Rules: Commands.).
  229.  
  230. 
  231. File: make.info,  Node: Wildcards,  Next: Directory Search,  Prev: Rule Syntax,  Up: Rules
  232.  
  233. Using Wildcard Characters in File Names
  234. =======================================
  235.  
  236.    A single file name can specify many files using "wildcard
  237. characters".  The wildcard characters in `make' are `*', `?' and
  238. `[...]', the same as in the Bourne shell.  For example, `*.c' specifies
  239. a list of all the files (in the working directory) whose names end in
  240. `.c'.
  241.  
  242.    The character `~' at the beginning of a file name also has special
  243. significance.  If alone, or followed by a slash, it represents your home
  244. directory.  For example `~/bin' expands to `/home/you/bin'.  If the `~'
  245. is followed by a word, the string represents the home directory of the
  246. user named by that word.  For example `~john/bin' expands to
  247. `/home/john/bin'.  On systems which don't have a home directory for
  248. each user (such as MS-DOS or MS-Windows), this functionality can be
  249. simulated by setting the environment variable HOME.
  250.  
  251.    Wildcard expansion happens automatically in targets, in
  252. prerequisites, and in commands (where the shell does the expansion).
  253. In other contexts, wildcard expansion happens only if you request it
  254. explicitly with the `wildcard' function.
  255.  
  256.    The special significance of a wildcard character can be turned off by
  257. preceding it with a backslash.  Thus, `foo\*bar' would refer to a
  258. specific file whose name consists of `foo', an asterisk, and `bar'.
  259.  
  260. * Menu:
  261.  
  262. * Wildcard Examples::           Several examples
  263. * Wildcard Pitfall::            Problems to avoid.
  264. * Wildcard Function::           How to cause wildcard expansion where
  265.                                   it does not normally take place.
  266.  
  267. 
  268. File: make.info,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Up: Wildcards
  269.  
  270. Wildcard Examples
  271. -----------------
  272.  
  273.    Wildcards can be used in the commands of a rule, where they are
  274. expanded by the shell.  For example, here is a rule to delete all the
  275. object files:
  276.  
  277.      clean:
  278.              rm -f *.o
  279.  
  280.    Wildcards are also useful in the prerequisites of a rule.  With the
  281. following rule in the makefile, `make print' will print all the `.c'
  282. files that have changed since the last time you printed them:
  283.  
  284.      print: *.c
  285.              lpr -p $?
  286.              touch print
  287.  
  288. This rule uses `print' as an empty target file; see *Note Empty Target
  289. Files to Record Events: Empty Targets.  (The automatic variable `$?' is
  290. used to print only those files that have changed; see *Note Automatic
  291. Variables: Automatic.)
  292.  
  293.    Wildcard expansion does not happen when you define a variable.
  294. Thus, if you write this:
  295.  
  296.      objects = *.o
  297.  
  298. then the value of the variable `objects' is the actual string `*.o'.
  299. However, if you use the value of `objects' in a target, prerequisite or
  300. command, wildcard expansion will take place at that time.  To set
  301. `objects' to the expansion, instead use:
  302.  
  303.      objects := $(wildcard *.o)
  304.  
  305. *Note Wildcard Function::.
  306.  
  307. 
  308. File: make.info,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
  309.  
  310. Pitfalls of Using Wildcards
  311. ---------------------------
  312.  
  313.    Now here is an example of a naive way of using wildcard expansion,
  314. that does not do what you would intend.  Suppose you would like to say
  315. that the executable file `foo' is made from all the object files in the
  316. directory, and you write this:
  317.  
  318.      objects = *.o
  319.      
  320.      foo : $(objects)
  321.              cc -o foo $(CFLAGS) $(objects)
  322.  
  323. The value of `objects' is the actual string `*.o'.  Wildcard expansion
  324. happens in the rule for `foo', so that each _existing_ `.o' file
  325. becomes a prerequisite of `foo' and will be recompiled if necessary.
  326.  
  327.    But what if you delete all the `.o' files?  When a wildcard matches
  328. no files, it is left as it is, so then `foo' will depend on the
  329. oddly-named file `*.o'.  Since no such file is likely to exist, `make'
  330. will give you an error saying it cannot figure out how to make `*.o'.
  331. This is not what you want!
  332.  
  333.    Actually it is possible to obtain the desired result with wildcard
  334. expansion, but you need more sophisticated techniques, including the
  335. `wildcard' function and string substitution.  *Note The Function
  336. `wildcard': Wildcard Function.
  337.  
  338.    Microsoft operating systems (MS-DOS and MS-Windows) use backslashes
  339. to separate directories in pathnames, like so:
  340.  
  341.        c:\foo\bar\baz.c
  342.  
  343.    This is equivalent to the Unix-style `c:/foo/bar/baz.c' (the `c:'
  344. part is the so-called drive letter).  When `make' runs on these
  345. systems, it supports backslashes as well as the Unix-style forward
  346. slashes in pathnames.  However, this support does _not_ include the
  347. wildcard expansion, where backslash is a quote character.  Therefore,
  348. you _must_ use Unix-style slashes in these cases.
  349.  
  350. 
  351. File: make.info,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildcards
  352.  
  353. The Function `wildcard'
  354. -----------------------
  355.  
  356.    Wildcard expansion happens automatically in rules.  But wildcard
  357. expansion does not normally take place when a variable is set, or
  358. inside the arguments of a function.  If you want to do wildcard
  359. expansion in such places, you need to use the `wildcard' function, like
  360. this:
  361.  
  362.      $(wildcard PATTERN...)
  363.  
  364. This string, used anywhere in a makefile, is replaced by a
  365. space-separated list of names of existing files that match one of the
  366. given file name patterns.  If no existing file name matches a pattern,
  367. then that pattern is omitted from the output of the `wildcard'
  368. function.  Note that this is different from how unmatched wildcards
  369. behave in rules, where they are used verbatim rather than ignored
  370. (*note Wildcard Pitfall::).
  371.  
  372.    One use of the `wildcard' function is to get a list of all the C
  373. source files in a directory, like this:
  374.  
  375.      $(wildcard *.c)
  376.  
  377.    We can change the list of C source files into a list of object files
  378. by replacing the `.c' suffix with `.o' in the result, like this:
  379.  
  380.      $(patsubst %.c,%.o,$(wildcard *.c))
  381.  
  382. (Here we have used another function, `patsubst'.  *Note Functions for
  383. String Substitution and Analysis: Text Functions.)
  384.  
  385.    Thus, a makefile to compile all C source files in the directory and
  386. then link them together could be written as follows:
  387.  
  388.      objects := $(patsubst %.c,%.o,$(wildcard *.c))
  389.      
  390.      foo : $(objects)
  391.              cc -o foo $(objects)
  392.  
  393. (This takes advantage of the implicit rule for compiling C programs, so
  394. there is no need to write explicit rules for compiling the files.
  395. *Note The Two Flavors of Variables: Flavors, for an explanation of
  396. `:=', which is a variant of `='.)
  397.  
  398. 
  399. File: make.info,  Node: Directory Search,  Next: Phony Targets,  Prev: Wildcards,  Up: Rules
  400.  
  401. Searching Directories for Prerequisites
  402. =======================================
  403.  
  404.    For large systems, it is often desirable to put sources in a separate
  405. directory from the binaries.  The "directory search" features of `make'
  406. facilitate this by searching several directories automatically to find
  407. a prerequisite.  When you redistribute the files among directories, you
  408. do not need to change the individual rules, just the search paths.
  409.  
  410. * Menu:
  411.  
  412. * General Search::              Specifying a search path that applies
  413.                                   to every prerequisite.
  414. * Selective Search::            Specifying a search path
  415.                                   for a specified class of names.
  416. * Search Algorithm::            When and how search paths are applied.
  417. * Commands/Search::             How to write shell commands that work together
  418.                                   with search paths.
  419. * Implicit/Search::             How search paths affect implicit rules.
  420. * Libraries/Search::            Directory search for link libraries.
  421.  
  422. 
  423. File: make.info,  Node: General Search,  Next: Selective Search,  Up: Directory Search
  424.  
  425. `VPATH': Search Path for All Prerequisites
  426. ------------------------------------------
  427.  
  428.    The value of the `make' variable `VPATH' specifies a list of
  429. directories that `make' should search.  Most often, the directories are
  430. expected to contain prerequisite files that are not in the current
  431. directory; however, `VPATH' specifies a search list that `make' applies
  432. for all files, including files which are targets of rules.
  433.  
  434.    Thus, if a file that is listed as a target or prerequisite does not
  435. exist in the current directory, `make' searches the directories listed
  436. in `VPATH' for a file with that name.  If a file is found in one of
  437. them, that file may become the prerequisite (see below).  Rules may then
  438. specify the names of files in the prerequisite list as if they all
  439. existed in the current directory.  *Note Writing Shell Commands with
  440. Directory Search: Commands/Search.
  441.  
  442.    In the `VPATH' variable, directory names are separated by colons or
  443. blanks.  The order in which directories are listed is the order followed
  444. by `make' in its search.  (On MS-DOS and MS-Windows, semi-colons are
  445. used as separators of directory names in `VPATH', since the colon can
  446. be used in the pathname itself, after the drive letter.)
  447.  
  448.    For example,
  449.  
  450.      VPATH = src:../headers
  451.  
  452. specifies a path containing two directories, `src' and `../headers',
  453. which `make' searches in that order.
  454.  
  455.    With this value of `VPATH', the following rule,
  456.  
  457.      foo.o : foo.c
  458.  
  459. is interpreted as if it were written like this:
  460.  
  461.      foo.o : src/foo.c
  462.  
  463. assuming the file `foo.c' does not exist in the current directory but
  464. is found in the directory `src'.
  465.  
  466. 
  467. File: make.info,  Node: Selective Search,  Next: Search Algorithm,  Prev: General Search,  Up: Directory Search
  468.  
  469. The `vpath' Directive
  470. ---------------------
  471.  
  472.    Similar to the `VPATH' variable, but more selective, is the `vpath'
  473. directive (note lower case), which allows you to specify a search path
  474. for a particular class of file names: those that match a particular
  475. pattern.  Thus you can supply certain search directories for one class
  476. of file names and other directories (or none) for other file names.
  477.  
  478.    There are three forms of the `vpath' directive:
  479.  
  480. `vpath PATTERN DIRECTORIES'
  481.      Specify the search path DIRECTORIES for file names that match
  482.      PATTERN.
  483.  
  484.      The search path, DIRECTORIES, is a list of directories to be
  485.      searched, separated by colons (semi-colons on MS-DOS and
  486.      MS-Windows) or blanks, just like the search path used in the
  487.      `VPATH' variable.
  488.  
  489. `vpath PATTERN'
  490.      Clear out the search path associated with PATTERN.
  491.  
  492. `vpath'
  493.      Clear all search paths previously specified with `vpath'
  494.      directives.
  495.  
  496.    A `vpath' pattern is a string containing a `%' character.  The
  497. string must match the file name of a prerequisite that is being searched
  498. for, the `%' character matching any sequence of zero or more characters
  499. (as in pattern rules; *note Defining and Redefining Pattern Rules:
  500. Pattern Rules.).  For example, `%.h' matches files that end in `.h'.
  501. (If there is no `%', the pattern must match the prerequisite exactly,
  502. which is not useful very often.)
  503.  
  504.    `%' characters in a `vpath' directive's pattern can be quoted with
  505. preceding backslashes (`\').  Backslashes that would otherwise quote
  506. `%' characters can be quoted with more backslashes.  Backslashes that
  507. quote `%' characters or other backslashes are removed from the pattern
  508. before it is compared to file names.  Backslashes that are not in
  509. danger of quoting `%' characters go unmolested.
  510.  
  511.    When a prerequisite fails to exist in the current directory, if the
  512. PATTERN in a `vpath' directive matches the name of the prerequisite
  513. file, then the DIRECTORIES in that directive are searched just like
  514. (and before) the directories in the `VPATH' variable.
  515.  
  516.    For example,
  517.  
  518.      vpath %.h ../headers
  519.  
  520. tells `make' to look for any prerequisite whose name ends in `.h' in
  521. the directory `../headers' if the file is not found in the current
  522. directory.
  523.  
  524.    If several `vpath' patterns match the prerequisite file's name, then
  525. `make' processes each matching `vpath' directive one by one, searching
  526. all the directories mentioned in each directive.  `make' handles
  527. multiple `vpath' directives in the order in which they appear in the
  528. makefile; multiple directives with the same pattern are independent of
  529. each other.
  530.  
  531.    Thus,
  532.  
  533.      vpath %.c foo
  534.      vpath %   blish
  535.      vpath %.c bar
  536.  
  537. will look for a file ending in `.c' in `foo', then `blish', then `bar',
  538. while
  539.  
  540.      vpath %.c foo:bar
  541.      vpath %   blish
  542.  
  543. will look for a file ending in `.c' in `foo', then `bar', then `blish'.
  544.  
  545. 
  546. File: make.info,  Node: Search Algorithm,  Next: Commands/Search,  Prev: Selective Search,  Up: Directory Search
  547.  
  548. How Directory Searches are Performed
  549. ------------------------------------
  550.  
  551.    When a prerequisite is found through directory search, regardless of
  552. type (general or selective), the pathname located may not be the one
  553. that `make' actually provides you in the prerequisite list.  Sometimes
  554. the path discovered through directory search is thrown away.
  555.  
  556.    The algorithm `make' uses to decide whether to keep or abandon a
  557. path found via directory search is as follows:
  558.  
  559.   1. If a target file does not exist at the path specified in the
  560.      makefile, directory search is performed.
  561.  
  562.   2. If the directory search is successful, that path is kept and this
  563.      file is tentatively stored as the target.
  564.  
  565.   3. All prerequisites of this target are examined using this same
  566.      method.
  567.  
  568.   4. After processing the prerequisites, the target may or may not need
  569.      to be rebuilt:
  570.  
  571.        a. If the target does _not_ need to be rebuilt, the path to the
  572.           file found during directory search is used for any
  573.           prerequisite lists which contain this target.  In short, if
  574.           `make' doesn't need to rebuild the target then you use the
  575.           path found via directory search.
  576.  
  577.        b. If the target _does_ need to be rebuilt (is out-of-date), the
  578.           pathname found during directory search is _thrown away_, and
  579.           the target is rebuilt using the file name specified in the
  580.           makefile.  In short, if `make' must rebuild, then the target
  581.           is rebuilt locally, not in the directory found via directory
  582.           search.
  583.  
  584.    This algorithm may seem complex, but in practice it is quite often
  585. exactly what you want.
  586.  
  587.    Other versions of `make' use a simpler algorithm: if the file does
  588. not exist, and it is found via directory search, then that pathname is
  589. always used whether or not the target needs to be built.  Thus, if the
  590. target is rebuilt it is created at the pathname discovered during
  591. directory search.
  592.  
  593.    If, in fact, this is the behavior you want for some or all of your
  594. directories, you can use the `GPATH' variable to indicate this to
  595. `make'.
  596.  
  597.    `GPATH' has the same syntax and format as `VPATH' (that is, a space-
  598. or colon-delimited list of pathnames).  If an out-of-date target is
  599. found by directory search in a directory that also appears in `GPATH',
  600. then that pathname is not thrown away.  The target is rebuilt using the
  601. expanded path.
  602.  
  603. 
  604. File: make.info,  Node: Commands/Search,  Next: Implicit/Search,  Prev: Search Algorithm,  Up: Directory Search
  605.  
  606. Writing Shell Commands with Directory Search
  607. --------------------------------------------
  608.  
  609.    When a prerequisite is found in another directory through directory
  610. search, this cannot change the commands of the rule; they will execute
  611. as written.  Therefore, you must write the commands with care so that
  612. they will look for the prerequisite in the directory where `make' finds
  613. it.
  614.  
  615.    This is done with the "automatic variables" such as `$^' (*note
  616. Automatic Variables: Automatic.).  For instance, the value of `$^' is a
  617. list of all the prerequisites of the rule, including the names of the
  618. directories in which they were found, and the value of `$@' is the
  619. target.  Thus:
  620.  
  621.      foo.o : foo.c
  622.              cc -c $(CFLAGS) $^ -o $@
  623.  
  624. (The variable `CFLAGS' exists so you can specify flags for C
  625. compilation by implicit rules; we use it here for consistency so it will
  626. affect all C compilations uniformly; *note Variables Used by Implicit
  627. Rules: Implicit Variables..)
  628.  
  629.    Often the prerequisites include header files as well, which you do
  630. not want to mention in the commands.  The automatic variable `$<' is
  631. just the first prerequisite:
  632.  
  633.      VPATH = src:../headers
  634.      foo.o : foo.c defs.h hack.h
  635.              cc -c $(CFLAGS) $< -o $@
  636.  
  637. 
  638. File: make.info,  Node: Implicit/Search,  Next: Libraries/Search,  Prev: Commands/Search,  Up: Directory Search
  639.  
  640. Directory Search and Implicit Rules
  641. -----------------------------------
  642.  
  643.    The search through the directories specified in `VPATH' or with
  644. `vpath' also happens during consideration of implicit rules (*note
  645. Using Implicit Rules: Implicit Rules.).
  646.  
  647.    For example, when a file `foo.o' has no explicit rule, `make'
  648. considers implicit rules, such as the built-in rule to compile `foo.c'
  649. if that file exists.  If such a file is lacking in the current
  650. directory, the appropriate directories are searched for it.  If `foo.c'
  651. exists (or is mentioned in the makefile) in any of the directories, the
  652. implicit rule for C compilation is applied.
  653.  
  654.    The commands of implicit rules normally use automatic variables as a
  655. matter of necessity; consequently they will use the file names found by
  656. directory search with no extra effort.
  657.  
  658. 
  659. File: make.info,  Node: Libraries/Search,  Prev: Implicit/Search,  Up: Directory Search
  660.  
  661. Directory Search for Link Libraries
  662. -----------------------------------
  663.  
  664.    Directory search applies in a special way to libraries used with the
  665. linker.  This special feature comes into play when you write a
  666. prerequisite whose name is of the form `-lNAME'.  (You can tell
  667. something strange is going on here because the prerequisite is normally
  668. the name of a file, and the _file name_ of a library generally looks
  669. like `libNAME.a', not like `-lNAME'.)
  670.  
  671.    When a prerequisite's name has the form `-lNAME', `make' handles it
  672. specially by searching for the file `libNAME.so' in the current
  673. directory, in directories specified by matching `vpath' search paths
  674. and the `VPATH' search path, and then in the directories `/lib',
  675. `/usr/lib', and `PREFIX/lib' (normally `/usr/local/lib', but
  676. MS-DOS/MS-Windows versions of `make' behave as if PREFIX is defined to
  677. be the root of the DJGPP installation tree).
  678.  
  679.    If that file is not found, then the file `libNAME.a' is searched
  680. for, in the same directories as above.
  681.  
  682.    For example, if there is a `/usr/lib/libcurses.a' library on your
  683. system (and no `/usr/lib/libcurses.so' file), then
  684.  
  685.      foo : foo.c -lcurses
  686.              cc $^ -o $@
  687.  
  688. would cause the command `cc foo.c /usr/lib/libcurses.a -o foo' to be
  689. executed when `foo' is older than `foo.c' or than
  690. `/usr/lib/libcurses.a'.
  691.  
  692.    Although the default set of files to be searched for is `libNAME.so'
  693. and `libNAME.a', this is customizable via the `.LIBPATTERNS' variable.
  694. Each word in the value of this variable is a pattern string.  When a
  695. prerequisite like `-lNAME' is seen, `make' will replace the percent in
  696. each pattern in the list with NAME and perform the above directory
  697. searches using that library filename.  If no library is found, the next
  698. word in the list will be used.
  699.  
  700.    The default value for `.LIBPATTERNS' is "`lib%.so lib%.a'", which
  701. provides the default behavior described above.
  702.  
  703.    You can turn off link library expansion completely by setting this
  704. variable to an empty value.
  705.  
  706. 
  707. File: make.info,  Node: Phony Targets,  Next: Force Targets,  Prev: Directory Search,  Up: Rules
  708.  
  709. Phony Targets
  710. =============
  711.  
  712.    A phony target is one that is not really the name of a file.  It is
  713. just a name for some commands to be executed when you make an explicit
  714. request.  There are two reasons to use a phony target: to avoid a
  715. conflict with a file of the same name, and to improve performance.
  716.  
  717.    If you write a rule whose commands will not create the target file,
  718. the commands will be executed every time the target comes up for
  719. remaking.  Here is an example:
  720.  
  721.      clean:
  722.              rm *.o temp
  723.  
  724. Because the `rm' command does not create a file named `clean', probably
  725. no such file will ever exist.  Therefore, the `rm' command will be
  726. executed every time you say `make clean'.
  727.  
  728.    The phony target will cease to work if anything ever does create a
  729. file named `clean' in this directory.  Since it has no prerequisites,
  730. the file `clean' would inevitably be considered up to date, and its
  731. commands would not be executed.  To avoid this problem, you can
  732. explicitly declare the target to be phony, using the special target
  733. `.PHONY' (*note Special Built-in Target Names: Special Targets.) as
  734. follows:
  735.  
  736.      .PHONY : clean
  737.  
  738. Once this is done, `make clean' will run the commands regardless of
  739. whether there is a file named `clean'.
  740.  
  741.    Since it knows that phony targets do not name actual files that
  742. could be remade from other files, `make' skips the implicit rule search
  743. for phony targets (*note Implicit Rules::).  This is why declaring a
  744. target phony is good for performance, even if you are not worried about
  745. the actual file existing.
  746.  
  747.    Thus, you first write the line that states that `clean' is a phony
  748. target, then you write the rule, like this:
  749.  
  750.      .PHONY: clean
  751.      clean:
  752.              rm *.o temp
  753.  
  754.    Another example of the usefulness of phony targets is in conjunction
  755. with recursive invocations of `make'.  In this case the makefile will
  756. often contain a variable which lists a number of subdirectories to be
  757. built.  One way to handle this is with one rule whose command is a
  758. shell loop over the subdirectories, like this:
  759.  
  760.      SUBDIRS = foo bar baz
  761.      
  762.      subdirs:
  763.              for dir in $(SUBDIRS); do \
  764.                $(MAKE) -C $$dir; \
  765.              done
  766.  
  767.    There are a few of problems with this method, however.  First, any
  768. error detected in a submake is not noted by this rule, so it will
  769. continue to build the rest of the directories even when one fails.
  770. This can be overcome by adding shell commands to note the error and
  771. exit, but then it will do so even if `make' is invoked with the `-k'
  772. option, which is unfortunate.  Second, and perhaps more importantly,
  773. you cannot take advantage of the parallel build capabilities of make
  774. using this method, since there is only one rule.
  775.  
  776.    By declaring the subdirectories as phony targets (you must do this as
  777. the subdirectory obviously always exists; otherwise it won't be built)
  778. you can remove these problems:
  779.  
  780.      SUBDIRS = foo bar baz
  781.      
  782.      .PHONY: subdirs $(SUBDIRS)
  783.      
  784.      subdirs: $(SUBDIRS)
  785.      
  786.      $(SUBDIRS):
  787.              $(MAKE) -C $ 
  788.      foo: baz
  789.  
  790.    Here we've also declared that the `foo' subdirectory cannot be built
  791. until after the `baz' subdirectory is complete; this kind of
  792. relationship declaration is particularly important when attempting
  793. parallel builds.
  794.  
  795.    A phony target should not be a prerequisite of a real target file;
  796. if it is, its commands are run every time `make' goes to update that
  797. file.  As long as a phony target is never a prerequisite of a real
  798. target, the phony target commands will be executed only when the phony
  799. target is a specified goal (*note Arguments to Specify the Goals:
  800. Goals.).
  801.  
  802.    Phony targets can have prerequisites.  When one directory contains
  803. multiple programs, it is most convenient to describe all of the
  804. programs in one makefile `./Makefile'.  Since the target remade by
  805. default will be the first one in the makefile, it is common to make
  806. this a phony target named `all' and give it, as prerequisites, all the
  807. individual programs.  For example:
  808.  
  809.      all : prog1 prog2 prog3
  810.      .PHONY : all
  811.      
  812.      prog1 : prog1.o utils.o
  813.              cc -o prog1 prog1.o utils.o
  814.      
  815.      prog2 : prog2.o
  816.              cc -o prog2 prog2.o
  817.      
  818.      prog3 : prog3.o sort.o utils.o
  819.              cc -o prog3 prog3.o sort.o utils.o
  820.  
  821. Now you can say just `make' to remake all three programs, or specify as
  822. arguments the ones to remake (as in `make prog1 prog3').
  823.  
  824.    When one phony target is a prerequisite of another, it serves as a
  825. subroutine of the other.  For example, here `make cleanall' will delete
  826. the object files, the difference files, and the file `program':
  827.  
  828.      .PHONY: cleanall cleanobj cleandiff
  829.      
  830.      cleanall : cleanobj cleandiff
  831.              rm program
  832.      
  833.      cleanobj :
  834.              rm *.o
  835.      
  836.      cleandiff :
  837.              rm *.diff
  838.  
  839. 
  840. File: make.info,  Node: Force Targets,  Next: Empty Targets,  Prev: Phony Targets,  Up: Rules
  841.  
  842. Rules without Commands or Prerequisites
  843. =======================================
  844.  
  845.    If a rule has no prerequisites or commands, and the target of the
  846. rule is a nonexistent file, then `make' imagines this target to have
  847. been updated whenever its rule is run.  This implies that all targets
  848. depending on this one will always have their commands run.
  849.  
  850.    An example will illustrate this:
  851.  
  852.      clean: FORCE
  853.              rm $(objects)
  854.      FORCE:
  855.  
  856.    Here the target `FORCE' satisfies the special conditions, so the
  857. target `clean' that depends on it is forced to run its commands.  There
  858. is nothing special about the name `FORCE', but that is one name
  859. commonly used this way.
  860.  
  861.    As you can see, using `FORCE' this way has the same results as using
  862. `.PHONY: clean'.
  863.  
  864.    Using `.PHONY' is more explicit and more efficient.  However, other
  865. versions of `make' do not support `.PHONY'; thus `FORCE' appears in
  866. many makefiles.  *Note Phony Targets::.
  867.  
  868. 
  869. File: make.info,  Node: Empty Targets,  Next: Special Targets,  Prev: Force Targets,  Up: Rules
  870.  
  871. Empty Target Files to Record Events
  872. ===================================
  873.  
  874.    The "empty target" is a variant of the phony target; it is used to
  875. hold commands for an action that you request explicitly from time to
  876. time.  Unlike a phony target, this target file can really exist; but
  877. the file's contents do not matter, and usually are empty.
  878.  
  879.    The purpose of the empty target file is to record, with its
  880. last-modification time, when the rule's commands were last executed.  It
  881. does so because one of the commands is a `touch' command to update the
  882. target file.
  883.  
  884.    The empty target file should have some prerequisites (otherwise it
  885. doesn't make sense).  When you ask to remake the empty target, the
  886. commands are executed if any prerequisite is more recent than the
  887. target; in other words, if a prerequisite has changed since the last
  888. time you remade the target.  Here is an example:
  889.  
  890.      print: foo.c bar.c
  891.              lpr -p $?
  892.              touch print
  893.  
  894. With this rule, `make print' will execute the `lpr' command if either
  895. source file has changed since the last `make print'.  The automatic
  896. variable `$?' is used to print only those files that have changed
  897. (*note Automatic Variables: Automatic.).
  898.  
  899. 
  900. File: make.info,  Node: Special Targets,  Next: Multiple Targets,  Prev: Empty Targets,  Up: Rules
  901.  
  902. Special Built-in Target Names
  903. =============================
  904.  
  905.    Certain names have special meanings if they appear as targets.
  906.  
  907. `.PHONY'
  908.      The prerequisites of the special target `.PHONY' are considered to
  909.      be phony targets.  When it is time to consider such a target,
  910.      `make' will run its commands unconditionally, regardless of
  911.      whether a file with that name exists or what its last-modification
  912.      time is.  *Note Phony Targets: Phony Targets.
  913.  
  914. `.SUFFIXES'
  915.      The prerequisites of the special target `.SUFFIXES' are the list
  916.      of suffixes to be used in checking for suffix rules.  *Note
  917.      Old-Fashioned Suffix Rules: Suffix Rules.
  918.  
  919. `.DEFAULT'
  920.      The commands specified for `.DEFAULT' are used for any target for
  921.      which no rules are found (either explicit rules or implicit rules).
  922.      *Note Last Resort::.  If `.DEFAULT' commands are specified, every
  923.      file mentioned as a prerequisite, but not as a target in a rule,
  924.      will have these commands executed on its behalf.  *Note Implicit
  925.      Rule Search Algorithm: Implicit Rule Search.
  926.  
  927. `.PRECIOUS'
  928.      The targets which `.PRECIOUS' depends on are given the following
  929.      special treatment: if `make' is killed or interrupted during the
  930.      execution of their commands, the target is not deleted.  *Note
  931.      Interrupting or Killing `make': Interrupts.  Also, if the target
  932.      is an intermediate file, it will not be deleted after it is no
  933.      longer needed, as is normally done.  *Note Chains of Implicit
  934.      Rules: Chained Rules.  In this latter respect it overlaps with the
  935.      `.SECONDARY' special target.
  936.  
  937.      You can also list the target pattern of an implicit rule (such as
  938.      `%.o') as a prerequisite file of the special target `.PRECIOUS' to
  939.      preserve intermediate files created by rules whose target patterns
  940.      match that file's name.
  941.  
  942. `.INTERMEDIATE'
  943.      The targets which `.INTERMEDIATE' depends on are treated as
  944.      intermediate files.  *Note Chains of Implicit Rules: Chained Rules.
  945.      `.INTERMEDIATE' with no prerequisites has no effect.
  946.  
  947. `.SECONDARY'
  948.      The targets which `.SECONDARY' depends on are treated as
  949.      intermediate files, except that they are never automatically
  950.      deleted.  *Note Chains of Implicit Rules: Chained Rules.
  951.  
  952.      `.SECONDARY' with no prerequisites causes all targets to be treated
  953.      as secondary (i.e., no target is removed because it is considered
  954.      intermediate).
  955.  
  956. `.DELETE_ON_ERROR'
  957.      If `.DELETE_ON_ERROR' is mentioned as a target anywhere in the
  958.      makefile, then `make' will delete the target of a rule if it has
  959.      changed and its commands exit with a nonzero exit status, just as
  960.      it does when it receives a signal.  *Note Errors in Commands:
  961.      Errors.
  962.  
  963. `.IGNORE'
  964.      If you specify prerequisites for `.IGNORE', then `make' will
  965.      ignore errors in execution of the commands run for those particular
  966.      files.  The commands for `.IGNORE' are not meaningful.
  967.  
  968.      If mentioned as a target with no prerequisites, `.IGNORE' says to
  969.      ignore errors in execution of commands for all files.  This usage
  970.      of `.IGNORE' is supported only for historical compatibility.  Since
  971.      this affects every command in the makefile, it is not very useful;
  972.      we recommend you use the more selective ways to ignore errors in
  973.      specific commands.  *Note Errors in Commands: Errors.
  974.  
  975. `.SILENT'
  976.      If you specify prerequisites for `.SILENT', then `make' will not
  977.      print the commands to remake those particular files before
  978.      executing them.  The commands for `.SILENT' are not meaningful.
  979.  
  980.      If mentioned as a target with no prerequisites, `.SILENT' says not
  981.      to print any commands before executing them.  This usage of
  982.      `.SILENT' is supported only for historical compatibility.  We
  983.      recommend you use the more selective ways to silence specific
  984.      commands.  *Note Command Echoing: Echoing.  If you want to silence
  985.      all commands for a particular run of `make', use the `-s' or
  986.      `--silent' option (*note Options Summary::).
  987.  
  988. `.EXPORT_ALL_VARIABLES'
  989.      Simply by being mentioned as a target, this tells `make' to export
  990.      all variables to child processes by default.  *Note Communicating
  991.      Variables to a Sub-`make': Variables/Recursion.
  992.  
  993. `.NOTPARALLEL'
  994.      If `.NOTPARALLEL' is mentioned as a target, then this invocation of
  995.      `make' will be run serially, even if the `-j' option is given.
  996.      Any recursively invoked `make' command will still be run in
  997.      parallel (unless its makefile contains this target).  Any
  998.      prerequisites on this target are ignored.
  999.  
  1000.    Any defined implicit rule suffix also counts as a special target if
  1001. it appears as a target, and so does the concatenation of two suffixes,
  1002. such as `.c.o'.  These targets are suffix rules, an obsolete way of
  1003. defining implicit rules (but a way still widely used).  In principle,
  1004. any target name could be special in this way if you break it in two and
  1005. add both pieces to the suffix list.  In practice, suffixes normally
  1006. begin with `.', so these special target names also begin with `.'.
  1007. *Note Old-Fashioned Suffix Rules: Suffix Rules.
  1008.  
  1009. 
  1010. File: make.info,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
  1011.  
  1012. Multiple Targets in a Rule
  1013. ==========================
  1014.  
  1015.    A rule with multiple targets is equivalent to writing many rules,
  1016. each with one target, and all identical aside from that.  The same
  1017. commands apply to all the targets, but their effects may vary because
  1018. you can substitute the actual target name into the command using `$@'.
  1019. The rule contributes the same prerequisites to all the targets also.
  1020.  
  1021.    This is useful in two cases.
  1022.  
  1023.    * You want just prerequisites, no commands.  For example:
  1024.  
  1025.           kbd.o command.o files.o: command.h
  1026.  
  1027.      gives an additional prerequisite to each of the three object files
  1028.      mentioned.
  1029.  
  1030.    * Similar commands work for all the targets.  The commands do not
  1031.      need to be absolutely identical, since the automatic variable `$@'
  1032.      can be used to substitute the particular target to be remade into
  1033.      the commands (*note Automatic Variables: Automatic.).  For example:
  1034.  
  1035.           bigoutput littleoutput : text.g
  1036.                   generate text.g -$(subst output,,$@) > $@
  1037.  
  1038.      is equivalent to
  1039.  
  1040.           bigoutput : text.g
  1041.                   generate text.g -big > bigoutput
  1042.           littleoutput : text.g
  1043.                   generate text.g -little > littleoutput
  1044.  
  1045.      Here we assume the hypothetical program `generate' makes two types
  1046.      of output, one if given `-big' and one if given `-little'.  *Note
  1047.      Functions for String Substitution and Analysis: Text Functions,
  1048.      for an explanation of the `subst' function.
  1049.  
  1050.    Suppose you would like to vary the prerequisites according to the
  1051. target, much as the variable `$@' allows you to vary the commands.  You
  1052. cannot do this with multiple targets in an ordinary rule, but you can
  1053. do it with a "static pattern rule".  *Note Static Pattern Rules: Static
  1054. Pattern.
  1055.  
  1056. 
  1057. File: make.info,  Node: Multiple Rules,  Next: Static Pattern,  Prev: Multiple Targets,  Up: Rules
  1058.  
  1059. Multiple Rules for One Target
  1060. =============================
  1061.  
  1062.    One file can be the target of several rules.  All the prerequisites
  1063. mentioned in all the rules are merged into one list of prerequisites for
  1064. the target.  If the target is older than any prerequisite from any rule,
  1065. the commands are executed.
  1066.  
  1067.    There can only be one set of commands to be executed for a file.  If
  1068. more than one rule gives commands for the same file, `make' uses the
  1069. last set given and prints an error message.  (As a special case, if the
  1070. file's name begins with a dot, no error message is printed.  This odd
  1071. behavior is only for compatibility with other implementations of
  1072. `make'.)  There is no reason to write your makefiles this way; that is
  1073. why `make' gives you an error message.
  1074.  
  1075.    An extra rule with just prerequisites can be used to give a few extra
  1076. prerequisites to many files at once.  For example, one usually has a
  1077. variable named `objects' containing a list of all the compiler output
  1078. files in the system being made.  An easy way to say that all of them
  1079. must be recompiled if `config.h' changes is to write the following:
  1080.  
  1081.      objects = foo.o bar.o
  1082.      foo.o : defs.h
  1083.      bar.o : defs.h test.h
  1084.      $(objects) : config.h
  1085.  
  1086.    This could be inserted or taken out without changing the rules that
  1087. really specify how to make the object files, making it a convenient
  1088. form to use if you wish to add the additional prerequisite
  1089. intermittently.
  1090.  
  1091.    Another wrinkle is that the additional prerequisites could be
  1092. specified with a variable that you set with a command argument to `make'
  1093. (*note Overriding Variables: Overriding.).  For example,
  1094.  
  1095.      extradeps=
  1096.      $(objects) : $(extradeps)
  1097.  
  1098. means that the command `make extradeps=foo.h' will consider `foo.h' as
  1099. a prerequisite of each object file, but plain `make' will not.
  1100.  
  1101.    If none of the explicit rules for a target has commands, then `make'
  1102. searches for an applicable implicit rule to find some commands *note
  1103. Using Implicit Rules: Implicit Rules.).
  1104.  
  1105. 
  1106. File: make.info,  Node: Static Pattern,  Next: Double-Colon,  Prev: Multiple Rules,  Up: Rules
  1107.  
  1108. Static Pattern Rules
  1109. ====================
  1110.  
  1111.    "Static pattern rules" are rules which specify multiple targets and
  1112. construct the prerequisite names for each target based on the target
  1113. name.  They are more general than ordinary rules with multiple targets
  1114. because the targets do not have to have identical prerequisites.  Their
  1115. prerequisites must be _analogous_, but not necessarily _identical_.
  1116.  
  1117. * Menu:
  1118.  
  1119. * Static Usage::                The syntax of static pattern rules.
  1120. * Static versus Implicit::      When are they better than implicit rules?
  1121.  
  1122. 
  1123. File: make.info,  Node: Static Usage,  Next: Static versus Implicit,  Up: Static Pattern
  1124.  
  1125. Syntax of Static Pattern Rules
  1126. ------------------------------
  1127.  
  1128.    Here is the syntax of a static pattern rule:
  1129.  
  1130.      TARGETS ...: TARGET-PATTERN: DEP-PATTERNS ...
  1131.              COMMANDS
  1132.              ...
  1133.  
  1134. The TARGETS list specifies the targets that the rule applies to.  The
  1135. targets can contain wildcard characters, just like the targets of
  1136. ordinary rules (*note Using Wildcard Characters in File Names:
  1137. Wildcards.).
  1138.  
  1139.    The TARGET-PATTERN and DEP-PATTERNS say how to compute the
  1140. prerequisites of each target.  Each target is matched against the
  1141. TARGET-PATTERN to extract a part of the target name, called the "stem".
  1142. This stem is substituted into each of the DEP-PATTERNS to make the
  1143. prerequisite names (one from each DEP-PATTERN).
  1144.  
  1145.    Each pattern normally contains the character `%' just once.  When the
  1146. TARGET-PATTERN matches a target, the `%' can match any part of the
  1147. target name; this part is called the "stem".  The rest of the pattern
  1148. must match exactly.  For example, the target `foo.o' matches the
  1149. pattern `%.o', with `foo' as the stem.  The targets `foo.c' and
  1150. `foo.out' do not match that pattern.
  1151.  
  1152.    The prerequisite names for each target are made by substituting the
  1153. stem for the `%' in each prerequisite pattern.  For example, if one
  1154. prerequisite pattern is `%.c', then substitution of the stem `foo'
  1155. gives the prerequisite name `foo.c'.  It is legitimate to write a
  1156. prerequisite pattern that does not contain `%'; then this prerequisite
  1157. is the same for all targets.
  1158.  
  1159.    `%' characters in pattern rules can be quoted with preceding
  1160. backslashes (`\').  Backslashes that would otherwise quote `%'
  1161. characters can be quoted with more backslashes.  Backslashes that quote
  1162. `%' characters or other backslashes are removed from the pattern before
  1163. it is compared to file names or has a stem substituted into it.
  1164. Backslashes that are not in danger of quoting `%' characters go
  1165. unmolested.  For example, the pattern `the\%weird\\%pattern\\' has
  1166. `the%weird\' preceding the operative `%' character, and `pattern\\'
  1167. following it.  The final two backslashes are left alone because they
  1168. cannot affect any `%' character.
  1169.  
  1170.    Here is an example, which compiles each of `foo.o' and `bar.o' from
  1171. the corresponding `.c' file:
  1172.  
  1173.      objects = foo.o bar.o
  1174.      
  1175.      all: $(objects)
  1176.      
  1177.      $(objects): %.o: %.c
  1178.              $(CC) -c $(CFLAGS) $< -o $@
  1179.  
  1180. Here `$<' is the automatic variable that holds the name of the
  1181. prerequisite and `$@' is the automatic variable that holds the name of
  1182. the target; see *Note Automatic Variables: Automatic.
  1183.  
  1184.    Each target specified must match the target pattern; a warning is
  1185. issued for each target that does not.  If you have a list of files,
  1186. only some of which will match the pattern, you can use the `filter'
  1187. function to remove nonmatching file names (*note Functions for String
  1188. Substitution and Analysis: Text Functions.):
  1189.  
  1190.      files = foo.elc bar.o lose.o
  1191.      
  1192.      $(filter %.o,$(files)): %.o: %.c
  1193.              $(CC) -c $(CFLAGS) $< -o $@
  1194.      $(filter %.elc,$(files)): %.elc: %.el
  1195.              emacs -f batch-byte-compile $<
  1196.  
  1197. In this example the result of `$(filter %.o,$(files))' is `bar.o
  1198. lose.o', and the first static pattern rule causes each of these object
  1199. files to be updated by compiling the corresponding C source file.  The
  1200. result of `$(filter %.elc,$(files))' is `foo.elc', so that file is made
  1201. from `foo.el'.
  1202.  
  1203.    Another example shows how to use `$*' in static pattern rules:
  1204.  
  1205.      bigoutput littleoutput : %output : text.g
  1206.              generate text.g -$* > $@
  1207.  
  1208. When the `generate' command is run, `$*' will expand to the stem,
  1209. either `big' or `little'.
  1210.  
  1211. 
  1212. File: make.info,  Node: Static versus Implicit,  Prev: Static Usage,  Up: Static Pattern
  1213.  
  1214. Static Pattern Rules versus Implicit Rules
  1215. ------------------------------------------
  1216.  
  1217.    A static pattern rule has much in common with an implicit rule
  1218. defined as a pattern rule (*note Defining and Redefining Pattern Rules:
  1219. Pattern Rules.).  Both have a pattern for the target and patterns for
  1220. constructing the names of prerequisites.  The difference is in how
  1221. `make' decides _when_ the rule applies.
  1222.  
  1223.    An implicit rule _can_ apply to any target that matches its pattern,
  1224. but it _does_ apply only when the target has no commands otherwise
  1225. specified, and only when the prerequisites can be found.  If more than
  1226. one implicit rule appears applicable, only one applies; the choice
  1227. depends on the order of rules.
  1228.  
  1229.    By contrast, a static pattern rule applies to the precise list of
  1230. targets that you specify in the rule.  It cannot apply to any other
  1231. target and it invariably does apply to each of the targets specified.
  1232. If two conflicting rules apply, and both have commands, that's an error.
  1233.  
  1234.    The static pattern rule can be better than an implicit rule for these
  1235. reasons:
  1236.  
  1237.    * You may wish to override the usual implicit rule for a few files
  1238.      whose names cannot be categorized syntactically but can be given
  1239.      in an explicit list.
  1240.  
  1241.    * If you cannot be sure of the precise contents of the directories
  1242.      you are using, you may not be sure which other irrelevant files
  1243.      might lead `make' to use the wrong implicit rule.  The choice
  1244.      might depend on the order in which the implicit rule search is
  1245.      done.  With static pattern rules, there is no uncertainty: each
  1246.      rule applies to precisely the targets specified.
  1247.  
  1248.