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