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