Ignore:
Timestamp:
Sep 15, 2006, 4:30:32 AM (19 years ago)
Author:
bird
Message:

Load make-3.81/ into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/doc/make.info-1

    r152 r501  
    1 This is make.info, produced by makeinfo version 4.6 from make.texi.
     1This is make.info, produced by makeinfo version 4.8 from make.texi.
     2
     3   This file documents the GNU `make' utility, which determines
     4automatically which pieces of a large program need to be recompiled,
     5and issues the commands to recompile them.
     6
     7   This is Edition 0.70, last updated 1 April 2006, of `The GNU Make
     8Manual', for GNU `make' version 3.81.
     9
     10   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
     111997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software
     12Foundation, Inc.
     13
     14     Permission is granted to copy, distribute and/or modify this
     15     document under the terms of the GNU Free Documentation License,
     16     Version 1.2 or any later version published by the Free Software
     17     Foundation; with no Invariant Sections, with the Front-Cover Texts
     18     being "A GNU Manual," and with the Back-Cover Texts as in (a)
     19     below.  A copy of the license is included in the section entitled
     20     "GNU Free Documentation License."
     21
     22     (a) The FSF's Back-Cover Text is: "You have freedom to copy and
     23     modify this GNU Manual, like GNU software.  Copies published by
     24     the Free Software Foundation raise funds for GNU development."
    225
    326INFO-DIR-SECTION GNU Packages
     
    629END-INFO-DIR-ENTRY
    730
    8    This file documents the GNU Make utility, which determines
     31
     32File: make.info,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)
     33
     34GNU `make'
     35**********
     36
     37This file documents the GNU `make' utility, which determines
    938automatically which pieces of a large program need to be recompiled,
    1039and issues the commands to recompile them.
    1140
    12    This is Edition 0.61, last updated 02 May 2003, of `The GNU Make
    13 Manual', for `make', Version 3.81.
    14 
    15    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    16 1998, 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
    17 
    18    Permission is granted to copy, distribute and/or modify this document
    19 under the terms of the GNU Free Documentation License, Version 1.1 or
    20 any later version published by the Free Software Foundation; with no
    21 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
    22 Texts.  A copy of the license is included in the section entitled "GNU
    23 Free Documentation License".
    24 
    25 
    26 File: make.info,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)
    27 
    28 Make
    29 ****
    30 
    31 The GNU `make' utility automatically determines which pieces of a large
    32 program need to be recompiled, and issues the commands to recompile
    33 them.
    34 
    35    This edition of the `GNU Make Manual', last updated 02 May 2003,
    36 documents GNU `make' Version 3.81.
    37 
    38    This manual describes `make' and contains the following chapters:
     41   This is Edition 0.70, last updated 1 April 2006, of `The GNU Make
     42Manual', for GNU `make' version 3.81.
     43
     44   Copyright (C) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
     451997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006 Free Software
     46Foundation, Inc.
     47
     48     Permission is granted to copy, distribute and/or modify this
     49     document under the terms of the GNU Free Documentation License,
     50     Version 1.2 or any later version published by the Free Software
     51     Foundation; with no Invariant Sections, with the Front-Cover Texts
     52     being "A GNU Manual," and with the Back-Cover Texts as in (a)
     53     below.  A copy of the license is included in the section entitled
     54     "GNU Free Documentation License."
     55
     56     (a) The FSF's Back-Cover Text is: "You have freedom to copy and
     57     modify this GNU Manual, like GNU software.  Copies published by
     58     the Free Software Foundation raise funds for GNU development."
    3959
    4060* Menu:
     
    96116                                  with another makefile.
    97117* Reading Makefiles::           How makefiles are parsed.
     118* Secondary Expansion::         How and when secondary expansion is performed.
    98119
    99120Writing Rules
     
    106127* Phony Targets::               Using a target that is not a real file's name.
    107128* Force Targets::               You can use a target without commands
    108                                   or prerequisites to mark other
    109                                   targets as phony.
     129                                  or prerequisites to mark other targets
     130                                  as phony.
    110131* Empty Targets::               When only the date matters and the
    111132                                  files are empty.
     
    147168Writing the Commands in Rules
    148169
     170* Command Syntax::              Command syntax features and pitfalls.
    149171* Echoing::                     How to control when commands are echoed.
    150172* Execution::                   How commands are executed.
     
    155177* Sequences::                   Defining canned sequences of commands.
    156178* Empty Commands::              Defining useful, do-nothing commands.
     179
     180Command Syntax
     181
     182* Splitting Lines::             Breaking long command lines for readability.
     183* Variables in Commands::       Using `make' variables in commands.
     184
     185Command Execution
     186
     187* Choosing the Shell::          How `make' chooses the shell used
     188                                  to run commands.
    157189
    158190Recursive Use of `make'
     
    200232* Text Functions::              General-purpose text manipulation functions.
    201233* File Name Functions::         Functions for manipulating file names.
     234* Conditional Functions::       Functions that implement conditions.
    202235* Foreach Function::            Repeat some text with controlled variation.
    203 * If Function::                 Conditionally expand a value.
    204236* Call Function::               Expand a user-defined function.
    205237* Value Function::              Return the un-expanded value of a variable.
    206238* Eval Function::               Evaluate the arguments as makefile syntax.
    207239* Origin Function::             Find where a variable got its value.
     240* Flavor Function::             Find out the flavor of a variable.
    208241* Shell Function::              Substitute the output of a shell command.
    209242* Make Control Functions::      Functions that control how make runs.
     
    233266* Chained Rules::               How to use a chain of implicit rules.
    234267* Pattern Rules::               How to define new implicit rules.
    235 * Last Resort::                 How to defining commands for rules
    236                                   which cannot find any.
     268* Last Resort::                 How to define commands for rules which
     269                                  cannot find any.
    237270* Suffix Rules::                The old-fashioned style of implicit rule.
    238271* Implicit Rule Search::        The precise algorithm for applying
     
    263296* Archive Symbols::             How to update archive symbol directories.
    264297
    265 Makefile Conventions
    266 
    267 * Makefile Basics::             General Conventions for Makefiles
    268 * Utilities in Makefiles::      Utilities in Makefiles
    269 * Command Variables::           Variables for Specifying Commands
    270 * Directory Variables::         Variables for Installation Directories
    271 * Standard Targets::            Standard Targets for Users
    272 * Install Command Categories::  Three categories of commands in the `install'
    273 
    274 Copying This Manual
    275 
    276298
    277299File: make.info,  Node: Overview,  Next: Introduction,  Prev: Top,  Up: Top
    278300
    279 Overview of `make'
    280 ******************
     3011 Overview of `make'
     302********************
    281303
    282304The `make' utility automatically determines which pieces of a large
     
    287309
    288310   GNU `make' conforms to section 6.2 of `IEEE Standard 1003.2-1992'
    289 (POSIX.2).
     311(POSIX.2). 
    290312
    291313   Our examples show C programs, since they are most common, but you
     
    329351File: make.info,  Node: Reading,  Next: Bugs,  Prev: Preparing,  Up: Overview
    330352
    331 How to Read This Manual
    332 =======================
     3531.1 How to Read This Manual
     354===========================
    333355
    334356If you are new to `make', or are looking for a general introduction,
     
    350372File: make.info,  Node: Bugs,  Prev: Reading,  Up: Overview
    351373
    352 Problems and Bugs
    353 =================
     3741.2 Problems and Bugs
     375=====================
    354376
    355377If you have problems with GNU `make' or think you've found a bug,
     
    393415File: make.info,  Node: Introduction,  Next: Makefiles,  Prev: Overview,  Up: Top
    394416
    395 An Introduction to Makefiles
    396 ****************************
     4172 An Introduction to Makefiles
     418******************************
    397419
    398420You need a file called a "makefile" to tell `make' what to do.  Most
    399 often, the makefile tells `make' how to compile and link a program.
     421often, the makefile tells `make' how to compile and link a program. 
    400422
    401423   In this chapter, we will discuss a simple makefile that describes
     
    412434Finally, if any source file has been recompiled, all the object files,
    413435whether newly made or saved from previous compilations, must be linked
    414 together to produce the new executable editor.
     436together to produce the new executable editor. 
    415437
    416438* Menu:
     
    427449File: make.info,  Node: Rule Introduction,  Next: Simple Makefile,  Prev: Introduction,  Up: Introduction
    428450
    429 What a Rule Looks Like
    430 ======================
     4512.1 What a Rule Looks Like
     452==========================
    431453
    432454A simple makefile consists of "rules" with the following shape:
     
    470492File: make.info,  Node: Simple Makefile,  Next: How Make Works,  Prev: Rule Introduction,  Up: Introduction
    471493
    472 A Simple Makefile
    473 =================
     4942.2 A Simple Makefile
     495=====================
    474496
    475497Here is a straightforward makefile that describes the way an executable
     
    485507             cc -o edit main.o kbd.o command.o display.o \
    486508                        insert.o search.o files.o utils.o
    487      
     509
    488510     main.o : main.c defs.h
    489511             cc -c main.c
     
    507529
    508530We split each long line into two lines using backslash-newline; this is
    509 like using one long line, but is easier to read.
     531like using one long line, but is easier to read. 
    510532
    511533   To use this makefile to create the executable file called `edit',
     
    535557prerequisites.  These shell commands say how to update the target file.
    536558A tab character must come at the beginning of every command line to
    537 distinguish commands lines from other lines in the makefile.  (Bear in
     559distinguish command lines from other lines in the makefile.  (Bear in
    538560mind that `make' does not know anything about how the commands work.
    539561It is up to you to supply commands that will update the target file
    540562properly.  All `make' does is execute the commands in the rule you have
    541 specified when the target file needs to be updated.)
     563specified when the target file needs to be updated.) 
    542564
    543565   The target `clean' is not a file, but merely the name of an action.
     
    550572called "phony targets".  *Note Phony Targets::, for information about
    551573this kind of target.  *Note Errors in Commands: Errors, to see how to
    552 cause `make' to ignore errors from `rm' or any other command.
     574cause `make' to ignore errors from `rm' or any other command. 
    553575
    554576
    555577File: make.info,  Node: How Make Works,  Next: Variables Simplify,  Prev: Simple Makefile,  Up: Introduction
    556578
    557 How `make' Processes a Makefile
    558 ===============================
     5792.3 How `make' Processes a Makefile
     580===================================
    559581
    560582By default, `make' starts with the first target (not targets whose
    561583names start with `.').  This is called the "default goal".  ("Goals"
    562 are the targets that `make' strives ultimately to update.  *Note
    563 Arguments to Specify the Goals: Goals.)
     584are the targets that `make' strives ultimately to update.    You can
     585override this behavior using the command line (*note Arguments to
     586Specify the Goals: Goals.) or with the `.DEFAULT_GOAL' special variable
     587(*note Other Special Variables: Special Variables.). 
    564588
    565589   In the simple example of the previous section, the default goal is to
     
    596620not exist, or if any of the object files are newer than it.  If an
    597621object file was just recompiled, it is now newer than `edit', so `edit'
    598 is relinked.
     622is relinked. 
    599623
    600624   Thus, if we change the file `insert.c' and run `make', `make' will
     
    607631File: make.info,  Node: Variables Simplify,  Next: make Deduces,  Prev: How Make Works,  Up: Introduction
    608632
    609 Variables Make Makefiles Simpler
    610 ================================
     6332.4 Variables Make Makefiles Simpler
     634====================================
    611635
    612636In our example, we had to list all the object files twice in the rule
     
    641665     objects = main.o kbd.o command.o display.o \
    642666               insert.o search.o files.o utils.o
    643      
     667
    644668     edit : $(objects)
    645669             cc -o edit $(objects)
     
    666690File: make.info,  Node: make Deduces,  Next: Combine By Prerequisite,  Prev: Variables Simplify,  Up: Introduction
    667691
    668 Letting `make' Deduce the Commands
    669 ==================================
     6922.5 Letting `make' Deduce the Commands
     693======================================
    670694
    671695It is not necessary to spell out the commands for compiling the
     
    686710     objects = main.o kbd.o command.o display.o \
    687711               insert.o search.o files.o utils.o
    688      
     712
    689713     edit : $(objects)
    690714             cc -o edit $(objects)
    691      
     715
    692716     main.o : defs.h
    693717     kbd.o : defs.h command.h
     
    698722     files.o : defs.h buffer.h command.h
    699723     utils.o : defs.h
    700      
     724
    701725     .PHONY : clean
    702726     clean :
     
    713737File: make.info,  Node: Combine By Prerequisite,  Next: Cleanup,  Prev: make Deduces,  Up: Introduction
    714738
    715 Another Style of Makefile
    716 =========================
     7392.6 Another Style of Makefile
     740=============================
    717741
    718742When the objects of a makefile are created only by implicit rules, an
     
    723747     objects = main.o kbd.o command.o display.o \
    724748               insert.o search.o files.o utils.o
    725      
     749
    726750     edit : $(objects)
    727751             cc -o edit $(objects)
    728      
     752
    729753     $(objects) : defs.h
    730754     kbd.o command.o files.o : command.h
     
    742766File: make.info,  Node: Cleanup,  Prev: Combine By Prerequisite,  Up: Introduction
    743767
    744 Rules for Cleaning the Directory
    745 ================================
     7682.7 Rules for Cleaning the Directory
     769====================================
    746770
    747771Compiling a program is not the only thing you might want to write rules
     
    781805File: make.info,  Node: Makefiles,  Next: Rules,  Prev: Introduction,  Up: Top
    782806
    783 Writing Makefiles
    784 *****************
     8073 Writing Makefiles
     808*******************
    785809
    786810The information that tells `make' how to recompile a system comes from
     
    799823                                  with another makefile.
    800824* Reading Makefiles::           How makefiles are parsed.
     825* Secondary Expansion::         How and when secondary expansion is performed.
    801826
    802827
    803828File: make.info,  Node: Makefile Contents,  Next: Makefile Names,  Prev: Makefiles,  Up: Makefiles
    804829
    805 What Makefiles Contain
    806 ======================
     8303.1 What Makefiles Contain
     831==========================
    807832
    808833Makefiles contain five kinds of things: "explicit rules", "implicit
     
    864889File: make.info,  Node: Makefile Names,  Next: Include,  Prev: Makefile Contents,  Up: Makefiles
    865890
    866 What Name to Give Your Makefile
    867 ===============================
     8913.2 What Name to Give Your Makefile
     892===================================
    868893
    869894By default, when `make' looks for the makefile, it tries the following
    870 names, in order: `GNUmakefile', `makefile' and `Makefile'.
     895names, in order: `GNUmakefile', `makefile' and `Makefile'. 
    871896
    872897   Normally you should call your makefile either `makefile' or
     
    891916concatenated in the order specified.  The default makefile names
    892917`GNUmakefile', `makefile' and `Makefile' are not checked automatically
    893 if you specify `-f' or `--file'.
     918if you specify `-f' or `--file'. 
    894919
    895920
    896921File: make.info,  Node: Include,  Next: MAKEFILES Variable,  Prev: Makefile Names,  Up: Makefiles
    897922
    898 Including Other Makefiles
    899 =========================
     9233.3 Including Other Makefiles
     924=============================
    900925
    901926The `include' directive tells `make' to suspend reading the current
     
    905930     include FILENAMES...
    906931
    907 FILENAMES can contain shell file name patterns.
     932FILENAMES can contain shell file name patterns.  If FILENAMES is empty,
     933nothing is included and no error is printed. 
    908934
    909935   Extra spaces are allowed and ignored at the beginning of the line,
     
    942968than that of somehow appending the prerequisites to the end of the main
    943969makefile as has been traditionally done with other versions of `make'.
    944 *Note Automatic Prerequisites::.
     970*Note Automatic Prerequisites::. 
    945971
    946972   If the specified name does not start with a slash, and the file is
     
    9801006File: make.info,  Node: MAKEFILES Variable,  Next: MAKEFILE_LIST Variable,  Prev: Include,  Up: Makefiles
    9811007
    982 The Variable `MAKEFILES'
    983 ========================
     10083.4 The Variable `MAKEFILES'
     1009============================
    9841010
    9851011If the environment variable `MAKEFILES' is defined, `make' considers
     
    10091035File: make.info,  Node: MAKEFILE_LIST Variable,  Next: Special Variables,  Prev: MAKEFILES Variable,  Up: Makefiles
    10101036
    1011 The Variable `MAKEFILE_LIST'
    1012 ============================
     10373.5 The Variable `MAKEFILE_LIST'
     1038================================
    10131039
    10141040As `make' reads various makefiles, including any obtained from the
     
    10251051   If a makefile named `Makefile' has this content:
    10261052
    1027      name1 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
    1028      
     1053     name1 := $(lastword $(MAKEFILE_LIST))
     1054
    10291055     include inc.mk
    1030      
    1031      name2 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
    1032      
     1056
     1057     name2 := $(lastword $(MAKEFILE_LIST))
     1058
    10331059     all:
    10341060             @echo name1 = $(name1)
     
    10481074File: make.info,  Node: Special Variables,  Next: Remaking Makefiles,  Prev: MAKEFILE_LIST Variable,  Up: Makefiles
    10491075
    1050 Other Special Variables
    1051 =======================
    1052 
    1053 GNU `make' also supports a special variable.  Note that any value you
    1054 assign to this variable will be ignored; it will always return its
    1055 special value.
    1056 
    1057    The first special variable is `.VARIABLES'.  When expanded, the
    1058 value consists of a list of the _names_ of all global variables defined
    1059 in all makefiles read up until that point.  This includes variables
    1060 which have empty values, as well as built-in variables (*note Variables
    1061 Used by Implicit Rules: Implicit Variables.), but does not include any
    1062 variables which are only defined in a target-specific context.
     10763.6 Other Special Variables
     1077===========================
     1078
     1079GNU `make' also supports other special variables.  Unless otherwise
     1080documented here, these values lose their special properties if they are
     1081set by a makefile or on the command line.
     1082
     1083`.DEFAULT_GOAL'
     1084     Sets the default goal to be used if no targets were specified on
     1085     the command line (*note Arguments to Specify the Goals: Goals.).
     1086     The `.DEFAULT_GOAL' variable allows you to discover the current
     1087     default goal, restart the default goal selection algorithm by
     1088     clearing its value, or to explicitly set the default goal.  The
     1089     following example illustrates these cases:
     1090
     1091          # Query the default goal.
     1092          ifeq ($(.DEFAULT_GOAL),)
     1093            $(warning no default goal is set)
     1094          endif
     1095
     1096          .PHONY: foo
     1097          foo: ; @echo $@
     1098
     1099          $(warning default goal is $(.DEFAULT_GOAL))
     1100
     1101          # Reset the default goal.
     1102          .DEFAULT_GOAL :=
     1103
     1104          .PHONY: bar
     1105          bar: ; @echo $@
     1106
     1107          $(warning default goal is $(.DEFAULT_GOAL))
     1108
     1109          # Set our own.
     1110          .DEFAULT_GOAL := foo
     1111
     1112     This makefile prints:
     1113
     1114          no default goal is set
     1115          default goal is foo
     1116          default goal is bar
     1117          foo
     1118
     1119     Note that assigning more than one target name to `.DEFAULT_GOAL' is
     1120     illegal and will result in an error.
     1121
     1122`MAKE_RESTARTS'
     1123     This variable is set only if this instance of `make' has restarted
     1124     (*note How Makefiles Are Remade: Remaking Makefiles.): it will
     1125     contain the number of times this instance has restarted.  Note
     1126     this is not the same as recursion (counted by the `MAKELEVEL'
     1127     variable).  You should not set, modify, or export this variable.
     1128
     1129`.VARIABLES'
     1130     Expands to a list of the _names_ of all global variables defined
     1131     so far.  This includes variables which have empty values, as well
     1132     as built-in variables (*note Variables Used by Implicit Rules:
     1133     Implicit Variables.), but does not include any variables which are
     1134     only defined in a target-specific context.  Note that any value
     1135     you assign to this variable will be ignored; it will always return
     1136     its special value.
     1137
     1138`.FEATURES'
     1139     Expands to a list of special features supported by this version of
     1140     `make'.  Possible values include:
     1141
     1142    `archives'
     1143          Supports `ar' (archive) files using special filename syntax.
     1144          *Note Using `make' to Update Archive Files: Archives.
     1145
     1146    `check-symlink'
     1147          Supports the `-L' (`--check-symlink-times') flag.  *Note
     1148          Summary of Options: Options Summary.
     1149
     1150    `else-if'
     1151          Supports "else if" non-nested conditionals.  *Note Syntax of
     1152          Conditionals: Conditional Syntax.
     1153
     1154    `jobserver'
     1155          Supports "job server" enhanced parallel builds.  *Note
     1156          Parallel Execution: Parallel.
     1157
     1158    `second-expansion'
     1159          Supports secondary expansion of prerequisite lists.
     1160
     1161    `order-only'
     1162          Supports order-only prerequisites.  *Note Types of
     1163          Prerequisites: Prerequisite Types.
     1164
     1165    `target-specific'
     1166          Supports target-specific and pattern-specific variable
     1167          assignments.  *Note Target-specific Variable Values:
     1168          Target-specific.
     1169
     1170
     1171`.INCLUDE_DIRS'
     1172     Expands to a list of directories that `make' searches for included
     1173     makefiles (*note Including Other Makefiles: Include.).
     1174
    10631175
    10641176
    10651177File: make.info,  Node: Remaking Makefiles,  Next: Overriding Makefiles,  Prev: Special Variables,  Up: Makefiles
    10661178
    1067 How Makefiles Are Remade
    1068 ========================
     11793.7 How Makefiles Are Remade
     1180============================
    10691181
    10701182Sometimes makefiles can be remade from other files, such as RCS or SCCS
     
    11031215   If you do not specify any makefiles to be read with `-f' or `--file'
    11041216options, `make' will try the default makefile names; *note What Name to
    1105 Give Your Makefile: Makefile Names..  Unlike makefiles explicitly
     1217Give Your Makefile: Makefile Names.  Unlike makefiles explicitly
    11061218requested with `-f' or `--file' options, `make' is not certain that
    11071219these makefiles should exist.  However, if a default makefile does not
     
    11431255File: make.info,  Node: Overriding Makefiles,  Next: Reading Makefiles,  Prev: Remaking Makefiles,  Up: Makefiles
    11441256
    1145 Overriding Part of Another Makefile
    1146 ===================================
     12573.8 Overriding Part of Another Makefile
     1258=======================================
    11471259
    11481260Sometimes it is useful to have a makefile that is mostly just like
     
    11641276     foo:
    11651277             frobnicate > foo
    1166      
     1278
    11671279     %: force
    11681280             @$(MAKE) -f Makefile $@
     
    11861298
    11871299
    1188 File: make.info,  Node: Reading Makefiles,  Prev: Overriding Makefiles,  Up: Makefiles
    1189 
    1190 How `make' Reads a Makefile
    1191 ===========================
     1300File: make.info,  Node: Reading Makefiles,  Next: Secondary Expansion,  Prev: Overriding Makefiles,  Up: Makefiles
     1301
     13023.9 How `make' Reads a Makefile
     1303===============================
    11921304
    11931305GNU `make' does its work in two distinct phases.  During the first
     
    12241336     IMMEDIATE := IMMEDIATE
    12251337     IMMEDIATE += DEFERRED or IMMEDIATE
    1226      
     1338
    12271339     define IMMEDIATE
    12281340       DEFERRED
     
    12381350All instances of conditional syntax are parsed immediately, in their
    12391351entirety; this includes the `ifdef', `ifeq', `ifndef', and `ifneq'
    1240 forms.
     1352forms.  Of course this means that automatic variables cannot be used in
     1353conditional statements, as automatic variables are not set until the
     1354command script for that rule is invoked.  If you need to use automatic
     1355variables in a conditional you _must_ use shell conditional syntax, in
     1356your command script proper, for these tests, not `make' conditionals.
    12411357
    12421358Rule Definition
     
    12541370
    12551371
     1372File: make.info,  Node: Secondary Expansion,  Prev: Reading Makefiles,  Up: Makefiles
     1373
     13743.10 Secondary Expansion
     1375========================
     1376
     1377In the previous section we learned that GNU `make' works in two
     1378distinct phases: a read-in phase and a target-update phase (*note How
     1379`make' Reads a Makefile: Reading Makefiles.).  GNU make also has the
     1380ability to enable a _second expansion_ of the prerequisites (only) for
     1381some or all targets defined in the makefile.  In order for this second
     1382expansion to occur, the special target `.SECONDEXPANSION' must be
     1383defined before the first prerequisite list that makes use of this
     1384feature.
     1385
     1386   If that special target is defined then in between the two phases
     1387mentioned above, right at the end of the read-in phase, all the
     1388prerequisites of the targets defined after the special target are
     1389expanded a _second time_.  In most circumstances this secondary
     1390expansion will have no effect, since all variable and function
     1391references will have been expanded during the initial parsing of the
     1392makefiles.  In order to take advantage of the secondary expansion phase
     1393of the parser, then, it's necessary to _escape_ the variable or
     1394function reference in the makefile.  In this case the first expansion
     1395merely un-escapes the reference but doesn't expand it, and expansion is
     1396left to the secondary expansion phase.  For example, consider this
     1397makefile:
     1398
     1399     .SECONDEXPANSION:
     1400     ONEVAR = onefile
     1401     TWOVAR = twofile
     1402     myfile: $(ONEVAR) $$(TWOVAR)
     1403
     1404   After the first expansion phase the prerequisites list of the
     1405`myfile' target will be `onefile' and `$(TWOVAR)'; the first
     1406(unescaped) variable reference to ONEVAR is expanded, while the second
     1407(escaped) variable reference is simply unescaped, without being
     1408recognized as a variable reference.  Now during the secondary expansion
     1409the first word is expanded again but since it contains no variable or
     1410function references it remains the static value `onefile', while the
     1411second word is now a normal reference to the variable TWOVAR, which is
     1412expanded to the value `twofile'.  The final result is that there are
     1413two prerequisites, `onefile' and `twofile'.
     1414
     1415   Obviously, this is not a very interesting case since the same result
     1416could more easily have been achieved simply by having both variables
     1417appear, unescaped, in the prerequisites list.  One difference becomes
     1418apparent if the variables are reset; consider this example:
     1419
     1420     .SECONDEXPANSION:
     1421     AVAR = top
     1422     onefile: $(AVAR)
     1423     twofile: $$(AVAR)
     1424     AVAR = bottom
     1425
     1426   Here the prerequisite of `onefile' will be expanded immediately, and
     1427resolve to the value `top', while the prerequisite of `twofile' will
     1428not be full expanded until the secondary expansion and yield a value of
     1429`bottom'.
     1430
     1431   This is marginally more exciting, but the true power of this feature
     1432only becomes apparent when you discover that secondary expansions
     1433always take place within the scope of the automatic variables for that
     1434target.  This means that you can use variables such as `$@', `$*', etc.
     1435during the second expansion and they will have their expected values,
     1436just as in the command script.  All you have to do is defer the
     1437expansion by escaping the `$'.  Also, secondary expansion occurs for
     1438both explicit and implicit (pattern) rules.  Knowing this, the possible
     1439uses for this feature increase dramatically.  For example:
     1440
     1441     .SECONDEXPANSION:
     1442     main_OBJS := main.o try.o test.o
     1443     lib_OBJS := lib.o api.o
     1444
     1445     main lib: $$($$@_OBJS)
     1446
     1447   Here, after the initial expansion the prerequisites of both the
     1448`main' and `lib' targets will be `$($@_OBJS)'.  During the secondary
     1449expansion, the `$@' variable is set to the name of the target and so
     1450the expansion for the `main' target will yield `$(main_OBJS)', or
     1451`main.o try.o test.o', while the secondary expansion for the `lib'
     1452target will yield `$(lib_OBJS)', or `lib.o api.o'.
     1453
     1454   You can also mix functions here, as long as they are properly
     1455escaped:
     1456
     1457     main_SRCS := main.c try.c test.c
     1458     lib_SRCS := lib.c api.c
     1459
     1460     .SECONDEXPANSION:
     1461     main lib: $$(patsubst %.c,%.o,$$($$@_SRCS))
     1462
     1463   This version allows users to specify source files rather than object
     1464files, but gives the same resulting prerequisites list as the previous
     1465example.
     1466
     1467   Evaluation of automatic variables during the secondary expansion
     1468phase, especially of the target name variable `$$@', behaves similarly
     1469to evaluation within command scripts.  However, there are some subtle
     1470differences and "corner cases" which come into play for the different
     1471types of rule definitions that `make' understands.  The subtleties of
     1472using the different automatic variables are described below.
     1473
     1474Secondary Expansion of Explicit Rules
     1475-------------------------------------
     1476
     1477During the secondary expansion of explicit rules, `$$@' and `$$%'
     1478evaluate, respectively, to the file name of the target and, when the
     1479target is an archive member, the target member name.  The `$$<'
     1480variable evaluates to the first prerequisite in the first rule for this
     1481target.  `$$^' and `$$+' evaluate to the list of all prerequisites of
     1482rules _that have already appeared_ for the same target (`$$+' with
     1483repetitions and `$$^' without).  The following example will help
     1484illustrate these behaviors:
     1485
     1486     .SECONDEXPANSION:
     1487
     1488     foo: foo.1 bar.1 $$< $$^ $$+    # line #1
     1489
     1490     foo: foo.2 bar.2 $$< $$^ $$+    # line #2
     1491
     1492     foo: foo.3 bar.3 $$< $$^ $$+    # line #3
     1493
     1494   In the first prerequisite list, all three variables (`$$<', `$$^',
     1495and `$$+') expand to the empty string.  In the second, they will have
     1496values `foo.1', `foo.1 bar.1', and `foo.1 bar.1' respectively.  In the
     1497third they will have values `foo.1', `foo.1 bar.1 foo.2 bar.2', and
     1498`foo.1 bar.1 foo.2 bar.2' respectively.
     1499
     1500   Rules undergo secondary expansion in makefile order, except that the
     1501rule with the command script is always evaluated last.
     1502
     1503   The variables `$$?' and `$$*' are not available and expand to the
     1504empty string.
     1505
     1506Secondary Expansion of Static Pattern Rules
     1507-------------------------------------------
     1508
     1509Rules for secondary expansion of static pattern rules are identical to
     1510those for explicit rules, above, with one exception: for static pattern
     1511rules the `$$*' variable is set to the pattern stem.  As with explicit
     1512rules, `$$?' is not available and expands to the empty string.
     1513
     1514Secondary Expansion of Implicit Rules
     1515-------------------------------------
     1516
     1517As `make' searches for an implicit rule, it substitutes the stem and
     1518then performs secondary expansion for every rule with a matching target
     1519pattern.  The value of the automatic variables is derived in the same
     1520fashion as for static pattern rules.  As an example:
     1521
     1522     .SECONDEXPANSION:
     1523
     1524     foo: bar
     1525
     1526     foo foz: fo%: bo%
     1527
     1528     %oo: $$< $$^ $$+ $$*
     1529
     1530   When the implicit rule is tried for target `foo', `$$<' expands to
     1531`bar', `$$^' expands to `bar boo', `$$+' also expands to `bar boo', and
     1532`$$*' expands to `f'.
     1533
     1534   Note that the directory prefix (D), as described in *Note Implicit
     1535Rule Search Algorithm: Implicit Rule Search, is appended (after
     1536expansion) to all the patterns in the prerequisites list.  As an
     1537example:
     1538
     1539     .SECONDEXPANSION:
     1540
     1541     /tmp/foo.o:
     1542
     1543     %.o: $$(addsuffix /%.c,foo bar) foo.h
     1544
     1545   The prerequisite list after the secondary expansion and directory
     1546prefix reconstruction will be `/tmp/foo/foo.c /tmp/var/bar/foo.c
     1547foo.h'.  If you are not interested in this reconstruction, you can use
     1548`$$*' instead of `%' in the prerequisites list.
     1549
     1550
    12561551File: make.info,  Node: Rules,  Next: Commands,  Prev: Makefiles,  Up: Top
    12571552
    1258 Writing Rules
    1259 *************
     15534 Writing Rules
     1554***************
    12601555
    12611556A "rule" appears in the makefile and says when and how to remake
     
    12881583* Phony Targets::               Using a target that is not a real file's name.
    12891584* Force Targets::               You can use a target without commands
    1290                                   or prerequisites to mark other
    1291                                   targets as phony.
     1585                                  or prerequisites to mark other targets
     1586                                  as phony.
    12921587* Empty Targets::               When only the date matters and the
    12931588                                  files are empty.
     
    13061601File: make.info,  Node: Rule Example,  Next: Rule Syntax,  Prev: Rules,  Up: Rules
    13071602
    1308 Rule Example
    1309 ============
     16034.1 Rule Example
     1604================
    13101605
    13111606Here is an example of a rule:
     
    13321627File: make.info,  Node: Rule Syntax,  Next: Prerequisite Types,  Prev: Rule Example,  Up: Rules
    13331628
    1334 Rule Syntax
    1335 ===========
     16294.2 Rule Syntax
     1630===============
    13361631
    13371632In general, a rule looks like this:
     
    13581653appear on the line after the prerequisites, with a tab character, or may
    13591654appear on the same line, with a semicolon.  Either way, the effect is
    1360 the same.  *Note Writing the Commands in Rules: Commands.
    1361 
    1362    Because dollar signs are used to start variable references, if you
    1363 really want a dollar sign in a rule you must write two of them, `$$'
    1364 (*note How to Use Variables: Using Variables.).  You may split a long
    1365 line by inserting a backslash followed by a newline, but this is not
    1366 required, as `make' places no limit on the length of a line in a
    1367 makefile.
     1655the same.  There are other differences in the syntax of command lines.
     1656*Note Writing the Commands in Rules: Commands.
     1657
     1658   Because dollar signs are used to start `make' variable references,
     1659if you really want a dollar sign in a target or prerequisite you must
     1660write two of them, `$$' (*note How to Use Variables: Using Variables.).
     1661If you have enabled secondary expansion (*note Secondary Expansion::)
     1662and you want a literal dollar sign in the prerequisites lise, you must
     1663actually write _four_ dollar signs (`$$$$').
     1664
     1665   You may split a long line by inserting a backslash followed by a
     1666newline, but this is not required, as `make' places no limit on the
     1667length of a line in a makefile.
    13681668
    13691669   A rule tells `make' two things: when the targets are out of date,
     
    13871687File: make.info,  Node: Prerequisite Types,  Next: Wildcards,  Prev: Rule Syntax,  Up: Rules
    13881688
    1389 Types of Prerequisites
    1390 ======================
     16894.3 Types of Prerequisites
     1690==========================
    13911691
    13921692There are actually two different types of prerequisites understood by
     
    14231723File: make.info,  Node: Wildcards,  Next: Directory Search,  Prev: Prerequisite Types,  Up: Rules
    14241724
    1425 Using Wildcard Characters in File Names
    1426 =======================================
     17254.4 Using Wildcard Characters in File Names
     1726===========================================
    14271727
    14281728A single file name can specify many files using "wildcard characters".
     
    14401740simulated by setting the environment variable HOME.
    14411741
    1442    Wildcard expansion happens automatically in targets, in
    1443 prerequisites, and in commands (where the shell does the expansion).
    1444 In other contexts, wildcard expansion happens only if you request it
    1445 explicitly with the `wildcard' function.
     1742   Wildcard expansion is performed by `make' automatically in targets
     1743and in prerequisites.  In commands the shell is responsible for
     1744wildcard expansion.  In other contexts, wildcard expansion happens only
     1745if you request it explicitly with the `wildcard' function.
    14461746
    14471747   The special significance of a wildcard character can be turned off by
     
    14591759File: make.info,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Prev: Wildcards,  Up: Wildcards
    14601760
    1461 Wildcard Examples
    1462 -----------------
     17614.4.1 Wildcard Examples
     1762-----------------------
    14631763
    14641764Wildcards can be used in the commands of a rule, where they are expanded
     
    14991799File: make.info,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
    15001800
    1501 Pitfalls of Using Wildcards
    1502 ---------------------------
     18014.4.2 Pitfalls of Using Wildcards
     1802---------------------------------
    15031803
    15041804Now here is an example of a naive way of using wildcard expansion, that
     
    15081808
    15091809     objects = *.o
    1510      
     1810
    15111811     foo : $(objects)
    15121812             cc -o foo $(CFLAGS) $(objects)
     
    15421842File: make.info,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildcards
    15431843
    1544 The Function `wildcard'
    1545 -----------------------
     18444.4.3 The Function `wildcard'
     1845-----------------------------
    15461846
    15471847Wildcard expansion happens automatically in rules.  But wildcard
     
    15781878
    15791879     objects := $(patsubst %.c,%.o,$(wildcard *.c))
    1580      
     1880
    15811881     foo : $(objects)
    15821882             cc -o foo $(objects)
     
    15901890File: make.info,  Node: Directory Search,  Next: Phony Targets,  Prev: Wildcards,  Up: Rules
    15911891
    1592 Searching Directories for Prerequisites
    1593 =======================================
     18924.5 Searching Directories for Prerequisites
     1893===========================================
    15941894
    15951895For large systems, it is often desirable to put sources in a separate
     
    16141914File: make.info,  Node: General Search,  Next: Selective Search,  Prev: Directory Search,  Up: Directory Search
    16151915
    1616 `VPATH': Search Path for All Prerequisites
    1617 ------------------------------------------
     19164.5.1 `VPATH': Search Path for All Prerequisites
     1917------------------------------------------------
    16181918
    16191919The value of the `make' variable `VPATH' specifies a list of
     
    16581958File: make.info,  Node: Selective Search,  Next: Search Algorithm,  Prev: General Search,  Up: Directory Search
    16591959
    1660 The `vpath' Directive
    1661 ---------------------
     19604.5.2 The `vpath' Directive
     1961---------------------------
    16621962
    16631963Similar to the `VPATH' variable, but more selective, is the `vpath'
     
    17372037File: make.info,  Node: Search Algorithm,  Next: Commands/Search,  Prev: Selective Search,  Up: Directory Search
    17382038
    1739 How Directory Searches are Performed
    1740 ------------------------------------
     20394.5.3 How Directory Searches are Performed
     2040------------------------------------------
    17412041
    17422042When a prerequisite is found through directory search, regardless of
     
    17952095File: make.info,  Node: Commands/Search,  Next: Implicit/Search,  Prev: Search Algorithm,  Up: Directory Search
    17962096
    1797 Writing Shell Commands with Directory Search
    1798 --------------------------------------------
     20974.5.4 Writing Shell Commands with Directory Search
     2098--------------------------------------------------
    17992099
    18002100When a prerequisite is found in another directory through directory
     
    18162116compilation by implicit rules; we use it here for consistency so it will
    18172117affect all C compilations uniformly; *note Variables Used by Implicit
    1818 Rules: Implicit Variables..)
     2118Rules: Implicit Variables.)
    18192119
    18202120   Often the prerequisites include header files as well, which you do
     
    18292129File: make.info,  Node: Implicit/Search,  Next: Libraries/Search,  Prev: Commands/Search,  Up: Directory Search
    18302130
    1831 Directory Search and Implicit Rules
    1832 -----------------------------------
     21314.5.5 Directory Search and Implicit Rules
     2132-----------------------------------------
    18332133
    18342134The search through the directories specified in `VPATH' or with `vpath'
     
    18502150File: make.info,  Node: Libraries/Search,  Prev: Implicit/Search,  Up: Directory Search
    18512151
    1852 Directory Search for Link Libraries
    1853 -----------------------------------
     21524.5.6 Directory Search for Link Libraries
     2153-----------------------------------------
    18542154
    18552155Directory search applies in a special way to libraries used with the
     
    18892189word in the list will be used.
    18902190
    1891    The default value for `.LIBPATTERNS' is "`lib%.so lib%.a'", which
     2191   The default value for `.LIBPATTERNS' is `lib%.so lib%.a', which
    18922192provides the default behavior described above.
    18932193
     
    18982198File: make.info,  Node: Phony Targets,  Next: Force Targets,  Prev: Directory Search,  Up: Rules
    18992199
    1900 Phony Targets
    1901 =============
     22004.6 Phony Targets
     2201=================
    19022202
    19032203A phony target is one that is not really the name of a file.  It is
     
    19152215Because the `rm' command does not create a file named `clean', probably
    19162216no such file will ever exist.  Therefore, the `rm' command will be
    1917 executed every time you say `make clean'.
     2217executed every time you say `make clean'. 
    19182218
    19192219   The phony target will cease to work if anything ever does create a
     
    19452245   Another example of the usefulness of phony targets is in conjunction
    19462246with recursive invocations of `make' (for more information, see *Note
    1947 Recursive Use of `make': Recursion).  In this case the makefile will
     2247Recursive Use of `make': Recursion.).  In this case the makefile will
    19482248often contain a variable which lists a number of subdirectories to be
    19492249built.  One way to handle this is with one rule whose command is a
     
    19512251
    19522252     SUBDIRS = foo bar baz
    1953      
     2253
    19542254     subdirs:
    19552255             for dir in $(SUBDIRS); do \
     
    19632263it will do so even if `make' is invoked with the `-k' option, which is
    19642264unfortunate.  Second, and perhaps more importantly, you cannot take
    1965 advantage of the parallel build capabilities of make using this method,
    1966 since there is only one rule.
     2265advantage of `make''s ability to build targets in parallel (*note
     2266Parallel Execution: Parallel.), since there is only one rule.
    19672267
    19682268   By declaring the subdirectories as phony targets (you must do this as
     
    19712271
    19722272     SUBDIRS = foo bar baz
    1973      
     2273
    19742274     .PHONY: subdirs $(SUBDIRS)
    1975      
     2275
    19762276     subdirs: $(SUBDIRS)
    1977      
     2277
    19782278     $(SUBDIRS):
    19792279             $(MAKE) -C $@
    1980      
     2280
    19812281     foo: baz
    19822282
     
    20022302     all : prog1 prog2 prog3
    20032303     .PHONY : all
    2004      
     2304
    20052305     prog1 : prog1.o utils.o
    20062306             cc -o prog1 prog1.o utils.o
    2007      
     2307
    20082308     prog2 : prog2.o
    20092309             cc -o prog2 prog2.o
    2010      
     2310
    20112311     prog3 : prog3.o sort.o utils.o
    20122312             cc -o prog3 prog3.o sort.o utils.o
    20132313
    20142314Now you can say just `make' to remake all three programs, or specify as
    2015 arguments the ones to remake (as in `make prog1 prog3').
     2315arguments the ones to remake (as in `make prog1 prog3').  Phoniness is
     2316not inherited: the prerequisites of a phony target are not themselves
     2317phony, unless explicitly declared to be so.
    20162318
    20172319   When one phony target is a prerequisite of another, it serves as a
     
    20202322
    20212323     .PHONY: cleanall cleanobj cleandiff
    2022      
     2324
    20232325     cleanall : cleanobj cleandiff
    20242326             rm program
    2025      
     2327
    20262328     cleanobj :
    20272329             rm *.o
    2028      
     2330
    20292331     cleandiff :
    20302332             rm *.diff
     
    20332335File: make.info,  Node: Force Targets,  Next: Empty Targets,  Prev: Phony Targets,  Up: Rules
    20342336
    2035 Rules without Commands or Prerequisites
    2036 =======================================
     23374.7 Rules without Commands or Prerequisites
     2338===========================================
    20372339
    20382340If a rule has no prerequisites or commands, and the target of the rule
     
    20622364File: make.info,  Node: Empty Targets,  Next: Special Targets,  Prev: Force Targets,  Up: Rules
    20632365
    2064 Empty Target Files to Record Events
    2065 ===================================
     23664.8 Empty Target Files to Record Events
     2367=======================================
    20662368
    20672369The "empty target" is a variant of the phony target; it is used to hold
     
    20842386             lpr -p $?
    20852387             touch print
    2086 
     2388   
    20872389With this rule, `make print' will execute the `lpr' command if either
    20882390source file has changed since the last `make print'.  The automatic
     
    20932395File: make.info,  Node: Special Targets,  Next: Multiple Targets,  Prev: Empty Targets,  Up: Rules
    20942396
    2095 Special Built-in Target Names
    2096 =============================
     23974.9 Special Built-in Target Names
     2398=================================
    20972399
    20982400Certain names have special meanings if they appear as targets.
     
    21472449     intermediate).
    21482450
     2451`.SECONDEXPANSION'
     2452     If `.SECONDEXPANSION' is mentioned as a target anywhere in the
     2453     makefile, then all prerequisite lists defined _after_ it appears
     2454     will be expanded a second time after all makefiles have been read
     2455     in.  *Note Secondary Expansion: Secondary Expansion.
     2456
     2457     The prerequisites of the special target `.SUFFIXES' are the list
     2458     of suffixes to be used in checking for suffix rules.  *Note
     2459     Old-Fashioned Suffix Rules: Suffix Rules.
     2460
    21492461`.DELETE_ON_ERROR'
    21502462     If `.DELETE_ON_ERROR' is mentioned as a target anywhere in the
     
    22332545File: make.info,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
    22342546
    2235 Multiple Targets in a Rule
    2236 ==========================
     25474.10 Multiple Targets in a Rule
     2548===============================
    22372549
    22382550A rule with multiple targets is equivalent to writing many rules, each
     
    22582570          bigoutput littleoutput : text.g
    22592571                  generate text.g -$(subst output,,$@) > $@
    2260 
     2572     
    22612573     is equivalent to
    22622574
     
    22802592File: make.info,  Node: Multiple Rules,  Next: Static Pattern,  Prev: Multiple Targets,  Up: Rules
    22812593
    2282 Multiple Rules for One Target
    2283 =============================
     25944.11 Multiple Rules for One Target
     2595==================================
    22842596
    22852597One file can be the target of several rules.  All the prerequisites
     
    23312643File: make.info,  Node: Static Pattern,  Next: Double-Colon,  Prev: Multiple Rules,  Up: Rules
    23322644
    2333 Static Pattern Rules
    2334 ====================
     26454.12 Static Pattern Rules
     2646=========================
    23352647
    23362648"Static pattern rules" are rules which specify multiple targets and
     
    23482660File: make.info,  Node: Static Usage,  Next: Static versus Implicit,  Prev: Static Pattern,  Up: Static Pattern
    23492661
    2350 Syntax of Static Pattern Rules
    2351 ------------------------------
     26624.12.1 Syntax of Static Pattern Rules
     2663-------------------------------------
    23522664
    23532665Here is the syntax of a static pattern rule:
     
    23972709
    23982710     objects = foo.o bar.o
    2399      
     2711
    24002712     all: $(objects)
    2401      
     2713
    24022714     $(objects): %.o: %.c
    24032715             $(CC) -c $(CFLAGS) $< -o $@
     
    24142726
    24152727     files = foo.elc bar.o lose.o
    2416      
     2728
    24172729     $(filter %.o,$(files)): %.o: %.c
    24182730             $(CC) -c $(CFLAGS) $< -o $@
     
    24262738from `foo.el'.
    24272739
    2428    Another example shows how to use `$*' in static pattern rules:
     2740   Another example shows how to use `$*' in static pattern rules: 
    24292741
    24302742     bigoutput littleoutput : %output : text.g
     
    24372749File: make.info,  Node: Static versus Implicit,  Prev: Static Usage,  Up: Static Pattern
    24382750
    2439 Static Pattern Rules versus Implicit Rules
    2440 ------------------------------------------
     27514.12.2 Static Pattern Rules versus Implicit Rules
     2752-------------------------------------------------
    24412753
    24422754A static pattern rule has much in common with an implicit rule defined
     
    24742786File: make.info,  Node: Double-Colon,  Next: Automatic Prerequisites,  Prev: Static Pattern,  Up: Rules
    24752787
    2476 Double-Colon Rules
    2477 ==================
     27884.13 Double-Colon Rules
     2789=======================
    24782790
    24792791"Double-colon" rules are rules written with `::' instead of `:' after
     
    25112823File: make.info,  Node: Automatic Prerequisites,  Prev: Double-Colon,  Up: Rules
    25122824
    2513 Generating Prerequisites Automatically
    2514 ======================================
     28254.14 Generating Prerequisites Automatically
     2826===========================================
    25152827
    25162828In the makefile for a program, many of the rules you need to write often
     
    25242836would have to write dozens of such rules in your makefile.  And, you
    25252837must always be very careful to update the makefile every time you add
    2526 or remove an `#include'.
     2838or remove an `#include'. 
    25272839
    25282840   To avoid this hassle, most modern C compilers can write these rules
     
    25432855makefile, so it can never be considered an intermediate file by implicit
    25442856rule search.  This means that `make' won't ever remove the file after
    2545 using it; *note Chains of Implicit Rules: Chained Rules..
     2857using it; *note Chains of Implicit Rules: Chained Rules.
    25462858
    25472859   With old `make' programs, it was traditional practice to use this
     
    25672879
    25682880     %.d: %.c
    2569              
     2881             @set -e; rm -f $@; \
    25702882              $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
    25712883              sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
     
    25742886*Note Pattern Rules::, for information on defining pattern rules.  The
    25752887`-e' flag to the shell causes it to exit immediately if the `$(CC)'
    2576 command (or any other command) fails (exits with a nonzero status).
     2888command (or any other command) fails (exits with a nonzero status). 
    25772889
    25782890   With the GNU C compiler, you may wish to use the `-MM' flag instead
     
    25992911
    26002912     sources = foo.c bar.c
    2601      
     2913
    26022914     include $(sources:.c=.d)
    26032915
     
    26102922
    26112923   Note that the `.d' files contain target definitions; you should be
    2612 sure to place the `include' directive _after_ the first, default target
     2924sure to place the `include' directive _after_ the first, default goal
    26132925in your makefiles or run the risk of having a random object file become
    2614 the default target.  *Note How Make Works::.
     2926the default goal.  *Note How Make Works::.
    26152927
    26162928
    26172929File: make.info,  Node: Commands,  Next: Using Variables,  Prev: Rules,  Up: Top
    26182930
    2619 Writing the Commands in Rules
    2620 *****************************
    2621 
    2622 The commands of a rule consist of shell command lines to be executed one
    2623 by one.  Each command line must start with a tab, except that the first
    2624 command line may be attached to the target-and-prerequisites line with a
    2625 semicolon in between.  Blank lines and lines of just comments may appear
    2626 among the command lines; they are ignored.  (But beware, an apparently
    2627 "blank" line that begins with a tab is _not_ blank!  It is an empty
    2628 command; *note Empty Commands::.)
     29315 Writing the Commands in Rules
     2932*******************************
     2933
     2934The commands of a rule consist of one or more shell command lines to be
     2935executed, one at a time, in the order they appear.  Typically, the
     2936result of executing these commands is that the target of the rule is
     2937brought up to date.
    26292938
    26302939   Users use many different shell programs, but commands in makefiles
     
    26322941otherwise.  *Note Command Execution: Execution.
    26332942
    2634    The shell that is in use determines whether comments can be written
    2635 on command lines, and what syntax they use.  When the shell is
    2636 `/bin/sh', a `#' starts a comment that extends to the end of the line.
    2637 The `#' does not have to be at the beginning of a line.  Text on a line
    2638 before a `#' is not part of the comment.
    2639 
    26402943* Menu:
    26412944
     2945* Command Syntax::              Command syntax features and pitfalls.
    26422946* Echoing::                     How to control when commands are echoed.
    26432947* Execution::                   How commands are executed.
     
    26502954
    26512955
    2652 File: make.info,  Node: Echoing,  Next: Execution,  Prev: Commands,  Up: Commands
    2653 
    2654 Command Echoing
    2655 ===============
     2956File: make.info,  Node: Command Syntax,  Next: Echoing,  Prev: Commands,  Up: Commands
     2957
     29585.1 Command Syntax
     2959==================
     2960
     2961Makefiles have the unusual property that there are really two distinct
     2962syntaxes in one file.  Most of the makefile uses `make' syntax (*note
     2963Writing Makefiles: Makefiles.).  However, commands are meant to be
     2964interpreted by the shell and so they are written using shell syntax.
     2965The `make' program does not try to understand shell syntax: it performs
     2966only a very few specific translations on the content of the command
     2967before handing it to the shell.
     2968
     2969   Each command line must start with a tab, except that the first
     2970command line may be attached to the target-and-prerequisites line with a
     2971semicolon in between.  _Any_ line in the makefile that begins with a
     2972tab and appears in a "rule context" (that is, after a rule has been
     2973started until another rule or variable definition) will be considered a
     2974command line for that rule.  Blank lines and lines of just comments may
     2975appear among the command lines; they are ignored.
     2976
     2977   Some consequences of these rules include:
     2978
     2979   * A blank line that begins with a tab is not blank: it's an empty
     2980     command (*note Empty Commands::).
     2981
     2982   * A comment in a command line is not a `make' comment; it will be
     2983     passed to the shell as-is.  Whether the shell treats it as a
     2984     comment or not depends on your shell.
     2985
     2986   * A variable definition in a "rule context" which is indented by a
     2987     tab as the first character on the line, will be considered a
     2988     command line, not a `make' variable definition, and passed to the
     2989     shell.
     2990
     2991   * A conditional expression (`ifdef', `ifeq', etc. *note Syntax of
     2992     Conditionals: Conditional Syntax.) in a "rule context" which is
     2993     indented by a tab as the first character on the line, will be
     2994     considered a command line and be passed to the shell.
     2995
     2996
     2997* Menu:
     2998
     2999* Splitting Lines::             Breaking long command lines for readability.
     3000* Variables in Commands::       Using `make' variables in commands.
     3001
     3002
     3003File: make.info,  Node: Splitting Lines,  Next: Variables in Commands,  Prev: Command Syntax,  Up: Command Syntax
     3004
     30055.1.1 Splitting Command Lines
     3006-----------------------------
     3007
     3008One of the few ways in which `make' does interpret command lines is
     3009checking for a backslash just before the newline.  As in normal
     3010makefile syntax, a single command can be split into multiple lines in
     3011the makefile by placing a backslash before each newline.  A sequence of
     3012lines like this is considered a single command, and one instance of the
     3013shell will be invoked to run it.
     3014
     3015   However, in contrast to how they are treated in other places in a
     3016makefile, backslash-newline pairs are _not_ removed from the command.
     3017Both the backslash and the newline characters are preserved and passed
     3018to the shell.  How the backslash-newline is interpreted depends on your
     3019shell.  If the first character of the next line after the
     3020backslash-newline is a tab, then that tab (and only that tab) is
     3021removed.  Whitespace is never added to the command.
     3022
     3023   For example, this makefile:
     3024
     3025     all :
     3026             @echo no\
     3027     space
     3028             @echo no\
     3029             space
     3030             @echo one \
     3031             space
     3032             @echo one\
     3033              space
     3034
     3035consists of four separate shell commands where the output is:
     3036
     3037     nospace
     3038     nospace
     3039     one space
     3040     one space
     3041
     3042   As a more complex example, this makefile:
     3043
     3044     all : ; @echo 'hello \
     3045             world' ; echo "hello \
     3046         world"
     3047
     3048will run one shell with a command script of:
     3049
     3050     echo 'hello \
     3051     world' ; echo "hello \
     3052         world"
     3053
     3054which, according to shell quoting rules, will yield the following
     3055output:
     3056
     3057     hello \
     3058     world
     3059     hello     world
     3060
     3061Notice how the backslash/newline pair was removed inside the string
     3062quoted with double quotes (`"..."'), but not from the string quoted
     3063with single quotes (`'...'').  This is the way the default shell
     3064(`/bin/sh') handles backslash/newline pairs.  If you specify a
     3065different shell in your makefiles it may treat them differently.
     3066
     3067   Sometimes you want to split a long line inside of single quotes, but
     3068you don't want the backslash-newline to appear in the quoted content.
     3069This is often the case when passing scripts to languages such as Perl,
     3070where extraneous backslashes inside the script can change its meaning
     3071or even be a syntax error.  One simple way of handling this is to place
     3072the quoted string, or even the entire command, into a `make' variable
     3073then use the variable in the command.  In this situation the newline
     3074quoting rules for makefiles will be used, and the backslash-newline
     3075will be removed.  If we rewrite our example above using this method:
     3076
     3077     HELLO = 'hello \
     3078     world'
     3079
     3080     all : ; @echo $(HELLO)
     3081
     3082we will get output like this:
     3083
     3084     hello world
     3085
     3086   If you like, you can also use target-specific variables (*note
     3087Target-specific Variable Values: Target-specific.) to obtain a tighter
     3088correspondence between the variable and the command that uses it.
     3089
     3090
     3091File: make.info,  Node: Variables in Commands,  Prev: Splitting Lines,  Up: Command Syntax
     3092
     30935.1.2 Using Variables in Commands
     3094---------------------------------
     3095
     3096The other way in which `make' processes commands is by expanding any
     3097variable references in them (*note Basics of Variable References:
     3098Reference.).  This occurs after make has finished reading all the
     3099makefiles and the target is determined to be out of date; so, the
     3100commands for targets which are not rebuilt are never expanded.
     3101
     3102   Variable and function references in commands have identical syntax
     3103and semantics to references elsewhere in the makefile.  They also have
     3104the same quoting rules: if you want a dollar sign to appear in your
     3105command, you must double it (`$$').  For shells like the default shell,
     3106that use dollar signs to introduce variables, it's important to keep
     3107clear in your mind whether the variable you want to reference is a
     3108`make' variable (use a single dollar sign) or a shell variable (use two
     3109dollar signs).  For example:
     3110
     3111     LIST = one two three
     3112     all:
     3113             for i in $(LIST); do \
     3114                 echo $$i; \
     3115             done
     3116
     3117results in the following command being passed to the shell:
     3118
     3119     for i in one two three; do \
     3120         echo $i; \
     3121     done
     3122
     3123which generates the expected result:
     3124
     3125     one
     3126     two
     3127     three
     3128
     3129
     3130File: make.info,  Node: Echoing,  Next: Execution,  Prev: Command Syntax,  Up: Commands
     3131
     31325.2 Command Echoing
     3133===================
    26563134
    26573135Normally `make' prints each command line before it is executed.  We
     
    26823160File: make.info,  Node: Execution,  Next: Parallel,  Prev: Echoing,  Up: Commands
    26833161
    2684 Command Execution
    2685 =================
     31625.3 Command Execution
     3163=====================
    26863164
    26873165When it is time to execute commands to update a target, they are
    2688 executed by making a new subshell for each line.  (In practice, `make'
    2689 may take shortcuts that do not affect the results.)
    2690 
    2691    *Please note:* this implies that shell commands such as `cd' that
    2692 set variables local to each process will not affect the following
    2693 command lines. (1)  If you want to use `cd' to affect the next command,
    2694 put the two on a single line with a semicolon between them.  Then
    2695 `make' will consider them a single command and pass them, together, to
    2696 a shell which will execute them in sequence.  For example:
     3166executed by invoking a new subshell for each command line.  (In
     3167practice, `make' may take shortcuts that do not affect the results.)
     3168
     3169   *Please note:* this implies that setting shell variables and
     3170invoking shell commands such as `cd' that set a context local to each
     3171process will not affect the following command lines.(1)  If you want to
     3172use `cd' to affect the next statement, put both statements in a single
     3173command line.  Then `make' will invoke one shell to run the entire
     3174line, and the shell will execute the statements in sequence.  For
     3175example:
    26973176
    26983177     foo : bar/lose
    2699              cd bar; gobble lose > ../foo
    2700 
    2701    If you would like to split a single shell command into multiple
    2702 lines of text, you must use a backslash at the end of all but the last
    2703 subline.  Such a sequence of lines is combined into a single line, by
    2704 deleting the backslash-newline sequences, before passing it to the
    2705 shell.  Thus, the following is equivalent to the preceding example:
    2706 
    2707      foo : bar/lose
    2708              cd bar;  \
    2709              gobble lose > ../foo
    2710 
    2711    The program used as the shell is taken from the variable `SHELL'.
    2712 By default, the program `/bin/sh' is used.
     3178             cd $(@D) && gobble $(@F) > ../$@
     3179
     3180Here we use the shell AND operator (`&&') so that if the `cd' command
     3181fails, the script will fail without trying to invoke the `gobble'
     3182command in the wrong directory, which could cause problems (in this
     3183case it would certainly cause `../foo' to be truncated, at least).
     3184
     3185* Menu:
     3186
     3187* Choosing the Shell::          How `make' chooses the shell used
     3188                                  to run commands.
     3189
     3190   ---------- Footnotes ----------
     3191
     3192   (1) On MS-DOS, the value of current working directory is *global*, so
     3193changing it _will_ affect the following command lines on those systems.
     3194
     3195
     3196File: make.info,  Node: Choosing the Shell,  Prev: Execution,  Up: Execution
     3197
     31985.3.1 Choosing the Shell
     3199------------------------
     3200
     3201The program used as the shell is taken from the variable `SHELL'.  If
     3202this variable is not set in your makefile, the program `/bin/sh' is
     3203used as the shell.
     3204
     3205   Unlike most variables, the variable `SHELL' is never set from the
     3206environment.  This is because the `SHELL' environment variable is used
     3207to specify your personal choice of shell program for interactive use.
     3208It would be very bad for personal choices like this to affect the
     3209functioning of makefiles.  *Note Variables from the Environment:
     3210Environment.
     3211
     3212   Furthermore, when you do set `SHELL' in your makefile that value is
     3213_not_ exported in the environment to commands that `make' invokes.
     3214Instead, the value inherited from the user's environment, if any, is
     3215exported.  You can override this behavior by explicitly exporting
     3216`SHELL' (*note Communicating Variables to a Sub-`make':
     3217Variables/Recursion.), forcing it to be passed in the environment to
     3218commands.
     3219
     3220   However, on MS-DOS and MS-Windows the value of `SHELL' in the
     3221environment *is* used, since on those systems most users do not set
     3222this variable, and therefore it is most likely set specifically to be
     3223used by `make'.  On MS-DOS, if the setting of `SHELL' is not suitable
     3224for `make', you can set the variable `MAKESHELL' to the shell that
     3225`make' should use; if set it will be used as the shell instead of the
     3226value of `SHELL'.
     3227
     3228Choosing a Shell in DOS and Windows
     3229...................................
     3230
     3231Choosing a shell in MS-DOS and MS-Windows is much more complex than on
     3232other systems.
    27133233
    27143234   On MS-DOS, if `SHELL' is not set, the value of the variable
     
    27563276
    27573277   The effect of the above DOS-specific processing is that a Makefile
    2758 that says `SHELL = /bin/sh' (as many Unix makefiles do), will work on
    2759 MS-DOS unaltered if you have e.g. `sh.exe' installed in some directory
    2760 along your `PATH'.
    2761 
    2762    Unlike most variables, the variable `SHELL' is never set from the
    2763 environment.  This is because the `SHELL' environment variable is used
    2764 to specify your personal choice of shell program for interactive use.
    2765 It would be very bad for personal choices like this to affect the
    2766 functioning of makefiles.  *Note Variables from the Environment:
    2767 Environment.  However, on MS-DOS and MS-Windows the value of `SHELL' in
    2768 the environment *is* used, since on those systems most users do not set
    2769 this variable, and therefore it is most likely set specifically to be
    2770 used by `make'.  On MS-DOS, if the setting of `SHELL' is not suitable
    2771 for `make', you can set the variable `MAKESHELL' to the shell that
    2772 `make' should use; this will override the value of `SHELL'.
    2773 
    2774    ---------- Footnotes ----------
    2775 
    2776    (1) On MS-DOS, the value of current working directory is *global*,
    2777 so changing it _will_ affect the following command lines on those
    2778 systems.
     3278that contains `SHELL = /bin/sh' (as many Unix makefiles do), will work
     3279on MS-DOS unaltered if you have e.g. `sh.exe' installed in some
     3280directory along your `PATH'.
    27793281
    27803282
    27813283File: make.info,  Node: Parallel,  Next: Errors,  Prev: Execution,  Up: Commands
    27823284
    2783 Parallel Execution
    2784 ==================
     32855.4 Parallel Execution
     3286======================
    27853287
    27863288GNU `make' knows how to execute several commands at once.  Normally,
     
    28083310streams of all but one running command.  This means that attempting to
    28093311read from standard input will usually be a fatal error (a `Broken pipe'
    2810 signal) for most child processes if there are several.
     3312signal) for most child processes if there are several. 
    28113313
    28123314   It is unpredictable which command will have a valid standard input
     
    28573359File: make.info,  Node: Errors,  Next: Interrupts,  Prev: Parallel,  Up: Commands
    28583360
    2859 Errors in Commands
    2860 ==================
     33615.5 Errors in Commands
     3362======================
    28613363
    28623364After each shell command returns, `make' looks at its exit status.  If
     
    29163418program as possible, perhaps to find several independent problems so
    29173419that you can correct them all before the next attempt to compile.  This
    2918 is why Emacs' `compile' command passes the `-k' flag by default.
     3420is why Emacs' `compile' command passes the `-k' flag by default. 
    29193421
    29203422   Usually when a command fails, if it has changed the target file at
     
    29333435File: make.info,  Node: Interrupts,  Next: Recursion,  Prev: Errors,  Up: Commands
    29343436
    2935 Interrupting or Killing `make'
    2936 ==============================
     34375.6 Interrupting or Killing `make'
     3438==================================
    29373439
    29383440If `make' gets a fatal signal while a command is executing, it may
     
    29643466File: make.info,  Node: Recursion,  Next: Sequences,  Prev: Interrupts,  Up: Commands
    29653467
    2966 Recursive Use of `make'
    2967 =======================
     34685.7 Recursive Use of `make'
     3469===========================
    29683470
    29693471Recursive use of `make' means using `make' as a command in a makefile.
     
    29813483     subsystem:
    29823484             $(MAKE) -C subdir
    2983 
     3485   
    29843486   You can write recursive `make' commands just by copying this example,
    29853487but there are many things to know about how they work and why, and about
     
    30113513File: make.info,  Node: MAKE Variable,  Next: Variables/Recursion,  Prev: Recursion,  Up: Recursion
    30123514
    3013 How the `MAKE' Variable Works
    3014 -----------------------------
     35155.7.1 How the `MAKE' Variable Works
     3516-----------------------------------
    30153517
    30163518Recursive `make' commands should always use the variable `MAKE', not
     
    30243526is `cd subdir && /bin/make'.  If you use a special version of `make' to
    30253527run the top-level makefile, the same special version will be executed
    3026 for recursive invocations.
     3528for recursive invocations. 
    30273529
    30283530   As a special feature, using the variable `MAKE' in the commands of a
     
    30423544file named `subsystem' and do nothing else.  What you really want it to
    30433545do is run `cd subdir && make -t'; but that would require executing the
    3044 command, and `-t' says not to execute commands.
     3546command, and `-t' says not to execute commands. 
    30453547
    30463548   The special feature makes this do what you want: whenever a command
     
    30563558File: make.info,  Node: Variables/Recursion,  Next: Options/Recursion,  Prev: MAKE Variable,  Up: Recursion
    30573559
    3058 Communicating Variables to a Sub-`make'
    3059 ---------------------------------------
     35605.7.2 Communicating Variables to a Sub-`make'
     3561---------------------------------------------
    30603562
    30613563Variable values of the top-level `make' can be passed to the sub-`make'
     
    30763578characters other than letters, numbers, and underscores.
    30773579
    3078    The special variables `SHELL' and `MAKEFLAGS' are always exported
    3079 (unless you unexport them).  `MAKEFILES' is exported if you set it to
    3080 anything.
     3580   The value of the `make' variable `SHELL' is not exported.  Instead,
     3581the value of the `SHELL' variable from the invoking environment is
     3582passed to the sub-`make'.  You can force `make' to export its value for
     3583`SHELL' by using the `export' directive, described below.  *Note
     3584Choosing the Shell::.
     3585
     3586   The special variable `MAKEFLAGS' is always exported (unless you
     3587unexport it).  `MAKEFILES' is exported if you set it to anything.
    30813588
    30823589   `make' automatically passes down variable values that were defined
     
    31533660`.EXPORT_ALL_VARIABLES' instead of using the `export' directive.  This
    31543661will be ignored by old `make's, while the `export' directive will cause
    3155 a syntax error.
     3662a syntax error. 
    31563663
    31573664   Likewise, you can use `unexport' by itself to tell `make' _not_ to
     
    31863693File: make.info,  Node: Options/Recursion,  Next: -w Option,  Prev: Variables/Recursion,  Up: Recursion
    31873694
    3188 Communicating Options to a Sub-`make'
    3189 -------------------------------------
     36955.7.3 Communicating Options to a Sub-`make'
     3696-------------------------------------------
    31903697
    31913698Flags such as `-s' and `-k' are passed automatically to the sub-`make'
     
    32913798File: make.info,  Node: -w Option,  Prev: Options/Recursion,  Up: Recursion
    32923799
    3293 The `--print-directory' Option
    3294 ------------------------------
     38005.7.4 The `--print-directory' Option
     3801------------------------------------
    32953802
    32963803If you use several levels of recursive `make' invocations, the `-w' or
     
    33173824File: make.info,  Node: Sequences,  Next: Empty Commands,  Prev: Recursion,  Up: Commands
    33183825
    3319 Defining Canned Command Sequences
    3320 =================================
     38265.8 Defining Canned Command Sequences
     3827=====================================
    33213828
    33223829When the same sequence of commands is useful in making various targets,
     
    33323839     mv y.tab.c $@
    33333840     endef
    3334 
     3841   
    33353842Here `run-yacc' is the name of the variable being defined; `endef'
    33363843marks the end of the definition; the lines in between are the commands.
     
    33923899File: make.info,  Node: Empty Commands,  Prev: Sequences,  Up: Commands
    33933900
    3394 Using Empty Commands
    3395 ====================
     39015.9 Using Empty Commands
     3902========================
    33963903
    33973904It is sometimes useful to define commands which do nothing.  This is
     
    34213928File: make.info,  Node: Using Variables,  Next: Conditionals,  Prev: Commands,  Up: Top
    34223929
    3423 How to Use Variables
    3424 ********************
     39306 How to Use Variables
     3931**********************
    34253932
    34263933A "variable" is a name defined in a makefile to represent a string of
     
    34283935explicit request into targets, prerequisites, commands, and other parts
    34293936of the makefile.  (In some other versions of `make', variables are
    3430 called "macros".)
     3937called "macros".) 
    34313938
    34323939   Variables and functions in all parts of a makefile are expanded when
     
    34833990File: make.info,  Node: Reference,  Next: Flavors,  Prev: Using Variables,  Up: Using Variables
    34843991
    3485 Basics of Variable References
    3486 =============================
     39926.1 Basics of Variable References
     3993=================================
    34873994
    34883995To substitute a variable's value, write a dollar sign followed by the
     
    35004007     program : $(objects)
    35014008             cc -o program $(objects)
    3502      
     4009
    35034010     $(objects) : defs.h
    35044011
     
    35234030File: make.info,  Node: Flavors,  Next: Advanced,  Prev: Reference,  Up: Using Variables
    35244031
    3525 The Two Flavors of Variables
    3526 ============================
     40326.2 The Two Flavors of Variables
     4033================================
    35274034
    35284035There are two ways that a variable in GNU `make' can have a value; we
     
    35444051     bar = $(ugh)
    35454052     ugh = Huh?
    3546      
     4053
    35474054     all:;echo $(foo)
    35484055
     
    35644071
    35654072because it will cause an infinite loop in the variable expansion.
    3566 (Actually `make' detects the infinite loop and reports an error.)
     4073(Actually `make' detects the infinite loop and reports an error.) 
    35674074
    35684075   Another disadvantage is that any functions (*note Functions for
     
    36054112
    36064113     ifeq (0,${MAKELEVEL})
    3607      cur-dir   := $(shell pwd)
    36084114     whoami    := $(shell whoami)
    36094115     host-type := $(shell arch)
     
    36154121
    36164122     ${subdirs}:
    3617            ${MAKE} cur-dir=${cur-dir}/$@ -C $@ all
     4123             ${MAKE} -C $@ all
    36184124
    36194125   Simply expanded variables generally make complicated makefile
     
    36694175File: make.info,  Node: Advanced,  Next: Values,  Prev: Flavors,  Up: Using Variables
    36704176
    3671 Advanced Features for Reference to Variables
    3672 ============================================
     41776.3 Advanced Features for Reference to Variables
     4178================================================
    36734179
    36744180This section describes some advanced features you can use to reference
     
    36844190File: make.info,  Node: Substitution Refs,  Next: Computed Names,  Prev: Advanced,  Up: Advanced
    36854191
    3686 Substitution References
    3687 -----------------------
     41926.3.1 Substitution References
     4193-----------------------------
    36884194
    36894195A "substitution reference" substitutes the value of a variable with
     
    37174223
    37184224For example:
    3719      
     4225
    37204226     foo := a.o b.o c.o
    37214227     bar := $(foo:%.o=%.c)
     
    37264232File: make.info,  Node: Computed Names,  Prev: Substitution Refs,  Up: Advanced
    37274233
    3728 Computed Variable Names
    3729 -----------------------
     42346.3.2 Computed Variable Names
     4235-----------------------------
    37304236
    37314237Computed variable names are a complicated concept needed only for
     
    37984304     a_dirs := dira dirb
    37994305     1_dirs := dir1 dir2
    3800      
     4306
    38014307     a_files := filea fileb
    38024308     1_files := file1 file2
    3803      
     4309
    38044310     ifeq "$(use_a)" "yes"
    38054311     a1 := a
     
    38074313     a1 := 1
    38084314     endif
    3809      
     4315
    38104316     ifeq "$(use_dirs)" "yes"
    38114317     df := dirs
     
    38134319     df := files
    38144320     endif
    3815      
     4321
    38164322     dirs := $($(a1)_$(df))
    38174323
     
    38234329     a_objects := a.o b.o c.o
    38244330     1_objects := 1.o 2.o 3.o
    3825      
     4331
    38264332     sources := $($(a1)_objects:.o=.c)
    38274333
     
    38394345     func := strip
    38404346     endif
    3841      
     4347
    38424348     bar := a d b g q c
    3843      
     4349
    38444350     foo := $($(func) $(bar))
    38454351
     
    38694375File: make.info,  Node: Values,  Next: Setting,  Prev: Advanced,  Up: Using Variables
    38704376
    3871 How Variables Get Their Values
    3872 ==============================
     43776.4 How Variables Get Their Values
     4378==================================
    38734379
    38744380Variables can get values in several different ways:
     
    38944400File: make.info,  Node: Setting,  Next: Appending,  Prev: Values,  Up: Using Variables
    38954401
    3896 Setting Variables
    3897 =================
     44026.5 Setting Variables
     4403=====================
    38984404
    38994405To set a variable from the makefile, write a line starting with the
     
    39474453File: make.info,  Node: Appending,  Next: Override Directive,  Prev: Setting,  Up: Using Variables
    39484454
    3949 Appending More Text to Variables
    3950 ================================
     44556.6 Appending More Text to Variables
     4456====================================
    39514457
    39524458Often it is useful to add more text to the value of a variable already
     
    39834489it a simply-expanded variable, `+=' adds to that simply-expanded
    39844490definition, and expands the new text before appending it to the old
    3985 value just as `:=' does (*note Setting Variables: Setting., for a full
    3986 explanation of `:=').  In fact,
     4491value just as `:=' does (see *Note Setting Variables: Setting, for a
     4492full explanation of `:=').  In fact,
    39874493
    39884494     variable := value
     
    39904496
    39914497is exactly equivalent to:
     4498
    39924499
    39934500     variable := value
     
    40224529The first line defines the `CFLAGS' variable with a reference to another
    40234530variable, `includes'.  (`CFLAGS' is used by the rules for C
    4024 compilation; *note Catalogue of Implicit Rules: Catalogue of Rules..)
     4531compilation; *note Catalogue of Implicit Rules: Catalogue of Rules.)
    40254532Using `=' for the definition makes `CFLAGS' a recursively-expanded
    40264533variable, meaning `$(includes) -O' is _not_ expanded when `make'
     
    40444551File: make.info,  Node: Override Directive,  Next: Defining,  Prev: Appending,  Up: Using Variables
    40454552
    4046 The `override' Directive
    4047 ========================
     45536.7 The `override' Directive
     4554============================
    40484555
    40494556If a variable has been set with a command argument (*note Overriding
     
    40884595File: make.info,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Using Variables
    40894596
    4090 Defining Variables Verbatim
    4091 ===========================
     45976.8 Defining Variables Verbatim
     4598===============================
    40924599
    40934600Another way to set the value of a variable is to use the `define'
     
    41474654File: make.info,  Node: Environment,  Next: Target-specific,  Prev: Defining,  Up: Using Variables
    41484655
    4149 Variables from the Environment
    4150 ==============================
     46566.9 Variables from the Environment
     4657==================================
    41514658
    41524659Variables in `make' can come from the environment in which `make' is
    41534660run.  Every environment variable that `make' sees when it starts up is
    4154 transformed into a `make' variable with the same name and value.  But
    4155 an explicit assignment in the makefile, or with a command argument,
    4156 overrides the environment.  (If the `-e' flag is specified, then values
    4157 from the environment override assignments in the makefile.  *Note
    4158 Summary of Options: Options Summary.  But this is not recommended
     4661transformed into a `make' variable with the same name and value.
     4662However, an explicit assignment in the makefile, or with a command
     4663argument, overrides the environment.  (If the `-e' flag is specified,
     4664then values from the environment override assignments in the makefile.
     4665*Note Summary of Options: Options Summary.  But this is not recommended
    41594666practice.)
    41604667
     
    41634670you prefer.  This is safe for variables with standard or conventional
    41644671meanings because you know that no makefile will use them for other
    4165 things.  (But this is not totally reliable; some makefiles set `CFLAGS'
    4166 explicitly and therefore are not affected by the value in the
     4672things.  (Note this is not totally reliable; some makefiles set
     4673`CFLAGS' explicitly and therefore are not affected by the value in the
    41674674environment.)
    41684675
    4169    When `make' is invoked recursively, variables defined in the outer
    4170 invocation can be passed to inner invocations through the environment
    4171 (*note Recursive Use of `make': Recursion.).  By default, only
    4172 variables that came from the environment or the command line are passed
    4173 to recursive invocations.  You can use the `export' directive to pass
    4174 other variables.  *Note Communicating Variables to a Sub-`make':
    4175 Variables/Recursion, for full details.
     4676   When `make' runs a command script, variables defined in the makefile
     4677are placed into the environment of that command.  This allows you to
     4678pass values to sub-`make' invocations (*note Recursive Use of `make':
     4679Recursion.).  By default, only variables that came from the environment
     4680or the command line are passed to recursive invocations.  You can use
     4681the `export' directive to pass other variables.  *Note Communicating
     4682Variables to a Sub-`make': Variables/Recursion, for full details.
    41764683
    41774684   Other use of variables from the environment is not recommended.  It
     
    41844691which is normally present in the environment to specify the user's
    41854692choice of interactive shell.  It would be very undesirable for this
    4186 choice to affect `make'.  So `make' ignores the environment value of
    4187 `SHELL' (except on MS-DOS and MS-Windows, where `SHELL' is usually not
    4188 set.  *Note Special handling of SHELL on MS-DOS: Execution.)
     4693choice to affect `make'; so, `make' handles the `SHELL' environment
     4694variable in a special way; see *Note Choosing the Shell::.
    41894695
    41904696
    41914697File: make.info,  Node: Target-specific,  Next: Pattern-specific,  Prev: Environment,  Up: Using Variables
    41924698
    4193 Target-specific Variable Values
    4194 ===============================
     46996.10 Target-specific Variable Values
     4700====================================
    41954701
    41964702Variable values in `make' are usually global; that is, they are the
     
    42614767File: make.info,  Node: Pattern-specific,  Prev: Target-specific,  Up: Using Variables
    42624768
    4263 Pattern-specific Variable Values
    4264 ================================
     47696.11 Pattern-specific Variable Values
     4770=====================================
    42654771
    42664772In addition to target-specific variable values (*note Target-specific
     
    42994805File: make.info,  Node: Conditionals,  Next: Functions,  Prev: Using Variables,  Up: Top
    43004806
    4301 Conditional Parts of Makefiles
    4302 ******************************
     48077 Conditional Parts of Makefiles
     4808********************************
    43034809
    43044810A "conditional" causes part of a makefile to be obeyed or ignored
     
    43184824File: make.info,  Node: Conditional Example,  Next: Conditional Syntax,  Prev: Conditionals,  Up: Conditionals
    43194825
    4320 Example of a Conditional
    4321 ========================
     48267.1 Example of a Conditional
     4827============================
    43224828
    43234829The following example of a conditional tells `make' to use one set of
     
    43304836     libs_for_gcc = -lgnu
    43314837     normal_libs =
    4332      
     4838
    43334839     foo: $(objects)
    43344840     ifeq ($(CC),gcc)
     
    43804886     libs_for_gcc = -lgnu
    43814887     normal_libs =
    4382      
     4888
    43834889     ifeq ($(CC),gcc)
    43844890       libs=$(libs_for_gcc)
     
    43864892       libs=$(normal_libs)
    43874893     endif
    4388      
     4894
    43894895     foo: $(objects)
    43904896             $(CC) -o foo $(objects) $(libs)
     
    43934899File: make.info,  Node: Conditional Syntax,  Next: Testing Flags,  Prev: Conditional Example,  Up: Conditionals
    43944900
    4395 Syntax of Conditionals
    4396 ======================
     49017.2 Syntax of Conditionals
     4902==========================
    43974903
    43984904The syntax of a simple conditional with no `else' is as follows:
     
    44144920     endif
    44154921
    4416 If the condition is true, TEXT-IF-TRUE is used; otherwise,
    4417 TEXT-IF-FALSE is used instead.  The TEXT-IF-FALSE can be any number of
    4418 lines of text.
     4922   or:
     4923
     4924     CONDITIONAL-DIRECTIVE
     4925     TEXT-IF-ONE-IS-TRUE
     4926     else CONDITIONAL-DIRECTIVE
     4927     TEXT-IF-TRUE
     4928     else
     4929     TEXT-IF-FALSE
     4930     endif
     4931
     4932There can be as many "`else' CONDITIONAL-DIRECTIVE" clauses as
     4933necessary.  Once a given condition is true, TEXT-IF-TRUE is used and no
     4934other clause is used; if no condition is true then TEXT-IF-FALSE is
     4935used.  The TEXT-IF-TRUE and TEXT-IF-FALSE can be any number of lines of
     4936text.
    44194937
    44204938   The syntax of the CONDITIONAL-DIRECTIVE is the same whether the
    4421 conditional is simple or complex.  There are four different directives
    4422 that test different conditions.  Here is a table of them:
     4939conditional is simple or complex; after an `else' or not.  There are
     4940four different directives that test different conditions.  Here is a
     4941table of them:
    44234942
    44244943`ifeq (ARG1, ARG2)'
     
    44564975
    44574976`ifdef VARIABLE-NAME'
    4458      If the variable VARIABLE-NAME has a non-empty value, the
    4459      TEXT-IF-TRUE is effective; otherwise, the TEXT-IF-FALSE, if any,
    4460      is effective.  Variables that have never been defined have an
    4461      empty value.  The variable VARIABLE-NAME is itself expanded, so it
    4462      could be a variable or function that expands to the name of a
    4463      variable.
     4977     The `ifdef' form takes the _name_ of a variable as its argument,
     4978     not a reference to a variable.  The value of that variable has a
     4979     non-empty value, the TEXT-IF-TRUE is effective; otherwise, the
     4980     TEXT-IF-FALSE, if any, is effective.  Variables that have never
     4981     been defined have an empty value.  The text VARIABLE-NAME is
     4982     expanded, so it could be a variable or function that expands to
     4983     the name of a variable.  For example:
     4984
     4985          bar = true
     4986          foo = bar
     4987          ifdef $(foo)
     4988          frobozz = yes
     4989          endif
     4990
     4991     The variable reference `$(foo)' is expanded, yielding `bar', which
     4992     is considered to be the name of a variable.  The variable `bar' is
     4993     not expanded, but its value is examined to determine if it is
     4994     non-empty.
    44644995
    44654996     Note that `ifdef' only tests whether a variable has a value.  It
     
    44915022     If the variable VARIABLE-NAME has an empty value, the TEXT-IF-TRUE
    44925023     is effective; otherwise, the TEXT-IF-FALSE, if any, is effective.
     5024     The rules for expansion and testing of VARIABLE-NAME are identical
     5025     to the `ifdef' directive.
    44935026
    44945027   Extra spaces are allowed and ignored at the beginning of the
     
    45255058File: make.info,  Node: Testing Flags,  Prev: Conditional Syntax,  Up: Conditionals
    45265059
    4527 Conditionals that Test Flags
    4528 ============================
     50607.3 Conditionals that Test Flags
     5061================================
    45295062
    45305063You can write a conditional that tests `make' command flags such as
     
    45565089File: make.info,  Node: Functions,  Next: Running,  Prev: Conditionals,  Up: Top
    45575090
    4558 Functions for Transforming Text
    4559 *******************************
     50918 Functions for Transforming Text
     5092*********************************
    45605093
    45615094"Functions" allow you to do text processing in the makefile to compute
     
    45715104* Text Functions::              General-purpose text manipulation functions.
    45725105* File Name Functions::         Functions for manipulating file names.
     5106* Conditional Functions::       Functions that implement conditions.
    45735107* Foreach Function::            Repeat some text with controlled variation.
    4574 * If Function::                 Conditionally expand a value.
    45755108* Call Function::               Expand a user-defined function.
    45765109* Value Function::              Return the un-expanded value of a variable.
    45775110* Eval Function::               Evaluate the arguments as makefile syntax.
    45785111* Origin Function::             Find where a variable got its value.
     5112* Flavor Function::             Find out the flavor of a variable.
    45795113* Shell Function::              Substitute the output of a shell command.
    45805114* Make Control Functions::      Functions that control how make runs.
     
    45835117File: make.info,  Node: Syntax of Functions,  Next: Text Functions,  Prev: Functions,  Up: Functions
    45845118
    4585 Function Call Syntax
    4586 ====================
     51198.1 Function Call Syntax
     5120========================
    45875121
    45885122A function call resembles a variable reference.  It looks like this:
     
    46375171File: make.info,  Node: Text Functions,  Next: File Name Functions,  Prev: Syntax of Functions,  Up: Functions
    46385172
    4639 Functions for String Substitution and Analysis
    4640 ==============================================
     51738.2 Functions for String Substitution and Analysis
     5174==================================================
    46415175
    46425176Here are some functions that operate on strings:
     
    48035337`$(wordlist S,E,TEXT)'
    48045338     Returns the list of words in TEXT starting with word S and ending
    4805      with word E (inclusive).  The legitimate values of S and E start
    4806      from 1.  If S is bigger than the number of words in TEXT, the
    4807      value is empty.  If E is bigger than the number of words in TEXT,
    4808      words up to the end of TEXT are returned.  If S is greater than E,
    4809      nothing is returned.  For example,
     5339     with word E (inclusive).  The legitimate values of S start from 1;
     5340     E may start from 0.  If S is bigger than the number of words in
     5341     TEXT, the value is empty.  If E is bigger than the number of words
     5342     in TEXT, words up to the end of TEXT are returned.  If S is
     5343     greater than E, nothing is returned.  For example,
    48105344
    48115345          $(wordlist 2, 3, foo bar baz)
     
    48295363     same as `$(word 1,TEXT)', the `firstword' function is retained for
    48305364     its simplicity.
     5365
     5366`$(lastword NAMES...)'
     5367     The argument NAMES is regarded as a series of names, separated by
     5368     whitespace.  The value is the last name in the series.
     5369
     5370     For example,
     5371
     5372          $(lastword foo bar)
     5373
     5374     produces the result `bar'.  Although `$(lastword TEXT)' is the
     5375     same as `$(word $(words TEXT),TEXT)', the `lastword' function was
     5376     added for its simplicity and better performance.
    48315377
    48325378   Here is a realistic example of the use of `subst' and `patsubst'.
     
    48575403
    48585404
    4859 File: make.info,  Node: File Name Functions,  Next: Foreach Function,  Prev: Text Functions,  Up: Functions
    4860 
    4861 Functions for File Names
    4862 ========================
     5405File: make.info,  Node: File Name Functions,  Next: Conditional Functions,  Prev: Text Functions,  Up: Functions
     5406
     54078.3 Functions for File Names
     5408============================
    48635409
    48645410Several of the built-in expansion functions relate specifically to
     
    49695515     File Names: Wildcards.
    49705516
    4971 
    4972 File: make.info,  Node: Foreach Function,  Next: If Function,  Prev: File Name Functions,  Up: Functions
    4973 
    4974 The `foreach' Function
    4975 ======================
     5517`$(realpath NAMES...)'
     5518     For each file name in NAMES return the canonical absolute name.  A
     5519     canonical name does not contain any `.' or `..' components, nor
     5520     any repeated path separators (`/') or symlinks.  In case of a
     5521     failure the empty string is returned.  Consult the `realpath(3)'
     5522     documentation for a list of possible failure causes.
     5523
     5524`$(abspath NAMES...)'
     5525     For each file name in NAMES return an absolute name that does not
     5526     contain any `.' or `..' components, nor any repeated path
     5527     separators (`/').  Note that, in contrast to `realpath' function,
     5528     `abspath' does not resolve symlinks and does not require the file
     5529     names to refer to an existing file or directory.  Use the
     5530     `wildcard' function to test for existence.
     5531
     5532
     5533File: make.info,  Node: Conditional Functions,  Next: Foreach Function,  Prev: File Name Functions,  Up: Functions
     5534
     55358.4 Functions for Conditionals
     5536==============================
     5537
     5538There are three functions that provide conditional expansion.  A key
     5539aspect of these functions is that not all of the arguments are expanded
     5540initially.  Only those arguments which need to be expanded, will be
     5541expanded.
     5542
     5543`$(if CONDITION,THEN-PART[,ELSE-PART])'
     5544     The `if' function provides support for conditional expansion in a
     5545     functional context (as opposed to the GNU `make' makefile
     5546     conditionals such as `ifeq' (*note Syntax of Conditionals:
     5547     Conditional Syntax.).
     5548
     5549     The first argument, CONDITION, first has all preceding and
     5550     trailing whitespace stripped, then is expanded.  If it expands to
     5551     any non-empty string, then the condition is considered to be true.
     5552     If it expands to an empty string, the condition is considered to
     5553     be false.
     5554
     5555     If the condition is true then the second argument, THEN-PART, is
     5556     evaluated and this is used as the result of the evaluation of the
     5557     entire `if' function.
     5558
     5559     If the condition is false then the third argument, ELSE-PART, is
     5560     evaluated and this is the result of the `if' function.  If there is
     5561     no third argument, the `if' function evaluates to nothing (the
     5562     empty string).
     5563
     5564     Note that only one of the THEN-PART or the ELSE-PART will be
     5565     evaluated, never both.  Thus, either can contain side-effects
     5566     (such as `shell' function calls, etc.)
     5567
     5568`$(or CONDITION1[,CONDITION2[,CONDITION3...]])'
     5569     The `or' function provides a "short-circuiting" OR operation.
     5570     Each argument is expanded, in order.  If an argument expands to a
     5571     non-empty string the processing stops and the result of the
     5572     expansion is that string.  If, after all arguments are expanded,
     5573     all of them are false (empty), then the result of the expansion is
     5574     the empty string.
     5575
     5576`$(and CONDITION1[,CONDITION2[,CONDITION3...]])'
     5577     The `and' function provides a "short-circuiting" AND operation.
     5578     Each argument is expanded, in order.  If an argument expands to an
     5579     empty string the processing stops and the result of the expansion
     5580     is the empty string.  If all arguments expand to a non-empty
     5581     string then the result of the expansion is the expansion of the
     5582     last argument.
     5583
     5584
     5585
     5586File: make.info,  Node: Foreach Function,  Next: Call Function,  Prev: Conditional Functions,  Up: Functions
     5587
     55888.5 The `foreach' Function
     5589==========================
    49765590
    49775591The `foreach' function is very different from other functions.  It
     
    50455659
    50465660
    5047 File: make.info,  Node: If Function,  Next: Call Function,  Prev: Foreach Function,  Up: Functions
    5048 
    5049 The `if' Function
    5050 =================
    5051 
    5052 The `if' function provides support for conditional expansion in a
    5053 functional context (as opposed to the GNU `make' makefile conditionals
    5054 such as `ifeq' (*note Syntax of Conditionals: Conditional Syntax.).
    5055 
    5056    An `if' function call can contain either two or three arguments:
    5057 
    5058      $(if CONDITION,THEN-PART[,ELSE-PART])
    5059 
    5060    The first argument, CONDITION, first has all preceding and trailing
    5061 whitespace stripped, then is expanded.  If it expands to any non-empty
    5062 string, then the condition is considered to be true.  If it expands to
    5063 an empty string, the condition is considered to be false.
    5064 
    5065    If the condition is true then the second argument, THEN-PART, is
    5066 evaluated and this is used as the result of the evaluation of the entire
    5067 `if' function.
    5068 
    5069    If the condition is false then the third argument, ELSE-PART, is
    5070 evaluated and this is the result of the `if' function.  If there is no
    5071 third argument, the `if' function evaluates to nothing (the empty
    5072 string).
    5073 
    5074    Note that only one of the THEN-PART or the ELSE-PART will be
    5075 evaluated, never both.  Thus, either can contain side-effects (such as
    5076 `shell' function calls, etc.)
    5077 
    5078 
    5079 File: make.info,  Node: Call Function,  Next: Value Function,  Prev: If Function,  Up: Functions
    5080 
    5081 The `call' Function
    5082 ===================
     5661File: make.info,  Node: Call Function,  Next: Value Function,  Prev: Foreach Function,  Up: Functions
     5662
     56638.6 The `call' Function
     5664=======================
    50835665
    50845666The `call' function is unique in that it can be used to create new
     
    51195701
    51205702     reverse = $(2) $(1)
    5121      
     5703
    51225704     foo = $(call reverse,a,b)
    51235705
     
    51285710
    51295711     pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
    5130      
     5712
    51315713     LS := $(call pathsearch,ls)
    51325714
     
    51565738File: make.info,  Node: Value Function,  Next: Eval Function,  Prev: Call Function,  Up: Functions
    51575739
    5158 The `value' Function
    5159 ====================
     57408.7 The `value' Function
     5741========================
    51605742
    51615743The `value' function provides a way for you to use the value of a
     
    51805762
    51815763     FOO = $PATH
    5182      
     5764
    51835765     all:
    51845766             @echo $(FOO)
     
    51965778File: make.info,  Node: Eval Function,  Next: Origin Function,  Prev: Value Function,  Up: Functions
    51975779
    5198 The `eval' Function
    5199 ===================
     57808.8 The `eval' Function
     5781=======================
    52005782
    52015783The `eval' function is very special: it allows you to define new
     
    52285810
    52295811     PROGRAMS    = server client
    5230      
     5812
    52315813     server_OBJS = server.o server_priv.o server_access.o
    52325814     server_LIBS = priv protocol
    5233      
     5815
    52345816     client_OBJS = client.o client_api.o client_mem.o
    52355817     client_LIBS = protocol
    5236      
     5818
    52375819     # Everything after this is generic
    5238      
     5820
    52395821     .PHONY: all
    52405822     all: $(PROGRAMS)
    5241      
     5823
    52425824     define PROGRAM_template
    52435825      $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%)
    52445826      ALL_OBJS   += $$($(1)_OBJS)
    52455827     endef
    5246      
     5828
    52475829     $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))
    5248      
     5830
    52495831     $(PROGRAMS):
    52505832             $(LINK.o) $^ $(LDLIBS) -o $@
    5251      
     5833
    52525834     clean:
    52535835             rm -f $(ALL_OBJS) $(PROGRAMS)
    52545836
    52555837
    5256 File: make.info,  Node: Origin Function,  Next: Shell Function,  Prev: Eval Function,  Up: Functions
    5257 
    5258 The `origin' Function
    5259 =====================
     5838File: make.info,  Node: Origin Function,  Next: Flavor Function,  Prev: Eval Function,  Up: Functions
     5839
     58408.9 The `origin' Function
     5841=========================
    52605842
    52615843The `origin' function is unlike most other functions in that it does
     
    53405922
    53415923
    5342 File: make.info,  Node: Shell Function,  Next: Make Control Functions,  Prev: Origin Function,  Up: Functions
    5343 
    5344 The `shell' Function
    5345 ====================
     5924File: make.info,  Node: Flavor Function,  Next: Shell Function,  Prev: Origin Function,  Up: Functions
     5925
     59268.10 The `flavor' Function
     5927==========================
     5928
     5929The `flavor' function is unlike most other functions (and like `origin'
     5930function) in that it does not operate on the values of variables; it
     5931tells you something _about_ a variable.  Specifically, it tells you the
     5932flavor of a variable (*note The Two Flavors of Variables: Flavors.).
     5933
     5934   The syntax of the `flavor' function is:
     5935
     5936     $(flavor VARIABLE)
     5937
     5938   Note that VARIABLE is the _name_ of a variable to inquire about; not
     5939a _reference_ to that variable.  Therefore you would not normally use a
     5940`$' or parentheses when writing it.  (You can, however, use a variable
     5941reference in the name if you want the name not to be a constant.)
     5942
     5943   The result of this function is a string that identifies the flavor
     5944of the variable VARIABLE:
     5945
     5946`undefined'
     5947     if VARIABLE was never defined.
     5948
     5949`recursive'
     5950     if VARIABLE is a recursively expanded variable.
     5951
     5952`simple'
     5953     if VARIABLE is a simply expanded variable.
     5954
     5955
     5956
     5957File: make.info,  Node: Shell Function,  Next: Make Control Functions,  Prev: Flavor Function,  Up: Functions
     5958
     59598.11 The `shell' Function
     5960=========================
    53465961
    53475962The `shell' function is unlike any other function other than the
     
    53745989
    53755990sets `files' to the expansion of `*.c'.  Unless `make' is using a very
    5376 strange shell, this has the same result as `$(wildcard *.c)'.
     5991strange shell, this has the same result as `$(wildcard *.c)' (as long
     5992as at least one `.c' file exists).
    53775993
    53785994
    53795995File: make.info,  Node: Make Control Functions,  Prev: Shell Function,  Up: Functions
    53805996
    5381 Functions That Control Make
    5382 ===========================
     59978.12 Functions That Control Make
     5998================================
    53835999
    53846000These functions control the way make runs.  Generally, they are used to
     
    54036019
    54046020          ERR = $(error found an error!)
    5405          
     6021
    54066022          .PHONY: err
    54076023          err: ; $(ERR)
     
    54186034     The result of the expansion of this function is the empty string.
    54196035
     6036`$(info TEXT...)'
     6037     This function does nothing more than print its (expanded)
     6038     argument(s) to standard output.  No makefile name or line number
     6039     is added.  The result of the expansion of this function is the
     6040     empty string.
     6041
    54206042
    54216043File: make.info,  Node: Running,  Next: Implicit Rules,  Prev: Functions,  Up: Top
    54226044
    5423 How to Run `make'
    5424 *****************
     60459 How to Run `make'
     6046*******************
    54256047
    54266048A makefile that says how to recompile a program can be used in more
     
    54686090File: make.info,  Node: Makefile Arguments,  Next: Goals,  Prev: Running,  Up: Running
    54696091
    5470 Arguments to Specify the Makefile
    5471 =================================
     60929.1 Arguments to Specify the Makefile
     6093=====================================
    54726094
    54736095The way to specify the name of the makefile is with the `-f' or
     
    54866108File: make.info,  Node: Goals,  Next: Instead of Execution,  Prev: Makefile Arguments,  Up: Running
    54876109
    5488 Arguments to Specify the Goals
    5489 ==============================
     61109.2 Arguments to Specify the Goals
     6111==================================
    54906112
    54916113The "goals" are the targets that `make' should strive ultimately to
     
    54986120program or programs they describe.  If the first rule in the makefile
    54996121has several targets, only the first target in the rule becomes the
    5500 default goal, not the whole list.
    5501 
    5502    You can specify a different goal or goals with arguments to `make'.
    5503 Use the name of the goal as an argument.  If you specify several goals,
    5504 `make' processes each of them in turn, in the order you name them.
     6122default goal, not the whole list.  You can manage the selection of the
     6123default goal from within your makefile using the `.DEFAULT_GOAL'
     6124variable (*note Other Special Variables: Special Variables.).
     6125
     6126   You can also specify a different goal or goals with command-line
     6127arguments to `make'.  Use the name of the goal as an argument.  If you
     6128specify several goals, `make' processes each of them in turn, in the
     6129order you name them.
    55056130
    55066131   Any target in the makefile may be specified as a goal (unless it
     
    55206145
    55216146     sources = foo.c bar.c
    5522      
     6147
    55236148     ifneq ($(MAKECMDGOALS),clean)
    55246149     include $(sources:.c=.d)
     
    56006225File: make.info,  Node: Instead of Execution,  Next: Avoiding Compilation,  Prev: Goals,  Up: Running
    56016226
    5602 Instead of Executing the Commands
    5603 =================================
     62279.3 Instead of Executing the Commands
     6228=====================================
    56046229
    56056230The makefile tells `make' how to tell whether a target is up to date,
     
    56796304File: make.info,  Node: Avoiding Compilation,  Next: Overriding,  Prev: Instead of Execution,  Up: Running
    56806305
    5681 Avoiding Recompilation of Some Files
    5682 ====================================
     63069.4 Avoiding Recompilation of Some Files
     6307========================================
    56836308
    56846309Sometimes you may have changed a source file but you do not want to
     
    57226347File: make.info,  Node: Overriding,  Next: Testing,  Prev: Avoiding Compilation,  Up: Running
    57236348
    5724 Overriding Variables
    5725 ====================
     63499.5 Overriding Variables
     6350========================
    57266351
    57276352An argument that contains `=' specifies the value of a variable: `V=X'
     
    57746399File: make.info,  Node: Testing,  Next: Options Summary,  Prev: Overriding,  Up: Running
    57756400
    5776 Testing the Compilation of a Program
    5777 ====================================
     64019.6 Testing the Compilation of a Program
     6402========================================
    57786403
    57796404Normally, when an error happens in executing a shell command, `make'
     
    58106435File: make.info,  Node: Options Summary,  Prev: Testing,  Up: Running
    58116436
    5812 Summary of Options
    5813 ==================
     64379.7 Summary of Options
     6438======================
    58146439
    58156440Here is a table of all the options `make' understands:
     
    58246449     Consider all targets out-of-date.  GNU `make' proceeds to consider
    58256450     targets and their prerequisites using the normal algorithms;
    5826      however, all these targets are remade, regardless of the status of
    5827      their prerequisites.
     6451     however, all targets so considered are always remade regardless of
     6452     the status of their prerequisites.  To avoid infinite recursion, if
     6453     `MAKE_RESTARTS' (*note Other Special Variables: Special
     6454     Variables.) is set to a number greater than 0 this option is
     6455     disabled when considering whether to remake makefiles (*note How
     6456     Makefiles Are Remade: Remaking Makefiles.).
    58286457
    58296458`-C DIR'
     
    59306559     floating-point number).  With no argument, removes a previous load
    59316560     limit.  *Note Parallel Execution: Parallel.
     6561
     6562`-L'
     6563`--check-symlink-times'
     6564     On systems that support symbolic links, this option causes `make'
     6565     to consider the timestamps on any symbolic links in addition to the
     6566     timestamp on the file referenced by those links.  When this option
     6567     is provided, the most recent timestamp among the file and the
     6568     symbolic links is taken as the modification time for this target
     6569     file.
    59326570
    59336571`-n'
     
    60526690File: make.info,  Node: Implicit Rules,  Next: Archives,  Prev: Running,  Up: Top
    60536691
    6054 Using Implicit Rules
    6055 ********************
     669210 Using Implicit Rules
     6693***********************
    60566694
    60576695Certain standard ways of remaking target files are used very often.  For
     
    60906728* Chained Rules::               How to use a chain of implicit rules.
    60916729* Pattern Rules::               How to define new implicit rules.
    6092 * Last Resort::                 How to defining commands for rules
    6093                                   which cannot find any.
     6730* Last Resort::                 How to define commands for rules which
     6731                                  cannot find any.
    60946732* Suffix Rules::                The old-fashioned style of implicit rule.
    60956733* Implicit Rule Search::        The precise algorithm for applying
     
    60996737File: make.info,  Node: Using Implicit,  Next: Catalogue of Rules,  Prev: Implicit Rules,  Up: Implicit Rules
    61006738
    6101 Using Implicit Rules
    6102 ====================
     673910.1 Using Implicit Rules
     6740=========================
    61036741
    61046742To allow `make' to find a customary method for updating a target file,
     
    61736811File: make.info,  Node: Catalogue of Rules,  Next: Implicit Variables,  Prev: Using Implicit,  Up: Implicit Rules
    61746812
    6175 Catalogue of Implicit Rules
    6176 ===========================
     681310.2 Catalogue of Implicit Rules
     6814================================
    61776815
    61786816Here is a catalogue of predefined implicit rules which are always
     
    61826820`--no-builtin-rules' option cancels all predefined rules.
    61836821
     6822   This manual only documents the default rules available on POSIX-based
     6823operating systems.  Other operating systems, such as VMS, Windows,
     6824OS/2, etc. may have different sets of default rules.  To see the full
     6825list of default rules and variables available in your version of GNU
     6826`make', run `make -p' in a directory with no makefile.
     6827
    61846828   Not all of these rules will always be defined, even when the `-r'
    61856829option is not given.  Many of the predefined implicit rules are
     
    61876831depends on the "suffix list" (the list of prerequisites of the special
    61886832target `.SUFFIXES').  The default suffix list is: `.out', `.a', `.ln',
    6189 `.o', `.c', `.cc', `.C', `.p', `.f', `.F', `.r', `.y', `.l', `.s',
    6190 `.S', `.mod', `.sym', `.def', `.h', `.info', `.dvi', `.tex', `.texinfo',
    6191 `.texi', `.txinfo', `.w', `.ch' `.web', `.sh', `.elc', `.el'.  All of
    6192 the implicit rules described below whose prerequisites have one of
    6193 these suffixes are actually suffix rules.  If you modify the suffix
    6194 list, the only predefined suffix rules in effect will be those named by
    6195 one or two of the suffixes that are on the list you specify; rules
    6196 whose suffixes fail to be on the list are disabled.  *Note
    6197 Old-Fashioned Suffix Rules: Suffix Rules, for full details on suffix
    6198 rules.
     6833`.o', `.c', `.cc', `.C', `.cpp', `.p', `.f', `.F', `.r', `.y', `.l',
     6834`.s', `.S', `.mod', `.sym', `.def', `.h', `.info', `.dvi', `.tex',
     6835`.texinfo', `.texi', `.txinfo', `.w', `.ch' `.web', `.sh', `.elc',
     6836`.el'.  All of the implicit rules described below whose prerequisites
     6837have one of these suffixes are actually suffix rules.  If you modify
     6838the suffix list, the only predefined suffix rules in effect will be
     6839those named by one or two of the suffixes that are on the list you
     6840specify; rules whose suffixes fail to be on the list are disabled.
     6841*Note Old-Fashioned Suffix Rules: Suffix Rules, for full details on
     6842suffix rules.
    61996843
    62006844Compiling C programs
     
    62036847
    62046848Compiling C++ programs
    6205      `N.o' is made automatically from `N.cc' or `N.C' with a command of
    6206      the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'.  We encourage you to
    6207      use the suffix `.cc' for C++ source files instead of `.C'.
     6849     `N.o' is made automatically from `N.cc', `N.cpp', or `N.C' with a
     6850     command of the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'.  We
     6851     encourage you to use the suffix `.cc' for C++ source files instead
     6852     of `.C'.
    62086853
    62096854Compiling Pascal programs
     
    63797024File: make.info,  Node: Implicit Variables,  Next: Chained Rules,  Prev: Catalogue of Rules,  Up: Implicit Rules
    63807025
    6381 Variables Used by Implicit Rules
    6382 ================================
     702610.3 Variables Used by Implicit Rules
     7027=====================================
    63837028
    63847029The commands in built-in implicit rules make liberal use of certain
    6385 predefined variables.  You can alter these variables in the makefile,
    6386 with arguments to `make', or in the environment to alter how the
    6387 implicit rules work without redefining the rules themselves.  You can
    6388 cancel all variables used by implicit rules with the `-R' or
     7030predefined variables.  You can alter the values of these variables in
     7031the makefile, with arguments to `make', or in the environment to alter
     7032how the implicit rules work without redefining the rules themselves.
     7033You can cancel all variables used by implicit rules with the `-R' or
    63897034`--no-builtin-variables' option.
    63907035
     
    64067051argument, separate them with spaces.
    64077052
    6408    Here is a table of variables used as names of programs in built-in
    6409 rules:
     7053   The following tables describe of some of the more commonly-used
     7054predefined variables.  This list is not exhaustive, and the default
     7055values shown here may not be what are selected by `make' for your
     7056environment.  To see the complete list of predefined variables for your
     7057instance of GNU `make' you can run `make -p' in a directory with no
     7058makefiles.
     7059
     7060   Here is a table of some of the more common variables used as names of
     7061programs in built-in rules: makefiles.
    64107062
    64117063`AR'
    6412      Archive-maintaining program; default `ar'.
     7064     Archive-maintaining program; default `ar'. 
    64137065
    64147066`AS'
    6415      Program for doing assembly; default `as'.
     7067     Program for compiling assembly files; default `as'. 
    64167068
    64177069`CC'
    6418      Program for compiling C programs; default `cc'.
     7070     Program for compiling C programs; default `cc'. 
     7071
     7072`CO'
     7073     Program for checking out files from RCS; default `co'. 
    64197074
    64207075`CXX'
    6421      Program for compiling C++ programs; default `g++'.
     7076     Program for compiling C++ programs; default `g++'. 
    64227077
    64237078`CO'
    6424      Program for extracting a file from RCS; default `co'.
     7079     Program for extracting a file from RCS; default `co'. 
    64257080
    64267081`CPP'
     
    64307085`FC'
    64317086     Program for compiling or preprocessing Fortran and Ratfor programs;
    6432      default `f77'.
     7087     default `f77'. 
    64337088
    64347089`GET'
    6435      Program for extracting a file from SCCS; default `get'.
     7090     Program for extracting a file from SCCS; default `get'. 
    64367091
    64377092`LEX'
    6438      Program to use to turn Lex grammars into C programs or Ratfor
    6439      programs; default `lex'.
     7093     Program to use to turn Lex grammars into source code; default
     7094     `lex'. 
     7095
     7096`YACC'
     7097     Program to use to turn Yacc grammars into source code; default
     7098     `yacc'. 
     7099
     7100`LINT'
     7101     Program to use to run lint on source code; default `lint'. 
     7102
     7103`M2C'
     7104     Program to use to compile Modula-2 source code; default `m2c'. 
    64407105
    64417106`PC'
    6442      Program for compiling Pascal programs; default `pc'.
    6443 
    6444 `YACC'
    6445      Program to use to turn Yacc grammars into C programs; default
    6446      `yacc'.
    6447 
    6448 `YACCR'
    6449      Program to use to turn Yacc grammars into Ratfor programs; default
    6450      `yacc -r'.
     7107     Program for compiling Pascal programs; default `pc'. 
    64517108
    64527109`MAKEINFO'
    64537110     Program to convert a Texinfo source file into an Info file; default
    6454      `makeinfo'.
     7111     `makeinfo'. 
    64557112
    64567113`TEX'
    6457      Program to make TeX DVI files from TeX source; default `tex'.
     7114     Program to make TeX DVI files from TeX source; default `tex'. 
    64587115
    64597116`TEXI2DVI'
    64607117     Program to make TeX DVI files from Texinfo source; default
    6461      `texi2dvi'.
     7118     `texi2dvi'. 
    64627119
    64637120`WEAVE'
    6464      Program to translate Web into TeX; default `weave'.
     7121     Program to translate Web into TeX; default `weave'. 
    64657122
    64667123`CWEAVE'
    6467      Program to translate C Web into TeX; default `cweave'.
     7124     Program to translate C Web into TeX; default `cweave'. 
    64687125
    64697126`TANGLE'
    6470      Program to translate Web into Pascal; default `tangle'.
     7127     Program to translate Web into Pascal; default `tangle'. 
    64717128
    64727129`CTANGLE'
    6473      Program to translate C Web into C; default `ctangle'.
     7130     Program to translate C Web into C; default `ctangle'. 
    64747131
    64757132`RM'
    6476      Command to remove a file; default `rm -f'.
     7133     Command to remove a file; default `rm -f'. 
    64777134
    64787135   Here is a table of variables whose values are additional arguments
     
    65137170     Extra flags to give to Lex.
    65147171
     7172`YFLAGS'
     7173     Extra flags to give to Yacc.
     7174
    65157175`PFLAGS'
    65167176     Extra flags to give to the Pascal compiler.
     
    65197179     Extra flags to give to the Fortran compiler for Ratfor programs.
    65207180
    6521 `YFLAGS'
    6522      Extra flags to give to Yacc.
     7181`LINTFLAGS'
     7182     Extra flags to give to lint.
    65237183
    65247184
    65257185File: make.info,  Node: Chained Rules,  Next: Pattern Rules,  Prev: Implicit Variables,  Up: Implicit Rules
    65267186
    6527 Chains of Implicit Rules
    6528 ========================
     718710.4 Chains of Implicit Rules
     7188=============================
    65297189
    65307190Sometimes a file can be made by a sequence of implicit rules.  For
     
    65787238as a prerequisite of the special target `.PRECIOUS' to preserve
    65797239intermediate files made by implicit rules whose target patterns match
    6580 that file's name; see *Note Interrupts::.
     7240that file's name; see *Note Interrupts::. 
    65817241
    65827242   A chain can involve more than two implicit rules.  For example, it is
     
    66007260earlier in the ordering of rules.
    66017261
    6602 
    6603 File: make.info,  Node: Pattern Rules,  Next: Last Resort,  Prev: Chained Rules,  Up: Implicit Rules
    6604 
    6605 Defining and Redefining Pattern Rules
    6606 =====================================
    6607 
    6608 You define an implicit rule by writing a "pattern rule".  A pattern
    6609 rule looks like an ordinary rule, except that its target contains the
    6610 character `%' (exactly one of them).  The target is considered a
    6611 pattern for matching file names; the `%' can match any nonempty
    6612 substring, while other characters match only themselves.  The
    6613 prerequisites likewise use `%' to show how their names relate to the
    6614 target name.
    6615 
    6616    Thus, a pattern rule `%.o : %.c' says how to make any file `STEM.o'
    6617 from another file `STEM.c'.
    6618 
    6619    Note that expansion using `%' in pattern rules occurs *after* any
    6620 variable or function expansions, which take place when the makefile is
    6621 read.  *Note How to Use Variables: Using Variables, and *Note Functions
    6622 for Transforming Text: Functions.
    6623 
    6624 * Menu:
    6625 
    6626 * Pattern Intro::               An introduction to pattern rules.
    6627 * Pattern Examples::            Examples of pattern rules.
    6628 * Automatic Variables::         How to use automatic variables in the
    6629                                   commands of implicit rules.
    6630 * Pattern Match::               How patterns match.
    6631 * Match-Anything Rules::        Precautions you should take prior to
    6632                                   defining rules that can match any
    6633                                   target file whatever.
    6634 * Canceling Rules::             How to override or cancel built-in rules.
    6635 
    6636 
    6637 File: make.info,  Node: Pattern Intro,  Next: Pattern Examples,  Prev: Pattern Rules,  Up: Pattern Rules
    6638 
    6639 Introduction to Pattern Rules
    6640 -----------------------------
    6641 
    6642 A pattern rule contains the character `%' (exactly one of them) in the
    6643 target; otherwise, it looks exactly like an ordinary rule.  The target
    6644 is a pattern for matching file names; the `%' matches any nonempty
    6645 substring, while other characters match only themselves.
    6646 
    6647    For example, `%.c' as a pattern matches any file name that ends in
    6648 `.c'.  `s.%.c' as a pattern matches any file name that starts with
    6649 `s.', ends in `.c' and is at least five characters long.  (There must
    6650 be at least one character to match the `%'.)  The substring that the
    6651 `%' matches is called the "stem".
    6652 
    6653    `%' in a prerequisite of a pattern rule stands for the same stem
    6654 that was matched by the `%' in the target.  In order for the pattern
    6655 rule to apply, its target pattern must match the file name under
    6656 consideration, and its prerequisite patterns must name files that exist
    6657 or can be made.  These files become prerequisites of the target.
    6658 
    6659    Thus, a rule of the form
    6660 
    6661      %.o : %.c ; COMMAND...
    6662 
    6663 specifies how to make a file `N.o', with another file `N.c' as its
    6664 prerequisite, provided that `N.c' exists or can be made.
    6665 
    6666    There may also be prerequisites that do not use `%'; such a
    6667 prerequisite attaches to every file made by this pattern rule.  These
    6668 unvarying prerequisites are useful occasionally.
    6669 
    6670    A pattern rule need not have any prerequisites that contain `%', or
    6671 in fact any prerequisites at all.  Such a rule is effectively a general
    6672 wildcard.  It provides a way to make any file that matches the target
    6673 pattern.  *Note Last Resort::.
    6674 
    6675    Pattern rules may have more than one target.  Unlike normal rules,
    6676 this does not act as many different rules with the same prerequisites
    6677 and commands.  If a pattern rule has multiple targets, `make' knows that
    6678 the rule's commands are responsible for making all of the targets.  The
    6679 commands are executed only once to make all the targets.  When searching
    6680 for a pattern rule to match a target, the target patterns of a rule
    6681 other than the one that matches the target in need of a rule are
    6682 incidental: `make' worries only about giving commands and prerequisites
    6683 to the file presently in question.  However, when this file's commands
    6684 are run, the other targets are marked as having been updated themselves.
    6685 
    6686    The order in which pattern rules appear in the makefile is important
    6687 since this is the order in which they are considered.  Of equally
    6688 applicable rules, only the first one found is used.  The rules you
    6689 write take precedence over those that are built in.  Note however, that
    6690 a rule whose prerequisites actually exist or are mentioned always takes
    6691 priority over a rule with prerequisites that must be made by chaining
    6692 other implicit rules.
    6693 
    6694 
    6695 File: make.info,  Node: Pattern Examples,  Next: Automatic Variables,  Prev: Pattern Intro,  Up: Pattern Rules
    6696 
    6697 Pattern Rule Examples
    6698 ---------------------
    6699 
    6700 Here are some examples of pattern rules actually predefined in `make'.
    6701 First, the rule that compiles `.c' files into `.o' files:
    6702 
    6703      %.o : %.c
    6704              $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    6705 
    6706 defines a rule that can make any file `X.o' from `X.c'.  The command
    6707 uses the automatic variables `$@' and `$<' to substitute the names of
    6708 the target file and the source file in each case where the rule applies
    6709 (*note Automatic Variables::).
    6710 
    6711    Here is a second built-in rule:
    6712 
    6713      % :: RCS/%,v
    6714              $(CO) $(COFLAGS) $<
    6715 
    6716 defines a rule that can make any file `X' whatsoever from a
    6717 corresponding file `X,v' in the subdirectory `RCS'.  Since the target
    6718 is `%', this rule will apply to any file whatever, provided the
    6719 appropriate prerequisite file exists.  The double colon makes the rule
    6720 "terminal", which means that its prerequisite may not be an intermediate
    6721 file (*note Match-Anything Pattern Rules: Match-Anything Rules.).
    6722 
    6723    This pattern rule has two targets:
    6724 
    6725      %.tab.c %.tab.h: %.y
    6726              bison -d $<
    6727 
    6728 This tells `make' that the command `bison -d X.y' will make both
    6729 `X.tab.c' and `X.tab.h'.  If the file `foo' depends on the files
    6730 `parse.tab.o' and `scan.o' and the file `scan.o' depends on the file
    6731 `parse.tab.h', when `parse.y' is changed, the command `bison -d parse.y'
    6732 will be executed only once, and the prerequisites of both `parse.tab.o'
    6733 and `scan.o' will be satisfied.  (Presumably the file `parse.tab.o'
    6734 will be recompiled from `parse.tab.c' and the file `scan.o' from
    6735 `scan.c', while `foo' is linked from `parse.tab.o', `scan.o', and its
    6736 other prerequisites, and it will execute happily ever after.)
    6737 
    6738 
    6739 File: make.info,  Node: Automatic Variables,  Next: Pattern Match,  Prev: Pattern Examples,  Up: Pattern Rules
    6740 
    6741 Automatic Variables
    6742 -------------------
    6743 
    6744 Suppose you are writing a pattern rule to compile a `.c' file into a
    6745 `.o' file: how do you write the `cc' command so that it operates on the
    6746 right source file name?  You cannot write the name in the command,
    6747 because the name is different each time the implicit rule is applied.
    6748 
    6749    What you do is use a special feature of `make', the "automatic
    6750 variables".  These variables have values computed afresh for each rule
    6751 that is executed, based on the target and prerequisites of the rule.
    6752 In this example, you would use `$@' for the object file name and `$<'
    6753 for the source file name.
    6754 
    6755    It's very important that you recognize the limited scope in which
    6756 automatic variable values are available: they only have values within
    6757 the command script.  In particular, you cannot use them anywhere within
    6758 the target or prerequisite lists of a rule; they have no value there
    6759 and will expand to the empty string.  A common mistake is attempting to
    6760 use `$@' within the prerequisites list in a rule; this will not work.
    6761 However, see below for information on the SysV-style `$$@' variables.
    6762 
    6763    Here is a table of automatic variables:
    6764 
    6765 `$@'
    6766      The file name of the target of the rule.  If the target is an
    6767      archive member, then `$@' is the name of the archive file.  In a
    6768      pattern rule that has multiple targets (*note Introduction to
    6769      Pattern Rules: Pattern Intro.), `$@' is the name of whichever
    6770      target caused the rule's commands to be run.
    6771 
    6772 `$%'
    6773      The target member name, when the target is an archive member.
    6774      *Note Archives::.  For example, if the target is `foo.a(bar.o)'
    6775      then `$%' is `bar.o' and `$@' is `foo.a'.  `$%' is empty when the
    6776      target is not an archive member.
    6777 
    6778 `$<'
    6779      The name of the first prerequisite.  If the target got its
    6780      commands from an implicit rule, this will be the first
    6781      prerequisite added by the implicit rule (*note Implicit Rules::).
    6782 
    6783 `$?'
    6784      The names of all the prerequisites that are newer than the target,
    6785      with spaces between them.  For prerequisites which are archive
    6786      members, only the member named is used (*note Archives::).
    6787 
    6788 `$^'
    6789      The names of all the prerequisites, with spaces between them.  For
    6790      prerequisites which are archive members, only the member named is
    6791      used (*note Archives::).  A target has only one prerequisite on
    6792      each other file it depends on, no matter how many times each file
    6793      is listed as a prerequisite.  So if you list a prerequisite more
    6794      than once for a target, the value of `$^' contains just one copy
    6795      of the name.
    6796 
    6797 `$+'
    6798      This is like `$^', but prerequisites listed more than once are
    6799      duplicated in the order they were listed in the makefile.  This is
    6800      primarily useful for use in linking commands where it is
    6801      meaningful to repeat library file names in a particular order.
    6802 
    6803 `$*'
    6804      The stem with which an implicit rule matches (*note How Patterns
    6805      Match: Pattern Match.).  If the target is `dir/a.foo.b' and the
    6806      target pattern is `a.%.b' then the stem is `dir/foo'.  The stem is
    6807      useful for constructing names of related files.
    6808 
    6809      In a static pattern rule, the stem is part of the file name that
    6810      matched the `%' in the target pattern.
    6811 
    6812      In an explicit rule, there is no stem; so `$*' cannot be determined
    6813      in that way.  Instead, if the target name ends with a recognized
    6814      suffix (*note Old-Fashioned Suffix Rules: Suffix Rules.), `$*' is
    6815      set to the target name minus the suffix.  For example, if the
    6816      target name is `foo.c', then `$*' is set to `foo', since `.c' is a
    6817      suffix.  GNU `make' does this bizarre thing only for compatibility
    6818      with other implementations of `make'.  You should generally avoid
    6819      using `$*' except in implicit rules or static pattern rules.
    6820 
    6821      If the target name in an explicit rule does not end with a
    6822      recognized suffix, `$*' is set to the empty string for that rule.
    6823 
    6824    `$?' is useful even in explicit rules when you wish to operate on
    6825 only the prerequisites that have changed.  For example, suppose that an
    6826 archive named `lib' is supposed to contain copies of several object
    6827 files.  This rule copies just the changed object files into the archive:
    6828 
    6829      lib: foo.o bar.o lose.o win.o
    6830              ar r lib $?
    6831 
    6832    Of the variables listed above, four have values that are single file
    6833 names, and three have values that are lists of file names.  These seven
    6834 have variants that get just the file's directory name or just the file
    6835 name within the directory.  The variant variables' names are formed by
    6836 appending `D' or `F', respectively.  These variants are semi-obsolete
    6837 in GNU `make' since the functions `dir' and `notdir' can be used to get
    6838 a similar effect (*note Functions for File Names: File Name
    6839 Functions.).  Note, however, that the `D' variants all omit the
    6840 trailing slash which always appears in the output of the `dir'
    6841 function.  Here is a table of the variants:
    6842 
    6843 `$(@D)'
    6844      The directory part of the file name of the target, with the
    6845      trailing slash removed.  If the value of `$@' is `dir/foo.o' then
    6846      `$(@D)' is `dir'.  This value is `.' if `$@' does not contain a
    6847      slash.
    6848 
    6849 `$(@F)'
    6850      The file-within-directory part of the file name of the target.  If
    6851      the value of `$@' is `dir/foo.o' then `$(@F)' is `foo.o'.  `$(@F)'
    6852      is equivalent to `$(notdir $@)'.
    6853 
    6854 `$(*D)'
    6855 `$(*F)'
    6856      The directory part and the file-within-directory part of the stem;
    6857      `dir' and `foo' in this example.
    6858 
    6859 `$(%D)'
    6860 `$(%F)'
    6861      The directory part and the file-within-directory part of the target
    6862      archive member name.  This makes sense only for archive member
    6863      targets of the form `ARCHIVE(MEMBER)' and is useful only when
    6864      MEMBER may contain a directory name.  (*Note Archive Members as
    6865      Targets: Archive Members.)
    6866 
    6867 `$(<D)'
    6868 `$(<F)'
    6869      The directory part and the file-within-directory part of the first
    6870      prerequisite.
    6871 
    6872 `$(^D)'
    6873 `$(^F)'
    6874      Lists of the directory parts and the file-within-directory parts
    6875      of all prerequisites.
    6876 
    6877 `$(+D)'
    6878 `$(+F)'
    6879      Lists of the directory parts and the file-within-directory parts
    6880      of all prerequisites, including multiple instances of duplicated
    6881      prerequisites.
    6882 
    6883 `$(?D)'
    6884 `$(?F)'
    6885      Lists of the directory parts and the file-within-directory parts of
    6886      all prerequisites that are newer than the target.
    6887 
    6888    Note that we use a special stylistic convention when we talk about
    6889 these automatic variables; we write "the value of `$<'", rather than
    6890 "the variable `<'" as we would write for ordinary variables such as
    6891 `objects' and `CFLAGS'.  We think this convention looks more natural in
    6892 this special case.  Please do not assume it has a deep significance;
    6893 `$<' refers to the variable named `<' just as `$(CFLAGS)' refers to the
    6894 variable named `CFLAGS'.  You could just as well use `$(<)' in place of
    6895 `$<'.
    6896 
    6897    GNU `make' provides support for the SysV `make' feature that allows
    6898 special variable references `$$@', `$$(@D)', and `$$(@F)' (note the
    6899 required double-"$"!) to appear with the _prerequisites list_ (normal
    6900 automatic variables are available only within a command script).  When
    6901 appearing in a prerequisites list, these variables are expanded to the
    6902 name of the target, the directory component of the target, and the file
    6903 component of the target, respectively.
    6904 
    6905    Note that these variables are available only within explicit and
    6906 static pattern (*note Static Pattern Rules: Static Pattern.) rules;
    6907 they have no special significance within implicit (suffix or pattern)
    6908 rules.  Also note that while SysV `make' actually expands its entire
    6909 prerequisite list _twice_, GNU `make' does not behave this way: instead
    6910 it simply expands these special variables without re-expanding any
    6911 other part of the prerequisites list.
    6912 
    6913    This somewhat bizarre feature is included only to provide some
    6914 compatibility with SysV makefiles.  In a native GNU `make' file there
    6915 are other ways to accomplish the same results.  This feature is
    6916 disabled if the special pseudo target `.POSIX' is defined.
    6917 
    6918 
    6919 File: make.info,  Node: Pattern Match,  Next: Match-Anything Rules,  Prev: Automatic Variables,  Up: Pattern Rules
    6920 
    6921 How Patterns Match
    6922 ------------------
    6923 
    6924 A target pattern is composed of a `%' between a prefix and a suffix,
    6925 either or both of which may be empty.  The pattern matches a file name
    6926 only if the file name starts with the prefix and ends with the suffix,
    6927 without overlap.  The text between the prefix and the suffix is called
    6928 the "stem".  Thus, when the pattern `%.o' matches the file name
    6929 `test.o', the stem is `test'.  The pattern rule prerequisites are
    6930 turned into actual file names by substituting the stem for the character
    6931 `%'.  Thus, if in the same example one of the prerequisites is written
    6932 as `%.c', it expands to `test.c'.
    6933 
    6934    When the target pattern does not contain a slash (and it usually does
    6935 not), directory names in the file names are removed from the file name
    6936 before it is compared with the target prefix and suffix.  After the
    6937 comparison of the file name to the target pattern, the directory names,
    6938 along with the slash that ends them, are added on to the prerequisite
    6939 file names generated from the pattern rule's prerequisite patterns and
    6940 the file name. The directories are ignored only for the purpose of
    6941 finding an implicit rule to use, not in the application of that rule.
    6942 Thus, `e%t' matches the file name `src/eat', with `src/a' as the stem.
    6943 When prerequisites are turned into file names, the directories from the
    6944 stem are added at the front, while the rest of the stem is substituted
    6945 for the `%'.  The stem `src/a' with a prerequisite pattern `c%r' gives
    6946 the file name `src/car'.
    6947 
    6948 
    6949 File: make.info,  Node: Match-Anything Rules,  Next: Canceling Rules,  Prev: Pattern Match,  Up: Pattern Rules
    6950 
    6951 Match-Anything Pattern Rules
    6952 ----------------------------
    6953 
    6954 When a pattern rule's target is just `%', it matches any file name
    6955 whatever.  We call these rules "match-anything" rules.  They are very
    6956 useful, but it can take a lot of time for `make' to think about them,
    6957 because it must consider every such rule for each file name listed
    6958 either as a target or as a prerequisite.
    6959 
    6960    Suppose the makefile mentions `foo.c'.  For this target, `make'
    6961 would have to consider making it by linking an object file `foo.c.o',
    6962 or by C compilation-and-linking in one step from `foo.c.c', or by
    6963 Pascal compilation-and-linking from `foo.c.p', and many other
    6964 possibilities.
    6965 
    6966    We know these possibilities are ridiculous since `foo.c' is a C
    6967 source file, not an executable.  If `make' did consider these
    6968 possibilities, it would ultimately reject them, because files such as
    6969 `foo.c.o' and `foo.c.p' would not exist.  But these possibilities are so
    6970 numerous that `make' would run very slowly if it had to consider them.
    6971 
    6972    To gain speed, we have put various constraints on the way `make'
    6973 considers match-anything rules.  There are two different constraints
    6974 that can be applied, and each time you define a match-anything rule you
    6975 must choose one or the other for that rule.
    6976 
    6977    One choice is to mark the match-anything rule as "terminal" by
    6978 defining it with a double colon.  When a rule is terminal, it does not
    6979 apply unless its prerequisites actually exist.  Prerequisites that
    6980 could be made with other implicit rules are not good enough.  In other
    6981 words, no further chaining is allowed beyond a terminal rule.
    6982 
    6983    For example, the built-in implicit rules for extracting sources from
    6984 RCS and SCCS files are terminal; as a result, if the file `foo.c,v' does
    6985 not exist, `make' will not even consider trying to make it as an
    6986 intermediate file from `foo.c,v.o' or from `RCS/SCCS/s.foo.c,v'.  RCS
    6987 and SCCS files are generally ultimate source files, which should not be
    6988 remade from any other files; therefore, `make' can save time by not
    6989 looking for ways to remake them.
    6990 
    6991    If you do not mark the match-anything rule as terminal, then it is
    6992 nonterminal.  A nonterminal match-anything rule cannot apply to a file
    6993 name that indicates a specific type of data.  A file name indicates a
    6994 specific type of data if some non-match-anything implicit rule target
    6995 matches it.
    6996 
    6997    For example, the file name `foo.c' matches the target for the pattern
    6998 rule `%.c : %.y' (the rule to run Yacc).  Regardless of whether this
    6999 rule is actually applicable (which happens only if there is a file
    7000 `foo.y'), the fact that its target matches is enough to prevent
    7001 consideration of any nonterminal match-anything rules for the file
    7002 `foo.c'.  Thus, `make' will not even consider trying to make `foo.c' as
    7003 an executable file from `foo.c.o', `foo.c.c', `foo.c.p', etc.
    7004 
    7005    The motivation for this constraint is that nonterminal match-anything
    7006 rules are used for making files containing specific types of data (such
    7007 as executable files) and a file name with a recognized suffix indicates
    7008 some other specific type of data (such as a C source file).
    7009 
    7010    Special built-in dummy pattern rules are provided solely to recognize
    7011 certain file names so that nonterminal match-anything rules will not be
    7012 considered.  These dummy rules have no prerequisites and no commands,
    7013 and they are ignored for all other purposes.  For example, the built-in
    7014 implicit rule
    7015 
    7016      %.p :
    7017 
    7018 exists to make sure that Pascal source files such as `foo.p' match a
    7019 specific target pattern and thereby prevent time from being wasted
    7020 looking for `foo.p.o' or `foo.p.c'.
    7021 
    7022    Dummy pattern rules such as the one for `%.p' are made for every
    7023 suffix listed as valid for use in suffix rules (*note Old-Fashioned
    7024 Suffix Rules: Suffix Rules.).
    7025 
    7026 
    7027 File: make.info,  Node: Canceling Rules,  Prev: Match-Anything Rules,  Up: Pattern Rules
    7028 
    7029 Canceling Implicit Rules
    7030 ------------------------
    7031 
    7032 You can override a built-in implicit rule (or one you have defined
    7033 yourself) by defining a new pattern rule with the same target and
    7034 prerequisites, but different commands.  When the new rule is defined,
    7035 the built-in one is replaced.  The new rule's position in the sequence
    7036 of implicit rules is determined by where you write the new rule.
    7037 
    7038    You can cancel a built-in implicit rule by defining a pattern rule
    7039 with the same target and prerequisites, but no commands.  For example,
    7040 the following would cancel the rule that runs the assembler:
    7041 
    7042      %.o : %.s
    7043 
    7044 
    7045 File: make.info,  Node: Last Resort,  Next: Suffix Rules,  Prev: Pattern Rules,  Up: Implicit Rules
    7046 
    7047 Defining Last-Resort Default Rules
    7048 ==================================
    7049 
    7050 You can define a last-resort implicit rule by writing a terminal
    7051 match-anything pattern rule with no prerequisites (*note Match-Anything
    7052 Rules::).  This is just like any other pattern rule; the only thing
    7053 special about it is that it will match any target.  So such a rule's
    7054 commands are used for all targets and prerequisites that have no
    7055 commands of their own and for which no other implicit rule applies.
    7056 
    7057    For example, when testing a makefile, you might not care if the
    7058 source files contain real data, only that they exist.  Then you might
    7059 do this:
    7060 
    7061      %::
    7062              touch $@
    7063 
    7064 to cause all the source files needed (as prerequisites) to be created
    7065 automatically.
    7066 
    7067    You can instead define commands to be used for targets for which
    7068 there are no rules at all, even ones which don't specify commands.  You
    7069 do this by writing a rule for the target `.DEFAULT'.  Such a rule's
    7070 commands are used for all prerequisites which do not appear as targets
    7071 in any explicit rule, and for which no implicit rule applies.
    7072 Naturally, there is no `.DEFAULT' rule unless you write one.
    7073 
    7074    If you use `.DEFAULT' with no commands or prerequisites:
    7075 
    7076      .DEFAULT:
    7077 
    7078 the commands previously stored for `.DEFAULT' are cleared.  Then `make'
    7079 acts as if you had never defined `.DEFAULT' at all.
    7080 
    7081    If you do not want a target to get the commands from a match-anything
    7082 pattern rule or `.DEFAULT', but you also do not want any commands to be
    7083 run for the target, you can give it empty commands (*note Defining
    7084 Empty Commands: Empty Commands.).
    7085 
    7086    You can use a last-resort rule to override part of another makefile.
    7087 *Note Overriding Part of Another Makefile: Overriding Makefiles.
    7088 
    7089 
    7090 File: make.info,  Node: Suffix Rules,  Next: Implicit Rule Search,  Prev: Last Resort,  Up: Implicit Rules
    7091 
    7092 Old-Fashioned Suffix Rules
    7093 ==========================
    7094 
    7095 "Suffix rules" are the old-fashioned way of defining implicit rules for
    7096 `make'.  Suffix rules are obsolete because pattern rules are more
    7097 general and clearer.  They are supported in GNU `make' for
    7098 compatibility with old makefiles.  They come in two kinds:
    7099 "double-suffix" and "single-suffix".
    7100 
    7101    A double-suffix rule is defined by a pair of suffixes: the target
    7102 suffix and the source suffix.  It matches any file whose name ends with
    7103 the target suffix.  The corresponding implicit prerequisite is made by
    7104 replacing the target suffix with the source suffix in the file name.  A
    7105 two-suffix rule whose target and source suffixes are `.o' and `.c' is
    7106 equivalent to the pattern rule `%.o : %.c'.
    7107 
    7108    A single-suffix rule is defined by a single suffix, which is the
    7109 source suffix.  It matches any file name, and the corresponding implicit
    7110 prerequisite name is made by appending the source suffix.  A
    7111 single-suffix rule whose source suffix is `.c' is equivalent to the
    7112 pattern rule `% : %.c'.
    7113 
    7114    Suffix rule definitions are recognized by comparing each rule's
    7115 target against a defined list of known suffixes.  When `make' sees a
    7116 rule whose target is a known suffix, this rule is considered a
    7117 single-suffix rule.  When `make' sees a rule whose target is two known
    7118 suffixes concatenated, this rule is taken as a double-suffix rule.
    7119 
    7120    For example, `.c' and `.o' are both on the default list of known
    7121 suffixes.  Therefore, if you define a rule whose target is `.c.o',
    7122 `make' takes it to be a double-suffix rule with source suffix `.c' and
    7123 target suffix `.o'.  Here is the old-fashioned way to define the rule
    7124 for compiling a C source file:
    7125 
    7126      .c.o:
    7127              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
    7128 
    7129    Suffix rules cannot have any prerequisites of their own.  If they
    7130 have any, they are treated as normal files with funny names, not as
    7131 suffix rules.  Thus, the rule:
    7132 
    7133      .c.o: foo.h
    7134              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
    7135 
    7136 tells how to make the file `.c.o' from the prerequisite file `foo.h',
    7137 and is not at all like the pattern rule:
    7138 
    7139      %.o: %.c foo.h
    7140              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
    7141 
    7142 which tells how to make `.o' files from `.c' files, and makes all `.o'
    7143 files using this pattern rule also depend on `foo.h'.
    7144 
    7145    Suffix rules with no commands are also meaningless.  They do not
    7146 remove previous rules as do pattern rules with no commands (*note
    7147 Canceling Implicit Rules: Canceling Rules.).  They simply enter the
    7148 suffix or pair of suffixes concatenated as a target in the data base.
    7149 
    7150    The known suffixes are simply the names of the prerequisites of the
    7151 special target `.SUFFIXES'.  You can add your own suffixes by writing a
    7152 rule for `.SUFFIXES' that adds more prerequisites, as in:
    7153 
    7154      .SUFFIXES: .hack .win
    7155 
    7156 which adds `.hack' and `.win' to the end of the list of suffixes.
    7157 
    7158    If you wish to eliminate the default known suffixes instead of just
    7159 adding to them, write a rule for `.SUFFIXES' with no prerequisites.  By
    7160 special dispensation, this eliminates all existing prerequisites of
    7161 `.SUFFIXES'.  You can then write another rule to add the suffixes you
    7162 want.  For example,
    7163 
    7164      .SUFFIXES:            # Delete the default suffixes
    7165      .SUFFIXES: .c .o .h   # Define our suffix list
    7166 
    7167    The `-r' or `--no-builtin-rules' flag causes the default list of
    7168 suffixes to be empty.
    7169 
    7170    The variable `SUFFIXES' is defined to the default list of suffixes
    7171 before `make' reads any makefiles.  You can change the list of suffixes
    7172 with a rule for the special target `.SUFFIXES', but that does not alter
    7173 this variable.
    7174 
Note: See TracChangeset for help on using the changeset viewer.