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 .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
40 .Nd maintain program dependencies
54 .Op Ar variable Ns No = Ns Ar value
58 is a program designed to simplify the maintenance of other programs.
59 Its input is a list of specifications
60 describing dependency relationships between the generation of
66 that can be found in either the current directory or a special object directory
69 will be read for this list of specifications.
72 can be found, it is also read (see
75 This manual page is intended as a reference document only.
76 For a more thorough introduction to
78 and makefiles, please refer to
79 .%T "Make \- A Tutorial" .
81 The options are as follows:
84 Try to be backwards compatible by executing a single shell per command and
85 by executing the commands to make the sources of a dependency line in sequence.
86 This is turned on by default unless
92 to be 1, in the global context.
94 Turn on debugging, and specify which portions of
96 are to print debugging information.
99 is one or more of the following:
102 Print all possible debugging information;
103 equivalent to specifying all of the debugging flags.
105 Print debugging information about archive searching and caching.
107 Print debugging information about conditional evaluation.
109 Print debugging information about directory searching and caching.
111 Print debugging information about the execution of for loops. Currently a
114 Print the input graph before making anything.
116 Print the input graph after making everything, or before exiting
119 Print debugging information about running multiple shells.
121 Print debugging information about making targets, including modification
124 Print debugging information about suffix-transformation rules.
126 Print debugging information about target list maintenance.
128 Print debugging information about variable assignment.
131 Specify a variable whose environment value (if any) will override
132 macro assignments within makefiles.
134 Specify that environment values override macro assignments within
135 makefiles for all variables.
137 Specify a makefile to read instead of the default
145 standard input is read.
146 Multiple makefiles may be specified, and are read in the order specified.
147 .It Fl I Ar directory
148 Specify a directory in which to search for makefiles and included makefiles.
149 The system makefile directory (or directories, see the
151 option) is automatically included as part of this list.
153 Ignore non-zero exit of shell commands in the makefile.
154 Equivalent to specifying
156 before each command line in the makefile.
158 Specify the maximum number of jobs that
160 may have running at any one time. Turns compatibility mode off, unless the
162 flag is also specified.
164 Continue processing after errors are encountered, but only on those targets
165 that do not depend on the target whose creation caused the error.
166 .It Fl m Ar directory
167 Specify a directory in which to search for sys.mk and makefiles included
168 via the <...> style. Multiple directories can be added to form a search path.
169 This path will override the default system include path:
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 Collate the output of a given job and display it only when the job finishes,
180 instead of mixing the output of parallel jobs together.
181 This option has no effect unless
185 Do not execute any commands, but exit 0 if the specified targets are
186 up-to-date and 1, otherwise.
188 Do not use the built-in rules specified in the system makefile.
190 Stop processing when an error is encountered.
191 Default behaviour. This is needed to negate the
193 option during recursive builds.
195 Do not echo any commands as they are executed.
196 Equivalent to specifying
198 before each command line in the makefile.
200 Rather than re-building a target as specified in the makefile, create it
201 or update its modification time to make it appear up-to-date.
207 in the global context.
208 Do not build any targets.
209 Multiple instances of this option may be specified;
210 the variables will be printed one per line,
211 with a blank line for each null or undefined variable.
214 For multi-job makes, this will cause file banners to be generated.
215 .It Ar variable Ns No = Ns Ar value
216 Set the value of the variable
222 There are seven different types of lines in a makefile: file dependency
223 specifications, shell commands, variable assignments, include statements,
224 conditional directives, for loops, and comments.
226 In general, lines may be continued from one line to the next by ending
227 them with a backslash
229 The trailing newline character and initial whitespace on the following
230 line are compressed into a single space.
231 .Sh FILE DEPENDENCY SPECIFICATIONS
232 Dependency lines consist of one or more targets, an operator, and zero
234 This creates a relationship where the targets
237 and are usually created from them.
238 The exact relationship between the target and the source is determined
239 by the operator that separates them.
240 The three operators are as follows:
243 A target is considered out-of-date if its modification time is less than
244 those of any of its sources.
245 Sources for a target accumulate over dependency lines when this operator
247 The target is removed if
251 Targets are always re-created, but not until all sources have been
252 examined and re-created as necessary.
253 Sources for a target accumulate over dependency lines when this operator
255 The target is removed if
259 If no sources are specified, the target is always re-created.
260 Otherwise, a target is considered out-of-date if any of its sources has
261 been modified more recently than the target.
262 Sources for a target do not accumulate over dependency lines when this
264 The target will not be removed if
269 Targets and sources may contain the shell wildcard expressions
280 may only be used as part of the final
281 component of the target or source, and must be used to describe existing
285 need not necessarily be used to describe existing files.
286 Expansion is in directory order, not alphabetically as done in the shell.
288 Each target may have associated with it a series of shell commands, normally
289 used to create the target.
290 Each of the commands in this script
292 be preceded by a tab.
293 While any target may appear on a dependency line, only one of these
294 dependencies may be followed by a creation script, unless the
298 If the first or first two characters of the command line are
302 the command is treated specially.
305 causes the command not to be echoed before it is executed.
308 causes any non-zero exit status of the command line to be ignored.
309 .Sh VARIABLE ASSIGNMENTS
312 are much like variables in the shell, and, by tradition,
313 consist of all upper-case letters.
314 The five operators that can be used to assign values to variables are as
318 Assign the value to the variable.
319 Any previous value is overridden.
321 Append the value to the current value of the variable.
323 Assign the value to the variable if it is not already defined.
325 Assign with expansion, i.e. expand the value before assigning it
327 Normally, expansion is not done until the variable is referenced.
329 Expand the value and pass it to the shell for execution and assign
330 the result to the variable.
331 Any newlines in the result are replaced with spaces.
334 Any whitespace before the assigned
336 is removed; if the value is being appended, a single space is inserted
337 between the previous contents of the variable and the appended value.
339 Variables are expanded by surrounding the variable name with either
344 and preceding it with
347 If the variable name contains only a single letter, the surrounding
348 braces or parentheses are not required.
349 This shorter form is not recommended.
351 Variable substitution occurs at two distinct times, depending on where
352 the variable is being used.
353 Variables in dependency lines are expanded as the line is read.
354 Variables in shell commands are expanded when the shell command is
357 The four different classes of variables (in order of increasing precedence)
360 .It Environment variables
361 Variables defined as part of
365 Variables defined in the makefile or in included makefiles.
366 .It Command line variables
367 Variables defined as part of the command line.
369 Variables that are defined specific to a certain target.
370 The seven local variables are as follows:
371 .Bl -tag -width ".ARCHIVE"
373 The list of all sources for this target; also known as
376 The name of the archive file; also known as
379 The name/path of the source from which the target is to be transformed
382 source); also known as
385 The name of the archive member; also known as
388 The list of sources for this target that were deemed out-of-date; also
392 The file prefix of the file, containing only the file portion, no suffix
393 or preceding directory components; also known as
396 The name of the target; also known as
409 are permitted for backward
410 compatibility and are not recommended.
420 permitted for compatibility with
422 makefiles and are not recommended.
424 Four of the local variables may be used in sources on dependency lines
425 because they expand to the proper value for each target on the line.
436 sets or knows about the following internal variables or environment
438 .Bl -tag -width MAKEFLAGS
444 expands to a single dollar
450 .Pq Va argv Ns Op 0 .
452 A path to the directory where
456 A path to the directory where the targets are built.
459 searches for an alternate directory to place target files.
460 It will attempt to change into this special directory
461 and will search this directory for makefiles
462 not found in the current directory.
463 The following directories are tried in order:
467 ${MAKEOBJDIRPREFIX}/`cwd`
478 The first directory that
480 successfully changes into is used.
487 is unable to change into the corresponding directory,
488 then the current directory is used
489 without checking the remainder of the list.
490 If they are undefined and
492 is unable to change into any of the remaining three directories,
493 then the current directory is used.
495 The environment variable
497 may contain anything that
500 command line. Its contents are stored in
504 Anything specified on
506 command line is appended to the
508 variable which is then
509 entered into the environment as
511 for all programs which
517 provided for backward compatibility.
519 Alternate path to the current directory.
520 Supported if built with WANT_ENV_PWD defined.
524 to the canonical path given by
526 However, if the environment variable
528 is set and gives a path to the current directory, then
536 is always set to the value of
538 for all programs which
544 is currently building.
554 Name of the machine architecture
556 is running on, obtained from the
558 environment variable, or through
562 Name of the machine architecture
564 was compiled for, defined at compilation time.
566 Makefiles may assign a colon-delimited list of directories to
568 These directories will be searched for source files by
572 has finished parsing all input makefiles.
575 Variable expansion may be modified to select or modify each word of the
578 is whitespace-delimited sequence of characters).
579 The general format of a variable expansion is as follows:
581 .Dl {variable[:modifier[:...]]}
583 Each modifier begins with a colon and one of the following
585 The colon may be escaped with a backslash
587 .Bl -tag -width Cm E\&
589 Replaces each word in the variable with its suffix.
591 Replaces each word in the variable with everything but the last component.
592 .It Cm M Ns Ar pattern
593 Select only those words that match the rest of the modifier.
594 The standard shell wildcard characters
601 The wildcard characters may be escaped with a backslash
603 .It Cm N Ns Ar pattern
606 but selects all words which do not match
607 the rest of the modifier.
609 Quotes every shell meta-character in the variable, so that it can be passed
610 safely through recursive invocations of
613 Replaces each word in the variable with everything but its suffix.
615 .It Cm S No \&/ Ar old_string Xo
616 .No \&/ Ar new_string
620 Modify the first occurrence of
622 in each word of the variable's value, replacing it with
626 is appended to the last slash of the pattern, all occurrences
627 in each word are replaced.
633 is anchored at the beginning of each word.
636 ends with a dollar sign
638 it is anchored at the end of each word.
645 Any character may be used as a delimiter for the parts of the modifier
647 The anchoring, ampersand, and delimiter characters may be escaped with a
651 Variable expansion occurs in the normal fashion inside both
655 with the single exception that a backslash is used to prevent the expansion
658 not a preceding dollar sign as is usual.
660 Replaces each word in the variable with its last component.
661 .It Ar old_string=new_string
664 style variable substitution.
665 It must be the last modifier specified.
670 do not contain the pattern matching character
672 then it is assumed that they are
673 anchored at the end of each word, so only suffixes or entire
674 words may be replaced. Otherwise
681 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
682 Directives, conditionals, and for loops reminiscent
683 of the C programming language are provided in
685 All such structures are identified by a line beginning with a single
688 character. The following directives are supported:
690 .It Ic \&.include Ar <file>
691 .It Ic \&.include Ar \*qfile\*q
692 Include the specified makefile. Variables between the angle brackets
693 or double quotes are expanded to form the file name. If angle brackets
694 are used, the included makefile is expected to be in the system
695 makefile directory. If double quotes are used, the including
696 makefile's directory and any directories specified using the
698 option are searched before the system
700 .It Ic \&.undef Ar variable
701 Un-define the specified global variable.
702 Only global variables may be un-defined.
703 .It Ic \&.error Ar message
704 Terminate processing of the makefile immediately. The filename of the
705 makefile, the line on which the error was encountered and the specified
706 message are printed to standard output and
708 terminates with exit code 1. Variables in the message are expanded.
711 Conditionals are used to determine which parts of the Makefile
712 to process. They are used similarly to the conditionals supported
713 by the C pre-processor. The following conditionals are supported:
717 .Oo \&! Oc Ns Ar expression
718 .Op Ar operator expression ...
720 Test the value of an expression.
723 .Oo \&! Oc Ns Ar variable
724 .Op Ar operator variable ...
726 Test the value of a variable.
729 .Oo \&! Oc Ns Ar variable
730 .Op Ar operator variable ...
732 Test the value of a variable.
735 .Oo \&! Oc Ns Ar target
736 .Op Ar operator target ...
738 Test the target being built.
742 .Op Ar operator target ...
744 Test the target being built.
746 Reverse the sense of the last conditional.
749 .Oo \&! Oc Ar expression
750 .Op Ar operator expression ...
758 .Oo \&! Oc Ns Ar variable
759 .Op Ar operator variable ...
767 .Oo \&! Oc Ns Ar variable
768 .Op Ar operator variable ...
776 .Oo \&! Oc Ns Ar target
777 .Op Ar operator target ...
785 .Oo \&! Oc Ns Ar target
786 .Op Ar operator target ...
793 End the body of the conditional.
798 may be any one of the following:
799 .Bl -tag -width "Cm XX"
805 of higher precedence than
811 will only evaluate a conditional as far as is necessary to determine
813 Parentheses may be used to change the order of evaluation.
816 may be used to logically negate an entire
818 It is of higher precedence than
823 may be any of the following:
824 .Bl -tag -width Ic defined
826 Takes a variable name as an argument and evaluates to true if the variable
829 Takes a target name as an argument and evaluates to true if the target
830 was specified as part of
832 command line or was declared the default target (either implicitly or
835 before the line containing the conditional.
837 Takes a variable, with possible modifiers, and evaluates to true if
838 the expansion of the variable would result in an empty string.
840 Takes a file name as an argument and evaluates to true if the file exists.
841 The file is searched for on the system search path (see
844 Takes a target name as an argument and evaluates to true if the target
850 may also be an arithmetic or string comparison. Variable expansion is
851 performed on both sides of the comparison, after which the integral
852 values are compared. A value is interpreted as hexadecimal if it is
853 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
854 The standard C relational operators are all supported. If after
855 variable expansion, either the left or right hand side of a
859 operator is not an integral value, then
860 string comparison is performed between the expanded
862 If no relational operator is given, it is assumed that the expanded
863 variable is being compared against 0.
867 is evaluating one of these conditional expressions, and it encounters
868 a word it doesn't recognize, either the
872 expression is applied to it, depending on the form of the conditional.
879 expression is applied.
880 Similarly, if the form is
886 expression is applied.
888 If the conditional evaluates to true the parsing of the makefile continues
890 If it evaluates to false, the following lines are skipped.
891 In both cases this continues until a
897 For loops are typically used to apply a set of rules to a list of files.
898 The syntax of a for loop is:
915 is evaluated, it is split into words. The
918 is successively set to each word, and substituted in the
920 inside the body of the for loop.
922 Comments begin with a hash
924 character, anywhere but in a shell
925 command line, and continue to the end of the line.
927 .Bl -tag -width Ic .IGNORE
929 Ignore any errors from the commands associated with this target, exactly
930 as if they all were preceded by a dash
933 Execute the commands associated with this target even if the
937 options were specified.
938 Normally used to mark recursive
943 selects the first target it encounters as the default target to be built
944 if no target was specified.
945 This source prevents this target from being selected.
947 If a target is marked with this attribute and
949 can't figure out how to create it, it will ignore this fact and assume
950 the file isn't needed or already exists.
954 is interrupted, it removes any partially made targets.
955 This source prevents the target from being removed.
957 Do not echo any of the commands associated with this target, exactly
958 as if they all were preceded by an at sign
964 When the target is used as a source for another target, the other target
965 acquires the commands, sources, and attributes (except for
969 If the target already has commands, the
971 target's commands are appended
976 source is appears in a dependency line, the sources that precede it are
977 made before the sources that succeed it in the line. Loops are not being
978 detected and targets that form loops will be silently ignored.
980 .Sh "SPECIAL TARGETS"
981 Special targets may not be included with other targets, i.e. they must be
982 the only target specified.
983 .Bl -tag -width Ic .BEGIN
985 Any command lines attached to this target are executed before anything
990 rule for any target (that was used only as a
993 can't figure out any other way to create.
994 Only the shell script is used.
997 variable of a target that inherits
1000 to the target's own name.
1002 Any command lines attached to this target are executed after everything
1005 Mark each of the sources with the
1008 If no sources are specified, this is the equivalent of specifying the
1012 A list of suffixes that indicate files that can be included in a source
1013 file. The suffix must have already been declared with
1015 any suffix so declared will have the directories on its search path (see
1019 special variable, each preceeded by a
1025 is interrupted, the commands for this target will be executed.
1027 This does for libraries what
1029 does for include files, except that the flag used is
1032 If no target is specified when
1034 is invoked, this target will be built.
1035 This is always set, either
1036 explicitly, or implicitly when
1038 selects the default target, to give the user a way to refer to the default
1039 target on the command line.
1041 This target provides a way to specify flags for
1043 when the makefile is used.
1044 The flags are as if typed to the shell, though the
1048 .\" XXX: NOT YET!!!!
1049 .\" .It Ic .NOTPARALLEL
1050 .\" The named targets are executed in non parallel mode. If no targets are
1051 .\" specified, then all targets are executed in non parallel mode.
1053 Disable parallel mode.
1055 Same as above, for compatibility with other pmake variants.
1057 The named targets are made in sequence.
1058 .\" XXX: NOT YET!!!!
1059 .\" .It Ic .PARALLEL
1060 .\" The named targets are executed in parallel mode. If no targets are
1061 .\" specified, then all targets are executed in parallel mode.
1063 The sources are directories which are to be searched for files not
1064 found in the current directory.
1065 If no sources are specified, any previously specified directories are
1067 Where possible, use of
1069 is preferred over use of the
1072 .It Ic .PATH\fIsuffix\fR
1073 The sources are directories which are to be searched for suffixed files
1074 not found in the current directory.
1076 first searches the suffixed search path, before reverting to the default
1077 path if the file is not found there.
1078 This form is required for
1086 attribute to any specified sources. Targets with this attribute are always
1087 considered to be out of date.
1091 attribute to any specified sources.
1092 If no sources are specified, the
1094 attribute is applied to every
1099 attribute to any specified sources.
1100 If no sources are specified, the
1102 attribute is applied to every
1103 command in the file.
1105 Each source specifies a suffix to
1107 If no sources are specified, any previous specified suffices are deleted.
1115 This was removed for POSIX compatibility.
1116 The internal variable
1118 is set to the same value as
1120 support for this may be removed in the future.
1122 Most of the more esoteric features of
1124 should probably be avoided for greater compatibility.
1127 uses the following environment variables, if they exist:
1132 .Ev MAKEOBJDIRPREFIX ,
1136 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1138 list of dependencies
1140 list of dependencies
1142 list of dependencies
1147 .It Pa /usr/share/mk
1148 system makefile directory
1149 .It /usr/share/doc/psd/12.make
1153 .Ev MAKEOBJDIRPREFIX
1157 The determination of
1159 is contorted to the point of absurdity.
1161 In the presence of several
1165 silently ignores all but the first.
1168 is not set to the default target when
1170 is invoked without a target name and no
1172 special target exists.
1176 in a test is very simple-minded. Currently, the only form that works is
1177 .Ql .if ${VAR} op something
1178 For instance, you should write tests as
1179 .Ql .if ${VAR} = "string"
1180 not the other way around, which doesn't work.
1182 For loops are expanded before tests, so a fragment such as:
1184 \&.for TMACHINE in ${SHARED_ARCHS}
1185 \&.if ${TMACHINE} = ${MACHINE}
1190 won't work, and should be rewritten the other way around.
1194 .%T "PMake - A Tutorial"