VirtualBox

source: kBuild/branches/FREEBSD/src/kmk/make.1@ 163

Last change on this file since 163 was 24, checked in by bird, 22 years ago

Import of RELENG_4_7_0_RELEASE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.9 KB
Line 
1.\" Copyright (c) 1990, 1993
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\" notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\" notice, this list of conditions and the following disclaimer in the
11.\" documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\" must display the following acknowledgement:
14.\" This product includes software developed by the University of
15.\" California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" from: @(#)make.1 8.4 (Berkeley) 3/19/94
33.\" $FreeBSD: src/usr.bin/make/make.1,v 1.29.2.14 2002/09/09 19:06:16 archie Exp $
34.\"
35.Dd March 19, 1994
36.Dt MAKE 1
37.Os
38.Sh NAME
39.Nm make
40.Nd maintain program dependencies
41.Sh SYNOPSIS
42.Nm
43.Op Fl BPSXeiknqrstv
44.Op Fl D Ar variable
45.Op Fl d Ar flags
46.Op Fl E Ar variable
47.Op Fl f Ar makefile
48.Op Fl I Ar directory
49.Bk -words
50.Op Fl j Ar max_jobs
51.Op Fl m Ar directory
52.Ek
53.Op Fl V Ar variable
54.Op Ar variable Ns No = Ns Ar value
55.Op Ar target ...
56.Sh DESCRIPTION
57The
58.Nm
59utility is a program designed to simplify the maintenance of other programs.
60Its input is a list of specifications
61describing dependency relationships between the generation of
62files and programs.
63The first of
64.Ql Pa makefile
65and
66.Ql Pa Makefile
67that can be found in either the current directory or a special object directory
68(see
69.Ql Va .OBJDIR )
70will be read for this list of specifications.
71If the file
72.Ql Pa .depend
73can be found, it is also read (see
74.Xr mkdep 1 ) .
75.Pp
76This manual page is intended as a reference document only.
77For a more thorough introduction to
78.Nm
79and makefiles, please refer to
80.%T "Make \- A Tutorial" .
81.Pp
82The options are as follows:
83.Bl -tag -width Ds
84.It Fl B
85Try to be backwards compatible by executing a single shell per command and
86by executing the commands to make the sources of a dependency line in sequence.
87This is turned on by default unless
88.Fl j
89is used.
90.It Fl D Ar variable
91Define
92.Ar variable
93to be 1, in the global context.
94.It Fl d Ar flags
95Turn on debugging, and specify which portions of
96.Nm
97are to print debugging information.
98Argument
99.Ar flags
100is one or more of the following:
101.Bl -tag -width Ds
102.It Ar A
103Print all possible debugging information;
104equivalent to specifying all of the debugging flags.
105.It Ar a
106Print debugging information about archive searching and caching.
107.It Ar c
108Print debugging information about conditional evaluation.
109.It Ar d
110Print debugging information about directory searching and caching.
111.It Ar f
112Print debugging information about the execution of for loops.
113Currently a
114no-op.
115.It Ar "g1"
116Print the input graph before making anything.
117.It Ar "g2"
118Print the input graph after making everything, or before exiting
119on error.
120.It Ar j
121Print debugging information about running multiple shells.
122.It Ar l
123Print commands in Makefiles regardless of whether or not they are prefixed
124by @ or other "quiet" flags.
125Also known as "loud" behavior.
126.It Ar m
127Print debugging information about making targets, including modification
128dates.
129.It Ar s
130Print debugging information about suffix-transformation rules.
131.It Ar t
132Print debugging information about target list maintenance.
133.It Ar v
134Print debugging information about variable assignment.
135.El
136.It Fl E Ar variable
137Specify a variable whose environment value (if any) will override
138macro assignments within makefiles.
139.It Fl e
140Specify that environment values override macro assignments within
141makefiles for all variables.
142.It Fl f Ar makefile
143Specify a makefile to read instead of the default
144.Ql Pa makefile
145and
146.Ql Pa Makefile .
147If
148.Ar makefile
149is
150.Ql \- ,
151standard input is read.
152Multiple makefiles may be specified, and are read in the order specified.
153.It Fl I Ar directory
154Specify a directory in which to search for makefiles and included makefiles.
155The system makefile directory (or directories, see the
156.Fl m
157option) is automatically included as part of this list.
158.It Fl i
159Ignore non-zero exit of shell commands in the makefile.
160Equivalent to specifying
161.Ql \-
162before each command line in the makefile.
163.It Fl j Ar max_jobs
164Specify the maximum number of jobs that
165.Nm
166may have running at any one time.
167Turns compatibility mode off, unless the
168.Ar B
169flag is also specified.
170.It Fl k
171Continue processing after errors are encountered, but only on those targets
172that do not depend on the target whose creation caused the error.
173.It Fl m Ar directory
174Specify a directory in which to search for sys.mk and makefiles included
175via the <...> style.
176Multiple directories can be added to form a search path.
177This path will override the default system include path:
178.Pa /usr/share/mk .
179Furthermore, the system include path will be appended to the search path used
180for "..."-style inclusions (see the
181.Fl I
182option).
183.It Fl n
184Display the commands that would have been executed, but do not actually
185execute them.
186.It Fl P
187Collate the output of a given job and display it only when the job finishes,
188instead of mixing the output of parallel jobs together.
189This option has no effect unless
190.Fl j
191is used too.
192.It Fl q
193Do not execute any commands, but exit 0 if the specified targets are
194up-to-date and 1, otherwise.
195.It Fl r
196Do not use the built-in rules specified in the system makefile.
197.It Fl S
198Stop processing when an error is encountered.
199Default behaviour.
200This is needed to negate the
201.Fl k
202option during recursive builds.
203.It Fl s
204Do not echo any commands as they are executed.
205Equivalent to specifying
206.Ql Ic @
207before each command line in the makefile.
208.It Fl t
209Rather than re-building a target as specified in the makefile, create it
210or update its modification time to make it appear up-to-date.
211.It Fl V Ar variable
212Print
213.Nm Ns 's
214idea of the value of
215.Ar variable ,
216in the global context.
217Do not build any targets.
218Multiple instances of this option may be specified;
219the variables will be printed one per line,
220with a blank line for each null or undefined variable.
221.It Fl v
222Be extra verbose.
223For multi-job makes, this will cause file banners to be generated.
224.It Fl X
225When using the
226.Fl V
227option to print the values of variables,
228do not recursively expand the values.
229.It Ar variable Ns No = Ns Ar value
230Set the value of the variable
231.Ar variable
232to
233.Ar value .
234.El
235.Pp
236There are seven different types of lines in a makefile: file dependency
237specifications, shell commands, variable assignments, include statements,
238conditional directives, for loops, and comments.
239.Pp
240In general, lines may be continued from one line to the next by ending
241them with a backslash
242.Pq Ql \e .
243The trailing newline character and initial whitespace on the following
244line are compressed into a single space.
245.Sh FILE DEPENDENCY SPECIFICATIONS
246Dependency lines consist of one or more targets, an operator, and zero
247or more sources.
248This creates a relationship where the targets
249.Dq depend
250on the sources
251and are usually created from them.
252The exact relationship between the target and the source is determined
253by the operator that separates them.
254The three operators are as follows:
255.Bl -tag -width flag
256.It Ic \&:
257A target is considered out-of-date if its modification time is less than
258those of any of its sources.
259Sources for a target accumulate over dependency lines when this operator
260is used.
261The target is removed if
262.Nm
263is interrupted.
264.It Ic \&!
265Targets are always re-created, but not until all sources have been
266examined and re-created as necessary.
267Sources for a target accumulate over dependency lines when this operator
268is used.
269The target is removed if
270.Nm
271is interrupted.
272.It Ic \&::
273If no sources are specified, the target is always re-created.
274Otherwise, a target is considered out-of-date if any of its sources has
275been modified more recently than the target.
276Sources for a target do not accumulate over dependency lines when this
277operator is used.
278The target will not be removed if
279.Nm
280is interrupted.
281.El
282.Pp
283Targets and sources may contain the shell wildcard expressions
284.Ql \&? ,
285.Ql * ,
286.Ql []
287and
288.Ql {} .
289The expressions
290.Ql \&? ,
291.Ql *
292and
293.Ql []
294may only be used as part of the final
295component of the target or source, and must be used to describe existing
296files.
297The expression
298.Ql {}
299need not necessarily be used to describe existing files.
300Expansion is in directory order, not alphabetically as done in the shell.
301.Sh SHELL COMMANDS
302Each target may have associated with it a series of shell commands, normally
303used to create the target.
304Each of the commands in this script
305.Em must
306be preceded by a tab.
307While any target may appear on a dependency line, only one of these
308dependencies may be followed by a creation script, unless the
309.Ql Ic ::
310operator is used.
311.Pp
312If the first or first two characters of the command line are
313.Ql Ic @
314and/or
315.Ql Ic \- ,
316the command is treated specially.
317A
318.Ql Ic @
319causes the command not to be echoed before it is executed.
320A
321.Ql Ic \-
322causes any non-zero exit status of the command line to be ignored.
323.Sh VARIABLE ASSIGNMENTS
324Variables in
325.Nm
326are much like variables in the shell, and, by tradition,
327consist of all upper-case letters.
328The five operators that can be used to assign values to variables are as
329follows:
330.Bl -tag -width Ds
331.It Ic \&=
332Assign the value to the variable.
333Any previous value is overridden.
334.It Ic \&+=
335Append the value to the current value of the variable.
336.It Ic \&?=
337Assign the value to the variable if it is not already defined.
338.It Ic \&:=
339Assign with expansion, i.e. expand the value before assigning it
340to the variable.
341Normally, expansion is not done until the variable is referenced.
342.It Ic \&!=
343Expand the value and pass it to the shell for execution and assign
344the result to the variable.
345Any newlines in the result are replaced with spaces.
346.El
347.Pp
348Any whitespace before the assigned
349.Ar value
350is removed; if the value is being appended, a single space is inserted
351between the previous contents of the variable and the appended value.
352.Pp
353Variables are expanded by surrounding the variable name with either
354curly braces
355.Pq Ql {}
356or parentheses
357.Pq Ql ()
358and preceding it with
359a dollar sign
360.Pq Ql \&$ .
361If the variable name contains only a single letter, the surrounding
362braces or parentheses are not required.
363This shorter form is not recommended.
364.Pp
365Variable substitution occurs at two distinct times, depending on where
366the variable is being used.
367Variables in dependency lines are expanded as the line is read.
368Variables in shell commands are expanded when the shell command is
369executed.
370.Pp
371The four different classes of variables (in order of increasing precedence)
372are:
373.Bl -tag -width Ds
374.It Environment variables
375Variables defined as part of
376.Nm Ns 's
377environment.
378.It Global variables
379Variables defined in the makefile or in included makefiles.
380.It Command line variables
381Variables defined as part of the command line.
382.It Local variables
383Variables that are defined specific to a certain target.
384The seven local variables are as follows:
385.Bl -tag -width ".ARCHIVE"
386.It Va .ALLSRC
387The list of all sources for this target; also known as
388.Ql Va \&> .
389.It Va .ARCHIVE
390The name of the archive file; also known as
391.Ql Va \&! .
392.It Va .IMPSRC
393The name/path of the source from which the target is to be transformed
394(the
395.Dq implied
396source); also known as
397.Ql Va \&< .
398.It Va .MEMBER
399The name of the archive member; also known as
400.Ql Va \&% .
401.It Va .OODATE
402The list of sources for this target that were deemed out-of-date; also
403known as
404.Ql Va \&? .
405.It Va .PREFIX
406The file prefix of the file, containing only the file portion, no suffix
407or preceding directory components; also known as
408.Ql Va * .
409.It Va .TARGET
410The name of the target; also known as
411.Ql Va @ .
412.El
413.Pp
414The shorter forms
415.Ql Va @ ,
416.Ql Va \&! ,
417.Ql Va \&< ,
418.Ql Va \&% ,
419.Ql Va \&? ,
420.Ql Va \&> ,
421and
422.Ql Va *
423are permitted for backward
424compatibility and are not recommended.
425The six variables
426.Ql Va "@F" ,
427.Ql Va "@D" ,
428.Ql Va "<F" ,
429.Ql Va "<D" ,
430.Ql Va "*F" ,
431and
432.Ql Va "*D"
433are
434permitted for compatibility with
435.At V
436makefiles and are not recommended.
437.Pp
438Four of the local variables may be used in sources on dependency lines
439because they expand to the proper value for each target on the line.
440These variables are
441.Ql Va .TARGET ,
442.Ql Va .PREFIX ,
443.Ql Va .ARCHIVE ,
444and
445.Ql Va .MEMBER .
446.El
447.Pp
448In addition,
449.Nm
450sets or knows about the following internal variables or environment
451variables:
452.Bl -tag -width MAKEFLAGS
453.It Va \&$
454A single dollar sign
455.Ql \&$ ,
456i.e.\&
457.Ql \&$$
458expands to a single dollar
459sign.
460.It Va MAKE
461The name that
462.Nm
463was executed with
464.Pq Va argv Ns Op 0 .
465.It Va .CURDIR
466A path to the directory where
467.Nm
468was executed.
469The
470.Nm
471utility sets
472.Va .CURDIR
473to the canonical path given by
474.Xr getcwd 3 .
475.It Va .OBJDIR
476A path to the directory where the targets are built.
477At startup,
478.Nm
479searches for an alternate directory to place target files.
480It will attempt to change into this special directory
481and will search this directory for makefiles
482not found in the current directory.
483The following directories are tried in order:
484.Pp
485.Bl -enum -compact
486.It
487${MAKEOBJDIRPREFIX}/`pwd`
488.It
489${MAKEOBJDIR}
490.It
491obj.${MACHINE}
492.It
493obj
494.It
495/usr/obj/`pwd`
496.El
497.Pp
498The first directory that
499.Nm
500successfully changes into is used.
501If either
502.Ev MAKEOBJDIRPREFIX
503or
504.Ev MAKEOBJDIR
505is set in the environment but
506.Nm
507is unable to change into the corresponding directory,
508then the current directory is used
509without checking the remainder of the list.
510If they are undefined and
511.Nm
512is unable to change into any of the remaining three directories,
513then the current directory is used.
514.It Va .MAKEFLAGS
515The environment variable
516.Ev MAKEFLAGS
517may contain anything that
518may be specified on
519.Nm Ns 's
520command line.
521Its contents are stored in
522.Nm Ns 's
523.Va .MAKEFLAGS
524variable.
525Anything specified on
526.Nm Ns 's
527command line is appended to the
528.Va .MAKEFLAGS
529variable which is then
530entered into the environment as
531.Ev MAKEFLAGS
532for all programs which
533.Nm
534executes.
535.It Va MFLAGS
536A synonym for
537.Va .MAKEFLAGS
538provided for backward compatibility.
539.It Ev PWD
540Alternate path to the current directory.
541Supported if built with WANT_ENV_PWD defined.
542.Nm
543normally sets
544.Ql Va .CURDIR
545to the canonical path given by
546.Xr getcwd 3 .
547However, if the environment variable
548.Ev PWD
549is set and gives a path to the current directory, then
550.Nm
551sets
552.Ql Va .CURDIR
553to the value of
554.Ev PWD
555instead.
556.Ev PWD
557is always set to the value of
558.Ql Va .OBJDIR
559for all programs which
560.Nm
561executes.
562.It Va .TARGETS
563List of targets
564.Nm
565is currently building.
566.It Va .INCLUDES
567See
568.Ic .INCLUDES
569special target.
570.It Va .LIBS
571See
572.Ic .LIBS
573special target.
574.It Va MACHINE
575Name of the machine architecture
576.Nm
577is running on, obtained from the
578.Ev MACHINE
579environment variable, or through
580.Xr uname 3
581if not defined.
582.It Va MACHINE_ARCH
583Name of the machine architecture
584.Nm
585was compiled for, defined at compilation time.
586.It Va VPATH
587Makefiles may assign a colon-delimited list of directories to
588.Va VPATH .
589These directories will be searched for source files by
590.Nm
591after
592.Nm
593has finished parsing all input makefiles.
594.El
595.Pp
596Variable expansion may be modified to select or modify each word of the
597variable (where a
598.Dq word
599is whitespace-delimited sequence of characters).
600The general format of a variable expansion is as follows:
601.Pp
602.Dl {variable[:modifier[:...]]}
603.Pp
604Each modifier begins with a colon and one of the following
605special characters.
606The colon may be escaped with a backslash
607.Pq Ql \e .
608.Bl -tag -width Cm
609.Sm off
610.It Cm C No \&/ Ar pattern Xo
611.No \&/ Ar replacement
612.No \&/ Op Cm 1g
613.Xc
614.Sm on
615The
616.Cm C
617modifier is just like the
618.Cm S
619modifier except that the old and new strings, instead of being
620simple strings, are an extended regular expression (see
621.Xr re_format 7 )
622and an
623.Xr ed 1 Ns \-style
624replacement string.
625Normally, the first occurrence of the pattern in
626each word of the value is changed.
627The
628.Ql 1
629modifier causes the substitution to apply to at most one word; the
630.Ql g
631modifier causes the substitution to apply to as many instances of the
632search pattern as occur in the word or words it is found in.
633Note that
634.Ql 1
635and
636.Ql g
637are orthogonal; the former specifies whether multiple words are
638potentially affected, the latter whether multiple substitutions can
639potentially occur within each affected word.
640.It Cm E
641Replaces each word in the variable with its suffix.
642.It Cm H
643Replaces each word in the variable with everything but the last component.
644.It Cm L
645Converts variable to lower-case letters.
646.It Cm M Ns Ar pattern
647Select only those words that match the rest of the modifier.
648The standard shell wildcard characters
649.Pf ( Ql * ,
650.Ql \&? ,
651and
652.Ql Op )
653may
654be used.
655The wildcard characters may be escaped with a backslash
656.Pq Ql \e .
657.It Cm N Ns Ar pattern
658This is identical to
659.Cm M ,
660but selects all words which do not match
661the rest of the modifier.
662.It Cm Q
663Quotes every shell meta-character in the variable, so that it can be passed
664safely through recursive invocations of
665.Nm .
666.It Cm R
667Replaces each word in the variable with everything but its suffix.
668.Sm off
669.It Cm S No \&/ Ar old_string Xo
670.No \&/ Ar new_string
671.No \&/ Op Cm g
672.Xc
673.Sm on
674Modify the first occurrence of
675.Ar old_string
676in each word of the variable's value, replacing it with
677.Ar new_string .
678If a
679.Ql g
680is appended to the last slash of the pattern, all occurrences
681in each word are replaced.
682If
683.Ar old_string
684begins with a caret
685.Pq Ql ^ ,
686.Ar old_string
687is anchored at the beginning of each word.
688If
689.Ar old_string
690ends with a dollar sign
691.Pq Ql \&$ ,
692it is anchored at the end of each word.
693Inside
694.Ar new_string ,
695an ampersand
696.Pq Ql &
697is replaced by
698.Ar old_string .
699Any character may be used as a delimiter for the parts of the modifier
700string.
701The anchoring, ampersand, and delimiter characters may be escaped with a
702backslash
703.Pq Ql \e .
704.Pp
705Variable expansion occurs in the normal fashion inside both
706.Ar old_string
707and
708.Ar new_string
709with the single exception that a backslash is used to prevent the expansion
710of a dollar sign
711.Pq Ql \&$ ,
712not a preceding dollar sign as is usual.
713.It Cm T
714Replaces each word in the variable with its last component.
715.It Ar old_string=new_string
716This is the
717.At V
718style variable substitution.
719It must be the last modifier specified.
720If
721.Ar old_string
722or
723.Ar new_string
724do not contain the pattern matching character
725.Ar %
726then it is assumed that they are
727anchored at the end of each word, so only suffixes or entire
728words may be replaced.
729Otherwise
730.Ar %
731is the substring of
732.Ar old_string
733to be replaced in
734.Ar new_string
735.It Cm U
736Converts variable to upper-case letters.
737.El
738.Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
739Directives, conditionals, and for loops reminiscent
740of the C programming language are provided in
741.Nm .
742All such structures are identified by a line beginning with a single
743dot
744.Pq Ql \&.
745character.
746The following directives are supported:
747.Bl -tag -width Ds
748.It Ic \&.include Ar <file>
749.It Ic \&.include Ar \*qfile\*q
750Include the specified makefile.
751Variables between the angle brackets
752or double quotes are expanded to form the file name.
753If angle brackets
754are used, the included makefile is expected to be in the system
755makefile directory.
756If double quotes are used, the including
757makefile's directory and any directories specified using the
758.Fl I
759option are searched before the system
760makefile directory.
761.It Ic \&.undef Ar variable
762Un-define the specified global variable.
763Only global variables may be un-defined.
764.It Ic \&.error Ar message
765Terminate processing of the makefile immediately.
766The filename of the
767makefile, the line on which the error was encountered and the specified
768message are printed to standard output and
769.Nm
770terminates with exit code 1.
771Variables in the message are expanded.
772.El
773.Pp
774Conditionals are used to determine which parts of the Makefile
775to process.
776They are used similarly to the conditionals supported
777by the C pre-processor.
778The following conditionals are supported:
779.Bl -tag -width Ds
780.It Xo
781.Ic \&.if
782.Oo \&! Oc Ns Ar expression
783.Op Ar operator expression ...
784.Xc
785Test the value of an expression.
786.It Xo
787.Ic .ifdef
788.Oo \&! Oc Ns Ar variable
789.Op Ar operator variable ...
790.Xc
791Test the value of a variable.
792.It Xo
793.Ic .ifndef
794.Oo \&! Oc Ns Ar variable
795.Op Ar operator variable ...
796.Xc
797Test the value of a variable.
798.It Xo
799.Ic .ifmake
800.Oo \&! Oc Ns Ar target
801.Op Ar operator target ...
802.Xc
803Test the target being built.
804.It Xo
805.Ic .ifnmake
806.Oo \&! Oc Ns Ar target
807.Op Ar operator target ...
808.Xc
809Test the target being built.
810.It Ic .else
811Reverse the sense of the last conditional.
812.It Xo
813.Ic .elif
814.Oo \&! Oc Ns Ar expression
815.Op Ar operator expression ...
816.Xc
817A combination of
818.Ql Ic .else
819followed by
820.Ql Ic .if .
821.It Xo
822.Ic .elifdef
823.Oo \&! Oc Ns Ar variable
824.Op Ar operator variable ...
825.Xc
826A combination of
827.Ql Ic .else
828followed by
829.Ql Ic .ifdef .
830.It Xo
831.Ic .elifndef
832.Oo \&! Oc Ns Ar variable
833.Op Ar operator variable ...
834.Xc
835A combination of
836.Ql Ic .else
837followed by
838.Ql Ic .ifndef .
839.It Xo
840.Ic .elifmake
841.Oo \&! Oc Ns Ar target
842.Op Ar operator target ...
843.Xc
844A combination of
845.Ql Ic .else
846followed by
847.Ql Ic .ifmake .
848.It Xo
849.Ic .elifnmake
850.Oo \&! Oc Ns Ar target
851.Op Ar operator target ...
852.Xc
853A combination of
854.Ql Ic .else
855followed by
856.Ql Ic .ifnmake .
857.It Ic .endif
858End the body of the conditional.
859.El
860.Pp
861The
862.Ar operator
863may be any one of the following:
864.Bl -tag -width "Cm XX"
865.It Cm \&|\&|
866logical OR
867.It Cm \&&&
868Logical
869.Tn AND ;
870of higher precedence than
871.Ql Ic || .
872.El
873.Pp
874As in C,
875.Nm
876will only evaluate a conditional as far as is necessary to determine
877its value.
878Parentheses may be used to change the order of evaluation.
879The boolean operator
880.Ql Ic !\&
881may be used to logically negate an entire
882conditional.
883It is of higher precedence than
884.Ql Ic \&&& .
885.Pp
886The value of
887.Ar expression
888may be any of the following:
889.Bl -tag -width Ic
890.It Ic defined
891Takes a variable name as an argument and evaluates to true if the variable
892has been defined.
893.It Ic make
894Takes a target name as an argument and evaluates to true if the target
895was specified as part of
896.Nm Ns 's
897command line or was declared the default target (either implicitly or
898explicitly, see
899.Va .MAIN )
900before the line containing the conditional.
901.It Ic empty
902Takes a variable, with possible modifiers, and evaluates to true if
903the expansion of the variable would result in an empty string.
904.It Ic exists
905Takes a file name as an argument and evaluates to true if the file exists.
906The file is searched for on the system search path (see
907.Va .PATH ) .
908.It Ic target
909Takes a target name as an argument and evaluates to true if the target
910has been defined.
911.El
912.Pp
913An
914.Ar expression
915may also be an arithmetic or string comparison.
916Variable expansion is
917performed on both sides of the comparison, after which the integral
918values are compared.
919A value is interpreted as hexadecimal if it is
920preceded by 0x, otherwise it is decimal; octal numbers are not supported.
921The standard C relational operators are all supported.
922If after
923variable expansion, either the left or right hand side of a
924.Ql Ic ==
925or
926.Ql Ic "!="
927operator is not an integral value, then
928string comparison is performed between the expanded
929variables.
930If no relational operator is given, it is assumed that the expanded
931variable is being compared against 0.
932.Pp
933When
934.Nm
935is evaluating one of these conditional expressions, and it encounters
936a word it doesn't recognize, either the
937.Dq make
938or
939.Dq defined
940expression is applied to it, depending on the form of the conditional.
941If the form is
942.Ql Ic .ifdef
943or
944.Ql Ic .ifndef ,
945the
946.Dq defined
947expression is applied.
948Similarly, if the form is
949.Ql Ic .ifmake
950or
951.Ql Ic .ifnmake ,
952the
953.Dq make
954expression is applied.
955.Pp
956If the conditional evaluates to true the parsing of the makefile continues
957as before.
958If it evaluates to false, the following lines are skipped.
959In both cases this continues until a
960.Ql Ic .else
961or
962.Ql Ic .endif
963is found.
964.Pp
965For loops are typically used to apply a set of rules to a list of files.
966The syntax of a for loop is:
967.Pp
968.Bl -tag -width indent -compact
969.It Ic .for Ar variable Ic in Ar expression
970.It <make-rules>
971.It Ic \&.endfor
972.El
973.Pp
974After the for
975.Ar expression
976is evaluated, it is split into words.
977The
978iteration
979.Ar variable
980is successively set to each word, and substituted in the
981.Ic make-rules
982inside the body of the for loop.
983.Sh COMMENTS
984Comments begin with a hash
985.Pq Ql \&#
986character, anywhere but in a shell
987command line, and continue to the end of the line.
988.Sh SPECIAL SOURCES
989.Bl -tag -width Ic
990.It Ic .IGNORE
991Ignore any errors from the commands associated with this target, exactly
992as if they all were preceded by a dash
993.Pq Ql \- .
994.It Ic .MAKE
995Execute the commands associated with this target even if the
996.Fl n
997or
998.Fl t
999options were specified.
1000Normally used to mark recursive
1001.Nm Ns 's .
1002.It Ic .NOTMAIN
1003Normally
1004.Nm
1005selects the first target it encounters as the default target to be built
1006if no target was specified.
1007This source prevents this target from being selected.
1008.It Ic .OPTIONAL
1009If a target is marked with this attribute and
1010.Nm
1011can't figure out how to create it, it will ignore this fact and assume
1012the file isn't needed or already exists.
1013.It Ic .PRECIOUS
1014When
1015.Nm
1016is interrupted, it removes any partially made targets.
1017This source prevents the target from being removed.
1018.It Ic .SILENT
1019Do not echo any of the commands associated with this target, exactly
1020as if they all were preceded by an at sign
1021.Pq Ql @ .
1022.It Ic .USE
1023Turn the target into
1024.Nm Ns 's
1025version of a macro.
1026When the target is used as a source for another target, the other target
1027acquires the commands, sources, and attributes (except for
1028.Ic .USE )
1029of the
1030source.
1031If the target already has commands, the
1032.Ic .USE
1033target's commands are appended
1034to them.
1035.It Ic .WAIT
1036If special
1037.Ic .WAIT
1038source is appears in a dependency line, the sources that precede it are
1039made before the sources that succeed it in the line.
1040Loops are not being
1041detected and targets that form loops will be silently ignored.
1042.El
1043.Sh "SPECIAL TARGETS"
1044Special targets may not be included with other targets, i.e. they must be
1045the only target specified.
1046.Bl -tag -width Ic
1047.It Ic .BEGIN
1048Any command lines attached to this target are executed before anything
1049else is done.
1050.It Ic .DEFAULT
1051This is sort of a
1052.Ic .USE
1053rule for any target (that was used only as a
1054source) that
1055.Nm
1056can't figure out any other way to create.
1057Only the shell script is used.
1058The
1059.Ic .IMPSRC
1060variable of a target that inherits
1061.Ic .DEFAULT Ns 's
1062commands is set
1063to the target's own name.
1064.It Ic .END
1065Any command lines attached to this target are executed after everything
1066else is done.
1067.It Ic .IGNORE
1068Mark each of the sources with the
1069.Ic .IGNORE
1070attribute.
1071If no sources are specified, this is the equivalent of specifying the
1072.Fl i
1073option.
1074.It Ic .INCLUDES
1075A list of suffixes that indicate files that can be included in a source
1076file.
1077The suffix must have already been declared with
1078.Ic .SUFFIXES ;
1079any suffix so declared will have the directories on its search path (see
1080.Ic .PATH )
1081placed in the
1082.Va .INCLUDES
1083special variable, each preceded by a
1084.Fl I
1085flag.
1086.It Ic .INTERRUPT
1087If
1088.Nm
1089is interrupted, the commands for this target will be executed.
1090.It Ic .LIBS
1091This does for libraries what
1092.Ic .INCLUDES
1093does for include files, except that the flag used is
1094.Fl L .
1095.It Ic .MAIN
1096If no target is specified when
1097.Nm
1098is invoked, this target will be built.
1099This is always set, either
1100explicitly, or implicitly when
1101.Nm
1102selects the default target, to give the user a way to refer to the default
1103target on the command line.
1104.It Ic .MAKEFLAGS
1105This target provides a way to specify flags for
1106.Nm
1107when the makefile is used.
1108The flags are as if typed to the shell, though the
1109.Fl f
1110option will have
1111no effect.
1112.\" XXX: NOT YET!!!!
1113.\" .It Ic .NOTPARALLEL
1114.\" The named targets are executed in non parallel mode. If no targets are
1115.\" specified, then all targets are executed in non parallel mode.
1116.It Ic .NOTPARALLEL
1117Disable parallel mode.
1118.It Ic .NO_PARALLEL
1119Same as above, for compatibility with other pmake variants.
1120.It Ic .ORDER
1121The named targets are made in sequence.
1122.\" XXX: NOT YET!!!!
1123.\" .It Ic .PARALLEL
1124.\" The named targets are executed in parallel mode. If no targets are
1125.\" specified, then all targets are executed in parallel mode.
1126.It Ic .PATH
1127The sources are directories which are to be searched for files not
1128found in the current directory.
1129If no sources are specified, any previously specified directories are
1130deleted.
1131Where possible, use of
1132.Ic .PATH
1133is preferred over use of the
1134.Va VPATH
1135variable.
1136.It Ic .PATH\fIsuffix\fR
1137The sources are directories which are to be searched for suffixed files
1138not found in the current directory.
1139The
1140.Nm
1141utility
1142first searches the suffixed search path, before reverting to the default
1143path if the file is not found there.
1144This form is required for
1145.Ic .LIBS
1146and
1147.Ic .INCLUDES
1148to work.
1149.It Ic .PHONY
1150Apply the
1151.Ic .PHONY
1152attribute to any specified sources.
1153Targets with this attribute are always
1154considered to be out of date.
1155.It Ic .PRECIOUS
1156Apply the
1157.Ic .PRECIOUS
1158attribute to any specified sources.
1159If no sources are specified, the
1160.Ic .PRECIOUS
1161attribute is applied to every
1162target in the file.
1163.It Ic .SILENT
1164Apply the
1165.Ic .SILENT
1166attribute to any specified sources.
1167If no sources are specified, the
1168.Ic .SILENT
1169attribute is applied to every
1170command in the file.
1171.It Ic .SUFFIXES
1172Each source specifies a suffix to
1173.Nm .
1174If no sources are specified, any previous specified suffices are deleted.
1175.El
1176.Sh COMPATIBILITY
1177Older versions of
1178.Nm
1179used
1180.Ev MAKE
1181instead of
1182.Ev MAKEFLAGS .
1183This was removed for POSIX compatibility.
1184The internal variable
1185.Va MAKE
1186is set to the same value as
1187.Va .MAKE ;
1188support for this may be removed in the future.
1189.Pp
1190Most of the more esoteric features of
1191.Nm
1192should probably be avoided for greater compatibility.
1193.Sh ENVIRONMENT
1194The
1195.Nm
1196utility uses the following environment variables, if they exist:
1197.Ev MACHINE ,
1198.Ev MAKE ,
1199.Ev MAKEFLAGS ,
1200.Ev MAKEOBJDIR ,
1201.Ev MAKEOBJDIRPREFIX ,
1202and
1203.Ev PWD .
1204.Sh FILES
1205.Bl -tag -width /usr/share/doc/psd/12.make -compact
1206.It Pa .depend
1207list of dependencies
1208.It Pa Makefile
1209list of dependencies
1210.It Pa makefile
1211list of dependencies
1212.It obj
1213object directory
1214.It Pa sys.mk
1215system makefile (processed before any other file, including
1216.Pa makefile
1217and
1218.Pa Makefile )
1219.It Pa /usr/share/mk
1220system makefile directory
1221.It /usr/share/doc/psd/12.make
1222PMake tutorial
1223.It Pa /usr/obj
1224default
1225.Ev MAKEOBJDIRPREFIX
1226directory.
1227.El
1228.Sh BUGS
1229The determination of
1230.Va .OBJDIR
1231is contorted to the point of absurdity.
1232.Pp
1233In the presence of several
1234.Ic .MAIN
1235special targets,
1236.Nm
1237silently ignores all but the first.
1238.Pp
1239.Va .TARGETS
1240is not set to the default target when
1241.Nm
1242is invoked without a target name and no
1243.Ic .MAIN
1244special target exists.
1245.Pp
1246The evaluation of
1247.Ar expression
1248in a test is very simple-minded.
1249Currently, the only form that works is
1250.Ql .if ${VAR} op something
1251For instance, you should write tests as
1252.Ql .if ${VAR} = "string"
1253not the other way around, which doesn't work.
1254.Pp
1255For loops are expanded before tests, so a fragment such as:
1256.Bd -literal
1257\&.for TMACHINE in ${SHARED_ARCHS}
1258\&.if ${TMACHINE} = ${MACHINE}
1259 ...
1260\&.endif
1261\&.endfor
1262.Ed
1263won't work, and should be rewritten the other way around.
1264.Sh SEE ALSO
1265.Xr mkdep 1 ,
1266.Xr make.conf 5
1267.Rs
1268.%T "PMake - A Tutorial"
1269.Re
1270in
1271.Pa /usr/share/doc/psd/12.make
1272.Sh HISTORY
1273A
1274.Nm
1275command appeared in
1276.At v7 .
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette