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