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