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