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