1 .\" Copyright (c) 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. All advertising materials mentioning features or use of this software
13 .\" must display the following acknowledgement:
14 .\" This product includes software developed by the University of
15 .\" California, Berkeley and its contributors.
16 .\" 4. Neither the name of the University nor the names of its contributors
17 .\" may be used to endorse or promote products derived from this software
18 .\" without specific prior written permission.
20 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 .\" @(#)make.1 8.8 (Berkeley) 6/13/95
40 .Nd maintain program dependencies
55 .Op Ar variable Ns No = Ns Ar value
60 utility is a program designed to simplify the maintenance of other programs.
61 Its input is a list of specifications
62 describing dependency relationships between the generation of
69 that can be found in either the current directory or a special object directory
72 will be read for this list of specifications.
75 can be found, it is also read (see
78 This manual page is intended as a reference document only.
79 For a more thorough introduction to
81 and makefiles, please refer to
82 .%T "Make \- A Tutorial" .
84 The options are as follows:
87 Try to be backwards compatible by executing a single shell per command and
88 by executing the commands to make the sources of a dependency line in sequence.
89 This is turned on by default unless
99 to be 1, in the global context.
101 Turn on debugging, and specify which portions of
103 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 debugging information about the execution of for loops.
120 Print the input graph before making anything.
122 Print the input graph after making everything, or before exiting
125 Print debugging information about running multiple shells.
127 Print commands in Makefiles regardless of whether or not they are prefixed
128 by @ or other "quiet" flags.
129 Also known as "loud" behavior.
131 Print debugging information about making targets, including modification
134 Print debugging information about suffix-transformation rules.
136 Print debugging information about target list maintenance.
138 Print debugging information about variable assignment.
141 Specify a variable whose environment value (if any) will override
142 macro assignments within makefiles.
144 Specify that environment values override macro assignments within
145 makefiles for all variables.
147 Specify a makefile to read instead of the default
155 standard input is read.
156 Multiple makefiles may be specified, and are read in the order specified.
157 .It Fl I Ar directory
158 Specify a directory in which to search for makefiles and included makefiles.
159 The system makefile directory (or directories, see the
161 option) is automatically included as part of this list.
163 Ignore non-zero exit of shell commands in the makefile.
164 Equivalent to specifying
166 before each command line in the makefile.
168 Specify the maximum number of jobs that
170 may have running at any one time.
171 Turns compatibility mode off, unless the
173 flag is also specified.
175 Continue processing after errors are encountered, but only on those targets
176 that do not depend on the target whose creation caused the error.
177 .It Fl m Ar directory
178 Specify a directory in which to search for
180 and makefiles included via the <...> style.
181 Multiple directories can be added to form a search path.
182 This path will override the default system include path:
184 Furthermore, the system include path will be appended to the search path used
185 for "..."-style inclusions (see the
189 Display the commands that would have been executed, but do not actually
192 Collate the output of a given job and display it only when the job finishes,
193 instead of mixing the output of parallel jobs together.
194 This option has no effect unless
198 Do not execute any commands, but exit 0 if the specified targets are
199 up-to-date and 1, otherwise.
201 Do not use the built-in rules specified in the system makefile.
203 Stop processing when an error is encountered.
205 This is needed to negate the
207 option during recursive builds.
209 Do not echo any commands as they are executed.
210 Equivalent to specifying
212 before each command line in the makefile.
214 Rather than re-building a target as specified in the makefile, create it
215 or update its modification time to make it appear up-to-date.
221 in the global context.
222 Do not build any targets.
223 Multiple instances of this option may be specified;
224 the variables will be printed one per line,
225 with a blank line for each null or undefined variable.
228 For multi-job makes, this will cause file banners to be generated.
232 option to print the values of variables,
233 do not recursively expand the values.
234 .It Ar variable Ns No = Ns Ar value
235 Set the value of the variable
241 There are seven different types of lines in a makefile: file dependency
242 specifications, shell commands, variable assignments, include statements,
243 conditional directives, for loops, and comments.
245 In general, lines may be continued from one line to the next by ending
246 them with a backslash
248 The trailing newline character and initial whitespace on the following
249 line are compressed into a single space.
250 .Sh FILE DEPENDENCY SPECIFICATIONS
251 Dependency lines consist of one or more targets, an operator, and zero
253 This creates a relationship where the targets
256 and are usually created from them.
257 The exact relationship between the target and the source is determined
258 by the operator that separates them.
259 The three operators are as follows:
262 A target is considered out-of-date if its modification time is less than
263 those of any of its sources.
264 Sources for a target accumulate over dependency lines when this operator
266 The target is removed if
270 Targets are always re-created, but not until all sources have been
271 examined and re-created as necessary.
272 Sources for a target accumulate over dependency lines when this operator
274 The target is removed if
278 If no sources are specified, the target is always re-created.
279 Otherwise, a target is considered out-of-date if any of its sources has
280 been modified more recently than the target.
281 Sources for a target do not accumulate over dependency lines when this
283 The target will not be removed if
288 Targets and sources may contain the shell wildcard expressions
299 may only be used as part of the final
300 component of the target or source, and must be used to describe existing
304 need not necessarily be used to describe existing files.
305 Expansion is in directory order, not alphabetically as done in the shell.
307 Each target may have associated with it a series of shell commands, normally
308 used to create the target.
309 Each of the commands in this script
311 be preceded by a tab.
312 While any target may appear on a dependency line, only one of these
313 dependencies may be followed by a creation script, unless the
317 If the first or first two characters of the command line are
321 the command is treated specially.
324 causes the command not to be echoed before it is executed.
327 causes any non-zero exit status of the command line to be ignored.
328 .Sh VARIABLE ASSIGNMENTS
331 are much like variables in the shell, and, by tradition,
332 consist of all upper-case letters.
333 The five operators that can be used to assign values to variables are as
337 Assign the value to the variable.
338 Any previous value is overridden.
340 Append the value to the current value of the variable.
342 Assign the value to the variable if it is not already defined.
344 Assign with expansion, i.e. expand the value before assigning it
346 Normally, expansion is not done until the variable is referenced.
348 Expand the value and pass it to the shell for execution and assign
349 the result to the variable.
350 Any newlines in the result are replaced with spaces.
353 Any whitespace before the assigned
355 is removed; if the value is being appended, a single space is inserted
356 between the previous contents of the variable and the appended value.
358 Variables are expanded by surrounding the variable name with either
363 and preceding it with
366 If the variable name contains only a single letter, the surrounding
367 braces or parentheses are not required.
368 This shorter form is not recommended.
370 Variable substitution occurs at two distinct times, depending on where
371 the variable is being used.
372 Variables in dependency lines are expanded as the line is read.
373 Variables in shell commands are expanded when the shell command is
376 The four different classes of variables (in order of increasing precedence)
379 .It Environment variables
380 Variables defined as part of
384 Variables defined in the makefile or in included makefiles.
385 .It Command line variables
386 Variables defined as part of the command line.
388 Variables that are defined specific to a certain target.
389 The seven local variables are as follows:
390 .Bl -tag -width ".ARCHIVE"
392 The list of all sources for this target; also known as
395 The name of the archive file; also known as
398 The name/path of the source from which the target is to be transformed
401 source); also known as
404 The name of the archive member; also known as
407 The list of sources for this target that were deemed out-of-date; also
411 The file prefix of the file, containing only the file portion, no suffix
412 or preceding directory components; also known as
415 The name of the target; also known as
428 are permitted for backward
429 compatibility and are not recommended.
439 permitted for compatibility with
441 makefiles and are not recommended.
443 Four of the local variables may be used in sources on dependency lines
444 because they expand to the proper value for each target on the line.
455 sets or knows about the following internal variables or environment
457 .Bl -tag -width MAKEFLAGS
463 expands to a single dollar
469 .Pq Va argv Ns Op 0 .
471 A path to the directory where
478 to the canonical path given by
481 A path to the directory where the targets are built.
484 searches for an alternate directory to place target files.
485 It will attempt to change into this special directory
486 and will search this directory for makefiles
487 not found in the current directory.
488 The following directories are tried in order:
492 ${MAKEOBJDIRPREFIX}/`pwd`
503 The first directory that
505 successfully changes into is used.
510 is set in the environment but
512 is unable to change into the corresponding directory,
513 then the current directory is used
514 without checking the remainder of the list.
515 If they are undefined and
517 is unable to change into any of the remaining three directories,
518 then the current directory is used.
524 to the canonical path given by
527 The environment variable
529 may contain anything that
533 Its contents are stored in
537 Anything specified on
539 command line is appended to the
541 variable which is then
542 entered into the environment as
544 for all programs which
550 provided for backward compatibility.
554 is currently building.
564 Name of the machine architecture
566 is running on, obtained from the
568 environment variable, or through
572 Name of the machine architecture
574 was compiled for, defined at compilation time.
576 Makefiles may assign a colon-delimited list of directories to
578 These directories will be searched for source files by
580 after it has finished parsing all input makefiles.
583 Variable expansion may be modified to select or modify each word of the
586 is whitespace-delimited sequence of characters).
587 The general format of a variable expansion is as follows:
589 .Dl {variable[:modifier[:...]]}
591 Each modifier begins with a colon and one of the following
593 The colon may be escaped with a backslash
597 .It Cm C No \&/ Ar pattern Xo
598 .No \&/ Ar replacement
604 modifier is just like the
606 modifier except that the old and new strings, instead of being
607 simple strings, are an extended regular expression (see
612 Normally, the first occurrence of the pattern in
613 each word of the value is changed.
616 modifier causes the substitution to apply to at most one word; the
618 modifier causes the substitution to apply to as many instances of the
619 search pattern as occur in the word or words it is found in.
624 are orthogonal; the former specifies whether multiple words are
625 potentially affected, the latter whether multiple substitutions can
626 potentially occur within each affected word.
628 Replaces each word in the variable with its suffix.
630 Replaces each word in the variable with everything but the last component.
632 Converts variable to lower-case letters.
633 .It Cm M Ns Ar pattern
634 Select only those words that match the rest of the modifier.
635 The standard shell wildcard characters
642 The wildcard characters may be escaped with a backslash
644 .It Cm N Ns Ar pattern
647 but selects all words which do not match
648 the rest of the modifier.
650 Quotes every shell meta-character in the variable, so that it can be passed
651 safely through recursive invocations of
654 Replaces each word in the variable with everything but its suffix.
656 .It Cm S No \&/ Ar old_string Xo
657 .No \&/ Ar new_string
661 Modify the first occurrence of
663 in each word of the variable's value, replacing it with
667 is appended to the last slash of the pattern, all occurrences
668 in each word are replaced.
674 is anchored at the beginning of each word.
677 ends with a dollar sign
679 it is anchored at the end of each word.
686 Any character may be used as a delimiter for the parts of the modifier
688 The anchoring, ampersand, and delimiter characters may be escaped with a
692 Variable expansion occurs in the normal fashion inside both
696 with the single exception that a backslash is used to prevent the expansion
699 not a preceding dollar sign as is usual.
700 .It Ar old_string=new_string
703 style variable substitution.
704 It must be the last modifier specified.
709 do not contain the pattern matching character
711 then it is assumed that they are
712 anchored at the end of each word, so only suffixes or entire
713 words may be replaced.
721 Replaces each word in the variable with its last component.
723 Converts variable to upper-case letters.
725 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
726 Directives, conditionals, and for loops reminiscent
727 of the C programming language are provided in
729 All such structures are identified by a line beginning with a single
733 The following directives are supported:
735 .It Ic \&.include Ar <file>
736 .It Ic \&.include Ar \*qfile\*q
737 Include the specified makefile.
738 Variables between the angle brackets
739 or double quotes are expanded to form the file name.
741 are used, the included makefile is expected to be in the system
743 If double quotes are used, the including
744 makefile's directory and any directories specified using the
746 option are searched before the system
748 .It Ic \&.undef Ar variable
749 Un-define the specified global variable.
750 Only global variables may be un-defined.
751 .It Ic \&.error Ar message
752 Terminate processing of the makefile immediately.
754 makefile, the line on which the error was encountered and the specified
755 message are printed to standard output and
757 terminates with exit code 1.
758 Variables in the message are expanded.
761 Conditionals are used to determine which parts of the Makefile
763 They are used similarly to the conditionals supported
764 by the C pre-processor.
765 The following conditionals are supported:
769 .Oo \&! Oc Ns Ar expression
770 .Op Ar operator expression ...
772 Test the value of an expression.
775 .Oo \&! Oc Ns Ar variable
776 .Op Ar operator variable ...
778 Test the value of a variable.
781 .Oo \&! Oc Ns Ar variable
782 .Op Ar operator variable ...
784 Test the value of a variable.
787 .Oo \&! Oc Ns Ar target
788 .Op Ar operator target ...
790 Test the target being built.
793 .Oo \&! Oc Ns Ar target
794 .Op Ar operator target ...
796 Test the target being built.
798 Reverse the sense of the last conditional.
801 .Oo \&! Oc Ns Ar expression
802 .Op Ar operator expression ...
810 .Oo \&! Oc Ns Ar variable
811 .Op Ar operator variable ...
819 .Oo \&! Oc Ns Ar variable
820 .Op Ar operator variable ...
828 .Oo \&! Oc Ns Ar target
829 .Op Ar operator target ...
837 .Oo \&! Oc Ns Ar target
838 .Op Ar operator target ...
845 End the body of the conditional.
850 may be any one of the following:
851 .Bl -tag -width "Cm XX"
858 of higher precedence than
864 will only evaluate a conditional as far as is necessary to determine
866 Parentheses may be used to change the order of evaluation.
869 may be used to logically negate an entire
871 It is of higher precedence than
876 may be any of the following:
879 Takes a variable name as an argument and evaluates to true if the variable
882 Takes a target name as an argument and evaluates to true if the target
883 was specified as part of
885 command line or was declared the default target (either implicitly or
888 before the line containing the conditional.
890 Takes a variable, with possible modifiers, and evaluates to true if
891 the expansion of the variable would result in an empty string.
893 Takes a file name as an argument and evaluates to true if the file exists.
894 The file is searched for on the system search path (see
897 Takes a target name as an argument and evaluates to true if the target
903 may also be an arithmetic or string comparison, with the left-hand side
904 being a variable expansion.
905 Variable expansion is
906 performed on both sides of the comparison, after which the integral
908 A value is interpreted as hexadecimal if it is
909 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
910 The standard C relational operators are all supported.
912 variable expansion, either the left or right hand side of a
916 operator is not an integral value, then
917 string comparison is performed between the expanded
919 If no relational operator is given, it is assumed that the expanded
920 variable is being compared against 0.
924 is evaluating one of these conditional expressions, and it encounters
925 a word it doesn't recognize, either the
929 expression is applied to it, depending on the form of the conditional.
937 expression is applied.
938 Similarly, if the form is
944 expression is applied.
946 If the conditional evaluates to true the parsing of the makefile continues
948 If it evaluates to false, the following lines are skipped.
949 In both cases this continues until a
955 For loops are typically used to apply a set of rules to a list of files.
956 The syntax of a for loop is:
958 .Bl -tag -width indent -compact
959 .It Ic .for Ar variable Ic in Ar expression
966 is evaluated, it is split into words.
970 is successively set to each word, and substituted in the
972 inside the body of the for loop.
974 Comments begin with a hash
976 character, anywhere but in a shell
977 command line, and continue to the end of the line.
981 Ignore any errors from the commands associated with this target, exactly
982 as if they all were preceded by a dash
985 Execute the commands associated with this target even if the
989 options were specified.
990 Normally used to mark recursive
995 selects the first target it encounters as the default target to be built
996 if no target was specified.
997 This source prevents this target from being selected.
999 If a target is marked with this attribute and
1001 can't figure out how to create it, it will ignore this fact and assume
1002 the file isn't needed or already exists.
1006 is interrupted, it removes any partially made targets.
1007 This source prevents the target from being removed.
1009 Do not echo any of the commands associated with this target, exactly
1010 as if they all were preceded by an at sign
1013 Turn the target into
1016 When the target is used as a source for another target, the other target
1017 acquires the commands, sources, and attributes (except for
1021 If the target already has commands, the
1023 target's commands are appended
1028 source is appears in a dependency line, the sources that precede it are
1029 made before the sources that succeed it in the line.
1031 detected and targets that form loops will be silently ignored.
1033 .Sh "SPECIAL TARGETS"
1034 Special targets may not be included with other targets, i.e. they must be
1035 the only target specified.
1038 Any command lines attached to this target are executed before anything
1043 rule for any target (that was used only as a
1046 can't figure out any other way to create.
1047 Only the shell script is used.
1050 variable of a target that inherits
1053 to the target's own name.
1055 Any command lines attached to this target are executed after everything
1058 Mark each of the sources with the
1061 If no sources are specified, this is the equivalent of specifying the
1065 A list of suffixes that indicate files that can be included in a source
1067 The suffix must have already been declared with
1069 any suffix so declared will have the directories on its search path (see
1073 special variable, each preceded by a
1079 is interrupted, the commands for this target will be executed.
1081 This does for libraries what
1083 does for include files, except that the flag used is
1086 If no target is specified when
1088 is invoked, this target will be built.
1089 This is always set, either
1090 explicitly, or implicitly when
1092 selects the default target, to give the user a way to refer to the default
1093 target on the command line.
1095 This target provides a way to specify flags for
1097 when the makefile is used.
1098 The flags are as if typed to the shell, though the
1102 .\" XXX: NOT YET!!!!
1103 .\" .It Ic .NOTPARALLEL
1104 .\" The named targets are executed in non parallel mode. If no targets are
1105 .\" specified, then all targets are executed in non parallel mode.
1107 Disable parallel mode.
1109 Same as above, for compatibility with other
1113 The named targets are made in sequence.
1114 .\" XXX: NOT YET!!!!
1115 .\" .It Ic .PARALLEL
1116 .\" The named targets are executed in parallel mode. If no targets are
1117 .\" specified, then all targets are executed in parallel mode.
1119 The sources are directories which are to be searched for files not
1120 found in the current directory.
1121 If no sources are specified, any previously specified directories are
1123 Where possible, use of
1125 is preferred over use of the
1128 .It Ic .PATH\fIsuffix\fR
1129 The sources are directories which are to be searched for suffixed files
1130 not found in the current directory.
1134 first searches the suffixed search path, before reverting to the default
1135 path if the file is not found there.
1136 This form is required for
1144 attribute to any specified sources.
1145 Targets with this attribute are always
1146 considered to be out of date.
1150 attribute to any specified sources.
1151 If no sources are specified, the
1153 attribute is applied to every
1158 attribute to any specified sources.
1159 If no sources are specified, the
1161 attribute is applied to every
1162 command in the file.
1164 Each source specifies a suffix to
1166 If no sources are specified, any previous specified suffices are deleted.
1175 This was removed for POSIX compatibility.
1176 The internal variable
1178 is set to the same value as
1180 support for this may be removed in the future.
1182 Most of the more esoteric features of
1184 should probably be avoided for greater compatibility.
1188 utility uses the following environment variables, if they exist:
1194 .Ev MAKEOBJDIRPREFIX .
1196 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1198 list of dependencies
1200 list of dependencies
1202 list of dependencies
1206 system makefile (processed before any other file, including
1210 .It Pa /usr/share/mk
1211 system makefile directory
1212 .It /usr/share/doc/psd/12.make
1216 .Ev MAKEOBJDIRPREFIX
1220 The determination of
1222 is contorted to the point of absurdity.
1224 In the presence of several
1228 silently ignores all but the first.
1231 is not set to the default target when
1233 is invoked without a target name and no
1235 special target exists.
1239 in a test is very simple-minded.
1240 Currently, the only form that works is
1241 .Ql .if ${VAR} op something
1242 For instance, you should write tests as
1243 .Ql .if ${VAR} = "string"
1244 not the other way around, which doesn't work.
1246 For loops are expanded before tests, so a fragment such as:
1247 .Bd -literal -offset indent
1248 \&.for TMACHINE in ${SHARED_ARCHS}
1249 \&.if ${TMACHINE} = ${MACHINE}
1255 won't work, and should be rewritten the other way around.
1257 The parsing code is broken with respect to handling a semicolon
1258 after a colon, so a fragment like this will fail:
1259 .Bd -literal -offset indent
1263 \&.for h in ${HDRS:S;^;${.CURDIR}/;}
1271 .%T "PMake - A Tutorial"
1274 .Pa /usr/share/doc/psd/12.make
1278 command appeared in PWB UNIX.