1
.\" $NetBSD: make.1,v 1.32 1999/03/10 05:22:18 erh Exp $
3
.\" Copyright (c) 1990, 1993
4
.\" The Regents of the University of California. All rights reserved.
6
.\" Redistribution and use in source and binary forms, with or without
7
.\" modification, are permitted provided that the following conditions
9
.\" 1. Redistributions of source code must retain the above copyright
10
.\" notice, this list of conditions and the following disclaimer.
11
.\" 2. Redistributions in binary form must reproduce the above copyright
12
.\" notice, this list of conditions and the following disclaimer in the
13
.\" documentation and/or other materials provided with the distribution.
14
.\" 3. All advertising materials mentioning features or use of this software
15
.\" must display the following acknowledgement:
16
.\" This product includes software developed by the University of
17
.\" California, Berkeley and its contributors.
18
.\" 4. Neither the name of the University nor the names of its contributors
19
.\" may be used to endorse or promote products derived from this software
20
.\" without specific prior written permission.
22
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
41
.Nd maintain program dependencies
72
is a program designed to simplify the maintenance of other programs.
73
Its input is a list of specifications as to the files upon which programs
74
and other files depend.
77
exists, it is read for this list of specifications.
78
If it does not exist, the file
83
exists, it is read (see
86
This manual page is intended as a reference document only.
87
For a more thorough description of
89
and makefiles, please refer to
90
.%T "Make \- A Tutorial" .
92
The options are as follows:
95
Try to be backwards compatible by executing a single shell per command and
96
by executing the commands to make the sources of a dependency line in sequence.
100
to be 1, in the global context.
102
Turn on debugging, and specify which portions of
104
are to print debugging information.
106
is one or more of the following:
109
Print all possible debugging information;
110
equivalent to specifying all of the debugging flags.
112
Print debugging information about archive searching and caching.
114
Print debugging information about conditional evaluation.
116
Print debugging information about directory searching and caching.
118
Print the input graph before making anything.
120
Print the input graph after making everything, or before exiting
123
Print debugging information about running multiple shells.
125
Print debugging information about making targets, including modification
128
Print debugging information about suffix-transformation rules.
130
Print debugging information about target list maintenance.
132
Print debugging information about variable assignment.
135
Specify that environmental variables override macro assignments within
138
Specify a makefile to read instead of the default
146
standard input is read.
147
Multiple makefile's may be specified, and are read in the order specified.
148
.It Fl I Ar directory
149
Specify a directory in which to search for makefiles and included makefiles.
150
The system makefile directory (or directories, see the
152
option) is automatically included as part of this list.
154
Ignore non-zero exit of shell commands in the makefile.
155
Equivalent to specifying
157
before each command line in the makefile.
159
Specify the maximum number of jobs that
161
may have running at any one time. Turns compatibility mode off, unless the
163
flag is also specified.
165
Continue processing after errors are encountered, but only on those targets
166
that do not depend on the target whose creation caused the error.
167
.It Fl m Ar directory
168
Specify a directory in which to search for sys.mk and makefiles included
169
via the <...> style. Multiple directories can be added to form a search path.
170
This path will override the default system include path: /usr/share/mk.
171
Furthermore the system include path will be appended to the search path used
172
for "..."-style inclusions (see the
176
Display the commands that would have been executed, but do not actually
179
Do not execute any commands, but exit 0 if the specified targets are
180
up-to-date and 1, otherwise.
182
Do not use the built-in rules specified in the system makefile.
184
Do not echo any commands as they are executed.
185
Equivalent to specifying
187
before each command line in the makefile.
189
Rather than re-building a target as specified in the makefile, create it
190
or update its modification time to make it appear up-to-date.
196
in the global context.
197
Do not build any targets.
198
Multiple instances of this option may be specified;
199
the variables will be printed one per line,
200
with a blank line for each null or undefined variable.
201
.It Ar variable=value
202
Set the value of the variable
208
There are seven different types of lines in a makefile: file dependency
209
specifications, shell commands, variable assignments, include statements,
210
conditional directives, for loops, and comments.
212
In general, lines may be continued from one line to the next by ending
213
them with a backslash
215
The trailing newline character and initial whitespace on the following
216
line are compressed into a single space.
217
.Sh FILE DEPENDENCY SPECIFICATIONS
218
Dependency lines consist of one or more targets, an operator, and zero
220
This creates a relationship where the targets ``depend'' on the sources
221
and are usually created from them.
222
The exact relationship between the target and the source is determined
223
by the operator that separates them.
224
The three operators are as follows:
227
A target is considered out-of-date if its modification time is less than
228
those of any of its sources.
229
Sources for a target accumulate over dependency lines when this operator
231
The target is removed if
235
Targets are always re-created, but not until all sources have been
236
examined and re-created as necessary.
237
Sources for a target accumulate over dependency lines when this operator
239
The target is removed if
243
If no sources are specified, the target is always re-created.
244
Otherwise, a target is considered out-of-date if any of its sources has
245
been modified more recently than the target.
246
Sources for a target do not accumulate over dependency lines when this
248
The target will not be removed if
253
Targets and sources may contain the shell wildcard values
264
may only be used as part of the final
265
component of the target or source, and must be used to describe existing
269
need not necessarily be used to describe existing files.
270
Expansion is in directory order, not alphabetically as done in the shell.
272
Each target may have associated with it a series of shell commands, normally
273
used to create the target.
274
Each of the commands in this script
276
be preceded by a tab.
277
While any target may appear on a dependency line, only one of these
278
dependencies may be followed by a creation script, unless the
282
If the first or first two characters of the command line are
286
the command is treated specially.
289
causes the command not to be echoed before it is executed.
292
causes any non-zero exit status of the command line to be ignored.
293
.Sh VARIABLE ASSIGNMENTS
294
Variables in make are much like variables in the shell, and, by tradition,
295
consist of all upper-case letters.
296
The five operators that can be used to assign values to variables are as
300
Assign the value to the variable.
301
Any previous value is overridden.
303
Append the value to the current value of the variable.
305
Assign the value to the variable if it is not already defined.
307
Assign with expansion, i.e. expand the value before assigning it
309
Normally, expansion is not done until the variable is referenced.
311
Expand the value and pass it to the shell for execution and assign
312
the result to the variable.
313
Any newlines in the result are replaced with spaces.
316
Any white-space before the assigned
318
is removed; if the value is being appended, a single space is inserted
319
between the previous contents of the variable and the appended value.
321
Variables are expanded by surrounding the variable name with either
326
and preceding it with
329
If the variable name contains only a single letter, the surrounding
330
braces or parentheses are not required.
331
This shorter form is not recommended.
333
Variable substitution occurs at two distinct times, depending on where
334
the variable is being used.
335
Variables in dependency lines are expanded as the line is read.
336
Variables in shell commands are expanded when the shell command is
339
The four different classes of variables (in order of increasing precedence)
342
.It Environment variables
343
Variables defined as part of
347
Variables defined in the makefile or in included makefiles.
348
.It Command line variables
349
Variables defined as part of the command line.
351
Variables that are defined specific to a certain target.
352
The seven local variables are as follows:
353
.Bl -tag -width ".ARCHIVE"
355
The list of all sources for this target; also known as
358
The name of the archive file.
360
The name/path of the source from which the target is to be transformed
361
(the ``implied'' source); also known as
364
The name of the archive member.
366
The list of sources for this target that were deemed out-of-date; also
370
The file prefix of the file, containing only the file portion, no suffix
371
or preceding directory components; also known as
374
The name of the target; also known as
384
are permitted for backward
385
compatibility with historical makefiles and are not recommended.
395
permitted for compatibility with
397
makefiles and are not recommended.
399
Four of the local variables may be used in sources on dependency lines
400
because they expand to the proper value for each target on the line.
410
sets or knows about the following variables:
411
.Bl -tag -width MAKEFLAGS
417
expands to a single dollar
425
A path to the directory where
429
A path to the directory where the targets are built.
431
The environment variable
433
may contain anything that
437
Anything specified on
439
command line is appended to the
441
variable which is then
442
entered into the environment for all programs which
446
Alternate path to the current directory.
450
to the canonical path given by
452
However, if the environment variable
454
is set and gives a path to the current directory, then
462
is set to the value of
464
for all programs which
469
Variable expansion may be modified to select or modify each word of the
470
variable (where a ``word'' is white-space delimited sequence of characters).
471
The general format of a variable expansion is as follows:
473
.Dl {variable[:modifier[:...]]}
475
Each modifier begins with a colon and one of the following
477
The colon may be escaped with a backslash
479
.Bl -tag -width "Cm E\&"
481
Replaces each word in the variable with its suffix.
483
Replaces each word in the variable with everything but the last component.
484
.It Cm M Ns Ar pattern
485
Select only those words that match the rest of the modifier.
486
The standard shell wildcard characters
493
The wildcard characters may be escaped with a backslash
495
.It Cm N Ns Ar pattern
498
but selects all words which do not match
499
the rest of the modifier.
501
Quotes every shell meta-character in the variable, so that it can be passed
502
safely through recursive invocations of
505
Replaces each word in the variable with everything but its suffix.
507
.It Cm S No \&/ Ar old_string Xo
508
.No \&/ Ar new_string
512
Modify the first occurrence of
514
in the variable's value, replacing it with
518
is appended to the last slash of the pattern, all occurrences
519
in each word are replaced.
522
is appended to the last slash of the pattern, only the first word
529
is anchored at the beginning of each word.
532
ends with a dollar sign
534
it is anchored at the end of each word.
545
Any character may be used as a delimiter for the parts of the modifier
547
The anchoring, ampersand and delimiter characters may be escaped with a
551
Variable expansion occurs in the normal fashion inside both
555
with the single exception that a backslash is used to prevent the expansion
558
not a preceding dollar sign as is usual.
560
.It Cm C No \&/ Ar pattern Xo
561
.No \&/ Ar replacement
567
modifier is just like the
569
modifier except that the the old and new strings, instead of being
570
simple strings, are a regular expression (see
574
replacement string. Normally, the first occurrence of the pattern in
575
each word of the value is changed. The
577
modifier causes the substitution to apply to at most one word; the
579
modifier causes the substitution to apply to as many instances of the
580
search pattern as occur in the word or words it is found in. Note that
584
are orthogonal; the former specifies whether multiple words are
585
potentially affected, the latter whether multiple substitutions can
586
potentially occur within each affected word.
588
Replaces each word in the variable with its last component.
589
.It Cm ? Ar true_string Ar \: Ar false_string
590
If the variable evaluates to true, return as its value the
594
.It Ar old_string=new_string
597
style variable substitution.
598
It must be the last modifier specified.
603
do not contain the pattern matching character
605
then it is assumed that they are
606
anchored at the end of each word, so only suffixes or entire
607
words may be replaced. Otherwise
615
.Sh INCLUDE STATEMENTS, CONDITIONALS AND FOR LOOPS
616
Makefile inclusion, conditional structures and for loops reminiscent
617
of the C programming language are provided in
619
All such structures are identified by a line beginning with a single
623
Files are included with either
624
.Cm \&.include Aq Ar file
626
.Cm \&.include Pf \*q Ar file Ns \*q .
627
Variables between the angle brackets or double quotes are expanded
628
to form the file name.
629
If angle brackets are used, the included makefile is expected to be in
630
the system makefile directory.
631
If double quotes are used, the including makefile's directory and any
632
directories specified using the
634
option are searched before the system
636
For compatibility with other versions of
639
is also accepted. If the include statement is written as
643
then errors locating and/or opening include files are ignored.
645
Conditional expressions are also preceded by a single dot as the first
647
The possible conditionals are as follows:
649
.It Ic .undef Ar variable
650
Un-define the specified global variable.
651
Only global variables may be un-defined.
654
.Oo \&! Oc Ns Ar expression
655
.Op Ar operator expression ...
657
Test the value of an expression.
660
.Oo \&! Oc Ns Ar variable
661
.Op Ar operator variable ...
663
Test the value of a variable.
666
.Oo \&! Oc Ns Ar variable
667
.Op Ar operator variable ...
669
Test the value of a variable.
672
.Oo \&! Oc Ns Ar target
673
.Op Ar operator target ...
675
Test the target being built.
679
.Op Ar operator target ...
681
Test the target being built.
683
Reverse the sense of the last conditional.
686
.Oo \&! Oc Ar expression
687
.Op Ar operator expression ...
695
.Oo \&! Oc Ns Ar variable
696
.Op Ar operator variable ...
704
.Oo \&! Oc Ns Ar variable
705
.Op Ar operator variable ...
713
.Oo \&! Oc Ns Ar target
714
.Op Ar operator target ...
722
.Oo \&! Oc Ns Ar target
723
.Op Ar operator target ...
730
End the body of the conditional.
735
may be any one of the following:
736
.Bl -tag -width "Cm XX"
742
of higher precedence than
748
will only evaluate a conditional as far as is necessary to determine
750
Parentheses may be used to change the order of evaluation.
753
may be used to logically negate an entire
755
It is of higher precedence than
760
may be any of the following:
761
.Bl -tag -width "Ic defined"
763
Takes a variable name as an argument and evaluates to true if the variable
766
Takes a target name as an argument and evaluates to true if the target
767
was specified as part of
769
command line or was declared the default target (either implicitly or
772
before the line containing the conditional.
774
Takes a variable, with possible modifiers, and evaluates to true if
775
the expansion of the variable would result in an empty string.
777
Takes a file name as an argument and evaluates to true if the file exists.
778
The file is searched for on the system search path (see
781
Takes a target name as an argument and evaluates to true if the target
786
may also be an arithmetic or string comparison. Variable expansion is
787
performed on both sides of the comparison, after which the integral
788
values are compared. A value is interpreted as hexadecimal if it is
789
preceded by 0x, otherwise it is decimal; octal numbers are not supported.
790
The standard C relational operators are all supported. If after
791
variable expansion, either the left or right hand side of a
795
operator is not an integral value, then
796
string comparison is performed between the expanded
798
If no relational operator is given, it is assumed that the expanded
799
variable is being compared against 0.
803
is evaluating one of these conditional expression, and it encounters
804
a word it doesn't recognize, either the ``make'' or ``defined''
805
expression is applied to it, depending on the form of the conditional.
810
the ``defined'' expression
812
Similarly, if the form is
815
.Ql Ic .ifnmake , the ``make''
816
expression is applied.
818
If the conditional evaluates to true the parsing of the makefile continues
820
If it evaluates to false, the following lines are skipped.
821
In both cases this continues until a
827
For loops are typically used to apply a set of rules to a list of files.
828
The syntax of a for loop is:
845
is evaluated, it is split into words. The
848
is successively set to each word, and substituted in the
850
inside the body of the for loop.
852
Comments begin with a hash
854
character, anywhere but in a shell
855
command line, and continue to the end of the line.
857
.Bl -tag -width "Ic .IGNORE"
859
Ignore any errors from the commands associated with this target, exactly
860
as if they all were preceded by a dash
863
Mark all sources of this target as being up-to-date.
865
Execute the commands associated with this target even if the
869
options were specified.
870
Normally used to mark recursive
875
selects the first target it encounters as the default target to be built
876
if no target was specified.
877
This source prevents this target from being selected.
879
If a target is marked with this attribute and
881
can't figure out how to create it, it will ignore this fact and assume
882
the file isn't needed or already exists.
886
is interrupted, it removes any partially made targets.
887
This source prevents the target from being removed.
889
Do not echo any of the commands associated with this target, exactly
890
as if they all were preceded by an at sign
896
When the target is used as a source for another target, the other target
897
acquires the commands, sources, and attributes (except for
901
If the target already has commands, the
903
target's commands are appended
908
source is appears in a dependency line, the sources that precede it are
909
made before the sources that succeed it in the line. Loops are not being
910
detected and targets that form loops will be silently ignored.
912
.Sh "SPECIAL TARGETS"
913
Special targets may not be included with other targets, i.e. they must be
914
the only target specified.
915
.Bl -tag -width "Ic .BEGIN"
917
Any command lines attached to this target are executed before anything
922
rule for any target (that was used only as a
925
can't figure out any other way to create.
926
Only the shell script is used.
929
variable of a target that inherits
932
to the target's own name.
934
Any command lines attached to this target are executed after everything
937
Mark each of the sources with the
940
If no sources are specified, this is the equivalent of specifying the
946
is interrupted, the commands for this target will be executed.
948
If no target is specified when
950
is invoked, this target will be built.
952
This target provides a way to specify flags for
954
when the makefile is used.
955
The flags are as if typed to the shell, though the
960
.\" .It Ic .NOTPARALLEL
961
.\" The named targets are executed in non parallel mode. If no targets are
962
.\" specified, then all targets are executed in non parallel mode.
966
attribute to any specified sources. Targets with this attribute are not
967
searched for in the directories specified by
970
Disable parallel mode.
972
Same as above, for compatibility with other pmake variants.
974
The named targets are made in sequence.
977
.\" The named targets are executed in parallel mode. If no targets are
978
.\" specified, then all targets are executed in parallel mode.
980
The sources are directories which are to be searched for files not
981
found in the current directory.
982
If no sources are specified, any previously specified directories are
987
attribute to any specified sources. Targets with this attribute do not
988
correspond to actual files; they are always considered to be out of date,
989
and will not be created with the
995
attribute to any specified sources.
996
If no sources are specified, the
998
attribute is applied to every
1003
attribute to any specified sources.
1004
If no sources are specified, the
1006
attribute is applied to every
1007
command in the file.
1009
Each source specifies a suffix to
1011
If no sources are specified, any previous specified suffices are deleted.
1015
utilizes the following environment variables, if they exist:
1024
.Bl -tag -width /usr/share/mk -compact
1026
list of dependencies
1028
list of dependencies
1030
list of dependencies
1034
system makefile directory