home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / gnu / make-3.70-src.lha / src / amiga / make-3.70 / make.info-3 < prev    next >
Encoding:
GNU Info File  |  1993-12-17  |  48.1 KB  |  1,225 lines

  1. This is Info file make.info, produced by Makeinfo-1.54 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.45, last updated 14 December 1993, of `The GNU
  9. Make Manual', for `make', Version 3.70 Beta.
  10.  
  11.    Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software
  12. 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: Errors,  Next: Interrupts,  Prev: Parallel,  Up: Commands
  30.  
  31. Errors in Commands
  32. ==================
  33.  
  34.    After each shell command returns, `make' looks at its exit status.
  35. If the command completed successfully, the next command line is executed
  36. in a new shell; after the last command line is finished, the rule is
  37. finished.
  38.  
  39.    If there is an error (the exit status is nonzero), `make' gives up on
  40. the current rule, and perhaps on all rules.
  41.  
  42.    Sometimes the failure of a certain command does not indicate a
  43. problem.  For example, you may use the `mkdir' command to ensure that a
  44. directory exists.  If the directory already exists, `mkdir' will report
  45. an error, but you probably want `make' to continue regardless.
  46.  
  47.    To ignore errors in a command line, write a `-' at the beginning of
  48. the line's text (after the initial tab).  The `-' is discarded before
  49. the command is passed to the shell for execution.
  50.  
  51.    For example,
  52.  
  53.      clean:
  54.              -rm -f *.o
  55.  
  56. This causes `rm' to continue even if it is unable to remove a file.
  57.  
  58.    When you run `make' with the `-i' or `--ignore-errors' flag, errors
  59. are ignored in all commands of all rules.  A rule in the makefile for
  60. the special target `.IGNORE' has the same effect.  These ways of
  61. ignoring errors are obsolete because `-' is more flexible.
  62.  
  63.    When errors are to be ignored, because of either a `-' or the `-i'
  64. flag, `make' treats an error return just like success, except that it
  65. prints out a message that tells you the status code the command exited
  66. with, and says that the error has been ignored.
  67.  
  68.    When an error happens that `make' has not been told to ignore, it
  69. implies that the current target cannot be correctly remade, and neither
  70. can any other that depends on it either directly or indirectly.  No
  71. further commands will be executed for these targets, since their
  72. preconditions have not been achieved.
  73.  
  74.    Normally `make' gives up immediately in this circumstance, returning
  75. a nonzero status.  However, if the `-k' or `--keep-going' flag is
  76. specified, `make' continues to consider the other dependencies of the
  77. pending targets, remaking them if necessary, before it gives up and
  78. returns nonzero status.  For example, after an error in compiling one
  79. object file, `make -k' will continue compiling other object files even
  80. though it already knows that linking them will be impossible.  *Note
  81. Summary of Options: Options Summary.
  82.  
  83.    The usual behavior assumes that your purpose is to get the specified
  84. targets up to date; once `make' learns that this is impossible, it
  85. might as well report the failure immediately.  The `-k' option says
  86. that the real purpose is to test as many of the changes made in the
  87. program as possible, perhaps to find several independent problems so
  88. that you can correct them all before the next attempt to compile.  This
  89. is why Emacs' `compile' command passes the `-k' flag by default.
  90.  
  91. 
  92. File: make.info,  Node: Interrupts,  Next: Recursion,  Prev: Errors,  Up: Commands
  93.  
  94. Interrupting or Killing `make'
  95. ==============================
  96.  
  97.    If `make' gets a fatal signal while a command is executing, it may
  98. delete the target file that the command was supposed to update.  This is
  99. done if the target file's last-modification time has changed since
  100. `make' first checked it.
  101.  
  102.    The purpose of deleting the target is to make sure that it is remade
  103. from scratch when `make' is next run.  Why is this?  Suppose you type
  104. `Ctrl-c' while a compiler is running, and it has begun to write an
  105. object file `foo.o'.  The `Ctrl-c' kills the compiler, resulting in an
  106. incomplete file whose last-modification time is newer than the source
  107. file `foo.c'.  But `make' also receives the `Ctrl-c' signal and deletes
  108. this incomplete file.  If `make' did not do this, the next invocation
  109. of `make' would think that `foo.o' did not require updating--resulting
  110. in a strange error message from the linker when it tries to link an
  111. object file half of which is missing.
  112.  
  113.    You can prevent the deletion of a target file in this way by making
  114. the special target `.PRECIOUS' depend on it.  Before remaking a target,
  115. `make' checks to see whether it appears on the dependencies of
  116. `.PRECIOUS', and thereby decides whether the target should be deleted
  117. if a signal happens.  Some reasons why you might do this are that the
  118. target is updated in some atomic fashion, or exists only to record a
  119. modification-time (its contents do not matter), or must exist at all
  120. times to prevent other sorts of trouble.
  121.  
  122. 
  123. File: make.info,  Node: Recursion,  Next: Sequences,  Prev: Interrupts,  Up: Commands
  124.  
  125. Recursive Use of `make'
  126. =======================
  127.  
  128.    Recursive use of `make' means using `make' as a command in a
  129. makefile.  This technique is useful when you want separate makefiles for
  130. various subsystems that compose a larger system.  For example, suppose
  131. you have a subdirectory `subdir' which has its own makefile, and you
  132. would like the containing directory's makefile to run `make' on the
  133. subdirectory.  You can do it by writing this:
  134.  
  135.      subsystem:
  136.              cd subdir; $(MAKE)
  137.  
  138. or, equivalently, this (*note Summary of Options: Options Summary.):
  139.  
  140.      subsystem:
  141.              $(MAKE) -C subdir
  142.  
  143.    You can write recursive `make' commands just by copying this example,
  144. but there are many things to know about how they work and why, and about
  145. how the sub-`make' relates to the top-level `make'.
  146.  
  147. * Menu:
  148.  
  149. * MAKE Variable::               The special effects of using `$(MAKE)'.
  150. * Variables/Recursion::         How to communicate variables to a sub-`make'.
  151. * Options/Recursion::           How to communicate options to a sub-`make'.
  152. * -w Option::                   How the `-w' or `--print-directory' option
  153.                                  helps debug use of recursive `make' commands.
  154.  
  155. 
  156. File: make.info,  Node: MAKE Variable,  Next: Variables/Recursion,  Up: Recursion
  157.  
  158. How the `MAKE' Variable Works
  159. -----------------------------
  160.  
  161.    Recursive `make' commands should always use the variable `MAKE', not
  162. the explicit command name `make', as shown here:
  163.  
  164.      subsystem:
  165.              cd subdir; $(MAKE)
  166.  
  167.    The value of this variable is the file name with which `make' was
  168. invoked.  If this file name was `/bin/make', then the command executed
  169. is `cd subdir; /bin/make'.  If you use a special version of `make' to
  170. run the top-level makefile, the same special version will be executed
  171. for recursive invocations.
  172.  
  173.    Also, any arguments that define variable values are added to `MAKE',
  174. so the sub-`make' gets them too.  Thus, if you do `make CFLAGS=-O', so
  175. that all C compilations will be optimized, the sub-`make' is run with
  176. `cd subdir; /bin/make CFLAGS=-O'.
  177.  
  178.    The `MAKE' variable actually just refers to two other variables
  179. which contain these special values.  In fact, `MAKE' is always defined
  180. as `$(MAKE_COMMAND) $(MAKEOVERRIDES)'.  The variable `MAKE_COMMAND' is
  181. the file name with which `make' was invoked (such as `/bin/make',
  182. above).  The variable `MAKEOVERRIDES' contains definitions for the
  183. variables defined on the command line; in the above example, its value
  184. is `CFLAGS=-O'.  If you *do not* want these variable definitions done
  185. in all recursive `make' invocations, you can redefine the
  186. `MAKEOVERRIDES' variable to remove them.  You do this in any of the
  187. normal ways for defining variables: in a makefile (*note Setting
  188. Variables: Setting.); on the command line with an argument like
  189. `MAKEOVERRIDES=' (*note Overriding Variables: Overriding.); or with an
  190. environment variable (*note Variables from the Environment:
  191. Environment.).
  192.  
  193.    As a special feature, using the variable `MAKE' in the commands of a
  194. rule alters the effects of the `-t' (`--touch'), `-n' (`--just-print'),
  195. or `-q' (`--question') option.  Using the `MAKE' variable has the same
  196. effect as using a `+' character at the beginning of the command line.
  197. *Note Instead of Executing the Commands: Instead of Execution.
  198.  
  199.    Consider the command `make -t' in the above example.  (The `-t'
  200. option marks targets as up to date without actually running any
  201. commands; see *Note Instead of Execution::.)  Following the usual
  202. definition of `-t', a `make -t' command in the example would create a
  203. file named `subsystem' and do nothing else.  What you really want it to
  204. do is run `cd subdir; make -t'; but that would require executing the
  205. command, and `-t' says not to execute commands.
  206.  
  207.    The special feature makes this do what you want: whenever a command
  208. line of a rule contains the variable `MAKE', the flags `-t', `-n' and
  209. `-q' do not apply to that line.  Command lines containing `MAKE' are
  210. executed normally despite the presence of a flag that causes most
  211. commands not to be run.  The usual `MAKEFLAGS' mechanism passes the
  212. flags to the sub-`make' (*note Communicating Options to a Sub-`make':
  213. Options/Recursion.), so your request to touch the files, or print the
  214. commands, is propagated to the subsystem.
  215.  
  216. 
  217. File: make.info,  Node: Variables/Recursion,  Next: Options/Recursion,  Prev: MAKE Variable,  Up: Recursion
  218.  
  219. Communicating Variables to a Sub-`make'
  220. ---------------------------------------
  221.  
  222.    Variable values of the top-level `make' can be passed to the
  223. sub-`make' through the environment by explicit request.  These
  224. variables are defined in the sub-`make' as defaults, but do not
  225. override what is specified in the sub-`make''s makefile unless you use
  226. the `-e' switch (*note Summary of Options: Options Summary.).
  227.  
  228.    To pass down, or "export", a variable, `make' adds the variable and
  229. its value to the environment for running each command.  The sub-`make',
  230. in turn, uses the environment to initialize its table of variable
  231. values.  *Note Variables from the Environment: Environment.
  232.  
  233.    Except by explicit request, `make' exports a variable only if it is
  234. either defined in the environment initially or set on the command line,
  235. and if its name consists only of letters, numbers, and underscores.
  236. Some shells cannot cope with environment variable names consisting of
  237. characters other than letters, numbers, and underscores.
  238.  
  239.    The special variables `SHELL' and `MAKEFLAGS' are always exported
  240. (unless you unexport them).  `MAKEFILES' is exported if you set it to
  241. anything.
  242.  
  243.    Variables are *not* normally passed down if they were created by
  244. default by `make' (*note Variables Used by Implicit Rules: Implicit
  245. Variables.).  The sub-`make' will define these for itself.
  246.  
  247.    If you want to export specific variables to a sub-`make', use the
  248. `export' directive, like this:
  249.  
  250.      export VARIABLE ...
  251.  
  252. If you want to *prevent* a variable from being exported, use the
  253. `unexport' directive, like this:
  254.  
  255.      unexport VARIABLE ...
  256.  
  257. As a convenience, you can define a variable and export it at the same
  258. time by doing:
  259.  
  260.      export VARIABLE = value
  261.  
  262. has the same result as:
  263.  
  264.      VARIABLE = value
  265.      export VARIABLE
  266.  
  267. and
  268.  
  269.      export VARIABLE := value
  270.  
  271. has the same result as:
  272.  
  273.      VARIABLE := value
  274.      export VARIABLE
  275.  
  276.    Likewise,
  277.  
  278.      export VARIABLE += value
  279.  
  280. is just like:
  281.  
  282.      VARIABLE += value
  283.      export VARIABLE
  284.  
  285. *Note Appending More Text to Variables: Appending.
  286.  
  287.    You may notice that the `export' and `unexport' directives work in
  288. `make' in the same way they work in the shell, `sh'.
  289.  
  290.    If you want all variables to be exported by default, you can use
  291. `export' by itself:
  292.  
  293.      export
  294.  
  295. This tells `make' that variables which are not explicitly mentioned in
  296. an `export' or `unexport' directive should be exported.  Any variable
  297. given in an `unexport' directive will still *not* be exported.  If you
  298. use `export' by itself to export variables by default, variables whose
  299. names contain characters other than alphanumerics and underscores will
  300. not be exported unless specifically mentioned in an `export' directive.
  301.  
  302.    The behavior elicited by an `export' directive by itself was the
  303. default in older versions of GNU `make'.  If your makefiles depend on
  304. this behavior and you want to be compatible with old versions of
  305. `make', you can write a rule for the special target
  306. `.EXPORT_ALL_VARIABLES' instead of using the `export' directive.  This
  307. will be ignored by old `make's, while the `export' directive will cause
  308. a syntax error.
  309.  
  310.    Likewise, you can use `unexport' by itself to tell `make' *not* to
  311. export variables by default.  Since this is the default behavior, you
  312. would only need to do this if `export' had been used by itself earlier
  313. (in an included makefile, perhaps).  You *cannot* use `export' and
  314. `unexport' by themselves to have variables exported for some commands
  315. and not for others.  The last `export' or `unexport' directive that
  316. appears by itself determines the behavior for the entire run of `make'.
  317.  
  318.    As a special feature, the variable `MAKELEVEL' is changed when it is
  319. passed down from level to level.  This variable's value is a string
  320. which is the depth of the level as a decimal number.  The value is `0'
  321. for the top-level `make'; `1' for a sub-`make', `2' for a
  322. sub-sub-`make', and so on.  The incrementation happens when `make' sets
  323. up the environment for a command.
  324.  
  325.    The main use of `MAKELEVEL' is to test it in a conditional directive
  326. (*note Conditional Parts of Makefiles: Conditionals.); this way you can
  327. write a makefile that behaves one way if run recursively and another
  328. way if run directly by you.
  329.  
  330.    You can use the variable `MAKEFILES' to cause all sub-`make'
  331. commands to use additional makefiles.  The value of `MAKEFILES' is a
  332. whitespace-separated list of file names.  This variable, if defined in
  333. the outer-level makefile, is passed down through the environment; then
  334. it serves as a list of extra makefiles for the sub-`make' to read
  335. before the usual or specified ones.  *Note The Variable `MAKEFILES':
  336. MAKEFILES Variable.
  337.  
  338. 
  339. File: make.info,  Node: Options/Recursion,  Next: -w Option,  Prev: Variables/Recursion,  Up: Recursion
  340.  
  341. Communicating Options to a Sub-`make'
  342. -------------------------------------
  343.  
  344.    Flags such as `-s' and `-k' are passed automatically to the
  345. sub-`make' through the variable `MAKEFLAGS'.  This variable is set up
  346. automatically by `make' to contain the flag letters that `make'
  347. received.  Thus, if you do `make -ks' then `MAKEFLAGS' gets the value
  348. `ks'.
  349.  
  350.    As a consequence, every sub-`make' gets a value for `MAKEFLAGS' in
  351. its environment.  In response, it takes the flags from that value and
  352. processes them as if they had been given as arguments.  *Note Summary
  353. of Options: Options Summary.
  354.  
  355.    The options `-C', `-f', `-I', `-o', and `-W' are not put into
  356. `MAKEFLAGS'; these options are not passed down.
  357.  
  358.    The `-j' option is a special case (*note Parallel Execution:
  359. Parallel.).  If you set it to some numeric value, `-j 1' is always put
  360. into `MAKEFLAGS' instead of the value you specified.  This is because if
  361. the `-j' option were passed down to sub-`make's, you would get many
  362. more jobs running in parallel than you asked for.  If you give `-j'
  363. with no numeric argument, meaning to run as many jobs as possible in
  364. parallel, this is passed down, since multiple infinities are no more
  365. than one.
  366.  
  367.    If you do not want to pass the other flags down, you must change the
  368. value of `MAKEFLAGS', like this:
  369.  
  370.      MAKEFLAGS=
  371.      subsystem:
  372.              cd subdir; $(MAKE)
  373.  
  374.    or like this:
  375.  
  376.      subsystem:
  377.              cd subdir; $(MAKE) MAKEFLAGS=
  378.  
  379.    A similar variable `MFLAGS' exists also, for historical
  380. compatibility.  It has the same value as `MAKEFLAGS' except that it
  381. always begins with a hyphen unless it is empty (`MAKEFLAGS' begins with
  382. a hyphen only when it begins with an option that has no single-letter
  383. version, such as `--warn-undefined-variables').  `MFLAGS' was
  384. traditionally used explicitly in the recursive `make' command, like
  385. this:
  386.  
  387.      subsystem:
  388.              cd subdir; $(MAKE) $(MFLAGS)
  389.  
  390. but now `MAKEFLAGS' makes this usage redundant.
  391.  
  392.    The `MAKEFLAGS' and `MFLAGS' variables can also be useful if you
  393. want to have certain options, such as `-k' (*note Summary of Options:
  394. Options Summary.), set each time you run `make'.  You simply put a
  395. value for `MAKEFLAGS' or `MFLAGS' in your environment.  These variables
  396. may also be set in makefiles, so a makefile can specify additional
  397. flags that should also be in effect for that makefile.
  398.  
  399.    When `make' interprets the value of `MAKEFLAGS' or `MFLAGS' (either
  400. from the environment or from a makefile), it first prepends a hyphen if
  401. the value does not already begin with one.  Then it chops the value into
  402. words separated by blanks, and parses these words as if they were
  403. options given on the command line (except that `-C', `-f', `-h', `-o',
  404. `-W', and their long-named versions are ignored; and there is no error
  405. for an invalid option).
  406.  
  407.    If you do put `MAKEFLAGS' or `MFLAGS' in your environment, you
  408. should be sure not to include any options that will drastically affect
  409. the actions of `make' and undermine the purpose of makefiles and of
  410. `make' itself.  For instance, the `-t', `-n', and `-q' options, if put
  411. in one of these variables, could have disastrous consequences and would
  412. certainly have at least surprising and probably annoying effects.
  413.  
  414. 
  415. File: make.info,  Node: -w Option,  Prev: Options/Recursion,  Up: Recursion
  416.  
  417. The `--print-directory' Option
  418. ------------------------------
  419.  
  420.    If you use several levels of recursive `make' invocations, the `-w'
  421. or `--print-directory' option can make the output a lot easier to
  422. understand by showing each directory as `make' starts processing it and
  423. as `make' finishes processing it.  For example, if `make -w' is run in
  424. the directory `/u/gnu/make', `make' will print a line of the form:
  425.  
  426.      make: Entering directory `/u/gnu/make'.
  427.  
  428. before doing anything else, and a line of the form:
  429.  
  430.      make: Leaving directory `/u/gnu/make'.
  431.  
  432. when processing is completed.
  433.  
  434.    Normally, you do not need to specify this option because `make' does
  435. it for you: `-w' is turned on automatically when you use the `-C'
  436. option, and in sub-`make's.  `make' will not automatically turn on `-w'
  437. if you also use `-s', which says to be silent, or if you use
  438. `--no-print-directory' to explicitly disable it.
  439.  
  440. 
  441. File: make.info,  Node: Sequences,  Next: Empty Commands,  Prev: Recursion,  Up: Commands
  442.  
  443. Defining Canned Command Sequences
  444. =================================
  445.  
  446.    When the same sequence of commands is useful in making various
  447. targets, you can define it as a canned sequence with the `define'
  448. directive, and refer to the canned sequence from the rules for those
  449. targets.  The canned sequence is actually a variable, so the name must
  450. not conflict with other variable names.
  451.  
  452.    Here is an example of defining a canned sequence of commands:
  453.  
  454.      define run-yacc
  455.      yacc $(firstword $^)
  456.      mv y.tab.c $@
  457.      endef
  458.  
  459. Here `run-yacc' is the name of the variable being defined; `endef'
  460. marks the end of the definition; the lines in between are the commands.
  461. The `define' directive does not expand variable references and
  462. function calls in the canned sequence; the `$' characters, parentheses,
  463. variable names, and so on, all become part of the value of the variable
  464. you are defining.  *Note Defining Variables Verbatim: Defining, for a
  465. complete explanation of `define'.
  466.  
  467.    The first command in this example runs Yacc on the first dependency
  468. of whichever rule uses the canned sequence.  The output file from Yacc
  469. is always named `y.tab.c'.  The second command moves the output to the
  470. rule's target file name.
  471.  
  472.    To use the canned sequence, substitute the variable into the
  473. commands of a rule.  You can substitute it like any other variable
  474. (*note Basics of Variable References: Reference.).  Because variables
  475. defined by `define' are recursively expanded variables, all the
  476. variable references you wrote inside the `define' are expanded now.
  477. For example:
  478.  
  479.      foo.c : foo.y
  480.              $(run-yacc)
  481.  
  482. `foo.y' will be substituted for the variable `$^' when it occurs in
  483. `run-yacc''s value, and `foo.c' for `$@'.
  484.  
  485.    This is a realistic example, but this particular one is not needed in
  486. practice because `make' has an implicit rule to figure out these
  487. commands based on the file names involved (*note Using Implicit Rules:
  488. Implicit Rules.).
  489.  
  490.    In command execution, each line of a canned sequence is treated just
  491. as if the line appeared on its own in the rule, preceded by a tab.  In
  492. particular, `make' invokes a separate subshell for each line.  You can
  493. use the special prefix characters that affect command lines (`@', `-',
  494. and `+') on each line of a canned sequence.  *Note Writing the Commands
  495. in Rules: Commands.  For example, using this canned sequence:
  496.  
  497.      define frobnicate
  498.      @echo "frobnicating target $@"
  499.      frob-step-1 $< -o $@-step-1
  500.      frob-step-2 $@-step-1 -o $@
  501.      endef
  502.  
  503. `make' will not echo the first line, the `echo' command.  But it *will*
  504. echo the following two command lines.
  505.  
  506.    On the other hand, prefix characters on the command line that refers
  507. to a canned sequence apply to every line in the sequence.  So the rule:
  508.  
  509.      frob.out: frob.in
  510.          @$(frobnicate)
  511.  
  512. does not echo *any* commands.  (*Note Command Echoing: Echoing, for a
  513. full explanation of `@'.)
  514.  
  515. 
  516. File: make.info,  Node: Empty Commands,  Prev: Sequences,  Up: Commands
  517.  
  518. Using Empty Commands
  519. ====================
  520.  
  521.    It is sometimes useful to define commands which do nothing.  This is
  522. done simply by giving a command that consists of nothing but
  523. whitespace.  For example:
  524.  
  525.      target: ;
  526.  
  527. defines an empty command string for `target'.  You could also use a
  528. line beginning with a tab character to define an empty command string,
  529. but this would be confusing because such a line looks empty.
  530.  
  531.    You may be wondering why you would want to define a command string
  532. that does nothing.  The only reason this is useful is to prevent a
  533. target from getting implicit commands (from implicit rules or the
  534. `.DEFAULT' special target; *note Implicit Rules::. and *note Defining
  535. Last-Resort Default Rules: Last Resort.).
  536.  
  537.    You may be inclined to define empty command strings for targets that
  538. are not actual files, but only exist so that their dependencies can be
  539. remade.  However, this is not the best way to do that, because the
  540. dependencies may not be remade properly if the target file actually
  541. does exist.  *Note Phony Targets: Phony Targets, for a better way to do
  542. this.
  543.  
  544. 
  545. File: make.info,  Node: Using Variables,  Next: Conditionals,  Prev: Commands,  Up: Top
  546.  
  547. How to Use Variables
  548. ********************
  549.  
  550.    A "variable" is a name defined in a makefile to represent a string
  551. of text, called the variable's "value".  These values are substituted
  552. by explicit request into targets, dependencies, commands, and other
  553. parts of the makefile.  (In some other versions of `make', variables
  554. are called "macros".)
  555.  
  556.    Variables and functions in all parts of a makefile are expanded when
  557. read, except for the shell commands in rules, the right-hand sides of
  558. variable definitions using `=', and the bodies of variable definitions
  559. using the `define' directive.
  560.  
  561.    Variables can represent lists of file names, options to pass to
  562. compilers, programs to run, directories to look in for source files,
  563. directories to write output in, or anything else you can imagine.
  564.  
  565.    A variable name may be any sequence of characters not containing `:',
  566. `#', `=', or leading or trailing whitespace.  However, variable names
  567. containing characters other than letters, numbers, and underscores
  568. should be avoided, as they may be given special meanings in the future,
  569. and with some shells they cannot be passed through the environment to a
  570. sub-`make' (*note Communicating Variables to a Sub-`make':
  571. Variables/Recursion.).
  572.  
  573.    Variable names are case-sensitive.  The names `foo', `FOO', and
  574. `Foo' all refer to different variables.
  575.  
  576.    It is traditional to use upper case letters in variable names, but we
  577. recommend using lower case letters for variable names that serve
  578. internal purposes in the makefile, and reserving upper case for
  579. parameters that control implicit rules or for parameters that the user
  580. should override with command options (*note Overriding Variables:
  581. Overriding.).
  582.  
  583. * Menu:
  584.  
  585. * Reference::                   How to use the value of a variable.
  586. * Flavors::                     Variables come in two flavors.
  587. * Advanced::                    Advanced features for referencing a variable.
  588. * Values::                      All the ways variables get their values.
  589. * Setting::                     How to set a variable in the makefile.
  590. * Appending::                   How to append more text to the old value
  591.                                   of a variable.
  592. * Override Directive::          How to set a variable in the makefile even if
  593.                                   the user has set it with a command argument.
  594. * Defining::                    An alternate way to set a variable
  595.                                   to a verbatim string.
  596. * Environment::                 Variable values can come from the environment.
  597.  
  598. 
  599. File: make.info,  Node: Reference,  Next: Flavors,  Up: Using Variables
  600.  
  601. Basics of Variable References
  602. =============================
  603.  
  604.    To substitute a variable's value, write a dollar sign followed by
  605. the name of the variable in parentheses or braces: either `$(foo)' or
  606. `${foo}' is a valid reference to the variable `foo'.  This special
  607. significance of `$' is why you must write `$$' to have the effect of a
  608. single dollar sign in a file name or command.
  609.  
  610.    Variable references can be used in any context: targets,
  611. dependencies, commands, most directives, and new variable values.  Here
  612. is an example of a common case, where a variable holds the names of all
  613. the object files in a program:
  614.  
  615.      objects = program.o foo.o utils.o
  616.      program : $(objects)
  617.              cc -o program $(objects)
  618.      
  619.      $(objects) : defs.h
  620.  
  621.    Variable references work by strict textual substitution.  Thus, the
  622. rule
  623.  
  624.      foo = c
  625.      prog.o : prog.$(foo)
  626.              $(foo)$(foo) -$(foo) prog.$(foo)
  627.  
  628. could be used to compile a C program `prog.c'.  Since spaces before the
  629. variable value are ignored in variable assignments, the value of `foo'
  630. is precisely `c'.  (Don't actually write your makefiles this way!)
  631.  
  632.    A dollar sign followed by a character other than a dollar sign,
  633. open-parenthesis or open-brace treats that single character as the
  634. variable name.  Thus, you could reference the variable `x' with `$x'.
  635. However, this practice is strongly discouraged, except in the case of
  636. the automatic variables (*note Automatic Variables: Automatic.).
  637.  
  638. 
  639. File: make.info,  Node: Flavors,  Next: Advanced,  Prev: Reference,  Up: Using Variables
  640.  
  641. The Two Flavors of Variables
  642. ============================
  643.  
  644.    There are two ways that a variable in GNU `make' can have a value;
  645. we call them the two "flavors" of variables.  The two flavors are
  646. distinguished in how they are defined and in what they do when expanded.
  647.  
  648.    The first flavor of variable is a "recursively expanded" variable.
  649. Variables of this sort are defined by lines using `=' (*note Setting
  650. Variables: Setting.) or by the `define' directive (*note Defining
  651. Variables Verbatim: Defining.).  The value you specify is installed
  652. verbatim; if it contains references to other variables, these
  653. references are expanded whenever this variable is substituted (in the
  654. course of expanding some other string).  When this happens, it is
  655. called "recursive expansion".
  656.  
  657.    For example,
  658.  
  659.      foo = $(bar)
  660.      bar = $(ugh)
  661.      ugh = Huh?
  662.      
  663.      all:;echo $(foo)
  664.  
  665. will echo `Huh?': `$(foo)' expands to `$(bar)' which expands to
  666. `$(ugh)' which finally expands to `Huh?'.
  667.  
  668.    This flavor of variable is the only sort supported by other versions
  669. of `make'.  It has its advantages and its disadvantages.  An advantage
  670. (most would say) is that:
  671.  
  672.      CFLAGS = $(include_dirs) -O
  673.      include_dirs = -Ifoo -Ibar
  674.  
  675. will do what was intended: when `CFLAGS' is expanded in a command, it
  676. will expand to `-Ifoo -Ibar -O'.  A major disadvantage is that you
  677. cannot append something on the end of a variable, as in
  678.  
  679.      CFLAGS = $(CFLAGS) -O
  680.  
  681. because it will cause an infinite loop in the variable expansion.
  682. (Actually `make' detects the infinite loop and reports an error.)
  683.  
  684.    Another disadvantage is that any functions (*note Functions for
  685. Transforming Text: Functions.) referenced in the definition will be
  686. executed every time the variable is expanded.  This makes `make' run
  687. slower; worse, it causes the `wildcard' and `shell' functions to give
  688. unpredictable results because you cannot easily control when they are
  689. called, or even how many times.
  690.  
  691.    To avoid all the problems and inconveniences of recursively expanded
  692. variables, there is another flavor: simply expanded variables.
  693.  
  694.    "Simply expanded variables" are defined by lines using `:=' (*note
  695. Setting Variables: Setting.).  The value of a simply expanded variable
  696. is scanned once and for all, expanding any references to other
  697. variables and functions, when the variable is defined.  The actual
  698. value of the simply expanded variable is the result of expanding the
  699. text that you write.  It does not contain any references to other
  700. variables; it contains their values *as of the time this variable was
  701. defined*.  Therefore,
  702.  
  703.      x := foo
  704.      y := $(x) bar
  705.      x := later
  706.  
  707. is equivalent to
  708.  
  709.      y := foo bar
  710.      x := later
  711.  
  712.    When a simply expanded variable is referenced, its value is
  713. substituted verbatim.
  714.  
  715.    Here is a somewhat more complicated example, illustrating the use of
  716. `:=' in conjunction with the `shell' function.  (*Note The `shell'
  717. Function: Shell Function.)  This example also shows use of the variable
  718. `MAKELEVEL', which is changed when it is passed down from level to
  719. level.  (*Note Communicating Variables to a Sub-`make':
  720. Variables/Recursion, for information about `MAKELEVEL'.)
  721.  
  722.      ifeq (0,${MAKELEVEL})
  723.      cur-dir   := $(shell pwd)
  724.      whoami    := $(shell whoami)
  725.      host-type := $(shell arch)
  726.      MAKE := ${MAKE} host-type=${host-type} whoami=${whoami}
  727.      endif
  728.  
  729. An advantage of this use of `:=' is that a typical `descend into a
  730. directory' command then looks like this:
  731.  
  732.      ${subdirs}:
  733.            ${MAKE} cur-dir=${cur-dir}/$@ -C $@ all
  734.  
  735.    Simply expanded variables generally make complicated makefile
  736. programming more predictable because they work like variables in most
  737. programming languages.  They allow you to redefine a variable using its
  738. own value (or its value processed in some way by one of the expansion
  739. functions) and to use the expansion functions much more efficiently
  740. (*note Functions for Transforming Text: Functions.).
  741.  
  742.    You can also use them to introduce controlled leading whitespace into
  743. variable values.  Leading whitespace characters are discarded from your
  744. input before substitution of variable references and function calls;
  745. this means you can include leading spaces in a variable value by
  746. protecting them with variable references, like this:
  747.  
  748.      nullstring :=
  749.      space := $(nullstring) # end of the line
  750.  
  751. Here the value of the variable `space' is precisely one space.  The
  752. comment `# end of the line' is included here just for clarity.  Since
  753. trailing space characters are *not* stripped from variable values, just
  754. a space at the end of the line would have the same effect (but be
  755. rather hard to read).  If you put whitespace at the end of a variable
  756. value, it is a good idea to put a comment like that at the end of the
  757. line to make your intent clear.  Conversely, if you do *not* want any
  758. whitespace characters at the end of your variable value, you must
  759. remember not to put a random comment on the end of the line after some
  760. whitespace, such as this:
  761.  
  762.      dir := /foo/bar    # directory to put the frobs in
  763.  
  764. Here the value of the variable `dir' is `/foo/bar    ' (with four
  765. trailing spaces), which was probably not the intention.  (Imagine
  766. something like `$(dir)/file' with this definition!)
  767.  
  768. 
  769. File: make.info,  Node: Advanced,  Next: Values,  Prev: Flavors,  Up: Using Variables
  770.  
  771. Advanced Features for Reference to Variables
  772. ============================================
  773.  
  774.    This section describes some advanced features you can use to
  775. reference variables in more flexible ways.
  776.  
  777. * Menu:
  778.  
  779. * Substitution Refs::           Referencing a variable with
  780.                                   substitutions on the value.
  781. * Computed Names::              Computing the name of the variable to refer to.
  782.  
  783. 
  784. File: make.info,  Node: Substitution Refs,  Next: Computed Names,  Up: Advanced
  785.  
  786. Substitution References
  787. -----------------------
  788.  
  789.    A "substitution reference" substitutes the value of a variable with
  790. alterations that you specify.  It has the form `$(VAR:A=B)' (or
  791. `${VAR:A=B}') and its meaning is to take the value of the variable VAR,
  792. replace every A at the end of a word with B in that value, and
  793. substitute the resulting string.
  794.  
  795.    When we say "at the end of a word", we mean that A must appear
  796. either followed by whitespace or at the end of the value in order to be
  797. replaced; other occurrences of A in the value are unaltered.  For
  798. example:
  799.  
  800.      foo := a.o b.o c.o
  801.      bar := $(foo:.o=.c)
  802.  
  803. sets `bar' to `a.c b.c c.c'.  *Note Setting Variables: Setting.
  804.  
  805.    A substitution reference is actually an abbreviation for use of the
  806. `patsubst' expansion function (*note Functions for String Substitution
  807. and Analysis: Text Functions.).  We provide substitution references as
  808. well as `patsubst' for compatibility with other implementations of
  809. `make'.
  810.  
  811.    Another type of substitution reference lets you use the full power of
  812. the `patsubst' function.  It has the same form `$(VAR:A=B)' described
  813. above, except that now A must contain a single `%' character.  This
  814. case is equivalent to `$(patsubst A,B,$(VAR))'.  *Note Functions for
  815. String Substitution and Analysis: Text Functions, for a description of
  816. the `patsubst' function.
  817.  
  818. For example:
  819.  
  820.      foo := a.o b.o c.o
  821.      bar := $(foo:%.o=%.c)
  822.  
  823. sets `bar' to `a.c b.c c.c'.
  824.  
  825. 
  826. File: make.info,  Node: Computed Names,  Prev: Substitution Refs,  Up: Advanced
  827.  
  828. Computed Variable Names
  829. -----------------------
  830.  
  831.    Computed variable names are a complicated concept needed only for
  832. sophisticated makefile programming.  For most purposes you need not
  833. consider them, except to know that making a variable with a dollar sign
  834. in its name might have strange results.  However, if you are the type
  835. that wants to understand everything, or you are actually interested in
  836. what they do, read on.
  837.  
  838.    Variables may be referenced inside the name of a variable.  This is
  839. called a "computed variable name" or a "nested variable reference".
  840. For example,
  841.  
  842.      x = y
  843.      y = z
  844.      a := $($(x))
  845.  
  846. defines `a' as `z': the `$(x)' inside `$($(x))' expands to `y', so
  847. `$($(x))' expands to `$(y)' which in turn expands to `z'.  Here the
  848. name of the variable to reference is not stated explicitly; it is
  849. computed by expansion of `$(x)'.  The reference `$(x)' here is nested
  850. within the outer variable reference.
  851.  
  852.    The previous example shows two levels of nesting, but any number of
  853. levels is possible.  For example, here are three levels:
  854.  
  855.      x = y
  856.      y = z
  857.      z = u
  858.      a := $($($(x)))
  859.  
  860. Here the innermost `$(x)' expands to `y', so `$($(x))' expands to
  861. `$(y)' which in turn expands to `z'; now we have `$(z)', which becomes
  862. `u'.
  863.  
  864.    References to recursively-expanded variables within a variable name
  865. are reexpanded in the usual fashion.  For example:
  866.  
  867.      x = $(y)
  868.      y = z
  869.      z = Hello
  870.      a := $($(x))
  871.  
  872. defines `a' as `Hello': `$($(x))' becomes `$($(y))' which becomes
  873. `$(z)' which becomes `Hello'.
  874.  
  875.    Nested variable references can also contain modified references and
  876. function invocations (*note Functions for Transforming Text:
  877. Functions.), just like any other reference.  For example, using the
  878. `subst' function (*note Functions for String Substitution and Analysis:
  879. Text Functions.):
  880.  
  881.      x = variable1
  882.      variable2 := Hello
  883.      y = $(subst 1,2,$(x))
  884.      z = y
  885.      a := $($($(z)))
  886.  
  887. eventually defines `a' as `Hello'.  It is doubtful that anyone would
  888. ever want to write a nested reference as convoluted as this one, but it
  889. works: `$($($(z)))' expands to `$($(y))' which becomes `$($(subst
  890. 1,2,$(x)))'.  This gets the value `variable1' from `x' and changes it
  891. by substitution to `variable2', so that the entire string becomes
  892. `$(variable2)', a simple variable reference whose value is `Hello'.
  893.  
  894.    A computed variable name need not consist entirely of a single
  895. variable reference.  It can contain several variable references, as
  896. well as some invariant text.  For example,
  897.  
  898.      a_dirs := dira dirb
  899.      1_dirs := dir1 dir2
  900.      
  901.      a_files := filea fileb
  902.      1_files := file1 file2
  903.      
  904.      ifeq "$(use_a)" "yes"
  905.      a1 := a
  906.      else
  907.      a1 := 1
  908.      endif
  909.      
  910.      ifeq "$(use_dirs)" "yes"
  911.      df := dirs
  912.      else
  913.      df := files
  914.      endif
  915.      
  916.      dirs := $($(a1)_$(df))
  917.  
  918. will give `dirs' the same value as `a_dirs', `1_dirs', `a_files' or
  919. `1_files' depending on the settings of `use_a' and `use_dirs'.
  920.  
  921.    Computed variable names can also be used in substitution references:
  922.  
  923.      a_objects := a.o b.o c.o
  924.      1_objects := 1.o 2.o 3.o
  925.      
  926.      sources := $($(a1)_objects:.o=.c)
  927.  
  928. defines `sources' as either `a.c b.c c.c' or `1.c 2.c 3.c', depending
  929. on the value of `a1'.
  930.  
  931.    The only restriction on this sort of use of nested variable
  932. references is that they cannot specify part of the name of a function
  933. to be called.  This is because the test for a recognized function name
  934. is done before the expansion of nested references.  For example,
  935.  
  936.      ifdef do_sort
  937.      func := sort
  938.      else
  939.      func := strip
  940.      endif
  941.      
  942.      bar := a d b g q c
  943.      
  944.      foo := $($(func) $(bar))
  945.  
  946. attempts to give `foo' the value of the variable `sort a d b g q c' or
  947. `strip a d b g q c', rather than giving `a d b g q c' as the argument
  948. to either the `sort' or the `strip' function.  This restriction could
  949. be removed in the future if that change is shown to be a good idea.
  950.  
  951.    You can also use computed variable names in the left-hand side of a
  952. variable assignment, or in a `define' directive, as in:
  953.  
  954.      dir = foo
  955.      $(dir)_sources := $(wildcard $(dir)/*.c)
  956.      define $(dir)_print
  957.      lpr $($(dir)_sources)
  958.      endef
  959.  
  960. This example defines the variables `dir', `foo_sources', and
  961. `foo_print'.
  962.  
  963.    Note that "nested variable references" are quite different from
  964. "recursively expanded variables" (*note The Two Flavors of Variables:
  965. Flavors.), though both are used together in complex ways when doing
  966. makefile programming.
  967.  
  968. 
  969. File: make.info,  Node: Values,  Next: Setting,  Prev: Advanced,  Up: Using Variables
  970.  
  971. How Variables Get Their Values
  972. ==============================
  973.  
  974.    Variables can get values in several different ways:
  975.  
  976.    * You can specify an overriding value when you run `make'.  *Note
  977.      Overriding Variables: Overriding.
  978.  
  979.    * You can specify a value in the makefile, either with an assignment
  980.      (*note Setting Variables: Setting.) or with a verbatim definition
  981.      (*note Defining Variables Verbatim: Defining.).
  982.  
  983.    * Variables in the environment become `make' variables.  *Note
  984.      Variables from the Environment: Environment.
  985.  
  986.    * Several "automatic" variables are given new values for each rule.
  987.      Each of these has a single conventional use.  *Note Automatic
  988.      Variables: Automatic.
  989.  
  990.    * Several variables have constant initial values.  *Note Variables
  991.      Used by Implicit Rules: Implicit Variables.
  992.  
  993. 
  994. File: make.info,  Node: Setting,  Next: Appending,  Prev: Values,  Up: Using Variables
  995.  
  996. Setting Variables
  997. =================
  998.  
  999.    To set a variable from the makefile, write a line starting with the
  1000. variable name followed by `=' or `:='.  Whatever follows the `=' or
  1001. `:=' on the line becomes the value.  For example,
  1002.  
  1003.      objects = main.o foo.o bar.o utils.o
  1004.  
  1005. defines a variable named `objects'.  Whitespace around the variable
  1006. name and immediately after the `=' is ignored.
  1007.  
  1008.    Variables defined with `=' are "recursively expanded" variables.
  1009. Variables defined with `:=' are "simply expanded" variables; these
  1010. definitions can contain variable references which will be expanded
  1011. before the definition is made.  *Note The Two Flavors of Variables:
  1012. Flavors.
  1013.  
  1014.    The variable name may contain function and variable references, which
  1015. are expanded when the line is read to find the actual variable name to
  1016. use.
  1017.  
  1018.    There is no limit on the length of the value of a variable except the
  1019. amount of swapping space on the computer.  When a variable definition is
  1020. long, it is a good idea to break it into several lines by inserting
  1021. backslash-newline at convenient places in the definition.  This will not
  1022. affect the functioning of `make', but it will make the makefile easier
  1023. to read.
  1024.  
  1025.    Most variable names are considered to have the empty string as a
  1026. value if you have never set them.  Several variables have built-in
  1027. initial values that are not empty, but you can set them in the usual
  1028. ways (*note Variables Used by Implicit Rules: Implicit Variables.).
  1029. Several special variables are set automatically to a new value for each
  1030. rule; these are called the "automatic" variables (*note Automatic
  1031. Variables: Automatic.).
  1032.  
  1033. 
  1034. File: make.info,  Node: Appending,  Next: Override Directive,  Prev: Setting,  Up: Using Variables
  1035.  
  1036. Appending More Text to Variables
  1037. ================================
  1038.  
  1039.    Often it is useful to add more text to the value of a variable
  1040. already defined.  You do this with a line containing `+=', like this:
  1041.  
  1042.      objects += another.o
  1043.  
  1044. This takes the value of the variable `objects', and adds the text
  1045. `another.o' to it (preceded by a single space).  Thus:
  1046.  
  1047.      objects = main.o foo.o bar.o utils.o
  1048.      objects += another.o
  1049.  
  1050. sets `objects' to `main.o foo.o bar.o utils.o another.o'.
  1051.  
  1052.    Using `+=' is similar to:
  1053.  
  1054.      objects = main.o foo.o bar.o utils.o
  1055.      objects := $(objects) another.o
  1056.  
  1057. but differs in ways that become important when you use more complex
  1058. values.
  1059.  
  1060.    When the variable in question has not been defined before, `+=' acts
  1061. just like normal `=': it defines a recursively-expanded variable.
  1062. However, when there *is* a previous definition, exactly what `+=' does
  1063. depends on what flavor of variable you defined originally.  *Note The
  1064. Two Flavors of Variables: Flavors, for an explanation of the two
  1065. flavors of variables.
  1066.  
  1067.    When you add to a variable's value with `+=', `make' acts
  1068. essentially as if you had included the extra text in the initial
  1069. definition of the variable.  If you defined it first with `:=', making
  1070. it a simply-expanded variable, `+=' adds to that simply-expanded
  1071. definition, and expands the new text before appending it to the old
  1072. value just as `:=' does (*note Setting Variables: Setting., for a full
  1073. explanation of `:=').  In fact,
  1074.  
  1075.      variable := value
  1076.      variable += more
  1077.  
  1078. is exactly equivalent to:
  1079.  
  1080.      variable := value
  1081.      variable := $(variable) more
  1082.  
  1083.    On the other hand, when you use `+=' with a variable that you defined
  1084. first to be recursively-expanded using plain `=', `make' does something
  1085. a bit different.  Recall that when you define a recursively-expanded
  1086. variable, `make' does not expand the value you set for variable and
  1087. function references immediately.  Instead it stores the text verbatim,
  1088. and saves these variable and function references to be expanded later,
  1089. when you refer to the new variable (*note The Two Flavors of Variables:
  1090. Flavors.).  When you use `+=' on a recursively-expanded variable, it is
  1091. this unexpanded text to which `make' appends the new text you specify.
  1092.  
  1093.      variable = value
  1094.      variable += more
  1095.  
  1096. is roughly equivalent to:
  1097.  
  1098.      temp = value
  1099.      variable = $(temp) more
  1100.  
  1101. except that of course it never defines a variable called `temp'.  The
  1102. importance of this comes when the variable's old value contains
  1103. variable references.  Take this common example:
  1104.  
  1105.      CFLAGS = $(includes) -O
  1106.      ...
  1107.      CFLAGS += -pg # enable profiling
  1108.  
  1109. The first line defines the `CFLAGS' variable with a reference to another
  1110. variable, `includes'.  (`CFLAGS' is used by the rules for C
  1111. compilation; *note Catalogue of Implicit Rules: Catalogue of Rules..)
  1112. Using `=' for the definition makes `CFLAGS' a recursively-expanded
  1113. variable, meaning `$(includes) -O' is *not* expanded when `make'
  1114. processes the definition of `CFLAGS'.  Thus, `includes' need not be
  1115. defined yet for its value to take effect.  It only has to be defined
  1116. before any reference to `CFLAGS'.  If we tried to append to the value
  1117. of `CFLAGS' without using `+=', we might do it like this:
  1118.  
  1119.      CFLAGS := $(CFLAGS) -pg # enable profiling
  1120.  
  1121. This is pretty close, but not quite what we want.  Using `:=' redefines
  1122. `CFLAGS' as a simply-expanded variable; this means `make' expands the
  1123. text `$(CFLAGS) -pg' before setting the variable.  If `includes' is not
  1124. yet defined, we get ` -O -pg', and a later definition of `includes'
  1125. will have no effect.  Conversely, by using `+=' we set `CFLAGS' to the
  1126. *unexpanded* value `$(includes) -O -pg'.  Thus we preserve the
  1127. reference to `includes', so if that variable gets defined at any later
  1128. point, a reference like `$(CFLAGS)' still uses its value.
  1129.  
  1130. 
  1131. File: make.info,  Node: Override Directive,  Next: Defining,  Prev: Appending,  Up: Using Variables
  1132.  
  1133. The `override' Directive
  1134. ========================
  1135.  
  1136.    If a variable has been set with a command argument (*note Overriding
  1137. Variables: Overriding.), then ordinary assignments in the makefile are
  1138. ignored.  If you want to set the variable in the makefile even though
  1139. it was set with a command argument, you can use an `override'
  1140. directive, which is a line that looks like this:
  1141.  
  1142.      override VARIABLE = VALUE
  1143.  
  1144. or
  1145.  
  1146.      override VARIABLE := VALUE
  1147.  
  1148.    To append more text to a variable defined on the command line, use:
  1149.  
  1150.      override VARIABLE += MORE TEXT
  1151.  
  1152. *Note Appending More Text to Variables: Appending.
  1153.  
  1154.    The `override' directive was not invented for escalation in the war
  1155. between makefiles and command arguments.  It was invented so you can
  1156. alter and add to values that the user specifies with command arguments.
  1157.  
  1158.    For example, suppose you always want the `-g' switch when you run the
  1159. C compiler, but you would like to allow the user to specify the other
  1160. switches with a command argument just as usual.  You could use this
  1161. `override' directive:
  1162.  
  1163.      override CFLAGS += -g
  1164.  
  1165.    You can also use `override' directives with `define' directives.
  1166. This is done as you might expect:
  1167.  
  1168.      override define foo
  1169.      bar
  1170.      endef
  1171.  
  1172. *Note Defining Variables Verbatim: Defining.
  1173.  
  1174. 
  1175. File: make.info,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Using Variables
  1176.  
  1177. Defining Variables Verbatim
  1178. ===========================
  1179.  
  1180. Another way to set the value of a variable is to use the `define'
  1181. directive.  This directive has an unusual syntax which allows newline
  1182. characters to be included in the value, which is convenient for defining
  1183. canned sequences of commands (*note Defining Canned Command Sequences:
  1184. Sequences.).
  1185.  
  1186.    The `define' directive is followed on the same line by the name of
  1187. the variable and nothing more.  The value to give the variable appears
  1188. on the following lines.  The end of the value is marked by a line
  1189. containing just the word `endef'.  Aside from this difference in
  1190. syntax, `define' works just like `=': it creates a recursively-expanded
  1191. variable (*note The Two Flavors of Variables: Flavors.).  The variable
  1192. name may contain function and variable references, which are expanded
  1193. when the directive is read to find the actual variable name to use.
  1194.  
  1195.      define two-lines
  1196.      echo foo
  1197.      echo $(bar)
  1198.      endef
  1199.  
  1200.    The value in an ordinary assignment cannot contain a newline; but the
  1201. newlines that separate the lines of the value in a `define' become part
  1202. of the variable's value (except for the final newline which precedes
  1203. the `endef' and is not considered part of the value).
  1204.  
  1205.    The previous example is functionally equivalent to this:
  1206.  
  1207.      two-lines = echo foo; echo $(bar)
  1208.  
  1209. since two commands separated by semicolon behave much like two separate
  1210. shell commands.  However, note that using two separate lines means
  1211. `make' will invoke the shell twice, running an independent subshell for
  1212. each line.  *Note Command Execution: Execution.
  1213.  
  1214.    If you want variable definitions made with `define' to take
  1215. precedence over command-line variable definitions, you can use the
  1216. `override' directive together with `define':
  1217.  
  1218.      override define two-lines
  1219.      foo
  1220.      $(bar)
  1221.      endef
  1222.  
  1223. *Note The `override' Directive: Override Directive.
  1224.  
  1225.