Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ make(1V) — RISC iX 1.2

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sh(1)

touch(1)

f77(1)

pc(1)

cc(1)

MAKE(1V)  —  UNIX Programmer’s Manual

NAME

make − maintain, update, and regenerate groups of programs

SYNOPSIS

make [ −f makefile ] [−i] [−k] [−p] [−s] [−r] [−n] [−e] [−t] [−q] [−S] [−g] [−d] [ name ...  ] [ macro=value ...  ]

DESCRIPTION

The following target names may be defined in the makefile and are interpreted as follows. 

.DEFAULT:
If a file must be made but there are no explicit commands or relevant built in rules, the commands associated with the name .DEFAULT are used instead. Note that this overrides file acquisition by SCCS and so should be used with care. 

.PRECIOUS:
Dependents of this target will not be removed if SIGINT or SIGQUIT occur. Note that this does not apply to makefile or Makefile if acquired by SCCS. 

.SILENT:
Same effect as the −s option.

.IGNORE:
Same effect as the −i option.

.SUFFIXES:
Add those suffixes following to the list of suffixes for which implicit rules may be used, or in the case where no suffixes follow, clear the suffixes list. Order is significant; the first possible name for which both a file and a rule (as described later) exist is inferred. The default list is:

.SUFFIXES: .o .c .c~ .y .y~ .l .l~ .s .s~ .h .h~ .sh .sh~ .f .f~ .e .r .yr .ye .cl .out .p

Make executes commands in the makefile to update one or more target names. Name is typically a program.  If no −f option is present, “makefile”, “Makefile” and the SCCS files s.makefile and s.Makefile are tried in order. Note that to use the SCCS support provided by make it is necessary to have (at least) an implementation of the SCCS get command to extract a file from its s.filename SCCS archive.  If makefile is “−”, the standard input is taken.  More than one −f option may appear. 

Make updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist. All prerequisites of a target are added recursively to the list of targets.  Missing files are deemed to be out of date. 

If no target is specified on the command line, make uses the first target defined in makefile.

If a target has no makefile entry, or if its entry has no rule, make attempts to derive a rule by each of the following methods, in turn, until a suitable rule is found. 

• Implicit rules, read in from a user-supplied makefile. 

• Standard implicit rules (also known as suffix rules), contained within the make program. 

• SCCS retrieval.  Make retrieves the most recent version from the SCCS archive file (if any). 

• The rule from the .DEFAULT: target entry, if there is such an entry in the makefile. 

If there is no makefile entry for a target, if no rule can be derived for building it, and if no file by that name is present, make issues an error message and halts. 

Reading Makefiles and the Environment

When make first starts, it reads the MAKEFLAGS environment variable to obtain any of the following options specified present in its value: −d, −e, −i, −k, −n, −p, −q, −r, −s, or −t.  (Within the MAKEFLAGS value, the leading “−” character for the option string is omitted.)  make then reads the command line for additional options, which also take effect. 

Next, make reads in a default makefile that typically contains predefined macro definitions, target entries for implicit rules, and additional rules, such as the rule for retrieving SCCS files. 

Next, make imports variables from the environment (unless the −e option is in effect), and treats them as defined macros.  Because make uses the most recent definition it encounters, a macro definition in the makefile normally overrides an environment variable of the same name.  When −e is in effect, however, environment variables are read in after all makefiles have been read.  In that case, the environment variables take precedence over definitions in the makefile. 

Next make reads any makefiles specified with −f, or one of makefile or Makefile as described above. 

Next, (after reading the environment if −e is in effect), make reads in any macro definitions supplied as command line arguments.  These override macro definitions in both the makefile and the environment, but only for the make command itself. 

Make exports environment variables, using the most recently defined value.  Macro definitions supplied on the command line are not normally exported, unless the macro is also an environment variable. 

Make does not export macros defined in the makefile.  If an environment variable is set, and a macro with the same name is defined on the command line, make exports its value as defined on the command line.  Unless −e is in effect, macro definitions within the makefile take precedence over those imported from the environment. 

The macros MAKEFLAGS, and MAKE, are special cases. 

Makefile contains a sequence of entries that specify dependencies.  The first line of an entry is a blank-separated, non-null list of targets, then a colon, then a list of prerequisite files or dependencies.  Text following a semicolon, and all following lines that begin with a tab, are shell commands to be executed to update the target.  The first line that does not begin with a tab or # begins a new dependency or macro definition. To continue commands across more than one line, all but the last line must be terminated by a backslash. 

Sharp and newline surround comments. 

If a name appears on the left of more than one “colon” line, then it depends on all of the names on the right of the colon on those lines, but only one command sequence may be specified for it.  If a name appears on a line with a double colon ( “::”) then the command sequence following that line is performed only if the name is out of date with respect to the names to the right of the double colon, and is not affected by other double colon lines on which that name may appear. 

Two special forms of a name are recognized.  A name like a(b) means the file named b stored in the ar(1) archive named a.  A name like a((b)) means the file stored in archive a containing the entry point b. 

The following makefile says that “pgm” depends on two files “a.o” and “b.o”, and that they in turn depend on “.c” files and a common file “incl”. 

pgm: a.o b.o
cc a.o b.o −lm −o pgm

a.o: incl a.c
cc −c a.c

b.o: incl b.c
cc −c b.c

Including other files

If the word include appears as the first seven letters of a line and is followed by a SPACE or TAB, the string that follows is taken as a filename to interpolate at that line.  Include files can be nested to a depth of no more than about 16.  If filename is a macro reference, it is expanded. 

Macros

Entries of the form

macro=value

define macros.  Macro is the name of the macro, and value, which consists of all characters up to a comment character or unescaped NEWLINE, is the value.  make strips leading white space ( ASCII space and TAB characters) in accepting the value but leaves trailing white space, up to (but not including) the end of the line or the start of a comment.  Beware, other versions of make only remove a single white space character from the start. 

Subsequent references to the macro, of the forms $(name) or ${name} are replaced by value. The parentheses or brackets can be omitted in a reference to a macro with a single-character name.

Macro references can contain references to other macros, in which case nested references are expanded first. 

Suffix Replacement Macro References

Substitutions within macros can be made as follows:

$(name:string1=string2 )

where string1 is either a suffix, or a word to be replaced in the macro definition, and string2 is the replacement suffix or word.  Words in a macro value are separated by SPACE, TAB, and escaped NEWLINE characters. 

Make infers prerequisites for files for which makefile gives no construction commands.  For example, a “.c” file may be inferred as prerequisite for a “.o” file and be compiled to produce the “.o” file.  Thus the preceding example can be done more briefly:

pgm: a.o b.o
cc a.o b.o −lm −o pgm

a.o b.o: incl

Prerequisites are inferred according to selected suffixes listed as the “prerequisites” for the special name “.SUFFIXES”. 

The rule to create a file with suffix s2 that depends on a similarly named file with suffix s1 is specified as an entry for the “target” s1s2. In such an entry, the special macro $∗ stands for the target name with suffix deleted, $@ for the full target name, $< for the complete list of prerequisites, and $?  for the list of prerequisites that are out of date.  For example, a rule for making optimized “.o” files from “.c” files is

.c.o: ; cc −c −O −o $@ $∗.c

Special-Purpose Macros

When the MAKEFLAGS variable is present in the environment, make takes options from it, in combination with options entered on the command line.  Make retains this combined value as the MAKEFLAGS macro, and exports it automatically to each command or shell it invokes. 

The MAKE macro is another special case. By default it is set to the name by which make was invoked (normally /usr/bin/make for this version of make), and temporarily overrides the −n option for any line in which it is referred to.  This allows nested invocations of make written as:

$(MAKE) $(MAKEFLAGS) ... 

to run recursively, with the −n flag in effect for all commands but make.  This lets you use “make −n” to test an entire hierarchy of makefiles, with the guarantee that they will all be processed by the same version of make, even if there is more than one. 

The SHELL macro, when set to a single-word value such as /usr/bin/csh, indicates the name of an alternate shell to use.  The default is /usr/bin/sh. Note that make executes commands that contain no shell metacharacters itself.  Built-in commands, such as dirs in the C shell and echo in either shell, are not recognized unless the command line includes a metacharacter (for instance, a semicolon).  The latter is a particularly likely source of bugs, as the program /usr/bin/echo has different semantics from the built-in echo of /usr/bin/sh.

Certain macros are used by the default inference rules to communicate optional arguments to any resulting commands.  In particular, “CFLAGS” is used for cc(1) options, “F77FLAGS” for f77(1) as invoked by $(F77) options, “PFLAGS” for pc(1) options, “ARFLAGS” for ar(1) options, “ASFLAGS” for as(1) options, “GFLAGS” for get options, “RMFLAGS” for rm(1) options, “LDFLAGS” for ld(1) options, “EFLAGS”, “FFLAGS” and “RFLAGS” for f77(1), ratfor(1), and efl(1), as invoked by $(FC) options, “LNFLAGS” for ln(1) options, and “LFLAGS” and “YFLAGS” for lex(1) and yacc(1) options.

Another special macro is “VPATH”.  The “VPATH” macro should be set to a list of directories separated by colons.  When make searches for a file as a result of a dependency relation, it will first search the current directory and then each of the directories on the “VPATH” list.  If the file is found, the actual path to the file will be used, rather than just the filename.  If “VPATH” is not defined, then only the current directory is searched. 

One use for “VPATH” is when one has several programs that compile from the same source.  The source can be kept in one directory and each set of object files (along with a separate makefile) would be in a separate subdirectory. The “VPATH” macro would point to the source directory in this case. 

Dynamic Macros

There are several dynamically maintained macros that are useful as abbreviations within rules.  They are shown here as references; if you were to define them, make would simply override the definition. 

$∗ The basename of the current target, derived as if selected for use with an implicit rule. 

$< The name of a dependency file, derived as if selected for use with an implicit rule. 

$@ The name of the current target.  This is the only dynamic macro whose value is strictly determined when used in a dependency list as opposed to the body of a rule.  See below for how to use this macro in a dependency list. 

$?  The list of dependencies that are newer than the target. 

$% The name of the library member being processed. 

To refer to the $@ dynamic macro within a dependency list, precede the reference with an additional “$” character (as in, “$$@”).  Because make assigns $< and $∗ as it would for implicit rules (according to the suffixes list and the directory contents), they may be unreliable when used within explicit target entries. 

These macros can be modified to apply either to the filename part, or the directory part of the strings they stand for, by adding an upper case F or D, respectively (and enclosing the resulting name in parentheses or braces).  Thus, “$(@D)” refers to the directory part of the string “$@”; if there is no directory part, “.” is assigned.  Similarly $(@F) refers to the filename part. 

Command Execution

Command lines are executed one at a time, each by its own shell.  A line is printed when it is executed unless the special target “.SILENT” is in makefile or the first character of the command is “@”. 

Commands returning nonzero status (see intro(1)) cause make to terminate unless the special target “.IGNORE” is in makefile or the first character of the command is “−”. 

Interrupt and quit cause the target to be deleted unless the target is a directory or is a dependency of the special name “.PRECIOUS”. 

OPTIONS

−f makefile
Use the description file makefile. A “−” as the makefile argument denotes the standard input.  The contents of makefile, when present, override the standard set of implicit rules and predefined macros.  When more than one “−f makefile” argument pair appears, make uses the concatenation of those files, in order of appearance. 

−i Equivalent to the special entry “.IGNORE:”. 

−k When a command returns nonzero status, abandon work on the current entry, but continue on branches that do not depend on the current entry. 

−p Print out the complete set of macro definitions and target descriptions. 

−s Equivalent to the special entry “.SILENT:”. 

−r Equivalent to an initial special entry “.SUFFIXES:” with no list and effectively turns off the built-in rules. 

−n Trace and print, but do not execute the commands needed to update the targets.  All commands are printed, even those which begin with “@”. 

−e Environment variables override assignments within makefiles. 

−t Touch, i.e. update the modified date of targets, without executing any commands. 

−q Query mode, make does not executed any commands, it simply returns a failure code (false exit status) unless the relevant targets are up to date. 

−S When a command returns nonzero status, abandon work on all entries. This is the opposite of −k. 

−g Turn on default $(GET) on files not found.  This is normally off, except when looking for makefile or Makefile.

−d Output debugging information on the progress of the make process. 

FILES

makefile, Makefile

SEE ALSO

sh(1), touch(1), f77(1), pc(1), cc(1). 
S. I. Feldman Make − A Program for Maintaining Computer Programs

NOTES

The shell ie executed with the flags “−ce”.  If the shell defined by “SHELL” does not handle these flags correctly make will not work.  The −c flag indicates that the argument is a command line to execute, the −e flag tells the shell to exit (with a failure code) when some part of the command fails.  The use of the −e flag can be prevented by preceding the command with the “−” character, or using the make -i option.  In some cases, in particular with the if built-in command of /usr/bin/sh, some part of the command is expected to fail - in this case it is essential that the command is not executed with the −e shell flag.  For example:

SHELL=/usr/bin/sh

target1:this one works
-if [ -f file ]; then command1; else command2; fi

target2:this is better
sh -c ’if [ -f file ]; then set -e; command1; else set -e; command2; fi’

The command associated with target1 will work, but fails to detect any errors.  The command associated with target2 is effectively equivalent to the first, however, by setting the −e flag manually within the command and not telling make to ignore errors, errors which do occur in command1 or command2 will be detected and cause the make to terminate. 

The above is portable across many systems.  Systems which have the System V shell, or something derived from it, can acheive the same effect by switching off the −e flag using:

set +e

at the appropriate point in the command.  Notice that, in any case, the shell returns the status of the last executed command, so if command2 in the above examples does not exist (ie if there is no else clause) it is essential to provide it; use:

exit 0

to cause the shell to exit with a success code. 

If in doubt:

• Is the correct shell being used?  Always set the “SHELL” variable in the makefile; unless you want the unpredictable effects of it changing.  Never use the −e flag! 

• Does the command work when executed at the shell command line; examine the status from the command, using $?  for the /usr/bin/sh shell or $status for the C shell.  Use make −n to find out what commands are being executed. 

• Does the command work when executed with the −e flag.  If not, and the command cannot be fixed up appropriately, use a “−” at the start of the command line or switch off the −e flag in some other way (not possible with the C shell). 

Commands which change the internal status of the shell, notably built-in commands such as cd(1), are ineffectual across newlines in make as a new shell is started for each line.  Use continuation lines (escape the newline with a \) to get round this.  As mentioned above make looks for a particular set of shell meta-characters when deciding whether to use the shell; built-in commands are not recognised.  However this rarely matters in practice as such commands are normally combined with other commands using shell meta-characters. 

Using directories as targets is not likely to behave as expected or to be useful.  Instead use a file within the directory which may be updated (or created) as appropriate to indicate the time the directory was last updated. 

BUGS

Make takes note of the SHELL environment variable.  This is never the correct thing to do; it can only be correct if the makefile itself is poorly constructed, in which case the real answer is to fix the makefile. To avoid this problem either do not use make(1V) − use make(1) (ie /usr/ucb/make) instead or, if you need the facilities provided by make(1V), always specify the value of the SHELL macro in the makefile and never use the −e option. 

Make does not check for a more recent SCCS version of an existing file − if both the file and the SCCS archive exist and there is no rule for generating the file make should check the latest entry in the SCCS archive to see if it is more up to date than the file.  Unfortunately this requires considerable knowledge within make about SCCS which would make make very dependent on the particular implementation of the source management system.  Notice that the −g option can currently be used with rcs(1) by providing a shell script to convert SCCS get commands into rcs co commands.  See co(1).

“VPATH” is intended to act like the System V “VPATH” support, but, in the absence of a definitive specification, there is no guarantee that it functions identically. 

The .DEFAULT: rule overrides the built-in SCCS support. 

System V

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026