VirtualBox

Changeset 503 in kBuild for trunk/src/gmake/doc/make.info-1


Ignore:
Timestamp:
Sep 15, 2006 5:09:38 AM (18 years ago)
Author:
bird
Message:

Untested merge with GNU Make v3.81 (vendor/gnumake/2005-05-16 -> vendor/gnumake/current).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gmake/doc/make.info-1

    r200 r503  
    1 This is ../../doc/make.info, produced by makeinfo version 4.6 from
    2 ../../doc/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."
    325
    426INFO-DIR-SECTION GNU Packages
     
    729END-INFO-DIR-ENTRY
    830
    9    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
    1038automatically which pieces of a large program need to be recompiled,
    1139and issues the commands to recompile them.
    1240
    13    This is Edition 0.61, last updated 02 May 2003, of `The GNU Make
    14 Manual', for `make', Version 3.81.
    15 
    16    Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    17 1998, 1999, 2000, 2002, 2003, 2004 Free Software Foundation, Inc.
    18 
    19    Permission is granted to copy, distribute and/or modify this document
    20 under the terms of the GNU Free Documentation License, Version 1.1 or
    21 any later version published by the Free Software Foundation; with no
    22 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
    23 Texts.  A copy of the license is included in the section entitled "GNU
    24 Free Documentation License".
    25 
    26 
    27 File: make.info,  Node: Top,  Next: Overview,  Prev: (dir),  Up: (dir)
    28 
    29 Make
    30 ****
    31 
    32 The GNU `make' utility automatically determines which pieces of a large
    33 program need to be recompiled, and issues the commands to recompile
    34 them.
    35 
    36    This edition of the `GNU Make Manual', last updated 02 May 2003,
    37 documents GNU `make' Version 3.81.
    38 
    39    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."
    4059
    4160* Menu:
     
    97116                                  with another makefile.
    98117* Reading Makefiles::           How makefiles are parsed.
     118* Secondary Expansion::         How and when secondary expansion is performed.
    99119
    100120Writing Rules
     
    107127* Phony Targets::               Using a target that is not a real file's name.
    108128* Force Targets::               You can use a target without commands
    109                                   or prerequisites to mark other
    110                                   targets as phony.
     129                                  or prerequisites to mark other targets
     130                                  as phony.
    111131* Empty Targets::               When only the date matters and the
    112132                                  files are empty.
     
    148168Writing the Commands in Rules
    149169
     170* Command Syntax::              Command syntax features and pitfalls.
    150171* Echoing::                     How to control when commands are echoed.
    151172* Execution::                   How commands are executed.
     
    156177* Sequences::                   Defining canned sequences of commands.
    157178* 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.
    158189
    159190Recursive Use of `make'
     
    201232* Text Functions::              General-purpose text manipulation functions.
    202233* File Name Functions::         Functions for manipulating file names.
     234* Conditional Functions::       Functions that implement conditions.
    203235* Foreach Function::            Repeat some text with controlled variation.
    204 * If Function::                 Conditionally expand a value.
    205236* Call Function::               Expand a user-defined function.
    206237* Value Function::              Return the un-expanded value of a variable.
    207238* Eval Function::               Evaluate the arguments as makefile syntax.
    208239* Origin Function::             Find where a variable got its value.
     240* Flavor Function::             Find out the flavor of a variable.
    209241* Shell Function::              Substitute the output of a shell command.
    210242* Make Control Functions::      Functions that control how make runs.
     
    234266* Chained Rules::               How to use a chain of implicit rules.
    235267* Pattern Rules::               How to define new implicit rules.
    236 * Last Resort::                 How to defining commands for rules
    237                                   which cannot find any.
     268* Last Resort::                 How to define commands for rules which
     269                                  cannot find any.
    238270* Suffix Rules::                The old-fashioned style of implicit rule.
    239271* Implicit Rule Search::        The precise algorithm for applying
     
    264296* Archive Symbols::             How to update archive symbol directories.
    265297
    266 Makefile Conventions
    267 
    268 * Makefile Basics::             General Conventions for Makefiles
    269 * Utilities in Makefiles::      Utilities in Makefiles
    270 * Command Variables::           Variables for Specifying Commands
    271 * Directory Variables::         Variables for Installation Directories
    272 * Standard Targets::            Standard Targets for Users
    273 * Install Command Categories::  Three categories of commands in the `install'
    274 
    275 Copying This Manual
    276 
    277298
    278299File: make.info,  Node: Overview,  Next: Introduction,  Prev: Top,  Up: Top
    279300
    280 Overview of `make'
    281 ******************
     3011 Overview of `make'
     302********************
    282303
    283304The `make' utility automatically determines which pieces of a large
     
    288309
    289310   GNU `make' conforms to section 6.2 of `IEEE Standard 1003.2-1992'
    290 (POSIX.2).
     311(POSIX.2). 
    291312
    292313   Our examples show C programs, since they are most common, but you
     
    330351File: make.info,  Node: Reading,  Next: Bugs,  Prev: Preparing,  Up: Overview
    331352
    332 How to Read This Manual
    333 =======================
     3531.1 How to Read This Manual
     354===========================
    334355
    335356If you are new to `make', or are looking for a general introduction,
     
    351372File: make.info,  Node: Bugs,  Prev: Reading,  Up: Overview
    352373
    353 Problems and Bugs
    354 =================
     3741.2 Problems and Bugs
     375=====================
    355376
    356377If you have problems with GNU `make' or think you've found a bug,
     
    394415File: make.info,  Node: Introduction,  Next: Makefiles,  Prev: Overview,  Up: Top
    395416
    396 An Introduction to Makefiles
    397 ****************************
     4172 An Introduction to Makefiles
     418******************************
    398419
    399420You need a file called a "makefile" to tell `make' what to do.  Most
    400 often, the makefile tells `make' how to compile and link a program.
     421often, the makefile tells `make' how to compile and link a program. 
    401422
    402423   In this chapter, we will discuss a simple makefile that describes
     
    413434Finally, if any source file has been recompiled, all the object files,
    414435whether newly made or saved from previous compilations, must be linked
    415 together to produce the new executable editor.
     436together to produce the new executable editor. 
    416437
    417438* Menu:
     
    428449File: make.info,  Node: Rule Introduction,  Next: Simple Makefile,  Prev: Introduction,  Up: Introduction
    429450
    430 What a Rule Looks Like
    431 ======================
     4512.1 What a Rule Looks Like
     452==========================
    432453
    433454A simple makefile consists of "rules" with the following shape:
     
    471492File: make.info,  Node: Simple Makefile,  Next: How Make Works,  Prev: Rule Introduction,  Up: Introduction
    472493
    473 A Simple Makefile
    474 =================
     4942.2 A Simple Makefile
     495=====================
    475496
    476497Here is a straightforward makefile that describes the way an executable
     
    486507             cc -o edit main.o kbd.o command.o display.o \
    487508                        insert.o search.o files.o utils.o
    488      
     509
    489510     main.o : main.c defs.h
    490511             cc -c main.c
     
    508529
    509530We split each long line into two lines using backslash-newline; this is
    510 like using one long line, but is easier to read.
     531like using one long line, but is easier to read. 
    511532
    512533   To use this makefile to create the executable file called `edit',
     
    536557prerequisites.  These shell commands say how to update the target file.
    537558A tab character must come at the beginning of every command line to
    538 distinguish commands lines from other lines in the makefile.  (Bear in
     559distinguish command lines from other lines in the makefile.  (Bear in
    539560mind that `make' does not know anything about how the commands work.
    540561It is up to you to supply commands that will update the target file
    541562properly.  All `make' does is execute the commands in the rule you have
    542 specified when the target file needs to be updated.)
     563specified when the target file needs to be updated.) 
    543564
    544565   The target `clean' is not a file, but merely the name of an action.
     
    551572called "phony targets".  *Note Phony Targets::, for information about
    552573this kind of target.  *Note Errors in Commands: Errors, to see how to
    553 cause `make' to ignore errors from `rm' or any other command.
     574cause `make' to ignore errors from `rm' or any other command. 
    554575
    555576
    556577File: make.info,  Node: How Make Works,  Next: Variables Simplify,  Prev: Simple Makefile,  Up: Introduction
    557578
    558 How `make' Processes a Makefile
    559 ===============================
     5792.3 How `make' Processes a Makefile
     580===================================
    560581
    561582By default, `make' starts with the first target (not targets whose
    562583names start with `.').  This is called the "default goal".  ("Goals"
    563 are the targets that `make' strives ultimately to update.  *Note
    564 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.). 
    565588
    566589   In the simple example of the previous section, the default goal is to
     
    597620not exist, or if any of the object files are newer than it.  If an
    598621object file was just recompiled, it is now newer than `edit', so `edit'
    599 is relinked.
     622is relinked. 
    600623
    601624   Thus, if we change the file `insert.c' and run `make', `make' will
     
    608631File: make.info,  Node: Variables Simplify,  Next: make Deduces,  Prev: How Make Works,  Up: Introduction
    609632
    610 Variables Make Makefiles Simpler
    611 ================================
     6332.4 Variables Make Makefiles Simpler
     634====================================
    612635
    613636In our example, we had to list all the object files twice in the rule
     
    642665     objects = main.o kbd.o command.o display.o \
    643666               insert.o search.o files.o utils.o
    644      
     667
    645668     edit : $(objects)
    646669             cc -o edit $(objects)
     
    667690File: make.info,  Node: make Deduces,  Next: Combine By Prerequisite,  Prev: Variables Simplify,  Up: Introduction
    668691
    669 Letting `make' Deduce the Commands
    670 ==================================
     6922.5 Letting `make' Deduce the Commands
     693======================================
    671694
    672695It is not necessary to spell out the commands for compiling the
     
    687710     objects = main.o kbd.o command.o display.o \
    688711               insert.o search.o files.o utils.o
    689      
     712
    690713     edit : $(objects)
    691714             cc -o edit $(objects)
    692      
     715
    693716     main.o : defs.h
    694717     kbd.o : defs.h command.h
     
    699722     files.o : defs.h buffer.h command.h
    700723     utils.o : defs.h
    701      
     724
    702725     .PHONY : clean
    703726     clean :
     
    714737File: make.info,  Node: Combine By Prerequisite,  Next: Cleanup,  Prev: make Deduces,  Up: Introduction
    715738
    716 Another Style of Makefile
    717 =========================
     7392.6 Another Style of Makefile
     740=============================
    718741
    719742When the objects of a makefile are created only by implicit rules, an
     
    724747     objects = main.o kbd.o command.o display.o \
    725748               insert.o search.o files.o utils.o
    726      
     749
    727750     edit : $(objects)
    728751             cc -o edit $(objects)
    729      
     752
    730753     $(objects) : defs.h
    731754     kbd.o command.o files.o : command.h
     
    743766File: make.info,  Node: Cleanup,  Prev: Combine By Prerequisite,  Up: Introduction
    744767
    745 Rules for Cleaning the Directory
    746 ================================
     7682.7 Rules for Cleaning the Directory
     769====================================
    747770
    748771Compiling a program is not the only thing you might want to write rules
     
    782805File: make.info,  Node: Makefiles,  Next: Rules,  Prev: Introduction,  Up: Top
    783806
    784 Writing Makefiles
    785 *****************
     8073 Writing Makefiles
     808*******************
    786809
    787810The information that tells `make' how to recompile a system comes from
     
    800823                                  with another makefile.
    801824* Reading Makefiles::           How makefiles are parsed.
     825* Secondary Expansion::         How and when secondary expansion is performed.
    802826
    803827
    804828File: make.info,  Node: Makefile Contents,  Next: Makefile Names,  Prev: Makefiles,  Up: Makefiles
    805829
    806 What Makefiles Contain
    807 ======================
     8303.1 What Makefiles Contain
     831==========================
    808832
    809833Makefiles contain five kinds of things: "explicit rules", "implicit
     
    865889File: make.info,  Node: Makefile Names,  Next: Include,  Prev: Makefile Contents,  Up: Makefiles
    866890
    867 What Name to Give Your Makefile
    868 ===============================
     8913.2 What Name to Give Your Makefile
     892===================================
    869893
    870894By default, when `make' looks for the makefile, it tries the following
    871 names, in order: `GNUmakefile', `makefile' and `Makefile'.
     895names, in order: `GNUmakefile', `makefile' and `Makefile'. 
    872896
    873897   Normally you should call your makefile either `makefile' or
     
    892916concatenated in the order specified.  The default makefile names
    893917`GNUmakefile', `makefile' and `Makefile' are not checked automatically
    894 if you specify `-f' or `--file'.
     918if you specify `-f' or `--file'. 
    895919
    896920
    897921File: make.info,  Node: Include,  Next: MAKEFILES Variable,  Prev: Makefile Names,  Up: Makefiles
    898922
    899 Including Other Makefiles
    900 =========================
     9233.3 Including Other Makefiles
     924=============================
    901925
    902926The `include' directive tells `make' to suspend reading the current
     
    906930     include FILENAMES...
    907931
    908 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. 
    909934
    910935   Extra spaces are allowed and ignored at the beginning of the line,
     
    943968than that of somehow appending the prerequisites to the end of the main
    944969makefile as has been traditionally done with other versions of `make'.
    945 *Note Automatic Prerequisites::.
     970*Note Automatic Prerequisites::. 
    946971
    947972   If the specified name does not start with a slash, and the file is
     
    9811006File: make.info,  Node: MAKEFILES Variable,  Next: MAKEFILE_LIST Variable,  Prev: Include,  Up: Makefiles
    9821007
    983 The Variable `MAKEFILES'
    984 ========================
     10083.4 The Variable `MAKEFILES'
     1009============================
    9851010
    9861011If the environment variable `MAKEFILES' is defined, `make' considers
     
    10101035File: make.info,  Node: MAKEFILE_LIST Variable,  Next: Special Variables,  Prev: MAKEFILES Variable,  Up: Makefiles
    10111036
    1012 The Variable `MAKEFILE_LIST'
    1013 ============================
     10373.5 The Variable `MAKEFILE_LIST'
     1038================================
    10141039
    10151040As `make' reads various makefiles, including any obtained from the
     
    10261051   If a makefile named `Makefile' has this content:
    10271052
    1028      name1 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
    1029      
     1053     name1 := $(lastword $(MAKEFILE_LIST))
     1054
    10301055     include inc.mk
    1031      
    1032      name2 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
    1033      
     1056
     1057     name2 := $(lastword $(MAKEFILE_LIST))
     1058
    10341059     all:
    10351060             @echo name1 = $(name1)
     
    10491074File: make.info,  Node: Special Variables,  Next: Remaking Makefiles,  Prev: MAKEFILE_LIST Variable,  Up: Makefiles
    10501075
    1051 Other Special Variables
    1052 =======================
    1053 
    1054 GNU `make' also supports a special variable.  Note that any value you
    1055 assign to this variable will be ignored; it will always return its
    1056 special value.
    1057 
    1058    The first special variable is `.VARIABLES'.  When expanded, the
    1059 value consists of a list of the _names_ of all global variables defined
    1060 in all makefiles read up until that point.  This includes variables
    1061 which have empty values, as well as built-in variables (*note Variables
    1062 Used by Implicit Rules: Implicit Variables.), but does not include any
    1063 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
    10641175
    10651176
    10661177File: make.info,  Node: Remaking Makefiles,  Next: Overriding Makefiles,  Prev: Special Variables,  Up: Makefiles
    10671178
    1068 How Makefiles Are Remade
    1069 ========================
     11793.7 How Makefiles Are Remade
     1180============================
    10701181
    10711182Sometimes makefiles can be remade from other files, such as RCS or SCCS
     
    11041215   If you do not specify any makefiles to be read with `-f' or `--file'
    11051216options, `make' will try the default makefile names; *note What Name to
    1106 Give Your Makefile: Makefile Names..  Unlike makefiles explicitly
     1217Give Your Makefile: Makefile Names.  Unlike makefiles explicitly
    11071218requested with `-f' or `--file' options, `make' is not certain that
    11081219these makefiles should exist.  However, if a default makefile does not
     
    11441255File: make.info,  Node: Overriding Makefiles,  Next: Reading Makefiles,  Prev: Remaking Makefiles,  Up: Makefiles
    11451256
    1146 Overriding Part of Another Makefile
    1147 ===================================
     12573.8 Overriding Part of Another Makefile
     1258=======================================
    11481259
    11491260Sometimes it is useful to have a makefile that is mostly just like
     
    11651276     foo:
    11661277             frobnicate > foo
    1167      
     1278
    11681279     %: force
    11691280             @$(MAKE) -f Makefile $@
     
    11871298
    11881299
    1189 File: make.info,  Node: Reading Makefiles,  Prev: Overriding Makefiles,  Up: Makefiles
    1190 
    1191 How `make' Reads a Makefile
    1192 ===========================
     1300File: make.info,  Node: Reading Makefiles,  Next: Secondary Expansion,  Prev: Overriding Makefiles,  Up: Makefiles
     1301
     13023.9 How `make' Reads a Makefile
     1303===============================
    11931304
    11941305GNU `make' does its work in two distinct phases.  During the first
     
    12251336     IMMEDIATE := IMMEDIATE
    12261337     IMMEDIATE += DEFERRED or IMMEDIATE
    1227      
     1338
    12281339     define IMMEDIATE
    12291340       DEFERRED
     
    12391350All instances of conditional syntax are parsed immediately, in their
    12401351entirety; this includes the `ifdef', `ifeq', `ifndef', and `ifneq'
    1241 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.
    12421357
    12431358Rule Definition
     
    12551370
    12561371
     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
    12571551File: make.info,  Node: Rules,  Next: Commands,  Prev: Makefiles,  Up: Top
    12581552
    1259 Writing Rules
    1260 *************
     15534 Writing Rules
     1554***************
    12611555
    12621556A "rule" appears in the makefile and says when and how to remake
     
    12891583* Phony Targets::               Using a target that is not a real file's name.
    12901584* Force Targets::               You can use a target without commands
    1291                                   or prerequisites to mark other
    1292                                   targets as phony.
     1585                                  or prerequisites to mark other targets
     1586                                  as phony.
    12931587* Empty Targets::               When only the date matters and the
    12941588                                  files are empty.
     
    13071601File: make.info,  Node: Rule Example,  Next: Rule Syntax,  Prev: Rules,  Up: Rules
    13081602
    1309 Rule Example
    1310 ============
     16034.1 Rule Example
     1604================
    13111605
    13121606Here is an example of a rule:
     
    13331627File: make.info,  Node: Rule Syntax,  Next: Prerequisite Types,  Prev: Rule Example,  Up: Rules
    13341628
    1335 Rule Syntax
    1336 ===========
     16294.2 Rule Syntax
     1630===============
    13371631
    13381632In general, a rule looks like this:
     
    13591653appear on the line after the prerequisites, with a tab character, or may
    13601654appear on the same line, with a semicolon.  Either way, the effect is
    1361 the same.  *Note Writing the Commands in Rules: Commands.
    1362 
    1363    Because dollar signs are used to start variable references, if you
    1364 really want a dollar sign in a rule you must write two of them, `$$'
    1365 (*note How to Use Variables: Using Variables.).  You may split a long
    1366 line by inserting a backslash followed by a newline, but this is not
    1367 required, as `make' places no limit on the length of a line in a
    1368 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.
    13691668
    13701669   A rule tells `make' two things: when the targets are out of date,
     
    13881687File: make.info,  Node: Prerequisite Types,  Next: Wildcards,  Prev: Rule Syntax,  Up: Rules
    13891688
    1390 Types of Prerequisites
    1391 ======================
     16894.3 Types of Prerequisites
     1690==========================
    13921691
    13931692There are actually two different types of prerequisites understood by
     
    14241723File: make.info,  Node: Wildcards,  Next: Directory Search,  Prev: Prerequisite Types,  Up: Rules
    14251724
    1426 Using Wildcard Characters in File Names
    1427 =======================================
     17254.4 Using Wildcard Characters in File Names
     1726===========================================
    14281727
    14291728A single file name can specify many files using "wildcard characters".
     
    14411740simulated by setting the environment variable HOME.
    14421741
    1443    Wildcard expansion happens automatically in targets, in
    1444 prerequisites, and in commands (where the shell does the expansion).
    1445 In other contexts, wildcard expansion happens only if you request it
    1446 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.
    14471746
    14481747   The special significance of a wildcard character can be turned off by
     
    14601759File: make.info,  Node: Wildcard Examples,  Next: Wildcard Pitfall,  Prev: Wildcards,  Up: Wildcards
    14611760
    1462 Wildcard Examples
    1463 -----------------
     17614.4.1 Wildcard Examples
     1762-----------------------
    14641763
    14651764Wildcards can be used in the commands of a rule, where they are expanded
     
    15001799File: make.info,  Node: Wildcard Pitfall,  Next: Wildcard Function,  Prev: Wildcard Examples,  Up: Wildcards
    15011800
    1502 Pitfalls of Using Wildcards
    1503 ---------------------------
     18014.4.2 Pitfalls of Using Wildcards
     1802---------------------------------
    15041803
    15051804Now here is an example of a naive way of using wildcard expansion, that
     
    15091808
    15101809     objects = *.o
    1511      
     1810
    15121811     foo : $(objects)
    15131812             cc -o foo $(CFLAGS) $(objects)
     
    15431842File: make.info,  Node: Wildcard Function,  Prev: Wildcard Pitfall,  Up: Wildcards
    15441843
    1545 The Function `wildcard'
    1546 -----------------------
     18444.4.3 The Function `wildcard'
     1845-----------------------------
    15471846
    15481847Wildcard expansion happens automatically in rules.  But wildcard
     
    15791878
    15801879     objects := $(patsubst %.c,%.o,$(wildcard *.c))
    1581      
     1880
    15821881     foo : $(objects)
    15831882             cc -o foo $(objects)
     
    15911890File: make.info,  Node: Directory Search,  Next: Phony Targets,  Prev: Wildcards,  Up: Rules
    15921891
    1593 Searching Directories for Prerequisites
    1594 =======================================
     18924.5 Searching Directories for Prerequisites
     1893===========================================
    15951894
    15961895For large systems, it is often desirable to put sources in a separate
     
    16151914File: make.info,  Node: General Search,  Next: Selective Search,  Prev: Directory Search,  Up: Directory Search
    16161915
    1617 `VPATH': Search Path for All Prerequisites
    1618 ------------------------------------------
     19164.5.1 `VPATH': Search Path for All Prerequisites
     1917------------------------------------------------
    16191918
    16201919The value of the `make' variable `VPATH' specifies a list of
     
    16591958File: make.info,  Node: Selective Search,  Next: Search Algorithm,  Prev: General Search,  Up: Directory Search
    16601959
    1661 The `vpath' Directive
    1662 ---------------------
     19604.5.2 The `vpath' Directive
     1961---------------------------
    16631962
    16641963Similar to the `VPATH' variable, but more selective, is the `vpath'
     
    17382037File: make.info,  Node: Search Algorithm,  Next: Commands/Search,  Prev: Selective Search,  Up: Directory Search
    17392038
    1740 How Directory Searches are Performed
    1741 ------------------------------------
     20394.5.3 How Directory Searches are Performed
     2040------------------------------------------
    17422041
    17432042When a prerequisite is found through directory search, regardless of
     
    17962095File: make.info,  Node: Commands/Search,  Next: Implicit/Search,  Prev: Search Algorithm,  Up: Directory Search
    17972096
    1798 Writing Shell Commands with Directory Search
    1799 --------------------------------------------
     20974.5.4 Writing Shell Commands with Directory Search
     2098--------------------------------------------------
    18002099
    18012100When a prerequisite is found in another directory through directory
     
    18172116compilation by implicit rules; we use it here for consistency so it will
    18182117affect all C compilations uniformly; *note Variables Used by Implicit
    1819 Rules: Implicit Variables..)
     2118Rules: Implicit Variables.)
    18202119
    18212120   Often the prerequisites include header files as well, which you do
     
    18302129File: make.info,  Node: Implicit/Search,  Next: Libraries/Search,  Prev: Commands/Search,  Up: Directory Search
    18312130
    1832 Directory Search and Implicit Rules
    1833 -----------------------------------
     21314.5.5 Directory Search and Implicit Rules
     2132-----------------------------------------
    18342133
    18352134The search through the directories specified in `VPATH' or with `vpath'
     
    18512150File: make.info,  Node: Libraries/Search,  Prev: Implicit/Search,  Up: Directory Search
    18522151
    1853 Directory Search for Link Libraries
    1854 -----------------------------------
     21524.5.6 Directory Search for Link Libraries
     2153-----------------------------------------
    18552154
    18562155Directory search applies in a special way to libraries used with the
     
    18902189word in the list will be used.
    18912190
    1892    The default value for `.LIBPATTERNS' is "`lib%.so lib%.a'", which
     2191   The default value for `.LIBPATTERNS' is `lib%.so lib%.a', which
    18932192provides the default behavior described above.
    18942193
     
    18992198File: make.info,  Node: Phony Targets,  Next: Force Targets,  Prev: Directory Search,  Up: Rules
    19002199
    1901 Phony Targets
    1902 =============
     22004.6 Phony Targets
     2201=================
    19032202
    19042203A phony target is one that is not really the name of a file.  It is
     
    19162215Because the `rm' command does not create a file named `clean', probably
    19172216no such file will ever exist.  Therefore, the `rm' command will be
    1918 executed every time you say `make clean'.
     2217executed every time you say `make clean'. 
    19192218
    19202219   The phony target will cease to work if anything ever does create a
     
    19462245   Another example of the usefulness of phony targets is in conjunction
    19472246with recursive invocations of `make' (for more information, see *Note
    1948 Recursive Use of `make': Recursion).  In this case the makefile will
     2247Recursive Use of `make': Recursion.).  In this case the makefile will
    19492248often contain a variable which lists a number of subdirectories to be
    19502249built.  One way to handle this is with one rule whose command is a
     
    19522251
    19532252     SUBDIRS = foo bar baz
    1954      
     2253
    19552254     subdirs:
    19562255             for dir in $(SUBDIRS); do \
     
    19642263it will do so even if `make' is invoked with the `-k' option, which is
    19652264unfortunate.  Second, and perhaps more importantly, you cannot take
    1966 advantage of the parallel build capabilities of make using this method,
    1967 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.
    19682267
    19692268   By declaring the subdirectories as phony targets (you must do this as
     
    19722271
    19732272     SUBDIRS = foo bar baz
    1974      
     2273
    19752274     .PHONY: subdirs $(SUBDIRS)
    1976      
     2275
    19772276     subdirs: $(SUBDIRS)
    1978      
     2277
    19792278     $(SUBDIRS):
    19802279             $(MAKE) -C $@
    1981      
     2280
    19822281     foo: baz
    19832282
     
    20032302     all : prog1 prog2 prog3
    20042303     .PHONY : all
    2005      
     2304
    20062305     prog1 : prog1.o utils.o
    20072306             cc -o prog1 prog1.o utils.o
    2008      
     2307
    20092308     prog2 : prog2.o
    20102309             cc -o prog2 prog2.o
    2011      
     2310
    20122311     prog3 : prog3.o sort.o utils.o
    20132312             cc -o prog3 prog3.o sort.o utils.o
    20142313
    20152314Now you can say just `make' to remake all three programs, or specify as
    2016 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.
    20172318
    20182319   When one phony target is a prerequisite of another, it serves as a
     
    20212322
    20222323     .PHONY: cleanall cleanobj cleandiff
    2023      
     2324
    20242325     cleanall : cleanobj cleandiff
    20252326             rm program
    2026      
     2327
    20272328     cleanobj :
    20282329             rm *.o
    2029      
     2330
    20302331     cleandiff :
    20312332             rm *.diff
     
    20342335File: make.info,  Node: Force Targets,  Next: Empty Targets,  Prev: Phony Targets,  Up: Rules
    20352336
    2036 Rules without Commands or Prerequisites
    2037 =======================================
     23374.7 Rules without Commands or Prerequisites
     2338===========================================
    20382339
    20392340If a rule has no prerequisites or commands, and the target of the rule
     
    20632364File: make.info,  Node: Empty Targets,  Next: Special Targets,  Prev: Force Targets,  Up: Rules
    20642365
    2065 Empty Target Files to Record Events
    2066 ===================================
     23664.8 Empty Target Files to Record Events
     2367=======================================
    20672368
    20682369The "empty target" is a variant of the phony target; it is used to hold
     
    20852386             lpr -p $?
    20862387             touch print
    2087 
     2388   
    20882389With this rule, `make print' will execute the `lpr' command if either
    20892390source file has changed since the last `make print'.  The automatic
     
    20942395File: make.info,  Node: Special Targets,  Next: Multiple Targets,  Prev: Empty Targets,  Up: Rules
    20952396
    2096 Special Built-in Target Names
    2097 =============================
     23974.9 Special Built-in Target Names
     2398=================================
    20982399
    20992400Certain names have special meanings if they appear as targets.
     
    21482449     intermediate).
    21492450
     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
    21502461`.DELETE_ON_ERROR'
    21512462     If `.DELETE_ON_ERROR' is mentioned as a target anywhere in the
     
    22342545File: make.info,  Node: Multiple Targets,  Next: Multiple Rules,  Prev: Special Targets,  Up: Rules
    22352546
    2236 Multiple Targets in a Rule
    2237 ==========================
     25474.10 Multiple Targets in a Rule
     2548===============================
    22382549
    22392550A rule with multiple targets is equivalent to writing many rules, each
     
    22592570          bigoutput littleoutput : text.g
    22602571                  generate text.g -$(subst output,,$@) > $@
    2261 
     2572     
    22622573     is equivalent to
    22632574
     
    22812592File: make.info,  Node: Multiple Rules,  Next: Static Pattern,  Prev: Multiple Targets,  Up: Rules
    22822593
    2283 Multiple Rules for One Target
    2284 =============================
     25944.11 Multiple Rules for One Target
     2595==================================
    22852596
    22862597One file can be the target of several rules.  All the prerequisites
     
    23322643File: make.info,  Node: Static Pattern,  Next: Double-Colon,  Prev: Multiple Rules,  Up: Rules
    23332644
    2334 Static Pattern Rules
    2335 ====================
     26454.12 Static Pattern Rules
     2646=========================
    23362647
    23372648"Static pattern rules" are rules which specify multiple targets and
     
    23492660File: make.info,  Node: Static Usage,  Next: Static versus Implicit,  Prev: Static Pattern,  Up: Static Pattern
    23502661
    2351 Syntax of Static Pattern Rules
    2352 ------------------------------
     26624.12.1 Syntax of Static Pattern Rules
     2663-------------------------------------
    23532664
    23542665Here is the syntax of a static pattern rule:
     
    23982709
    23992710     objects = foo.o bar.o
    2400      
     2711
    24012712     all: $(objects)
    2402      
     2713
    24032714     $(objects): %.o: %.c
    24042715             $(CC) -c $(CFLAGS) $< -o $@
     
    24152726
    24162727     files = foo.elc bar.o lose.o
    2417      
     2728
    24182729     $(filter %.o,$(files)): %.o: %.c
    24192730             $(CC) -c $(CFLAGS) $< -o $@
     
    24272738from `foo.el'.
    24282739
    2429    Another example shows how to use `$*' in static pattern rules:
     2740   Another example shows how to use `$*' in static pattern rules: 
    24302741
    24312742     bigoutput littleoutput : %output : text.g
     
    24382749File: make.info,  Node: Static versus Implicit,  Prev: Static Usage,  Up: Static Pattern
    24392750
    2440 Static Pattern Rules versus Implicit Rules
    2441 ------------------------------------------
     27514.12.2 Static Pattern Rules versus Implicit Rules
     2752-------------------------------------------------
    24422753
    24432754A static pattern rule has much in common with an implicit rule defined
     
    24752786File: make.info,  Node: Double-Colon,  Next: Automatic Prerequisites,  Prev: Static Pattern,  Up: Rules
    24762787
    2477 Double-Colon Rules
    2478 ==================
     27884.13 Double-Colon Rules
     2789=======================
    24792790
    24802791"Double-colon" rules are rules written with `::' instead of `:' after
     
    25122823File: make.info,  Node: Automatic Prerequisites,  Prev: Double-Colon,  Up: Rules
    25132824
    2514 Generating Prerequisites Automatically
    2515 ======================================
     28254.14 Generating Prerequisites Automatically
     2826===========================================
    25162827
    25172828In the makefile for a program, many of the rules you need to write often
     
    25252836would have to write dozens of such rules in your makefile.  And, you
    25262837must always be very careful to update the makefile every time you add
    2527 or remove an `#include'.
     2838or remove an `#include'. 
    25282839
    25292840   To avoid this hassle, most modern C compilers can write these rules
     
    25442855makefile, so it can never be considered an intermediate file by implicit
    25452856rule search.  This means that `make' won't ever remove the file after
    2546 using it; *note Chains of Implicit Rules: Chained Rules..
     2857using it; *note Chains of Implicit Rules: Chained Rules.
    25472858
    25482859   With old `make' programs, it was traditional practice to use this
     
    25682879
    25692880     %.d: %.c
    2570              
     2881             @set -e; rm -f $@; \
    25712882              $(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
    25722883              sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
     
    25752886*Note Pattern Rules::, for information on defining pattern rules.  The
    25762887`-e' flag to the shell causes it to exit immediately if the `$(CC)'
    2577 command (or any other command) fails (exits with a nonzero status).
     2888command (or any other command) fails (exits with a nonzero status). 
    25782889
    25792890   With the GNU C compiler, you may wish to use the `-MM' flag instead
     
    26002911
    26012912     sources = foo.c bar.c
    2602      
     2913
    26032914     include $(sources:.c=.d)
    26042915
     
    26112922
    26122923   Note that the `.d' files contain target definitions; you should be
    2613 sure to place the `include' directive _after_ the first, default target
     2924sure to place the `include' directive _after_ the first, default goal
    26142925in your makefiles or run the risk of having a random object file become
    2615 the default target.  *Note How Make Works::.
     2926the default goal.  *Note How Make Works::.
    26162927
    26172928
    26182929File: make.info,  Node: Commands,  Next: Using Variables,  Prev: Rules,  Up: Top
    26192930
    2620 Writing the Commands in Rules
    2621 *****************************
    2622 
    2623 The commands of a rule consist of shell command lines to be executed one
    2624 by one.  Each command line must start with a tab, except that the first
    2625 command line may be attached to the target-and-prerequisites line with a
    2626 semicolon in between.  Blank lines and lines of just comments may appear
    2627 among the command lines; they are ignored.  (But beware, an apparently
    2628 "blank" line that begins with a tab is _not_ blank!  It is an empty
    2629 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.
    26302938
    26312939   Users use many different shell programs, but commands in makefiles
     
    26332941otherwise.  *Note Command Execution: Execution.
    26342942
    2635    The shell that is in use determines whether comments can be written
    2636 on command lines, and what syntax they use.  When the shell is
    2637 `/bin/sh', a `#' starts a comment that extends to the end of the line.
    2638 The `#' does not have to be at the beginning of a line.  Text on a line
    2639 before a `#' is not part of the comment.
    2640 
    26412943* Menu:
    26422944
     2945* Command Syntax::              Command syntax features and pitfalls.
    26432946* Echoing::                     How to control when commands are echoed.
    26442947* Execution::                   How commands are executed.
     
    26512954
    26522955
    2653 File: make.info,  Node: Echoing,  Next: Execution,  Prev: Commands,  Up: Commands
    2654 
    2655 Command Echoing
    2656 ===============
     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===================
    26573134
    26583135Normally `make' prints each command line before it is executed.  We
     
    26833160File: make.info,  Node: Execution,  Next: Parallel,  Prev: Echoing,  Up: Commands
    26843161
    2685 Command Execution
    2686 =================
     31625.3 Command Execution
     3163=====================
    26873164
    26883165When it is time to execute commands to update a target, they are
    2689 executed by making a new subshell for each line.  (In practice, `make'
    2690 may take shortcuts that do not affect the results.)
    2691 
    2692    *Please note:* this implies that shell commands such as `cd' that
    2693 set variables local to each process will not affect the following
    2694 command lines. (1)  If you want to use `cd' to affect the next command,
    2695 put the two on a single line with a semicolon between them.  Then
    2696 `make' will consider them a single command and pass them, together, to
    2697 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:
    26983176
    26993177     foo : bar/lose
    2700              cd bar; gobble lose > ../foo
    2701 
    2702    If you would like to split a single shell command into multiple
    2703 lines of text, you must use a backslash at the end of all but the last
    2704 subline.  Such a sequence of lines is combined into a single line, by
    2705 deleting the backslash-newline sequences, before passing it to the
    2706 shell.  Thus, the following is equivalent to the preceding example:
    2707 
    2708      foo : bar/lose
    2709              cd bar;  \
    2710              gobble lose > ../foo
    2711 
    2712    The program used as the shell is taken from the variable `SHELL'.
    2713 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.
    27143233
    27153234   On MS-DOS, if `SHELL' is not set, the value of the variable
     
    27573276
    27583277   The effect of the above DOS-specific processing is that a Makefile
    2759 that says `SHELL = /bin/sh' (as many Unix makefiles do), will work on
    2760 MS-DOS unaltered if you have e.g. `sh.exe' installed in some directory
    2761 along your `PATH'.
    2762 
    2763    Unlike most variables, the variable `SHELL' is never set from the
    2764 environment.  This is because the `SHELL' environment variable is used
    2765 to specify your personal choice of shell program for interactive use.
    2766 It would be very bad for personal choices like this to affect the
    2767 functioning of makefiles.  *Note Variables from the Environment:
    2768 Environment.  However, on MS-DOS and MS-Windows the value of `SHELL' in
    2769 the environment *is* used, since on those systems most users do not set
    2770 this variable, and therefore it is most likely set specifically to be
    2771 used by `make'.  On MS-DOS, if the setting of `SHELL' is not suitable
    2772 for `make', you can set the variable `MAKESHELL' to the shell that
    2773 `make' should use; this will override the value of `SHELL'.
    2774 
    2775    ---------- Footnotes ----------
    2776 
    2777    (1) On MS-DOS, the value of current working directory is *global*,
    2778 so changing it _will_ affect the following command lines on those
    2779 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'.
    27803281
    27813282
    27823283File: make.info,  Node: Parallel,  Next: Errors,  Prev: Execution,  Up: Commands
    27833284
    2784 Parallel Execution
    2785 ==================
     32855.4 Parallel Execution
     3286======================
    27863287
    27873288GNU `make' knows how to execute several commands at once.  Normally,
     
    28093310streams of all but one running command.  This means that attempting to
    28103311read from standard input will usually be a fatal error (a `Broken pipe'
    2811 signal) for most child processes if there are several.
     3312signal) for most child processes if there are several. 
    28123313
    28133314   It is unpredictable which command will have a valid standard input
     
    28583359File: make.info,  Node: Errors,  Next: Interrupts,  Prev: Parallel,  Up: Commands
    28593360
    2860 Errors in Commands
    2861 ==================
     33615.5 Errors in Commands
     3362======================
    28623363
    28633364After each shell command returns, `make' looks at its exit status.  If
     
    29173418program as possible, perhaps to find several independent problems so
    29183419that you can correct them all before the next attempt to compile.  This
    2919 is why Emacs' `compile' command passes the `-k' flag by default.
     3420is why Emacs' `compile' command passes the `-k' flag by default. 
    29203421
    29213422   Usually when a command fails, if it has changed the target file at
     
    29343435File: make.info,  Node: Interrupts,  Next: Recursion,  Prev: Errors,  Up: Commands
    29353436
    2936 Interrupting or Killing `make'
    2937 ==============================
     34375.6 Interrupting or Killing `make'
     3438==================================
    29383439
    29393440If `make' gets a fatal signal while a command is executing, it may
     
    29653466File: make.info,  Node: Recursion,  Next: Sequences,  Prev: Interrupts,  Up: Commands
    29663467
    2967 Recursive Use of `make'
    2968 =======================
     34685.7 Recursive Use of `make'
     3469===========================
    29693470
    29703471Recursive use of `make' means using `make' as a command in a makefile.
     
    29823483     subsystem:
    29833484             $(MAKE) -C subdir
    2984 
     3485   
    29853486   You can write recursive `make' commands just by copying this example,
    29863487but there are many things to know about how they work and why, and about
     
    30123513File: make.info,  Node: MAKE Variable,  Next: Variables/Recursion,  Prev: Recursion,  Up: Recursion
    30133514
    3014 How the `MAKE' Variable Works
    3015 -----------------------------
     35155.7.1 How the `MAKE' Variable Works
     3516-----------------------------------
    30163517
    30173518Recursive `make' commands should always use the variable `MAKE', not
     
    30253526is `cd subdir && /bin/make'.  If you use a special version of `make' to
    30263527run the top-level makefile, the same special version will be executed
    3027 for recursive invocations.
     3528for recursive invocations. 
    30283529
    30293530   As a special feature, using the variable `MAKE' in the commands of a
     
    30433544file named `subsystem' and do nothing else.  What you really want it to
    30443545do is run `cd subdir && make -t'; but that would require executing the
    3045 command, and `-t' says not to execute commands.
     3546command, and `-t' says not to execute commands. 
    30463547
    30473548   The special feature makes this do what you want: whenever a command
     
    30573558File: make.info,  Node: Variables/Recursion,  Next: Options/Recursion,  Prev: MAKE Variable,  Up: Recursion
    30583559
    3059 Communicating Variables to a Sub-`make'
    3060 ---------------------------------------
     35605.7.2 Communicating Variables to a Sub-`make'
     3561---------------------------------------------
    30613562
    30623563Variable values of the top-level `make' can be passed to the sub-`make'
     
    30773578characters other than letters, numbers, and underscores.
    30783579
    3079    The special variables `SHELL' and `MAKEFLAGS' are always exported
    3080 (unless you unexport them).  `MAKEFILES' is exported if you set it to
    3081 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.
    30823588
    30833589   `make' automatically passes down variable values that were defined
     
    31543660`.EXPORT_ALL_VARIABLES' instead of using the `export' directive.  This
    31553661will be ignored by old `make's, while the `export' directive will cause
    3156 a syntax error.
     3662a syntax error. 
    31573663
    31583664   Likewise, you can use `unexport' by itself to tell `make' _not_ to
     
    31873693File: make.info,  Node: Options/Recursion,  Next: -w Option,  Prev: Variables/Recursion,  Up: Recursion
    31883694
    3189 Communicating Options to a Sub-`make'
    3190 -------------------------------------
     36955.7.3 Communicating Options to a Sub-`make'
     3696-------------------------------------------
    31913697
    31923698Flags such as `-s' and `-k' are passed automatically to the sub-`make'
     
    32923798File: make.info,  Node: -w Option,  Prev: Options/Recursion,  Up: Recursion
    32933799
    3294 The `--print-directory' Option
    3295 ------------------------------
     38005.7.4 The `--print-directory' Option
     3801------------------------------------
    32963802
    32973803If you use several levels of recursive `make' invocations, the `-w' or
     
    33183824File: make.info,  Node: Sequences,  Next: Empty Commands,  Prev: Recursion,  Up: Commands
    33193825
    3320 Defining Canned Command Sequences
    3321 =================================
     38265.8 Defining Canned Command Sequences
     3827=====================================
    33223828
    33233829When the same sequence of commands is useful in making various targets,
     
    33333839     mv y.tab.c $@
    33343840     endef
    3335 
     3841   
    33363842Here `run-yacc' is the name of the variable being defined; `endef'
    33373843marks the end of the definition; the lines in between are the commands.
     
    33933899File: make.info,  Node: Empty Commands,  Prev: Sequences,  Up: Commands
    33943900
    3395 Using Empty Commands
    3396 ====================
     39015.9 Using Empty Commands
     3902========================
    33973903
    33983904It is sometimes useful to define commands which do nothing.  This is
     
    34223928File: make.info,  Node: Using Variables,  Next: Conditionals,  Prev: Commands,  Up: Top
    34233929
    3424 How to Use Variables
    3425 ********************
     39306 How to Use Variables
     3931**********************
    34263932
    34273933A "variable" is a name defined in a makefile to represent a string of
     
    34293935explicit request into targets, prerequisites, commands, and other parts
    34303936of the makefile.  (In some other versions of `make', variables are
    3431 called "macros".)
     3937called "macros".) 
    34323938
    34333939   Variables and functions in all parts of a makefile are expanded when
     
    34843990File: make.info,  Node: Reference,  Next: Flavors,  Prev: Using Variables,  Up: Using Variables
    34853991
    3486 Basics of Variable References
    3487 =============================
     39926.1 Basics of Variable References
     3993=================================
    34883994
    34893995To substitute a variable's value, write a dollar sign followed by the
     
    35014007     program : $(objects)
    35024008             cc -o program $(objects)
    3503      
     4009
    35044010     $(objects) : defs.h
    35054011
     
    35244030File: make.info,  Node: Flavors,  Next: Advanced,  Prev: Reference,  Up: Using Variables
    35254031
    3526 The Two Flavors of Variables
    3527 ============================
     40326.2 The Two Flavors of Variables
     4033================================
    35284034
    35294035There are two ways that a variable in GNU `make' can have a value; we
     
    35454051     bar = $(ugh)
    35464052     ugh = Huh?
    3547      
     4053
    35484054     all:;echo $(foo)
    35494055
     
    35654071
    35664072because it will cause an infinite loop in the variable expansion.
    3567 (Actually `make' detects the infinite loop and reports an error.)
     4073(Actually `make' detects the infinite loop and reports an error.) 
    35684074
    35694075   Another disadvantage is that any functions (*note Functions for
     
    36064112
    36074113     ifeq (0,${MAKELEVEL})
    3608      cur-dir   := $(shell pwd)
    36094114     whoami    := $(shell whoami)
    36104115     host-type := $(shell arch)
     
    36164121
    36174122     ${subdirs}:
    3618            ${MAKE} cur-dir=${cur-dir}/$@ -C $@ all
     4123             ${MAKE} -C $@ all
    36194124
    36204125   Simply expanded variables generally make complicated makefile
     
    36704175File: make.info,  Node: Advanced,  Next: Values,  Prev: Flavors,  Up: Using Variables
    36714176
    3672 Advanced Features for Reference to Variables
    3673 ============================================
     41776.3 Advanced Features for Reference to Variables
     4178================================================
    36744179
    36754180This section describes some advanced features you can use to reference
     
    36854190File: make.info,  Node: Substitution Refs,  Next: Computed Names,  Prev: Advanced,  Up: Advanced
    36864191
    3687 Substitution References
    3688 -----------------------
     41926.3.1 Substitution References
     4193-----------------------------
    36894194
    36904195A "substitution reference" substitutes the value of a variable with
     
    37184223
    37194224For example:
    3720      
     4225
    37214226     foo := a.o b.o c.o
    37224227     bar := $(foo:%.o=%.c)
     
    37274232File: make.info,  Node: Computed Names,  Prev: Substitution Refs,  Up: Advanced
    37284233
    3729 Computed Variable Names
    3730 -----------------------
     42346.3.2 Computed Variable Names
     4235-----------------------------
    37314236
    37324237Computed variable names are a complicated concept needed only for
     
    37994304     a_dirs := dira dirb
    38004305     1_dirs := dir1 dir2
    3801      
     4306
    38024307     a_files := filea fileb
    38034308     1_files := file1 file2
    3804      
     4309
    38054310     ifeq "$(use_a)" "yes"
    38064311     a1 := a
     
    38084313     a1 := 1
    38094314     endif
    3810      
     4315
    38114316     ifeq "$(use_dirs)" "yes"
    38124317     df := dirs
     
    38144319     df := files
    38154320     endif
    3816      
     4321
    38174322     dirs := $($(a1)_$(df))
    38184323
     
    38244329     a_objects := a.o b.o c.o
    38254330     1_objects := 1.o 2.o 3.o
    3826      
     4331
    38274332     sources := $($(a1)_objects:.o=.c)
    38284333
     
    38404345     func := strip
    38414346     endif
    3842      
     4347
    38434348     bar := a d b g q c
    3844      
     4349
    38454350     foo := $($(func) $(bar))
    38464351
     
    38704375File: make.info,  Node: Values,  Next: Setting,  Prev: Advanced,  Up: Using Variables
    38714376
    3872 How Variables Get Their Values
    3873 ==============================
     43776.4 How Variables Get Their Values
     4378==================================
    38744379
    38754380Variables can get values in several different ways:
     
    38954400File: make.info,  Node: Setting,  Next: Appending,  Prev: Values,  Up: Using Variables
    38964401
    3897 Setting Variables
    3898 =================
     44026.5 Setting Variables
     4403=====================
    38994404
    39004405To set a variable from the makefile, write a line starting with the
     
    39484453File: make.info,  Node: Appending,  Next: Override Directive,  Prev: Setting,  Up: Using Variables
    39494454
    3950 Appending More Text to Variables
    3951 ================================
     44556.6 Appending More Text to Variables
     4456====================================
    39524457
    39534458Often it is useful to add more text to the value of a variable already
     
    39844489it a simply-expanded variable, `+=' adds to that simply-expanded
    39854490definition, and expands the new text before appending it to the old
    3986 value just as `:=' does (*note Setting Variables: Setting., for a full
    3987 explanation of `:=').  In fact,
     4491value just as `:=' does (see *Note Setting Variables: Setting, for a
     4492full explanation of `:=').  In fact,
    39884493
    39894494     variable := value
     
    39914496
    39924497is exactly equivalent to:
     4498
    39934499
    39944500     variable := value
     
    40234529The first line defines the `CFLAGS' variable with a reference to another
    40244530variable, `includes'.  (`CFLAGS' is used by the rules for C
    4025 compilation; *note Catalogue of Implicit Rules: Catalogue of Rules..)
     4531compilation; *note Catalogue of Implicit Rules: Catalogue of Rules.)
    40264532Using `=' for the definition makes `CFLAGS' a recursively-expanded
    40274533variable, meaning `$(includes) -O' is _not_ expanded when `make'
     
    40454551File: make.info,  Node: Override Directive,  Next: Defining,  Prev: Appending,  Up: Using Variables
    40464552
    4047 The `override' Directive
    4048 ========================
     45536.7 The `override' Directive
     4554============================
    40494555
    40504556If a variable has been set with a command argument (*note Overriding
     
    40894595File: make.info,  Node: Defining,  Next: Environment,  Prev: Override Directive,  Up: Using Variables
    40904596
    4091 Defining Variables Verbatim
    4092 ===========================
     45976.8 Defining Variables Verbatim
     4598===============================
    40934599
    40944600Another way to set the value of a variable is to use the `define'
     
    41484654File: make.info,  Node: Environment,  Next: Target-specific,  Prev: Defining,  Up: Using Variables
    41494655
    4150 Variables from the Environment
    4151 ==============================
     46566.9 Variables from the Environment
     4657==================================
    41524658
    41534659Variables in `make' can come from the environment in which `make' is
    41544660run.  Every environment variable that `make' sees when it starts up is
    4155 transformed into a `make' variable with the same name and value.  But
    4156 an explicit assignment in the makefile, or with a command argument,
    4157 overrides the environment.  (If the `-e' flag is specified, then values
    4158 from the environment override assignments in the makefile.  *Note
    4159 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
    41604666practice.)
    41614667
     
    41644670you prefer.  This is safe for variables with standard or conventional
    41654671meanings because you know that no makefile will use them for other
    4166 things.  (But this is not totally reliable; some makefiles set `CFLAGS'
    4167 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
    41684674environment.)
    41694675
    4170    When `make' is invoked recursively, variables defined in the outer
    4171 invocation can be passed to inner invocations through the environment
    4172 (*note Recursive Use of `make': Recursion.).  By default, only
    4173 variables that came from the environment or the command line are passed
    4174 to recursive invocations.  You can use the `export' directive to pass
    4175 other variables.  *Note Communicating Variables to a Sub-`make':
    4176 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.
    41774683
    41784684   Other use of variables from the environment is not recommended.  It
     
    41854691which is normally present in the environment to specify the user's
    41864692choice of interactive shell.  It would be very undesirable for this
    4187 choice to affect `make'.  So `make' ignores the environment value of
    4188 `SHELL' (except on MS-DOS and MS-Windows, where `SHELL' is usually not
    4189 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::.
    41904695
    41914696
    41924697File: make.info,  Node: Target-specific,  Next: Pattern-specific,  Prev: Environment,  Up: Using Variables
    41934698
    4194 Target-specific Variable Values
    4195 ===============================
     46996.10 Target-specific Variable Values
     4700====================================
    41964701
    41974702Variable values in `make' are usually global; that is, they are the
     
    42624767File: make.info,  Node: Pattern-specific,  Prev: Target-specific,  Up: Using Variables
    42634768
    4264 Pattern-specific Variable Values
    4265 ================================
     47696.11 Pattern-specific Variable Values
     4770=====================================
    42664771
    42674772In addition to target-specific variable values (*note Target-specific
     
    43004805File: make.info,  Node: Conditionals,  Next: Functions,  Prev: Using Variables,  Up: Top
    43014806
    4302 Conditional Parts of Makefiles
    4303 ******************************
     48077 Conditional Parts of Makefiles
     4808********************************
    43044809
    43054810A "conditional" causes part of a makefile to be obeyed or ignored
     
    43194824File: make.info,  Node: Conditional Example,  Next: Conditional Syntax,  Prev: Conditionals,  Up: Conditionals
    43204825
    4321 Example of a Conditional
    4322 ========================
     48267.1 Example of a Conditional
     4827============================
    43234828
    43244829The following example of a conditional tells `make' to use one set of
     
    43314836     libs_for_gcc = -lgnu
    43324837     normal_libs =
    4333      
     4838
    43344839     foo: $(objects)
    43354840     ifeq ($(CC),gcc)
     
    43814886     libs_for_gcc = -lgnu
    43824887     normal_libs =
    4383      
     4888
    43844889     ifeq ($(CC),gcc)
    43854890       libs=$(libs_for_gcc)
     
    43874892       libs=$(normal_libs)
    43884893     endif
    4389      
     4894
    43904895     foo: $(objects)
    43914896             $(CC) -o foo $(objects) $(libs)
     
    43944899File: make.info,  Node: Conditional Syntax,  Next: Testing Flags,  Prev: Conditional Example,  Up: Conditionals
    43954900
    4396 Syntax of Conditionals
    4397 ======================
     49017.2 Syntax of Conditionals
     4902==========================
    43984903
    43994904The syntax of a simple conditional with no `else' is as follows:
     
    44154920     endif
    44164921
    4417 If the condition is true, TEXT-IF-TRUE is used; otherwise,
    4418 TEXT-IF-FALSE is used instead.  The TEXT-IF-FALSE can be any number of
    4419 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.
    44204937
    44214938   The syntax of the CONDITIONAL-DIRECTIVE is the same whether the
    4422 conditional is simple or complex.  There are four different directives
    4423 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:
    44244942
    44254943`ifeq (ARG1, ARG2)'
     
    44574975
    44584976`ifdef VARIABLE-NAME'
    4459      If the variable VARIABLE-NAME has a non-empty value, the
    4460      TEXT-IF-TRUE is effective; otherwise, the TEXT-IF-FALSE, if any,
    4461      is effective.  Variables that have never been defined have an
    4462      empty value.  The variable VARIABLE-NAME is itself expanded, so it
    4463      could be a variable or function that expands to the name of a
    4464      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.
    44654995
    44664996     Note that `ifdef' only tests whether a variable has a value.  It
     
    44925022     If the variable VARIABLE-NAME has an empty value, the TEXT-IF-TRUE
    44935023     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.
    44945026
    44955027   Extra spaces are allowed and ignored at the beginning of the
     
    45265058File: make.info,  Node: Testing Flags,  Prev: Conditional Syntax,  Up: Conditionals
    45275059
    4528 Conditionals that Test Flags
    4529 ============================
     50607.3 Conditionals that Test Flags
     5061================================
    45305062
    45315063You can write a conditional that tests `make' command flags such as
     
    45575089File: make.info,  Node: Functions,  Next: Running,  Prev: Conditionals,  Up: Top
    45585090
    4559 Functions for Transforming Text
    4560 *******************************
     50918 Functions for Transforming Text
     5092*********************************
    45615093
    45625094"Functions" allow you to do text processing in the makefile to compute
     
    45725104* Text Functions::              General-purpose text manipulation functions.
    45735105* File Name Functions::         Functions for manipulating file names.
     5106* Conditional Functions::       Functions that implement conditions.
    45745107* Foreach Function::            Repeat some text with controlled variation.
    4575 * If Function::                 Conditionally expand a value.
    45765108* Call Function::               Expand a user-defined function.
    45775109* Value Function::              Return the un-expanded value of a variable.
    45785110* Eval Function::               Evaluate the arguments as makefile syntax.
    45795111* Origin Function::             Find where a variable got its value.
     5112* Flavor Function::             Find out the flavor of a variable.
    45805113* Shell Function::              Substitute the output of a shell command.
    45815114* Make Control Functions::      Functions that control how make runs.
     
    45845117File: make.info,  Node: Syntax of Functions,  Next: Text Functions,  Prev: Functions,  Up: Functions
    45855118
    4586 Function Call Syntax
    4587 ====================
     51198.1 Function Call Syntax
     5120========================
    45885121
    45895122A function call resembles a variable reference.  It looks like this:
     
    46385171File: make.info,  Node: Text Functions,  Next: File Name Functions,  Prev: Syntax of Functions,  Up: Functions
    46395172
    4640 Functions for String Substitution and Analysis
    4641 ==============================================
     51738.2 Functions for String Substitution and Analysis
     5174==================================================
    46425175
    46435176Here are some functions that operate on strings:
     
    48045337`$(wordlist S,E,TEXT)'
    48055338     Returns the list of words in TEXT starting with word S and ending
    4806      with word E (inclusive).  The legitimate values of S and E start
    4807      from 1.  If S is bigger than the number of words in TEXT, the
    4808      value is empty.  If E is bigger than the number of words in TEXT,
    4809      words up to the end of TEXT are returned.  If S is greater than E,
    4810      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,
    48115344
    48125345          $(wordlist 2, 3, foo bar baz)
     
    48305363     same as `$(word 1,TEXT)', the `firstword' function is retained for
    48315364     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.
    48325377
    48335378   Here is a realistic example of the use of `subst' and `patsubst'.
     
    48585403
    48595404
    4860 File: make.info,  Node: File Name Functions,  Next: Foreach Function,  Prev: Text Functions,  Up: Functions
    4861 
    4862 Functions for File Names
    4863 ========================
     5405File: make.info,  Node: File Name Functions,  Next: Conditional Functions,  Prev: Text Functions,  Up: Functions
     5406
     54078.3 Functions for File Names
     5408============================
    48645409
    48655410Several of the built-in expansion functions relate specifically to
     
    49705515     File Names: Wildcards.
    49715516
    4972 
    4973 File: make.info,  Node: Foreach Function,  Next: If Function,  Prev: File Name Functions,  Up: Functions
    4974 
    4975 The `foreach' Function
    4976 ======================
     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==========================
    49775590
    49785591The `foreach' function is very different from other functions.  It
     
    50465659
    50475660
    5048 File: make.info,  Node: If Function,  Next: Call Function,  Prev: Foreach Function,  Up: Functions
    5049 
    5050 The `if' Function
    5051 =================
    5052 
    5053 The `if' function provides support for conditional expansion in a
    5054 functional context (as opposed to the GNU `make' makefile conditionals
    5055 such as `ifeq' (*note Syntax of Conditionals: Conditional Syntax.).
    5056 
    5057    An `if' function call can contain either two or three arguments:
    5058 
    5059      $(if CONDITION,THEN-PART[,ELSE-PART])
    5060 
    5061    The first argument, CONDITION, first has all preceding and trailing
    5062 whitespace stripped, then is expanded.  If it expands to any non-empty
    5063 string, then the condition is considered to be true.  If it expands to
    5064 an empty string, the condition is considered to be false.
    5065 
    5066    If the condition is true then the second argument, THEN-PART, is
    5067 evaluated and this is used as the result of the evaluation of the entire
    5068 `if' function.
    5069 
    5070    If the condition is false then the third argument, ELSE-PART, is
    5071 evaluated and this is the result of the `if' function.  If there is no
    5072 third argument, the `if' function evaluates to nothing (the empty
    5073 string).
    5074 
    5075    Note that only one of the THEN-PART or the ELSE-PART will be
    5076 evaluated, never both.  Thus, either can contain side-effects (such as
    5077 `shell' function calls, etc.)
    5078 
    5079 
    5080 File: make.info,  Node: Call Function,  Next: Value Function,  Prev: If Function,  Up: Functions
    5081 
    5082 The `call' Function
    5083 ===================
     5661File: make.info,  Node: Call Function,  Next: Value Function,  Prev: Foreach Function,  Up: Functions
     5662
     56638.6 The `call' Function
     5664=======================
    50845665
    50855666The `call' function is unique in that it can be used to create new
     
    51205701
    51215702     reverse = $(2) $(1)
    5122      
     5703
    51235704     foo = $(call reverse,a,b)
    51245705
     
    51295710
    51305711     pathsearch = $(firstword $(wildcard $(addsuffix /$(1),$(subst :, ,$(PATH)))))
    5131      
     5712
    51325713     LS := $(call pathsearch,ls)
    51335714
     
    51575738File: make.info,  Node: Value Function,  Next: Eval Function,  Prev: Call Function,  Up: Functions
    51585739
    5159 The `value' Function
    5160 ====================
     57408.7 The `value' Function
     5741========================
    51615742
    51625743The `value' function provides a way for you to use the value of a
     
    51815762
    51825763     FOO = $PATH
    5183      
     5764
    51845765     all:
    51855766             @echo $(FOO)
     
    51975778File: make.info,  Node: Eval Function,  Next: Origin Function,  Prev: Value Function,  Up: Functions
    51985779
    5199 The `eval' Function
    5200 ===================
     57808.8 The `eval' Function
     5781=======================
    52015782
    52025783The `eval' function is very special: it allows you to define new
     
    52295810
    52305811     PROGRAMS    = server client
    5231      
     5812
    52325813     server_OBJS = server.o server_priv.o server_access.o
    52335814     server_LIBS = priv protocol
    5234      
     5815
    52355816     client_OBJS = client.o client_api.o client_mem.o
    52365817     client_LIBS = protocol
    5237      
     5818
    52385819     # Everything after this is generic
    5239      
     5820
    52405821     .PHONY: all
    52415822     all: $(PROGRAMS)
    5242      
     5823
    52435824     define PROGRAM_template
    52445825      $(1): $$($(1)_OBJS) $$($(1)_LIBS:%=-l%)
    52455826      ALL_OBJS   += $$($(1)_OBJS)
    52465827     endef
    5247      
     5828
    52485829     $(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))
    5249      
     5830
    52505831     $(PROGRAMS):
    52515832             $(LINK.o) $^ $(LDLIBS) -o $@
    5252      
     5833
    52535834     clean:
    52545835             rm -f $(ALL_OBJS) $(PROGRAMS)
    52555836
    52565837
    5257 File: make.info,  Node: Origin Function,  Next: Shell Function,  Prev: Eval Function,  Up: Functions
    5258 
    5259 The `origin' Function
    5260 =====================
     5838File: make.info,  Node: Origin Function,  Next: Flavor Function,  Prev: Eval Function,  Up: Functions
     5839
     58408.9 The `origin' Function
     5841=========================
    52615842
    52625843The `origin' function is unlike most other functions in that it does
     
    53415922
    53425923
    5343 File: make.info,  Node: Shell Function,  Next: Make Control Functions,  Prev: Origin Function,  Up: Functions
    5344 
    5345 The `shell' Function
    5346 ====================
     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=========================
    53475961
    53485962The `shell' function is unlike any other function other than the
     
    53755989
    53765990sets `files' to the expansion of `*.c'.  Unless `make' is using a very
    5377 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).
    53785993
    53795994
    53805995File: make.info,  Node: Make Control Functions,  Prev: Shell Function,  Up: Functions
    53815996
    5382 Functions That Control Make
    5383 ===========================
     59978.12 Functions That Control Make
     5998================================
    53845999
    53856000These functions control the way make runs.  Generally, they are used to
     
    54046019
    54056020          ERR = $(error found an error!)
    5406          
     6021
    54076022          .PHONY: err
    54086023          err: ; $(ERR)
     
    54196034     The result of the expansion of this function is the empty string.
    54206035
     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
    54216042
    54226043File: make.info,  Node: Running,  Next: Implicit Rules,  Prev: Functions,  Up: Top
    54236044
    5424 How to Run `make'
    5425 *****************
     60459 How to Run `make'
     6046*******************
    54266047
    54276048A makefile that says how to recompile a program can be used in more
     
    54696090File: make.info,  Node: Makefile Arguments,  Next: Goals,  Prev: Running,  Up: Running
    54706091
    5471 Arguments to Specify the Makefile
    5472 =================================
     60929.1 Arguments to Specify the Makefile
     6093=====================================
    54736094
    54746095The way to specify the name of the makefile is with the `-f' or
     
    54876108File: make.info,  Node: Goals,  Next: Instead of Execution,  Prev: Makefile Arguments,  Up: Running
    54886109
    5489 Arguments to Specify the Goals
    5490 ==============================
     61109.2 Arguments to Specify the Goals
     6111==================================
    54916112
    54926113The "goals" are the targets that `make' should strive ultimately to
     
    54996120program or programs they describe.  If the first rule in the makefile
    55006121has several targets, only the first target in the rule becomes the
    5501 default goal, not the whole list.
    5502 
    5503    You can specify a different goal or goals with arguments to `make'.
    5504 Use the name of the goal as an argument.  If you specify several goals,
    5505 `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.
    55066130
    55076131   Any target in the makefile may be specified as a goal (unless it
     
    55216145
    55226146     sources = foo.c bar.c
    5523      
     6147
    55246148     ifneq ($(MAKECMDGOALS),clean)
    55256149     include $(sources:.c=.d)
     
    56016225File: make.info,  Node: Instead of Execution,  Next: Avoiding Compilation,  Prev: Goals,  Up: Running
    56026226
    5603 Instead of Executing the Commands
    5604 =================================
     62279.3 Instead of Executing the Commands
     6228=====================================
    56056229
    56066230The makefile tells `make' how to tell whether a target is up to date,
     
    56806304File: make.info,  Node: Avoiding Compilation,  Next: Overriding,  Prev: Instead of Execution,  Up: Running
    56816305
    5682 Avoiding Recompilation of Some Files
    5683 ====================================
     63069.4 Avoiding Recompilation of Some Files
     6307========================================
    56846308
    56856309Sometimes you may have changed a source file but you do not want to
     
    57236347File: make.info,  Node: Overriding,  Next: Testing,  Prev: Avoiding Compilation,  Up: Running
    57246348
    5725 Overriding Variables
    5726 ====================
     63499.5 Overriding Variables
     6350========================
    57276351
    57286352An argument that contains `=' specifies the value of a variable: `V=X'
     
    57756399File: make.info,  Node: Testing,  Next: Options Summary,  Prev: Overriding,  Up: Running
    57766400
    5777 Testing the Compilation of a Program
    5778 ====================================
     64019.6 Testing the Compilation of a Program
     6402========================================
    57796403
    57806404Normally, when an error happens in executing a shell command, `make'
     
    58116435File: make.info,  Node: Options Summary,  Prev: Testing,  Up: Running
    58126436
    5813 Summary of Options
    5814 ==================
     64379.7 Summary of Options
     6438======================
    58156439
    58166440Here is a table of all the options `make' understands:
     
    58256449     Consider all targets out-of-date.  GNU `make' proceeds to consider
    58266450     targets and their prerequisites using the normal algorithms;
    5827      however, all these targets are remade, regardless of the status of
    5828      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.).
    58296457
    58306458`-C DIR'
     
    59316559     floating-point number).  With no argument, removes a previous load
    59326560     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.
    59336570
    59346571`-n'
     
    60536690File: make.info,  Node: Implicit Rules,  Next: Archives,  Prev: Running,  Up: Top
    60546691
    6055 Using Implicit Rules
    6056 ********************
     669210 Using Implicit Rules
     6693***********************
    60576694
    60586695Certain standard ways of remaking target files are used very often.  For
     
    60916728* Chained Rules::               How to use a chain of implicit rules.
    60926729* Pattern Rules::               How to define new implicit rules.
    6093 * Last Resort::                 How to defining commands for rules
    6094                                   which cannot find any.
     6730* Last Resort::                 How to define commands for rules which
     6731                                  cannot find any.
    60956732* Suffix Rules::                The old-fashioned style of implicit rule.
    60966733* Implicit Rule Search::        The precise algorithm for applying
     
    61006737File: make.info,  Node: Using Implicit,  Next: Catalogue of Rules,  Prev: Implicit Rules,  Up: Implicit Rules
    61016738
    6102 Using Implicit Rules
    6103 ====================
     673910.1 Using Implicit Rules
     6740=========================
    61046741
    61056742To allow `make' to find a customary method for updating a target file,
     
    61746811File: make.info,  Node: Catalogue of Rules,  Next: Implicit Variables,  Prev: Using Implicit,  Up: Implicit Rules
    61756812
    6176 Catalogue of Implicit Rules
    6177 ===========================
     681310.2 Catalogue of Implicit Rules
     6814================================
    61786815
    61796816Here is a catalogue of predefined implicit rules which are always
     
    61836820`--no-builtin-rules' option cancels all predefined rules.
    61846821
     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
    61856828   Not all of these rules will always be defined, even when the `-r'
    61866829option is not given.  Many of the predefined implicit rules are
     
    61886831depends on the "suffix list" (the list of prerequisites of the special
    61896832target `.SUFFIXES').  The default suffix list is: `.out', `.a', `.ln',
    6190 `.o', `.c', `.cc', `.C', `.p', `.f', `.F', `.r', `.y', `.l', `.s',
    6191 `.S', `.mod', `.sym', `.def', `.h', `.info', `.dvi', `.tex', `.texinfo',
    6192 `.texi', `.txinfo', `.w', `.ch' `.web', `.sh', `.elc', `.el'.  All of
    6193 the implicit rules described below whose prerequisites have one of
    6194 these suffixes are actually suffix rules.  If you modify the suffix
    6195 list, the only predefined suffix rules in effect will be those named by
    6196 one or two of the suffixes that are on the list you specify; rules
    6197 whose suffixes fail to be on the list are disabled.  *Note
    6198 Old-Fashioned Suffix Rules: Suffix Rules, for full details on suffix
    6199 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.
    62006843
    62016844Compiling C programs
     
    62046847
    62056848Compiling C++ programs
    6206      `N.o' is made automatically from `N.cc' or `N.C' with a command of
    6207      the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'.  We encourage you to
    6208      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'.
    62096853
    62106854Compiling Pascal programs
     
    63807024File: make.info,  Node: Implicit Variables,  Next: Chained Rules,  Prev: Catalogue of Rules,  Up: Implicit Rules
    63817025
    6382 Variables Used by Implicit Rules
    6383 ================================
     702610.3 Variables Used by Implicit Rules
     7027=====================================
    63847028
    63857029The commands in built-in implicit rules make liberal use of certain
    6386 predefined variables.  You can alter these variables in the makefile,
    6387 with arguments to `make', or in the environment to alter how the
    6388 implicit rules work without redefining the rules themselves.  You can
    6389 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
    63907034`--no-builtin-variables' option.
    63917035
     
    64077051argument, separate them with spaces.
    64087052
    6409    Here is a table of variables used as names of programs in built-in
    6410 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.
    64117062
    64127063`AR'
    6413      Archive-maintaining program; default `ar'.
     7064     Archive-maintaining program; default `ar'. 
    64147065
    64157066`AS'
    6416      Program for doing assembly; default `as'.
     7067     Program for compiling assembly files; default `as'. 
    64177068
    64187069`CC'
    6419      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'. 
    64207074
    64217075`CXX'
    6422      Program for compiling C++ programs; default `g++'.
     7076     Program for compiling C++ programs; default `g++'. 
    64237077
    64247078`CO'
    6425      Program for extracting a file from RCS; default `co'.
     7079     Program for extracting a file from RCS; default `co'. 
    64267080
    64277081`CPP'
     
    64317085`FC'
    64327086     Program for compiling or preprocessing Fortran and Ratfor programs;
    6433      default `f77'.
     7087     default `f77'. 
    64347088
    64357089`GET'
    6436      Program for extracting a file from SCCS; default `get'.
     7090     Program for extracting a file from SCCS; default `get'. 
    64377091
    64387092`LEX'
    6439      Program to use to turn Lex grammars into C programs or Ratfor
    6440      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'. 
    64417105
    64427106`PC'
    6443      Program for compiling Pascal programs; default `pc'.
    6444 
    6445 `YACC'
    6446      Program to use to turn Yacc grammars into C programs; default
    6447      `yacc'.
    6448 
    6449 `YACCR'
    6450      Program to use to turn Yacc grammars into Ratfor programs; default
    6451      `yacc -r'.
     7107     Program for compiling Pascal programs; default `pc'. 
    64527108
    64537109`MAKEINFO'
    64547110     Program to convert a Texinfo source file into an Info file; default
    6455      `makeinfo'.
     7111     `makeinfo'. 
    64567112
    64577113`TEX'
    6458      Program to make TeX DVI files from TeX source; default `tex'.
     7114     Program to make TeX DVI files from TeX source; default `tex'. 
    64597115
    64607116`TEXI2DVI'
    64617117     Program to make TeX DVI files from Texinfo source; default
    6462      `texi2dvi'.
     7118     `texi2dvi'. 
    64637119
    64647120`WEAVE'
    6465      Program to translate Web into TeX; default `weave'.
     7121     Program to translate Web into TeX; default `weave'. 
    64667122
    64677123`CWEAVE'
    6468      Program to translate C Web into TeX; default `cweave'.
     7124     Program to translate C Web into TeX; default `cweave'. 
    64697125
    64707126`TANGLE'
    6471      Program to translate Web into Pascal; default `tangle'.
     7127     Program to translate Web into Pascal; default `tangle'. 
    64727128
    64737129`CTANGLE'
    6474      Program to translate C Web into C; default `ctangle'.
     7130     Program to translate C Web into C; default `ctangle'. 
    64757131
    64767132`RM'
    6477      Command to remove a file; default `rm -f'.
     7133     Command to remove a file; default `rm -f'. 
    64787134
    64797135   Here is a table of variables whose values are additional arguments
     
    65147170     Extra flags to give to Lex.
    65157171
     7172`YFLAGS'
     7173     Extra flags to give to Yacc.
     7174
    65167175`PFLAGS'
    65177176     Extra flags to give to the Pascal compiler.
     
    65207179     Extra flags to give to the Fortran compiler for Ratfor programs.
    65217180
    6522 `YFLAGS'
    6523      Extra flags to give to Yacc.
     7181`LINTFLAGS'
     7182     Extra flags to give to lint.
    65247183
    65257184
    65267185File: make.info,  Node: Chained Rules,  Next: Pattern Rules,  Prev: Implicit Variables,  Up: Implicit Rules
    65277186
    6528 Chains of Implicit Rules
    6529 ========================
     718710.4 Chains of Implicit Rules
     7188=============================
    65307189
    65317190Sometimes a file can be made by a sequence of implicit rules.  For
     
    65797238as a prerequisite of the special target `.PRECIOUS' to preserve
    65807239intermediate files made by implicit rules whose target patterns match
    6581 that file's name; see *Note Interrupts::.
     7240that file's name; see *Note Interrupts::. 
    65827241
    65837242   A chain can involve more than two implicit rules.  For example, it is
     
    66017260earlier in the ordering of rules.
    66027261
    6603 
    6604 File: make.info,  Node: Pattern Rules,  Next: Last Resort,  Prev: Chained Rules,  Up: Implicit Rules
    6605 
    6606 Defining and Redefining Pattern Rules
    6607 =====================================
    6608 
    6609 You define an implicit rule by writing a "pattern rule".  A pattern
    6610 rule looks like an ordinary rule, except that its target contains the
    6611 character `%' (exactly one of them).  The target is considered a
    6612 pattern for matching file names; the `%' can match any nonempty
    6613 substring, while other characters match only themselves.  The
    6614 prerequisites likewise use `%' to show how their names relate to the
    6615 target name.
    6616 
    6617    Thus, a pattern rule `%.o : %.c' says how to make any file `STEM.o'
    6618 from another file `STEM.c'.
    6619 
    6620    Note that expansion using `%' in pattern rules occurs *after* any
    6621 variable or function expansions, which take place when the makefile is
    6622 read.  *Note How to Use Variables: Using Variables, and *Note Functions
    6623 for Transforming Text: Functions.
    6624 
    6625 * Menu:
    6626 
    6627 * Pattern Intro::               An introduction to pattern rules.
    6628 * Pattern Examples::            Examples of pattern rules.
    6629 * Automatic Variables::         How to use automatic variables in the
    6630                                   commands of implicit rules.
    6631 * Pattern Match::               How patterns match.
    6632 * Match-Anything Rules::        Precautions you should take prior to
    6633                                   defining rules that can match any
    6634                                   target file whatever.
    6635 * Canceling Rules::             How to override or cancel built-in rules.
    6636 
    6637 
    6638 File: make.info,  Node: Pattern Intro,  Next: Pattern Examples,  Prev: Pattern Rules,  Up: Pattern Rules
    6639 
    6640 Introduction to Pattern Rules
    6641 -----------------------------
    6642 
    6643 A pattern rule contains the character `%' (exactly one of them) in the
    6644 target; otherwise, it looks exactly like an ordinary rule.  The target
    6645 is a pattern for matching file names; the `%' matches any nonempty
    6646 substring, while other characters match only themselves.
    6647 
    6648    For example, `%.c' as a pattern matches any file name that ends in
    6649 `.c'.  `s.%.c' as a pattern matches any file name that starts with
    6650 `s.', ends in `.c' and is at least five characters long.  (There must
    6651 be at least one character to match the `%'.)  The substring that the
    6652 `%' matches is called the "stem".
    6653 
    6654    `%' in a prerequisite of a pattern rule stands for the same stem
    6655 that was matched by the `%' in the target.  In order for the pattern
    6656 rule to apply, its target pattern must match the file name under
    6657 consideration, and its prerequisite patterns must name files that exist
    6658 or can be made.  These files become prerequisites of the target.
    6659 
    6660    Thus, a rule of the form
    6661 
    6662      %.o : %.c ; COMMAND...
    6663 
    6664 specifies how to make a file `N.o', with another file `N.c' as its
    6665 prerequisite, provided that `N.c' exists or can be made.
    6666 
    6667    There may also be prerequisites that do not use `%'; such a
    6668 prerequisite attaches to every file made by this pattern rule.  These
    6669 unvarying prerequisites are useful occasionally.
    6670 
    6671    A pattern rule need not have any prerequisites that contain `%', or
    6672 in fact any prerequisites at all.  Such a rule is effectively a general
    6673 wildcard.  It provides a way to make any file that matches the target
    6674 pattern.  *Note Last Resort::.
    6675 
    6676    Pattern rules may have more than one target.  Unlike normal rules,
    6677 this does not act as many different rules with the same prerequisites
    6678 and commands.  If a pattern rule has multiple targets, `make' knows that
    6679 the rule's commands are responsible for making all of the targets.  The
    6680 commands are executed only once to make all the targets.  When searching
    6681 for a pattern rule to match a target, the target patterns of a rule
    6682 other than the one that matches the target in need of a rule are
    6683 incidental: `make' worries only about giving commands and prerequisites
    6684 to the file presently in question.  However, when this file's commands
    6685 are run, the other targets are marked as having been updated themselves.
    6686 
    6687    The order in which pattern rules appear in the makefile is important
    6688 since this is the order in which they are considered.  Of equally
    6689 applicable rules, only the first one found is used.  The rules you
    6690 write take precedence over those that are built in.  Note however, that
    6691 a rule whose prerequisites actually exist or are mentioned always takes
    6692 priority over a rule with prerequisites that must be made by chaining
    6693 other implicit rules.
    6694 
    6695 
    6696 File: make.info,  Node: Pattern Examples,  Next: Automatic Variables,  Prev: Pattern Intro,  Up: Pattern Rules
    6697 
    6698 Pattern Rule Examples
    6699 ---------------------
    6700 
    6701 Here are some examples of pattern rules actually predefined in `make'.
    6702 First, the rule that compiles `.c' files into `.o' files:
    6703 
    6704      %.o : %.c
    6705              $(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
    6706 
    6707 defines a rule that can make any file `X.o' from `X.c'.  The command
    6708 uses the automatic variables `$@' and `$<' to substitute the names of
    6709 the target file and the source file in each case where the rule applies
    6710 (*note Automatic Variables::).
    6711 
    6712    Here is a second built-in rule:
    6713 
    6714      % :: RCS/%,v
    6715              $(CO) $(COFLAGS) $<
    6716 
    6717 defines a rule that can make any file `X' whatsoever from a
    6718 corresponding file `X,v' in the subdirectory `RCS'.  Since the target
    6719 is `%', this rule will apply to any file whatever, provided the
    6720 appropriate prerequisite file exists.  The double colon makes the rule
    6721 "terminal", which means that its prerequisite may not be an intermediate
    6722 file (*note Match-Anything Pattern Rules: Match-Anything Rules.).
    6723 
    6724    This pattern rule has two targets:
    6725 
    6726      %.tab.c %.tab.h: %.y
    6727              bison -d $<
    6728 
    6729 This tells `make' that the command `bison -d X.y' will make both
    6730 `X.tab.c' and `X.tab.h'.  If the file `foo' depends on the files
    6731 `parse.tab.o' and `scan.o' and the file `scan.o' depends on the file
    6732 `parse.tab.h', when `parse.y' is changed, the command `bison -d parse.y'
    6733 will be executed only once, and the prerequisites of both `parse.tab.o'
    6734 and `scan.o' will be satisfied.  (Presumably the file `parse.tab.o'
    6735 will be recompiled from `parse.tab.c' and the file `scan.o' from
    6736 `scan.c', while `foo' is linked from `parse.tab.o', `scan.o', and its
    6737 other prerequisites, and it will execute happily ever after.)
    6738 
    6739 
    6740 File: make.info,  Node: Automatic Variables,  Next: Pattern Match,  Prev: Pattern Examples,  Up: Pattern Rules
    6741 
    6742 Automatic Variables
    6743 -------------------
    6744 
    6745 Suppose you are writing a pattern rule to compile a `.c' file into a
    6746 `.o' file: how do you write the `cc' command so that it operates on the
    6747 right source file name?  You cannot write the name in the command,
    6748 because the name is different each time the implicit rule is applied.
    6749 
    6750    What you do is use a special feature of `make', the "automatic
    6751 variables".  These variables have values computed afresh for each rule
    6752 that is executed, based on the target and prerequisites of the rule.
    6753 In this example, you would use `$@' for the object file name and `$<'
    6754 for the source file name.
    6755 
    6756    It's very important that you recognize the limited scope in which
    6757 automatic variable values are available: they only have values within
    6758 the command script.  In particular, you cannot use them anywhere within
    6759 the target or prerequisite lists of a rule; they have no value there
    6760 and will expand to the empty string.  A common mistake is attempting to
    6761 use `$@' within the prerequisites list in a rule; this will not work.
    6762 However, see below for information on the SysV-style `$$@' variables.
    6763 
    6764    Here is a table of automatic variables:
    6765 
    6766 `$@'
    6767      The file name of the target of the rule.  If the target is an
    6768      archive member, then `$@' is the name of the archive file.  In a
    6769      pattern rule that has multiple targets (*note Introduction to
    6770      Pattern Rules: Pattern Intro.), `$@' is the name of whichever
    6771      target caused the rule's commands to be run.
    6772 
    6773 `$%'
    6774      The target member name, when the target is an archive member.
    6775      *Note Archives::.  For example, if the target is `foo.a(bar.o)'
    6776      then `$%' is `bar.o' and `$@' is `foo.a'.  `$%' is empty when the
    6777      target is not an archive member.
    6778 
    6779 `$<'
    6780      The name of the first prerequisite.  If the target got its
    6781      commands from an implicit rule, this will be the first
    6782      prerequisite added by the implicit rule (*note Implicit Rules::).
    6783 
    6784 `$?'
    6785      The names of all the prerequisites that are newer than the target,
    6786      with spaces between them.  For prerequisites which are archive
    6787      members, only the member named is used (*note Archives::).
    6788 
    6789 `$^'
    6790      The names of all the prerequisites, with spaces between them.  For
    6791      prerequisites which are archive members, only the member named is
    6792      used (*note Archives::).  A target has only one prerequisite on
    6793      each other file it depends on, no matter how many times each file
    6794      is listed as a prerequisite.  So if you list a prerequisite more
    6795      than once for a target, the value of `$^' contains just one copy
    6796      of the name.
    6797 
    6798 `$+'
    6799      This is like `$^', but prerequisites listed more than once are
    6800      duplicated in the order they were listed in the makefile.  This is
    6801      primarily useful for use in linking commands where it is
    6802      meaningful to repeat library file names in a particular order.
    6803 
    6804 `$*'
    6805      The stem with which an implicit rule matches (*note How Patterns
    6806      Match: Pattern Match.).  If the target is `dir/a.foo.b' and the
    6807      target pattern is `a.%.b' then the stem is `dir/foo'.  The stem is
    6808      useful for constructing names of related files.
    6809 
    6810      In a static pattern rule, the stem is part of the file name that
    6811      matched the `%' in the target pattern.
    6812 
    6813      In an explicit rule, there is no stem; so `$*' cannot be determined
    6814      in that way.  Instead, if the target name ends with a recognized
    6815      suffix (*note Old-Fashioned Suffix Rules: Suffix Rules.), `$*' is
    6816      set to the target name minus the suffix.  For example, if the
    6817      target name is `foo.c', then `$*' is set to `foo', since `.c' is a
    6818      suffix.  GNU `make' does this bizarre thing only for compatibility
    6819      with other implementations of `make'.  You should generally avoid
    6820      using `$*' except in implicit rules or static pattern rules.
    6821 
    6822      If the target name in an explicit rule does not end with a
    6823      recognized suffix, `$*' is set to the empty string for that rule.
    6824 
    6825    `$?' is useful even in explicit rules when you wish to operate on
    6826 only the prerequisites that have changed.  For example, suppose that an
    6827 archive named `lib' is supposed to contain copies of several object
    6828 files.  This rule copies just the changed object files into the archive:
    6829 
    6830      lib: foo.o bar.o lose.o win.o
    6831              ar r lib $?
    6832 
    6833    Of the variables listed above, four have values that are single file
    6834 names, and three have values that are lists of file names.  These seven
    6835 have variants that get just the file's directory name or just the file
    6836 name within the directory.  The variant variables' names are formed by
    6837 appending `D' or `F', respectively.  These variants are semi-obsolete
    6838 in GNU `make' since the functions `dir' and `notdir' can be used to get
    6839 a similar effect (*note Functions for File Names: File Name
    6840 Functions.).  Note, however, that the `D' variants all omit the
    6841 trailing slash which always appears in the output of the `dir'
    6842 function.  Here is a table of the variants:
    6843 
    6844 `$(@D)'
    6845      The directory part of the file name of the target, with the
    6846      trailing slash removed.  If the value of `$@' is `dir/foo.o' then
    6847      `$(@D)' is `dir'.  This value is `.' if `$@' does not contain a
    6848      slash.
    6849 
    6850 `$(@F)'
    6851      The file-within-directory part of the file name of the target.  If
    6852      the value of `$@' is `dir/foo.o' then `$(@F)' is `foo.o'.  `$(@F)'
    6853      is equivalent to `$(notdir $@)'.
    6854 
    6855 `$(*D)'
    6856 `$(*F)'
    6857      The directory part and the file-within-directory part of the stem;
    6858      `dir' and `foo' in this example.
    6859 
    6860 `$(%D)'
    6861 `$(%F)'
    6862      The directory part and the file-within-directory part of the target
    6863      archive member name.  This makes sense only for archive member
    6864      targets of the form `ARCHIVE(MEMBER)' and is useful only when
    6865      MEMBER may contain a directory name.  (*Note Archive Members as
    6866      Targets: Archive Members.)
    6867 
    6868 `$(<D)'
    6869 `$(<F)'
    6870      The directory part and the file-within-directory part of the first
    6871      prerequisite.
    6872 
    6873 `$(^D)'
    6874 `$(^F)'
    6875      Lists of the directory parts and the file-within-directory parts
    6876      of all prerequisites.
    6877 
    6878 `$(+D)'
    6879 `$(+F)'
    6880      Lists of the directory parts and the file-within-directory parts
    6881      of all prerequisites, including multiple instances of duplicated
    6882      prerequisites.
    6883 
    6884 `$(?D)'
    6885 `$(?F)'
    6886      Lists of the directory parts and the file-within-directory parts of
    6887      all prerequisites that are newer than the target.
    6888 
    6889    Note that we use a special stylistic convention when we talk about
    6890 these automatic variables; we write "the value of `$<'", rather than
    6891 "the variable `<'" as we would write for ordinary variables such as
    6892 `objects' and `CFLAGS'.  We think this convention looks more natural in
    6893 this special case.  Please do not assume it has a deep significance;
    6894 `$<' refers to the variable named `<' just as `$(CFLAGS)' refers to the
    6895 variable named `CFLAGS'.  You could just as well use `$(<)' in place of
    6896 `$<'.
    6897 
    6898    GNU `make' provides support for the SysV `make' feature that allows
    6899 special variable references `$$@', `$$(@D)', and `$$(@F)' (note the
    6900 required double-"$"!) to appear with the _prerequisites list_ (normal
    6901 automatic variables are available only within a command script).  When
    6902 appearing in a prerequisites list, these variables are expanded to the
    6903 name of the target, the directory component of the target, and the file
    6904 component of the target, respectively.
    6905 
    6906    Note that these variables are available only within explicit and
    6907 static pattern (*note Static Pattern Rules: Static Pattern.) rules;
    6908 they have no special significance within implicit (suffix or pattern)
    6909 rules.  Also note that while SysV `make' actually expands its entire
    6910 prerequisite list _twice_, GNU `make' does not behave this way: instead
    6911 it simply expands these special variables without re-expanding any
    6912 other part of the prerequisites list.
    6913 
    6914    This somewhat bizarre feature is included only to provide some
    6915 compatibility with SysV makefiles.  In a native GNU `make' file there
    6916 are other ways to accomplish the same results.  This feature is
    6917 disabled if the special pseudo target `.POSIX' is defined.
    6918 
    6919 
    6920 File: make.info,  Node: Pattern Match,  Next: Match-Anything Rules,  Prev: Automatic Variables,  Up: Pattern Rules
    6921 
    6922 How Patterns Match
    6923 ------------------
    6924 
    6925 A target pattern is composed of a `%' between a prefix and a suffix,
    6926 either or both of which may be empty.  The pattern matches a file name
    6927 only if the file name starts with the prefix and ends with the suffix,
    6928 without overlap.  The text between the prefix and the suffix is called
    6929 the "stem".  Thus, when the pattern `%.o' matches the file name
    6930 `test.o', the stem is `test'.  The pattern rule prerequisites are
    6931 turned into actual file names by substituting the stem for the character
    6932 `%'.  Thus, if in the same example one of the prerequisites is written
    6933 as `%.c', it expands to `test.c'.
    6934 
    6935    When the target pattern does not contain a slash (and it usually does
    6936 not), directory names in the file names are removed from the file name
    6937 before it is compared with the target prefix and suffix.  After the
    6938 comparison of the file name to the target pattern, the directory names,
    6939 along with the slash that ends them, are added on to the prerequisite
    6940 file names generated from the pattern rule's prerequisite patterns and
    6941 the file name. The directories are ignored only for the purpose of
    6942 finding an implicit rule to use, not in the application of that rule.
    6943 Thus, `e%t' matches the file name `src/eat', with `src/a' as the stem.
    6944 When prerequisites are turned into file names, the directories from the
    6945 stem are added at the front, while the rest of the stem is substituted
    6946 for the `%'.  The stem `src/a' with a prerequisite pattern `c%r' gives
    6947 the file name `src/car'.
    6948 
    6949 
    6950 File: make.info,  Node: Match-Anything Rules,  Next: Canceling Rules,  Prev: Pattern Match,  Up: Pattern Rules
    6951 
    6952 Match-Anything Pattern Rules
    6953 ----------------------------
    6954 
    6955 When a pattern rule's target is just `%', it matches any file name
    6956 whatever.  We call these rules "match-anything" rules.  They are very
    6957 useful, but it can take a lot of time for `make' to think about them,
    6958 because it must consider every such rule for each file name listed
    6959 either as a target or as a prerequisite.
    6960 
    6961    Suppose the makefile mentions `foo.c'.  For this target, `make'
    6962 would have to consider making it by linking an object file `foo.c.o',
    6963 or by C compilation-and-linking in one step from `foo.c.c', or by
    6964 Pascal compilation-and-linking from `foo.c.p', and many other
    6965 possibilities.
    6966 
    6967    We know these possibilities are ridiculous since `foo.c' is a C
    6968 source file, not an executable.  If `make' did consider these
    6969 possibilities, it would ultimately reject them, because files such as
    6970 `foo.c.o' and `foo.c.p' would not exist.  But these possibilities are so
    6971 numerous that `make' would run very slowly if it had to consider them.
    6972 
    6973    To gain speed, we have put various constraints on the way `make'
    6974 considers match-anything rules.  There are two different constraints
    6975 that can be applied, and each time you define a match-anything rule you
    6976 must choose one or the other for that rule.
    6977 
    6978    One choice is to mark the match-anything rule as "terminal" by
    6979 defining it with a double colon.  When a rule is terminal, it does not
    6980 apply unless its prerequisites actually exist.  Prerequisites that
    6981 could be made with other implicit rules are not good enough.  In other
    6982 words, no further chaining is allowed beyond a terminal rule.
    6983 
    6984    For example, the built-in implicit rules for extracting sources from
    6985 RCS and SCCS files are terminal; as a result, if the file `foo.c,v' does
    6986 not exist, `make' will not even consider trying to make it as an
    6987 intermediate file from `foo.c,v.o' or from `RCS/SCCS/s.foo.c,v'.  RCS
    6988 and SCCS files are generally ultimate source files, which should not be
    6989 remade from any other files; therefore, `make' can save time by not
    6990 looking for ways to remake them.
    6991 
    6992    If you do not mark the match-anything rule as terminal, then it is
    6993 nonterminal.  A nonterminal match-anything rule cannot apply to a file
    6994 name that indicates a specific type of data.  A file name indicates a
    6995 specific type of data if some non-match-anything implicit rule target
    6996 matches it.
    6997 
    6998    For example, the file name `foo.c' matches the target for the pattern
    6999 rule `%.c : %.y' (the rule to run Yacc).  Regardless of whether this
    7000 rule is actually applicable (which happens only if there is a file
    7001 `foo.y'), the fact that its target matches is enough to prevent
    7002 consideration of any nonterminal match-anything rules for the file
    7003 `foo.c'.  Thus, `make' will not even consider trying to make `foo.c' as
    7004 an executable file from `foo.c.o', `foo.c.c', `foo.c.p', etc.
    7005 
    7006    The motivation for this constraint is that nonterminal match-anything
    7007 rules are used for making files containing specific types of data (such
    7008 as executable files) and a file name with a recognized suffix indicates
    7009 some other specific type of data (such as a C source file).
    7010 
    7011    Special built-in dummy pattern rules are provided solely to recognize
    7012 certain file names so that nonterminal match-anything rules will not be
    7013 considered.  These dummy rules have no prerequisites and no commands,
    7014 and they are ignored for all other purposes.  For example, the built-in
    7015 implicit rule
    7016 
    7017      %.p :
    7018 
    7019 exists to make sure that Pascal source files such as `foo.p' match a
    7020 specific target pattern and thereby prevent time from being wasted
    7021 looking for `foo.p.o' or `foo.p.c'.
    7022 
    7023    Dummy pattern rules such as the one for `%.p' are made for every
    7024 suffix listed as valid for use in suffix rules (*note Old-Fashioned
    7025 Suffix Rules: Suffix Rules.).
    7026 
    7027 
    7028 File: make.info,  Node: Canceling Rules,  Prev: Match-Anything Rules,  Up: Pattern Rules
    7029 
    7030 Canceling Implicit Rules
    7031 ------------------------
    7032 
    7033 You can override a built-in implicit rule (or one you have defined
    7034 yourself) by defining a new pattern rule with the same target and
    7035 prerequisites, but different commands.  When the new rule is defined,
    7036 the built-in one is replaced.  The new rule's position in the sequence
    7037 of implicit rules is determined by where you write the new rule.
    7038 
    7039    You can cancel a built-in implicit rule by defining a pattern rule
    7040 with the same target and prerequisites, but no commands.  For example,
    7041 the following would cancel the rule that runs the assembler:
    7042 
    7043      %.o : %.s
    7044 
    7045 
    7046 File: make.info,  Node: Last Resort,  Next: Suffix Rules,  Prev: Pattern Rules,  Up: Implicit Rules
    7047 
    7048 Defining Last-Resort Default Rules
    7049 ==================================
    7050 
    7051 You can define a last-resort implicit rule by writing a terminal
    7052 match-anything pattern rule with no prerequisites (*note Match-Anything
    7053 Rules::).  This is just like any other pattern rule; the only thing
    7054 special about it is that it will match any target.  So such a rule's
    7055 commands are used for all targets and prerequisites that have no
    7056 commands of their own and for which no other implicit rule applies.
    7057 
    7058    For example, when testing a makefile, you might not care if the
    7059 source files contain real data, only that they exist.  Then you might
    7060 do this:
    7061 
    7062      %::
    7063              touch $@
    7064 
    7065 to cause all the source files needed (as prerequisites) to be created
    7066 automatically.
    7067 
    7068    You can instead define commands to be used for targets for which
    7069 there are no rules at all, even ones which don't specify commands.  You
    7070 do this by writing a rule for the target `.DEFAULT'.  Such a rule's
    7071 commands are used for all prerequisites which do not appear as targets
    7072 in any explicit rule, and for which no implicit rule applies.
    7073 Naturally, there is no `.DEFAULT' rule unless you write one.
    7074 
    7075    If you use `.DEFAULT' with no commands or prerequisites:
    7076 
    7077      .DEFAULT:
    7078 
    7079 the commands previously stored for `.DEFAULT' are cleared.  Then `make'
    7080 acts as if you had never defined `.DEFAULT' at all.
    7081 
    7082    If you do not want a target to get the commands from a match-anything
    7083 pattern rule or `.DEFAULT', but you also do not want any commands to be
    7084 run for the target, you can give it empty commands (*note Defining
    7085 Empty Commands: Empty Commands.).
    7086 
    7087    You can use a last-resort rule to override part of another makefile.
    7088 *Note Overriding Part of Another Makefile: Overriding Makefiles.
    7089 
    7090 
    7091 File: make.info,  Node: Suffix Rules,  Next: Implicit Rule Search,  Prev: Last Resort,  Up: Implicit Rules
    7092 
    7093 Old-Fashioned Suffix Rules
    7094 ==========================
    7095 
    7096 "Suffix rules" are the old-fashioned way of defining implicit rules for
    7097 `make'.  Suffix rules are obsolete because pattern rules are more
    7098 general and clearer.  They are supported in GNU `make' for
    7099 compatibility with old makefiles.  They come in two kinds:
    7100 "double-suffix" and "single-suffix".
    7101 
    7102    A double-suffix rule is defined by a pair of suffixes: the target
    7103 suffix and the source suffix.  It matches any file whose name ends with
    7104 the target suffix.  The corresponding implicit prerequisite is made by
    7105 replacing the target suffix with the source suffix in the file name.  A
    7106 two-suffix rule whose target and source suffixes are `.o' and `.c' is
    7107 equivalent to the pattern rule `%.o : %.c'.
    7108 
    7109    A single-suffix rule is defined by a single suffix, which is the
    7110 source suffix.  It matches any file name, and the corresponding implicit
    7111 prerequisite name is made by appending the source suffix.  A
    7112 single-suffix rule whose source suffix is `.c' is equivalent to the
    7113 pattern rule `% : %.c'.
    7114 
    7115    Suffix rule definitions are recognized by comparing each rule's
    7116 target against a defined list of known suffixes.  When `make' sees a
    7117 rule whose target is a known suffix, this rule is considered a
    7118 single-suffix rule.  When `make' sees a rule whose target is two known
    7119 suffixes concatenated, this rule is taken as a double-suffix rule.
    7120 
    7121    For example, `.c' and `.o' are both on the default list of known
    7122 suffixes.  Therefore, if you define a rule whose target is `.c.o',
    7123 `make' takes it to be a double-suffix rule with source suffix `.c' and
    7124 target suffix `.o'.  Here is the old-fashioned way to define the rule
    7125 for compiling a C source file:
    7126 
    7127      .c.o:
    7128              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
    7129 
    7130    Suffix rules cannot have any prerequisites of their own.  If they
    7131 have any, they are treated as normal files with funny names, not as
    7132 suffix rules.  Thus, the rule:
    7133 
    7134      .c.o: foo.h
    7135              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
    7136 
    7137 tells how to make the file `.c.o' from the prerequisite file `foo.h',
    7138 and is not at all like the pattern rule:
    7139 
    7140      %.o: %.c foo.h
    7141              $(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
    7142 
    7143 which tells how to make `.o' files from `.c' files, and makes all `.o'
    7144 files using this pattern rule also depend on `foo.h'.
    7145 
    7146    Suffix rules with no commands are also meaningless.  They do not
    7147 remove previous rules as do pattern rules with no commands (*note
    7148 Canceling Implicit Rules: Canceling Rules.).  They simply enter the
    7149 suffix or pair of suffixes concatenated as a target in the data base.
    7150 
    7151    The known suffixes are simply the names of the prerequisites of the
    7152 special target `.SUFFIXES'.  You can add your own suffixes by writing a
    7153 rule for `.SUFFIXES' that adds more prerequisites, as in:
    7154 
    7155      .SUFFIXES: .hack .win
    7156 
    7157 which adds `.hack' and `.win' to the end of the list of suffixes.
    7158 
    7159    If you wish to eliminate the default known suffixes instead of just
    7160 adding to them, write a rule for `.SUFFIXES' with no prerequisites.  By
    7161 special dispensation, this eliminates all existing prerequisites of
    7162 `.SUFFIXES'.  You can then write another rule to add the suffixes you
    7163 want.  For example,
    7164 
    7165      .SUFFIXES:            # Delete the default suffixes
    7166      .SUFFIXES: .c .o .h   # Define our suffix list
    7167 
    7168    The `-r' or `--no-builtin-rules' flag causes the default list of
    7169 suffixes to be empty.
    7170 
    7171    The variable `SUFFIXES' is defined to the default list of suffixes
    7172 before `make' reads any makefiles.  You can change the list of suffixes
    7173 with a rule for the special target `.SUFFIXES', but that does not alter
    7174 this variable.
    7175 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette