home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / gnu / djgpp / docs / make / make.inf < prev    next >
Encoding:
GNU Info File  |  1993-11-27  |  356.5 KB  |  8,506 lines

  1. This is Info file make.info, produced by Makeinfo-1.55 from the input
  2. file make.tex.
  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.44, last updated 3 November 1993, of `The GNU Make
  9. Manual', for `make', Version 3.69 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,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)
  30.  
  31. Make
  32. ****
  33.  
  34.    The GNU `make' utility automatically determines which pieces of a
  35. large program need to be recompiled, and issues the commands to
  36. recompile them.
  37.  
  38.    This is Edition 0.44 of the `GNU Make Manual', last updated 3
  39. November 1993 for `make' Version 3.69 Beta.
  40.  
  41.    This manual describes `make' and contains the following chapters:
  42.  
  43. * Menu:
  44.  
  45. * Overview::                    Overview of `make'.
  46. * Introduction::                An introduction to `make'.
  47. * Makefiles::                   Makefiles tell `make' what to do.
  48. * Rules::                       Rules describe when a file must be remade.
  49. * Commands::                    Commands say how to remake a file.
  50. * Using Variables::             You can use variables to avoid repetition.
  51. * Conditionals::                Use or ignore parts of the makefile based
  52.                                  on the values of variables.
  53. * Functions::                   Many powerful ways to manipulate text.
  54. * make Invocation: Running.     How to invoke `make' on the command line.
  55. * Implicit Rules::              Use implicit rules to treat many files alike,
  56.                                  based on their file names.
  57. * Archives::                    How `make' can update library archives.
  58. * Features::                    Features GNU `make' has over other `make's.
  59. * Missing::                     What GNU `make' lacks from other `make's.
  60. * Makefile Conventions::        Conventions for makefiles in GNU programs.
  61. * Quick Reference::             A quick reference for experienced users.
  62. * Complex Makefile::            A real example of a straightforward,
  63.                                  but nontrivial, makefile.
  64. * Concept Index::               Index of Concepts
  65. * Name Index::                  Index of Functions, Variables, & Directives
  66.  
  67.  -- The Detailed Node Listing --
  68.  
  69. Overview of `make'
  70.  
  71. * Preparing::                   Preparing and Running Make
  72. * Reading::                     On Reading this Text
  73. * Bugs::                        Problems and Bugs
  74.  
  75. An Introduction to Makefiles
  76.  
  77. * Rule Introduction::           What a rule looks like.
  78. * Simple Makefile::             A Simple Makefile
  79. * How Make Works::              How `make' Processes This Makefile
  80. * Variables Simplify::          Variables Make Makefiles Simpler
  81. * make Deduces::                Letting `make' Deduce the Commands
  82. * Combine By Dependency::       Another Style of Makefile
  83. * Cleanup::                     Rules for Cleaning the Directory
  84.  
  85. Writing Makefiles
  86.  
  87. * Makefile Contents::           What makefiles contain.
  88. * Makefile Names::              How to name your makefile.
  89. * Include::                     How one makefile can use another makefile.
  90. * MAKEFILES Variable::          The environment can specify extra makefiles.
  91. * Remaking Makefiles::          How makefiles get remade.
  92. * Overriding Makefiles::        How to override part of one makefile
  93.                                  with another makefile.
  94.  
  95. Writing Rules
  96.  
  97. * Rule Example::                An example explained.
  98. * Rule Syntax::                 General syntax explained.
  99. * Wildcards::                   Using wildcard characters such as `*'.
  100. * Directory Search::            Searching other directories for source files.
  101. * Phony Targets::               Using a target that is not a real file's name.
  102. * Force Targets::               You can use a target without commands
  103.                                   or dependencies to mark other
  104.                                   targets as phony.
  105. * Empty Targets::               When only the date matters and the
  106.                                   files are empty.
  107. * Special Targets::             Targets with special built-in meanings.
  108. * Multiple Targets::            When to make use of several targets in a rule.
  109. * Multiple Rules::              How to use several rules with the same target.
  110. * Static Pattern::              Static pattern rules apply to multiple targets
  111.                                   and can vary the dependencies according to
  112.                                   the target name.
  113. * Double-Colon::                How to use a special kind of rule to allow
  114.                                   several independent rules for one target.
  115. * Automatic Dependencies::      How to automatically generate rules giving
  116.                                  dependencies from the source files themselves.
  117.  
  118. Using Wildcard Characters in File Names
  119.  
  120. * Wildcard Examples::           Several examples
  121. * Wildcard Pitfall::            Problems to avoid.
  122. * Wildcard Function::           How to cause wildcard expansion where
  123.                                   it does not normally take place.
  124.  
  125. Searching Directories for Dependencies
  126.  
  127. * General Search::              Specifying a search path that applies
  128.                                   to every dependency.
  129. * Selective Search::            Specifying a search path
  130.                                   for a specified class of names.
  131. * Commands/Search::             How to write shell commands that work together
  132.                                   with search paths.
  133. * Implicit/Search::             How search paths affect implicit rules.
  134. * Libraries/Search::            Directory search for link libraries.
  135.  
  136. Static Pattern Rules
  137.  
  138. * Static Usage::                The syntax of static pattern rules.
  139. * Static versus Implicit::      When are they better than implicit rules?
  140.  
  141. Writing the Commands in Rules
  142.  
  143. * Echoing::                     How to control when commands are echoed.
  144. * Execution::                   How commands are executed.
  145. * Parallel::                    How commands can be executed in parallel.
  146. * Errors::                      What happens after a command execution error.
  147. * Interrupts::                  What happens when a command is interrupted.
  148. * Recursion::                   Invoking `make' from makefiles.
  149. * Sequences::                   Defining canned sequences of commands.
  150. * Empty Commands::              Defining useful, do-nothing commands.
  151.  
  152. Recursive Use of `make'
  153.  
  154. * MAKE Variable::               The special effects of using `$(MAKE)'.
  155. * Variables/Recursion::         How to communicate variables to a sub-`make'.
  156. * Options/Recursion::           How to communicate options to a sub-`make'.
  157. * -w Option::                   How the `-w' or `--print-directory' option
  158.                                  helps debug use of recursive `make' commands.
  159.  
  160. How to Use Variables
  161.  
  162. * Reference::                   How to use the value of a variable.
  163. * Flavors::                     Variables come in two flavors.
  164. * Advanced::                    Advanced features for referencing a variable.
  165. * Values::                      All the ways variables get their values.
  166. * Setting::                     How to set a variable in the makefile.
  167. * Appending::                   How to append more text to the old value
  168.                                   of a variable.
  169. * Override Directive::          How to set a variable in the makefile even if
  170.                                   the user has set it with a command argument.
  171. * Defining::                    An alternate way to set a variable
  172.                                   to a verbatim string.
  173. * Environment::                 Variable values can come from the environment.
  174.  
  175. Advanced Features for Reference to Variables
  176.  
  177. * Substitution Refs::           Referencing a variable with
  178.                                   substitutions on the value.
  179. * Computed Names::              Computing the name of the variable to refer to.
  180.  
  181. Conditional Parts of Makefiles
  182.  
  183. * Conditional Example::         Example of a conditional
  184. * Conditional Syntax::          The syntax of conditionals.
  185. * Testing Flags::               Conditionals that test flags.
  186.  
  187. Functions for Transforming Text
  188.  
  189. * Syntax of Functions::         How to write a function call.
  190. * Text Functions::              General-purpose text manipulation functions.
  191. * Filename Functions::          Functions for manipulating file names.
  192. * Foreach Function::            Repeat some text with controlled variation.
  193. * Origin Function::             Find where a variable got its value.
  194. * Shell Function::              Substitute the output of a shell command.
  195.  
  196. How to Run `make'
  197.  
  198. * Makefile Arguments::          How to specify which makefile to use.
  199. * Goals::                       How to use goal arguments to specify which
  200.                                   parts of the makefile to use.
  201. * Instead of Execution::        How to use mode flags to specify what
  202.                                   kind of thing to do with the commands
  203.                                   in the makefile other than simply
  204.                                   execute them.
  205. * Avoiding Compilation::        How to avoid recompiling certain files.
  206. * Overriding::                  How to override a variable to specify
  207.                                   an alternate compiler and other things.
  208. * Testing::                     How to proceed past some errors, to
  209.                                   test compilation.
  210. * Options Summary::             Summary of Options
  211.  
  212. Using Implicit Rules
  213.  
  214. * Using Implicit::              How to use an existing implicit rule
  215.                                   to get the commands for updating a file.
  216. * Catalogue of Rules::          A list of built-in implicit rules.
  217. * Implicit Variables::          How to change what predefined rules do.
  218. * Chained Rules::               How to use a chain of implicit rules.
  219. * Pattern Rules::               How to define new implicit rules.
  220. * Last Resort::                 How to defining commands for rules
  221.                                   which cannot find any.
  222. * Suffix Rules::                The old-fashioned style of implicit rule.
  223. * Search Algorithm::            The precise algorithm for applying
  224.                                   implicit rules.
  225.  
  226. Defining and Redefining Pattern Rules
  227.  
  228. * Pattern Intro::               An introduction to pattern rules.
  229. * Pattern Examples::            Examples of pattern rules.
  230. * Automatic::                   How to use automatic variables in the
  231.                                   commands of implicit rules.
  232. * Pattern Match::               How patterns match.
  233. * Match-Anything Rules::        Precautions you should take prior to
  234.                                   defining rules that can match any
  235.                                   target file whatever.
  236. * Canceling Rules::             How to override or cancel built-in rules.
  237.  
  238. Using `make' to Update Archive Files
  239.  
  240. * Archive Members::             Archive members as targets.
  241. * Archive Update::              The implicit rule for archive member targets.
  242. * Archive Suffix Rules::        You can write a special kind of suffix rule
  243.                                   for updating archives.
  244.  
  245. Implicit Rule for Archive Member Targets
  246.  
  247. * Archive Symbols::             How to update archive symbol directories.
  248.  
  249. 
  250. File: make,  Node: Overview,  Next: Introduction,  Prev: Top,  Up: Top
  251.  
  252. Overview of `make'
  253. ******************
  254.  
  255.    The `make' utility automatically determines which pieces of a large
  256. program need to be recompiled, and issues commands to recompile them.
  257. This manual describes GNU `make', which was implemented by Richard
  258. Stallman and Roland McGrath.  GNU `make' conforms to section 6.2 of
  259. `IEEE Standard 1003.2-1992' (POSIX.2).
  260.  
  261.    Our examples show C programs, since they are most common, but you
  262. can use `make' with any programming language whose compiler can be run
  263. with a shell command.  Indeed, `make' is not limited to programs.  You
  264. can use it to describe any task where some files must be updated
  265. automatically from others whenever the others change.
  266.  
  267. * Menu:
  268.  
  269. * Preparing::                   Preparing and Running Make
  270. * Reading::                     On Reading this Text
  271. * Bugs::                        Problems and Bugs
  272.  
  273. 
  274. File: make,  Node: Preparing,  Next: Reading,  Up: Overview
  275.  
  276. Preparing and Running Make
  277. ==========================
  278.  
  279.    To prepare to use `make', you must write a file called the
  280. "makefile" that describes the relationships among files in your program
  281. and provides commands for updating each file.  In a program, typically,
  282. the executable file is updated from object files, which are in turn
  283. made by compiling source files.
  284.  
  285.    Once a suitable makefile exists, each time you change some source
  286. files, this simple shell command:
  287.  
  288.      make
  289.  
  290. suffices to perform all necessary recompilations.  The `make' program
  291. uses the makefile data base and the last-modification times of the
  292. files to decide which of the files need to be updated.  For each of
  293. those files, it issues the commands recorded in the data base.
  294.  
  295.    You can provide command line arguments to `make' to control which
  296. files should be recompiled, or how.  *Note How to Run `make': Running.
  297.  
  298. 
  299. File: make,  Node: Reading,  Next: Bugs,  Prev: Preparing,  Up: Overview
  300.  
  301. How to Read This Manual
  302. =======================
  303.  
  304.    If you are new to `make', or are looking for a general introduction,
  305. read the first few sections of each chapter, skipping the later
  306. sections.  In each chapter, the first few sections contain introductory
  307. or general information and the later sections contain specialized or
  308. technical information.  The exception is the second chapter, *Note An
  309. Introduction to Makefiles: Introduction, all of which is introductory.
  310.  
  311.    If you are familiar with other `make' programs, see *Note Features
  312. of GNU `make': Features, which lists the enhancements GNU `make' has,
  313. and *Note Incompatibilities and Missing Features: Missing, which
  314. explains the few things GNU `make' lacks that others have.
  315.  
  316.    For a quick summary, see *Note Options Summary::, *Note Quick
  317. Reference::, and *Note Special Targets::.
  318.  
  319. 
  320. File: make,  Node: Bugs,  Prev: Reading,  Up: Overview
  321.  
  322. Problems and Bugs
  323. =================
  324.  
  325.    If you have problems with GNU `make' or think you've found a bug,
  326. please report it to the developers; we cannot promise to do anything but
  327. we might well want to fix it.
  328.  
  329.    Before reporting a bug, make sure you've actually found a real bug.
  330. Carefully reread the documentation and see if it really says you can do
  331. what you're trying to do.  If it's not clear whether you should be able
  332. to do something or not, report that too; it's a bug in the
  333. documentation!
  334.  
  335.    Before reporting a bug or trying to fix it yourself, try to isolate
  336. it to the smallest possible makefile that reproduces the problem.  Then
  337. send us the makefile and the exact results `make' gave you.  Also say
  338. what you expected to occur; this will help us decide whether the
  339. problem was really in the documentation.
  340.  
  341.    Once you've got a precise problem, please send electronic mail either
  342. through the Internet or via UUCP:
  343.  
  344.      Internet address:
  345.          bug-gnu-utils@prep.ai.mit.edu
  346.      
  347.      UUCP path:
  348.          mit-eddie!prep.ai.mit.edu!bug-gnu-utils
  349.  
  350. Please include the version number of `make' you are using.  You can get
  351. this information with the command `make --version'.  Be sure also to
  352. include the type of machine and operating system you are using.  If
  353. possible, include the contents of the file `config.h' that is generated
  354. by the configuration process.
  355.  
  356.    Non-bug suggestions are always welcome as well.  If you have
  357. questions about things that are unclear in the documentation or are
  358. just obscure features, contact Roland McGrath; he will try to help you
  359. out, although he may not have time to fix the problem.
  360.  
  361.    You can send electronic mail to Roland McGrath either through the
  362. Internet or via UUCP:
  363.  
  364.      Internet address:
  365.          roland@prep.ai.mit.edu
  366.      
  367.      UUCP path:
  368.          mit-eddie!prep.ai.mit.edu!roland
  369.  
  370. 
  371. File: make,  Node: Introduction,  Next: Makefiles,  Prev: Overview,  Up: Top
  372.  
  373. An Introduction to Makefiles
  374. ****************************
  375.  
  376.    You need a file called a "makefile" to tell `make' what to do.  Most
  377. often, the makefile tells `make' how to compile and link a program.
  378.  
  379.    In this chapter, we will discuss a simple makefile that describes
  380. how to compile and link a text editor which consists of eight C source
  381. files and three header files.  The makefile can also tell `make' how to
  382. run miscellaneous commands when explicitly asked (for example, to remove
  383. certain files as a clean-up operation).  To see a more complex example
  384. of a makefile, see *Note Complex Makefile::.
  385.  
  386.    When `make' recompiles the editor, each changed C source file must
  387. be recompiled.  If a header file has changed, each C source file that
  388. includes the header file must be recompiled to be safe.  Each
  389. compilation produces an object file corresponding to the source file.
  390. Finally, if any source file has been recompiled, all the object files,
  391. whether newly made or saved from previous compilations, must be linked
  392. together to produce the new executable editor.
  393.  
  394. * Menu:
  395.  
  396. * Rule Introduction::           What a rule looks like.
  397. * Simple Makefile::             A Simple Makefile
  398. * How Make Works::              How `make' Processes This Makefile
  399. * Variables Simplify::          Variables Make Makefiles Simpler
  400. * make Deduces::                Letting `make' Deduce the Commands
  401. * Combine By Dependency::       Another Style of Makefile
  402. * Cleanup::                     Rules for Cleaning the Directory
  403.  
  404. 
  405. File: make,  Node: Rule Introduction,  Next: Simple Makefile,  Up: Introduction
  406.  
  407. What a Rule Looks Like
  408. ======================
  409.  
  410.    A simple makefile consists of "rules" with the following shape:
  411.  
  412.      TARGET ... : DEPENDENCIES ...
  413.              COMMAND
  414.              ...
  415.              ...
  416.  
  417.    A "target" is usually the name of a file that is generated by a
  418. program; examples of targets are executable or object files.  A target
  419. can also be the name of an action to carry out, such as `clean' (*note
  420. Phony Targets::.).
  421.  
  422.    A "dependency" is a file that is used as input to create the target.
  423. A target often depends on several files.
  424.  
  425.    A "command" is an action that `make' carries out.  A rule may have
  426. more than one command, each on its own line.  *Please note:* you need
  427. to put a tab character at the beginning of every command line!  This is
  428. an obscurity that catches the unwary.
  429.  
  430.    Usually a command is in a rule with dependencies and serves to
  431. create a target file if any of the dependencies change.  However, the
  432. rule that specifies commands for the target need not have dependencies.
  433. For example, the rule containing the delete command associated with the
  434. target `clean' does not have dependencies.
  435.  
  436.    A "rule", then, explains how and when to remake certain files which
  437. are the targets of the particular rule.  `make' carries out the
  438. commands on the dependencies to create or update the target.  A rule
  439. can also explain how and when to carry out an action.  *Note Writing
  440. Rules: Rules.
  441.  
  442.    A makefile may contain other text besides rules, but a simple
  443. makefile need only contain rules.  Rules may look somewhat more
  444. complicated than shown in this template, but all fit the pattern more
  445. or less.
  446.  
  447. 
  448. File: make,  Node: Simple Makefile,  Next: How Make Works,  Prev: Rule Introduction,  Up: Introduction
  449.  
  450. A Simple Makefile
  451. =================
  452.  
  453.    Here is a straightforward makefile that describes the way an
  454. executable file called `edit' depends on eight object files which, in
  455. turn, depend on eight C source and three header files.
  456.  
  457.    In this example, all the C files include `defs.h', but only those
  458. defining editing commands include `command.h', and only low level files
  459. that change the editor buffer include `buffer.h'.
  460.  
  461.      edit : main.o kbd.o command.o display.o \
  462.             insert.o search.o files.o utils.o
  463.              cc -o edit main.o kbd.o command.o display.o \
  464.                         insert.o search.o files.o utils.o
  465.      
  466.      main.o : main.c defs.h
  467.              cc -c main.c
  468.      kbd.o : kbd.c defs.h command.h
  469.              cc -c kbd.c
  470.      command.o : command.c defs.h command.h
  471.              cc -c command.c
  472.      display.o : display.c defs.h buffer.h
  473.              cc -c display.c
  474.      insert.o : insert.c defs.h buffer.h
  475.              cc -c insert.c
  476.      search.o : search.c defs.h buffer.h
  477.              cc -c search.c
  478.      files.o : files.c defs.h buffer.h command.h
  479.              cc -c files.c
  480.      utils.o : utils.c defs.h
  481.              cc -c utils.c
  482.      clean :
  483.              rm edit main.o kbd.o command.o display.o \
  484.                 insert.o search.o files.o utils.o
  485.  
  486. We split each long line into two lines using backslash-newline; this is
  487. like using one long line, but is easier to read.
  488.  
  489.    To use this makefile to create the executable file called `edit',
  490. type:
  491.  
  492.      make
  493.  
  494.    To use this makefile to delete the executable file and all the object
  495. files from the directory, type:
  496.  
  497.      make clean
  498.  
  499.    In the example makefile, the targets include the executable file
  500. `edit', and the object files `main.o' and `kbd.o'.  The dependencies
  501. are files such as `main.c' and `defs.h'.  In fact, each `.o' file is
  502. both a target and a dependency.  Commands include `cc -c main.c' and
  503. `cc -c kbd.c'.
  504.  
  505.    When a target is a file, it needs to be recompiled or relinked if any
  506. of its dependencies change.  In addition, any dependencies that are
  507. themselves automatically generated should be updated first.  In this
  508. example, `edit' depends on each of the eight object files; the object
  509. file `main.o' depends on the source file `main.c' and on the header
  510. file `defs.h'.
  511.  
  512.    A shell command follows each line that contains a target and
  513. dependencies.  These shell commands say how to update the target file.
  514. A tab character must come at the beginning of every command line to
  515. distinguish commands lines from other lines in the makefile.  (Bear in
  516. mind that `make' does not know anything about how the commands work.
  517. It is up to you to supply commands that will update the target file
  518. properly.  All `make' does is execute the commands in the rule you have
  519. specified when the target file needs to be updated.)
  520.  
  521.    The target `clean' is not a file, but merely the name of an action.
  522. Since you normally do not want to carry out the actions in this rule,
  523. `clean' is not a dependency of any other rule.  Consequently, `make'
  524. never does anything with it unless you tell it specifically.  Note that
  525. this rule not only is not a dependency, it also does not have any
  526. dependencies, so the only purpose of the rule is to run the specified
  527. commands.  Targets that do not refer to files but are just actions are
  528. called "phony targets".  *Note Phony Targets::, for information about
  529. this kind of target.  *Note Errors in Commands: Errors, to see how to
  530. cause `make' to ignore errors from `rm' or any other command.
  531.  
  532. 
  533. File: make,  Node: How Make Works,  Next: Variables Simplify,  Prev: Simple Makefile,  Up: Introduction
  534.  
  535. How `make' Processes a Makefile
  536. ===============================
  537.  
  538.    By default, `make' starts with the first rule (not counting rules
  539. whose target names start with `.').  This is called the "default goal".
  540. ("Goals" are the targets that `make' strives ultimately to update.
  541. *Note Arguments to Specify the Goals: Goals.)
  542.  
  543.    In the simple example of the previous section, the default goal is to
  544. update the executable program `edit'; therefore, we put that rule first.
  545.  
  546.    Thus, when you give the command:
  547.  
  548.      make
  549.  
  550. `make' reads the makefile in the current directory and begins by
  551. processing the first rule.  In the example, this rule is for relinking
  552. `edit'; but before `make' can fully process this rule, it must process
  553. the rules for the files that `edit' depends on, which in this case are
  554. the object files.  Each of these files is processed according to its
  555. own rule.  These rules say to update each `.o' file by compiling its
  556. source file.  The recompilation must be done if the source file, or any
  557. of the header files named as dependencies, is more recent than the
  558. object file, or if the object file does not exist.
  559.  
  560.    The other rules are processed because their targets appear as
  561. dependencies of the goal.  If some other rule is not depended on by the
  562. goal (or anything it depends on, etc.), that rule is not processed,
  563. unless you tell `make' to do so (with a command such as `make clean').
  564.  
  565.    Before recompiling an object file, `make' considers updating its
  566. dependencies, the source file and header files.  This makefile does not
  567. specify anything to be done for them--the `.c' and `.h' files are not
  568. the targets of any rules--so `make' does nothing for these files.  But
  569. `make' would update automatically generated C programs, such as those
  570. made by Bison or Yacc, by their own rules at this time.
  571.  
  572.    After recompiling whichever object files need it, `make' decides
  573. whether to relink `edit'.  This must be done if the file `edit' does
  574. not exist, or if any of the object files are newer than it.  If an
  575. object file was just recompiled, it is now newer than `edit', so `edit'
  576. is relinked.
  577.  
  578.    Thus, if we change the file `insert.c' and run `make', `make' will
  579. compile that file to update `insert.o', and then link `edit'.  If we
  580. change the file `command.h' and run `make', `make' will recompile the
  581. object files `kbd.o', `command.o' and `files.o' and then link the file
  582. `edit'.
  583.  
  584. 
  585. File: make,  Node: Variables Simplify,  Next: make Deduces,  Prev: How Make Works,  Up: Introduction
  586.  
  587. Variables Make Makefiles Simpler
  588. ================================
  589.  
  590.    In our example, we had to list all the object files twice in the
  591. rule for `edit' (repeated here):
  592.  
  593.      edit : main.o kbd.o command.o display.o \
  594.                    insert.o search.o files.o utils.o
  595.              cc -o edit main.o kbd.o command.o display.o \
  596.                         insert.o search.o files.o utils.o
  597.  
  598.    Such duplication is error-prone; if a new object file is added to the
  599. system, we might add it to one list and forget the other.  We can
  600. eliminate the risk and simplify the makefile by using a variable.
  601. "Variables" allow a text string to be defined once and substituted in
  602. multiple places later (*note How to Use Variables: Using Variables.).
  603.  
  604.    It is standard practice for every makefile to have a variable named
  605. `objects', `OBJECTS', `objs', `OBJS', `obj', or `OBJ' which is a list
  606. of all object file names.  We would define such a variable `objects'
  607. with a line like this in the makefile:
  608.  
  609.      objects = main.o kbd.o command.o display.o \
  610.                insert.o search.o files.o utils.o
  611.  
  612. Then, each place we want to put a list of the object file names, we can
  613. substitute the variable's value by writing `$(objects)' (*note How to
  614. Use Variables: Using Variables.).
  615.  
  616.    Here is how the complete simple makefile looks when you use a
  617. variable for the object files:
  618.  
  619.      objects = main.o kbd.o command.o display.o \
  620.                insert.o search.o files.o utils.o
  621.      
  622.      edit : $(objects)
  623.              cc -o edit $(objects)
  624.      main.o : main.c defs.h
  625.              cc -c main.c
  626.      kbd.o : kbd.c defs.h command.h
  627.              cc -c kbd.c
  628.      command.o : command.c defs.h command.h
  629.              cc -c command.c
  630.      display.o : display.c defs.h buffer.h
  631.              cc -c display.c
  632.      insert.o : insert.c defs.h buffer.h
  633.              cc -c insert.c
  634.      search.o : search.c defs.h buffer.h
  635.              cc -c search.c
  636.      files.o : files.c defs.h buffer.h command.h
  637.              cc -c files.c
  638.      utils.o : utils.c defs.h
  639.              cc -c utils.c
  640.      clean :
  641.              rm edit $(objects)
  642.  
  643. 
  644. File: make,  Node: make Deduces,  Next: Combine By Dependency,  Prev: Variables Simplify,  Up: Introduction
  645.  
  646. Letting `make' Deduce the Commands
  647. ==================================
  648.  
  649.    It is not necessary to spell out the commands for compiling the
  650. individual C source files, because `make' can figure them out: it has an
  651. "implicit rule" for updating a `.o' file from a correspondingly named
  652. `.c' file using a `cc -c' command.  For example, it will use the
  653. command `cc -c main.c -o main.o' to compile `main.c' into `main.o'.  We
  654. can therefore omit the commands from the rules for the object files.
  655. *Note Using Implicit Rules: Implicit Rules.
  656.  
  657.    When a `.c' file is used automatically in this way, it is also
  658. automatically added to the list of dependencies.  We can therefore omit
  659. the `.c' files from the dependencies, provided we omit the commands.
  660.  
  661.    Here is the entire example, with both of these changes, and a
  662. variable `objects' as suggested above:
  663.  
  664.      objects = main.o kbd.o command.o display.o \
  665.                insert.o search.o files.o utils.o
  666.      
  667.      edit : $(objects)
  668.              cc -o edit $(objects)
  669.      
  670.      main.o : defs.h
  671.      kbd.o : defs.h command.h
  672.      command.o : defs.h command.h
  673.      display.o : defs.h buffer.h
  674.      insert.o : defs.h buffer.h
  675.      search.o : defs.h buffer.h
  676.      files.o : defs.h buffer.h command.h
  677.      utils.o : defs.h
  678.      
  679.      .PHONY : clean
  680.      clean :
  681.              -rm edit $(objects)
  682.  
  683. This is how we would write the makefile in actual practice.  (The
  684. complications associated with `clean' are described elsewhere.  See
  685. *Note Phony Targets::, and *Note Errors in Commands: Errors.)
  686.  
  687.    Because implicit rules are so convenient, they are important.  You
  688. will see them used frequently.
  689.  
  690. 
  691. File: make,  Node: Combine By Dependency,  Next: Cleanup,  Prev: make Deduces,  Up: Introduction
  692.  
  693. Another Style of Makefile
  694. =========================
  695.  
  696.    When the objects of a makefile are created only by implicit rules, an
  697. alternative style of makefile is possible.  In this style of makefile,
  698. you group entries by their dependencies instead of by their targets.
  699. Here is what one looks like:
  700.  
  701.      objects = main.o kbd.o command.o display.o \
  702.                insert.o search.o files.o utils.o
  703.      
  704.      edit : $(objects)
  705.              cc -o edit $(objects)
  706.      
  707.      $(objects) : defs.h
  708.      kbd.o command.o files.o : command.h
  709.      display.o insert.o search.o files.o : buffer.h
  710.  
  711. Here `defs.h' is given as a dependency of all the object files;
  712. `command.h' and `buffer.h' are dependencies of the specific object
  713. files listed for them.
  714.  
  715.    Whether this is better is a matter of taste: it is more compact, but
  716. some people dislike it because they find it clearer to put all the
  717. information about each target in one place.
  718.  
  719. 
  720. File: make,  Node: Cleanup,  Prev: Combine By Dependency,  Up: Introduction
  721.  
  722. Rules for Cleaning the Directory
  723. ================================
  724.  
  725.    Compiling a program is not the only thing you might want to write
  726. rules for.  Makefiles commonly tell how to do a few other things besides
  727. compiling a program: for example, how to delete all the object files
  728. and executables so that the directory is `clean'.
  729.  
  730.    Here is how we could write a `make' rule for cleaning our example
  731. editor:
  732.  
  733.      clean:
  734.              rm edit $(objects)
  735.  
  736.    In practice, we might want to write the rule in a somewhat more
  737. complicated manner to handle unanticipated situations.  We would do
  738. this:
  739.  
  740.      .PHONY : clean
  741.      clean :
  742.              -rm edit $(objects)
  743.  
  744. This prevents `make' from getting confused by an actual file called
  745. `clean' and causes it to continue in spite of errors from `rm'.  (See
  746. *Note Phony Targets::, and *Note Errors in Commands: Errors.)
  747.  
  748. A rule such as this should not be placed at the beginning of the
  749. makefile, because we do not want it to run by default!  Thus, in the
  750. example makefile, we want the rule for `edit', which recompiles the
  751. editor, to remain the default goal.
  752.  
  753.    Since `clean' is not a dependency of `edit', this rule will not run
  754. at all if we give the command `make' with no arguments.  In order to
  755. make the rule run, we have to type `make clean'.  *Note How to Run
  756. `make': Running.
  757.  
  758. 
  759. File: make,  Node: Makefiles,  Next: Rules,  Prev: Introduction,  Up: Top
  760.  
  761. Writing Makefiles
  762. *****************
  763.  
  764.    The information that tells `make' how to recompile a system comes
  765. from reading a data base called the "makefile".
  766.  
  767. * Menu:
  768.  
  769. * Makefile Contents::           What makefiles contain.
  770. * Makefile Names::              How to name your makefile.
  771. * Include::                     How one makefile can use another makefile.
  772. * MAKEFILES Variable::          The environment can specify extra makefiles.
  773. * Remaking Makefiles::          How makefiles get remade.
  774. * Overriding Makefiles::        How to override part of one makefile
  775.                                  with another makefile.
  776.  
  777. 
  778. File: make,  Node: Makefile Contents,  Next: Makefile Names,  Up: Makefiles
  779.  
  780. What Makefiles Contain
  781. ======================
  782.  
  783.    Makefiles contain five kinds of things: "explicit rules", "implicit
  784. rules", "variable definitions", "directives", and "comments".  Rules,
  785. variables, and directives are described at length in later chapters.
  786.  
  787.    * An "explicit rule" says when and how to remake one or more files,
  788.      called the rule's targets.  It lists the other files that the
  789.      targets "depend on", and may also give commands to use to create
  790.      or update the targets.  *Note Writing Rules: Rules.
  791.  
  792.    * An "implicit rule" says when and how to remake a class of files
  793.      based on their names.  It describes how a target may depend on a
  794.      file with a name similar to the target and gives commands to
  795.      create or update such a target.  *Note Using Implicit Rules:
  796.      Implicit Rules.
  797.  
  798.    * A "variable definition" is a line that specifies a text string
  799.      value for a variable that can be substituted into the text later.
  800.      The simple makefile example shows a variable definition for
  801.      `objects' as a list of all object files (*note Variables Make
  802.      Makefiles Simpler: Variables Simplify.).
  803.  
  804.    * A "directive" is a command for `make' to do something special while
  805.      reading the makefile.  These include:
  806.  
  807.         * Reading another makefile (*note Including Other Makefiles:
  808.           Include.).
  809.  
  810.         * Deciding (based on the values of variables) whether to use or
  811.           ignore a part of the makefile (*note Conditional Parts of
  812.           Makefiles: Conditionals.).
  813.  
  814.         * Defining a variable from a verbatim string containing
  815.           multiple lines (*note Defining Variables Verbatim: Defining.).
  816.  
  817.    * `#' in a line of a makefile starts a "comment".  It and the rest of
  818.      the line are ignored, except that a trailing backslash not escaped
  819.      by another backslash will continue the comment across multiple
  820.      lines.  Comments may appear on any of the lines in the makefile,
  821.      except within a `define' directive, and perhaps within commands
  822.      (where the shell decides what is a comment).  A line containing
  823.      just a comment (with perhaps spaces before it) is effectively
  824.      blank, and is ignored.
  825.  
  826. 
  827. File: make,  Node: Makefile Names,  Next: Include,  Prev: Makefile Contents,  Up: Makefiles
  828.  
  829. What Name to Give Your Makefile
  830. ===============================
  831.  
  832.    By default, when `make' looks for the makefile, it tries the
  833. following names, in order: `GNUmakefile', `makefile' and `Makefile'.
  834.  
  835.    Normally you should call your makefile either `makefile' or
  836. `Makefile'.  (We recommend `Makefile' because it appears prominently
  837. near the beginning of a directory listing, right near other important
  838. files such as `README'.)  The first name checked, `GNUmakefile', is not
  839. recommended for most makefiles.  You should use this name if you have a
  840. makefile that is specific to GNU `make', and will not be understood by
  841. other versions of `make'.  Other `make' programs look for `makefile' and
  842. `Makefile', but not `GNUmakefile'.
  843.  
  844.    If `make' finds none of these names, it does not use any makefile.
  845. Then you must specify a goal with a command argument, and `make' will
  846. attempt to figure out how to remake it using only its built-in implicit
  847. rules.  *Note Using Implicit Rules: Implicit Rules.
  848.  
  849.    If you want to use a nonstandard name for your makefile, you can
  850. specify the makefile name with the `-f' or `--file' option.  The
  851. arguments `-f NAME' or `--file=NAME' tell `make' to read the file NAME
  852. as the makefile.  If you use more than one `-f' or `--file' option, you
  853. can specify several makefiles.  All the makefiles are effectively
  854. concatenated in the order specified.  The default makefile names
  855. `GNUmakefile', `makefile' and `Makefile' are not checked automatically
  856. if you specify `-f' or `--file'.
  857.  
  858. 
  859. File: make,  Node: Include,  Next: MAKEFILES Variable,  Prev: Makefile Names,  Up: Makefiles
  860.  
  861. Including Other Makefiles
  862. =========================
  863.  
  864.    The `include' directive tells `make' to suspend reading the current
  865. makefile and read one or more other makefiles before continuing.  The
  866. directive is a line in the makefile that looks like this:
  867.  
  868.      include FILENAMES...
  869.  
  870. FILENAMES can contain shell file name patterns.
  871.  
  872.    Extra spaces are allowed and ignored at the beginning of the line,
  873. but a tab is not allowed.  (If the line begins with a tab, it will be
  874. considered a command line.)  Whitespace is required between `include'
  875. and the file names, and between file names; extra whitespace is ignored
  876. there and at the end of the directive.  A comment starting with `#' is
  877. allowed at the end of the line.  If the file names contain any variable
  878. or function references, they are expanded.  *Note How to Use Variables:
  879. Using Variables.
  880.  
  881.    For example, if you have three `.mk' files, `a.mk', `b.mk', and
  882. `c.mk', and `$(bar)' expands to `bish bash', then the following
  883. expression
  884.  
  885.      include foo *.mk $(bar)
  886.  
  887.    is equivalent to
  888.  
  889.      include foo a.mk b.mk c.mk bish bash
  890.  
  891.    When `make' processes an `include' directive, it suspends reading of
  892. the containing makefile and reads from each listed file in turn.  When
  893. that is finished, `make' resumes reading the makefile in which the
  894. directive appears.
  895.  
  896.    One occasion for using `include' directives is when several programs,
  897. handled by individual makefiles in various directories, need to use a
  898. common set of variable definitions (*note Setting Variables: Setting.)
  899. or pattern rules (*note Defining and Redefining Pattern Rules: Pattern
  900. Rules.).
  901.  
  902.    Another such occasion is when you want to generate dependencies from
  903. source files automatically; the dependencies can be put in a file that
  904. is included by the main makefile.  This practice is generally cleaner
  905. than that of somehow appending the dependencies to the end of the main
  906. makefile as has been traditionally done with other versions of `make'.
  907. *Note Automatic Dependencies::.
  908.  
  909.    If the specified name does not start with a slash, and the file is
  910. not found in the current directory, several other directories are
  911. searched.  First, any directories you have specified with the `-I' or
  912. `--include-dir' option are searched (*note Summary of Options: Options
  913. Summary.).  Then the following directories (if they exist) are
  914. searched, in this order: `PREFIX/include' (normally
  915. `/usr/local/include') `/usr/gnu/include', `/usr/local/include',
  916. `/usr/include'.
  917.  
  918.    If an included makefile cannot be found in any of these directories,
  919. a warning message is generated, but it is not an immediately fatal
  920. error; processing of the makefile containing the `include' continues.
  921. Once it has finished reading makefiles, `make' will try to remake any
  922. that are out of date or don't exist.  *Note How Makefiles Are Remade:
  923. Remaking Makefiles.  Only after it has tried to find a way to remake a
  924. makefile and failed, will `make' diagnose the missing makefile as a
  925. fatal error.
  926.  
  927.    If you want `make' to simply ignore a makefile which does not exist
  928. and cannot be remade, with no error message, use the `-include'
  929. directive instead of `include', like this:
  930.  
  931.      -include FILENAMES...
  932.  
  933.    This is acts like `include' in every way except that there is no
  934. error (not even a warning) if any of the FILENAMES do not exist.
  935.  
  936. 
  937. File: make,  Node: MAKEFILES Variable,  Next: Remaking Makefiles,  Prev: Include,  Up: Makefiles
  938.  
  939. The Variable `MAKEFILES'
  940. ========================
  941.  
  942.    If the environment variable `MAKEFILES' is defined, `make' considers
  943. its value as a list of names (separated by whitespace) of additional
  944. makefiles to be read before the others.  This works much like the
  945. `include' directive: various directories are searched for those files
  946. (*note Including Other Makefiles: Include.).  In addition, the default
  947. goal is never taken from one of these makefiles and it is not an error
  948. if the files listed in `MAKEFILES' are not found.
  949.  
  950.    The main use of `MAKEFILES' is in communication between recursive
  951. invocations of `make' (*note Recursive Use of `make': Recursion.).  It
  952. usually is not desirable to set the environment variable before a
  953. top-level invocation of `make', because it is usually better not to
  954. mess with a makefile from outside.  However, if you are running `make'
  955. without a specific makefile, a makefile in `MAKEFILES' can do useful
  956. things to help the built-in implicit rules work better, such as
  957. defining search paths (*note Directory Search::.).
  958.  
  959.    Some users are tempted to set `MAKEFILES' in the environment
  960. automatically on login, and program makefiles to expect this to be done.
  961. This is a very bad idea, because such makefiles will fail to work if
  962. run by anyone else.  It is much better to write explicit `include'
  963. directives in the makefiles.  *Note Including Other Makefiles: Include.
  964.  
  965. 
  966. File: make,  Node: Remaking Makefiles,  Next: Overriding Makefiles,  Prev: MAKEFILES Variable,  Up: Makefiles
  967.  
  968. How Makefiles Are Remade
  969. ========================
  970.  
  971.    Sometimes makefiles can be remade from other files, such as RCS or
  972. SCCS files.  If a makefile can be remade from other files, you probably
  973. want `make' to get an up-to-date version of the makefile to read in.
  974.  
  975.    To this end, after reading in all makefiles, `make' will consider
  976. each as a goal target and attempt to update it.  If a makefile has a
  977. rule which says how to update it (found either in that very makefile or
  978. in another one) or if an implicit rule applies to it (*note Using
  979. Implicit Rules: Implicit Rules.), it will be updated if necessary.
  980. After all makefiles have been checked, if any have actually been
  981. changed, `make' starts with a clean slate and reads all the makefiles
  982. over again.  (It will also attempt to update each of them over again,
  983. but normally this will not change them again, since they are already up
  984. to date.)
  985.  
  986.    If the makefiles specify a double-colon rule to remake a file with
  987. commands but no dependencies, that file will always be remade (*note
  988. Double-Colon::.).  In the case of makefiles, a makefile that has a
  989. double-colon rule with commands but no dependencies will be remade every
  990. time `make' is run, and then again after `make' starts over and reads
  991. the makefiles in again.  This would cause an infinite loop: `make'
  992. would constantly remake the makefile, and never do anything else.  So,
  993. to avoid this, `make' will *not* attempt to remake makefiles which are
  994. specified as double-colon targets but have no dependencies.
  995.  
  996.    If you do not specify any makefiles to be read with `-f' or `--file'
  997. options, `make' will try the default makefile names; *note What Name to
  998. Give Your Makefile: Makefile Names..  Unlike makefiles explicitly
  999. requested with `-f' or `--file' options, `make' is not certain that
  1000. these makefiles should exist.  However, if a default makefile does not
  1001. exist but can be created by running `make' rules, you probably want the
  1002. rules to be run so that the makefile can be used.
  1003.  
  1004.    Therefore, if none of the default makefiles exists, `make' will try
  1005. to make each of them in the same order in which they are searched for
  1006. (*note What Name to Give Your Makefile: Makefile Names.) until it
  1007. succeeds in making one, or it runs out of names to try.  Note that it
  1008. is not an error if `make' cannot find or make any makefile; a makefile
  1009. is not always necessary.
  1010.  
  1011.    When you use the `-t' or `--touch' option (*note Instead of
  1012. Executing the Commands: Instead of Execution.), you would not want to
  1013. use an out-of-date makefile to decide which targets to touch.  So the
  1014. `-t' option has no effect on updating makefiles; they are really
  1015. updated even if `-t' is specified.  Likewise, `-q' (or `--question')
  1016. and `-n' (or `--just-print') do not prevent updating of makefiles,
  1017. because an out-of-date makefile would result in the wrong output for
  1018. other targets.  Thus, `make -f mfile -n foo' will update `mfile', read
  1019. it in, and then print the commands to update `foo' and its dependencies
  1020. without running them.  The commands printed for `foo' will be those
  1021. specified in the updated contents of `mfile'.
  1022.  
  1023.    However, on occasion you might actually wish to prevent updating of
  1024. even the makefiles.  You can do this by specifying the makefiles as
  1025. goals in the command line as well as specifying them as makefiles.
  1026. When the makefile name is specified explicitly as a goal, the options
  1027. `-t' and so on do apply to them.
  1028.  
  1029.    Thus, `make -f mfile -n mfile foo' would read the makefile `mfile',
  1030. print the commands needed to update it without actually running them,
  1031. and then print the commands needed to update `foo' without running
  1032. them.  The commands for `foo' will be those specified by the existing
  1033. contents of `mfile'.
  1034.  
  1035. 
  1036. File: make,  Node: Overriding Makefiles,  Prev: Remaking Makefiles,  Up: Makefiles
  1037.  
  1038. Overriding Part of Another Makefile
  1039. ===================================
  1040.  
  1041.    Sometimes it is useful to have a makefile that is mostly just like
  1042. another makefile.  You can often use the `include' directive to include
  1043. one in the other, and add more targets or variable definitions.
  1044. However, if the two makefiles give different commands for the same
  1045. target, `make' will not let you just do this.  But there is another way.
  1046.  
  1047.    In the containing makefile (the one that wants to include the other),
  1048. you can use the `.DEFAULT' special target to say that to remake any
  1049. target that cannot be made from the information in the containing
  1050. makefile, `make' should look in another makefile.  *Note Defining
  1051. Last-Resort Default Rules: Last Resort, for more information on
  1052. `.DEFAULT'.
  1053.  
  1054.    For example, if you have a makefile called `Makefile' that says how
  1055. to make the target `foo' (and other targets), you can write a makefile
  1056. called `GNUmakefile' that contains:
  1057.  
  1058.      foo:
  1059.              frobnicate > foo
  1060.      
  1061.      .DEFAULT:
  1062.              @$(MAKE) -f Makefile $@
  1063.  
  1064.    If you say `make foo', `make' will find `GNUmakefile', read it, and
  1065. see that to make `foo', it needs to run the command `frobnicate > foo'.
  1066. If you say `make bar', `make' will find no way to make `bar' in
  1067. `GNUmakefile', so it will use the commands from `.DEFAULT': `make -f
  1068. Makefile bar'.  If `Makefile' provides a rule for updating `bar', `make'
  1069. will apply the rule.  And likewise for any other target that
  1070. `GNUmakefile' does not say how to make.
  1071.  
  1072. 
  1073. File: make,  Node: Rules,  Next: Commands,  Prev: Makefiles,  Up: Top
  1074.  
  1075. Writing Rules
  1076. *************
  1077.  
  1078.    A "rule" appears in the makefile and says when and how to remake
  1079. certain files, called the rule's "targets" (most often only one per
  1080. rule).  It lists the other files that are the "dependencies" of the
  1081. target, and "commands" to use to create or update the target.
  1082.  
  1083.    The order of rules is not significant, except for determining the
  1084. "default goal": the target for `make' to consider, if you do not
  1085. otherwise specify one.  The default goal is the target of the first
  1086. rule in the first makefile.  If the first rule has multiple targets,
  1087. only the first target is taken as the default.  There are two
  1088. exceptions: a target starting with a period is not a default unless it
  1089. contains one or more slashes, `/', as well; and, a target that defines
  1090. a pattern rule has no effect on the default goal.  (*Note Defining and
  1091. Redefining Pattern Rules: Pattern Rules.)
  1092.  
  1093.    Therefore, we usually write the makefile so that the first rule is
  1094. the one for compiling the entire program or all the programs described
  1095. by the makefile (often with a target called `all').  *Note Arguments to
  1096. Specify the Goals: Goals.
  1097.  
  1098. * Menu:
  1099.  
  1100. * Rule Example::                An example explained.
  1101. * Rule Syntax::                 General syntax explained.
  1102. * Wildcards::                   Using wildcard characters such as `*'.
  1103. * Directory Search::            Searching other directories for source files.
  1104. * Phony Targets::               Using a target that is not a real file's name.
  1105. * Force Targets::               You can use a target without commands
  1106.                                   or dependencies to mark other
  1107.                                   targets as phony.
  1108. * Empty Targets::               When only the date matters and the
  1109.                                   files are empty.
  1110. * Special Targets::             Targets with special built-in meanings.
  1111. * Multiple Targets::            When to make use of several targets in a rule.
  1112. * Multiple Rules::              How to use several rules with the same target.
  1113. * Static Pattern::              Static pattern rules apply to multiple targets
  1114.                                   and can vary the dependencies according to
  1115.                                   the target name.
  1116. * Double-Colon::                How to use a special kind of rule to allow
  1117.                                   several independent rules for one target.
  1118. * Automatic Dependencies::      How to automatically generate rules giving
  1119.                                  dependencies from the source files themselves.
  1120.  
  1121. 
  1122. File: make,  Node: Rule Example,  Next: Rule Syntax,  Up: Rules
  1123.  
  1124. Rule Example
  1125. ============
  1126.  
  1127.    Here is an example of a rule:
  1128.  
  1129.      foo.o : foo.c defs.h       # module for twiddling the frobs
  1130.              cc -c -g foo.c
  1131.  
  1132.    Its target is `foo.o' and its dependencies are `foo.c' and `defs.h'.
  1133. It has one command, which is `cc -c -g foo.c'.  The command line
  1134. starts with a tab to identify it as a command.
  1135.  
  1136.    This rule says two things:
  1137.  
  1138.    * How to decide whether `foo.o' is out of date: it is out of date if
  1139.      it does not exist, or if either `foo.c' or `defs.h' is more recent
  1140.      than it.
  1141.  
  1142.    * How to update the file `foo.o': by running `cc' as stated.  The
  1143.      command does not explicitly mention `defs.h', but we presume that
  1144.      `foo.c' includes it, and that that is why `defs.h' was added to
  1145.      the dependencies.
  1146.  
  1147. 
  1148. File: make,  Node: Rule Syntax,  Next: Wildcards,  Prev: Rule Example,  Up: Rules
  1149.  
  1150. Rule Syntax
  1151. ===========
  1152.  
  1153.    In general, a rule looks like this:
  1154.  
  1155.      TARGETS : DEPENDENCIES
  1156.              COMMAND
  1157.              ...
  1158.  
  1159. or like this:
  1160.  
  1161.      TARGETS : DEPENDENCIES ; COMMAND
  1162.              COMMAND
  1163.              ...
  1164.  
  1165.    The TARGETS are file names, separated by spaces.  Wildcard
  1166. characters may be used (*note Using Wildcard Characters in File Names:
  1167. Wildcards.) and a name of the form `A(M)' represents member M in
  1168. archive file A (*note Archive Members as Targets: Archive Members.).
  1169. Usually there is only one target per rule, but occasionally there is a
  1170. reason to have more (*note Multiple Targets in a Rule: Multiple
  1171. Targets.).
  1172.  
  1173.    The COMMAND lines start with a tab character.  The first command may
  1174. appear on the line after the dependencies, with a tab character, or may
  1175. appear on the same line, with a semicolon.  Either way, the effect is
  1176. the same.  *Note Writing the Commands in Rules: Commands.
  1177.  
  1178.    Because dollar signs are used to start variable references, if you
  1179. really want a dollar sign in a rule you must write two of them, `$$'
  1180. (*note How to Use Variables: Using Variables.).  You may split a long
  1181. line by inserting a backslash followed by a newline, but this is not
  1182. required, as `make' places no limit on the length of a line in a
  1183. makefile.
  1184.  
  1185.    A rule tells `make' two things: when the targets are out of date,
  1186. and how to update them when necessary.
  1187.  
  1188.    The criterion for being out of date is specified in terms of the
  1189. DEPENDENCIES, which consist of file names separated by spaces.
  1190. (Wildcards and archive members (*note Archives::.) are allowed here
  1191. too.) A target is out of date if it does not exist or if it is older
  1192. than any of the dependencies (by comparison of last-modification
  1193. times).  The idea is that the contents of the target file are computed
  1194. based on information in the dependencies, so if any of the dependencies
  1195. changes, the contents of the existing target file are no longer
  1196. necessarily valid.
  1197.  
  1198.    How to update is specified by COMMANDS.  These are lines to be
  1199. executed by the shell (normally `sh'), but with some extra features
  1200. (*note Writing the Commands in Rules: Commands.).
  1201.  
  1202. 
  1203. File: make,  Node: Wildcards,  Next: Directory Search,  Prev: Rule Syntax,  Up: Rules
  1204.  
  1205. Using Wildcard Characters in File Names
  1206. =======================================
  1207.  
  1208.    A single file name can specify many files using "wildcard
  1209. characters".  The wildcard characters in `make' are `*', `?' and
  1210. `[...]', the same as in the Bourne shell.  For example, `*.c' specifies
  1211. a list of all the files (in the working directory) whose names end in
  1212. `.c'.
  1213.  
  1214.    The character `~' at the beginning of a file name also has special
  1215. significance.  If alone, or followed by a slash, it represents your home
  1216. directory.  For example `~/bin' expands to `/home/you/bin'.  If the `~'
  1217. is followed by a word, the string represents the home directory of the
  1218. user named by that word.  For example `~john/bin' expands to
  1219. `/home/john/bin'.
  1220.  
  1221.    Wildcard expansion happens automatically in targets, in dependencies,
  1222. and in commands (where the shell does the expansion).  In other
  1223. contexts, wildcard expansion happens only if you request it explicitly
  1224. with the `wildcard' function.
  1225.  
  1226.    The special significance of a wildcard character can be turned off by
  1227. preceding it with a backslash.  Thus, `foo\*bar' would refer to a
  1228. specific file whose name consists of `foo', an asterisk, and `bar'.
  1229.  
  1230. * Menu:
  1231.  
  1232. * Wildcard Examples::           Several examples
  1233. * Wildcard Pitfall::            Problems to avoid.
  1234. * Wildcard Function::           How to cause wildcard expansion where
  1235.                                   it does not normally take place.
  1236.  
  1237. 
  1238. File: make,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Up: Wildcards
  1239.  
  1240. Wildcard Examples
  1241. -----------------
  1242.  
  1243.    Wildcards can be used in the commands of a rule, where they are
  1244. expanded by the shell.  For example, here is a rule to delete all the
  1245. object files:
  1246.  
  1247.      clean:
  1248.              rm -f *.o
  1249.  
  1250.    Wildcards are also useful in the dependencies of a rule.  With the
  1251. following rule in the makefile, `make print' will print all the `.c'
  1252. files that have changed since the last time you printed them:
  1253.  
  1254.      print: *.c
  1255.              lpr -p $?
  1256.              touch print
  1257.  
  1258. This rule uses `print' as an empty target file; see *Note Empty Target
  1259. Files to Record Events: Empty Targets.  (The automatic variable `$?' is
  1260. used to print only those files that have changed; see *Note Automatic
  1261. Variables: Automatic.)
  1262.  
  1263.    Wildcard expansion does not happen when you define a variable.
  1264. Thus, if you write this:
  1265.  
  1266.      objects = *.o
  1267.  
  1268. then the value of the variable `objects' is the actual string `*.o'.
  1269. However, if you use the value of `objects' in a target, dependency or
  1270. command, wildcard expansion will take place at that time.  To set
  1271. `objects' to the expansion, instead use:
  1272.  
  1273.      objects := $(wildcard *.o)
  1274.  
  1275. *Note Wildcard Function::.
  1276.  
  1277. 
  1278. File: make,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
  1279.  
  1280. Pitfalls of Using Wildcards
  1281. ---------------------------
  1282.  
  1283.    Now here is an example of a naive way of using wildcard expansion,
  1284. that does not do what you would intend.  Suppose you would like to say
  1285. that the executable file `foo' is made from all the object files in the
  1286. directory, and you write this:
  1287.  
  1288.      objects = *.o
  1289.      
  1290.      foo : $(objects)
  1291.              cc -o foo $(CFLAGS) $(objects)
  1292.  
  1293. The value of `objects' is the actual string `*.o'.  Wildcard expansion
  1294. happens in the rule for `foo', so that each *existing* `.o' file
  1295. becomes a dependency of `foo' and will be recompiled if necessary.
  1296.  
  1297.    But what if you delete all the `.o' files?  When a wildcard matches
  1298. no files, it is left as it is, so then `foo' will depend on the
  1299. oddly-named file `*.o'.  Since so such file is likely to exist, `make'
  1300. will give you an error saying it cannot figure out how to make `*.o'.
  1301. This is not what you want!
  1302.  
  1303.    Actually it is possible to obtain the desired result with wildcard
  1304. expansion, but you need more sophisticated techniques, including the
  1305. `wildcard' function and string substitution.  *Note The Function
  1306. `wildcard': Wildcard Function.
  1307.  
  1308. 
  1309. File: make,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildcards
  1310.  
  1311. The Function `wildcard'
  1312. -----------------------
  1313.  
  1314.    Wildcard expansion happens automatically in rules.  But wildcard
  1315. expansion does not normally take place when a variable is set, or
  1316. inside the arguments of a function.  If you want to do wildcard
  1317. expansion in such places, you need to use the `wildcard' function, like
  1318. this:
  1319.  
  1320.      $(wildcard PATTERN...)
  1321.  
  1322. This string, used anywhere in a makefile, is replaced by a
  1323. space-separated list of names of existing files that match one of the
  1324. given file name patterns.  If no existing file name matches a pattern,
  1325. then that pattern is omitted from the output of the `wildcard'
  1326. function.  Note that this is different from how unmatched wildcards
  1327. behave in rules, where they are used verbatim rather than ignored
  1328. (*note Wildcard Pitfall::.).
  1329.  
  1330.    One use of the `wildcard' function is to get a list of all the C
  1331. source files in a directory, like this:
  1332.  
  1333.      $(wildcard *.c)
  1334.  
  1335.    We can change the list of C source files into a list of object files
  1336. by replacing the `.o' suffix with `.c' in the result, like this:
  1337.  
  1338.      $(patsubst %.c,%.o,$(wildcard *.c))
  1339.  
  1340. (Here we have used another function, `patsubst'.  *Note Functions for
  1341. String Substitution and Analysis: Text Functions.)
  1342.  
  1343.    Thus, a makefile to compile all C source files in the directory and
  1344. then link them together could be written as follows:
  1345.  
  1346.      objects := $(patsubst %.c,%.o,$(wildcard *.c))
  1347.      
  1348.      foo : $(objects)
  1349.              cc -o foo $(objects)
  1350.  
  1351. (This takes advantage of the implicit rule for compiling C programs, so
  1352. there is no need to write explicit rules for compiling the files.
  1353. *Note The Two Flavors of Variables: Flavors, for an explanation of
  1354. `:=', which is a variant of `='.)
  1355.  
  1356. 
  1357. File: make,  Node: Directory Search,  Next: Phony Targets,  Prev: Wildcards,  Up: Rules
  1358.  
  1359. Searching Directories for Dependencies
  1360. ======================================
  1361.  
  1362.    For large systems, it is often desirable to put sources in a separate
  1363. directory from the binaries.  The "directory search" features of `make'
  1364. facilitate this by searching several directories automatically to find
  1365. a dependency.  When you redistribute the files among directories, you
  1366. do not need to change the individual rules, just the search paths.
  1367.  
  1368. * Menu:
  1369.  
  1370. * General Search::              Specifying a search path that applies
  1371.                                   to every dependency.
  1372. * Selective Search::            Specifying a search path
  1373.                                   for a specified class of names.
  1374. * Commands/Search::             How to write shell commands that work together
  1375.                                   with search paths.
  1376. * Implicit/Search::             How search paths affect implicit rules.
  1377. * Libraries/Search::            Directory search for link libraries.
  1378.  
  1379. 
  1380. File: make,  Node: General Search,  Next: Selective Search,  Up: Directory Search
  1381.  
  1382. `VPATH': Search Path for All Dependencies
  1383. -----------------------------------------
  1384.  
  1385.    The value of the `make' variable `VPATH' specifies a list of
  1386. directories that `make' should search.  Most often, the directories are
  1387. expected to contain dependency files that are not in the current
  1388. directory; however, `VPATH' specifies a search list that `make' applies
  1389. for all files, including files which are targets of rules.
  1390.  
  1391.    Thus, if a file that is listed as a target or dependency does not
  1392. exist in the current directory, `make' searches the directories listed
  1393. in `VPATH' for a file with that name.  If a file is found in one of
  1394. them, that file becomes the dependency.  Rules may then specify the
  1395. names of source files in the dependencies as if they all existed in the
  1396. current directory.  *Note Writing Shell Commands with Directory Search:
  1397. Commands/Search.
  1398.  
  1399.    In the `VPATH' variable, directory names are separated by colons.
  1400. The order in which directories are listed is the order followed by
  1401. `make' in its search.
  1402.  
  1403.    For example,
  1404.  
  1405.      VPATH = src:../headers
  1406.  
  1407. specifies a path containing two directories, `src' and `../headers',
  1408. which `make' searches in that order.
  1409.  
  1410.    With this value of `VPATH', the following rule,
  1411.  
  1412.      foo.o : foo.c
  1413.  
  1414. is interpreted as if it were written like this:
  1415.  
  1416.      foo.o : src/foo.c
  1417.  
  1418. assuming the file `foo.c' does not exist in the current directory but
  1419. is found in the directory `src'.
  1420.  
  1421. 
  1422. File: make,  Node: Selective Search,  Next: Commands/Search,  Prev: General Search,  Up: Directory Search
  1423.  
  1424. The `vpath' Directive
  1425. ---------------------
  1426.  
  1427.    Similar to the `VPATH' variable but more selective is the `vpath'
  1428. directive (note lower case), which allows you to specify a search path
  1429. for a particular class of file names, those that match a particular
  1430. pattern.  Thus you can supply certain search directories for one class
  1431. of file names and other directories (or none) for other file names.
  1432.  
  1433.    There are three forms of the `vpath' directive:
  1434.  
  1435. `vpath PATTERN DIRECTORIES'
  1436.      Specify the search path DIRECTORIES for file names that match
  1437.      PATTERN.
  1438.  
  1439.      The search path, DIRECTORIES, is a colon-separated list of
  1440.      directories to be searched, just like the search path used in the
  1441.      `VPATH' variable.
  1442.  
  1443. `vpath PATTERN'
  1444.      Clear out the search path associated with PATTERN.
  1445.  
  1446. `vpath'
  1447.      Clear all search paths previously specified with `vpath'
  1448.      directives.
  1449.  
  1450.    A `vpath' pattern is a string containing a `%' character.  The
  1451. string must match the file name of a dependency that is being searched
  1452. for, the `%' character matching any sequence of zero or more characters
  1453. (as in pattern rules; *note Defining and Redefining Pattern Rules:
  1454. Pattern Rules.).  For example, `%.h' matches files that end in `.h'.
  1455. (If there is no `%', the pattern must match the dependency exactly,
  1456. which is not useful very often.)
  1457.  
  1458.    `%' characters in a `vpath' directive's pattern can be quoted with
  1459. preceding backslashes (`\').  Backslashes that would otherwise quote
  1460. `%' characters can be quoted with more backslashes.  Backslashes that
  1461. quote `%' characters or other backslashes are removed from the pattern
  1462. before it is compared to file names.  Backslashes that are not in
  1463. danger of quoting `%' characters go unmolested.
  1464.  
  1465.    When a dependency fails to exist in the current directory, if the
  1466. PATTERN in a `vpath' directive matches the name of the dependency file,
  1467. then the DIRECTORIES in that directive are searched just like (and
  1468. before) the directories in the `VPATH' variable.
  1469.  
  1470.    For example,
  1471.  
  1472.      vpath %.h ../headers
  1473.  
  1474. tells `make' to look for any dependency whose name ends in `.h' in the
  1475. directory `../headers' if the file is not found in the current
  1476. directory.
  1477.  
  1478.    If several `vpath' patterns match the dependency file's name, then
  1479. `make' processes each matching `vpath' directive one by one, searching
  1480. all the directories mentioned in each directive.  `make' handles
  1481. multiple `vpath' directives in the order in which they appear in the
  1482. makefile; multiple directives with the same pattern are independent of
  1483. each other.
  1484.  
  1485.    Thus,
  1486.  
  1487.      vpath %.c foo
  1488.      vpath %   blish
  1489.      vpath %.c bar
  1490.  
  1491. will look for a file ending in `.c' in `foo', then `blish', then `bar',
  1492. while
  1493.  
  1494.      vpath %.c foo:bar
  1495.      vpath %   blish
  1496.  
  1497. will look for a file ending in `.c' in `foo', then `bar', then `blish'.
  1498.  
  1499. 
  1500. File: make,  Node: Commands/Search,  Next: Implicit/Search,  Prev: Selective Search,  Up: Directory Search
  1501.  
  1502. Writing Shell Commands with Directory Search
  1503. --------------------------------------------
  1504.  
  1505.    When a dependency is found in another directory through directory
  1506. search, this cannot change the commands of the rule; they will execute
  1507. as written.  Therefore, you must write the commands with care so that
  1508. they will look for the dependency in the directory where `make' finds
  1509. it.
  1510.  
  1511.    This is done with the "automatic variables" such as `$^' (*note
  1512. Automatic Variables: Automatic.).  For instance, the value of `$^' is a
  1513. list of all the dependencies of the rule, including the names of the
  1514. directories in which they were found, and the value of `$@' is the
  1515. target.  Thus:
  1516.  
  1517.      foo.o : foo.c
  1518.              cc -c $(CFLAGS) $^ -o $@
  1519.  
  1520. (The variable `CFLAGS' exists so you can specify flags for C
  1521. compilation by implicit rules; we use it here for consistency so it will
  1522. affect all C compilations uniformly; *note Variables Used by Implicit
  1523. Rules: Implicit Variables..)
  1524.  
  1525.    Often the dependencies include header files as well, which you do not
  1526. want to mention in the commands.  The automatic variable `$<' is just
  1527. the first dependency:
  1528.  
  1529.      VPATH = src:../headers
  1530.      foo.o : foo.c defs.h hack.h
  1531.              cc -c $(CFLAGS) $< -o $@
  1532.  
  1533. 
  1534. File: make,  Node: Implicit/Search,  Next: Libraries/Search,  Prev: Commands/Search,  Up: Directory Search
  1535.  
  1536. Directory Search and Implicit Rules
  1537. -----------------------------------
  1538.  
  1539.    The search through the directories specified in `VPATH' or with
  1540. `vpath' also happens during consideration of implicit rules (*note
  1541. Using Implicit Rules: Implicit Rules.).
  1542.  
  1543.    For example, when a file `foo.o' has no explicit rule, `make'
  1544. considers implicit rules, such as the built-in rule to compile `foo.c'
  1545. if that file exists.  If such a file is lacking in the current
  1546. directory, the appropriate directories are searched for it.  If `foo.c'
  1547. exists (or is mentioned in the makefile) in any of the directories, the
  1548. implicit rule for C compilation is applied.
  1549.  
  1550.    The commands of implicit rules normally use automatic variables as a
  1551. matter of necessity; consequently they will use the file names found by
  1552. directory search with no extra effort.
  1553.  
  1554. 
  1555. File: make,  Node: Libraries/Search,  Prev: Implicit/Search,  Up: Directory Search
  1556.  
  1557. Directory Search for Link Libraries
  1558. -----------------------------------
  1559.  
  1560.    Directory search applies in a special way to libraries used with the
  1561. linker.  This special feature comes into play when you write a
  1562. dependency whose name is of the form `-lNAME'.  (You can tell something
  1563. strange is going on here because the dependency is normally the name of
  1564. a file, and the *file name* of the library looks like `libNAME.a', not
  1565. like `-lNAME'.)
  1566.  
  1567.    When a dependency's name has the form `-lNAME', `make' handles it
  1568. specially by searching for the file `libNAME.a' in the current
  1569. directory, in directories specified by matching `vpath' search paths
  1570. and the `VPATH' search path, and then in the directories `/lib',
  1571. `/usr/lib', and `PREFIX/lib' (normally `/usr/local/lib').
  1572.  
  1573.    For example,
  1574.  
  1575.      foo : foo.c -lcurses
  1576.              cc $^ -o $@
  1577.  
  1578. would cause the command `cc foo.c /usr/lib/libcurses.a -o foo' to be
  1579. executed when `foo' is older than `foo.c' or than
  1580. `/usr/lib/libcurses.a'.
  1581.  
  1582. 
  1583. File: make,  Node: Phony Targets,  Next: Force Targets,  Prev: Directory Search,  Up: Rules
  1584.  
  1585. Phony Targets
  1586. =============
  1587.  
  1588.    A phony target is one that is not really the name of a file.  It is
  1589. just a name for some commands to be executed when you make an explicit
  1590. request.  There are two reasons to use a phony target: to avoid a
  1591. conflict with a file of the same name, and to improve performance.
  1592.  
  1593.    If you write a rule whose commands will not create the target file,
  1594. the commands will be executed every time the target comes up for
  1595. remaking.  Here is an example:
  1596.  
  1597.      clean:
  1598.              rm *.o temp
  1599.  
  1600. Because the `rm' command does not create a file named `clean', probably
  1601. no such file will ever exist.  Therefore, the `rm' command will be
  1602. executed every time you say `make clean'.
  1603.  
  1604.    The phony target will cease to work if anything ever does create a
  1605. file named `clean' in this directory.  Since it has no dependencies, the
  1606. file `clean' would inevitably be considered up to date, and its
  1607. commands would not be executed.  To avoid this problem, you can
  1608. explicitly declare the target to be phony, using the special target
  1609. `.PHONY' (*note Special Built-in Target Names: Special Targets.) as
  1610. follows:
  1611.  
  1612.      .PHONY : clean
  1613.  
  1614. Once this is done, `make clean' will run the commands regardless of
  1615. whether there is a file named `clean'.
  1616.  
  1617.    Since it knows that phony targets do not name actual files that
  1618. could be remade from other files, `make' skips the implicit rule search
  1619. for phony targets (*note Implicit Rules::.).  This is why declaring a
  1620. target phony is good for performance, even if you are not worried about
  1621. the actual file existing.
  1622.  
  1623.    Thus, you first write the line that states that `clean' is a phony
  1624. target, then you write the rule, like this:
  1625.  
  1626.      .PHONY: clean
  1627.      clean:
  1628.              rm *.o temp
  1629.  
  1630.    A phony target should not be a dependency of a real target file; if
  1631. it is, its commands are run every time `make' goes to update that file.
  1632. As long as a phony target is never a dependency of a real target, the
  1633. phony target commands will be executed only when the phony target is a
  1634. specified goal (*note Arguments to Specify the Goals: Goals.).
  1635.  
  1636.    Phony targets can have dependencies.  When one directory contains
  1637. multiple programs, it is most convenient to describe all of the
  1638. programs in one makefile `./Makefile'.  Since the target remade by
  1639. default will be the first one in the makefile, it is common to make
  1640. this a phony target named `all' and give it, as dependencies, all the
  1641. individual programs.  For example:
  1642.  
  1643.      all : prog1 prog2 prog3
  1644.      .PHONY : all
  1645.      
  1646.      prog1 : prog1.o utils.o
  1647.              cc -o prog1 prog1.o utils.o
  1648.      
  1649.      prog2 : prog2.o
  1650.              cc -o prog2 prog2.o
  1651.      
  1652.      prog3 : prog3.o sort.o utils.o
  1653.              cc -o prog3 prog3.o sort.o utils.o
  1654.  
  1655. Now you can say just `make' to remake all three programs, or specify as
  1656. arguments the ones to remake (as in `make prog1 prog3').
  1657.  
  1658.    When one phony target is a dependency of another, it serves as a
  1659. subroutine of the other.  For example, here `make cleanall' will delete
  1660. the object files, the difference files, and the file `program':
  1661.  
  1662.      .PHONY: cleanall cleanobj cleandiff
  1663.      
  1664.      cleanall : cleanobj cleandiff
  1665.              rm program
  1666.      
  1667.      cleanobj :
  1668.              rm *.o
  1669.      
  1670.      cleandiff :
  1671.              rm *.diff
  1672.  
  1673. 
  1674. File: make,  Node: Force Targets,  Next: Empty Targets,  Prev: Phony Targets,  Up: Rules
  1675.  
  1676. Rules without Commands or Dependencies
  1677. ======================================
  1678.  
  1679.    If a rule has no dependencies or commands, and the target of the rule
  1680. is a nonexistent file, then `make' imagines this target to have been
  1681. updated whenever its rule is run.  This implies that all targets
  1682. depending on this one will always have their commands run.
  1683.  
  1684.    An example will illustrate this:
  1685.  
  1686.      clean: FORCE
  1687.              rm $(objects)
  1688.      FORCE:
  1689.  
  1690.    Here the target `FORCE' satisfies the special conditions, so the
  1691. target `clean' that depends on it is forced to run its commands.  There
  1692. is nothing special about the name `FORCE', but that is one name
  1693. commonly used this way.
  1694.  
  1695.    As you can see, using `FORCE' this way has the same results as using
  1696. `.PHONY: clean'.
  1697.  
  1698.    Using `.PHONY' is more explicit and more efficient.  However, other
  1699. versions of `make' do not support `.PHONY'; thus `FORCE' appears in
  1700. many makefiles.  *Note Phony Targets::.
  1701.  
  1702. 
  1703. File: make,  Node: Empty Targets,  Next: Special Targets,  Prev: Force Targets,  Up: Rules
  1704.  
  1705. Empty Target Files to Record Events
  1706. ===================================
  1707.  
  1708.    The "empty target" is a variant of the phony target; it is used to
  1709. hold commands for an action that you request explicitly from time to
  1710. time.  Unlike a phony target, this target file can really exist; but
  1711. the file's contents do not matter, and usually are empty.
  1712.  
  1713.    The purpose of the empty target file is to record, with its
  1714. last-modification time, when the rule's commands were last executed.  It
  1715. does so because one of the commands is a `touch' command to update the
  1716. target file.
  1717.  
  1718.    The empty target file must have some dependencies.  When you ask to
  1719. remake the empty target, the commands are executed if any dependency is
  1720. more recent than the target; in other words, if a dependency has
  1721. changed since the last time you remade the target.  Here is an example:
  1722.  
  1723.      print: foo.c bar.c
  1724.              lpr -p $?
  1725.              touch print
  1726.  
  1727. With this rule, `make print' will execute the `lpr' command if either
  1728. source file has changed since the last `make print'.  The automatic
  1729. variable `$?' is used to print only those files that have changed
  1730. (*note Automatic Variables: Automatic.).
  1731.  
  1732. 
  1733. File: make,  Node: Special Targets,  Next: Multiple Targets,  Prev: Empty Targets,  Up: Rules
  1734.  
  1735. Special Built-in Target Names
  1736. =============================
  1737.  
  1738.    Certain names have special meanings if they appear as targets.
  1739.  
  1740. `.PHONY'
  1741.      The dependencies of the special target `.PHONY' are considered to
  1742.      be phony targets.  When it is time to consider such a target,
  1743.      `make' will run its commands unconditionally, regardless of
  1744.      whether a file with that name exists or what its last-modification
  1745.      time is.  *Note Phony Targets: Phony Targets.
  1746.  
  1747. `.SUFFIXES'
  1748.      The dependencies of the special target `.SUFFIXES' are the list of
  1749.      suffixes to be used in checking for suffix rules.  *Note
  1750.      Old-Fashioned Suffix Rules: Suffix Rules.
  1751.  
  1752. `.DEFAULT'
  1753.      The commands specified for `.DEFAULT' are used for any target for
  1754.      which no rules are found (either explicit rules or implicit rules).
  1755.      *Note Last Resort::.  If `.DEFAULT' commands are specified, every
  1756.      file mentioned as a dependency, but not as a target in a rule,
  1757.      will have these commands executed on its behalf.  *Note Implicit
  1758.      Rule Search Algorithm: Search Algorithm.
  1759.  
  1760. `.PRECIOUS'
  1761.      The targets which `.PRECIOUS' depends on are given the following
  1762.      special treatment: if `make' is killed or interrupted during the
  1763.      execution of their commands, the target is not deleted.  *Note
  1764.      Interrupting or Killing `make': Interrupts.  Also, if the target
  1765.      is an intermediate file, it will not be deleted after it is no
  1766.      longer needed, as is normally done.  *Note Chains of Implicit
  1767.      Rules: Chained Rules.
  1768.  
  1769.      You can also list the target pattern of an implicit rule (such as
  1770.      `%.o') as a dependency file of the special target `.PRECIOUS' to
  1771.      preserve intermediate files created by rules whose target patterns
  1772.      match that file's name.
  1773.  
  1774. `.IGNORE'
  1775.      Simply by being mentioned as a target, `.IGNORE' says to ignore
  1776.      errors in execution of commands.  The dependencies and commands for
  1777.      `.IGNORE' are not meaningful.
  1778.  
  1779.      `.IGNORE' exists for historical compatibility.  Since `.IGNORE'
  1780.      affects every command in the makefile, it is not very useful; we
  1781.      recommend you use the more selective ways to ignore errors in
  1782.      specific commands.  *Note Errors in Commands: Errors.
  1783.  
  1784. `.SILENT'
  1785.      Simply by being mentioned as a target, `.SILENT' says not to print
  1786.      commands before executing them.  The dependencies and commands for
  1787.      `.SILENT' are not meaningful.
  1788.  
  1789.      `.SILENT' exists for historical compatibility.  We recommend you
  1790.      use the more selective ways to silence specific commands.  *Note
  1791.      Command Echoing: Echoing.  If you want to silence all commands for
  1792.      a particular run of `make', use the `-s' or `--silent' option
  1793.      (*note Options Summary::.).
  1794.  
  1795. `.EXPORT_ALL_VARIABLES'
  1796.      Simply by being mentioned as a target, this tells `make' to export
  1797.      all variables to child processes by default.  *Note Communicating
  1798.      Variables to a Sub-`make': Variables/Recursion.
  1799.  
  1800.    Any defined implicit rule suffix also counts as a special target if
  1801. it appears as a target, and so does the concatenation of two suffixes,
  1802. such as `.c.o'.  These targets are suffix rules, an obsolete way of
  1803. defining implicit rules (but a way still widely used).  In principle,
  1804. any target name could be special in this way if you break it in two and
  1805. add both pieces to the suffix list.  In practice, suffixes normally
  1806. begin with `.', so these special target names also begin with `.'.
  1807. *Note Old-Fashioned Suffix Rules: Suffix Rules.
  1808.  
  1809. 
  1810. File: make,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
  1811.  
  1812. Multiple Targets in a Rule
  1813. ==========================
  1814.  
  1815.    A rule with multiple targets is equivalent to writing many rules,
  1816. each with one target, and all identical aside from that.  The same
  1817. commands apply to all the targets, but their effects may vary because
  1818. you can substitute the actual target name into the command using `$@'.
  1819. The rule contributes the same dependencies to all the targets also.
  1820.  
  1821.    This is useful in two cases.
  1822.  
  1823.    * You want just dependencies, no commands.  For example:
  1824.  
  1825.           kbd.o command.o files.o: command.h
  1826.  
  1827.      gives an additional dependency to each of the three object files
  1828.      mentioned.
  1829.  
  1830.    * Similar commands work for all the targets.  The commands do not
  1831.      need to be absolutely identical, since the automatic variable `$@'
  1832.      can be used to substitute the particular target to be remade into
  1833.      the commands (*note Automatic Variables: Automatic.).  For example:
  1834.  
  1835.           bigoutput littleoutput : text.g
  1836.                   generate text.g -$(subst output,,$@) > $@
  1837.  
  1838.      is equivalent to
  1839.  
  1840.           bigoutput : text.g
  1841.                   generate text.g -big > bigoutput
  1842.           littleoutput : text.g
  1843.                   generate text.g -little > littleoutput
  1844.  
  1845.      Here we assume the hypothetical program `generate' makes two types
  1846.      of output, one if given `-big' and one if given `-little'.  *Note
  1847.      Functions for String Substitution and Analysis: Text Functions,
  1848.      for an explanation of the `subst' function.
  1849.  
  1850.    Suppose you would like to vary the dependencies according to the
  1851. target, much as the variable `$@' allows you to vary the commands.  You
  1852. cannot do this with multiple targets in an ordinary rule, but you can
  1853. do it with a "static pattern rule".  *Note Static Pattern Rules: Static
  1854. Pattern.
  1855.  
  1856. 
  1857. File: make,  Node: Multiple Rules,  Next: Static Pattern,  Prev: Multiple Targets,  Up: Rules
  1858.  
  1859. Multiple Rules for One Target
  1860. =============================
  1861.  
  1862.    One file can be the target of several rules.  All the dependencies
  1863. mentioned in all the rules are merged into one list of dependencies for
  1864. the target.  If the target is older than any dependency from any rule,
  1865. the commands are executed.
  1866.  
  1867.    There can only be one set of commands to be executed for a file.  If
  1868. more than one rule gives commands for the same file, `make' uses the
  1869. last set given and prints an error message.  (As a special case, if the
  1870. file's name begins with a dot, no error message is printed.  This odd
  1871. behavior is only for compatibility with other implementations of
  1872. `make'.) There is no reason to write your makefiles this way; that is
  1873. why `make' gives you an error message.
  1874.  
  1875.    An extra rule with just dependencies can be used to give a few extra
  1876. dependencies to many files at once.  For example, one usually has a
  1877. variable named `objects' containing a list of all the compiler output
  1878. files in the system being made.  An easy way to say that all of them
  1879. must be recompiled if `config.h' changes is to write the following:
  1880.  
  1881.      objects = foo.o bar.o
  1882.      foo.o : defs.h
  1883.      bar.o : defs.h test.h
  1884.      $(objects) : config.h
  1885.  
  1886.    This could be inserted or taken out without changing the rules that
  1887. really specify how to make the object files, making it a convenient
  1888. form to use if you wish to add the additional dependency intermittently.
  1889.  
  1890.    Another wrinkle is that the additional dependencies could be
  1891. specified with a variable that you set with a command argument to `make'
  1892. (*note Overriding Variables: Overriding.).  For example,
  1893.  
  1894.      extradeps=
  1895.      $(objects) : $(extradeps)
  1896.  
  1897. means that the command `make extradeps=foo.h' will consider `foo.h' as
  1898. a dependency of each object file, but plain `make' will not.
  1899.  
  1900.    If none of the explicit rules for a target has commands, then `make'
  1901. searches for an applicable implicit rule to find some commands *note
  1902. Using Implicit Rules: Implicit Rules.).
  1903.  
  1904. 
  1905. File: make,  Node: Static Pattern,  Next: Double-Colon,  Prev: Multiple Rules,  Up: Rules
  1906.  
  1907. Static Pattern Rules
  1908. ====================
  1909.  
  1910.    "Static pattern rules" are rules which specify multiple targets and
  1911. construct the dependency names for each target based on the target name.
  1912. They are more general than ordinary rules with multiple targets because
  1913. the targets do not have to have identical dependencies.  Their
  1914. dependencies must be *analogous*, but not necessarily *identical*.
  1915.  
  1916. * Menu:
  1917.  
  1918. * Static Usage::                The syntax of static pattern rules.
  1919. * Static versus Implicit::      When are they better than implicit rules?
  1920.  
  1921. 
  1922. File: make,  Node: Static Usage,  Next: Static versus Implicit,  Up: Static Pattern
  1923.  
  1924. Syntax of Static Pattern Rules
  1925. ------------------------------
  1926.  
  1927.    Here is the syntax of a static pattern rule:
  1928.  
  1929.      TARGETS ...: TARGET-PATTERN: DEP-PATTERNS ...
  1930.              COMMANDS
  1931.              ...
  1932.  
  1933. The TARGETS list specifies the targets that the rule applies to.  The
  1934. targets can contain wildcard characters, just like the targets of
  1935. ordinary rules (*note Using Wildcard Characters in File Names:
  1936. Wildcards.).
  1937.  
  1938.    The TARGET-PATTERN and DEP-PATTERNS say how to compute the
  1939. dependencies of each target.  Each target is matched against the
  1940. TARGET-PATTERN to extract a part of the target name, called the "stem".
  1941. This stem is substituted into each of the DEP-PATTERNS to make the
  1942. dependency names (one from each DEP-PATTERN).
  1943.  
  1944.    Each pattern normally contains the character `%' just once.  When the
  1945. TARGET-PATTERN matches a target, the `%' can match any part of the
  1946. target name; this part is called the "stem".  The rest of the pattern
  1947. must match exactly.  For example, the target `foo.o' matches the
  1948. pattern `%.o', with `foo' as the stem.  The targets `foo.c' and
  1949. `foo.out' do not match that pattern.
  1950.  
  1951.    The dependency names for each target are made by substituting the
  1952. stem for the `%' in each dependency pattern.  For example, if one
  1953. dependency pattern is `%.c', then substitution of the stem `foo' gives
  1954. the dependency name `foo.c'.  It is legitimate to write a dependency
  1955. pattern that does not contain `%'; then this dependency is the same for
  1956. all targets.
  1957.  
  1958.    `%' characters in pattern rules can be quoted with preceding
  1959. backslashes (`\').  Backslashes that would otherwise quote `%'
  1960. characters can be quoted with more backslashes.  Backslashes that quote
  1961. `%' characters or other backslashes are removed from the pattern before
  1962. it is compared to file names or has a stem substituted into it.
  1963. Backslashes that are not in danger of quoting `%' characters go
  1964. unmolested.  For example, the pattern `the\%weird\\%pattern\\' has
  1965. `the%weird\' preceding the operative `%' character, and `pattern\\'
  1966. following it.  The final two backslashes are left alone because they
  1967. cannot affect any `%' character.
  1968.  
  1969.    Here is an example, which compiles each of `foo.o' and `bar.o' from
  1970. the corresponding `.c' file:
  1971.  
  1972.      objects = foo.o bar.o
  1973.      
  1974.      $(objects): %.o: %.c
  1975.              $(CC) -c $(CFLAGS) $< -o $@
  1976.  
  1977. Here `$<' is the automatic variable that holds the name of the
  1978. dependency and `$@' is the automatic variable that holds the name of
  1979. the target; see *Note Automatic Variables: Automatic.
  1980.  
  1981.    Each target specified must match the target pattern; a warning is
  1982. issued for each target that does not.  If you have a list of files,
  1983. only some of which will match the pattern, you can use the `filter'
  1984. function to remove nonmatching file names (*note Functions for String
  1985. Substitution and Analysis: Text Functions.):
  1986.  
  1987.      files = foo.elc bar.o lose.o
  1988.      
  1989.      $(filter %.o,$(files)): %.o: %.c
  1990.              $(CC) -c $(CFLAGS) $< -o $@
  1991.      $(filter %.elc,$(files)): %.elc: %.el
  1992.              emacs -f batch-byte-compile $<
  1993.  
  1994. In this example the result of `$(filter %.o,$(files))' is `bar.o
  1995. lose.o', and the first static pattern rule causes each of these object
  1996. files to be updated by compiling the corresponding C source file.  The
  1997. result of `$(filter %.elc,$(files))' is `foo.elc', so that file is made
  1998. from `foo.el'.
  1999.  
  2000.    Another example shows how to use `$*' in static pattern rules:
  2001.  
  2002.      bigoutput littleoutput : %output : text.g
  2003.              generate text.g -$* > $@
  2004.  
  2005. When the `generate' command is run, `$*' will expand to the stem,
  2006. either `big' or `little'.
  2007.  
  2008. 
  2009. File: make,  Node: Static versus Implicit,  Prev: Static Usage,  Up: Static Pattern
  2010.  
  2011. Static Pattern Rules versus Implicit Rules
  2012. ------------------------------------------
  2013.  
  2014.    A static pattern rule has much in common with an implicit rule
  2015. defined as a pattern rule (*note Defining and Redefining Pattern Rules:
  2016. Pattern Rules.).  Both have a pattern for the target and patterns for
  2017. constructing the names of dependencies.  The difference is in how
  2018. `make' decides *when* the rule applies.
  2019.  
  2020.    An implicit rule *can* apply to any target that matches its pattern,
  2021. but it *does* apply only when the target has no commands otherwise
  2022. specified, and only when the dependencies can be found.  If more than
  2023. one implicit rule appears applicable, only one applies; the choice
  2024. depends on the order of rules.
  2025.  
  2026.    By contrast, a static pattern rule applies to the precise list of
  2027. targets that you specify in the rule.  It cannot apply to any other
  2028. target and it invariably does apply to each of the targets specified.
  2029. If two conflicting rules apply, and both have commands, that's an error.
  2030.  
  2031.    The static pattern rule can be better than an implicit rule for these
  2032. reasons:
  2033.  
  2034.    * You may wish to override the usual implicit rule for a few files
  2035.      whose names cannot be categorized syntactically but can be given
  2036.      in an explicit list.
  2037.  
  2038.    * If you cannot be sure of the precise contents of the directories
  2039.      you are using, you may not be sure which other irrelevant files
  2040.      might lead `make' to use the wrong implicit rule.  The choice
  2041.      might depend on the order in which the implicit rule search is
  2042.      done.  With static pattern rules, there is no uncertainty: each
  2043.      rule applies to precisely the targets specified.
  2044.  
  2045. 
  2046. File: make,  Node: Double-Colon,  Next: Automatic Dependencies,  Prev: Static Pattern,  Up: Rules
  2047.  
  2048. Double-Colon Rules
  2049. ==================
  2050.  
  2051.    "Double-colon" rules are rules written with `::' instead of `:'
  2052. after the target names.  They are handled differently from ordinary
  2053. rules when the same target appears in more than one rule.
  2054.  
  2055.    When a target appears in multiple rules, all the rules must be the
  2056. same type: all ordinary, or all double-colon.  If they are
  2057. double-colon, each of them is independent of the others.  Each
  2058. double-colon rule's commands are executed if the target is older than
  2059. any dependencies of that rule.  This can result in executing none, any,
  2060. or all of the double-colon rules.
  2061.  
  2062.    Double-colon rules with the same target are in fact completely
  2063. separate from one another.  Each double-colon rule is processed
  2064. individually, just as rules with different targets are processed.
  2065.  
  2066.    The double-colon rules for a target are executed in the order they
  2067. appear in the makefile.  However, the cases where double-colon rules
  2068. really make sense are those where the order of executing the commands
  2069. would not matter.
  2070.  
  2071.    Double-colon rules are somewhat obscure and not often very useful;
  2072. they provide a mechanism for cases in which the method used to update a
  2073. target differs depending on which dependency files caused the update,
  2074. and such cases are rare.
  2075.  
  2076.    Each double-colon rule should specify commands; if it does not, an
  2077. implicit rule will be used if one applies.  *Note Using Implicit Rules:
  2078. Implicit Rules.
  2079.  
  2080. 
  2081. File: make,  Node: Automatic Dependencies,  Prev: Double-Colon,  Up: Rules
  2082.  
  2083. Generating Dependencies Automatically
  2084. =====================================
  2085.  
  2086.    In the makefile for a program, many of the rules you need to write
  2087. often say only that some object file depends on some header file.  For
  2088. example, if `main.c' uses `defs.h' via an `#include', you would write:
  2089.  
  2090.      main.o: defs.h
  2091.  
  2092. You need this rule so that `make' knows that it must remake `main.o'
  2093. whenever `defs.h' changes.  You can see that for a large program you
  2094. would have to write dozens of such rules in your makefile.  And, you
  2095. must always be very careful to update the makefile every time you add
  2096. or remove an `#include'.
  2097.  
  2098.    To avoid this hassle, most modern C compilers can write these rules
  2099. for you, by looking at the `#include' lines in the source files.
  2100. Usually this is done with the `-M' option to the compiler.  For
  2101. example, the command:
  2102.  
  2103.      cc -M main.c
  2104.  
  2105. generates the output:
  2106.  
  2107.      main.o : main.c defs.h
  2108.  
  2109. Thus you no longer have to write all those rules yourself.  The
  2110. compiler will do it for you.
  2111.  
  2112.    With old `make' programs, it was traditional practice to use this
  2113. compiler feature to generate dependencies on demand with a command like
  2114. `make depend'.  That command would create a file `depend' containing
  2115. all the automatically-generated dependencies; then the makefile could
  2116. use `include' to read them in (*note Include::.).
  2117.  
  2118.    In GNU `make', the feature of remaking makefiles makes this practice
  2119. obsolete--you need never tell `make' explicitly to regenerate the
  2120. dependencies, because it always regenerates any makefile that is out of
  2121. date.  *Note Remaking Makefiles::.
  2122.  
  2123.    The practice we recommend for automatic dependency generation is to
  2124. have one makefile corresponding to each source file.  For each source
  2125. file `NAME.c' there is a makefile `NAME.d' which lists what files the
  2126. object file `NAME.o' depends on.  That way only the source files that
  2127. have changed need to be rescanned to produce the new dependencies.
  2128.  
  2129.    Here is the pattern rule to generate a file of dependencies (i.e., a
  2130. makefile) called `NAME.d' from a C source file called `NAME.c':
  2131.  
  2132.      %.d: %.c
  2133.              $(SHELL) -ec '$(CC) -M $(CPPFLAGS) $< | sed '\''s/$*.o/& $@/g'\'' > $@'
  2134.  
  2135. *Note Pattern Rules::, for information on defining pattern rules.  The
  2136. `-e' flag to the shell makes it exit immediately if the `$(CC)' command
  2137. fails (exits with a nonzero status).  Normally the shell exits with the
  2138. status of the last command in the pipeline (`sed' in this case), so
  2139. `make' would not notice a nonzero status from the compiler.
  2140.  
  2141.    The purpose of the `sed' command is to translate (for example):
  2142.  
  2143.      main.o : main.c defs.h
  2144.  
  2145. into:
  2146.  
  2147.      main.o main.d : main.c defs.h
  2148.  
  2149. This makes each `.d' file depend on all the source and header files
  2150. that the corresponding `.o' file depends on.  `make' then knows it must
  2151. regenerate the dependencies whenever any of the source or header files
  2152. changes.
  2153.  
  2154.    Once you've defined the rule to remake the `.d' files, you then use
  2155. the `include' directive to read them all in.  *Note Include::.  For
  2156. example:
  2157.  
  2158.      sources = foo.c bar.c
  2159.      
  2160.      include $(sources:.c=.d)
  2161.  
  2162. (This example uses a substitution variable reference to translate the
  2163. list of source files `foo.c bar.c' into a list of dependency makefiles,
  2164. `foo.d bar.d'.  *Note Substitution Refs::, for full information on
  2165. substitution references.)  Since the `.d' files are makefiles like any
  2166. others, `make' will remake them as necessary with no further work from
  2167. you.  *Note Remaking Makefiles::.
  2168.  
  2169. 
  2170. File: make,  Node: Commands,  Next: Using Variables,  Prev: Rules,  Up: Top
  2171.  
  2172. Writing the Commands in Rules
  2173. *****************************
  2174.  
  2175.    The commands of a rule consist of shell command lines to be executed
  2176. one by one.  Each command line must start with a tab, except that the
  2177. first command line may be attached to the target-and-dependencies line
  2178. with a semicolon in between.  Blank lines and lines of just comments
  2179. may appear among the command lines; they are ignored.
  2180.  
  2181.    Users use many different shell programs, but commands in makefiles
  2182. are always interpreted by `/bin/sh' unless the makefile specifies
  2183. otherwise.  *Note Command Execution: Execution.
  2184.  
  2185.    The shell that is in use determines whether comments can be written
  2186. on command lines, and what syntax they use.  When the shell is
  2187. `/bin/sh', a `#' starts a comment that extends to the end of the line.
  2188. The `#' does not have to be at the beginning of a line.  Text on a line
  2189. before a `#' is not part of the comment.
  2190.  
  2191. * Menu:
  2192.  
  2193. * Echoing::                     How to control when commands are echoed.
  2194. * Execution::                   How commands are executed.
  2195. * Parallel::                    How commands can be executed in parallel.
  2196. * Errors::                      What happens after a command execution error.
  2197. * Interrupts::                  What happens when a command is interrupted.
  2198. * Recursion::                   Invoking `make' from makefiles.
  2199. * Sequences::                   Defining canned sequences of commands.
  2200. * Empty Commands::              Defining useful, do-nothing commands.
  2201.  
  2202. 
  2203. File: make,  Node: Echoing,  Next: Execution,  Up: Commands
  2204.  
  2205. Command Echoing
  2206. ===============
  2207.  
  2208.    Normally `make' prints each command line before it is executed.  We
  2209. call this "echoing" because it gives the appearance that you are typing
  2210. the commands yourself.
  2211.  
  2212.    When a line starts with `@', the echoing of that line is suppressed.
  2213. The `@' is discarded before the command is passed to the shell.
  2214. Typically you would use this for a command whose only effect is to print
  2215. something, such as an `echo' command to indicate progress through the
  2216. makefile:
  2217.  
  2218.      @echo About to make distribution files
  2219.  
  2220.    When `make' is given the flag `-n' or `--just-print', echoing is all
  2221. that happens, no execution.  *Note Summary of Options: Options Summary.
  2222. In this case and only this case, even the commands starting with `@'
  2223. are printed.  This flag is useful for finding out which commands `make'
  2224. thinks are necessary without actually doing them.
  2225.  
  2226.    The `-s' or `--silent' flag to `make' prevents all echoing, as if
  2227. all commands started with `@'.  A rule in the makefile for the special
  2228. target `.SILENT' has the same effect (*note Special Built-in Target
  2229. Names: Special Targets.).  `.SILENT' is essentially obsolete since `@'
  2230. is more flexible.
  2231.  
  2232. 
  2233. File: make,  Node: Execution,  Next: Parallel,  Prev: Echoing,  Up: Commands
  2234.  
  2235. Command Execution
  2236. =================
  2237.  
  2238.    When it is time to execute commands to update a target, they are
  2239. executed by making a new subshell for each line.  (In practice, `make'
  2240. may take shortcuts that do not affect the results.)
  2241.  
  2242.    *Please note:* this implies that shell commands such as `cd' that
  2243. set variables local to each process will not affect the following
  2244. command lines.  If you want to use `cd' to affect the next command, put
  2245. the two on a single line with a semicolon between them.  Then `make'
  2246. will consider them a single command and pass them, together, to a shell
  2247. which will execute them in sequence.  For example:
  2248.  
  2249.      foo : bar/lose
  2250.              cd bar; gobble lose > ../foo
  2251.  
  2252.    If you would like to split a single shell command into multiple
  2253. lines of text, you must use a backslash at the end of all but the last
  2254. subline.  Such a sequence of lines is combined into a single line, by
  2255. deleting the backslash-newline sequences, before passing it to the
  2256. shell.  Thus, the following is equivalent to the preceding example:
  2257.  
  2258.      foo : bar/lose
  2259.              cd bar;  \
  2260.              gobble lose > ../foo
  2261.  
  2262.    The program used as the shell is taken from the variable `SHELL'.
  2263. By default, the program `/bin/sh' is used.
  2264.  
  2265.    Unlike most variables, the variable `SHELL' is never set from the
  2266. environment.  This is because the `SHELL' environment variable is used
  2267. to specify your personal choice of shell program for interactive use.
  2268. It would be very bad for personal choices like this to affect the
  2269. functioning of makefiles.  *Note Variables from the Environment:
  2270. Environment.
  2271.  
  2272. 
  2273. File: make,  Node: Parallel,  Next: Errors,  Prev: Execution,  Up: Commands
  2274.  
  2275. Parallel Execution
  2276. ==================
  2277.  
  2278.    GNU `make' knows how to execute several commands at once.  Normally,
  2279. `make' will execute only one command at a time, waiting for it to
  2280. finish before executing the next.  However, the `-j' or `--jobs' option
  2281. tells `make' to execute many commands simultaneously.
  2282.  
  2283.    If the `-j' option is followed by an integer, this is the number of
  2284. commands to execute at once; this is called the number of "job slots".
  2285. If there is nothing looking like an integer after the `-j' option,
  2286. there is no limit on the number of job slots.  The default number of job
  2287. slots is one, which means serial execution (one thing at a time).
  2288.  
  2289.    One unpleasant consequence of running several commands
  2290. simultaneously is that output from all of the commands comes when the
  2291. commands send it, so messages from different commands may be
  2292. interspersed.
  2293.  
  2294.    Another problem is that two processes cannot both take input from the
  2295. same device; so to make sure that only one command tries to take input
  2296. from the terminal at once, `make' will invalidate the standard input
  2297. streams of all but one running command.  This means that attempting to
  2298. read from standard input will usually be a fatal error (a `Broken pipe'
  2299. signal) for most child processes if there are several.
  2300.  
  2301.    It is unpredictable which command will have a valid standard input
  2302. stream (which will come from the terminal, or wherever you redirect the
  2303. standard input of `make').  The first command run will always get it
  2304. first, and the first command started after that one finishes will get
  2305. it next, and so on.
  2306.  
  2307.    We will change how this aspect of `make' works if we find a better
  2308. alternative.  In the mean time, you should not rely on any command using
  2309. standard input at all if you are using the parallel execution feature;
  2310. but if you are not using this feature, then standard input works
  2311. normally in all commands.
  2312.  
  2313.    If a command fails (is killed by a signal or exits with a nonzero
  2314. status), and errors are not ignored for that command (*note Errors in
  2315. Commands: Errors.), the remaining command lines to remake the same
  2316. target will not be run.  If a command fails and the `-k' or
  2317. `--keep-going' option was not given (*note Summary of Options: Options
  2318. Summary.), `make' aborts execution.  If make terminates for any reason
  2319. (including a signal) with child processes running, it waits for them to
  2320. finish before actually exiting.
  2321.  
  2322.    When the system is heavily loaded, you will probably want to run
  2323. fewer jobs than when it is lightly loaded.  You can use the `-l' option
  2324. to tell `make' to limit the number of jobs to run at once, based on the
  2325. load average.  The `-l' or `--max-load' option is followed by a
  2326. floating-point number.  For example,
  2327.  
  2328.      -l 2.5
  2329.  
  2330. will not let `make' start more than one job if the load average is
  2331. above 2.5.  The `-l' option with no following number removes the load
  2332. limit, if one was given with a previous `-l' option.
  2333.  
  2334.    More precisely, when `make' goes to start up a job, and it already
  2335. has at least one job running, it checks the current load average; if it
  2336. is not lower than the limit given with `-l', `make' waits until the load
  2337. average goes below that limit, or until all the other jobs finish.
  2338.  
  2339.    By default, there is no load limit.
  2340.  
  2341. 
  2342. File: make,  Node: Errors,  Next: Interrupts,  Prev: Parallel,  Up: Commands
  2343.  
  2344. Errors in Commands
  2345. ==================
  2346.  
  2347.    After each shell command returns, `make' looks at its exit status.
  2348. If the command completed successfully, the next command line is executed
  2349. in a new shell; after the last command line is finished, the rule is
  2350. finished.
  2351.  
  2352.    If there is an error (the exit status is nonzero), `make' gives up on
  2353. the current rule, and perhaps on all rules.
  2354.  
  2355.    Sometimes the failure of a certain command does not indicate a
  2356. problem.  For example, you may use the `mkdir' command to ensure that a
  2357. directory exists.  If the directory already exists, `mkdir' will report
  2358. an error, but you probably want `make' to continue regardless.
  2359.  
  2360.    To ignore errors in a command line, write a `-' at the beginning of
  2361. the line's text (after the initial tab).  The `-' is discarded before
  2362. the command is passed to the shell for execution.
  2363.  
  2364.    For example,
  2365.  
  2366.      clean:
  2367.              -rm -f *.o
  2368.  
  2369. This causes `rm' to continue even if it is unable to remove a file.
  2370.  
  2371.    When you run `make' with the `-i' or `--ignore-errors' flag, errors
  2372. are ignored in all commands of all rules.  A rule in the makefile for
  2373. the special target `.IGNORE' has the same effect.  These ways of
  2374. ignoring errors are obsolete because `-' is more flexible.
  2375.  
  2376.    When errors are to be ignored, because of either a `-' or the `-i'
  2377. flag, `make' treats an error return just like success, except that it
  2378. prints out a message that tells you the status code the command exited
  2379. with, and says that the error has been ignored.
  2380.  
  2381.    When an error happens that `make' has not been told to ignore, it
  2382. implies that the current target cannot be correctly remade, and neither
  2383. can any other that depends on it either directly or indirectly.  No
  2384. further commands will be executed for these targets, since their
  2385. preconditions have not been achieved.
  2386.  
  2387.    Normally `make' gives up immediately in this circumstance, returning
  2388. a nonzero status.  However, if the `-k' or `--keep-going' flag is
  2389. specified, `make' continues to consider the other dependencies of the
  2390. pending targets, remaking them if necessary, before it gives up and
  2391. returns nonzero status.  For example, after an error in compiling one
  2392. object file, `make -k' will continue compiling other object files even
  2393. though it already knows that linking them will be impossible.  *Note
  2394. Summary of Options: Options Summary.
  2395.  
  2396.    The usual behavior assumes that your purpose is to get the specified
  2397. targets up to date; once `make' learns that this is impossible, it
  2398. might as well report the failure immediately.  The `-k' option says
  2399. that the real purpose is to test as many of the changes made in the
  2400. program as possible, perhaps to find several independent problems so
  2401. that you can correct them all before the next attempt to compile.  This
  2402. is why Emacs' `compile' command passes the `-k' flag by default.
  2403.  
  2404. 
  2405. File: make,  Node: Interrupts,  Next: Recursion,  Prev: Errors,  Up: Commands
  2406.  
  2407. Interrupting or Killing `make'
  2408. ==============================
  2409.  
  2410.    If `make' gets a fatal signal while a command is executing, it may
  2411. delete the target file that the command was supposed to update.  This is
  2412. done if the target file's last-modification time has changed since
  2413. `make' first checked it.
  2414.  
  2415.    The purpose of deleting the target is to make sure that it is remade
  2416. from scratch when `make' is next run.  Why is this?  Suppose you type
  2417. `Ctrl-c' while a compiler is running, and it has begun to write an
  2418. object file `foo.o'.  The `Ctrl-c' kills the compiler, resulting in an
  2419. incomplete file whose last-modification time is newer than the source
  2420. file `foo.c'.  But `make' also receives the `Ctrl-c' signal and deletes
  2421. this incomplete file.  If `make' did not do this, the next invocation
  2422. of `make' would think that `foo.o' did not require updating--resulting
  2423. in a strange error message from the linker when it tries to link an
  2424. object file half of which is missing.
  2425.  
  2426.    You can prevent the deletion of a target file in this way by making
  2427. the special target `.PRECIOUS' depend on it.  Before remaking a target,
  2428. `make' checks to see whether it appears on the dependencies of
  2429. `.PRECIOUS', and thereby decides whether the target should be deleted
  2430. if a signal happens.  Some reasons why you might do this are that the
  2431. target is updated in some atomic fashion, or exists only to record a
  2432. modification-time (its contents do not matter), or must exist at all
  2433. times to prevent other sorts of trouble.
  2434.  
  2435. 
  2436. File: make,  Node: Recursion,  Next: Sequences,  Prev: Interrupts,  Up: Commands
  2437.  
  2438. Recursive Use of `make'
  2439. =======================
  2440.  
  2441.    Recursive use of `make' means using `make' as a command in a
  2442. makefile.  This technique is useful when you want separate makefiles for
  2443. various subsystems that compose a larger system.  For example, suppose
  2444. you have a subdirectory `subdir' which has its own makefile, and you
  2445. would like the containing directory's makefile to run `make' on the
  2446. subdirectory.  You can do it by writing this:
  2447.  
  2448.      subsystem:
  2449.              cd subdir; $(MAKE)
  2450.  
  2451. or, equivalently, this (*note Summary of Options: Options Summary.):
  2452.  
  2453.      subsystem:
  2454.              $(MAKE) -C subdir
  2455.  
  2456.    You can write recursive `make' commands just by copying this example,
  2457. but there are many things to know about how they work and why, and about
  2458. how the sub-`make' relates to the top-level `make'.
  2459.  
  2460. * Menu:
  2461.  
  2462. * MAKE Variable::               The special effects of using `$(MAKE)'.
  2463. * Variables/Recursion::         How to communicate variables to a sub-`make'.
  2464. * Options/Recursion::           How to communicate options to a sub-`make'.
  2465. * -w Option::                   How the `-w' or `--print-directory' option
  2466.                                  helps debug use of recursive `make' commands.
  2467.  
  2468. 
  2469. File: make,  Node: MAKE Variable,  Next: Variables/Recursion,  Up: Recursion
  2470.  
  2471. How the `MAKE' Variable Works
  2472. -----------------------------
  2473.  
  2474.    Recursive `make' commands should always use the variable `MAKE', not
  2475. the explicit command name `make', as shown here:
  2476.  
  2477.      subsystem:
  2478.              cd subdir; $(MAKE)
  2479.  
  2480.    The value of this variable is the file name with which `make' was
  2481. invoked.  If this file name was `/bin/make', then the command executed
  2482. is `cd subdir; /bin/make'.  If you use a special version of `make' to
  2483. run the top-level makefile, the same special version will be executed
  2484. for recursive invocations.
  2485.  
  2486.    Also, any arguments that define variable values are added to `MAKE',
  2487. so the sub-`make' gets them too.  Thus, if you do `make CFLAGS=-O', so
  2488. that all C compilations will be optimized, the sub-`make' is run with
  2489. `cd subdir; /bin/make CFLAGS=-O'.
  2490.  
  2491.    The `MAKE' variable actually just refers to two other variables
  2492. which contain these special values.  In fact, `MAKE' is always defined
  2493. as `$(MAKE_COMMAND) $(MAKEOVERRIDES)'.  The variable `MAKE_COMMAND' is
  2494. the file name with which `make' was invoked (such as `/bin/make',
  2495. above).  The variable `MAKEOVERRIDES' contains definitions for the
  2496. variables defined on the command line; in the above example, its value
  2497. is `CFLAGS=-O'.  If you *do not* want these variable definitions done
  2498. in all recursive `make' invocations, you can redefine the
  2499. `MAKEOVERRIDES' variable to remove them.  You do this in any of the
  2500. normal ways for defining variables: in a makefile (*note Setting
  2501. Variables: Setting.); on the command line with an argument like
  2502. `MAKEOVERRIDES=' (*note Overriding Variables: Overriding.); or with an
  2503. environment variable (*note Variables from the Environment:
  2504. Environment.).
  2505.  
  2506.    As a special feature, using the variable `MAKE' in the commands of a
  2507. rule alters the effects of the `-t' (`--touch'), `-n' (`--just-print'),
  2508. or `-q' (`--question') option.  Using the `MAKE' variable has the same
  2509. effect as using a `+' character at the beginning of the command line.
  2510. *Note Instead of Executing the Commands: Instead of Execution.
  2511.  
  2512.    Consider the command `make -t' in the above example.  (The `-t'
  2513. option marks targets as up to date without actually running any
  2514. commands; see *Note Instead of Execution::.)  Following the usual
  2515. definition of `-t', a `make -t' command in the example would create a
  2516. file named `subsystem' and do nothing else.  What you really want it to
  2517. do is run `cd subdir; make -t'; but that would require executing the
  2518. command, and `-t' says not to execute commands.
  2519.  
  2520.    The special feature makes this do what you want: whenever a command
  2521. line of a rule contains the variable `MAKE', the flags `-t', `-n' and
  2522. `-q' do not apply to that line.  Command lines containing `MAKE' are
  2523. executed normally despite the presence of a flag that causes most
  2524. commands not to be run.  The usual `MAKEFLAGS' mechanism passes the
  2525. flags to the sub-`make' (*note Communicating Options to a Sub-`make':
  2526. Options/Recursion.), so your request to touch the files, or print the
  2527. commands, is propagated to the subsystem.
  2528.  
  2529. 
  2530. File: make,  Node: Variables/Recursion,  Next: Options/Recursion,  Prev: MAKE Variable,  Up: Recursion
  2531.  
  2532. Communicating Variables to a Sub-`make'
  2533. ---------------------------------------
  2534.  
  2535.    Variable values of the top-level `make' can be passed to the
  2536. sub-`make' through the environment by explicit request.  These
  2537. variables are defined in the sub-`make' as defaults, but do not
  2538. override what is specified in the sub-`make''s makefile unless you use
  2539. the `-e' switch (*note Summary of Options: Options Summary.).
  2540.  
  2541.    To pass down, or "export", a variable, `make' adds the variable and
  2542. its value to the environment for running each command.  The sub-`make',
  2543. in turn, uses the environment to initialize its table of variable
  2544. values.  *Note Variables from the Environment: Environment.
  2545.  
  2546.    Except by explicit request, `make' exports a variable only if it is
  2547. either defined in the environment initially or set on the command line,
  2548. and if its name consists only of letters, numbers, and underscores.
  2549. Some shells cannot cope with environment variable names consisting of
  2550. characters other than letters, numbers, and underscores.
  2551.  
  2552.    The special variables `SHELL' and `MAKEFLAGS' are always exported
  2553. (unless you unexport them).  `MAKEFILES' is exported if you set it to
  2554. anything.
  2555.  
  2556.    Variables are *not* normally passed down if they were created by
  2557. default by `make' (*note Variables Used by Implicit Rules: Implicit
  2558. Variables.).  The sub-`make' will define these for itself.
  2559.  
  2560.    If you want to export specific variables to a sub-`make', use the
  2561. `export' directive, like this:
  2562.  
  2563.      export VARIABLE ...
  2564.  
  2565. If you want to *prevent* a variable from being exported, use the
  2566. `unexport' directive, like this:
  2567.  
  2568.      unexport VARIABLE ...
  2569.  
  2570. As a convenience, you can define a variable and export it at the same
  2571. time by doing:
  2572.  
  2573.      export VARIABLE = value
  2574.  
  2575. has the same result as:
  2576.  
  2577.      VARIABLE = value
  2578.      export VARIABLE
  2579.  
  2580. and
  2581.  
  2582.      export VARIABLE := value
  2583.  
  2584. has the same result as:
  2585.  
  2586.      VARIABLE := value
  2587.      export VARIABLE
  2588.  
  2589.    Likewise,
  2590.  
  2591.      export VARIABLE += value
  2592.  
  2593. is just like:
  2594.  
  2595.      VARIABLE += value
  2596.      export VARIABLE
  2597.  
  2598. *Note Appending More Text to Variables: Appending.
  2599.  
  2600.    You may notice that the `export' and `unexport' directives work in
  2601. `make' in the same way they work in the shell, `sh'.
  2602.  
  2603.    If you want all variables to be exported by default, you can use
  2604. `export' by itself:
  2605.  
  2606.      export
  2607.  
  2608. This tells `make' that variables which are not explicitly mentioned in
  2609. an `export' or `unexport' directive should be exported.  Any variable
  2610. given in an `unexport' directive will still *not* be exported.  If you
  2611. use `export' by itself to export variables by default, variables whose
  2612. names contain characters other than alphanumerics and underscores will
  2613. not be exported unless specifically mentioned in an `export' directive.
  2614.  
  2615.    The behavior elicited by an `export' directive by itself was the
  2616. default in older versions of GNU `make'.  If your makefiles depend on
  2617. this behavior and you want to be compatible with old versions of
  2618. `make', you can write a rule for the special target
  2619. `.EXPORT_ALL_VARIABLES' instead of using the `export' directive.  This
  2620. will be ignored by old `make's, while the `export' directive will cause
  2621. a syntax error.
  2622.  
  2623.    Likewise, you can use `unexport' by itself to tell `make' *not* to
  2624. export variables by default.  Since this is the default behavior, you
  2625. would only need to do this if `export' had been used by itself earlier
  2626. (in an included makefile, perhaps).  You *cannot* use `export' and
  2627. `unexport' by themselves to have variables exported for some commands
  2628. and not for others.  The last `export' or `unexport' directive that
  2629. appears by itself determines the behavior for the entire run of `make'.
  2630.  
  2631.    As a special feature, the variable `MAKELEVEL' is changed when it is
  2632. passed down from level to level.  This variable's value is a string
  2633. which is the depth of the level as a decimal number.  The value is `0'
  2634. for the top-level `make'; `1' for a sub-`make', `2' for a
  2635. sub-sub-`make', and so on.  The incrementation happens when `make' sets
  2636. up the environment for a command.
  2637.  
  2638.    The main use of `MAKELEVEL' is to test it in a conditional directive
  2639. (*note Conditional Parts of Makefiles: Conditionals.); this way you can
  2640. write a makefile that behaves one way if run recursively and another
  2641. way if run directly by you.
  2642.  
  2643.    You can use the variable `MAKEFILES' to cause all sub-`make'
  2644. commands to use additional makefiles.  The value of `MAKEFILES' is a
  2645. whitespace-separated list of file names.  This variable, if defined in
  2646. the outer-level makefile, is passed down through the environment; then
  2647. it serves as a list of extra makefiles for the sub-`make' to read
  2648. before the usual or specified ones.  *Note The Variable `MAKEFILES':
  2649. MAKEFILES Variable.
  2650.  
  2651. 
  2652. File: make,  Node: Options/Recursion,  Next: -w Option,  Prev: Variables/Recursion,  Up: Recursion
  2653.  
  2654. Communicating Options to a Sub-`make'
  2655. -------------------------------------
  2656.  
  2657.    Flags such as `-s' and `-k' are passed automatically to the
  2658. sub-`make' through the variable `MAKEFLAGS'.  This variable is set up
  2659. automatically by `make' to contain the flag letters that `make'
  2660. received.  Thus, if you do `make -ks' then `MAKEFLAGS' gets the value
  2661. `ks'.
  2662.  
  2663.    As a consequence, every sub-`make' gets a value for `MAKEFLAGS' in
  2664. its environment.  In response, it takes the flags from that value and
  2665. processes them as if they had been given as arguments.  *Note Summary
  2666. of Options: Options Summary.
  2667.  
  2668.    The options `-C', `-f', `-I', `-o', and `-W' are not put into
  2669. `MAKEFLAGS'; these options are not passed down.
  2670.  
  2671.    The `-j' option is a special case (*note Parallel Execution:
  2672. Parallel.).  If you set it to some numeric value, `-j 1' is always put
  2673. into `MAKEFLAGS' instead of the value you specified.  This is because if
  2674. the `-j' option were passed down to sub-`make's, you would get many
  2675. more jobs running in parallel than you asked for.  If you give `-j'
  2676. with no numeric argument, meaning to run as many jobs as possible in
  2677. parallel, this is passed down, since multiple infinities are no more
  2678. than one.
  2679.  
  2680.    If you do not want to pass the other flags down, you must change the
  2681. value of `MAKEFLAGS', like this:
  2682.  
  2683.      MAKEFLAGS=
  2684.      subsystem:
  2685.              cd subdir; $(MAKE)
  2686.  
  2687.    or like this:
  2688.  
  2689.      subsystem:
  2690.              cd subdir; $(MAKE) MAKEFLAGS=
  2691.  
  2692.    A similar variable `MFLAGS' exists also, for historical
  2693. compatibility.  It has the same value as `MAKEFLAGS' except that it
  2694. always begins with a hyphen unless it is empty (`MAKEFLAGS' begins with
  2695. a hyphen only when it begins with an option that has no single-letter
  2696. version, such as `--warn-undefined-variables').  `MFLAGS' was
  2697. traditionally used explicitly in the recursive `make' command, like
  2698. this:
  2699.  
  2700.      subsystem:
  2701.              cd subdir; $(MAKE) $(MFLAGS)
  2702.  
  2703. but now `MAKEFLAGS' makes this usage redundant.
  2704.  
  2705.    The `MAKEFLAGS' and `MFLAGS' variables can also be useful if you
  2706. want to have certain options, such as `-k' (*note Summary of Options:
  2707. Options Summary.), set each time you run `make'.  You simply put a
  2708. value for `MAKEFLAGS' or `MFLAGS' in your environment.  These variables
  2709. may also be set in makefiles, so a makefile can specify additional
  2710. flags that should also be in effect for that makefile.
  2711.  
  2712.    When `make' interprets the value of `MAKEFLAGS' or `MFLAGS' (either
  2713. from the environment or from a makefile), it first prepends a hyphen if
  2714. the value does not already begin with one.  Then it chops the value into
  2715. words separated by blanks, and parses these words as if they were
  2716. options given on the command line (except that `-C', `-f', `-h', `-o',
  2717. `-W', and their long-named versions are ignored; and there is no error
  2718. for an invalid option).
  2719.  
  2720.    If you do put `MAKEFLAGS' or `MFLAGS' in your environment, you
  2721. should be sure not to include any options that will drastically affect
  2722. the actions of `make' and undermine the purpose of makefiles and of
  2723. `make' itself.  For instance, the `-t', `-n', and `-q' options, if put
  2724. in one of these variables, could have disastrous consequences and would
  2725. certainly have at least surprising and probably annoying effects.
  2726.  
  2727. 
  2728. File: make,  Node: -w Option,  Prev: Options/Recursion,  Up: Recursion
  2729.  
  2730. The `--print-directory' Option
  2731. ------------------------------
  2732.  
  2733.    If you use several levels of recursive `make' invocations, the `-w'
  2734. or `--print-directory' option can make the output a lot easier to
  2735. understand by showing each directory as `make' starts processing it and
  2736. as `make' finishes processing it.  For example, if `make -w' is run in
  2737. the directory `/u/gnu/make', `make' will print a line of the form:
  2738.  
  2739.      make: Entering directory `/u/gnu/make'.
  2740.  
  2741. before doing anything else, and a line of the form:
  2742.  
  2743.      make: Leaving directory `/u/gnu/make'.
  2744.  
  2745. when processing is completed.
  2746.  
  2747.    Normally, you do not need to specify this option because `make' does
  2748. it for you: `-w' is turned on automatically when you use the `-C'
  2749. option, and in sub-`make's.  `make' will not automatically turn on `-w'
  2750. if you also use `-s', which says to be silent, or if you use
  2751. `--no-print-directory' to explicitly disable it.
  2752.  
  2753. 
  2754. File: make,  Node: Sequences,  Next: Empty Commands,  Prev: Recursion,  Up: Commands
  2755.  
  2756. Defining Canned Command Sequences
  2757. =================================
  2758.  
  2759.    When the same sequence of commands is useful in making various
  2760. targets, you can define it as a canned sequence with the `define'
  2761. directive, and refer to the canned sequence from the rules for those
  2762. targets.  The canned sequence is actually a variable, so the name must
  2763. not conflict with other variable names.
  2764.  
  2765.    Here is an example of defining a canned sequence of commands:
  2766.  
  2767.      define run-yacc
  2768.      yacc $(firstword $^)
  2769.      mv y.tab.c $@
  2770.      endef
  2771.  
  2772. Here `run-yacc' is the name of the variable being defined; `endef'
  2773. marks the end of the definition; the lines in between are the commands.
  2774. The `define' directive does not expand variable references and
  2775. function calls in the canned sequence; the `$' characters, parentheses,
  2776. variable names, and so on, all become part of the value of the variable
  2777. you are defining.  *Note Defining Variables Verbatim: Defining, for a
  2778. complete explanation of `define'.
  2779.  
  2780.    The first command in this example runs Yacc on the first dependency
  2781. of whichever rule uses the canned sequence.  The output file from Yacc
  2782. is always named `y.tab.c'.  The second command moves the output to the
  2783. rule's target file name.
  2784.  
  2785.    To use the canned sequence, substitute the variable into the
  2786. commands of a rule.  You can substitute it like any other variable
  2787. (*note Basics of Variable References: Reference.).  Because variables
  2788. defined by `define' are recursively expanded variables, all the
  2789. variable references you wrote inside the `define' are expanded now.
  2790. For example:
  2791.  
  2792.      foo.c : foo.y
  2793.              $(run-yacc)
  2794.  
  2795. `foo.y' will be substituted for the variable `$^' when it occurs in
  2796. `run-yacc''s value, and `foo.c' for `$@'.
  2797.  
  2798.    This is a realistic example, but this particular one is not needed in
  2799. practice because `make' has an implicit rule to figure out these
  2800. commands based on the file names involved (*note Using Implicit Rules:
  2801. Implicit Rules.).
  2802.  
  2803.    In command execution, each line of a canned sequence is treated just
  2804. as if the line appeared on its own in the rule, preceded by a tab.  In
  2805. particular, `make' invokes a separate subshell for each line.  You can
  2806. use the special prefix characters that affect command lines (`@', `-',
  2807. and `+') on each line of a canned sequence.  *Note Writing the Commands
  2808. in Rules: Commands.  For example, using this canned sequence:
  2809.  
  2810.      define frobnicate
  2811.      @echo "frobnicating target $@"
  2812.      frob-step-1 $< -o $@-step-1
  2813.      frob-step-2 $@-step-1 -o $@
  2814.      endef
  2815.  
  2816. `make' will not echo the first line, the `echo' command.  But it *will*
  2817. echo the following two command lines.
  2818.  
  2819.    On the other hand, prefix characters on the command line that refers
  2820. to a canned sequence apply to every line in the sequence.  So the rule:
  2821.  
  2822.      frob.out: frob.in
  2823.          @$(frobnicate)
  2824.  
  2825. does not echo *any* commands.  (*Note Command Echoing: Echoing, for a
  2826. full explanation of `@'.)
  2827.  
  2828. 
  2829. File: make,  Node: Empty Commands,  Prev: Sequences,  Up: Commands
  2830.  
  2831. Using Empty Commands
  2832. ====================
  2833.  
  2834.    It is sometimes useful to define commands which do nothing.  This is
  2835. done simply by giving a command that consists of nothing but
  2836. whitespace.  For example:
  2837.  
  2838.      target: ;
  2839.  
  2840. defines an empty command string for `target'.  You could also use a
  2841. line beginning with a tab character to define an empty command string,
  2842. but this would be confusing because such a line looks empty.
  2843.  
  2844.    You may be wondering why you would want to define a command string
  2845. that does nothing.  The only reason this is useful is to prevent a
  2846. target from getting implicit commands (from implicit rules or the
  2847. `.DEFAULT' special target; *note Implicit Rules::. and *note Defining
  2848. Last-Resort Default Rules: Last Resort.).
  2849.  
  2850.    You may be inclined to define empty command strings for targets that
  2851. are not actual files, but only exist so that their dependencies can be
  2852. remade.  However, this is not the best way to do that, because the
  2853. dependencies may not be remade properly if the target file actually
  2854. does exist.  *Note Phony Targets: Phony Targets, for a better way to do
  2855. this.
  2856.  
  2857. 
  2858. File: make,  Node: Using Variables,  Next: Conditionals,  Prev: Commands,  Up: Top
  2859.  
  2860. How to Use Variables
  2861. ********************
  2862.  
  2863.    A "variable" is a name defined in a makefile to represent a string
  2864. of text, called the variable's "value".  These values are substituted
  2865. by explicit request into targets, dependencies, commands, and other
  2866. parts of the makefile.  (In some other versions of `make', variables
  2867. are called "macros".)
  2868.  
  2869.    Variables and functions in all parts of a makefile are expanded when
  2870. read, except for the shell commands in rules, the right-hand sides of
  2871. variable definitions using `=', and the bodies of variable definitions
  2872. using the `define' directive.
  2873.  
  2874.    Variables can represent lists of file names, options to pass to
  2875. compilers, programs to run, directories to look in for source files,
  2876. directories to write output in, or anything else you can imagine.
  2877.  
  2878.    A variable name may be any sequence of characters not containing `:',
  2879. `#', `=', or leading or trailing whitespace.  However, variable names
  2880. containing characters other than letters, numbers, and underscores
  2881. should be avoided, as they may be given special meanings in the future,
  2882. and with some shells they cannot be passed through the environment to a
  2883. sub-`make' (*note Communicating Variables to a Sub-`make':
  2884. Variables/Recursion.).
  2885.  
  2886.    Variable names are case-sensitive.  The names `foo', `FOO', and
  2887. `Foo' all refer to different variables.
  2888.  
  2889.    It is traditional to use upper case letters in variable names, but we
  2890. recommend using lower case letters for variable names that serve
  2891. internal purposes in the makefile, and reserving upper case for
  2892. parameters that control implicit rules or for parameters that the user
  2893. should override with command options (*note Overriding Variables:
  2894. Overriding.).
  2895.  
  2896. * Menu:
  2897.  
  2898. * Reference::                   How to use the value of a variable.
  2899. * Flavors::                     Variables come in two flavors.
  2900. * Advanced::                    Advanced features for referencing a variable.
  2901. * Values::                      All the ways variables get their values.
  2902. * Setting::                     How to set a variable in the makefile.
  2903. * Appending::                   How to append more text to the old value
  2904.                                   of a variable.
  2905. * Override Directive::          How to set a variable in the makefile even if
  2906.                                   the user has set it with a command argument.
  2907. * Defining::                    An alternate way to set a variable
  2908.                                   to a verbatim string.
  2909. * Environment::                 Variable values can come from the environment.
  2910.  
  2911. 
  2912. File: make,  Node: Reference,  Next: Flavors,  Up: Using Variables
  2913.  
  2914. Basics of Variable References
  2915. =============================
  2916.  
  2917.    To substitute a variable's value, write a dollar sign followed by
  2918. the name of the variable in parentheses or braces: either `$(foo)' or
  2919. `${foo}' is a valid reference to the variable `foo'.  This special
  2920. significance of `$' is why you must write `$$' to have the effect of a
  2921. single dollar sign in a file name or command.
  2922.  
  2923.    Variable references can be used in any context: targets,
  2924. dependencies, commands, most directives, and new variable values.  Here
  2925. is an example of a common case, where a variable holds the names of all
  2926. the object files in a program:
  2927.  
  2928.      objects = program.o foo.o utils.o
  2929.      program : $(objects)
  2930.              cc -o program $(objects)
  2931.      
  2932.      $(objects) : defs.h
  2933.  
  2934.    Variable references work by strict textual substitution.  Thus, the
  2935. rule
  2936.  
  2937.      foo = c
  2938.      prog.o : prog.$(foo)
  2939.              $(foo)$(foo) -$(foo) prog.$(foo)
  2940.  
  2941. could be used to compile a C program `prog.c'.  Since spaces before the
  2942. variable value are ignored in variable assignments, the value of `foo'
  2943. is precisely `c'.  (Don't actually write your makefiles this way!)
  2944.  
  2945.    A dollar sign followed by a character other than a dollar sign,
  2946. open-parenthesis or open-brace treats that single character as the
  2947. variable name.  Thus, you could reference the variable `x' with `$x'.
  2948. However, this practice is strongly discouraged, except in the case of
  2949. the automatic variables (*note Automatic Variables: Automatic.).
  2950.  
  2951. 
  2952. File: make,  Node: Flavors,  Next: Advanced,  Prev: Reference,  Up: Using Variables
  2953.  
  2954. The Two Flavors of Variables
  2955. ============================
  2956.  
  2957.    There are two ways that a variable in GNU `make' can have a value;
  2958. we call them the two "flavors" of variables.  The two flavors are
  2959. distinguished in how they are defined and in what they do when expanded.
  2960.  
  2961.    The first flavor of variable is a "recursively expanded" variable.
  2962. Variables of this sort are defined by lines using `=' (*note Setting
  2963. Variables: Setting.) or by the `define' directive (*note Defining
  2964. Variables Verbatim: Defining.).  The value you specify is installed
  2965. verbatim; if it contains references to other variables, these
  2966. references are expanded whenever this variable is substituted (in the
  2967. course of expanding some other string).  When this happens, it is
  2968. called "recursive expansion".
  2969.  
  2970.    For example,
  2971.  
  2972.      foo = $(bar)
  2973.      bar = $(ugh)
  2974.      ugh = Huh?
  2975.      
  2976.      all:;echo $(foo)
  2977.  
  2978. will echo `Huh?': `$(foo)' expands to `$(bar)' which expands to
  2979. `$(ugh)' which finally expands to `Huh?'.
  2980.  
  2981.    This flavor of variable is the only sort supported by other versions
  2982. of `make'.  It has its advantages and its disadvantages.  An advantage
  2983. (most would say) is that:
  2984.  
  2985.      CFLAGS = $(include_dirs) -O
  2986.      include_dirs = -Ifoo -Ibar
  2987.  
  2988. will do what was intended: when `CFLAGS' is expanded in a command, it
  2989. will expand to `-Ifoo -Ibar -O'.  A major disadvantage is that you
  2990. cannot append something on the end of a variable, as in
  2991.  
  2992.      CFLAGS = $(CFLAGS) -O
  2993.  
  2994. because it will cause an infinite loop in the variable expansion.
  2995. (Actually `make' detects the infinite loop and reports an error.)
  2996.  
  2997.    Another disadvantage is that any functions (*note Functions for
  2998. Transforming Text: Functions.) referenced in the definition will be
  2999. executed every time the variable is expanded.  This makes `make' run
  3000. slower; worse, it causes the `wildcard' and `shell' functions to give
  3001. unpredictable results because you cannot easily control when they are
  3002. called, or even how many times.
  3003.  
  3004.    To avoid all the problems and inconveniences of recursively expanded
  3005. variables, there is another flavor: simply expanded variables.
  3006.  
  3007.    "Simply expanded variables" are defined by lines using `:=' (*note
  3008. Setting Variables: Setting.).  The value of a simply expanded variable
  3009. is scanned once and for all, expanding any references to other
  3010. variables and functions, when the variable is defined.  The actual
  3011. value of the simply expanded variable is the result of expanding the
  3012. text that you write.  It does not contain any references to other
  3013. variables; it contains their values *as of the time this variable was
  3014. defined*.  Therefore,
  3015.  
  3016.      x := foo
  3017.      y := $(x) bar
  3018.      x := later
  3019.  
  3020. is equivalent to
  3021.  
  3022.      y := foo bar
  3023.      x := later
  3024.  
  3025.    When a simply expanded variable is referenced, its value is
  3026. substituted verbatim.
  3027.  
  3028.    Here is a somewhat more complicated example, illustrating the use of
  3029. `:=' in conjunction with the `shell' function.  (*Note The `shell'
  3030. Function: Shell Function.)  This example also shows use of the variable
  3031. `MAKELEVEL', which is changed when it is passed down from level to
  3032. level.  (*Note Communicating Variables to a Sub-`make':
  3033. Variables/Recursion, for information about `MAKELEVEL'.)
  3034.  
  3035.      ifeq (0,${MAKELEVEL})
  3036.      cur-dir   := $(shell pwd)
  3037.      whoami    := $(shell whoami)
  3038.      host-type := $(shell arch)
  3039.      MAKE := ${MAKE} host-type=${host-type} whoami=${whoami}
  3040.      endif
  3041.  
  3042. An advantage of this use of `:=' is that a typical `descend into a
  3043. directory' command then looks like this:
  3044.  
  3045.      ${subdirs}:
  3046.            ${MAKE} cur-dir=${cur-dir}/$@ -C $@ all
  3047.  
  3048.    Simply expanded variables generally make complicated makefile
  3049. programming more predictable because they work like variables in most
  3050. programming languages.  They allow you to redefine a variable using its
  3051. own value (or its value processed in some way by one of the expansion
  3052. functions) and to use the expansion functions much more efficiently
  3053. (*note Functions for Transforming Text: Functions.).
  3054.  
  3055.    You can also use them to introduce controlled leading or trailing
  3056. spaces into variable values.  Such spaces are discarded from your input
  3057. before substitution of variable references and function calls; this
  3058. means you can include leading or trailing spaces in a variable value by
  3059. protecting them with variable references, like this:
  3060.  
  3061.      nullstring :=
  3062.      space := $(nullstring) $(nullstring)
  3063.  
  3064. Here the value of the variable `space' is precisely one space.
  3065.  
  3066. 
  3067. File: make,  Node: Advanced,  Next: Values,  Prev: Flavors,  Up: Using Variables
  3068.  
  3069. Advanced Features for Reference to Variables
  3070. ============================================
  3071.  
  3072.    This section describes some advanced features you can use to
  3073. reference variables in more flexible ways.
  3074.  
  3075. * Menu:
  3076.  
  3077. * Substitution Refs::           Referencing a variable with
  3078.                                   substitutions on the value.
  3079. * Computed Names::              Computing the name of the variable to refer to.
  3080.  
  3081. 
  3082. File: make,  Node: Substitution Refs,  Next: Computed Names,  Up: Advanced
  3083.  
  3084. Substitution References
  3085. -----------------------
  3086.  
  3087.    A "substitution reference" substitutes the value of a variable with
  3088. alterations that you specify.  It has the form `$(VAR:A=B)' (or
  3089. `${VAR:A=B}') and its meaning is to take the value of the variable VAR,
  3090. replace every A at the end of a word with B in that value, and
  3091. substitute the resulting string.
  3092.  
  3093.    When we say "at the end of a word", we mean that A must appear
  3094. either followed by whitespace or at the end of the value in order to be
  3095. replaced; other occurrences of A in the value are unaltered.  For
  3096. example:
  3097.  
  3098.      foo := a.o b.o c.o
  3099.      bar := $(foo:.o=.c)
  3100.  
  3101. sets `bar' to `a.c b.c c.c'.  *Note Setting Variables: Setting.
  3102.  
  3103.    A substitution reference is actually an abbreviation for use of the
  3104. `patsubst' expansion function (*note Functions for String Substitution
  3105. and Analysis: Text Functions.).  We provide substitution references as
  3106. well as `patsubst' for compatibility with other implementations of
  3107. `make'.
  3108.  
  3109.    Another type of substitution reference lets you use the full power of
  3110. the `patsubst' function.  It has the same form `$(VAR:A=B)' described
  3111. above, except that now A must contain a single `%' character.  This
  3112. case is equivalent to `$(patsubst A,B,$(VAR))'.  *Note Functions for
  3113. String Substitution and Analysis: Text Functions, for a description of
  3114. the `patsubst' function.
  3115.  
  3116. For example:
  3117.  
  3118.      foo := a.o b.o c.o
  3119.      bar := $(foo:%.o=%.c)
  3120.  
  3121. sets `bar' to `a.c b.c c.c'.
  3122.  
  3123. 
  3124. File: make,  Node: Computed Names,  Prev: Substitution Refs,  Up: Advanced
  3125.  
  3126. Computed Variable Names
  3127. -----------------------
  3128.  
  3129.    Computed variable names are a complicated concept needed only for
  3130. sophisticated makefile programming.  For most purposes you need not
  3131. consider them, except to know that making a variable with a dollar sign
  3132. in its name might have strange results.  However, if you are the type
  3133. that wants to understand everything, or you are actually interested in
  3134. what they do, read on.
  3135.  
  3136.    Variables may be referenced inside the name of a variable.  This is
  3137. called a "computed variable name" or a "nested variable reference".
  3138. For example,
  3139.  
  3140.      x = y
  3141.      y = z
  3142.      a := $($(x))
  3143.  
  3144. defines `a' as `z': the `$(x)' inside `$($(x))' expands to `y', so
  3145. `$($(x))' expands to `$(y)' which in turn expands to `z'.  Here the
  3146. name of the variable to reference is not stated explicitly; it is
  3147. computed by expansion of `$(x)'.  The reference `$(x)' here is nested
  3148. within the outer variable reference.
  3149.  
  3150.    The previous example shows two levels of nesting, but any number of
  3151. levels is possible.  For example, here are three levels:
  3152.  
  3153.      x = y
  3154.      y = z
  3155.      z = u
  3156.      a := $($($(x)))
  3157.  
  3158. Here the innermost `$(x)' expands to `y', so `$($(x))' expands to
  3159. `$(y)' which in turn expands to `z'; now we have `$(z)', which becomes
  3160. `u'.
  3161.  
  3162.    References to recursively-expanded variables within a variable name
  3163. are reexpanded in the usual fashion.  For example:
  3164.  
  3165.      x = $(y)
  3166.      y = z
  3167.      z = Hello
  3168.      a := $($(x))
  3169.  
  3170. defines `a' as `Hello': `$($(x))' becomes `$($(y))' which becomes
  3171. `$(z)' which becomes `Hello'.
  3172.  
  3173.    Nested variable references can also contain modified references and
  3174. function invocations (*note Functions for Transforming Text:
  3175. Functions.), just like any other reference.  For example, using the
  3176. `subst' function (*note Functions for String Substitution and Analysis:
  3177. Text Functions.):
  3178.  
  3179.      x = variable1
  3180.      variable2 := Hello
  3181.      y = $(subst 1,2,$(x))
  3182.      z = y
  3183.      a := $($($(z)))
  3184.  
  3185. eventually defines `a' as `Hello'.  It is doubtful that anyone would
  3186. ever want to write a nested reference as convoluted as this one, but it
  3187. works: `$($($(z)))' expands to `$($(y))' which becomes `$($(subst
  3188. 1,2,$(x)))'.  This gets the value `variable1' from `x' and changes it
  3189. by substitution to `variable2', so that the entire string becomes
  3190. `$(variable2)', a simple variable reference whose value is `Hello'.
  3191.  
  3192.    A computed variable name need not consist entirely of a single
  3193. variable reference.  It can contain several variable references, as
  3194. well as some invariant text.  For example,
  3195.  
  3196.      a_dirs := dira dirb
  3197.      1_dirs := dir1 dir2
  3198.      
  3199.      a_files := filea fileb
  3200.      1_files := file1 file2
  3201.      
  3202.      ifeq "$(use_a)" "yes"
  3203.      a1 := a
  3204.      else
  3205.      a1 := 1
  3206.      endif
  3207.      
  3208.      ifeq "$(use_dirs)" "yes"
  3209.      df := dirs
  3210.      else
  3211.      df := files
  3212.      endif
  3213.      
  3214.      dirs := $($(a1)_$(df))
  3215.  
  3216. will give `dirs' the same value as `a_dirs', `1_dirs', `a_files' or
  3217. `1_files' depending on the settings of `use_a' and `use_dirs'.
  3218.  
  3219.    Computed variable names can also be used in substitution references:
  3220.  
  3221.      a_objects := a.o b.o c.o
  3222.      1_objects := 1.o 2.o 3.o
  3223.      
  3224.      sources := $($(a1)_objects:.o=.c)
  3225.  
  3226. defines `sources' as either `a.c b.c c.c' or `1.c 2.c 3.c', depending
  3227. on the value of `a1'.
  3228.  
  3229.    The only restriction on this sort of use of nested variable
  3230. references is that they cannot specify part of the name of a function
  3231. to be called.  This is because the test for a recognized function name
  3232. is done before the expansion of nested references.  For example,
  3233.  
  3234.      ifdef do_sort
  3235.      func := sort
  3236.      else
  3237.      func := strip
  3238.      endif
  3239.      
  3240.      bar := a d b g q c
  3241.      
  3242.      foo := $($(func) $(bar))
  3243.  
  3244. attempts to give `foo' the value of the variable `sort a d b g q c' or
  3245. `strip a d b g q c', rather than giving `a d b g q c' as the argument
  3246. to either the `sort' or the `strip' function.  This restriction could
  3247. be removed in the future if that change is shown to be a good idea.
  3248.  
  3249.    You can also use computed variable names in the left-hand side of a
  3250. variable assignment, or in a `define' directive, as in:
  3251.  
  3252.      dir = foo
  3253.      $(dir)_sources := $(wildcard $(dir)/*.c)
  3254.      define $(dir)_print
  3255.      lpr $($(dir)_sources)
  3256.      endef
  3257.  
  3258. This example defines the variables `dir', `foo_sources', and
  3259. `foo_print'.
  3260.  
  3261.    Note that "nested variable references" are quite different from
  3262. "recursively expanded variables" (*note The Two Flavors of Variables:
  3263. Flavors.), though both are used together in complex ways when doing
  3264. makefile programming.
  3265.  
  3266. 
  3267. File: make,  Node: Values,  Next: Setting,  Prev: Advanced,  Up: Using Variables
  3268.  
  3269. How Variables Get Their Values
  3270. ==============================
  3271.  
  3272.    Variables can get values in several different ways:
  3273.  
  3274.    * You can specify an overriding value when you run `make'.  *Note
  3275.      Overriding Variables: Overriding.
  3276.  
  3277.    * You can specify a value in the makefile, either with an assignment
  3278.      (*note Setting Variables: Setting.) or with a verbatim definition
  3279.      (*note Defining Variables Verbatim: Defining.).
  3280.  
  3281.    * Variables in the environment become `make' variables.  *Note
  3282.      Variables from the Environment: Environment.
  3283.  
  3284.    * Several "automatic" variables are given new values for each rule.
  3285.      Each of these has a single conventional use.  *Note Automatic
  3286.      Variables: Automatic.
  3287.  
  3288.    * Several variables have constant initial values.  *Note Variables
  3289.      Used by Implicit Rules: Implicit Variables.
  3290.  
  3291. 
  3292. File: make,  Node: Setting,  Next: Appending,  Prev: Values,  Up: Using Variables
  3293.  
  3294. Setting Variables
  3295. =================
  3296.  
  3297.    To set a variable from the makefile, write a line starting with the
  3298. variable name followed by `=' or `:='.  Whatever follows the `=' or
  3299. `:=' on the line becomes the value.  For example,
  3300.  
  3301.      objects = main.o foo.o bar.o utils.o
  3302.  
  3303. defines a variable named `objects'.  Whitespace around the variable
  3304. name and immediately after the `=' is ignored.
  3305.  
  3306.    Variables defined with `=' are "recursively expanded" variables.
  3307. Variables defined with `:=' are "simply expanded" variables; these
  3308. definitions can contain variable references which will be expanded
  3309. before the definition is made.  *Note The Two Flavors of Variables:
  3310. Flavors.
  3311.  
  3312.    The variable name may contain function and variable references, which
  3313. are expanded when the line is read to find the actual variable name to
  3314. use.
  3315.  
  3316.    There is no limit on the length of the value of a variable except the
  3317. amount of swapping space on the computer.  When a variable definition is
  3318. long, it is a good idea to break it into several lines by inserting
  3319. backslash-newline at convenient places in the definition.  This will not
  3320. affect the functioning of `make', but it will make the makefile easier
  3321. to read.
  3322.  
  3323.    Most variable names are considered to have the empty string as a
  3324. value if you have never set them.  Several variables have built-in
  3325. initial values that are not empty, but you can set them in the usual
  3326. ways (*note Variables Used by Implicit Rules: Implicit Variables.).
  3327. Several special variables are set automatically to a new value for each
  3328. rule; these are called the "automatic" variables (*note Automatic
  3329. Variables: Automatic.).
  3330.  
  3331. 
  3332. File: make,  Node: Appending,  Next: Override Directive,  Prev: Setting,  Up: Using Variables
  3333.  
  3334. Appending More Text to Variables
  3335. ================================
  3336.  
  3337.    Often it is useful to add more text to the value of a variable
  3338. already defined.  You do this with a line containing `+=', like this:
  3339.  
  3340.      objects += another.o
  3341.  
  3342. This takes the value of the variable `objects', and adds the text
  3343. `another.o' to it (preceded by a single space).  Thus:
  3344.  
  3345.      objects = main.o foo.o bar.o utils.o
  3346.      objects += another.o
  3347.  
  3348. sets `objects' to `main.o foo.o bar.o utils.o another.o'.
  3349.  
  3350.    Using `+=' is similar to:
  3351.  
  3352.      objects = main.o foo.o bar.o utils.o
  3353.      objects := $(objects) another.o
  3354.  
  3355. but differs in ways that become important when you use more complex
  3356. values.
  3357.  
  3358.    When the variable in question has not been defined before, `+=' acts
  3359. just like normal `=': it defines a recursively-expanded variable.
  3360. However, when there *is* a previous definition, exactly what `+=' does
  3361. depends on what flavor of variable you defined originally.  *Note The
  3362. Two Flavors of Variables: Flavors, for an explanation of the two
  3363. flavors of variables.
  3364.  
  3365.    When you add to a variable's value with `+=', `make' acts
  3366. essentially as if you had included the extra text in the initial
  3367. definition of the variable.  If you defined it first with `:=', making
  3368. it a simply-expanded variable, `+=' adds to that simply-expanded
  3369. definition, and expands the new text before appending it to the old
  3370. value just as `:=' does (*note Setting Variables: Setting., for a full
  3371. explanation of `:=').  In fact,
  3372.  
  3373.      variable := value
  3374.      variable += more
  3375.  
  3376. is exactly equivalent to:
  3377.  
  3378.      variable := value
  3379.      variable := $(variable) more
  3380.  
  3381.    On the other hand, when you use `+=' with a variable that you defined
  3382. first to be recursively-expanded using plain `=', `make' does something
  3383. a bit different.  Recall that when you define a recursively-expanded
  3384. variable, `make' does not expand the value you set for variable and
  3385. function references immediately.  Instead it stores the text verbatim,
  3386. and saves these variable and function references to be expanded later,
  3387. when you refer to the new variable (*note The Two Flavors of Variables:
  3388. Flavors.).  When you use `+=' on a recursively-expanded variable, it is
  3389. this unexpanded text to which `make' appends the new text you specify.
  3390.  
  3391.      variable = value
  3392.      variable += more
  3393.  
  3394. is roughly equivalent to:
  3395.  
  3396.      temp = value
  3397.      variable = $(temp) more
  3398.  
  3399. except that of course it never defines a variable called `temp'.  The
  3400. importance of this comes when the variable's old value contains
  3401. variable references.  Take this common example:
  3402.  
  3403.      CFLAGS = $(includes) -O
  3404.      ...
  3405.      CFLAGS += -pg # enable profiling
  3406.  
  3407. The first line defines the `CFLAGS' variable with a reference to another
  3408. variable, `includes'.  (`CFLAGS' is used by the rules for C
  3409. compilation; *note Catalogue of Implicit Rules: Catalogue of Rules..)
  3410. Using `=' for the definition makes `CFLAGS' a recursively-expanded
  3411. variable, meaning `$(includes) -O' is *not* expanded when `make'
  3412. processes the definition of `CFLAGS'.  Thus, `includes' need not be
  3413. defined yet for its value to take effect.  It only has to be defined
  3414. before any reference to `CFLAGS'.  If we tried to append to the value
  3415. of `CFLAGS' without using `+=', we might do it like this:
  3416.  
  3417.      CFLAGS := $(CFLAGS) -pg # enable profiling
  3418.  
  3419. This is pretty close, but not quite what we want.  Using `:=' redefines
  3420. `CFLAGS' as a simply-expanded variable; this means `make' expands the
  3421. text `$(CFLAGS) -pg' before setting the variable.  If `includes' is not
  3422. yet defined, we get ` -O -pg', and a later definition of `includes'
  3423. will have no effect.  Conversely, by using `+=' we set `CFLAGS' to the
  3424. *unexpanded* value `$(includes) -O -pg'.  Thus we preserve the
  3425. reference to `includes', so if that variable gets defined at any later
  3426. point, a reference like `$(CFLAGS)' still uses its value.
  3427.  
  3428. 
  3429. File: make,  Node: Override Directive,  Next: Defining,  Prev: Appending,  Up: Using Variables
  3430.  
  3431. The `override' Directive
  3432. ========================
  3433.  
  3434.    If a variable has been set with a command argument (*note Overriding
  3435. Variables: Overriding.), then ordinary assignments in the makefile are
  3436. ignored.  If you want to set the variable in the makefile even though
  3437. it was set with a command argument, you can use an `override'
  3438. directive, which is a line that looks like this:
  3439.  
  3440.      override VARIABLE = VALUE
  3441.  
  3442. or
  3443.  
  3444.      override VARIABLE := VALUE
  3445.  
  3446.    To append more text to a variable defined on the command line, use:
  3447.  
  3448.      override VARIABLE += MORE TEXT
  3449.  
  3450. *Note Appending More Text to Variables: Appending.
  3451.  
  3452.    The `override' directive was not invented for escalation in the war
  3453. between makefiles and command arguments.  It was invented so you can
  3454. alter and add to values that the user specifies with command arguments.
  3455.  
  3456.    For example, suppose you always want the `-g' switch when you run the
  3457. C compiler, but you would like to allow the user to specify the other
  3458. switches with a command argument just as usual.  You could use this
  3459. `override' directive:
  3460.  
  3461.      override CFLAGS += -g
  3462.  
  3463.    You can also use `override' directives with `define' directives.
  3464. This is done as you might expect:
  3465.  
  3466.      override define foo
  3467.      bar
  3468.      endef
  3469.  
  3470. *Note Defining Variables Verbatim: Defining.
  3471.  
  3472. 
  3473. File: make,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Using Variables
  3474.  
  3475. Defining Variables Verbatim
  3476. ===========================
  3477.  
  3478. Another way to set the value of a variable is to use the `define'
  3479. directive.  This directive has an unusual syntax which allows newline
  3480. characters to be included in the value, which is convenient for defining
  3481. canned sequences of commands (*note Defining Canned Command Sequences:
  3482. Sequences.).
  3483.  
  3484.    The `define' directive is followed on the same line by the name of
  3485. the variable and nothing more.  The value to give the variable appears
  3486. on the following lines.  The end of the value is marked by a line
  3487. containing just the word `endef'.  Aside from this difference in
  3488. syntax, `define' works just like `=': it creates a recursively-expanded
  3489. variable (*note The Two Flavors of Variables: Flavors.).  The variable
  3490. name may contain function and variable references, which are expanded
  3491. when the directive is read to find the actual variable name to use.
  3492.  
  3493.      define two-lines
  3494.      echo foo
  3495.      echo $(bar)
  3496.      endef
  3497.  
  3498.    The value in an ordinary assignment cannot contain a newline; but the
  3499. newlines that separate the lines of the value in a `define' become part
  3500. of the variable's value (except for the final newline which precedes
  3501. the `endef' and is not considered part of the value).
  3502.  
  3503.    The previous example is functionally equivalent to this:
  3504.  
  3505.      two-lines = echo foo; echo $(bar)
  3506.  
  3507. since two commands separated by semicolon behave much like two separate
  3508. shell commands.  However, note that using two separate lines means
  3509. `make' will invoke the shell twice, running an independent subshell for
  3510. each line.  *Note Command Execution: Execution.
  3511.  
  3512.    If you want variable definitions made with `define' to take
  3513. precedence over command-line variable definitions, you can use the
  3514. `override' directive together with `define':
  3515.  
  3516.      override define two-lines
  3517.      foo
  3518.      $(bar)
  3519.      endef
  3520.  
  3521. *Note The `override' Directive: Override Directive.
  3522.  
  3523. 
  3524. File: make,  Node: Environment,  Prev: Defining,  Up: Using Variables
  3525.  
  3526. Variables from the Environment
  3527. ==============================
  3528.  
  3529.    Variables in `make' can come from the environment in which `make' is
  3530. run.  Every environment variable that `make' sees when it starts up is
  3531. transformed into a `make' variable with the same name and value.  But
  3532. an explicit assignment in the makefile, or with a command argument,
  3533. overrides the environment.  (If the `-e' flag is specified, then values
  3534. from the environment override assignments in the makefile.  *Note
  3535. Summary of Options: Options Summary.  But this is not recommended
  3536. practice.)
  3537.  
  3538.    Thus, by setting the variable `CFLAGS' in your environment, you can
  3539. cause all C compilations in most makefiles to use the compiler switches
  3540. you prefer.  This is safe for variables with standard or conventional
  3541. meanings because you know that no makefile will use them for other
  3542. things.  (But this is not totally reliable; some makefiles set `CFLAGS'
  3543. explicitly and therefore are not affected by the value in the
  3544. environment.)
  3545.  
  3546.    When `make' is invoked recursively, variables defined in the outer
  3547. invocation can be passed to inner invocations through the environment
  3548. (*note Recursive Use of `make': Recursion.).  By default, only
  3549. variables that came from the environment or the command line are passed
  3550. to recursive invocations.  You can use the `export' directive to pass
  3551. other variables.  *Note Communicating Variables to a Sub-`make':
  3552. Variables/Recursion, for full details.
  3553.  
  3554.    Other use of variables from the environment is not recommended.  It
  3555. is not wise for makefiles to depend for their functioning on
  3556. environment variables set up outside their control, since this would
  3557. cause different users to get different results from the same makefile.
  3558. This is against the whole purpose of most makefiles.
  3559.  
  3560.    Such problems would be especially likely with the variable `SHELL',
  3561. which is normally present in the environment to specify the user's
  3562. choice of interactive shell.  It would be very undesirable for this
  3563. choice to affect `make'.  So `make' ignores the environment value of
  3564. `SHELL'.
  3565.  
  3566. 
  3567. File: make,  Node: Conditionals,  Next: Functions,  Prev: Using Variables,  Up: Top
  3568.  
  3569. Conditional Parts of Makefiles
  3570. ******************************
  3571.  
  3572.    A "conditional" causes part of a makefile to be obeyed or ignored
  3573. depending on the values of variables.  Conditionals can compare the
  3574. value of one variable to another, or the value of a variable to a
  3575. constant string.  Conditionals control what `make' actually "sees" in
  3576. the makefile, so they *cannot* be used to control shell commands at the
  3577. time of execution.
  3578.  
  3579. * Menu:
  3580.  
  3581. * Conditional Example::         Example of a conditional
  3582. * Conditional Syntax::          The syntax of conditionals.
  3583. * Testing Flags::               Conditionals that test flags.
  3584.  
  3585. 
  3586. File: make,  Node: Conditional Example,  Next: Conditional Syntax,  Up: Conditionals
  3587.  
  3588. Example of a Conditional
  3589. ========================
  3590.  
  3591.    The following example of a conditional tells `make' to use one set
  3592. of libraries if the `CC' variable is `gcc', and a different set of
  3593. libraries otherwise.  It works by controlling which of two command
  3594. lines will be used as the command for a rule.  The result is that
  3595. `CC=gcc' as an argument to `make' changes not only which compiler is
  3596. used but also which libraries are linked.
  3597.  
  3598.      libs_for_gcc = -lgnu
  3599.      normal_libs =
  3600.      
  3601.      foo: $(objects)
  3602.      ifeq ($(CC),gcc)
  3603.              $(CC) -o foo $(objects) $(libs_for_gcc)
  3604.      else
  3605.              $(CC) -o foo $(objects) $(normal_libs)
  3606.      endif
  3607.  
  3608.    This conditional uses three directives: one `ifeq', one `else' and
  3609. one `endif'.
  3610.  
  3611.    The `ifeq' directive begins the conditional, and specifies the
  3612. condition.  It contains two arguments, separated by a comma and
  3613. surrounded by parentheses.  Variable substitution is performed on both
  3614. arguments and then they are compared.  The lines of the makefile
  3615. following the `ifeq' are obeyed if the two arguments match; otherwise
  3616. they are ignored.
  3617.  
  3618.    The `else' directive causes the following lines to be obeyed if the
  3619. previous conditional failed.  In the example above, this means that the
  3620. second alternative linking command is used whenever the first
  3621. alternative is not used.  It is optional to have an `else' in a
  3622. conditional.
  3623.  
  3624.    The `endif' directive ends the conditional.  Every conditional must
  3625. end with an `endif'.  Unconditional makefile text follows.
  3626.  
  3627.    As this example illustrates, conditionals work at the textual level:
  3628. the lines of the conditional are treated as part of the makefile, or
  3629. ignored, according to the condition.  This is why the larger syntactic
  3630. units of the makefile, such as rules, may cross the beginning or the
  3631. end of the conditional.
  3632.  
  3633.    When the variable `CC' has the value `gcc', the above example has
  3634. this effect:
  3635.  
  3636.      foo: $(objects)
  3637.              $(CC) -o foo $(objects) $(libs_for_gcc)
  3638.  
  3639. When the variable `CC' has any other value, the effect is this:
  3640.  
  3641.      foo: $(objects)
  3642.              $(CC) -o foo $(objects) $(normal_libs)
  3643.  
  3644.    Equivalent results can be obtained in another way by
  3645. conditionalizing a variable assignment and then using the variable
  3646. unconditionally:
  3647.  
  3648.      libs_for_gcc = -lgnu
  3649.      normal_libs =
  3650.      
  3651.      ifeq ($(CC),gcc)
  3652.        libs=$(libs_for_gcc)
  3653.      else
  3654.        libs=$(normal_libs)
  3655.      endif
  3656.      
  3657.      foo: $(objects)
  3658.              $(CC) -o foo $(objects) $(libs)
  3659.  
  3660. 
  3661. File: make,  Node: Conditional Syntax,  Next: Testing Flags,  Prev: Conditional Example,  Up: Conditionals
  3662.  
  3663. Syntax of Conditionals
  3664. ======================
  3665.  
  3666.    The syntax of a simple conditional with no `else' is as follows:
  3667.  
  3668.      CONDITIONAL-DIRECTIVE
  3669.      TEXT-IF-TRUE
  3670.      endif
  3671.  
  3672. The TEXT-IF-TRUE may be any lines of text, to be considered as part of
  3673. the makefile if the condition is true.  If the condition is false, no
  3674. text is used instead.
  3675.  
  3676.    The syntax of a complex conditional is as follows:
  3677.  
  3678.      CONDITIONAL-DIRECTIVE
  3679.      TEXT-IF-TRUE
  3680.      else
  3681.      TEXT-IF-FALSE
  3682.      endif
  3683.  
  3684. If the condition is true, TEXT-IF-TRUE is used; otherwise,
  3685. TEXT-IF-FALSE is used instead.  The TEXT-IF-FALSE can be any number of
  3686. lines of text.
  3687.  
  3688.    The syntax of the CONDITIONAL-DIRECTIVE is the same whether the
  3689. conditional is simple or complex.  There are four different directives
  3690. that test different conditions.  Here is a table of them:
  3691.  
  3692. `ifeq (ARG1, ARG2)'
  3693. `ifeq 'ARG1' 'ARG2''
  3694. `ifeq "ARG1" "ARG2"'
  3695. `ifeq "ARG1" 'ARG2''
  3696. `ifeq 'ARG1' "ARG2"'
  3697.      Expand all variable references in ARG1 and ARG2 and compare them.
  3698.      If they are identical, the TEXT-IF-TRUE is effective; otherwise,
  3699.      the TEXT-IF-FALSE, if any, is effective.
  3700.  
  3701.      Often you want to test if a variable has a non-empty value.  When
  3702.      the value results from complex expansions of variables and
  3703.      functions, expansions you would consider empty may actually
  3704.      contain whitespace characters and thus are not seen as empty.
  3705.      However, you can use the `strip' function (*note Text
  3706.      Functions::.) to avoid interpreting whitespace as a non-empty
  3707.      value.  For example:
  3708.  
  3709.           ifeq ($(strip $(foo)),)
  3710.           TEXT-IF-EMPTY
  3711.           endif
  3712.  
  3713.      will evaluate TEXT-IF-EMPTY even if the expansion of `$(foo)'
  3714.      contains whitespace characters.
  3715.  
  3716. `ifneq (ARG1, ARG2)'
  3717. `ifneq 'ARG1' 'ARG2''
  3718. `ifneq "ARG1" "ARG2"'
  3719. `ifneq "ARG1" 'ARG2''
  3720. `ifneq 'ARG1' "ARG2"'
  3721.      Expand all variable references in ARG1 and ARG2 and compare them.
  3722.      If they are different, the TEXT-IF-TRUE is effective; otherwise,
  3723.      the TEXT-IF-FALSE, if any, is effective.
  3724.  
  3725. `ifdef VARIABLE-NAME'
  3726.      If the variable VARIABLE-NAME has a non-empty value, the
  3727.      TEXT-IF-TRUE is effective; otherwise, the TEXT-IF-FALSE, if any,
  3728.      is effective.  Variables that have never been defined have an
  3729.      empty value.
  3730.  
  3731.      Note that `ifdef' only tests whether a variable has a value.  It
  3732.      does not expand the variable to see if that value is nonempty.
  3733.      Consequently, tests using `ifdef' return true for all definitions
  3734.      except those like `foo ='.  To test for an empty value, use
  3735.      `ifeq ($(foo),)'.  For example,
  3736.  
  3737.           bar =
  3738.           foo = $(bar)
  3739.           ifdef foo
  3740.           frobozz = yes
  3741.           else
  3742.           frobozz = no
  3743.           endif
  3744.  
  3745.      sets `frobozz' to `yes', while:
  3746.  
  3747.           foo =
  3748.           ifdef foo
  3749.           frobozz = yes
  3750.           else
  3751.           frobozz = no
  3752.           endif
  3753.  
  3754.      sets `frobozz' to `no'.
  3755.  
  3756. `ifndef VARIABLE-NAME'
  3757.      If the variable VARIABLE-NAME has an empty value, the TEXT-IF-TRUE
  3758.      is effective; otherwise, the TEXT-IF-FALSE, if any, is effective.
  3759.  
  3760.    Extra spaces are allowed and ignored at the beginning of the
  3761. conditional directive line, but a tab is not allowed.  (If the line
  3762. begins with a tab, it will be considered a command for a rule.)  Aside
  3763. from this, extra spaces or tabs may be inserted with no effect anywhere
  3764. except within the directive name or within an argument.  A comment
  3765. starting with `#' may appear at the end of the line.
  3766.  
  3767.    The other two directives that play a part in a conditional are `else'
  3768. and `endif'.  Each of these directives is written as one word, with no
  3769. arguments.  Extra spaces are allowed and ignored at the beginning of the
  3770. line, and spaces or tabs at the end.  A comment starting with `#' may
  3771. appear at the end of the line.
  3772.  
  3773.    Conditionals affect which lines of the makefile `make' uses.  If the
  3774. condition is true, `make' reads the lines of the TEXT-IF-TRUE as part
  3775. of the makefile; if the condition is false, `make' ignores those lines
  3776. completely.  It follows that syntactic units of the makefile, such as
  3777. rules, may safely be split across the beginning or the end of the
  3778. conditional.
  3779.  
  3780.    `make' evaluates conditionals when it reads a makefile.
  3781. Consequently, you cannot use automatic variables in the tests of
  3782. conditionals because they are not defined until commands are run (*note
  3783. Automatic Variables: Automatic.).
  3784.  
  3785.    To prevent intolerable confusion, it is not permitted to start a
  3786. conditional in one makefile and end it in another.  However, you may
  3787. write an `include' directive within a conditional, provided you do not
  3788. attempt to terminate the conditional inside the included file.
  3789.  
  3790. 
  3791. File: make,  Node: Testing Flags,  Prev: Conditional Syntax,  Up: Conditionals
  3792.  
  3793. Conditionals that Test Flags
  3794. ============================
  3795.  
  3796.    You can write a conditional that tests `make' command flags such as
  3797. `-t' by using the variable `MAKEFLAGS' together with the `findstring'
  3798. function (*note Functions for String Substitution and Analysis: Text
  3799. Functions.).  This is useful when `touch' is not enough to make a file
  3800. appear up to date.
  3801.  
  3802.    The `findstring' function determines whether one string appears as a
  3803. substring of another.  If you want to test for the `-t' flag, use `t'
  3804. as the first string and the value of `MAKEFLAGS' as the other.
  3805.  
  3806.    For example, here is how to arrange to use `ranlib -t' to finish
  3807. marking an archive file up to date:
  3808.  
  3809.      archive.a: ...
  3810.      ifneq (,$(findstring t,$(MAKEFLAGS)))
  3811.              +touch archive.a
  3812.              +ranlib -t archive.a
  3813.      else
  3814.              ranlib archive.a
  3815.      endif
  3816.  
  3817. The `+' prefix marks those command lines as "recursive" so that they
  3818. will be executed despite use of the `-t' flag.  *Note Recursive Use of
  3819. `make': Recursion.
  3820.  
  3821. 
  3822. File: make,  Node: Functions,  Next: Running,  Prev: Conditionals,  Up: Top
  3823.  
  3824. Functions for Transforming Text
  3825. *******************************
  3826.  
  3827.    "Functions" allow you to do text processing in the makefile to
  3828. compute the files to operate on or the commands to use.  You use a
  3829. function in a "function call", where you give the name of the function
  3830. and some text (the "arguments") for the function to operate on.  The
  3831. result of the function's processing is substituted into the makefile at
  3832. the point of the call, just as a variable might be substituted.
  3833.  
  3834. * Menu:
  3835.  
  3836. * Syntax of Functions::         How to write a function call.
  3837. * Text Functions::              General-purpose text manipulation functions.
  3838. * Filename Functions::          Functions for manipulating file names.
  3839. * Foreach Function::            Repeat some text with controlled variation.
  3840. * Origin Function::             Find where a variable got its value.
  3841. * Shell Function::              Substitute the output of a shell command.
  3842.  
  3843. 
  3844. File: make,  Node: Syntax of Functions,  Next: Text Functions,  Up: Functions
  3845.  
  3846. Function Call Syntax
  3847. ====================
  3848.  
  3849.    A function call resembles a variable reference.  It looks like this:
  3850.  
  3851.      $(FUNCTION ARGUMENTS)
  3852.  
  3853. or like this:
  3854.  
  3855.      ${FUNCTION ARGUMENTS}
  3856.  
  3857.    Here FUNCTION is a function name; one of a short list of names that
  3858. are part of `make'.  There is no provision for defining new functions.
  3859.  
  3860.    The ARGUMENTS are the arguments of the function.  They are separated
  3861. from the function name by one or more spaces or tabs, and if there is
  3862. more than one argument, then they are separated by commas.  Such
  3863. whitespace and commas are not part of an argument's value.  The
  3864. delimiters which you use to surround the function call, whether
  3865. parentheses or braces, can appear in an argument only in matching pairs;
  3866. the other kind of delimiters may appear singly.  If the arguments
  3867. themselves contain other function calls or variable references, it is
  3868. wisest to use the same kind of delimiters for all the references; write
  3869. `$(subst a,b,$(x))', not `$(subst a,b,${x})'.  This is because it is
  3870. clearer, and because only one type of delimiter is matched to find the
  3871. end of the reference.
  3872.  
  3873.    The text written for each argument is processed by substitution of
  3874. variables and function calls to produce the argument value, which is
  3875. the text on which the function acts.  The substitution is done in the
  3876. order in which the arguments appear.
  3877.  
  3878.    Commas and unmatched parentheses or braces cannot appear in the text
  3879. of an argument as written; leading spaces cannot appear in the text of
  3880. the first argument as written.  These characters can be put into the
  3881. argument value by variable substitution.  First define variables
  3882. `comma' and `space' whose values are isolated comma and space
  3883. characters, then substitute these variables where such characters are
  3884. wanted, like this:
  3885.  
  3886.      comma:= ,
  3887.      empty:=
  3888.      space:= $(empty) $(empty)
  3889.      foo:= a b c
  3890.      bar:= $(subst $(space),$(comma),$(foo))
  3891.      # bar is now `a,b,c'.
  3892.  
  3893. Here the `subst' function replaces each space with a comma, through the
  3894. value of `foo', and substitutes the result.
  3895.  
  3896. 
  3897. File: make,  Node: Text Functions,  Next: Filename Functions,  Prev: Syntax of Functions,  Up: Functions
  3898.  
  3899. Functions for String Substitution and Analysis
  3900. ==============================================
  3901.  
  3902.    Here are some functions that operate on strings:
  3903.  
  3904. `$(subst FROM,TO,TEXT)'
  3905.      Performs a textual replacement on the text TEXT: each occurrence
  3906.      of FROM is replaced by TO.  The result is substituted for the
  3907.      function call.  For example,
  3908.  
  3909.           $(subst ee,EE,feet on the street)
  3910.  
  3911.      substitutes the string `fEEt on the strEEt'.
  3912.  
  3913. `$(patsubst PATTERN,REPLACEMENT,TEXT)'
  3914.      Finds whitespace-separated words in TEXT that match PATTERN and
  3915.      replaces them with REPLACEMENT.  Here PATTERN may contain a `%'
  3916.      which acts as a wildcard, matching any number of any characters
  3917.      within a word.  If REPLACEMENT also contains a `%', the `%' is
  3918.      replaced by the text that matched the `%' in PATTERN.
  3919.  
  3920.      `%' characters in `patsubst' function invocations can be quoted
  3921.      with preceding backslashes (`\').  Backslashes that would
  3922.      otherwise quote `%' characters can be quoted with more backslashes.
  3923.      Backslashes that quote `%' characters or other backslashes are
  3924.      removed from the pattern before it is compared file names or has a
  3925.      stem substituted into it.  Backslashes that are not in danger of
  3926.      quoting `%' characters go unmolested.  For example, the pattern
  3927.      `the\%weird\\%pattern\\' has `the%weird\' preceding the operative
  3928.      `%' character, and `pattern\\' following it.  The final two
  3929.      backslashes are left alone because they cannot affect any `%'
  3930.      character.
  3931.  
  3932.      Whitespace between words is folded into single space characters;
  3933.      leading and trailing whitespace is discarded.
  3934.  
  3935.      For example,
  3936.  
  3937.           $(patsubst %.c,%.o,x.c.c bar.c)
  3938.  
  3939.      produces the value `x.c.o bar.o'.
  3940.  
  3941.      Substitution references (*note Substitution References:
  3942.      Substitution Refs.) are a simpler way to get the effect of the
  3943.      `patsubst' function:
  3944.  
  3945.           $(VAR:PATTERN=REPLACEMENT)
  3946.  
  3947.      is equivalent to
  3948.  
  3949.           $(patsubst PATTERN,REPLACEMENT,$(VAR))
  3950.  
  3951.      The second shorthand simplifies one of the most common uses of
  3952.      `patsubst': replacing the suffix at the end of file names.
  3953.  
  3954.           $(VAR:SUFFIX=REPLACEMENT)
  3955.  
  3956.      is equivalent to
  3957.  
  3958.           $(patsubst %SUFFIX,%REPLACEMENT,$(VAR))
  3959.  
  3960.      For example, you might have a list of object files:
  3961.  
  3962.           objects = foo.o bar.o baz.o
  3963.  
  3964.      To get the list of corresponding source files, you could simply
  3965.      write:
  3966.  
  3967.           $(objects:.o=.c)
  3968.  
  3969.      instead of using the general form:
  3970.  
  3971.           $(patsubst %.o,%.c,$(objects))
  3972.  
  3973. `$(strip STRING)'
  3974.      Removes leading and trailing whitespace from STRING and replaces
  3975.      each internal sequence of one or more whitespace characters with a
  3976.      single space.  Thus, `$(strip a b  c )' results in `a b c'.
  3977.  
  3978.      The function `strip' can be very useful when used in conjunction
  3979.      with conditionals.  When comparing something with the empty string
  3980.      `' using `ifeq' or `ifneq', you usually want a string of just
  3981.      whitespace to match the empty string (*note Conditionals::.).
  3982.  
  3983.      Thus, the following may fail to have the desired results:
  3984.  
  3985.           .PHONY: all
  3986.           ifneq   "$(needs_made)" ""
  3987.           all: $(needs_made)
  3988.           else
  3989.           all:;@echo 'Nothing to make!'
  3990.           endif
  3991.  
  3992.      Replacing the variable reference `$(needs_made)' with the function
  3993.      call `$(strip $(needs_made))' in the `ifneq' directive would make
  3994.      it more robust.
  3995.  
  3996. `$(findstring FIND,IN)'
  3997.      Searches IN for an occurrence of FIND.  If it occurs, the value is
  3998.      FIND; otherwise, the value is empty.  You can use this function in
  3999.      a conditional to test for the presence of a specific substring in
  4000.      a given string.  Thus, the two examples,
  4001.  
  4002.           $(findstring a,a b c)
  4003.           $(findstring a,b c)
  4004.  
  4005.      produce the values `a' and `' (the empty string), respectively.
  4006.      *Note Testing Flags::, for a practical application of `findstring'.
  4007.  
  4008. `$(filter PATTERN...,TEXT)'
  4009.      Removes all whitespace-separated words in TEXT that do *not* match
  4010.      any of the PATTERN words, returning only matching words.  The
  4011.      patterns are written using `%', just like the patterns used in the
  4012.      `patsubst' function above.
  4013.  
  4014.      The `filter' function can be used to separate out different types
  4015.      of strings (such as file names) in a variable.  For example:
  4016.  
  4017.           sources := foo.c bar.c baz.s ugh.h
  4018.           foo: $(sources)
  4019.                   cc $(filter %.c %.s,$(sources)) -o foo
  4020.  
  4021.      says that `foo' depends of `foo.c', `bar.c', `baz.s' and `ugh.h'
  4022.      but only `foo.c', `bar.c' and `baz.s' should be specified in the
  4023.      command to the compiler.
  4024.  
  4025. `$(filter-out PATTERN...,TEXT)'
  4026.      Removes all whitespace-separated words in TEXT that *do* match the
  4027.      PATTERN words, returning only the words that *do not* match.  This
  4028.      is the exact opposite of the `filter' function.
  4029.  
  4030.      For example, given:
  4031.  
  4032.           objects=main1.o foo.o main2.o bar.o
  4033.           mains=main1.o main2.o
  4034.  
  4035.      the following generates a list which contains all the object files
  4036.      not in `mains':
  4037.  
  4038.           $(filter-out $(mains),$(objects))
  4039.  
  4040. `$(sort LIST)'
  4041.      Sorts the words of LIST in lexical order, removing duplicate
  4042.      words.  The output is a list of words separated by single spaces.
  4043.      Thus,
  4044.  
  4045.           $(sort foo bar lose)
  4046.  
  4047.      returns the value `bar foo lose'.
  4048.  
  4049.      Incidentally, since `sort' removes duplicate words, you can use it
  4050.      for this purpose even if you don't care about the sort order.
  4051.  
  4052.    Here is a realistic example of the use of `subst' and `patsubst'.
  4053. Suppose that a makefile uses the `VPATH' variable to specify a list of
  4054. directories that `make' should search for dependency files (*note
  4055. `VPATH' Search Path for All Dependencies: General Search.).  This
  4056. example shows how to tell the C compiler to search for header files in
  4057. the same list of directories.
  4058.  
  4059.    The value of `VPATH' is a list of directories separated by colons,
  4060. such as `src:../headers'.  First, the `subst' function is used to
  4061. change the colons to spaces:
  4062.  
  4063.      $(subst :, ,$(VPATH))
  4064.  
  4065. This produces `src ../headers'.  Then `patsubst' is used to turn each
  4066. directory name into a `-I' flag.  These can be added to the value of
  4067. the variable `CFLAGS', which is passed automatically to the C compiler,
  4068. like this:
  4069.  
  4070.      override CFLAGS += $(patsubst %,-I%,$(subst :, ,$(VPATH)))
  4071.  
  4072. The effect is to append the text `-Isrc -I../headers' to the previously
  4073. given value of `CFLAGS'.  The `override' directive is used so that the
  4074. new value is assigned even if the previous value of `CFLAGS' was
  4075. specified with a command argument (*note The `override' Directive:
  4076. Override Directive.).
  4077.  
  4078. 
  4079. File: make,  Node: Filename Functions,  Next: Foreach Function,  Prev: Text Functions,  Up: Functions
  4080.  
  4081. Functions for File Names
  4082. ========================
  4083.  
  4084.    Several of the built-in expansion functions relate specifically to
  4085. taking apart file names or lists of file names.
  4086.  
  4087.    Each of the following functions performs a specific transformation
  4088. on a file name.  The argument of the function is regarded as a series
  4089. of file names, separated by whitespace.  (Leading and trailing
  4090. whitespace is ignored.)  Each file name in the series is transformed in
  4091. the same way and the results are concatenated with single spaces
  4092. between them.
  4093.  
  4094. `$(dir NAMES...)'
  4095.      Extracts the directory-part of each file name in NAMES.  The
  4096.      directory-part of the file name is everything up through (and
  4097.      including) the last slash in it.  If the file name contains no
  4098.      slash, the directory part is the string `./'.  For example,
  4099.  
  4100.           $(dir src/foo.c hacks)
  4101.  
  4102.      produces the result `src/ ./'.
  4103.  
  4104. `$(notdir NAMES...)'
  4105.      Extracts all but the directory-part of each file name in NAMES.
  4106.      If the file name contains no slash, it is left unchanged.
  4107.      Otherwise, everything through the last slash is removed from it.
  4108.  
  4109.      A file name that ends with a slash becomes an empty string.  This
  4110.      is unfortunate, because it means that the result does not always
  4111.      have the same number of whitespace-separated file names as the
  4112.      argument had; but we do not see any other valid alternative.
  4113.  
  4114.      For example,
  4115.  
  4116.           $(notdir src/foo.c hacks)
  4117.  
  4118.      produces the result `foo.c hacks'.
  4119.  
  4120. `$(suffix NAMES...)'
  4121.      Extracts the suffix of each file name in NAMES.  If the file name
  4122.      contains a period, the suffix is everything starting with the last
  4123.      period.  Otherwise, the suffix is the empty string.  This
  4124.      frequently means that the result will be empty when NAMES is not,
  4125.      and if NAMES contains multiple file names, the result may contain
  4126.      fewer file names.
  4127.  
  4128.      For example,
  4129.  
  4130.           $(suffix src/foo.c hacks)
  4131.  
  4132.      produces the result `.c'.
  4133.  
  4134. `$(basename NAMES...)'
  4135.      Extracts all but the suffix of each file name in NAMES.  If the
  4136.      file name contains a period, the basename is everything starting
  4137.      up to (and not including) the last period.  Otherwise, the
  4138.      basename is the entire file name.  For example,
  4139.  
  4140.           $(basename src/foo.c hacks)
  4141.  
  4142.      produces the result `src/foo hacks'.
  4143.  
  4144. `$(addsuffix SUFFIX,NAMES...)'
  4145.      The argument NAMES is regarded as a series of names, separated by
  4146.      whitespace; SUFFIX is used as a unit.  The value of SUFFIX is
  4147.      appended to the end of each individual name and the resulting
  4148.      larger names are concatenated with single spaces between them.
  4149.      For example,
  4150.  
  4151.           $(addsuffix .c,foo bar)
  4152.  
  4153.      produces the result `foo.c bar.c'.
  4154.  
  4155. `$(addprefix PREFIX,NAMES...)'
  4156.      The argument NAMES is regarded as a series of names, separated by
  4157.      whitespace; PREFIX is used as a unit.  The value of PREFIX is
  4158.      prepended to the front of each individual name and the resulting
  4159.      larger names are concatenated with single spaces between them.
  4160.      For example,
  4161.  
  4162.           $(addprefix src/,foo bar)
  4163.  
  4164.      produces the result `src/foo src/bar'.
  4165.  
  4166. `$(join LIST1,LIST2)'
  4167.      Concatenates the two arguments word by word: the two first words
  4168.      (one from each argument) concatenated form the first word of the
  4169.      result, the two second words form the second word of the result,
  4170.      and so on.  So the Nth word of the result comes from the Nth word
  4171.      of each argument.  If one argument has more words that the other,
  4172.      the extra words are copied unchanged into the result.
  4173.  
  4174.      For example, `$(join a b,.c .o)' produces `a.c b.o'.
  4175.  
  4176.      Whitespace between the words in the lists is not preserved; it is
  4177.      replaced with a single space.
  4178.  
  4179.      This function can merge the results of the `dir' and `notdir'
  4180.      functions, to produce the original list of files which was given
  4181.      to those two functions.
  4182.  
  4183. `$(word N,TEXT)'
  4184.      Returns the Nth word of TEXT.  The legitimate values of N start
  4185.      from 1.  If N is bigger than the number of words in TEXT, the
  4186.      value is empty.  For example,
  4187.  
  4188.           $(word 2, foo bar baz)
  4189.  
  4190.      returns `bar'.
  4191.  
  4192. `$(words TEXT)'
  4193.      Returns the number of words in TEXT.  Thus, the last word of TEXT
  4194.      is `$(word $(words TEXT),TEXT)'.
  4195.  
  4196. `$(firstword NAMES...)'
  4197.      The argument NAMES is regarded as a series of names, separated by
  4198.      whitespace.  The value is the first name in the series.  The rest
  4199.      of the names are ignored.
  4200.  
  4201.      For example,
  4202.  
  4203.           $(firstword foo bar)
  4204.  
  4205.      produces the result `foo'.  Although `$(firstword TEXT)' is the
  4206.      same as `$(word 1,TEXT)', the `firstword' function is retained for
  4207.      its simplicity.
  4208.  
  4209. `$(wildcard PATTERN)'
  4210.      The argument PATTERN is a file name pattern, typically containing
  4211.      wildcard characters (as in shell file name patterns).  The result
  4212.      of `wildcard' is a space-separated list of the names of existing
  4213.      files that match the pattern.  *Note Using Wildcard Characters in
  4214.      File Names: Wildcards.
  4215.  
  4216. 
  4217. File: make,  Node: Foreach Function,  Next: Origin Function,  Prev: Filename Functions,  Up: Functions
  4218.  
  4219. The `foreach' Function
  4220. ======================
  4221.  
  4222.    The `foreach' function is very different from other functions.  It
  4223. causes one piece of text to be used repeatedly, each time with a
  4224. different substitution performed on it.  It resembles the `for' command
  4225. in the shell `sh' and the `foreach' command in the C-shell `csh'.
  4226.  
  4227.    The syntax of the `foreach' function is:
  4228.  
  4229.      $(foreach VAR,LIST,TEXT)
  4230.  
  4231. The first two arguments, VAR and LIST, are expanded before anything
  4232. else is done; note that the last argument, TEXT, is *not* expanded at
  4233. the same time.  Then for each word of the expanded value of LIST, the
  4234. variable named by the expanded value of VAR is set to that word, and
  4235. TEXT is expanded.  Presumably TEXT contains references to that
  4236. variable, so its expansion will be different each time.
  4237.  
  4238.    The result is that TEXT is expanded as many times as there are
  4239. whitespace-separated words in LIST.  The multiple expansions of TEXT
  4240. are concatenated, with spaces between them, to make the result of
  4241. `foreach'.
  4242.  
  4243.    This simple example sets the variable `files' to the list of all
  4244. files in the directories in the list `dirs':
  4245.  
  4246.      dirs := a b c d
  4247.      files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
  4248.  
  4249.    Here TEXT is `$(wildcard $(dir)/*)'.  The first repetition finds the
  4250. value `a' for `dir', so it produces the same result as `$(wildcard
  4251. a/*)'; the second repetition produces the result of `$(wildcard b/*)';
  4252. and the third, that of `$(wildcard c/*)'.
  4253.  
  4254.    This example has the same result (except for setting `dirs') as the
  4255. following example:
  4256.  
  4257.      files := $(wildcard a/* b/* c/* d/*)
  4258.  
  4259.    When TEXT is complicated, you can improve readability by giving it a
  4260. name, with an additional variable:
  4261.  
  4262.      find_files = $(wildcard $(dir)/*)
  4263.      dirs := a b c d
  4264.      files := $(foreach dir,$(dirs),$(find_files))
  4265.  
  4266. Here we use the variable `find_files' this way.  We use plain `=' to
  4267. define a recursively-expanding variable, so that its value contains an
  4268. actual function call to be reexpanded under the control of `foreach'; a
  4269. simply-expanded variable would not do, since `wildcard' would be called
  4270. only once at the time of defining `find_files'.
  4271.  
  4272.    The `foreach' function has no permanent effect on the variable VAR;
  4273. its value and flavor after the `foreach' function call are the same as
  4274. they were beforehand.  The other values which are taken from LIST are
  4275. in effect only temporarily, during the execution of `foreach'.  The
  4276. variable VAR is a simply-expanded variable during the execution of
  4277. `foreach'.  If VAR was undefined before the `foreach' function call, it
  4278. is undefined after the call.  *Note The Two Flavors of Variables:
  4279. Flavors.
  4280.  
  4281.    You must take care when using complex variable expressions that
  4282. result in variable names because many strange things are valid variable
  4283. names, but are probably not what you intended.  For example,
  4284.  
  4285.      files := $(foreach Es escrito en espanol!,b c ch,$(find_files))
  4286.  
  4287. might be useful if the value of `find_files' references the variable
  4288. whose name is `Es escrito en espanol!' (es un nombre bastante largo,
  4289. no?), but it is more likely to be a mistake.
  4290.  
  4291. 
  4292. File: make,  Node: Origin Function,  Next: Shell Function,  Prev: Foreach Function,  Up: Functions
  4293.  
  4294. The `origin' Function
  4295. =====================
  4296.  
  4297.    The `origin' function is unlike most other functions in that it does
  4298. not operate on the values of variables; it tells you something *about*
  4299. a variable.  Specifically, it tells you where it came from.
  4300.  
  4301.    The syntax of the `origin' function is:
  4302.  
  4303.      $(origin VARIABLE)
  4304.  
  4305.    Note that VARIABLE is the *name* of a variable to inquire about; not
  4306. a *reference* to that variable.  Therefore you would not normally use a
  4307. `$' or parentheses when writing it.  (You can, however, use a variable
  4308. reference in the name if you want the name not to be a constant.)
  4309.  
  4310.    The result of this function is a string telling you how the variable
  4311. VARIABLE was defined:
  4312.  
  4313. `undefined'
  4314.      if VARIABLE was never defined.
  4315.  
  4316. `default'
  4317.      if VARIABLE has a default definition, as is usual with `CC' and so
  4318.      on.  *Note Variables Used by Implicit Rules: Implicit Variables.
  4319.      Note that if you have redefined a default variable, the `origin'
  4320.      function will return the origin of the later definition.
  4321.  
  4322. `environment'
  4323.      if VARIABLE was defined as an environment variable and the `-e'
  4324.      option is *not* turned on (*note Summary of Options: Options
  4325.      Summary.).
  4326.  
  4327. `environment override'
  4328.      if VARIABLE was defined as an environment variable and the `-e'
  4329.      option *is* turned on (*note Summary of Options: Options Summary.).
  4330.  
  4331. `file'
  4332.      if VARIABLE was defined in a makefile.
  4333.  
  4334. `command line'
  4335.      if VARIABLE was defined on the command line.
  4336.  
  4337. `override'
  4338.      if VARIABLE was defined with an `override' directive in a makefile
  4339.      (*note The `override' Directive: Override Directive.).
  4340.  
  4341. `automatic'
  4342.      if VARIABLE is an automatic variable defined for the execution of
  4343.      the commands for each rule (*note Automatic Variables: Automatic.).
  4344.  
  4345.    This information is primarily useful (other than for your curiosity)
  4346. to determine if you want to believe the value of a variable.  For
  4347. example, suppose you have a makefile `foo' that includes another
  4348. makefile `bar'.  You want a variable `bletch' to be defined in `bar' if
  4349. you run the command `make -f bar', even if the environment contains a
  4350. definition of `bletch'.  However, if `foo' defined `bletch' before
  4351. including `bar', you do not want to override that definition.  This
  4352. could be done by using an `override' directive in `foo', giving that
  4353. definition precedence over the later definition in `bar';
  4354. unfortunately, the `override' directive would also override any command
  4355. line definitions.  So, `bar' could include:
  4356.  
  4357.      ifdef bletch
  4358.      ifeq "$(origin bletch)" "environment"
  4359.      bletch = barf, gag, etc.
  4360.      endif
  4361.      endif
  4362.  
  4363. If `bletch' has been defined from the environment, this will redefine
  4364. it.
  4365.  
  4366.    If you want to override a previous definition of `bletch' if it came
  4367. from the environment, even under `-e', you could instead write:
  4368.  
  4369.      ifneq "$(findstring environment,$(origin bletch))" ""
  4370.      bletch = barf, gag, etc.
  4371.      endif
  4372.  
  4373.    Here the redefinition takes place if `$(origin bletch)' returns
  4374. either `environment' or `environment override'.  *Note Functions for
  4375. String Substitution and Analysis: Text Functions.
  4376.  
  4377. 
  4378. File: make,  Node: Shell Function,  Prev: Origin Function,  Up: Functions
  4379.  
  4380. The `shell' Function
  4381. ====================
  4382.  
  4383.    The `shell' function is unlike any other function except the
  4384. `wildcard' function (*note The Function `wildcard': Wildcard Function.)
  4385. in that it communicates with the world outside of `make'.
  4386.  
  4387.    The `shell' function performs the same function that backquotes
  4388. (``') perform in most shells: it does "command expansion".  This means
  4389. that it takes an argument that is a shell command and returns the
  4390. output of the command.  The only processing `make' does on the result,
  4391. before substituting it into the surrounding text, is to convert
  4392. newlines to spaces.
  4393.  
  4394.    The commands run by calls to the `shell' function are run when the
  4395. function calls are expanded.  In most cases, this is when the makefile
  4396. is read in.  The exception is that function calls in the commands of
  4397. the rules are expanded when the commands are run, and this applies to
  4398. `shell' function calls like all others.
  4399.  
  4400.    Here are some examples of the use of the `shell' function:
  4401.  
  4402.      contents := $(shell cat foo)
  4403.  
  4404. sets `contents' to the contents of the file `foo', with a space (rather
  4405. than a newline) separating each line.
  4406.  
  4407.      files := $(shell echo *.c)
  4408.  
  4409. sets `files' to the expansion of `*.c'.  Unless `make' is using a very
  4410. strange shell, this has the same result as `$(wildcard *.c)'.
  4411.  
  4412. 
  4413. File: make,  Node: Running,  Next: Implicit Rules,  Prev: Functions,  Up: Top
  4414.  
  4415. How to Run `make'
  4416. *****************
  4417.  
  4418.    A makefile that says how to recompile a program can be used in more
  4419. than one way.  The simplest use is to recompile every file that is out
  4420. of date.  Usually, makefiles are written so that if you run `make' with
  4421. no arguments, it does just that.
  4422.  
  4423.    But you might want to update only some of the files; you might want
  4424. to use a different compiler or different compiler options; you might
  4425. want just to find out which files are out of date without changing them.
  4426.  
  4427.    By giving arguments when you run `make', you can do any of these
  4428. things and many others.
  4429.  
  4430. * Menu:
  4431.  
  4432. * Makefile Arguments::          How to specify which makefile to use.
  4433. * Goals::                       How to use goal arguments to specify which
  4434.                                   parts of the makefile to use.
  4435. * Instead of Execution::        How to use mode flags to specify what
  4436.                                   kind of thing to do with the commands
  4437.                                   in the makefile other than simply
  4438.                                   execute them.
  4439. * Avoiding Compilation::        How to avoid recompiling certain files.
  4440. * Overriding::                  How to override a variable to specify
  4441.                                   an alternate compiler and other things.
  4442. * Testing::                     How to proceed past some errors, to
  4443.                                   test compilation.
  4444. * Options Summary::             Summary of Options
  4445.  
  4446. 
  4447. File: make,  Node: Makefile Arguments,  Next: Goals,  Up: Running
  4448.  
  4449. Arguments to Specify the Makefile
  4450. =================================
  4451.  
  4452.    The way to specify the name of the makefile is with the `-f' or
  4453. `--file' option (`--makefile' also works).  For example, `-f altmake'
  4454. says to use the file `altmake' as the makefile.
  4455.  
  4456.    If you use the `-f' flag several times and follow each `-f' with an
  4457. argument, all the specified files are used jointly as makefiles.
  4458.  
  4459.    If you do not use the `-f' or `--file' flag, the default is to try
  4460. `GNUmakefile', `makefile', and `Makefile', in that order, and use the
  4461. first of these three which exists or can be made (*note Writing
  4462. Makefiles: Makefiles.).
  4463.  
  4464. 
  4465. File: make,  Node: Goals,  Next: Instead of Execution,  Prev: Makefile Arguments,  Up: Running
  4466.  
  4467. Arguments to Specify the Goals
  4468. ==============================
  4469.  
  4470.    The "goals" are the targets that `make' should strive ultimately to
  4471. update.  Other targets are updated as well if they appear as
  4472. dependencies of goals, or dependencies of dependencies of goals, etc.
  4473.  
  4474.    By default, the goal is the first target in the makefile (not
  4475. counting targets that start with a period).  Therefore, makefiles are
  4476. usually written so that the first target is for compiling the entire
  4477. program or programs they describe.
  4478.  
  4479.    You can specify a different goal or goals with arguments to `make'.
  4480. Use the name of the goal as an argument.  If you specify several goals,
  4481. `make' processes each of them in turn, in the order you name them.
  4482.  
  4483.    Any target in the makefile may be specified as a goal (unless it
  4484. starts with `-' or contains an `=', in which case it will be parsed as
  4485. a switch or variable definition, respectively).  Even targets not in
  4486. the makefile may be specified, if `make' can find implicit rules that
  4487. say how to make them.
  4488.  
  4489.    One use of specifying a goal is if you want to compile only a part of
  4490. the program, or only one of several programs.  Specify as a goal each
  4491. file that you wish to remake.  For example, consider a directory
  4492. containing several programs, with a makefile that starts like this:
  4493.  
  4494.      .PHONY: all
  4495.      all: size nm ld ar as
  4496.  
  4497.    If you are working on the program `size', you might want to say
  4498. `make size' so that only the files of that program are recompiled.
  4499.  
  4500.    Another use of specifying a goal is to make files that are not
  4501. normally made.  For example, there may be a file of debugging output,
  4502. or a version of the program that is compiled specially for testing,
  4503. which has a rule in the makefile but is not a dependency of the default
  4504. goal.
  4505.  
  4506.    Another use of specifying a goal is to run the commands associated
  4507. with a phony target (*note Phony Targets::.) or empty target (*note
  4508. Empty Target Files to Record Events: Empty Targets.).  Many makefiles
  4509. contain a phony target named `clean' which deletes everything except
  4510. source files.  Naturally, this is done only if you request it
  4511. explicitly with `make clean'.  Here is a list of typical phony and
  4512. empty target names:
  4513.  
  4514. `all'
  4515.      Make all the top-level targets the makefile knows about.
  4516.  
  4517. `clean'
  4518.      Delete all files that are normally created by running `make'.
  4519.  
  4520. `mostlyclean'
  4521.      Like `clean', but may refrain from deleting a few files that people
  4522.      normally don't want to recompile.  For example, the `mostlyclean'
  4523.      target for GCC does not delete `libgcc.a', because recompiling it
  4524.      is rarely necessary and takes a lot of time.
  4525.  
  4526. `distclean'
  4527. `realclean'
  4528. `clobber'
  4529.      Any of these three might be defined to delete everything that would
  4530.      not be part of a standard distribution.  For example, this would
  4531.      delete configuration files or links that you would normally create
  4532.      as preparation for compilation, even if the makefile itself cannot
  4533.      create these files.
  4534.  
  4535. `install'
  4536.      Copy the executable file into a directory that users typically
  4537.      search for commands; copy any auxiliary files that the executable
  4538.      uses into the directories where it will look for them.
  4539.  
  4540. `print'
  4541.      Print listings of the source files that have changed.
  4542.  
  4543. `tar'
  4544.      Create a tar file of the source files.
  4545.  
  4546. `shar'
  4547.      Create a shell archive (shar file) of the source files.
  4548.  
  4549. `dist'
  4550.      Create a distribution file of the source files.  This might be a
  4551.      tar file, or a shar file, or a compressed version of one of the
  4552.      above, or even more than one of the above.
  4553.  
  4554. `TAGS'
  4555.      Update a tags table for this program.
  4556.  
  4557. `check'
  4558. `test'
  4559.      Perform self tests on the program this makefile builds.
  4560.  
  4561. 
  4562. File: make,  Node: Instead of Execution,  Next: Avoiding Compilation,  Prev: Goals,  Up: Running
  4563.  
  4564. Instead of Executing the Commands
  4565. =================================
  4566.  
  4567.    The makefile tells `make' how to tell whether a target is up to date,
  4568. and how to update each target.  But updating the targets is not always
  4569. what you want.  Certain options specify other activities for `make'.
  4570.  
  4571. `-n'
  4572. `--just-print'
  4573. `--dry-run'
  4574. `--recon'
  4575.      "No-op".  The activity is to print what commands would be used to
  4576.      make the targets up to date, but not actually execute them.
  4577.  
  4578. `-t'
  4579. `--touch'
  4580.      "Touch".  The activity is to mark the targets as up to date without
  4581.      actually changing them.  In other words, `make' pretends to compile
  4582.      the targets but does not really change their contents.
  4583.  
  4584. `-q'
  4585. `--question'
  4586.      "Question".  The activity is to find out silently whether the
  4587.      targets are up to date already; but execute no commands in either
  4588.      case.  In other words, neither compilation nor output will occur.
  4589.  
  4590. `-W FILE'
  4591. `--what-if=FILE'
  4592. `--assume-new=FILE'
  4593. `--new-file=FILE'
  4594.      "What if".  Each `-W' flag is followed by a file name.  The given
  4595.      files' modification times are recorded by `make' as being the
  4596.      present time, although the actual modification times remain the
  4597.      same.  You can use the `-W' flag in conjunction with the `-n' flag
  4598.      to see what would happen if you were to modify specific files.
  4599.  
  4600.    With the `-n' flag, `make' prints the commands that it would
  4601. normally execute but does not execute them.
  4602.  
  4603.    With the `-t' flag, `make' ignores the commands in the rules and
  4604. uses (in effect) the command `touch' for each target that needs to be
  4605. remade.  The `touch' command is also printed, unless `-s' or `.SILENT'
  4606. is used.  For speed, `make' does not actually invoke the program
  4607. `touch'.  It does the work directly.
  4608.  
  4609.    With the `-q' flag, `make' prints nothing and executes no commands,
  4610. but the exit status code it returns is zero if and only if the targets
  4611. to be considered are already up to date.
  4612.  
  4613.    It is an error to use more than one of these three flags in the same
  4614. invocation of `make'.
  4615.  
  4616.    The `-n', `-t', and `-q' options do not affect command lines that
  4617. begin with `+' characters or contain the strings `$(MAKE)' or
  4618. `${MAKE}'.  Note that only the line containing the `+' character or the
  4619. strings `$(MAKE)' or `${MAKE}' is run regardless of these options.
  4620. Other lines in the same rule are not run unless they too begin with `+'
  4621. or contain `$(MAKE)' or `${MAKE}' (*Note How the `MAKE' Variable Works:
  4622. MAKE Variable.)
  4623.  
  4624.    The `-W' flag provides two features:
  4625.  
  4626.    * If you also use the `-n' or `-q' flag, you can see what `make'
  4627.      would do if you were to modify some files.
  4628.  
  4629.    * Without the `-n' or `-q' flag, when `make' is actually executing
  4630.      commands, the `-W' flag can direct `make' to act as if some files
  4631.      had been modified, without actually modifying the files.
  4632.  
  4633.    Note that the options `-p' and `-v' allow you to obtain other
  4634. information about `make' or about the makefiles in use (*note Summary
  4635. of Options: Options Summary.).
  4636.  
  4637. 
  4638. File: make,  Node: Avoiding Compilation,  Next: Overriding,  Prev: Instead of Execution,  Up: Running
  4639.  
  4640. Avoiding Recompilation of Some Files
  4641. ====================================
  4642.  
  4643.    Sometimes you may have changed a source file but you do not want to
  4644. recompile all the files that depend on it.  For example, suppose you
  4645. add a macro or a declaration to a header file that many other files
  4646. depend on.  Being conservative, `make' assumes that any change in the
  4647. header file requires recompilation of all dependent files, but you know
  4648. that they do not need to be recompiled and you would rather not waste
  4649. the time waiting for them to compile.
  4650.  
  4651.    If you anticipate the problem before changing the header file, you
  4652. can use the `-t' flag.  This flag tells `make' not to run the commands
  4653. in the rules, but rather to mark the target up to date by changing its
  4654. last-modification date.  You would follow this procedure:
  4655.  
  4656.   1. Use the command `make' to recompile the source files that really
  4657.      need recompilation.
  4658.  
  4659.   2. Make the changes in the header files.
  4660.  
  4661.   3. Use the command `make -t' to mark all the object files as up to
  4662.      date.  The next time you run `make', the changes in the header
  4663.      files will not cause any recompilation.
  4664.  
  4665.    If you have already changed the header file at a time when some files
  4666. do need recompilation, it is too late to do this.  Instead, you can use
  4667. the `-o FILE' flag, which marks a specified file as "old" (*note
  4668. Summary of Options: Options Summary.).  This means that the file itself
  4669. will not be remade, and nothing else will be remade on its account.
  4670. Follow this procedure:
  4671.  
  4672.   1. Recompile the source files that need compilation for reasons
  4673.      independent of the particular header file, with `make -o
  4674.      HEADERFILE'.  If several header files are involved, use a separate
  4675.      `-o' option for each header file.
  4676.  
  4677.   2. Touch all the object files with `make -t'.
  4678.  
  4679. 
  4680. File: make,  Node: Overriding,  Next: Testing,  Prev: Avoiding Compilation,  Up: Running
  4681.  
  4682. Overriding Variables
  4683. ====================
  4684.  
  4685.    An argument that contains `=' specifies the value of a variable:
  4686. `V=X' sets the value of the variable V to X.  If you specify a value in
  4687. this way, all ordinary assignments of the same variable in the makefile
  4688. are ignored; we say they have been "overridden" by the command line
  4689. argument.
  4690.  
  4691.    The most common way to use this facility is to pass extra flags to
  4692. compilers.  For example, in a properly written makefile, the variable
  4693. `CFLAGS' is included in each command that runs the C compiler, so a
  4694. file `foo.c' would be compiled something like this:
  4695.  
  4696.      cc -c $(CFLAGS) foo.c
  4697.  
  4698.    Thus, whatever value you set for `CFLAGS' affects each compilation
  4699. that occurs.  The makefile probably specifies the usual value for
  4700. `CFLAGS', like this:
  4701.  
  4702.      CFLAGS=-g
  4703.  
  4704.    Each time you run `make', you can override this value if you wish.
  4705. For example, if you say `make CFLAGS='-g -O'', each C compilation will
  4706. be done with `cc -c -g -O'.  (This illustrates how you can use quoting
  4707. in the shell to enclose spaces and other special characters in the
  4708. value of a variable when you override it.)
  4709.  
  4710.    The variable `CFLAGS' is only one of many standard variables that
  4711. exist just so that you can change them this way.  *Note Variables Used
  4712. by Implicit Rules: Implicit Variables, for a complete list.
  4713.  
  4714.    You can also program the makefile to look at additional variables of
  4715. your own, giving the user the ability to control other aspects of how
  4716. the makefile works by changing the variables.
  4717.  
  4718.    When you override a variable with a command argument, you can define
  4719. either a recursively-expanded variable or a simply-expanded variable.
  4720. The examples shown above make a recursively-expanded variable; to make a
  4721. simply-expanded variable, write `:=' instead of `='.  But, unless you
  4722. want to include a variable reference or function call in the *value*
  4723. that you specify, it makes no difference which kind of variable you
  4724. create.
  4725.  
  4726.    There is one way that the makefile can change a variable that you
  4727. have overridden.  This is to use the `override' directive, which is a
  4728. line that looks like this: `override VARIABLE = VALUE' (*note The
  4729. `override' Directive: Override Directive.).
  4730.  
  4731. 
  4732. File: make,  Node: Testing,  Next: Options Summary,  Prev: Overriding,  Up: Running
  4733.  
  4734. Testing the Compilation of a Program
  4735. ====================================
  4736.  
  4737.    Normally, when an error happens in executing a shell command, `make'
  4738. gives up immediately, returning a nonzero status.  No further commands
  4739. are executed for any target.  The error implies that the goal cannot be
  4740. correctly remade, and `make' reports this as soon as it knows.
  4741.  
  4742.    When you are compiling a program that you have just changed, this is
  4743. not what you want.  Instead, you would rather that `make' try compiling
  4744. every file that can be tried, to show you as many compilation errors as
  4745. possible.
  4746.  
  4747.    On these occasions, you should use the `-k' or `--keep-going' flag.
  4748. This tells `make' to continue to consider the other dependencies of the
  4749. pending targets, remaking them if necessary, before it gives up and
  4750. returns nonzero status.  For example, after an error in compiling one
  4751. object file, `make -k' will continue compiling other object files even
  4752. though it already knows that linking them will be impossible.  In
  4753. addition to continuing after failed shell commands, `make -k' will
  4754. continue as much as possible after discovering that it does not know
  4755. how to make a target or dependency file.  This will always cause an
  4756. error message, but without `-k', it is a fatal error (*note Summary of
  4757. Options: Options Summary.).
  4758.  
  4759.    The usual behavior of `make' assumes that your purpose is to get the
  4760. goals up to date; once `make' learns that this is impossible, it might
  4761. as well report the failure immediately.  The `-k' flag says that the
  4762. real purpose is to test as much as possible of the changes made in the
  4763. program, perhaps to find several independent problems so that you can
  4764. correct them all before the next attempt to compile.  This is why Emacs'
  4765. `M-x compile' command passes the `-k' flag by default.
  4766.  
  4767. 
  4768. File: make,  Node: Options Summary,  Prev: Testing,  Up: Running
  4769.  
  4770. Summary of Options
  4771. ==================
  4772.  
  4773.    Here is a table of all the options `make' understands:
  4774.  
  4775. `-b'
  4776. `-m'
  4777.      These options are ignored for compatibility with other versions of
  4778.      `make'.
  4779.  
  4780. `-C DIR'
  4781. `--directory=DIR'
  4782.      Change to directory DIR before reading the makefiles.  If multiple
  4783.      `-C' options are specified, each is interpreted relative to the
  4784.      previous one: `-C / -C etc' is equivalent to `-C /etc'.  This is
  4785.      typically used with recursive invocations of `make' (*note
  4786.      Recursive Use of `make': Recursion.).
  4787.  
  4788. `-d'
  4789. `--debug'
  4790.      Print debugging information in addition to normal processing.  The
  4791.      debugging information says which files are being considered for
  4792.      remaking, which file-times are being compared and with what
  4793.      results, which files actually need to be remade, which implicit
  4794.      rules are considered and which are applied--everything interesting
  4795.      about how `make' decides what to do.
  4796.  
  4797. `-e'
  4798. `--environment-overrides'
  4799.      Give variables taken from the environment precedence over
  4800.      variables from makefiles.  *Note Variables from the Environment:
  4801.      Environment.
  4802.  
  4803. `-f FILE'
  4804. `--file=FILE'
  4805. `--makefile=FILE'
  4806.      Read the file named FILE as a makefile.  *Note Writing Makefiles:
  4807.      Makefiles.
  4808.  
  4809. `-h'
  4810. `--help'
  4811.      Remind you of the options that `make' understands and then exit.
  4812.  
  4813. `-i'
  4814. `--ignore-errors'
  4815.      Ignore all errors in commands executed to remake files.  *Note
  4816.      Errors in Commands: Errors.
  4817.  
  4818. `-I DIR'
  4819. `--include-dir=DIR'
  4820.      Specifies a directory DIR to search for included makefiles.  *Note
  4821.      Including Other Makefiles: Include.  If several `-I' options are
  4822.      used to specify several directories, the directories are searched
  4823.      in the order specified.
  4824.  
  4825. `-j [JOBS]'
  4826. `--jobs=[JOBS]'
  4827.      Specifies the number of jobs (commands) to run simultaneously.
  4828.      With no argument, `make' runs as many jobs simultaneously as
  4829.      possible.  If there is more than one `-j' option, the last one is
  4830.      effective.  *Note Parallel Execution: Parallel, for more
  4831.      information on how commands are run.
  4832.  
  4833. `-k'
  4834. `--keep-going'
  4835.      Continue as much as possible after an error.  While the target that
  4836.      failed, and those that depend on it, cannot be remade, the other
  4837.      dependencies of these targets can be processed all the same.
  4838.      *Note Testing the Compilation of a Program: Testing.
  4839.  
  4840. `-l [LOAD]'
  4841. `--load-average[=LOAD]'
  4842. `--max-load[=LOAD]'
  4843.      Specifies that no new jobs (commands) should be started if there
  4844.      are other jobs running and the load average is at least LOAD (a
  4845.      floating-point number).  With no argument, removes a previous load
  4846.      limit.  *Note Parallel Execution: Parallel.
  4847.  
  4848. `-n'
  4849. `--just-print'
  4850. `--dry-run'
  4851. `--recon'
  4852.      Print the commands that would be executed, but do not execute them.
  4853.      *Note Instead of Executing the Commands: Instead of Execution.
  4854.  
  4855. `-o FILE'
  4856. `--old-file=FILE'
  4857. `--assume-old=FILE'
  4858.      Do not remake the file FILE even if it is older than its
  4859.      dependencies, and do not remake anything on account of changes in
  4860.      FILE.  Essentially the file is treated as very old and its rules
  4861.      are ignored.  *Note Avoiding Recompilation of Some Files: Avoiding
  4862.      Compilation.
  4863.  
  4864. `-p'
  4865. `--print-data-base'
  4866.      Print the data base (rules and variable values) that results from
  4867.      reading the makefiles; then execute as usual or as otherwise
  4868.      specified.  This also prints the version information given by the
  4869.      `-v' switch (see below).  To print the data base without trying to
  4870.      remake any files, use `make -p -f /dev/null'.
  4871.  
  4872. `-q'
  4873. `--question'
  4874.      "Question mode".  Do not run any commands, or print anything; just
  4875.      return an exit status that is zero if the specified targets are
  4876.      already up to date, nonzero otherwise.  *Note Instead of Executing
  4877.      the Commands: Instead of Execution.
  4878.  
  4879. `-r'
  4880. `--no-builtin-rules'
  4881.      Eliminate use of the built-in implicit rules (*note Using Implicit
  4882.      Rules: Implicit Rules.).  You can still define your own by writing
  4883.      pattern rules (*note Defining and Redefining Pattern Rules:
  4884.      Pattern Rules.).  The `-r' option also clears out the default list
  4885.      of suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
  4886.      Suffix Rules.).  But you can still define your own suffixes with a
  4887.      rule for `.SUFFIXES', and then define your own suffix rules.
  4888.  
  4889. `-s'
  4890. `--silent'
  4891. `--quiet'
  4892.      Silent operation; do not print the commands as they are executed.
  4893.      *Note Command Echoing: Echoing.
  4894.  
  4895. `-S'
  4896. `--no-keep-going'
  4897. `--stop'
  4898.      Cancel the effect of the `-k' option.  This is never necessary
  4899.      except in a recursive `make' where `-k' might be inherited from
  4900.      the top-level `make' via `MAKEFLAGS' (*note Recursive Use of
  4901.      `make': Recursion.) or if you set `-k' in `MAKEFLAGS' in your
  4902.      environment.
  4903.  
  4904. `-t'
  4905. `--touch'
  4906.      Touch files (mark them up to date without really changing them)
  4907.      instead of running their commands.  This is used to pretend that
  4908.      the commands were done, in order to fool future invocations of
  4909.      `make'.  *Note Instead of Executing the Commands: Instead of
  4910.      Execution.
  4911.  
  4912. `-v'
  4913. `--version'
  4914.      Print the version of the `make' program plus a copyright, a list
  4915.      of authors, and a notice that there is no warranty; then exit.
  4916.  
  4917. `-w'
  4918. `--print-directory'
  4919.      Print a message containing the working directory both before and
  4920.      after executing the makefile.  This may be useful for tracking
  4921.      down errors from complicated nests of recursive `make' commands.
  4922.      *Note Recursive Use of `make': Recursion.  (In practice, you
  4923.      rarely need to specify this option since `make' does it for you;
  4924.      see *Note The `--print-directory' Option: -w Option.)
  4925.  
  4926. `--no-print-directory'
  4927.      Disable printing of the working directory under `-w'.  This option
  4928.      is useful when `-w' is turned on automatically, but you do not
  4929.      want to see the extra messages.  *Note The `--print-directory'
  4930.      Option: -w Option.
  4931.  
  4932. `-W FILE'
  4933. `--what-if=FILE'
  4934. `--new-file=FILE'
  4935. `--assume-new=FILE'
  4936.      Pretend that the target FILE has just been modified.  When used
  4937.      with the `-n' flag, this shows you what would happen if you were
  4938.      to modify that file.  Without `-n', it is almost the same as
  4939.      running a `touch' command on the given file before running `make',
  4940.      except that the modification time is changed only in the
  4941.      imagination of `make'.  *Note Instead of Executing the Commands:
  4942.      Instead of Execution.
  4943.  
  4944. `--warn-undefined-variables'
  4945.      Issue a warning message whenever `make' sees a reference to an
  4946.      undefined variable.  This can be helpful when you are trying to
  4947.      debug makefiles which use variables in complex ways.
  4948.  
  4949. 
  4950. File: make,  Node: Implicit Rules,  Next: Archives,  Prev: Running,  Up: Top
  4951.  
  4952. Using Implicit Rules
  4953. ********************
  4954.  
  4955.    Certain standard ways of remaking target files are used very often.
  4956. For example, one customary way to make an object file is from a C
  4957. source file using the C compiler, `cc'.
  4958.  
  4959.    "Implicit rules" tell `make' how to use customary techniques so that
  4960. you do not have to specify them in detail when you want to use them.
  4961. For example, there is an implicit rule for C compilation.  File names
  4962. determine which implicit rules are run.  For example, C compilation
  4963. typically takes a `.c' file and makes a `.o' file.  So `make' applies
  4964. the implicit rule for C compilation when it sees this combination of
  4965. file name endings.
  4966.  
  4967.    A chain of implicit rules can apply in sequence; for example, `make'
  4968. will remake a `.o' file from a `.y' file by way of a `.c' file.
  4969.  
  4970.    The built-in implicit rules use several variables in their commands
  4971. so that, by changing the values of the variables, you can change the
  4972. way the implicit rule works.  For example, the variable `CFLAGS'
  4973. controls the flags given to the C compiler by the implicit rule for C
  4974. compilation.
  4975.  
  4976.    You can define your own implicit rules by writing "pattern rules".
  4977.  
  4978.    "Suffix rules" are a more limited way to define implicit rules.
  4979. Pattern rules are more general and clearer, but suffix rules are
  4980. retained for compatibility.
  4981.  
  4982. * Menu:
  4983.  
  4984. * Using Implicit::              How to use an existing implicit rule
  4985.                                   to get the commands for updating a file.
  4986. * Catalogue of Rules::          A list of built-in implicit rules.
  4987. * Implicit Variables::          How to change what predefined rules do.
  4988. * Chained Rules::               How to use a chain of implicit rules.
  4989. * Pattern Rules::               How to define new implicit rules.
  4990. * Last Resort::                 How to defining commands for rules
  4991.                                   which cannot find any.
  4992. * Suffix Rules::                The old-fashioned style of implicit rule.
  4993. * Search Algorithm::            The precise algorithm for applying
  4994.                                   implicit rules.
  4995.  
  4996. 
  4997. File: make,  Node: Using Implicit,  Next: Catalogue of Rules,  Up: Implicit Rules
  4998.  
  4999. Using Implicit Rules
  5000. ====================
  5001.  
  5002.    To allow `make' to find a customary method for updating a target
  5003. file, all you have to do is refrain from specifying commands yourself.
  5004. Either write a rule with no command lines, or don't write a rule at
  5005. all.  Then `make' will figure out which implicit rule to use based on
  5006. which kind of source file exists or can be made.
  5007.  
  5008.    For example, suppose the makefile looks like this:
  5009.  
  5010.      foo : foo.o bar.o
  5011.              cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
  5012.  
  5013. Because you mention `foo.o' but do not give a rule for it, `make' will
  5014. automatically look for an implicit rule that tells how to update it.
  5015. This happens whether or not the file `foo.o' currently exists.
  5016.  
  5017.    If an implicit rule is found, it can supply both commands and one or
  5018. more dependencies (the source files).  You would want to write a rule
  5019. for `foo.o' with no command lines if you need to specify additional
  5020. dependencies, such as header files, that the implicit rule cannot
  5021. supply.
  5022.  
  5023.    Each implicit rule has a target pattern and dependency patterns.
  5024. There may be many implicit rules with the same target pattern.  For
  5025. example, numerous rules make `.o' files: one, from a `.c' file with the
  5026. C compiler; another, from a `.p' file with the Pascal compiler; and so
  5027. on.  The rule that actually applies is the one whose dependencies exist
  5028. or can be made.  So, if you have a file `foo.c', `make' will run the C
  5029. compiler; otherwise, if you have a file `foo.p', `make' will run the
  5030. Pascal compiler; and so on.
  5031.  
  5032.    Of course, when you write the makefile, you know which implicit rule
  5033. you want `make' to use, and you know it will choose that one because you
  5034. know which possible dependency files are supposed to exist.  *Note
  5035. Catalogue of Implicit Rules: Catalogue of Rules, for a catalogue of all
  5036. the predefined implicit rules.
  5037.  
  5038.    Above, we said an implicit rule applies if the required dependencies
  5039. "exist or can be made".  A file "can be made" if it is mentioned
  5040. explicitly in the makefile as a target or a dependency, or if an
  5041. implicit rule can be recursively found for how to make it.  When an
  5042. implicit dependency is the result of another implicit rule, we say that
  5043. "chaining" is occurring.  *Note Chains of Implicit Rules: Chained Rules.
  5044.  
  5045.    In general, `make' searches for an implicit rule for each target, and
  5046. for each double-colon rule, that has no commands.  A file that is
  5047. mentioned only as a dependency is considered a target whose rule
  5048. specifies nothing, so implicit rule search happens for it.  *Note
  5049. Implicit Rule Search Algorithm: Search Algorithm, for the details of
  5050. how the search is done.
  5051.  
  5052.    Note that explicit dependencies do not influence implicit rule
  5053. search.  For example, consider this explicit rule:
  5054.  
  5055.      foo.o: foo.p
  5056.  
  5057. The dependency on `foo.p' does not necessarily mean that `make' will
  5058. remake `foo.o' according to the implicit rule to make an object file, a
  5059. `.o' file, from a Pascal source file, a `.p' file.  For example, if
  5060. `foo.c' also exists, the implicit rule to make an object file from a C
  5061. source file is used instead, because it appears before the Pascal rule
  5062. in the list of predefined implicit rules (*note Catalogue of Implicit
  5063. Rules: Catalogue of Rules.).
  5064.  
  5065.    If you do not want an implicit rule to be used for a target that has
  5066. no commands, you can give that target empty commands by writing a
  5067. semicolon (*note Defining Empty Commands: Empty Commands.).
  5068.  
  5069. 
  5070. File: make,  Node: Catalogue of Rules,  Next: Implicit Variables,  Prev: Using Implicit,  Up: Implicit Rules
  5071.  
  5072. Catalogue of Implicit Rules
  5073. ===========================
  5074.  
  5075.    Here is a catalogue of predefined implicit rules which are always
  5076. available unless the makefile explicitly overrides or cancels them.
  5077. *Note Canceling Implicit Rules: Canceling Rules, for information on
  5078. canceling or overriding an implicit rule.  The `-r' or
  5079. `--no-builtin-rules' option cancels all predefined rules.
  5080.  
  5081.    Not all of these rules will always be defined, even when the `-r'
  5082. option is not given.  Many of the predefined implicit rules are
  5083. implemented in `make' as suffix rules, so which ones will be defined
  5084. depends on the "suffix list" (the list of dependencies of the special
  5085. target `.SUFFIXES').  The default suffix list is: `.out', `.a', `.ln',
  5086. `.o', `.c', `.cc', `.C', `.p', `.f', `.F', `.r', `.y', `.l', `.s',
  5087. `.S', `.mod', `.sym', `.def', `.h', `.info', `.dvi', `.tex', `.texinfo',
  5088. `.texi', `.txinfo', `.w', `.ch' `.web', `.sh', `.elc', `.el'.  All of
  5089. the implicit rules described below whose dependencies have one of these
  5090. suffixes are actually suffix rules.  If you modify the suffix list, the
  5091. only predefined suffix rules in effect will be those named by one or
  5092. two of the suffixes that are on the list you specify; rules whose
  5093. suffixes fail to be on the list are disabled.  *Note Old-Fashioned
  5094. Suffix Rules: Suffix Rules, for full details on suffix rules.
  5095.  
  5096. Compiling C programs
  5097.      `N.o' is made automatically from `N.c' with a command of the form
  5098.      `$(CC) -c $(CPPFLAGS) $(CFLAGS)'.
  5099.  
  5100. Compiling C++ programs
  5101.      `N.o' is made automatically from `N.cc' or `N.C' with a command of
  5102.      the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'.  We encourage you to
  5103.      use the suffix `.cc' for C++ source files instead of `.C'.
  5104.  
  5105. Compiling Pascal programs
  5106.      `N.o' is made automatically from `N.p' with the command `$(PC) -c
  5107.      $(PFLAGS)'.
  5108.  
  5109. Compiling Fortran and Ratfor programs
  5110.      `N.o' is made automatically from `N.r', `N.F' or `N.f' by running
  5111.      the Fortran compiler.  The precise command used is as follows:
  5112.  
  5113.     `.f'
  5114.           `$(FC) -c $(FFLAGS)'.
  5115.  
  5116.     `.F'
  5117.           `$(FC) -c $(FFLAGS) $(CPPFLAGS)'.
  5118.  
  5119.     `.r'
  5120.           `$(FC) -c $(FFLAGS) $(RFLAGS)'.
  5121.  
  5122. Preprocessing Fortran and Ratfor programs
  5123.      `N.f' is made automatically from `N.r' or `N.F'.  This rule runs
  5124.      just the preprocessor to convert a Ratfor or preprocessable
  5125.      Fortran program into a strict Fortran program.  The precise
  5126.      command used is as follows:
  5127.  
  5128.     `.F'
  5129.           `$(FC) -F $(CPPFLAGS) $(FFLAGS)'.
  5130.  
  5131.     `.r'
  5132.           `$(FC) -F $(FFLAGS) $(RFLAGS)'.
  5133.  
  5134. Compiling Modula-2 programs
  5135.      `N.sym' is made from `N.def' with a command of the form `$(M2C)
  5136.      $(M2FLAGS) $(DEFFLAGS)'.  `N.o' is made from `N.mod'; the form is:
  5137.      `$(M2C) $(M2FLAGS) $(MODFLAGS)'.
  5138.  
  5139. Assembling and preprocessing assembler programs
  5140.      `N.o' is made automatically from `N.s' by running the assembler,
  5141.      `as'.  The precise command is `$(AS) $(ASFLAGS)'.
  5142.  
  5143.      `N.s' is made automatically from `N.S' by running the C
  5144.      preprocessor, `cpp'.  The precise command is `$(CPP) $(CPPFLAGS)'.
  5145.  
  5146. Linking a single object file
  5147.      `N' is made automatically from `N.o' by running the linker
  5148.      (usually called `ld') via the C compiler.  The precise command
  5149.      used is `$(CC) $(LDFLAGS) N.o $(LOADLIBES)'.
  5150.  
  5151.      This rule does the right thing for a simple program with only one
  5152.      source file.  It will also do the right thing if there are multiple
  5153.      object files (presumably coming from various other source files),
  5154.      one of which has a name matching that of the executable file.
  5155.      Thus,
  5156.  
  5157.           x: y.o z.o
  5158.  
  5159.      when `x.c', `y.c' and `z.c' all exist will execute:
  5160.  
  5161.           cc -c x.c -o x.o
  5162.           cc -c y.c -o y.o
  5163.           cc -c z.c -o z.o
  5164.           cc x.o y.o z.o -o x
  5165.           rm -f x.o
  5166.           rm -f y.o
  5167.           rm -f z.o
  5168.  
  5169.      In more complicated cases, such as when there is no object file
  5170.      whose name derives from the executable file name, you must write
  5171.      an explicit command for linking.
  5172.  
  5173.      Each kind of file automatically made into `.o' object files will
  5174.      be automatically linked by using the compiler (`$(CC)', `$(FC)' or
  5175.      `$(PC)'; the C compiler `$(CC)' is used to assemble `.s' files)
  5176.      without the `-c' option.  This could be done by using the `.o'
  5177.      object files as intermediates, but it is faster to do the
  5178.      compiling and linking in one step, so that's how it's done.
  5179.  
  5180. Yacc for C programs
  5181.      `N.c' is made automatically from `N.y' by running Yacc with the
  5182.      command `$(YACC) $(YFLAGS)'.
  5183.  
  5184. Lex for C programs
  5185.      `N.c' is made automatically from `N.l' by by running Lex.  The
  5186.      actual command is `$(LEX) $(LFLAGS)'.
  5187.  
  5188. Lex for Ratfor programs
  5189.      `N.r' is made automatically from `N.l' by by running Lex.  The
  5190.      actual command is `$(LEX) $(LFLAGS)'.
  5191.  
  5192.      The convention of using the same suffix `.l' for all Lex files
  5193.      regardless of whether they produce C code or Ratfor code makes it
  5194.      impossible for `make' to determine automatically which of the two
  5195.      languages you are using in any particular case.  If `make' is
  5196.      called upon to remake an object file from a `.l' file, it must
  5197.      guess which compiler to use.  It will guess the C compiler, because
  5198.      that is more common.  If you are using Ratfor, make sure `make'
  5199.      knows this by mentioning `N.r' in the makefile.  Or, if you are
  5200.      using Ratfor exclusively, with no C files, remove `.c' from the
  5201.      list of implicit rule suffixes with:
  5202.  
  5203.           .SUFFIXES:
  5204.           .SUFFIXES: .o .r .f .l ...
  5205.  
  5206. Making Lint Libraries from C, Yacc, or Lex programs
  5207.      `N.ln' is made from `N.c' by running `lint'.  The precise command
  5208.      is `$(LINT) $(LINTFLAGS) $(CPPFLAGS) -i'.  The same command is
  5209.      used on the C code produced from `N.y' or `N.l'.
  5210.  
  5211. TeX and Web
  5212.      `N.dvi' is made from `N.tex' with the command `$(TEX)'.  `N.tex'
  5213.      is made from `N.web' with `$(WEAVE)', or from `N.w' (and from
  5214.      `N.ch' if it exists or can be made) with `$(CWEAVE)'.  `N.p' is
  5215.      made from `N.web' with `$(TANGLE)' and `N.c' is made from `N.w'
  5216.      (and from `N.ch' if it exists or can be made) with `$(CTANGLE)'.
  5217.  
  5218. Texinfo and Info
  5219.      `N.dvi' is made from `N.texinfo', `N.texi', or `N.txinfo', with
  5220.      the `$(TEXI2DVI)' command.  `N.info' is made from `N.texinfo',
  5221.      `N.texi', or `N.txinfo', with the `$(MAKEINFO)' command.
  5222.  
  5223. RCS
  5224.      Any file `N' is extracted if necessary from an RCS file named
  5225.      either `N,v' or `RCS/N,v'.  The precise command used is
  5226.      `$(CO) $(COFLAGS)'.  `N' will not be extracted from RCS if it
  5227.      already exists, even if the RCS file is newer.  The rules for RCS
  5228.      are terminal (*note Match-Anything Pattern Rules: Match-Anything
  5229.      Rules.), so RCS files cannot be generated from another source;
  5230.      they must actually exist.
  5231.  
  5232. SCCS
  5233.      Any file `N' is extracted if necessary from an SCCS file named
  5234.      either `s.N' or `SCCS/s.N'.  The precise command used is
  5235.      `$(GET) $(GFLAGS)'.  The rules for SCCS are terminal (*note
  5236.      Match-Anything Pattern Rules: Match-Anything Rules.), so SCCS
  5237.      files cannot be generated from another source; they must actually
  5238.      exist.
  5239.  
  5240.      For the benefit of SCCS, a file `N' is copied from `N.sh' and made
  5241.      executable (by everyone).  This is for shell scripts that are
  5242.      checked into SCCS.  Since RCS preserves the execution permission
  5243.      of a file, you do not need to use this feature with RCS.
  5244.  
  5245.      We recommend that you avoid using of SCCS.  RCS is widely held to
  5246.      be superior, and is also free.  By choosing free software in place
  5247.      of comparable (or inferior) proprietary software, you support the
  5248.      free software movement.
  5249.  
  5250.    Usually, you want to change only the variables listed in the table
  5251. above, which are documented in the following section.
  5252.  
  5253.    However, the commands in built-in implicit rules actually use
  5254. variables such as `COMPILE.c', `LINK.p', and `PREPROCESS.S', whose
  5255. values contain the commands listed above.
  5256.  
  5257.    `make' follows the convention that the rule to compile a `.X' source
  5258. file uses the variable `COMPILE.X'.  Similarly, the rule to produce an
  5259. executable from a `.X' file uses `LINK.X'; and the rule to preprocess a
  5260. `.X' file uses `PREPROCESS.X'.
  5261.  
  5262.    Every rule that produces an object file uses the variable
  5263. `OUTPUT_OPTION'.  `make' defines this variable either to contain `-o
  5264. $@', or to be empty, depending on a compile-time option.  You need the
  5265. `-o' option to ensure that the output goes into the right file when the
  5266. source file is in a different directory, as when using `VPATH' (*note
  5267. Directory Search::.).  However, compilers on some systems do not accept
  5268. a `-o' switch for object files.  If you use such a system, and use
  5269. `VPATH', some compilations will put their output in the wrong place.  A
  5270. possible workaround for this problem is to give `OUTPUT_OPTION' the
  5271. value `; mv $*.o $@'.
  5272.  
  5273. 
  5274. File: make,  Node: Implicit Variables,  Next: Chained Rules,  Prev: Catalogue of Rules,  Up: Implicit Rules
  5275.  
  5276. Variables Used by Implicit Rules
  5277. ================================
  5278.  
  5279.    The commands in built-in implicit rules make liberal use of certain
  5280. predefined variables.  You can alter these variables in the makefile,
  5281. with arguments to `make', or in the environment to alter how the
  5282. implicit rules work without redefining the rules themselves.
  5283.  
  5284.    For example, the command used to compile a C source file actually
  5285. says `$(CC) -c $(CFLAGS) $(CPPFLAGS)'.  The default values of the
  5286. variables used are `cc' and nothing, resulting in the command `cc -c'.
  5287. By redefining `CC' to `ncc', you could cause `ncc' to be used for all C
  5288. compilations performed by the implicit rule.  By redefining `CFLAGS' to
  5289. be `-g', you could pass the `-g' option to each compilation.  *All*
  5290. implicit rules that do C compilation use `$(CC)' to get the program
  5291. name for the compiler and *all* include `$(CFLAGS)' among the arguments
  5292. given to the compiler.
  5293.  
  5294.    The variables used in implicit rules fall into two classes: those
  5295. that are names of programs (like `CC') and those that contain arguments
  5296. for the programs (like `CFLAGS').  (The "name of a program" may also
  5297. contain some command arguments, but it must start with an actual
  5298. executable program name.)  If a variable value contains more than one
  5299. argument, separate them with spaces.
  5300.  
  5301.    Here is a table of variables used as names of programs in built-in
  5302. rules:
  5303.  
  5304. `AR'
  5305.      Archive-maintaining program; default `ar'.
  5306.  
  5307. `AS'
  5308.      Program for doing assembly; default `as'.
  5309.  
  5310. `CC'
  5311.      Program for compiling C programs; default `cc'.
  5312.  
  5313. `CXX'
  5314.      Program for compiling C++ programs; default `g++'.
  5315.  
  5316. `CO'
  5317.      Program for extracting a file from RCS; default `co'.
  5318.  
  5319. `CPP'
  5320.      Program for running the C preprocessor, with results to standard
  5321.      output; default `$(CC) -E'.
  5322.  
  5323. `FC'
  5324.      Program for compiling or preprocessing Fortran and Ratfor programs;
  5325.      default `f77'.
  5326.  
  5327. `GET'
  5328.      Program for extracting a file from SCCS; default `get'.
  5329.  
  5330. `LEX'
  5331.      Program to use to turn Lex grammars into C programs or Ratfor
  5332.      programs; default `lex'.
  5333.  
  5334. `PC'
  5335.      Program for compiling Pascal programs; default `pc'.
  5336.  
  5337. `YACC'
  5338.      Program to use to turn Yacc grammars into C programs; default
  5339.      `yacc'.
  5340.  
  5341. `YACCR'
  5342.      Program to use to turn Yacc grammars into Ratfor programs; default
  5343.      `yacc -r'.
  5344.  
  5345. `MAKEINFO'
  5346.      Program to convert a Texinfo source file into an Info file; default
  5347.      `makeinfo'.
  5348.  
  5349. `TEX'
  5350.      Program to make TeX DVI files from TeX source; default `tex'.
  5351.  
  5352. `TEXI2DVI'
  5353.      Program to make TeX DVI files from Texinfo source; default
  5354.      `texi2dvi'.
  5355.  
  5356. `WEAVE'
  5357.      Program to translate Web into TeX; default `weave'.
  5358.  
  5359. `CWEAVE'
  5360.      Program to translate C Web into TeX; default `cweave'.
  5361.  
  5362. `TANGLE'
  5363.      Program to translate Web into Pascal; default `tangle'.
  5364.  
  5365. `CTANGLE'
  5366.      Program to translate C Web into C; default `ctangle'.
  5367.  
  5368. `RM'
  5369.      Command to remove a file; default `rm -f'.
  5370.  
  5371.    Here is a table of variables whose values are additional arguments
  5372. for the programs above.  The default values for all of these is the
  5373. empty string, unless otherwise noted.
  5374.  
  5375. `ARFLAGS'
  5376.      Flags to give the archive-maintaining program; default `rv'.
  5377.  
  5378. `ASFLAGS'
  5379.      Extra flags to give to the assembler (when explicitly invoked on a
  5380.      `.s' or `.S' file).
  5381.  
  5382. `CFLAGS'
  5383.      Extra flags to give to the C compiler.
  5384.  
  5385. `CXXFLAGS'
  5386.      Extra flags to give to the C++ compiler.
  5387.  
  5388. `COFLAGS'
  5389.      Extra flags to give to the RCS `co' program.
  5390.  
  5391. `CPPFLAGS'
  5392.      Extra flags to give to the C preprocessor and programs that use it
  5393.      (the C and Fortran compilers).
  5394.  
  5395. `FFLAGS'
  5396.      Extra flags to give to the Fortran compiler.
  5397.  
  5398. `GFLAGS'
  5399.      Extra flags to give to the SCCS `get' program.
  5400.  
  5401. `LDFLAGS'
  5402.      Extra flags to give to compilers when they are supposed to invoke
  5403.      the linker, `ld'.
  5404.  
  5405. `LFLAGS'
  5406.      Extra flags to give to Lex.
  5407.  
  5408. `PFLAGS'
  5409.      Extra flags to give to the Pascal compiler.
  5410.  
  5411. `RFLAGS'
  5412.      Extra flags to give to the Fortran compiler for Ratfor programs.
  5413.  
  5414. `YFLAGS'
  5415.      Extra flags to give to Yacc.
  5416.  
  5417. 
  5418. File: make,  Node: Chained Rules,  Next: Pattern Rules,  Prev: Implicit Variables,  Up: Implicit Rules
  5419.  
  5420. Chains of Implicit Rules
  5421. ========================
  5422.  
  5423.    Sometimes a file can be made by a sequence of implicit rules.  For
  5424. example, a file `N.o' could be made from `N.y' by running first Yacc
  5425. and then `cc'.  Such a sequence is called a "chain".
  5426.  
  5427.    If the file `N.c' exists, or is mentioned in the makefile, no
  5428. special searching is required: `make' finds that the object file can be
  5429. made by C compilation from `N.c'; later on, when considering how to
  5430. make `N.c', the rule for running Yacc is used.  Ultimately both `N.c'
  5431. and `N.o' are updated.
  5432.  
  5433.    However, even if `N.c' does not exist and is not mentioned, `make'
  5434. knows how to envision it as the missing link between `N.o' and `N.y'!
  5435. In this case, `N.c' is called an "intermediate file".  Once `make' has
  5436. decided to use the intermediate file, it is entered in the data base as
  5437. if it had been mentioned in the makefile, along with the implicit rule
  5438. that says how to create it.
  5439.  
  5440.    Intermediate files are remade using their rules just like all other
  5441. files.  The difference is that the intermediate file is deleted when
  5442. `make' is finished.  Therefore, the intermediate file which did not
  5443. exist before `make' also does not exist after `make'.  The deletion is
  5444. reported to you by printing a `rm -f' command that shows what `make' is
  5445. doing.  (You can list the target pattern of an implicit rule (such as
  5446. `%.o') as a dependency of the special target `.PRECIOUS' to preserve
  5447. intermediate files made by implicit rules whose target patterns match
  5448. that file's name; see *Note Interrupts::.)
  5449.  
  5450.    A chain can involve more than two implicit rules.  For example, it is
  5451. possible to make a file `foo' from `RCS/foo.y,v' by running RCS, Yacc
  5452. and `cc'.  Then both `foo.y' and `foo.c' are intermediate files that
  5453. are deleted at the end.
  5454.  
  5455.    No single implicit rule can appear more than once in a chain.  This
  5456. means that `make' will not even consider such a ridiculous thing as
  5457. making `foo' from `foo.o.o' by running the linker twice.  This
  5458. constraint has the added benefit of preventing any infinite loop in the
  5459. search for an implicit rule chain.
  5460.  
  5461.    There are some special implicit rules to optimize certain cases that
  5462. would otherwise be handled by rule chains.  For example, making `foo'
  5463. from `foo.c' could be handled by compiling and linking with separate
  5464. chained rules, using `foo.o' as an intermediate file.  But what
  5465. actually happens is that a special rule for this case does the
  5466. compilation and linking with a single `cc' command.  The optimized rule
  5467. is used in preference to the step-by-step chain because it comes
  5468. earlier in the ordering of rules.
  5469.  
  5470. 
  5471. File: make,  Node: Pattern Rules,  Next: Last Resort,  Prev: Chained Rules,  Up: Implicit Rules
  5472.  
  5473. Defining and Redefining Pattern Rules
  5474. =====================================
  5475.  
  5476.    You define an implicit rule by writing a "pattern rule".  A pattern
  5477. rule looks like an ordinary rule, except that its target contains the
  5478. character `%' (exactly one of them).  The target is considered a
  5479. pattern for matching file names; the `%' can match any nonempty
  5480. substring, while other characters match only themselves.  The
  5481. dependencies likewise use `%' to show how their names relate to the
  5482. target name.
  5483.  
  5484.    Thus, a pattern rule `%.o : %.c' says how to make any file `STEM.o'
  5485. from another file `STEM.c'.
  5486.  
  5487.    Note that expansion using `%' in pattern rules occurs *after* any
  5488. variable or function expansions, which take place when the makefile is
  5489. read.  *Note How to Use Variables: Using Variables, and *Note Functions
  5490. for Transforming Text: Functions.
  5491.  
  5492. * Menu:
  5493.  
  5494. * Pattern Intro::               An introduction to pattern rules.
  5495. * Pattern Examples::            Examples of pattern rules.
  5496. * Automatic::                   How to use automatic variables in the
  5497.                                   commands of implicit rules.
  5498. * Pattern Match::               How patterns match.
  5499. * Match-Anything Rules::        Precautions you should take prior to
  5500.                                   defining rules that can match any
  5501.                                   target file whatever.
  5502. * Canceling Rules::             How to override or cancel built-in rules.
  5503.  
  5504. 
  5505. File: make,  Node: Pattern Intro,  Next: Pattern Examples,  Up: Pattern Rules
  5506.  
  5507. Introduction to Pattern Rules
  5508. -----------------------------
  5509.  
  5510.    A pattern rule contains the character `%' (exactly one of them) in
  5511. the target; otherwise, it looks exactly like an ordinary rule.  The
  5512. target is a pattern for matching file names; the `%' matches any
  5513. nonempty substring, while other characters match only themselves.
  5514.  
  5515.    For example, `%.c' as a pattern matches any file name that ends in
  5516. `.c'.  `s.%.c' as a pattern matches any file name that starts with
  5517. `s.', ends in `.c' and is at least five characters long.  (There must
  5518. be at least one character to match the `%'.)  The substring that the
  5519. `%' matches is called the "stem".
  5520.  
  5521.    `%' in a dependency of a pattern rule stands for the same stem that
  5522. was matched by the `%' in the target.  In order for the pattern rule to
  5523. apply, its target pattern must match the file name under consideration,
  5524. and its dependency patterns must name files that exist or can be made.
  5525. These files become dependencies of the target.
  5526.  
  5527.    Thus, a rule of the form
  5528.  
  5529.      %.o : %.c ; COMMAND...
  5530.  
  5531. specifies how to make a file `N.o', with another file `N.c' as its
  5532. dependency, provided that `N.c' exists or can be made.
  5533.  
  5534.    There may also be dependencies that do not use `%'; such a dependency
  5535. attaches to every file made by this pattern rule.  These unvarying
  5536. dependencies are useful occasionally.
  5537.  
  5538.    A pattern rule need not have any dependencies that contain `%', or
  5539. in fact any dependencies at all.  Such a rule is effectively a general
  5540. wildcard.  It provides a way to make any file that matches the target
  5541. pattern.  *Note Last Resort::.
  5542.  
  5543.    Pattern rules may have more than one target.  Unlike normal rules,
  5544. this does not act as many different rules with the same dependencies and
  5545. commands.  If a pattern rule has multiple targets, `make' knows that
  5546. the rule's commands are responsible for making all of the targets.  The
  5547. commands are executed only once to make all the targets.  When searching
  5548. for a pattern rule to match a target, the target patterns of a rule
  5549. other than the one that matches the target in need of a rule are
  5550. incidental: `make' worries only about giving commands and dependencies
  5551. to the file presently in question.  However, when this file's commands
  5552. are run, the other targets are marked as having been updated themselves.
  5553.  
  5554.    The order in which pattern rules appear in the makefile is important
  5555. since this is the order in which they are considered.  Of equally
  5556. applicable rules, only the first one found is used.  The rules you
  5557. write take precedence over those that are built in.  Note however, that
  5558. a rule whose dependencies actually exist or are mentioned always takes
  5559. priority over a rule with dependencies that must be made by chaining
  5560. other implicit rules.
  5561.  
  5562. 
  5563. File: make,  Node: Pattern Examples,  Next: Automatic,  Prev: Pattern Intro,  Up: Pattern Rules
  5564.  
  5565. Pattern Rule Examples
  5566. ---------------------
  5567.  
  5568.    Here are some examples of pattern rules actually predefined in
  5569. `make'.  First, the rule that compiles `.c' files into `.o' files:
  5570.  
  5571.      %.o : %.c
  5572.              $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
  5573.  
  5574. defines a rule that can make any file `X.o' from `X.c'.  The command
  5575. uses the automatic variables `$@' and `$<' to substitute the names of
  5576. the target file and the source file in each case where the rule applies
  5577. (*note Automatic Variables: Automatic.).
  5578.  
  5579.    Here is a second built-in rule:
  5580.  
  5581.      % :: RCS/%,v
  5582.              $(CO) $(COFLAGS) $<
  5583.  
  5584. defines a rule that can make any file `X' whatsoever from a
  5585. corresponding file `X,v' in the subdirectory `RCS'.  Since the target
  5586. is `%', this rule will apply to any file whatever, provided the
  5587. appropriate dependency file exists.  The double colon makes the rule
  5588. "terminal", which means that its dependency may not be an intermediate
  5589. file (*note Match-Anything Pattern Rules: Match-Anything Rules.).
  5590.  
  5591.    This pattern rule has two targets:
  5592.  
  5593.      %.tab.c %.tab.h: %.y
  5594.              bison -d $<
  5595.  
  5596. This tells `make' that the command `bison -d X.y' will make both
  5597. `X.tab.c' and `X.tab.h'.  If the file `foo' depends on the files
  5598. `parse.tab.o' and `scan.o' and the file `scan.o' depends on the file
  5599. `parse.tab.h', when `parse.y' is changed, the command `bison -d parse.y'
  5600. will be executed only once, and the dependencies of both `parse.tab.o'
  5601. and `scan.o' will be satisfied.  (Presumably the file `parse.tab.o'
  5602. will be recompiled from `parse.tab.c' and the file `scan.o' from
  5603. `scan.c', while `foo' is linked from `parse.tab.o', `scan.o', and its
  5604. other dependencies, and it will execute happily ever after.)
  5605.  
  5606. 
  5607. File: make,  Node: Automatic,  Next: Pattern Match,  Prev: Pattern Examples,  Up: Pattern Rules
  5608.  
  5609. Automatic Variables
  5610. -------------------
  5611.  
  5612.    Suppose you are writing a pattern rule to compile a `.c' file into a
  5613. `.o' file: how do you write the `cc' command so that it operates on the
  5614. right source file name?  You cannot write the name in the command,
  5615. because the name is different each time the implicit rule is applied.
  5616.  
  5617.    What you do is use a special feature of `make', the "automatic
  5618. variables".  These variables have values computed afresh for each rule
  5619. that is executed, based on the target and dependencies of the rule.  In
  5620. this example, you would use `$@' for the object file name and `$<' for
  5621. the source file name.
  5622.  
  5623.    Here is a table of automatic variables:
  5624.  
  5625. `$@'
  5626.      The file name of the target of the rule.  If the target is an
  5627.      archive member, then `$@' is the name of the archive file.  In a
  5628.      pattern rule that has multiple targets (*note Introduction to
  5629.      Pattern Rules: Pattern Intro.), `$@' is the name of whichever
  5630.      target caused the rule's commands to be run.
  5631.  
  5632. `$%'
  5633.      The target member name, when the target is an archive member.
  5634.      *Note Archives::.  For example, if the target is `foo.a(bar.o)'
  5635.      then `$%' is `bar.o' and `$@' is `foo.a'.  `$%' is empty when the
  5636.      target is not an archive member.
  5637.  
  5638. `$<'
  5639.      The name of the first dependency.  If the target got its commands
  5640.      from an implicit rule, this will be the first dependency added by
  5641.      the implicit rule (*note Implicit Rules::.).
  5642.  
  5643. `$?'
  5644.      The names of all the dependencies that are newer than the target,
  5645.      with spaces between them.  For dependencies which are archive
  5646.      members, only the member named is used (*note Archives::.).
  5647.  
  5648. `$^'
  5649.      The names of all the dependencies, with spaces between them.  For
  5650.      dependencies which are archive members, only the member named is
  5651.      used (*note Archives::.).
  5652.  
  5653. `$*'
  5654.      The stem with which an implicit rule matches (*note How Patterns
  5655.      Match: Pattern Match.).  If the target is `dir/a.foo.b' and the
  5656.      target pattern is `a.%.b' then the stem is `dir/foo'.  The stem is
  5657.      useful for constructing names of related files.
  5658.  
  5659.      In a static pattern rule, the stem is part of the file name that
  5660.      matched the `%' in the target pattern.
  5661.  
  5662.      In an explicit rule, there is no stem; so `$*' cannot be determined
  5663.      in that way.  Instead, if the target name ends with a recognized
  5664.      suffix (*note Old-Fashioned Suffix Rules: Suffix Rules.), `$*' is
  5665.      set to the target name minus the suffix.  For example, if the
  5666.      target name is `foo.c', then `$*' is set to `foo', since `.c' is a
  5667.      suffix.  GNU `make' does this bizarre thing only for compatibility
  5668.      with other implementations of `make'.  You should generally avoid
  5669.      using `$*' except in implicit rules or static pattern rules.
  5670.  
  5671.      If the target name in an explicit rule does not end with a
  5672.      recognized suffix, `$*' is set to the empty string for that rule.
  5673.  
  5674.    `$?' is useful even in explicit rules when you wish to operate on
  5675. only the dependencies that have changed.  For example, suppose that an
  5676. archive named `lib' is supposed to contain copies of several object
  5677. files.  This rule copies just the changed object files into the archive:
  5678.  
  5679.      lib: foo.o bar.o lose.o win.o
  5680.              ar r lib $?
  5681.  
  5682.    Of the variables listed above, four have values that are single file
  5683. names, and two have values that are lists of file names.  These six
  5684. have variants that get just the file's directory name or just the file
  5685. name within the directory.  The variant variables' names are formed by
  5686. appending `D' or `F', respectively.  These variants are semi-obsolete
  5687. in GNU `make' since the functions `dir' and `notdir' can be used to get
  5688. an equivalent effect (*note Functions for File Names: Filename
  5689. Functions.).  Here is a table of the variants:
  5690.  
  5691. `$(@D)'
  5692.      The directory part of the file name of the target.  If the value of
  5693.      `$@' is `dir/foo.o' then `$(@D)' is `dir/'.  This value is `./' if
  5694.      `$@' does not contain a slash.  `$(@D)' is equivalent to
  5695.      `$(dir $@)'.
  5696.  
  5697. `$(@F)'
  5698.      The file-within-directory part of the file name of the target.  If
  5699.      the value of `$@' is `dir/foo.o' then `$(@F)' is `foo.o'.  `$(@F)'
  5700.      is equivalent to `$(notdir $@)'.
  5701.  
  5702. `$(*D)'
  5703. `$(*F)'
  5704.      The directory part and the file-within-directory part of the stem;
  5705.      `dir/' and `foo' in this example.
  5706.  
  5707. `$(%D)'
  5708. `$(%F)'
  5709.      The directory part and the file-within-directory part of the target
  5710.      archive member name.  This makes sense only for archive member
  5711.      targets of the form `ARCHIVE(MEMBER)' and is useful only when
  5712.      MEMBER may contain a directory name.  (*Note Archive Members as
  5713.      Targets: Archive Members.)
  5714.  
  5715. `$(<D)'
  5716. `$(<F)'
  5717.      The directory part and the file-within-directory part of the first
  5718.      dependency.
  5719.  
  5720. `$(^D)'
  5721. `$(^F)'
  5722.      Lists of the directory parts and the file-within-directory parts
  5723.      of all dependencies.
  5724.  
  5725. `$(?D)'
  5726. `$(?F)'
  5727.      Lists of the directory parts and the file-within-directory parts of
  5728.      all dependencies that are newer than the target.
  5729.  
  5730.    Note that we use a special stylistic convention when we talk about
  5731. these automatic variables; we write "the value of `$<'", rather than
  5732. "the variable `<'" as we would write for ordinary variables such as
  5733. `objects' and `CFLAGS'.  We think this convention looks more natural in
  5734. this special case.  Please do not assume it has a deep significance;
  5735. `$<' refers to the variable named `<' just as `$(CFLAGS)' refers to the
  5736. variable named `CFLAGS'.  You could just as well use `$(<)' in place of
  5737. `$<'.
  5738.  
  5739. 
  5740. File: make,  Node: Pattern Match,  Next: Match-Anything Rules,  Prev: Automatic,  Up: Pattern Rules
  5741.  
  5742. How Patterns Match
  5743. ------------------
  5744.  
  5745.    A target pattern is composed of a `%' between a prefix and a suffix,
  5746. either or both of which may be empty.  The pattern matches a file name
  5747. only if the file name starts with the prefix and ends with the suffix,
  5748. without overlap.  The text between the prefix and the suffix is called
  5749. the "stem".  Thus, when the pattern `%.o' matches the file name
  5750. `test.o', the stem is `test'.  The pattern rule dependencies are turned
  5751. into actual file names by substituting the stem for the character `%'.
  5752. Thus, if in the same example one of the dependencies is written as
  5753. `%.c', it expands to `test.c'.
  5754.  
  5755.    When the target pattern does not contain a slash (and it usually does
  5756. not), directory names in the file names are removed from the file name
  5757. before it is compared with the target prefix and suffix.  After the
  5758. comparison of the file name to the target pattern, the directory names,
  5759. along with the slash that ends them, are added on to the dependency
  5760. file names generated from the pattern rule's dependency patterns and
  5761. the file name. The directories are ignored only for the purpose of
  5762. finding an implicit rule to use, not in the application of that rule.
  5763. Thus, `e%t' matches the file name `src/eat', with `src/a' as the stem.
  5764. When dependencies are turned into file names, the directories from the
  5765. stem are added at the front, while the rest of the stem is substituted
  5766. for the `%'.  The stem `src/a' with a dependency pattern `c%r' gives
  5767. the file name `src/car'.
  5768.  
  5769. 
  5770. File: make,  Node: Match-Anything Rules,  Next: Canceling Rules,  Prev: Pattern Match,  Up: Pattern Rules
  5771.  
  5772. Match-Anything Pattern Rules
  5773. ----------------------------
  5774.  
  5775.    When a pattern rule's target is just `%', it matches any file name
  5776. whatever.  We call these rules "match-anything" rules.  They are very
  5777. useful, but it can take a lot of time for `make' to think about them,
  5778. because it must consider every such rule for each file name listed
  5779. either as a target or as a dependency.
  5780.  
  5781.    Suppose the makefile mentions `foo.c'.  For this target, `make'
  5782. would have to consider making it by linking an object file `foo.c.o',
  5783. or by C compilation-and-linking in one step from `foo.c.c', or by
  5784. Pascal compilation-and-linking from `foo.c.p', and many other
  5785. possibilities.
  5786.  
  5787.    We know these possibilities are ridiculous since `foo.c' is a C
  5788. source file, not an executable.  If `make' did consider these
  5789. possibilities, it would ultimately reject them, because files such as
  5790. `foo.c.o' and `foo.c.p' would not exist.  But these possibilities are so
  5791. numerous that `make' would run very slowly if it had to consider them.
  5792.  
  5793.    To gain speed, we have put various constraints on the way `make'
  5794. considers match-anything rules.  There are two different constraints
  5795. that can be applied, and each time you define a match-anything rule you
  5796. must choose one or the other for that rule.
  5797.  
  5798.    One choice is to mark the match-anything rule as "terminal" by
  5799. defining it with a double colon.  When a rule is terminal, it does not
  5800. apply unless its dependencies actually exist.  Dependencies that could
  5801. be made with other implicit rules are not good enough.  In other words,
  5802. no further chaining is allowed beyond a terminal rule.
  5803.  
  5804.    For example, the built-in implicit rules for extracting sources from
  5805. RCS and SCCS files are terminal; as a result, if the file `foo.c,v' does
  5806. not exist, `make' will not even consider trying to make it as an
  5807. intermediate file from `foo.c,v.o' or from `RCS/SCCS/s.foo.c,v'.  RCS
  5808. and SCCS files are generally ultimate source files, which should not be
  5809. remade from any other files; therefore, `make' can save time by not
  5810. looking for ways to remake them.
  5811.  
  5812.    If you do not mark the match-anything rule as terminal, then it is
  5813. nonterminal.  A nonterminal match-anything rule cannot apply to a file
  5814. name that indicates a specific type of data.  A file name indicates a
  5815. specific type of data if some non-match-anything implicit rule target
  5816. matches it.
  5817.  
  5818.    For example, the file name `foo.c' matches the target for the pattern
  5819. rule `%.c : %.y' (the rule to run Yacc).  Regardless of whether this
  5820. rule is actually applicable (which happens only if there is a file
  5821. `foo.y'), the fact that its target matches is enough to prevent
  5822. consideration of any nonterminal match-anything rules for the file
  5823. `foo.c'.  Thus, `make' will not even consider trying to make `foo.c' as
  5824. an executable file from `foo.c.o', `foo.c.c', `foo.c.p', etc.
  5825.  
  5826.    The motivation for this constraint is that nonterminal match-anything
  5827. rules are used for making files containing specific types of data (such
  5828. as executable files) and a file name with a recognized suffix indicates
  5829. some other specific type of data (such as a C source file).
  5830.  
  5831.    Special built-in dummy pattern rules are provided solely to recognize
  5832. certain file names so that nonterminal match-anything rules will not be
  5833. considered.  These dummy rules have no dependencies and no commands, and
  5834. they are ignored for all other purposes.  For example, the built-in
  5835. implicit rule
  5836.  
  5837.      %.p :
  5838.  
  5839. exists to make sure that Pascal source files such as `foo.p' match a
  5840. specific target pattern and thereby prevent time from being wasted
  5841. looking for `foo.p.o' or `foo.p.c'.
  5842.  
  5843.    Dummy pattern rules such as the one for `%.p' are made for every
  5844. suffix listed as valid for use in suffix rules (*note Old-Fashioned
  5845. Suffix Rules: Suffix Rules.).
  5846.  
  5847. 
  5848. File: make,  Node: Canceling Rules,  Prev: Match-Anything Rules,  Up: Pattern Rules
  5849.  
  5850. Canceling Implicit Rules
  5851. ------------------------
  5852.  
  5853.    You can override a built-in implicit rule (or one you have defined
  5854. yourself) by defining a new pattern rule with the same target and
  5855. dependencies, but different commands.  When the new rule is defined, the
  5856. built-in one is replaced.  The new rule's position in the sequence of
  5857. implicit rules is determined by where you write the new rule.
  5858.  
  5859.    You can cancel a built-in implicit rule by defining a pattern rule
  5860. with the same target and dependencies, but no commands.  For example,
  5861. the following would cancel the rule that runs the assembler:
  5862.  
  5863.      %.o : %.s
  5864.  
  5865. 
  5866. File: make,  Node: Last Resort,  Next: Suffix Rules,  Prev: Pattern Rules,  Up: Implicit Rules
  5867.  
  5868. Defining Last-Resort Default Rules
  5869. ==================================
  5870.  
  5871.    You can define a last-resort implicit rule by writing a terminal
  5872. match-anything pattern rule with no dependencies (*note Match-Anything
  5873. Rules::.).  This is just like any other pattern rule; the only thing
  5874. special about it is that it will match any target.  So such a rule's
  5875. commands are used for all targets and dependencies that have no commands
  5876. of their own and for which no other implicit rule applies.
  5877.  
  5878.    For example, when testing a makefile, you might not care if the
  5879. source files contain real data, only that they exist.  Then you might
  5880. do this:
  5881.  
  5882.      %::
  5883.              touch $@
  5884.  
  5885. to cause all the source files needed (as dependencies) to be created
  5886. automatically.
  5887.  
  5888.    You can instead define commands to be used for targets for which
  5889. there are no rules at all, even ones which don't specify commands.  You
  5890. do this by writing a rule for the target `.DEFAULT'.  Such a rule's
  5891. commands are used for all dependencies which do not appear as targets in
  5892. any explicit rule, and for which no implicit rule applies.  Naturally,
  5893. there is no `.DEFAULT' rule unless you write one.
  5894.  
  5895.    If you use `.DEFAULT' with no commands or dependencies:
  5896.  
  5897.      .DEFAULT:
  5898.  
  5899. the commands previously stored for `.DEFAULT' are cleared.  Then `make'
  5900. acts as if you had never defined `.DEFAULT' at all.
  5901.  
  5902.    If you do not want a target to get the commands from a match-anything
  5903. pattern rule or `.DEFAULT', but you also do not want any commands to be
  5904. run for the target, you can give it empty commands (*note Defining
  5905. Empty Commands: Empty Commands.).
  5906.  
  5907.    You can use a last-resort rule to override part of another makefile.
  5908. *Note Overriding Part of Another Makefile: Overriding Makefiles.
  5909.  
  5910. 
  5911. File: make,  Node: Suffix Rules,  Next: Search Algorithm,  Prev: Last Resort,  Up: Implicit Rules
  5912.  
  5913. Old-Fashioned Suffix Rules
  5914. ==========================
  5915.  
  5916.    "Suffix rules" are the old-fashioned way of defining implicit rules
  5917. for `make'.  Suffix rules are obsolete because pattern rules are more
  5918. general and clearer.  They are supported in GNU `make' for
  5919. compatibility with old makefiles.  They come in two kinds:
  5920. "double-suffix" and "single-suffix".
  5921.  
  5922.    A double-suffix rule is defined by a pair of suffixes: the target
  5923. suffix and the source suffix.  It matches any file whose name ends with
  5924. the target suffix.  The corresponding implicit dependency is made by
  5925. replacing the target suffix with the source suffix in the file name.  A
  5926. two-suffix rule whose target and source suffixes are `.o' and `.c' is
  5927. equivalent to the pattern rule `%.o : %.c'.
  5928.  
  5929.    A single-suffix rule is defined by a single suffix, which is the
  5930. source suffix.  It matches any file name, and the corresponding implicit
  5931. dependency name is made by appending the source suffix.  A single-suffix
  5932. rule whose source suffix is `.c' is equivalent to the pattern rule `% :
  5933. %.c'.
  5934.  
  5935.    Suffix rule definitions are recognized by comparing each rule's
  5936. target against a defined list of known suffixes.  When `make' sees a
  5937. rule whose target is a known suffix, this rule is considered a
  5938. single-suffix rule.  When `make' sees a rule whose target is two known
  5939. suffixes concatenated, this rule is taken as a double-suffix rule.
  5940.  
  5941.    For example, `.c' and `.o' are both on the default list of known
  5942. suffixes.  Therefore, if you define a rule whose target is `.c.o',
  5943. `make' takes it to be a double-suffix rule with source suffix `.c' and
  5944. target suffix `.o'.  Here is the old-fashioned way to define the rule
  5945. for compiling a C source file:
  5946.  
  5947.      .c.o:
  5948.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  5949.  
  5950.    Suffix rules cannot have any dependencies of their own.  If they
  5951. have any, they are treated as normal files with funny names, not as
  5952. suffix rules.  Thus, the rule:
  5953.  
  5954.      .c.o: foo.h
  5955.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  5956.  
  5957. tells how to make the file `.c.o' from the dependency file `foo.h', and
  5958. is not at all like the pattern rule:
  5959.  
  5960.      %.o: %.c foo.h
  5961.              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
  5962.  
  5963. which tells how to make `.o' files from `.c' files, and makes all `.o'
  5964. files using this pattern rule also depend on `foo.h'.
  5965.  
  5966.    Suffix rules with no commands are also meaningless.  They do not
  5967. remove previous rules as do pattern rules with no commands (*note
  5968. Canceling Implicit Rules: Canceling Rules.).  They simply enter the
  5969. suffix or pair of suffixes concatenated as a target in the data base.
  5970.  
  5971.    The known suffixes are simply the names of the dependencies of the
  5972. special target `.SUFFIXES'.  You can add your own suffixes by writing a
  5973. rule for `.SUFFIXES' that adds more dependencies, as in:
  5974.  
  5975.      .SUFFIXES: .hack .win
  5976.  
  5977. which adds `.hack' and `.win' to the end of the list of suffixes.
  5978.  
  5979.    If you wish to eliminate the default known suffixes instead of just
  5980. adding to them, write a rule for `.SUFFIXES' with no dependencies.  By
  5981. special dispensation, this eliminates all existing dependencies of
  5982. `.SUFFIXES'.  You can then write another rule to add the suffixes you
  5983. want.  For example,
  5984.  
  5985.      .SUFFIXES:            # Delete the default suffixes
  5986.      .SUFFIXES: .c .o .h   # Define our suffix list
  5987.  
  5988.    The `-r' or `--no-builtin-rules' flag causes the default list of
  5989. suffixes to be empty.
  5990.  
  5991.    The variable `SUFFIXES' is defined to the default list of suffixes
  5992. before `make' reads any makefiles.  You can change the list of suffixes
  5993. with a rule for the special target `.SUFFIXES', but that does not alter
  5994. this variable.
  5995.  
  5996. 
  5997. File: make,  Node: Search Algorithm,  Prev: Suffix Rules,  Up: Implicit Rules
  5998.  
  5999. Implicit Rule Search Algorithm
  6000. ==============================
  6001.  
  6002.    Here is the procedure `make' uses for searching for an implicit rule
  6003. for a target T.  This procedure is followed for each double-colon rule
  6004. with no commands, for each target of ordinary rules none of which have
  6005. commands, and for each dependency that is not the target of any rule.
  6006. It is also followed recursively for dependencies that come from implicit
  6007. rules, in the search for a chain of rules.
  6008.  
  6009.    Suffix rules are not mentioned in this algorithm because suffix
  6010. rules are converted to equivalent pattern rules once the makefiles have
  6011. been read in.
  6012.  
  6013.    For an archive member target of the form `ARCHIVE(MEMBER)', the
  6014. following algorithm is run twice, first using the entire target name T,
  6015. and second using `(MEMBER)' as the target T if the first run found no
  6016. rule.
  6017.  
  6018.   1. Split T into a directory part, called D, and the rest, called N.
  6019.      For example, if T is `src/foo.o', then D is `src/' and N is
  6020.      `foo.o'.
  6021.  
  6022.   2. Make a list of all the pattern rules one of whose targets matches
  6023.      T or N.  If the target pattern contains a slash, it is matched
  6024.      against T; otherwise, against N.
  6025.  
  6026.   3. If any rule in that list is *not* a match-anything rule, then
  6027.      remove all nonterminal match-anything rules from the list.
  6028.  
  6029.   4. Remove from the list all rules with no commands.
  6030.  
  6031.   5. For each pattern rule in the list:
  6032.  
  6033.        a. Find the stem S, which is the nonempty part of T or N matched
  6034.           by the `%' in the target pattern.
  6035.  
  6036.        b. Compute the dependency names by substituting S for `%'; if
  6037.           the target pattern does not contain a slash, append D to the
  6038.           front of each dependency name.
  6039.  
  6040.        c. Test whether all the dependencies exist or ought to exist.
  6041.           (If a file name is mentioned in the makefile as a target or
  6042.           as an explicit dependency, then we say it ought to exist.)
  6043.  
  6044.           If all dependencies exist or ought to exist, or there are no
  6045.           dependencies, then this rule applies.
  6046.  
  6047.   6. If no pattern rule has been found so far, try harder.  For each
  6048.      pattern rule in the list:
  6049.  
  6050.        a. If the rule is terminal, ignore it and go on to the next rule.
  6051.  
  6052.        b. Compute the dependency names as before.
  6053.  
  6054.        c. Test whether all the dependencies exist or ought to exist.
  6055.  
  6056.        d. For each dependency that does not exist, follow this algorithm
  6057.           recursively to see if the dependency can be made by an
  6058.           implicit rule.
  6059.  
  6060.        e. If all dependencies exist, ought to exist, or can be made by
  6061.           implicit rules, then this rule applies.
  6062.  
  6063.   7. If no implicit rule applies, the rule for `.DEFAULT', if any,
  6064.      applies.  In that case, give T the same commands that `.DEFAULT'
  6065.      has.  Otherwise, there are no commands for T.
  6066.  
  6067.    Once a rule that applies has been found, for each target pattern of
  6068. the rule other than the one that matched T or N, the `%' in the pattern
  6069. is replaced with S and the resultant file name is stored until the
  6070. commands to remake the target file T are executed.  After these
  6071. commands are executed, each of these stored file names are entered into
  6072. the data base and marked as having been updated and having the same
  6073. update status as the file T.
  6074.  
  6075.    When the commands of a pattern rule are executed for T, the automatic
  6076. variables are set corresponding to the target and dependencies.  *Note
  6077. Automatic Variables: Automatic.
  6078.  
  6079. 
  6080. File: make,  Node: Archives,  Next: Features,  Prev: Implicit Rules,  Up: Top
  6081.  
  6082. Using `make' to Update Archive Files
  6083. ************************************
  6084.  
  6085.    "Archive files" are files containing named subfiles called
  6086. "members"; they are maintained with the program `ar' and their main use
  6087. is as subroutine libraries for linking.
  6088.  
  6089. * Menu:
  6090.  
  6091. * Archive Members::             Archive members as targets.
  6092. * Archive Update::              The implicit rule for archive member targets.
  6093. * Archive Suffix Rules::        You can write a special kind of suffix rule
  6094.                                   for updating archives.
  6095.  
  6096. 
  6097. File: make,  Node: Archive Members,  Next: Archive Update,  Up: Archives
  6098.  
  6099. Archive Members as Targets
  6100. ==========================
  6101.  
  6102.    An individual member of an archive file can be used as a target or
  6103. dependency in `make'.  The archive file must already exist, but the
  6104. member need not exist.  You specify the member named MEMBER in archive
  6105. file ARCHIVE as follows:
  6106.  
  6107.      ARCHIVE(MEMBER)
  6108.  
  6109. This construct is available only in targets and dependencies, not in
  6110. commands!  Most programs that you might use in commands do not support
  6111. this syntax and cannot act directly on archive members.  Only `ar' and
  6112. other programs specifically designed to operate on archives can do so.
  6113. Therefore, valid commands to update an archive member target probably
  6114. must use `ar'.  For example, this rule says to create a member `hack.o'
  6115. in archive `foolib' by copying the file `hack.o':
  6116.  
  6117.      foolib(hack.o) : hack.o
  6118.              ar r foolib hack.o
  6119.  
  6120.    In fact, nearly all archive member targets are updated in just this
  6121. way and there is an implicit rule to do it for you.
  6122.  
  6123.    To specify several members in the same archive, you can write all the
  6124. member names together between the parentheses.  For example:
  6125.  
  6126.      foolib(hack.o kludge.o)
  6127.  
  6128. is equivalent to:
  6129.  
  6130.      foolib(hack.o) foolib(kludge.o)
  6131.  
  6132.    You can also use shell-style wildcards in an archive member
  6133. reference.  *Note Using Wildcard Characters in File Names: Wildcards.
  6134. For example, `foolib(*.o)' expands to all existing members of the
  6135. `foolib' archive whose names end in `.o'; perhaps `foolib(hack.o)
  6136. foolib(kludge.o)'.
  6137.  
  6138. 
  6139. File: make,  Node: Archive Update,  Next: Archive Suffix Rules,  Prev: Archive Members,  Up: Archives
  6140.  
  6141. Implicit Rule for Archive Member Targets
  6142. ========================================
  6143.  
  6144.    Recall that a target that looks like `A(M)' stands for the member
  6145. named M in the archive file A.
  6146.  
  6147.    When `make' looks for an implicit rule for such a target, as a
  6148. special feature it considers implicit rules that match `(M)', as well as
  6149. those that match the actual target `A(M)'.
  6150.  
  6151.    This causes one special rule whose target is `(%)' to match.  This
  6152. rule updates the target `A(M)' by copying the file M into the archive.
  6153. For example, it will update the archive member target `foo.a(bar.o)' by
  6154. copying the *file* `bar.o' into the archive `foo.a' as a *member* named
  6155. `bar.o'.
  6156.  
  6157.    When this rule is chained with others, the result is very powerful.
  6158. Thus, `make "foo.a(bar.o)"' (the quotes are needed to protect the `('
  6159. and `)' from being interpreted specially by the shell) in the presence
  6160. of a file `bar.c' is enough to cause the following commands to be run,
  6161. even without a makefile:
  6162.  
  6163.      cc -c bar.c -o bar.o
  6164.      ar r foo.a bar.o
  6165.      rm -f bar.o
  6166.  
  6167. Here `make' has envisioned the file `bar.o' as an intermediate file.
  6168. *Note Chains of Implicit Rules: Chained Rules.
  6169.  
  6170.    Implicit rules such as this one are written using the automatic
  6171. variable `$%'.  *Note Automatic Variables: Automatic.
  6172.  
  6173.    An archive member name in an archive cannot contain a directory
  6174. name, but it may be useful in a makefile to pretend that it does.  If
  6175. you write an archive member target `foo.a(dir/file.o)', `make' will
  6176. perform automatic updating with this command:
  6177.  
  6178.      ar r foo.a dir/file.o
  6179.  
  6180. which has the effect of copying the file `dir/foo.o' into a member
  6181. named `foo.o'.  In connection with such usage, the automatic variables
  6182. `%D' and `%F' may be useful.
  6183.  
  6184. * Menu:
  6185.  
  6186. * Archive Symbols::             How to update archive symbol directories.
  6187.  
  6188. 
  6189. File: make,  Node: Archive Symbols,  Up: Archive Update
  6190.  
  6191. Updating Archive Symbol Directories
  6192. -----------------------------------
  6193.  
  6194.    An archive file that is used as a library usually contains a special
  6195. member named `__.SYMDEF' that contains a directory of the external
  6196. symbol names defined by all the other members.  After you update any
  6197. other members, you need to update `__.SYMDEF' so that it will summarize
  6198. the other members properly.  This is done by running the `ranlib'
  6199. program:
  6200.  
  6201.      ranlib ARCHIVEFILE
  6202.  
  6203.    Normally you would put this command in the rule for the archive file,
  6204. and make all the members of the archive file dependencies of that rule.
  6205. For example,
  6206.  
  6207.      libfoo.a: libfoo.a(x.o) libfoo.a(y.o) ...
  6208.              ranlib libfoo.a
  6209.  
  6210. The effect of this is to update archive members `x.o', `y.o', etc., and
  6211. then update the symbol directory member `__.SYMDEF' by running
  6212. `ranlib'.  The rules for updating the members are not shown here; most
  6213. likely you can omit them and use the implicit rule which copies files
  6214. into the archive, as described in the preceding section.
  6215.  
  6216.    This is not necessary when using the GNU `ar' program, which updates
  6217. the `__.SYMDEF' member automatically.
  6218.  
  6219. 
  6220. File: make,  Node: Archive Suffix Rules,  Prev: Archive Update,  Up: Archives
  6221.  
  6222. Suffix Rules for Archive Files
  6223. ==============================
  6224.  
  6225.    You can write a special kind of suffix rule for dealing with archive
  6226. files.  *Note Suffix Rules::, for a full explanation of suffix rules.
  6227. Archive suffix rules are obsolete in GNU `make', because pattern rules
  6228. for archives are a more general mechanism (*note Archive Update::.).
  6229. But they are retained for compatibility with other `make's.
  6230.  
  6231.    To write a suffix rule for archives, you simply write a suffix rule
  6232. using the target suffix `.a' (the usual suffix for archive files).  For
  6233. example, here is the old-fashioned suffix rule to update a library
  6234. archive from C source files:
  6235.  
  6236.      .c.a:
  6237.              $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  6238.              $(AR) r $@ $*.o
  6239.              $(RM) $*.o
  6240.  
  6241. This works just as if you had written the pattern rule:
  6242.  
  6243.      (%.o): %.c
  6244.              $(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $*.o
  6245.              $(AR) r $@ $*.o
  6246.              $(RM) $*.o
  6247.  
  6248.    In fact, this is just what `make' does when it sees a suffix rule
  6249. with `.a' as the target suffix.  Any double-suffix rule `.X.a' is
  6250. converted to a pattern rule with the target pattern `(%.o)' and a
  6251. dependency pattern of `%.X'.
  6252.  
  6253.    Since you might want to use `.a' as the suffix for some other kind
  6254. of file, `make' also converts archive suffix rules to pattern rules in
  6255. the normal way (*note Suffix Rules::.).  Thus a double-suffix rule
  6256. `.X.a' produces two pattern rules: `(%.o): %.X' and `%.a: %.X'.
  6257.  
  6258. 
  6259. File: make,  Node: Features,  Next: Missing,  Prev: Archives,  Up: Top
  6260.  
  6261. Features of GNU `make'
  6262. **********************
  6263.  
  6264.    Here is a summary of the features of GNU `make', for comparison with
  6265. and credit to other versions of `make'.  We consider the features of
  6266. `make' in 4.2 BSD systems as a baseline.  If you are concerned with
  6267. writing portable makefiles, you should use only the features of `make'
  6268. *not* listed here or in *Note Missing::.
  6269.  
  6270.    Many features come from the version of `make' in System V.
  6271.  
  6272.    * The `VPATH' variable and its special meaning.  *Note Searching
  6273.      Directories for Dependencies: Directory Search.  This feature
  6274.      exists in System V `make', but is undocumented.  It is documented
  6275.      in 4.3 BSD `make' (which says it mimics System V's `VPATH'
  6276.      feature).
  6277.  
  6278.    * Included makefiles.  *Note Including Other Makefiles: Include.
  6279.      Allowing multiple files to be included with a single directive is
  6280.      a GNU extension.
  6281.  
  6282.    * Variables are read from and communicated via the environment.
  6283.      *Note Variables from the Environment: Environment.
  6284.  
  6285.    * Options passed through the variable `MAKEFLAGS' to recursive
  6286.      invocations of `make'.  *Note Communicating Options to a
  6287.      Sub-`make': Options/Recursion.
  6288.  
  6289.    * The automatic variable `$%' is set to the member name in an
  6290.      archive reference.  *Note Automatic Variables: Automatic.
  6291.  
  6292.    * The automatic variables `$@', `$*', `$<', `$%', and `$?' have
  6293.      corresponding forms like `$(@F)' and `$(@D)'.  We have generalized
  6294.      this to `$^' as an obvious extension.  *Note Automatic Variables:
  6295.      Automatic.
  6296.  
  6297.    * Substitution variable references.  *Note Basics of Variable
  6298.      References: Reference.
  6299.  
  6300.    * The command-line options `-b' and `-m', accepted and ignored.  In
  6301.      System V `make', these options actually do something.
  6302.  
  6303.    * Execution of recursive commands to run `make' via the variable
  6304.      `MAKE' even if `-n', `-q' or `-t' is specified.  *Note Recursive
  6305.      Use of `make': Recursion.
  6306.  
  6307.    * Support for suffix `.a' in suffix rules.  *Note Archive Suffix
  6308.      Rules::.  This feature is obsolete in GNU `make', because the
  6309.      general feature of rule chaining (*note Chains of Implicit Rules:
  6310.      Chained Rules.) allows one pattern rule for installing members in
  6311.      an archive (*note Archive Update::.) to be sufficient.
  6312.  
  6313.    * The arrangement of lines and backslash-newline combinations in
  6314.      commands is retained when the commands are printed, so they appear
  6315.      as they do in the makefile, except for the stripping of initial
  6316.      whitespace.
  6317.  
  6318.    The following features were inspired by various other versions of
  6319. `make'.  In some cases it is unclear exactly which versions inspired
  6320. which others.
  6321.  
  6322.    * Pattern rules using `%'.  This has been implemented in several
  6323.      versions of `make'.  We're not sure who invented it first, but
  6324.      it's been spread around a bit.  *Note Defining and Redefining
  6325.      Pattern Rules: Pattern Rules.
  6326.  
  6327.    * Rule chaining and implicit intermediate files.  This was
  6328.      implemented by Stu Feldman in his version of `make' for AT&T
  6329.      Eighth Edition Research Unix, and later by Andrew Hume of AT&T
  6330.      Bell Labs in his `mk' program (where he terms it "transitive
  6331.      closure").  We do not really know if we got this from either of
  6332.      them or thought it up ourselves at the same time.  *Note Chains of
  6333.      Implicit Rules: Chained Rules.
  6334.  
  6335.    * The automatic variable `$^' containing a list of all dependencies
  6336.      of the current target.  We did not invent this, but we have no
  6337.      idea who did.  *Note Automatic Variables: Automatic.
  6338.  
  6339.    * The "what if" flag (`-W' in GNU `make') was (as far as we know)
  6340.      invented by Andrew Hume in `mk'.  *Note Instead of Executing the
  6341.      Commands: Instead of Execution.
  6342.  
  6343.    * The concept of doing several things at once (parallelism) exists in
  6344.      many incarnations of `make' and similar programs, though not in the
  6345.      System V or BSD implementations.  *Note Command Execution:
  6346.      Execution.
  6347.  
  6348.    * Modified variable references using pattern substitution come from
  6349.      SunOS 4.  *Note Basics of Variable References: Reference.  This
  6350.      functionality was provided in GNU `make' by the `patsubst'
  6351.      function before the alternate syntax was implemented for
  6352.      compatibility with SunOS 4.  It is not altogether clear who
  6353.      inspired whom, since GNU `make' had `patsubst' before SunOS 4 was
  6354.      released.
  6355.  
  6356.    * The special significance of `+' characters preceding command lines
  6357.      (*note Instead of Executing the Commands: Instead of Execution.) is
  6358.      mandated by `IEEE Standard 1003.2-1992' (POSIX.2).
  6359.  
  6360.    * The `+=' syntax to append to the value of a variable comes from
  6361.      SunOS 4 `make'.  *Note Appending More Text to Variables: Appending.
  6362.  
  6363.    * The syntax `ARCHIVE(MEM1 MEM2...)' to list multiple members in a
  6364.      single archive file comes from SunOS 4 `make'.  *Note Archive
  6365.      Members::.
  6366.  
  6367.    * The `-include' directive to include makefiles with no error for a
  6368.      nonexistent file comes from SunOS 4 `make'.  (But note that SunOS 4
  6369.      `make' does not allow multiple makefiles to be specified in one
  6370.      `-include' directive.)
  6371.  
  6372.    The remaining features are inventions new in GNU `make':
  6373.  
  6374.    * Use the `-v' or `--version' option to print version and copyright
  6375.      information.
  6376.  
  6377.    * Use the `-h' or `--help' option to summarize the options to `make'.
  6378.  
  6379.    * Simply-expanded variables.  *Note The Two Flavors of Variables:
  6380.      Flavors.
  6381.  
  6382.    * Pass command-line variable assignments automatically through the
  6383.      variable `MAKE' to recursive `make' invocations.  *Note Recursive
  6384.      Use of `make': Recursion.
  6385.  
  6386.    * Use the `-C' or `--directory' command option to change directory.
  6387.      *Note Summary of Options: Options Summary.
  6388.  
  6389.    * Make verbatim variable definitions with `define'.  *Note Defining
  6390.      Variables Verbatim: Defining.
  6391.  
  6392.    * Declare phony targets with the special target `.PHONY'.
  6393.  
  6394.      Andrew Hume of AT&T Bell Labs implemented a similar feature with a
  6395.      different syntax in his `mk' program.  This seems to be a case of
  6396.      parallel discovery.  *Note Phony Targets: Phony Targets.
  6397.  
  6398.    * Manipulate text by calling functions.  *Note Functions for
  6399.      Transforming Text: Functions.
  6400.  
  6401.    * Use the `-o' or `--old-file' option to pretend a file's
  6402.      modification-time is old.  *Note Avoiding Recompilation of Some
  6403.      Files: Avoiding Compilation.
  6404.  
  6405.    * Conditional execution.
  6406.  
  6407.      This feature has been implemented numerous times in various
  6408.      versions of `make'; it seems a natural extension derived from the
  6409.      features of the C preprocessor and similar macro languages and is
  6410.      not a revolutionary concept.  *Note Conditional Parts of
  6411.      Makefiles: Conditionals.
  6412.  
  6413.    * Specify a search path for included makefiles.  *Note Including
  6414.      Other Makefiles: Include.
  6415.  
  6416.    * Specify extra makefiles to read with an environment variable.
  6417.      *Note The Variable `MAKEFILES': MAKEFILES Variable.
  6418.  
  6419.    * Strip leading sequences of `./' from file names, so that `./FILE'
  6420.      and `FILE' are considered to be the same file.
  6421.  
  6422.    * Use a special search method for library dependencies written in the
  6423.      form `-lNAME'.  *Note Directory Search for Link Libraries:
  6424.      Libraries/Search.
  6425.  
  6426.    * Allow suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
  6427.      Suffix Rules.) to contain any characters.  In other versions of
  6428.      `make', they must begin with `.' and not contain any `/'
  6429.      characters.
  6430.  
  6431.    * Keep track of the current level of `make' recursion using the
  6432.      variable `MAKELEVEL'.  *Note Recursive Use of `make': Recursion.
  6433.  
  6434.    * Specify static pattern rules.  *Note Static Pattern Rules: Static
  6435.      Pattern.
  6436.  
  6437.    * Provide selective `vpath' search.  *Note Searching Directories for
  6438.      Dependencies: Directory Search.
  6439.  
  6440.    * Provide computed variable references.  *Note Basics of Variable
  6441.      References: Reference.
  6442.  
  6443.    * Update makefiles.  *Note How Makefiles Are Remade: Remaking
  6444.      Makefiles.  System V `make' has a very, very limited form of this
  6445.      functionality in that it will check out SCCS files for makefiles.
  6446.  
  6447.    * Various new built-in implicit rules.  *Note Catalogue of Implicit
  6448.      Rules: Catalogue of Rules.
  6449.  
  6450.    * The built-in variable `MAKE_VERSION' gives the version number of
  6451.      `make'.
  6452.  
  6453. 
  6454. File: make,  Node: Missing,  Next: Makefile Conventions,  Prev: Features,  Up: Top
  6455.  
  6456. Incompatibilities and Missing Features
  6457. **************************************
  6458.  
  6459.    The `make' programs in various other systems support a few features
  6460. that are not implemented in GNU `make'.  The POSIX.2 standard (`IEEE
  6461. Standard 1003.2-1992') which specifies `make' does not require any of
  6462. these features.
  6463.  
  6464.    * A target of the form `FILE((ENTRY))' stands for a member of
  6465.      archive file FILE.  The member is chosen, not by name, but by
  6466.      being an object file which defines the linker symbol ENTRY.
  6467.  
  6468.      This feature was not put into GNU `make' because of the
  6469.      nonmodularity of putting knowledge into `make' of the internal
  6470.      format of archive file symbol tables.  *Note Updating Archive
  6471.      Symbol Directories: Archive Symbols.
  6472.  
  6473.    * Suffixes (used in suffix rules) that end with the character `~'
  6474.      have a special meaning to System V `make'; they refer to the SCCS
  6475.      file that corresponds to the file one would get without the `~'.
  6476.      For example, the suffix rule `.c~.o' would make the file `N.o' from
  6477.      the SCCS file `s.N.c'.  For complete coverage, a whole series of
  6478.      such suffix rules is required.  *Note Old-Fashioned Suffix Rules:
  6479.      Suffix Rules.
  6480.  
  6481.      In GNU `make', this entire series of cases is handled by two
  6482.      pattern rules for extraction from SCCS, in combination with the
  6483.      general feature of rule chaining.  *Note Chains of Implicit Rules:
  6484.      Chained Rules.
  6485.  
  6486.    * In System V `make', the string `$$@' has the strange meaning that,
  6487.      in the dependencies of a rule with multiple targets, it stands for
  6488.      the particular target that is being processed.
  6489.  
  6490.      This is not defined in GNU `make' because `$$' should always stand
  6491.      for an ordinary `$'.
  6492.  
  6493.      It is possible to get this functionality through the use of static
  6494.      pattern rules (*note Static Pattern Rules: Static Pattern.).  The
  6495.      System V `make' rule:
  6496.  
  6497.           $(targets): $$@.o lib.a
  6498.  
  6499.      can be replaced with the GNU `make' static pattern rule:
  6500.  
  6501.           $(targets): %: %.o lib.a
  6502.  
  6503.    * In System V and 4.3 BSD `make', files found by `VPATH' search
  6504.      (*note Searching Directories for Dependencies: Directory Search.)
  6505.      have their names changed inside command strings.  We feel it is
  6506.      much cleaner to always use automatic variables and thus make this
  6507.      feature obsolete.
  6508.  
  6509.    * In some Unix `make's, the automatic variable `$*' appearing in the
  6510.      dependencies of a rule has the amazingly strange "feature" of
  6511.      expanding to the full name of the *target of that rule*.  We cannot
  6512.      imagine what went on in the minds of Unix `make' developers to do
  6513.      this; it is utterly inconsistent with the normal definition of
  6514.      `$*'.
  6515.  
  6516.    * In some Unix `make's, implicit rule search (*note Using Implicit
  6517.      Rules: Implicit Rules.) is apparently done for *all* targets, not
  6518.      just those without commands.  This means you can do:
  6519.  
  6520.           foo.o:
  6521.                   cc -c foo.c
  6522.  
  6523.      and Unix `make' will intuit that `foo.o' depends on `foo.c'.
  6524.  
  6525.      We feel that such usage is broken.  The dependency properties of
  6526.      `make' are well-defined (for GNU `make', at least), and doing such
  6527.      a thing simply does not fit the model.
  6528.  
  6529.    * GNU `make' does not include any built-in implicit rules for
  6530.      compiling or preprocessing EFL programs.  If we hear of anyone who
  6531.      is using EFL, we will gladly add them.
  6532.  
  6533.    * It appears that in SVR4 `make', a suffix rule can be specified with
  6534.      no commands, and it is treated as if it had empty commands (*note
  6535.      Empty Commands::.).  For example:
  6536.  
  6537.           .c.a:
  6538.  
  6539.      will override the built-in `.c.a' suffix rule.
  6540.  
  6541.      We feel that it is cleaner for a rule without commands to always
  6542.      simply add to the dependency list for the target.  The above
  6543.      example can be easily rewritten to get the desired behavior in GNU
  6544.      `make':
  6545.  
  6546.           .c.a: ;
  6547.  
  6548.    * Some versions of `make' invoke the shell with the `-e' flag,
  6549.      except under `-k' (*note Testing the Compilation of a Program:
  6550.      Testing.).  The `-e' flag tells the shell to exit as soon as any
  6551.      program it runs returns a nonzero status.  We feel it is cleaner to
  6552.      write each shell command line to stand on its own and not require
  6553.      this special treatment.
  6554.  
  6555. 
  6556. File: make,  Node: Makefile Conventions,  Next: Quick Reference,  Prev: Missing,  Up: Top
  6557.  
  6558. Makefile Conventions
  6559. ********************
  6560.  
  6561.    This chapter describes conventions for writing the Makefiles for GNU
  6562. programs.
  6563.  
  6564. * Menu:
  6565.  
  6566. * Makefile Basics::
  6567. * Utilities in Makefiles::
  6568. * Standard Targets::
  6569. * Command Variables::
  6570. * Directory Variables::
  6571.  
  6572. 
  6573. File: make,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
  6574.  
  6575. General Conventions for Makefiles
  6576. =================================
  6577.  
  6578.    Every Makefile should contain this line:
  6579.  
  6580.      SHELL = /bin/sh
  6581.  
  6582. to avoid trouble on systems where the `SHELL' variable might be
  6583. inherited from the environment.  (This is never a problem with GNU
  6584. `make'.)
  6585.  
  6586.    Don't assume that `.' is in the path for command execution.  When
  6587. you need to run programs that are a part of your package during the
  6588. make, please make sure that it uses `./' if the program is built as
  6589. part of the make or `$(srcdir)/' if the file is an unchanging part of
  6590. the source code.  Without one of these prefixes, the current search
  6591. path is used.
  6592.  
  6593.    The distinction between `./' and `$(srcdir)/' is important when
  6594. using the `--srcdir' option to `configure'.  A rule of the form:
  6595.  
  6596.      foo.1 : foo.man sedscript
  6597.              sed -e sedscript foo.man > foo.1
  6598.  
  6599. will fail when the current directory is not the source directory,
  6600. because `foo.man' and `sedscript' are not in the current directory.
  6601.  
  6602.    When using GNU `make', relying on `VPATH' to find the source file
  6603. will work in the case where there is a single dependency file, since
  6604. the `make' automatic variable `$<' will represent the source file
  6605. wherever it is.  (Many versions of `make' set `$<' only in implicit
  6606. rules.)  A makefile target like
  6607.  
  6608.      foo.o : bar.c
  6609.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  6610.  
  6611. should instead be written as
  6612.  
  6613.      foo.o : bar.c
  6614.              $(CC) $(CFLAGS) $< -o $@
  6615.  
  6616. in order to allow `VPATH' to work correctly.  When the target has
  6617. multiple dependencies, using an explicit `$(srcdir)' is the easiest way
  6618. to make the rule work well.  For example, the target above for `foo.1'
  6619. is best written as:
  6620.  
  6621.      foo.1 : foo.man sedscript
  6622.              sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1
  6623.  
  6624. 
  6625. File: make,  Node: Utilities in Makefiles,  Next: Standard Targets,  Prev: Makefile Basics,  Up: Makefile Conventions
  6626.  
  6627. Utilities in Makefiles
  6628. ======================
  6629.  
  6630.    Write the Makefile commands (and any shell scripts, such as
  6631. `configure') to run in `sh', not in `csh'.  Don't use any special
  6632. features of `ksh' or `bash'.
  6633.  
  6634.    The `configure' script and the Makefile rules for building and
  6635. installation should not use any utilities directly except these:
  6636.  
  6637.      cat cmp cp echo egrep expr grep
  6638.      ln mkdir mv pwd rm rmdir sed test touch
  6639.  
  6640.    Stick to the generally supported options for these programs.  For
  6641. example, don't use `mkdir -p', convenient as it may be, because most
  6642. systems don't support it.
  6643.  
  6644.    The Makefile rules for building and installation can also use
  6645. compilers and related programs, but should do so via `make' variables
  6646. so that the user can substitute alternatives.  Here are some of the
  6647. programs we mean:
  6648.  
  6649.      ar bison cc flex install ld lex
  6650.      make makeinfo ranlib texi2dvi yacc
  6651.  
  6652.    When you use `ranlib', you should test whether it exists, and run it
  6653. only if it exists, so that the distribution will work on systems that
  6654. don't have `ranlib'.
  6655.  
  6656.    If you use symbolic links, you should implement a fallback for
  6657. systems that don't have symbolic links.
  6658.  
  6659.    It is ok to use other utilities in Makefile portions (or scripts)
  6660. intended only for particular systems where you know those utilities to
  6661. exist.
  6662.  
  6663. 
  6664. File: make,  Node: Standard Targets,  Next: Command Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
  6665.  
  6666. Standard Targets for Users
  6667. ==========================
  6668.  
  6669.    All GNU programs should have the following targets in their
  6670. Makefiles:
  6671.  
  6672. `all'
  6673.      Compile the entire program.  This should be the default target.
  6674.      This target need not rebuild any documentation files; Info files
  6675.      should normally be included in the distribution, and DVI files
  6676.      should be made only when explicitly asked for.
  6677.  
  6678. `install'
  6679.      Compile the program and copy the executables, libraries, and so on
  6680.      to the file names where they should reside for actual use.  If
  6681.      there is a simple test to verify that a program is properly
  6682.      installed, this target should run that test.
  6683.  
  6684.      The commands should create all the directories in which files are
  6685.      to be installed, if they don't already exist.  This includes the
  6686.      directories specified as the values of the variables `prefix' and
  6687.      `exec_prefix', as well as all subdirectories that are needed.  One
  6688.      way to do this is by means of an `installdirs' target as described
  6689.      below.
  6690.  
  6691.      Use `-' before any command for installing a man page, so that
  6692.      `make' will ignore any errors.  This is in case there are systems
  6693.      that don't have the Unix man page documentation system installed.
  6694.  
  6695.      The way to install Info files is to copy them into `$(infodir)'
  6696.      with `$(INSTALL_DATA)' (*note Command Variables::.), and then run
  6697.      the `install-info' program if it is present.  `install-info' is a
  6698.      script that edits the Info `dir' file to add or update the menu
  6699.      entry for the given Info file; it will be part of the Texinfo
  6700.      package.  Here is a sample rule to install an Info file:
  6701.  
  6702.           $(infodir)/foo.info: foo.info
  6703.           # There may be a newer info file in . than in srcdir.
  6704.                   -if test -f foo.info; then d=.; \
  6705.                    else d=$(srcdir); fi; \
  6706.                   $(INSTALL_DATA) $$d/foo.info $@; \
  6707.           # Run install-info only if it exists.
  6708.           # Use `if' instead of just prepending `-' to the
  6709.           # line so we notice real errors from install-info.
  6710.           # We use `$(SHELL) -c' because some shells do not
  6711.           # fail gracefully when there is an unknown command.
  6712.                   if $(SHELL) -c 'install-info --version' \
  6713.                      >/dev/null 2>&1; then \
  6714.                     install-info --infodir=$(infodir) $$d/foo.info; \
  6715.                   else true; fi
  6716.  
  6717. `uninstall'
  6718.      Delete all the installed files that the `install' target would
  6719.      create (but not the noninstalled files such as `make all' would
  6720.      create).
  6721.  
  6722. `clean'
  6723.      Delete all files from the current directory that are normally
  6724.      created by building the program.  Don't delete the files that
  6725.      record the configuration.  Also preserve files that could be made
  6726.      by building, but normally aren't because the distribution comes
  6727.      with them.
  6728.  
  6729.      Delete `.dvi' files here if they are not part of the distribution.
  6730.  
  6731. `distclean'
  6732.      Delete all files from the current directory that are created by
  6733.      configuring or building the program.  If you have unpacked the
  6734.      source and built the program without creating any other files,
  6735.      `make distclean' should leave only the files that were in the
  6736.      distribution.
  6737.  
  6738. `mostlyclean'
  6739.      Like `clean', but may refrain from deleting a few files that people
  6740.      normally don't want to recompile.  For example, the `mostlyclean'
  6741.      target for GCC does not delete `libgcc.a', because recompiling it
  6742.      is rarely necessary and takes a lot of time.
  6743.  
  6744. `realclean'
  6745.      Delete everything from the current directory that can be
  6746.      reconstructed with this Makefile.  This typically includes
  6747.      everything deleted by `distclean', plus more: C source files
  6748.      produced by Bison, tags tables, Info files, and so on.
  6749.  
  6750.      One exception, however: `make realclean' should not delete
  6751.      `configure' even if `configure' can be remade using a rule in the
  6752.      Makefile.  More generally, `make realclean' should not delete
  6753.      anything that needs to exist in order to run `configure' and then
  6754.      begin to build the program.
  6755.  
  6756. `TAGS'
  6757.      Update a tags table for this program.
  6758.  
  6759. `info'
  6760.      Generate any Info files needed.  The best way to write the rules
  6761.      is as follows:
  6762.  
  6763.           info: foo.info
  6764.           
  6765.           foo.info: foo.texi chap1.texi chap2.texi
  6766.                   $(MAKEINFO) $(srcdir)/foo.texi
  6767.  
  6768.      You must define the variable `MAKEINFO' in the Makefile.  It should
  6769.      run the `makeinfo' program, which is part of the Texinfo
  6770.      distribution.
  6771.  
  6772. `dvi'
  6773.      Generate DVI files for all TeXinfo documentation.  For example:
  6774.  
  6775.           dvi: foo.dvi
  6776.           
  6777.           foo.dvi: foo.texi chap1.texi chap2.texi
  6778.                   $(TEXI2DVI) $(srcdir)/foo.texi
  6779.  
  6780.      You must define the variable `TEXI2DVI' in the Makefile.  It should
  6781.      run the program `texi2dvi', which is part of the Texinfo
  6782.      distribution.  Alternatively, write just the dependencies, and
  6783.      allow GNU Make to provide the command.
  6784.  
  6785. `dist'
  6786.      Create a distribution tar file for this program.  The tar file
  6787.      should be set up so that the file names in the tar file start with
  6788.      a subdirectory name which is the name of the package it is a
  6789.      distribution for.  This name can include the version number.
  6790.  
  6791.      For example, the distribution tar file of GCC version 1.40 unpacks
  6792.      into a subdirectory named `gcc-1.40'.
  6793.  
  6794.      The easiest way to do this is to create a subdirectory
  6795.      appropriately named, use `ln' or `cp' to install the proper files
  6796.      in it, and then `tar' that subdirectory.
  6797.  
  6798.      The `dist' target should explicitly depend on all non-source files
  6799.      that are in the distribution, to make sure they are up to date in
  6800.      the distribution.  *Note Making Releases: (standards)Releases.
  6801.  
  6802. `check'
  6803.      Perform self-tests (if any).  The user must build the program
  6804.      before running the tests, but need not install the program; you
  6805.      should write the self-tests so that they work when the program is
  6806.      built but not installed.
  6807.  
  6808.    The following targets are suggested as conventional names, for
  6809. programs in which they are useful.
  6810.  
  6811. `installcheck'
  6812.      Perform installation tests (if any).  The user must build and
  6813.      install the program before running the tests.  You should not
  6814.      assume that `$(bindir)' is in the search path.
  6815.  
  6816. `installdirs'
  6817.      It's useful to add a target named `installdirs' to create the
  6818.      directories where files are installed, and their parent
  6819.      directories.  There is a script called `mkinstalldirs' which is
  6820.      convenient for this; find it in the Texinfo package.You can use a
  6821.      rule like this:
  6822.  
  6823.           # Make sure all installation directories (e.g. $(bindir))
  6824.           # actually exist by making them if necessary.
  6825.           installdirs: mkinstalldirs
  6826.                   $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
  6827.                                           $(libdir) $(infodir) \
  6828.                                           $(mandir)
  6829.  
  6830. 
  6831. File: make,  Node: Command Variables,  Next: Directory Variables,  Prev: Standard Targets,  Up: Makefile Conventions
  6832.  
  6833. Variables for Specifying Commands
  6834. =================================
  6835.  
  6836.    Makefiles should provide variables for overriding certain commands,
  6837. options, and so on.
  6838.  
  6839.    In particular, you should run most utility programs via variables.
  6840. Thus, if you use Bison, have a variable named `BISON' whose default
  6841. value is set with `BISON = bison', and refer to it with `$(BISON)'
  6842. whenever you need to use Bison.
  6843.  
  6844.    File management utilities such as `ln', `rm', `mv', and so on, need
  6845. not be referred to through variables in this way, since users don't
  6846. need to replace them with other programs.
  6847.  
  6848.    Each program-name variable should come with an options variable that
  6849. is used to supply options to the program.  Append `FLAGS' to the
  6850. program-name variable name to get the options variable name--for
  6851. example, `BISONFLAGS'.  (The name `CFLAGS' is an exception to this
  6852. rule, but we keep it because it is standard.)  Use `CPPFLAGS' in any
  6853. compilation command that runs the preprocessor, and use `LDFLAGS' in
  6854. any compilation command that does linking as well as in any direct use
  6855. of `ld'.
  6856.  
  6857.    If there are C compiler options that *must* be used for proper
  6858. compilation of certain files, do not include them in `CFLAGS'.  Users
  6859. expect to be able to specify `CFLAGS' freely themselves.  Instead,
  6860. arrange to pass the necessary options to the C compiler independently
  6861. of `CFLAGS', by writing them explicitly in the compilation commands or
  6862. by defining an implicit rule, like this:
  6863.  
  6864.      CFLAGS = -g
  6865.      ALL_CFLAGS = -I. $(CFLAGS)
  6866.      .c.o:
  6867.              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  6868.  
  6869.    Do include the `-g' option in `CFLAGS', because that is not
  6870. *required* for proper compilation.  You can consider it a default that
  6871. is only recommended.  If the package is set up so that it is compiled
  6872. with GCC by default, then you might as well include `-O' in the default
  6873. value of `CFLAGS' as well.
  6874.  
  6875.    Put `CFLAGS' last in the compilation command, after other variables
  6876. containing compiler options, so the user can use `CFLAGS' to override
  6877. the others.
  6878.  
  6879.    Every Makefile should define the variable `INSTALL', which is the
  6880. basic command for installing a file into the system.
  6881.  
  6882.    Every Makefile should also define the variables `INSTALL_PROGRAM'
  6883. and `INSTALL_DATA'.  (The default for each of these should be
  6884. `$(INSTALL)'.)  Then it should use those variables as the commands for
  6885. actual installation, for executables and nonexecutables respectively.
  6886. Use these variables as follows:
  6887.  
  6888.      $(INSTALL_PROGRAM) foo $(bindir)/foo
  6889.      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  6890.  
  6891. Always use a file name, not a directory name, as the second argument of
  6892. the installation commands.  Use a separate command for each file to be
  6893. installed.
  6894.  
  6895. 
  6896. File: make,  Node: Directory Variables,  Prev: Command Variables,  Up: Makefile Conventions
  6897.  
  6898. Variables for Installation Directories
  6899. ======================================
  6900.  
  6901.    Installation directories should always be named by variables, so it
  6902. is easy to install in a nonstandard place.  The standard names for these
  6903. variables are:
  6904.  
  6905. `prefix'
  6906.      A prefix used in constructing the default values of the variables
  6907.      listed below.  The default value of `prefix' should be `/usr/local'
  6908.      (at least for now).
  6909.  
  6910. `exec_prefix'
  6911.      A prefix used in constructing the default values of some of the
  6912.      variables listed below.  The default value of `exec_prefix' should
  6913.      be `$(prefix)'.
  6914.  
  6915.      Generally, `$(exec_prefix)' is used for directories that contain
  6916.      machine-specific files (such as executables and subroutine
  6917.      libraries), while `$(prefix)' is used directly for other
  6918.      directories.
  6919.  
  6920. `bindir'
  6921.      The directory for installing executable programs that users can
  6922.      run.  This should normally be `/usr/local/bin', but write it as
  6923.      `$(exec_prefix)/bin'.
  6924.  
  6925. `libdir'
  6926.      The directory for installing executable files to be run by the
  6927.      program rather than by users.  Object files and libraries of
  6928.      object code should also go in this directory.  The idea is that
  6929.      this directory is used for files that pertain to a specific
  6930.      machine architecture, but need not be in the path for commands.
  6931.      The value of `libdir' should normally be `/usr/local/lib', but
  6932.      write it as `$(exec_prefix)/lib'.
  6933.  
  6934. `datadir'
  6935.      The directory for installing read-only data files which the
  6936.      programs refer to while they run.  This directory is used for
  6937.      files which are independent of the type of machine being used.
  6938.      This should normally be `/usr/local/lib', but write it as
  6939.      `$(prefix)/lib'.
  6940.  
  6941. `statedir'
  6942.      The directory for installing data files which the programs modify
  6943.      while they run.  These files should be independent of the type of
  6944.      machine being used, and it should be possible to share them among
  6945.      machines at a network installation.  This should normally be
  6946.      `/usr/local/lib', but write it as `$(prefix)/lib'.
  6947.  
  6948. `includedir'
  6949.      The directory for installing header files to be included by user
  6950.      programs with the C `#include' preprocessor directive.  This
  6951.      should normally be `/usr/local/include', but write it as
  6952.      `$(prefix)/include'.
  6953.  
  6954.      Most compilers other than GCC do not look for header files in
  6955.      `/usr/local/include'.  So installing the header files this way is
  6956.      only useful with GCC.  Sometimes this is not a problem because some
  6957.      libraries are only really intended to work with GCC.  But some
  6958.      libraries are intended to work with other compilers.  They should
  6959.      install their header files in two places, one specified by
  6960.      `includedir' and one specified by `oldincludedir'.
  6961.  
  6962. `oldincludedir'
  6963.      The directory for installing `#include' header files for use with
  6964.      compilers other than GCC.  This should normally be `/usr/include'.
  6965.  
  6966.      The Makefile commands should check whether the value of
  6967.      `oldincludedir' is empty.  If it is, they should not try to use
  6968.      it; they should cancel the second installation of the header files.
  6969.  
  6970.      A package should not replace an existing header in this directory
  6971.      unless the header came from the same package.  Thus, if your Foo
  6972.      package provides a header file `foo.h', then it should install the
  6973.      header file in the `oldincludedir' directory if either (1) there
  6974.      is no `foo.h' there or (2) the `foo.h' that exists came from the
  6975.      Foo package.
  6976.  
  6977.      To tell whether `foo.h' came from the Foo package, put a magic
  6978.      string in the file--part of a comment--and grep for that string.
  6979.  
  6980. `mandir'
  6981.      The directory for installing the man pages (if any) for this
  6982.      package.  It should include the suffix for the proper section of
  6983.      the manual--usually `1' for a utility.  It will normally be
  6984.      `/usr/local/man/man1', but you should write it as
  6985.      `$(prefix)/man/man1'.
  6986.  
  6987. `man1dir'
  6988.      The directory for installing section 1 man pages.
  6989.  
  6990. `man2dir'
  6991.      The directory for installing section 2 man pages.
  6992.  
  6993. `...'
  6994.      Use these names instead of `mandir' if the package needs to
  6995.      install man pages in more than one section of the manual.
  6996.  
  6997.      *Don't make the primary documentation for any GNU software be a
  6998.      man page.  Write a manual in Texinfo instead.  Man pages are just
  6999.      for the sake of people running GNU software on Unix, which is a
  7000.      secondary application only.*
  7001.  
  7002. `manext'
  7003.      The file name extension for the installed man page.  This should
  7004.      contain a period followed by the appropriate digit; it should
  7005.      normally be `.1'.
  7006.  
  7007. `man1ext'
  7008.      The file name extension for installed section 1 man pages.
  7009.  
  7010. `man2ext'
  7011.      The file name extension for installed section 2 man pages.
  7012.  
  7013. `...'
  7014.      Use these names instead of `manext' if the package needs to
  7015.      install man pages in more than one section of the manual.
  7016.  
  7017. `infodir'
  7018.      The directory for installing the Info files for this package.  By
  7019.      default, it should be `/usr/local/info', but it should be written
  7020.      as `$(prefix)/info'.
  7021.  
  7022. `srcdir'
  7023.      The directory for the sources being compiled.  The value of this
  7024.      variable is normally inserted by the `configure' shell script.
  7025.  
  7026.    For example:
  7027.  
  7028.      # Common prefix for installation directories.
  7029.      # NOTE: This directory must exist when you start the install.
  7030.      prefix = /usr/local
  7031.      exec_prefix = $(prefix)
  7032.      # Where to put the executable for the command `gcc'.
  7033.      bindir = $(exec_prefix)/bin
  7034.      # Where to put the directories used by the compiler.
  7035.      libdir = $(exec_prefix)/lib
  7036.      # Where to put the Info files.
  7037.      infodir = $(prefix)/info
  7038.  
  7039.    If your program installs a large number of files into one of the
  7040. standard user-specified directories, it might be useful to group them
  7041. into a subdirectory particular to that program.  If you do this, you
  7042. should write the `install' rule to create these subdirectories.
  7043.  
  7044.    Do not expect the user to include the subdirectory name in the value
  7045. of any of the variables listed above.  The idea of having a uniform set
  7046. of variable names for installation directories is to enable the user to
  7047. specify the exact same values for several different GNU packages.  In
  7048. order for this to be useful, all the packages must be designed so that
  7049. they will work sensibly when the user does so.
  7050.  
  7051. 
  7052. File: make,  Node: Quick Reference,  Next: Complex Makefile,  Prev: Makefile Conventions,  Up: Top
  7053.  
  7054. Quick Reference
  7055. ***************
  7056.  
  7057.    This appendix summarizes the directives, text manipulation functions,
  7058. and special variables which GNU `make' understands.  *Note Special
  7059. Targets::, *Note Catalogue of Implicit Rules: Catalogue of Rules, and
  7060. *Note Summary of Options: Options Summary, for other summaries.
  7061.  
  7062.    Here is a summary of the directives GNU `make' recognizes:
  7063.  
  7064. `define VARIABLE'
  7065. `endef'
  7066.      Define a multi-line, recursively-expanded variable.
  7067.      *Note Sequences::.
  7068.  
  7069. `ifdef VARIABLE'
  7070. `ifndef VARIABLE'
  7071. `ifeq (A,B)'
  7072. `ifeq "A" "B"'
  7073. `ifeq 'A' 'B''
  7074. `ifneq (A,B)'
  7075. `ifneq "A" "B"'
  7076. `ifneq 'A' 'B''
  7077. `else'
  7078. `endif'
  7079.      Conditionally evaluate part of the makefile.
  7080.      *Note Conditionals::.
  7081.  
  7082. `include FILE'
  7083.      Include another makefile.
  7084.      *Note Including Other Makefiles: Include.
  7085.  
  7086. `override VARIABLE = VALUE'
  7087. `override VARIABLE := VALUE'
  7088. `override VARIABLE += VALUE'
  7089. `override define VARIABLE'
  7090. `endef'
  7091.      Define a variable, overriding any previous definition, even one
  7092.      from the command line.
  7093.      *Note The `override' Directive: Override Directive.
  7094.  
  7095. `export'
  7096.      Tell `make' to export all variables to child processes by default.
  7097.      *Note Communicating Variables to a Sub-`make': Variables/Recursion.
  7098.  
  7099. `export VARIABLE'
  7100. `export VARIABLE = VALUE'
  7101. `export VARIABLE := VALUE'
  7102. `export VARIABLE += VALUE'
  7103. `unexport VARIABLE'
  7104.      Tell `make' whether or not to export a particular variable to child
  7105.      processes.
  7106.      *Note Communicating Variables to a Sub-`make': Variables/Recursion.
  7107.  
  7108. `vpath PATTERN PATH'
  7109.      Specify a search path for files matching a `%' pattern.
  7110.      *Note The `vpath' Directive: Selective Search.
  7111.  
  7112. `vpath PATTERN'
  7113.      Remove all search paths previously specified for PATTERN.
  7114.  
  7115. `vpath'
  7116.      Remove all search paths previously specified in any `vpath'
  7117.      directive.
  7118.  
  7119.    Here is a summary of the text manipulation functions (*note
  7120. Functions::.):
  7121.  
  7122. `$(subst FROM,TO,TEXT)'
  7123.      Replace FROM with TO in TEXT.
  7124.      *Note Functions for String Substitution and Analysis: Text
  7125.      Functions.
  7126.  
  7127. `$(patsubst PATTERN,REPLACEMENT,TEXT)'
  7128.      Replace words matching PATTERN with REPLACEMENT in TEXT.
  7129.      *Note Functions for String Substitution and Analysis: Text
  7130.      Functions.
  7131.  
  7132. `$(strip STRING)'
  7133.      Remove excess whitespace characters from STRING.
  7134.      *Note Functions for String Substitution and Analysis: Text
  7135.      Functions.
  7136.  
  7137. `$(findstring FIND,TEXT)'
  7138.      Locate FIND in TEXT.
  7139.      *Note Functions for String Substitution and Analysis: Text
  7140.      Functions.
  7141.  
  7142. `$(filter PATTERN...,TEXT)'
  7143.      Select words in TEXT that match one of the PATTERN words.
  7144.      *Note Functions for String Substitution and Analysis: Text
  7145.      Functions.
  7146.  
  7147. `$(filter-out PATTERN...,TEXT)'
  7148.      Select words in TEXT that *do not* match any of the PATTERN words.
  7149.      *Note Functions for String Substitution and Analysis: Text
  7150.      Functions.
  7151.  
  7152. `$(sort LIST)'
  7153.      Sort the words in LIST lexicographically, removing duplicates.
  7154.      *Note Functions for String Substitution and Analysis: Text
  7155.      Functions.
  7156.  
  7157. `$(dir NAMES...)'
  7158.      Extract the directory part of each file name.
  7159.      *Note Functions for File Names: Filename Functions.
  7160.  
  7161. `$(notdir NAMES...)'
  7162.      Extract the non-directory part of each file name.
  7163.      *Note Functions for File Names: Filename Functions.
  7164.  
  7165. `$(suffix NAMES...)'
  7166.      Extract the suffix (the last `.' and following characters) of each
  7167.      file name.
  7168.      *Note Functions for File Names: Filename Functions.
  7169.  
  7170. `$(basename NAMES...)'
  7171.      Extract the base name (name without suffix) of each file name.
  7172.      *Note Functions for File Names: Filename Functions.
  7173.  
  7174. `$(addsuffix SUFFIX,NAMES...)'
  7175.      Append SUFFIX to each word in NAMES.
  7176.      *Note Functions for File Names: Filename Functions.
  7177.  
  7178. `$(addprefix PREFIX,NAMES...)'
  7179.      Prepend PREFIX to each word in NAMES.
  7180.      *Note Functions for File Names: Filename Functions.
  7181.  
  7182. `$(join LIST1,LIST2)'
  7183.      Join two parallel lists of words.
  7184.      *Note Functions for File Names: Filename Functions.
  7185.  
  7186. `$(word N,TEXT)'
  7187.      Extract the Nth word (one-origin) of TEXT.
  7188.      *Note Functions for File Names: Filename Functions.
  7189.  
  7190. `$(words TEXT)'
  7191.      Count the number of words in TEXT.
  7192.      *Note Functions for File Names: Filename Functions.
  7193.  
  7194. `$(firstword NAMES...)'
  7195.      Extract the first word of NAMES.
  7196.      *Note Functions for File Names: Filename Functions.
  7197.  
  7198. `$(wildcard PATTERN...)'
  7199.      Find file names matching a shell file name pattern (*not* a `%'
  7200.      pattern).
  7201.      *Note The Function `wildcard': Wildcard Function.
  7202.  
  7203. `$(shell COMMAND)'
  7204.      Execute a shell command and return its output.
  7205.      *Note The `shell' Function: Shell Function.
  7206.  
  7207. `$(origin VARIABLE)'
  7208.      Return a string describing how the `make' variable VARIABLE was
  7209.      defined.
  7210.      *Note The `origin' Function: Origin Function.
  7211.  
  7212. `$(foreach VAR,WORDS,TEXT)'
  7213.      Evaluate TEXT with VAR bound to each word in WORDS, and
  7214.      concatenate the results.
  7215.      *Note The `foreach' Function: Foreach Function.
  7216.  
  7217.    Here is a summary of the automatic variables.  *Note Automatic
  7218. Variables: Automatic, for full information.
  7219.  
  7220. `$@'
  7221.      The file name of the target.
  7222.  
  7223. `$%'
  7224.      The target member name, when the target is an archive member.
  7225.  
  7226. `$<'
  7227.      The name of the first dependency.
  7228.  
  7229. `$?'
  7230.      The names of all the dependencies that are newer than the target,
  7231.      with spaces between them.  For dependencies which are archive
  7232.      members, only the member named is used (*note Archives::.).
  7233.  
  7234. `$^'
  7235.      The names of all the dependencies, with spaces between them.  For
  7236.      dependencies which are archive members, only the member named is
  7237.      used (*note Archives::.).
  7238.  
  7239. `$*'
  7240.      The stem with which an implicit rule matches (*note How Patterns
  7241.      Match: Pattern Match.).
  7242.  
  7243. `$(@D)'
  7244. `$(@F)'
  7245.      The directory part and the file-within-directory part of `$@'.
  7246.  
  7247. `$(*D)'
  7248. `$(*F)'
  7249.      The directory part and the file-within-directory part of `$*'.
  7250.  
  7251. `$(%D)'
  7252. `$(%F)'
  7253.      The directory part and the file-within-directory part of `$%'.
  7254.  
  7255. `$(<D)'
  7256. `$(<F)'
  7257.      The directory part and the file-within-directory part of `$<'.
  7258.  
  7259. `$(^D)'
  7260. `$(^F)'
  7261.      The directory part and the file-within-directory part of `$^'.
  7262.  
  7263. `$(?D)'
  7264. `$(?F)'
  7265.      The directory part and the file-within-directory part of `$?'.
  7266.  
  7267.    These variables are used specially by GNU `make':
  7268.  
  7269. `MAKEFILES'
  7270.      Makefiles to be read on every invocation of `make'.
  7271.      *Note The Variable `MAKEFILES': MAKEFILES Variable.
  7272.  
  7273. `VPATH'
  7274.      Directory search path for files not found in the current directory.
  7275.      *Note `VPATH' Search Path for All Dependencies: General Search.
  7276.  
  7277. `SHELL'
  7278.      The name of the system default command interpreter, usually
  7279.      `/bin/sh'.  You can set `SHELL' in the makefile to change the
  7280.      shell used to run commands.  *Note Command Execution: Execution.
  7281.  
  7282. `MAKE'
  7283.      The name with which `make' was invoked.  Using this variable in
  7284.      commands has special meaning.  *Note How the `MAKE' Variable
  7285.      Works: MAKE Variable.
  7286.  
  7287. `MAKELEVEL'
  7288.      The number of levels of recursion (sub-`make's).
  7289.      *Note Variables/Recursion::.
  7290.  
  7291. `MAKEFLAGS'
  7292. `MFLAGS'
  7293.      The flags given to `make'.  You can set this in the environment or
  7294.      a makefile to set flags.
  7295.      *Note Communicating Options to a Sub-`make': Options/Recursion.
  7296.  
  7297. `SUFFIXES'
  7298.      The default list of suffixes before `make' reads any makefiles.
  7299.  
  7300. 
  7301. File: make,  Node: Complex Makefile,  Next: Concept Index,  Prev: Quick Reference,  Up: Top
  7302.  
  7303. Complex Makefile Example
  7304. ************************
  7305.  
  7306.    Here is the makefile for the GNU `tar' program.  This is a
  7307. moderately complex makefile.
  7308.  
  7309.    Because it is the first target, the default goal is `all'.  An
  7310. interesting feature of this makefile is that `testpad.h' is a source
  7311. file automatically created by the `testpad' program, itself compiled
  7312. from `testpad.c'.
  7313.  
  7314.    If you type `make' or `make all', then `make' creates the `tar'
  7315. executable, the `rmt' daemon that provides remote tape access, and the
  7316. `tar.info' Info file.
  7317.  
  7318.    If you type `make install', then `make' not only creates `tar',
  7319. `rmt', and `tar.info', but also installs them.
  7320.  
  7321.    If you type `make clean', then `make' removes the `.o' files, and
  7322. the `tar', `rmt', `testpad', `testpad.h', and `core' files.
  7323.  
  7324.    If you type `make distclean', then `make' not only removes the same
  7325. files as does `make clean' but also the `TAGS', `Makefile', and
  7326. `config.status' files.  (Although it is not evident, this makefile (and
  7327. `config.status') is generated by the user with the `configure' program,
  7328. which is provided in the `tar' distribution, but is not shown here.)
  7329.  
  7330.    If you type `make realclean', then `make' removes the same files as
  7331. does `make distclean' and also removes the Info files generated from
  7332. `tar.texinfo'.
  7333.  
  7334.    In addition, there are targets `shar' and `dist' that create
  7335. distribution kits.
  7336.  
  7337.      # Generated automatically from Makefile.in by configure.
  7338.      # Un*x Makefile for GNU tar program.
  7339.      # Copyright (C) 1991 Free Software Foundation, Inc.
  7340.      
  7341.      # This program is free software; you can redistribute
  7342.      # it and/or modify it under the terms of the GNU
  7343.      # General Public License ...
  7344.      ...
  7345.      ...
  7346.      
  7347.      SHELL = /bin/sh
  7348.      
  7349.      #### Start of system configuration section. ####
  7350.      
  7351.      srcdir = .
  7352.      
  7353.      # If you use gcc, you should either run the
  7354.      # fixincludes script that comes with it or else use
  7355.      # gcc with the -traditional option.  Otherwise ioctl
  7356.      # calls will be compiled incorrectly on some systems.
  7357.      CC = gcc -O
  7358.      YACC = bison -y
  7359.      INSTALL = /usr/local/bin/install -c
  7360.      INSTALLDATA = /usr/local/bin/install -c -m 644
  7361.      
  7362.      # Things you might add to DEFS:
  7363.      # -DSTDC_HEADERS        If you have ANSI C headers and
  7364.      #                       libraries.
  7365.      # -DPOSIX               If you have POSIX.1 headers and
  7366.      #                       libraries.
  7367.      # -DBSD42               If you have sys/dir.h (unless
  7368.      #                       you use -DPOSIX), sys/file.h,
  7369.      #                       and st_blocks in `struct stat'.
  7370.      # -DUSG                 If you have System V/ANSI C
  7371.      #                       string and memory functions
  7372.      #                       and headers, sys/sysmacros.h,
  7373.      #                       fcntl.h, getcwd, no valloc,
  7374.      #                       and ndir.h (unless
  7375.      #                       you use -DDIRENT).
  7376.      # -DNO_MEMORY_H         If USG or STDC_HEADERS but do not
  7377.      #                       include memory.h.
  7378.      # -DDIRENT              If USG and you have dirent.h
  7379.      #                       instead of ndir.h.
  7380.      # -DSIGTYPE=int         If your signal handlers
  7381.      #                       return int, not void.
  7382.      # -DNO_MTIO             If you lack sys/mtio.h
  7383.      #                       (magtape ioctls).
  7384.      # -DNO_REMOTE           If you do not have a remote shell
  7385.      #                       or rexec.
  7386.      # -DUSE_REXEC           To use rexec for remote tape
  7387.      #                       operations instead of
  7388.      #                       forking rsh or remsh.
  7389.      # -DVPRINTF_MISSING     If you lack vprintf function
  7390.      #                       (but have _doprnt).
  7391.      # -DDOPRNT_MISSING      If you lack _doprnt function.
  7392.      #                       Also need to define
  7393.      #                       -DVPRINTF_MISSING.
  7394.      # -DFTIME_MISSING       If you lack ftime system call.
  7395.      # -DSTRSTR_MISSING      If you lack strstr function.
  7396.      # -DVALLOC_MISSING      If you lack valloc function.
  7397.      # -DMKDIR_MISSING       If you lack mkdir and
  7398.      #                       rmdir system calls.
  7399.      # -DRENAME_MISSING      If you lack rename system call.
  7400.      # -DFTRUNCATE_MISSING   If you lack ftruncate
  7401.      #                       system call.
  7402.      # -DV7                  On Version 7 Unix (not
  7403.      #                       tested in a long time).
  7404.      # -DEMUL_OPEN3          If you lack a 3-argument version
  7405.      #                       of open, and want to emulate it
  7406.      #                       with system calls you do have.
  7407.      # -DNO_OPEN3            If you lack the 3-argument open
  7408.      #                       and want to disable the tar -k
  7409.      #                       option instead of emulating open.
  7410.      # -DXENIX               If you have sys/inode.h
  7411.      #                       and need it 94 to be included.
  7412.      
  7413.      DEFS =  -DSIGTYPE=int -DDIRENT -DSTRSTR_MISSING \
  7414.              -DVPRINTF_MISSING -DBSD42
  7415.      # Set this to rtapelib.o unless you defined NO_REMOTE,
  7416.      # in which case make it empty.
  7417.      RTAPELIB = rtapelib.o
  7418.      LIBS =
  7419.      DEF_AR_FILE = /dev/rmt8
  7420.      DEFBLOCKING = 20
  7421.      
  7422.      CDEBUG = -g
  7423.      CFLAGS = $(CDEBUG) -I. -I$(srcdir) $(DEFS) \
  7424.              -DDEF_AR_FILE=\"$(DEF_AR_FILE)\" \
  7425.              -DDEFBLOCKING=$(DEFBLOCKING)
  7426.      LDFLAGS = -g
  7427.      
  7428.      prefix = /usr/local
  7429.      # Prefix for each installed program,
  7430.      # normally empty or `g'.
  7431.      binprefix =
  7432.      
  7433.      # The directory to install tar in.
  7434.      bindir = $(prefix)/bin
  7435.      
  7436.      # The directory to install the info files in.
  7437.      infodir = $(prefix)/info
  7438.      
  7439.      #### End of system configuration section. ####
  7440.      
  7441.      SRC1 =  tar.c create.c extract.c buffer.c \
  7442.              getoldopt.c update.c gnu.c mangle.c
  7443.      SRC2 =  version.c list.c names.c diffarch.c \
  7444.              port.c wildmat.c getopt.c
  7445.      SRC3 =  getopt1.c regex.c getdate.y
  7446.      SRCS =  $(SRC1) $(SRC2) $(SRC3)
  7447.      OBJ1 =  tar.o create.o extract.o buffer.o \
  7448.              getoldopt.o update.o gnu.o mangle.o
  7449.      OBJ2 =  version.o list.o names.o diffarch.o \
  7450.              port.o wildmat.o getopt.o
  7451.      OBJ3 =  getopt1.o regex.o getdate.o $(RTAPELIB)
  7452.      OBJS =  $(OBJ1) $(OBJ2) $(OBJ3)
  7453.      AUX =   README COPYING ChangeLog Makefile.in  \
  7454.              makefile.pc configure configure.in \
  7455.              tar.texinfo tar.info* texinfo.tex \
  7456.              tar.h port.h open3.h getopt.h regex.h \
  7457.              rmt.h rmt.c rtapelib.c alloca.c \
  7458.              msd_dir.h msd_dir.c tcexparg.c \
  7459.              level-0 level-1 backup-specs testpad.c
  7460.      
  7461.      all:    tar rmt tar.info
  7462.      
  7463.      tar:    $(OBJS)
  7464.              $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  7465.      
  7466.      rmt:    rmt.c
  7467.              $(CC) $(CFLAGS) $(LDFLAGS) -o $@ rmt.c
  7468.      
  7469.      tar.info: tar.texinfo
  7470.              makeinfo tar.texinfo
  7471.      
  7472.      install: all
  7473.              $(INSTALL) tar $(bindir)/$(binprefix)tar
  7474.              -test ! -f rmt || $(INSTALL) rmt /etc/rmt
  7475.              $(INSTALLDATA) $(srcdir)/tar.info* $(infodir)
  7476.      
  7477.      $(OBJS): tar.h port.h testpad.h
  7478.      regex.o buffer.o tar.o: regex.h
  7479.      # getdate.y has 8 shift/reduce conflicts.
  7480.      
  7481.      testpad.h: testpad
  7482.              ./testpad
  7483.      
  7484.      testpad: testpad.o
  7485.              $(CC) -o $@ testpad.o
  7486.      
  7487.      TAGS:   $(SRCS)
  7488.              etags $(SRCS)
  7489.      
  7490.      clean:
  7491.              rm -f *.o tar rmt testpad testpad.h core
  7492.      
  7493.      distclean: clean
  7494.              rm -f TAGS Makefile config.status
  7495.      
  7496.      realclean: distclean
  7497.              rm -f tar.info*
  7498.      
  7499.      shar: $(SRCS) $(AUX)
  7500.              shar $(SRCS) $(AUX) | compress \
  7501.                > tar-`sed -e '/version_string/!d' \
  7502.                           -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
  7503.                           -e q
  7504.                           version.c`.shar.Z
  7505.      
  7506.      dist: $(SRCS) $(AUX)
  7507.              echo tar-`sed \
  7508.                   -e '/version_string/!d' \
  7509.                   -e 's/[^0-9.]*\([0-9.]*\).*/\1/' \
  7510.                   -e q
  7511.                   version.c` > .fname
  7512.              -rm -rf `cat .fname`
  7513.              mkdir `cat .fname`
  7514.              ln $(SRCS) $(AUX) `cat .fname`
  7515.              -rm -rf `cat .fname` .fname
  7516.              tar chZf `cat .fname`.tar.Z `cat .fname`
  7517.      
  7518.      tar.zoo: $(SRCS) $(AUX)
  7519.              -rm -rf tmp.dir
  7520.              -mkdir tmp.dir
  7521.              -rm tar.zoo
  7522.              for X in $(SRCS) $(AUX) ; do \
  7523.                  echo $$X ; \
  7524.                  sed 's/$$/^M/' $$X \
  7525.                  > tmp.dir/$$X ; done
  7526.              cd tmp.dir ; zoo aM ../tar.zoo *
  7527.              -rm -rf tmp.dir
  7528.  
  7529. 
  7530. File: make,  Node: Concept Index,  Next: Name Index,  Prev: Complex Makefile,  Up: Top
  7531.  
  7532. Index of Concepts
  7533. *****************
  7534.  
  7535. * Menu:
  7536.  
  7537. * +, and define:                        Sequences.
  7538. * +=:                                   Appending.
  7539. * ,v (RCS file extension):              Catalogue of Rules.
  7540. * -, and define:                        Sequences.
  7541. * .C:                                   Catalogue of Rules.
  7542. * .c:                                   Catalogue of Rules.
  7543. * .cc:                                  Catalogue of Rules.
  7544. * .ch:                                  Catalogue of Rules.
  7545. * .def:                                 Catalogue of Rules.
  7546. * .dvi:                                 Catalogue of Rules.
  7547. * .F:                                   Catalogue of Rules.
  7548. * .f:                                   Catalogue of Rules.
  7549. * .info:                                Catalogue of Rules.
  7550. * .l:                                   Catalogue of Rules.
  7551. * .ln:                                  Catalogue of Rules.
  7552. * .mod:                                 Catalogue of Rules.
  7553. * .o:                                   Catalogue of Rules.
  7554. * .o:                                   Catalogue of Rules.
  7555. * .p:                                   Catalogue of Rules.
  7556. * .r:                                   Catalogue of Rules.
  7557. * .s:                                   Catalogue of Rules.
  7558. * .S:                                   Catalogue of Rules.
  7559. * .sh:                                  Catalogue of Rules.
  7560. * .sym:                                 Catalogue of Rules.
  7561. * .tex:                                 Catalogue of Rules.
  7562. * .texi:                                Catalogue of Rules.
  7563. * .texinfo:                             Catalogue of Rules.
  7564. * .txinfo:                              Catalogue of Rules.
  7565. * .w:                                   Catalogue of Rules.
  7566. * .web:                                 Catalogue of Rules.
  7567. * .y:                                   Catalogue of Rules.
  7568. * :=:                                   Setting.
  7569. * :=:                                   Flavors.
  7570. * =:                                    Flavors.
  7571. * =:                                    Setting.
  7572. * @, and define:                        Sequences.
  7573. * #include:                             Automatic Dependencies.
  7574. * # (comments), in commands:            Commands.
  7575. * # (comments), in makefile:            Makefile Contents.
  7576. * $, in function call:                  Syntax of Functions.
  7577. * $, in rules:                          Rule Syntax.
  7578. * $, in variable name:                  Computed Names.
  7579. * $, in variable reference:             Reference.
  7580. * %, in pattern rules:                  Pattern Intro.
  7581. * %, quoting in patsubst:               Text Functions.
  7582. * %, quoting in vpath:                  Selective Search.
  7583. * %, quoting in static pattern:         Static Usage.
  7584. * %, quoting with \ (backslash):        Text Functions.
  7585. * %, quoting with \ (backslash):        Selective Search.
  7586. * %, quoting with \ (backslash):        Static Usage.
  7587. * * (wildcard character):               Wildcards.
  7588. * -assume-new:                          Options Summary.
  7589. * -assume-new:                          Instead of Execution.
  7590. * -assume-new, and recursion:           Options/Recursion.
  7591. * -assume-old:                          Avoiding Compilation.
  7592. * -assume-old:                          Options Summary.
  7593. * -assume-old, and recursion:           Options/Recursion.
  7594. * -debug:                               Options Summary.
  7595. * -directory:                           Options Summary.
  7596. * -directory:                           Recursion.
  7597. * -directory, and -print-directory:     -w Option.
  7598. * -directory, and recursion:            Options/Recursion.
  7599. * -dry-run:                             Options Summary.
  7600. * -dry-run:                             Echoing.
  7601. * -dry-run:                             Instead of Execution.
  7602. * -environment-overrides:               Options Summary.
  7603. * -file:                                Makefile Names.
  7604. * -file:                                Options Summary.
  7605. * -file:                                Makefile Arguments.
  7606. * -file, and recursion:                 Options/Recursion.
  7607. * -help:                                Options Summary.
  7608. * -ignore-errors:                       Errors.
  7609. * -ignore-errors:                       Options Summary.
  7610. * -include-dir:                         Options Summary.
  7611. * -include-dir:                         Include.
  7612. * -include-dir, and recursion:          Options/Recursion.
  7613. * -jobs:                                Parallel.
  7614. * -jobs:                                Options Summary.
  7615. * -jobs, and recursion:                 Options/Recursion.
  7616. * -just-print:                          Echoing.
  7617. * -just-print:                          Options Summary.
  7618. * -just-print:                          Instead of Execution.
  7619. * -keep-going:                          Errors.
  7620. * -keep-going:                          Options Summary.
  7621. * -keep-going:                          Testing.
  7622. * -load-average:                        Options Summary.
  7623. * -load-average:                        Parallel.
  7624. * -makefile:                            Makefile Names.
  7625. * -makefile:                            Makefile Arguments.
  7626. * -makefile:                            Options Summary.
  7627. * -max-load:                            Parallel.
  7628. * -max-load:                            Options Summary.
  7629. * -new-file:                            Options Summary.
  7630. * -new-file:                            Instead of Execution.
  7631. * -new-file, and recursion:             Options/Recursion.
  7632. * -no-builtin-rules:                    Options Summary.
  7633. * -no-keep-going:                       Options Summary.
  7634. * -no-print-directory:                  Options Summary.
  7635. * -no-print-directory:                  -w Option.
  7636. * -old-file:                            Avoiding Compilation.
  7637. * -old-file:                            Options Summary.
  7638. * -old-file, and recursion:             Options/Recursion.
  7639. * -print-data-base:                     Options Summary.
  7640. * -print-directory:                     Options Summary.
  7641. * -print-directory, and -directory:     -w Option.
  7642. * -print-directory, and recursion:      -w Option.
  7643. * -print-directory, disabling:          -w Option.
  7644. * -question:                            Instead of Execution.
  7645. * -question:                            Options Summary.
  7646. * -quiet:                               Options Summary.
  7647. * -quiet:                               Echoing.
  7648. * -recon:                               Echoing.
  7649. * -recon:                               Options Summary.
  7650. * -recon:                               Instead of Execution.
  7651. * -silent:                              Echoing.
  7652. * -silent:                              Options Summary.
  7653. * -stop:                                Options Summary.
  7654. * -touch:                               Instead of Execution.
  7655. * -touch:                               Options Summary.
  7656. * -touch, and recursion:                MAKE Variable.
  7657. * -version:                             Options Summary.
  7658. * -warn-undefined-variables:            Options Summary.
  7659. * -what-if:                             Instead of Execution.
  7660. * -what-if:                             Options Summary.
  7661. * -b:                                   Options Summary.
  7662. * -C:                                   Options Summary.
  7663. * -C:                                   Recursion.
  7664. * -C, and -w:                           -w Option.
  7665. * -C, and recursion:                    Options/Recursion.
  7666. * -d:                                   Options Summary.
  7667. * -e:                                   Options Summary.
  7668. * -e (shell flag):                      Automatic Dependencies.
  7669. * -f:                                   Makefile Arguments.
  7670. * -f:                                   Options Summary.
  7671. * -f:                                   Makefile Names.
  7672. * -f, and recursion:                    Options/Recursion.
  7673. * -h:                                   Options Summary.
  7674. * -i:                                   Options Summary.
  7675. * -I:                                   Include.
  7676. * -I:                                   Options Summary.
  7677. * -i:                                   Errors.
  7678. * -I, and recursion:                    Options/Recursion.
  7679. * -j:                                   Parallel.
  7680. * -j:                                   Options Summary.
  7681. * -j, and recursion:                    Options/Recursion.
  7682. * -k:                                   Testing.
  7683. * -k:                                   Errors.
  7684. * -k:                                   Options Summary.
  7685. * -l:                                   Options Summary.
  7686. * -l (library search):                  Libraries/Search.
  7687. * -l (load average):                    Parallel.
  7688. * -m:                                   Options Summary.
  7689. * -M (to compiler):                     Automatic Dependencies.
  7690. * -n:                                   Echoing.
  7691. * -n:                                   Options Summary.
  7692. * -n:                                   Instead of Execution.
  7693. * -o:                                   Avoiding Compilation.
  7694. * -o:                                   Options Summary.
  7695. * -o, and recursion:                    Options/Recursion.
  7696. * -p:                                   Options Summary.
  7697. * -q:                                   Instead of Execution.
  7698. * -q:                                   Options Summary.
  7699. * -r:                                   Options Summary.
  7700. * -S:                                   Options Summary.
  7701. * -s:                                   Echoing.
  7702. * -s:                                   Options Summary.
  7703. * -t:                                   Instead of Execution.
  7704. * -t:                                   Options Summary.
  7705. * -t, and recursion:                    MAKE Variable.
  7706. * -v:                                   Options Summary.
  7707. * -w:                                   Options Summary.
  7708. * -W:                                   Instead of Execution.
  7709. * -W:                                   Options Summary.
  7710. * -w, and -C:                           -w Option.
  7711. * -w, and recursion:                    -w Option.
  7712. * -W, and recursion:                    Options/Recursion.
  7713. * -w, disabling:                        -w Option.
  7714. * - (in commands):                      Errors.
  7715. * .a (archives):                        Archive Suffix Rules.
  7716. * .DEFAULT, used to override:           Overriding Makefiles.
  7717. * .d:                                   Automatic Dependencies.
  7718. * .PRECIOUS intermediate files:         Chained Rules.
  7719. * :: rules (double-colon):              Double-Colon.
  7720. * ? (wildcard character):               Wildcards.
  7721. * @ (in commands):                      Echoing.
  7722. * [...] (wildcard characters):          Wildcards.
  7723. * \ (backslash), for continuation lines: Simple Makefile.
  7724. * \ (backslash), in commands:           Execution.
  7725. * \ (backslash), to quote %:            Selective Search.
  7726. * \ (backslash), to quote %:            Static Usage.
  7727. * \ (backslash), to quote %:            Text Functions.
  7728. * __.SYMDEF:                            Archive Symbols.
  7729. * all (standard target):                Goals.
  7730. * cd (shell command):                   Execution.
  7731. * cd (shell command):                   MAKE Variable.
  7732. * check (standard target):              Goals.
  7733. * clean (standard target):              Goals.
  7734. * clean target:                         Cleanup.
  7735. * clean target:                         Simple Makefile.
  7736. * clobber (standard target):            Goals.
  7737. * distclean (standard target):          Goals.
  7738. * dist (standard target):               Goals.
  7739. * FORCE:                                Force Targets.
  7740. * install (standard target):            Goals.
  7741. * lint, rule to run:                    Catalogue of Rules.
  7742. * lpr (shell command):                  Wildcard Examples.
  7743. * lpr (shell command):                  Empty Targets.
  7744. * make depend:                          Automatic Dependencies.
  7745. * mostlyclean (standard target):        Goals.
  7746. * OBJECTS:                              Variables Simplify.
  7747. * objects:                              Variables Simplify.
  7748. * OBJS:                                 Variables Simplify.
  7749. * objs:                                 Variables Simplify.
  7750. * OBJ:                                  Variables Simplify.
  7751. * obj:                                  Variables Simplify.
  7752. * print (standard target):              Goals.
  7753. * print target:                         Empty Targets.
  7754. * print target:                         Wildcard Examples.
  7755. * README:                               Makefile Names.
  7756. * realclean (standard target):          Goals.
  7757. * rm (shell command):                   Simple Makefile.
  7758. * rm (shell command):                   Phony Targets.
  7759. * rm (shell command):                   Wildcard Examples.
  7760. * rm (shell command):                   Errors.
  7761. * sed (shell command):                  Automatic Dependencies.
  7762. * shar (standard target):               Goals.
  7763. * TAGS (standard target):               Goals.
  7764. * tar (standard target):                Goals.
  7765. * test (standard target):               Goals.
  7766. * touch (shell command):                Wildcard Examples.
  7767. * touch (shell command):                Empty Targets.
  7768. * VPATH, and implicit rules:            Implicit/Search.
  7769. * VPATH, and link libraries:            Libraries/Search.
  7770. * yacc:                                 Sequences.
  7771. * ~ (tilde):                            Wildcards.
  7772. * TeX, rule to run:                     Catalogue of Rules.
  7773. * appending to variables:               Appending.
  7774. * ar:                                   Implicit Variables.
  7775. * archive:                              Archives.
  7776. * archive member targets:               Archive Members.
  7777. * archive symbol directory updating:    Archive Symbols.
  7778. * archive, suffix rule for:             Archive Suffix Rules.
  7779. * arguments of functions:               Syntax of Functions.
  7780. * as:                                   Implicit Variables.
  7781. * as:                                   Catalogue of Rules.
  7782. * assembly, rule to compile:            Catalogue of Rules.
  7783. * automatic generation of dependencies: Include.
  7784. * automatic generation of dependencies: Automatic Dependencies.
  7785. * automatic variables:                  Automatic.
  7786. * backquotes:                           Shell Function.
  7787. * backslash (\), for continuation lines: Simple Makefile.
  7788. * backslash (\), in commands:           Execution.
  7789. * backslash (\), to quote %:            Static Usage.
  7790. * backslash (\), to quote %:            Selective Search.
  7791. * backslash (\), to quote %:            Text Functions.
  7792. * basename:                             Filename Functions.
  7793. * broken pipe:                          Parallel.
  7794. * bugs, reporting:                      Bugs.
  7795. * built-in special targets:             Special Targets.
  7796. * C++, rule to compile:                 Catalogue of Rules.
  7797. * C, rule to compile:                   Catalogue of Rules.
  7798. * cc:                                   Implicit Variables.
  7799. * cc:                                   Catalogue of Rules.
  7800. * chains of rules:                      Chained Rules.
  7801. * cleaning up:                          Cleanup.
  7802. * co:                                   Implicit Variables.
  7803. * co:                                   Catalogue of Rules.
  7804. * combining rules by dependency:        Combine By Dependency.
  7805. * command line variables:               Overriding.
  7806. * commands:                             Rule Syntax.
  7807. * commands, backslash (\) in:           Execution.
  7808. * commands, comments in:                Commands.
  7809. * commands, echoing:                    Echoing.
  7810. * commands, empty:                      Empty Commands.
  7811. * commands, errors in:                  Errors.
  7812. * commands, execution:                  Execution.
  7813. * commands, execution in parallel:      Parallel.
  7814. * commands, expansion:                  Shell Function.
  7815. * commands, how to write:               Commands.
  7816. * commands, instead of executing:       Instead of Execution.
  7817. * commands, introduction to:            Rule Introduction.
  7818. * commands, quoting newlines in:        Execution.
  7819. * commands, sequences of:               Sequences.
  7820. * comments, in commands:                Commands.
  7821. * comments, in makefile:                Makefile Contents.
  7822. * compatibility:                        Features.
  7823. * compatibility in exporting:           Variables/Recursion.
  7824. * compilation, testing:                 Testing.
  7825. * computed variable name:               Computed Names.
  7826. * conditionals:                         Conditionals.
  7827. * continuation lines:                   Simple Makefile.
  7828. * conventions for makefiles:            Makefile Conventions.
  7829. * ctangle:                              Implicit Variables.
  7830. * ctangle:                              Catalogue of Rules.
  7831. * cweave:                               Implicit Variables.
  7832. * cweave:                               Catalogue of Rules.
  7833. * deducing commands (implicit rules):   make Deduces.
  7834. * default goal:                         Rules.
  7835. * default goal:                         How Make Works.
  7836. * default makefile name:                Makefile Names.
  7837. * default rules, last-resort:           Last Resort.
  7838. * defining variables verbatim:          Defining.
  7839. * deletion of target files:             Interrupts.
  7840. * dependencies:                         Rule Syntax.
  7841. * dependencies, automatic generation:   Automatic Dependencies.
  7842. * dependencies, automatic generation:   Include.
  7843. * dependencies, introduction to:        Rule Introduction.
  7844. * dependencies, list of all:            Automatic.
  7845. * dependencies, list of changed:        Automatic.
  7846. * dependencies, varying (static pattern): Static Pattern.
  7847. * dependency:                           Rules.
  7848. * dependency pattern, implicit:         Pattern Intro.
  7849. * dependency pattern, static (not implicit): Static Usage.
  7850. * directive:                            Makefile Contents.
  7851. * directories, printing them:           -w Option.
  7852. * directories, updating archive symbol: Archive Symbols.
  7853. * directory part:                       Filename Functions.
  7854. * directory search (VPATH):             Directory Search.
  7855. * directory search (VPATH), and implicit rules: Implicit/Search.
  7856. * directory search (VPATH), and link libraries: Libraries/Search.
  7857. * directory search (VPATH), and shell commands: Commands/Search.
  7858. * dollar sign ($), in function call:    Syntax of Functions.
  7859. * dollar sign ($), in rules:            Rule Syntax.
  7860. * dollar sign ($), in variable name:    Computed Names.
  7861. * dollar sign ($), in variable reference: Reference.
  7862. * double-colon rules:                   Double-Colon.
  7863. * duplicate words, removing:            Text Functions.
  7864. * echoing of commands:                  Echoing.
  7865. * editor:                               Introduction.
  7866. * Emacs (M-x compile):                  Errors.
  7867. * empty commands:                       Empty Commands.
  7868. * empty targets:                        Empty Targets.
  7869. * environment:                          Environment.
  7870. * environment, SHELL in:                Execution.
  7871. * environment, and recursion:           Variables/Recursion.
  7872. * errors (in commands):                 Errors.
  7873. * errors with wildcards:                Wildcard Pitfall.
  7874. * execution, in parallel:               Parallel.
  7875. * execution, instead of:                Instead of Execution.
  7876. * execution, of commands:               Execution.
  7877. * exit status (errors):                 Errors.
  7878. * explicit rule, definition of:         Makefile Contents.
  7879. * exporting variables:                  Variables/Recursion.
  7880. * f77:                                  Implicit Variables.
  7881. * f77:                                  Catalogue of Rules.
  7882. * features of GNU make:                 Features.
  7883. * features, missing:                    Missing.
  7884. * file name functions:                  Filename Functions.
  7885. * file name of makefile:                Makefile Names.
  7886. * file name of makefile, how to specify: Makefile Names.
  7887. * file name prefix, adding:             Filename Functions.
  7888. * file name suffix:                     Filename Functions.
  7889. * file name suffix, adding:             Filename Functions.
  7890. * file name with wildcards:             Wildcards.
  7891. * file name, basename of:               Filename Functions.
  7892. * file name, directory part:            Filename Functions.
  7893. * file name, nondirectory part:         Filename Functions.
  7894. * files, assuming new:                  Instead of Execution.
  7895. * files, assuming old:                  Avoiding Compilation.
  7896. * files, avoiding recompilation of:     Avoiding Compilation.
  7897. * files, intermediate:                  Chained Rules.
  7898. * filtering out words:                  Text Functions.
  7899. * filtering words:                      Text Functions.
  7900. * finding strings:                      Text Functions.
  7901. * flags:                                Options Summary.
  7902. * flags for compilers:                  Implicit Variables.
  7903. * flavors of variables:                 Flavors.
  7904. * force targets:                        Force Targets.
  7905. * Fortran, rule to compile:             Catalogue of Rules.
  7906. * functions:                            Functions.
  7907. * functions, for file names:            Filename Functions.
  7908. * functions, for text:                  Text Functions.
  7909. * functions, syntax of:                 Syntax of Functions.
  7910. * g++:                                  Implicit Variables.
  7911. * g++:                                  Catalogue of Rules.
  7912. * gcc:                                  Catalogue of Rules.
  7913. * generating dependencies automatically: Automatic Dependencies.
  7914. * generating dependencies automatically: Include.
  7915. * get:                                  Implicit Variables.
  7916. * get:                                  Catalogue of Rules.
  7917. * globbing (wildcards):                 Wildcards.
  7918. * goal:                                 How Make Works.
  7919. * goal, default:                        Rules.
  7920. * goal, default:                        How Make Works.
  7921. * goal, how to specify:                 Goals.
  7922. * home directory:                       Wildcards.
  7923. * IEEE Standard 1003.2:                 Overview.
  7924. * implicit rule:                        Implicit Rules.
  7925. * implicit rule, and VPATH:             Implicit/Search.
  7926. * implicit rule, and directory search:  Implicit/Search.
  7927. * implicit rule, definition of:         Makefile Contents.
  7928. * implicit rule, how to use:            Using Implicit.
  7929. * implicit rule, introduction to:       make Deduces.
  7930. * implicit rule, predefined:            Catalogue of Rules.
  7931. * implicit rule, search algorithm:      Search Algorithm.
  7932. * including (MAKEFILES variable):       MAKEFILES Variable.
  7933. * including other makefiles:            Include.
  7934. * incompatibilities:                    Missing.
  7935. * Info, rule to format:                 Catalogue of Rules.
  7936. * intermediate files:                   Chained Rules.
  7937. * intermediate files, preserving:       Chained Rules.
  7938. * interrupt:                            Interrupts.
  7939. * job slots:                            Parallel.
  7940. * job slots, and recursion:             Options/Recursion.
  7941. * jobs, limiting based on load:         Parallel.
  7942. * joining lists of words:               Filename Functions.
  7943. * killing (interruption):               Interrupts.
  7944. * last-resort default rules:            Last Resort.
  7945. * ld:                                   Catalogue of Rules.
  7946. * lex:                                  Implicit Variables.
  7947. * lex:                                  Catalogue of Rules.
  7948. * Lex, rule to run:                     Catalogue of Rules.
  7949. * libraries for linking, directory search: Libraries/Search.
  7950. * library archive, suffix rule for:     Archive Suffix Rules.
  7951. * limiting jobs based on load:          Parallel.
  7952. * link libraries, and directory search: Libraries/Search.
  7953. * linking, predefined rule for:         Catalogue of Rules.
  7954. * lint:                                 Catalogue of Rules.
  7955. * list of all dependencies:             Automatic.
  7956. * list of changed dependencies:         Automatic.
  7957. * load average:                         Parallel.
  7958. * loops in variable expansion:          Flavors.
  7959. * m2c:                                  Catalogue of Rules.
  7960. * macro:                                Using Variables.
  7961. * makefile:                             Introduction.
  7962. * makefile name:                        Makefile Names.
  7963. * makefile name, how to specify:        Makefile Names.
  7964. * makefile rule parts:                  Rule Introduction.
  7965. * makefile, and MAKEFILES variable:     MAKEFILES Variable.
  7966. * makefile, conventions for:            Makefile Conventions.
  7967. * makefile, how make processes:         How Make Works.
  7968. * makefile, how to write:               Makefiles.
  7969. * makefile, including:                  Include.
  7970. * makefile, overriding:                 Overriding Makefiles.
  7971. * makefile, remaking of:                Remaking Makefiles.
  7972. * makefile, simple:                     Simple Makefile.
  7973. * makeinfo:                             Catalogue of Rules.
  7974. * makeinfo:                             Implicit Variables.
  7975. * match-anything rule:                  Match-Anything Rules.
  7976. * missing features:                     Missing.
  7977. * mistakes with wildcards:              Wildcard Pitfall.
  7978. * modified variable reference:          Substitution Refs.
  7979. * Modula-2, rule to compile:            Catalogue of Rules.
  7980. * multiple rules for one target:        Multiple Rules.
  7981. * multiple rules for one target (::):   Double-Colon.
  7982. * multiple targets:                     Multiple Targets.
  7983. * multiple targets, in pattern rule:    Pattern Intro.
  7984. * name of makefile:                     Makefile Names.
  7985. * name of makefile, how to specify:     Makefile Names.
  7986. * nested variable reference:            Computed Names.
  7987. * newline, quoting, in commands:        Execution.
  7988. * newline, quoting, in makefile:        Simple Makefile.
  7989. * nondirectory part:                    Filename Functions.
  7990. * old-fashioned suffix rules:           Suffix Rules.
  7991. * options:                              Options Summary.
  7992. * options, and recursion:               Options/Recursion.
  7993. * options, setting from environment:    Options/Recursion.
  7994. * options, setting in makefiles:        Options/Recursion.
  7995. * order of pattern rules:               Pattern Intro.
  7996. * origin of variable:                   Origin Function.
  7997. * overriding makefiles:                 Overriding Makefiles.
  7998. * overriding variables with arguments:  Overriding.
  7999. * overriding with override:             Override Directive.
  8000. * parallel execution:                   Parallel.
  8001. * parts of makefile rule:               Rule Introduction.
  8002. * Pascal, rule to compile:              Catalogue of Rules.
  8003. * pattern rule:                         Pattern Intro.
  8004. * pattern rules, order of:              Pattern Intro.
  8005. * pattern rules, static (not implicit): Static Pattern.
  8006. * pattern rules, static, syntax of:     Static Usage.
  8007. * pc:                                   Implicit Variables.
  8008. * pc:                                   Catalogue of Rules.
  8009. * phony targets:                        Phony Targets.
  8010. * pitfalls of wildcards:                Wildcard Pitfall.
  8011. * portability:                          Features.
  8012. * POSIX:                                Overview.
  8013. * precious targets:                     Special Targets.
  8014. * prefix, adding:                       Filename Functions.
  8015. * preserving intermediate files:        Chained Rules.
  8016. * preserving with .PRECIOUS:            Chained Rules.
  8017. * preserving with .PRECIOUS:            Special Targets.
  8018. * printing directories:                 -w Option.
  8019. * printing of commands:                 Echoing.
  8020. * problems and bugs, reporting:         Bugs.
  8021. * problems with wildcards:              Wildcard Pitfall.
  8022. * processing a makefile:                How Make Works.
  8023. * question mode:                        Instead of Execution.
  8024. * quoting %, in patsubst:               Text Functions.
  8025. * quoting %, in vpath:                  Selective Search.
  8026. * quoting %, in static pattern:         Static Usage.
  8027. * quoting newline, in commands:         Execution.
  8028. * quoting newline, in makefile:         Simple Makefile.
  8029. * Ratfor, rule to compile:              Catalogue of Rules.
  8030. * RCS, rule to extract from:            Catalogue of Rules.
  8031. * recompilation:                        Introduction.
  8032. * recompilation, avoiding:              Avoiding Compilation.
  8033. * recording events with empty targets:  Empty Targets.
  8034. * recursion:                            Recursion.
  8035. * recursion, and -C:                    Options/Recursion.
  8036. * recursion, and -f:                    Options/Recursion.
  8037. * recursion, and -I:                    Options/Recursion.
  8038. * recursion, and -j:                    Options/Recursion.
  8039. * recursion, and -o:                    Options/Recursion.
  8040. * recursion, and -t:                    MAKE Variable.
  8041. * recursion, and -W:                    Options/Recursion.
  8042. * recursion, and -w:                    -w Option.
  8043. * recursion, and MAKEFILES variable:    MAKEFILES Variable.
  8044. * recursion, and MAKE variable:         MAKE Variable.
  8045. * recursion, and environment:           Variables/Recursion.
  8046. * recursion, and options:               Options/Recursion.
  8047. * recursion, and printing directories:  -w Option.
  8048. * recursion, and variables:             Variables/Recursion.
  8049. * recursion, level of:                  Variables/Recursion.
  8050. * recursive variable expansion:         Using Variables.
  8051. * recursive variable expansion:         Flavors.
  8052. * recursively expanded variables:       Flavors.
  8053. * reference to variables:               Advanced.
  8054. * reference to variables:               Reference.
  8055. * relinking:                            How Make Works.
  8056. * remaking makefiles:                   Remaking Makefiles.
  8057. * removing duplicate words:             Text Functions.
  8058. * removing, to clean up:                Cleanup.
  8059. * reporting bugs:                       Bugs.
  8060. * rm:                                   Implicit Variables.
  8061. * rule commands:                        Commands.
  8062. * rule dependencies:                    Rule Syntax.
  8063. * rule syntax:                          Rule Syntax.
  8064. * rule targets:                         Rule Syntax.
  8065. * rule, and $:                          Rule Syntax.
  8066. * rule, double-colon (::):              Double-Colon.
  8067. * rule, explicit, definition of:        Makefile Contents.
  8068. * rule, how to write:                   Rules.
  8069. * rule, implicit:                       Implicit Rules.
  8070. * rule, implicit, and VPATH:            Implicit/Search.
  8071. * rule, implicit, and directory search: Implicit/Search.
  8072. * rule, implicit, chains of:            Chained Rules.
  8073. * rule, implicit, definition of:        Makefile Contents.
  8074. * rule, implicit, how to use:           Using Implicit.
  8075. * rule, implicit, introduction to:      make Deduces.
  8076. * rule, implicit, predefined:           Catalogue of Rules.
  8077. * rule, introduction to:                Rule Introduction.
  8078. * rule, multiple for one target:        Multiple Rules.
  8079. * rule, no commands or dependencies:    Force Targets.
  8080. * rule, pattern:                        Pattern Intro.
  8081. * rule, static pattern:                 Static Pattern.
  8082. * rule, static pattern versus implicit: Static versus Implicit.
  8083. * rule, with multiple targets:          Multiple Targets.
  8084. * s. (SCCS file prefix):                Catalogue of Rules.
  8085. * SCCS, rule to extract from:           Catalogue of Rules.
  8086. * search algorithm, implicit rule:      Search Algorithm.
  8087. * search path for dependencies (VPATH): Directory Search.
  8088. * search path for dependencies (VPATH), and implicit rules: Implicit/Search.
  8089. * search path for dependencies (VPATH), and link libraries: Libraries/Search.
  8090. * searching for strings:                Text Functions.
  8091. * selecting words:                      Filename Functions.
  8092. * sequences of commands:                Sequences.
  8093. * setting options from environment:     Options/Recursion.
  8094. * setting options in makefiles:         Options/Recursion.
  8095. * setting variables:                    Setting.
  8096. * several rules for one target:         Multiple Rules.
  8097. * several targets in a rule:            Multiple Targets.
  8098. * shell command:                        Simple Makefile.
  8099. * shell command, and directory search:  Commands/Search.
  8100. * shell command, execution:             Execution.
  8101. * shell command, function for:          Shell Function.
  8102. * shell file name pattern (in include): Include.
  8103. * shell wildcards (in include):         Include.
  8104. * signal:                               Interrupts.
  8105. * silent operation:                     Echoing.
  8106. * simple makefile:                      Simple Makefile.
  8107. * simple variable expansion:            Using Variables.
  8108. * simplifying with variables:           Variables Simplify.
  8109. * simply expanded variables:            Flavors.
  8110. * sorting words:                        Text Functions.
  8111. * spaces, in variable values:           Flavors.
  8112. * spaces, stripping:                    Text Functions.
  8113. * special targets:                      Special Targets.
  8114. * specifying makefile name:             Makefile Names.
  8115. * standard input:                       Parallel.
  8116. * standards conformance:                Overview.
  8117. * standards for makefiles:              Makefile Conventions.
  8118. * static pattern rule:                  Static Pattern.
  8119. * static pattern rule, syntax of:       Static Usage.
  8120. * static pattern rule, versus implicit: Static versus Implicit.
  8121. * stem:                                 Pattern Match.
  8122. * stem:                                 Static Usage.
  8123. * stem, variable for:                   Automatic.
  8124. * strings, searching for:               Text Functions.
  8125. * stripping whitespace:                 Text Functions.
  8126. * sub-make:                             Variables/Recursion.
  8127. * subdirectories, recursion for:        Recursion.
  8128. * substitution variable reference:      Substitution Refs.
  8129. * suffix rule:                          Suffix Rules.
  8130. * suffix rule, for archive:             Archive Suffix Rules.
  8131. * suffix, adding:                       Filename Functions.
  8132. * suffix, function to find:             Filename Functions.
  8133. * suffix, substituting in variables:    Substitution Refs.
  8134. * switches:                             Options Summary.
  8135. * symbol directories, updating archive: Archive Symbols.
  8136. * syntax of rules:                      Rule Syntax.
  8137. * tab character (in commands):          Rule Syntax.
  8138. * tabs in rules:                        Rule Introduction.
  8139. * tangle:                               Catalogue of Rules.
  8140. * tangle:                               Implicit Variables.
  8141. * target:                               Rules.
  8142. * target pattern, implicit:             Pattern Intro.
  8143. * target pattern, static (not implicit): Static Usage.
  8144. * target, deleting on interrupt:        Interrupts.
  8145. * target, multiple in pattern rule:     Pattern Intro.
  8146. * target, multiple rules for one:       Multiple Rules.
  8147. * target, touching:                     Instead of Execution.
  8148. * targets:                              Rule Syntax.
  8149. * targets without a file:               Phony Targets.
  8150. * targets, built-in special:            Special Targets.
  8151. * targets, empty:                       Empty Targets.
  8152. * targets, force:                       Force Targets.
  8153. * targets, introduction to:             Rule Introduction.
  8154. * targets, multiple:                    Multiple Targets.
  8155. * targets, phony:                       Phony Targets.
  8156. * terminal rule:                        Match-Anything Rules.
  8157. * testing compilation:                  Testing.
  8158. * tex:                                  Implicit Variables.
  8159. * tex:                                  Catalogue of Rules.
  8160. * texi2dvi:                             Catalogue of Rules.
  8161. * texi2dvi:                             Implicit Variables.
  8162. * Texinfo, rule to format:              Catalogue of Rules.
  8163. * tilde (~):                            Wildcards.
  8164. * touching files:                       Instead of Execution.
  8165. * undefined variables, warning message: Options Summary.
  8166. * updating archive symbol directories:  Archive Symbols.
  8167. * updating makefiles:                   Remaking Makefiles.
  8168. * value:                                Using Variables.
  8169. * value, how a variable gets it:        Values.
  8170. * variable:                             Using Variables.
  8171. * variable definition:                  Makefile Contents.
  8172. * variables:                            Variables Simplify.
  8173. * variables, $ in name:                 Computed Names.
  8174. * variables, and implicit rule:         Automatic.
  8175. * variables, appending to:              Appending.
  8176. * variables, automatic:                 Automatic.
  8177. * variables, command line:              Overriding.
  8178. * variables, computed names:            Computed Names.
  8179. * variables, defining verbatim:         Defining.
  8180. * variables, environment:               Variables/Recursion.
  8181. * variables, environment:               Environment.
  8182. * variables, exporting:                 Variables/Recursion.
  8183. * variables, flavors:                   Flavors.
  8184. * variables, how they get their values: Values.
  8185. * variables, how to reference:          Reference.
  8186. * variables, loops in expansion:        Flavors.
  8187. * variables, modified reference:        Substitution Refs.
  8188. * variables, nested references:         Computed Names.
  8189. * variables, origin of:                 Origin Function.
  8190. * variables, overriding:                Override Directive.
  8191. * variables, overriding with arguments: Overriding.
  8192. * variables, recursively expanded:      Flavors.
  8193. * variables, setting:                   Setting.
  8194. * variables, simply expanded:           Flavors.
  8195. * variables, spaces in values:          Flavors.
  8196. * variables, substituting suffix in:    Substitution Refs.
  8197. * variables, substitution reference:    Substitution Refs.
  8198. * variables, warning for undefined:     Options Summary.
  8199. * varying dependencies:                 Static Pattern.
  8200. * verbatim variable definition:         Defining.
  8201. * vpath:                                Directory Search.
  8202. * weave:                                Catalogue of Rules.
  8203. * weave:                                Implicit Variables.
  8204. * Web, rule to run:                     Catalogue of Rules.
  8205. * what if:                              Instead of Execution.
  8206. * whitespace, stripping:                Text Functions.
  8207. * wildcard:                             Wildcards.
  8208. * wildcard pitfalls:                    Wildcard Pitfall.
  8209. * wildcard, function:                   Filename Functions.
  8210. * wildcard, in include:                 Include.
  8211. * wildcard, in archive member:          Archive Members.
  8212. * words, extracting first:              Filename Functions.
  8213. * words, filtering:                     Text Functions.
  8214. * words, filtering out:                 Text Functions.
  8215. * words, finding number:                Filename Functions.
  8216. * words, iterating over:                Foreach Function.
  8217. * words, joining lists:                 Filename Functions.
  8218. * words, removing duplicates:           Text Functions.
  8219. * words, selecting:                     Filename Functions.
  8220. * writing rule commands:                Commands.
  8221. * writing rules:                        Rules.
  8222. * yacc:                                 Catalogue of Rules.
  8223. * yacc:                                 Implicit Variables.
  8224. * Yacc, rule to run:                    Catalogue of Rules.
  8225.  
  8226. 
  8227. File: make,  Node: Name Index,  Prev: Concept Index,  Up: Top
  8228.  
  8229. Index of Functions, Variables, & Directives
  8230. *******************************************
  8231.  
  8232. * Menu:
  8233.  
  8234. * $%:                                   Automatic.
  8235. * $(%D):                                Automatic.
  8236. * $(%F):                                Automatic.
  8237. * $(*D):                                Automatic.
  8238. * $(*F):                                Automatic.
  8239. * $(<D):                                Automatic.
  8240. * $(<F):                                Automatic.
  8241. * $(?D):                                Automatic.
  8242. * $(?F):                                Automatic.
  8243. * $(@D):                                Automatic.
  8244. * $(@F):                                Automatic.
  8245. * $(^D):                                Automatic.
  8246. * $(^F):                                Automatic.
  8247. * $*:                                   Automatic.
  8248. * $*, and static pattern:               Static Usage.
  8249. * $<:                                   Automatic.
  8250. * $?:                                   Automatic.
  8251. * $@:                                   Automatic.
  8252. * $^:                                   Automatic.
  8253. * % (automatic variable):               Automatic.
  8254. * %D (automatic variable):              Automatic.
  8255. * %F (automatic variable):              Automatic.
  8256. * * (automatic variable), unsupported bizarre usage: Missing.
  8257. * * (automatic variable):               Automatic.
  8258. * *D (automatic variable):              Automatic.
  8259. * *F (automatic variable):              Automatic.
  8260. * .DEFAULT:                             Last Resort.
  8261. * .DEFAULT:                             Special Targets.
  8262. * .DEFAULT, and empty commands:         Empty Commands.
  8263. * .EXPORT_ALL_VARIABLES:                Special Targets.
  8264. * .EXPORT_ALL_VARIABLES:                Variables/Recursion.
  8265. * .IGNORE:                              Errors.
  8266. * .IGNORE:                              Special Targets.
  8267. * .PHONY:                               Phony Targets.
  8268. * .PHONY:                               Special Targets.
  8269. * .PRECIOUS:                            Interrupts.
  8270. * .PRECIOUS:                            Special Targets.
  8271. * .SILENT:                              Echoing.
  8272. * .SILENT:                              Special Targets.
  8273. * .SUFFIXES:                            Suffix Rules.
  8274. * .SUFFIXES:                            Special Targets.
  8275. * /usr/gnu/include:                     Include.
  8276. * /usr/include:                         Include.
  8277. * /usr/local/include:                   Include.
  8278. * < (automatic variable):               Automatic.
  8279. * <D (automatic variable):              Automatic.
  8280. * <F (automatic variable):              Automatic.
  8281. * ? (automatic variable):               Automatic.
  8282. * ?D (automatic variable):              Automatic.
  8283. * ?F (automatic variable):              Automatic.
  8284. * @ (automatic variable):               Automatic.
  8285. * @D (automatic variable):              Automatic.
  8286. * @F (automatic variable):              Automatic.
  8287. * ^ (automatic variable):               Automatic.
  8288. * ^D (automatic variable):              Automatic.
  8289. * ^F (automatic variable):              Automatic.
  8290. * addprefix:                            Filename Functions.
  8291. * addsuffix:                            Filename Functions.
  8292. * AR:                                   Implicit Variables.
  8293. * ARFLAGS:                              Implicit Variables.
  8294. * AS:                                   Implicit Variables.
  8295. * ASFLAGS:                              Implicit Variables.
  8296. * basename:                             Filename Functions.
  8297. * CC:                                   Implicit Variables.
  8298. * CFLAGS:                               Implicit Variables.
  8299. * CO:                                   Implicit Variables.
  8300. * COFLAGS:                              Implicit Variables.
  8301. * CPP:                                  Implicit Variables.
  8302. * CPPFLAGS:                             Implicit Variables.
  8303. * CTANGLE:                              Implicit Variables.
  8304. * CWEAVE:                               Implicit Variables.
  8305. * CXX:                                  Implicit Variables.
  8306. * CXXFLAGS:                             Implicit Variables.
  8307. * define:                               Defining.
  8308. * dir:                                  Filename Functions.
  8309. * else:                                 Conditional Syntax.
  8310. * endef:                                Defining.
  8311. * endif:                                Conditional Syntax.
  8312. * export:                               Variables/Recursion.
  8313. * FC:                                   Implicit Variables.
  8314. * FFLAGS:                               Implicit Variables.
  8315. * filter:                               Text Functions.
  8316. * filter-out:                           Text Functions.
  8317. * findstring:                           Text Functions.
  8318. * firstword:                            Filename Functions.
  8319. * foreach:                              Foreach Function.
  8320. * GET:                                  Implicit Variables.
  8321. * GFLAGS:                               Implicit Variables.
  8322. * GNUmakefile:                          Makefile Names.
  8323. * ifdef:                                Conditional Syntax.
  8324. * ifeq:                                 Conditional Syntax.
  8325. * ifndef:                               Conditional Syntax.
  8326. * ifneq:                                Conditional Syntax.
  8327. * include:                              Include.
  8328. * join:                                 Filename Functions.
  8329. * LDFLAGS:                              Implicit Variables.
  8330. * LEX:                                  Implicit Variables.
  8331. * LFLAGS:                               Implicit Variables.
  8332. * MAKE:                                 Flavors.
  8333. * MAKE:                                 MAKE Variable.
  8334. * MAKE_COMMAND:                         MAKE Variable.
  8335. * Makefile:                             Makefile Names.
  8336. * makefile:                             Makefile Names.
  8337. * MAKEFILES:                            MAKEFILES Variable.
  8338. * MAKEFILES:                            Variables/Recursion.
  8339. * MAKEFLAGS:                            Options/Recursion.
  8340. * MAKEINFO:                             Implicit Variables.
  8341. * MAKELEVEL:                            Variables/Recursion.
  8342. * MAKELEVEL:                            Flavors.
  8343. * MAKEOVERRIDES:                        MAKE Variable.
  8344. * MFLAGS:                               Options/Recursion.
  8345. * notdir:                               Filename Functions.
  8346. * origin:                               Origin Function.
  8347. * OUTPUT_OPTION:                        Catalogue of Rules.
  8348. * override:                             Override Directive.
  8349. * patsubst:                             Text Functions.
  8350. * patsubst:                             Substitution Refs.
  8351. * PC:                                   Implicit Variables.
  8352. * PFLAGS:                               Implicit Variables.
  8353. * RFLAGS:                               Implicit Variables.
  8354. * RM:                                   Implicit Variables.
  8355. * SHELL:                                Execution.
  8356. * shell:                                Shell Function.
  8357. * SHELL (command execution):            Execution.
  8358. * sort:                                 Text Functions.
  8359. * strip:                                Text Functions.
  8360. * subst:                                Multiple Targets.
  8361. * subst:                                Text Functions.
  8362. * suffix:                               Filename Functions.
  8363. * SUFFIXES:                             Suffix Rules.
  8364. * TANGLE:                               Implicit Variables.
  8365. * TEX:                                  Implicit Variables.
  8366. * TEXI2DVI:                             Implicit Variables.
  8367. * unexport:                             Variables/Recursion.
  8368. * vpath:                                Selective Search.
  8369. * vpath:                                Directory Search.
  8370. * VPATH:                                Directory Search.
  8371. * VPATH:                                General Search.
  8372. * WEAVE:                                Implicit Variables.
  8373. * wildcard:                             Filename Functions.
  8374. * wildcard:                             Wildcard Function.
  8375. * word:                                 Filename Functions.
  8376. * words:                                Filename Functions.
  8377. * YACC:                                 Implicit Variables.
  8378. * YACCR:                                Implicit Variables.
  8379. * YFLAGS:                               Implicit Variables.
  8380.  
  8381.  
  8382. 
  8383. Tag Table:
  8384. Node: Top1127
  8385. Node: Overview11996
  8386. Node: Preparing12928
  8387. Node: Reading13878
  8388. Node: Bugs14795
  8389. Node: Introduction16698
  8390. Node: Rule Introduction18280
  8391. Node: Simple Makefile19984
  8392. Node: How Make Works23592
  8393. Node: Variables Simplify26085
  8394. Node: make Deduces28286
  8395. Node: Combine By Dependency30028
  8396. Node: Cleanup31051
  8397. Node: Makefiles32456
  8398. Node: Makefile Contents33148
  8399. Node: Makefile Names35403
  8400. Node: Include37000
  8401. Node: MAKEFILES Variable40406
  8402. Node: Remaking Makefiles41903
  8403. Node: Overriding Makefiles45716
  8404. Node: Rules47301
  8405. Node: Rule Example49896
  8406. Node: Rule Syntax50726
  8407. Node: Wildcards52930
  8408. Node: Wildcard Examples54435
  8409. Node: Wildcard Pitfall55665
  8410. Node: Wildcard Function56910
  8411. Node: Directory Search58686
  8412. Node: General Search59741
  8413. Node: Selective Search61243
  8414. Node: Commands/Search64143
  8415. Node: Implicit/Search65478
  8416. Node: Libraries/Search66408
  8417. Node: Phony Targets67472
  8418. Node: Force Targets70812
  8419. Node: Empty Targets71844
  8420. Node: Special Targets73099
  8421. Node: Multiple Targets76675
  8422. Node: Multiple Rules78537
  8423. Node: Static Pattern80615
  8424. Node: Static Usage81250
  8425. Node: Static versus Implicit84899
  8426. Node: Double-Colon86625
  8427. Node: Automatic Dependencies88150
  8428. Node: Commands91697
  8429. Node: Echoing93253
  8430. Node: Execution94485
  8431. Node: Parallel96148
  8432. Node: Errors99458
  8433. Node: Interrupts102352
  8434. Node: Recursion103928
  8435. Node: MAKE Variable105209
  8436. Node: Variables/Recursion108295
  8437. Node: Options/Recursion113070
  8438. Node: -w Option116397
  8439. Node: Sequences117378
  8440. Node: Empty Commands120368
  8441. Node: Using Variables121531
  8442. Node: Reference124150
  8443. Node: Flavors125690
  8444. Node: Advanced130172
  8445. Node: Substitution Refs130667
  8446. Node: Computed Names132189
  8447. Node: Values136754
  8448. Node: Setting137666
  8449. Node: Appending139370
  8450. Node: Override Directive143283
  8451. Node: Defining144657
  8452. Node: Environment146650
  8453. Node: Conditionals148773
  8454. Node: Conditional Example149477
  8455. Node: Conditional Syntax152038
  8456. Node: Testing Flags156779
  8457. Node: Functions157871
  8458. Node: Syntax of Functions158864
  8459. Node: Text Functions160996
  8460. Node: Filename Functions167745
  8461. Node: Foreach Function172861
  8462. Node: Origin Function176058
  8463. Node: Shell Function179278
  8464. Node: Running180650
  8465. Node: Makefile Arguments182187
  8466. Node: Goals182877
  8467. Node: Instead of Execution186653
  8468. Node: Avoiding Compilation189738
  8469. Node: Overriding191634
  8470. Node: Testing193917
  8471. Node: Options Summary195789
  8472. Node: Implicit Rules202540
  8473. Node: Using Implicit204681
  8474. Node: Catalogue of Rules208163
  8475. Node: Implicit Variables217098
  8476. Node: Chained Rules221219
  8477. Node: Pattern Rules223912
  8478. Node: Pattern Intro225435
  8479. Node: Pattern Examples228241
  8480. Node: Automatic230029
  8481. Node: Pattern Match235664
  8482. Node: Match-Anything Rules237263
  8483. Node: Canceling Rules241117
  8484. Node: Last Resort241815
  8485. Node: Suffix Rules243647
  8486. Node: Search Algorithm247349
  8487. Node: Archives250840
  8488. Node: Archive Members251452
  8489. Node: Archive Update253008
  8490. Node: Archive Symbols254921
  8491. Node: Archive Suffix Rules256115
  8492. Node: Features257648
  8493. Node: Missing265930
  8494. Node: Makefile Conventions270254
  8495. Node: Makefile Basics270597
  8496. Node: Utilities in Makefiles272478
  8497. Node: Standard Targets273904
  8498. Node: Command Variables281003
  8499. Node: Directory Variables283823
  8500. Node: Quick Reference290285
  8501. Node: Complex Makefile297692
  8502. Node: Concept Index306354
  8503. Node: Name Index344989
  8504. 
  8505. End Tag Table
  8506.