home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 318 / utilsrc / make-2 < prev    next >
Encoding:
Text File  |  1988-10-20  |  48.5 KB  |  1,204 lines

  1.  
  2. File: make,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
  3.  
  4. Multiple Targets in a Rule
  5. ==========================
  6.  
  7. A rule with multiple targets is equivalent to writing many rules, each with
  8. one target, and all identical aside from that.  The same commands apply to
  9. all the targets, but their effects may vary because you can substitute the
  10. actual target name into the command using `$@'.  The rule contributes the
  11. same dependencies to all the targets also.
  12.  
  13. This is useful in two cases.
  14.  
  15.    * You want just dependencies, no commands.  For example:
  16.  
  17.           kbd.o commands.o files.o: command.h
  18.  
  19.      gives an additional dependency to each of the three object files
  20.      mentioned.
  21.  
  22.    * Similar commands work for all the targets.  The commands do not need
  23.      to be absolutely identical, since the automatic variable `$@' can be
  24.      used to substitute the particular target to be remade into the
  25.      commands (*Note Automatic::.).  For example:
  26.  
  27.           bigoutput littleoutput : text.g
  28.                   generate text.g -$(subst output,,$@) > $@
  29.  
  30.      is equivalent to
  31.  
  32.           bigoutput : text.g
  33.                   generate text.g -big > bigoutput
  34.           littleoutput : text.g
  35.                   generate text.g -little > littleoutput
  36.  
  37.      Here we assume the hypothetical program `generate' makes two types of
  38.      output, one if given `-big' and one if given `-little'.
  39.  
  40. Suppose you would like to vary the dependencies according to the target,
  41. much as the variable `$@' allows you to vary the commands.  You cannot do
  42. this with multiple targets in an ordinary rule, but you can do it with a
  43. "static pattern rule".  *note Static Pattern::.
  44.  
  45. File: make,  Node: Static Pattern,  Next: Multiple Rules,  Prev: Multiple Targets,  Up: Rules
  46.  
  47. Static Pattern Rules
  48. ====================
  49.  
  50. "Static pattern rules" are rules which specify multiple targets and
  51. construct the dependency names for each target based on the target name. 
  52. They are more general than ordinary rules with multiple targets because the
  53. targets don't have to have identical dependencies.  Their dependencies must
  54. be *analogous*, but not necessarily *identical*.
  55.  
  56. * Menu:
  57.  
  58. * Usage: Static Usage.    How to use static pattern rules.
  59. * Static vs Implicit::  When are they better than implicit rules?
  60.  
  61.  
  62. File: make,  Node: Static Usage,  Next: Static vs Implicit,  Prev: Static Pattern,  Up: Static Pattern
  63.  
  64. Syntax of Static Pattern Rules
  65. ------------------------------
  66.  
  67. Here is the syntax of a static pattern rule:
  68.  
  69.      TARGETS: TARGET-PATTERN: DEP-PATTERNS ...
  70.              COMMANDS
  71.              ...
  72.  
  73.  The TARGETS gives the list of targets that the rule applies to.  The
  74. targets can contain wildcard characters, just like the targets of ordinary
  75. rules (*Note Wildcards::.).
  76.  
  77. The TARGET-PATTERN and DEP-PATTERNS say how to compute the dependencies of
  78. each target.  Each target is matched against the TARGET-PATTERN to extract
  79. a part of the target name, called the "stem".  This stem is substituted
  80. into each of the DEP-PATTERNS to make the dependency names (one from each
  81. DEP-PATTERN).
  82.  
  83. Each pattern normally contains the character `%' just once.  When the
  84. TARGET-PATTERN matches a target, the `%' can match any part of the target
  85. name; this part is called the "stem".  The rest of the pattern must match
  86. exactly.  For example, the target `foo.o' matches the pattern `%.o', with
  87. `foo' as the stem.  The targets `foo.c' and `foo.out' don't match that
  88. pattern.
  89.  
  90. The dependency names for each target are made by substituting the stem for
  91. the `%' in each dependency pattern.  For example, if one dependency pattern
  92. is `%.c', then substitution of the stem `foo' gives the dependency name
  93. `foo.c'.  It is fine to write a dependency pattern that doesn't contain
  94. `%'; then this dependency is the same for all targets.
  95.  
  96. Here is an example, which compiles each of `foo.o' and `bar.o' from the
  97. corresponding `.c' file:
  98.  
  99.      objects := foo.o bar.o
  100.      
  101.      $(objects): %.o: %.c
  102.              $(CC) -c $(CFLAGS) $< -o $@
  103.  
  104. Each target specified must match the target pattern; a warning is issued
  105. for each that does not.  If you have a list of files, only some of which
  106. will match the pattern, you can use the `filter' function to remove
  107. nonmatching filenames (*Note Text Functions::.):
  108.  
  109.      files := foo.elc bar.o
  110.      
  111.      $(filter %.o,$(files)): %.o: %.c
  112.              $(CC) -c $(CFLAGS) $< -o $@
  113.      $(filter %.elc,$(files)): %.elc: %.el
  114.              emacs -f batch-byte-compile $<
  115.  
  116. Here the result of `$(filter %.o,$(files))' is just `bar.o', and the first
  117. static pattern rule causes it to be made from `bar.c'.  The result of
  118. `$(filter %.elc,$(files))' is `foo.elc', which is made from `foo.el'.
  119.  
  120. File: make,  Node: Static vs Implicit,  Prev: Static Usage,  Up: Static Pattern
  121.  
  122. Static Pattern Rules versus Implicit Rules
  123. ------------------------------------------
  124.  
  125. A static pattern rule has much in common with an implicit rule defined as a
  126. pattern rule (*Note Pattern Rules::.).  Both have a pattern for the target
  127. and patterns for constructing the names of dependencies.  The difference is
  128. in how `make' decides *when* the rule applies.
  129.  
  130. An implicit rule *can* apply to any target that matches its pattern, but it
  131. *does* apply only when the target has no commands otherwise specified, and
  132. only when the dependencies can be found.  If more than one implicit rule
  133. appears applicable, only one applies; the choice depends on the order of
  134. rules.
  135.  
  136. By contrast, a static pattern rule applies to the precise list of targets
  137. that you specify in the rule.  It cannot apply to any other target and it
  138. invariably does apply to each of the targets specified.  If two conflicting
  139. rules apply, and both have commands, that's an error.
  140.  
  141. The static pattern rule can be better than an implicit rule for these
  142. reasons:
  143.  
  144.    * You may wish to override the usual implicit rule for a few files whose
  145.      names cannot be categorized syntactically but can be given in an
  146.      explicit list.
  147.  
  148.    * If you cannot be sure of the precise contents of the directories you
  149.      are using, you may not be sure which other irrelevant files might lead
  150.      `make' to use the wrong implicit rule.  The choice might depend on the
  151.      order in which the implicit rule search is done.  With static pattern
  152.      rules, there is no uncertainty: each rule applies to precisely the
  153.      targets specified.
  154.  
  155. File: make,  Node: Multiple Rules,  Next: Double-Colon,  Prev: Static Pattern,  Up: Rules
  156.  
  157. Multiple Rules for One Target
  158. =============================
  159.  
  160. One file can be the target of several rules if at most one rule has commands.
  161.  The other rules can only have dependencies.  All the dependencies
  162. mentioned in all the rules are merged into one list of dependencies for the
  163. target.  If the target is older than any dependency from any rule, the
  164. commands are executed.
  165.  
  166. An extra rule with just dependencies can be used to give a few extra
  167. dependencies to many files at once.  For example, one usually has a
  168. variable named `objects' containing a list of all the compiler output files
  169. in the system being made.  An easy way to say that all of them must be
  170. recompiled if `config.h' changes is to write
  171.  
  172.      objects = foo.o bar.o
  173.      foo.o : defs.h
  174.      bar.o : defs.h test.h
  175.      $(objects) : config.h
  176.  
  177. This could be inserted or taken out without changing the rules that really
  178. say how to make the object files, making it a convenient form to use if you
  179. wish to add the additional dependency intermittently.
  180.  
  181. Another wrinkle is that the additional dependencies could be specified with
  182. a variable that you could set with a command argument to `make' (*Note
  183. Overriding::.).  For example,
  184.  
  185.      extradeps=
  186.      $(objects) : $(extradeps)
  187.  
  188. means that the command `make extradeps=foo.h' will consider `foo.h' as a
  189. dependency of each object file, but plain `make' will not.
  190.  
  191. If none of the explicit rules for a target has commands, then `make'
  192. searches for an applicable implicit rule to find some commands.  *note
  193. Implicit::.
  194.  
  195. File: make,  Node: Double-Colon,  Prev: Multiple Rules,  Up: Rules
  196.  
  197. Double-Colon Rules
  198. ==================
  199.  
  200. "Double-colon" rules are rules written with `::' instead of `:' after the
  201. target names.  They are handled differently from ordinary rules when the
  202. same target appears in more than one rule.
  203.  
  204. When a target appears in multiple rules, all the rules must be the same
  205. type: all ordinary, or all double-colon.  If they are double-colon, each of
  206. them is independent of the others.  Each double-colon rule's commands are
  207. executed if the target is older than any dependencies of that rule.  This
  208. can result in executing none, any or all of the double-colon rules.
  209.  
  210. The double-colon rules for a target are executed in the order they appear
  211. in the makefile.  However, the cases where double-colon rules really make
  212. sense are those where the order of executing the commands would not matter.
  213.  
  214. Each double-colon rule should specify commands; if it does not, an implicit
  215. rule will be used if one applies.  *note Implicit::.
  216.  
  217. File: make,  Node: Commands,  Next: Variables,  Prev: Rules,  Up: Top
  218.  
  219. Writing the Commands in Rules
  220. *****************************
  221.  
  222. The commands of a rule consist of shell command lines to be executed one by
  223. one.  Each command line must start with a tab, except that the first
  224. command line may be attached to the target-and-dependencies line with a
  225. semicolon in between.  Blank lines and lines of just comments may appear
  226. among the command lines; they are ignored.
  227.  
  228. Users use many different shell programs, but commands in makefiles are
  229. always interpreted by `/bin/sh' unless the makefile specifies otherwise.
  230.  
  231. Whether comments can be written on command lines, and what syntax they use,
  232. is under the control of the shell that is in use.  If it is `/bin/sh', a
  233. `#' at the start of a word starts a comment.
  234.  
  235. * Menu:
  236.  
  237. * Echoing::       Normally commands are echoed before execution,
  238.                     but you can control this in several ways.
  239. * Execution::     How commands are executed.
  240. * Errors::      What happens after an error in command execution.
  241.            How to ignore errors in certain commands.
  242. * Interrupts::      If a command is interrupted or killed,
  243.            the target may be deleted.
  244. * Recursion::      Invoking `make' from commands in makefiles.
  245. * Sequences::     Defining canned sequences of commands.
  246.  
  247.  
  248. File: make,  Node: Echoing,  Next: Execution,  Prev: Commands,  Up: Commands
  249.  
  250. Command Echoing
  251. ===============
  252.  
  253. Normally `make' prints each command line before it is executed.  We call
  254. this "echoing" because it gives the appearance that you are typing the
  255. commands yourself.
  256.  
  257. When a line starts with `@', it is normally not echoed.  The `@' is
  258. discarded before the command is passed to the shell.  Typically you would
  259. use this for a command whose only effect is to print something, such as an
  260. `echo' command.
  261.  
  262. When `make' is given the flag `-n', echoing is all that happens, no
  263. execution.  *note Options::.  In this case and only this case, even the
  264. commands starting with `@' are printed.  This flag is useful for finding
  265. out which commands `make' thinks are necessary without actually doing them.
  266.  
  267. The `-s' flag to `make' prevents all echoing, as if all commands started
  268. with `@'.  A rule in the makefile for the special target `.SILENT' has the
  269. same effect (*Note Special Targets::.).  `.SILENT' is essentially obsolete
  270. since `@' is more general.
  271.  
  272. File: make,  Node: Execution,  Next: Errors,  Prev: Echoing,  Up: Commands
  273.  
  274. Command Execution
  275. =================
  276.  
  277. When it is time to execute commands to update a target, they are executed
  278. one at a time by making a new subshell for each line.  (In practice, `make'
  279. may take shortcuts that do not affect the results.)
  280.  
  281. This implies that shell commands such as `cd' that set variables local to
  282. each process will not affect the following command lines.  If you want to
  283. use `cd' to affect the next command, put the two on a single line with a
  284. semicolon between them.  Then `make' will consider them a single command
  285. and pass them, together, to a shell which will execute them in sequence. 
  286. For example:
  287.  
  288.      foo : bar/lose
  289.              cd bar; gobble lose > ../foo
  290.  
  291. If you would like to split a single shell command into multiple lines of
  292. text, you must use a backslash at the end of all but the last subline. 
  293. Such a sequence of lines is combined into a single line, by deleting the
  294. backslash-newline sequences, before passing it to the shell.  Thus, the
  295. following is equivalent to the preceding example:
  296.  
  297.      foo : bar/lose
  298.              cd bar;  \
  299.              gobble lose > ../foo
  300.  
  301. The program used as the shell is taken from the variable `SHELL'.  By
  302. default, the program `/bin/sh' is used.
  303.  
  304. Unlike most variables, the variable `SHELL' will not be set from the
  305. environment, except in a recursive `make'.  This is because the environment
  306. variable `SHELL' is used to specify your personal choice of shell program
  307. for interactive use.  It would be very bad for personal choices like this
  308. to affect the functioning of makefiles.  *note Environment::.
  309.  
  310. File: make,  Node: Errors,  Next: Interrupts,  Prev: Execution,  Up: Commands
  311.  
  312. Errors in Commands
  313. ==================
  314.  
  315. After each shell command returns, `make' looks at its exit status.  If the
  316. command completed successfully, the next command line is executed in a new
  317. shell, or after the last command line the rule is finished.
  318.  
  319. If there is an error (the exit status is nonzero), `make' gives up on the
  320. current rule, and perhaps on all rules.
  321.  
  322. Sometimes it does not matter whether a command fails.  For example, you may
  323. use the `mkdir' command to insure that a directory exists.  If the
  324. directory already exists, `mkdir' will report an error, but you probably
  325. want `make' to continue regardless.
  326.  
  327. To ignore errors in a command line, write a `-' at the beginning of the
  328. line's text (after the initial tab).  The `-' is discarded before the
  329. command is passed to the shell for execution.
  330.  
  331. When `make' is run with the `-i' flag, errors are ignored in all commands
  332. of all rules.  A rule in the makefile for the special target `.IGNORE' has
  333. the same effect.  These ways of ignoring errors are obsolete because `-' is
  334. more general.
  335.  
  336. When errors are to be ignored, because of either a `-' or the `-i' flag,
  337. `make' treats an error return just like success.
  338.  
  339. When an error happens that `make' has not been told to ignore, it implies
  340. that the current target cannot be correctly remade, and neither can any
  341. other that depends on it either directly or indirectly.  No further
  342. commands will be executed for these targets, since their preconditions have
  343. not been achieved.
  344.  
  345. Normally `make' gives up immediately in this circumstance, returning a
  346. nonzero status.  However, if the `-k' flag is specified, `make' continues
  347. to consider the other dependencies of the pending targets, remaking them if
  348. necessary, before it gives up and returns nonzero status.  For example,
  349. after an error in compiling one object file, `make -k' will continue
  350. compiling other object files even though it already knows that linking them
  351. will be impossible.  *note Options::.
  352.  
  353. The usual behavior assumes that your purpose is to get the specified
  354. targets up to date; once `make' learns that this is impossible, it might as
  355. well report the failure immediately.  The `-k' option says that the real
  356. purpose is to test as much as possible of the changes made in the program,
  357. perhaps to find several independent problems so that you can correct them
  358. all before the next attempt to compile.  This is why Emacs's `compile'
  359. command passes the `-k' flag by default.
  360.  
  361. File: make,  Node: Interrupts,  Next: Recursion,  Prev: Errors,  Up: Commands
  362.  
  363. Interrupting or Killing `make'
  364. ==============================
  365.  
  366. If `make' gets a fatal signal while a command is executing, it may delete
  367. the target file that the command was supposed to update.  This is done if
  368. the target file's last-modification time has changed since `make' first
  369. checked it.
  370.  
  371. The purpose of deleting the target is to make sure that it is remade from
  372. scratch when `make' is next run.  Otherwise, a partially written file could
  373. appear to be valid, since it is more recent than the dependencies.
  374.  
  375. You can prevent the deletion of a target file in this way by making the
  376. special target `.PRECIOUS' depend on it.  Before remaking a target, `make'
  377. checks to see whether it appears on the dependencies of `.PRECIOUS', and
  378. thereby decides whether the target should be deleted if a signal happens. 
  379. Some reasons why you might do this are that the target is updated in some
  380. atomic fashion or exists only to record a modification-time (its contents
  381. do not matter) or will cause trouble if it ever fails to exist.
  382.  
  383. File: make,  Node: Recursion,  Next: Sequences,  Prev: Interrupts,  Up: Commands
  384.  
  385. Recursive Use of `make'
  386. =======================
  387.  
  388. Recursive use of `make' means using `make' as a command in a makefile. 
  389. This technique is useful when you want separate makefiles for various
  390. subsystems that compose a larger system.  For example, suppose you have a
  391. subdirectory `subdir' which has its own makefile, and you would like the
  392. containing directory's makefile to run `make' on the subdirectory.  You can
  393. do it by writing this:
  394.  
  395.      subsystem:
  396.              cd subdir; $(MAKE)
  397.  
  398. or, equivalently, this (*Note Options::.):
  399.  
  400.      subsystem:
  401.              $(MAKE) -c subdir
  402.  
  403. You can write recursive `make' commands just by copying this example, but
  404. there are many things to know about how they work and why, and about how
  405. the sub-`make' relates to the top-level `make'.
  406.  
  407. * Menu:
  408.  
  409. * MAKE Variable::        Special effects of using `$(MAKE)'.
  410. * Variables/Recursion::  How variables are communicated to a sub-`make'.
  411. * Options/Recursion::    How options are communicated to a sub-`make'.
  412. * -w Option::            The `-w' option facilitates debugging
  413.                            makefiles with recursive `make' commands.
  414.  
  415.  
  416. File: make,  Node: MAKE Variable,  Next: Variables/Recursion,  Prev: Recursion,  Up: Recursion
  417.  
  418. How the `MAKE' Variable Works
  419. -----------------------------
  420.  
  421. Recursive `make' commands should always use the variable `MAKE', not the
  422. explicit command name `make', as shown here:
  423.  
  424.      subsystem:
  425.              cd subdir; $(MAKE)
  426.  
  427. The value of this variable is the file name with which `make' was invoked. 
  428. If this file name was `/bin/make', then the command executed is `cd subdir;
  429. /bin/make'.  If you use a special version of `make' to run the top-level
  430. makefile, the same special version will be executed for recursive
  431. invocations.
  432.  
  433. Also, any arguments that define variable values are added to `MAKE', so the
  434. sub-`make' gets them too.  Thus, if you do `make CFLAGS=-O', so that all
  435. C-compilations will be optimized, the sub-`make' is run with `cd subdir;
  436. /bin/make CFLAGS=-O'.
  437.  
  438. As a special feature, using the variable `MAKE' in the commands of a rule
  439. alters the effects of the `-t', `-n' or `-q' option.  (*note Instead of
  440. Execution::.)
  441.  
  442. Consider the command `make -t' in the above example.  Following the usual
  443. definition of `-t', this would create a file named `subsystem' and do
  444. nothing else.  What you really want it to do is run `cd subdir; make -t';
  445. but that would require executing the command, and `-t' says not to execute
  446. commands.
  447.  
  448. The special feature makes this do what you want: whenever a rule's commands
  449. use the variable `MAKE', the flags `-t', `-n' or `-q' do not apply to that
  450. rule.  The commands of that rule are executed normally despite the presence
  451. of a flag that causes most commands not to be run.  The usual `MAKEFLAGS'
  452. mechanism passes the flags to the sub-`make' (*Note Options/Recursion::.),
  453. so your request to touch the files, or print the commands, is propagated to
  454. the subsystem.
  455.  
  456. File: make,  Node: Variables/Recursion,  Next: Options/Recursion,  Prev: MAKE Variable,  Up: Recursion
  457.  
  458. Communicating Variables to a Sub-`make'
  459. ---------------------------------------
  460.  
  461. Most variable values of the top-level `make' are passed to the sub-`make'
  462. through the environment.  These variables are defined in the sub-`make' as
  463. defaults, but do not override what is specified in the sub-`make''s
  464. makefile.  (Variables are passed down if their names consist of letters,
  465. numbers and underscores.)
  466.  
  467. The way this works is that `make' adds each variable and its value to the
  468. environment for running each command.  (Variables whose names start with
  469. non-alphanumeric characters are left out.)  The sub-`make', in turn, uses
  470. the environment to initialize its table of variable values.  *note
  471. Environment::.
  472.  
  473. As a special feature, the variable `MAKELEVEL' is changed when it is passed
  474. down from level to level.  This variable's value is a string which is the
  475. depth of the level as a decimal number.  The value is `0' for the top-level
  476. `make'; `1' for a sub-`make', `2' for a sub-sub-`make', and so on.  The
  477. incrementation happens when `make' sets up the environment for a command.
  478.  
  479. The main use of `MAKELEVEL' is to test it in a conditional directive (*Note
  480. Conditionals::.); this way you can write a makefile that behaves one way if
  481. run recursively and another way if run directly by you.
  482.  
  483. You can use the variable `MAKEFILES' to cause all sub-`make' commands to
  484. use additional makefiles.  The value of `MAKEFILES' is a
  485. whitespace-separated list of filenames.  This variable, if defined in the
  486. outer-level makefile, is passed down through the environment as usual; then
  487. it serves as a list of extra makefiles for the sub-`make' to read before
  488. the usual or specified ones.  *note MAKEFILES Variable::.
  489.  
  490. File: make,  Node: Options/Recursion,  Next: -w Option,  Prev: Variables/Recursion,  Up: Recursion
  491.  
  492. Communicating Options to a Sub-`make'
  493. -------------------------------------
  494.  
  495. Flags such as `-s' and `-k' are passed automatically to the sub-`make'
  496. through the variable `MAKEFLAGS'.  This variable is set up automatically by
  497. `make' to contain the flag letters that `make' received.  Thus, if you do
  498. `make -ks' then `MAKEFLAGS' gets the value `ks'.
  499.  
  500. As a consequence, every sub-`make' gets a value for `MAKEFLAGS' in its
  501. environment.  In response, it takes the flags from that value and processes
  502. them as if they had been given as arguments.  *note Options::.
  503.  
  504. The options `-c', `-d', `-f', `-I', `-o', and `-p' are not put into
  505. `MAKEFLAGS'; these options are not passed down.
  506.  
  507. If you don't want to pass the other the flags down, you must change the
  508. value of `MAKEFLAGS', like this:
  509.  
  510.      subsystem:
  511.              cd subdir; $(MAKE) MAKEFLAGS=
  512.  
  513. A similar variable `MFLAGS' exists also, for historical compatibility.  It
  514. has the same value as `MAKEFLAGS' except that a hyphen is added at the
  515. beginning if it is not empty.  `MFLAGS' was traditionally used explicitly
  516. in the recursive `make' command, like this:
  517.  
  518.      subsystem:
  519.              cd subdir; $(MAKE) $(MFLAGS)
  520.  
  521. but now `MAKEFLAGS' makes this usage redundant.
  522.  
  523. File: make,  Node: -w Option,  Prev: Options/Recursion,  Up: Recursion
  524.  
  525. The `-w' Option
  526. ---------------
  527.  
  528. If you are running `make' over a large directory tree, the `-w' option can
  529. make the output a lot easier to understand by showing each directory as it
  530. is entered and exited.  For example, if `make -w' is run in the directory
  531. `/u/gnu/make', `make' will print a line of the form:
  532.  
  533.      make: Entering directory `/u/gnu/make'.
  534.  
  535.  before doing anything else, and a line of this form:
  536.  
  537.      make: Leaving directory `/u/gnu/make'.
  538.  
  539.  when processing is completed.
  540.  
  541. File: make,  Node: Sequences,  Prev: Recursion,  Up: Commands
  542.  
  543. Defining Canned Command Sequences
  544. =================================
  545.  
  546. When the same sequence of commands is useful in making various targets, you
  547. can define it as a canned sequence with the `define' directive, and refer
  548. to the canned sequence from the rules for those targets.  The canned
  549. sequence is actually a variable, so the name must not conflict with other
  550. variable names.
  551.  
  552. Here is an example of defining a canned sequence of commands:
  553.  
  554.      define run-yacc
  555.      yacc $(firstword $^)
  556.      mv y.tab.c $@
  557.      endef
  558.  
  559. Here `run-yacc' is the name of the variable being defined; `endef' marks
  560. the end of the definition; the lines in between are the commands.  The
  561. `define' directive does not expand variable references and function calls
  562. in the canned sequence; the `$' characters, parentheses, variable names,
  563. and so on, all become part of the value of the variable you are defining. 
  564. *note Defining::, for a complete explanation of `define'.
  565.  
  566. The first command in this example runs Yacc on the first dependency (of
  567. whichever rule uses the canned sequence).  The output file from Yacc is
  568. always named `y.tab.c'.  The second command moves the output to the rule's
  569. target file name.
  570.  
  571. To use the canned sequence, substitute the variable into the commands of a
  572. rule.  You can substitute it like any other variable (*Note Reference::.). 
  573. Because variables defined by `define' are recursively expanded variables,
  574. all the variable references you wrote inside the `define' are expanded now.
  575.  For example:
  576.  
  577.      foo.c : foo.y
  578.              $(run-yacc)
  579.  
  580. `foo.y' will substituted for the variable `$^' when it occurs in
  581. `run-yacc''s value, and `foo.c' for `$@'.
  582.  
  583. This is a realistic example, but this particular one is not needed in
  584. practice because `make' has an implicit rule to figure out these commands
  585. based on the file names involved.  *note Implicit::.
  586.  
  587. File: make,  Node: Variables,  Next: Conditionals,  Prev: Commands,  Up: Top
  588.  
  589. How to Use Variables
  590. ********************
  591.  
  592. A "variable" is a name defined within `make' to represent a string of text,
  593. called the variable's "value".  These values can be substituted by explicit
  594. request into targets, dependencies, commands and other parts of the makefile.
  595.  
  596. Variables can represent lists of file names, options to pass to compilers,
  597. programs to run, directories to look in for source files, directories to
  598. write output in, or anything else you can imagine.
  599.  
  600. A variable name may be any sequence characters not containing `:', `#',
  601. `=', leading or trailing whitespace.  However, variable names containing
  602. characters other than letters, numbers and underscores should be avoided,
  603. as they may be given special meanings in the future, and they are not
  604. passed through the environment to a sub-`make' (*Note
  605. Variables/Recursion::.).
  606.  
  607. It is traditional to use upper case letters in variable names, but we
  608. recommend using lower case letters for variable names that serve internal
  609. purposes in the makefile, and reserving upper case for parameters that
  610. control implicit rules or for parameters that the user should override with
  611. command options (*Note Overriding::.).
  612.  
  613. * Menu:
  614.  
  615. * Reference::    How to use the value of a variable.
  616. * Values::      All the ways variables get their values.
  617. * Flavors::    Variables come in two flavors.
  618. * Setting::    How to set a variable in the makefile.
  619. * Override Directive:: Setting a variable in the makefile
  620.          even if the user has set it with a command argument.
  621. * Defining::    An alternate way to set a variable to a verbatim string.
  622. * Environment:: Variable values can come from the environment.
  623.  
  624.  
  625. File: make,  Node: Reference,  Next: Values,  Prev: Variables,  Up: Variables
  626.  
  627. Reference to Variables
  628. ======================
  629.  
  630. To substitute a variable's value, write a dollar sign followed by the name
  631. of the variable in parentheses or braces: either `$(foo)' or `${foo}' is a
  632. valid reference to the variable `foo'.  This special significance of `$' is
  633. why you must write `$$' to have the effect of a single dollar sign in a
  634. file name or command.
  635.  
  636. Variable references can be used in any context: targets, dependencies,
  637. commands, most directives, and new variable values.  Here is a common kind
  638. of example, where a variable holds the names of all the object files in a
  639. program:
  640.  
  641.      objects = program.o foo.o utils.o
  642.      program : $(objects)
  643.              cc -o program $(objects)
  644.      
  645.      $(objects) : defs.h
  646.  
  647. Variable references work by strict textual substitution.  Thus, the rule
  648.  
  649.      foo = c
  650.      prog.o : prog.c
  651.              $(foo)$(foo) prog.c
  652.  
  653. could be used to compile a C program `prog.c'.  (Since spaces around the
  654. variable value are ignored in variable assignments, the value of `foo' is
  655. precisely `c'.)
  656.  
  657. A dollar sign followed by a character other than a dollar sign,
  658. open-parenthesis or open-brace treats that single character as the variable
  659. name.  Thus, you could reference the variable `x' with `$x'.  However, this
  660. practice is strongly discouraged, except with the automatic variables
  661. (*Note Automatic::.).
  662.  
  663. Modified References
  664. -------------------
  665.  
  666. In addition to simple references, variables can be referenced in a manner
  667. which modifies the value of the reference but do not modify the value of
  668. the variable referenced.  Such a reference is a "substitution reference".
  669.  
  670. A "substitution reference" is really a simplified form of the `patsubst'
  671. expansion function (*Note Functions::.).  It has the form `$(var:a=b)' (or
  672. `${var:a=b}') and is equivalent to `$(patsubst %a,%b,$(var))'.  This means
  673. that it replaces every `a' at the end of a whitespace-separated word with a
  674. `b'.  For example:
  675.  
  676.      foo := a.o b.o c.o
  677.      bar := $(foo:.o=.c)
  678.  
  679. sets `bar' to `a.c b.c c.c'.  *note Setting::.
  680.  
  681. Recursive References
  682. --------------------
  683.  
  684. Variables may be referenced inside a variable reference.  This is called a
  685. "recursive variable reference".  For example,
  686.  
  687.      x = y
  688.      y = z
  689.      a := $($(x))
  690.  
  691. defines `a' as `z': the `$(x)' inside `$($(x))' expands to `y', so
  692. `$($(x))' expands to `$(y)' which in turn expands to `z'.
  693.  
  694. Recursive variable references can get yet more recursive.  For example,
  695.  
  696.      x = $(y)
  697.      y = z
  698.      z = Hello
  699.      a := $($(x))
  700.  
  701. defines `a' as `Hello': `$($(x))' becomes `$($(y))' which becomes `$(z)'
  702. which becomes `Hello'.  This sort of recursion can go on for as many levels
  703. as you like (and can comprehend), though it's not clear that very many
  704. levels of recursion are useful.
  705.  
  706. Recursive variable references can also contain modified references and
  707. function invokations (*Note Functions::.), just like any other reference. 
  708. For example, using the `subst' function (*Note Text Functions::.):
  709.  
  710.      x = variable1
  711.      variable2 := Hello
  712.      y = $(subst 1,2,$(x))
  713.      z = y
  714.      a := $($($(z)))
  715.  
  716. eventually defines `a' as `Hello'.  It is doubtful that anyone would ever
  717. want to write a recursive reference as convoluted as this one, but it
  718. works: `$($($(z)))' expands to `$($(y))' which becomes `$($(subst
  719. 1,2,$(x)))' which changes `variable1' to `variable2' in `$(x)' and finally
  720. expands to `$(variable2)', a simple variable reference that becomes `Hello'.
  721.  
  722. Recursive variable references are a complicated concept needed only for
  723. very complex makefile programming.  You need not worry about them in
  724. general, except to know that making a variable with a dollar sign in its
  725. name might have strange results.  Note also that "recursive variable
  726. references" are quite different from "recursive variables" (*Note
  727. Flavors::.), though both are used together in complex ways when doing
  728. makefile programming.
  729.  
  730. File: make,  Node: Values,  Next: Flavors,  Prev: Reference,  Up: Variables
  731.  
  732. How Variables Get Their Values
  733. ==============================
  734.  
  735. Variables can get values in several different ways:
  736.  
  737.    * You can specify an overriding value when you run `make'.  *note
  738.      Overriding::.
  739.  
  740.    * You can specify a value in the makefile, either with an assignment
  741.      (*Note Setting::.) or with a verbatim definition (*Note Defining::.).
  742.  
  743.    * Values are inherited from the environment.  *note Environment::.
  744.  
  745.    * Several "automatic" variables are given new values for each rule. 
  746.      *note Automatic::.
  747.  
  748.    * Several variables have constant initial values.  *note Implicit
  749.      Variables::.
  750.  
  751. File: make,  Node: Flavors,  Next: Setting,  Prev: Values,  Up: Variables
  752.  
  753. The Two Flavors of Variables
  754. ============================
  755.  
  756. There are two kinds of variables in GNU `make'.  They are distinguished by
  757. two things: how they are defined and how they are expanded.
  758.  
  759. The first flavor of variable is a "recursively expanded" variable. 
  760. Variables of this sort are defined by lines using `='
  761.  
  762. (*Note Setting::.).  The value you specify is installed verbatim; if it
  763. contains references to other variables, these references are expanded
  764. whenever this variable is substituted (in the course of expanding some
  765. other string).  When this happens, it is recursive expansion.
  766.  
  767. For example,
  768.  
  769.      foo = $(bar)
  770.      bar = $(ugh)
  771.      ugh = Huh?
  772.      
  773.      all:;echo $(foo)
  774.  
  775. will echo `Huh?': `$(foo)' expands to `$(bar)' which expands to `$(ugh)'
  776. which finally expands to `Huh?'.
  777.  
  778. This flavor of variable is the only sort supported by other versions of
  779. `make'.  It has its advantages and its disadvantages.  An advantage (most
  780. would say) is that:
  781.  
  782.      CFLAGS = $(include_dirs) -O
  783.      include_dirs = -Ifoo -Ibar
  784.  
  785. will do what was intended: when `CFLAGS' is expanded in a command, it will
  786. expand to `-Ifoo -Ibar'.  A major disadvantage is that you can't append
  787. something on the end of a variable, as in
  788.  
  789.      CFLAGS = $(CFLAGS) -O
  790.  
  791. because it will cause an infinite loop in the variable expansion. 
  792. (Actually `make' detects the infinite loop and reports an error.)
  793.  
  794. Another disadvantage is that any functions (*Note Functions::.) referenced
  795. in the definition will be executed every time the variable is expanded. 
  796. This makes `make' run slower; worse, it causes the `wildcard' function to
  797. give unpredictable results.
  798.  
  799. To avoid all the problems and inconveniences of recursively expanded
  800. variables, there is another flavor: "simply expanded" variables.  Simply
  801. expanded variables are defined by lines using `:='
  802.  
  803. (*Note Setting::.).  The value of a simply expanded variable is scanned
  804. once and for all, expanding any references to other variables and
  805. functions, when the variable is defined.  The actual value of the simply
  806. expanded variable is the result of expanding the value you write.  It does
  807. not contain any references to other variables; it contains their values *as
  808. of the time this variable was defined*.  Therefore,
  809.  
  810.      x := foo
  811.      y := $(x) bar
  812.      x := later
  813.  
  814. is equivalent to
  815.  
  816.      y := foo bar
  817.      x := later
  818.  
  819. When a simply expanded variable is referenced, its value is substituted
  820. verbatim.
  821.  
  822. Simply expanded variables generally make complicated makefile programming
  823. more predictable because they work like variables in most programming
  824. languages.  They allow you to redefine a variable using its own value (or
  825. its value processed in some way by one of the expansion functions) and to
  826. use the expansion functions much more efficiently (*Note Functions::.).
  827.  
  828. You can also use them to introduce controlled leading or trailing spaces
  829. into variable values.  Such spaces are discarded from your input before
  830. substitution of variable references and function calls; this means you can
  831. include leading or trailing spaces in a variable value by protecting them
  832. with variable references, like this:
  833.  
  834.      nullstring :=
  835.      space := $(nullstring) $(nullstring)
  836.  
  837. Here the value of the variable `space' is precisely one space.
  838.  
  839. File: make,  Node: Setting,  Next: Override Directive,  Prev: Flavors,  Up: Variables
  840.  
  841. Setting Variables
  842. =================
  843.  
  844. To set a variable from the makefile, write a line starting with the
  845. variable name followed by `=' or `:='.  Whatever follows the `=' or `:=' on
  846. the line becomes the value.  For example,
  847.  
  848.      objects = main.o foo.o bar.o utils.o
  849.  
  850. defines a variable named `objects'.  Spaces around the variable name are
  851. ignored, and so are spaces after the `=' or at the end of the line.
  852.  
  853. Variables defined with `=' are "recursively expanded" variables.  Variables
  854. defined with `:=' are "simply expanded" variables; these definitions can
  855. contain variable references which will be expanded before the definition is
  856. made.  *note Flavors::.
  857.  
  858. There is no limit on the length of the value of a variable except the
  859. amount of swapping space on the computer.  When a variable definition is
  860. long, it is a good idea to break it into several lines by inserting
  861. backslash-newline at convenient places in the definition.  This will not
  862. affect the functioning of `make', but it will make the makefile easier to
  863. read.
  864.  
  865. Most variable names are considered to have the empty string as a value if
  866. you have never set them.  Several variables have built-in initial values
  867. that are not empty, but can be set by you in the usual ways (*Note Implicit
  868. Variables::.).  Several special variables are set automatically to a new
  869. value for each rule; these are called the "automatic" variables (*Note
  870. Automatic::.).
  871.  
  872. File: make,  Node: Override Directive,  Next: Defining,  Prev: Setting,  Up: Variables
  873.  
  874. The `override' Directive
  875. ========================
  876.  
  877. If a variable has been set with a command argument (*Note Overriding::.),
  878. then ordinary assignments in the makefile are ignored.  If you want to set
  879. the variable in the makefile even though it was set with a command
  880. argument, you can use an `override' directive, which is a line that looks
  881. like this:
  882.  
  883.      override VARIABLE = VALUE
  884.  
  885. or
  886.  
  887.      override VARIABLE := VALUE
  888.  
  889. The `override' directive was not invented for escalation in the war between
  890. makefiles and command arguments.  It was invented so you can alter and add
  891. to values that the user specifies with command arguments.
  892.  
  893. For example, suppose you always want the `-g' switch when you run the C
  894. compiler, but you would like to allow the user to specify the other
  895. switches with a command argument just as usual.  You could use this
  896. `override' directive:
  897.  
  898.      override CFLAGS := $(CFLAGS) -g
  899.  
  900. File: make,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Variables
  901.  
  902. Defining Variables Verbatim
  903. ===========================
  904.  
  905. Another way to set the value of a variable is to use the `define'
  906. directive.  This directive has a different syntax which allows newline
  907. characters to be included in the value, which is convenient for defining
  908. canned sequences of commands (*Note Sequences::.).
  909.  
  910. The `define' directive is followed on the same line the name of the
  911. variable and nothing more.  The value to give the variable appears on the
  912. following lines.  The end of the value is marked by a line containing just
  913. the word `endef'.  Aside from this difference in syntax, `define' works
  914. just like `='; it creates a recursively-expanded variable (*Note Flavors::.).
  915.  
  916.      define two-lines
  917.      echo foo
  918.      echo $(bar)
  919.      endef
  920.  
  921. The value in an ordinary assignment cannot contain a newline; but the
  922. newlines that separate the lines of the value in a `define' become part of
  923. the variable's value (except for the final newline which precedes the
  924. `endef' and is not considered part of the value).
  925.  
  926. The previous example is functionally equivalent to this:
  927.  
  928.      two-lines = echo foo; echo $(bar)
  929.  
  930. since the shell will interpret the semicolon and the newline identically.
  931.  
  932. File: make,  Node: Environment,  Prev: Defining,  Up: Variables
  933.  
  934. Variables from the Environment
  935. ==============================
  936.  
  937. Variables in `make' can come from the environment with which `make' is run.
  938.  Every environment variable that `make' sees when it starts up is
  939. transformed into a `make' variable with the same name and value.  But an
  940. explicit assignment in the makefile, or with a command argument, overrides
  941. the environment.  (If the `-e' flag is specified, then values from the
  942. environment override assignments in the makefile.  *note Options::.  But
  943. this is not recommended practice.)
  944.  
  945. By setting the variable `CFLAGS' in your environment, you can cause all C
  946. compilations in most makefiles to use the compiler switches you prefer. 
  947. This is safe for variables with standard or conventional meanings because
  948. you know that no makefile will use them for other things.  (But this is not
  949. totally reliable; some makefiles set `CFLAGS' explicitly and therefore are
  950. not affected by the value in the environment.)
  951.  
  952. When `make' is invoked recursively, variables defined in the outer
  953. invocation are automatically passed to inner invocations through the
  954. environment (*Note Recursion::.).  This is the main purpose of turning
  955. environment variables into `make' variables, and it requires no attention
  956. from you.
  957.  
  958. Other use of variables from the environment is not recommended.  It is not
  959. wise for makefiles to depend for their functioning on environment variables
  960. set up outside their control, since this would cause different users to get
  961. different results from the same makefile.  This is against the whole
  962. purpose of most makefiles.
  963.  
  964. Such problems would be especially likely with the variable `SHELL', which
  965. is normally present in the environment to specify the user's choice of
  966. interactive shell.  It would be very undesirable for this choice to affect
  967. `make'.  So `make' ignores the environment value of `SHELL' if the value of
  968. `MAKELEVEL' is zero (which is normally true except in recursive invocations
  969. of `make').
  970.  
  971. File: make,  Node: Conditionals,  Next: Functions,  Prev: Variables,  Up: Top
  972.  
  973. Conditional Parts of Makefiles
  974. ******************************
  975.  
  976. A "conditional" causes part of a makefile to be obeyed or ignored depending
  977. on the values of variables.  Conditionals can compare the value of one
  978. variable with another, or the value of a variable with a constant string. 
  979. Conditionals control what `make' actually ``sees'' in the makefile, so they
  980. *cannot* be used to control shell commands at the time of execution.
  981.  
  982. * Menu:
  983.  
  984. * Example: Conditional Example.   An annotated example.
  985. * Syntax: Conditional Syntax.     Precise rules for syntax of conditionals.
  986. * Flags: Testing Flags.           Conditionals testing flags such as `-t'.
  987.  
  988.  
  989. File: make,  Node: Conditional Example,  Next: Conditional Syntax,  Prev: Conditionals,  Up: Conditionals
  990.  
  991. Example of a Conditional
  992. ========================
  993.  
  994. This conditional tells `make' to use one set of libraries if the `CC'
  995. variable is `gcc', and a different set of libraries otherwise.  It works by
  996. controlling which of two command lines will be used as the command for a
  997. rule.  The result is that `CC=gcc' as an argument to `make' not only
  998. changes which compiler is used but also which libraries are linked.
  999.  
  1000.      libs_for_gcc = -lgnu
  1001.      normal_libs =
  1002.      
  1003.      foo: $(objects)
  1004.      ifeq ($(CC),gcc)
  1005.              $(CC) -o foo $(objects) $(libs_for_gcc)
  1006.      else
  1007.              $(CC) -o foo $(objects) $(normal_libs)
  1008.      endif
  1009.  
  1010. This conditional uses three directives: one `ifeq', one `else' and one
  1011. `endif'.
  1012.  
  1013. The `ifeq' directive contains two arguments, separated by a comma and
  1014. surrounded by parentheses.  Variable substitution is performed on both
  1015. arguments and then they are compared.  The lines of the makefile following
  1016. the `ifeq' are obeyed if the two arguments match; otherwise they are ignored.
  1017.  
  1018. The `else' directive causes the following lines to be obeyed if the
  1019. previous conditional failed.  In the example above, this means that the
  1020. second alternative linking command is used whenever the first alternative
  1021. is not used.  It is optional to have an `else' in a conditional.
  1022.  
  1023. The `endif' directive ends the conditional.  Every conditional must end
  1024. with an `endif'.  Unconditional makefile text follows.
  1025.  
  1026. When the variable `CC' has the value `gcc', the above example has this
  1027. effect:
  1028.  
  1029.      foo: $(objects)
  1030.              $(CC) -o foo $(objects) $(libs_for_gcc)
  1031.  
  1032. When the variable `CC' has any other value, this effect is this:
  1033.  
  1034.      foo: $(objects)
  1035.              $(CC) -o foo $(objects) $(normal_libs)
  1036.  
  1037. Equivalent results can be obtained in another way by conditionalizing a
  1038. variable assignment and then using the variable unconditionally:
  1039.  
  1040.      libs_for_gcc = -lgnu
  1041.      normal_libs =
  1042.      
  1043.      ifeq ($(CC),gcc)
  1044.        libs=$(libs_for_gcc)
  1045.      else
  1046.        libs=$(normal_libs)
  1047.      endif
  1048.      
  1049.      foo: $(objects)
  1050.              $(CC) -o foo $(objects) $(libs)
  1051.  
  1052. File: make,  Node: Conditional Syntax,  Next: Testing Flags,  Prev: Conditional Example,  Up: Conditionals
  1053.  
  1054. Syntax of Conditionals
  1055. ======================
  1056.  
  1057. The syntax of a simple conditional with no `else' is as follows:
  1058.  
  1059.      CONDITIONAL-DIRECTIVE
  1060.      TEXT-IF-TRUE
  1061.      endif
  1062.  
  1063. The TEXT-IF-TRUE may be any lines of text, to be considered as part of the
  1064. makefile if the condition is true.  If the condition is false, no text is
  1065. used instead.
  1066.  
  1067. The syntax of a complex conditional is as follows:
  1068.  
  1069.      CONDITIONAL-DIRECTIVE
  1070.      TEXT-IF-TRUE
  1071.      else
  1072.      TEXT-IF-FALSE
  1073.      endif
  1074.  
  1075. If the condition is true, TEXT-IF-TRUE is used; otherwise, TEXT-IF-FALSE is
  1076. used instead.  The TEXT-IF-FALSE can be any number of lines of text.
  1077.  
  1078. Conditionals work at the textual level.  The lines of the TEXT-IF-TRUE are
  1079. read as part of the makefile if the condition is true; if the condition is
  1080. false, those lines are ignored completely.  It follows that syntactic units
  1081. of the makefile, such as rules, may safely be split across the beginning or
  1082. the end of the conditional.
  1083.  
  1084. You may use an `include' directive within a conditional, but you may not
  1085. start a conditional in one file and end it in another.
  1086.  
  1087. The syntax of the CONDITIONAL-DIRECTIVE is the same whether the conditional
  1088. is simple or complex.  There are four different directives that test
  1089. different conditions.  Here is a table of them:
  1090.  
  1091. `ifeq (ARG1, ARG2)'
  1092.      Expand all variable references in ARG1 and ARG2 and compare them.  If
  1093.      they are identical, the TEXT-IF-TRUE is effective; otherwise, the
  1094.      TEXT-IF-FALSE, if any, is effective.
  1095.  
  1096. `ifneq (ARG1, ARG2)'
  1097.      Expand all variable references in ARG1 and ARG2 and compare them.  If
  1098.      they are different, the TEXT-IF-TRUE is effective; otherwise, the
  1099.      TEXT-IF-FALSE, if any, is effective.
  1100.  
  1101. `ifdef VARIABLE-NAME'
  1102.      If the variable VARIABLE-NAME has a non-empty value, the TEXT-IF-TRUE
  1103.      is effective; otherwise, the TEXT-IF-FALSE, if any, is effective. 
  1104.      Variables that have never been defined have an empty value.
  1105.  
  1106. `ifndef VARIABLE-NAME'
  1107.      If the variable VARIABLE-NAME has an empty value, the TEXT-IF-TRUE is
  1108.      effective; otherwise, the TEXT-IF-FALSE, if any, is effective.
  1109.  
  1110. Extra spaces are allowed and ignored at the beginning of the conditional
  1111. directive line, but a tab is not allowed.  (If the line begins with a tab,
  1112. it will be considered a command for a rule.)  Aside from this, extra spaces
  1113. or tabs may be inserted with no effect anywhere except within the directive
  1114. name or within an argument.  A comment starting with `#' may appear at the
  1115. end of the line.
  1116.  
  1117. The other two directives that play a part in a conditional are `else' and
  1118. `endif'.  Each of these directives is written as one word, with no
  1119. arguments.  Extra spaces are allowed and ignored at the beginning of the
  1120. line, and spaces or tabs at the end.  A comment starting with `#' may
  1121. appear at the end of the line.
  1122.  
  1123. File: make,  Node: Testing Flags,  Prev: Conditional Syntax,  Up: Conditionals
  1124.  
  1125. Conditionals that Test Flags
  1126. ============================
  1127.  
  1128. You can write a conditional that tests `make' command flags such as `-t' by
  1129. using the variable `MAKEFLAGS' together with the `findstring' function. 
  1130. This is useful when `touch' is not enough to make a file appear up to date.
  1131.  
  1132. The `findstring' function determines whether one string appears as a
  1133. substring of another.  If you want to test for the `-t' flag, use `t' as
  1134. the first string and the value of `MAKEFLAGS' as the other.
  1135.  
  1136. For example, here is how to arrange to use `ranlib -t' to finish marking an
  1137. archive file up to date:
  1138.  
  1139.      archive.a: ...
  1140.      ifneq (,$(findstring t,$(MAKEFLAGS)))
  1141.              @echo $(MAKE) > /dev/null
  1142.              touch archive.a
  1143.              ranlib -t archive.a
  1144.      else
  1145.              ranlib archive.a
  1146.      endif
  1147.  
  1148. The `echo' command does nothing when executed; but its presence, with a
  1149. reference to the variable `MAKE', marks the rule as ``recursive'' so that
  1150. its commands will be executed despite use of the `-t' flag.  *note
  1151. Recursion::.
  1152.  
  1153. File: make,  Node: Functions,  Next: Running,  Prev: Conditionals,  Up: Top
  1154.  
  1155. Functions for Transforming Text
  1156. *******************************
  1157.  
  1158. "Functions" allow you to do text processing in the makefile to compute the
  1159. files to operate on or the commands to use.  You use a function in a
  1160. "function call", where you give the name of the function and some text (the
  1161. "arguments") for the function to operate on.  The result of the function's
  1162. processing is substituted into the makefile at the point of the call, just
  1163. as a variable might be substituted.
  1164.  
  1165. * Menu:
  1166.  
  1167. * Syntax: Function Syntax.  Syntax of function calls in general.
  1168. * Text Functions::          Text manipulation functions.
  1169. * Foreach Function::        The `foreach' function.
  1170. * Filename Functions::      Functions for manipulating file names.
  1171.  
  1172.  
  1173.