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