1
This is make.info, produced by makeinfo version 4.0 from make.texinfo.
3
INFO-DIR-SECTION GNU Packages
5
* Make: (make). Remake files automatically.
8
This file documents the GNU Make utility, which determines
9
automatically which pieces of a large program need to be recompiled,
10
and issues the commands to recompile them.
12
This is Edition 0.54, last updated 09 September 1999, of `The GNU
13
Make Manual', for `make', Version 3.78.1.
15
Copyright (C) 1988, '89, '90, '91, '92, '93, '94, '95, '96, '97,
16
'98, '99 Free Software Foundation, Inc.
18
Permission is granted to make and distribute verbatim copies of this
19
manual provided the copyright notice and this permission notice are
20
preserved on all copies.
22
Permission is granted to copy and distribute modified versions of
23
this manual under the conditions for verbatim copying, provided that
24
the entire resulting derived work is distributed under the terms of a
25
permission notice identical to this one.
27
Permission is granted to copy and distribute translations of this
28
manual into another language, under the above conditions for modified
29
versions, except that this permission notice may be stated in a
30
translation approved by the Free Software Foundation.
33
File: make.info, Node: File Name Functions, Next: Foreach Function, Prev: Text Functions, Up: Functions
35
Functions for File Names
36
========================
38
Several of the built-in expansion functions relate specifically to
39
taking apart file names or lists of file names.
41
Each of the following functions performs a specific transformation
42
on a file name. The argument of the function is regarded as a series
43
of file names, separated by whitespace. (Leading and trailing
44
whitespace is ignored.) Each file name in the series is transformed in
45
the same way and the results are concatenated with single spaces
49
Extracts the directory-part of each file name in NAMES. The
50
directory-part of the file name is everything up through (and
51
including) the last slash in it. If the file name contains no
52
slash, the directory part is the string `./'. For example,
54
$(dir src/foo.c hacks)
56
produces the result `src/ ./'.
59
Extracts all but the directory-part of each file name in NAMES.
60
If the file name contains no slash, it is left unchanged.
61
Otherwise, everything through the last slash is removed from it.
63
A file name that ends with a slash becomes an empty string. This
64
is unfortunate, because it means that the result does not always
65
have the same number of whitespace-separated file names as the
66
argument had; but we do not see any other valid alternative.
70
$(notdir src/foo.c hacks)
72
produces the result `foo.c hacks'.
75
Extracts the suffix of each file name in NAMES. If the file name
76
contains a period, the suffix is everything starting with the last
77
period. Otherwise, the suffix is the empty string. This
78
frequently means that the result will be empty when NAMES is not,
79
and if NAMES contains multiple file names, the result may contain
84
$(suffix src/foo.c src-1.0/bar.c hacks)
86
produces the result `.c .c'.
88
`$(basename NAMES...)'
89
Extracts all but the suffix of each file name in NAMES. If the
90
file name contains a period, the basename is everything starting
91
up to (and not including) the last period. Periods in the
92
directory part are ignored. If there is no period, the basename
93
is the entire file name. For example,
95
$(basename src/foo.c src-1.0/bar hacks)
97
produces the result `src/foo src-1.0/bar hacks'.
99
`$(addsuffix SUFFIX,NAMES...)'
100
The argument NAMES is regarded as a series of names, separated by
101
whitespace; SUFFIX is used as a unit. The value of SUFFIX is
102
appended to the end of each individual name and the resulting
103
larger names are concatenated with single spaces between them.
106
$(addsuffix .c,foo bar)
108
produces the result `foo.c bar.c'.
110
`$(addprefix PREFIX,NAMES...)'
111
The argument NAMES is regarded as a series of names, separated by
112
whitespace; PREFIX is used as a unit. The value of PREFIX is
113
prepended to the front of each individual name and the resulting
114
larger names are concatenated with single spaces between them.
117
$(addprefix src/,foo bar)
119
produces the result `src/foo src/bar'.
121
`$(join LIST1,LIST2)'
122
Concatenates the two arguments word by word: the two first words
123
(one from each argument) concatenated form the first word of the
124
result, the two second words form the second word of the result,
125
and so on. So the Nth word of the result comes from the Nth word
126
of each argument. If one argument has more words that the other,
127
the extra words are copied unchanged into the result.
129
For example, `$(join a b,.c .o)' produces `a.c b.o'.
131
Whitespace between the words in the lists is not preserved; it is
132
replaced with a single space.
134
This function can merge the results of the `dir' and `notdir'
135
functions, to produce the original list of files which was given
136
to those two functions.
139
Returns the Nth word of TEXT. The legitimate values of N start
140
from 1. If N is bigger than the number of words in TEXT, the
141
value is empty. For example,
143
$(word 2, foo bar baz)
147
`$(wordlist S,E,TEXT)'
148
Returns the list of words in TEXT starting with word S and ending
149
with word E (inclusive). The legitimate values of S and E start
150
from 1. If S is bigger than the number of words in TEXT, the
151
value is empty. If E is bigger than the number of words in TEXT,
152
words up to the end of TEXT are returned. If S is greater than E,
153
`make' swaps them for you. For example,
155
$(wordlist 2, 3, foo bar baz)
160
Returns the number of words in TEXT. Thus, the last word of TEXT
161
is `$(word $(words TEXT),TEXT)'.
163
`$(firstword NAMES...)'
164
The argument NAMES is regarded as a series of names, separated by
165
whitespace. The value is the first name in the series. The rest
166
of the names are ignored.
172
produces the result `foo'. Although `$(firstword TEXT)' is the
173
same as `$(word 1,TEXT)', the `firstword' function is retained for
176
`$(wildcard PATTERN)'
177
The argument PATTERN is a file name pattern, typically containing
178
wildcard characters (as in shell file name patterns). The result
179
of `wildcard' is a space-separated list of the names of existing
180
files that match the pattern. *Note Using Wildcard Characters in
181
File Names: Wildcards.
184
File: make.info, Node: Foreach Function, Next: If Function, Prev: File Name Functions, Up: Functions
186
The `foreach' Function
187
======================
189
The `foreach' function is very different from other functions. It
190
causes one piece of text to be used repeatedly, each time with a
191
different substitution performed on it. It resembles the `for' command
192
in the shell `sh' and the `foreach' command in the C-shell `csh'.
194
The syntax of the `foreach' function is:
196
$(foreach VAR,LIST,TEXT)
198
The first two arguments, VAR and LIST, are expanded before anything
199
else is done; note that the last argument, TEXT, is *not* expanded at
200
the same time. Then for each word of the expanded value of LIST, the
201
variable named by the expanded value of VAR is set to that word, and
202
TEXT is expanded. Presumably TEXT contains references to that
203
variable, so its expansion will be different each time.
205
The result is that TEXT is expanded as many times as there are
206
whitespace-separated words in LIST. The multiple expansions of TEXT
207
are concatenated, with spaces between them, to make the result of
210
This simple example sets the variable `files' to the list of all
211
files in the directories in the list `dirs':
214
files := $(foreach dir,$(dirs),$(wildcard $(dir)/*))
216
Here TEXT is `$(wildcard $(dir)/*)'. The first repetition finds the
217
value `a' for `dir', so it produces the same result as `$(wildcard
218
a/*)'; the second repetition produces the result of `$(wildcard b/*)';
219
and the third, that of `$(wildcard c/*)'.
221
This example has the same result (except for setting `dirs') as the
224
files := $(wildcard a/* b/* c/* d/*)
226
When TEXT is complicated, you can improve readability by giving it a
227
name, with an additional variable:
229
find_files = $(wildcard $(dir)/*)
231
files := $(foreach dir,$(dirs),$(find_files))
233
Here we use the variable `find_files' this way. We use plain `=' to
234
define a recursively-expanding variable, so that its value contains an
235
actual function call to be reexpanded under the control of `foreach'; a
236
simply-expanded variable would not do, since `wildcard' would be called
237
only once at the time of defining `find_files'.
239
The `foreach' function has no permanent effect on the variable VAR;
240
its value and flavor after the `foreach' function call are the same as
241
they were beforehand. The other values which are taken from LIST are
242
in effect only temporarily, during the execution of `foreach'. The
243
variable VAR is a simply-expanded variable during the execution of
244
`foreach'. If VAR was undefined before the `foreach' function call, it
245
is undefined after the call. *Note The Two Flavors of Variables:
248
You must take care when using complex variable expressions that
249
result in variable names because many strange things are valid variable
250
names, but are probably not what you intended. For example,
252
files := $(foreach Esta escrito en espanol!,b c ch,$(find_files))
254
might be useful if the value of `find_files' references the variable
255
whose name is `Esta escrito en espanol!' (es un nombre bastante largo,
256
no?), but it is more likely to be a mistake.
259
File: make.info, Node: If Function, Next: Call Function, Prev: Foreach Function, Up: Functions
264
The `if' function provides support for conditional expansion in a
265
functional context (as opposed to the GNU `make' makefile conditionals
266
such as `ifeq' (*note Syntax of Conditionals: Conditional Syntax.).
268
An `if' function call can contain either two or three arguments:
270
$(if CONDITION,THEN-PART[,ELSE-PART])
272
The first argument, CONDITION, first has all preceding and trailing
273
whitespace stripped, then is expanded. If it expands to any non-empty
274
string, then the condition is considered to be true. If it expands to
275
an empty string, the condition is considered to be false.
277
If the condition is true then the second argument, THEN-PART, is
278
evaluated and this is used as the result of the evaluation of the entire
281
If the condition is false then the third argument, ELSE-PART, is
282
evaluated and this is the result of the `if' function. If there is no
283
third argument, the `if' function evaluates to nothing (the empty
286
Note that only one of the THEN-PART or the ELSE-PART will be
287
evaluated, never both. Thus, either can contain side-effects (such as
288
`shell' function calls, etc.)
291
File: make.info, Node: Call Function, Next: Origin Function, Prev: If Function, Up: Functions
296
The `call' function is unique in that it can be used to create new
297
parameterized functions. You can write a complex expression as the
298
value of a variable, then use `call' to expand it with different values.
300
The syntax of the `call' function is:
302
$(call VARIABLE,PARAM,PARAM,...)
304
When `make' expands this function, it assigns each PARAM to
305
temporary variables `$(1)', `$(2)', etc. The variable `$(0)' will
306
contain VARIABLE. There is no maximum number of parameter arguments.
307
There is no minimum, either, but it doesn't make sense to use `call'
310
Then VARIABLE is expanded as a `make' variable in the context of
311
these temporary assignments. Thus, any reference to `$(1)' in the
312
value of VARIABLE will resolve to the first PARAM in the invocation of
315
Note that VARIABLE is the _name_ of a variable, not a _reference_ to
316
that variable. Therefore you would not normally use a `$' or
317
parentheses when writing it. (You can, however, use a variable
318
reference in the name if you want the name not to be a constant.)
320
If VARIABLE is the name of a builtin function, the builtin function
321
is always invoked (even if a `make' variable by that name also exists).
323
Some examples may make this clearer.
325
This macro simply reverses its arguments:
330
bar = $(call reverse,$(foo))
332
Here BAR will contain `b a'.
334
This one is slightly more interesting: it defines a macro to search
335
for the first instance of a program in `PATH':
337
pathsearch = $(firstword $(wildcard $(addsufix /$(1),$(subst :, ,$(PATH)))))
339
LS := $(call pathsearch,ls)
341
Now the variable LS contains `/bin/ls' or similar.
343
The `call' function can be nested. Each recursive invocation gets
344
its own local values for `$(1)', etc. that mask the values of
345
higher-level `call'. For example, here is an implementation of a "map"
348
map = $(foreach a,$(2),$(call $(1),$(a)))
350
Now you can MAP a function that normally takes only one argument,
351
such as `origin', to multiple values in one step:
353
o = $(call map,origin,o map MAKE)
355
and end up with O containing something like `file file default'.
357
A final caution: be careful when adding whitespace to the arguments
358
to `call'. As with other functions, any whitespace contained in the
359
second and subsequent arguments is kept; this can cause strange
360
effects. It's generally safest to remove all extraneous whitespace when
361
providing parameters to `call'.
364
File: make.info, Node: Origin Function, Next: Shell Function, Prev: Call Function, Up: Functions
366
The `origin' Function
367
=====================
369
The `origin' function is unlike most other functions in that it does
370
not operate on the values of variables; it tells you something _about_
371
a variable. Specifically, it tells you where it came from.
373
The syntax of the `origin' function is:
377
Note that VARIABLE is the _name_ of a variable to inquire about; not
378
a _reference_ to that variable. Therefore you would not normally use a
379
`$' or parentheses when writing it. (You can, however, use a variable
380
reference in the name if you want the name not to be a constant.)
382
The result of this function is a string telling you how the variable
383
VARIABLE was defined:
386
if VARIABLE was never defined.
389
if VARIABLE has a default definition, as is usual with `CC' and so
390
on. *Note Variables Used by Implicit Rules: Implicit Variables.
391
Note that if you have redefined a default variable, the `origin'
392
function will return the origin of the later definition.
395
if VARIABLE was defined as an environment variable and the `-e'
396
option is _not_ turned on (*note Summary of Options: Options
399
`environment override'
400
if VARIABLE was defined as an environment variable and the `-e'
401
option _is_ turned on (*note Summary of Options: Options Summary.).
404
if VARIABLE was defined in a makefile.
407
if VARIABLE was defined on the command line.
410
if VARIABLE was defined with an `override' directive in a makefile
411
(*note The `override' Directive: Override Directive.).
414
if VARIABLE is an automatic variable defined for the execution of
415
the commands for each rule (*note Automatic Variables: Automatic.).
417
This information is primarily useful (other than for your curiosity)
418
to determine if you want to believe the value of a variable. For
419
example, suppose you have a makefile `foo' that includes another
420
makefile `bar'. You want a variable `bletch' to be defined in `bar' if
421
you run the command `make -f bar', even if the environment contains a
422
definition of `bletch'. However, if `foo' defined `bletch' before
423
including `bar', you do not want to override that definition. This
424
could be done by using an `override' directive in `foo', giving that
425
definition precedence over the later definition in `bar';
426
unfortunately, the `override' directive would also override any command
427
line definitions. So, `bar' could include:
430
ifeq "$(origin bletch)" "environment"
431
bletch = barf, gag, etc.
435
If `bletch' has been defined from the environment, this will redefine
438
If you want to override a previous definition of `bletch' if it came
439
from the environment, even under `-e', you could instead write:
441
ifneq "$(findstring environment,$(origin bletch))" ""
442
bletch = barf, gag, etc.
445
Here the redefinition takes place if `$(origin bletch)' returns
446
either `environment' or `environment override'. *Note Functions for
447
String Substitution and Analysis: Text Functions.
450
File: make.info, Node: Shell Function, Next: Make Control Functions, Prev: Origin Function, Up: Functions
455
The `shell' function is unlike any other function except the
456
`wildcard' function (*note The Function `wildcard': Wildcard Function.)
457
in that it communicates with the world outside of `make'.
459
The `shell' function performs the same function that backquotes
460
(``') perform in most shells: it does "command expansion". This means
461
that it takes an argument that is a shell command and returns the
462
output of the command. The only processing `make' does on the result,
463
before substituting it into the surrounding text, is to convert each
464
newline or carriage-return / newline pair to a single space. It also
465
removes the trailing (carriage-return and) newline, if it's the last
468
The commands run by calls to the `shell' function are run when the
469
function calls are expanded. In most cases, this is when the makefile
470
is read in. The exception is that function calls in the commands of
471
the rules are expanded when the commands are run, and this applies to
472
`shell' function calls like all others.
474
Here are some examples of the use of the `shell' function:
476
contents := $(shell cat foo)
478
sets `contents' to the contents of the file `foo', with a space (rather
479
than a newline) separating each line.
481
files := $(shell echo *.c)
483
sets `files' to the expansion of `*.c'. Unless `make' is using a very
484
strange shell, this has the same result as `$(wildcard *.c)'.
487
File: make.info, Node: Make Control Functions, Prev: Shell Function, Up: Functions
489
Functions That Control Make
490
===========================
492
These functions control the way make runs. Generally, they are used
493
to provide information to the user of the makefile or to cause make to
494
stop if some sort of environmental error is detected.
497
Generates a fatal error where the message is TEXT. Note that the
498
error is generated whenever this function is evaluated. So, if
499
you put it inside a command script or on the right side of a
500
recursive variable assignment, it won't be evaluated until later.
501
The TEXT will be expanded before the error is generated.
506
$(error error is $(ERROR1))
509
will generate a fatal error during the read of the makefile if the
510
`make' variable `ERROR1' is defined. Or,
512
ERR = $(error found an error!)
517
will generate a fatal error while `make' is running, if the `err'
521
This function works similarly to the `error' function, above,
522
except that `make' doesn't exit. Instead, TEXT is expanded and
523
the resulting message is displayed, but processing of the makefile
526
The result of the expansion of this function is the empty string.
529
File: make.info, Node: Running, Next: Implicit Rules, Prev: Functions, Up: Top
534
A makefile that says how to recompile a program can be used in more
535
than one way. The simplest use is to recompile every file that is out
536
of date. Usually, makefiles are written so that if you run `make' with
537
no arguments, it does just that.
539
But you might want to update only some of the files; you might want
540
to use a different compiler or different compiler options; you might
541
want just to find out which files are out of date without changing them.
543
By giving arguments when you run `make', you can do any of these
544
things and many others.
546
The exit status of `make' is always one of three values:
548
The exit status is zero if `make' is successful.
551
The exit status is two if `make' encounters any errors. It will
552
print messages describing the particular errors.
555
The exit status is one if you use the `-q' flag and `make'
556
determines that some target is not already up to date. *Note
557
Instead of Executing the Commands: Instead of Execution.
561
* Makefile Arguments:: How to specify which makefile to use.
562
* Goals:: How to use goal arguments to specify which
563
parts of the makefile to use.
564
* Instead of Execution:: How to use mode flags to specify what
565
kind of thing to do with the commands
566
in the makefile other than simply
568
* Avoiding Compilation:: How to avoid recompiling certain files.
569
* Overriding:: How to override a variable to specify
570
an alternate compiler and other things.
571
* Testing:: How to proceed past some errors, to
573
* Options Summary:: Summary of Options
576
File: make.info, Node: Makefile Arguments, Next: Goals, Up: Running
578
Arguments to Specify the Makefile
579
=================================
581
The way to specify the name of the makefile is with the `-f' or
582
`--file' option (`--makefile' also works). For example, `-f altmake'
583
says to use the file `altmake' as the makefile.
585
If you use the `-f' flag several times and follow each `-f' with an
586
argument, all the specified files are used jointly as makefiles.
588
If you do not use the `-f' or `--file' flag, the default is to try
589
`GNUmakefile', `makefile', and `Makefile', in that order, and use the
590
first of these three which exists or can be made (*note Writing
591
Makefiles: Makefiles.).
594
File: make.info, Node: Goals, Next: Instead of Execution, Prev: Makefile Arguments, Up: Running
596
Arguments to Specify the Goals
597
==============================
599
The "goals" are the targets that `make' should strive ultimately to
600
update. Other targets are updated as well if they appear as
601
prerequisites of goals, or prerequisites of prerequisites of goals, etc.
603
By default, the goal is the first target in the makefile (not
604
counting targets that start with a period). Therefore, makefiles are
605
usually written so that the first target is for compiling the entire
606
program or programs they describe. If the first rule in the makefile
607
has several targets, only the first target in the rule becomes the
608
default goal, not the whole list.
610
You can specify a different goal or goals with arguments to `make'.
611
Use the name of the goal as an argument. If you specify several goals,
612
`make' processes each of them in turn, in the order you name them.
614
Any target in the makefile may be specified as a goal (unless it
615
starts with `-' or contains an `=', in which case it will be parsed as
616
a switch or variable definition, respectively). Even targets not in
617
the makefile may be specified, if `make' can find implicit rules that
618
say how to make them.
620
`Make' will set the special variable `MAKECMDGOALS' to the list of
621
goals you specified on the command line. If no goals were given on the
622
command line, this variable is empty. Note that this variable should
623
be used only in special circumstances.
625
An example of appropriate use is to avoid including `.d' files
626
during `clean' rules (*note Automatic Prerequisites::), so `make' won't
627
create them only to immediately remove them again:
629
sources = foo.c bar.c
631
ifneq ($(MAKECMDGOALS),clean)
632
include $(sources:.c=.d)
635
One use of specifying a goal is if you want to compile only a part of
636
the program, or only one of several programs. Specify as a goal each
637
file that you wish to remake. For example, consider a directory
638
containing several programs, with a makefile that starts like this:
641
all: size nm ld ar as
643
If you are working on the program `size', you might want to say
644
`make size' so that only the files of that program are recompiled.
646
Another use of specifying a goal is to make files that are not
647
normally made. For example, there may be a file of debugging output,
648
or a version of the program that is compiled specially for testing,
649
which has a rule in the makefile but is not a prerequisite of the
652
Another use of specifying a goal is to run the commands associated
653
with a phony target (*note Phony Targets::) or empty target (*note
654
Empty Target Files to Record Events: Empty Targets.). Many makefiles
655
contain a phony target named `clean' which deletes everything except
656
source files. Naturally, this is done only if you request it
657
explicitly with `make clean'. Following is a list of typical phony and
658
empty target names. *Note Standard Targets::, for a detailed list of
659
all the standard target names which GNU software packages use.
662
Make all the top-level targets the makefile knows about.
665
Delete all files that are normally created by running `make'.
668
Like `clean', but may refrain from deleting a few files that people
669
normally don't want to recompile. For example, the `mostlyclean'
670
target for GCC does not delete `libgcc.a', because recompiling it
671
is rarely necessary and takes a lot of time.
676
Any of these targets might be defined to delete _more_ files than
677
`clean' does. For example, this would delete configuration files
678
or links that you would normally create as preparation for
679
compilation, even if the makefile itself cannot create these files.
682
Copy the executable file into a directory that users typically
683
search for commands; copy any auxiliary files that the executable
684
uses into the directories where it will look for them.
687
Print listings of the source files that have changed.
690
Create a tar file of the source files.
693
Create a shell archive (shar file) of the source files.
696
Create a distribution file of the source files. This might be a
697
tar file, or a shar file, or a compressed version of one of the
698
above, or even more than one of the above.
701
Update a tags table for this program.
705
Perform self tests on the program this makefile builds.
708
File: make.info, Node: Instead of Execution, Next: Avoiding Compilation, Prev: Goals, Up: Running
710
Instead of Executing the Commands
711
=================================
713
The makefile tells `make' how to tell whether a target is up to date,
714
and how to update each target. But updating the targets is not always
715
what you want. Certain options specify other activities for `make'.
721
"No-op". The activity is to print what commands would be used to
722
make the targets up to date, but not actually execute them.
726
"Touch". The activity is to mark the targets as up to date without
727
actually changing them. In other words, `make' pretends to compile
728
the targets but does not really change their contents.
732
"Question". The activity is to find out silently whether the
733
targets are up to date already; but execute no commands in either
734
case. In other words, neither compilation nor output will occur.
740
"What if". Each `-W' flag is followed by a file name. The given
741
files' modification times are recorded by `make' as being the
742
present time, although the actual modification times remain the
743
same. You can use the `-W' flag in conjunction with the `-n' flag
744
to see what would happen if you were to modify specific files.
746
With the `-n' flag, `make' prints the commands that it would
747
normally execute but does not execute them.
749
With the `-t' flag, `make' ignores the commands in the rules and
750
uses (in effect) the command `touch' for each target that needs to be
751
remade. The `touch' command is also printed, unless `-s' or `.SILENT'
752
is used. For speed, `make' does not actually invoke the program
753
`touch'. It does the work directly.
755
With the `-q' flag, `make' prints nothing and executes no commands,
756
but the exit status code it returns is zero if and only if the targets
757
to be considered are already up to date. If the exit status is one,
758
then some updating needs to be done. If `make' encounters an error,
759
the exit status is two, so you can distinguish an error from a target
760
that is not up to date.
762
It is an error to use more than one of these three flags in the same
763
invocation of `make'.
765
The `-n', `-t', and `-q' options do not affect command lines that
766
begin with `+' characters or contain the strings `$(MAKE)' or
767
`${MAKE}'. Note that only the line containing the `+' character or the
768
strings `$(MAKE)' or `${MAKE}' is run regardless of these options.
769
Other lines in the same rule are not run unless they too begin with `+'
770
or contain `$(MAKE)' or `${MAKE}' (*Note How the `MAKE' Variable Works:
773
The `-W' flag provides two features:
775
* If you also use the `-n' or `-q' flag, you can see what `make'
776
would do if you were to modify some files.
778
* Without the `-n' or `-q' flag, when `make' is actually executing
779
commands, the `-W' flag can direct `make' to act as if some files
780
had been modified, without actually modifying the files.
782
Note that the options `-p' and `-v' allow you to obtain other
783
information about `make' or about the makefiles in use (*note Summary
784
of Options: Options Summary.).
787
File: make.info, Node: Avoiding Compilation, Next: Overriding, Prev: Instead of Execution, Up: Running
789
Avoiding Recompilation of Some Files
790
====================================
792
Sometimes you may have changed a source file but you do not want to
793
recompile all the files that depend on it. For example, suppose you add
794
a macro or a declaration to a header file that many other files depend
795
on. Being conservative, `make' assumes that any change in the header
796
file requires recompilation of all dependent files, but you know that
797
they do not need to be recompiled and you would rather not waste the
798
time waiting for them to compile.
800
If you anticipate the problem before changing the header file, you
801
can use the `-t' flag. This flag tells `make' not to run the commands
802
in the rules, but rather to mark the target up to date by changing its
803
last-modification date. You would follow this procedure:
805
1. Use the command `make' to recompile the source files that really
808
2. Make the changes in the header files.
810
3. Use the command `make -t' to mark all the object files as up to
811
date. The next time you run `make', the changes in the header
812
files will not cause any recompilation.
814
If you have already changed the header file at a time when some files
815
do need recompilation, it is too late to do this. Instead, you can use
816
the `-o FILE' flag, which marks a specified file as "old" (*note
817
Summary of Options: Options Summary.). This means that the file itself
818
will not be remade, and nothing else will be remade on its account.
819
Follow this procedure:
821
1. Recompile the source files that need compilation for reasons
822
independent of the particular header file, with `make -o
823
HEADERFILE'. If several header files are involved, use a separate
824
`-o' option for each header file.
826
2. Touch all the object files with `make -t'.
829
File: make.info, Node: Overriding, Next: Testing, Prev: Avoiding Compilation, Up: Running
834
An argument that contains `=' specifies the value of a variable:
835
`V=X' sets the value of the variable V to X. If you specify a value in
836
this way, all ordinary assignments of the same variable in the makefile
837
are ignored; we say they have been "overridden" by the command line
840
The most common way to use this facility is to pass extra flags to
841
compilers. For example, in a properly written makefile, the variable
842
`CFLAGS' is included in each command that runs the C compiler, so a
843
file `foo.c' would be compiled something like this:
845
cc -c $(CFLAGS) foo.c
847
Thus, whatever value you set for `CFLAGS' affects each compilation
848
that occurs. The makefile probably specifies the usual value for
853
Each time you run `make', you can override this value if you wish.
854
For example, if you say `make CFLAGS='-g -O'', each C compilation will
855
be done with `cc -c -g -O'. (This illustrates how you can use quoting
856
in the shell to enclose spaces and other special characters in the
857
value of a variable when you override it.)
859
The variable `CFLAGS' is only one of many standard variables that
860
exist just so that you can change them this way. *Note Variables Used
861
by Implicit Rules: Implicit Variables, for a complete list.
863
You can also program the makefile to look at additional variables of
864
your own, giving the user the ability to control other aspects of how
865
the makefile works by changing the variables.
867
When you override a variable with a command argument, you can define
868
either a recursively-expanded variable or a simply-expanded variable.
869
The examples shown above make a recursively-expanded variable; to make a
870
simply-expanded variable, write `:=' instead of `='. But, unless you
871
want to include a variable reference or function call in the _value_
872
that you specify, it makes no difference which kind of variable you
875
There is one way that the makefile can change a variable that you
876
have overridden. This is to use the `override' directive, which is a
877
line that looks like this: `override VARIABLE = VALUE' (*note The
878
`override' Directive: Override Directive.).
881
File: make.info, Node: Testing, Next: Options Summary, Prev: Overriding, Up: Running
883
Testing the Compilation of a Program
884
====================================
886
Normally, when an error happens in executing a shell command, `make'
887
gives up immediately, returning a nonzero status. No further commands
888
are executed for any target. The error implies that the goal cannot be
889
correctly remade, and `make' reports this as soon as it knows.
891
When you are compiling a program that you have just changed, this is
892
not what you want. Instead, you would rather that `make' try compiling
893
every file that can be tried, to show you as many compilation errors as
896
On these occasions, you should use the `-k' or `--keep-going' flag.
897
This tells `make' to continue to consider the other prerequisites of
898
the pending targets, remaking them if necessary, before it gives up and
899
returns nonzero status. For example, after an error in compiling one
900
object file, `make -k' will continue compiling other object files even
901
though it already knows that linking them will be impossible. In
902
addition to continuing after failed shell commands, `make -k' will
903
continue as much as possible after discovering that it does not know
904
how to make a target or prerequisite file. This will always cause an
905
error message, but without `-k', it is a fatal error (*note Summary of
906
Options: Options Summary.).
908
The usual behavior of `make' assumes that your purpose is to get the
909
goals up to date; once `make' learns that this is impossible, it might
910
as well report the failure immediately. The `-k' flag says that the
911
real purpose is to test as much as possible of the changes made in the
912
program, perhaps to find several independent problems so that you can
913
correct them all before the next attempt to compile. This is why Emacs'
914
`M-x compile' command passes the `-k' flag by default.
917
File: make.info, Node: Options Summary, Prev: Testing, Up: Running
922
Here is a table of all the options `make' understands:
926
These options are ignored for compatibility with other versions of
931
Change to directory DIR before reading the makefiles. If multiple
932
`-C' options are specified, each is interpreted relative to the
933
previous one: `-C / -C etc' is equivalent to `-C /etc'. This is
934
typically used with recursive invocations of `make' (*note
935
Recursive Use of `make': Recursion.).
939
Print debugging information in addition to normal processing. The
940
debugging information says which files are being considered for
941
remaking, which file-times are being compared and with what
942
results, which files actually need to be remade, which implicit
943
rules are considered and which are applied--everything interesting
944
about how `make' decides what to do.
947
`--environment-overrides'
948
Give variables taken from the environment precedence over
949
variables from makefiles. *Note Variables from the Environment:
955
Read the file named FILE as a makefile. *Note Writing Makefiles:
960
Remind you of the options that `make' understands and then exit.
964
Ignore all errors in commands executed to remake files. *Note
965
Errors in Commands: Errors.
969
Specifies a directory DIR to search for included makefiles. *Note
970
Including Other Makefiles: Include. If several `-I' options are
971
used to specify several directories, the directories are searched
972
in the order specified.
976
Specifies the number of jobs (commands) to run simultaneously.
977
With no argument, `make' runs as many jobs simultaneously as
978
possible. If there is more than one `-j' option, the last one is
979
effective. *Note Parallel Execution: Parallel, for more
980
information on how commands are run. Note that this option is
985
Continue as much as possible after an error. While the target that
986
failed, and those that depend on it, cannot be remade, the other
987
prerequisites of these targets can be processed all the same.
988
*Note Testing the Compilation of a Program: Testing.
991
`--load-average[=LOAD]'
993
Specifies that no new jobs (commands) should be started if there
994
are other jobs running and the load average is at least LOAD (a
995
floating-point number). With no argument, removes a previous load
996
limit. *Note Parallel Execution: Parallel.
1002
Print the commands that would be executed, but do not execute them.
1003
*Note Instead of Executing the Commands: Instead of Execution.
1008
Do not remake the file FILE even if it is older than its
1009
prerequisites, and do not remake anything on account of changes in
1010
FILE. Essentially the file is treated as very old and its rules
1011
are ignored. *Note Avoiding Recompilation of Some Files: Avoiding
1016
Print the data base (rules and variable values) that results from
1017
reading the makefiles; then execute as usual or as otherwise
1018
specified. This also prints the version information given by the
1019
`-v' switch (see below). To print the data base without trying to
1020
remake any files, use `make -qp'. To print the data base of
1021
predefined rules and variables, use `make -p -f /dev/null'.
1025
"Question mode". Do not run any commands, or print anything; just
1026
return an exit status that is zero if the specified targets are
1027
already up to date, one if any remaking is required, or two if an
1028
error is encountered. *Note Instead of Executing the Commands:
1029
Instead of Execution.
1032
`--no-builtin-rules'
1033
Eliminate use of the built-in implicit rules (*note Using Implicit
1034
Rules: Implicit Rules.). You can still define your own by writing
1035
pattern rules (*note Defining and Redefining Pattern Rules:
1036
Pattern Rules.). The `-r' option also clears out the default list
1037
of suffixes for suffix rules (*note Old-Fashioned Suffix Rules:
1038
Suffix Rules.). But you can still define your own suffixes with a
1039
rule for `.SUFFIXES', and then define your own suffix rules. Note
1040
that only _rules_ are affected by the `-r' option; default
1041
variables remain in effect (*note Variables Used by Implicit
1042
Rules: Implicit Variables.); see the `-R' option below.
1045
`--no-builtin-variables'
1046
Eliminate use of the built-in rule-specific variables (*note
1047
Variables Used by Implicit Rules: Implicit Variables.). You can
1048
still define your own, of course. The `-R' option also
1049
automatically enables the `-r' option (see above), since it
1050
doesn't make sense to have implicit rules without any definitions
1051
for the variables that they use.
1056
Silent operation; do not print the commands as they are executed.
1057
*Note Command Echoing: Echoing.
1062
Cancel the effect of the `-k' option. This is never necessary
1063
except in a recursive `make' where `-k' might be inherited from
1064
the top-level `make' via `MAKEFLAGS' (*note Recursive Use of
1065
`make': Recursion.) or if you set `-k' in `MAKEFLAGS' in your
1070
Touch files (mark them up to date without really changing them)
1071
instead of running their commands. This is used to pretend that
1072
the commands were done, in order to fool future invocations of
1073
`make'. *Note Instead of Executing the Commands: Instead of
1078
Print the version of the `make' program plus a copyright, a list
1079
of authors, and a notice that there is no warranty; then exit.
1083
Print a message containing the working directory both before and
1084
after executing the makefile. This may be useful for tracking
1085
down errors from complicated nests of recursive `make' commands.
1086
*Note Recursive Use of `make': Recursion. (In practice, you
1087
rarely need to specify this option since `make' does it for you;
1088
see *Note The `--print-directory' Option: -w Option.)
1090
`--no-print-directory'
1091
Disable printing of the working directory under `-w'. This option
1092
is useful when `-w' is turned on automatically, but you do not
1093
want to see the extra messages. *Note The `--print-directory'
1100
Pretend that the target FILE has just been modified. When used
1101
with the `-n' flag, this shows you what would happen if you were
1102
to modify that file. Without `-n', it is almost the same as
1103
running a `touch' command on the given file before running `make',
1104
except that the modification time is changed only in the
1105
imagination of `make'. *Note Instead of Executing the Commands:
1106
Instead of Execution.
1108
`--warn-undefined-variables'
1109
Issue a warning message whenever `make' sees a reference to an
1110
undefined variable. This can be helpful when you are trying to
1111
debug makefiles which use variables in complex ways.
1114
File: make.info, Node: Implicit Rules, Next: Archives, Prev: Running, Up: Top
1116
Using Implicit Rules
1117
********************
1119
Certain standard ways of remaking target files are used very often.
1120
For example, one customary way to make an object file is from a C
1121
source file using the C compiler, `cc'.
1123
"Implicit rules" tell `make' how to use customary techniques so that
1124
you do not have to specify them in detail when you want to use them.
1125
For example, there is an implicit rule for C compilation. File names
1126
determine which implicit rules are run. For example, C compilation
1127
typically takes a `.c' file and makes a `.o' file. So `make' applies
1128
the implicit rule for C compilation when it sees this combination of
1131
A chain of implicit rules can apply in sequence; for example, `make'
1132
will remake a `.o' file from a `.y' file by way of a `.c' file.
1134
The built-in implicit rules use several variables in their commands
1135
so that, by changing the values of the variables, you can change the
1136
way the implicit rule works. For example, the variable `CFLAGS'
1137
controls the flags given to the C compiler by the implicit rule for C
1140
You can define your own implicit rules by writing "pattern rules".
1142
"Suffix rules" are a more limited way to define implicit rules.
1143
Pattern rules are more general and clearer, but suffix rules are
1144
retained for compatibility.
1148
* Using Implicit:: How to use an existing implicit rule
1149
to get the commands for updating a file.
1150
* Catalogue of Rules:: A list of built-in implicit rules.
1151
* Implicit Variables:: How to change what predefined rules do.
1152
* Chained Rules:: How to use a chain of implicit rules.
1153
* Pattern Rules:: How to define new implicit rules.
1154
* Last Resort:: How to defining commands for rules
1155
which cannot find any.
1156
* Suffix Rules:: The old-fashioned style of implicit rule.
1157
* Implicit Rule Search:: The precise algorithm for applying
1161
File: make.info, Node: Using Implicit, Next: Catalogue of Rules, Up: Implicit Rules
1163
Using Implicit Rules
1164
====================
1166
To allow `make' to find a customary method for updating a target
1167
file, all you have to do is refrain from specifying commands yourself.
1168
Either write a rule with no command lines, or don't write a rule at
1169
all. Then `make' will figure out which implicit rule to use based on
1170
which kind of source file exists or can be made.
1172
For example, suppose the makefile looks like this:
1175
cc -o foo foo.o bar.o $(CFLAGS) $(LDFLAGS)
1177
Because you mention `foo.o' but do not give a rule for it, `make' will
1178
automatically look for an implicit rule that tells how to update it.
1179
This happens whether or not the file `foo.o' currently exists.
1181
If an implicit rule is found, it can supply both commands and one or
1182
more prerequisites (the source files). You would want to write a rule
1183
for `foo.o' with no command lines if you need to specify additional
1184
prerequisites, such as header files, that the implicit rule cannot
1187
Each implicit rule has a target pattern and prerequisite patterns.
1188
There may be many implicit rules with the same target pattern. For
1189
example, numerous rules make `.o' files: one, from a `.c' file with the
1190
C compiler; another, from a `.p' file with the Pascal compiler; and so
1191
on. The rule that actually applies is the one whose prerequisites
1192
exist or can be made. So, if you have a file `foo.c', `make' will run
1193
the C compiler; otherwise, if you have a file `foo.p', `make' will run
1194
the Pascal compiler; and so on.
1196
Of course, when you write the makefile, you know which implicit rule
1197
you want `make' to use, and you know it will choose that one because you
1198
know which possible prerequisite files are supposed to exist. *Note
1199
Catalogue of Implicit Rules: Catalogue of Rules, for a catalogue of all
1200
the predefined implicit rules.
1202
Above, we said an implicit rule applies if the required
1203
prerequisites "exist or can be made". A file "can be made" if it is
1204
mentioned explicitly in the makefile as a target or a prerequisite, or
1205
if an implicit rule can be recursively found for how to make it. When
1206
an implicit prerequisite is the result of another implicit rule, we say
1207
that "chaining" is occurring. *Note Chains of Implicit Rules: Chained
1210
In general, `make' searches for an implicit rule for each target, and
1211
for each double-colon rule, that has no commands. A file that is
1212
mentioned only as a prerequisite is considered a target whose rule
1213
specifies nothing, so implicit rule search happens for it. *Note
1214
Implicit Rule Search Algorithm: Implicit Rule Search, for the details
1215
of how the search is done.
1217
Note that explicit prerequisites do not influence implicit rule
1218
search. For example, consider this explicit rule:
1222
The prerequisite on `foo.p' does not necessarily mean that `make' will
1223
remake `foo.o' according to the implicit rule to make an object file, a
1224
`.o' file, from a Pascal source file, a `.p' file. For example, if
1225
`foo.c' also exists, the implicit rule to make an object file from a C
1226
source file is used instead, because it appears before the Pascal rule
1227
in the list of predefined implicit rules (*note Catalogue of Implicit
1228
Rules: Catalogue of Rules.).
1230
If you do not want an implicit rule to be used for a target that has
1231
no commands, you can give that target empty commands by writing a
1232
semicolon (*note Defining Empty Commands: Empty Commands.).