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