Changeset 3140 for trunk/src/kmk/doc


Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/doc/Makefile.am

    r2591 r3140  
    11# -*-Makefile-*-, or close enough
    2 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    3 # 2010 Free Software Foundation, Inc.
     2# Copyright (C) 2000-2016 Free Software Foundation, Inc.
    43# This file is part of GNU Make.
    54#
     
    2423
    2524CLEANFILES = make*.html
    26 
    27 ## ----------------------------- ##
    28 ## Other documentation formats.  ##
    29 ## ----------------------------- ##
    30 
    31 html: make_1.html
    32 
    33 make_1.html: $(info_TEXINFOS) $(make_TEXINFOS)
    34         $(TEXI2HTML) $(TEXI2HTML_FLAGS) $(srcdir)/make.texi
    35 
    36 .PHONY: html
  • trunk/src/kmk/doc/make.texi

    r2591 r3140  
    44
    55@include version.texi
    6 @set EDITION 0.71
    7 @set RCSID $Id: make.texi,v 1.66 2010/07/19 07:10:54 psmith Exp $
     6@set EDITION 0.74
    87
    98@settitle GNU @code{make}
     
    2827Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
    29281996, 1997, 1998, 1999, 2000, 2002, 2003, 2004, 2005, 2006, 2007,
    30 2008, 2009, 2010 Free Software Foundation, Inc.
     292008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free Software
     30Foundation, Inc.
    3131
    3232@quotation
    3333Permission is granted to copy, distribute and/or modify this document
    34 under the terms of the GNU Free Documentation License, Version 1.2 or
     34under the terms of the GNU Free Documentation License, Version 1.3 or
    3535any later version published by the Free Software Foundation; with no
    3636Invariant Sections, with the Front-Cover Texts being ``A GNU Manual,''
     
    101101                                  based on their file names.
    102102* Archives::                    How @code{make} can update library archives.
     103* Extending make::              Using extensions to @code{make}.
     104* Integrating make::            Integrating @code{make} with other tools.
    103105* Features::                    Features GNU @code{make} has over other @code{make}s.
    104106* Missing::                     What GNU @code{make} lacks from other @code{make}s.
     
    110112                                  but nontrivial, makefile.
    111113
    112 * GNU Free Documentation License::  License for copying this manual
    113 * Concept Index::               Index of Concepts
    114 * Name Index::                  Index of Functions, Variables, & Directives
     114* GNU Free Documentation License::  License for copying this manual.
     115* Concept Index::               Index of Concepts.
     116* Name Index::                  Index of Functions, Variables, & Directives.
    115117
    116118@detailmenu
     
    119121Overview of @code{make}
    120122
    121 * Preparing::                   Preparing and running make
    122 * Reading::                     On reading this text
    123 * Bugs::                        Problems and bugs
     123* Preparing::                   Preparing and running @code{make}.
     124* Reading::                     On reading this text.
     125* Bugs::                        Problems and bugs.
    124126
    125127An Introduction to Makefiles
    126128
    127129* Rule Introduction::           What a rule looks like.
    128 * Simple Makefile::             A simple makefile
    129 * How Make Works::              How @code{make} processes this makefile
    130 * Variables Simplify::          Variables make makefiles simpler
    131 * make Deduces::                Letting @code{make} deduce the recipe
    132 * Combine By Prerequisite::     Another style of makefile
    133 * Cleanup::                     Rules for cleaning the directory
     130* Simple Makefile::             A simple makefile.
     131* How Make Works::              How @code{make} processes this makefile.
     132* Variables Simplify::          Variables make makefiles simpler.
     133* make Deduces::                Letting @code{make} deduce the recipes.
     134* Combine By Prerequisite::     Another style of makefile.
     135* Cleanup::                     Rules for cleaning the directory.
    134136
    135137Writing Makefiles
     
    144146* Reading Makefiles::           How makefiles are parsed.
    145147* Secondary Expansion::         How and when secondary expansion is performed.
     148
     149What Makefiles Contain
     150
     151* Splitting Lines::             Splitting long lines in makefiles
    146152
    147153Writing Rules
     
    171177Using Wildcard Characters in File Names
    172178
    173 * Wildcard Examples::           Several examples
     179* Wildcard Examples::           Several examples.
    174180* Wildcard Pitfall::            Problems to avoid.
    175181* Wildcard Function::           How to cause wildcard expansion where
     
    207213Recipe Syntax
    208214
    209 * Splitting Lines::             Breaking long recipe lines for readability.
     215* Splitting Recipe Lines::      Breaking long recipe lines for readability.
    210216* Variables in Recipes::        Using @code{make} variables in recipes.
    211217
    212218Recipe Execution
    213219
     220* One Shell::                   One shell for all lines in a recipe.
    214221* Choosing the Shell::          How @code{make} chooses the shell used
    215222                                  to run recipes.
     223
     224Parallel Execution
     225
     226* Parallel Output::             Handling output during parallel execution
     227* Parallel Input::              Handling input during parallel execution
    216228
    217229Recursive Use of @code{make}
     
    236248* Multi-Line::                  An alternate way to set a variable
    237249                                  to a multi-line string.
     250* Undefine Directive::          How to undefine a variable so that it appears
     251                                  as if it was never set.
    238252* Environment::                 Variable values can come from the environment.
    239253* Target-specific::             Variable values can be defined on a per-target
     
    263277* Conditional Functions::       Functions that implement conditions.
    264278* Foreach Function::            Repeat some text with controlled variation.
     279* File Function::               Write text to a file.
    265280* Call Function::               Expand a user-defined function.
    266281* Value Function::              Return the un-expanded value of a variable.
     
    268283* Origin Function::             Find where a variable got its value.
    269284* Flavor Function::             Find out the flavor of a variable.
     285* Make Control Functions::      Functions that control how make runs.
    270286* Shell Function::              Substitute the output of a shell command.
    271 * Make Control Functions::      Functions that control how make runs.
     287* Guile Function::              Use GNU Guile embedded scripting language.
    272288
    273289How to Run @code{make}
     
    290306
    291307* Using Implicit::              How to use an existing implicit rule
    292                                   to get the recipe for updating a file.
    293 * Catalogue of Rules::          A list of built-in implicit rules.
     308                                  to get the recipes for updating a file.
     309* Catalogue of Rules::          A list of built-in rules.
    294310* Implicit Variables::          How to change what predefined rules do.
    295311* Chained Rules::               How to use a chain of implicit rules.
     
    325341* Archive Symbols::             How to update archive symbol directories.
    326342
     343Extending GNU @code{make}
     344
     345* Guile Integration::           Using Guile as an embedded scripting language.
     346* Loading Objects::             Loading dynamic objects as extensions.
     347
     348GNU Guile Integration
     349
     350* Guile Types::                 Converting Guile types to @code{make} strings.
     351* Guile Interface::             Invoking @code{make} functions from Guile.
     352* Guile Example::               Example using Guile in @code{make}.
     353
     354Loading Dynamic Objects
     355
     356* load Directive::              Loading dynamic objects as extensions.
     357* Remaking Loaded Objects::     How loaded objects get remade.
     358* Loaded Object API::           Programmatic interface for loaded objects.
     359* Loaded Object Example::       Example of a loaded object
     360
     361Integrating GNU @code{make}
     362
     363* Job Slots::                   Share job slots with GNU @code{make}.
     364* Terminal Output::             Control output to terminals.
     365
     366Sharing Job Slots with GNU @code{make}
     367
     368* POSIX Jobserver::             Using the jobserver on POSIX systems.
     369* Windows Jobserver::           Using the jobserver on Windows systems.
     370
    327371@end detailmenu
    328372@end menu
     
    351395
    352396@menu
    353 * Preparing::                   Preparing and Running Make
    354 * Reading::                     On Reading this Text
    355 * Bugs::                        Problems and Bugs
     397* Preparing::                   Preparing and running @code{make}.
     398* Reading::                     On reading this text.
     399* Bugs::                        Problems and bugs.
    356400@end menu
    357401
     
    487531@menu
    488532* Rule Introduction::           What a rule looks like.
    489 * Simple Makefile::             A Simple Makefile
    490 * How Make Works::              How @code{make} Processes This Makefile
    491 * Variables Simplify::          Variables Make Makefiles Simpler
    492 * make Deduces::                Letting @code{make} Deduce the Recipes
    493 * Combine By Prerequisite::     Another Style of Makefile
    494 * Cleanup::                     Rules for Cleaning the Directory
     533* Simple Makefile::             A simple makefile.
     534* How Make Works::              How @code{make} processes this makefile.
     535* Variables Simplify::          Variables make makefiles simpler.
     536* make Deduces::                Letting @code{make} deduce the recipes.
     537* Combine By Prerequisite::     Another style of makefile.
     538* Cleanup::                     Rules for cleaning the directory.
    495539@end menu
    496540
     
    592636
    593637@noindent
    594 We split each long line into two lines using backslash-newline; this is
    595 like using one long line, but is easier to read.
     638We split each long line into two lines using backslash/newline; this is
     639like using one long line, but is easier to read.  @xref{Splitting Lines,
     640, Splitting Long Lines}.
    596641@cindex continuation lines
    597642@cindex @code{\} (backslash), for continuation lines
     
    10271072@end itemize
    10281073
     1074@menu
     1075* Splitting Lines::             Splitting long lines in makefiles
     1076@end menu
     1077
     1078@node Splitting Lines,  , Makefile Contents, Makefile Contents
     1079@subsection Splitting Long Lines
     1080@cindex splitting long lines
     1081@cindex long lines, splitting
     1082@cindex backslash (@code{\}), to quote newlines
     1083
     1084Makefiles use a ``line-based'' syntax in which the newline character
     1085is special and marks the end of a statement.  GNU @code{make} has no
     1086limit on the length of a statement line, up to the amount of memory in
     1087your computer.
     1088
     1089However, it is difficult to read lines which are too long to display
     1090without wrapping or scrolling.  So, you can format your makefiles for
     1091readability by adding newlines into the middle of a statement: you do
     1092this by escaping the internal newlines with a backslash (@code{\})
     1093character.  Where we need to make a distinction we will refer to
     1094``physical lines'' as a single line ending with a newline (regardless
     1095of whether it is escaped) and a ``logical line'' being a complete
     1096statement including all escaped newlines up to the first non-escaped
     1097newline.
     1098
     1099The way in which backslash/newline combinations are handled depends on
     1100whether the statement is a recipe line or a non-recipe line.  Handling
     1101of backslash/newline in a recipe line is discussed later
     1102(@pxref{Splitting Recipe Lines}).
     1103
     1104Outside of recipe lines, backslash/newlines are converted into a
     1105single space character.  Once that is done, all whitespace around the
     1106backslash/newline is condensed into a single space: this includes all
     1107whitespace preceding the backslash, all whitespace at the beginning of
     1108the line after the backslash/newline, and any consecutive
     1109backslash/newline combinations.
     1110
     1111If the @code{.POSIX} special target is defined then backslash/newline
     1112handling is modified slightly to conform to POSIX.2: first, whitespace
     1113preceding a backslash is not removed and second, consecutive
     1114backslash/newlines are not condensed.
     1115
    10291116@node Makefile Names, Include, Makefile Contents, Makefiles
    10301117@section What Name to Give Your Makefile
     
    12201307@node Remaking Makefiles, Overriding Makefiles, MAKEFILES Variable, Makefiles
    12211308@section How Makefiles Are Remade
    1222 
    12231309@cindex updating makefiles
    12241310@cindex remaking makefiles
     
    12421328you want to keep @code{make} from performing an implicit rule search
    12431329on them, perhaps for efficiency reasons, you can use any normal method
    1244 of preventing implicit rule lookup to do so.  For example, you can
     1330of preventing implicit rule look-up to do so.  For example, you can
    12451331write an explicit rule with the makefile as the target, and an empty
    12461332recipe (@pxref{Empty Recipes, ,Using Empty Recipes}).
     
    13061392another makefile.  You can often use the @samp{include} directive to
    13071393include one in the other, and add more targets or variable definitions.
    1308 However, it is illegal for two makefiles to give different recipes for
     1394However, it is invalid for two makefiles to give different recipes for
    13091395the same target.  But there is another way.
    13101396
     
    13801466@cindex ?=, expansion
    13811467@cindex +=, expansion
     1468@cindex !=, expansion
    13821469@cindex define, expansion
    13831470
     
    13881475@var{immediate} ?= @var{deferred}
    13891476@var{immediate} := @var{immediate}
     1477@var{immediate} ::= @var{immediate}
    13901478@var{immediate} += @var{deferred} or @var{immediate}
     1479@var{immediate} != @var{immediate}
    13911480
    13921481define @var{immediate}
     
    14061495endef
    14071496
     1497define @var{immediate} ::=
     1498  @var{immediate}
     1499endef
     1500
    14081501define @var{immediate} +=
    14091502  @var{deferred} or @var{immediate}
    14101503endef
     1504
     1505define @var{immediate} !=
     1506  @var{immediate}
     1507endef
    14111508@end example
    14121509
    14131510For the append operator, @samp{+=}, the right-hand side is considered
    14141511immediate if the variable was previously set as a simple variable
    1415 (@samp{:=}), and deferred otherwise.
     1512(@samp{:=} or @samp{::=}), and deferred otherwise.
     1513
     1514For the shell assignment operator, @samp{!=}, the right-hand side is
     1515evaluated immediately and handed to the shell.  The result is stored in the
     1516variable named on the left, and that variable becomes a simple variable
     1517(and will thus be re-evaluated on each reference).
    14161518
    14171519@subheading Conditional Directives
     
    14391541@example
    14401542@var{immediate} : @var{immediate} ; @var{deferred}
    1441         @var{deferred}
     1543        @var{deferred}
    14421544@end example
    14431545
     
    14881590without being recognized as a variable reference.  Now during the
    14891591secondary expansion the first word is expanded again but since it
    1490 contains no variable or function references it remains the static
    1491 value @file{onefile}, while the second word is now a normal reference
    1492 to the variable @var{TWOVAR}, which is expanded to the value
    1493 @file{twofile}.  The final result is that there are two prerequisites,
    1494 @file{onefile} and @file{twofile}.
     1592contains no variable or function references it remains the value
     1593@file{onefile}, while the second word is now a normal reference to the
     1594variable @var{TWOVAR}, which is expanded to the value @file{twofile}.
     1595The final result is that there are two prerequisites, @file{onefile}
     1596and @file{twofile}.
    14951597
    14961598Obviously, this is not a very interesting case since the same result
     
    16341736Search, ,Implicit Rule Search Algorithm}, is appended (after
    16351737expansion) to all the patterns in the prerequisites list.  As an
    1636 example:
     1738example:@refill
    16371739
    16381740@example
     
    16421744
    16431745%.o: $$(addsuffix /%.c,foo bar) foo.h
    1644 @end example
    1645 
    1646 The prerequisite list after the secondary expansion and directory
    1647 prefix reconstruction will be @file{/tmp/foo/foo.c /tmp/var/bar/foo.c
    1648 foo.h}.  If you are not interested in this reconstruction, you can use
    1649 @code{$$*} instead of @code{%} in the prerequisites list.
     1746        @@echo $^
     1747@end example
     1748
     1749The prerequisite list printed, after the secondary expansion and
     1750directory prefix reconstruction, will be @file{/tmp/foo/foo.c
     1751/tmp/bar/foo.c foo.h}.  If you are not interested in this
     1752reconstruction, you can use @code{$$*} instead of @code{%} in the
     1753prerequisites list.
    16501754
    16511755@node Rules, Recipes, Makefiles, Top
     
    16851789* Directory Search::            Searching other directories for source files.
    16861790* Phony Targets::               Using a target that is not a real file's name.
    1687 * Force Targets::               You can use a target without recipes
     1791* Force Targets::               You can use a target without a recipe
    16881792                                  or prerequisites to mark other targets
    16891793                                  as phony.
     
    19222026
    19232027@menu
    1924 * Wildcard Examples::           Several examples
     2028* Wildcard Examples::           Several examples.
    19252029* Wildcard Pitfall::            Problems to avoid.
    19262030* Wildcard Function::           How to cause wildcard expansion where
     
    21202224                                  for a specified class of names.
    21212225* Search Algorithm::            When and how search paths are applied.
    2122 * Recipes/Search::             How to write recipes that work together
     2226* Recipes/Search::              How to write recipes that work together
    21232227                                  with search paths.
    21242228* Implicit/Search::             How search paths affect implicit rules.
     
    24562560@samp{-l@var{name}} is seen, @code{make} will replace the percent in
    24572561each pattern in the list with @var{name} and perform the above directory
    2458 searches using each library filename.
     2562searches using each library file name.
    24592563
    24602564The default value for @code{.LIBPATTERNS} is @samp{lib%.so lib%.a},
     
    24932597
    24942598@findex .PHONY
    2495 The phony target will cease to work if anything ever does create a file
    2496 named @file{clean} in this directory.  Since it has no prerequisites, the
    2497 file @file{clean} would inevitably be considered up to date, and its
    2498 recipe would not be executed.  To avoid this problem, you can explicitly
    2499 declare the target to be phony, using the special target @code{.PHONY}
     2599In this example, the @file{clean} target will not work properly if a
     2600file named @file{clean} is ever created in this directory.  Since it
     2601has no prerequisites, @file{clean} would always be considered up to
     2602date and its recipe would not be executed.  To avoid this problem you
     2603can explicitly declare the target to be phony by making it a
     2604prerequisite of the special target @code{.PHONY}
    25002605(@pxref{Special Targets, ,Special Built-in Target Names}) as follows:
    2501 
    2502 @example
    2503 .PHONY : clean
    2504 @end example
    2505 
    2506 @noindent
    2507 Once this is done, @samp{make clean} will run the recipe regardless of
    2508 whether there is a file named @file{clean}.
    2509 
    2510 Since it knows that phony targets do not name actual files that could be
    2511 remade from other files, @code{make} skips the implicit rule search for
    2512 phony targets (@pxref{Implicit Rules}).  This is why declaring a target
    2513 phony is good for performance, even if you are not worried about the
    2514 actual file existing.
    2515 
    2516 Thus, you first write the line that states that @code{clean} is a
    2517 phony target, then you write the rule, like this:
    25182606
    25192607@example
     
    25252613@end example
    25262614
    2527 Another example of the usefulness of phony targets is in conjunction
    2528 with recursive invocations of @code{make} (for more information, see
    2529 @ref{Recursion, ,Recursive Use of @code{make}}).  In this case the
    2530 makefile will often contain a variable which lists a number of
    2531 subdirectories to be built.  One way to handle this is with one rule
    2532 whose recipe is a shell loop over the subdirectories, like this:
     2615@noindent
     2616Once this is done, @samp{make clean} will run the recipe regardless of
     2617whether there is a file named @file{clean}.
     2618
     2619Phony targets are also useful in conjunction with recursive
     2620invocations of @code{make} (@pxref{Recursion, ,Recursive Use of @code{make}}).
     2621In this situation the makefile will often contain a variable which
     2622lists a number of sub-directories to be built.  A simplistic way to
     2623handle this is to define one rule with a recipe that loops over the
     2624sub-directories, like this:
    25332625
    25342626@example
     
    25442636
    25452637There are problems with this method, however.  First, any error
    2546 detected in a submake is ignored by this rule, so it will continue
     2638detected in a sub-make is ignored by this rule, so it will continue
    25472639to build the rest of the directories even when one fails.  This can be
    25482640overcome by adding shell commands to note the error and exit, but then
     
    25532645one rule.
    25542646
    2555 By declaring the subdirectories as phony targets (you must do this as
    2556 the subdirectory obviously always exists; otherwise it won't be built)
    2557 you can remove these problems:
     2647By declaring the sub-directories as @code{.PHONY} targets (you must do
     2648this as the sub-directory obviously always exists; otherwise it won't
     2649be built) you can remove these problems:
    25582650
    25592651@example
     
    25722664@end example
    25732665
    2574 Here we've also declared that the @file{foo} subdirectory cannot be
    2575 built until after the @file{baz} subdirectory is complete; this kind of
     2666Here we've also declared that the @file{foo} sub-directory cannot be
     2667built until after the @file{baz} sub-directory is complete; this kind of
    25762668relationship declaration is particularly important when attempting
    25772669parallel builds.
     2670
     2671The implicit rule search (@pxref{Implicit Rules}) is skipped for
     2672@code{.PHONY} targets.  This is why declaring a target as
     2673@code{.PHONY} is good for performance, even if you are not worried
     2674about the actual file existing.
    25782675
    25792676A phony target should not be a prerequisite of a real target file; if it
     
    28172914is up to date.  Unfortunately, some hosts do not provide a way to set a
    28182915high resolution file time stamp, so commands like @samp{cp -p} that
    2819 explicitly set a file's time stamp must discard its subsecond part.
     2916explicitly set a file's time stamp must discard its sub-second part.
    28202917If a file is created by such a command, you should list it as a
    28212918prerequisite of @code{.LOW_RESOLUTION_TIME} so that @command{make}
     
    28312928@end example
    28322929
    2833 Since @samp{cp -p} discards the subsecond part of @file{src}'s time
     2930Since @samp{cp -p} discards the sub-second part of @file{src}'s time
    28342931stamp, @file{dst} is typically slightly older than @file{src} even when
    28352932it is up to date.  The @code{.LOW_RESOLUTION_TIME} line causes
     
    31333230for each target that does not.  If you have a list of files, only some of
    31343231which will match the pattern, you can use the @code{filter} function to
    3135 remove nonmatching file names (@pxref{Text Functions, ,Functions for String Substitution and Analysis}):
     3232remove non-matching file names (@pxref{Text Functions, ,Functions for String Substitution and Analysis}):
    31363233
    31373234@example
     
    32873384The compiler will do it for you.
    32883385
    3289 Note that such a prerequisite constitutes mentioning @file{main.o} in a
    3290 makefile, so it can never be considered an intermediate file by implicit
    3291 rule search.  This means that @code{make} won't ever remove the file
    3292 after using it; @pxref{Chained Rules, ,Chains of Implicit Rules}.
     3386Note that such a rule constitutes mentioning @file{main.o} in a
     3387makefile, so it can never be considered an intermediate file by
     3388implicit rule search.  This means that @code{make} won't ever remove
     3389the file after using it; @pxref{Chained Rules, ,Chains of Implicit
     3390Rules}.
    32933391
    32943392@cindex @code{make depend}
     
    33353433of @samp{-M}.  This omits prerequisites on system header files.
    33363434@xref{Preprocessor Options, , Options Controlling the Preprocessor,
    3337 gcc.info, Using GNU CC}, for details.
     3435gcc, Using GNU CC}, for details.
    33383436
    33393437@cindex @code{sed} (shell command)
     
    34643562
    34653563@menu
    3466 * Splitting Lines::             Breaking long recipe lines for readability.
     3564* Splitting Recipe Lines::      Breaking long recipe lines for readability.
    34673565* Variables in Recipes::        Using @code{make} variables in recipes.
    34683566@end menu
    34693567
    3470 @node Splitting Lines, Variables in Recipes, Recipe Syntax, Recipe Syntax
     3568@node Splitting Recipe Lines, Variables in Recipes, Recipe Syntax, Recipe Syntax
    34713569@subsection Splitting Recipe Lines
    34723570@cindex recipes, splitting
     
    34873585
    34883586However, in contrast to how they are treated in other places in a
    3489 makefile, backslash-newline pairs are @emph{not} removed from the
    3490 recipe.  Both the backslash and the newline characters are preserved
    3491 and passed to the shell.  How the backslash-newline is interpreted
    3492 depends on your shell.  If the first character of the next line after
    3493 the backslash-newline is the recipe prefix character (a tab by
    3494 default; @pxref{Special Variables}), then that character (and only
    3495 that character) is removed.  Whitespace is never added to the recipe.
     3587makefile (@pxref{Splitting Lines, , Splitting Long Lines}),
     3588backslash/newline pairs are @emph{not} removed from the recipe.  Both
     3589the backslash and the newline characters are preserved and passed to
     3590the shell.  How the backslash/newline is interpreted depends on your
     3591shell.  If the first character of the next line after the
     3592backslash/newline is the recipe prefix character (a tab by default;
     3593@pxref{Special Variables}), then that character (and only that
     3594character) is removed.  Whitespace is never added to the recipe.
    34963595
    34973596For example, the recipe for the all target in this makefile:
     
    35643663
    35653664Sometimes you want to split a long line inside of single quotes, but
    3566 you don't want the backslash-newline to appear in the quoted content.
     3665you don't want the backslash/newline to appear in the quoted content.
    35673666This is often the case when passing scripts to languages such as Perl,
    35683667where extraneous backslashes inside the script can change its meaning
     
    35713670@code{make} variable then use the variable in the recipe.  In this
    35723671situation the newline quoting rules for makefiles will be used, and
    3573 the backslash-newline will be removed.  If we rewrite our example
     3672the backslash/newline will be removed.  If we rewrite our example
    35743673above using this method:
    35753674
     
    35973696uses it.
    35983697
    3599 @node Variables in Recipes,  , Splitting Lines, Recipe Syntax
     3698@node Variables in Recipes,  , Splitting Recipe Lines, Recipe Syntax
    36003699@subsection Using Variables in Recipes
    36013700@cindex variable references in recipes
     
    37003799
    37013800When it is time to execute recipes to update a target, they are
    3702 executed by invoking a new subshell for each line of the recipe,
     3801executed by invoking a new sub-shell for each line of the recipe,
    37033802unless the @code{.ONESHELL} special target is in effect
    37043803(@pxref{One Shell, ,Using One Shell})  (In practice, @code{make} may
     
    37313830
    37323831@menu
    3733 * One Shell::                   One shell for all lines in a recipe
     3832* One Shell::                   One shell for all lines in a recipe.
    37343833* Choosing the Shell::          How @code{make} chooses the shell used
    37353834                                  to run recipes.
     
    39704069slots is one, which means serial execution (one thing at a time).
    39714070
    3972 One unpleasant consequence of running several recipes simultaneously is
    3973 that output generated by the recipes appears whenever each recipe
    3974 sends it, so messages from different recipes may be interspersed.
    3975 
    3976 Another problem is that two processes cannot both take input from the
    3977 same device; so to make sure that only one recipe tries to take input
    3978 from the terminal at once, @code{make} will invalidate the standard
    3979 input streams of all but one running recipe.  This means that
    3980 attempting to read from standard input will usually be a fatal error (a
    3981 @samp{Broken pipe} signal) for most child processes if there are
    3982 several.
    3983 @cindex broken pipe
    3984 @cindex standard input
    3985 
    3986 It is unpredictable which recipe will have a valid standard input stream
    3987 (which will come from the terminal, or wherever you redirect the standard
    3988 input of @code{make}).  The first recipe run will always get it first, and
    3989 the first recipe started after that one finishes will get it next, and so
    3990 on.
    3991 
    3992 We will change how this aspect of @code{make} works if we find a better
    3993 alternative.  In the mean time, you should not rely on any recipe using
    3994 standard input at all if you are using the parallel execution feature; but
    3995 if you are not using this feature, then standard input works normally in
    3996 all recipes.
    3997 
    3998 Finally, handling recursive @code{make} invocations raises issues.  For
    3999 more information on this, see
    4000 @ref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}.
     4071Handling recursive @code{make} invocations raises issues for parallel
     4072execution.  For more information on this, see @ref{Options/Recursion,
     4073,Communicating Options to a Sub-@code{make}}.
    40014074
    40024075If a recipe fails (is killed by a signal or exits with a nonzero
    4003 status), and errors are not ignored for that recipe
    4004 (@pxref{Errors, ,Errors in Recipes}),
    4005 the remaining recipe lines to remake the same target will not be run.
    4006 If a recipe fails and the @samp{-k} or @samp{--keep-going}
    4007 option was not given
    4008 (@pxref{Options Summary, ,Summary of Options}),
    4009 @code{make} aborts execution.  If make
     4076status), and errors are not ignored for that recipe (@pxref{Errors,
     4077,Errors in Recipes}), the remaining recipe lines to remake the same
     4078target will not be run.  If a recipe fails and the @samp{-k} or
     4079@samp{--keep-going} option was not given (@pxref{Options Summary,
     4080,Summary of Options}), @code{make} aborts execution.  If make
    40104081terminates for any reason (including a signal) with child processes
    40114082running, it waits for them to finish before actually exiting.@refill
     
    40394110
    40404111By default, there is no load limit.
     4112
     4113@menu
     4114* Parallel Output::             Handling output during parallel execution
     4115* Parallel Input::              Handling input during parallel execution
     4116@end menu
     4117
     4118@node Parallel Output, Parallel Input, Parallel, Parallel
     4119@subsection Output During Parallel Execution
     4120@cindex output during parallel execution
     4121@cindex parallel execution, output during
     4122
     4123When running several recipes in parallel the output from each
     4124recipe appears as soon as it is generated, with the result that
     4125messages from different recipes may be interspersed, sometimes even
     4126appearing on the same line.  This can make reading the output very
     4127difficult.
     4128
     4129@cindex @code{--output-sync}
     4130@cindex @code{-O}
     4131To avoid this you can use the @samp{--output-sync} (@samp{-O}) option.
     4132This option instructs @code{make} to save the output from the commands
     4133it invokes and print it all once the commands are completed.
     4134Additionally, if there are multiple recursive @code{make} invocations
     4135running in parallel, they will communicate so that only one of them is
     4136generating output at a time.
     4137
     4138If working directory printing is enabled (@pxref{-w Option, ,The
     4139@samp{--print-directory} Option}), the enter/leave messages are
     4140printed around each output grouping.  If you prefer not to see these
     4141messages add the @samp{--no-print-directory} option to @code{MAKEFLAGS}.
     4142
     4143There are four levels of granularity when synchronizing output,
     4144specified by giving an argument to the option (e.g.,  @samp{-Oline} or
     4145@samp{--output-sync=recurse}).
     4146
     4147@table @code
     4148@item none
     4149This is the default: all output is sent directly as it is generated and
     4150no synchronization is performed.
     4151
     4152@item line
     4153Output from each individual line of the recipe is grouped and printed
     4154as soon as that line is complete.  If a recipe consists of multiple
     4155lines, they may be interspersed with lines from other recipes.
     4156
     4157@item target
     4158Output from the entire recipe for each target is grouped and printed
     4159once the target is complete.  This is the default if the
     4160@code{--output-sync} or @code{-O} option is given with no argument.
     4161
     4162@item recurse
     4163Output from each recursive invocation of @code{make} is grouped and
     4164printed once the recursive invocation is complete.
     4165
     4166@end table
     4167
     4168Regardless of the mode chosen, the total build time will be the same.
     4169The only difference is in how the output appears.
     4170
     4171The @samp{target} and @samp{recurse} modes both collect the output of
     4172the entire recipe of a target and display it uninterrupted when the
     4173recipe completes.  The difference between them is in how recipes that
     4174contain recursive invocations of @code{make} are treated
     4175(@pxref{Recursion, ,Recursive Use of @code{make}}).  For all recipes
     4176which have no recursive lines, the @samp{target} and @samp{recurse}
     4177modes behave identically.
     4178
     4179If the @samp{recurse} mode is chosen, recipes that contain recursive
     4180@code{make} invocations are treated the same as other targets: the
     4181output from the recipe, including the output from the recursive
     4182@code{make}, is saved and printed after the entire recipe is complete.
     4183This ensures output from all the targets built by a given recursive
     4184@code{make} instance are grouped together, which may make the output
     4185easier to understand.  However it also leads to long periods of time
     4186during the build where no output is seen, followed by large bursts of
     4187output.  If you are not watching the build as it proceeds, but instead
     4188viewing a log of the build after the fact, this may be the best option
     4189for you.
     4190
     4191If you are watching the output, the long gaps of quiet during the
     4192build can be frustrating.  The @samp{target} output synchronization
     4193mode detects when @code{make} is going to be invoked recursively,
     4194using the standard methods, and it will not synchronize the output of
     4195those lines.  The recursive @code{make} will perform the
     4196synchronization for its targets and the output from each will be
     4197displayed immediately when it completes.  Be aware that output from
     4198recursive lines of the recipe are not synchronized (for example if
     4199the recursive line prints a message before running @code{make}, that
     4200message will not be synchronized).
     4201
     4202The @samp{line} mode can be useful for front-ends that are watching
     4203the output of @code{make} to track when recipes are started and
     4204completed.
     4205
     4206Some programs invoked by @code{make} may behave differently if they
     4207determine they're writing output to a terminal versus a file (often
     4208described as ``interactive'' vs. ``non-interactive'' modes).  For
     4209example, many programs that can display colorized output will not do
     4210so if they determine they are not writing to a terminal.  If your
     4211makefile invokes a program like this then using the output
     4212synchronization options will cause the program to believe it's running
     4213in ``non-interactive'' mode even though the output will ultimately go
     4214to the terminal.
     4215
     4216@node Parallel Input,  , Parallel Output, Parallel
     4217@subsection Input During Parallel Execution
     4218@cindex input during parallel execution
     4219@cindex parallel execution, input during
     4220@cindex standard input
     4221
     4222Two processes cannot both take input from the same device at the same
     4223time.  To make sure that only one recipe tries to take input from the
     4224terminal at once, @code{make} will invalidate the standard input
     4225streams of all but one running recipe.  If another recipe attempts to
     4226read from standard input it will usually incur a fatal error (a
     4227@samp{Broken pipe} signal).
     4228@cindex broken pipe
     4229
     4230It is unpredictable which recipe will have a valid standard input stream
     4231(which will come from the terminal, or wherever you redirect the standard
     4232input of @code{make}).  The first recipe run will always get it first, and
     4233the first recipe started after that one finishes will get it next, and so
     4234on.
     4235
     4236We will change how this aspect of @code{make} works if we find a better
     4237alternative.  In the mean time, you should not rely on any recipe using
     4238standard input at all if you are using the parallel execution feature; but
     4239if you are not using this feature, then standard input works normally in
     4240all recipes.
    40414241
    40424242@node Errors, Interrupts, Parallel, Recipes
     
    41794379makefile.  This technique is useful when you want separate makefiles for
    41804380various subsystems that compose a larger system.  For example, suppose you
    4181 have a subdirectory @file{subdir} which has its own makefile, and you would
     4381have a sub-directory @file{subdir} which has its own makefile, and you would
    41824382like the containing directory's makefile to run @code{make} on the
    4183 subdirectory.  You can do it by writing this:
     4383sub-directory.  You can do it by writing this:
    41844384
    41854385@example
     
    42934493Variable values of the top-level @code{make} can be passed to the
    42944494sub-@code{make} through the environment by explicit request.  These
    4295 variables are defined in the sub-@code{make} as defaults, but do not
    4296 override what is specified in the makefile used by the sub-@code{make}
    4297 makefile unless you use the @samp{-e} switch (@pxref{Options Summary,
    4298 ,Summary of Options}).@refill
     4495variables are defined in the sub-@code{make} as defaults, but they do
     4496not override variables defined in the makefile used by
     4497the sub-@code{make} unless you use the @samp{-e} switch (@pxref{Options
     4498Summary, ,Summary of Options}).@refill
    42994499
    43004500To pass down, or @dfn{export}, a variable, @code{make} adds the
     
    45224722
    45234723If your operating system doesn't support the above communication, then
    4524 @samp{-j 1} is always put into @code{MAKEFLAGS} instead of the value you
    4525 specified.  This is because if the @w{@samp{-j}} option were passed down
    4526 to sub-@code{make}s, you would get many more jobs running in parallel
     4724no @samp{-j} is added to @code{MAKEFLAGS}, so that sub-@code{make}s
     4725run in non-parallel mode.  If the @w{@samp{-j}} option were passed down
     4726to sub-@code{make}s you would get many more jobs running in parallel
    45274727than you asked for.  If you give @samp{-j} with no numeric argument,
    45284728meaning to run as many jobs as possible in parallel, this is passed
     
    45564756see the error message @samp{Arg list too long}, this may be the problem.
    45574757@findex .POSIX
    4558 @cindex POSIX.2
     4758@cindex POSIX
    45594759(For strict compliance with POSIX.2, changing @code{MAKEOVERRIDES} does
    45604760not affect @code{MAKEFLAGS} if the special target @samp{.POSIX} appears
     
    46084808put in one of these variables, could have disastrous consequences and would
    46094809certainly have at least surprising and probably annoying effects.@refill
     4810
     4811If you'd like to run other implementations of @code{make} in addition
     4812to GNU @code{make}, and hence do not want to add GNU
     4813@code{make}-specific flags to the @code{MAKEFLAGS} variable, you can
     4814add them to the @code{GNUMAKEFLAGS} variable instead.  This variable
     4815is parsed just before @code{MAKEFLAGS}, in the same way as
     4816@code{MAKEFLAGS}.  When @code{make} constructs @code{MAKEFLAGS} to
     4817pass to a recursive @code{make} it will include all flags, even those
     4818taken from @code{GNUMAKEFLAGS}.  As a result, after parsing
     4819@code{GNUMAKEFLAGS} GNU @code{make} sets this variable to the empty
     4820string to avoid duplicating flags during recursion.
     4821
     4822It's best to use @code{GNUMAKEFLAGS} only with flags which won't
     4823materially change the behavior of your makefiles.  If your makefiles
     4824require GNU make anyway then simply use @code{MAKEFLAGS}.  Flags such
     4825as @samp{--no-print-directory} or @samp{--output-sync} may be
     4826appropriate for @code{GNUMAKEFLAGS}.
    46104827
    46114828@node -w Option,  , Options/Recursion, Recursion
     
    47174934In recipe execution, each line of a canned sequence is treated just as
    47184935if the line appeared on its own in the rule, preceded by a tab.  In
    4719 particular, @code{make} invokes a separate subshell for each line.  You
     4936particular, @code{make} invokes a separate sub-shell for each line.  You
    47204937can use the special prefix characters that affect command lines
    47214938(@samp{@@}, @samp{-}, and @samp{+}) on each line of a canned sequence.
     
    47664983
    47674984@findex .DEFAULT@r{, and empty recipes}
    4768 You may be wondering why you would want to define a recipe that
    4769 does nothing.  The only reason this is useful is to prevent a target
    4770 from getting implicit recipes (from implicit rules or the
    4771 @code{.DEFAULT} special target; @pxref{Implicit Rules} and
    4772 @pxref{Last Resort, ,Defining Last-Resort Default Rules}).@refill
    4773 
    4774 @c !!! another reason is for canonical stamp files:
    4775 @ignore
    4776 @example
    4777 foo: stamp-foo ;
    4778 stamp-foo: foo.in
    4779         create foo frm foo.in
    4780         touch $@
    4781 @end example
    4782 @end ignore
    4783 
    4784 You may be inclined to define empty recipes for targets that are
    4785 not actual files, but only exist so that their prerequisites can be
     4985You may be wondering why you would want to define a recipe that does
     4986nothing.  One reason this is useful is to prevent a target from
     4987getting implicit recipes (from implicit rules or the @code{.DEFAULT}
     4988special target; @pxref{Implicit Rules} and @pxref{Last Resort,
     4989,Defining Last-Resort Default Rules}).@refill
     4990
     4991Empty recipes can also be used to avoid errors for targets that will
     4992be created as a side-effect of another recipe: if the target does not
     4993exist the empty recipe ensures that @code{make} won't complain that it
     4994doesn't know how to build the target, and @code{make} will assume the
     4995target is out of date.
     4996
     4997You may be inclined to define empty recipes for targets that are not
     4998actual files, but only exist so that their prerequisites can be
    47864999remade.  However, this is not the best way to do that, because the
    4787 prerequisites may not be remade properly if the target file actually does exist.
    4788 @xref{Phony Targets, ,Phony Targets}, for a better way to do this.
     5000prerequisites may not be remade properly if the target file actually
     5001does exist.  @xref{Phony Targets, ,Phony Targets}, for a better way to
     5002do this.
    47895003
    47905004@node Using Variables, Conditionals, Recipes, Top
     
    48115025write output in, or anything else you can imagine.
    48125026
    4813 A variable name may be any sequence of characters not containing @samp{:},
    4814 @samp{#}, @samp{=}, or leading or trailing whitespace.  However,
    4815 variable names containing characters other than letters, numbers, and
    4816 underscores should be avoided, as they may be given special meanings in the
    4817 future, and with some shells they cannot be passed through the environment to a
    4818 sub-@code{make}
    4819 (@pxref{Variables/Recursion, ,Communicating Variables to a Sub-@code{make}}).
     5027A variable name may be any sequence of characters not containing
     5028@samp{:}, @samp{#}, @samp{=}, or whitespace.  However, variable names
     5029containing characters other than letters, numbers, and underscores
     5030should be considered carefully, as in some shells they cannot be
     5031passed through the environment to a sub-@code{make}
     5032(@pxref{Variables/Recursion, ,Communicating Variables to a
     5033Sub-@code{make}}).  Variable names beginning with @samp{.} and an
     5034uppercase letter may be given special meaning in future versions of
     5035@code{make}.
    48205036
    48215037Variable names are case-sensitive.  The names @samp{foo}, @samp{FOO},
     
    49415157expands to @samp{$(ugh)} which finally expands to @samp{Huh?}.@refill
    49425158
    4943 This flavor of variable is the only sort supported by other versions of
    4944 @code{make}.  It has its advantages and its disadvantages.  An advantage
    4945 (most would say) is that:
     5159This flavor of variable is the only sort supported by most other
     5160versions of @code{make}.  It has its advantages and its disadvantages.
     5161An advantage (most would say) is that:
    49465162
    49475163@example
     
    49795195@cindex variables, simply expanded
    49805196@cindex :=
     5197@cindex ::=
    49815198@dfn{Simply expanded variables} are defined by lines using @samp{:=}
    4982 (@pxref{Setting, ,Setting Variables}).
     5199or @samp{::=} (@pxref{Setting, ,Setting Variables}).  Both forms are
     5200equivalent in GNU @code{make}; however only the @samp{::=} form is
     5201described by the POSIX standard (support for @samp{::=} was added to
     5202the POSIX standard in 2012, so older versions of @code{make} won't
     5203accept this form either).
     5204
    49835205The value of a simply expanded variable is scanned
    49845206once and for all, expanding any references to other variables and
     
    52205442
    52215443References to recursively-expanded variables within a variable name are
    5222 reexpanded in the usual fashion.  For example:
     5444re-expanded in the usual fashion.  For example:
    52235445
    52245446@example
     
    53995621@cindex =
    54005622@cindex :=
     5623@cindex ::=
    54015624@cindex ?=
     5625@cindex !=
    54025626
    54035627To set a variable from the makefile, write a line starting with the
    5404 variable name followed by @samp{=} or @samp{:=}.  Whatever follows the
    5405 @samp{=} or @samp{:=} on the line becomes the value.  For example,
     5628variable name followed by @samp{=}, @samp{:=}, or @samp{::=}.  Whatever
     5629follows the @samp{=}, @samp{:=}, or @samp{::=} on the line becomes the
     5630value.  For example,
    54065631
    54075632@example
     
    54135638name and immediately after the @samp{=} is ignored.
    54145639
    5415 Variables defined with @samp{=} are @dfn{recursively expanded} variables.
    5416 Variables defined with @samp{:=} are @dfn{simply expanded} variables; these
    5417 definitions can contain variable references which will be expanded before
    5418 the definition is made.  @xref{Flavors, ,The Two Flavors of Variables}.
     5640Variables defined with @samp{=} are @dfn{recursively expanded}
     5641variables.  Variables defined with @samp{:=} or @samp{::=} are
     5642@dfn{simply expanded} variables; these definitions can contain
     5643variable references which will be expanded before the definition is
     5644made.  @xref{Flavors, ,The Two Flavors of Variables}.
    54195645
    54205646The variable name may contain function and variable references, which
     
    54225648
    54235649There is no limit on the length of the value of a variable except the
    5424 amount of swapping space on the computer.  When a variable definition is
    5425 long, it is a good idea to break it into several lines by inserting
    5426 backslash-newline at convenient places in the definition.  This will not
    5427 affect the functioning of @code{make}, but it will make the makefile easier
    5428 to read.
     5650amount of memory on the computer.  You can split the value of a
     5651variable into multiple physical lines for readability
     5652(@pxref{Splitting Lines, ,Splitting Long Lines}).
    54295653
    54305654Most variable names are considered to have the empty string as a value if
     
    54545678@end example
    54555679
     5680The shell assignment operator @samp{!=} can be used to execute a
     5681shell script and set a variable to its output.  This operator first
     5682evaluates the right-hand side, then passes that result to the shell
     5683for execution.  If the result of the execution ends in a newline, that
     5684one newline is removed; all other newlines are replaced by spaces.
     5685The resulting string is then placed into the named
     5686recursively-expanded variable.  For example:
     5687
     5688@example
     5689hash != printf '\043'
     5690file_list != find . -name '*.c'
     5691@end example
     5692
     5693If the result of the execution could produce a @code{$}, and you don't
     5694intend what follows that to be interpreted as a make variable or
     5695function reference, then you must replace every @code{$} with
     5696@code{$$} as part of the execution.  Alternatively, you can set a
     5697simply expanded variable to the result of running a program using the
     5698@code{shell} function call.  @xref{Shell Function, , The @code{shell}
     5699Function}.  For example:
     5700
     5701@example
     5702hash := $(shell printf '\043')
     5703var := $(shell find . -name "*.c")
     5704@end example
     5705
     5706As with the @code{shell} function, the exit status of the just-invoked
     5707shell script is stored in the @code{.SHELLSTATUS} variable.
     5708
     5709
    54565710@node Appending, Override Directive, Setting, Using Variables
    54575711@section Appending More Text to Variables
     
    54985752When you add to a variable's value with @samp{+=}, @code{make} acts
    54995753essentially as if you had included the extra text in the initial
    5500 definition of the variable.  If you defined it first with @samp{:=},
    5501 making it a simply-expanded variable, @samp{+=} adds to that
    5502 simply-expanded definition, and expands the new text before appending it
    5503 to the old value just as @samp{:=} does
    5504 (see @ref{Setting, ,Setting Variables}, for a full explanation of @samp{:=}).
    5505 In fact,
     5754definition of the variable.  If you defined it first with @samp{:=} or
     5755@samp{::=}, making it a simply-expanded variable, @samp{+=} adds to
     5756that simply-expanded definition, and expands the new text before
     5757appending it to the old value just as @samp{:=} does (see
     5758@ref{Setting, ,Setting Variables}, for a full explanation of
     5759@samp{:=} or @samp{::=}).  In fact,
    55065760
    55075761@example
     
    55615815The first line defines the @code{CFLAGS} variable with a reference to another
    55625816variable, @code{includes}.  (@code{CFLAGS} is used by the rules for C
    5563 compilation; @pxref{Catalogue of Rules, ,Catalogue of Implicit Rules}.)
     5817compilation; @pxref{Catalogue of Rules, ,Catalogue of Built-In Rules}.)
    55645818Using @samp{=} for the definition makes @code{CFLAGS} a recursively-expanded
    55655819variable, meaning @w{@samp{$(includes) -O}} is @emph{not} expanded when
     
    57175971since two commands separated by semicolon behave much like two separate
    57185972shell commands.  However, note that using two separate lines means
    5719 @code{make} will invoke the shell twice, running an independent subshell
     5973@code{make} will invoke the shell twice, running an independent sub-shell
    57205974for each line.  @xref{Execution, ,Recipe Execution}.
    57215975
     
    58436097
    58446098The @var{variable-assignment} can be any valid form of assignment;
    5845 recursive (@samp{=}), static (@samp{:=}), appending (@samp{+=}), or
    5846 conditional (@samp{?=}).  All variables that appear within the
    5847 @var{variable-assignment} are evaluated within the context of the
    5848 target: thus, any previously-defined target-specific variable values
    5849 will be in effect.  Note that this variable is actually distinct from
    5850 any ``global'' value: the two variables do not have to have the same
    5851 flavor (recursive vs.@: static).
     6099recursive (@samp{=}), simple (@samp{:=} or @samp{::=}), appending
     6100(@samp{+=}), or conditional (@samp{?=}).  All variables that appear
     6101within the @var{variable-assignment} are evaluated within the context
     6102of the target: thus, any previously-defined target-specific variable
     6103values will be in effect.  Note that this variable is actually
     6104distinct from any ``global'' value: the two variables do not have to
     6105have the same flavor (recursive vs.@: simple).
    58526106
    58536107Target-specific variables have the same priority as any other makefile
     
    59746228Due to the @code{private} modifier, @code{a.o} and @code{b.o} will not
    59756229inherit the @code{EXTRA_CFLAGS} variable assignment from the
    5976 @code{progs} target.
     6230@code{prog} target.
    59776231
    59786232@node Special Variables,  , Suppressing Inheritance, Using Variables
     
    60706324
    60716325Note that assigning more than one target name to @code{.DEFAULT_GOAL} is
    6072 illegal and will result in an error.
     6326invalid and will result in an error.
    60736327
    60746328@vindex MAKE_RESTARTS @r{(number of times @code{make} has restarted)}
     
    60796333this is not the same as recursion (counted by the @code{MAKELEVEL}
    60806334variable).  You should not set, modify, or export this variable.
     6335
     6336@vindex MAKE_TERMOUT @r{(whether stdout is a terminal)}
     6337@vindex MAKE_TERMERR @r{(whether stderr is a terminal)}
     6338@item MAKE_TERMOUT
     6339@itemx MAKE_TERMERR
     6340When @code{make} starts it will check whether stdout and stderr will
     6341show their output on a terminal.  If so, it will set
     6342@code{MAKE_TERMOUT} and @code{MAKE_TERMERR}, respectively, to the name
     6343of the terminal device (or @code{true} if this cannot be determined).
     6344If set these variables will be marked for export.  These variables
     6345will not be changed by @code{make} and they will not be modified if
     6346already set.
     6347
     6348These values can be used (particularly in combination with output
     6349synchronization (@pxref{Parallel Output, ,Output During Parallel
     6350Execution}) to determine whether @code{make} itself is writing to a
     6351terminal; they can be tested to decide whether to force recipe
     6352commands to generate colorized output for example.
     6353
     6354If you invoke a sub-@code{make} and redirect its stdout or stderr it
     6355is your responsibility to reset or unexport these variables as well,
     6356if your makefiles rely on them.
    60816357
    60826358@vindex .RECIPEPREFIX @r{(change the recipe prefix character)}
     
    61216397@item .FEATURES
    61226398Expands to a list of special features supported by this version of
    6123 @code{make}.  Possible values include:
     6399@code{make}.  Possible values include, but are not limited to:
    61246400
    61256401@table @samp
    61266402
    61276403@item archives
    6128 Supports @code{ar} (archive) files using special filename syntax.
     6404Supports @code{ar} (archive) files using special file name syntax.
    61296405@xref{Archives, ,Using @code{make} to Update Archive Files}.
    61306406
     
    61416417,Parallel Execution}.
    61426418
    6143 @item second-expansion
    6144 Supports secondary expansion of prerequisite lists.
     6419@item oneshell
     6420Supports the @code{.ONESHELL} special target.  @xref{One Shell, ,Using
     6421One Shell}.
    61456422
    61466423@item order-only
     
    61486425of Prerequisites}.
    61496426
     6427@item second-expansion
     6428Supports secondary expansion of prerequisite lists.
     6429
     6430@item shortest-stem
     6431Uses the ``shortest stem'' method of choosing which pattern, of
     6432multiple applicable options, will be used.  @xref{Pattern Match, ,How
     6433Patterns Match}.
     6434
    61506435@item target-specific
    61516436Supports target-specific and pattern-specific variable assignments.
    61526437@xref{Target-specific, ,Target-specific Variable Values}.
    61536438
     6439@item undefine
     6440Supports the @code{undefine} directive.  @xref{Undefine Directive}.
     6441
     6442@item guile
     6443Has GNU Guile available as an embedded extension language.
     6444@xref{Guile Integration, ,GNU Guile Integration}.
     6445
     6446@item load
     6447Supports dynamically loadable objects for creating custom extensions.
     6448@xref{Loading Objects, ,Loading Dynamic Objects}.
    61546449@end table
    61556450
     
    62926587
    62936588@example
    6294 @var{conditional-directive}
     6589@var{conditional-directive-one}
    62956590@var{text-if-one-is-true}
    6296 else @var{conditional-directive}
    6297 @var{text-if-true}
     6591else @var{conditional-directive-two}
     6592@var{text-if-two-is-true}
    62986593else
    6299 @var{text-if-false}
     6594@var{text-if-one-and-two-are-false}
    63006595endif
    63016596@end example
     
    63546649@item ifdef @var{variable-name}
    63556650The @code{ifdef} form takes the @emph{name} of a variable as its
    6356 argument, not a reference to a variable.  The value of that variable
    6357 has a non-empty value, the @var{text-if-true} is effective; otherwise,
    6358 the @var{text-if-false}, if any, is effective.  Variables that have
    6359 never been defined have an empty value.  The text @var{variable-name}
    6360 is expanded, so it could be a variable or function that expands
    6361 to the name of a variable.  For example:
     6651argument, not a reference to a variable.  If the value of that
     6652variable has a non-empty value, the @var{text-if-true} is effective;
     6653otherwise, the @var{text-if-false}, if any, is effective.  Variables
     6654that have never been defined have an empty value.  The text
     6655@var{variable-name} is expanded, so it could be a variable or function
     6656that expands to the name of a variable.  For example:
    63626657
    63636658@example
     
    64936788* Conditional Functions::       Functions that implement conditions.
    64946789* Foreach Function::            Repeat some text with controlled variation.
     6790* File Function::               Write text to a file.
    64956791* Call Function::               Expand a user-defined function.
    64966792* Value Function::              Return the un-expanded value of a variable.
     
    64986794* Origin Function::             Find where a variable got its value.
    64996795* Flavor Function::             Find out the flavor of a variable.
     6796* Make Control Functions::      Functions that control how make runs.
    65006797* Shell Function::              Substitute the output of a shell command.
    6501 * Make Control Functions::      Functions that control how make runs.
     6798* Guile Function::              Use GNU Guile embedded scripting language.
    65026799@end menu
    65036800
     
    65096806@cindex functions, syntax of
    65106807
    6511 A function call resembles a variable reference.  It looks like this:
     6808A function call resembles a variable reference.  It can appear
     6809anywhere a variable reference can appear, and it is expanded using the
     6810same rules as variable references.  A function call looks like this:
    65126811
    65136812@example
     
    65246823Here @var{function} is a function name; one of a short list of names
    65256824that are part of @code{make}.  You can also essentially create your own
    6526 functions by using the @code{call} builtin function.
     6825functions by using the @code{call} built-in function.
    65276826
    65286827The @var{arguments} are the arguments of the function.  They are
     
    71417440@end table
    71427441
    7143 @node Foreach Function, Call Function, Conditional Functions, Functions
     7442@node Foreach Function, File Function, Conditional Functions, Functions
    71447443@section The @code{foreach} Function
    71457444@findex foreach
     
    72037502Here we use the variable @code{find_files} this way.  We use plain @samp{=}
    72047503to define a recursively-expanding variable, so that its value contains an
    7205 actual function call to be reexpanded under the control of @code{foreach};
     7504actual function call to be re-expanded under the control of @code{foreach};
    72067505a simply-expanded variable would not do, since @code{wildcard} would be
    72077506called only once at the time of defining @code{find_files}.
     
    72217520
    72227521@smallexample
    7223 files := $(foreach Esta escrito en espanol!,b c ch,$(find_files))
     7522files := $(foreach Esta-escrito-en-espanol!,b c ch,$(find_files))
    72247523@end smallexample
    72257524
    72267525@noindent
    72277526might be useful if the value of @code{find_files} references the variable
    7228 whose name is @samp{Esta escrito en espanol!} (es un nombre bastante largo,
     7527whose name is @samp{Esta-escrito-en-espanol!} (es un nombre bastante largo,
    72297528no?), but it is more likely to be a mistake.
    72307529
    7231 @node Call Function, Value Function, Foreach Function, Functions
     7530@node File Function, Call Function, Foreach Function, Functions
     7531@section The @code{file} Function
     7532@findex file
     7533@cindex writing to a file
     7534@cindex file, writing to
     7535@cindex reading from a file
     7536@cindex file, reading from
     7537
     7538The @code{file} function allows the makefile to write to or read from
     7539a file.  Two modes of writing are supported: overwrite, where the text
     7540is written to the beginning of the file and any existing content is
     7541lost, and append, where the text is written to the end of the file,
     7542preserving the existing content.  In both cases the file is created if
     7543it does not exist.  It is a fatal error if the file cannot be opened
     7544for writing, or if the write operation fails.  The @code{file}
     7545function expands to the empty string when writing to a file.
     7546
     7547When reading from a file, the @code{file} function expands to the
     7548verbatim contents of the file, except that the final newline (if there
     7549is one) will be stripped.  Attempting to read from a non-existent file
     7550expands to the empty string.
     7551
     7552The syntax of the @code{file} function is:
     7553
     7554@example
     7555$(file @var{op} @var{filename}[,@var{text}])
     7556@end example
     7557
     7558When the @code{file} function is evaluated all its arguments are
     7559expanded first, then the file indicated by @var{filename} will be
     7560opened in the mode described by @var{op}.
     7561
     7562The operator @var{op} can be @code{>} to indicate the file will be
     7563overwritten with new content, @code{>>} to indicate the current
     7564contents of the file will be appended to, or @code{<} to indicate the
     7565contents of the file will be read in.  The @var{filename} specifies
     7566the file to be written to or read from.  There may optionally be
     7567whitespace between the operator and the file name.
     7568
     7569When reading files, it is an error to provide a @var{text} value.
     7570
     7571When writing files, @var{text} will be written to the file.  If
     7572@var{text} does not already end in a newline a final newline will be
     7573written (even if @var{text} is the empty string).  If the @var{text}
     7574argument is not given at all, nothing will be written.
     7575
     7576For example, the @code{file} function can be useful if your build
     7577system has a limited command line size and your recipe runs a command
     7578that can accept arguments from a file as well.  Many commands use the
     7579convention that an argument prefixed with an @code{@@} specifies a
     7580file containing more arguments.  Then you might write your recipe in
     7581this way:
     7582
     7583@example
     7584@group
     7585program: $(OBJECTS)
     7586        $(file >$@@.in,$^)
     7587        $(CMD) $(CMDFLAGS) @@$@@.in
     7588        @@rm $@@.in
     7589@end group
     7590@end example
     7591
     7592If the command required each argument to be on a separate line of the
     7593input file, you might write your recipe like this:
     7594
     7595@example
     7596@group
     7597program: $(OBJECTS)
     7598        $(file >$@@.in) $(foreach O,$^,$(file >>$@@.in,$O))
     7599        $(CMD) $(CMDFLAGS) @@$@@.in
     7600        @@rm $@@.in
     7601@end group
     7602@end example
     7603
     7604@node Call Function, Value Function, File Function, Functions
    72327605@section The @code{call} Function
    72337606@findex call
     
    72637636constant.)
    72647637
    7265 If @var{variable} is the name of a builtin function, the builtin function
     7638If @var{variable} is the name of a built-in function, the built-in function
    72667639is always invoked (even if a @code{make} variable by that name also
    72677640exists).
     
    72697642The @code{call} function expands the @var{param} arguments before
    72707643assigning them to temporary variables.  This means that @var{variable}
    7271 values containing references to builtin functions that have special
     7644values containing references to built-in functions that have special
    72727645expansion rules, like @code{foreach} or @code{if}, may not work as you
    72737646expect.
     
    73417714@end example
    73427715
    7343 Note that @var{variable} is the @emph{name} of a variable; not a
     7716Note that @var{variable} is the @emph{name} of a variable, not a
    73447717@emph{reference} to that variable.  Therefore you would not normally
    73457718use a @samp{$} or parentheses when writing it.  (You can, however, use
     
    74527825@end example
    74537826
    7454 Note that @var{variable} is the @emph{name} of a variable to inquire about;
     7827Note that @var{variable} is the @emph{name} of a variable to inquire about,
    74557828not a @emph{reference} to that variable.  Therefore you would not normally
    74567829use a @samp{$} or parentheses when writing it.  (You can, however, use a
     
    75457918@xref{Text Functions, , Functions for String Substitution and Analysis}.
    75467919
    7547 @node Flavor Function, Shell Function, Origin Function, Functions
     7920@node Flavor Function, Make Control Functions, Origin Function, Functions
    75487921@section The @code{flavor} Function
    75497922@findex flavor
     
    75517924@cindex flavor of variable
    75527925
    7553 The @code{flavor} function is unlike most other functions (and like
    7554 @code{origin} function) in that it does not operate on the values of
    7555 variables; it tells you something @emph{about} a variable.
    7556 Specifically, it tells you the flavor of a variable (@pxref{Flavors,
    7557 ,The Two Flavors of Variables}).
     7926The @code{flavor} function, like the @code{origin} function, does not
     7927operate on the values of variables but rather it tells you something
     7928@emph{about} a variable.  Specifically, it tells you the flavor of a
     7929variable (@pxref{Flavors, ,The Two Flavors of Variables}).
    75587930
    75597931The syntax of the @code{flavor} function is:
     
    75637935@end example
    75647936
    7565 Note that @var{variable} is the @emph{name} of a variable to inquire about;
     7937Note that @var{variable} is the @emph{name} of a variable to inquire about,
    75667938not a @emph{reference} to that variable.  Therefore you would not normally
    75677939use a @samp{$} or parentheses when writing it.  (You can, however, use a
     
    75867958@end table
    75877959
    7588 
    7589 @node Shell Function, Make Control Functions, Flavor Function, Functions
    7590 @section The @code{shell} Function
    7591 @findex shell
    7592 @cindex command expansion
    7593 @cindex backquotes
    7594 @cindex shell command, function for
    7595 
    7596 The @code{shell} function is unlike any other function other than the
    7597 @code{wildcard} function
    7598 (@pxref{Wildcard Function, ,The Function @code{wildcard}}) in that it
    7599 communicates with the world outside of @code{make}.
    7600 
    7601 The @code{shell} function performs the same function that backquotes
    7602 (@samp{`}) perform in most shells: it does @dfn{command expansion}.
    7603 This means that it takes as an argument a shell command and evaluates
    7604 to the output of the command.  The only processing @code{make} does on
    7605 the result is to convert each newline (or carriage-return / newline
    7606 pair) to a single space.  If there is a trailing (carriage-return
    7607 and) newline it will simply be removed.@refill
    7608 
    7609 The commands run by calls to the @code{shell} function are run when the
    7610 function calls are expanded (@pxref{Reading Makefiles, , How
    7611 @code{make} Reads a Makefile}).  Because this function involves
    7612 spawning a new shell, you should carefully consider the performance
    7613 implications of using the @code{shell} function within recursively
    7614 expanded variables vs.@: simply expanded variables (@pxref{Flavors, ,The
    7615 Two Flavors of Variables}).
    7616 
    7617 Here are some examples of the use of the @code{shell} function:
    7618 
    7619 @example
    7620 contents := $(shell cat foo)
    7621 @end example
    7622 
    7623 @noindent
    7624 sets @code{contents} to the contents of the file @file{foo}, with a space
    7625 (rather than a newline) separating each line.
    7626 
    7627 @example
    7628 files := $(shell echo *.c)
    7629 @end example
    7630 
    7631 @noindent
    7632 sets @code{files} to the expansion of @samp{*.c}.  Unless @code{make} is
    7633 using a very strange shell, this has the same result as
    7634 @w{@samp{$(wildcard *.c)}} (as long as at least one @samp{.c} file
    7635 exists).@refill
    7636 
    7637 @node Make Control Functions,  , Shell Function, Functions
     7960@node Make Control Functions, Shell Function, Flavor Function, Functions
    76387961@section Functions That Control Make
    76397962@cindex functions, for controlling make
     
    76968019result of the expansion of this function is the empty string.
    76978020@end table
     8021
     8022@node Shell Function, Guile Function, Make Control Functions, Functions
     8023@section The @code{shell} Function
     8024@findex shell
     8025@cindex command expansion
     8026@cindex backquotes
     8027@cindex shell command, function for
     8028
     8029The @code{shell} function is unlike any other function other than the
     8030@code{wildcard} function
     8031(@pxref{Wildcard Function, ,The Function @code{wildcard}}) in that it
     8032communicates with the world outside of @code{make}.
     8033
     8034The @code{shell} function performs the same function that backquotes
     8035(@samp{`}) perform in most shells: it does @dfn{command expansion}.
     8036This means that it takes as an argument a shell command and evaluates
     8037to the output of the command.  The only processing @code{make} does on
     8038the result is to convert each newline (or carriage-return / newline
     8039pair) to a single space.  If there is a trailing (carriage-return
     8040and) newline it will simply be removed.@refill
     8041
     8042The commands run by calls to the @code{shell} function are run when the
     8043function calls are expanded (@pxref{Reading Makefiles, , How
     8044@code{make} Reads a Makefile}).  Because this function involves
     8045spawning a new shell, you should carefully consider the performance
     8046implications of using the @code{shell} function within recursively
     8047expanded variables vs.@: simply expanded variables (@pxref{Flavors, ,The
     8048Two Flavors of Variables}).
     8049
     8050@vindex .SHELLSTATUS
     8051After the @code{shell} function or @samp{!=} assignment operator is
     8052used, its exit status is placed in the @code{.SHELLSTATUS} variable.
     8053
     8054Here are some examples of the use of the @code{shell} function:
     8055
     8056@example
     8057contents := $(shell cat foo)
     8058@end example
     8059
     8060@noindent
     8061sets @code{contents} to the contents of the file @file{foo}, with a space
     8062(rather than a newline) separating each line.
     8063
     8064@example
     8065files := $(shell echo *.c)
     8066@end example
     8067
     8068@noindent
     8069sets @code{files} to the expansion of @samp{*.c}.  Unless @code{make} is
     8070using a very strange shell, this has the same result as
     8071@w{@samp{$(wildcard *.c)}} (as long as at least one @samp{.c} file
     8072exists).@refill
     8073
     8074@node Guile Function,  , Shell Function, Functions
     8075@section The @code{guile} Function
     8076@findex guile
     8077@cindex Guile
     8078
     8079If GNU @code{make} is built with support for GNU Guile as an embedded
     8080extension language then the @code{guile} function will be available.
     8081The @code{guile} function takes one argument which is first expanded
     8082by @code{make} in the normal fashion, then passed to the GNU Guile
     8083evaluator.  The result of the evaluator is converted into a string and
     8084used as the expansion of the @code{guile} function in the makefile.
     8085See @ref{Guile Integration, ,GNU Guile Integration} for details on
     8086writing extensions to @code{make} in Guile.
     8087
     8088You can determine whether GNU Guile support is available by checking
     8089the @code{.FEATURES} variable for the word @var{guile}.
    76988090
    76998091@node Running, Implicit Rules, Functions, Top
     
    79198311@cindex @code{-n}
    79208312
    7921 ``No-op''.  The activity is to print what recipe would be used to make
    7922 the targets up to date, but not actually execute it.  Some recipes are
    7923 still executed, even with this flag (@pxref{MAKE Variable, ,How the @code{MAKE} Variable Works}).
     8313``No-op''.  Causes @code{make} to print the recipes that are needed to
     8314make the targets up to date, but not actually execute them.  Note that
     8315some recipes are still executed, even with this flag (@pxref{MAKE
     8316Variable, ,How the @code{MAKE} Variable Works}).  Also any recipes
     8317needed to update included makefiles are still executed
     8318(@pxref{Remaking Makefiles, ,How Makefiles Are Remade}).
    79248319
    79258320@item -t
     
    79308325@cindex @code{-t}
    79318326
    7932 ``Touch''.  The activity is to mark the targets as up to date without
    7933 actually changing them.  In other words, @code{make} pretends to compile
    7934 the targets but does not really change their contents.
     8327``Touch''.  Marks targets as up to date without actually changing
     8328them.  In other words, @code{make} pretends to update the targets but
     8329does not really change their contents; instead only their modified
     8330times are updated.
    79358331
    79368332@item -q
     
    79408336@cindex question mode
    79418337
    7942 ``Question''.  The activity is to find out silently whether the targets
    7943 are up to date already; but execute no recipe in either case.  In other
    7944 words, neither compilation nor output will occur.
     8338``Question''.  Silently check whether the targets are up to date, but
     8339do not execute recipes; the exit code shows whether any updates are
     8340needed.
    79458341
    79468342@item -W @var{file}
     
    81168512define either a recursively-expanded variable or a simply-expanded
    81178513variable.  The examples shown above make a recursively-expanded
    8118 variable; to make a simply-expanded variable, write @samp{:=} instead
    8119 of @samp{=}.  But, unless you want to include a variable reference or
    8120 function call in the @emph{value} that you specify, it makes no
    8121 difference which kind of variable you create.
     8514variable; to make a simply-expanded variable, write @samp{:=} or
     8515@samp{::=} instead of @samp{=}.  But, unless you want to include a
     8516variable reference or function call in the @emph{value} that you
     8517specify, it makes no difference which kind of variable you create.
    81228518
    81238519There is one way that the makefile can change a variable that you have
     
    82438639
    82448640@item j (@i{jobs})
    8245 Prints messages giving details on the invocation of specific subcommands.
     8641Prints messages giving details on the invocation of specific sub-commands.
    82468642
    82478643@item m (@i{makefile})
     
    82508646too.  Note that the @samp{all} option does enable this option.  This
    82518647option also enables @samp{basic} messages.
     8648
     8649@item n (@i{none})
     8650Disable all debugging currently enabled.  If additional debugging
     8651flags are encountered after this they will still take effect.
    82528652@end table
    82538653
     
    83678767are ignored.  @xref{Avoiding Compilation, ,Avoiding Recompilation of
    83688768Some Files}.@refill
     8769
     8770@item -O[@var{type}]
     8771@cindex @code{-O}
     8772@itemx --output-sync[=@var{type}]
     8773@cindex @code{--output-sync}
     8774@cindex output during parallel execution
     8775@cindex parallel execution, output during
     8776Ensure that the complete output from each recipe is printed in one
     8777uninterrupted sequence.  This option is only useful when using the
     8778@code{--jobs} option to run multiple recipes simultaneously
     8779(@pxref{Parallel, ,Parallel Execution})  Without this option output
     8780will be displayed as it is generated by the recipes.@refill
     8781
     8782With no type or the type @samp{target}, output from the entire recipe
     8783of each target is grouped together.  With the type @samp{line}, output
     8784from each line in the recipe is grouped together.  With the type
     8785@samp{recurse}, the output from an entire recursive make is grouped
     8786together.  With the type @samp{none}, no output synchronization is
     8787performed.  @xref{Parallel Output, ,Output During Parallel Execution}.
    83698788
    83708789@item -p
     
    83808799to remake any files, use @w{@samp{make -qp}}.  To print the data base
    83818800of predefined rules and variables, use @w{@samp{make -p -f /dev/null}}.
    8382 The data base output contains filename and linenumber information for
     8801The data base output contains file name and line number information for
    83838802recipe and variable definitions, so it can be a useful debugging tool
    83848803in complex environments.
     
    84558874@code{make}.  @xref{Instead of Execution, ,Instead of Executing Recipes}.
    84568875
     8876@item --trace
     8877@cindex @code{--trace}
     8878Show tracing information for @code{make} execution.  Prints the entire
     8879recipe to be executed, even for recipes that are normally silent (due
     8880to @code{.SILENT} or @samp{@@}).  Also prints the makefile name and
     8881line number where the recipe was defined, and information on why the
     8882target is being rebuilt.
     8883
    84578884@item -v
    84588885@cindex @code{-v}
     
    84738900see @ref{-w Option, ,The @samp{--print-directory} Option}.)
    84748901
    8475 @itemx --no-print-directory
     8902@item --no-print-directory
    84768903@cindex @code{--no-print-directory}
    84778904Disable printing of the working directory under @code{-w}.
     
    85518978* Using Implicit::              How to use an existing implicit rule
    85528979                                  to get the recipes for updating a file.
    8553 * Catalogue of Rules::          A list of built-in implicit rules.
     8980* Catalogue of Rules::          A list of built-in rules.
    85548981* Implicit Variables::          How to change what predefined rules do.
    85558982* Chained Rules::               How to use a chain of implicit rules.
    85568983* Pattern Rules::               How to define new implicit rules.
    8557 * Last Resort::                 How to define recipes for rules which
     8984* Last Resort::                 How to define a recipe for rules which
    85588985                                  cannot find any.
    85598986* Suffix Rules::                The old-fashioned style of implicit rule.
     
    86039030want @code{make} to use, and you know it will choose that one because you
    86049031know which possible prerequisite files are supposed to exist.
    8605 @xref{Catalogue of Rules, ,Catalogue of Implicit Rules},
     9032@xref{Catalogue of Rules, ,Catalogue of Built-In Rules},
    86069033for a catalogue of all the predefined implicit rules.
    86079034
     
    86339060rule to make an object file from a C source file is used instead,
    86349061because it appears before the Pascal rule in the list of predefined
    8635 implicit rules (@pxref{Catalogue of Rules, , Catalogue of Implicit
     9062implicit rules (@pxref{Catalogue of Rules, , Catalogue of Built-In
    86369063Rules}).
    86379064
     
    86419068
    86429069@node Catalogue of Rules, Implicit Variables, Using Implicit, Implicit Rules
    8643 @section Catalogue of Implicit Rules
     9070@section Catalogue of Built-In Rules
    86449071@cindex implicit rule, predefined
    86459072@cindex rule, implicit, predefined
     
    89879414Here is a table of some of the more common variables used as names of
    89889415programs in built-in rules:
    8989 makefiles.
    89909416
    89919417@table @code
     
    91429568@vindex LDFLAGS
    91439569Extra flags to give to compilers when they are supposed to invoke the linker,
    9144 @samp{ld}.
     9570@samp{ld}, such as @code{-L}.  Libraries (@code{-lfoo}) should be
     9571added to the @code{LDLIBS} variable instead.
     9572
     9573@item LDLIBS
     9574@vindex LDLIBS
     9575@vindex LOADLIBES
     9576Library flags or names given to compilers when they are supposed to
     9577invoke the linker, @samp{ld}.  @code{LOADLIBES} is a deprecated (but
     9578still supported) alternative to @code{LDLIBS}.  Non-library linker
     9579flags, such as @code{-L}, should go in the @code{LDFLAGS} variable.
    91459580
    91469581@item LFLAGS
     
    92759710* Pattern Examples::            Examples of pattern rules.
    92769711* Automatic Variables::         How to use automatic variables in the
    9277                                   recipes of implicit rules.
     9712                                  recipe of implicit rules.
    92789713* Pattern Match::               How patterns match.
    92799714* Match-Anything Rules::        Precautions you should take prior to
     
    93759810@noindent
    93769811defines a rule that can make any file @file{@var{x}} whatsoever from a
    9377 corresponding file @file{@var{x},v} in the subdirectory @file{RCS}.  Since
     9812corresponding file @file{@var{x},v} in the sub-directory @file{RCS}.  Since
    93789813the target is @samp{%}, this rule will apply to any file whatever, provided
    93799814the appropriate prerequisite file exists.  The double colon makes the rule
     
    974810183
    974910184If you do not mark the match-anything rule as terminal, then it is
    9750 nonterminal.  A nonterminal match-anything rule cannot apply to a file name
     10185non-terminal.  A non-terminal match-anything rule cannot apply to a file name
    975110186that indicates a specific type of data.  A file name indicates a specific
    975210187type of data if some non-match-anything implicit rule target matches it.
     
    975610191rule is actually applicable (which happens only if there is a file
    975710192@file{foo.y}), the fact that its target matches is enough to prevent
    9758 consideration of any nonterminal match-anything rules for the file
     10193consideration of any non-terminal match-anything rules for the file
    975910194@file{foo.c}.  Thus, @code{make} will not even consider trying to make
    976010195@file{foo.c} as an executable file from @file{foo.c.o}, @file{foo.c.c},
    976110196@file{foo.c.p}, etc.@refill
    976210197
    9763 The motivation for this constraint is that nonterminal match-anything
     10198The motivation for this constraint is that non-terminal match-anything
    976410199rules are used for making files containing specific types of data (such as
    976510200executable files) and a file name with a recognized suffix indicates some
     
    976710202
    976810203Special built-in dummy pattern rules are provided solely to recognize
    9769 certain file names so that nonterminal match-anything rules will not be
     10204certain file names so that non-terminal match-anything rules will not be
    977010205considered.  These dummy rules have no prerequisites and no recipes, and
    977110206they are ignored for all other purposes.  For example, the built-in
     
    998710422@item
    998810423If any rule in that list is @emph{not} a match-anything rule, then
    9989 remove all nonterminal match-anything rules from the list.
     10424remove all non-terminal match-anything rules from the list.
    999010425
    999110426@item
     
    1005610491prerequisites.  @xref{Automatic Variables}.
    1005710492
    10058 @node Archives, Features, Implicit Rules, Top
     10493@node Archives, Extending make, Implicit Rules, Top
    1005910494@chapter Using @code{make} to Update Archive Files
    1006010495@cindex archive
    1006110496
    10062 @dfn{Archive files} are files containing named subfiles called
     10497@dfn{Archive files} are files containing named sub-files called
    1006310498@dfn{members}; they are maintained with the program @code{ar} and their
    1006410499main use is as subroutine libraries for linking.
     
    1028310718@w{%.@var{x}}} and @samp{@w{%.a}: @w{%.@var{x}}}.@refill
    1028410719
    10285 @node Features, Missing, Archives, Top
     10720@node Extending make, Integrating make, Archives, Top
     10721@chapter Extending GNU @code{make}
     10722@cindex make extensions
     10723
     10724GNU @code{make} provides many advanced capabilities, including many
     10725useful functions.  However, it does not contain a complete programming
     10726language and so it has limitations.  Sometimes these limitations can be
     10727overcome through use of the @code{shell} function to invoke a separate
     10728program, although this can be inefficient.
     10729
     10730In cases where the built-in capabilities of GNU @code{make} are
     10731insufficient to your requirements there are two options for extending
     10732@code{make}.  On systems where it's provided, you can utilize GNU
     10733Guile as an embedded scripting language (@pxref{Guile Integration,,GNU
     10734Guile Integration}).  On systems which support dynamically loadable
     10735objects, you can write your own extension in any language (which can
     10736be compiled into such an object) and load it to provide extended
     10737capabilities (@pxref{load Directive, ,The @code{load} Directive}).
     10738
     10739@menu
     10740* Guile Integration::           Using Guile as an embedded scripting language.
     10741* Loading Objects::             Loading dynamic objects as extensions.
     10742@end menu
     10743
     10744@node Guile Integration, Loading Objects, Extending make, Extending make
     10745@section GNU Guile Integration
     10746@cindex Guile
     10747@cindex extensions, Guile
     10748
     10749GNU @code{make} may be built with support for GNU Guile as an embedded
     10750extension language.  Guile implements the Scheme language.  A review
     10751of GNU Guile and the Scheme language and its features is beyond the
     10752scope of this manual: see the documentation for GNU Guile and Scheme.
     10753
     10754You can determine if @code{make} contains support for Guile by
     10755examining the @code{.FEATURES} variable; it will contain the word
     10756@var{guile} if Guile support is available.
     10757
     10758The Guile integration provides one new @code{make} function: @code{guile}.
     10759The @code{guile} function takes one argument which is first expanded
     10760by @code{make} in the normal fashion, then passed to the GNU Guile
     10761evaluator.  The result of the evaluator is converted into a string and
     10762used as the expansion of the @code{guile} function in the makefile.
     10763
     10764In addition, GNU @code{make} exposes Guile procedures for use in Guile
     10765scripts.
     10766
     10767@menu
     10768* Guile Types::                 Converting Guile types to @code{make} strings.
     10769* Guile Interface::             Invoking @code{make} functions from Guile.
     10770* Guile Example::               Example using Guile in @code{make}.
     10771@end menu
     10772
     10773@node Guile Types, Guile Interface, Guile Integration, Guile Integration
     10774@subsection Conversion of Guile Types
     10775@cindex convert guile types
     10776@cindex guile, conversion of types
     10777@cindex types, conversion of
     10778
     10779There is only one ``data type'' in @code{make}: a string.  GNU Guile,
     10780on the other hand, provides a rich variety of different data types.
     10781An important aspect of the interface between @code{make} and GNU Guile
     10782is the conversion of Guile data types into @code{make} strings.
     10783
     10784This conversion is relevant in two places: when a makefile invokes the
     10785@code{guile} function to evaluate a Guile expression, the result of
     10786that evaluation must be converted into a make string so it can be
     10787further evaluated by @code{make}.  And secondly, when a Guile script
     10788invokes one of the procedures exported by @code{make} the argument
     10789provided to the procedure must be converted into a string.
     10790
     10791The conversion of Guile types into @code{make} strings is as below:
     10792
     10793@table @code
     10794@item #f
     10795False is converted into the empty string: in @code{make} conditionals
     10796the empty string is considered false.
     10797
     10798@item #t
     10799True is converted to the string @samp{#t}: in @code{make} conditionals
     10800any non-empty string is considered true.
     10801
     10802@item symbol
     10803@item number
     10804A symbol or number is converted into the string representation of that
     10805symbol or number.
     10806
     10807@item character
     10808A printable character is converted to the same character.
     10809
     10810@item string
     10811A string containing only printable characters is converted to the same
     10812string.
     10813
     10814@item list
     10815A list is converted recursively according to the above rules.  This
     10816implies that any structured list will be flattened (that is, a result
     10817of @samp{'(a b (c d) e)} will be converted to the @code{make} string
     10818@samp{a b c d e}).
     10819
     10820@item other
     10821Any other Guile type results in an error.  In future versions of
     10822@code{make}, other Guile types may be converted.
     10823
     10824@end table
     10825
     10826The translation of @samp{#f} (to the empty string) and @samp{#t} (to
     10827the non-empty string @samp{#t}) is designed to allow you to use Guile
     10828boolean results directly as @code{make} boolean conditions.  For
     10829example:
     10830
     10831@example
     10832$(if $(guile (access? "myfile" R_OK)),$(info myfile exists))
     10833@end example
     10834
     10835As a consequence of these conversion rules you must consider the
     10836result of your Guile script, as that result will be converted into a
     10837string and parsed by @code{make}.  If there is no natural result for
     10838the script (that is, the script exists solely for its side-effects),
     10839you should add @samp{#f} as the final expression in order to avoid
     10840syntax errors in your makefile.
     10841
     10842@node Guile Interface, Guile Example, Guile Types, Guile Integration
     10843@subsection Interfaces from Guile to @code{make}
     10844@cindex make interface to guile
     10845@cindex make procedures in guile
     10846
     10847In addition to the @code{guile} function available in makefiles,
     10848@code{make} exposes some procedures for use in your Guile scripts.  At
     10849startup @code{make} creates a new Guile module, @code{gnu make}, and
     10850exports these procedures as public interfaces from that module:
     10851
     10852@table @code
     10853@item gmk-expand
     10854@findex gmk-expand
     10855This procedure takes a single argument which is converted into a
     10856string.  The string is expanded by @code{make} using normal
     10857@code{make} expansion rules.  The result of the expansion is converted
     10858into a Guile string and provided as the result of the procedure.
     10859
     10860@item gmk-eval
     10861@findex gmk-eval
     10862This procedure takes a single argument which is converted into a
     10863string.  The string is evaluated by @code{make} as if it were a
     10864makefile.  This is the same capability available via the @code{eval}
     10865function (@pxref{Eval Function}).  The result of the @code{gmk-eval}
     10866procedure is always the empty string.
     10867
     10868Note that @code{gmk-eval} is not quite the same as using
     10869@code{gmk-expand} with the @code{eval} function: in the latter case
     10870the evaluated string will be expanded @emph{twice}; first by
     10871@code{gmk-expand}, then again by the @code{eval} function.
     10872
     10873@end table
     10874
     10875@node Guile Example,  , Guile Interface, Guile Integration
     10876@subsection Example Using Guile in @code{make}
     10877@cindex Guile example
     10878@cindex example using Guile
     10879
     10880Here is a very simple example using GNU Guile to manage writing to a
     10881file.  These Guile procedures simply open a file, allow writing to the
     10882file (one string per line), and close the file.  Note that because we
     10883cannot store complex values such as Guile ports in @code{make}
     10884variables, we'll keep the port as a global variable in the Guile
     10885interpreter.
     10886
     10887You can create Guile functions easily using @code{define}/@code{endef}
     10888to create a Guile script, then use the @code{guile} function to
     10889internalize it:
     10890
     10891@example
     10892@group
     10893define GUILEIO
     10894;; A simple Guile IO library for GNU make
     10895
     10896(define MKPORT #f)
     10897
     10898(define (mkopen name mode)
     10899  (set! MKPORT (open-file name mode))
     10900  #f)
     10901
     10902(define (mkwrite s)
     10903  (display s MKPORT)
     10904  (newline MKPORT)
     10905  #f)
     10906
     10907(define (mkclose)
     10908  (close-port MKPORT)
     10909  #f)
     10910
     10911#f
     10912endef
     10913
     10914# Internalize the Guile IO functions
     10915$(guile $(GUILEIO))
     10916@end group
     10917@end example
     10918
     10919If you have a significant amount of Guile support code, you might
     10920consider keeping it in a different file (e.g., @file{guileio.scm}) and
     10921then loading it in your makefile using the @code{guile} function:
     10922
     10923@example
     10924$(guile (load "guileio.scm"))
     10925@end example
     10926
     10927An advantage to this method is that when editing @file{guileio.scm},
     10928your editor will understand that this file contains Scheme syntax
     10929rather than makefile syntax.
     10930
     10931Now you can use these Guile functions to create files.  Suppose you
     10932need to operate on a very large list, which cannot fit on the command
     10933line, but the utility you're using accepts the list as input as well:
     10934
     10935@example
     10936@group
     10937prog: $(PREREQS)
     10938        @@$(guile (mkopen "tmp.out" "w")) \
     10939         $(foreach X,$^,$(guile (mkwrite "$(X)"))) \
     10940         $(guile (mkclose))
     10941        $(LINK) < tmp.out
     10942@end group
     10943@end example
     10944
     10945A more comprehensive suite of file manipulation procedures is possible
     10946of course.  You could, for example, maintain multiple output files at
     10947the same time by choosing a symbol for each one and using it as the
     10948key to a hash table, where the value is a port, then returning the
     10949symbol to be stored in a @code{make} variable.
     10950
     10951@node Loading Objects,  , Guile Integration, Extending make
     10952@section Loading Dynamic Objects
     10953@cindex loaded objects
     10954@cindex objects, loaded
     10955@cindex extensions, loading
     10956
     10957@cartouche
     10958@quotation Warning
     10959The @code{load} directive and extension capability is considered a
     10960``technology preview'' in this release of GNU make.  We encourage you
     10961to experiment with this feature and we appreciate any feedback on it.
     10962However we cannot guarantee to maintain backward-compatibility in the
     10963next release.  Consider using GNU Guile instead for extending GNU make
     10964(@pxref{Guile Function, ,The @code{guile} Function}).
     10965@end quotation
     10966@end cartouche
     10967
     10968Many operating systems provide a facility for dynamically loading
     10969compiled objects.  If your system provides this facility, GNU
     10970@code{make} can make use of it to load dynamic objects at runtime,
     10971providing new capabilities which may then be invoked by your makefile.
     10972
     10973The @code{load} directive is used to load a dynamic object.  Once the
     10974object is loaded, a ``setup'' function will be invoked to allow the
     10975object to initialize itself and register new facilities with GNU
     10976@code{make}.  A dynamic object might include new @code{make} functions,
     10977for example, and the ``setup'' function would register them with GNU
     10978@code{make}'s function handling system.
     10979
     10980@menu
     10981* load Directive::              Loading dynamic objects as extensions.
     10982* Remaking Loaded Objects::     How loaded objects get remade.
     10983* Loaded Object API::           Programmatic interface for loaded objects.
     10984* Loaded Object Example::       Example of a loaded object
     10985@end menu
     10986
     10987@node load Directive, Remaking Loaded Objects, Loading Objects, Loading Objects
     10988@subsection The @code{load} Directive
     10989@cindex load directive
     10990@cindex extensions, load directive
     10991
     10992Objects are loaded into GNU @code{make} by placing the @code{load}
     10993directive into your makefile.  The syntax of the @code{load} directive
     10994is as follows:
     10995
     10996@findex load
     10997@example
     10998load @var{object-file} @dots{}
     10999@end example
     11000
     11001or:
     11002
     11003@example
     11004load @var{object-file}(@var{symbol-name}) @dots{}
     11005@end example
     11006
     11007The file @var{object-file} is dynamically loaded by GNU @code{make}.
     11008If @var{object-file} does not include a directory path then it is
     11009first looked for in the current directory.  If it is not found there,
     11010or a directory path is included, then system-specific paths will be
     11011searched.  If the load fails for any reason, @code{make} will print a
     11012message and exit.
     11013
     11014If the load succeeds @code{make} will invoke an initializing function.
     11015
     11016If @var{symbol-name} is provided, it will be used as the name of the
     11017initializing function.
     11018
     11019If no @var{symbol-name} is provided, the initializing function name is
     11020created by taking the base file name of @var{object-file}, up to the
     11021first character which is not a valid symbol name character
     11022(alphanumerics and underscores are valid symbol name characters).  To
     11023this prefix will be appended the suffix @code{_gmk_setup}.
     11024
     11025More than one object file may be loaded with a single @code{load}
     11026directive, and both forms of @code{load} arguments may be used in the
     11027same directive.
     11028
     11029The initializing function will be provided the file name and line
     11030number of the invocation of the @code{load} operation.  It should
     11031return a value of type @code{int}, which must be @code{0} on failure
     11032and non-@code{0} on success.  If the return value is @code{-1}, then
     11033GNU make will @emph{not} attempt to rebuild the object file
     11034(@pxref{Remaking Loaded Objects, ,How Loaded Objects Are Remade}).
     11035
     11036For example:
     11037
     11038@example
     11039load ../mk_funcs.so
     11040@end example
     11041
     11042will load the dynamic object @file{../mk_funcs.so}.  After the object
     11043is loaded, @code{make} will invoke the function (assumed to be defined
     11044by the shared object) @code{mk_funcs_gmk_setup}.
     11045
     11046On the other hand:
     11047
     11048@example
     11049load ../mk_funcs.so(init_mk_func)
     11050@end example
     11051
     11052will load the dynamic object @file{../mk_funcs.so}.  After the object
     11053is loaded, @code{make} will invoke the function @code{init_mk_func}.
     11054
     11055Regardless of how many times an object file appears in a @code{load}
     11056directive, it will only be loaded (and its setup function will only
     11057be invoked) once.
     11058
     11059@vindex .LOADED
     11060After an object has been successfully loaded, its file name is
     11061appended to the @code{.LOADED} variable.
     11062
     11063@findex -load
     11064If you would prefer that failure to load a dynamic object not be
     11065reported as an error, you can use the @code{-load} directive instead
     11066of @code{load}.  GNU @code{make} will not fail and no message will be
     11067generated if an object fails to load.  The failed object is not added
     11068to the @code{.LOADED} variable, which can then be consulted to
     11069determine if the load was successful.
     11070
     11071@node Remaking Loaded Objects, Loaded Object API, load Directive, Loading Objects
     11072@subsection How Loaded Objects Are Remade
     11073@cindex updating loaded objects
     11074@cindex remaking loaded objects
     11075@cindex loaded objects, remaking of
     11076
     11077Loaded objects undergo the same re-make procedure as makefiles
     11078(@pxref{Remaking Makefiles, ,How Makefiles Are Remade}).  If any
     11079loaded object is recreated, then @code{make} will start from scratch
     11080and re-read all the makefiles, and reload the object files again.  It
     11081is not necessary for the loaded object to do anything special to
     11082support this.@refill
     11083
     11084It's up to the makefile author to provide the rules needed for
     11085rebuilding the loaded object.
     11086
     11087@node Loaded Object API, Loaded Object Example, Remaking Loaded Objects, Loading Objects
     11088@subsection Loaded Object Interface
     11089@cindex loaded object API
     11090@cindex interface for loaded objects
     11091
     11092@cartouche
     11093@quotation Warning
     11094For this feature to be useful your extensions will need to invoke
     11095various functions internal to GNU @code{make}.  The programming
     11096interfaces provided in this release should not be considered stable:
     11097functions may be added, removed, or change calling signatures or
     11098implementations in future versions of GNU @code{make}.
     11099@end quotation
     11100@end cartouche
     11101
     11102To be useful, loaded objects must be able to interact with GNU
     11103@code{make}.  This interaction includes both interfaces the loaded
     11104object provides to makefiles and also interfaces @code{make} provides
     11105to the loaded object to manipulate @code{make}'s operation.
     11106
     11107The interface between loaded objects and @code{make} is defined by the
     11108@file{gnumake.h} C header file.  All loaded objects written in C
     11109should include this header file.  Any loaded object not written in C
     11110will need to implement the interface defined in this header file.
     11111
     11112Typically, a loaded object will register one or more new GNU
     11113@code{make} functions using the @code{gmk_add_function} routine from
     11114within its setup function.  The implementations of these @code{make}
     11115functions may make use of the @code{gmk_expand} and @code{gmk_eval}
     11116routines to perform their tasks, then optionally return a string as
     11117the result of the function expansion.
     11118
     11119@subsubheading Loaded Object Licensing
     11120@cindex loaded object licensing
     11121@cindex plugin_is_GPL_compatible
     11122
     11123Every dynamic extension should define the global symbol
     11124@code{plugin_is_GPL_compatible} to assert that it has been licensed
     11125under a GPL-compatible license.  If this symbol does not exist,
     11126@code{make} emits a fatal error and exits when it tries to load your
     11127extension.
     11128
     11129The declared type of the symbol should be @code{int}. It does not need
     11130to be in any allocated section, though.  The code merely asserts that
     11131the symbol exists in the global scope. Something like this is enough:
     11132
     11133@example
     11134int plugin_is_GPL_compatible;
     11135@end example
     11136
     11137@subsubheading Data Structures
     11138
     11139@table @code
     11140@item gmk_floc
     11141This structure represents a filename/location pair.  It is provided
     11142when defining items, so GNU @code{make} can inform the user later
     11143where the definition occurred if necessary.
     11144@end table
     11145
     11146@subsubheading Registering Functions
     11147@findex gmk_add_function
     11148
     11149There is currently one way for makefiles to invoke operations provided
     11150by the loaded object: through the @code{make} function call
     11151interface.  A loaded object can register one or more new functions
     11152which may then be invoked from within the makefile in the same way as
     11153any other function.
     11154
     11155Use @code{gmk_add_function} to create a new @code{make} function.  Its
     11156arguments are as follows:
     11157
     11158@table @code
     11159@item name
     11160The function name.  This is what the makefile should use to invoke the
     11161function.  The name must be between 1 and 255 characters long and it
     11162may only contain alphanumeric, period (@samp{.}), dash (@samp{-}), and
     11163underscore (@samp{_}) characters.  It may not begin with a period.
     11164
     11165@item func_ptr
     11166A pointer to a function that @code{make} will invoke when it expands
     11167the function in a makefile.  This function must be defined by the
     11168loaded object.
     11169
     11170@item min_args
     11171The minimum number of arguments the function will accept.  Must be
     11172between 0 and 255.  GNU @code{make} will check this and fail before
     11173invoking @code{func_ptr} if the function was invoked with too few
     11174arguments.
     11175
     11176@item max_args
     11177The maximum number of arguments the function will accept.  Must be
     11178between 0 and 255.  GNU @code{make} will check this and fail before
     11179invoking @code{func_ptr} if the function was invoked with too few
     11180arguments.  If the value is 0, then any number of arguments is
     11181accepted.  If the value is greater than 0, then it must be greater
     11182than or equal to @code{min_args}.
     11183
     11184@item flags
     11185Flags that specify how this function will operate; the desired flags
     11186should be OR'd together.  If the @code{GMK_FUNC_NOEXPAND} flag is
     11187given then the function arguments will not be expanded before the
     11188function is called; otherwise they will be expanded first.
     11189@end table
     11190
     11191@subsubheading Registered Function Interface
     11192@findex gmk_func_ptr
     11193
     11194A function registered with @code{make} must match the
     11195@code{gmk_func_ptr} type.  It will be invoked with three parameters:
     11196@code{name} (the name of the function), @code{argc} (the number of
     11197arguments to the function), and @code{argv} (an array of pointers to
     11198arguments to the function).  The last pointer (that is,
     11199@code{argv[argc]}) will be null (@code{0}).
     11200
     11201The return value of the function is the result of expanding the
     11202function.  If the function expands to nothing the return value may be
     11203null.  Otherwise, it must be a pointer to a string created with
     11204@code{gmk_alloc}.  Once the function returns, @code{make} owns this
     11205string and will free it when appropriate; it cannot be accessed by the
     11206loaded object.
     11207
     11208@subsubheading GNU @code{make} Facilities
     11209
     11210There are some facilities exported by GNU @code{make} for use by
     11211loaded objects.  Typically these would be run from within the
     11212setup function and/or the functions registered via
     11213@code{gmk_add_function}, to retrieve or modify the data @code{make}
     11214works with.
     11215
     11216@table @code
     11217@item gmk_expand
     11218@findex gmk_expand
     11219This function takes a string and expands it using @code{make}
     11220expansion rules.  The result of the expansion is returned in a
     11221nil-terminated string buffer.  The caller is responsible for calling
     11222@code{gmk_free} with a pointer to the returned buffer when done.
     11223
     11224@item gmk_eval
     11225@findex gmk_eval
     11226This function takes a buffer and evaluates it as a segment of makefile
     11227syntax.  This function can be used to define new variables, new rules,
     11228etc.  It is equivalent to using the @code{eval} @code{make} function.
     11229@end table
     11230
     11231Note that there is a difference between @code{gmk_eval} and calling
     11232@code{gmk_expand} with a string using the @code{eval} function: in
     11233the latter case the string will be expanded @emph{twice}; once by
     11234@code{gmk_expand} and then again by the @code{eval} function.  Using
     11235@code{gmk_eval} the buffer is only expanded once, at most (as it's
     11236read by the @code{make} parser).
     11237
     11238@subsubheading Memory Management
     11239
     11240Some systems allow for different memory management schemes.  Thus you
     11241should never pass memory that you've allocated directly to any
     11242@code{make} function, nor should you attempt to directly free any
     11243memory returned to you by any @code{make} function.  Instead, use the
     11244@code{gmk_alloc} and @code{gmk_free} functions.
     11245
     11246In particular, the string returned to @code{make} by a function
     11247registered using @code{gmk_add_function} @emph{must} be allocated
     11248using @code{gmk_alloc}, and the string returned from the @code{make}
     11249@code{gmk_expand} function @emph{must} be freed (when no longer
     11250needed) using @code{gmk_free}.
     11251
     11252@table @code
     11253@item gmk_alloc
     11254@findex gmk_alloc
     11255Return a pointer to a newly-allocated buffer.  This function will
     11256always return a valid pointer; if not enough memory is available
     11257@code{make} will exit.
     11258
     11259@item gmk_free
     11260@findex gmk_free
     11261Free a buffer returned to you by @code{make}.  Once the
     11262@code{gmk_free} function returns the string will no longer be valid.
     11263@end table
     11264
     11265@node Loaded Object Example,  , Loaded Object API, Loading Objects
     11266@subsection Example Loaded Object
     11267@cindex loaded object example
     11268@cindex example of loaded objects
     11269
     11270Let's suppose we wanted to write a new GNU @code{make} function that
     11271would create a temporary file and return its name.  We would like our
     11272function to take a prefix as an argument.  First we can write the
     11273function in a file @file{mk_temp.c}:
     11274
     11275@example
     11276@group
     11277#include <stdlib.h>
     11278#include <stdlib.h>
     11279#include <stdio.h>
     11280#include <string.h>
     11281#include <unistd.h>
     11282#include <errno.h>
     11283
     11284#include <gnumake.h>
     11285
     11286int plugin_is_GPL_compatible;
     11287
     11288char *
     11289gen_tmpfile(const char *nm, int argc, char **argv)
     11290@{
     11291  int fd;
     11292
     11293  /* Compute the size of the filename and allocate space for it.  */
     11294  int len = strlen (argv[0]) + 6 + 1;
     11295  char *buf = gmk_alloc (len);
     11296
     11297  strcpy (buf, argv[0]);
     11298  strcat (buf, "XXXXXX");
     11299
     11300  fd = mkstemp(buf);
     11301  if (fd >= 0)
     11302    @{
     11303      /* Don't leak the file descriptor.  */
     11304      close (fd);
     11305      return buf;
     11306    @}
     11307
     11308  /* Failure.  */
     11309  fprintf (stderr, "mkstemp(%s) failed: %s\n", buf, strerror (errno));
     11310  gmk_free (buf);
     11311  return NULL;
     11312@}
     11313
     11314int
     11315mk_temp_gmk_setup ()
     11316@{
     11317  /* Register the function with make name "mk-temp".  */
     11318  gmk_add_function ("mk-temp", gen_tmpfile, 1, 1, 1);
     11319  return 1;
     11320@}
     11321@end group
     11322@end example
     11323
     11324Next, we will write a makefile that can build this shared object, load
     11325it, and use it:
     11326
     11327@example
     11328@group
     11329all:
     11330        @@echo Temporary file: $(mk-temp tmpfile.)
     11331
     11332load mk_temp.so
     11333
     11334mk_temp.so: mk_temp.c
     11335        $(CC) -shared -fPIC -o $@ $<
     11336@end group
     11337@end example
     11338
     11339On MS-Windows, due to peculiarities of how shared objects are
     11340produced, the compiler needs to scan the @dfn{import library} produced
     11341when building @code{make}, typically called
     11342@file{libgnumake-@var{version}.dll.a}, where @var{version} is the
     11343version of the load object API.  So the recipe to produce a shared
     11344object will look on Windows like this (assuming the API version is 1):
     11345
     11346@example
     11347@group
     11348mk_temp.dll: mk_temp.c
     11349        $(CC) -shared -o $@ $< -lgnumake-1
     11350@end group
     11351@end example
     11352
     11353Now when you run @code{make} you'll see something like:
     11354
     11355@example
     11356$ make
     11357cc -shared -fPIC -o mk_temp.so mk_temp.c
     11358Temporary filename: tmpfile.A7JEwd
     11359@end example
     11360
     11361@node Integrating make, Features, Extending make, Top
     11362@chapter Integrating GNU @code{make}
     11363@cindex make integration
     11364
     11365GNU @code{make} is often one component in a larger system of tools,
     11366including integrated development environments, compiler toolchains,
     11367and others.  The role of @code{make} is to start commands and
     11368determine whether they succeeded or not: no special integration is
     11369needed to accomplish that.  However, sometimes it is convenient to
     11370bind @code{make} more tightly with other parts of the system, both
     11371higher-level (tools that invoke @code{make}) and lower-level (tools
     11372that @code{make} invokes).
     11373
     11374@menu
     11375* Job Slots::                   Share job slots with GNU @code{make}.
     11376* Terminal Output::             Control output to terminals.
     11377@end menu
     11378
     11379@node Job Slots, Terminal Output, Integrating make, Integrating make
     11380@section Sharing Job Slots with GNU @code{make}
     11381@cindex job slots, sharing
     11382@cindex tools, sharing job slots
     11383
     11384GNU @code{make} has the ability to run multiple recipes in parallel
     11385(@pxref{Parallel, ,Parallel Execution}) and to cap the total number of
     11386parallel jobs even across recursive invocations of @code{make}
     11387(@pxref{Options/Recursion, ,Communicating Options to a
     11388Sub-@code{make}}).  Tools that @code{make} invokes which are also able
     11389to run multiple operations in parallel, either using multiple threads
     11390or multiple processes, can be enhanced to participate in GNU
     11391@code{make}'s job management facility to ensure that the total number
     11392of active threads/processes running on the system does not exceed the
     11393maximum number of slots provided to GNU @code{make}. @refill
     11394
     11395@cindex jobserver
     11396GNU @code{make} uses a method called the ``jobserver'' to control the
     11397number of active jobs across recursive invocations.  The actual
     11398implementation of the jobserver varies across different operating
     11399systems, but some fundamental aspects are always true.
     11400
     11401First, only command lines that @code{make} understands to be recursive
     11402invocations of @code{make} (@pxref{MAKE Variable, ,How the @code{MAKE}
     11403Variable Works}) will have access to the jobserver.  When writing
     11404makefiles you must be sure to mark the command as recursive (most
     11405commonly by prefixing the command line with the @code{+} indicator
     11406(@pxref{Recursion, ,Recursive Use of @code{make}}).
     11407
     11408Second, @code{make} will provide information necessary for accessing
     11409the jobserver through the environment to its children, in the
     11410@code{MAKEFLAGS} environment variable.  Tools which want to
     11411participate in the jobserver protocol will need to parse this
     11412environment variable, as described in subsequent sections.
     11413
     11414Third, every command @code{make} starts has one implicit job slot
     11415reserved for it before it starts.  Any tool which wants to participate
     11416in the jobserver protocol should assume it can always run one job
     11417without having to contact the jobserver at all.
     11418
     11419Finally, it's critical that tools that participate in the jobserver
     11420protocol return the exact number of slots they obtained from the
     11421jobserver back to the jobserver before they exit, even under error
     11422conditions.  Remember that the implicit job slot should @strong{not}
     11423be returned to the jobserver!  Returning too few slots means that
     11424those slots will be lost for the rest of the build process; returning
     11425too many slots means that extra slots will be available.  The
     11426top-level @code{make} command will print an error message at the end
     11427of the build if it detects an incorrect number of slots available in
     11428the jobserver.
     11429
     11430As an example, suppose you are implementing a linker which provides
     11431for multithreaded operation.  You would like to enhance the linker so
     11432that if it is invoked by GNU @code{make} it can participate in the
     11433jobserver protocol to control how many threads are used during link.
     11434First you will need to modify the linker to determine if the
     11435@code{MAKEFLAGS} environment variable is set.  Next you will need to
     11436parse the value of that variable to determine if the jobserver is
     11437available, and how to access it.  If it is available then you can
     11438access it to obtain job slots controlling how much parallelism your
     11439tool can use.  Once done your tool must return those job slots back to
     11440the jobserver.
     11441
     11442@menu
     11443* POSIX Jobserver::             Using the jobserver on POSIX systems.
     11444* Windows Jobserver::           Using the jobserver on Windows systems.
     11445@end menu
     11446
     11447@node POSIX Jobserver, Windows Jobserver, Job Slots, Job Slots
     11448@subsection POSIX Jobserver Interaction
     11449@cindex jobserver on POSIX
     11450
     11451On POSIX systems the jobserver is implemented as a simple UNIX pipe.
     11452The pipe will be pre-loaded with one single-character token for each
     11453available job.  To obtain an extra slot you must read a single
     11454character from the jobserver pipe; to release a slot you must write a
     11455single character back into the jobserver pipe.
     11456
     11457To access the pipe you must parse the @code{MAKEFLAGS} variable and
     11458look for the argument string @code{--jobserver-auth=R,W} where
     11459@samp{R} and @samp{W} are non-negative integers representing file
     11460descriptors: @samp{R} is the read file descriptor and @samp{W} is the
     11461write file descriptor.
     11462
     11463It's important that when you release the job slot, you write back the
     11464same character you read from the pipe for that slot.  Don't assume
     11465that all tokens are the same character; different characters may have
     11466different meanings to GNU @code{make}.  The order is not important,
     11467since @code{make} has no idea in what order jobs will complete anyway.
     11468
     11469There are various error conditions you must consider to ensure your
     11470implementation is robust:
     11471
     11472@itemize @bullet
     11473@item
     11474Usually you will have a command-line argument controlling the parallel
     11475operation of your tool.  Consider whether your tool should detect
     11476situations where both the jobserver and the command-line argument are
     11477specified, and how it should react.
     11478
     11479@item
     11480If your tool determines that the @code{--jobserver-auth} option is
     11481available in @code{MAKEFLAGS} but that the file descriptors specified
     11482are closed, this means that the calling @code{make} process did not
     11483think that your tool was a recursive @code{make} invocation (e.g., the
     11484command line was not prefixed with a @code{+} character).  You should
     11485notify your users of this situation.
     11486
     11487@item
     11488Your tool should also examine the first word of the @code{MAKEFLAGS}
     11489variable and look for the character @code{n}.  If this character is
     11490present then @code{make} was invoked with the @samp{-n} option and
     11491your tool should stop without performing any operations.
     11492
     11493@item
     11494Your tool should be sure to write back the tokens it read, even under
     11495error conditions.  This includes not only errors in your tool but also
     11496outside influences such as interrupts (@code{SIGINT}), etc.  You may
     11497want to install signal handlers to manage this write-back.
     11498@end itemize
     11499
     11500@node Windows Jobserver,  , POSIX Jobserver, Job Slots
     11501@subsection Windows Jobserver Interaction
     11502@cindex jobserver on Windows
     11503
     11504On Windows systems the jobserver is implemented as a named semaphore.
     11505The semaphore will be set with an initial count equal to the number of
     11506available slots; to obtain a slot you must wait on the semaphore (with
     11507or without a timeout).  To release a slot, release the semaphore.
     11508
     11509To access the semaphore you must parse the @code{MAKEFLAGS} variable and
     11510look for the argument string @code{--jobserver-auth=NAME} where
     11511@samp{NAME} is the name of the named semaphore.  Use this name with
     11512@code{OpenSemaphore} to create a handle to the semaphore.
     11513
     11514There are various error conditions you must consider to ensure your
     11515implementation is robust:
     11516
     11517@itemize @bullet
     11518@item
     11519Usually you will have a command-line argument controlling the parallel
     11520operation of your tool.  Consider whether your tool should detect
     11521situations where both the jobserver and the command-line argument are
     11522specified, and how it should react.
     11523
     11524@item
     11525Your tool should be sure to release the semaphore for the tokens it
     11526read, even under error conditions.  This includes not only errors in
     11527your tool but also outside influences such as interrupts
     11528(@code{SIGINT}), etc.  You may want to install signal handlers to
     11529manage this write-back.
     11530@end itemize
     11531
     11532@node Terminal Output,  , Job Slots, Integrating make
     11533@section Synchronized Terminal Output
     11534@cindex parallel output to terminal
     11535@cindex terminal, output to
     11536
     11537Normally GNU @code{make} will invoke all commands with access to the
     11538same standard and error outputs that @code{make} itself was started
     11539with.  A number of tools will detect whether the output is a terminal
     11540or not-a-terminal, and use this information to change the output
     11541style.  For example if the output goes to a terminal the tool may add
     11542control characters that set color, or even change the location of the
     11543cursor.  If the output is not going to a terminal then these special
     11544control characters are not emitted so that they don't corrupt log
     11545files, etc.
     11546
     11547The @code{--output-sync} (@pxref{Parallel Output, ,Output During
     11548Parallel Output}) option will defeat the terminal detection.  When
     11549output synchronization is enabled GNU @code{make} arranges for all
     11550command output to be written to a file, so that its output can be
     11551written as a block without interference from other commands.  This
     11552means that all tools invoked by @code{make} will believe that their
     11553output is not going to be displayed on a terminal, even when it will
     11554be (because @code{make} will display it there after the command is
     11555completed).
     11556
     11557In order to facilitate tools which would like to determine whether or
     11558not their output will be displayed on a terminal, GNU @code{make} will
     11559set the @code{MAKE_TERMOUT} and @code{MAKE_TERMERR} environment
     11560variables before invoking any commands.  Tools which would like to
     11561determine whether standard or error output (respectively) will be
     11562displayed on a terminal can check these environment variables to
     11563determine if they exist and contain a non-empty value.  If so the tool
     11564can assume that the output will (eventually) be displayed on a
     11565terminal.  If the variables are not set or have an empty value, then
     11566the tool should fall back to its normal methods of detecting whether
     11567output is going to a terminal or not.
     11568
     11569The content of the variables can be parsed to determine the type of
     11570terminal which will be used to display the output.
     11571
     11572Similarly, environments which invoke @code{make} and would like to
     11573capture the output and eventually display it on a terminal (or some
     11574display which can interpret terminal control characters) can set these
     11575variables before invoking @code{make}.  GNU @code{make} will not
     11576modify these environment variables if they already exist when it
     11577starts.
     11578
     11579@node Features, Missing, Integrating make, Top
    1028611580@chapter Features of GNU @code{make}
    1028711581@cindex features of GNU @code{make}
     
    1035011644
    1035111645@item
    10352 The arrangement of lines and backslash-newline combinations in
     11646The arrangement of lines and backslash/newline combinations in
    1035311647recipes is retained when the recipes are printed, so they appear as
    1035411648they do in the makefile, except for the stripping of initial
     
    1039311687
    1039411688@item
     11689A number of different build tools that support parallelism also
     11690support collecting output and displaying as a single block.
     11691@xref{Parallel Output, ,Output During Parallel Execution}.
     11692
     11693@item
    1039511694Modified variable references using pattern substitution come from
    1039611695SunOS 4.  @xref{Reference, ,Basics of Variable References}.
     
    1042111720@code{-include} directive.)  The same feature appears with the name
    1042211721@code{sinclude} in SGI @code{make} and perhaps others.
     11722
     11723@item
     11724The @code{!=} shell assignment operator exists in many BSD of
     11725@code{make} and is purposefully implemented here to behave identically
     11726to those implementations.
     11727
     11728@item
     11729Various build management tools are implemented using scripting
     11730languages such as Perl or Python and thus provide a natural embedded
     11731scripting language, similar to GNU @code{make}'s integration of GNU
     11732Guile.
    1042311733@end itemize
    1042411734
     
    1052411834@item
    1052511835Various new built-in implicit rules.
    10526 @xref{Catalogue of Rules, ,Catalogue of Implicit Rules}.
     11836@xref{Catalogue of Rules, ,Catalogue of Built-In Rules}.
    1052711837
    1052811838@item
    10529 The built-in variable @samp{MAKE_VERSION} gives the version number of
    10530 @code{make}.
    10531 @vindex MAKE_VERSION
     11839Load dynamic objects which can modify the behavior of @code{make}.
     11840@xref{Loading Objects, ,Loading Dynamic Objects}.
    1053211841@end itemize
    1053311842
     
    1055011859
    1055111860This feature was not put into GNU @code{make} because of the
    10552 nonmodularity of putting knowledge into @code{make} of the internal
     11861non-modularity of putting knowledge into @code{make} of the internal
    1055311862format of archive file symbol tables.
    1055411863@xref{Archive Symbols, ,Updating Archive Symbol Directories}.
     
    1064811957This appendix summarizes the directives, text manipulation functions,
    1064911958and special variables which GNU @code{make} understands.
    10650 @xref{Special Targets}, @ref{Catalogue of Rules, ,Catalogue of Implicit Rules},
     11959@xref{Special Targets}, @ref{Catalogue of Rules, ,Catalogue of Built-In Rules},
    1065111960and @ref{Options Summary, ,Summary of Options},
    1065211961for other summaries.
     
    1065811967@itemx define @var{variable} =
    1065911968@itemx define @var{variable} :=
     11969@itemx define @var{variable} ::=
    1066011970@itemx define @var{variable} +=
    1066111971@itemx define @var{variable} ?=
     
    1087212182@xref{Eval Function, ,The @code{eval} Function}.
    1087312183
     12184@item $(file @var{op} @var{filename},@var{text})
     12185Expand the arguments, then open the file @var{filename} using mode
     12186@var{op} and write @var{text} to that file.@*
     12187@xref{File Function, ,The @code{file} Function}.
     12188
    1087412189@item $(value @var{var})
    1087512190Evaluates to the contents of the variable @var{var}, with no expansion
     
    1097112286@code{MAKE} Variable Works}.
    1097212287
     12288@item MAKE_VERSION
     12289
     12290The built-in variable @samp{MAKE_VERSION} expands to the version
     12291number of the GNU @code{make} program.
     12292@vindex MAKE_VERSION
     12293
     12294@item MAKE_HOST
     12295
     12296The built-in variable @samp{MAKE_HOST} expands to a string
     12297representing the host that GNU @code{make} was built to run on.
     12298@vindex MAKE_HOST
     12299
    1097312300@item MAKELEVEL
    1097412301
     
    1098712314through the environment from its parent.
    1098812315
     12316@item GNUMAKEFLAGS
     12317
     12318Other flags parsed by @code{make}.  You can set this in the environment or
     12319a makefile to set @code{make} command-line flags.  GNU @code{make}
     12320never sets this variable itself.  This variable is only needed if
     12321you'd like to set GNU @code{make}-specific flags in a POSIX-compliant
     12322makefile.  This variable will be seen by GNU @code{make} and ignored
     12323by other @code{make} implementations.  It's not needed if you only use
     12324GNU @code{make}; just use @code{MAKEFLAGS} directly.
     12325@xref{Options/Recursion, ,Communicating Options to a Sub-@code{make}}.
     12326
    1098912327@item MAKECMDGOALS
    1099012328
     
    1099512333@item CURDIR
    1099612334
    10997 Set to the pathname of the current working directory (after all
    10998 @code{-C} options are processed, if any).  Setting this variable has no
    10999 effect on the operation of @code{make}.@*
     12335Set to the absolute pathname of the current working directory (after
     12336all @code{-C} options are processed, if any).  Setting this variable
     12337has no effect on the operation of @code{make}.@*
    1100012338@xref{Recursion, ,Recursive Use of @code{make}}.
    1100112339
     
    1102512363Error messages are all either prefixed with the name of the program
    1102612364(usually @samp{make}), or, if the error is found in a makefile, the name
    11027 of the file and linenumber containing the problem.
     12365of the file and line number containing the problem.
    1102812366
    1102912367In the table below, these common prefixes are left off.
     
    1103912377signal of some type).  @xref{Errors, ,Errors in Recipes}.
    1104012378
    11041 If no @code{***} is attached to the message, then the subprocess failed
     12379If no @code{***} is attached to the message, then the sub-process failed
    1104212380but the rule in the makefile was prefixed with the @code{-} special
    1104312381character, so @code{make} ignored the error.
     
    1107912417If you want that file to be built, you will need to add a rule to your
    1108012418makefile describing how that target can be built.  Other possible
    11081 sources of this problem are typos in the makefile (if that filename is
     12419sources of this problem are typos in the makefile (if that file name is
    1108212420wrong) or a corrupted source tree (if that file is not supposed to be
    1108312421built, but rather only a prerequisite).
     
    1111312451This means you've defined a normal (recursive) @code{make} variable
    1111412452@var{xxx} that, when it's expanded, will refer to itself (@var{xxx}).
    11115 This is not allowed; either use simply-expanded variables (@code{:=}) or
    11116 use the append operator (@code{+=}).  @xref{Using Variables, ,How to Use
    11117 Variables}.
     12453This is not allowed; either use simply-expanded variables (@samp{:=}
     12454or @samp{::=}) or use the append operator (@samp{+=}).  @xref{Using
     12455Variables, ,How to Use Variables}.
    1111812456
    1111912457@item Unterminated variable reference.  Stop.
     
    1113012468@itemx target pattern contains no `%'.  Stop.
    1113112469@itemx mixed implicit and static pattern rules.  Stop.
    11132 These are generated for malformed static pattern rules.  The first means
    11133 there's no pattern in the target section of the rule; the second means
    11134 there are multiple patterns in the target section; the third means
    11135 the target doesn't contain a pattern character (@code{%}); and the
    11136 fourth means that all three parts of the static pattern rule contain
    11137 pattern characters (@code{%})--only the first two parts should.
     12470These are generated for malformed static pattern rules.  The first
     12471means there's no pattern in the target section of the rule; the second
     12472means there are multiple patterns in the target section; the third
     12473means the target doesn't contain a pattern character (@code{%}); and
     12474the fourth means that all three parts of the static pattern rule
     12475contain pattern characters (@code{%})--only the first two parts
     12476should.  If you see these errors and you aren't trying to create a
     12477static pattern rule, check the value of any variables in your target
     12478and prerequisite lists to be sure they do not contain colons.
    1113812479@xref{Static Usage, ,Syntax of Static Pattern Rules}.
    1113912480
     
    1116812509
    1116912510Here is the makefile for the GNU @code{tar} program.  This is a
    11170 moderately complex makefile.
     12511moderately complex makefile.  The first line uses a @code{#!} setting
     12512to allow the makefile to be executed directly.
    1117112513
    1117212514Because it is the first target, the default goal is @samp{all}.  An
     
    1120412546@example
    1120512547@group
     12548#!/usr/bin/make -f
    1120612549# Generated automatically from Makefile.in by configure.
    1120712550# Un*x Makefile for GNU tar program.
Note: See TracChangeset for help on using the changeset viewer.