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