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