GNU make - 12. Features of GNU make
12. Features of GNU make
Here is a summary of the features of GNU make, for comparison
with and credit to other versions of make. We consider the
features of make in 4.2 BSD systems as a baseline. If you are
concerned with writing portable makefiles, you should use only the
features of make not listed here or in section 13. Incompatibilities and Missing Features.
Many features come from the version of make in System V.
-
The
VPATHvariable and its special meaning. See section 4.3 Searching Directories for Dependencies. This feature exists in System Vmake, but is undocumented. It is documented in 4.3 BSDmake(which says it mimics System V'sVPATHfeature). - Included makefiles. See section 3.3 Including Other Makefiles. Allowing multiple files to be included with a single directive is a GNU extension.
- Variables are read from and communicated via the environment. See section 6.9 Variables from the Environment.
-
Options passed through the variable
MAKEFLAGSto recursive invocations ofmake. See section 5.6.3 Communicating Options to a Sub-make. -
The automatic variable
$%is set to the member name in an archive reference. See section 10.5.3 Automatic Variables. -
The automatic variables
$@,$*,$<,$%, and$?have corresponding forms like$(@F)and$(@D). We have generalized this to$^as an obvious extension. See section 10.5.3 Automatic Variables. - Substitution variable references. See section 6.1 Basics of Variable References.
-
The command-line options `-b' and `-m', accepted and
ignored. In System V
make, these options actually do something. -
Execution of recursive commands to run
makevia the variableMAKEeven if `-n', `-q' or `-t' is specified. See section 5.6 Recursive Use ofmake. -
Support for suffix `.a' in suffix rules. See section 11.4 Suffix Rules for Archive Files. This feature is obsolete in GNU
make, because the general feature of rule chaining (see section 10.4 Chains of Implicit Rules) allows one pattern rule for installing members in an archive (see section 11.2 Implicit Rule for Archive Member Targets) to be sufficient. - The arrangement of lines and backslash-newline combinations in commands is retained when the commands are printed, so they appear as they do in the makefile, except for the stripping of initial whitespace.
The following features were inspired by various other versions of
make. In some cases it is unclear exactly which versions inspired
which others.
-
Pattern rules using `%'.
This has been implemented in several versions of
make. We're not sure who invented it first, but it's been spread around a bit. See section 10.5 Defining and Redefining Pattern Rules. -
Rule chaining and implicit intermediate files.
This was implemented by Stu Feldman in his version of
makefor AT&T Eighth Edition Research Unix, and later by Andrew Hume of AT&T Bell Labs in hismkprogram (where he terms it "transitive closure"). We do not really know if we got this from either of them or thought it up ourselves at the same time. See section 10.4 Chains of Implicit Rules. -
The automatic variable
$^containing a list of all dependencies of the current target. We did not invent this, but we have no idea who did. See section 10.5.3 Automatic Variables. The automatic variable$+is a simple extension of$^. -
The "what if" flag (`-W' in GNU
make) was (as far as we know) invented by Andrew Hume inmk. See section 9.3 Instead of Executing the Commands. -
The concept of doing several things at once (parallelism) exists in
many incarnations of
makeand similar programs, though not in the System V or BSD implementations. See section 5.2 Command Execution. -
Modified variable references using pattern substitution come from
SunOS 4. See section 6.1 Basics of Variable References.
This functionality was provided in GNU
makeby thepatsubstfunction before the alternate syntax was implemented for compatibility with SunOS 4. It is not altogether clear who inspired whom, since GNUmakehadpatsubstbefore SunOS 4 was released. - The special significance of `+' characters preceding command lines (see section 9.3 Instead of Executing the Commands) is mandated by IEEE Standard 1003.2-1992 (POSIX.2).
-
The `+=' syntax to append to the value of a variable comes from SunOS
4
make. See section 6.6 Appending More Text to Variables. -
The syntax `archive(mem1 mem2...)' to list
multiple members in a single archive file comes from SunOS 4
make. See section 11.1 Archive Members as Targets. -
The
-includedirective to include makefiles with no error for a nonexistent file comes from SunOS 4make. (But note that SunOS 4makedoes not allow multiple makefiles to be specified in one-includedirective.) The same feature appears with the namesincludein SGImakeand perhaps others.
The remaining features are inventions new in GNU make:
- Use the `-v' or `--version' option to print version and copyright information.
-
Use the `-h' or `--help' option to summarize the options to
make. - Simply-expanded variables. See section 6.2 The Two Flavors of Variables.
-
Pass command-line variable assignments automatically through the
variable
MAKEto recursivemakeinvocations. See section 5.6 Recursive Use ofmake. - Use the `-C' or `--directory' command option to change directory. See section 9.7 Summary of Options.
-
Make verbatim variable definitions with
define. See section 6.8 Defining Variables Verbatim. -
Declare phony targets with the special target
.PHONY. Andrew Hume of AT&T Bell Labs implemented a similar feature with a different syntax in hismkprogram. This seems to be a case of parallel discovery. See section 4.4 Phony Targets. - Manipulate text by calling functions. See section 8. Functions for Transforming Text.
- Use the `-o' or `--old-file' option to pretend a file's modification-time is old. See section 9.4 Avoiding Recompilation of Some Files.
-
Conditional execution.
This feature has been implemented numerous times in various versions
of
make; it seems a natural extension derived from the features of the C preprocessor and similar macro languages and is not a revolutionary concept. See section 7. Conditional Parts of Makefiles. - Specify a search path for included makefiles. See section 3.3 Including Other Makefiles.
-
Specify extra makefiles to read with an environment variable.
See section 3.4 The Variable
MAKEFILES. - Strip leading sequences of `./' from file names, so that `./file' and `file' are considered to be the same file.
- Use a special search method for library dependencies written in the form `-lname'. See section 4.3.6 Directory Search for Link Libraries.
-
Allow suffixes for suffix rules
(see section 10.7 Old-Fashioned Suffix Rules) to contain any
characters. In other versions of
make, they must begin with `.' and not contain any `/' characters. -
Keep track of the current level of
makerecursion using the variableMAKELEVEL. See section 5.6 Recursive Use ofmake. -
Provide any goals given on the command line in the variable
MAKECMDGOALS. See section 9.2 Arguments to Specify the Goals. - Specify static pattern rules. See section 4.10 Static Pattern Rules.
-
Provide selective
vpathsearch. See section 4.3 Searching Directories for Dependencies. - Provide computed variable references. See section 6.1 Basics of Variable References.
-
Update makefiles. See section 3.5 How Makefiles Are Remade.
System V
makehas a very, very limited form of this functionality in that it will check out SCCS files for makefiles. - Various new built-in implicit rules. See section 10.2 Catalogue of Implicit Rules.
-
The built-in variable `MAKE_VERSION' gives the version number of
make.
Go to the first, previous, next, last section, table of contents.