Merge from vendor branch GDB:
[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.3 2003/11/18 23:49:54 dillon Exp $
35 .\"
36 .Dd March 19, 1994
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 MAKEFLAGS
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 .MAKEFLAGS
521 The environment variable
522 .Ev MAKEFLAGS
523 may contain anything that
524 may be specified on
525 .Nm Ns 's
526 command line.
527 Its contents are stored in
528 .Nm Ns 's
529 .Va .MAKEFLAGS
530 variable.
531 Anything specified on
532 .Nm Ns 's
533 command line is appended to the
534 .Va .MAKEFLAGS
535 variable which is then
536 entered into the environment as
537 .Ev MAKEFLAGS
538 for all programs which
539 .Nm
540 executes.
541 .It Va MFLAGS
542 A synonym for
543 .Va .MAKEFLAGS
544 provided for backward compatibility.
545 .It Ev PWD
546 Alternate path to the current directory.
547 Supported if built with WANT_ENV_PWD defined.
548 .Nm
549 normally sets
550 .Ql Va .CURDIR
551 to the canonical path given by
552 .Xr getcwd 3 .
553 However, if the environment variable
554 .Ev PWD
555 is set and gives a path to the current directory, then
556 .Nm
557 sets
558 .Ql Va .CURDIR
559 to the value of
560 .Ev PWD
561 instead.
562 .Ev PWD
563 is always set to the value of
564 .Ql Va .OBJDIR
565 for all programs which
566 .Nm
567 executes.
568 .It Va .TARGETS
569 List of targets
570 .Nm
571 is currently building.
572 .It Va .INCLUDES
573 See
574 .Ic .INCLUDES
575 special target.
576 .It Va .LIBS
577 See
578 .Ic .LIBS
579 special target.
580 .It Va MACHINE
581 Name of the machine architecture
582 .Nm
583 is running on, obtained from the
584 .Ev MACHINE
585 environment variable, or through
586 .Xr uname 3
587 if not defined.
588 .It Va MACHINE_ARCH
589 Name of the machine architecture
590 .Nm
591 was compiled for, defined at compilation time.
592 .It Va VPATH
593 Makefiles may assign a colon-delimited list of directories to
594 .Va VPATH .
595 These directories will be searched for source files by
596 .Nm
597 after
598 .Nm
599 has finished parsing all input makefiles.
600 .El
601 .Pp
602 Variable expansion may be modified to select or modify each word of the
603 variable (where a
604 .Dq word
605 is whitespace-delimited sequence of characters).
606 The general format of a variable expansion is as follows:
607 .Pp
608 .Dl {variable[:modifier[:...]]}
609 .Pp
610 Each modifier begins with a colon and one of the following
611 special characters.
612 The colon may be escaped with a backslash
613 .Pq Ql \e .
614 .Bl -tag -width Cm
615 .Sm off
616 .It Cm C No \&/ Ar pattern Xo
617 .No \&/ Ar replacement
618 .No \&/ Op Cm 1g
619 .Xc
620 .Sm on
621 The
622 .Cm C
623 modifier is just like the
624 .Cm S
625 modifier except that the old and new strings, instead of being
626 simple strings, are an extended regular expression (see
627 .Xr re_format 7 )
628 and an
629 .Xr ed 1 Ns \-style
630 replacement string.
631 Normally, the first occurrence of the pattern in
632 each word of the value is changed.
633 The
634 .Ql 1
635 modifier causes the substitution to apply to at most one word; the
636 .Ql g
637 modifier causes the substitution to apply to as many instances of the
638 search pattern as occur in the word or words it is found in.
639 Note that
640 .Ql 1
641 and
642 .Ql g
643 are orthogonal; the former specifies whether multiple words are
644 potentially affected, the latter whether multiple substitutions can
645 potentially occur within each affected word.
646 .It Cm E
647 Replaces each word in the variable with its suffix.
648 .It Cm H
649 Replaces each word in the variable with everything but the last component.
650 .It Cm L
651 Converts variable to lower-case letters.
652 .It Cm M Ns Ar pattern
653 Select only those words that match the rest of the modifier.
654 The standard shell wildcard characters
655 .Pf ( Ql * ,
656 .Ql \&? ,
657 and
658 .Ql Op )
659 may
660 be used.
661 The wildcard characters may be escaped with a backslash
662 .Pq Ql \e .
663 .It Cm N Ns Ar pattern
664 This is identical to
665 .Cm M ,
666 but selects all words which do not match
667 the rest of the modifier.
668 .It Cm Q
669 Quotes every shell meta-character in the variable, so that it can be passed
670 safely through recursive invocations of
671 .Nm .
672 .It Cm R
673 Replaces each word in the variable with everything but its suffix.
674 .Sm off
675 .It Cm S No \&/ Ar old_string Xo
676 .No \&/ Ar new_string
677 .No \&/ Op Cm g
678 .Xc
679 .Sm on
680 Modify the first occurrence of
681 .Ar old_string
682 in each word of the variable's value, replacing it with
683 .Ar new_string .
684 If a
685 .Ql g
686 is appended to the last slash of the pattern, all occurrences
687 in each word are replaced.
688 If
689 .Ar old_string
690 begins with a caret
691 .Pq Ql ^ ,
692 .Ar old_string
693 is anchored at the beginning of each word.
694 If
695 .Ar old_string
696 ends with a dollar sign
697 .Pq Ql \&$ ,
698 it is anchored at the end of each word.
699 Inside
700 .Ar new_string ,
701 an ampersand
702 .Pq Ql &
703 is replaced by
704 .Ar old_string .
705 Any character may be used as a delimiter for the parts of the modifier
706 string.
707 The anchoring, ampersand, and delimiter characters may be escaped with a
708 backslash
709 .Pq Ql \e .
710 .Pp
711 Variable expansion occurs in the normal fashion inside both
712 .Ar old_string
713 and
714 .Ar new_string
715 with the single exception that a backslash is used to prevent the expansion
716 of a dollar sign
717 .Pq Ql \&$ ,
718 not a preceding dollar sign as is usual.
719 .It Cm T
720 Replaces each word in the variable with its last component.
721 .It Ar old_string=new_string
722 This is the
723 .At V
724 style variable substitution.
725 It must be the last modifier specified.
726 If
727 .Ar old_string
728 or
729 .Ar new_string
730 do not contain the pattern matching character
731 .Ar %
732 then it is assumed that they are
733 anchored at the end of each word, so only suffixes or entire
734 words may be replaced.
735 Otherwise
736 .Ar %
737 is the substring of
738 .Ar old_string
739 to be replaced in
740 .Ar new_string
741 .It Cm U
742 Converts variable to upper-case letters.
743 .El
744 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
745 Directives, conditionals, and for loops reminiscent
746 of the C programming language are provided in
747 .Nm .
748 All such structures are identified by a line beginning with a single
749 dot
750 .Pq Ql \&.
751 character.
752 The following directives are supported:
753 .Bl -tag -width Ds
754 .It Ic \&.include Ar <file>
755 .It Ic \&.include Ar \*qfile\*q
756 Include the specified makefile.
757 Variables between the angle brackets
758 or double quotes are expanded to form the file name.
759 If angle brackets
760 are used, the included makefile is expected to be in the system
761 makefile directory.
762 If double quotes are used, the including
763 makefile's directory and any directories specified using the
764 .Fl I
765 option are searched before the system
766 makefile directory.
767 .It Ic \&.undef Ar variable
768 Un-define the specified global variable.
769 Only global variables may be un-defined.
770 .It Ic \&.makeenv Ar variable
771 Set the environment flag for a preexisting global variable.  The current
772 and future contents of the variable will be exported to the environment.
773 .It Ic \&.error Ar message
774 Terminate processing of the makefile immediately.
775 The filename of the
776 makefile, the line on which the error was encountered and the specified
777 message are printed to standard output and
778 .Nm
779 terminates with exit code 1.
780 Variables in the message are expanded.
781 .El
782 .Pp
783 Conditionals are used to determine which parts of the Makefile
784 to process.
785 They are used similarly to the conditionals supported
786 by the C pre-processor.
787 The following conditionals are supported:
788 .Bl -tag -width Ds
789 .It Xo
790 .Ic \&.if
791 .Oo \&! Oc Ns Ar expression
792 .Op Ar operator expression ...
793 .Xc
794 Test the value of an expression.
795 .It Xo
796 .Ic .ifdef
797 .Oo \&! Oc Ns Ar variable
798 .Op Ar operator variable ...
799 .Xc
800 Test the value of a variable.
801 .It Xo
802 .Ic .ifndef
803 .Oo \&! Oc Ns Ar variable
804 .Op Ar operator variable ...
805 .Xc
806 Test the value of a variable.
807 .It Xo
808 .Ic .ifmake
809 .Oo \&! Oc Ns Ar target
810 .Op Ar operator target ...
811 .Xc
812 Test the target being built.
813 .It Xo
814 .Ic .ifnmake
815 .Oo \&! Oc Ns Ar target
816 .Op Ar operator target ...
817 .Xc
818 Test the target being built.
819 .It Ic .else
820 Reverse the sense of the last conditional.
821 .It Xo
822 .Ic .elif
823 .Oo \&! Oc Ns Ar expression
824 .Op Ar operator expression ...
825 .Xc
826 A combination of
827 .Ql Ic .else
828 followed by
829 .Ql Ic .if .
830 .It Xo
831 .Ic .elifdef
832 .Oo \&! Oc Ns Ar variable
833 .Op Ar operator variable ...
834 .Xc
835 A combination of
836 .Ql Ic .else
837 followed by
838 .Ql Ic .ifdef .
839 .It Xo
840 .Ic .elifndef
841 .Oo \&! Oc Ns Ar variable
842 .Op Ar operator variable ...
843 .Xc
844 A combination of
845 .Ql Ic .else
846 followed by
847 .Ql Ic .ifndef .
848 .It Xo
849 .Ic .elifmake
850 .Oo \&! Oc Ns Ar target
851 .Op Ar operator target ...
852 .Xc
853 A combination of
854 .Ql Ic .else
855 followed by
856 .Ql Ic .ifmake .
857 .It Xo
858 .Ic .elifnmake
859 .Oo \&! Oc Ns Ar target
860 .Op Ar operator target ...
861 .Xc
862 A combination of
863 .Ql Ic .else
864 followed by
865 .Ql Ic .ifnmake .
866 .It Ic .endif
867 End the body of the conditional.
868 .El
869 .Pp
870 The
871 .Ar operator
872 may be any one of the following:
873 .Bl -tag -width "Cm XX"
874 .It Cm \&|\&|
875 logical OR
876 .It Cm \&&&
877 Logical
878 .Tn AND ;
879 of higher precedence than
880 .Ql Ic || .
881 .El
882 .Pp
883 As in C,
884 .Nm
885 will only evaluate a conditional as far as is necessary to determine
886 its value.
887 Parentheses may be used to change the order of evaluation.
888 The boolean operator
889 .Ql Ic !\&
890 may be used to logically negate an entire
891 conditional.
892 It is of higher precedence than
893 .Ql Ic \&&& .
894 .Pp
895 The value of
896 .Ar expression
897 may be any of the following:
898 .Bl -tag -width Ic
899 .It Ic defined
900 Takes a variable name as an argument and evaluates to true if the variable
901 has been defined.
902 .It Ic make
903 Takes a target name as an argument and evaluates to true if the target
904 was specified as part of
905 .Nm Ns 's
906 command line or was declared the default target (either implicitly or
907 explicitly, see
908 .Va .MAIN )
909 before the line containing the conditional.
910 .It Ic empty
911 Takes a variable, with possible modifiers, and evaluates to true if
912 the expansion of the variable would result in an empty string.
913 .It Ic exists
914 Takes a file name as an argument and evaluates to true if the file exists.
915 The file is searched for on the system search path (see
916 .Va .PATH ) .
917 .It Ic target
918 Takes a target name as an argument and evaluates to true if the target
919 has been defined.
920 .El
921 .Pp
922 An
923 .Ar expression
924 may also be an arithmetic or string comparison.
925 Variable expansion is
926 performed on both sides of the comparison, after which the integral
927 values are compared.
928 A value is interpreted as hexadecimal if it is
929 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
930 The standard C relational operators are all supported.
931 If after
932 variable expansion, either the left or right hand side of a
933 .Ql Ic ==
934 or
935 .Ql Ic "!="
936 operator is not an integral value, then
937 string comparison is performed between the expanded
938 variables.
939 If no relational operator is given, it is assumed that the expanded
940 variable is being compared against 0.
941 .Pp
942 When
943 .Nm
944 is evaluating one of these conditional expressions, and it encounters
945 a word it doesn't recognize, either the
946 .Dq make
947 or
948 .Dq defined
949 expression is applied to it, depending on the form of the conditional.
950 If the form is
951 .Ql Ic .ifdef
952 or
953 .Ql Ic .ifndef ,
954 the
955 .Dq defined
956 expression is applied.
957 Similarly, if the form is
958 .Ql Ic .ifmake
959 or
960 .Ql Ic .ifnmake ,
961 the
962 .Dq make
963 expression is applied.
964 .Pp
965 If the conditional evaluates to true the parsing of the makefile continues
966 as before.
967 If it evaluates to false, the following lines are skipped.
968 In both cases this continues until a
969 .Ql Ic .else
970 or
971 .Ql Ic .endif
972 is found.
973 .Pp
974 For loops are typically used to apply a set of rules to a list of files.
975 The syntax of a for loop is:
976 .Pp
977 .Bl -tag -width indent -compact
978 .It Ic .for Ar variable Ic in Ar expression
979 .It <make-rules>
980 .It Ic \&.endfor
981 .El
982 .Pp
983 After the for
984 .Ar expression
985 is evaluated, it is split into words.
986 The
987 iteration
988 .Ar variable
989 is successively set to each word, and substituted in the
990 .Ic make-rules
991 inside the body of the for loop.
992 .Sh COMMENTS
993 Comments begin with a hash
994 .Pq Ql \&#
995 character, anywhere but in a shell
996 command line, and continue to the end of the line.
997 .Sh SPECIAL SOURCES
998 .Bl -tag -width Ic
999 .It Ic .IGNORE
1000 Ignore any errors from the commands associated with this target, exactly
1001 as if they all were preceded by a dash
1002 .Pq Ql \- .
1003 .It Ic .MAKE
1004 Execute the commands associated with this target even if the
1005 .Fl n
1006 or
1007 .Fl t
1008 options were specified.
1009 Normally used to mark recursive
1010 .Nm Ns 's .
1011 .It Ic .NOTMAIN
1012 Normally
1013 .Nm
1014 selects the first target it encounters as the default target to be built
1015 if no target was specified.
1016 This source prevents this target from being selected.
1017 .It Ic .OPTIONAL
1018 If a target is marked with this attribute and
1019 .Nm
1020 can't figure out how to create it, it will ignore this fact and assume
1021 the file isn't needed or already exists.
1022 .It Ic .PRECIOUS
1023 When
1024 .Nm
1025 is interrupted, it removes any partially made targets.
1026 This source prevents the target from being removed.
1027 .It Ic .SILENT
1028 Do not echo any of the commands associated with this target, exactly
1029 as if they all were preceded by an at sign
1030 .Pq Ql @ .
1031 .It Ic .USE
1032 Turn the target into
1033 .Nm Ns 's
1034 version of a macro.
1035 When the target is used as a source for another target, the other target
1036 acquires the commands, sources, and attributes (except for
1037 .Ic .USE )
1038 of the
1039 source.
1040 If the target already has commands, the
1041 .Ic .USE
1042 target's commands are appended
1043 to them.
1044 .It Ic .WAIT
1045 If special
1046 .Ic .WAIT
1047 source is appears in a dependency line, the sources that precede it are
1048 made before the sources that succeed it in the line.
1049 Loops are not being
1050 detected and targets that form loops will be silently ignored.
1051 .El
1052 .Sh "SPECIAL TARGETS"
1053 Special targets may not be included with other targets, i.e. they must be
1054 the only target specified.
1055 .Bl -tag -width Ic
1056 .It Ic .BEGIN
1057 Any command lines attached to this target are executed before anything
1058 else is done.
1059 .It Ic .DEFAULT
1060 This is sort of a
1061 .Ic .USE
1062 rule for any target (that was used only as a
1063 source) that
1064 .Nm
1065 can't figure out any other way to create.
1066 Only the shell script is used.
1067 The
1068 .Ic .IMPSRC
1069 variable of a target that inherits
1070 .Ic .DEFAULT Ns 's
1071 commands is set
1072 to the target's own name.
1073 .It Ic .END
1074 Any command lines attached to this target are executed after everything
1075 else is done.
1076 .It Ic .IGNORE
1077 Mark each of the sources with the
1078 .Ic .IGNORE
1079 attribute.
1080 If no sources are specified, this is the equivalent of specifying the
1081 .Fl i
1082 option.
1083 .It Ic .INCLUDES
1084 A list of suffixes that indicate files that can be included in a source
1085 file.
1086 The suffix must have already been declared with
1087 .Ic .SUFFIXES ;
1088 any suffix so declared will have the directories on its search path (see
1089 .Ic .PATH )
1090 placed in the
1091 .Va .INCLUDES
1092 special variable, each preceded by a
1093 .Fl I
1094 flag.
1095 .It Ic .INTERRUPT
1096 If
1097 .Nm
1098 is interrupted, the commands for this target will be executed.
1099 .It Ic .LIBS
1100 This does for libraries what
1101 .Ic .INCLUDES
1102 does for include files, except that the flag used is
1103 .Fl L .
1104 .It Ic .MAIN
1105 If no target is specified when
1106 .Nm
1107 is invoked, this target will be built.
1108 This is always set, either
1109 explicitly, or implicitly when
1110 .Nm
1111 selects the default target, to give the user a way to refer to the default
1112 target on the command line.
1113 .It Ic .MAKEFLAGS
1114 This target provides a way to specify flags for
1115 .Nm
1116 when the makefile is used.
1117 The flags are as if typed to the shell, though the
1118 .Fl f
1119 option will have
1120 no effect.
1121 .\" XXX: NOT YET!!!!
1122 .\" .It Ic .NOTPARALLEL
1123 .\" The named targets are executed in non parallel mode. If no targets are
1124 .\" specified, then all targets are executed in non parallel mode.
1125 .It Ic .NOTPARALLEL
1126 Disable parallel mode.
1127 .It Ic .NO_PARALLEL
1128 Same as above, for compatibility with other pmake variants.
1129 .It Ic .ORDER
1130 The named targets are made in sequence.
1131 .\" XXX: NOT YET!!!!
1132 .\" .It Ic .PARALLEL
1133 .\" The named targets are executed in parallel mode. If no targets are
1134 .\" specified, then all targets are executed in parallel mode.
1135 .It Ic .PATH
1136 The sources are directories which are to be searched for files not
1137 found in the current directory.
1138 If no sources are specified, any previously specified directories are
1139 deleted.
1140 Where possible, use of
1141 .Ic .PATH
1142 is preferred over use of the
1143 .Va VPATH
1144 variable.
1145 .It Ic .PATH\fIsuffix\fR
1146 The sources are directories which are to be searched for suffixed files
1147 not found in the current directory.
1148 The
1149 .Nm
1150 utility
1151 first searches the suffixed search path, before reverting to the default
1152 path if the file is not found there.
1153 This form is required for
1154 .Ic .LIBS
1155 and
1156 .Ic .INCLUDES
1157 to work.
1158 .It Ic .PHONY
1159 Apply the
1160 .Ic .PHONY
1161 attribute to any specified sources.
1162 Targets with this attribute are always
1163 considered to be out of date.
1164 .It Ic .PRECIOUS
1165 Apply the
1166 .Ic .PRECIOUS
1167 attribute to any specified sources.
1168 If no sources are specified, the
1169 .Ic .PRECIOUS
1170 attribute is applied to every
1171 target in the file.
1172 .It Ic .SILENT
1173 Apply the
1174 .Ic .SILENT
1175 attribute to any specified sources.
1176 If no sources are specified, the
1177 .Ic .SILENT
1178 attribute is applied to every
1179 command in the file.
1180 .It Ic .SUFFIXES
1181 Each source specifies a suffix to
1182 .Nm .
1183 If no sources are specified, any previous specified suffices are deleted.
1184 .El
1185 .Sh COMPATIBILITY
1186 Older versions of
1187 .Nm
1188 used
1189 .Ev MAKE
1190 instead of
1191 .Ev MAKEFLAGS .
1192 This was removed for POSIX compatibility.
1193 The internal variable
1194 .Va MAKE
1195 is set to the same value as
1196 .Va .MAKE ;
1197 support for this may be removed in the future.
1198 .Pp
1199 Most of the more esoteric features of
1200 .Nm
1201 should probably be avoided for greater compatibility.
1202 .Sh ENVIRONMENT
1203 The
1204 .Nm
1205 utility uses the following environment variables, if they exist:
1206 .Ev MACHINE ,
1207 .Ev MAKE ,
1208 .Ev MAKEFLAGS ,
1209 .Ev MAKEOBJDIR ,
1210 .Ev MAKEOBJDIRPREFIX ,
1211 and
1212 .Ev PWD .
1213 .Sh FILES
1214 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1215 .It Pa .depend
1216 list of dependencies
1217 .It Pa Makefile
1218 list of dependencies
1219 .It Pa makefile
1220 list of dependencies
1221 .It obj
1222 object directory
1223 .It Pa sys.mk
1224 system makefile (processed before any other file, including
1225 .Pa makefile
1226 and
1227 .Pa Makefile )
1228 .It Pa /usr/share/mk
1229 system makefile directory
1230 .It /usr/share/doc/psd/12.make
1231 PMake tutorial
1232 .It Pa /usr/obj
1233 default
1234 .Ev MAKEOBJDIRPREFIX
1235 directory.
1236 .El
1237 .Sh BUGS
1238 The determination of
1239 .Va .OBJDIR
1240 is contorted to the point of absurdity.
1241 .Pp
1242 In the presence of several
1243 .Ic .MAIN
1244 special targets,
1245 .Nm
1246 silently ignores all but the first.
1247 .Pp
1248 .Va .TARGETS
1249 is not set to the default target when
1250 .Nm
1251 is invoked without a target name and no
1252 .Ic .MAIN
1253 special target exists.
1254 .Pp
1255 The evaluation of
1256 .Ar expression
1257 in a test is very simple-minded.
1258 Currently, the only form that works is
1259 .Ql .if ${VAR} op something
1260 For instance, you should write tests as
1261 .Ql .if ${VAR} = "string"
1262 not the other way around, which doesn't work.
1263 .Pp
1264 For loops are expanded before tests, so a fragment such as:
1265 .Bd -literal
1266 \&.for TMACHINE in ${SHARED_ARCHS}
1267 \&.if ${TMACHINE} = ${MACHINE}
1268      ...
1269 \&.endif
1270 \&.endfor
1271 .Ed
1272 won't work, and should be rewritten the other way around.
1273 .Sh SEE ALSO
1274 .Xr mkdep 1 ,
1275 .Xr make.conf 5
1276 .Rs
1277 .%T "PMake - A Tutorial"
1278 .Re
1279 in
1280 .Pa /usr/share/doc/psd/12.make
1281 .Sh HISTORY
1282 A
1283 .Nm
1284 command appeared in
1285 .At v7 .