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