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