2926
2942
the default goal. *Note How Make Works::.
2929
File: make.info, Node: Commands, Next: Using Variables, Prev: Rules, Up: Top
2931
5 Writing the Commands in Rules
2932
*******************************
2934
The commands of a rule consist of one or more shell command lines to be
2945
File: make.info, Node: Recipes, Next: Using Variables, Prev: Rules, Up: Top
2947
5 Writing Recipes in Rules
2948
**************************
2950
The recipe of a rule consists of one or more shell command lines to be
2935
2951
executed, one at a time, in the order they appear. Typically, the
2936
2952
result of executing these commands is that the target of the rule is
2937
2953
brought up to date.
2939
Users use many different shell programs, but commands in makefiles
2940
are always interpreted by `/bin/sh' unless the makefile specifies
2941
otherwise. *Note Command Execution: Execution.
2955
Users use many different shell programs, but recipes in makefiles are
2956
always interpreted by `/bin/sh' unless the makefile specifies
2957
otherwise. *Note Recipe Execution: Execution.
2945
* Command Syntax:: Command syntax features and pitfalls.
2946
* Echoing:: How to control when commands are echoed.
2947
* Execution:: How commands are executed.
2948
* Parallel:: How commands can be executed in parallel.
2949
* Errors:: What happens after a command execution error.
2950
* Interrupts:: What happens when a command is interrupted.
2961
* Recipe Syntax:: Recipe syntax features and pitfalls.
2962
* Echoing:: How to control when recipes are echoed.
2963
* Execution:: How recipes are executed.
2964
* Parallel:: How recipes can be executed in parallel.
2965
* Errors:: What happens after a recipe execution error.
2966
* Interrupts:: What happens when a recipe is interrupted.
2951
2967
* Recursion:: Invoking `make' from makefiles.
2952
* Sequences:: Defining canned sequences of commands.
2953
* Empty Commands:: Defining useful, do-nothing commands.
2968
* Canned Recipes:: Defining canned recipes.
2969
* Empty Recipes:: Defining useful, do-nothing recipes.
2956
File: make.info, Node: Command Syntax, Next: Echoing, Prev: Commands, Up: Commands
2972
File: make.info, Node: Recipe Syntax, Next: Echoing, Prev: Recipes, Up: Recipes
2961
2977
Makefiles have the unusual property that there are really two distinct
2962
2978
syntaxes in one file. Most of the makefile uses `make' syntax (*note
2963
Writing Makefiles: Makefiles.). However, commands are meant to be
2979
Writing Makefiles: Makefiles.). However, recipes are meant to be
2964
2980
interpreted by the shell and so they are written using shell syntax.
2965
2981
The `make' program does not try to understand shell syntax: it performs
2966
only a very few specific translations on the content of the command
2982
only a very few specific translations on the content of the recipe
2967
2983
before handing it to the shell.
2969
Each command line must start with a tab, except that the first
2970
command line may be attached to the target-and-prerequisites line with a
2971
semicolon in between. _Any_ line in the makefile that begins with a
2972
tab and appears in a "rule context" (that is, after a rule has been
2973
started until another rule or variable definition) will be considered a
2974
command line for that rule. Blank lines and lines of just comments may
2975
appear among the command lines; they are ignored.
2985
Each line in the recipe must start with a tab (or the first character
2986
in the value of the `.RECIPEPREFIX' variable; *note Special
2987
Variables::), except that the first recipe line may be attached to the
2988
target-and-prerequisites line with a semicolon in between. _Any_ line
2989
in the makefile that begins with a tab and appears in a "rule context"
2990
(that is, after a rule has been started until another rule or variable
2991
definition) will be considered part of a recipe for that rule. Blank
2992
lines and lines of just comments may appear among the recipe lines;
2977
2995
Some consequences of these rules include:
2979
2997
* A blank line that begins with a tab is not blank: it's an empty
2980
command (*note Empty Commands::).
2998
recipe (*note Empty Recipes::).
2982
* A comment in a command line is not a `make' comment; it will be
2983
passed to the shell as-is. Whether the shell treats it as a
2984
comment or not depends on your shell.
3000
* A comment in a recipe is not a `make' comment; it will be passed
3001
to the shell as-is. Whether the shell treats it as a comment or
3002
not depends on your shell.
2986
3004
* A variable definition in a "rule context" which is indented by a
2987
tab as the first character on the line, will be considered a
2988
command line, not a `make' variable definition, and passed to the
3005
tab as the first character on the line, will be considered part of
3006
a recipe, not a `make' variable definition, and passed to the
2991
3009
* A conditional expression (`ifdef', `ifeq', etc. *note Syntax of
2992
3010
Conditionals: Conditional Syntax.) in a "rule context" which is
2993
3011
indented by a tab as the first character on the line, will be
2994
considered a command line and be passed to the shell.
3012
considered part of a recipe and be passed to the shell.
2999
* Splitting Lines:: Breaking long command lines for readability.
3000
* Variables in Commands:: Using `make' variables in commands.
3017
* Splitting Recipe Lines:: Breaking long recipe lines for readability.
3018
* Variables in Recipes:: Using `make' variables in recipes.
3003
File: make.info, Node: Splitting Lines, Next: Variables in Commands, Prev: Command Syntax, Up: Command Syntax
3005
5.1.1 Splitting Command Lines
3006
-----------------------------
3008
One of the few ways in which `make' does interpret command lines is
3009
checking for a backslash just before the newline. As in normal
3010
makefile syntax, a single command can be split into multiple lines in
3011
the makefile by placing a backslash before each newline. A sequence of
3012
lines like this is considered a single command, and one instance of the
3013
shell will be invoked to run it.
3021
File: make.info, Node: Splitting Recipe Lines, Next: Variables in Recipes, Prev: Recipe Syntax, Up: Recipe Syntax
3023
5.1.1 Splitting Recipe Lines
3024
----------------------------
3026
One of the few ways in which `make' does interpret recipes is checking
3027
for a backslash just before the newline. As in normal makefile syntax,
3028
a single logical recipe line can be split into multiple physical lines
3029
in the makefile by placing a backslash before each newline. A sequence
3030
of lines like this is considered a single recipe line, and one instance
3031
of the shell will be invoked to run it.
3015
3033
However, in contrast to how they are treated in other places in a
3016
makefile, backslash-newline pairs are _not_ removed from the command.
3017
Both the backslash and the newline characters are preserved and passed
3018
to the shell. How the backslash-newline is interpreted depends on your
3019
shell. If the first character of the next line after the
3020
backslash-newline is a tab, then that tab (and only that tab) is
3021
removed. Whitespace is never added to the command.
3034
makefile (*note Splitting Long Lines: Splitting Lines.),
3035
backslash/newline pairs are _not_ removed from the recipe. Both the
3036
backslash and the newline characters are preserved and passed to the
3037
shell. How the backslash/newline is interpreted depends on your shell.
3038
If the first character of the next line after the backslash/newline is
3039
the recipe prefix character (a tab by default; *note Special
3040
Variables::), then that character (and only that character) is removed.
3041
Whitespace is never added to the recipe.
3023
For example, this makefile:
3043
For example, the recipe for the all target in this makefile:
3356
3444
By default, there is no load limit.
3359
File: make.info, Node: Errors, Next: Interrupts, Prev: Parallel, Up: Commands
3361
5.5 Errors in Commands
3362
======================
3364
After each shell command returns, `make' looks at its exit status. If
3365
the command completed successfully, the next command line is executed
3366
in a new shell; after the last command line is finished, the rule is
3448
* Parallel Output:: Handling output during parallel execution
3449
* Parallel Input:: Handling input during parallel execution
3452
File: make.info, Node: Parallel Output, Next: Parallel Input, Prev: Parallel, Up: Parallel
3454
5.4.1 Output During Parallel Execution
3455
--------------------------------------
3457
When running several recipes in parallel the output from each recipe
3458
appears as soon as it is generated, with the result that messages from
3459
different recipes may be interspersed, sometimes even appearing on the
3460
same line. This can make reading the output very difficult.
3462
To avoid this you can use the `--output-sync' (`-O') option. This
3463
option instructs `make' to save the output from the commands it invokes
3464
and print it all once the commands are completed. Additionally, if
3465
there are multiple recursive `make' invocations running in parallel,
3466
they will communicate so that only one of them is generating output at
3469
If working directory printing is enabled (*note The
3470
`--print-directory' Option: -w Option.), the enter/leave messages are
3471
printed around each output grouping. If you prefer not to see these
3472
messages add the `--no-print-directory' option to `MAKEFLAGS'.
3474
There are four levels of granularity when synchronizing output,
3475
specified by giving an argument to the option (e.g., `-Oline' or
3476
`--output-sync=recurse').
3479
This is the default: all output is sent directly as it is
3480
generated and no synchronization is performed.
3483
Output from each individual line of the recipe is grouped and
3484
printed as soon as that line is complete. If a recipe consists of
3485
multiple lines, they may be interspersed with lines from other
3489
Output from the entire recipe for each target is grouped and
3490
printed once the target is complete. This is the default if the
3491
`--output-sync' or `-O' option is given with no argument.
3494
Output from each recursive invocation of `make' is grouped and
3495
printed once the recursive invocation is complete.
3498
Regardless of the mode chosen, the total build time will be the same.
3499
The only difference is in how the output appears.
3501
The `target' and `recurse' modes both collect the output of the
3502
entire recipe of a target and display it uninterrupted when the recipe
3503
completes. The difference between them is in how recipes that contain
3504
recursive invocations of `make' are treated (*note Recursive Use of
3505
`make': Recursion.). For all recipes which have no recursive lines,
3506
the `target' and `recurse' modes behave identically.
3508
If the `recurse' mode is chosen, recipes that contain recursive
3509
`make' invocations are treated the same as other targets: the output
3510
from the recipe, including the output from the recursive `make', is
3511
saved and printed after the entire recipe is complete. This ensures
3512
output from all the targets built by a given recursive `make' instance
3513
are grouped together, which may make the output easier to understand.
3514
However it also leads to long periods of time during the build where no
3515
output is seen, followed by large bursts of output. If you are not
3516
watching the build as it proceeds, but instead viewing a log of the
3517
build after the fact, this may be the best option for you.
3519
If you are watching the output, the long gaps of quiet during the
3520
build can be frustrating. The `target' output synchronization mode
3521
detects when `make' is going to be invoked recursively, using the
3522
standard methods, and it will not synchronize the output of those
3523
lines. The recursive `make' will perform the synchronization for its
3524
targets and the output from each will be displayed immediately when it
3525
completes. Be aware that output from recursive lines of the recipe are
3526
not synchronized (for example if the recursive line prints a message
3527
before running `make', that message will not be synchronized).
3529
The `line' mode can be useful for front-ends that are watching the
3530
output of `make' to track when recipes are started and completed.
3532
Some programs invoked by `make' may behave differently if they
3533
determine they're writing output to a terminal versus a file (often
3534
described as "interactive" vs. "non-interactive" modes). For example,
3535
many programs that can display colorized output will not do so if they
3536
determine they are not writing to a terminal. If your makefile invokes
3537
a program like this then using the output synchronization options will
3538
cause the program to believe it's running in "non-interactive" mode
3539
even though the output will ultimately go to the terminal.
3542
File: make.info, Node: Parallel Input, Prev: Parallel Output, Up: Parallel
3544
5.4.2 Input During Parallel Execution
3545
-------------------------------------
3547
Two processes cannot both take input from the same device at the same
3548
time. To make sure that only one recipe tries to take input from the
3549
terminal at once, `make' will invalidate the standard input streams of
3550
all but one running recipe. If another recipe attempts to read from
3551
standard input it will usually incur a fatal error (a `Broken pipe'
3554
It is unpredictable which recipe will have a valid standard input
3555
stream (which will come from the terminal, or wherever you redirect the
3556
standard input of `make'). The first recipe run will always get it
3557
first, and the first recipe started after that one finishes will get it
3560
We will change how this aspect of `make' works if we find a better
3561
alternative. In the mean time, you should not rely on any recipe using
3562
standard input at all if you are using the parallel execution feature;
3563
but if you are not using this feature, then standard input works
3564
normally in all recipes.
3567
File: make.info, Node: Errors, Next: Interrupts, Prev: Parallel, Up: Recipes
3569
5.5 Errors in Recipes
3570
=====================
3572
After each shell invocation returns, `make' looks at its exit status.
3573
If the shell completed successfully (the exit status is zero), the next
3574
line in the recipe is executed in a new shell; after the last line is
3575
finished, the rule is finished.
3369
3577
If there is an error (the exit status is nonzero), `make' gives up on
3370
3578
the current rule, and perhaps on all rules.
3372
Sometimes the failure of a certain command does not indicate a
3580
Sometimes the failure of a certain recipe line does not indicate a
3373
3581
problem. For example, you may use the `mkdir' command to ensure that a
3374
3582
directory exists. If the directory already exists, `mkdir' will report
3375
3583
an error, but you probably want `make' to continue regardless.
3377
To ignore errors in a command line, write a `-' at the beginning of
3585
To ignore errors in a recipe line, write a `-' at the beginning of
3378
3586
the line's text (after the initial tab). The `-' is discarded before
3379
the command is passed to the shell for execution.
3587
the line is passed to the shell for execution.
3386
This causes `rm' to continue even if it is unable to remove a file.
3594
This causes `make' to continue even if `rm' is unable to remove a file.
3388
3596
When you run `make' with the `-i' or `--ignore-errors' flag, errors
3389
are ignored in all commands of all rules. A rule in the makefile for
3597
are ignored in all recipes of all rules. A rule in the makefile for
3390
3598
the special target `.IGNORE' has the same effect, if there are no
3391
3599
prerequisites. These ways of ignoring errors are obsolete because `-'
3392
3600
is more flexible.
3394
3602
When errors are to be ignored, because of either a `-' or the `-i'
3395
3603
flag, `make' treats an error return just like success, except that it
3396
prints out a message that tells you the status code the command exited
3604
prints out a message that tells you the status code the shell exited
3397
3605
with, and says that the error has been ignored.
3399
3607
When an error happens that `make' has not been told to ignore, it
3400
3608
implies that the current target cannot be correctly remade, and neither
3401
3609
can any other that depends on it either directly or indirectly. No
3402
further commands will be executed for these targets, since their
3610
further recipes will be executed for these targets, since their
3403
3611
preconditions have not been achieved.
3405
3613
Normally `make' gives up immediately in this circumstance, returning
3870
4093
commands based on the file names involved (*note Using Implicit Rules:
3871
4094
Implicit Rules.).
3873
In command execution, each line of a canned sequence is treated just
4096
In recipe execution, each line of a canned sequence is treated just
3874
4097
as if the line appeared on its own in the rule, preceded by a tab. In
3875
particular, `make' invokes a separate subshell for each line. You can
4098
particular, `make' invokes a separate sub-shell for each line. You can
3876
4099
use the special prefix characters that affect command lines (`@', `-',
3877
and `+') on each line of a canned sequence. *Note Writing the Commands
3878
in Rules: Commands. For example, using this canned sequence:
4100
and `+') on each line of a canned sequence. *Note Writing Recipes in
4101
Rules: Recipes. For example, using this canned sequence:
3881
4104
@echo "frobnicating target $@"
3882
4105
frob-step-1 $< -o $@-step-1
3883
4106
frob-step-2 $@-step-1 -o $@
3886
4109
`make' will not echo the first line, the `echo' command. But it _will_
3887
echo the following two command lines.
4110
echo the following two recipe lines.
3889
On the other hand, prefix characters on the command line that refers
4112
On the other hand, prefix characters on the recipe line that refers
3890
4113
to a canned sequence apply to every line in the sequence. So the rule:
3892
4115
frob.out: frob.in
3895
does not echo _any_ commands. (*Note Command Echoing: Echoing, for a
3896
full explanation of `@'.)
4118
does not echo _any_ recipe lines. (*Note Recipe Echoing: Echoing, for
4119
a full explanation of `@'.)
3899
File: make.info, Node: Empty Commands, Prev: Sequences, Up: Commands
3901
5.9 Using Empty Commands
3902
========================
3904
It is sometimes useful to define commands which do nothing. This is
3905
done simply by giving a command that consists of nothing but
3906
whitespace. For example:
4122
File: make.info, Node: Empty Recipes, Prev: Canned Recipes, Up: Recipes
4124
5.9 Using Empty Recipes
4125
=======================
4127
It is sometimes useful to define recipes which do nothing. This is done
4128
simply by giving a recipe that consists of nothing but whitespace. For
3910
defines an empty command string for `target'. You could also use a
3911
line beginning with a tab character to define an empty command string,
3912
but this would be confusing because such a line looks empty.
3914
You may be wondering why you would want to define a command string
3915
that does nothing. The only reason this is useful is to prevent a
3916
target from getting implicit commands (from implicit rules or the
3917
`.DEFAULT' special target; *note Implicit Rules:: and *note Defining
3918
Last-Resort Default Rules: Last Resort.).
3920
You may be inclined to define empty command strings for targets that
3921
are not actual files, but only exist so that their prerequisites can be
3922
remade. However, this is not the best way to do that, because the
3923
prerequisites may not be remade properly if the target file actually
3924
does exist. *Note Phony Targets: Phony Targets, for a better way to do
4133
defines an empty recipe for `target'. You could also use a line
4134
beginning with a recipe prefix character to define an empty recipe, but
4135
this would be confusing because such a line looks empty.
4137
You may be wondering why you would want to define a recipe that does
4138
nothing. The only reason this is useful is to prevent a target from
4139
getting implicit recipes (from implicit rules or the `.DEFAULT' special
4140
target; *note Implicit Rules:: and *note Defining Last-Resort Default
4141
Rules: Last Resort.).
4143
You may be inclined to define empty recipes for targets that are not
4144
actual files, but only exist so that their prerequisites can be remade.
4145
However, this is not the best way to do that, because the prerequisites
4146
may not be remade properly if the target file actually does exist.
4147
*Note Phony Targets: Phony Targets, for a better way to do this.
3928
File: make.info, Node: Using Variables, Next: Conditionals, Prev: Commands, Up: Top
4150
File: make.info, Node: Using Variables, Next: Conditionals, Prev: Recipes, Up: Top
3930
4152
6 How to Use Variables
3931
4153
**********************
3933
4155
A "variable" is a name defined in a makefile to represent a string of
3934
4156
text, called the variable's "value". These values are substituted by
3935
explicit request into targets, prerequisites, commands, and other parts
4157
explicit request into targets, prerequisites, recipes, and other parts
3936
4158
of the makefile. (In some other versions of `make', variables are
3937
4159
called "macros".)
3939
4161
Variables and functions in all parts of a makefile are expanded when
3940
read, except for the shell commands in rules, the right-hand sides of
3941
variable definitions using `=', and the bodies of variable definitions
3942
using the `define' directive.
4162
read, except for in recipes, the right-hand sides of variable
4163
definitions using `=', and the bodies of variable definitions using the
3944
4166
Variables can represent lists of file names, options to pass to
3945
4167
compilers, programs to run, directories to look in for source files,
3946
4168
directories to write output in, or anything else you can imagine.
3948
A variable name may be any sequence of characters not containing `:',
3949
`#', `=', or leading or trailing whitespace. However, variable names
3950
containing characters other than letters, numbers, and underscores
3951
should be avoided, as they may be given special meanings in the future,
3952
and with some shells they cannot be passed through the environment to a
3953
sub-`make' (*note Communicating Variables to a Sub-`make':
3954
Variables/Recursion.).
4170
A variable name may be any sequence of characters not containing
4171
`:', `#', `=', or whitespace. However, variable names containing
4172
characters other than letters, numbers, and underscores should be
4173
considered carefully, as in some shells they cannot be passed through
4174
the environment to a sub-`make' (*note Communicating Variables to a
4175
Sub-`make': Variables/Recursion.). Variable names beginning with `.'
4176
and an uppercase letter may be given special meaning in future versions
3956
4179
Variable names are case-sensitive. The names `foo', `FOO', and
3957
4180
`Foo' all refer to different variables.
4801
5079
will assign `CFLAGS' the value of `-O' for all targets matching the
5082
If a target matches more than one pattern, the matching
5083
pattern-specific variables with longer stems are interpreted first.
5084
This results in more specific variables taking precedence over the more
5085
generic ones, for example:
5088
$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
5090
lib/%.o: CFLAGS := -fPIC -g
5093
all: foo.o lib/bar.o
5095
In this example the first definition of the `CFLAGS' variable will
5096
be used to update `lib/bar.o' even though the second one also applies
5097
to this target. Pattern-specific variables which result in the same
5098
stem length are considered in the order in which they were defined in
5101
Pattern-specific variables are searched after any target-specific
5102
variables defined explicitly for that target, and before target-specific
5103
variables defined for the parent target.
5106
File: make.info, Node: Suppressing Inheritance, Next: Special Variables, Prev: Pattern-specific, Up: Using Variables
5108
6.13 Suppressing Inheritance
5109
============================
5111
As described in previous sections, `make' variables are inherited by
5112
prerequisites. This capability allows you to modify the behavior of a
5113
prerequisite based on which targets caused it to be rebuilt. For
5114
example, you might set a target-specific variable on a `debug' target,
5115
then running `make debug' will cause that variable to be inherited by
5116
all prerequisites of `debug', while just running `make all' (for
5117
example) would not have that assignment.
5119
Sometimes, however, you may not want a variable to be inherited. For
5120
these situations, `make' provides the `private' modifier. Although
5121
this modifier can be used with any variable assignment, it makes the
5122
most sense with target- and pattern-specific variables. Any variable
5123
marked `private' will be visible to its local target but will not be
5124
inherited by prerequisites of that target. A global variable marked
5125
`private' will be visible in the global scope but will not be inherited
5126
by any target, and hence will not be visible in any recipe.
5128
As an example, consider this makefile:
5131
prog: private EXTRA_CFLAGS = -L/usr/local/lib
5134
Due to the `private' modifier, `a.o' and `b.o' will not inherit the
5135
`EXTRA_CFLAGS' variable assignment from the `prog' target.
5138
File: make.info, Node: Special Variables, Prev: Suppressing Inheritance, Up: Using Variables
5140
6.14 Other Special Variables
5141
============================
5143
GNU `make' supports some variables that have special properties.
5146
Contains the name of each makefile that is parsed by `make', in
5147
the order in which it was parsed. The name is appended just
5148
before `make' begins to parse the makefile. Thus, if the first
5149
thing a makefile does is examine the last word in this variable, it
5150
will be the name of the current makefile. Once the current
5151
makefile has used `include', however, the last word will be the
5152
just-included makefile.
5154
If a makefile named `Makefile' has this content:
5156
name1 := $(lastword $(MAKEFILE_LIST))
5160
name2 := $(lastword $(MAKEFILE_LIST))
5163
@echo name1 = $(name1)
5164
@echo name2 = $(name2)
5166
then you would expect to see this output:
5172
Sets the default goal to be used if no targets were specified on
5173
the command line (*note Arguments to Specify the Goals: Goals.).
5174
The `.DEFAULT_GOAL' variable allows you to discover the current
5175
default goal, restart the default goal selection algorithm by
5176
clearing its value, or to explicitly set the default goal. The
5177
following example illustrates these cases:
5179
# Query the default goal.
5180
ifeq ($(.DEFAULT_GOAL),)
5181
$(warning no default goal is set)
5187
$(warning default goal is $(.DEFAULT_GOAL))
5189
# Reset the default goal.
5195
$(warning default goal is $(.DEFAULT_GOAL))
5198
.DEFAULT_GOAL := foo
5200
This makefile prints:
5202
no default goal is set
5207
Note that assigning more than one target name to `.DEFAULT_GOAL' is
5208
invalid and will result in an error.
5211
This variable is set only if this instance of `make' has restarted
5212
(*note How Makefiles Are Remade: Remaking Makefiles.): it will
5213
contain the number of times this instance has restarted. Note
5214
this is not the same as recursion (counted by the `MAKELEVEL'
5215
variable). You should not set, modify, or export this variable.
5218
The first character of the value of this variable is used as the
5219
character make assumes is introducing a recipe line. If the
5220
variable is empty (as it is by default) that character is the
5221
standard tab character. For example, this is a valid makefile:
5225
> @echo Hello, world
5227
The value of `.RECIPEPREFIX' can be changed multiple times; once
5228
set it stays in effect for all rules parsed until it is modified.
5231
Expands to a list of the _names_ of all global variables defined
5232
so far. This includes variables which have empty values, as well
5233
as built-in variables (*note Variables Used by Implicit Rules:
5234
Implicit Variables.), but does not include any variables which are
5235
only defined in a target-specific context. Note that any value
5236
you assign to this variable will be ignored; it will always return
5240
Expands to a list of special features supported by this version of
5241
`make'. Possible values include, but are not limited to:
5244
Supports `ar' (archive) files using special file name syntax.
5245
*Note Using `make' to Update Archive Files: Archives.
5248
Supports the `-L' (`--check-symlink-times') flag. *Note
5249
Summary of Options: Options Summary.
5252
Supports "else if" non-nested conditionals. *Note Syntax of
5253
Conditionals: Conditional Syntax.
5256
Supports "job server" enhanced parallel builds. *Note
5257
Parallel Execution: Parallel.
5260
Supports the `.ONESHELL' special target. *Note Using One
5264
Supports order-only prerequisites. *Note Types of
5265
Prerequisites: Prerequisite Types.
5268
Supports secondary expansion of prerequisite lists.
5271
Uses the "shortest stem" method of choosing which pattern, of
5272
multiple applicable options, will be used. *Note How
5273
Patterns Match: Pattern Match.
5276
Supports target-specific and pattern-specific variable
5277
assignments. *Note Target-specific Variable Values:
5281
Supports the `undefine' directive. *Note Undefine
5285
Has GNU Guile available as an embedded extension language.
5286
*Note GNU Guile Integration: Guile Integration.
5289
Supports dynamically loadable objects for creating custom
5290
extensions. *Note Loading Dynamic Objects: Loading Objects.
5293
Expands to a list of directories that `make' searches for included
5294
makefiles (*note Including Other Makefiles: Include.).
4805
5298
File: make.info, Node: Conditionals, Next: Functions, Prev: Using Variables, Up: Top
4807
5300
7 Conditional Parts of Makefiles
4808
5301
********************************
4810
A "conditional" causes part of a makefile to be obeyed or ignored
4811
depending on the values of variables. Conditionals can compare the
4812
value of one variable to another, or the value of a variable to a
5303
A "conditional" directive causes part of a makefile to be obeyed or
5304
ignored depending on the values of variables. Conditionals can compare
5305
the value of one variable to another, or the value of a variable to a
4813
5306
constant string. Conditionals control what `make' actually "sees" in
4814
the makefile, so they _cannot_ be used to control shell commands at the
5307
the makefile, so they _cannot_ be used to control recipes at the time
6431
7006
correct them all before the next attempt to compile. This is why Emacs'
6432
7007
`M-x compile' command passes the `-k' flag by default.
6435
File: make.info, Node: Options Summary, Prev: Testing, Up: Running
6437
9.7 Summary of Options
6438
======================
6440
Here is a table of all the options `make' understands:
6444
These options are ignored for compatibility with other versions of
6449
Consider all targets out-of-date. GNU `make' proceeds to consider
6450
targets and their prerequisites using the normal algorithms;
6451
however, all targets so considered are always remade regardless of
6452
the status of their prerequisites. To avoid infinite recursion, if
6453
`MAKE_RESTARTS' (*note Other Special Variables: Special
6454
Variables.) is set to a number greater than 0 this option is
6455
disabled when considering whether to remake makefiles (*note How
6456
Makefiles Are Remade: Remaking Makefiles.).
6460
Change to directory DIR before reading the makefiles. If multiple
6461
`-C' options are specified, each is interpreted relative to the
6462
previous one: `-C / -C etc' is equivalent to `-C /etc'. This is
6463
typically used with recursive invocations of `make' (*note
6464
Recursive Use of `make': Recursion.).
6467
Print debugging information in addition to normal processing. The
6468
debugging information says which files are being considered for
6469
remaking, which file-times are being compared and with what
6470
results, which files actually need to be remade, which implicit
6471
rules are considered and which are applied--everything interesting
6472
about how `make' decides what to do. The `-d' option is
6473
equivalent to `--debug=a' (see below).
6476
Print debugging information in addition to normal processing.
6477
Various levels and types of output can be chosen. With no
6478
arguments, print the "basic" level of debugging. Possible
6479
arguments are below; only the first character is considered, and
6480
values must be comma- or space-separated.
6483
All types of debugging output are enabled. This is
6484
equivalent to using `-d'.
6487
Basic debugging prints each target that was found to be
6488
out-of-date, and whether the build was successful or not.
6491
A level above `basic'; includes messages about which
6492
makefiles were parsed, prerequisites that did not need to be
6493
rebuilt, etc. This option also enables `basic' messages.
6496
Prints messages describing the implicit rule searches for
6497
each target. This option also enables `basic' messages.
6500
Prints messages giving details on the invocation of specific
6504
By default, the above messages are not enabled while trying
6505
to remake the makefiles. This option enables messages while
6506
rebuilding makefiles, too. Note that the `all' option does
6507
enable this option. This option also enables `basic'
6511
`--environment-overrides'
6512
Give variables taken from the environment precedence over
6513
variables from makefiles. *Note Variables from the Environment:
6519
Read the file named FILE as a makefile. *Note Writing Makefiles:
6524
Remind you of the options that `make' understands and then exit.
6528
Ignore all errors in commands executed to remake files. *Note
6529
Errors in Commands: Errors.
6533
Specifies a directory DIR to search for included makefiles. *Note
6534
Including Other Makefiles: Include. If several `-I' options are
6535
used to specify several directories, the directories are searched
6536
in the order specified.
6540
Specifies the number of jobs (commands) to run simultaneously.
6541
With no argument, `make' runs as many jobs simultaneously as
6542
possible. If there is more than one `-j' option, the last one is
6543
effective. *Note Parallel Execution: Parallel, for more
6544
information on how commands are run. Note that this option is
6549
Continue as much as possible after an error. While the target that
6550
failed, and those that depend on it, cannot be remade, the other
6551
prerequisites of these targets can be processed all the same.
6552
*Note Testing the Compilation of a Program: Testing.
6555
`--load-average[=LOAD]'
6557
Specifies that no new jobs (commands) should be started if there
6558
are other jobs running and the load average is at least LOAD (a
6559
floating-point number). With no argument, removes a previous load
6560
limit. *Note Parallel Execution: Parallel.
6563
`--check-symlink-times'
6564
On systems that support symbolic links, this option causes `make'
6565
to consider the timestamps on any symbolic links in addition to the
6566
timestamp on the file referenced by those links. When this option
6567
is provided, the most recent timestamp among the file and the
6568
symbolic links is taken as the modification time for this target
6575
Print the commands that would be executed, but do not execute them.
6576
*Note Instead of Executing the Commands: Instead of Execution.
6581
Do not remake the file FILE even if it is older than its
6582
prerequisites, and do not remake anything on account of changes in
6583
FILE. Essentially the file is treated as very old and its rules
6584
are ignored. *Note Avoiding Recompilation of Some Files: Avoiding
6589
Print the data base (rules and variable values) that results from
6590
reading the makefiles; then execute as usual or as otherwise
6591
specified. This also prints the version information given by the
6592
`-v' switch (see below). To print the data base without trying to
6593
remake any files, use `make -qp'. To print the data base of
6594
predefined rules and variables, use `make -p -f /dev/null'. The
6595
data base output contains filename and linenumber information for
6596
command and variable definitions, so it can be a useful debugging
6597
tool in complex environments.
6601
"Question mode". Do not run any commands, or print anything; just
6602
return an exit status that is zero if the specified targets are
6603
already up to date, one if any remaking is required, or two if an
6604
error is encountered. *Note Instead of Executing the Commands:
6605
Instead of Execution.
6608
`--no-builtin-rules'
6609
Eliminate use of the built-in implicit rules (*note Using Implicit
6610
Rules: Implicit Rules.). You can still define your own by writing
6611
pattern rules (*note Defining and Redefining Pattern Rules:
6612
Pattern Rules.). The `-r' option also clears out the default list
6613
of suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
6614
Suffix Rules.). But you can still define your own suffixes with a
6615
rule for `.SUFFIXES', and then define your own suffix rules. Note
6616
that only _rules_ are affected by the `-r' option; default
6617
variables remain in effect (*note Variables Used by Implicit
6618
Rules: Implicit Variables.); see the `-R' option below.
6621
`--no-builtin-variables'
6622
Eliminate use of the built-in rule-specific variables (*note
6623
Variables Used by Implicit Rules: Implicit Variables.). You can
6624
still define your own, of course. The `-R' option also
6625
automatically enables the `-r' option (see above), since it
6626
doesn't make sense to have implicit rules without any definitions
6627
for the variables that they use.
6632
Silent operation; do not print the commands as they are executed.
6633
*Note Command Echoing: Echoing.
6638
Cancel the effect of the `-k' option. This is never necessary
6639
except in a recursive `make' where `-k' might be inherited from
6640
the top-level `make' via `MAKEFLAGS' (*note Recursive Use of
6641
`make': Recursion.) or if you set `-k' in `MAKEFLAGS' in your
6646
Touch files (mark them up to date without really changing them)
6647
instead of running their commands. This is used to pretend that
6648
the commands were done, in order to fool future invocations of
6649
`make'. *Note Instead of Executing the Commands: Instead of
6654
Print the version of the `make' program plus a copyright, a list
6655
of authors, and a notice that there is no warranty; then exit.
6659
Print a message containing the working directory both before and
6660
after executing the makefile. This may be useful for tracking
6661
down errors from complicated nests of recursive `make' commands.
6662
*Note Recursive Use of `make': Recursion. (In practice, you
6663
rarely need to specify this option since `make' does it for you;
6664
see *Note The `--print-directory' Option: -w Option.)
6666
`--no-print-directory'
6667
Disable printing of the working directory under `-w'. This option
6668
is useful when `-w' is turned on automatically, but you do not
6669
want to see the extra messages. *Note The `--print-directory'
6676
Pretend that the target FILE has just been modified. When used
6677
with the `-n' flag, this shows you what would happen if you were
6678
to modify that file. Without `-n', it is almost the same as
6679
running a `touch' command on the given file before running `make',
6680
except that the modification time is changed only in the
6681
imagination of `make'. *Note Instead of Executing the Commands:
6682
Instead of Execution.
6684
`--warn-undefined-variables'
6685
Issue a warning message whenever `make' sees a reference to an
6686
undefined variable. This can be helpful when you are trying to
6687
debug makefiles which use variables in complex ways.
6690
File: make.info, Node: Implicit Rules, Next: Archives, Prev: Running, Up: Top
6692
10 Using Implicit Rules
6693
***********************
6695
Certain standard ways of remaking target files are used very often. For
6696
example, one customary way to make an object file is from a C source
6697
file using the C compiler, `cc'.
6699
"Implicit rules" tell `make' how to use customary techniques so that
6700
you do not have to specify them in detail when you want to use them.
6701
For example, there is an implicit rule for C compilation. File names
6702
determine which implicit rules are run. For example, C compilation
6703
typically takes a `.c' file and makes a `.o' file. So `make' applies
6704
the implicit rule for C compilation when it sees this combination of
6707
A chain of implicit rules can apply in sequence; for example, `make'
6708
will remake a `.o' file from a `.y' file by way of a `.c' file.
6710
The built-in implicit rules use several variables in their commands
6711
so that, by changing the values of the variables, you can change the
6712
way the implicit rule works. For example, the variable `CFLAGS'
6713
controls the flags given to the C compiler by the implicit rule for C
6716
You can define your own implicit rules by writing "pattern rules".
6718
"Suffix rules" are a more limited way to define implicit rules.
6719
Pattern rules are more general and clearer, but suffix rules are
6720
retained for compatibility.
6724
* Using Implicit:: How to use an existing implicit rule
6725
to get the commands for updating a file.
6726
* Catalogue of Rules:: A list of built-in implicit rules.
6727
* Implicit Variables:: How to change what predefined rules do.
6728
* Chained Rules:: How to use a chain of implicit rules.
6729
* Pattern Rules:: How to define new implicit rules.
6730
* Last Resort:: How to define commands for rules which
6732
* Suffix Rules:: The old-fashioned style of implicit rule.
6733
* Implicit Rule Search:: The precise algorithm for applying
6737
File: make.info, Node: Using Implicit, Next: Catalogue of Rules, Prev: Implicit Rules, Up: Implicit Rules
6739
10.1 Using Implicit Rules
6740
=========================
6742
To allow `make' to find a customary method for updating a target file,
6743
all you have to do is refrain from specifying commands yourself. Either
6744
write a rule with no command lines, or don't write a rule at all. Then
6745
`make' will figure out which implicit rule to use based on which kind
6746
of source file exists or can be made.
6748
For example, suppose the makefile looks like this:
6751
cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
6753
Because you mention `foo.o' but do not give a rule for it, `make' will
6754
automatically look for an implicit rule that tells how to update it.
6755
This happens whether or not the file `foo.o' currently exists.
6757
If an implicit rule is found, it can supply both commands and one or
6758
more prerequisites (the source files). You would want to write a rule
6759
for `foo.o' with no command lines if you need to specify additional
6760
prerequisites, such as header files, that the implicit rule cannot
6763
Each implicit rule has a target pattern and prerequisite patterns.
6764
There may be many implicit rules with the same target pattern. For
6765
example, numerous rules make `.o' files: one, from a `.c' file with the
6766
C compiler; another, from a `.p' file with the Pascal compiler; and so
6767
on. The rule that actually applies is the one whose prerequisites
6768
exist or can be made. So, if you have a file `foo.c', `make' will run
6769
the C compiler; otherwise, if you have a file `foo.p', `make' will run
6770
the Pascal compiler; and so on.
6772
Of course, when you write the makefile, you know which implicit rule
6773
you want `make' to use, and you know it will choose that one because you
6774
know which possible prerequisite files are supposed to exist. *Note
6775
Catalogue of Implicit Rules: Catalogue of Rules, for a catalogue of all
6776
the predefined implicit rules.
6778
Above, we said an implicit rule applies if the required
6779
prerequisites "exist or can be made". A file "can be made" if it is
6780
mentioned explicitly in the makefile as a target or a prerequisite, or
6781
if an implicit rule can be recursively found for how to make it. When
6782
an implicit prerequisite is the result of another implicit rule, we say
6783
that "chaining" is occurring. *Note Chains of Implicit Rules: Chained
6786
In general, `make' searches for an implicit rule for each target, and
6787
for each double-colon rule, that has no commands. A file that is
6788
mentioned only as a prerequisite is considered a target whose rule
6789
specifies nothing, so implicit rule search happens for it. *Note
6790
Implicit Rule Search Algorithm: Implicit Rule Search, for the details
6791
of how the search is done.
6793
Note that explicit prerequisites do not influence implicit rule
6794
search. For example, consider this explicit rule:
6798
The prerequisite on `foo.p' does not necessarily mean that `make' will
6799
remake `foo.o' according to the implicit rule to make an object file, a
6800
`.o' file, from a Pascal source file, a `.p' file. For example, if
6801
`foo.c' also exists, the implicit rule to make an object file from a C
6802
source file is used instead, because it appears before the Pascal rule
6803
in the list of predefined implicit rules (*note Catalogue of Implicit
6804
Rules: Catalogue of Rules.).
6806
If you do not want an implicit rule to be used for a target that has
6807
no commands, you can give that target empty commands by writing a
6808
semicolon (*note Defining Empty Commands: Empty Commands.).
6811
File: make.info, Node: Catalogue of Rules, Next: Implicit Variables, Prev: Using Implicit, Up: Implicit Rules
6813
10.2 Catalogue of Implicit Rules
6814
================================
6816
Here is a catalogue of predefined implicit rules which are always
6817
available unless the makefile explicitly overrides or cancels them.
6818
*Note Canceling Implicit Rules: Canceling Rules, for information on
6819
canceling or overriding an implicit rule. The `-r' or
6820
`--no-builtin-rules' option cancels all predefined rules.
6822
This manual only documents the default rules available on POSIX-based
6823
operating systems. Other operating systems, such as VMS, Windows,
6824
OS/2, etc. may have different sets of default rules. To see the full
6825
list of default rules and variables available in your version of GNU
6826
`make', run `make -p' in a directory with no makefile.
6828
Not all of these rules will always be defined, even when the `-r'
6829
option is not given. Many of the predefined implicit rules are
6830
implemented in `make' as suffix rules, so which ones will be defined
6831
depends on the "suffix list" (the list of prerequisites of the special
6832
target `.SUFFIXES'). The default suffix list is: `.out', `.a', `.ln',
6833
`.o', `.c', `.cc', `.C', `.cpp', `.p', `.f', `.F', `.r', `.y', `.l',
6834
`.s', `.S', `.mod', `.sym', `.def', `.h', `.info', `.dvi', `.tex',
6835
`.texinfo', `.texi', `.txinfo', `.w', `.ch' `.web', `.sh', `.elc',
6836
`.el'. All of the implicit rules described below whose prerequisites
6837
have one of these suffixes are actually suffix rules. If you modify
6838
the suffix list, the only predefined suffix rules in effect will be
6839
those named by one or two of the suffixes that are on the list you
6840
specify; rules whose suffixes fail to be on the list are disabled.
6841
*Note Old-Fashioned Suffix Rules: Suffix Rules, for full details on
6844
Compiling C programs
6845
`N.o' is made automatically from `N.c' with a command of the form
6846
`$(CC) -c $(CPPFLAGS) $(CFLAGS)'.
6848
Compiling C++ programs
6849
`N.o' is made automatically from `N.cc', `N.cpp', or `N.C' with a
6850
command of the form `$(CXX) -c $(CPPFLAGS) $(CXXFLAGS)'. We
6851
encourage you to use the suffix `.cc' for C++ source files instead
6854
Compiling Pascal programs
6855
`N.o' is made automatically from `N.p' with the command `$(PC) -c
6858
Compiling Fortran and Ratfor programs
6859
`N.o' is made automatically from `N.r', `N.F' or `N.f' by running
6860
the Fortran compiler. The precise command used is as follows:
6863
`$(FC) -c $(FFLAGS)'.
6866
`$(FC) -c $(FFLAGS) $(CPPFLAGS)'.
6869
`$(FC) -c $(FFLAGS) $(RFLAGS)'.
6871
Preprocessing Fortran and Ratfor programs
6872
`N.f' is made automatically from `N.r' or `N.F'. This rule runs
6873
just the preprocessor to convert a Ratfor or preprocessable
6874
Fortran program into a strict Fortran program. The precise
6875
command used is as follows:
6878
`$(FC) -F $(CPPFLAGS) $(FFLAGS)'.
6881
`$(FC) -F $(FFLAGS) $(RFLAGS)'.
6883
Compiling Modula-2 programs
6884
`N.sym' is made from `N.def' with a command of the form `$(M2C)
6885
$(M2FLAGS) $(DEFFLAGS)'. `N.o' is made from `N.mod'; the form is:
6886
`$(M2C) $(M2FLAGS) $(MODFLAGS)'.
6888
Assembling and preprocessing assembler programs
6889
`N.o' is made automatically from `N.s' by running the assembler,
6890
`as'. The precise command is `$(AS) $(ASFLAGS)'.
6892
`N.s' is made automatically from `N.S' by running the C
6893
preprocessor, `cpp'. The precise command is `$(CPP) $(CPPFLAGS)'.
6895
Linking a single object file
6896
`N' is made automatically from `N.o' by running the linker
6897
(usually called `ld') via the C compiler. The precise command
6898
used is `$(CC) $(LDFLAGS) N.o $(LOADLIBES) $(LDLIBS)'.
6900
This rule does the right thing for a simple program with only one
6901
source file. It will also do the right thing if there are multiple
6902
object files (presumably coming from various other source files),
6903
one of which has a name matching that of the executable file.
6908
when `x.c', `y.c' and `z.c' all exist will execute:
6918
In more complicated cases, such as when there is no object file
6919
whose name derives from the executable file name, you must write
6920
an explicit command for linking.
6922
Each kind of file automatically made into `.o' object files will
6923
be automatically linked by using the compiler (`$(CC)', `$(FC)' or
6924
`$(PC)'; the C compiler `$(CC)' is used to assemble `.s' files)
6925
without the `-c' option. This could be done by using the `.o'
6926
object files as intermediates, but it is faster to do the
6927
compiling and linking in one step, so that's how it's done.
6930
`N.c' is made automatically from `N.y' by running Yacc with the
6931
command `$(YACC) $(YFLAGS)'.
6934
`N.c' is made automatically from `N.l' by running Lex. The actual
6935
command is `$(LEX) $(LFLAGS)'.
6937
Lex for Ratfor programs
6938
`N.r' is made automatically from `N.l' by running Lex. The actual
6939
command is `$(LEX) $(LFLAGS)'.
6941
The convention of using the same suffix `.l' for all Lex files
6942
regardless of whether they produce C code or Ratfor code makes it
6943
impossible for `make' to determine automatically which of the two
6944
languages you are using in any particular case. If `make' is
6945
called upon to remake an object file from a `.l' file, it must
6946
guess which compiler to use. It will guess the C compiler, because
6947
that is more common. If you are using Ratfor, make sure `make'
6948
knows this by mentioning `N.r' in the makefile. Or, if you are
6949
using Ratfor exclusively, with no C files, remove `.c' from the
6950
list of implicit rule suffixes with:
6953
.SUFFIXES: .o .r .f .l ...
6955
Making Lint Libraries from C, Yacc, or Lex programs
6956
`N.ln' is made from `N.c' by running `lint'. The precise command
6957
is `$(LINT) $(LINTFLAGS) $(CPPFLAGS) -i'. The same command is
6958
used on the C code produced from `N.y' or `N.l'.
6961
`N.dvi' is made from `N.tex' with the command `$(TEX)'. `N.tex'
6962
is made from `N.web' with `$(WEAVE)', or from `N.w' (and from
6963
`N.ch' if it exists or can be made) with `$(CWEAVE)'. `N.p' is
6964
made from `N.web' with `$(TANGLE)' and `N.c' is made from `N.w'
6965
(and from `N.ch' if it exists or can be made) with `$(CTANGLE)'.
6968
`N.dvi' is made from `N.texinfo', `N.texi', or `N.txinfo', with
6969
the command `$(TEXI2DVI) $(TEXI2DVI_FLAGS)'. `N.info' is made from
6970
`N.texinfo', `N.texi', or `N.txinfo', with the command
6971
`$(MAKEINFO) $(MAKEINFO_FLAGS)'.
6974
Any file `N' is extracted if necessary from an RCS file named
6975
either `N,v' or `RCS/N,v'. The precise command used is
6976
`$(CO) $(COFLAGS)'. `N' will not be extracted from RCS if it
6977
already exists, even if the RCS file is newer. The rules for RCS
6978
are terminal (*note Match-Anything Pattern Rules: Match-Anything
6979
Rules.), so RCS files cannot be generated from another source;
6980
they must actually exist.
6983
Any file `N' is extracted if necessary from an SCCS file named
6984
either `s.N' or `SCCS/s.N'. The precise command used is
6985
`$(GET) $(GFLAGS)'. The rules for SCCS are terminal (*note
6986
Match-Anything Pattern Rules: Match-Anything Rules.), so SCCS
6987
files cannot be generated from another source; they must actually
6990
For the benefit of SCCS, a file `N' is copied from `N.sh' and made
6991
executable (by everyone). This is for shell scripts that are
6992
checked into SCCS. Since RCS preserves the execution permission
6993
of a file, you do not need to use this feature with RCS.
6995
We recommend that you avoid using of SCCS. RCS is widely held to
6996
be superior, and is also free. By choosing free software in place
6997
of comparable (or inferior) proprietary software, you support the
6998
free software movement.
7000
Usually, you want to change only the variables listed in the table
7001
above, which are documented in the following section.
7003
However, the commands in built-in implicit rules actually use
7004
variables such as `COMPILE.c', `LINK.p', and `PREPROCESS.S', whose
7005
values contain the commands listed above.
7007
`make' follows the convention that the rule to compile a `.X' source
7008
file uses the variable `COMPILE.X'. Similarly, the rule to produce an
7009
executable from a `.X' file uses `LINK.X'; and the rule to preprocess a
7010
`.X' file uses `PREPROCESS.X'.
7012
Every rule that produces an object file uses the variable
7013
`OUTPUT_OPTION'. `make' defines this variable either to contain `-o
7014
$@', or to be empty, depending on a compile-time option. You need the
7015
`-o' option to ensure that the output goes into the right file when the
7016
source file is in a different directory, as when using `VPATH' (*note
7017
Directory Search::). However, compilers on some systems do not accept
7018
a `-o' switch for object files. If you use such a system, and use
7019
`VPATH', some compilations will put their output in the wrong place. A
7020
possible workaround for this problem is to give `OUTPUT_OPTION' the
7021
value `; mv $*.o $@'.
7024
File: make.info, Node: Implicit Variables, Next: Chained Rules, Prev: Catalogue of Rules, Up: Implicit Rules
7026
10.3 Variables Used by Implicit Rules
7027
=====================================
7029
The commands in built-in implicit rules make liberal use of certain
7030
predefined variables. You can alter the values of these variables in
7031
the makefile, with arguments to `make', or in the environment to alter
7032
how the implicit rules work without redefining the rules themselves.
7033
You can cancel all variables used by implicit rules with the `-R' or
7034
`--no-builtin-variables' option.
7036
For example, the command used to compile a C source file actually
7037
says `$(CC) -c $(CFLAGS) $(CPPFLAGS)'. The default values of the
7038
variables used are `cc' and nothing, resulting in the command `cc -c'.
7039
By redefining `CC' to `ncc', you could cause `ncc' to be used for all C
7040
compilations performed by the implicit rule. By redefining `CFLAGS' to
7041
be `-g', you could pass the `-g' option to each compilation. _All_
7042
implicit rules that do C compilation use `$(CC)' to get the program
7043
name for the compiler and _all_ include `$(CFLAGS)' among the arguments
7044
given to the compiler.
7046
The variables used in implicit rules fall into two classes: those
7047
that are names of programs (like `CC') and those that contain arguments
7048
for the programs (like `CFLAGS'). (The "name of a program" may also
7049
contain some command arguments, but it must start with an actual
7050
executable program name.) If a variable value contains more than one
7051
argument, separate them with spaces.
7053
The following tables describe of some of the more commonly-used
7054
predefined variables. This list is not exhaustive, and the default
7055
values shown here may not be what are selected by `make' for your
7056
environment. To see the complete list of predefined variables for your
7057
instance of GNU `make' you can run `make -p' in a directory with no
7060
Here is a table of some of the more common variables used as names of
7061
programs in built-in rules: makefiles.
7064
Archive-maintaining program; default `ar'.
7067
Program for compiling assembly files; default `as'.
7070
Program for compiling C programs; default `cc'.
7073
Program for checking out files from RCS; default `co'.
7076
Program for compiling C++ programs; default `g++'.
7079
Program for extracting a file from RCS; default `co'.
7082
Program for running the C preprocessor, with results to standard
7083
output; default `$(CC) -E'.
7086
Program for compiling or preprocessing Fortran and Ratfor programs;
7090
Program for extracting a file from SCCS; default `get'.
7093
Program to use to turn Lex grammars into source code; default
7097
Program to use to turn Yacc grammars into source code; default
7101
Program to use to run lint on source code; default `lint'.
7104
Program to use to compile Modula-2 source code; default `m2c'.
7107
Program for compiling Pascal programs; default `pc'.
7110
Program to convert a Texinfo source file into an Info file; default
7114
Program to make TeX DVI files from TeX source; default `tex'.
7117
Program to make TeX DVI files from Texinfo source; default
7121
Program to translate Web into TeX; default `weave'.
7124
Program to translate C Web into TeX; default `cweave'.
7127
Program to translate Web into Pascal; default `tangle'.
7130
Program to translate C Web into C; default `ctangle'.
7133
Command to remove a file; default `rm -f'.
7135
Here is a table of variables whose values are additional arguments
7136
for the programs above. The default values for all of these is the
7137
empty string, unless otherwise noted.
7140
Flags to give the archive-maintaining program; default `rv'.
7143
Extra flags to give to the assembler (when explicitly invoked on a
7147
Extra flags to give to the C compiler.
7150
Extra flags to give to the C++ compiler.
7153
Extra flags to give to the RCS `co' program.
7156
Extra flags to give to the C preprocessor and programs that use it
7157
(the C and Fortran compilers).
7160
Extra flags to give to the Fortran compiler.
7163
Extra flags to give to the SCCS `get' program.
7166
Extra flags to give to compilers when they are supposed to invoke
7170
Extra flags to give to Lex.
7173
Extra flags to give to Yacc.
7176
Extra flags to give to the Pascal compiler.
7179
Extra flags to give to the Fortran compiler for Ratfor programs.
7182
Extra flags to give to lint.
7185
File: make.info, Node: Chained Rules, Next: Pattern Rules, Prev: Implicit Variables, Up: Implicit Rules
7187
10.4 Chains of Implicit Rules
7188
=============================
7190
Sometimes a file can be made by a sequence of implicit rules. For
7191
example, a file `N.o' could be made from `N.y' by running first Yacc
7192
and then `cc'. Such a sequence is called a "chain".
7194
If the file `N.c' exists, or is mentioned in the makefile, no
7195
special searching is required: `make' finds that the object file can be
7196
made by C compilation from `N.c'; later on, when considering how to
7197
make `N.c', the rule for running Yacc is used. Ultimately both `N.c'
7198
and `N.o' are updated.
7200
However, even if `N.c' does not exist and is not mentioned, `make'
7201
knows how to envision it as the missing link between `N.o' and `N.y'!
7202
In this case, `N.c' is called an "intermediate file". Once `make' has
7203
decided to use the intermediate file, it is entered in the data base as
7204
if it had been mentioned in the makefile, along with the implicit rule
7205
that says how to create it.
7207
Intermediate files are remade using their rules just like all other
7208
files. But intermediate files are treated differently in two ways.
7210
The first difference is what happens if the intermediate file does
7211
not exist. If an ordinary file B does not exist, and `make' considers
7212
a target that depends on B, it invariably creates B and then updates
7213
the target from B. But if B is an intermediate file, then `make' can
7214
leave well enough alone. It won't bother updating B, or the ultimate
7215
target, unless some prerequisite of B is newer than that target or
7216
there is some other reason to update that target.
7218
The second difference is that if `make' _does_ create B in order to
7219
update something else, it deletes B later on after it is no longer
7220
needed. Therefore, an intermediate file which did not exist before
7221
`make' also does not exist after `make'. `make' reports the deletion
7222
to you by printing a `rm -f' command showing which file it is deleting.
7224
Ordinarily, a file cannot be intermediate if it is mentioned in the
7225
makefile as a target or prerequisite. However, you can explicitly mark
7226
a file as intermediate by listing it as a prerequisite of the special
7227
target `.INTERMEDIATE'. This takes effect even if the file is mentioned
7228
explicitly in some other way.
7230
You can prevent automatic deletion of an intermediate file by
7231
marking it as a "secondary" file. To do this, list it as a
7232
prerequisite of the special target `.SECONDARY'. When a file is
7233
secondary, `make' will not create the file merely because it does not
7234
already exist, but `make' does not automatically delete the file.
7235
Marking a file as secondary also marks it as intermediate.
7237
You can list the target pattern of an implicit rule (such as `%.o')
7238
as a prerequisite of the special target `.PRECIOUS' to preserve
7239
intermediate files made by implicit rules whose target patterns match
7240
that file's name; see *Note Interrupts::.
7242
A chain can involve more than two implicit rules. For example, it is
7243
possible to make a file `foo' from `RCS/foo.y,v' by running RCS, Yacc
7244
and `cc'. Then both `foo.y' and `foo.c' are intermediate files that
7245
are deleted at the end.
7247
No single implicit rule can appear more than once in a chain. This
7248
means that `make' will not even consider such a ridiculous thing as
7249
making `foo' from `foo.o.o' by running the linker twice. This
7250
constraint has the added benefit of preventing any infinite loop in the
7251
search for an implicit rule chain.
7253
There are some special implicit rules to optimize certain cases that
7254
would otherwise be handled by rule chains. For example, making `foo'
7255
from `foo.c' could be handled by compiling and linking with separate
7256
chained rules, using `foo.o' as an intermediate file. But what
7257
actually happens is that a special rule for this case does the
7258
compilation and linking with a single `cc' command. The optimized rule
7259
is used in preference to the step-by-step chain because it comes
7260
earlier in the ordering of rules.