Professional Documents
Culture Documents
The ifeq directive begins the conditional, and specifies the condition. It contains two
arguments, separated by a comma and surrounded by parentheses. Variable
substitution is performed on both arguments and then they are compared. The lines
of the makefile following the ifeq are obeyed if the two arguments match; otherwise
they are ignored.
The endif directive ends the conditional. Every conditional must end with an endif.
The syntax of the conditional-directive is the same whether the conditional is simple
or complex; after an else or not.
There are four different directives that test different conditions.
ifeq (arg1, arg2)
ifeq ’arg1’ ’arg2’
ifeq "arg1" "arg2"
ifeq "arg1" ’arg2’
ifeq ’arg1’ "arg2"
Expand all variable references in arg1 and arg2 and compare them. If they are
identical, the text-if-true is effective; otherwise, the text-if-false, if any, is effective.
Often you want to test if a variable has a non-empty value. When the value results
from complex expansions of variables and functions, expansions you would consider
empty may actually contain white-space characters and thus are not seen as empty.
However, you can use the strip function to avoid interpreting white-space as a non-
empty value.
For example:
ifeq ($(strip $(foo)),)
text-if-empty
endif
will evaluate text-if-empty even if the expansion of $(foo) contains white-space
characters.
ifdef variable-name
The ifdef form takes the name of a variable as its argument, not a reference to a
variable. The value of that variable has a non-empty value, the text-if-true is
effective; otherwise, the text-if-false, if any, is effective.
Variables that have never been defined have an empty value.
The text variable-name is expanded, so it could be a variable or function that
expands to the name of a variable.
For example:
bar = true
foo = bar
ifdef $(foo)
frobozz = yes
endif
ifndef variable-name
If the variable variable-name has an empty value, the text-if-true is effective;
otherwise, the text-if-false, if any, is effective. The rules for expansion and testing of
variable-name are identical to the ifdef directive.
The other two directives that play a part in a conditional are else and endif. Each of
these directives is written as one word, with no arguments. Extra spaces are allowed
and ignored at the beginning of the line, and spaces or tabs at the end. Extra spaces
are allowed and ignored at the beginning of the conditional directive line, but a tab is
not allowed. (If the line begins with a tab, it will be considered part of a recipe for a
rule.)
A comment starting with ‘#’ may appear at the end of the line.
When make is given the flag ‘-n’ or ‘--just-print’ it only echoes most recipes, without
executing them. In this case even the recipe lines starting with ‘@’ are printed. This
flag is useful for finding out which recipes make thinks are necessary without actually
doing them.
The ‘-s’ or ‘--silent’ flag to make prevents all echoing, as if all recipes started with
‘@’. A rule in the makefile for the special target .SILENT has the same effect.
Errors in Recipes:
After each shell invocation returns, make looks at its exit status. If the shell
completed successfully (the exit status is zero), the next line in the recipe is
executed in a new shell; after the last line is finished, the rule is finished.
If there is an error (the exit status is nonzero), make gives up on the current rule, and
perhaps on all rules. Sometimes the failure of a certain recipe line does not indicate
a problem.
For example,
you may use the mkdir command to ensure that a directory exists. If the directory
already exists, mkdir will report an error, but you probably want make to continue
regardless.
To ignore errors in a recipe line, write a ‘-’ at the beginning of the line’s text (after the
initial tab). The ‘-’ is discarded before the line is passed to the shell for execution.
For example,
clean:
-rm -f *.o
This causes make to continue even if rm is unable to remove a file.
When you run make with the ‘-i’ or ‘--ignore-errors’ flag, errors are ignored in all
recipes of all rules. A rule in the makefile for the special target .IGNORE has the
same effect.
‘-n’
‘--just-print’
‘--dry-run’
‘--recon’
Print the recipe that would be executed, but do not execute it (except in certain
circumstances)
‘-q’
‘--question’
“Question mode”
Do not run any recipes, or print anything; just return an exit status that is zero if the
specified targets are already up to date, one if any remaking is required, or two if an
error is encountered.
‘-s’
‘--silent’
‘--quiet’
Silent operation; do not print the recipes as they are executed.
‘-v’
‘--version’
Print the version of the make program plus a copyright, a list of authors, and a notice
that there is no warranty; then exit.
‘-t’
‘--touch’
Marks targets as up to date without actually running any recipes.
Touch files (mark them up to date without really changing them) instead of running
their recipes. This is used to pretend that the recipes were done, in order to fool
future invocations of make.