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
54 .Op Ar variable Ns No = Ns Ar value
59 utility is a program designed to simplify the maintenance of other programs.
60 Its input is a list of specifications
61 describing dependency relationships between the generation of
68 that can be found in either the current directory or a special object directory
71 will be read for this list of specifications.
74 can be found, it is also read (see
77 This manual page is intended as a reference document only.
78 For a more thorough introduction to
80 and makefiles, please refer to
81 .%T "Make \- A Tutorial" .
83 The options are as follows:
86 Try to be backwards compatible by executing a single shell per command and
87 by executing the commands to make the sources of a dependency line in sequence.
88 This is turned on by default unless
94 to be 1, in the global context.
96 Turn on debugging, and specify which portions of
98 are to print debugging information.
101 is one or more of the following:
104 Print all possible debugging information;
105 equivalent to specifying all of the debugging flags.
107 Print debugging information about archive searching and caching.
109 Print debugging information about conditional evaluation.
111 Print debugging information about directory searching and caching.
113 Print debugging information about the execution of for loops.
117 Print the input graph before making anything.
119 Print the input graph after making everything, or before exiting
122 Print debugging information about running multiple shells.
124 Print commands in Makefiles regardless of whether or not they are prefixed
125 by @ or other "quiet" flags.
126 Also known as "loud" behavior.
128 Print debugging information about making targets, including modification
131 Print debugging information about suffix-transformation rules.
133 Print debugging information about target list maintenance.
135 Print debugging information about variable assignment.
138 Specify a variable whose environment value (if any) will override
139 macro assignments within makefiles.
141 Specify that environment values override macro assignments within
142 makefiles for all variables.
144 Specify a makefile to read instead of the default
152 standard input is read.
153 Multiple makefiles may be specified, and are read in the order specified.
154 .It Fl I Ar directory
155 Specify a directory in which to search for makefiles and included makefiles.
156 The system makefile directory (or directories, see the
158 option) is automatically included as part of this list.
160 Ignore non-zero exit of shell commands in the makefile.
161 Equivalent to specifying
163 before each command line in the makefile.
165 Specify the maximum number of jobs that
167 may have running at any one time.
168 Turns compatibility mode off, unless the
170 flag is also specified.
172 Continue processing after errors are encountered, but only on those targets
173 that do not depend on the target whose creation caused the error.
174 .It Fl m Ar directory
175 Specify a directory in which to search for
177 and makefiles included via the <...> style.
178 Multiple directories can be added to form a search path.
179 This path will override the default system include path:
181 Furthermore, the system include path will be appended to the search path used
182 for "..."-style inclusions (see the
186 Display the commands that would have been executed, but do not actually
189 Collate the output of a given job and display it only when the job finishes,
190 instead of mixing the output of parallel jobs together.
191 This option has no effect unless
195 Do not execute any commands, but exit 0 if the specified targets are
196 up-to-date and 1, otherwise.
198 Do not use the built-in rules specified in the system makefile.
200 Stop processing when an error is encountered.
202 This is needed to negate the
204 option during recursive builds.
206 Do not echo any commands as they are executed.
207 Equivalent to specifying
209 before each command line in the makefile.
211 Rather than re-building a target as specified in the makefile, create it
212 or update its modification time to make it appear up-to-date.
218 in the global context.
219 Do not build any targets.
220 Multiple instances of this option may be specified;
221 the variables will be printed one per line,
222 with a blank line for each null or undefined variable.
225 For multi-job makes, this will cause file banners to be generated.
229 option to print the values of variables,
230 do not recursively expand the values.
231 .It Ar variable Ns No = Ns Ar value
232 Set the value of the variable
238 There are seven different types of lines in a makefile: file dependency
239 specifications, shell commands, variable assignments, include statements,
240 conditional directives, for loops, and comments.
242 In general, lines may be continued from one line to the next by ending
243 them with a backslash
245 The trailing newline character and initial whitespace on the following
246 line are compressed into a single space.
247 .Sh FILE DEPENDENCY SPECIFICATIONS
248 Dependency lines consist of one or more targets, an operator, and zero
250 This creates a relationship where the targets
253 and are usually created from them.
254 The exact relationship between the target and the source is determined
255 by the operator that separates them.
256 The three operators are as follows:
259 A target is considered out-of-date if its modification time is less than
260 those of any of its sources.
261 Sources for a target accumulate over dependency lines when this operator
263 The target is removed if
267 Targets are always re-created, but not until all sources have been
268 examined and re-created as necessary.
269 Sources for a target accumulate over dependency lines when this operator
271 The target is removed if
275 If no sources are specified, the target is always re-created.
276 Otherwise, a target is considered out-of-date if any of its sources has
277 been modified more recently than the target.
278 Sources for a target do not accumulate over dependency lines when this
280 The target will not be removed if
285 Targets and sources may contain the shell wildcard expressions
296 may only be used as part of the final
297 component of the target or source, and must be used to describe existing
301 need not necessarily be used to describe existing files.
302 Expansion is in directory order, not alphabetically as done in the shell.
304 Each target may have associated with it a series of shell commands, normally
305 used to create the target.
306 Each of the commands in this script
308 be preceded by a tab.
309 While any target may appear on a dependency line, only one of these
310 dependencies may be followed by a creation script, unless the
314 If the first or first two characters of the command line are
318 the command is treated specially.
321 causes the command not to be echoed before it is executed.
324 causes any non-zero exit status of the command line to be ignored.
325 .Sh VARIABLE ASSIGNMENTS
328 are much like variables in the shell, and, by tradition,
329 consist of all upper-case letters.
330 The five operators that can be used to assign values to variables are as
334 Assign the value to the variable.
335 Any previous value is overridden.
337 Append the value to the current value of the variable.
339 Assign the value to the variable if it is not already defined.
341 Assign with expansion, i.e. expand the value before assigning it
343 Normally, expansion is not done until the variable is referenced.
345 Expand the value and pass it to the shell for execution and assign
346 the result to the variable.
347 Any newlines in the result are replaced with spaces.
350 Any whitespace before the assigned
352 is removed; if the value is being appended, a single space is inserted
353 between the previous contents of the variable and the appended value.
355 Variables are expanded by surrounding the variable name with either
360 and preceding it with
363 If the variable name contains only a single letter, the surrounding
364 braces or parentheses are not required.
365 This shorter form is not recommended.
367 Variable substitution occurs at two distinct times, depending on where
368 the variable is being used.
369 Variables in dependency lines are expanded as the line is read.
370 Variables in shell commands are expanded when the shell command is
373 The four different classes of variables (in order of increasing precedence)
376 .It Environment variables
377 Variables defined as part of
381 Variables defined in the makefile or in included makefiles.
382 .It Command line variables
383 Variables defined as part of the command line.
385 Variables that are defined specific to a certain target.
386 The seven local variables are as follows:
387 .Bl -tag -width ".ARCHIVE"
389 The list of all sources for this target; also known as
392 The name of the archive file; also known as
395 The name/path of the source from which the target is to be transformed
398 source); also known as
401 The name of the archive member; also known as
404 The list of sources for this target that were deemed out-of-date; also
408 The file prefix of the file, containing only the file portion, no suffix
409 or preceding directory components; also known as
412 The name of the target; also known as
425 are permitted for backward
426 compatibility and are not recommended.
436 permitted for compatibility with
438 makefiles and are not recommended.
440 Four of the local variables may be used in sources on dependency lines
441 because they expand to the proper value for each target on the line.
452 sets or knows about the following internal variables or environment
454 .Bl -tag -width MAKEFLAGS
460 expands to a single dollar
466 .Pq Va argv Ns Op 0 .
468 A path to the directory where
475 to the canonical path given by
478 A path to the directory where the targets are built.
481 searches for an alternate directory to place target files.
482 It will attempt to change into this special directory
483 and will search this directory for makefiles
484 not found in the current directory.
485 The following directories are tried in order:
489 ${MAKEOBJDIRPREFIX}/`pwd`
500 The first directory that
502 successfully changes into is used.
507 is set in the environment but
509 is unable to change into the corresponding directory,
510 then the current directory is used
511 without checking the remainder of the list.
512 If they are undefined and
514 is unable to change into any of the remaining three directories,
515 then the current directory is used.
521 to the canonical path given by
524 The environment variable
526 may contain anything that
530 Its contents are stored in
534 Anything specified on
536 command line is appended to the
538 variable which is then
539 entered into the environment as
541 for all programs which
547 provided for backward compatibility.
551 is currently building.
561 Name of the machine architecture
563 is running on, obtained from the
565 environment variable, or through
569 Name of the machine architecture
571 was compiled for, defined at compilation time.
573 Makefiles may assign a colon-delimited list of directories to
575 These directories will be searched for source files by
577 after it has finished parsing all input makefiles.
580 Variable expansion may be modified to select or modify each word of the
583 is whitespace-delimited sequence of characters).
584 The general format of a variable expansion is as follows:
586 .Dl {variable[:modifier[:...]]}
588 Each modifier begins with a colon and one of the following
590 The colon may be escaped with a backslash
594 .It Cm C No \&/ Ar pattern Xo
595 .No \&/ Ar replacement
601 modifier is just like the
603 modifier except that the old and new strings, instead of being
604 simple strings, are a regular expression (see
609 Normally, the first occurrence of the pattern in
610 each word of the value is changed.
613 modifier causes the substitution to apply to at most one word; the
615 modifier causes the substitution to apply to as many instances of the
616 search pattern as occur in the word or words it is found in.
621 are orthogonal; the former specifies whether multiple words are
622 potentially affected, the latter whether multiple substitutions can
623 potentially occur within each affected word.
625 Replaces each word in the variable with its suffix.
627 Replaces each word in the variable with everything but the last component.
629 Converts variable to lower-case letters.
630 .It Cm M Ns Ar pattern
631 Select only those words that match the rest of the modifier.
632 The standard shell wildcard characters
639 The wildcard characters may be escaped with a backslash
641 .It Cm N Ns Ar pattern
644 but selects all words which do not match
645 the rest of the modifier.
647 Quotes every shell meta-character in the variable, so that it can be passed
648 safely through recursive invocations of
651 Replaces each word in the variable with everything but its suffix.
653 .It Cm S No \&/ Ar old_string Xo
654 .No \&/ Ar new_string
658 Modify the first occurrence of
660 in each word of the variable's value, replacing it with
664 is appended to the last slash of the pattern, all occurrences
665 in each word are replaced.
671 is anchored at the beginning of each word.
674 ends with a dollar sign
676 it is anchored at the end of each word.
683 Any character may be used as a delimiter for the parts of the modifier
685 The anchoring, ampersand, and delimiter characters may be escaped with a
689 Variable expansion occurs in the normal fashion inside both
693 with the single exception that a backslash is used to prevent the expansion
696 not a preceding dollar sign as is usual.
697 .It Ar old_string=new_string
700 style variable substitution.
701 It must be the last modifier specified.
706 do not contain the pattern matching character
708 then it is assumed that they are
709 anchored at the end of each word, so only suffixes or entire
710 words may be replaced.
718 Replaces each word in the variable with its last component.
720 Converts variable to upper-case letters.
722 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
723 Directives, conditionals, and for loops reminiscent
724 of the C programming language are provided in
726 All such structures are identified by a line beginning with a single
730 The following directives are supported:
732 .It Ic \&.include Ar <file>
733 .It Ic \&.include Ar \*qfile\*q
734 Include the specified makefile.
735 Variables between the angle brackets
736 or double quotes are expanded to form the file name.
738 are used, the included makefile is expected to be in the system
740 If double quotes are used, the including
741 makefile's directory and any directories specified using the
743 option are searched before the system
745 .It Ic \&.undef Ar variable
746 Un-define the specified global variable.
747 Only global variables may be un-defined.
748 .It Ic \&.error Ar message
749 Terminate processing of the makefile immediately.
751 makefile, the line on which the error was encountered and the specified
752 message are printed to standard output and
754 terminates with exit code 1.
755 Variables in the message are expanded.
758 Conditionals are used to determine which parts of the Makefile
760 They are used similarly to the conditionals supported
761 by the C pre-processor.
762 The following conditionals are supported:
766 .Oo \&! Oc Ns Ar expression
767 .Op Ar operator expression ...
769 Test the value of an expression.
772 .Oo \&! Oc Ns Ar variable
773 .Op Ar operator variable ...
775 Test the value of a variable.
778 .Oo \&! Oc Ns Ar variable
779 .Op Ar operator variable ...
781 Test the value of a variable.
784 .Oo \&! Oc Ns Ar target
785 .Op Ar operator target ...
787 Test the target being built.
790 .Oo \&! Oc Ns Ar target
791 .Op Ar operator target ...
793 Test the target being built.
795 Reverse the sense of the last conditional.
798 .Oo \&! Oc Ns Ar expression
799 .Op Ar operator expression ...
807 .Oo \&! Oc Ns Ar variable
808 .Op Ar operator variable ...
816 .Oo \&! Oc Ns Ar variable
817 .Op Ar operator variable ...
825 .Oo \&! Oc Ns Ar target
826 .Op Ar operator target ...
834 .Oo \&! Oc Ns Ar target
835 .Op Ar operator target ...
842 End the body of the conditional.
847 may be any one of the following:
848 .Bl -tag -width "Cm XX"
855 of higher precedence than
861 will only evaluate a conditional as far as is necessary to determine
863 Parentheses may be used to change the order of evaluation.
866 may be used to logically negate an entire
868 It is of higher precedence than
873 may be any of the following:
876 Takes a variable name as an argument and evaluates to true if the variable
879 Takes a target name as an argument and evaluates to true if the target
880 was specified as part of
882 command line or was declared the default target (either implicitly or
885 before the line containing the conditional.
887 Takes a variable, with possible modifiers, and evaluates to true if
888 the expansion of the variable would result in an empty string.
890 Takes a file name as an argument and evaluates to true if the file exists.
891 The file is searched for on the system search path (see
894 Takes a target name as an argument and evaluates to true if the target
900 may also be an arithmetic or string comparison.
901 Variable expansion is
902 performed on both sides of the comparison, after which the integral
904 A value is interpreted as hexadecimal if it is
905 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
906 The standard C relational operators are all supported.
908 variable expansion, either the left or right hand side of a
912 operator is not an integral value, then
913 string comparison is performed between the expanded
915 If no relational operator is given, it is assumed that the expanded
916 variable is being compared against 0.
920 is evaluating one of these conditional expressions, and it encounters
921 a word it doesn't recognize, either the
925 expression is applied to it, depending on the form of the conditional.
932 expression is applied.
933 Similarly, if the form is
939 expression is applied.
941 If the conditional evaluates to true the parsing of the makefile continues
943 If it evaluates to false, the following lines are skipped.
944 In both cases this continues until a
950 For loops are typically used to apply a set of rules to a list of files.
951 The syntax of a for loop is:
953 .Bl -tag -width indent -compact
954 .It Ic .for Ar variable Ic in Ar expression
961 is evaluated, it is split into words.
965 is successively set to each word, and substituted in the
967 inside the body of the for loop.
969 Comments begin with a hash
971 character, anywhere but in a shell
972 command line, and continue to the end of the line.
976 Ignore any errors from the commands associated with this target, exactly
977 as if they all were preceded by a dash
980 Execute the commands associated with this target even if the
984 options were specified.
985 Normally used to mark recursive
990 selects the first target it encounters as the default target to be built
991 if no target was specified.
992 This source prevents this target from being selected.
994 If a target is marked with this attribute and
996 can't figure out how to create it, it will ignore this fact and assume
997 the file isn't needed or already exists.
1001 is interrupted, it removes any partially made targets.
1002 This source prevents the target from being removed.
1004 Do not echo any of the commands associated with this target, exactly
1005 as if they all were preceded by an at sign
1008 Turn the target into
1011 When the target is used as a source for another target, the other target
1012 acquires the commands, sources, and attributes (except for
1016 If the target already has commands, the
1018 target's commands are appended
1023 source is appears in a dependency line, the sources that precede it are
1024 made before the sources that succeed it in the line.
1026 detected and targets that form loops will be silently ignored.
1028 .Sh "SPECIAL TARGETS"
1029 Special targets may not be included with other targets, i.e. they must be
1030 the only target specified.
1033 Any command lines attached to this target are executed before anything
1038 rule for any target (that was used only as a
1041 can't figure out any other way to create.
1042 Only the shell script is used.
1045 variable of a target that inherits
1048 to the target's own name.
1050 Any command lines attached to this target are executed after everything
1053 Mark each of the sources with the
1056 If no sources are specified, this is the equivalent of specifying the
1060 A list of suffixes that indicate files that can be included in a source
1062 The suffix must have already been declared with
1064 any suffix so declared will have the directories on its search path (see
1068 special variable, each preceded by a
1074 is interrupted, the commands for this target will be executed.
1076 This does for libraries what
1078 does for include files, except that the flag used is
1081 If no target is specified when
1083 is invoked, this target will be built.
1084 This is always set, either
1085 explicitly, or implicitly when
1087 selects the default target, to give the user a way to refer to the default
1088 target on the command line.
1090 This target provides a way to specify flags for
1092 when the makefile is used.
1093 The flags are as if typed to the shell, though the
1097 .\" XXX: NOT YET!!!!
1098 .\" .It Ic .NOTPARALLEL
1099 .\" The named targets are executed in non parallel mode. If no targets are
1100 .\" specified, then all targets are executed in non parallel mode.
1102 Disable parallel mode.
1104 Same as above, for compatibility with other
1108 The named targets are made in sequence.
1109 .\" XXX: NOT YET!!!!
1110 .\" .It Ic .PARALLEL
1111 .\" The named targets are executed in parallel mode. If no targets are
1112 .\" specified, then all targets are executed in parallel mode.
1114 The sources are directories which are to be searched for files not
1115 found in the current directory.
1116 If no sources are specified, any previously specified directories are
1118 Where possible, use of
1120 is preferred over use of the
1123 .It Ic .PATH\fIsuffix\fR
1124 The sources are directories which are to be searched for suffixed files
1125 not found in the current directory.
1129 first searches the suffixed search path, before reverting to the default
1130 path if the file is not found there.
1131 This form is required for
1139 attribute to any specified sources.
1140 Targets with this attribute are always
1141 considered to be out of date.
1145 attribute to any specified sources.
1146 If no sources are specified, the
1148 attribute is applied to every
1153 attribute to any specified sources.
1154 If no sources are specified, the
1156 attribute is applied to every
1157 command in the file.
1159 Each source specifies a suffix to
1161 If no sources are specified, any previous specified suffices are deleted.
1170 This was removed for POSIX compatibility.
1171 The internal variable
1173 is set to the same value as
1175 support for this may be removed in the future.
1177 Most of the more esoteric features of
1179 should probably be avoided for greater compatibility.
1183 utility uses the following environment variables, if they exist:
1189 .Ev MAKEOBJDIRPREFIX .
1191 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1193 list of dependencies
1195 list of dependencies
1197 list of dependencies
1201 system makefile (processed before any other file, including
1205 .It Pa /usr/share/mk
1206 system makefile directory
1207 .It /usr/share/doc/psd/12.make
1211 .Ev MAKEOBJDIRPREFIX
1215 The determination of
1217 is contorted to the point of absurdity.
1219 In the presence of several
1223 silently ignores all but the first.
1226 is not set to the default target when
1228 is invoked without a target name and no
1230 special target exists.
1234 in a test is very simple-minded.
1235 Currently, the only form that works is
1236 .Ql .if ${VAR} op something
1237 For instance, you should write tests as
1238 .Ql .if ${VAR} = "string"
1239 not the other way around, which doesn't work.
1241 For loops are expanded before tests, so a fragment such as:
1243 \&.for TMACHINE in ${SHARED_ARCHS}
1244 \&.if ${TMACHINE} = ${MACHINE}
1249 won't work, and should be rewritten the other way around.
1254 .%T "PMake - A Tutorial"
1257 .Pa /usr/share/doc/psd/12.make