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
95 before reading the makefiles or doing anything else.
98 options are specified, each is interpreted relative to the previous one:
99 .Fl C Pa / Fl C Pa etc
105 to be 1, in the global context.
107 Turn on debugging, and specify which portions of
109 are to print debugging information.
112 is one or more of the following:
115 Print all possible debugging information;
116 equivalent to specifying all of the debugging flags.
118 Print debugging information about archive searching and caching.
120 Print debugging information about conditional evaluation.
122 Print debugging information about directory searching and caching.
124 Print debugging information about the execution of for loops.
126 Print the input graph before making anything.
128 Print the input graph after making everything, or before exiting
131 Print debugging information about running multiple shells.
133 Print commands in Makefiles regardless of whether or not they are prefixed
134 by @ or other "quiet" flags.
135 Also known as "loud" behavior.
137 Print debugging information about making targets, including modification
140 Print debugging information about suffix-transformation rules.
142 Print debugging information about target list maintenance.
144 Print debugging information about variable assignment.
147 Specify a variable whose environment value (if any) will override
148 macro assignments within makefiles.
150 Specify that environment values override macro assignments within
151 makefiles for all variables.
153 Specify a makefile to read instead of the default
161 standard input is read.
162 Multiple makefiles may be specified, and are read in the order specified.
163 .It Fl I Ar directory
164 Specify a directory in which to search for makefiles and included makefiles.
165 The system makefile directory (or directories, see the
167 option) is automatically included as part of this list.
169 Ignore non-zero exit of shell commands in the makefile.
170 Equivalent to specifying
172 before each command line in the makefile.
174 Specify the maximum number of jobs that
176 may have running at any one time.
177 Turns compatibility mode off, unless the
179 flag is also specified.
181 Continue processing after errors are encountered, but only on those targets
182 that do not depend on the target whose creation caused the error.
183 .It Fl m Ar directory
184 Specify a directory in which to search for
186 and makefiles included via the <...> style.
187 Multiple directories can be added to form a search path.
188 This path will override the default system include path:
190 Furthermore, the system include path will be appended to the search path used
191 for "..."-style inclusions (see the
195 Display the commands that would have been executed, but do not actually
198 Collate the output of a given job and display it only when the job finishes,
199 instead of mixing the output of parallel jobs together.
200 This option has no effect unless
204 Do not execute any commands, but exit 0 if the specified targets are
205 up-to-date and 1, otherwise.
207 Do not use the built-in rules specified in the system makefile.
209 Stop processing when an error is encountered.
211 This is needed to negate the
213 option during recursive builds.
215 Do not echo any commands as they are executed.
216 Equivalent to specifying
218 before each command line in the makefile.
220 Rather than re-building a target as specified in the makefile, create it
221 or update its modification time to make it appear up-to-date.
227 in the global context.
228 Do not build any targets.
229 Multiple instances of this option may be specified;
230 the variables will be printed one per line,
231 with a blank line for each null or undefined variable.
234 For multi-job makes, this will cause file banners to be generated.
238 option to print the values of variables,
239 do not recursively expand the values.
240 .It Ar variable Ns No = Ns Ar value
241 Set the value of the variable
247 There are seven different types of lines in a makefile: file dependency
248 specifications, shell commands, variable assignments, include statements,
249 conditional directives, for loops, and comments.
251 In general, lines may be continued from one line to the next by ending
252 them with a backslash
254 The trailing newline character and initial whitespace on the following
255 line are compressed into a single space.
256 .Sh FILE DEPENDENCY SPECIFICATIONS
257 Dependency lines consist of one or more targets, an operator, and zero
259 This creates a relationship where the targets
262 and are usually created from them.
263 The exact relationship between the target and the source is determined
264 by the operator that separates them.
265 The three operators are as follows:
268 A target is considered out-of-date if its modification time is less than
269 those of any of its sources.
270 Sources for a target accumulate over dependency lines when this operator
272 The target is removed if
276 Targets are always re-created, but not until all sources have been
277 examined and re-created as necessary.
278 Sources for a target accumulate over dependency lines when this operator
280 The target is removed if
284 If no sources are specified, the target is always re-created.
285 Otherwise, a target is considered out-of-date if any of its sources has
286 been modified more recently than the target.
287 Sources for a target do not accumulate over dependency lines when this
289 The target will not be removed if
294 Targets and sources may contain the shell wildcard expressions
305 may only be used as part of the final
306 component of the target or source, and must be used to describe existing
310 need not necessarily be used to describe existing files.
311 Expansion is in directory order, not alphabetically as done in the shell.
313 Each target may have associated with it a series of shell commands, normally
314 used to create the target.
315 Each of the commands in this script
317 be preceded by a tab.
318 While any target may appear on a dependency line, only one of these
319 dependencies may be followed by a creation script, unless the
323 If the first characters of the command line are
328 the command is treated specially.
331 causes the command not to be echoed before it is executed.
334 causes any non-zero exit status of the command line to be ignored.
337 causes the command to be executed even if
339 is specified on the command line.
340 .Sh VARIABLE ASSIGNMENTS
343 are much like variables in the shell, and, by tradition,
344 consist of all upper-case letters.
345 The five operators that can be used to assign values to variables are as
349 Assign the value to the variable.
350 Any previous value is overridden.
352 Append the value to the current value of the variable.
354 Assign the value to the variable if it is not already defined.
356 Assign with expansion, i.e., expand the value before assigning it
358 Normally, expansion is not done until the variable is referenced.
360 Expand the value and pass it to the shell for execution and assign
361 the result to the variable.
362 Any newlines in the result are replaced with spaces.
365 Any whitespace before the assigned
367 is removed; if the value is being appended, a single space is inserted
368 between the previous contents of the variable and the appended value.
370 Variables are expanded by surrounding the variable name with either
375 and preceding it with
378 If the variable name contains only a single letter, the surrounding
379 braces or parentheses are not required.
380 This shorter form is not recommended.
382 Variable substitution occurs at two distinct times, depending on where
383 the variable is being used.
384 Variables in dependency lines are expanded as the line is read.
385 Variables in shell commands are expanded when the shell command is
388 The four different classes of variables (in order of increasing precedence)
391 .It Environment variables
392 Variables defined as part of
396 Variables defined in the makefile or in included makefiles.
397 .It Command line variables
398 Variables defined as part of the command line and variables
401 environment variable or the
405 Variables that are defined specific to a certain target.
406 The seven local variables are as follows:
407 .Bl -tag -width ".ARCHIVE"
409 The list of all sources for this target; also known as
412 The name of the archive file; also known as
415 The name/path of the source from which the target is to be transformed
418 source); also known as
421 The name of the archive member; also known as
424 The list of sources for this target that were deemed out-of-date; also
428 The file prefix of the file, containing only the file portion, no suffix
429 or preceding directory components; also known as
432 The name of the target; also known as
445 are permitted for backward
446 compatibility and are not recommended.
456 permitted for compatibility with
458 makefiles and are not recommended.
460 Four of the local variables may be used in sources on dependency lines
461 because they expand to the proper value for each target on the line.
472 sets or knows about the following internal variables or environment
474 .Bl -tag -width ".Va MAKEFILE_LIST"
480 expands to a single dollar
486 .Pq Va argv Ns Op 0 .
488 A path to the directory where
495 to the canonical path given by
498 A path to the directory where the targets are built.
501 searches for an alternate directory to place target files.
502 It will attempt to change into this special directory
503 and will search this directory for makefiles
504 not found in the current directory.
505 The following directories are tried in order:
509 ${MAKEOBJDIRPREFIX}/`pwd`
520 The first directory that
522 successfully changes into is used.
527 is set in the environment but
529 is unable to change into the corresponding directory,
530 then the current directory is used
531 without checking the remainder of the list.
532 If they are undefined and
534 is unable to change into any of the remaining three directories,
535 then the current directory is used.
540 must be environment variables and should not be set on
548 to the canonical path given by
550 .It Va .MAKEFILE_LIST
553 reads various makefiles, including the default files and any
554 obtained from the command line and
556 directives, their names will be automatically appended to the
559 They are added right before
561 begins to parse them, so that the name of the current makefile is the
562 last word in this variable.
564 The environment variable
566 may contain anything that
570 Its contents are stored in
574 All options and variable assignments specified on
576 command line are appended to the
578 variable which is then
579 entered into the environment as
581 for all programs which
585 is provided for backward compatibility and
586 contains all the options from the
588 environment variable plus any options specified on
594 is currently building.
604 Name of the machine architecture
606 is running on, obtained from the
608 environment variable, or through
612 Name of the machine architecture
614 was compiled for, defined at compilation time.
616 Makefiles may assign a colon-delimited list of directories to
618 These directories will be searched for source files by
620 after it has finished parsing all input makefiles.
623 Variable expansion may be modified to select or modify each word of the
626 is whitespace-delimited sequence of characters).
627 The general format of a variable expansion is as follows:
629 .Dl {variable[:modifier[:...]]}
631 Each modifier begins with a colon and one of the following
633 The colon may be escaped with a backslash
637 .It Cm C No \&/ Ar pattern Xo
638 .No \&/ Ar replacement
642 Modify each word of the value,
643 substituting every match of the extended regular expression
651 Normally, the first occurrence of the pattern in
652 each word of the value is changed.
655 modifier causes the substitution to apply to at most one word; the
657 modifier causes the substitution to apply to as many instances of the
658 search pattern as occur in the word or words it is found in.
663 are orthogonal; the former specifies whether multiple words are
664 potentially affected, the latter whether multiple substitutions can
665 potentially occur within each affected word.
667 Replaces each word in the variable with its suffix.
669 Replaces each word in the variable with everything but the last component.
671 Converts variable to lower-case letters.
672 .It Cm M Ns Ar pattern
673 Select only those words that match the rest of the modifier.
674 The standard shell wildcard characters
681 The wildcard characters may be escaped with a backslash
683 .It Cm N Ns Ar pattern
686 but selects all words which do not match
687 the rest of the modifier.
689 Order every word in the variable alphabetically.
691 Quotes every shell meta-character in the variable, so that it can be passed
692 safely through recursive invocations of
695 Replaces each word in the variable with everything but its suffix.
697 .It Cm S No \&/ Ar old_string Xo
698 .No \&/ Ar new_string
702 Modify the first occurrence of
704 in each word of the variable's value, replacing it with
708 is appended to the last slash of the pattern, all occurrences
709 in each word are replaced.
715 is anchored at the beginning of each word.
718 ends with a dollar sign
720 it is anchored at the end of each word.
727 Any character may be used as a delimiter for the parts of the modifier
729 The anchoring, ampersand, and delimiter characters may be escaped with a
733 Variable expansion occurs in the normal fashion inside both
737 with the single exception that a backslash is used to prevent the expansion
740 not a preceding dollar sign as is usual.
741 .It Ar old_string=new_string
744 style variable substitution.
745 It must be the last modifier specified.
750 do not contain the pattern matching character
752 then it is assumed that they are
753 anchored at the end of each word, so only suffixes or entire
754 words may be replaced.
762 Replaces each word in the variable with its last component.
764 Converts variable to upper-case letters.
766 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
767 Directives, conditionals, and for loops reminiscent
768 of the C programming language are provided in
770 All such structures are identified by a line beginning with a single
774 The following directives are supported:
776 .It Ic \&.include Ar <file>
777 .It Ic \&.include Ar \*qfile\*q
778 Include the specified makefile.
779 Variables between the angle brackets
780 or double quotes are expanded to form the file name.
782 are used, the included makefile is expected to be in the system
784 If double quotes are used, the including
785 makefile's directory and any directories specified using the
787 option are searched before the system
789 .It Ic .undef Ar variable
790 Un-define the specified global variable.
791 Only global variables may be un-defined.
792 .It Ic .error Ar message
793 Terminate processing of the makefile immediately.
795 makefile, the line on which the error was encountered and the specified
796 message are printed to the standard error output and
798 terminates with exit code 1.
799 Variables in the message are expanded.
800 .It Ic .warning Ar message
801 Emit a warning message.
802 The filename of the makefile,
803 the line on which the warning was encountered,
804 and the specified message are printed to the standard error output.
805 Variables in the message are expanded.
808 Conditionals are used to determine which parts of the Makefile
810 They are used similarly to the conditionals supported
811 by the C pre-processor.
812 The following conditionals are supported:
816 .Oo \&! Oc Ns Ar expression
817 .Op Ar operator expression ...
819 Test the value of an expression.
822 .Oo \&! Oc Ns Ar variable
823 .Op Ar operator variable ...
825 Test the value of a variable.
828 .Oo \&! Oc Ns Ar variable
829 .Op Ar operator variable ...
831 Test the value of a variable.
834 .Oo \&! Oc Ns Ar target
835 .Op Ar operator target ...
837 Test the target being built.
840 .Oo \&! Oc Ns Ar target
841 .Op Ar operator target ...
843 Test the target being built.
845 Reverse the sense of the last conditional.
848 .Oo \&! Oc Ns Ar expression
849 .Op Ar operator expression ...
857 .Oo \&! Oc Ns Ar variable
858 .Op Ar operator variable ...
866 .Oo \&! Oc Ns Ar variable
867 .Op Ar operator variable ...
875 .Oo \&! Oc Ns Ar target
876 .Op Ar operator target ...
884 .Oo \&! Oc Ns Ar target
885 .Op Ar operator target ...
892 End the body of the conditional.
897 may be any one of the following:
898 .Bl -tag -width "Cm XX"
905 of higher precedence than
911 will only evaluate a conditional as far as is necessary to determine
913 Parentheses may be used to change the order of evaluation.
916 may be used to logically negate an entire
918 It is of higher precedence than
923 may be any of the following:
926 Takes a variable name as an argument and evaluates to true if the variable
929 Takes a target name as an argument and evaluates to true if the target
930 was specified as part of
932 command line or was declared the default target (either implicitly or
935 before the line containing the conditional.
937 Takes a variable, with possible modifiers, and evaluates to true if
938 the expansion of the variable would result in an empty string.
940 Takes a file name as an argument and evaluates to true if the file exists.
941 The file is searched for on the system search path (see
944 Takes a target name as an argument and evaluates to true if the target
950 may also be an arithmetic or string comparison, with the left-hand side
951 being a variable expansion.
952 Variable expansion is
953 performed on both sides of the comparison, after which the integral
955 A value is interpreted as hexadecimal if it is
956 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
957 The standard C relational operators are all supported.
959 variable expansion, either the left or right hand side of a
963 operator is not an integral value, then
964 string comparison is performed between the expanded
966 If no relational operator is given, it is assumed that the expanded
967 variable is being compared against 0.
971 is evaluating one of these conditional expressions, and it encounters
972 a word it doesn't recognize, either the
976 expression is applied to it, depending on the form of the conditional.
984 expression is applied.
985 Similarly, if the form is
991 expression is applied.
993 If the conditional evaluates to true the parsing of the makefile continues
995 If it evaluates to false, the following lines are skipped.
996 In both cases this continues until a
1002 For loops are typically used to apply a set of rules to a list of files.
1003 The syntax of a for loop is:
1005 .Bl -tag -width indent -compact
1006 .It Ic .for Ar variable Ic in Ar expression
1013 is evaluated, it is split into words.
1017 is successively set to each word, and substituted in the
1019 inside the body of the for loop.
1021 Comments begin with a hash
1023 character, anywhere but in a shell
1024 command line, and continue to the end of the line.
1028 Ignore any errors from the commands associated with this target, exactly
1029 as if they all were preceded by a dash
1032 Execute the commands associated with this target even if the
1036 options were specified.
1037 Normally used to mark recursive
1042 selects the first target it encounters as the default target to be built
1043 if no target was specified.
1044 This source prevents this target from being selected.
1046 If a target is marked with this attribute and
1048 can't figure out how to create it, it will ignore this fact and assume
1049 the file isn't needed or already exists.
1053 is interrupted, it removes any partially made targets.
1054 This source prevents the target from being removed.
1056 Do not echo any of the commands associated with this target, exactly
1057 as if they all were preceded by an at sign
1060 Turn the target into
1063 When the target is used as a source for another target, the other target
1064 acquires the commands, sources, and attributes (except for
1068 If the target already has commands, the
1070 target's commands are appended
1075 source is appears in a dependency line, the sources that precede it are
1076 made before the sources that succeed it in the line.
1078 detected and targets that form loops will be silently ignored.
1080 .Sh "SPECIAL TARGETS"
1081 Special targets may not be included with other targets, i.e., they must be
1082 the only target specified.
1085 Any command lines attached to this target are executed before anything
1090 rule for any target (that was used only as a
1093 can't figure out any other way to create.
1094 Only the shell script is used.
1097 variable of a target that inherits
1100 to the target's own name.
1102 Any command lines attached to this target are executed after everything
1105 Mark each of the sources with the
1108 If no sources are specified, this is the equivalent of specifying the
1112 A list of suffixes that indicate files that can be included in a source
1114 The suffix must have already been declared with
1116 any suffix so declared will have the directories on its search path (see
1120 special variable, each preceded by a
1126 is interrupted, the commands for this target will be executed.
1128 This does for libraries what
1130 does for include files, except that the flag used is
1133 If no target is specified when
1135 is invoked, this target will be built.
1136 This is always set, either
1137 explicitly, or implicitly when
1139 selects the default target, to give the user a way to refer to the default
1140 target on the command line.
1142 This target provides a way to specify flags for
1144 when the makefile is used.
1145 The flags are as if typed to the shell, though the
1150 Same as above, for backward compatibility.
1151 .\" XXX: NOT YET!!!!
1152 .\" .It Ic .NOTPARALLEL
1153 .\" The named targets are executed in non parallel mode. If no targets are
1154 .\" specified, then all targets are executed in non parallel mode.
1156 Disable parallel mode.
1158 Same as above, for compatibility with other
1162 The named targets are made in sequence.
1163 .\" XXX: NOT YET!!!!
1164 .\" .It Ic .PARALLEL
1165 .\" The named targets are executed in parallel mode. If no targets are
1166 .\" specified, then all targets are executed in parallel mode.
1168 The sources are directories which are to be searched for files not
1169 found in the current directory.
1170 If no sources are specified, any previously specified directories are
1172 Where possible, use of
1174 is preferred over use of the
1177 .It Ic .PATH\fIsuffix\fR
1178 The sources are directories which are to be searched for suffixed files
1179 not found in the current directory.
1183 first searches the suffixed search path, before reverting to the default
1184 path if the file is not found there.
1185 This form is required for
1193 attribute to any specified sources.
1194 Targets with this attribute are always
1195 considered to be out of date.
1199 attribute to any specified sources.
1200 If no sources are specified, the
1202 attribute is applied to every
1207 attribute to any specified sources.
1208 If no sources are specified, the
1210 attribute is applied to every
1211 command in the file.
1213 Each source specifies a suffix to
1215 If no sources are specified, any previous specified suffices are deleted.
1224 This was removed for POSIX compatibility.
1225 The internal variable
1227 is set to the same value as
1229 support for this may be removed in the future.
1231 Most of the more esoteric features of
1233 should probably be avoided for greater compatibility.
1237 utility uses the following environment variables, if they exist:
1243 .Ev MAKEOBJDIRPREFIX .
1245 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1247 list of dependencies
1249 list of dependencies
1251 list of dependencies
1255 system makefile (processed before any other file, including
1259 .It Pa /usr/share/mk
1260 system makefile directory
1261 .It /usr/share/doc/psd/12.make
1265 .Ev MAKEOBJDIRPREFIX
1269 List all included makefiles in order visited:
1271 .Dl "make -V .MAKEFILE_LIST | tr \e\ \e\en"
1273 The determination of
1275 is contorted to the point of absurdity.
1277 In the presence of several
1281 silently ignores all but the first.
1284 is not set to the default target when
1286 is invoked without a target name and no
1288 special target exists.
1292 in a test is very simple-minded.
1293 Currently, the only form that works is
1294 .Ql .if ${VAR} op something
1295 For instance, you should write tests as
1296 .Ql .if ${VAR} == "string"
1297 not the other way around, which would give you an error.
1299 For loops are expanded before tests, so a fragment such as:
1300 .Bd -literal -offset indent
1301 \&.for ARCH in ${SHARED_ARCHS}
1302 \&.if ${ARCH} == ${MACHINE}
1308 won't work, and should be rewritten as:
1309 .Bd -literal -offset indent
1310 \&.for ARCH in ${SHARED_ARCHS}
1311 \&.if ${MACHINE} == ${ARCH}
1317 The parsing code is broken with respect to handling a semicolon
1318 after a colon, so a fragment like this will fail:
1319 .Bd -literal -offset indent
1323 \&.for h in ${HDRS:S;^;${.CURDIR}/;}
1331 .%T "PMake - A Tutorial"
1334 .Pa /usr/share/doc/psd/12.make
1338 command appeared in PWB UNIX.