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