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