home *** CD-ROM | disk | FTP | other *** search
/ Openstep 4.2 (Developer) / Openstep Developer 4.2.iso / NextDeveloper / Source / GNU / make / make-3.74 / make.info-4 < prev    next >
Encoding:
GNU Info File  |  1995-08-01  |  49.3 KB  |  1,297 lines

  1. This is Info file make.info, produced by Makeinfo-1.55 from the input
  2. file ./make.texinfo.
  3.  
  4.    This file documents the GNU Make utility, which determines
  5. automatically which pieces of a large program need to be recompiled,
  6. and issues the commands to recompile them.
  7.  
  8.    This is Edition 0.48, last updated 4 April 1995, of `The GNU Make
  9. Manual', for `make', Version 3.73 Beta.
  10.  
  11.    Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95     Free
  12. Software Foundation, Inc.
  13.  
  14.    Permission is granted to make and distribute verbatim copies of this
  15. manual provided the copyright notice and this permission notice are
  16. preserved on all copies.
  17.  
  18.    Permission is granted to copy and distribute modified versions of
  19. this manual under the conditions for verbatim copying, provided that
  20. the entire resulting derived work is distributed under the terms of a
  21. permission notice identical to this one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that this permission notice may be stated in a
  26. translation approved by the Free Software Foundation.
  27.  
  28. 
  29. File: make.info,  Node: Override Directive,  Next: Defining,  Prev: Appending,  Up: Using Variables
  30.  
  31. The `override' Directive
  32. ========================
  33.  
  34.    If a variable has been set with a command argument (*note Overriding
  35. Variables: Overriding.), then ordinary assignments in the makefile are
  36. ignored.  If you want to set the variable in the makefile even though
  37. it was set with a command argument, you can use an `override'
  38. directive, which is a line that looks like this:
  39.  
  40.      override VARIABLE = VALUE
  41.  
  42. or
  43.  
  44.      override VARIABLE := VALUE
  45.  
  46.    To append more text to a variable defined on the command line, use:
  47.  
  48.      override VARIABLE += MORE TEXT
  49.  
  50. *Note Appending More Text to Variables: Appending.
  51.  
  52.    The `override' directive was not invented for escalation in the war
  53. between makefiles and command arguments.  It was invented so you can
  54. alter and add to values that the user specifies with command arguments.
  55.  
  56.    For example, suppose you always want the `-g' switch when you run the
  57. C compiler, but you would like to allow the user to specify the other
  58. switches with a command argument just as usual.  You could use this
  59. `override' directive:
  60.  
  61.      override CFLAGS += -g
  62.  
  63.    You can also use `override' directives with `define' directives.
  64. This is done as you might expect:
  65.  
  66.      override define foo
  67.      bar
  68.      endef
  69.  
  70. *Note Defining Variables Verbatim: Defining.
  71.  
  72. 
  73. File: make.info,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Using Variables
  74.  
  75. Defining Variables Verbatim
  76. ===========================
  77.  
  78. Another way to set the value of a variable is to use the `define'
  79. directive.  This directive has an unusual syntax which allows newline
  80. characters to be included in the value, which is convenient for defining
  81. canned sequences of commands (*note Defining Canned Command Sequences:
  82. Sequences.).
  83.  
  84.    The `define' directive is followed on the same line by the name of
  85. the variable and nothing more.  The value to give the variable appears
  86. on the following lines.  The end of the value is marked by a line
  87. containing just the word `endef'.  Aside from this difference in
  88. syntax, `define' works just like `=': it creates a recursively-expanded
  89. variable (*note The Two Flavors of Variables: Flavors.).  The variable
  90. name may contain function and variable references, which are expanded
  91. when the directive is read to find the actual variable name to use.
  92.  
  93.      define two-lines
  94.      echo foo
  95.      echo $(bar)
  96.      endef
  97.  
  98.    The value in an ordinary assignment cannot contain a newline; but the
  99. newlines that separate the lines of the value in a `define' become part
  100. of the variable's value (except for the final newline which precedes
  101. the `endef' and is not considered part of the value).
  102.  
  103.    The previous example is functionally equivalent to this:
  104.  
  105.      two-lines = echo foo; echo $(bar)
  106.  
  107. since two commands separated by semicolon behave much like two separate
  108. shell commands.  However, note that using two separate lines means
  109. `make' will invoke the shell twice, running an independent subshell for
  110. each line.  *Note Command Execution: Execution.
  111.  
  112.    If you want variable definitions made with `define' to take
  113. precedence over command-line variable definitions, you can use the
  114. `override' directive together with `define':
  115.  
  116.      override define two-lines
  117.      foo
  118.      $(bar)
  119.      endef
  120.  
  121. *Note The `override' Directive: Override Directive.
  122.  
  123. 
  124. File: make.info,  Node: Environment,  Prev: Defining,  Up: Using Variables
  125.  
  126. Variables from the Environment
  127. ==============================
  128.  
  129.    Variables in `make' can come from the environment in which `make' is
  130. run.  Every environment variable that `make' sees when it starts up is
  131. transformed into a `make' variable with the same name and value.  But
  132. an explicit assignment in the makefile, or with a command argument,
  133. overrides the environment.  (If the `-e' flag is specified, then values
  134. from the environment override assignments in the makefile.  *Note
  135. Summary of Options: Options Summary.  But this is not recommended
  136. practice.)
  137.  
  138.    Thus, by setting the variable `CFLAGS' in your environment, you can
  139. cause all C compilations in most makefiles to use the compiler switches
  140. you prefer.  This is safe for variables with standard or conventional
  141. meanings because you know that no makefile will use them for other
  142. things.  (But this is not totally reliable; some makefiles set `CFLAGS'
  143. explicitly and therefore are not affected by the value in the
  144. environment.)
  145.  
  146.    When `make' is invoked recursively, variables defined in the outer
  147. invocation can be passed to inner invocations through the environment
  148. (*note Recursive Use of `make': Recursion.).  By default, only
  149. variables that came from the environment or the command line are passed
  150. to recursive invocations.  You can use the `export' directive to pass
  151. other variables.  *Note Communicating Variables to a Sub-`make':
  152. Variables/Recursion, for full details.
  153.  
  154.    Other use of variables from the environment is not recommended.  It
  155. is not wise for makefiles to depend for their functioning on
  156. environment variables set up outside their control, since this would
  157. cause different users to get different results from the same makefile.
  158. This is against the whole purpose of most makefiles.
  159.  
  160.    Such problems would be especially likely with the variable `SHELL',
  161. which is normally present in the environment to specify the user's
  162. choice of interactive shell.  It would be very undesirable for this
  163. choice to affect `make'.  So `make' ignores the environment value of
  164. `SHELL'.
  165.  
  166. 
  167. File: make.info,  Node: Conditionals,  Next: Functions,  Prev: Using Variables,  Up: Top
  168.  
  169. Conditional Parts of Makefiles
  170. ******************************
  171.  
  172.    A "conditional" causes part of a makefile to be obeyed or ignored
  173. depending on the values of variables.  Conditionals can compare the
  174. value of one variable to another, or the value of a variable to a
  175. constant string.  Conditionals control what `make' actually "sees" in
  176. the makefile, so they *cannot* be used to control shell commands at the
  177. time of execution.
  178.  
  179. * Menu:
  180.  
  181. * Conditional Example::         Example of a conditional
  182. * Conditional Syntax::          The syntax of conditionals.
  183. * Testing Flags::               Conditionals that test flags.
  184.  
  185. 
  186. File: make.info,  Node: Conditional Example,  Next: Conditional Syntax,  Up: Conditionals
  187.  
  188. Example of a Conditional
  189. ========================
  190.  
  191.    The following example of a conditional tells `make' to use one set
  192. of libraries if the `CC' variable is `gcc', and a different set of
  193. libraries otherwise.  It works by controlling which of two command
  194. lines will be used as the command for a rule.  The result is that
  195. `CC=gcc' as an argument to `make' changes not only which compiler is
  196. used but also which libraries are linked.
  197.  
  198.      libs_for_gcc = -lgnu
  199.      normal_libs =
  200.      
  201.      foo: $(objects)
  202.      ifeq ($(CC),gcc)
  203.              $(CC) -o foo $(objects) $(libs_for_gcc)
  204.      else
  205.              $(CC) -o foo $(objects) $(normal_libs)
  206.      endif
  207.  
  208.    This conditional uses three directives: one `ifeq', one `else' and
  209. one `endif'.
  210.  
  211.    The `ifeq' directive begins the conditional, and specifies the
  212. condition.  It contains two arguments, separated by a comma and
  213. surrounded by parentheses.  Variable substitution is performed on both
  214. arguments and then they are compared.  The lines of the makefile
  215. following the `ifeq' are obeyed if the two arguments match; otherwise
  216. they are ignored.
  217.  
  218.    The `else' directive causes the following lines to be obeyed if the
  219. previous conditional failed.  In the example above, this means that the
  220. second alternative linking command is used whenever the first
  221. alternative is not used.  It is optional to have an `else' in a
  222. conditional.
  223.  
  224.    The `endif' directive ends the conditional.  Every conditional must
  225. end with an `endif'.  Unconditional makefile text follows.
  226.  
  227.    As this example illustrates, conditionals work at the textual level:
  228. the lines of the conditional are treated as part of the makefile, or
  229. ignored, according to the condition.  This is why the larger syntactic
  230. units of the makefile, such as rules, may cross the beginning or the
  231. end of the conditional.
  232.  
  233.    When the variable `CC' has the value `gcc', the above example has
  234. this effect:
  235.  
  236.      foo: $(objects)
  237.              $(CC) -o foo $(objects) $(libs_for_gcc)
  238.  
  239. When the variable `CC' has any other value, the effect is this:
  240.  
  241.      foo: $(objects)
  242.              $(CC) -o foo $(objects) $(normal_libs)
  243.  
  244.    Equivalent results can be obtained in another way by
  245. conditionalizing a variable assignment and then using the variable
  246. unconditionally:
  247.  
  248.      libs_for_gcc = -lgnu
  249.      normal_libs =
  250.      
  251.      ifeq ($(CC),gcc)
  252.        libs=$(libs_for_gcc)
  253.      else
  254.        libs=$(normal_libs)
  255.      endif
  256.      
  257.      foo: $(objects)
  258.              $(CC) -o foo $(objects) $(libs)
  259.  
  260. 
  261. File: make.info,  Node: Conditional Syntax,  Next: Testing Flags,  Prev: Conditional Example,  Up: Conditionals
  262.  
  263. Syntax of Conditionals
  264. ======================
  265.  
  266.    The syntax of a simple conditional with no `else' is as follows:
  267.  
  268.      CONDITIONAL-DIRECTIVE
  269.      TEXT-IF-TRUE
  270.      endif
  271.  
  272. The TEXT-IF-TRUE may be any lines of text, to be considered as part of
  273. the makefile if the condition is true.  If the condition is false, no
  274. text is used instead.
  275.  
  276.    The syntax of a complex conditional is as follows:
  277.  
  278.      CONDITIONAL-DIRECTIVE
  279.      TEXT-IF-TRUE
  280.      else
  281.      TEXT-IF-FALSE
  282.      endif
  283.  
  284. If the condition is true, TEXT-IF-TRUE is used; otherwise,
  285. TEXT-IF-FALSE is used instead.  The TEXT-IF-FALSE can be any number of
  286. lines of text.
  287.  
  288.    The syntax of the CONDITIONAL-DIRECTIVE is the same whether the
  289. conditional is simple or complex.  There are four different directives
  290. that test different conditions.  Here is a table of them:
  291.  
  292. `ifeq (ARG1, ARG2)'
  293. `ifeq 'ARG1' 'ARG2''
  294. `ifeq "ARG1" "ARG2"'
  295. `ifeq "ARG1" 'ARG2''
  296. `ifeq 'ARG1' "ARG2"'
  297.      Expand all variable references in ARG1 and ARG2 and compare them.
  298.      If they are identical, the TEXT-IF-TRUE is effective; otherwise,
  299.      the TEXT-IF-FALSE, if any, is effective.
  300.  
  301.      Often you want to test if a variable has a non-empty value.  When
  302.      the value results from complex expansions of variables and
  303.      functions, expansions you would consider empty may actually
  304.      contain whitespace characters and thus are not seen as empty.
  305.      However, you can use the `strip' function (*note Text
  306.      Functions::.) to avoid interpreting whitespace as a non-empty
  307.      value.  For example:
  308.  
  309.           ifeq ($(strip $(foo)),)
  310.           TEXT-IF-EMPTY
  311.           endif
  312.  
  313.      will evaluate TEXT-IF-EMPTY even if the expansion of `$(foo)'
  314.      contains whitespace characters.
  315.  
  316. `ifneq (ARG1, ARG2)'
  317. `ifneq 'ARG1' 'ARG2''
  318. `ifneq "ARG1" "ARG2"'
  319. `ifneq "ARG1" 'ARG2''
  320. `ifneq 'ARG1' "ARG2"'
  321.      Expand all variable references in ARG1 and ARG2 and compare them.
  322.      If they are different, the TEXT-IF-TRUE is effective; otherwise,
  323.      the TEXT-IF-FALSE, if any, is effective.
  324.  
  325. `ifdef VARIABLE-NAME'
  326.      If the variable VARIABLE-NAME has a non-empty value, the
  327.      TEXT-IF-TRUE is effective; otherwise, the TEXT-IF-FALSE, if any,
  328.      is effective.  Variables that have never been defined have an
  329.      empty value.
  330.  
  331.      Note that `ifdef' only tests whether a variable has a value.  It
  332.      does not expand the variable to see if that value is nonempty.
  333.      Consequently, tests using `ifdef' return true for all definitions
  334.      except those like `foo ='.  To test for an empty value, use
  335.      `ifeq ($(foo),)'.  For example,
  336.  
  337.           bar =
  338.           foo = $(bar)
  339.           ifdef foo
  340.           frobozz = yes
  341.           else
  342.           frobozz = no
  343.           endif
  344.  
  345.      sets `frobozz' to `yes', while:
  346.  
  347.           foo =
  348.           ifdef foo
  349.           frobozz = yes
  350.           else
  351.           frobozz = no
  352.           endif
  353.  
  354.      sets `frobozz' to `no'.
  355.  
  356. `ifndef VARIABLE-NAME'
  357.      If the variable VARIABLE-NAME has an empty value, the TEXT-IF-TRUE
  358.      is effective; otherwise, the TEXT-IF-FALSE, if any, is effective.
  359.  
  360.    Extra spaces are allowed and ignored at the beginning of the
  361. conditional directive line, but a tab is not allowed.  (If the line
  362. begins with a tab, it will be considered a command for a rule.)  Aside
  363. from this, extra spaces or tabs may be inserted with no effect anywhere
  364. except within the directive name or within an argument.  A comment
  365. starting with `#' may appear at the end of the line.
  366.  
  367.    The other two directives that play a part in a conditional are `else'
  368. and `endif'.  Each of these directives is written as one word, with no
  369. arguments.  Extra spaces are allowed and ignored at the beginning of the
  370. line, and spaces or tabs at the end.  A comment starting with `#' may
  371. appear at the end of the line.
  372.  
  373.    Conditionals affect which lines of the makefile `make' uses.  If the
  374. condition is true, `make' reads the lines of the TEXT-IF-TRUE as part
  375. of the makefile; if the condition is false, `make' ignores those lines
  376. completely.  It follows that syntactic units of the makefile, such as
  377. rules, may safely be split across the beginning or the end of the
  378. conditional.
  379.  
  380.    `make' evaluates conditionals when it reads a makefile.
  381. Consequently, you cannot use automatic variables in the tests of
  382. conditionals because they are not defined until commands are run (*note
  383. Automatic Variables: Automatic.).
  384.  
  385.    To prevent intolerable confusion, it is not permitted to start a
  386. conditional in one makefile and end it in another.  However, you may
  387. write an `include' directive within a conditional, provided you do not
  388. attempt to terminate the conditional inside the included file.
  389.  
  390. 
  391. File: make.info,  Node: Testing Flags,  Prev: Conditional Syntax,  Up: Conditionals
  392.  
  393. Conditionals that Test Flags
  394. ============================
  395.  
  396.    You can write a conditional that tests `make' command flags such as
  397. `-t' by using the variable `MAKEFLAGS' together with the `findstring'
  398. function (*note Functions for String Substitution and Analysis: Text
  399. Functions.).  This is useful when `touch' is not enough to make a file
  400. appear up to date.
  401.  
  402.    The `findstring' function determines whether one string appears as a
  403. substring of another.  If you want to test for the `-t' flag, use `t'
  404. as the first string and the value of `MAKEFLAGS' as the other.
  405.  
  406.    For example, here is how to arrange to use `ranlib -t' to finish
  407. marking an archive file up to date:
  408.  
  409.      archive.a: ...
  410.      ifneq (,$(findstring t,$(MAKEFLAGS)))
  411.              +touch archive.a
  412.              +ranlib -t archive.a
  413.      else
  414.              ranlib archive.a
  415.      endif
  416.  
  417. The `+' prefix marks those command lines as "recursive" so that they
  418. will be executed despite use of the `-t' flag.  *Note Recursive Use of
  419. `make': Recursion.
  420.  
  421. 
  422. File: make.info,  Node: Functions,  Next: Running,  Prev: Conditionals,  Up: Top
  423.  
  424. Functions for Transforming Text
  425. *******************************
  426.  
  427.    "Functions" allow you to do text processing in the makefile to
  428. compute the files to operate on or the commands to use.  You use a
  429. function in a "function call", where you give the name of the function
  430. and some text (the "arguments") for the function to operate on.  The
  431. result of the function's processing is substituted into the makefile at
  432. the point of the call, just as a variable might be substituted.
  433.  
  434. * Menu:
  435.  
  436. * Syntax of Functions::         How to write a function call.
  437. * Text Functions::              General-purpose text manipulation functions.
  438. * Filename Functions::          Functions for manipulating file names.
  439. * Foreach Function::            Repeat some text with controlled variation.
  440. * Origin Function::             Find where a variable got its value.
  441. * Shell Function::              Substitute the output of a shell command.
  442.  
  443. 
  444. File: make.info,  Node: Syntax of Functions,  Next: Text Functions,  Up: Functions
  445.  
  446. Function Call Syntax
  447. ====================
  448.  
  449.    A function call resembles a variable reference.  It looks like this:
  450.  
  451.      $(FUNCTION ARGUMENTS)
  452.  
  453. or like this:
  454.  
  455.      ${FUNCTION ARGUMENTS}
  456.  
  457.    Here FUNCTION is a function name; one of a short list of names that
  458. are part of `make'.  There is no provision for defining new functions.
  459.  
  460.    The ARGUMENTS are the arguments of the function.  They are separated
  461. from the function name by one or more spaces or tabs, and if there is
  462. more than one argument, then they are separated by commas.  Such
  463. whitespace and commas are not part of an argument's value.  The
  464. delimiters which you use to surround the function call, whether
  465. parentheses or braces, can appear in an argument only in matching pairs;
  466. the other kind of delimiters may appear singly.  If the arguments
  467. themselves contain other function calls or variable references, it is
  468. wisest to use the same kind of delimiters for all the references; write
  469. `$(subst a,b,$(x))', not `$(subst a,b,${x})'.  This is because it is
  470. clearer, and because only one type of delimiter is matched to find the
  471. end of the reference.
  472.  
  473.    The text written for each argument is processed by substitution of
  474. variables and function calls to produce the argument value, which is
  475. the text on which the function acts.  The substitution is done in the
  476. order in which the arguments appear.
  477.  
  478.    Commas and unmatched parentheses or braces cannot appear in the text
  479. of an argument as written; leading spaces cannot appear in the text of
  480. the first argument as written.  These characters can be put into the
  481. argument value by variable substitution.  First define variables
  482. `comma' and `space' whose values are isolated comma and space
  483. characters, then substitute these variables where such characters are
  484. wanted, like this:
  485.  
  486.      comma:= ,
  487.      empty:=
  488.      space:= $(empty) $(empty)
  489.      foo:= a b c
  490.      bar:= $(subst $(space),$(comma),$(foo))
  491.      # bar is now `a,b,c'.
  492.  
  493. Here the `subst' function replaces each space with a comma, through the
  494. value of `foo', and substitutes the result.
  495.  
  496. 
  497. File: make.info,  Node: Text Functions,  Next: Filename Functions,  Prev: Syntax of Functions,  Up: Functions
  498.  
  499. Functions for String Substitution and Analysis
  500. ==============================================
  501.  
  502.    Here are some functions that operate on strings:
  503.  
  504. `$(subst FROM,TO,TEXT)'
  505.      Performs a textual replacement on the text TEXT: each occurrence
  506.      of FROM is replaced by TO.  The result is substituted for the
  507.      function call.  For example,
  508.  
  509.           $(subst ee,EE,feet on the street)
  510.  
  511.      substitutes the string `fEEt on the strEEt'.
  512.  
  513. `$(patsubst PATTERN,REPLACEMENT,TEXT)'
  514.      Finds whitespace-separated words in TEXT that match PATTERN and
  515.      replaces them with REPLACEMENT.  Here PATTERN may contain a `%'
  516.      which acts as a wildcard, matching any number of any characters
  517.      within a word.  If REPLACEMENT also contains a `%', the `%' is
  518.      replaced by the text that matched the `%' in PATTERN.
  519.  
  520.      `%' characters in `patsubst' function invocations can be quoted
  521.      with preceding backslashes (`\').  Backslashes that would
  522.      otherwise quote `%' characters can be quoted with more backslashes.
  523.      Backslashes that quote `%' characters or other backslashes are
  524.      removed from the pattern before it is compared file names or has a
  525.      stem substituted into it.  Backslashes that are not in danger of
  526.      quoting `%' characters go unmolested.  For example, the pattern
  527.      `the\%weird\\%pattern\\' has `the%weird\' preceding the operative
  528.      `%' character, and `pattern\\' following it.  The final two
  529.      backslashes are left alone because they cannot affect any `%'
  530.      character.
  531.  
  532.      Whitespace between words is folded into single space characters;
  533.      leading and trailing whitespace is discarded.
  534.  
  535.      For example,
  536.  
  537.           $(patsubst %.c,%.o,x.c.c bar.c)
  538.  
  539.      produces the value `x.c.o bar.o'.
  540.  
  541.      Substitution references (*note Substitution References:
  542.      Substitution Refs.) are a simpler way to get the effect of the
  543.      `patsubst' function:
  544.  
  545.           $(VAR:PATTERN=REPLACEMENT)
  546.  
  547.      is equivalent to
  548.  
  549.           $(patsubst PATTERN,REPLACEMENT,$(VAR))
  550.  
  551.      The second shorthand simplifies one of the most common uses of
  552.      `patsubst': replacing the suffix at the end of file names.
  553.  
  554.           $(VAR:SUFFIX=REPLACEMENT)
  555.  
  556.      is equivalent to
  557.  
  558.           $(patsubst %SUFFIX,%REPLACEMENT,$(VAR))
  559.  
  560.      For example, you might have a list of object files:
  561.  
  562.           objects = foo.o bar.o baz.o
  563.  
  564.      To get the list of corresponding source files, you could simply
  565.      write:
  566.  
  567.           $(objects:.o=.c)
  568.  
  569.      instead of using the general form:
  570.  
  571.           $(patsubst %.o,%.c,$(objects))
  572.  
  573. `$(strip STRING)'
  574.      Removes leading and trailing whitespace from STRING and replaces
  575.      each internal sequence of one or more whitespace characters with a
  576.      single space.  Thus, `$(strip a b  c )' results in `a b c'.
  577.  
  578.      The function `strip' can be very useful when used in conjunction
  579.      with conditionals.  When comparing something with the empty string
  580.      `' using `ifeq' or `ifneq', you usually want a string of just
  581.      whitespace to match the empty string (*note Conditionals::.).
  582.  
  583.      Thus, the following may fail to have the desired results:
  584.  
  585.           .PHONY: all
  586.           ifneq   "$(needs_made)" ""
  587.           all: $(needs_made)
  588.           else
  589.           all:;@echo 'Nothing to make!'
  590.           endif
  591.  
  592.      Replacing the variable reference `$(needs_made)' with the function
  593.      call `$(strip $(needs_made))' in the `ifneq' directive would make
  594.      it more robust.
  595.  
  596. `$(findstring FIND,IN)'
  597.      Searches IN for an occurrence of FIND.  If it occurs, the value is
  598.      FIND; otherwise, the value is empty.  You can use this function in
  599.      a conditional to test for the presence of a specific substring in
  600.      a given string.  Thus, the two examples,
  601.  
  602.           $(findstring a,a b c)
  603.           $(findstring a,b c)
  604.  
  605.      produce the values `a' and `' (the empty string), respectively.
  606.      *Note Testing Flags::, for a practical application of `findstring'.
  607.  
  608. `$(filter PATTERN...,TEXT)'
  609.      Removes all whitespace-separated words in TEXT that do *not* match
  610.      any of the PATTERN words, returning only matching words.  The
  611.      patterns are written using `%', just like the patterns used in the
  612.      `patsubst' function above.
  613.  
  614.      The `filter' function can be used to separate out different types
  615.      of strings (such as file names) in a variable.  For example:
  616.  
  617.           sources := foo.c bar.c baz.s ugh.h
  618.           foo: $(sources)
  619.                   cc $(filter %.c %.s,$(sources)) -o foo
  620.  
  621.      says that `foo' depends of `foo.c', `bar.c', `baz.s' and `ugh.h'
  622.      but only `foo.c', `bar.c' and `baz.s' should be specified in the
  623.      command to the compiler.
  624.  
  625. `$(filter-out PATTERN...,TEXT)'
  626.      Removes all whitespace-separated words in TEXT that *do* match the
  627.      PATTERN words, returning only the words that *do not* match.  This
  628.      is the exact opposite of the `filter' function.
  629.  
  630.      For example, given:
  631.  
  632.           objects=main1.o foo.o main2.o bar.o
  633.           mains=main1.o main2.o
  634.  
  635.      the following generates a list which contains all the object files
  636.      not in `mains':
  637.  
  638.           $(filter-out $(mains),$(objects))
  639.  
  640. `$(sort LIST)'
  641.      Sorts the words of LIST in lexical order, removing duplicate
  642.      words.  The output is a list of words separated by single spaces.
  643.      Thus,
  644.  
  645.           $(sort foo bar lose)
  646.  
  647.      returns the value `bar foo lose'.
  648.  
  649.      Incidentally, since `sort' removes duplicate words, you can use it
  650.      for this purpose even if you don't care about the sort order.
  651.  
  652.    Here is a realistic example of the use of `subst' and `patsubst'.
  653. Suppose that a makefile uses the `VPATH' variable to specify a list of
  654. directories that `make' should search for dependency files (*note
  655. `VPATH' Search Path for All Dependencies: General Search.).  This
  656. example shows how to tell the C compiler to search for header files in
  657. the same list of directories.
  658.  
  659.    The value of `VPATH' is a list of directories separated by colons,
  660. such as `src:../headers'.  First, the `subst' function is used to
  661. change the colons to spaces:
  662.  
  663.      $(subst :, ,$(VPATH))
  664.  
  665. This produces `src ../headers'.  Then `patsubst' is used to turn each
  666. directory name into a `-I' flag.  These can be added to the value of
  667. the variable `CFLAGS', which is passed automatically to the C compiler,
  668. like this:
  669.  
  670.      override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
  671.  
  672. The effect is to append the text `-Isrc -I../headers' to the previously
  673. given value of `CFLAGS'.  The `override' directive is used so that the
  674. new value is assigned even if the previous value of `CFLAGS' was
  675. specified with a command argument (*note The `override' Directive:
  676. Override Directive.).
  677.  
  678. 
  679. File: make.info,  Node: Filename Functions,  Next: Foreach Function,  Prev: Text Functions,  Up: Functions
  680.  
  681. Functions for File Names
  682. ========================
  683.  
  684.    Several of the built-in expansion functions relate specifically to
  685. taking apart file names or lists of file names.
  686.  
  687.    Each of the following functions performs a specific transformation
  688. on a file name.  The argument of the function is regarded as a series
  689. of file names, separated by whitespace.  (Leading and trailing
  690. whitespace is ignored.)  Each file name in the series is transformed in
  691. the same way and the results are concatenated with single spaces
  692. between them.
  693.  
  694. `$(dir NAMES...)'
  695.      Extracts the directory-part of each file name in NAMES.  The
  696.      directory-part of the file name is everything up through (and
  697.      including) the last slash in it.  If the file name contains no
  698.      slash, the directory part is the string `./'.  For example,
  699.  
  700.           $(dir src/foo.c hacks)
  701.  
  702.      produces the result `src/ ./'.
  703.  
  704. `$(notdir NAMES...)'
  705.      Extracts all but the directory-part of each file name in NAMES.
  706.      If the file name contains no slash, it is left unchanged.
  707.      Otherwise, everything through the last slash is removed from it.
  708.  
  709.      A file name that ends with a slash becomes an empty string.  This
  710.      is unfortunate, because it means that the result does not always
  711.      have the same number of whitespace-separated file names as the
  712.      argument had; but we do not see any other valid alternative.
  713.  
  714.      For example,
  715.  
  716.           $(notdir src/foo.c hacks)
  717.  
  718.      produces the result `foo.c hacks'.
  719.  
  720. `$(suffix NAMES...)'
  721.      Extracts the suffix of each file name in NAMES.  If the file name
  722.      contains a period, the suffix is everything starting with the last
  723.      period.  Otherwise, the suffix is the empty string.  This
  724.      frequently means that the result will be empty when NAMES is not,
  725.      and if NAMES contains multiple file names, the result may contain
  726.      fewer file names.
  727.  
  728.      For example,
  729.  
  730.           $(suffix src/foo.c hacks)
  731.  
  732.      produces the result `.c'.
  733.  
  734. `$(basename NAMES...)'
  735.      Extracts all but the suffix of each file name in NAMES.  If the
  736.      file name contains a period, the basename is everything starting
  737.      up to (and not including) the last period.  Otherwise, the
  738.      basename is the entire file name.  For example,
  739.  
  740.           $(basename src/foo.c hacks)
  741.  
  742.      produces the result `src/foo hacks'.
  743.  
  744. `$(addsuffix SUFFIX,NAMES...)'
  745.      The argument NAMES is regarded as a series of names, separated by
  746.      whitespace; SUFFIX is used as a unit.  The value of SUFFIX is
  747.      appended to the end of each individual name and the resulting
  748.      larger names are concatenated with single spaces between them.
  749.      For example,
  750.  
  751.           $(addsuffix .c,foo bar)
  752.  
  753.      produces the result `foo.c bar.c'.
  754.  
  755. `$(addprefix PREFIX,NAMES...)'
  756.      The argument NAMES is regarded as a series of names, separated by
  757.      whitespace; PREFIX is used as a unit.  The value of PREFIX is
  758.      prepended to the front of each individual name and the resulting
  759.      larger names are concatenated with single spaces between them.
  760.      For example,
  761.  
  762.           $(addprefix src/,foo bar)
  763.  
  764.      produces the result `src/foo src/bar'.
  765.  
  766. `$(join LIST1,LIST2)'
  767.      Concatenates the two arguments word by word: the two first words
  768.      (one from each argument) concatenated form the first word of the
  769.      result, the two second words form the second word of the result,
  770.      and so on.  So the Nth word of the result comes from the Nth word
  771.      of each argument.  If one argument has more words that the other,
  772.      the extra words are copied unchanged into the result.
  773.  
  774.      For example, `$(join a b,.c .o)' produces `a.c b.o'.
  775.  
  776.      Whitespace between the words in the lists is not preserved; it is
  777.      replaced with a single space.
  778.  
  779.      This function can merge the results of the `dir' and `notdir'
  780.      functions, to produce the original list of files which was given
  781.      to those two functions.
  782.  
  783. `$(word N,TEXT)'
  784.      Returns the Nth word of TEXT.  The legitimate values of N start
  785.      from 1.  If N is bigger than the number of words in TEXT, the
  786.      value is empty.  For example,
  787.  
  788.           $(word 2, foo bar baz)
  789.  
  790.      returns `bar'.
  791.  
  792. `$(words TEXT)'
  793.      Returns the number of words in TEXT.  Thus, the last word of TEXT
  794.      is `$(word $(words TEXT),TEXT)'.
  795.  
  796. `$(firstword NAMES...)'
  797.      The argument NAMES is regarded as a series of names, separated by
  798.      whitespace.  The value is the first name in the series.  The rest
  799.      of the names are ignored.
  800.  
  801.      For example,
  802.  
  803.           $(firstword foo bar)
  804.  
  805.      produces the result `foo'.  Although `$(firstword TEXT)' is the
  806.      same as `$(word 1,TEXT)', the `firstword' function is retained for
  807.      its simplicity.
  808.  
  809. `$(wildcard PATTERN)'
  810.      The argument PATTERN is a file name pattern, typically containing
  811.      wildcard characters (as in shell file name patterns).  The result
  812.      of `wildcard' is a space-separated list of the names of existing
  813.      files that match the pattern.  *Note Using Wildcard Characters in
  814.      File Names: Wildcards.
  815.  
  816. 
  817. File: make.info,  Node: Foreach Function,  Next: Origin Function,  Prev: Filename Functions,  Up: Functions
  818.  
  819. The `foreach' Function
  820. ======================
  821.  
  822.    The `foreach' function is very different from other functions.  It
  823. causes one piece of text to be used repeatedly, each time with a
  824. different substitution performed on it.  It resembles the `for' command
  825. in the shell `sh' and the `foreach' command in the C-shell `csh'.
  826.  
  827.    The syntax of the `foreach' function is:
  828.  
  829.      $(foreach VAR,LIST,TEXT)
  830.  
  831. The first two arguments, VAR and LIST, are expanded before anything
  832. else is done; note that the last argument, TEXT, is *not* expanded at
  833. the same time.  Then for each word of the expanded value of LIST, the
  834. variable named by the expanded value of VAR is set to that word, and
  835. TEXT is expanded.  Presumably TEXT contains references to that
  836. variable, so its expansion will be different each time.
  837.  
  838.    The result is that TEXT is expanded as many times as there are
  839. whitespace-separated words in LIST.  The multiple expansions of TEXT
  840. are concatenated, with spaces between them, to make the result of
  841. `foreach'.
  842.  
  843.    This simple example sets the variable `files' to the list of all
  844. files in the directories in the list `dirs':
  845.  
  846.      dirs := a b c d
  847.      files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
  848.  
  849.    Here TEXT is `$(wildcard $(dir)/*)'.  The first repetition finds the
  850. value `a' for `dir', so it produces the same result as `$(wildcard
  851. a/*)'; the second repetition produces the result of `$(wildcard b/*)';
  852. and the third, that of `$(wildcard c/*)'.
  853.  
  854.    This example has the same result (except for setting `dirs') as the
  855. following example:
  856.  
  857.      files := $(wildcard a/* b/* c/* d/*)
  858.  
  859.    When TEXT is complicated, you can improve readability by giving it a
  860. name, with an additional variable:
  861.  
  862.      find_files = $(wildcard $(dir)/*)
  863.      dirs := a b c d
  864.      files := $(foreach dir,$(dirs),$(find_files))
  865.  
  866. Here we use the variable `find_files' this way.  We use plain `=' to
  867. define a recursively-expanding variable, so that its value contains an
  868. actual function call to be reexpanded under the control of `foreach'; a
  869. simply-expanded variable would not do, since `wildcard' would be called
  870. only once at the time of defining `find_files'.
  871.  
  872.    The `foreach' function has no permanent effect on the variable VAR;
  873. its value and flavor after the `foreach' function call are the same as
  874. they were beforehand.  The other values which are taken from LIST are
  875. in effect only temporarily, during the execution of `foreach'.  The
  876. variable VAR is a simply-expanded variable during the execution of
  877. `foreach'.  If VAR was undefined before the `foreach' function call, it
  878. is undefined after the call.  *Note The Two Flavors of Variables:
  879. Flavors.
  880.  
  881.    You must take care when using complex variable expressions that
  882. result in variable names because many strange things are valid variable
  883. names, but are probably not what you intended.  For example,
  884.  
  885.      files := $(foreach Esta escrito en espanol!,b c ch,$(find_files))
  886.  
  887. might be useful if the value of `find_files' references the variable
  888. whose name is `Esta escrito en espanol!' (es un nombre bastante largo,
  889. no?), but it is more likely to be a mistake.
  890.  
  891. 
  892. File: make.info,  Node: Origin Function,  Next: Shell Function,  Prev: Foreach Function,  Up: Functions
  893.  
  894. The `origin' Function
  895. =====================
  896.  
  897.    The `origin' function is unlike most other functions in that it does
  898. not operate on the values of variables; it tells you something *about*
  899. a variable.  Specifically, it tells you where it came from.
  900.  
  901.    The syntax of the `origin' function is:
  902.  
  903.      $(origin VARIABLE)
  904.  
  905.    Note that VARIABLE is the *name* of a variable to inquire about; not
  906. a *reference* to that variable.  Therefore you would not normally use a
  907. `$' or parentheses when writing it.  (You can, however, use a variable
  908. reference in the name if you want the name not to be a constant.)
  909.  
  910.    The result of this function is a string telling you how the variable
  911. VARIABLE was defined:
  912.  
  913. `undefined'
  914.      if VARIABLE was never defined.
  915.  
  916. `default'
  917.      if VARIABLE has a default definition, as is usual with `CC' and so
  918.      on.  *Note Variables Used by Implicit Rules: Implicit Variables.
  919.      Note that if you have redefined a default variable, the `origin'
  920.      function will return the origin of the later definition.
  921.  
  922. `environment'
  923.      if VARIABLE was defined as an environment variable and the `-e'
  924.      option is *not* turned on (*note Summary of Options: Options
  925.      Summary.).
  926.  
  927. `environment override'
  928.      if VARIABLE was defined as an environment variable and the `-e'
  929.      option *is* turned on (*note Summary of Options: Options Summary.).
  930.  
  931. `file'
  932.      if VARIABLE was defined in a makefile.
  933.  
  934. `command line'
  935.      if VARIABLE was defined on the command line.
  936.  
  937. `override'
  938.      if VARIABLE was defined with an `override' directive in a makefile
  939.      (*note The `override' Directive: Override Directive.).
  940.  
  941. `automatic'
  942.      if VARIABLE is an automatic variable defined for the execution of
  943.      the commands for each rule (*note Automatic Variables: Automatic.).
  944.  
  945.    This information is primarily useful (other than for your curiosity)
  946. to determine if you want to believe the value of a variable.  For
  947. example, suppose you have a makefile `foo' that includes another
  948. makefile `bar'.  You want a variable `bletch' to be defined in `bar' if
  949. you run the command `make -f bar', even if the environment contains a
  950. definition of `bletch'.  However, if `foo' defined `bletch' before
  951. including `bar', you do not want to override that definition.  This
  952. could be done by using an `override' directive in `foo', giving that
  953. definition precedence over the later definition in `bar';
  954. unfortunately, the `override' directive would also override any command
  955. line definitions.  So, `bar' could include:
  956.  
  957.      ifdef bletch
  958.      ifeq "$(origin bletch)" "environment"
  959.      bletch = barf, gag, etc.
  960.      endif
  961.      endif
  962.  
  963. If `bletch' has been defined from the environment, this will redefine
  964. it.
  965.  
  966.    If you want to override a previous definition of `bletch' if it came
  967. from the environment, even under `-e', you could instead write:
  968.  
  969.      ifneq "$(findstring environment,$(origin bletch))" ""
  970.      bletch = barf, gag, etc.
  971.      endif
  972.  
  973.    Here the redefinition takes place if `$(origin bletch)' returns
  974. either `environment' or `environment override'.  *Note Functions for
  975. String Substitution and Analysis: Text Functions.
  976.  
  977. 
  978. File: make.info,  Node: Shell Function,  Prev: Origin Function,  Up: Functions
  979.  
  980. The `shell' Function
  981. ====================
  982.  
  983.    The `shell' function is unlike any other function except the
  984. `wildcard' function (*note The Function `wildcard': Wildcard Function.)
  985. in that it communicates with the world outside of `make'.
  986.  
  987.    The `shell' function performs the same function that backquotes
  988. (``') perform in most shells: it does "command expansion".  This means
  989. that it takes an argument that is a shell command and returns the
  990. output of the command.  The only processing `make' does on the result,
  991. before substituting it into the surrounding text, is to convert
  992. newlines to spaces.
  993.  
  994.    The commands run by calls to the `shell' function are run when the
  995. function calls are expanded.  In most cases, this is when the makefile
  996. is read in.  The exception is that function calls in the commands of
  997. the rules are expanded when the commands are run, and this applies to
  998. `shell' function calls like all others.
  999.  
  1000.    Here are some examples of the use of the `shell' function:
  1001.  
  1002.      contents := $(shell cat foo)
  1003.  
  1004. sets `contents' to the contents of the file `foo', with a space (rather
  1005. than a newline) separating each line.
  1006.  
  1007.      files := $(shell echo *.c)
  1008.  
  1009. sets `files' to the expansion of `*.c'.  Unless `make' is using a very
  1010. strange shell, this has the same result as `$(wildcard *.c)'.
  1011.  
  1012. 
  1013. File: make.info,  Node: Running,  Next: Implicit Rules,  Prev: Functions,  Up: Top
  1014.  
  1015. How to Run `make'
  1016. *****************
  1017.  
  1018.    A makefile that says how to recompile a program can be used in more
  1019. than one way.  The simplest use is to recompile every file that is out
  1020. of date.  Usually, makefiles are written so that if you run `make' with
  1021. no arguments, it does just that.
  1022.  
  1023.    But you might want to update only some of the files; you might want
  1024. to use a different compiler or different compiler options; you might
  1025. want just to find out which files are out of date without changing them.
  1026.  
  1027.    By giving arguments when you run `make', you can do any of these
  1028. things and many others.
  1029.  
  1030.    The exit status of `make' is always one of three values:
  1031. `0'
  1032.      The exit status is zero if `make' is successful.
  1033.  
  1034. `2'
  1035.      The exit status is two if `make' encounters any errors.  It will
  1036.      print messages describing the particular errors.
  1037.  
  1038. `1'
  1039.      The exit status is one if you use the `-q' flag and `make'
  1040.      determines that some target is not already up to date.  *Note
  1041.      Instead of Executing the Commands: Instead of Execution.
  1042.  
  1043. * Menu:
  1044.  
  1045. * Makefile Arguments::          How to specify which makefile to use.
  1046. * Goals::                       How to use goal arguments to specify which
  1047.                                   parts of the makefile to use.
  1048. * Instead of Execution::        How to use mode flags to specify what
  1049.                                   kind of thing to do with the commands
  1050.                                   in the makefile other than simply
  1051.                                   execute them.
  1052. * Avoiding Compilation::        How to avoid recompiling certain files.
  1053. * Overriding::                  How to override a variable to specify
  1054.                                   an alternate compiler and other things.
  1055. * Testing::                     How to proceed past some errors, to
  1056.                                   test compilation.
  1057. * Options Summary::             Summary of Options
  1058.  
  1059. 
  1060. File: make.info,  Node: Makefile Arguments,  Next: Goals,  Up: Running
  1061.  
  1062. Arguments to Specify the Makefile
  1063. =================================
  1064.  
  1065.    The way to specify the name of the makefile is with the `-f' or
  1066. `--file' option (`--makefile' also works).  For example, `-f altmake'
  1067. says to use the file `altmake' as the makefile.
  1068.  
  1069.    If you use the `-f' flag several times and follow each `-f' with an
  1070. argument, all the specified files are used jointly as makefiles.
  1071.  
  1072.    If you do not use the `-f' or `--file' flag, the default is to try
  1073. `GNUmakefile', `makefile', and `Makefile', in that order, and use the
  1074. first of these three which exists or can be made (*note Writing
  1075. Makefiles: Makefiles.).
  1076.  
  1077. 
  1078. File: make.info,  Node: Goals,  Next: Instead of Execution,  Prev: Makefile Arguments,  Up: Running
  1079.  
  1080. Arguments to Specify the Goals
  1081. ==============================
  1082.  
  1083.    The "goals" are the targets that `make' should strive ultimately to
  1084. update.  Other targets are updated as well if they appear as
  1085. dependencies of goals, or dependencies of dependencies of goals, etc.
  1086.  
  1087.    By default, the goal is the first target in the makefile (not
  1088. counting targets that start with a period).  Therefore, makefiles are
  1089. usually written so that the first target is for compiling the entire
  1090. program or programs they describe.  If the first rule in the makefile
  1091. has several targets, only the first target in the rule becomes the
  1092. default goal, not the whole list.
  1093.  
  1094.    You can specify a different goal or goals with arguments to `make'.
  1095. Use the name of the goal as an argument.  If you specify several goals,
  1096. `make' processes each of them in turn, in the order you name them.
  1097.  
  1098.    Any target in the makefile may be specified as a goal (unless it
  1099. starts with `-' or contains an `=', in which case it will be parsed as
  1100. a switch or variable definition, respectively).  Even targets not in
  1101. the makefile may be specified, if `make' can find implicit rules that
  1102. say how to make them.
  1103.  
  1104.    One use of specifying a goal is if you want to compile only a part of
  1105. the program, or only one of several programs.  Specify as a goal each
  1106. file that you wish to remake.  For example, consider a directory
  1107. containing several programs, with a makefile that starts like this:
  1108.  
  1109.      .PHONY: all
  1110.      all: size nm ld ar as
  1111.  
  1112.    If you are working on the program `size', you might want to say
  1113. `make size' so that only the files of that program are recompiled.
  1114.  
  1115.    Another use of specifying a goal is to make files that are not
  1116. normally made.  For example, there may be a file of debugging output,
  1117. or a version of the program that is compiled specially for testing,
  1118. which has a rule in the makefile but is not a dependency of the default
  1119. goal.
  1120.  
  1121.    Another use of specifying a goal is to run the commands associated
  1122. with a phony target (*note Phony Targets::.) or empty target (*note
  1123. Empty Target Files to Record Events: Empty Targets.).  Many makefiles
  1124. contain a phony target named `clean' which deletes everything except
  1125. source files.  Naturally, this is done only if you request it
  1126. explicitly with `make clean'.  Following is a list of typical phony and
  1127. empty target names.  *Note Standard Targets::, for a detailed list of
  1128. all the standard target names which GNU software packages use.
  1129.  
  1130. `all'
  1131.      Make all the top-level targets the makefile knows about.
  1132.  
  1133. `clean'
  1134.      Delete all files that are normally created by running `make'.
  1135.  
  1136. `mostlyclean'
  1137.      Like `clean', but may refrain from deleting a few files that people
  1138.      normally don't want to recompile.  For example, the `mostlyclean'
  1139.      target for GCC does not delete `libgcc.a', because recompiling it
  1140.      is rarely necessary and takes a lot of time.
  1141.  
  1142. `distclean'
  1143. `realclean'
  1144. `clobber'
  1145.      Any of these targets might be defined to delete *more* files than
  1146.      `clean' does.  For example, this would delete configuration files
  1147.      or links that you would normally create as preparation for
  1148.      compilation, even if the makefile itself cannot create these files.
  1149.  
  1150. `install'
  1151.      Copy the executable file into a directory that users typically
  1152.      search for commands; copy any auxiliary files that the executable
  1153.      uses into the directories where it will look for them.
  1154.  
  1155. `print'
  1156.      Print listings of the source files that have changed.
  1157.  
  1158. `tar'
  1159.      Create a tar file of the source files.
  1160.  
  1161. `shar'
  1162.      Create a shell archive (shar file) of the source files.
  1163.  
  1164. `dist'
  1165.      Create a distribution file of the source files.  This might be a
  1166.      tar file, or a shar file, or a compressed version of one of the
  1167.      above, or even more than one of the above.
  1168.  
  1169. `TAGS'
  1170.      Update a tags table for this program.
  1171.  
  1172. `check'
  1173. `test'
  1174.      Perform self tests on the program this makefile builds.
  1175.  
  1176. 
  1177. File: make.info,  Node: Instead of Execution,  Next: Avoiding Compilation,  Prev: Goals,  Up: Running
  1178.  
  1179. Instead of Executing the Commands
  1180. =================================
  1181.  
  1182.    The makefile tells `make' how to tell whether a target is up to date,
  1183. and how to update each target.  But updating the targets is not always
  1184. what you want.  Certain options specify other activities for `make'.
  1185.  
  1186. `-n'
  1187. `--just-print'
  1188. `--dry-run'
  1189. `--recon'
  1190.      "No-op".  The activity is to print what commands would be used to
  1191.      make the targets up to date, but not actually execute them.
  1192.  
  1193. `-t'
  1194. `--touch'
  1195.      "Touch".  The activity is to mark the targets as up to date without
  1196.      actually changing them.  In other words, `make' pretends to compile
  1197.      the targets but does not really change their contents.
  1198.  
  1199. `-q'
  1200. `--question'
  1201.      "Question".  The activity is to find out silently whether the
  1202.      targets are up to date already; but execute no commands in either
  1203.      case.  In other words, neither compilation nor output will occur.
  1204.  
  1205. `-W FILE'
  1206. `--what-if=FILE'
  1207. `--assume-new=FILE'
  1208. `--new-file=FILE'
  1209.      "What if".  Each `-W' flag is followed by a file name.  The given
  1210.      files' modification times are recorded by `make' as being the
  1211.      present time, although the actual modification times remain the
  1212.      same.  You can use the `-W' flag in conjunction with the `-n' flag
  1213.      to see what would happen if you were to modify specific files.
  1214.  
  1215.    With the `-n' flag, `make' prints the commands that it would
  1216. normally execute but does not execute them.
  1217.  
  1218.    With the `-t' flag, `make' ignores the commands in the rules and
  1219. uses (in effect) the command `touch' for each target that needs to be
  1220. remade.  The `touch' command is also printed, unless `-s' or `.SILENT'
  1221. is used.  For speed, `make' does not actually invoke the program
  1222. `touch'.  It does the work directly.
  1223.  
  1224.    With the `-q' flag, `make' prints nothing and executes no commands,
  1225. but the exit status code it returns is zero if and only if the targets
  1226. to be considered are already up to date.  If the exit status is one,
  1227. then some updating needs to be done.  If `make' encounters an error,
  1228. the exit status is two, so you can distinguish an error from a target
  1229. that is not up to date.
  1230.  
  1231.    It is an error to use more than one of these three flags in the same
  1232. invocation of `make'.
  1233.  
  1234.    The `-n', `-t', and `-q' options do not affect command lines that
  1235. begin with `+' characters or contain the strings `$(MAKE)' or
  1236. `${MAKE}'.  Note that only the line containing the `+' character or the
  1237. strings `$(MAKE)' or `${MAKE}' is run regardless of these options.
  1238. Other lines in the same rule are not run unless they too begin with `+'
  1239. or contain `$(MAKE)' or `${MAKE}' (*Note How the `MAKE' Variable Works:
  1240. MAKE Variable.)
  1241.  
  1242.    The `-W' flag provides two features:
  1243.  
  1244.    * If you also use the `-n' or `-q' flag, you can see what `make'
  1245.      would do if you were to modify some files.
  1246.  
  1247.    * Without the `-n' or `-q' flag, when `make' is actually executing
  1248.      commands, the `-W' flag can direct `make' to act as if some files
  1249.      had been modified, without actually modifying the files.
  1250.  
  1251.    Note that the options `-p' and `-v' allow you to obtain other
  1252. information about `make' or about the makefiles in use (*note Summary
  1253. of Options: Options Summary.).
  1254.  
  1255. 
  1256. File: make.info,  Node: Avoiding Compilation,  Next: Overriding,  Prev: Instead of Execution,  Up: Running
  1257.  
  1258. Avoiding Recompilation of Some Files
  1259. ====================================
  1260.  
  1261.    Sometimes you may have changed a source file but you do not want to
  1262. recompile all the files that depend on it.  For example, suppose you
  1263. add a macro or a declaration to a header file that many other files
  1264. depend on.  Being conservative, `make' assumes that any change in the
  1265. header file requires recompilation of all dependent files, but you know
  1266. that they do not need to be recompiled and you would rather not waste
  1267. the time waiting for them to compile.
  1268.  
  1269.    If you anticipate the problem before changing the header file, you
  1270. can use the `-t' flag.  This flag tells `make' not to run the commands
  1271. in the rules, but rather to mark the target up to date by changing its
  1272. last-modification date.  You would follow this procedure:
  1273.  
  1274.   1. Use the command `make' to recompile the source files that really
  1275.      need recompilation.
  1276.  
  1277.   2. Make the changes in the header files.
  1278.  
  1279.   3. Use the command `make -t' to mark all the object files as up to
  1280.      date.  The next time you run `make', the changes in the header
  1281.      files will not cause any recompilation.
  1282.  
  1283.    If you have already changed the header file at a time when some files
  1284. do need recompilation, it is too late to do this.  Instead, you can use
  1285. the `-o FILE' flag, which marks a specified file as "old" (*note
  1286. Summary of Options: Options Summary.).  This means that the file itself
  1287. will not be remade, and nothing else will be remade on its account.
  1288. Follow this procedure:
  1289.  
  1290.   1. Recompile the source files that need compilation for reasons
  1291.      independent of the particular header file, with `make -o
  1292.      HEADERFILE'.  If several header files are involved, use a separate
  1293.      `-o' option for each header file.
  1294.  
  1295.   2. Touch all the object files with `make -t'.
  1296.  
  1297.