xref: /original-bsd/usr.bin/make/make.1 (revision 237fdba6)
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.man%
5.\"
6.\"     @(#)make.1	5.2 (Berkeley) 06/11/90
7.\"
8.Dd
9.Dt MAKE 1
10.Os BSD 4.4
11.Sh NAME
12.Nm make
13.Nd maintain program dependencies
14.Sh SYNOPSIS
15.Nm make
16.Op Fl eiknqrstv
17.Op Fl D Ar variable
18.Op Fl d Ar flags
19.Op Fl f Ar makefile
20.Op Fl I Ar directory
21.Op Fl j Ar max_jobs
22.Op Ar variable=value
23.Op Ar target ...
24.Sh DESCRIPTION
25.Nm Make
26is a program designed to simplify the maintenance of other programs.
27Its input is a ``makefile'' which specifies files that programs and
28other files are dependent upon.
29.Pp
30This manual page is intended as a reference document only.
31For a more thorough description of
32.Nm make
33and makefiles, please refer to
34.Em Make \-\- A Tutorial .
35.Pp
36The options are as follows:
37.Tw Ds
38.Tp Cx Fl
39.Ar variable
40.Cx
41Define
42.Ar variable
43to be 1, in the global context.
44.Tp Cx Fl d
45.Ar flags
46.Cx
47Turn on debugging, and specify which portions of
48.Nm make
49are to print debugging information.
50.Ar Flags
51is one or more of the following:
52.Tw Ds
53.Tp Ic A
54Print all possible debugging information; equivalent to specifying
55all of the debugging flags.
56.Tp Ic a
57Print debugging information about archive searching and caching.
58.Tp Ic c
59Print debugging information about conditional evaluation.
60.Tp Ic d
61Print debugging information about directory searching and caching.
62.Tp Ic g1
63Print the input graph before making anything.
64.Tp Ic g2
65Print the input graph after making everything, or before exiting
66on error.
67.Tp Ic j
68Print debugging information about running multiple shells.
69.Tp Ic m
70Print debugging information about making targets, including modification
71dates.
72.Tp Ic s
73Print debugging information about suffix-transformation rules.
74.Tp Ic t
75Print debugging information about target list maintenance.
76.Tp Ic v
77Print debugging information about variable assignment.
78.Tp
79.Tp Cx Fl f
80.Ar makefile
81.Cx
82Specify a makefile to read.
83If no makefile is specified, the files ``makefile'' and ``Makefile''
84are searched for, in that order.
85If
86.Ar makefile
87is ``\-'', standard input is read.
88Multiple makefile's may be specified, and are read in the order specified.
89.Tp Cx Fl I
90.Ar directory
91.Cx
92Specify a directory in which to search for makefiles and included makefiles.
93The system makefile directory is automatically included as part of this
94list.
95.Tp Fl i
96Ignore non-zero exit of shell commands in the makefile.
97Equivalent to specifying ``\-'' before each command line in the makefile.
98.Tp Cx Fl j
99.Ar max_jobs
100.Cx
101Specify the maximum number of jobs that
102.Nm make
103may have running at any one time.
104.Tp Fl k
105Continue processing after errors are encountered, but only on those targets
106that do not depend on the target whose creation caused the error.
107.Tp Fl n
108Display the commands that would have been executed, but do not actually
109execute them.
110.Tp Fl q
111Do not execute any commands, but exit 0 if the specified targets are
112up-to-date and 1, otherwise.
113.Tp Fl r
114Do not use the built-in rules specified in the system makefile.
115.Tp Fl s
116Do not echo any commands as they are executed.
117Equivalent to specifying ``@'' before each command line in the makefile.
118.Tp Fl t
119Rather than re-building a target as specified in the makefile, create it
120or update its modification time to make it appear up-to-date.
121.Tp Ar variable=value
122Set the value of the variable
123.Ar variable
124to
125.Ar value  .
126.Tp
127.Pp
128There are six different types of lines in a makefile: file dependency
129specifications, shell commands, variable assignments, include statements,
130conditional directives, and comments.
131.Pp
132In general, lines may be continued from one line to the next by ending
133them with a backslash (``\e'').
134The trailing newline character and initial whitespace on the following
135line are compressed into a single space.
136.Sh FILE DEPENDENCY SPECIFICATIONS
137Dependency lines consist of one or more targets, an operator, and zero
138or more sources.
139This creates a relationship where the targets ``depend'' on the sources
140and are usually created from them.
141The exact relationship between the target and the source is determined
142by the operator that separates them.
143The three operators are as follows:
144.Tp Ic \&:
145A target is considered out-of-date if its modification time is less than
146those of any of its sources.
147Sources for a target accumulate over dependency lines when this operator
148is used.
149The target is removed if
150.Nm make
151is interrupted.
152.Tp Ic \&!
153Targets are always re-created, but not until all sources have been
154examined and re-created as necessary.
155Sources for a target accumulate over dependency lines when this operator
156is used.
157The target is removed if
158.Nm make
159is interrupted.
160.Tp Ic \&::
161If no sources are specified, the target is always re-created.
162Otherwise, a target is considered out-of-date if any of its sources has
163been modified more recently than the target.
164Sources for a target do not accumulate over dependency lines when this
165operator is used.
166The target will not be removed if
167.Nm make
168is interrupted.
169.Tp
170.Pp
171Targets and sources may contain the shell wildcard values ``?'', ``*'',
172.Dq Op
173and ``{}''.
174The values ``?'', ``*'' and
175.Dq Op
176may only be used as part of the final
177component of the target or source, and must be used to describe existing
178files.
179The value ``{}'' need not necessarily be used to describe existing files.
180Expansion is in directory order, not alphabetically as done in the shell.
181.Sh SHELL COMMANDS
182Each target may have associated with it a series of shell commands, normally
183used to create the target.
184Each of the commands in this script
185.Em must
186be preceded by a tab.
187While any target may appear on a dependency line, only one of these
188dependencies may be followed by a creation script, unless the ``::''
189operator is used.
190.Pp
191If the first or first two characters of the command line are ``@'' and/or
192``\-'', the command is treated specially.
193A ``@'' causes the command not to be echoed before it is executed.
194A ``\-'' causes any non-zero exit status of the command line to be ignored.
195.Sh VARIABLE ASSIGNMENTS
196Variables in make are much like variables in the shell, and, by tradition,
197consist of all upper-case letters.
198The five operators that can be used to assign values to variables are as
199follows:
200.Tp Ic \&=
201Assign the value to the variable.
202Any previous value is overridden.
203.Tp Ic \&+=
204Append the value to the current value of the variable.
205.Tp Ic \&?=
206Assign the value to the variable if it is not already defined.
207.Tp Ic \&:=
208Assign with expansion, i.e. expand the value before assigning it
209to the variable.
210Normally, expansion is not done until the variable is referenced.
211.Tp Ic \&!=
212Expand the value and pass it to the shell for execution and assign
213the result to the variable.
214Any newlines in the result are replaced with spaces.
215.Tp
216.Pp
217Any white-space before the assigned
218.Ar value
219is removed; if the value is being appended, a single space is inserted
220between the previous contents of the variable and the appended value.
221.Pp
222Variables are expanded by surrounding the variable name with either
223curly braces (``{}'') or parenthesis (``()'') and preceding it with
224a dollar sign (``$'').
225If the variable name contains only a single letter, the surrounding
226braces or parenthesis are not required.
227This shorter form is not recommended.
228.Pp
229Variable substitution occurs at two distinct times, depending on where
230the variable is being used.
231Variables in dependency lines are expanded as the line is read.
232Variables in shell commands are expanded when the shell command is
233executed.
234.Pp
235The four different classes of variables (in order of increasing precedence)
236are:
237.Tw Ds
238.Tp environment variables
239Variables defined as part of
240.Cx Nm make
241.Cx \'s
242.Cx
243environment.
244.Tp global variables
245Variables defined in the makefile or in included makefiles.
246.Tp command line variables
247Variables defined as part of the command line.
248.Tp local variables
249Variables that are defined specific to a certain target.
250The seven local variables are as follows:
251.Tw Ds
252.Tp Va \&.ALLSRC
253The list of all sources for this target; also known as ``>''.
254.Tp Va \&.ARCHIVE
255The name of the archive file.
256.Tp Va \&.IMPSRC
257The name/path of the source from which the target is to be transformed
258(the ``implied'' source); also known as ``<''.
259.Tp Va \&.MEMBER
260The name of the archive member.
261.Tp Va \&.OODATE
262The list of sources for this target that were deemed out-of-date; also
263known as ``?''.
264.Tp Va \&.PREFIX
265The file prefix of the file, containing only the file portion, no suffix
266or preceding directory components; also known as ``*'.
267.Tp Va \&.TARGET
268The name of the target; also known as ``@''.
269.Tp
270.Pp
271The shorter forms ``@'', ``?'', ``>'' and ``*'' are permitted for backward
272compatibility with historical makefiles and are not recommended.
273The six variables ``@F'', ``@D'', ``<F'', ``<D'', ``*F'' and ``*D'' are
274permitted for compatibility with System V makefiles and are not recommended.
275.Pp
276Four of the local variables may be used in sources on dependency lines
277because they expand to the proper value for each target on the line.
278These variables are ``.TARGET'', ``.PREFIX'', ``.ARCHIVE'', and ``.MEMBER''.
279.Pp
280In addition,
281.Nm make
282sets or knows about the following variables:
283.Tw MAKEFLAGS
284.Tp Va \&$
285A single dollar sign (``$''), i.e. ``$$'' expands to a single dollar
286sign.
287.Tp Va \&.MAKE
288The name that
289.Nm make
290was executed with
291.Pq Cx Va argv
292.Op 0
293.Cx
294.Tp Va \&.CURDIR
295A path to the directory where
296.Nm make
297was executed.
298.Tp Va MAKEFLAGS
299The environment variable ``MAKEFLAGS'' may contain anything that
300may be specified on
301.Cx Nm make
302.Cx \'s
303.Cx
304command line.
305Anything specified on
306.Cx Nm make
307.Cx \'s
308.Cx
309command line is appended to the ``MAKEFLAGS'' variable which is then
310entered into the environment for all programs which
311.Nm make
312executes.
313.Tp
314.Pp
315Variable expansion may be modified to select or modify each word of the
316variable (where a ``word'' is white-space delimited sequence of characters).
317The general format of a variable expansion is as follows:
318.Pp
319.Dl {variable[:modifier[:...]]}
320.Pp
321Each modifier begins with a colon and one of the following
322special characters.
323The colon may be escaped with a backslash (``\e'').
324.Tp Cm E\&
325Replaces each word in the variable with its suffix.
326.Tp Cm \&H
327Replaces each word in the variable with everything but the last component.
328.Tp Cx Ic M
329.Ar pattern
330.Cx
331Select only those words that match the rest of the modifier.
332The standard shell wildcard characters (``*'', ``?'', and
333.Dq Op )
334may
335be used.
336The wildcard characters may be escaped with a backslash (``\e'').
337.Tp Cx Ic N
338.Ar pattern
339.Cx
340This is identical to ``M'', but selects all words which do not match
341the rest of the modifier.
342.Tp Cm R
343Replaces each word in the variable with everything but its suffix.
344.Tp Cx Cm S
345.Cx \&/
346.Ar old_pattern
347.Cx \&/
348.Ar new_pattern
349.Cx \&/
350.Op Cm g
351.Cx
352Modify the first occurrence of
353.Ar old _pattern
354in each word to be replaced with
355.Ar new _pattern  .
356If a ``g'' is appended to the last slash of the pattern, all occurrences
357in each word are replaced.
358If
359.Ar old _pattern
360begins with a carat (``^''),
361.Ar old _pattern
362is anchored at the beginning of each word.
363If
364.Ar old _pattern
365ends with a dollar sign (``$''), it is anchored at the end of each word.
366Inside
367.Ar new _string  ,
368an ampersand (``&'') is replaced by
369.Ar old _pattern .
370Any character may be used as a delimiter for the parts of the modifier
371string.
372The anchoring, ampersand and delimiter characters may be escaped with a
373backslash (``\e'').
374.Pp
375Variable expansion occurs in the normal fashion inside both
376.Ar old _string
377and
378.Ar new _string
379with the single exception that a backslash is used to prevent the expansion
380of a dollar sign (``$''), not a preceding dollar sign as is usual.
381.Tp Cm T
382Replaces each word in the variable with its last component.
383.Tp Ar old_string=new_string
384This is the System V style variable substitution.
385It must be the last modifier specified.
386.Ar Old _string
387is anchored at the end of each word, so only suffixes or entire
388words may be replaced.
389.Tp
390.Sh INCLUDE STATEMENTS AND CONDITIONALS
391Makefile inclusion and conditional structures reminiscent of the C
392programming language are provided in
393.Nm make  .
394All such structures are identified by a line beginning with a single
395dot (``.'') character.
396Files are included with either ``.include <file>'' or ``.include "file"''.
397Variables between the angle brackets or double quotes are expanded
398to form the file name.
399If angle brackets are used, the included makefile is expected to be in
400the system makefile directory.
401If double quotes are used, the including makefile's directory and any
402directories specified using the -I option are searched before the system
403makefile directory.
404.Pp
405Conditional expressions are also preceded by a single dot as the first
406chraracter of a line.
407The possible conditionals are as follows:
408.Tw Ds
409.Tp Cx Ic \&.undef
410.Cx \&\ \&
411.Ar variable
412.Cx
413Un-define the specified global variable.
414Only global variables may be un-defined.
415.Tp Cx Ic \&.if
416.Cx \&\ \&
417.Op \&!
418.Cx \&\ \&
419.Ar expression
420.Cx \&\ \&
421.Op Ar operator expression ...
422.Cx
423Test the value of an expression.
424.Tp Cx Ic \&.ifdef
425.Cx \&\ \&
426.Op \&!
427.Ar variable
428.Cx \&\ \&
429.Op Ar  operator variable ...
430.Cx
431Test the value of an variable.
432.Tp Cx Ic \&.ifndef
433.Cx \&\ \&
434.Op \&!
435.Cx \&\ \&
436.Ar variable
437.Cx \&\ \&
438.Op Ar operator variable ...
439.Cx
440Test the value of an variable.
441.Tp Cx Ic \&.ifmake
442.Cx \&\ \&
443.Op \&!
444.Cx \&\ \&
445.Ar target
446.Cx \&\ \&
447.Op Ar operator target ...
448.Cx
449Test the the target being built.
450.Tp Cx Ic \&.ifnmake
451.Cx \&\ \&
452.Op \&!
453.Ar target
454.Cx \&\ \&
455.Op Ar operator target ...
456.Cx
457Test the target being built.
458.Tp Ic \&.else
459Reverse the sense of the last conditional.
460.Tp Cx Ic \&.elif
461.Cx \&\ \&
462.Op \&!
463.Cx \&\ \&
464.Ar expression
465.Cx \&\ \&
466.Op Ar operator expression ...
467.Cx
468A combination of ``.else'' followed by ``.if''.
469.Tp Cx Ic \&.elifdef
470.Cx \&\ \&
471.Op \&!
472.Cx \&\ \&
473.Ar variable
474.Cx \&\ \&
475.Op Ar operator variable ...
476.Cx
477A combination of ``.else'' followed by ``.ifdef''.
478.Tp Cx Ic \&.elifndef
479.Cx \&\ \&
480.Op \&!
481.Cx \&\ \&
482.Ar variable
483.Cx \&\ \&
484.Op Ar operator variable ...
485.Cx
486A combination of ``.else'' followed by ``.ifndef''.
487.Tp Cx Ic \&.elifmake
488.Cx \&\ \&
489.Op \&!
490.Cx \&\ \&
491.Ar target
492.Cx \&\ \&
493.Op Ar operator target ...
494.Cx
495A combination of ``.else'' followed by ``.ifmake''.
496.Tp Cx Ic \&.elifnmake
497.Cx \&\ \&
498.Op \&!
499.Cx \&\ \&
500.Ar target
501.Cx \&\ \&
502.Op Ar operator target ...
503.Cx
504A combination of ``.else'' followed by ``.ifnmake''.
505.Tp Ic \&.endif
506End the body of the conditional.
507.Tp
508.Pp
509The
510.Ar operator
511may be any one of the following:
512.Tp Cm \&|\&|
513logical OR
514.Tp Cm \&&&
515Logical AND; of higher precedence than ``''.
516.Tp
517.Pp
518As in C,
519.Nm make
520will only evaluate a conditional as far as is necessary to determine
521its value.
522Parenthesis may be used to change the order of evaluation.
523The boolean operator ``!'' may be used to logically negate an entire
524conditional.
525It is of higher precendence than ``&&''.
526.Pp
527The value of
528.Ar expression
529may be any of the following:
530.Tp Ic defined
531Takes a variable name as an argument and evaluates to true if the variable
532has been defined.
533.Tp Ic make
534Takes a target name as an argument and evaluates to true if the target
535was specified as part of
536.Cx Nm make
537.Cx \'s
538.Cx
539command line or was declared the default target (either implicitly or
540explicitly, see .MAIN) before the line containing the conditional.
541.Tp Ic empty
542Takes a variable, with possible modifiers, and evalutes to true if
543the expansion of the variable would result in an empty string.
544.Tp Ic exists
545Takes a file name as an argument and evaluates to true if the file exists.
546The file is searched for on the system search path (see .PATH).
547.Tp Ic target
548Takes a target name as an argument and evaluates to true if the target
549has been defined.
550.Tp
551.Pp
552.Ar Expression
553may also be an arithmetic or string comparison, with the left-hand side
554being a variable expansion.
555The standard C relational operators are all supported, and the usual
556number/base conversion is performed.
557Note, octal numbers are not supported.
558If the righthand value of a ``=='' or ``!='' operator begins with a
559quotation mark (``"'') a string comparison is done between the expanded
560variable and the text between the quotation marks.
561If no relational operator is given, it is assumed that the expanded
562variable is being compared against 0.
563.Pp
564When
565.Nm make
566is evaluating one of these conditional expression, and it encounters
567a word it doesn't recognize, either the ``make'' or ``defined''
568expression is applied to it, depending on the form of the conditional.
569If the form is ``.ifdef'' or ``.ifndef'', the ``defined'' expression
570is applied.
571Similarly, if the form is ``.ifmake'' or ``.ifnmake'', the ``make''
572expression is applied.
573.Pp
574If the conditional evaluates to true the parsing of the makefile continues
575as before.
576If it evaluates to false, the following lines are skipped.
577In both cases this continues until a ``.else'' or ``.endif'' is found.
578.Sh COMMENTS
579Comments begin with a hash (``#'') character, anywhere but in a shell
580command line, and continue to the end of the line.
581.Sh SPECIAL SOURCES
582.Tp Ic \&.IGNORE
583Ignore any errors from the commands associated with this target, exactly
584as if they all were preceded by a dash (``\-'').
585.Tp Ic \&.MAKE
586Execute the commands associated with this target even if the -n or -t
587options were specified.
588Normally used to mark recursive
589.Cx Nm make
590.Cx \'s .
591.Cx
592.Tp Ic \&.NOTMAIN
593Normally
594.Nm make
595selects the first target it encounters as the default target to be built
596if no target was specified.
597This source prevents this target from being selected.
598.Tp Ic \&.OPTIONAL
599If a target is marked with this attribute and
600.Nm make
601can't figure out how to create it, it will ignore this fact and assume
602the file isn't needed or already exists.
603.Tp Ic \&.PRECIOUS
604When
605.Nm make
606is interrupted, it removes any partially made targets.
607This source prevents the target from being removed.
608.Tp Ic \&.SILENT
609Do not echo any of the commands associated with this target, exactly
610as if they all were preceded by an at sign (``@'').
611.Tp Ic \&.USE
612Turn the target into
613.Cx Nm make
614.Cx \'s .
615.Cx
616version of a macro.
617When the target is used as a source for another target, the other target
618acquires the commands, sources, and attributes (except for .USE) of the
619source.
620If the target already has commands, the .USE target's commands are appended
621to them.
622.Tp
623.Sh "SPECIAL TARGETS"
624Special targets may not be included with other targets, i.e. they must be
625the only target specified.
626.Tp Ic \&.BEGIN
627Any command lines attached to this target are executed before anything
628else is done.
629.Tp Ic \&.DEFAULT
630This is sort of a .USE rule for any target (that was used only as a
631source) that
632.Nm make
633can't figure out any other way to create.
634Only the shell script is used.
635The .IMPSRC variable of a target that inherits .DEFAULT's commands is set
636to the target's own name.
637.Tp Ic \&.END
638Any command lines attached to this target are executed after everything
639else is done.
640.Tp Ic \&.IGNORE
641Mark each of the sources with the .IGNORE attribute.
642If no sources are specified, this is the equivalent of specifying the -i
643option.
644.Tp Ic \&.INTERRUPT
645If
646.Nm make
647is interrupted, the commands for this target will be executed.
648.Tp Ic \&.MAIN
649If no target is specified when
650.Nm make
651is invoked, this target will be built.
652.Tp Ic \&.MAKEFLAGS
653This target provides a way to specify flags for
654.Nm make
655when the makefile is used.
656The flags are as if typed to the shell, though the -f option will have
657no effect.
658.Tp Ic \&.PATH
659The sources are directories which are to be searched for files not
660found in the current directory.
661If no sources are specified, any previously specified directories are
662deleted.
663.Tp Ic \&.PRECIOUS
664Apply the .PRECIOUS attribute to any specified sources.
665If no sources are specified, the .PRECIOUS attribute is applied to every
666target in the file.
667.Tp Ic \&.SILENT
668Apply the .SILENT attribute to any specified sources.
669If no sources are specified, the .SILENT attribute is applied to every
670command in the file.
671.Tp Ic \&.SUFFIXES
672Each source specifies a suffix to
673.Nm make  .
674If no sources are specified, any previous specifies suffices are deleted.
675.Sh ENVIRONMENT
676.Nm make
677can utilize the
678.Ev MAKE ,
679.Ev MAKEFLAGS
680and
681.Ev MAKEOBJDIR
682environment variables.
683.Sh FILES
684.Dw /usr/share/mk
685.Di L
686.Dp Pa /usr/share/mk
687system makefile directory
688.Dp Pa sys.mk
689include system makefile
690.Dp Pa bsd.mk
691BSD source tree template
692.Dp Pa subdir.mk
693BSD source tree subdirectory template
694.Dp
695.Sh SEE ALSO
696.Sh HISTORY
697.Nm Make
698appeared in Version 7 AT&T UNIX.
699The
700.Nm make
701this man page describes is derived from code contributed by Adam
702de Boor.
703