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 not use the
features of make listed here, nor the ones in section Incompatibilities and Missing Features.
Many features come from the version of make in System V.
VPATH variable and its special meaning.
See section Searching Directories for Prerequisites.
This feature exists in System V make, but is undocumented.
It is documented in 4.3 BSD make (which says it mimics System V's
VPATH feature).
MAKEFLAGS to recursive
invocations of make.
See section Communicating Options to a Sub-make.
$% is set to the member name
in an archive reference. See section Automatic Variables.
$@, $*, $<, $%,
and $? have corresponding forms like $(@F) and
$(@D). We have generalized this to $^ as an obvious
extension. See section Automatic Variables.
make, these options actually do something.
make via the variable
MAKE even if `-n', `-q' or `-t' is specified.
See section Recursive Use of make.
make, because the
general feature of rule chaining (see section Chains of Implicit Rules) allows one pattern rule for installing members in an
archive (see section Implicit Rule for Archive Member Targets) to be sufficient.
The following features were inspired by various other versions of
make. In some cases it is unclear exactly which versions inspired
which others.
make.
We're not sure who invented it first, but it's been spread around a bit.
See section Defining and Redefining Pattern Rules.
make
for AT&T Eighth Edition Research Unix, and later by Andrew Hume of
AT&T Bell Labs in his mk program (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 Chains of Implicit Rules.
$^ containing a list of all prerequisites
of the current target. We did not invent this, but we have no idea who
did. See section Automatic Variables. The automatic variable
$+ is a simple extension of $^.
make) was (as far as we know)
invented by Andrew Hume in mk.
See section Instead of Executing the Commands.
make and similar programs, though not in the
System V or BSD implementations. See section Command Execution.
make by the
patsubst function before the alternate syntax was implemented
for compatibility with SunOS 4. It is not altogether clear who
inspired whom, since GNU make had patsubst before SunOS
4 was released.
make. See section Appending More Text to Variables.
make.
See section Archive Members as Targets.
-include directive to include makefiles with no error for a
nonexistent file comes from SunOS 4 make. (But note that SunOS 4
make does not allow multiple makefiles to be specified in one
-include directive.) The same feature appears with the name
sinclude in SGI make and perhaps others.
The remaining features are inventions new in GNU make:
make.
MAKE to recursive make invocations.
See section Recursive Use of make.
define.
See section Defining Variables Verbatim.
.PHONY.
Andrew Hume of AT&T Bell Labs implemented a similar feature with a
different syntax in his mk program. This seems to be a case of
parallel discovery. See section Phony Targets.
is equivalent to:
foolib(hack.o) foolib(kludge.o)
You can also use shell-style wildcards in an archive member reference. See section Using Wildcard Characters in File Names. For example, `foolib(*.o)' expands to all existing members of the `foolib' archive whose names end in `.o'; perhaps `foolib(hack.o) foolib(kludge.o)'.
Recall that a target that looks like `a(m)' stands for the member named m in the archive file a.
When make looks for an implicit rule for such a target, as a special
feature it considers implicit rules that match `(m)', as well as
those that match the actual target `a(m)'.
This causes one special rule whose target is `(%)' to match. This rule updates the target `a(m)' by copying the file m into the archive. For example, it will update the archive member target `foo.a(bar.o)' by copying the file `bar.o' into the archive `foo.a' as a member named `bar.o'.
When this rule is chained with others, the result is very powerful. Thus, `make "foo.a(bar.o)"' (the quotes are needed to protect the `(' and `)' from being interpreted specially by the shell) in the presence of a file `bar.c' is enough to cause the following commands to be run, even without a makefile:
cc -c bar.c -o bar.o ar r foo.a bar.o rm -f bar.o
Here make has envisioned the file `bar.o' as an intermediate
file. See section Chains of Implicit Rules.
Implicit rules such as this one are written using the automatic variable `$%'. See section Automatic Variables.
An archive member name in an archive cannot contain a directory name, but
it may be useful in a makefile to pretend that it does. If you write an
archive member target `foo.a(dir/file.o)', make will perform
automatic updating with this command:
ar r foo.a dir/file.o
which has the effect of copying the file `dir/file.o' into a member
named `file.o'. In connection with such usage, the automatic variables
%D and %F may be useful.