]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.bin/make/make.1
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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 .\"     @(#)make.1      8.8 (Berkeley) 6/13/95
33 .\" $FreeBSD$
34 .\"
35 .Dd May 30, 2012
36 .Dt MAKE 1
37 .Os
38 .Sh NAME
39 .Nm make
40 .Nd maintain program dependencies
41 .Sh SYNOPSIS
42 .Nm
43 .Op Fl ABPSXeiknpqrstv
44 .Op Fl C Ar directory
45 .Op Fl D Ar variable
46 .Op Fl d Ar flags
47 .Op Fl E Ar variable
48 .Op Fl f Ar makefile
49 .Op Fl I Ar directory
50 .Bk -words
51 .Op Fl j Ar max_jobs
52 .Op Fl m Ar directory
53 .Ek
54 .Op Fl V Ar variable
55 .Op Fl x Ar warning_options
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 .Pp
66 First of all, the initial list of specifications will be read
67 from the system makefile,
68 .Pa sys.mk ,
69 unless inhibited with the
70 .Fl r
71 option.
72 The standard
73 .Pa sys.mk
74 as shipped with
75 .Fx
76 also handles
77 .Xr make.conf 5 ,
78 the default path to which
79 can be altered via the
80 .Nm
81 variable
82 .Va __MAKE_CONF .
83 .Pp
84 Then the first of
85 .Pa BSDmakefile ,
86 .Pa makefile ,
87 and
88 .Pa Makefile
89 that can be found in the current directory, object directory (see
90 .Va .OBJDIR ) ,
91 or search path (see the
92 .Fl I
93 option)
94 will be read for the main list of dependency specifications.
95 A different makefile or list of them can be supplied via the
96 .Fl f
97 option(s).
98 Finally, if the file
99 .Pa .depend
100 can be found in any of the aforesaid locations, it will also be read (see
101 .Xr mkdep 1 ) .
102 .Pp
103 When
104 .Nm
105 searches for a makefile, its name takes precedence over its location.
106 For instance,
107 .Pa BSDmakefile
108 in the object directory will be favored over
109 .Pa Makefile
110 in the current directory.
111 .Pp
112 The options are as follows:
113 .Bl -tag -width Ds
114 .It Fl A
115 Make archive errors non-fatal, causing
116 .Nm
117 to just skip the remainder
118 or all of the archive and continue after printing a message.
119 .It Fl B
120 Try to be backwards compatible by executing a single shell per command and
121 by executing the commands to make the sources of a dependency line in sequence.
122 This is turned on by default unless
123 .Fl j
124 is used.
125 .It Fl C Ar directory
126 Change to
127 .Ar directory
128 before reading the makefiles or doing anything else.
129 If multiple
130 .Fl C
131 options are specified, each is interpreted relative to the previous one:
132 .Fl C Pa / Fl C Pa etc
133 is equivalent to
134 .Fl C Pa /etc .
135 .It Fl D Ar variable
136 Define
137 .Ar variable
138 to be 1, in the global context.
139 .It Fl d Ar flags
140 Turn on debugging, and specify which portions of
141 .Nm
142 are to print debugging information.
143 Argument
144 .Ar flags
145 is one or more of the following:
146 .Bl -tag -width Ds
147 .It Ar A
148 Print all possible debugging information;
149 equivalent to specifying all of the debugging flags.
150 .It Ar a
151 Print debugging information about archive searching and caching.
152 .It Ar c
153 Print debugging information about conditional evaluation.
154 .It Ar d
155 Print debugging information about directory searching and caching.
156 .It Ar f
157 Print debugging information about the execution of for loops.
158 .It Ar "g1"
159 Print the input graph before making anything.
160 .It Ar "g2"
161 Print the input graph after making everything, or before exiting
162 on error.
163 .It Ar j
164 Print debugging information about running multiple shells.
165 .It Ar l
166 Print commands in Makefiles regardless of whether or not they are prefixed
167 by @ or other "quiet" flags.
168 Also known as "loud" behavior.
169 .It Ar m
170 Print debugging information about making targets, including modification
171 dates.
172 .It Ar s
173 Print debugging information about suffix-transformation rules.
174 .It Ar t
175 Print debugging information about target list maintenance.
176 .It Ar v
177 Print debugging information about variable assignment.
178 .El
179 .It Fl E Ar variable
180 Specify a variable whose environment value (if any) will override
181 macro assignments within makefiles.
182 .It Fl e
183 Specify that environment values override macro assignments within
184 makefiles for all variables.
185 .It Fl f Ar makefile
186 Specify a makefile to read instead of the default one.
187 If
188 .Ar makefile
189 is not an absolute pathname,
190 .Nm
191 will search for it as described above.
192 In case
193 .Ar makefile
194 is
195 .Sq Fl ,
196 standard input is read.
197 Multiple
198 .Fl f
199 options can be supplied,
200 and the makefiles will be read in that order.
201 Unlike the other command-line options,
202 .Fl f
203 is neither stored in
204 .Va .MAKEFLAGS
205 nor pushed down to sub-makes via
206 .Ev MAKEFLAGS .
207 See below for more details on these variables.
208 .It Fl I Ar directory
209 Specify a directory in which to search for makefiles and included makefiles.
210 Multiple
211 .Fl I
212 options can be specified to form a search path.
213 The system makefile directory (or directories, see the
214 .Fl m
215 option) is automatically appended at the tail of this path.
216 .It Fl i
217 Ignore non-zero exit of shell commands in the makefile.
218 Equivalent to specifying
219 .Sq Ic \-
220 before each command line in the makefile.
221 .It Fl j Ar max_jobs
222 Specify the maximum number of jobs that
223 .Nm
224 may have running at any one time.
225 Turns compatibility mode off, unless the
226 .Fl B
227 flag is also specified.
228 .It Fl k
229 Continue processing after errors are encountered, but only on those targets
230 that do not depend on the target whose creation caused the error.
231 .It Fl m Ar directory
232 Specify a directory in which to search for
233 the system makefile and makefiles included via the <...> style.
234 Multiple
235 .Fl m
236 options can be specified to form a search path.
237 This path will override the default system include path,
238 .Pa /usr/share/mk .
239 The system include path will always be appended to the search path used
240 for "..."-style inclusions and makefile searches (see the
241 .Fl I
242 option).
243 .Pp
244 If a file or directory name in the
245 .Fl m
246 argument (or the
247 .Ev MAKESYSPATH
248 environment variable) starts with the string
249 .Qq \&.../
250 then
251 .Nm
252 will search for the specified file or directory named in the remaining part
253 of the argument string.
254 The search starts with the current directory of the Makefile and then works
255 upward towards the root of the filesystem.
256 If the search is successful,
257 then the resulting directory replaces the
258 .Qq \&.../
259 specification in the
260 .Fl m
261 argument.
262 If used, this feature allows
263 .Nm
264 to easily search in the current source tree for customized sys.mk files
265 (e.g. by using
266 .Qq \&.../mk/sys.mk
267 as an argument).
268 Note that a
269 .Fl C
270 that are earlier on the command line affect where
271 .Fl m Qq \&.../
272 searches.
273 .It Fl n
274 Display the commands that would have been executed, but do not actually
275 execute them.
276 .It Fl P
277 Collate the output of a given job and display it only when the job finishes,
278 instead of mixing the output of parallel jobs together.
279 This option has no effect unless
280 .Fl j
281 is used too.
282 .It Fl p
283 Only print the input graph, not executing any commands.
284 The output is the same as
285 .Fl d Ar g1 .
286 When combined with
287 .Fl f Pa /dev/null ,
288 only the builtin rules of
289 .Nm
290 are displayed.
291 .It Fl Q
292 Be extra quiet.
293 For multi-job makes, this will cause file banners not to be generated.
294 .It Fl q
295 Do not execute any commands, but exit 0 if the specified targets are
296 up-to-date and 1, otherwise.
297 .It Fl r
298 Do not process the system makefile.
299 .It Fl S
300 Stop processing when an error is encountered.
301 Default behaviour.
302 This is needed to negate the
303 .Fl k
304 option during recursive builds.
305 .It Fl s
306 Do not echo any commands as they are executed.
307 Equivalent to specifying
308 .Sq Ic @
309 before each command line in the makefile.
310 .It Fl t
311 Rather than re-building a target as specified in the makefile, create it
312 or update its modification time to make it appear up-to-date.
313 .It Fl V Ar variable
314 Print
315 .Nm Ns 's
316 idea of the value of
317 .Ar variable ,
318 in the global context.
319 Do not build any targets.
320 Multiple instances of this option may be specified;
321 the variables will be printed one per line,
322 with a blank line for each null or undefined variable.
323 If
324 .Ar variable
325 contains a
326 .Sq Ic $
327 then the value will be expanded before printing.
328 .It Fl v
329 Be extra verbose.
330 Print any extra information.
331 .It Fl X
332 When using the
333 .Fl V
334 option to print the values of variables,
335 do not recursively expand the values.
336 .It Ar variable Ns No = Ns Ar value
337 Set the value of the variable
338 .Ar variable
339 to
340 .Ar value .
341 .It Fl x Ar warning_options
342 Specify extended warning options.
343 This option may be specified several times.
344 A
345 .Ar warning_option
346 can be prefixed with
347 .Dq Li no
348 in which case the warning is switched off.
349 The currently available options are:
350 .Bl -tag -width indent
351 .It Li dirsyntax
352 Warn if anything except blanks and comments follows an
353 .Ic .endif
354 or
355 .Ic .else
356 directive.
357 .El
358 .Pp
359 See also the
360 .Ic .WARN
361 special target.
362 .El
363 .Pp
364 There are seven different types of lines in a makefile: file dependency
365 specifications, shell commands, variable assignments, include statements,
366 conditional directives, for loops, and comments.
367 .Pp
368 In general, lines may be continued from one line to the next by ending
369 them with a backslash
370 .Pq Ql \e .
371 The trailing newline character and initial whitespace on the following
372 line are compressed into a single space.
373 .Sh FILE DEPENDENCY SPECIFICATIONS
374 Dependency lines consist of one or more targets, an operator, and zero
375 or more sources.
376 This creates a relationship where the targets
377 .Dq depend
378 on the sources
379 and are usually created from them.
380 The exact relationship between the target and the source is determined
381 by the operator that separates them.
382 The three operators are as follows:
383 .Bl -tag -width flag
384 .It Ic \&:
385 A target is considered out-of-date if its modification time is less than
386 those of any of its sources.
387 Sources for a target accumulate over dependency lines when this operator
388 is used.
389 The target is removed if
390 .Nm
391 is interrupted.
392 .It Ic \&!
393 Targets are always re-created, but not until all sources have been
394 examined and re-created as necessary.
395 Sources for a target accumulate over dependency lines when this operator
396 is used.
397 The target is removed if
398 .Nm
399 is interrupted.
400 .It Ic ::
401 If no sources are specified, the target is always re-created.
402 Otherwise, a target is considered out-of-date if any of its sources has
403 been modified more recently than the target.
404 Sources for a target do not accumulate over dependency lines when this
405 operator is used.
406 The target will not be removed if
407 .Nm
408 is interrupted.
409 .El
410 .Pp
411 Targets and sources may contain the shell wildcard expressions
412 .Ql \&? ,
413 .Ql * ,
414 .Ql []
415 and
416 .Ql {} .
417 The expressions
418 .Ql \&? ,
419 .Ql *
420 and
421 .Ql []
422 may only be used as part of the final
423 component of the target or source, and must be used to describe existing
424 files.
425 The expression
426 .Ql {}
427 need not necessarily be used to describe existing files.
428 Expansion is in directory order, not alphabetically as done in the shell.
429 .Sh SHELL COMMANDS
430 Each target may have associated with it a series of shell commands, normally
431 used to create the target.
432 Each of the commands in this script
433 .Em must
434 be preceded by a tab.
435 While any target may appear on a dependency line, only one of these
436 dependencies may be followed by a creation script, unless the
437 .Sq Ic ::
438 operator is used.
439 .Pp
440 If the first characters of the command line are
441 .Sq Ic @ ,
442 .Sq Ic \- ,
443 and/or
444 .Sq Ic + ,
445 the command is treated specially.
446 A
447 .Sq Ic @
448 causes the command not to be echoed before it is executed.
449 A
450 .Sq Ic \-
451 causes any non-zero exit status of the command line to be ignored.
452 A
453 .Sq Ic +
454 causes the command to be executed even if
455 .Fl n
456 is specified on the command line.
457 .Sh VARIABLE ASSIGNMENTS
458 Variables in
459 .Nm
460 are much like variables in the shell, and, by tradition,
461 consist of all upper-case letters.
462 The five operators that can be used to assign values to variables are as
463 follows:
464 .Bl -tag -width Ds
465 .It Ic =
466 Assign the value to the variable.
467 Any previous value is overridden.
468 .It Ic +=
469 Append the value to the current value of the variable.
470 .It Ic ?=
471 Assign the value to the variable if it is not already defined.
472 .It Ic :=
473 Assign with expansion, i.e., expand the value before assigning it
474 to the variable.
475 Normally, expansion is not done until the variable is referenced.
476 .It Ic !=
477 Expand the value and pass it to the shell for execution and assign
478 the result to the variable.
479 Any newlines in the result are replaced with spaces.
480 .El
481 .Pp
482 Any whitespace before the assigned
483 .Ar value
484 is removed; if the value is being appended, a single space is inserted
485 between the previous contents of the variable and the appended value.
486 .Pp
487 Variables are expanded by surrounding the variable name with either
488 curly braces
489 .Pq Ql {}
490 or parentheses
491 .Pq Ql ()
492 and preceding it with
493 a dollar sign
494 .Pq Ql $ .
495 If the variable name contains only a single letter, the surrounding
496 braces or parentheses are not required.
497 This shorter form is not recommended.
498 .Pp
499 Variable substitution occurs at two distinct times, depending on where
500 the variable is being used.
501 Variables in dependency lines are expanded as the line is read.
502 Variables in shell commands are expanded when the shell command is
503 executed.
504 .Pp
505 The four different classes of variables (in order of increasing precedence)
506 are:
507 .Bl -tag -width Ds
508 .It Environment variables
509 Variables defined as part of
510 .Nm Ns 's
511 environment.
512 .It Global variables
513 Variables defined in the makefile or in included makefiles.
514 .It Command line variables
515 Variables defined as part of the command line and variables
516 obtained from the
517 .Ev MAKEFLAGS
518 environment variable or the
519 .Ic .MAKEFLAGS
520 target.
521 .It Local variables
522 Variables that are defined specific to a certain target.
523 .El
524 .Pp
525 If the name of an environment variable appears in a makefile
526 on the left-hand side of an assignment,
527 a global variable with the same name is created, and the latter
528 shadows the former as per their relative precedences.
529 The environment is not changed in this case, and the change
530 is not exported to programs executed by
531 .Nm .
532 However, a command-line variable actually replaces
533 the environment variable of the same name if the latter exists,
534 which is visible to child programs.
535 .Pp
536 There are seven local variables in
537 .Nm :
538 .Bl -tag -width ".ARCHIVE"
539 .It Va .ALLSRC
540 The list of all sources for this target; also known as
541 .Sq Va > .
542 .It Va .ARCHIVE
543 The name of the archive file; also known as
544 .Sq Va \&! .
545 .It Va .IMPSRC
546 The name/path of the source from which the target is to be transformed
547 (the
548 .Dq implied
549 source); also known as
550 .Sq Va < .
551 .It Va .MEMBER
552 The name of the archive member; also known as
553 .Sq Va % .
554 .It Va .OODATE
555 The list of sources for this target that were deemed out-of-date; also
556 known as
557 .Sq Va \&? .
558 .It Va .PREFIX
559 The file prefix of the file, containing only the file portion, no suffix
560 or preceding directory components; also known as
561 .Sq Va * .
562 .It Va .TARGET
563 The name of the target; also known as
564 .Sq Va @ .
565 .El
566 .Pp
567 The shorter forms
568 .Sq Va @ ,
569 .Sq Va \&! ,
570 .Sq Va < ,
571 .Sq Va % ,
572 .Sq Va \&? ,
573 .Sq Va > ,
574 and
575 .Sq Va *
576 are permitted for backward
577 compatibility and are not recommended.
578 The six variables
579 .Sq Va @F ,
580 .Sq Va @D ,
581 .Sq Va <F ,
582 .Sq Va <D ,
583 .Sq Va *F ,
584 and
585 .Sq Va *D
586 are
587 permitted for compatibility with
588 .At V
589 makefiles and are not recommended.
590 .Pp
591 Four of the local variables may be used in sources on dependency lines
592 because they expand to the proper value for each target on the line.
593 These variables are
594 .Va .TARGET ,
595 .Va .PREFIX ,
596 .Va .ARCHIVE ,
597 and
598 .Va .MEMBER .
599 .Pp
600 In addition,
601 .Nm
602 sets or knows about the following internal variables or environment
603 variables:
604 .Bl -tag -width ".Va .MAKEFILE_LIST"
605 .It Va $
606 A single dollar sign
607 .Ql $ ,
608 i.e.\&
609 .Ql $$
610 expands to a single dollar
611 sign.
612 .It Va MAKE
613 The name that
614 .Nm
615 was executed with
616 .Pq Va argv Ns Op 0 .
617 .It Va .CURDIR
618 A path to the directory where
619 .Nm
620 was executed.
621 The
622 .Nm
623 utility sets
624 .Va .CURDIR
625 to the canonical path given by
626 .Xr getcwd 3 .
627 .It Va .OBJDIR
628 A path to the directory where the targets are built.
629 At startup,
630 .Nm
631 searches for an alternate directory to place target files.
632 It will attempt to change into this special directory
633 and will search this directory for makefiles
634 not found in the current directory.
635 The following directories are tried in order:
636 .Pp
637 .Bl -enum -compact
638 .It
639 ${MAKEOBJDIRPREFIX}/`pwd -P`
640 .It
641 ${MAKEOBJDIR}
642 .It
643 obj.${MACHINE}
644 .It
645 obj
646 .It
647 /usr/obj/`pwd -P`
648 .El
649 .Pp
650 The first directory that
651 .Nm
652 successfully changes into is used.
653 If either
654 .Ev MAKEOBJDIRPREFIX
655 or
656 .Ev MAKEOBJDIR
657 is set in the environment but
658 .Nm
659 is unable to change into the corresponding directory,
660 then the current directory is used
661 without checking the remainder of the list.
662 If they are undefined and
663 .Nm
664 is unable to change into any of the remaining three directories,
665 then the current directory is used.
666 Note, that
667 .Ev MAKEOBJDIRPREFIX
668 and
669 .Ev MAKEOBJDIR
670 must be environment variables and should not be set on
671 .Nm Ns 's
672 command line.
673 .Pp
674 The
675 .Nm
676 utility sets
677 .Va .OBJDIR
678 to the canonical path given by
679 .Xr getcwd 3 .
680 .It Va .MAKEFILE_LIST
681 As
682 .Nm
683 reads various makefiles, including the default files and any
684 obtained from the command line and
685 .Ic .include
686 and
687 .Ic .sinclude
688 directives, their names will be automatically appended to the
689 .Va .MAKEFILE_LIST
690 variable.
691 They are added right before
692 .Nm
693 begins to parse them, so that the name of the current makefile is the
694 last word in this variable.
695 .It Ev MAKEFLAGS
696 The environment variable
697 .Ev MAKEFLAGS
698 may initially contain anything that
699 may be specified on
700 .Nm Ns 's
701 command line,
702 including
703 .Fl f
704 option(s).
705 After processing, its contents are stored in the
706 .Va .MAKEFLAGS
707 global variable, although any
708 .Fl f
709 options are omitted.
710 Then all options and variable assignments specified on
711 .Nm Ns 's
712 command line, except for
713 .Fl f ,
714 are appended to the
715 .Va .MAKEFLAGS
716 variable.
717 .Pp
718 Whenever
719 .Nm
720 executes a program, it sets
721 .Ev MAKEFLAGS
722 in the program's environment to the current value of the
723 .Va .MAKEFLAGS
724 global variable.
725 Thus, if
726 .Ev MAKEFLAGS
727 in
728 .Nm Ns 's
729 environment contains any
730 .Fl f
731 options, they will not be pushed down to child programs automatically.
732 The
733 .Nm
734 utility effectively filters out
735 .Fl f
736 options from the environment and command line although it
737 passes the rest of its options down to sub-makes via
738 .Ev MAKEFLAGS
739 by default.
740 .Pp
741 When passing macro definitions and flag arguments in the
742 .Ev MAKEFLAGS
743 environment variable,
744 space and tab characters are quoted by preceding them with a backslash.
745 When reading the
746 .Ev MAKEFLAGS
747 variable from the environment,
748 all sequences of a backslash and one of space or tab
749 are replaced just with their second character
750 without causing a word break.
751 Any other occurrences of a backslash are retained.
752 Groups of unquoted space, tab and newline characters cause word
753 breaking.
754 .It Va .MAKEFLAGS
755 Initially, this global variable contains
756 .Nm Ns 's
757 current run-time options from the environment
758 and command line as described above, under
759 .Ev MAKEFLAGS .
760 By modifying the contents of the
761 .Va .MAKEFLAGS
762 global variable, the makefile can alter the contents of the
763 .Ev MAKEFLAGS
764 environment variable made available for all programs which
765 .Nm
766 executes.
767 This includes adding
768 .Fl f
769 option(s).
770 The current value of
771 .Va .MAKEFLAGS
772 is just copied verbatim to
773 .Ev MAKEFLAGS
774 in the environment of child programs.
775 .Pp
776 Note that any options entered to
777 .Va .MAKEFLAGS
778 neither affect the current instance of
779 .Nm
780 nor show up in its own copy of
781 .Ev MAKEFLAGS
782 instantly.
783 However, they do show up in the
784 .Ev MAKEFLAGS
785 environment variable of programs executed by
786 .Nm .
787 On the other hand, a direct assignment to
788 .Ev MAKEFLAGS
789 neither affects the current instance of
790 .Nm
791 nor is passed down to
792 .Nm Ns 's
793 children.
794 Compare with the
795 .Ic .MAKEFLAGS
796 special target below.
797 .It Va MFLAGS
798 This variable is provided for backward compatibility and
799 contains all the options from the
800 .Ev MAKEFLAGS
801 environment variable plus any options specified on
802 .Nm Ns 's
803 command line.
804 .It Va .MAKE.PID
805 The process-id of
806 .Nm .
807 .It Va .MAKE.PPID
808 The parent process-id of
809 .Nm .
810 .It Va .MAKE.JOB.PREFIX
811 If
812 .Nm
813 is run with
814 .Fl j Fl v
815 then output for each target is prefixed with a token
816 .Ql --- target ---
817 the first part of which can be controlled via
818 .Va .MAKE.JOB.PREFIX .
819 .br
820 For example:
821 .Li .MAKE.JOB.PREFIX=${.newline}---${MAKE:T}[${.MAKE.PID}]
822 would produce tokens like
823 .Ql ---make[1234] target ---
824 or
825 .Li .MAKE.JOB.PREFIX=---pid[${.MAKE.PID}],ppid[${.MAKE.PPID}]
826 would produce tokens like
827 .Ql ---pid[56789],ppid[1234] target ---
828 making it easier to track the degree of parallelism being achieved.
829 .It Va .TARGETS
830 List of targets
831 .Nm
832 is currently building.
833 .It Va .INCLUDES
834 See
835 .Ic .INCLUDES
836 special target.
837 .It Va .LIBS
838 See
839 .Ic .LIBS
840 special target.
841 .It Va MACHINE
842 Name of the machine architecture
843 .Nm
844 is running on, obtained from the
845 .Ev MACHINE
846 environment variable, or through
847 .Xr uname 3
848 if not defined.
849 .It Va MACHINE_ARCH
850 Name of the machine architecture
851 .Nm
852 was compiled for, defined at compilation time.
853 .It Va VPATH
854 Makefiles may assign a colon-delimited list of directories to
855 .Va VPATH .
856 These directories will be searched for source files by
857 .Nm
858 after it has finished parsing all input makefiles.
859 .El
860 .Ss Variable Modifiers
861 Variable expansion may be modified to select or modify each word of the
862 variable (where a
863 .Dq word
864 is whitespace-delimited sequence of characters).
865 The general format of a variable expansion is as follows:
866 .Pp
867 .Dl {variable[:modifier[:...]]}
868 .Pp
869 Each modifier begins with a colon and one of the following
870 special characters.
871 The colon may be escaped with a backslash
872 .Pq Ql \e .
873 .Bl -tag -width Cm
874 .Sm off
875 .It Cm :C No / Ar pattern Xo
876 .No / Ar replacement
877 .No / Op Cm 1g
878 .Xc
879 .Sm on
880 Modify each word of the value,
881 substituting every match of the extended regular expression
882 .Ar pattern
883 (see
884 .Xr re_format 7 )
885 with the
886 .Xr ed 1 Ns \-style
887 .Ar replacement
888 string.
889 Normally, the first occurrence of the pattern in
890 each word of the value is changed.
891 The
892 .Ql 1
893 modifier causes the substitution to apply to at most one word; the
894 .Ql g
895 modifier causes the substitution to apply to as many instances of the
896 search pattern as occur in the word or words it is found in.
897 Note that
898 .Ql 1
899 and
900 .Ql g
901 are orthogonal; the former specifies whether multiple words are
902 potentially affected, the latter whether multiple substitutions can
903 potentially occur within each affected word.
904 .It Cm :E
905 Replaces each word in the variable with its suffix.
906 .It Cm :H
907 Replaces each word in the variable with everything but the last component.
908 .It Cm :L
909 Converts variable to lower-case letters.
910 (deprecated)
911 .It Cm :M Ns Ar pattern
912 Select only those words that match the rest of the modifier.
913 The standard shell wildcard characters
914 .Pf ( Ql * ,
915 .Ql \&? ,
916 and
917 .Ql [] )
918 may
919 be used.
920 The wildcard characters may be escaped with a backslash
921 .Pq Ql \e .
922 .It Cm :N Ns Ar pattern
923 This is identical to
924 .Cm :M ,
925 but selects all words which do not match
926 the rest of the modifier.
927 .It Cm :O
928 Order every word in the variable alphabetically.
929 .It Cm :Q
930 Quotes every shell meta-character in the variable, so that it can be passed
931 safely through recursive invocations of
932 .Nm .
933 .It Cm :R
934 Replaces each word in the variable with everything but its suffix.
935 .Sm off
936 .It Cm :S No / Ar old_string Xo
937 .No / Ar new_string
938 .No / Op Cm g
939 .Xc
940 .Sm on
941 Modify the first occurrence of
942 .Ar old_string
943 in each word of the variable's value, replacing it with
944 .Ar new_string .
945 If a
946 .Ql g
947 is appended to the last slash of the pattern, all occurrences
948 in each word are replaced.
949 If
950 .Ar old_string
951 begins with a caret
952 .Pq Ql ^ ,
953 .Ar old_string
954 is anchored at the beginning of each word.
955 If
956 .Ar old_string
957 ends with a dollar sign
958 .Pq Ql $ ,
959 it is anchored at the end of each word.
960 Inside
961 .Ar new_string ,
962 an ampersand
963 .Pq Ql &
964 is replaced by
965 .Ar old_string .
966 Any character may be used as a delimiter for the parts of the modifier
967 string.
968 The anchoring, ampersand, and delimiter characters may be escaped with a
969 backslash
970 .Pq Ql \e .
971 .Pp
972 Variable expansion occurs in the normal fashion inside both
973 .Ar old_string
974 and
975 .Ar new_string
976 with the single exception that a backslash is used to prevent the expansion
977 of a dollar sign
978 .Pq Ql $ ,
979 not a preceding dollar sign as is usual.
980 .It Ar :old_string=new_string
981 This is the
982 .At V
983 style variable substitution.
984 It must be the last modifier specified.
985 If
986 .Ar old_string
987 or
988 .Ar new_string
989 do not contain the pattern matching character
990 .Ar %
991 then it is assumed that they are
992 anchored at the end of each word, so only suffixes or entire
993 words may be replaced.
994 Otherwise
995 .Ar %
996 is the substring of
997 .Ar old_string
998 to be replaced in
999 .Ar new_string .
1000 .It Cm :T
1001 Replaces each word in the variable with its last component.
1002 .It Cm :tl
1003 Converts variable to lower-case letters.
1004 .It Cm :tu
1005 Converts variable to upper-case letters.
1006 .It Cm :U
1007 Converts variable to upper-case letters.
1008 (deprecated)
1009 .It Cm :u
1010 Remove adjacent duplicate words (like
1011 .Xr uniq 1 ) .
1012 .El
1013 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
1014 Directives, conditionals, and for loops reminiscent
1015 of the C programming language are provided in
1016 .Nm .
1017 All such structures are identified by a line beginning with a single
1018 dot
1019 .Pq Ql \&.
1020 character.
1021 The following directives are supported:
1022 .Bl -tag -width Ds
1023 .It Ic .include Ar <file>
1024 .It Ic .include Ar \*qfile\*q
1025 Include the specified makefile.
1026 Variables between the angle brackets
1027 or double quotes are expanded to form the file name.
1028 If angle brackets
1029 are used, the included makefile is expected to be in the system
1030 makefile directory.
1031 If double quotes are used, the including
1032 makefile's directory and any directories specified using the
1033 .Fl I
1034 option are searched before the system
1035 makefile directory.
1036 .It Ic .sinclude Ar <file>
1037 .It Ic .sinclude Ar \*qfile\*q
1038 Like
1039 .Ic .include ,
1040 but silently ignored if the file cannot be found and opened.
1041 .It Ic .undef Ar variable
1042 Un-define the specified global variable.
1043 Only global variables may be un-defined.
1044 .It Ic .error Ar message
1045 Terminate processing of the makefile immediately.
1046 The filename of the
1047 makefile, the line on which the error was encountered and the specified
1048 message are printed to the standard error output and
1049 .Nm
1050 terminates with exit code 1.
1051 Variables in the message are expanded.
1052 .It Ic .warning Ar message
1053 Emit a warning message.
1054 The filename of the makefile,
1055 the line on which the warning was encountered,
1056 and the specified message are printed to the standard error output.
1057 Variables in the message are expanded.
1058 .El
1059 .Pp
1060 Conditionals are used to determine which parts of the Makefile
1061 to process.
1062 They are used similarly to the conditionals supported
1063 by the C pre-processor.
1064 The following conditionals are supported:
1065 .Bl -tag -width Ds
1066 .It Xo
1067 .Ic .if
1068 .Oo \&! Oc Ns Ar expression
1069 .Op Ar operator expression ...
1070 .Xc
1071 Test the value of an expression.
1072 .It Xo
1073 .Ic .ifdef
1074 .Oo \&! Oc Ns Ar variable
1075 .Op Ar operator variable ...
1076 .Xc
1077 Test the value of a variable.
1078 .It Xo
1079 .Ic .ifndef
1080 .Oo \&! Oc Ns Ar variable
1081 .Op Ar operator variable ...
1082 .Xc
1083 Test the value of a variable.
1084 .It Xo
1085 .Ic .ifmake
1086 .Oo \&! Oc Ns Ar target
1087 .Op Ar operator target ...
1088 .Xc
1089 Test the target being built.
1090 .It Xo
1091 .Ic .ifnmake
1092 .Oo \&! Oc Ns Ar target
1093 .Op Ar operator target ...
1094 .Xc
1095 Test the target being built.
1096 .It Ic .else
1097 Reverse the sense of the last conditional.
1098 .It Xo
1099 .Ic .elif
1100 .Oo \&! Oc Ns Ar expression
1101 .Op Ar operator expression ...
1102 .Xc
1103 A combination of
1104 .Ic .else
1105 followed by
1106 .Ic .if .
1107 .It Xo
1108 .Ic .elifdef
1109 .Oo \&! Oc Ns Ar variable
1110 .Op Ar operator variable ...
1111 .Xc
1112 A combination of
1113 .Ic .else
1114 followed by
1115 .Ic .ifdef .
1116 .It Xo
1117 .Ic .elifndef
1118 .Oo \&! Oc Ns Ar variable
1119 .Op Ar operator variable ...
1120 .Xc
1121 A combination of
1122 .Ic .else
1123 followed by
1124 .Ic .ifndef .
1125 .It Xo
1126 .Ic .elifmake
1127 .Oo \&! Oc Ns Ar target
1128 .Op Ar operator target ...
1129 .Xc
1130 A combination of
1131 .Ic .else
1132 followed by
1133 .Ic .ifmake .
1134 .It Xo
1135 .Ic .elifnmake
1136 .Oo \&! Oc Ns Ar target
1137 .Op Ar operator target ...
1138 .Xc
1139 A combination of
1140 .Ic .else
1141 followed by
1142 .Ic .ifnmake .
1143 .It Ic .endif
1144 End the body of the conditional.
1145 .El
1146 .Pp
1147 The
1148 .Ar operator
1149 may be any one of the following:
1150 .Bl -tag -width "Cm XX"
1151 .It Cm ||
1152 Logical
1153 .Tn OR
1154 .It Cm &&
1155 Logical
1156 .Tn AND ;
1157 of higher precedence than
1158 .Sq Ic || .
1159 .El
1160 .Pp
1161 As in C,
1162 .Nm
1163 will only evaluate a conditional as far as is necessary to determine
1164 its value.
1165 Parentheses may be used to change the order of evaluation.
1166 The boolean operator
1167 .Sq Ic !\&
1168 may be used to logically negate an entire
1169 conditional.
1170 It is of higher precedence than
1171 .Sq Ic && .
1172 .Pp
1173 The value of
1174 .Ar expression
1175 may be any of the following:
1176 .Bl -tag -width Ic
1177 .It Ic defined
1178 Takes a variable name as an argument and evaluates to true if the variable
1179 has been defined.
1180 .It Ic make
1181 Takes a target name as an argument and evaluates to true if the target
1182 was specified as part of
1183 .Nm Ns 's
1184 command line or was declared the default target (either implicitly or
1185 explicitly, see
1186 .Va .MAIN )
1187 before the line containing the conditional.
1188 .It Ic empty
1189 Takes a variable, with possible modifiers, and evaluates to true if
1190 the expansion of the variable would result in an empty string.
1191 .It Ic exists
1192 Takes a file name as an argument and evaluates to true if the file exists.
1193 The file is searched for on the system search path (see
1194 .Va .PATH ) .
1195 .It Ic target
1196 Takes a target name as an argument and evaluates to true if the target
1197 has been defined.
1198 .El
1199 .Pp
1200 An
1201 .Ar expression
1202 may also be a numeric or string comparison:
1203 in this case, the left-hand side
1204 .Ar must be
1205 a variable expansion, whereas the right-hand side can be a
1206 constant or a variable expansion.
1207 Variable expansion is performed on both sides, after which the resulting
1208 values are compared.
1209 A value is interpreted as hexadecimal if it is
1210 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1211 .Pp
1212 String comparison can only use the
1213 .Sq Ic ==
1214 or
1215 .Sq Ic !=
1216 operators, whereas numeric values (both integer and floating point)
1217 can also be compared using the
1218 .Sq Ic > ,
1219 .Sq Ic >= ,
1220 .Sq Ic <
1221 and
1222 .Sq Ic <=
1223 operators.
1224 .Pp
1225 If no relational operator (and right-hand value) are given, an implicit
1226 .Sq Ic != 0
1227 is used.
1228 However be very careful in using this feature especially
1229 when the left-hand side variable expansion returns a string.
1230 .Pp
1231 When
1232 .Nm
1233 is evaluating one of these conditional expressions, and it encounters
1234 a word it does not recognize, either the
1235 .Dq make
1236 or
1237 .Dq defined
1238 expression is applied to it, depending on the form of the conditional.
1239 If the form is
1240 .Ic .if ,
1241 .Ic .ifdef
1242 or
1243 .Ic .ifndef ,
1244 the
1245 .Dq defined
1246 expression is applied.
1247 Similarly, if the form is
1248 .Ic .ifmake
1249 or
1250 .Ic .ifnmake ,
1251 the
1252 .Dq make
1253 expression is applied.
1254 .Pp
1255 If the conditional evaluates to true the parsing of the makefile continues
1256 as before.
1257 If it evaluates to false, the following lines are skipped.
1258 In both cases this continues until a
1259 .Ic .else
1260 or
1261 .Ic .endif
1262 is found.
1263 .Pp
1264 For loops are typically used to apply a set of rules to a list of files.
1265 The syntax of a for loop is:
1266 .Pp
1267 .Bl -tag -width indent -compact
1268 .It Ic .for Ar variable Ic in Ar expression
1269 .It <make-rules>
1270 .It Ic .endfor
1271 .El
1272 .Pp
1273 After the for
1274 .Ar expression
1275 is evaluated, it is split into words.
1276 The
1277 iteration
1278 .Ar variable
1279 is successively set to each word, and substituted in the
1280 .Ic make-rules
1281 inside the body of the for loop.
1282 .Sh COMMENTS
1283 Comments begin with a hash
1284 .Pq Ql #
1285 character, anywhere but in a shell
1286 command line, and continue to the end of the line.
1287 .Sh SPECIAL SOURCES
1288 .Bl -tag -width Ic
1289 .It Ic .IGNORE
1290 Ignore any errors from the commands associated with this target, exactly
1291 as if they all were preceded by a dash
1292 .Pq Ql \- .
1293 .It Ic .MAKE
1294 Execute the commands associated with this target even if the
1295 .Fl n
1296 or
1297 .Fl t
1298 options were specified.
1299 Normally used to mark recursive
1300 .Nm Ns 's .
1301 .It Ic .NOTMAIN
1302 Normally
1303 .Nm
1304 selects the first target it encounters as the default target to be built
1305 if no target was specified.
1306 This source prevents this target from being selected.
1307 .It Ic .OPTIONAL
1308 If a target is marked with this attribute and
1309 .Nm
1310 cannot figure out how to create it, it will ignore this fact and assume
1311 the file is not needed or already exists.
1312 .It Ic .PRECIOUS
1313 When
1314 .Nm
1315 is interrupted, it removes any partially made targets.
1316 This source prevents the target from being removed.
1317 .It Ic .SILENT
1318 Do not echo any of the commands associated with this target, exactly
1319 as if they all were preceded by an at sign
1320 .Pq Ql @ .
1321 .It Ic .USE
1322 Turn the target into
1323 .Nm Ns 's
1324 version of a macro.
1325 When the target is used as a source for another target, the other target
1326 acquires the commands, sources, and attributes (except for
1327 .Ic .USE )
1328 of the
1329 source.
1330 If the target already has commands, the
1331 .Ic .USE
1332 target's commands are appended
1333 to them.
1334 .It Ic .WAIT
1335 If special
1336 .Ic .WAIT
1337 source appears in a dependency line, the sources that precede it are
1338 made before the sources that succeed it in the line.
1339 Loops are not being
1340 detected and targets that form loops will be silently ignored.
1341 .El
1342 .Sh SPECIAL TARGETS
1343 Special targets may not be included with other targets, i.e., they must be
1344 the only target specified.
1345 .Bl -tag -width Ic
1346 .It Ic .BEGIN
1347 Any command lines attached to this target are executed before anything
1348 else is done.
1349 .It Ic .DEFAULT
1350 This is sort of a
1351 .Ic .USE
1352 rule for any target (that was used only as a
1353 source) that
1354 .Nm
1355 cannot figure out any other way to create.
1356 Only the shell script is used.
1357 The
1358 .Ic .IMPSRC
1359 variable of a target that inherits
1360 .Ic .DEFAULT Ns 's
1361 commands is set
1362 to the target's own name.
1363 .It Ic .END
1364 Any command lines attached to this target are executed after everything
1365 else is done.
1366 .It Ic .IGNORE
1367 Mark each of the sources with the
1368 .Ic .IGNORE
1369 attribute.
1370 If no sources are specified, this is the equivalent of specifying the
1371 .Fl i
1372 option.
1373 .It Ic .INCLUDES
1374 A list of suffixes that indicate files that can be included in a source
1375 file.
1376 The suffix must have already been declared with
1377 .Ic .SUFFIXES ;
1378 any suffix so declared will have the directories on its search path (see
1379 .Ic .PATH )
1380 placed in the
1381 .Va .INCLUDES
1382 special variable, each preceded by a
1383 .Fl I
1384 flag.
1385 .It Ic .INTERRUPT
1386 If
1387 .Nm
1388 is interrupted, the commands for this target will be executed.
1389 .It Ic .LIBS
1390 This does for libraries what
1391 .Ic .INCLUDES
1392 does for include files, except that the flag used is
1393 .Fl L .
1394 .It Ic .MAIN
1395 If no target is specified when
1396 .Nm
1397 is invoked, this target will be built.
1398 This is always set, either
1399 explicitly, or implicitly when
1400 .Nm
1401 selects the default target, to give the user a way to refer to the default
1402 target on the command line.
1403 .It Ic .MAKEFILEDEPS
1404 Enable the
1405 .Dq Remaking Makefiles
1406 functionality, as explained in the
1407 .Sx REMAKING MAKEFILES
1408 section below.
1409 .It Ic .MAKEFLAGS
1410 This target provides a way to specify flags for
1411 .Nm
1412 when the makefile is used.
1413 The flags are as if typed to the shell, though the
1414 .Fl f
1415 option will have
1416 no effect.
1417 Flags (except for
1418 .Fl f )
1419 and variable assignments specified as the source
1420 for this target are also appended to the
1421 .Va .MAKEFLAGS
1422 internal variable.
1423 Please note the difference between this target and the
1424 .Va .MAKEFLAGS
1425 internal variable: specifying an option or variable
1426 assignment as the source for this target will affect
1427 .Em both
1428 the current makefile and all processes that
1429 .Nm
1430 executes.
1431 .It Ic .MFLAGS
1432 Same as above, for backward compatibility.
1433 .\" XXX: NOT YET!!!!
1434 .\" .It Ic .NOTPARALLEL
1435 .\" The named targets are executed in non parallel mode. If no targets are
1436 .\" specified, then all targets are executed in non parallel mode.
1437 .It Ic .NOTPARALLEL
1438 Disable parallel mode.
1439 .It Ic .NO_PARALLEL
1440 Same as above, for compatibility with other
1441 .Nm pmake
1442 variants.
1443 .It Ic .ORDER
1444 The named targets are made in sequence.
1445 .\" XXX: NOT YET!!!!
1446 .\" .It Ic .PARALLEL
1447 .\" The named targets are executed in parallel mode. If no targets are
1448 .\" specified, then all targets are executed in parallel mode.
1449 .It Ic .PATH
1450 The sources are directories which are to be searched for files not
1451 found in the current directory.
1452 If no sources are specified, any previously specified directories are
1453 deleted.
1454 Where possible, use of
1455 .Ic .PATH
1456 is preferred over use of the
1457 .Va VPATH
1458 variable.
1459 .It Ic .PATH\fIsuffix\fR
1460 The sources are directories which are to be searched for suffixed files
1461 not found in the current directory.
1462 The
1463 .Nm
1464 utility
1465 first searches the suffixed search path, before reverting to the default
1466 path if the file is not found there.
1467 This form is required for
1468 .Ic .LIBS
1469 and
1470 .Ic .INCLUDES
1471 to work.
1472 .It Ic .PHONY
1473 Apply the
1474 .Ic .PHONY
1475 attribute to any specified sources.
1476 Targets with this attribute are always
1477 considered to be out of date.
1478 .It Ic .POSIX
1479 Adjust
1480 .Nm Ap s
1481 behavior to match the applicable
1482 .Tn POSIX
1483 specifications.
1484 (Note this disables the
1485 .Dq Remaking Makefiles
1486 feature.)
1487 .It Ic .PRECIOUS
1488 Apply the
1489 .Ic .PRECIOUS
1490 attribute to any specified sources.
1491 If no sources are specified, the
1492 .Ic .PRECIOUS
1493 attribute is applied to every
1494 target in the file.
1495 .It Ic .SHELL
1496 Select another shell.
1497 The sources of this target have the format
1498 .Ar key Ns = Ns Ar value .
1499 The
1500 .Ar key
1501 is one of:
1502 .Bl -tag -width ".Va hasErrCtl"
1503 .It Va path
1504 Specify the path to the new shell.
1505 .It Va name
1506 Specify the name of the new shell.
1507 This may be either one of the three builtin shells (see below) or any
1508 other name.
1509 .It Va quiet
1510 Specify the shell command to turn echoing off.
1511 .It Va echo
1512 Specify the shell command to turn echoing on.
1513 .It Va filter
1514 Usually shells print the echo off command before turning echoing off.
1515 This is the exact string that will be printed by the shell and is used
1516 to filter the shell output to remove the echo off command.
1517 .It Va echoFlag
1518 The shell option that turns echoing on.
1519 .It Va errFlag
1520 The shell option to turn on error checking.
1521 If error checking is on, the shell should exit if a command returns
1522 a non-zero status.
1523 .It Va hasErrCtl
1524 True if the shell has error control.
1525 .It Va check
1526 If
1527 .Va hasErrCtl
1528 is true then this is the shell command to turn error checking on.
1529 If
1530 .Va hasErrCtl
1531 is false then this is a command template to echo commands for which error
1532 checking is disabled.
1533 The template must contain a
1534 .Ql %s .
1535 .It Va ignore
1536 If
1537 .Va hasErrCtl
1538 is true, this is the shell command to turn error checking off.
1539 If
1540 .Va hasErrCtl
1541 is false, this is a command template to execute a command so that errors
1542 are ignored.
1543 The template must contain a
1544 .Ql %s .
1545 .It Va meta
1546 This is a string of meta characters of the shell.
1547 .It Va builtins
1548 This is a string holding all the shell's builtin commands separated by blanks.
1549 The
1550 .Va meta
1551 and
1552 .Va builtins
1553 strings are used in compat mode.
1554 When a command line contains neither a meta
1555 character nor starts with a shell builtin, it is executed directly without
1556 invoking a shell.
1557 When one of these strings (or both) is empty all commands are executed
1558 through a shell.
1559 .It Va unsetenv
1560 If true, remove the
1561 .Ev ENV
1562 environment variable before executing any command.
1563 This is useful for the Korn-shell
1564 .Pq Nm ksh .
1565 .El
1566 .Pp
1567 Values that are strings must be surrounded by double quotes.
1568 Boolean values are specified as
1569 .Ql T
1570 or
1571 .Ql Y
1572 (in either case) to mean true.
1573 Any other value is taken to mean false.
1574 .Pp
1575 There are several uses of the
1576 .Ic .SHELL
1577 target:
1578 .Bl -bullet
1579 .It
1580 Selecting one of the builtin shells.
1581 This is done by just specifying the name of the shell with the
1582 .Va name
1583 keyword.
1584 It is also possible to modify the parameters of the builtin shell by just
1585 specifying other keywords (except for
1586 .Va path ) .
1587 .It
1588 Using another executable for one of the builtin shells.
1589 This is done by specifying the path to the executable with the
1590 .Va path
1591 keyword.
1592 If the last component is the same as the name of the builtin shell, no
1593 name needs to be specified; if it is different, the name must be given:
1594 .Bd -literal -offset indent
1595 \&.SHELL: path="/usr/local/bin/sh"
1596 .Ed
1597 .Pp
1598 selects the builtin shell
1599 .Dq Li sh
1600 but will execute it from
1601 .Pa /usr/local/bin/sh .
1602 Like in the previous case, it is possible to modify parameters of the builtin
1603 shell by just specifying them.
1604 .It
1605 Using an entirely different shell.
1606 This is done by specifying all keywords.
1607 .El
1608 .Pp
1609 The builtin shells are
1610 .Dq Li sh ,
1611 .Dq Li csh
1612 and
1613 .Dq Li ksh .
1614 Because
1615 .Fx
1616 has no
1617 .Nm ksh
1618 in
1619 .Pa /bin ,
1620 it is unwise to specify
1621 .Va name Ns = Ns Qq Li ksh
1622 without also specifying a path.
1623 .It Ic .SILENT
1624 Apply the
1625 .Ic .SILENT
1626 attribute to any specified sources.
1627 If no sources are specified, the
1628 .Ic .SILENT
1629 attribute is applied to every
1630 command in the file.
1631 .It Ic .SUFFIXES
1632 Each source specifies a suffix to
1633 .Nm .
1634 If no sources are specified, any previous specified suffixes are deleted.
1635 .It Ic .WARN
1636 Each source specifies a warning flag as previously described for the
1637 .Fl x
1638 command line option.
1639 Warning flags specified on the command line take precedence over flags
1640 specified in the makefile.
1641 Also, command line warning flags are pushed to sub-makes through the
1642 .Ev MAKEFLAGS
1643 environment variables so that a warning flag specified on the command
1644 line will influence all sub-makes.
1645 Several flags can be specified on a single
1646 .Ic .WARN
1647 target by separating them with blanks.
1648 .El
1649 .Sh REMAKING MAKEFILES
1650 If the special target
1651 .Ic .MAKEFILEDEPS
1652 exists in the Makefile,
1653 .Nm
1654 enables the
1655 .Dq Remaking Makefiles
1656 feature.
1657 After reading Makefile and all the files that are included using
1658 .Ic .include
1659 or
1660 .Ic .sinclude
1661 directives (source Makefiles)
1662 .Nm
1663 considers each source Makefile as a target and tries to rebuild it.
1664 Both explicit and implicit rules are checked and all source Makefiles
1665 are updated if necessary. If any of the source Makefiles were rebuilt,
1666 .Nm
1667 restarts from clean state.
1668 .Pp
1669 To prevent infinite loops the following source Makefile targets are ignored:
1670 .Bl -bullet
1671 .It
1672 .Ic ::
1673 targets that have no prerequisites
1674 .It
1675 .Ic !
1676 targets
1677 .It
1678 targets that have
1679 .Ic .PHONY
1680 or
1681 .Ic .EXEC
1682 attributes
1683 .It
1684 targets without prerequisites and without commands
1685 .El
1686 .Pp
1687 When remaking a source Makefile options
1688 .Ic -t
1689 (touch target),
1690 .Ic -q
1691 (query mode), and
1692 .Ic -n
1693 (no exec) do not take effect, unless source Makefile is specified
1694 explicitly as a target in
1695 .Nm
1696 command line.
1697 .Pp
1698 Additionally, system makefiles and
1699 .Ic .depend
1700 are not considered as Makefiles that can be rebuilt.
1701 .Sh ENVIRONMENT
1702 The
1703 .Nm
1704 utility uses the following environment variables, if they exist:
1705 .Ev MACHINE ,
1706 .Ev MAKE ,
1707 .Ev MAKEFLAGS ,
1708 .Ev MAKEOBJDIR ,
1709 .Ev MAKEOBJDIRPREFIX ,
1710 and
1711 .Ev MAKESYSPATH .
1712 .Sh FILES
1713 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1714 .It Pa .depend
1715 list of dependencies
1716 .It Pa Makefile
1717 list of dependencies
1718 .It Pa makefile
1719 list of dependencies
1720 .It Pa obj
1721 object directory
1722 .It Pa sys.mk
1723 system makefile
1724 .It Pa /usr/share/mk
1725 default system makefile directory
1726 .It Pa /usr/share/doc/psd/12.make
1727 PMake tutorial
1728 .It Pa /usr/obj
1729 default
1730 .Ev MAKEOBJDIRPREFIX
1731 directory.
1732 .It Pa /etc/make.conf
1733 default path to
1734 .Xr make.conf 5
1735 .El
1736 .Sh EXAMPLES
1737 List all included makefiles in order visited:
1738 .Pp
1739 .Dl "make -V .MAKEFILE_LIST | tr \e\  \e\en"
1740 .Sh COMPATIBILITY
1741 Older versions of
1742 .Nm
1743 used
1744 .Ev MAKE
1745 instead of
1746 .Ev MAKEFLAGS .
1747 This was removed for
1748 .Tn POSIX
1749 compatibility.
1750 The internal variable
1751 .Va MAKE
1752 is set to the same value as
1753 .Va .MAKE ;
1754 support for this may be removed in the future.
1755 .Pp
1756 The use of the
1757 .Cm :L
1758 and
1759 .Cm :U
1760 modifiers will be deprecated
1761 in
1762 .Fx 10.0
1763 and the more portable (among Pmake decedents)
1764 .Cm :tl
1765 and
1766 .Cm :tu
1767 should be used instead.
1768 .Pp
1769 Most of the more esoteric features of
1770 .Nm
1771 should probably be avoided for greater compatibility.
1772 .Sh SEE ALSO
1773 .Xr mkdep 1 ,
1774 .Xr make.conf 5
1775 .Rs
1776 .%T "PMake - A Tutorial"
1777 .Re
1778 in
1779 .Pa /usr/share/doc/psd/12.make
1780 .Sh HISTORY
1781 A
1782 .Nm
1783 command appeared in PWB UNIX.
1784 .Sh BUGS
1785 The determination of
1786 .Va .OBJDIR
1787 is contorted to the point of absurdity.
1788 .Pp
1789 In the presence of several
1790 .Ic .MAIN
1791 special targets,
1792 .Nm
1793 silently ignores all but the first.
1794 .Pp
1795 .Va .TARGETS
1796 is not set to the default target when
1797 .Nm
1798 is invoked without a target name and no
1799 .Ic .MAIN
1800 special target exists.
1801 .Pp
1802 The evaluation of
1803 .Ar expression
1804 in a test is very simple-minded.
1805 Currently, the only form that works is
1806 .Ql .if ${VAR} op something .
1807 For instance, you should write tests as
1808 .Ql .if ${VAR} == "string"
1809 not the other way around, which would give you an error.
1810 .Pp
1811 For loops are expanded before tests, so a fragment such as:
1812 .Bd -literal -offset indent
1813 \&.for ARCH in ${SHARED_ARCHS}
1814 \&.if ${ARCH} == ${MACHINE}
1815      ...
1816 \&.endif
1817 \&.endfor
1818 .Ed
1819 .Pp
1820 will not work, and should be rewritten as:
1821 .Bd -literal -offset indent
1822 \&.for ARCH in ${SHARED_ARCHS}
1823 \&.if ${MACHINE} == ${ARCH}
1824      ...
1825 \&.endif
1826 \&.endfor
1827 .Ed
1828 .Pp
1829 The parsing code is broken with respect to handling a semicolon
1830 after a colon, so a fragment like this will fail:
1831 .Bd -literal -offset indent
1832 HDRS=   foo.h bar.h
1833
1834 all:
1835 \&.for h in ${HDRS:S;^;${.CURDIR}/;}
1836      ...
1837 \&.endfor
1838 .Ed
1839 .Pp
1840 A trailing backslash in a variable value defined on the command line causes
1841 the delimiting space in the
1842 .Ev MAKEFLAGS
1843 environment variable to be preceded by that backslash.
1844 That causes a submake to not treat that space as a word delimiter.
1845 Fixing this requires a larger rewrite of the code handling command line
1846 macros and assignments to
1847 .Va .MAKEFLAGS .