71c7f1e42c059ad2c9c2d25b2174dc03123aa778
[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.13 2004/12/01 01:10:17 joerg Exp $
35 .\"
36 .Dd August 4, 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 characters of the command line are
325 .Sq Ic @ ,
326 .Sq Ic \- ,
327 and/or
328 .Sq Ic + ,
329 the command is treated specially.
330 A
331 .Sq Ic @
332 causes the command not to be echoed before it is executed.
333 A
334 .Sq Ic \-
335 causes any non-zero exit status of the command line to be ignored.
336 A
337 .Sq Ic +
338 causes the command to be executed even if
339 .Fl n
340 is specified on the command line.
341 .Sh VARIABLE ASSIGNMENTS
342 Variables in
343 .Nm
344 are much like variables in the shell, and, by tradition,
345 consist of all upper-case letters.
346 The five operators that can be used to assign values to variables are as
347 follows:
348 .Bl -tag -width Ds
349 .It Ic \&=
350 Assign the value to the variable.
351 Any previous value is overridden.
352 .It Ic \&+=
353 Append the value to the current value of the variable.
354 .It Ic \&?=
355 Assign the value to the variable if it is not already defined.
356 .It Ic \&:=
357 Assign with expansion, i.e., expand the value before assigning it
358 to the variable.
359 Normally, expansion is not done until the variable is referenced.
360 .It Ic \&!=
361 Expand the value and pass it to the shell for execution and assign
362 the result to the variable.
363 Any newlines in the result are replaced with spaces.
364 .El
365 .Pp
366 Any whitespace before the assigned
367 .Ar value
368 is removed; if the value is being appended, a single space is inserted
369 between the previous contents of the variable and the appended value.
370 .Pp
371 Variables are expanded by surrounding the variable name with either
372 curly braces
373 .Pq Ql {}
374 or parentheses
375 .Pq Ql ()
376 and preceding it with
377 a dollar sign
378 .Pq Ql \&$ .
379 If the variable name contains only a single letter, the surrounding
380 braces or parentheses are not required.
381 This shorter form is not recommended.
382 .Pp
383 Variable substitution occurs at two distinct times, depending on where
384 the variable is being used.
385 Variables in dependency lines are expanded as the line is read.
386 Variables in shell commands are expanded when the shell command is
387 executed.
388 .Pp
389 The four different classes of variables (in order of increasing precedence)
390 are:
391 .Bl -tag -width Ds
392 .It Environment variables
393 Variables defined as part of
394 .Nm Ns 's
395 environment.
396 .It Global variables
397 Variables defined in the makefile or in included makefiles.
398 .It Command line variables
399 Variables defined as part of the command line and variables
400 obtained from the
401 .Ev MAKEFLAGS
402 environment variable or the
403 .Ic .MAKEFLAGS
404 target.
405 .It Local variables
406 Variables that are defined specific to a certain target.
407 The seven local variables are as follows:
408 .Bl -tag -width ".ARCHIVE"
409 .It Va .ALLSRC
410 The list of all sources for this target; also known as
411 .Sq Va \&> .
412 .It Va .ARCHIVE
413 The name of the archive file; also known as
414 .Sq Va \&! .
415 .It Va .IMPSRC
416 The name/path of the source from which the target is to be transformed
417 (the
418 .Dq implied
419 source); also known as
420 .Sq Va \&< .
421 .It Va .MEMBER
422 The name of the archive member; also known as
423 .Sq Va \&% .
424 .It Va .OODATE
425 The list of sources for this target that were deemed out-of-date; also
426 known as
427 .Sq Va \&? .
428 .It Va .PREFIX
429 The file prefix of the file, containing only the file portion, no suffix
430 or preceding directory components; also known as
431 .Sq Va * .
432 .It Va .TARGET
433 The name of the target; also known as
434 .Sq Va @ .
435 .El
436 .Pp
437 The shorter forms
438 .Sq Va @ ,
439 .Sq Va \&! ,
440 .Sq Va \&< ,
441 .Sq Va \&% ,
442 .Sq Va \&? ,
443 .Sq Va \&> ,
444 and
445 .Sq Va *
446 are permitted for backward
447 compatibility and are not recommended.
448 The six variables
449 .Sq Va @F ,
450 .Sq Va @D ,
451 .Sq Va <F ,
452 .Sq Va <D ,
453 .Sq Va *F ,
454 and
455 .Sq Va *D
456 are
457 permitted for compatibility with
458 .At V
459 makefiles and are not recommended.
460 .Pp
461 Four of the local variables may be used in sources on dependency lines
462 because they expand to the proper value for each target on the line.
463 These variables are
464 .Va .TARGET ,
465 .Va .PREFIX ,
466 .Va .ARCHIVE ,
467 and
468 .Va .MEMBER .
469 .El
470 .Pp
471 In addition,
472 .Nm
473 sets or knows about the following internal variables or environment
474 variables:
475 .Bl -tag -width ".Va MAKEFILE_LIST"
476 .It Va \&$
477 A single dollar sign
478 .Ql \&$ ,
479 i.e.\&
480 .Ql \&$$
481 expands to a single dollar
482 sign.
483 .It Va MAKE
484 The name that
485 .Nm
486 was executed with
487 .Pq Va argv Ns Op 0 .
488 .It Va .CURDIR
489 A path to the directory where
490 .Nm
491 was executed.
492 The
493 .Nm
494 utility sets
495 .Va .CURDIR
496 to the canonical path given by
497 .Xr getcwd 3 .
498 .It Va .OBJDIR
499 A path to the directory where the targets are built.
500 At startup,
501 .Nm
502 searches for an alternate directory to place target files.
503 It will attempt to change into this special directory
504 and will search this directory for makefiles
505 not found in the current directory.
506 The following directories are tried in order:
507 .Pp
508 .Bl -enum -compact
509 .It
510 ${MAKEOBJDIRPREFIX}/`pwd`
511 .It
512 ${MAKEOBJDIR}
513 .It
514 obj.${MACHINE}
515 .It
516 obj
517 .It
518 /usr/obj/`pwd`
519 .El
520 .Pp
521 The first directory that
522 .Nm
523 successfully changes into is used.
524 If either
525 .Ev MAKEOBJDIRPREFIX
526 or
527 .Ev MAKEOBJDIR
528 is set in the environment but
529 .Nm
530 is unable to change into the corresponding directory,
531 then the current directory is used
532 without checking the remainder of the list.
533 If they are undefined and
534 .Nm
535 is unable to change into any of the remaining three directories,
536 then the current directory is used.
537 .Pp
538 .Nm Make
539 sets
540 .Va .OBJDIR
541 to the canonical path given by
542 .Xr getcwd 3 .
543 .It Va .MAKEFILE_LIST
544 As
545 .Nm
546 reads various makefiles, including the default files and any
547 obtained from the command line and
548 .Ic .include
549 directives, their names will be automatically appended to the
550 .Va .MAKEFILE_LIST
551 variable.
552 They are added right before
553 .Nm
554 begins to parse them, so that the name of the current makefile is the
555 last word in this variable.
556 .It Va .MAKEFLAGS
557 The environment variable
558 .Ev MAKEFLAGS
559 may contain anything that
560 may be specified on
561 .Nm Ns 's
562 command line.
563 Its contents are stored in
564 .Nm Ns 's
565 .Va .MAKEFLAGS
566 variable.
567 All options and variable assignments specified on
568 .Nm Ns 's
569 command line are appended to the
570 .Va .MAKEFLAGS
571 variable which is then
572 entered into the environment as
573 .Ev MAKEFLAGS
574 for all programs which
575 .Nm
576 executes.
577 .It Va MFLAGS
578 is provided for backward compatibility and
579 contains all the options from the
580 .Ev MAKEFLAGS
581 environment variable plus any options specified on
582 .Nm Ns 's
583 command line.
584 .It Va .TARGETS
585 List of targets
586 .Nm
587 is currently building.
588 .It Va .INCLUDES
589 See
590 .Ic .INCLUDES
591 special target.
592 .It Va .LIBS
593 See
594 .Ic .LIBS
595 special target.
596 .It Va MACHINE
597 Name of the machine architecture
598 .Nm
599 is running on, obtained from the
600 .Ev MACHINE
601 environment variable, or through
602 .Xr uname 3
603 if not defined.
604 .It Va MACHINE_ARCH
605 Name of the machine architecture
606 .Nm
607 was compiled for, defined at compilation time.
608 .It Va VPATH
609 Makefiles may assign a colon-delimited list of directories to
610 .Va VPATH .
611 These directories will be searched for source files by
612 .Nm
613 after it has finished parsing all input makefiles.
614 .El
615 .Pp
616 Variable expansion may be modified to select or modify each word of the
617 variable (where a
618 .Dq word
619 is whitespace-delimited sequence of characters).
620 The general format of a variable expansion is as follows:
621 .Pp
622 .Dl {variable[:modifier[:...]]}
623 .Pp
624 Each modifier begins with a colon and one of the following
625 special characters.
626 The colon may be escaped with a backslash
627 .Pq Ql \e .
628 .Bl -tag -width Cm
629 .Sm off
630 .It Cm C No \&/ Ar pattern Xo
631 .No \&/ Ar replacement
632 .No \&/ Op Cm 1g
633 .Xc
634 .Sm on
635 Modify each word of the value,
636 substituting every match of the extended regular expression
637 .Ar pattern
638 (see
639 .Xr re_format 7 )
640 with the
641 .Xr ed 1 Ns \-style
642 .Ar replacement
643 string.
644 Normally, the first occurrence of the pattern in
645 each word of the value is changed.
646 The
647 .Ql 1
648 modifier causes the substitution to apply to at most one word; the
649 .Ql g
650 modifier causes the substitution to apply to as many instances of the
651 search pattern as occur in the word or words it is found in.
652 Note that
653 .Ql 1
654 and
655 .Ql g
656 are orthogonal; the former specifies whether multiple words are
657 potentially affected, the latter whether multiple substitutions can
658 potentially occur within each affected word.
659 .It Cm E
660 Replaces each word in the variable with its suffix.
661 .It Cm H
662 Replaces each word in the variable with everything but the last component.
663 .It Cm L
664 Converts variable to lower-case letters.
665 .It Cm M Ns Ar pattern
666 Select only those words that match the rest of the modifier.
667 The standard shell wildcard characters
668 .Pf ( Ql * ,
669 .Ql \&? ,
670 and
671 .Ql [] )
672 may
673 be used.
674 The wildcard characters may be escaped with a backslash
675 .Pq Ql \e .
676 .It Cm N Ns Ar pattern
677 This is identical to
678 .Cm M ,
679 but selects all words which do not match
680 the rest of the modifier.
681 .It Cm Q
682 Quotes every shell meta-character in the variable, so that it can be passed
683 safely through recursive invocations of
684 .Nm Ns .
685 .It Cm R
686 Replaces each word in the variable with everything but its suffix.
687 .Sm off
688 .It Cm S No \&/ Ar old_string Xo
689 .No \&/ Ar new_string
690 .No \&/ Op Cm g
691 .Xc
692 .Sm on
693 Modify the first occurrence of
694 .Ar old_string
695 in each word of the variable's value, replacing it with
696 .Ar new_string .
697 If a
698 .Ql g
699 is appended to the last slash of the pattern, all occurrences
700 in each word are replaced.
701 If
702 .Ar old_string
703 begins with a caret
704 .Pq Ql ^ ,
705 .Ar old_string
706 is anchored at the beginning of each word.
707 If
708 .Ar old_string
709 ends with a dollar sign
710 .Pq Ql \&$ ,
711 it is anchored at the end of each word.
712 Inside
713 .Ar new_string ,
714 an ampersand
715 .Pq Ql &
716 is replaced by
717 .Ar old_string .
718 Any character may be used as a delimiter for the parts of the modifier
719 string.
720 The anchoring, ampersand, and delimiter characters may be escaped with a
721 backslash
722 .Pq Ql \e .
723 .Pp
724 Variable expansion occurs in the normal fashion inside both
725 .Ar old_string
726 and
727 .Ar new_string
728 with the single exception that a backslash is used to prevent the expansion
729 of a dollar sign
730 .Pq Ql \&$ ,
731 not a preceding dollar sign as is usual.
732 .It Ar old_string=new_string
733 This is the
734 .At V
735 style variable substitution.
736 It must be the last modifier specified.
737 If
738 .Ar old_string
739 or
740 .Ar new_string
741 do not contain the pattern matching character
742 .Ar %
743 then it is assumed that they are
744 anchored at the end of each word, so only suffixes or entire
745 words may be replaced.
746 Otherwise
747 .Ar %
748 is the substring of
749 .Ar old_string
750 to be replaced in
751 .Ar new_string
752 .It Cm T
753 Replaces each word in the variable with its last component.
754 .It Cm U
755 Converts variable to upper-case letters.
756 .El
757 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
758 Directives, conditionals, and for loops reminiscent
759 of the C programming language are provided in
760 .Nm Ns .
761 All such structures are identified by a line beginning with a single
762 dot
763 .Pq Ql \&.
764 character.
765 The following directives are supported:
766 .Bl -tag -width Ds
767 .It Ic \&.include Ar <file>
768 .It Ic \&.include Ar \*qfile\*q
769 Include the specified makefile.
770 Variables between the angle brackets
771 or double quotes are expanded to form the file name.
772 If angle brackets
773 are used, the included makefile is expected to be in the system
774 makefile directory.
775 If double quotes are used, the including
776 makefile's directory and any directories specified using the
777 .Fl I
778 option are searched before the system
779 makefile directory.
780 .It Ic .undef Ar variable
781 Un-define the specified global variable.
782 Only global variables may be un-defined.
783 .It Ic \&.makeenv Ar variable
784 Set the environment flag for a preexisting global variable.  The current
785 and future contents of the variable will be exported to the environment.
786 .It Ic .error Ar message
787 Terminate processing of the makefile immediately.
788 The filename of the
789 makefile, the line on which the error was encountered and the specified
790 message are printed to the standard error output and
791 .Nm
792 terminates with exit code 1.
793 Variables in the message are expanded.
794 .It Ic .warning Ar message
795 Emit a warning message.
796 The filename of the makefile,
797 the line on which the warning was encountered,
798 and the specified message are printed to the standard error output.
799 Variables in the message are expanded.
800 .El
801 .Pp
802 Conditionals are used to determine which parts of the Makefile
803 to process.
804 They are used similarly to the conditionals supported
805 by the C pre-processor.
806 The following conditionals are supported:
807 .Bl -tag -width Ds
808 .It Xo
809 .Ic .if
810 .Oo \&! Oc Ns Ar expression
811 .Op Ar operator expression ...
812 .Xc
813 Test the value of an expression.
814 .It Xo
815 .Ic .ifdef
816 .Oo \&! Oc Ns Ar variable
817 .Op Ar operator variable ...
818 .Xc
819 Test the value of a variable.
820 .It Xo
821 .Ic .ifndef
822 .Oo \&! Oc Ns Ar variable
823 .Op Ar operator variable ...
824 .Xc
825 Test the value of a variable.
826 .It Xo
827 .Ic .ifmake
828 .Oo \&! Oc Ns Ar target
829 .Op Ar operator target ...
830 .Xc
831 Test the target being built.
832 .It Xo
833 .Ic .ifnmake
834 .Oo \&! Oc Ns Ar target
835 .Op Ar operator target ...
836 .Xc
837 Test the target being built.
838 .It Ic .else
839 Reverse the sense of the last conditional.
840 .It Xo
841 .Ic .elif
842 .Oo \&! Oc Ns Ar expression
843 .Op Ar operator expression ...
844 .Xc
845 A combination of
846 .Ic .else
847 followed by
848 .Ic .if .
849 .It Xo
850 .Ic .elifdef
851 .Oo \&! Oc Ns Ar variable
852 .Op Ar operator variable ...
853 .Xc
854 A combination of
855 .Ic .else
856 followed by
857 .Ic .ifdef .
858 .It Xo
859 .Ic .elifndef
860 .Oo \&! Oc Ns Ar variable
861 .Op Ar operator variable ...
862 .Xc
863 A combination of
864 .Ic .else
865 followed by
866 .Ic .ifndef .
867 .It Xo
868 .Ic .elifmake
869 .Oo \&! Oc Ns Ar target
870 .Op Ar operator target ...
871 .Xc
872 A combination of
873 .Ic .else
874 followed by
875 .Ic .ifmake .
876 .It Xo
877 .Ic .elifnmake
878 .Oo \&! Oc Ns Ar target
879 .Op Ar operator target ...
880 .Xc
881 A combination of
882 .Ic .else
883 followed by
884 .Ic .ifnmake .
885 .It Ic .endif
886 End the body of the conditional.
887 .El
888 .Pp
889 The
890 .Ar operator
891 may be any one of the following:
892 .Bl -tag -width "Cm XX"
893 .It Cm ||
894 logical
895 .Tn OR
896 .It Cm &&
897 Logical
898 .Tn AND ;
899 of higher precedence than
900 .Sq Ic || .
901 .El
902 .Pp
903 As in C,
904 .Nm
905 will only evaluate a conditional as far as is necessary to determine
906 its value.
907 Parentheses may be used to change the order of evaluation.
908 The boolean operator
909 .Sq Ic !\&
910 may be used to logically negate an entire
911 conditional.
912 It is of higher precedence than
913 .Sq Ic && .
914 .Pp
915 The value of
916 .Ar expression
917 may be any of the following:
918 .Bl -tag -width Ic
919 .It Ic defined
920 Takes a variable name as an argument and evaluates to true if the variable
921 has been defined.
922 .It Ic make
923 Takes a target name as an argument and evaluates to true if the target
924 was specified as part of
925 .Nm Ns 's
926 command line or was declared the default target (either implicitly or
927 explicitly, see
928 .Va .MAIN )
929 before the line containing the conditional.
930 .It Ic empty
931 Takes a variable, with possible modifiers, and evaluates to true if
932 the expansion of the variable would result in an empty string.
933 .It Ic exists
934 Takes a file name as an argument and evaluates to true if the file exists.
935 The file is searched for on the system search path (see
936 .Va .PATH ) .
937 .It Ic target
938 Takes a target name as an argument and evaluates to true if the target
939 has been defined.
940 .El
941 .Pp
942 An
943 .Ar expression
944 may also be an arithmetic or string comparison, with the left-hand side
945 being a variable expansion.
946 Variable expansion is
947 performed on both sides of the comparison, after which the integral
948 values are compared.
949 A value is interpreted as hexadecimal if it is
950 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
951 The standard C relational operators are all supported.
952 If after
953 variable expansion, either the left or right hand side of a
954 .Sq Ic ==
955 or
956 .Sq Ic !=
957 operator is not an integral value, then
958 string comparison is performed between the expanded
959 variables.
960 If no relational operator is given, it is assumed that the expanded
961 variable is being compared against 0.
962 .Pp
963 When
964 .Nm
965 is evaluating one of these conditional expressions, and it encounters
966 a word it doesn't recognize, either the
967 .Dq make
968 or
969 .Dq defined
970 expression is applied to it, depending on the form of the conditional.
971 If the form is
972 .Ic .if ,
973 .Ic .ifdef
974 or
975 .Ic .ifndef ,
976 the
977 .Dq defined
978 expression is applied.
979 Similarly, if the form is
980 .Ic .ifmake
981 or
982 .Ic .ifnmake ,
983 the
984 .Dq make
985 expression is applied.
986 .Pp
987 If the conditional evaluates to true the parsing of the makefile continues
988 as before.
989 If it evaluates to false, the following lines are skipped.
990 In both cases this continues until a
991 .Ic .else
992 or
993 .Ic .endif
994 is found.
995 .Pp
996 For loops are typically used to apply a set of rules to a list of files.
997 The syntax of a for loop is:
998 .Pp
999 .Bl -tag -width indent -compact
1000 .It Ic .for Ar variable Ic in Ar expression
1001 .It <make-rules>
1002 .It Ic .endfor
1003 .El
1004 .Pp
1005 After the for
1006 .Ar expression
1007 is evaluated, it is split into words.
1008 The
1009 iteration
1010 .Ar variable
1011 is successively set to each word, and substituted in the
1012 .Ic make-rules
1013 inside the body of the for loop.
1014 .Sh COMMENTS
1015 Comments begin with a hash
1016 .Pq Ql #
1017 character, anywhere but in a shell
1018 command line, and continue to the end of the line.
1019 .Sh SPECIAL SOURCES
1020 .Bl -tag -width Ic
1021 .It Ic .IGNORE
1022 Ignore any errors from the commands associated with this target, exactly
1023 as if they all were preceded by a dash
1024 .Pq Ql \- .
1025 .It Ic .MAKE
1026 Execute the commands associated with this target even if the
1027 .Fl n
1028 or
1029 .Fl t
1030 options were specified.
1031 Normally used to mark recursive
1032 .Nm Ns 's .
1033 .It Ic .NOTMAIN
1034 Normally
1035 .Nm
1036 selects the first target it encounters as the default target to be built
1037 if no target was specified.
1038 This source prevents this target from being selected.
1039 .It Ic .OPTIONAL
1040 If a target is marked with this attribute and
1041 .Nm
1042 can't figure out how to create it, it will ignore this fact and assume
1043 the file isn't needed or already exists.
1044 .It Ic .PRECIOUS
1045 When
1046 .Nm
1047 is interrupted, it removes any partially made targets.
1048 This source prevents the target from being removed.
1049 .It Ic .SILENT
1050 Do not echo any of the commands associated with this target, exactly
1051 as if they all were preceded by an at sign
1052 .Pq Ql @ .
1053 .It Ic .USE
1054 Turn the target into
1055 .Nm Ns 's
1056 version of a macro.
1057 When the target is used as a source for another target, the other target
1058 acquires the commands, sources, and attributes (except for
1059 .Ic .USE )
1060 of the
1061 source.
1062 If the target already has commands, the
1063 .Ic .USE
1064 target's commands are appended
1065 to them.
1066 .It Ic .WAIT
1067 If special
1068 .Ic .WAIT
1069 source is appears in a dependency line, the sources that precede it are
1070 made before the sources that succeed it in the line.
1071 Loops are not being
1072 detected and targets that form loops will be silently ignored.
1073 .El
1074 .Sh "SPECIAL TARGETS"
1075 Special targets may not be included with other targets, i.e., they must be
1076 the only target specified.
1077 .Bl -tag -width Ic
1078 .It Ic .BEGIN
1079 Any command lines attached to this target are executed before anything
1080 else is done.
1081 .It Ic .DEFAULT
1082 This is sort of a
1083 .Ic .USE
1084 rule for any target (that was used only as a
1085 source) that
1086 .Nm
1087 can't figure out any other way to create.
1088 Only the shell script is used.
1089 The
1090 .Ic .IMPSRC
1091 variable of a target that inherits
1092 .Ic .DEFAULT Ns 's
1093 commands is set
1094 to the target's own name.
1095 .It Ic .END
1096 Any command lines attached to this target are executed after everything
1097 else is done.
1098 .It Ic .IGNORE
1099 Mark each of the sources with the
1100 .Ic .IGNORE
1101 attribute.
1102 If no sources are specified, this is the equivalent of specifying the
1103 .Fl i
1104 option.
1105 .It Ic .INCLUDES
1106 A list of suffixes that indicate files that can be included in a source
1107 file.
1108 The suffix must have already been declared with
1109 .Ic .SUFFIXES ;
1110 any suffix so declared will have the directories on its search path (see
1111 .Ic .PATH )
1112 placed in the
1113 .Va .INCLUDES
1114 special variable, each preceded by a
1115 .Fl I
1116 flag.
1117 .It Ic .INTERRUPT
1118 If
1119 .Nm
1120 is interrupted, the commands for this target will be executed.
1121 .It Ic .LIBS
1122 This does for libraries what
1123 .Ic .INCLUDES
1124 does for include files, except that the flag used is
1125 .Fl L .
1126 .It Ic .MAIN
1127 If no target is specified when
1128 .Nm
1129 is invoked, this target will be built.
1130 This is always set, either
1131 explicitly, or implicitly when
1132 .Nm
1133 selects the default target, to give the user a way to refer to the default
1134 target on the command line.
1135 .It Ic .MAKEFLAGS
1136 This target provides a way to specify flags for
1137 .Nm
1138 when the makefile is used.
1139 The flags are as if typed to the shell, though the
1140 .Fl f
1141 option will have
1142 no effect.
1143 .It Ic .MFLAGS
1144 Same as above, for backward compatibility.
1145 .\" XXX: NOT YET!!!!
1146 .\" .It Ic .NOTPARALLEL
1147 .\" The named targets are executed in non parallel mode. If no targets are
1148 .\" specified, then all targets are executed in non parallel mode.
1149 .It Ic .NOTPARALLEL
1150 Disable parallel mode.
1151 .It Ic .NO_PARALLEL
1152 Same as above, for compatibility with other
1153 .Nm pmake
1154 variants.
1155 .It Ic .ORDER
1156 The named targets are made in sequence.
1157 .\" XXX: NOT YET!!!!
1158 .\" .It Ic .PARALLEL
1159 .\" The named targets are executed in parallel mode. If no targets are
1160 .\" specified, then all targets are executed in parallel mode.
1161 .It Ic .PATH
1162 The sources are directories which are to be searched for files not
1163 found in the current directory.
1164 If no sources are specified, any previously specified directories are
1165 deleted.
1166 Where possible, use of
1167 .Ic .PATH
1168 is preferred over use of the
1169 .Va VPATH
1170 variable.
1171 .It Ic .PATH\fIsuffix\fR
1172 The sources are directories which are to be searched for suffixed files
1173 not found in the current directory.
1174 The
1175 .Nm
1176 utility
1177 first searches the suffixed search path, before reverting to the default
1178 path if the file is not found there.
1179 This form is required for
1180 .Ic .LIBS
1181 and
1182 .Ic .INCLUDES
1183 to work.
1184 .It Ic .PHONY
1185 Apply the
1186 .Ic .PHONY
1187 attribute to any specified sources.
1188 Targets with this attribute are always
1189 considered to be out of date.
1190 .It Ic .PRECIOUS
1191 Apply the
1192 .Ic .PRECIOUS
1193 attribute to any specified sources.
1194 If no sources are specified, the
1195 .Ic .PRECIOUS
1196 attribute is applied to every
1197 target in the file.
1198 .It Ic .SILENT
1199 Apply the
1200 .Ic .SILENT
1201 attribute to any specified sources.
1202 If no sources are specified, the
1203 .Ic .SILENT
1204 attribute is applied to every
1205 command in the file.
1206 .It Ic .SUFFIXES
1207 Each source specifies a suffix to
1208 .Nm Ns .
1209 If no sources are specified, any previous specified suffices are deleted.
1210 .El
1211 .Sh COMPATIBILITY
1212 Older versions of
1213 .Nm
1214 used
1215 .Ev MAKE
1216 instead of
1217 .Ev MAKEFLAGS .
1218 This was removed for POSIX compatibility.
1219 The internal variable
1220 .Va MAKE
1221 is set to the same value as
1222 .Va .MAKE ;
1223 support for this may be removed in the future.
1224 .Pp
1225 Most of the more esoteric features of
1226 .Nm
1227 should probably be avoided for greater compatibility.
1228 .Sh ENVIRONMENT
1229 The
1230 .Nm
1231 utility uses the following environment variables, if they exist:
1232 .Ev MACHINE ,
1233 .Ev MAKE ,
1234 .Ev MAKEFLAGS ,
1235 .Ev MAKEOBJDIR ,
1236 and
1237 .Ev MAKEOBJDIRPREFIX .
1238 .Sh FILES
1239 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1240 .It Pa .depend
1241 list of dependencies
1242 .It Pa Makefile
1243 list of dependencies
1244 .It Pa makefile
1245 list of dependencies
1246 .It obj
1247 object directory
1248 .It Pa sys.mk
1249 system makefile (processed before any other file, including
1250 .Pa makefile
1251 and
1252 .Pa Makefile )
1253 .It Pa /usr/share/mk
1254 system makefile directory
1255 .It /usr/share/doc/psd/12.make
1256 PMake tutorial
1257 .It Pa /usr/obj
1258 default
1259 .Ev MAKEOBJDIRPREFIX
1260 directory.
1261 .El
1262 .Sh EXAMPLES
1263 List all included makefiles in order visited:
1264 .Pp
1265 .Dl "make -V .MAKEFILE_LIST | tr \e\  \e\en"
1266 .Sh BUGS
1267 The determination of
1268 .Va .OBJDIR
1269 is contorted to the point of absurdity.
1270 .Pp
1271 In the presence of several
1272 .Ic .MAIN
1273 special targets,
1274 .Nm
1275 silently ignores all but the first.
1276 .Pp
1277 .Va .TARGETS
1278 is not set to the default target when
1279 .Nm
1280 is invoked without a target name and no
1281 .Ic .MAIN
1282 special target exists.
1283 .Pp
1284 The evaluation of
1285 .Ar expression
1286 in a test is very simple-minded.
1287 Currently, the only form that works is
1288 .Ql .if ${VAR} op something
1289 For instance, you should write tests as
1290 .Ql .if ${VAR} == "string"
1291 not the other way around, which would give you an error.
1292 .Pp
1293 For loops are expanded before tests, so a fragment such as:
1294 .Bd -literal -offset indent
1295 \&.for ARCH in ${SHARED_ARCHS}
1296 \&.if ${ARCH} == ${MACHINE}
1297      ...
1298 \&.endif
1299 \&.endfor
1300 .Ed
1301 .Pp
1302 won't work, and should be rewritten as:
1303 .Bd -literal -offset indent
1304 \&.for ARCH in ${SHARED_ARCHS}
1305 \&.if ${MACHINE} == ${ARCH} 
1306      ...
1307 \&.endif
1308 \&.endfor
1309 .Ed
1310 .Pp
1311 The parsing code is broken with respect to handling a semicolon
1312 after a colon, so a fragment like this will fail:
1313 .Bd -literal -offset indent
1314 HDRS=   foo.h bar.h
1315
1316 all:
1317 \&.for h in ${HDRS:S;^;${.CURDIR}/;}
1318      ...
1319 \&.endfor
1320 .Ed
1321 .Sh SEE ALSO
1322 .Xr mkdep 1 ,
1323 .Xr make.conf 5
1324 .Rs
1325 .%T "PMake - A Tutorial"
1326 .Re
1327 in
1328 .Pa /usr/share/doc/psd/12.make
1329 .Sh HISTORY
1330 A
1331 .Nm
1332 command appeared in PWB UNIX.