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