xref: /original-bsd/usr.bin/make/make.1 (revision a1c2194a)
1.\" Copyright (c) 1990 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.redist.roff%
5.\"
6.\"	@(#)make.1	5.7 (Berkeley) 07/24/91
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 six different types of lines in a makefile: file dependency
140specifications, shell commands, variable assignments, include statements,
141conditional directives, 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 AND CONDITIONALS
466Makefile inclusion and conditional structures reminiscent of the C
467programming 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, with the left-hand side
629being a variable expansion.
630The standard C relational operators are all supported, and the usual
631number/base conversion is performed.
632Note, octal numbers are not supported.
633If the righthand value of a
634.Ql Ic ==
635or
636.Ql Ic "!="
637operator begins with a
638quotation mark
639.Pq Ql \*q
640a string comparison is done between the expanded
641variable and the text between the quotation marks.
642If no relational operator is given, it is assumed that the expanded
643variable is being compared against 0.
644.Pp
645When
646.Nm make
647is evaluating one of these conditional expression, and it encounters
648a word it doesn't recognize, either the ``make'' or ``defined''
649expression is applied to it, depending on the form of the conditional.
650If the form is
651.Ql Ic .ifdef
652or
653.Ql Ic .ifndef ,
654the ``defined'' expression
655is applied.
656Similarly, if the form is
657.Ql Ic .ifmake
658or
659.Ql Ic .ifnmake , the ``make''
660expression is applied.
661.Pp
662If the conditional evaluates to true the parsing of the makefile continues
663as before.
664If it evaluates to false, the following lines are skipped.
665In both cases this continues until a
666.Ql Ic .else
667or
668.Ql Ic .endif
669is found.
670.Sh COMMENTS
671Comments begin with a hash
672.Pq Ql \&#
673character, anywhere but in a shell
674command line, and continue to the end of the line.
675.Sh SPECIAL SOURCES
676.Bl -tag -width Ic .IGNORE
677.It Ic .IGNORE
678Ignore any errors from the commands associated with this target, exactly
679as if they all were preceded by a dash
680.Pq Ql \- .
681.It Ic .MAKE
682Execute the commands associated with this target even if the
683.Fl n
684or
685.Fl t
686options were specified.
687Normally used to mark recursive
688.Nm make Ns 's .
689.It Ic .NOTMAIN
690Normally
691.Nm make
692selects the first target it encounters as the default target to be built
693if no target was specified.
694This source prevents this target from being selected.
695.It Ic .OPTIONAL
696If a target is marked with this attribute and
697.Nm make
698can't figure out how to create it, it will ignore this fact and assume
699the file isn't needed or already exists.
700.It Ic .PRECIOUS
701When
702.Nm make
703is interrupted, it removes any partially made targets.
704This source prevents the target from being removed.
705.It Ic .SILENT
706Do not echo any of the commands associated with this target, exactly
707as if they all were preceded by an at sign
708.Pq Ql @ .
709.It Ic .USE
710Turn the target into
711.Nm make Ns 's .
712version of a macro.
713When the target is used as a source for another target, the other target
714acquires the commands, sources, and attributes (except for
715.Ic .USE )
716of the
717source.
718If the target already has commands, the
719.Ic .USE
720target's commands are appended
721to them.
722.El
723.Sh "SPECIAL TARGETS"
724Special targets may not be included with other targets, i.e. they must be
725the only target specified.
726.Bl -tag -width Ic .BEGIN
727.It Ic .BEGIN
728Any command lines attached to this target are executed before anything
729else is done.
730.It Ic .DEFAULT
731This is sort of a
732.Ic .USE
733rule for any target (that was used only as a
734source) that
735.Nm make
736can't figure out any other way to create.
737Only the shell script is used.
738The
739.Ic .IMPSRC
740variable of a target that inherits
741.Ic .DEFAULT Ns 's
742commands is set
743to the target's own name.
744.It Ic .END
745Any command lines attached to this target are executed after everything
746else is done.
747.It Ic .IGNORE
748Mark each of the sources with the
749.Ic .IGNORE
750attribute.
751If no sources are specified, this is the equivalent of specifying the
752.Fl i
753option.
754.It Ic .INTERRUPT
755If
756.Nm make
757is interrupted, the commands for this target will be executed.
758.It Ic .MAIN
759If no target is specified when
760.Nm make
761is invoked, this target will be built.
762.It Ic .MAKEFLAGS
763This target provides a way to specify flags for
764.Nm make
765when the makefile is used.
766The flags are as if typed to the shell, though the
767.Fl f
768option will have
769no effect.
770.It Ic .PATH
771The sources are directories which are to be searched for files not
772found in the current directory.
773If no sources are specified, any previously specified directories are
774deleted.
775.It Ic .PRECIOUS
776Apply the
777.Ic .PRECIOUS
778attribute to any specified sources.
779If no sources are specified, the
780.Ic .PRECIOUS
781attribute is applied to every
782target in the file.
783.It Ic .SILENT
784Apply the
785.Ic .SILENT
786attribute to any specified sources.
787If no sources are specified, the
788.Ic .SILENT
789attribute is applied to every
790command in the file.
791.It Ic .SUFFIXES
792Each source specifies a suffix to
793.Nm make .
794If no sources are specified, any previous specifies suffices are deleted.
795.Sh ENVIRONMENT
796.Nm Make
797utilizes the following environment variables, if they exist:
798.Ev MAKE ,
799.Ev MAKEFLAGS
800and
801.Ev MAKEOBJDIR .
802.Sh FILES
803.Bl -tag -width /usr/share/mk -compact
804.It .depend
805list of dependencies
806.It Makefile
807list of dependencies
808.It makefile
809list of dependencies
810.It sys.mk
811system makefile
812.It /usr/share/mk
813system makefile directory
814.El
815.Sh SEE ALSO
816.Xr mkdep 1
817.Sh HISTORY
818A
819.Nm Make
820command appeared in
821.At v7 .
822