Major updates in preparation for 3.80.

New version of the manual, put into the doc subdir.
Enhancements: $(eval ...) and $(value ...) functions, various bug
fixes, etc.  See the ChangeLog.
More to come.
This commit is contained in:
Paul Smith 2002-07-08 02:26:47 +00:00
parent 4a07398023
commit 8572d6adf0
26 changed files with 8477 additions and 8949 deletions

6733
ChangeLog

File diff suppressed because it is too large Load Diff

6648
ChangeLog.2 Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
AUTOMAKE_OPTIONS = 1.6 dist-bzip2
ACLOCAL_AMFLAGS = -I config
SUBDIRS = glob config po
SUBDIRS = glob config po doc
bin_PROGRAMS = make
@ -23,10 +23,9 @@ EXTRA_make_SOURCES = remote-stub.c remote-cstms.c
noinst_HEADERS = commands.h dep.h filedef.h job.h make.h rule.h variable.h \
debug.h getopt.h gettext.h
make_LDADD = @LIBOBJS@ @ALLOCA@ $(GLOBLIB) @GETLOADAVG_LIBS@
make_LDADD = @LIBOBJS@ @ALLOCA@ $(GLOBLIB) @GETLOADAVG_LIBS@ @LIBINTL@
man_MANS = make.1
info_TEXINFOS = make.texinfo
DEFS = -DLOCALEDIR=\"$(localedir)\" -DLIBDIR=\"$(libdir)\" -DINCLUDEDIR=\"$(includedir)\" @DEFS@
@ -40,7 +39,7 @@ AM_CPPFLAGS = $(GLOBINC)
EXTRA_DIST = README build.sh.in $(man_MANS)\
README.customs\
make-stds.texi SCOPTIONS SMakefile\
SCOPTIONS SMakefile\
README.Amiga Makefile.ami config.ami make.lnk amiga.c amiga.h\
README.DOS Makefile.DOS configure.bat dosbuild.bat configh.dos\
README.W32 NMakefile config.h.W32 build_w32.bat subproc.bat\
@ -50,6 +49,13 @@ EXTRA_DIST = README build.sh.in $(man_MANS)\
MAKE_HOST = @MAKE_HOST@
# Forward targets
html pdf:
cd doc && $(MAKE) $(AM_MAKEFLAGS) $@
.PHONY: html pdf
# --------------- Internationalization Section
localedir = $(datadir)/locale

18
NEWS
View File

@ -1,6 +1,6 @@
GNU make NEWS -*-indented-text-*-
History of user-visible changes.
21 April 2002
06 July 2002
Copyright (C) 2002 Free Software Foundation, Inc.
See the end for copying conditions.
@ -14,6 +14,22 @@ reports.
Version <next>
* A new function is defined: $(quote ...). The argument to this
function is the _name_ of a variable. The result of the function is
the value of the variable, without having been expanded.
* A new function is defined: $(eval ...). The arguments to this
function should expand to makefile commands, which will then be
evaluated as if they had appeared in the makefile. In combination
with define/endef multiline variable definitions this is an extremely
powerful capability. The $(quote ...) function is also useful here.
* A new built-in variable is defined, $(MAKEFILE_LIST). It contains a
list of each makefile GNU make has read, or started to read, in the
order in which they were encountered. So, the last filename in the
list when a makefile is just being read (before any includes) is the
name of the current makefile.
* The arguments to $(call ...) functions were being stored in $1, $2,
etc. as recursive variables, even though they are fully expanded
before assignment. This means that escaped dollar signs ($$ etc.)

View File

@ -24,7 +24,7 @@ Building From CVS
-----------------
To build GNU make from CVS, you will need Autoconf 2.53 (or better),
Automake 1.6.1 (or better), and Gettext 0.11.1 (or better), and any
Automake 1.6.1 (or better), and Gettext 0.11.3-pre2 (or better), and any
tools that those utilities require (GNU m4, Perl, etc.).
After checking out the code, you will need to perform these steps to get
@ -34,19 +34,11 @@ Hopefully at some point in the (near) future this will all be obsolete
and you can just run "autoreconf" and have it DTRT.
1) $ gettextize --no-changelog
$ mv config/Makefile.am{~,}
$ mv Makefile.am{~,}
$ mv configure.in{~,}
1) $ autopoint
This will instantiate various m4 macros files, etc. in the config
and po directories.
The mv commands are necessary because gettextize doesn't realize
that the things it's adding to those files already exist in it.
Hopefully there will be a better solution for this in upcoming
versions of Gettext.
2) $ aclocal -I config
@ -129,10 +121,7 @@ swift click o' mouse-2 into an xterm. I even grudgingly removed my use
of "advanced shell features" like {}. Go for it!
gettextize --no-changelog
mv config/Makefile.am~ config/Makefile.am
mv Makefile.am~ Makefile.am
mv configure.in~ configure.in
autopoint
aclocal -I config
autoheader
automake --add-missing

View File

@ -1,6 +1,6 @@
# Process this file with autoconf to produce a configure script.
AC_INIT(GNU make,3.79.2a1,bug-make@gnu.org)
AC_INIT(GNU make,3.80rc1,bug-make@gnu.org)
AC_PREREQ(2.53)
@ -31,7 +31,8 @@ AC_ISC_POSIX
AC_MINIX
# Enable gettext, in "external" mode.
# Maintainers: this requires gettext 0.11 or better!
GETTEXT_VERSION=0.11.3-pre2
AM_GNU_GETTEXT([external])
# This test must come as early as possible after the compiler configuration
@ -279,7 +280,7 @@ AC_CACHE_VAL(make_cv_sys_gnu_glob, [
#if !defined _LIBC && defined __GNU_LIBRARY__ && __GNU_LIBRARY__ > 1
# include <gnu-versions.h>
# if _GNU_GLOB_INTERFACE_VERSION == GLOB_INTERFACE_VERSION
# gnu glob
gnu glob
# endif
#endif
], [AC_MSG_RESULT(yes)
@ -354,7 +355,7 @@ esac
# We only generate the build.sh if we have a build.sh.in; we won't have
# one before we've created a distribution.
AC_CONFIG_FILES(Makefile glob/Makefile po/Makefile.in config/Makefile)
AC_CONFIG_FILES(Makefile glob/Makefile po/Makefile.in config/Makefile doc/Makefile)
if test -f $srcdir/build.sh.in; then
AC_CONFIG_FILES(build.sh)

1
dep.h
View File

@ -72,5 +72,6 @@ extern char *dep_name ();
extern struct dep *copy_dep_chain PARAMS ((struct dep *d));
extern struct dep *read_all_makefiles PARAMS ((char **makefiles));
extern int eval_buffer PARAMS ((char *buffer));
extern int update_goal_chain PARAMS ((struct dep *goals, int makefiles));
extern void uniquize_deps PARAMS ((struct dep *));

29
doc/Makefile.am Normal file
View File

@ -0,0 +1,29 @@
## Process this file with automake to create Makefile.in.
## Makefile for GNU make documentation.
## Copyright 2002 Free Software Foundation, Inc.
TEXI2HTML = texi2html
TEXI2HTML_FLAGS = -split_chapter
info_TEXINFOS = make.texi
make_TEXINFOS = fdl.texi make-stds.texi
CLEANFILES = make*.html make*.pdf
## ----------------------------- ##
## Other documentation formats. ##
## ----------------------------- ##
html: make_1.html
make_1.html: $(info_TEXINFOS) $(make_TEXINFOS)
$(TEXI2HTML) $(TEXI2HTML_FLAGS) $(srcdir)/make.texi
pdf: make.pdf
make.pdf: $(info_TEXINFOS) $(make_TEXINFOS)
$(TEXI2DVI) --pdf --batch $(srcdir)/make.texi
.PHONY: html pdf

View File

@ -8,12 +8,12 @@
@c FSF publishers: format makebook.texi instead of using this file directly.
@set RCSID $Id$
@set EDITION 0.55
@set VERSION 3.79
@set UPDATED 04 April 2000
@set UPDATE-MONTH April 2000
@set EDITION 0.60
@set VERSION 3.80
@set UPDATED 08 July 2002
@set UPDATE-MONTH July 2002
@comment The ISBN number might need to change on next publication.
@set ISBN 1-882114-80-9 @c CHANGE THIS BEFORE PRINTING AGAIN! --psmith 16jul98
@set ISBN 1-882114-81-7 @c From Brian Youmans <3diff@gnu.org>, 25 Apr 2000
@c finalout
@ -38,29 +38,15 @@ and issues the commands to recompile them.
This is Edition @value{EDITION}, last updated @value{UPDATED},
of @cite{The GNU Make Manual}, for @code{make}, Version @value{VERSION}.
Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95, '96, '97, '98, '99, 2000
Free Software Foundation, Inc.
Copyright 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002
Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
@ignore
Permission is granted to process this file through TeX and print the
results, provided the printed document carries copying permission
notice identical to this one except for the removal of this paragraph
(this paragraph not being relevant to the printed manual).
@end ignore
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@end ifinfo
@iftex
@ -71,11 +57,11 @@ by the Free Software Foundation.
@subtitle A Program for Directing Recompilation
@subtitle GNU @code{make} Version @value{VERSION}
@subtitle @value{UPDATE-MONTH}
@author Richard M. Stallman and Roland McGrath
@author Richard M. Stallman, Roland McGrath, Paul Smith
@page
@vskip 0pt plus 1filll
Copyright @copyright{} 1988, '89, '90, '91, '92, '93, '94, '95, '96, '97, '98, '99, 2000
Free Software Foundation, Inc.
Copyright @copyright{} 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
1996, 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
@sp 2
Published by the Free Software Foundation @*
59 Temple Place -- Suite 330, @*
@ -84,26 +70,19 @@ ISBN @value{ISBN} @*
Maintenance and updates since Version 3.76 by Paul D. Smith.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions,
except that this permission notice may be stated in a translation approved
by the Free Software Foundation.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.1 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled
``GNU Free Documentation License''.
@sp 2
Cover art by Etienne Suvasa.
@end titlepage
@page
@ifinfo
@node Top, Overview, , (dir)
@node Top, Overview, (dir), (dir)
@top Make
The GNU @code{make} utility automatically determines which pieces of a
@ -125,22 +104,26 @@ This manual describes @code{make} and contains the following chapters:@refill
* Commands:: Commands say how to remake a file.
* Using Variables:: You can use variables to avoid repetition.
* Conditionals:: Use or ignore parts of the makefile based
on the values of variables.
on the values of variables.
* Functions:: Many powerful ways to manipulate text.
* Invoking make: Running. How to invoke @code{make} on the command line.
* Implicit Rules:: Use implicit rules to treat many files alike,
based on their file names.
based on their file names.
* Archives:: How @code{make} can update library archives.
* Features:: Features GNU @code{make} has over other @code{make}s.
* Missing:: What GNU @code{make} lacks from other @code{make}s.
* Makefile Conventions:: Conventions for makefiles in GNU programs.
* Makefile Conventions:: Conventions for writing makefiles for
GNU programs.
* Quick Reference:: A quick reference for experienced users.
* Error Messages:: A list of common errors generated by @code{make}.
* Complex Makefile:: A real example of a straightforward,
but nontrivial, makefile.
but nontrivial, makefile.
* GNU Free Documentation License:: License for copying this manual
* Concept Index:: Index of Concepts
* Name Index:: Index of Functions, Variables, & Directives
@detailmenu
--- The Detailed Node Listing ---
Overview of @code{make}
@ -165,9 +148,10 @@ Writing Makefiles
* Makefile Names:: How to name your makefile.
* Include:: How one makefile can use another makefile.
* MAKEFILES Variable:: The environment can specify extra makefiles.
* MAKEFILE_LIST Variable:: Discover which makefiles have been read.
* Remaking Makefiles:: How makefiles get remade.
* Overriding Makefiles:: How to override part of one makefile
with another makefile.
with another makefile.
* Reading Makefiles:: How makefiles are parsed.
Writing Rules
@ -191,7 +175,7 @@ Writing Rules
* Double-Colon:: How to use a special kind of rule to allow
several independent rules for one target.
* Automatic Prerequisites:: How to automatically generate rules giving
prerequisites from source files themselves.
prerequisites from source files themselves.
Using Wildcard Characters in File Names
@ -234,7 +218,7 @@ Recursive Use of @code{make}
* Variables/Recursion:: How to communicate variables to a sub-@code{make}.
* Options/Recursion:: How to communicate options to a sub-@code{make}.
* -w Option:: How the @samp{-w} or @samp{--print-directory} option
helps debug use of recursive @code{make} commands.
helps debug use of recursive @code{make} commands.
How to Use Variables
@ -250,8 +234,10 @@ How to Use Variables
* Defining:: An alternate way to set a variable
to a verbatim string.
* Environment:: Variable values can come from the environment.
* Automatic:: Some special variables have predefined
meanings for use with implicit rules.
* Target-specific:: Variable values can be defined on a per-target
basis.
* Pattern-specific:: Target-specific variable values can be applied
to a group of targets that match a pattern.
Advanced Features for Reference to Variables
@ -271,9 +257,13 @@ Functions for Transforming Text
* Text Functions:: General-purpose text manipulation functions.
* File Name Functions:: Functions for manipulating file names.
* Foreach Function:: Repeat some text with controlled variation.
* If Function:: Conditionally expand a value.
* Call Function:: Expand a user-defined function.
* Value Function:: Return the un-expanded value of a variable.
* Eval Function:: Evaluate the arguments as makefile syntax.
* Origin Function:: Find where a variable got its value.
* Shell Function:: Substitute the output of a shell command.
* Make Control Functions:: Functions that control how make runs.
How to Run @code{make}
@ -328,6 +318,19 @@ Using @code{make} to Update Archive Files
Implicit Rule for Archive Member Targets
* Archive Symbols:: How to update archive symbol directories.
Makefile Conventions
* Makefile Basics:: General Conventions for Makefiles
* Utilities in Makefiles:: Utilities in Makefiles
* Command Variables:: Variables for Specifying Commands
* Directory Variables:: Variables for Installation Directories
* Standard Targets:: Standard Targets for Users
* Install Command Categories:: Three categories of commands in the `install'
Copying This Manual
@end detailmenu
@end menu
@node Overview, Introduction, Top, Top
@ -338,7 +341,7 @@ The @code{make} utility automatically determines which pieces of a large
program need to be recompiled, and issues commands to recompile them.
This manual describes GNU @code{make}, which was implemented by Richard
Stallman and Roland McGrath. Development since Version 3.76 has been
handled by Paul D. Smith.
handled by Paul Smith.
GNU @code{make} conforms to section 6.2 of @cite{IEEE Standard
1003.2-1992} (POSIX.2).
@ -358,7 +361,7 @@ from others whenever the others change.
* Bugs:: Problems and Bugs
@end menu
@node Preparing, Reading, , Overview
@node Preparing, Reading, Overview, Overview
@ifinfo
@heading Preparing and Running Make
@end ifinfo
@ -430,9 +433,12 @@ documentation!
Before reporting a bug or trying to fix it yourself, try to isolate it
to the smallest possible makefile that reproduces the problem. Then
send us the makefile and the exact results @code{make} gave you. Also
say what you expected to occur; this will help us decide whether the
problem was really in the documentation.
send us the makefile and the exact results @code{make} gave you. When
generating this small makefile, be sure to not use any non-free or
unusual tools in your commands: you can almost always emulate what
such a tool would do with simple shell commands. Finally, be sure to
explain what you expected to occur; this will help us decide whether
the problem was really in the documentation.
Once you've got a precise problem, please send electronic mail to:
@ -444,8 +450,7 @@ Once you've got a precise problem, please send electronic mail to:
Please include the version number of @code{make} you are using. You can
get this information with the command @samp{make --version}.
Be sure also to include the type of machine and operating system you are
using. If possible, include the contents of the file @file{config.h}
that is generated by the configuration process.
using.
@node Introduction, Makefiles, Overview, Top
@comment node-name, next, previous, up
@ -483,7 +488,7 @@ together to produce the new executable editor.
* Cleanup:: Rules for Cleaning the Directory
@end menu
@node Rule Introduction, Simple Makefile, , Introduction
@node Rule Introduction, Simple Makefile, Introduction, Introduction
@comment node-name, next, previous, up
@section What a Rule Looks Like
@cindex rule, introduction to
@ -817,7 +822,7 @@ utils.o : defs.h
.PHONY : clean
clean :
-rm edit $(objects)
rm edit $(objects)
@end group
@end example
@ -922,13 +927,14 @@ reading a data base called the @dfn{makefile}.
* Makefile Names:: How to name your makefile.
* Include:: How one makefile can use another makefile.
* MAKEFILES Variable:: The environment can specify extra makefiles.
* MAKEFILE_LIST Variable:: Discover which makefiles have been read.
* Remaking Makefiles:: How makefiles get remade.
* Overriding Makefiles:: How to override part of one makefile
with another makefile.
with another makefile.
* Reading Makefiles:: How makefiles are parsed.
@end menu
@node Makefile Contents, Makefile Names, , Makefiles
@node Makefile Contents, Makefile Names, Makefiles, Makefiles
@section What Makefiles Contain
Makefiles contain five kinds of things: @dfn{explicit rules},
@ -1142,12 +1148,12 @@ directive instead of @code{include}, like this:
-include @var{filenames}@dots{}
@end example
This is acts like @code{include} in every way except that there is no
This acts like @code{include} in every way except that there is no
error (not even a warning) if any of the @var{filenames} do not exist.
For compatibility with some other @code{make} implementations,
@code{sinclude} is another name for @w{@code{-include}}.
@node MAKEFILES Variable, Remaking Makefiles, Include, Makefiles
@node MAKEFILES Variable, MAKEFILE_LIST Variable, Include, Makefiles
@section The Variable @code{MAKEFILES}
@cindex makefile, and @code{MAKEFILES} variable
@cindex including (@code{MAKEFILES} variable)
@ -1177,7 +1183,55 @@ This is a very bad idea, because such makefiles will fail to work if run by
anyone else. It is much better to write explicit @code{include} directives
in the makefiles. @xref{Include, , Including Other Makefiles}.
@node Remaking Makefiles, Overriding Makefiles, MAKEFILES Variable, Makefiles
@node MAKEFILE_LIST Variable, Remaking Makefiles, MAKEFILES Variable, Makefiles
@comment node-name, next, previous, up
@section The Variable @code{MAKEFILE_LIST}
@cindex makefiles, and @code{MAKEFILE_LIST} variable
@cindex including (@code{MAKEFILE_LIST} variable)
As @code{make} reads various makefiles, including any obtained from the
@code{MAKEFILES} variable, the command line, the default files, or
from @code{include} directives, their names will be automatically
appended to the @code{MAKEFILE_LIST} variable. They are added right
before @code{make} begins to parse them.
This means that if the first thing a makefile does is examine the last
word in this variable, it will be the name of the current makefile.
Once the current makefile has used @code{include}, however, the last
word will be the just-included makefile.
If a makefile named @code{Makefile} has this content:
@example
@group
name1 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
include inc.mk
name2 := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
all:
@@echo name1 = $(name1)
@@echo name2 = $(name2)
@end group
@end example
@noindent
then you would expect to see this output:
@example
@group
name1 = Makefile
name2 = inc.mk
@end group
@end example
@xref{Text Functions}, for more information on the @code{word} and
@code{words} functions used above. @xref{Flavors, The Two Flavors of
Variables}, for more information on simply-expanded (@code{:=})
variable definitions.
@node Remaking Makefiles, Overriding Makefiles, MAKEFILE_LIST Variable, Makefiles
@section How Makefiles Are Remade
@cindex updating makefiles
@ -1358,7 +1412,7 @@ For the append operator, @samp{+=}, the right-hand side is considered
immediate if the variable was previously set as a simple variable
(@samp{:=}), and deferred otherwise.
@subheading Conditional Syntax
@subheading Conditional Statements
@cindex ifdef, expansion
@cindex ifeq, expansion
@cindex ifndef, expansion
@ -1440,7 +1494,7 @@ the makefile (often with a target called @samp{all}).
@end menu
@ifinfo
@node Rule Example, Rule Syntax, , Rules
@node Rule Example, Rule Syntax, Rules, Rules
@section Rule Example
Here is an example of a rule:
@ -1584,7 +1638,7 @@ specific file whose name consists of @samp{foo}, an asterisk, and
it does not normally take place.
@end menu
@node Wildcard Examples, Wildcard Pitfall, , Wildcards
@node Wildcard Examples, Wildcard Pitfall, Wildcards, Wildcards
@subsection Wildcard Examples
Wildcards can be used in the commands of a rule, where they are expanded
@ -1780,7 +1834,7 @@ just the search paths.
* Libraries/Search:: Directory search for link libraries.
@end menu
@node General Search, Selective Search, , Directory Search
@node General Search, Selective Search, Directory Search, Directory Search
@subsection @code{VPATH}: Search Path for All Prerequisites
@vindex VPATH
@ -2608,21 +2662,22 @@ mentioned in all the rules are merged into one list of prerequisites for
the target. If the target is older than any prerequisite from any rule,
the commands are executed.
There can only be one set of commands to be executed for a file.
If more than one rule gives commands for the same file,
@code{make} uses the last set given and prints an error message.
(As a special case, if the file's name begins with a dot, no
error message is printed. This odd behavior is only for
compatibility with other implementations of @code{make}.)
There is no reason to
write your makefiles this way; that is why @code{make} gives you
an error message.@refill
There can only be one set of commands to be executed for a file. If
more than one rule gives commands for the same file, @code{make} uses
the last set given and prints an error message. (As a special case,
if the file's name begins with a dot, no error message is printed.
This odd behavior is only for compatibility with other implementations
of @code{make}... you should avoid using it). Occasionally it is
useful to have the same target invoke multiple commands which are
defined in different parts of your makefile; you can use
@dfn{double-colon rules} (@pxref{Double-Colon}) for this.
An extra rule with just prerequisites can be used to give a few extra
prerequisites to many files at once. For example, one usually has a
variable named @code{objects} containing a list of all the compiler output
files in the system being made. An easy way to say that all of them must
be recompiled if @file{config.h} changes is to write the following:
prerequisites to many files at once. For example, makefiles often
have a variable, such as @code{objects}, containing a list of all the
compiler output files in the system being made. An easy way to say
that all of them must be recompiled if @file{config.h} changes is to
write the following:
@example
objects = foo.o bar.o
@ -2674,7 +2729,7 @@ be @emph{analogous}, but not necessarily @emph{identical}.
* Static versus Implicit:: When are they better than implicit rules?
@end menu
@node Static Usage, Static versus Implicit, , Static Pattern
@node Static Usage, Static versus Implicit, Static Pattern, Static Pattern
@subsection Syntax of Static Pattern Rules
@cindex static pattern rule, syntax of
@cindex pattern rules, static, syntax of
@ -2936,19 +2991,18 @@ called @file{@var{name}.d} from a C source file called @file{@var{name}.c}:
@smallexample
@group
%.d: %.c
set -e; $(CC) -M $(CPPFLAGS) $< \
| sed 's/\($*\)\.o[ :]*/\1.o $@@ : /g' > $@@; \
[ -s $@@ ] || rm -f $@@
@set -e; rm -f $@@; \
$(CC) -M $(CPPFLAGS) $< > $@@.$$$$; \
sed 's,\($*\)\.o[ :]*,\1.o $@@ : ,g' < $@@.$$$$ > $@@; \
rm -f $@@.$$$$
@end group
@end smallexample
@noindent
@xref{Pattern Rules}, for information on defining pattern rules. The
@samp{-e} flag to the shell makes it exit immediately if the
@code{$(CC)} command fails (exits with a nonzero status). Normally the
shell exits with the status of the last command in the pipeline
(@code{sed} in this case), so @code{make} would not notice a nonzero
status from the compiler.
@samp{-e} flag to the shell causes it to exit immediately if the
@code{$(CC)} command (or any other command) fails (exits with a
nonzero status).
@cindex @code{-e} (shell flag)
@cindex @code{-MM} (to GNU compiler)
@ -2998,6 +3052,12 @@ information on substitution references.) Since the @samp{.d} files are
makefiles like any others, @code{make} will remake them as necessary
with no further work from you. @xref{Remaking Makefiles}.
Note that the @samp{.d} files contain target definitions; you should
be sure to place the @code{include} directive @emph{after} the first,
default target in your makefiles or run the risk of having a random
object file become the default target.
@xref{How Make Works}.
@node Commands, Using Variables, Rules, Top
@chapter Writing the Commands in Rules
@cindex commands, how to write
@ -3036,7 +3096,7 @@ Text on a line before a @samp{#} is not part of the comment.
* Empty Commands:: Defining useful, do-nothing commands.
@end menu
@node Echoing, Execution, , Commands
@node Echoing, Execution, Commands, Commands
@section Command Echoing
@cindex echoing of commands
@cindex silent operation
@ -3469,10 +3529,10 @@ effect on the operation of @code{make}
* Variables/Recursion:: How to communicate variables to a sub-@code{make}.
* Options/Recursion:: How to communicate options to a sub-@code{make}.
* -w Option:: How the @samp{-w} or @samp{--print-directory} option
helps debug use of recursive @code{make} commands.
helps debug use of recursive @code{make} commands.
@end menu
@node MAKE Variable, Variables/Recursion, , Recursion
@node MAKE Variable, Variables/Recursion, Recursion, Recursion
@subsection How the @code{MAKE} Variable Works
@vindex MAKE
@cindex recursion, and @code{MAKE} variable
@ -4077,11 +4137,9 @@ they have particular specialized uses. @xref{Automatic, ,Automatic Variables}.
basis.
* Pattern-specific:: Target-specific variable values can be applied
to a group of targets that match a pattern.
* Automatic:: Some special variables have predefined
meanings for use with implicit rules.
@end menu
@node Reference, Flavors, , Using Variables
@node Reference, Flavors, Using Variables, Using Variables
@section Basics of Variable References
@cindex variables, how to reference
@cindex reference to variables
@ -4342,7 +4400,7 @@ variables in more flexible ways.
* Computed Names:: Computing the name of the variable to refer to.
@end menu
@node Substitution Refs, Computed Names, , Advanced
@node Substitution Refs, Computed Names, Advanced, Advanced
@subsection Substitution References
@cindex modified variable reference
@cindex substitution variable reference
@ -4886,8 +4944,9 @@ See the next section for information about @code{define}.
Another way to set the value of a variable is to use the @code{define}
directive. This directive has an unusual syntax which allows newline
characters to be included in the value, which is convenient for defining
canned sequences of commands
(@pxref{Sequences, ,Defining Canned Command Sequences}).
both canned sequences of commands
(@pxref{Sequences, ,Defining Canned Command Sequences}), and also
sections of makefile syntax to use with @code{eval} (@pxref{Eval Function}).
The @code{define} directive is followed on the same line by the name of the
variable and nothing more. The value to give the variable appears on the
@ -4899,6 +4958,13 @@ The variable name may contain function and variable references, which
are expanded when the directive is read to find the actual variable name
to use.
You may nest @code{define} directives: @code{make} will keep track of
nested directives and report an error if they are not all properly
closed with @code{endef}. Note that lines beginning with tab
characters are considered part of a command script, so any
@code{define} or @code{endef} strings appearing on such a line will
not be considered @code{make} operators.
@example
define two-lines
echo foo
@ -4912,7 +4978,8 @@ part of the variable's value (except for the final newline which precedes
the @code{endef} and is not considered part of the value).@refill
@need 800
The previous example is functionally equivalent to this:
When used in a command script, the previous example is functionally
equivalent to this:
@example
two-lines = echo foo; echo $(bar)
@ -5106,7 +5173,7 @@ commands at the time of execution.@refill
* Testing Flags:: Conditionals that test flags.
@end menu
@node Conditional Example, Conditional Syntax, , Conditionals
@node Conditional Example, Conditional Syntax, Conditionals, Conditionals
@section Example of a Conditional
The following example of a conditional tells @code{make} to use one set
@ -5388,12 +5455,14 @@ call, just as a variable might be substituted.
* Foreach Function:: Repeat some text with controlled variation.
* If Function:: Conditionally expand a value.
* Call Function:: Expand a user-defined function.
* Value Function:: Return the un-expanded value of a variable.
* Eval Function:: Evaluate the arguments as makefile syntax.
* Origin Function:: Find where a variable got its value.
* Shell Function:: Substitute the output of a shell command.
* Make Control Functions:: Functions that control how make runs.
@end menu
@node Syntax of Functions, Text Functions, , Functions
@node Syntax of Functions, Text Functions, Functions, Functions
@section Function Call Syntax
@cindex @code{$}, in function call
@cindex dollar sign (@code{$}), in function call
@ -5650,11 +5719,6 @@ match any of the @var{pattern} words, removing the words that @emph{do}
match one or more. This is the exact opposite of the @code{filter}
function.@refill
Removes all whitespace-separated words in @var{text} that @emph{do}
match the @var{pattern} words, returning only the words that @emph{do
not} match. This is the exact opposite of the @code{filter}
function.@refill
For example, given:
@example
@ -5692,6 +5756,65 @@ returns the value @samp{bar foo lose}.
@cindex words, removing duplicates
Incidentally, since @code{sort} removes duplicate words, you can use
it for this purpose even if you don't care about the sort order.
@item $(word @var{n},@var{text})
@findex word
@cindex word, selecting a
@cindex selecting a word
Returns the @var{n}th word of @var{text}. The legitimate values of
@var{n} start from 1. If @var{n} is bigger than the number of words
in @var{text}, the value is empty. For example,
@example
$(word 2, foo bar baz)
@end example
@noindent
returns @samp{bar}.
@item $(wordlist @var{s},@var{e},@var{text})
@findex wordlist
@cindex words, selecting lists of
@cindex selecting word lists
Returns the list of words in @var{text} starting with word @var{s} and
ending with word @var{e} (inclusive). The legitimate values of @var{s}
and @var{e} start from 1. If @var{s} is bigger than the number of words
in @var{text}, the value is empty. If @var{e} is bigger than the number
of words in @var{text}, words up to the end of @var{text} are returned.
If @var{s} is greater than @var{e}, nothing is returned. For example,
@example
$(wordlist 2, 3, foo bar baz)
@end example
@noindent
returns @samp{bar baz}.
@c Following item phrased to prevent overfull hbox. --RJC 17 Jul 92
@item $(words @var{text})
@findex words
@cindex words, finding number
Returns the number of words in @var{text}.
Thus, the last word of @var{text} is
@w{@code{$(word $(words @var{text}),@var{text})}}.@refill
@item $(firstword @var{names}@dots{})
@findex firstword
@cindex words, extracting first
The argument @var{names} is regarded as a series of names, separated
by whitespace. The value is the first name in the series. The rest
of the names are ignored.
For example,
@example
$(firstword foo bar)
@end example
@noindent
produces the result @samp{foo}. Although @code{$(firstword
@var{text})} is the same as @code{$(word 1,@var{text})}, the
@code{firstword} function is retained for its simplicity.@refill
@end table
Here is a realistic example of the use of @code{subst} and
@ -5873,65 +5996,6 @@ This function can merge the results of the @code{dir} and
@code{notdir} functions, to produce the original list of files which
was given to those two functions.@refill
@item $(word @var{n},@var{text})
@findex word
@cindex word, selecting a
@cindex selecting a word
Returns the @var{n}th word of @var{text}. The legitimate values of
@var{n} start from 1. If @var{n} is bigger than the number of words
in @var{text}, the value is empty. For example,
@example
$(word 2, foo bar baz)
@end example
@noindent
returns @samp{bar}.
@item $(wordlist @var{s},@var{e},@var{text})
@findex wordlist
@cindex words, selecting lists of
@cindex selecting word lists
Returns the list of words in @var{text} starting with word @var{s} and
ending with word @var{e} (inclusive). The legitimate values of @var{s}
and @var{e} start from 1. If @var{s} is bigger than the number of words
in @var{text}, the value is empty. If @var{e} is bigger than the number
of words in @var{text}, words up to the end of @var{text} are returned.
If @var{s} is greater than @var{e}, nothing is returned. For example,
@example
$(wordlist 2, 3, foo bar baz)
@end example
@noindent
returns @samp{bar baz}.
@c Following item phrased to prevent overfull hbox. --RJC 17 Jul 92
@item $(words @var{text})
@findex words
@cindex words, finding number
Returns the number of words in @var{text}.
Thus, the last word of @var{text} is
@w{@code{$(word $(words @var{text}),@var{text})}}.@refill
@item $(firstword @var{names}@dots{})
@findex firstword
@cindex words, extracting first
The argument @var{names} is regarded as a series of names, separated
by whitespace. The value is the first name in the series. The rest
of the names are ignored.
For example,
@example
$(firstword foo bar)
@end example
@noindent
produces the result @samp{foo}. Although @code{$(firstword
@var{text})} is the same as @code{$(word 1,@var{text})}, the
@code{firstword} function is retained for its simplicity.@refill
@item $(wildcard @var{pattern})
@findex wildcard
@cindex wildcard, function
@ -6064,7 +6128,7 @@ Note that only one of the @var{then-part} or the @var{else-part} will be
evaluated, never both. Thus, either can contain side-effects (such as
@code{shell} function calls, etc.)
@node Call Function, Origin Function, If Function, Functions
@node Call Function, Value Function, If Function, Functions
@section The @code{call} Function
@findex call
@cindex functions, user defined
@ -6157,8 +6221,121 @@ second and subsequent arguments is kept; this can cause strange
effects. It's generally safest to remove all extraneous whitespace when
providing parameters to @code{call}.
@node Value Function, Eval Function, Call Function, Functions
@comment node-name, next, previous, up
@section The @code{value} Function
@findex value
@cindex variables, unexpanded value
@node Origin Function, Shell Function, Call Function, Functions
The @code{value} function provides a way for you to use the value of a
variable @emph{without} having it expanded. Please note that this
does not undo expansions which have already occurred; for example if
you create a simply expanded variable its value is expanded during the
definition; in that case the @code{value} function will return the
same result as using the variable directly.
The syntax of the @code{value} function is:
@example
$(value @var{variable})
@end example
Note that @var{variable} is the @emph{name} of a variable; not a
@emph{reference} to that variable. Therefore you would not normally
use a @samp{$} or parentheses when writing it. (You can, however, use
a variable reference in the name if you want the name not to be a
constant.)
The result of this function is a string containing the value of
@var{variable}, without any expansion occurring. For example, in this
makefile:
@example
@group
FOO = $PATH
all:
@@echo $(FOO)
@@echo $(value FOO)
@end group
@end example
@noindent
The first output line would be @code{ATH}, since the ``$P'' would be
expanded as a @code{make} variable, while the second output line would
be the current value of your @code{$PATH} environment variable, since
the @code{value} function avoided the expansion.
The @code{value} function is most often used in conjunction with the
@code{eval} function (@pxref{Eval Function}).
@node Eval Function, Origin Function, Value Function, Functions
@comment node-name, next, previous, up
@section The @code{eval} Function
@findex eval
@cindex evaluating makefile syntax
@cindex makefile syntax, evaluating
The @code{eval} function is very special: it allows you to define new
makefile constructs that are not constant; which are the result of
evaluating other variables and functions. The argument to the
@code{eval} function is expanded, then the results of that expansion
are parsed as makefile syntax. The expanded results can define new
@code{make} variables, targets, implicit or explicit rules, etc.
The result of the @code{eval} function is always the empty string;
thus, it can be placed virtually anywhere in a makefile without
causing syntax errors.
It's important to realize that the @code{eval} argument is expanded
@emph{twice}; first by the @code{eval} function, then the results of
that expansion are expanded again when they are parsed as makefile
syntax. This means you may need to provide extra levels of escaping
for ``$'' characters when using @code{eval}. The @code{value}
function (@pxref{Value Function}) can sometimes be useful in these
situations, to circumvent unwanted expansions.
Here is an example of how @code{eval} can be used; this example
combines a number of concepts and other functions. Although it might
seem overly complex to use @code{eval} in this example, rather than
just writing out the rules, consider two things: first, the template
definition (in @code{PROGRAM_template}) could need to be much more
complex than it is here; and second, you might put the complex,
``generic'' part of this example into another makefile, then include
it in all the individual makefiles. Now your individual makefiles are
quite straightforward.
@example
@group
PROGRAMS = server client
server_OBJS = server.o server_priv.o server_access.o
server_LIBS = priv protocol
client_OBJS = client.o client_api.o client_mem.o
client_LIBS = protocol
# Everything after this is generic
.PHONY: all
all: $(PROGRAMS)
define PROGRAM_template
$(1): $$($(1)_OBJ) $$($(1)_LIBS:%=-l%)
ALL_OBJS += $$($(1)_OBJS)
endef
$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog))))
$(PROGRAMS):
$(LINK.o) $^ $(LDLIBS) -o $@@
clean:
rm -f $(ALL_OBJS) $(PROGRAMS)
@end group
@end example
@node Origin Function, Shell Function, Eval Function, Functions
@section The @code{origin} Function
@findex origin
@cindex variables, origin of
@ -6412,7 +6589,7 @@ determines that some target is not already up to date.
* Options Summary:: Summary of Options
@end menu
@node Makefile Arguments, Goals, , Running
@node Makefile Arguments, Goals, Running, Running
@section Arguments to Specify the Makefile
@cindex @code{--file}
@cindex @code{--makefile}
@ -6699,7 +6876,8 @@ changing its last-modification date. You would follow this procedure:
@enumerate
@item
Use the command @samp{make} to recompile the source files that really
need recompilation.
need recompilation, ensuring that the object files are up-to-date
before you begin.
@item
Make the changes in the header files.
@ -6760,9 +6938,10 @@ CFLAGS=-g
Each time you run @code{make}, you can override this value if you
wish. For example, if you say @samp{make CFLAGS='-g -O'}, each C
compilation will be done with @samp{cc -c -g -O}. (This illustrates
how you can use quoting in the shell to enclose spaces and other
special characters in the value of a variable when you override it.)
compilation will be done with @samp{cc -c -g -O}. (This also
illustrates how you can use quoting in the shell to enclose spaces and
other special characters in the value of a variable when you override
it.)
The variable @code{CFLAGS} is only one of many standard variables that
exist just so that you can change them this way. @xref{Implicit
@ -7188,7 +7367,7 @@ retained for compatibility.
implicit rules.
@end menu
@node Using Implicit, Catalogue of Rules, , Implicit Rules
@node Using Implicit, Catalogue of Rules, Implicit Rules, Implicit Rules
@section Using Implicit Rules
@cindex implicit rule, how to use
@cindex rule, implicit, how to use
@ -7437,11 +7616,11 @@ running Yacc with the command @samp{$(YACC) $(YFLAGS)}.
@cindex Lex, rule to run
@pindex .l
@file{@var{n}.c} is made automatically from @file{@var{n}.l} by
by running Lex. The actual command is @samp{$(LEX) $(LFLAGS)}.
running Lex. The actual command is @samp{$(LEX) $(LFLAGS)}.
@item Lex for Ratfor programs
@file{@var{n}.r} is made automatically from @file{@var{n}.l} by
by running Lex. The actual command is @samp{$(LEX) $(LFLAGS)}.
running Lex. The actual command is @samp{$(LEX) $(LFLAGS)}.
The convention of using the same suffix @samp{.l} for all Lex files
regardless of whether they produce C code or Ratfor code makes it
@ -7885,7 +8064,7 @@ Variables}, and @ref{Functions, ,Functions for Transforming Text}.
* Canceling Rules:: How to override or cancel built-in rules.
@end menu
@node Pattern Intro, Pattern Examples, , Pattern Rules
@node Pattern Intro, Pattern Examples, Pattern Rules, Pattern Rules
@subsection Introduction to Pattern Rules
@cindex pattern rule
@cindex rule, pattern
@ -8603,7 +8782,7 @@ main use is as subroutine libraries for linking.
for updating archives.
@end menu
@node Archive Members, Archive Update, , Archives
@node Archive Members, Archive Update, Archives, Archives
@section Archive Members as Targets
@cindex archive member targets
@ -8655,7 +8834,7 @@ example, @w{@samp{foolib(*.o)}} expands to all existing members of the
@file{foolib} archive whose names end in @samp{.o}; perhaps
@samp{@w{foolib(hack.o)} @w{foolib(kludge.o)}}.
@node Archive Update
@node Archive Update, Archive Pitfalls, Archive Members, Archives
@section Implicit Rule for Archive Member Targets
Recall that a target that looks like @file{@var{a}(@var{m})} stands for the
@ -8708,7 +8887,7 @@ named @file{file.o}. In connection with such usage, the automatic variables
* Archive Symbols:: How to update archive symbol directories.
@end menu
@node Archive Symbols, , , Archive Update
@node Archive Symbols, , Archive Update, Archive Update
@subsection Updating Archive Symbol Directories
@cindex @code{__.SYMDEF}
@cindex updating archive symbol directories
@ -8745,7 +8924,7 @@ files into the archive, as described in the preceding section.
This is not necessary when using the GNU @code{ar} program, which
updates the @file{__.SYMDEF} member automatically.
@node Archive Pitfalls
@node Archive Pitfalls, Archive Suffix Rules, Archive Update, Archives
@section Dangers When Using Archives
@cindex archive, and parallel execution
@cindex parallel execution, and archive update
@ -8762,7 +8941,7 @@ circumvent this problem by serializing all commands that operate on the
same archive file. But for the time being, you must either write your
makefiles to avoid this problem in some other way, or not use @code{-j}.
@node Archive Suffix Rules, , Archive Pitfalls, Archives
@node Archive Suffix Rules, , Archive Pitfalls, Archives
@section Suffix Rules for Archive Files
@cindex suffix rule, for archive
@cindex archive, suffix rule for
@ -9636,11 +9815,14 @@ of its arguments. @xref{Functions, ,Functions for Transforming Text}.
@item missing target pattern. Stop.
@itemx multiple target patterns. Stop.
@itemx target pattern contains no `%'. Stop.
@itemx mixed implicit and static pattern rules. Stop.
These are generated for malformed static pattern rules. The first means
there's no pattern in the target section of the rule, the second means
there are multiple patterns in the target section, and the third means
the target doesn't contain a pattern character (@code{%}). @xref{Static
Usage, ,Syntax of Static Pattern Rules}.
there's no pattern in the target section of the rule; the second means
there are multiple patterns in the target section; the third means
the target doesn't contain a pattern character (@code{%}); and the
fourth means that all three parts of the static pattern rule contain
pattern characters (@code{%})--only the first two parts should.
@xref{Static Usage, ,Syntax of Static Pattern Rules}.
@item warning: -jN forced in submake: disabling jobserver mode.
This warning and the next are generated if @code{make} detects error
@ -9668,7 +9850,7 @@ sequential manner.
@end table
@node Complex Makefile, Concept Index, Error Messages, Top
@node Complex Makefile, GNU Free Documentation License, Error Messages, Top
@appendix Complex Makefile Example
Here is the makefile for the GNU @code{tar} program. This is a
@ -9940,7 +10122,11 @@ tar.zoo: $(SRCS) $(AUX)
@end group
@end example
@node Concept Index, Name Index, Complex Makefile, Top
@raisesections
@include fdl.texi
@lowersections
@node Concept Index, Name Index, GNU Free Documentation License, Top
@unnumbered Index of Concepts
@printindex cp

View File

@ -1140,6 +1140,42 @@ func_wildcard (o, argv, funcname)
return o;
}
/*
$(eval <makefile string>)
Always resolves to the empty string.
Treat the arguments as a segment of makefile, and parse them.
*/
static char *
func_eval (o, argv, funcname)
char *o;
char **argv;
const char *funcname;
{
eval_buffer (argv[0]);
return o;
}
static char *
func_value (o, argv, funcname)
char *o;
char **argv;
const char *funcname;
{
/* Look up the variable. */
struct variable *v = lookup_variable (argv[0], strlen (argv[0]));
/* Copy its value into the output buffer without expanding it. */
if (v)
o = variable_buffer_output (o, v->value, strlen(v->value));
return o;
}
/*
\r is replaced on UNIX as well. Is this desirable?
*/
@ -1618,8 +1654,6 @@ func_not (char* o, char **argv, char *funcname)
#endif
#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
/* Lookup table for builtin functions.
This doesn't have to be sorted; we use a straight lookup. We might gain
@ -1664,6 +1698,8 @@ static struct function_table_entry function_table[] =
{ STRING_SIZE_TUPLE("error"), 0, 1, 1, func_error},
{ STRING_SIZE_TUPLE("warning"), 0, 1, 1, func_error},
{ STRING_SIZE_TUPLE("if"), 2, 3, 0, func_if},
{ STRING_SIZE_TUPLE("value"), 0, 1, 1, func_value},
{ STRING_SIZE_TUPLE("eval"), 0, 1, 1, func_eval},
#ifdef EXPERIMENTAL
{ STRING_SIZE_TUPLE("eq"), 2, 2, 1, func_eq},
{ STRING_SIZE_TUPLE("not"), 0, 1, 1, func_not},

View File

@ -1,396 +0,0 @@
@setfilename gpl.info
@unnumbered GNU GENERAL PUBLIC LICENSE
@center Version 2, June 1991
@display
Copyright @copyright{} 1989, 1991 Free Software Foundation, Inc.
59 Temple Place -- Suite 330, Boston, MA 02111-1307, USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@end display
@unnumberedsec Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software---to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
@iftex
@unnumberedsec TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@end iftex
@ifinfo
@center TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@end ifinfo
@enumerate
@item
This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The ``Program'', below,
refers to any such program or work, and a ``work based on the Program''
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term ``modification''.) Each licensee is addressed as ``you''.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
@item
You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
@item
You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
@enumerate a
@item
You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
@item
You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
@item
If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
@end enumerate
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
@item
You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
@enumerate a
@item
Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
@item
Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
@item
Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
@end enumerate
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
@item
You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
@item
You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
@item
Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
@item
If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
@item
If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
@item
The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and ``any
later version'', you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
@item
If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
@iftex
@heading NO WARRANTY
@end iftex
@ifinfo
@center NO WARRANTY
@end ifinfo
@item
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM ``AS IS'' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
@item
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
@end enumerate
@iftex
@heading END OF TERMS AND CONDITIONS
@end iftex
@ifinfo
@center END OF TERMS AND CONDITIONS
@end ifinfo
@page
@unnumberedsec How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the ``copyright'' line and a pointer to where the full notice is found.
@smallexample
@var{one line to give the program's name and an idea of what it does.}
Copyright (C) 19@var{yy} @var{name of author}
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
@end smallexample
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
@smallexample
Gnomovision version 69, Copyright (C) 19@var{yy} @var{name of author}
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
type `show w'. This is free software, and you are welcome
to redistribute it under certain conditions; type `show c'
for details.
@end smallexample
The hypothetical commands @samp{show w} and @samp{show c} should show
the appropriate parts of the General Public License. Of course, the
commands you use may be called something other than @samp{show w} and
@samp{show c}; they could even be mouse-clicks or menu items---whatever
suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a ``copyright disclaimer'' for the program, if
necessary. Here is a sample; alter the names:
@smallexample
@group
Yoyodyne, Inc., hereby disclaims all copyright
interest in the program `Gnomovision'
(which makes passes at compilers) written
by James Hacker.
@var{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
@end group
@end smallexample
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -100,7 +100,7 @@ pattern_search (file, archive, depth, recursions)
/* List of dependencies found recursively. */
struct file **intermediate_files
= (struct file **) alloca (max_pattern_deps * sizeof (struct file *));
= (struct file **) xmalloc (max_pattern_deps * sizeof (struct file *));
/* List of the patterns used to find intermediate files. */
char **intermediate_patterns
@ -121,8 +121,8 @@ pattern_search (file, archive, depth, recursions)
/* Buffer in which we store all the rules that are possibly applicable. */
struct rule **tryrules
= (struct rule **) alloca (num_pattern_rules * max_pattern_targets
* sizeof (struct rule *));
= (struct rule **) xmalloc (num_pattern_rules * max_pattern_targets
* sizeof (struct rule *));
/* Number of valid elements in TRYRULES. */
unsigned int nrules;
@ -495,7 +495,7 @@ pattern_search (file, archive, depth, recursions)
/* RULE is nil if the loop went all the way
through the list and everything failed. */
if (rule == 0)
return 0;
goto done;
foundrule = i;
@ -624,6 +624,9 @@ pattern_search (file, archive, depth, recursions)
file->also_make = new;
}
done:
free (intermediate_files);
free (tryrules);
return 1;
return rule != 0;
}

47
main.c
View File

@ -904,12 +904,26 @@ int main (int argc, char ** argv)
/* Make sure stdout is line-buffered. */
#ifdef HAVE_SETVBUF
# ifndef SETVBUF_REVERSED
setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
_WAIT_NOHANG
# if defined SIGCHLD
(void) bsd_signal (SIGCHLD, SIG_DFL);
# endif
# if defined SIGCLD && SIGCLD != SIGCHLD
(void) bsd_signal (SIGCLD, SIG_DFL);
# endif
#endif
/* Make sure stdout is line-buffered. */
#ifdef HAVE_SETVBUF
# ifdef SETVBUF_REVERSED
setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
# else /* setvbuf not reversed. */
/* Some buggy systems lose if we pass 0 instead of allocating ourselves. */
setvbuf (stdout, _IOLBF, xmalloc (BUFSIZ), BUFSIZ);
setvbuf (stdout, (char *) 0, _IOLBF, BUFSIZ);
# endif /* setvbuf reversed. */
#elif HAVE_SETLINEBUF
setlinebuf (stdout);
@ -2074,6 +2088,7 @@ static void
print_usage (bad)
int bad;
{
extern char *make_host;
register const struct command_switch *cs;
FILE *usageto;
@ -2165,7 +2180,10 @@ print_usage (bad)
buf, gettext (cs->description));
}
fprintf (usageto, _("\nReport bugs to <bug-make@gnu.org>.\n"));
fprintf (usageto, _("\nBuilt for %s"), make_host);
if (remote_description != 0 && *remote_description != '\0')
fprintf (usageto, " (%s)", remote_description);
fprintf (usageto, _("\nReport bugs to <bug-make@gnu.org>\n"));
}
/* Decode switches from ARGC and ARGV.
@ -2697,7 +2715,6 @@ define_makeflags (all, makefile)
static void
print_version ()
{
extern char *make_host;
static int printed_version = 0;
char *precede = print_data_base_flag ? "# " : "";
@ -2706,19 +2723,19 @@ print_version ()
/* Do it only once. */
return;
printf ("%sGNU Make version %s", precede, version_string);
if (remote_description != 0 && *remote_description != '\0')
printf ("-%s", remote_description);
/* Print this untranslated. The coding standards recommend translating the
(C) to the copyright symbol, but this string is going to change every
year, and none of the rest of it should be translated (including the
word "Copyright", so it hardly seems worth it. */
printf (_(", by Richard Stallman and Roland McGrath.\n\
%sBuilt for %s\n\
%sCopyright (C) 2002 Free Software Foundation, Inc.\n\
%sThis is free software; see the source for copying conditions.\n\
printf ("%sGNU Make %s\n\
%sCopyright (C) 2002 Free Software Foundation, Inc.\n",
precede, version_string, precede);
printf (_("%sThis is free software; see the source for copying conditions.\n\
%sThere is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n\
%sPARTICULAR PURPOSE.\n\n\
%sReport bugs to <bug-make@gnu.org>.\n\n"),
precede, make_host,
precede, precede, precede, precede, precede);
%sPARTICULAR PURPOSE.\n"),
precede, precede, precede);
printed_version = 1;

View File

@ -88,3 +88,105 @@ TARFILE := $(distdir).tar.gz
alpha: $(ALPHA) $(TARFILE)
@rm -f $(ALPHA)/$(TARFILE)
cp -p $(TARFILE) $(ALPHA)
# ----------------------------------------------------------------------
#
# The sections below were stolen from the Makefile.maint used by fileutils,
# sh-utils, textutils, CPPI, Bison, and Autoconf.
## ---------------- ##
## Updating files. ##
## ---------------- ##
WGET = wget --passive-ftp --non-verbose
ftp-gnu = ftp://ftp.gnu.org/gnu
move_if_change = if test -r $(target) && cmp -s $(target).t $(target); then \
echo $(target) is unchanged; rm -f $(target).t; \
else \
mv $(target).t $(target); \
fi
# ------------------- #
# Updating PO files. #
# ------------------- #
po_repo = http://www.iro.umontreal.ca/contrib/po/maint/$(PACKAGE)
.PHONY: do-po-update po-update
do-po-update:
tmppo=/tmp/$(PACKAGE)-$(VERSION)-po &&\
rm -rf $$tmppo && \
mkdir $$tmppo && \
(cd $$tmppo && $(WGET) -r -l1 -nd --no-parent -A '*.po' $(po_repo)) &&\
cp $$tmppo/*.po po
cd po && $(MAKE) update-po
$(MAKE) po-check
po-update:
if test -d "po"; then \
$(MAKE) do-po-update; \
fi
# -------------------------- #
# Updating GNU build tools. #
# -------------------------- #
# The following pseudo table associates a local directory and a URL
# with each of the files that belongs to some other package and is
# regularly updated from the specified URL.
# $(srcdir)/src/ansi2knr.c
wget_files ?= $(srcdir)/config/config.guess $(srcdir)/config/config.sub \
$(srcdir)/doc/texinfo.tex $(srcdir)/doc/make-stds.texi \
$(srcdir)/doc/fdl.texi
wget-targets = $(patsubst %, get-%, $(wget_files))
config.guess-url_prefix = $(ftp-gnu)/config/
config.sub-url_prefix = $(ftp-gnu)/config/
ansi2knr.c-url_prefix = ftp://ftp.cs.wisc.edu/ghost/
texinfo.tex-url_prefix = $(ftp-gnu)/texinfo/
standards.texi-url_prefix = $(ftp-gnu)/GNUinfo/
make-stds.texi-url_prefix = $(ftp-gnu)/GNUinfo/
fdl.texi-url_prefix = $(ftp-gnu)/GNUinfo/
target = $(patsubst get-%,%,$@)
url = $($(notdir $(target))-url_prefix)$(notdir $(target))
.PHONY: $(wget-targets)
$(wget-targets):
@echo $(WGET) $(url) -O $(target) \
&& $(WGET) $(url) -O $(target).t \
&& $(move_if_change)
.PHONY: wget-update
wget-update: $(wget-targets)
# Updating tools via CVS.
cvs_files ?= depcomp missing
cvs-targets = $(patsubst %, get-%, $(cvs_files))
automake_repo = :pserver:anoncvs@anoncvs.cygnus.com:/cvs/automake
.PHONY: $(cvs-targets)
$(cvs-targets):
$(CVS) -d $(automake_repo) co -p automake/lib/$(notdir $(target)) \
>$(target).t \
&& $(move_if_change)
.PHONY: cvs-update
cvs-update: $(cvs-targets)
# --------------------- #
# Updating everything. #
# --------------------- #
.PHONY: update
update: wget-update cvs-update po-update

View File

@ -1,916 +0,0 @@
@comment This file is included by both standards.texi and make.texinfo.
@comment It was broken out of standards.texi on 1/6/93 by roland.
@node Makefile Conventions
@chapter Makefile Conventions
@comment standards.texi does not print an index, but make.texinfo does.
@cindex makefile, conventions for
@cindex conventions for makefiles
@cindex standards for makefiles
This
@ifinfo
node
@end ifinfo
@iftex
@ifset CODESTD
section
@end ifset
@ifclear CODESTD
chapter
@end ifclear
@end iftex
describes conventions for writing the Makefiles for GNU programs.
Using Automake will help you write a Makefile that follows these
conventions.
@menu
* Makefile Basics:: General Conventions for Makefiles
* Utilities in Makefiles:: Utilities in Makefiles
* Command Variables:: Variables for Specifying Commands
* Directory Variables:: Variables for Installation Directories
* Standard Targets:: Standard Targets for Users
* Install Command Categories:: Three categories of commands in the `install'
rule: normal, pre-install and post-install.
@end menu
@node Makefile Basics
@section General Conventions for Makefiles
Every Makefile should contain this line:
@example
SHELL = /bin/sh
@end example
@noindent
to avoid trouble on systems where the @code{SHELL} variable might be
inherited from the environment. (This is never a problem with GNU
@code{make}.)
Different @code{make} programs have incompatible suffix lists and
implicit rules, and this sometimes creates confusion or misbehavior. So
it is a good idea to set the suffix list explicitly using only the
suffixes you need in the particular Makefile, like this:
@example
.SUFFIXES:
.SUFFIXES: .c .o
@end example
@noindent
The first line clears out the suffix list, the second introduces all
suffixes which may be subject to implicit rules in this Makefile.
Don't assume that @file{.} is in the path for command execution. When
you need to run programs that are a part of your package during the
make, please make sure that it uses @file{./} if the program is built as
part of the make or @file{$(srcdir)/} if the file is an unchanging part
of the source code. Without one of these prefixes, the current search
path is used.
The distinction between @file{./} (the @dfn{build directory}) and
@file{$(srcdir)/} (the @dfn{source directory}) is important because
users can build in a separate directory using the @samp{--srcdir} option
to @file{configure}. A rule of the form:
@smallexample
foo.1 : foo.man sedscript
sed -e sedscript foo.man > foo.1
@end smallexample
@noindent
will fail when the build directory is not the source directory, because
@file{foo.man} and @file{sedscript} are in the the source directory.
When using GNU @code{make}, relying on @samp{VPATH} to find the source
file will work in the case where there is a single dependency file,
since the @code{make} automatic variable @samp{$<} will represent the
source file wherever it is. (Many versions of @code{make} set @samp{$<}
only in implicit rules.) A Makefile target like
@smallexample
foo.o : bar.c
$(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
@end smallexample
@noindent
should instead be written as
@smallexample
foo.o : bar.c
$(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@@
@end smallexample
@noindent
in order to allow @samp{VPATH} to work correctly. When the target has
multiple dependencies, using an explicit @samp{$(srcdir)} is the easiest
way to make the rule work well. For example, the target above for
@file{foo.1} is best written as:
@smallexample
foo.1 : foo.man sedscript
sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@
@end smallexample
GNU distributions usually contain some files which are not source
files---for example, Info files, and the output from Autoconf, Automake,
Bison or Flex. Since these files normally appear in the source
directory, they should always appear in the source directory, not in the
build directory. So Makefile rules to update them should put the
updated files in the source directory.
However, if a file does not appear in the distribution, then the
Makefile should not put it in the source directory, because building a
program in ordinary circumstances should not modify the source directory
in any way.
Try to make the build and installation targets, at least (and all their
subtargets) work correctly with a parallel @code{make}.
@node Utilities in Makefiles
@section Utilities in Makefiles
Write the Makefile commands (and any shell scripts, such as
@code{configure}) to run in @code{sh}, not in @code{csh}. Don't use any
special features of @code{ksh} or @code{bash}.
The @code{configure} script and the Makefile rules for building and
installation should not use any utilities directly except these:
@c dd find
@c gunzip gzip md5sum
@c mkfifo mknod tee uname
@example
cat cmp cp diff echo egrep expr false grep install-info
ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
@end example
The compression program @code{gzip} can be used in the @code{dist} rule.
Stick to the generally supported options for these programs. For
example, don't use @samp{mkdir -p}, convenient as it may be, because
most systems don't support it.
It is a good idea to avoid creating symbolic links in makefiles, since a
few systems don't support them.
The Makefile rules for building and installation can also use compilers
and related programs, but should do so via @code{make} variables so that the
user can substitute alternatives. Here are some of the programs we
mean:
@example
ar bison cc flex install ld ldconfig lex
make makeinfo ranlib texi2dvi yacc
@end example
Use the following @code{make} variables to run those programs:
@example
$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
@end example
When you use @code{ranlib} or @code{ldconfig}, you should make sure
nothing bad happens if the system does not have the program in question.
Arrange to ignore an error from that command, and print a message before
the command to tell the user that failure of this command does not mean
a problem. (The Autoconf @samp{AC_PROG_RANLIB} macro can help with
this.)
If you use symbolic links, you should implement a fallback for systems
that don't have symbolic links.
Additional utilities that can be used via Make variables are:
@example
chgrp chmod chown mknod
@end example
It is ok to use other utilities in Makefile portions (or scripts)
intended only for particular systems where you know those utilities
exist.
@node Command Variables
@section Variables for Specifying Commands
Makefiles should provide variables for overriding certain commands, options,
and so on.
In particular, you should run most utility programs via variables.
Thus, if you use Bison, have a variable named @code{BISON} whose default
value is set with @samp{BISON = bison}, and refer to it with
@code{$(BISON)} whenever you need to use Bison.
File management utilities such as @code{ln}, @code{rm}, @code{mv}, and
so on, need not be referred to through variables in this way, since users
don't need to replace them with other programs.
Each program-name variable should come with an options variable that is
used to supply options to the program. Append @samp{FLAGS} to the
program-name variable name to get the options variable name---for
example, @code{BISONFLAGS}. (The names @code{CFLAGS} for the C
compiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, are
exceptions to this rule, but we keep them because they are standard.)
Use @code{CPPFLAGS} in any compilation command that runs the
preprocessor, and use @code{LDFLAGS} in any compilation command that
does linking as well as in any direct use of @code{ld}.
If there are C compiler options that @emph{must} be used for proper
compilation of certain files, do not include them in @code{CFLAGS}.
Users expect to be able to specify @code{CFLAGS} freely themselves.
Instead, arrange to pass the necessary options to the C compiler
independently of @code{CFLAGS}, by writing them explicitly in the
compilation commands or by defining an implicit rule, like this:
@smallexample
CFLAGS = -g
ALL_CFLAGS = -I. $(CFLAGS)
.c.o:
$(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
@end smallexample
Do include the @samp{-g} option in @code{CFLAGS}, because that is not
@emph{required} for proper compilation. You can consider it a default
that is only recommended. If the package is set up so that it is
compiled with GCC by default, then you might as well include @samp{-O}
in the default value of @code{CFLAGS} as well.
Put @code{CFLAGS} last in the compilation command, after other variables
containing compiler options, so the user can use @code{CFLAGS} to
override the others.
@code{CFLAGS} should be used in every invocation of the C compiler,
both those which do compilation and those which do linking.
Every Makefile should define the variable @code{INSTALL}, which is the
basic command for installing a file into the system.
Every Makefile should also define the variables @code{INSTALL_PROGRAM}
and @code{INSTALL_DATA}. (The default for each of these should be
@code{$(INSTALL)}.) Then it should use those variables as the commands
for actual installation, for executables and nonexecutables
respectively. Use these variables as follows:
@example
$(INSTALL_PROGRAM) foo $(bindir)/foo
$(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
@end example
Optionally, you may prepend the value of @code{DESTDIR} to the target
filename. Doing this allows the installer to create a snapshot of the
installation to be copied onto the real target filesystem later. Do not
set the value of @code{DESTDIR} in your Makefile, and do not include it
in any installed files. With support for @code{DESTDIR}, the above
examples become:
@example
$(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
$(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
@end example
@noindent
Always use a file name, not a directory name, as the second argument of
the installation commands. Use a separate command for each file to be
installed.
@node Directory Variables
@section Variables for Installation Directories
Installation directories should always be named by variables, so it is
easy to install in a nonstandard place. The standard names for these
variables are described below. They are based on a standard filesystem
layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and
other modern operating systems.
These two variables set the root for the installation. All the other
installation directories should be subdirectories of one of these two,
and nothing should be directly installed into these two directories.
@table @samp
@item prefix
A prefix used in constructing the default values of the variables listed
below. The default value of @code{prefix} should be @file{/usr/local}.
When building the complete GNU system, the prefix will be empty and
@file{/usr} will be a symbolic link to @file{/}.
(If you are using Autoconf, write it as @samp{@@prefix@@}.)
Running @samp{make install} with a different value of @code{prefix}
from the one used to build the program should @var{not} recompile
the program.
@item exec_prefix
A prefix used in constructing the default values of some of the
variables listed below. The default value of @code{exec_prefix} should
be @code{$(prefix)}.
(If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
Generally, @code{$(exec_prefix)} is used for directories that contain
machine-specific files (such as executables and subroutine libraries),
while @code{$(prefix)} is used directly for other directories.
Running @samp{make install} with a different value of @code{exec_prefix}
from the one used to build the program should @var{not} recompile the
program.
@end table
Executable programs are installed in one of the following directories.
@table @samp
@item bindir
The directory for installing executable programs that users can run.
This should normally be @file{/usr/local/bin}, but write it as
@file{$(exec_prefix)/bin}.
(If you are using Autoconf, write it as @samp{@@bindir@@}.)
@item sbindir
The directory for installing executable programs that can be run from
the shell, but are only generally useful to system administrators. This
should normally be @file{/usr/local/sbin}, but write it as
@file{$(exec_prefix)/sbin}.
(If you are using Autoconf, write it as @samp{@@sbindir@@}.)
@item libexecdir
@comment This paragraph adjusted to avoid overfull hbox --roland 5jul94
The directory for installing executable programs to be run by other
programs rather than by users. This directory should normally be
@file{/usr/local/libexec}, but write it as @file{$(exec_prefix)/libexec}.
(If you are using Autoconf, write it as @samp{@@libexecdir@@}.)
@end table
Data files used by the program during its execution are divided into
categories in two ways.
@itemize @bullet
@item
Some files are normally modified by programs; others are never normally
modified (though users may edit some of these).
@item
Some files are architecture-independent and can be shared by all
machines at a site; some are architecture-dependent and can be shared
only by machines of the same kind and operating system; others may never
be shared between two machines.
@end itemize
This makes for six different possibilities. However, we want to
discourage the use of architecture-dependent files, aside from object
files and libraries. It is much cleaner to make other data files
architecture-independent, and it is generally not hard.
Therefore, here are the variables Makefiles should use to specify
directories:
@table @samp
@item datadir
The directory for installing read-only architecture independent data
files. This should normally be @file{/usr/local/share}, but write it as
@file{$(prefix)/share}.
(If you are using Autoconf, write it as @samp{@@datadir@@}.)
As a special exception, see @file{$(infodir)}
and @file{$(includedir)} below.
@item sysconfdir
The directory for installing read-only data files that pertain to a
single machine--that is to say, files for configuring a host. Mailer
and network configuration files, @file{/etc/passwd}, and so forth belong
here. All the files in this directory should be ordinary ASCII text
files. This directory should normally be @file{/usr/local/etc}, but
write it as @file{$(prefix)/etc}.
(If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
Do not install executables here in this directory (they probably belong
in @file{$(libexecdir)} or @file{$(sbindir)}). Also do not install
files that are modified in the normal course of their use (programs
whose purpose is to change the configuration of the system excluded).
Those probably belong in @file{$(localstatedir)}.
@item sharedstatedir
The directory for installing architecture-independent data files which
the programs modify while they run. This should normally be
@file{/usr/local/com}, but write it as @file{$(prefix)/com}.
(If you are using Autoconf, write it as @samp{@@sharedstatedir@@}.)
@item localstatedir
The directory for installing data files which the programs modify while
they run, and that pertain to one specific machine. Users should never
need to modify files in this directory to configure the package's
operation; put such configuration information in separate files that go
in @file{$(datadir)} or @file{$(sysconfdir)}. @file{$(localstatedir)}
should normally be @file{/usr/local/var}, but write it as
@file{$(prefix)/var}.
(If you are using Autoconf, write it as @samp{@@localstatedir@@}.)
@item libdir
The directory for object files and libraries of object code. Do not
install executables here, they probably ought to go in @file{$(libexecdir)}
instead. The value of @code{libdir} should normally be
@file{/usr/local/lib}, but write it as @file{$(exec_prefix)/lib}.
(If you are using Autoconf, write it as @samp{@@libdir@@}.)
@item infodir
The directory for installing the Info files for this package. By
default, it should be @file{/usr/local/info}, but it should be written
as @file{$(prefix)/info}.
(If you are using Autoconf, write it as @samp{@@infodir@@}.)
@item lispdir
The directory for installing any Emacs Lisp files in this package. By
default, it should be @file{/usr/local/share/emacs/site-lisp}, but it
should be written as @file{$(prefix)/share/emacs/site-lisp}.
If you are using Autoconf, write the default as @samp{@@lispdir@@}.
In order to make @samp{@@lispdir@@} work, you need the following lines
in your @file{configure.in} file:
@example
lispdir='$@{datadir@}/emacs/site-lisp'
AC_SUBST(lispdir)
@end example
@item includedir
@c rewritten to avoid overfull hbox --roland
The directory for installing header files to be included by user
programs with the C @samp{#include} preprocessor directive. This
should normally be @file{/usr/local/include}, but write it as
@file{$(prefix)/include}.
(If you are using Autoconf, write it as @samp{@@includedir@@}.)
Most compilers other than GCC do not look for header files in directory
@file{/usr/local/include}. So installing the header files this way is
only useful with GCC. Sometimes this is not a problem because some
libraries are only really intended to work with GCC. But some libraries
are intended to work with other compilers. They should install their
header files in two places, one specified by @code{includedir} and one
specified by @code{oldincludedir}.
@item oldincludedir
The directory for installing @samp{#include} header files for use with
compilers other than GCC. This should normally be @file{/usr/include}.
(If you are using Autoconf, you can write it as @samp{@@oldincludedir@@}.)
The Makefile commands should check whether the value of
@code{oldincludedir} is empty. If it is, they should not try to use
it; they should cancel the second installation of the header files.
A package should not replace an existing header in this directory unless
the header came from the same package. Thus, if your Foo package
provides a header file @file{foo.h}, then it should install the header
file in the @code{oldincludedir} directory if either (1) there is no
@file{foo.h} there or (2) the @file{foo.h} that exists came from the Foo
package.
To tell whether @file{foo.h} came from the Foo package, put a magic
string in the file---part of a comment---and @code{grep} for that string.
@end table
Unix-style man pages are installed in one of the following:
@table @samp
@item mandir
The top-level directory for installing the man pages (if any) for this
package. It will normally be @file{/usr/local/man}, but you should
write it as @file{$(prefix)/man}.
(If you are using Autoconf, write it as @samp{@@mandir@@}.)
@item man1dir
The directory for installing section 1 man pages. Write it as
@file{$(mandir)/man1}.
@item man2dir
The directory for installing section 2 man pages. Write it as
@file{$(mandir)/man2}
@item @dots{}
@strong{Don't make the primary documentation for any GNU software be a
man page. Write a manual in Texinfo instead. Man pages are just for
the sake of people running GNU software on Unix, which is a secondary
application only.}
@item manext
The file name extension for the installed man page. This should contain
a period followed by the appropriate digit; it should normally be @samp{.1}.
@item man1ext
The file name extension for installed section 1 man pages.
@item man2ext
The file name extension for installed section 2 man pages.
@item @dots{}
Use these names instead of @samp{manext} if the package needs to install man
pages in more than one section of the manual.
@end table
And finally, you should set the following variable:
@table @samp
@item srcdir
The directory for the sources being compiled. The value of this
variable is normally inserted by the @code{configure} shell script.
(If you are using Autconf, use @samp{srcdir = @@srcdir@@}.)
@end table
For example:
@smallexample
@c I have changed some of the comments here slightly to fix an overfull
@c hbox, so the make manual can format correctly. --roland
# Common prefix for installation directories.
# NOTE: This directory must exist when you start the install.
prefix = /usr/local
exec_prefix = $(prefix)
# Where to put the executable for the command `gcc'.
bindir = $(exec_prefix)/bin
# Where to put the directories used by the compiler.
libexecdir = $(exec_prefix)/libexec
# Where to put the Info files.
infodir = $(prefix)/info
@end smallexample
If your program installs a large number of files into one of the
standard user-specified directories, it might be useful to group them
into a subdirectory particular to that program. If you do this, you
should write the @code{install} rule to create these subdirectories.
Do not expect the user to include the subdirectory name in the value of
any of the variables listed above. The idea of having a uniform set of
variable names for installation directories is to enable the user to
specify the exact same values for several different GNU packages. In
order for this to be useful, all the packages must be designed so that
they will work sensibly when the user does so.
@node Standard Targets
@section Standard Targets for Users
All GNU programs should have the following targets in their Makefiles:
@table @samp
@item all
Compile the entire program. This should be the default target. This
target need not rebuild any documentation files; Info files should
normally be included in the distribution, and DVI files should be made
only when explicitly asked for.
By default, the Make rules should compile and link with @samp{-g}, so
that executable programs have debugging symbols. Users who don't mind
being helpless can strip the executables later if they wish.
@item install
Compile the program and copy the executables, libraries, and so on to
the file names where they should reside for actual use. If there is a
simple test to verify that a program is properly installed, this target
should run that test.
Do not strip executables when installing them. Devil-may-care users can
use the @code{install-strip} target to do that.
If possible, write the @code{install} target rule so that it does not
modify anything in the directory where the program was built, provided
@samp{make all} has just been done. This is convenient for building the
program under one user name and installing it under another.
The commands should create all the directories in which files are to be
installed, if they don't already exist. This includes the directories
specified as the values of the variables @code{prefix} and
@code{exec_prefix}, as well as all subdirectories that are needed.
One way to do this is by means of an @code{installdirs} target
as described below.
Use @samp{-} before any command for installing a man page, so that
@code{make} will ignore any errors. This is in case there are systems
that don't have the Unix man page documentation system installed.
The way to install Info files is to copy them into @file{$(infodir)}
with @code{$(INSTALL_DATA)} (@pxref{Command Variables}), and then run
the @code{install-info} program if it is present. @code{install-info}
is a program that edits the Info @file{dir} file to add or update the
menu entry for the given Info file; it is part of the Texinfo package.
Here is a sample rule to install an Info file:
@comment This example has been carefully formatted for the Make manual.
@comment Please do not reformat it without talking to roland@gnu.ai.mit.edu.
@smallexample
$(DESTDIR)$(infodir)/foo.info: foo.info
$(POST_INSTALL)
# There may be a newer info file in . than in srcdir.
-if test -f foo.info; then d=.; \
else d=$(srcdir); fi; \
$(INSTALL_DATA) $$d/foo.info $(DESTDIR)$@@; \
# Run install-info only if it exists.
# Use `if' instead of just prepending `-' to the
# line so we notice real errors from install-info.
# We use `$(SHELL) -c' because some shells do not
# fail gracefully when there is an unknown command.
if $(SHELL) -c 'install-info --version' \
>/dev/null 2>&1; then \
install-info --dir-file=$(DESTDIR)$(infodir)/dir \
$(DESTDIR)$(infodir)/foo.info; \
else true; fi
@end smallexample
When writing the @code{install} target, you must classify all the
commands into three categories: normal ones, @dfn{pre-installation}
commands and @dfn{post-installation} commands. @xref{Install Command
Categories}.
@item uninstall
Delete all the installed files---the copies that the @samp{install}
target creates.
This rule should not modify the directories where compilation is done,
only the directories where files are installed.
The uninstallation commands are divided into three categories, just like
the installation commands. @xref{Install Command Categories}.
@item install-strip
Like @code{install}, but strip the executable files while installing
them. In many cases, the definition of this target can be very simple:
@smallexample
install-strip:
$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
install
@end smallexample
Normally we do not recommend stripping an executable unless you are sure
the program has no bugs. However, it can be reasonable to install a
stripped executable for actual execution while saving the unstripped
executable elsewhere in case there is a bug.
@comment The gratuitous blank line here is to make the table look better
@comment in the printed Make manual. Please leave it in.
@item clean
Delete all files from the current directory that are normally created by
building the program. Don't delete the files that record the
configuration. Also preserve files that could be made by building, but
normally aren't because the distribution comes with them.
Delete @file{.dvi} files here if they are not part of the distribution.
@item distclean
Delete all files from the current directory that are created by
configuring or building the program. If you have unpacked the source
and built the program without creating any other files, @samp{make
distclean} should leave only the files that were in the distribution.
@item mostlyclean
Like @samp{clean}, but may refrain from deleting a few files that people
normally don't want to recompile. For example, the @samp{mostlyclean}
target for GCC does not delete @file{libgcc.a}, because recompiling it
is rarely necessary and takes a lot of time.
@item maintainer-clean
Delete almost everything from the current directory that can be
reconstructed with this Makefile. This typically includes everything
deleted by @code{distclean}, plus more: C source files produced by
Bison, tags tables, Info files, and so on.
The reason we say ``almost everything'' is that running the command
@samp{make maintainer-clean} should not delete @file{configure} even if
@file{configure} can be remade using a rule in the Makefile. More generally,
@samp{make maintainer-clean} should not delete anything that needs to
exist in order to run @file{configure} and then begin to build the
program. This is the only exception; @code{maintainer-clean} should
delete everything else that can be rebuilt.
The @samp{maintainer-clean} target is intended to be used by a maintainer of
the package, not by ordinary users. You may need special tools to
reconstruct some of the files that @samp{make maintainer-clean} deletes.
Since these files are normally included in the distribution, we don't
take care to make them easy to reconstruct. If you find you need to
unpack the full distribution again, don't blame us.
To help make users aware of this, the commands for the special
@code{maintainer-clean} target should start with these two:
@smallexample
@@echo 'This command is intended for maintainers to use; it'
@@echo 'deletes files that may need special tools to rebuild.'
@end smallexample
@item TAGS
Update a tags table for this program.
@c ADR: how?
@item info
Generate any Info files needed. The best way to write the rules is as
follows:
@smallexample
info: foo.info
foo.info: foo.texi chap1.texi chap2.texi
$(MAKEINFO) $(srcdir)/foo.texi
@end smallexample
@noindent
You must define the variable @code{MAKEINFO} in the Makefile. It should
run the @code{makeinfo} program, which is part of the Texinfo
distribution.
Normally a GNU distribution comes with Info files, and that means the
Info files are present in the source directory. Therefore, the Make
rule for an info file should update it in the source directory. When
users build the package, ordinarily Make will not update the Info files
because they will already be up to date.
@item dvi
Generate DVI files for all Texinfo documentation.
For example:
@smallexample
dvi: foo.dvi
foo.dvi: foo.texi chap1.texi chap2.texi
$(TEXI2DVI) $(srcdir)/foo.texi
@end smallexample
@noindent
You must define the variable @code{TEXI2DVI} in the Makefile. It should
run the program @code{texi2dvi}, which is part of the Texinfo
distribution.@footnote{@code{texi2dvi} uses @TeX{} to do the real work
of formatting. @TeX{} is not distributed with Texinfo.} Alternatively,
write just the dependencies, and allow GNU @code{make} to provide the command.
@item dist
Create a distribution tar file for this program. The tar file should be
set up so that the file names in the tar file start with a subdirectory
name which is the name of the package it is a distribution for. This
name can include the version number.
For example, the distribution tar file of GCC version 1.40 unpacks into
a subdirectory named @file{gcc-1.40}.
The easiest way to do this is to create a subdirectory appropriately
named, use @code{ln} or @code{cp} to install the proper files in it, and
then @code{tar} that subdirectory.
Compress the tar file file with @code{gzip}. For example, the actual
distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
The @code{dist} target should explicitly depend on all non-source files
that are in the distribution, to make sure they are up to date in the
distribution.
@ifset CODESTD
@xref{Releases, , Making Releases}.
@end ifset
@ifclear CODESTD
@xref{Releases, , Making Releases, standards, GNU Coding Standards}.
@end ifclear
@item check
Perform self-tests (if any). The user must build the program before
running the tests, but need not install the program; you should write
the self-tests so that they work when the program is built but not
installed.
@end table
The following targets are suggested as conventional names, for programs
in which they are useful.
@table @code
@item installcheck
Perform installation tests (if any). The user must build and install
the program before running the tests. You should not assume that
@file{$(bindir)} is in the search path.
@item installdirs
It's useful to add a target named @samp{installdirs} to create the
directories where files are installed, and their parent directories.
There is a script called @file{mkinstalldirs} which is convenient for
this; you can find it in the Texinfo package.
@c It's in /gd/gnu/lib/mkinstalldirs.
You can use a rule like this:
@comment This has been carefully formatted to look decent in the Make manual.
@comment Please be sure not to make it extend any further to the right.--roland
@smallexample
# Make sure all installation directories (e.g. $(bindir))
# actually exist by making them if necessary.
installdirs: mkinstalldirs
$(srcdir)/mkinstalldirs $(bindir) $(datadir) \
$(libdir) $(infodir) \
$(mandir)
@end smallexample
This rule should not modify the directories where compilation is done.
It should do nothing but create installation directories.
@end table
@node Install Command Categories
@section Install Command Categories
@cindex pre-installation commands
@cindex post-installation commands
When writing the @code{install} target, you must classify all the
commands into three categories: normal ones, @dfn{pre-installation}
commands and @dfn{post-installation} commands.
Normal commands move files into their proper places, and set their
modes. They may not alter any files except the ones that come entirely
from the package they belong to.
Pre-installation and post-installation commands may alter other files;
in particular, they can edit global configuration files or data bases.
Pre-installation commands are typically executed before the normal
commands, and post-installation commands are typically run after the
normal commands.
The most common use for a post-installation command is to run
@code{install-info}. This cannot be done with a normal command, since
it alters a file (the Info directory) which does not come entirely and
solely from the package being installed. It is a post-installation
command because it needs to be done after the normal command which
installs the package's Info files.
Most programs don't need any pre-installation commands, but we have the
feature just in case it is needed.
To classify the commands in the @code{install} rule into these three
categories, insert @dfn{category lines} among them. A category line
specifies the category for the commands that follow.
A category line consists of a tab and a reference to a special Make
variable, plus an optional comment at the end. There are three
variables you can use, one for each category; the variable name
specifies the category. Category lines are no-ops in ordinary execution
because these three Make variables are normally undefined (and you
@emph{should not} define them in the makefile).
Here are the three possible category lines, each with a comment that
explains what it means:
@smallexample
$(PRE_INSTALL) # @r{Pre-install commands follow.}
$(POST_INSTALL) # @r{Post-install commands follow.}
$(NORMAL_INSTALL) # @r{Normal commands follow.}
@end smallexample
If you don't use a category line at the beginning of the @code{install}
rule, all the commands are classified as normal until the first category
line. If you don't use any category lines, all the commands are
classified as normal.
These are the category lines for @code{uninstall}:
@smallexample
$(PRE_UNINSTALL) # @r{Pre-uninstall commands follow.}
$(POST_UNINSTALL) # @r{Post-uninstall commands follow.}
$(NORMAL_UNINSTALL) # @r{Normal commands follow.}
@end smallexample
Typically, a pre-uninstall command would be used for deleting entries
from the Info directory.
If the @code{install} or @code{uninstall} target has any dependencies
which act as subroutines of installation, then you should start
@emph{each} dependency's commands with a category line, and start the
main target's commands with a category line also. This way, you can
ensure that each command is placed in the right category regardless of
which of the dependencies actually run.
Pre-installation and post-installation commands should not run any
programs except for these:
@example
[ basename bash cat chgrp chmod chown cmp cp dd diff echo
egrep expand expr false fgrep find getopt grep gunzip gzip
hostname install install-info kill ldconfig ln ls md5sum
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
test touch true uname xargs yes
@end example
@cindex binary packages
The reason for distinguishing the commands in this way is for the sake
of making binary packages. Typically a binary package contains all the
executables and other files that need to be installed, and has its own
method of installing them---so it does not need to run the normal
installation commands. But installing the binary package does need to
execute the pre-installation and post-installation commands.
Programs to build binary packages work by extracting the
pre-installation and post-installation commands. Here is one way of
extracting the pre-installation commands:
@smallexample
make -n install -o all \
PRE_INSTALL=pre-install \
POST_INSTALL=post-install \
NORMAL_INSTALL=normal-install \
| gawk -f pre-install.awk
@end smallexample
@noindent
where the file @file{pre-install.awk} could contain this:
@smallexample
$0 ~ /^\t[ \t]*(normal_install|post_install)[ \t]*$/ @{on = 0@}
on @{print $0@}
$0 ~ /^\t[ \t]*pre_install[ \t]*$/ @{on = 1@}
@end smallexample
The resulting file of pre-installation commands is executed as a shell
script as part of installing the binary package.

4
make.h
View File

@ -393,6 +393,8 @@ struct floc
};
#define NILF ((struct floc *)0)
#define STRING_SIZE_TUPLE(_s) (_s), (sizeof (_s)-1)
/* Fancy processing for variadic functions in both ANSI and pre-ANSI
compilers. */
@ -419,7 +421,7 @@ extern char *xmalloc PARAMS ((unsigned int));
extern char *xrealloc PARAMS ((char *, unsigned int));
extern char *xstrdup PARAMS ((const char *));
extern char *find_next_token PARAMS ((char **, unsigned int *));
extern char *next_token PARAMS ((char *));
extern char *next_token PARAMS ((const char *));
extern char *end_of_token PARAMS ((char *));
extern void collapse_continuations PARAMS ((char *));
extern void remove_comments PARAMS((char *));

10
misc.c
View File

@ -520,13 +520,11 @@ end_of_token_w32 (s, stopchar)
char *
next_token (s)
char *s;
const char *s;
{
register char *p = s;
while (isblank ((unsigned char)*p))
++p;
return p;
while (isblank ((unsigned char)*s))
++s;
return (char *)s;
}
/* Find the next token in PTR; return the address of it, and store the

1256
read.c

File diff suppressed because it is too large Load Diff

View File

@ -706,6 +706,7 @@ notice_finished_file (file)
{
struct dep *d;
int ran = file->command_state == cs_running;
int touched = 0;
file->command_state = cs_finished;
file->updated = 1;
@ -734,24 +735,36 @@ notice_finished_file (file)
if (file->phony)
file->update_status = 0;
else
/* Should set file's modification date and do nothing else. */
file->update_status = touch_file (file);
{
/* Should set file's modification date and do nothing else. */
file->update_status = touch_file (file);
/* Pretend we ran a real touch command, to suppress the
"`foo' is up to date" message. */
commands_started++;
/* Request for the timestamp to be updated (and distributed
to the double-colon entries). Simply setting ran=1 would
almost have done the trick, but messes up with the also_make
updating logic below. */
touched = 1;
}
}
}
if (file->mtime_before_update == UNKNOWN_MTIME)
file->mtime_before_update = file->last_mtime;
if (ran && !file->phony)
if ((ran && !file->phony) || touched)
{
struct file *f;
int i = 0;
/* If -n or -q and all the commands are recursive, we ran them so
/* If -n, -t, or -q and all the commands are recursive, we ran them so
really check the target's mtime again. Otherwise, assume the target
would have been updated. */
if (question_flag || just_print_flag)
if (question_flag || just_print_flag || touch_flag)
{
for (i = file->cmds->ncommand_lines; i > 0; --i)
if (! (file->cmds->lines_flags[i-1] & COMMANDS_RECURSE))

View File

@ -1,3 +1,9 @@
2002-07-07 Paul D. Smith <psmith@gnu.org>
* scripts/functions/eval: Test new function.
* scripts/functions/value: Test new function.
* scripts/variables/MAKEFILE_LIST: Test new variable.
2002-04-28 Paul D. Smith <psmith@gnu.org>
* scripts/functions/call: New test: transitive closure

View File

@ -0,0 +1,60 @@
# -*-perl-*-
$description = "Test the eval function.";
$details = "This is a test of the eval function in GNU make.
This function will evaluate inline makefile syntax and incorporate the
results into its internal database.\n";
open(MAKEFILE,"> $makefile");
print MAKEFILE <<'EOF';
define Y
all:: ; @echo $AA
A = B
endef
X = $(eval $(value Y))
$(eval $(shell echo A = A))
$(eval $(Y))
$(eval A = C)
$(eval $(X))
EOF
close(MAKEFILE);
&run_make_with_options($makefile, "", &get_logfile);
# Create the answer to what should be produced by this Makefile
$answer = "AA\nBA\n";
&compare_output($answer,&get_logfile(1));
# Test to make sure defining variables when we have extra scope pushed works
# as expected.
$makefile2 = &get_tmpfile;
open(MAKEFILE,"> $makefile2");
print MAKEFILE <<'EOF';
VARS = A B
VARSET = $(1) = $(2)
$(foreach v,$(VARS),$(eval $(call VARSET,$v,$v)))
all: ; @echo A = $(A) B = $(B)
EOF
close(MAKEFILE);
&run_make_with_options($makefile2, "", &get_logfile);
# Create the answer to what should be produced by this Makefile
$answer = "A = A B = B\n";
&compare_output($answer,&get_logfile(1));
1;

View File

@ -0,0 +1,30 @@
# -*-perl-*-
$description = "Test the value function.";
$details = "This is a test of the value function in GNU make.
This function will evaluate to the value of the named variable with no
further expansion performed on it.\n";
open(MAKEFILE,"> $makefile");
print MAKEFILE <<'EOF';
export FOO = foo
recurse = FOO = $FOO
static := FOO = $(value FOO)
all: ; @echo $(recurse) $(value recurse) $(static) $(value static)
EOF
close(MAKEFILE);
&run_make_with_options($makefile, "", &get_logfile);
# Create the answer to what should be produced by this Makefile
$answer = "FOO = OO FOO = foo FOO = foo FOO = foo\n";
&compare_output($answer,&get_logfile(1));
1;

View File

@ -0,0 +1,30 @@
# -*-perl-*-
$description = "Test the MAKEFILE_LIST variable.";
$makefile2 = &get_tmpfile;
open(MAKEFILE,"> $makefile");
print MAKEFILE <<EOF;
m1 := \$(MAKEFILE_LIST)
include $makefile2
m3 := \$(MAKEFILE_LIST)
all:
\t\@echo \$(m1)
\t\@echo \$(m2)
\t\@echo \$(m3)
EOF
close(MAKEFILE);
open(MAKEFILE,"> $makefile2");
print MAKEFILE "m2 := \$(MAKEFILE_LIST)\n";
close(MAKEFILE);
&run_make_with_options($makefile, "", &get_logfile);
$answer = "$makefile\n$makefile $makefile2\n$makefile $makefile2\n";
&compare_output($answer,&get_logfile(1));
1;

View File

@ -37,6 +37,16 @@ define
endef
endif
define outer
define inner
A = B
endef
endef
$(eval $(outer))
outer: ; @echo $(inner)
EOF
# END of Contents of MAKEFILE
@ -64,5 +74,12 @@ $answer = "later foo bar\n";
$answer = "$makefile:23: *** empty variable name. Stop.\n";
&compare_output($answer, &get_logfile(1));
# TEST #4
# -------
&run_make_with_options($makefile, "outer", &get_logfile);
$answer = "A = B\n";
&compare_output($answer, &get_logfile(1));
1;

View File

@ -57,7 +57,7 @@ struct variable_set_list *current_variable_set_list = &global_setlist;
struct variable *
define_variable_in_set (name, length, value, origin, recursive, set, flocp)
char *name;
const char *name;
unsigned int length;
char *value;
enum variable_origin origin;
@ -69,6 +69,9 @@ define_variable_in_set (name, length, value, origin, recursive, set, flocp)
register unsigned int hashval;
register struct variable *v;
if (set == NULL)
set = &global_variable_set;
hashval = 0;
for (i = 0; i < length; ++i)
HASH (hashval, name[i]);
@ -741,6 +744,227 @@ target_environment (file)
return result;
}
/* Given a variable, a value, and a flavor, define the variable.
See the try_variable_definition() function for details on the parameters. */
struct variable *
do_variable_definition (flocp, varname, value, origin, flavor, target_var)
const struct floc *flocp;
const char *varname;
char *value;
enum variable_origin origin;
enum variable_flavor flavor;
int target_var;
{
char *p, *alloc_value = NULL;
struct variable *v;
int append = 0;
/* Calculate the variable's new value in VALUE. */
switch (flavor)
{
default:
case f_bogus:
/* Should not be possible. */
abort ();
case f_simple:
/* A simple variable definition "var := value". Expand the value.
We have to allocate memory since otherwise it'll clobber the
variable buffer, and we may still need that if we're looking at a
target-specific variable. */
p = alloc_value = allocated_variable_expand (value);
break;
case f_conditional:
/* A conditional variable definition "var ?= value".
The value is set IFF the variable is not defined yet. */
v = lookup_variable (varname, strlen (varname));
if (v)
return v;
flavor = f_recursive;
/* FALLTHROUGH */
case f_recursive:
/* A recursive variable definition "var = value".
The value is used verbatim. */
p = value;
break;
case f_append:
{
/* If we have += but we're in a target variable context, we want to
append only with other variables in the context of this target. */
if (target_var)
{
append = 1;
v = lookup_variable_in_set (varname, strlen (varname),
current_variable_set_list->set);
}
else
v = lookup_variable (varname, strlen (varname));
if (v == 0)
{
/* There was no old value.
This becomes a normal recursive definition. */
p = value;
flavor = f_recursive;
}
else
{
/* Paste the old and new values together in VALUE. */
unsigned int oldlen, newlen;
p = value;
if (v->recursive)
/* The previous definition of the variable was recursive.
The new value is the unexpanded old and new values. */
flavor = f_recursive;
else
/* The previous definition of the variable was simple.
The new value comes from the old value, which was expanded
when it was set; and from the expanded new value. Allocate
memory for the expansion as we may still need the rest of the
buffer if we're looking at a target-specific variable. */
p = alloc_value = allocated_variable_expand (p);
oldlen = strlen (v->value);
newlen = strlen (p);
p = (char *) alloca (oldlen + 1 + newlen + 1);
bcopy (v->value, p, oldlen);
p[oldlen] = ' ';
bcopy (value, &p[oldlen + 1], newlen + 1);
}
}
}
#ifdef __MSDOS__
/* Many Unix Makefiles include a line saying "SHELL=/bin/sh", but
non-Unix systems don't conform to this default configuration (in
fact, most of them don't even have `/bin'). On the other hand,
$SHELL in the environment, if set, points to the real pathname of
the shell.
Therefore, we generally won't let lines like "SHELL=/bin/sh" from
the Makefile override $SHELL from the environment. But first, we
look for the basename of the shell in the directory where SHELL=
points, and along the $PATH; if it is found in any of these places,
we define $SHELL to be the actual pathname of the shell. Thus, if
you have bash.exe installed as d:/unix/bash.exe, and d:/unix is on
your $PATH, then SHELL=/usr/local/bin/bash will have the effect of
defining SHELL to be "d:/unix/bash.exe". */
if ((origin == o_file || origin == o_override)
&& strcmp (varname, "SHELL") == 0)
{
char shellpath[PATH_MAX];
extern char * __dosexec_find_on_path (const char *, char *[], char *);
/* See if we can find "/bin/sh.exe", "/bin/sh.com", etc. */
if (__dosexec_find_on_path (p, (char **)0, shellpath))
{
char *p;
for (p = shellpath; *p; p++)
{
if (*p == '\\')
*p = '/';
}
v = define_variable_loc (varname, strlen (varname),
shellpath, origin, flavor == f_recursive,
flocp);
}
else
{
char *shellbase, *bslash;
struct variable *pathv = lookup_variable ("PATH", 4);
char *path_string;
char *fake_env[2];
size_t pathlen = 0;
shellbase = strrchr (p, '/');
bslash = strrchr (p, '\\');
if (!shellbase || bslash > shellbase)
shellbase = bslash;
if (!shellbase && p[1] == ':')
shellbase = p + 1;
if (shellbase)
shellbase++;
else
shellbase = p;
/* Search for the basename of the shell (with standard
executable extensions) along the $PATH. */
if (pathv)
pathlen = strlen (pathv->value);
path_string = (char *)xmalloc (5 + pathlen + 2 + 1);
/* On MSDOS, current directory is considered as part of $PATH. */
sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
fake_env[0] = path_string;
fake_env[1] = (char *)0;
if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
{
char *p;
for (p = shellpath; *p; p++)
{
if (*p == '\\')
*p = '/';
}
v = define_variable_loc (varname, strlen (varname),
shellpath, origin,
flavor == f_recursive, flocp);
}
else
v = lookup_variable (varname, strlen (varname));
free (path_string);
}
}
else
#endif /* __MSDOS__ */
#ifdef WINDOWS32
if ((origin == o_file || origin == o_override) && streq (varname, "SHELL"))
{
extern char *default_shell;
/* Call shell locator function. If it returns TRUE, then
set no_default_sh_exe to indicate sh was found and
set new value for SHELL variable. */
if (find_and_set_default_shell (p))
{
v = define_variable_in_set (varname, strlen (varname), default_shell,
origin, flavor == f_recursive,
(target_var
? current_variable_set_list->set
: NULL),
flocp);
no_default_sh_exe = 0;
}
else
v = lookup_variable (varname, strlen (varname));
}
else
#endif
/* If we are defining variables inside an $(eval ...), we might have a
different variable context pushed, not the global context (maybe we're
inside a $(call ...) or something. Since this function is only ever
invoked in places where we want to define globally visible variables,
make sure we define this variable in the global set. */
v = define_variable_in_set (varname, strlen (varname), p,
origin, flavor == f_recursive,
(target_var
? current_variable_set_list->set : NULL),
flocp);
v->append = append;
if (alloc_value)
free (alloc_value);
return v;
}
/* Try to interpret LINE (a null-terminated string) as a variable definition.
ORIGIN may be o_file, o_override, o_env, o_env_override,
@ -765,11 +989,9 @@ try_variable_definition (flocp, line, origin, target_var)
register char *p = line;
register char *beg;
register char *end;
enum { f_bogus,
f_simple, f_recursive, f_append, f_conditional } flavor = f_bogus;
char *name, *expanded_name, *value=0, *alloc_value=NULL;
enum variable_flavor flavor = f_bogus;
char *name, *expanded_name;
struct variable *v;
int append = 0;
while (1)
{
@ -848,195 +1070,9 @@ try_variable_definition (flocp, line, origin, target_var)
if (expanded_name[0] == '\0')
fatal (flocp, _("empty variable name"));
/* Calculate the variable's new value in VALUE. */
v = do_variable_definition (flocp, expanded_name, p,
origin, flavor, target_var);
switch (flavor)
{
case f_bogus:
/* Should not be possible. */
abort ();
case f_simple:
/* A simple variable definition "var := value". Expand the value.
We have to allocate memory since otherwise it'll clobber the
variable buffer, and we may still need that if we're looking at a
target-specific variable. */
value = alloc_value = allocated_variable_expand (p);
break;
case f_conditional:
/* A conditional variable definition "var ?= value".
The value is set IFF the variable is not defined yet. */
v = lookup_variable(expanded_name, strlen(expanded_name));
if (v)
{
free(expanded_name);
return v;
}
flavor = f_recursive;
/* FALLTHROUGH */
case f_recursive:
/* A recursive variable definition "var = value".
The value is used verbatim. */
value = p;
break;
case f_append:
{
/* If we have += but we're in a target variable context, we want to
append only with other variables in the context of this target. */
if (target_var)
{
append = 1;
v = lookup_variable_in_set (expanded_name, strlen (expanded_name),
current_variable_set_list->set);
}
else
v = lookup_variable (expanded_name, strlen (expanded_name));
if (v == 0)
{
/* There was no old value.
This becomes a normal recursive definition. */
value = p;
flavor = f_recursive;
}
else
{
/* Paste the old and new values together in VALUE. */
unsigned int oldlen, newlen;
if (v->recursive)
/* The previous definition of the variable was recursive.
The new value is the unexpanded old and new values. */
flavor = f_recursive;
else
/* The previous definition of the variable was simple.
The new value comes from the old value, which was expanded
when it was set; and from the expanded new value. Allocate
memory for the expansion as we may still need the rest of the
buffer if we're looking at a target-specific variable. */
p = alloc_value = allocated_variable_expand (p);
oldlen = strlen (v->value);
newlen = strlen (p);
value = (char *) alloca (oldlen + 1 + newlen + 1);
bcopy (v->value, value, oldlen);
value[oldlen] = ' ';
bcopy (p, &value[oldlen + 1], newlen + 1);
}
}
}
#ifdef __MSDOS__
/* Many Unix Makefiles include a line saying "SHELL=/bin/sh", but
non-Unix systems don't conform to this default configuration (in
fact, most of them don't even have `/bin'). On the other hand,
$SHELL in the environment, if set, points to the real pathname of
the shell.
Therefore, we generally won't let lines like "SHELL=/bin/sh" from
the Makefile override $SHELL from the environment. But first, we
look for the basename of the shell in the directory where SHELL=
points, and along the $PATH; if it is found in any of these places,
we define $SHELL to be the actual pathname of the shell. Thus, if
you have bash.exe installed as d:/unix/bash.exe, and d:/unix is on
your $PATH, then SHELL=/usr/local/bin/bash will have the effect of
defining SHELL to be "d:/unix/bash.exe". */
if ((origin == o_file || origin == o_override)
&& strcmp (expanded_name, "SHELL") == 0)
{
char shellpath[PATH_MAX];
extern char * __dosexec_find_on_path (const char *, char *[], char *);
/* See if we can find "/bin/sh.exe", "/bin/sh.com", etc. */
if (__dosexec_find_on_path (value, (char **)0, shellpath))
{
char *p;
for (p = shellpath; *p; p++)
{
if (*p == '\\')
*p = '/';
}
v = define_variable_loc (expanded_name, strlen (expanded_name),
shellpath, origin, flavor == f_recursive,
flocp);
}
else
{
char *shellbase, *bslash;
struct variable *pathv = lookup_variable ("PATH", 4);
char *path_string;
char *fake_env[2];
size_t pathlen = 0;
shellbase = strrchr (value, '/');
bslash = strrchr (value, '\\');
if (!shellbase || bslash > shellbase)
shellbase = bslash;
if (!shellbase && value[1] == ':')
shellbase = value + 1;
if (shellbase)
shellbase++;
else
shellbase = value;
/* Search for the basename of the shell (with standard
executable extensions) along the $PATH. */
if (pathv)
pathlen = strlen (pathv->value);
path_string = (char *)xmalloc (5 + pathlen + 2 + 1);
/* On MSDOS, current directory is considered as part of $PATH. */
sprintf (path_string, "PATH=.;%s", pathv ? pathv->value : "");
fake_env[0] = path_string;
fake_env[1] = (char *)0;
if (__dosexec_find_on_path (shellbase, fake_env, shellpath))
{
char *p;
for (p = shellpath; *p; p++)
{
if (*p == '\\')
*p = '/';
}
v = define_variable_loc (expanded_name, strlen (expanded_name),
shellpath, origin,
flavor == f_recursive, flocp);
}
else
v = lookup_variable (expanded_name, strlen (expanded_name));
free (path_string);
}
}
else
#endif /* __MSDOS__ */
#ifdef WINDOWS32
if ((origin == o_file || origin == o_override)
&& strcmp (expanded_name, "SHELL") == 0)
{
extern char* default_shell;
/*
* Call shell locator function. If it returns TRUE, then
* set no_default_sh_exe to indicate sh was found and
* set new value for SHELL variable.
*/
if (find_and_set_default_shell(value)) {
v = define_variable_loc (expanded_name, strlen (expanded_name),
default_shell, origin, flavor == f_recursive,
flocp);
no_default_sh_exe = 0;
}
}
else
#endif
v = define_variable_loc (expanded_name, strlen (expanded_name), value,
origin, flavor == f_recursive, flocp);
v->append = append;
if (alloc_value)
free (alloc_value);
free (expanded_name);
return v;

View File

@ -31,6 +31,15 @@ enum variable_origin
o_invalid /* Core dump time. */
};
enum variable_flavor
{
f_bogus, /* Bogus (error) */
f_simple, /* Simple definition (:=) */
f_recursive, /* Recursive definition (=) */
f_append, /* Appending definition (+=) */
f_conditional /* Conditional definition (?=) */
};
/* Structure that represents one variable definition.
Each bucket of the hash table is a chain of these,
chained through `next'. */
@ -117,6 +126,7 @@ extern void initialize_file_variables PARAMS ((struct file *file, int read));
extern void print_file_variables PARAMS ((struct file *file));
extern void print_variable_set PARAMS ((struct variable_set *set, char *prefix));
extern void merge_variable_set_lists PARAMS ((struct variable_set_list **setlist0, struct variable_set_list *setlist1));
extern struct variable *do_variable_definition PARAMS ((const struct floc *flocp, const char *name, char *value, enum variable_origin origin, enum variable_flavor flavor, int target_var));
extern struct variable *try_variable_definition PARAMS ((const struct floc *flocp, char *line, enum variable_origin origin, int target_var));
extern struct variable *lookup_variable PARAMS ((const char *name, unsigned int length));
@ -125,7 +135,7 @@ extern struct variable *lookup_variable_in_set PARAMS ((const char *name,
const struct variable_set *set));
extern struct variable *define_variable_in_set
PARAMS ((char *name, unsigned int length, char *value,
PARAMS ((const char *name, unsigned int length, char *value,
enum variable_origin origin, int recursive,
struct variable_set *set, const struct floc *flocp));
@ -141,6 +151,11 @@ extern struct variable *define_variable_in_set
define_variable_in_set((n),(l),(v),(o),(r),\
current_variable_set_list->set,(f))
/* Define a variable with a location in the global variable set. */
#define define_variable_global(n,l,v,o,r,f) \
define_variable_in_set((n),(l),(v),(o),(r),NULL,(f))
/* Define a variable in FILE's variable set. */
#define define_variable_for_file(n,l,v,o,r,f) \