Programming Utilities Guide

Command Usage

The make Command

The make command takes macro definitions, options, description filenames, and target filenames as arguments in the form:

$ make [ options ] [ macro definitions and targets ]

The following summary of command operations explains how these arguments are interpreted.

First, all macro definition arguments (arguments with embedded = symbols) are analyzed and the assignments made. Command line macros override corresponding definitions found in the description files. Next, the option arguments are examined. The permissible options are as follows:

-i

Ignore error codes returned by invoked commands. This mode is entered if the fake target name .IGNORE appears in the description file.

-s

Silent mode. Do not print command lines before executing. This mode is also entered if the fake target name .SILENT appears in the description file.

-r

Do not use the built-in rules.

-n

No execute mode. Print commands, but do not execute them. Even lines beginning with an @ sign are printed.

-t

Touch the target files (causing them to come up to date) rather than issue the usual commands.

-q

Question. The make command returns a zero or nonzero status code depending on whether the target file is or is not up to date.

-p

Print the complete set of macro definitions and target descriptions.

-k

Abandon work on the current entry if something goes wrong, but continue on other branches that do not depend on the current entry.

-e

Environment variables override assignments within makefiles.

-f

Description filename. The next argument is assumed to be the name of a description file. A file name of - denotes the standard input. If there are no -f arguments, the file named makefile, Makefile, s.makefile, or s.Makefile in the current directory is read. The contents of the description files override the built-in rules if they are present. The following two fake target names are evaluated in the same manner as flags:

.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 if it exists.

.PRECIOUS

Dependents on this target are not removed when Quit or Interrupt is pressed.

Finally, the remaining arguments are assumed to be the names of targets to be made and the arguments are done in left-to-right order. If there are no such arguments, the first name in the description file that does not begin with the symbol . is made.

Environment Variables

Environment variables are read and added to the macro definitions each time make executes. Precedence is a prime consideration in doing this properly. The following describes make's interaction with the environment. A macro, MAKEFLAGS, is maintained by make. The macro is defined as the collection of all input flag arguments into a string (without minus signs). The macro is exported and thus accessible to recursive invocations of make. Command line flags and assignments in the makefile update MAKEFLAGS. Thus, to describe how the environment interacts with make, the MAKEFLAGS macro (environment variable) must be considered.

When executed, make assigns macro definitions in the following order:

  1. Read the MAKEFLAGS environment variable. If it is not present or null, the internal make variable MAKEFLAGS is set to the null string. Otherwise, each letter in MAKEFLAGS is assumed to be an input flag argument and is processed as such. (The only exceptions are the -f, -p, and -r flags.)

  2. Read the internal list of macro definitions.

  3. Read the environment. The environment variables are treated as macro definitions and marked as exported (in the shell sense).

  4. Read the makefile(s). The assignments in the makefile(s) override the environment. This order is chosen so that when a makefile is read and executed, you know what to expect. That is, you get what is seen unless the -e flag is used. The -e is the input flag argument, which tells make to have the environment override the makefile assignments. Thus, if make -e is entered, the variables in the environment override the definitions in the makefile. Also MAKEFLAGS overrides the environment if assigned. This is useful for further invocations of make from the current makefile.

    It might be clearer to list the precedence of assignments. Thus, in order from least binding to most binding, the precedence of assignments is as follows:

  1. Internal definitions

  2. Environment

  3. makefile(s)

  4. Command line

    The -e flag has the effect of rearranging the order to:

  1. Internal definitions

  2. makefile(s)

  3. Environment

  4. Command line

    This order is general enough to allow a programmer to define a makefile or set of makefiles whose parameters are dynamically definable.