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