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