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