]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/make/make.1
This commit was generated by cvs2svn to compensate for changes in r174294,
[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 April 8, 2006
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 ABPSXeiknqrstv
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 Fl x Ar warning_options
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 .Pp
66 First of all, the initial list of specifications will be read
67 from the system makefile,
68 .Pa sys.mk ,
69 unless inhibited with the
70 .Fl r
71 option.
72 The standard
73 .Pa sys.mk
74 as shipped with
75 .Fx
76 also handles
77 .Xr make.conf 5 ,
78 the default path to which
79 can be altered via the
80 .Nm
81 variable
82 .Va __MAKE_CONF .
83 .Pp
84 Then the first of
85 .Pa BSDmakefile ,
86 .Pa makefile ,
87 and
88 .Pa Makefile
89 that can be found in the current directory, object directory (see
90 .Va .OBJDIR ) ,
91 or search path (see the
92 .Fl I
93 option)
94 will be read for the main list of dependency specifications.
95 A different makefile or list of them can be supplied via the
96 .Fl f
97 option(s).
98 Finally, if the file
99 .Pa .depend
100 can be found in any of the aforesaid locations, it will also be read (see
101 .Xr mkdep 1 ) .
102 .Pp
103 When
104 .Nm
105 searches for a makefile, its name takes precedence over its location.
106 For instance,
107 .Pa BSDmakefile
108 in the object directory will be favored over
109 .Pa Makefile
110 in the current directory.
111 .Pp
112 The options are as follows:
113 .Bl -tag -width Ds
114 .It Fl A
115 Make archive errors non-fatal, causing
116 .Nm
117 to just skip the remainder
118 or all of the archive and continue after printing a message.
119 .It Fl B
120 Try to be backwards compatible by executing a single shell per command and
121 by executing the commands to make the sources of a dependency line in sequence.
122 This is turned on by default unless
123 .Fl j
124 is used.
125 .It Fl C Ar directory
126 Change to
127 .Ar directory
128 before reading the makefiles or doing anything else.
129 If multiple
130 .Fl C
131 options are specified, each is interpreted relative to the previous one:
132 .Fl C Pa / Fl C Pa etc
133 is equivalent to
134 .Fl C Pa /etc .
135 .It Fl D Ar variable
136 Define
137 .Ar variable
138 to be 1, in the global context.
139 .It Fl d Ar flags
140 Turn on debugging, and specify which portions of
141 .Nm
142 are to print debugging information.
143 Argument
144 .Ar flags
145 is one or more of the following:
146 .Bl -tag -width Ds
147 .It Ar A
148 Print all possible debugging information;
149 equivalent to specifying all of the debugging flags.
150 .It Ar a
151 Print debugging information about archive searching and caching.
152 .It Ar c
153 Print debugging information about conditional evaluation.
154 .It Ar d
155 Print debugging information about directory searching and caching.
156 .It Ar f
157 Print debugging information about the execution of for loops.
158 .It Ar "g1"
159 Print the input graph before making anything.
160 .It Ar "g2"
161 Print the input graph after making everything, or before exiting
162 on error.
163 .It Ar j
164 Print debugging information about running multiple shells.
165 .It Ar l
166 Print commands in Makefiles regardless of whether or not they are prefixed
167 by @ or other "quiet" flags.
168 Also known as "loud" behavior.
169 .It Ar m
170 Print debugging information about making targets, including modification
171 dates.
172 .It Ar s
173 Print debugging information about suffix-transformation rules.
174 .It Ar t
175 Print debugging information about target list maintenance.
176 .It Ar v
177 Print debugging information about variable assignment.
178 .El
179 .It Fl E Ar variable
180 Specify a variable whose environment value (if any) will override
181 macro assignments within makefiles.
182 .It Fl e
183 Specify that environment values override macro assignments within
184 makefiles for all variables.
185 .It Fl f Ar makefile
186 Specify a makefile to read instead of the default one.
187 If
188 .Ar makefile
189 is not an absolute pathname,
190 .Nm
191 will search for it as described above.
192 In case
193 .Ar makefile
194 is
195 .Sq Fl ,
196 standard input is read.
197 Multiple
198 .Fl f
199 options can be supplied,
200 and the makefiles will be read in that order.
201 Unlike the other command-line options,
202 .Fl f
203 is neither stored in
204 .Va .MAKEFLAGS
205 nor pushed down to sub-makes via
206 .Ev MAKEFLAGS .
207 See below for more details on these variables.
208 .It Fl I Ar directory
209 Specify a directory in which to search for makefiles and included makefiles.
210 Multiple
211 .Fl I
212 options can be specified to form a search path.
213 The system makefile directory (or directories, see the
214 .Fl m
215 option) is automatically appended at the tail of this path.
216 .It Fl i
217 Ignore non-zero exit of shell commands in the makefile.
218 Equivalent to specifying
219 .Sq Ic \-
220 before each command line in the makefile.
221 .It Fl j Ar max_jobs
222 Specify the maximum number of jobs that
223 .Nm
224 may have running at any one time.
225 Turns compatibility mode off, unless the
226 .Fl B
227 flag is also specified.
228 .It Fl k
229 Continue processing after errors are encountered, but only on those targets
230 that do not depend on the target whose creation caused the error.
231 .It Fl m Ar directory
232 Specify a directory in which to search for
233 the system makefile and makefiles included via the <...> style.
234 Multiple
235 .Fl m
236 options can be specified to form a search path.
237 This path will override the default system include path,
238 .Pa /usr/share/mk .
239 The system include path will always be appended to the search path used
240 for "..."-style inclusions and makefile searches (see the
241 .Fl I
242 option).
243 .It Fl n
244 Display the commands that would have been executed, but do not actually
245 execute them.
246 .It Fl P
247 Collate the output of a given job and display it only when the job finishes,
248 instead of mixing the output of parallel jobs together.
249 This option has no effect unless
250 .Fl j
251 is used too.
252 .It Fl q
253 Do not execute any commands, but exit 0 if the specified targets are
254 up-to-date and 1, otherwise.
255 .It Fl r
256 Do not process the system makefile.
257 .It Fl S
258 Stop processing when an error is encountered.
259 Default behaviour.
260 This is needed to negate the
261 .Fl k
262 option during recursive builds.
263 .It Fl s
264 Do not echo any commands as they are executed.
265 Equivalent to specifying
266 .Sq Ic @
267 before each command line in the makefile.
268 .It Fl t
269 Rather than re-building a target as specified in the makefile, create it
270 or update its modification time to make it appear up-to-date.
271 .It Fl V Ar variable
272 Print
273 .Nm Ns 's
274 idea of the value of
275 .Ar variable ,
276 in the global context.
277 Do not build any targets.
278 Multiple instances of this option may be specified;
279 the variables will be printed one per line,
280 with a blank line for each null or undefined variable.
281 .It Fl v
282 Be extra verbose.
283 For multi-job makes, this will cause file banners to be generated.
284 .It Fl X
285 When using the
286 .Fl V
287 option to print the values of variables,
288 do not recursively expand the values.
289 .It Ar variable Ns No = Ns Ar value
290 Set the value of the variable
291 .Ar variable
292 to
293 .Ar value .
294 .It Fl x Ar warning_options
295 Specify extended warning options.
296 This option may be specified several times.
297 A
298 .Ar warning_option
299 can be prefixed with
300 .Dq Li no
301 in which case the warning is switched off.
302 The currently available options are:
303 .Bl -tag -width indent
304 .It Li dirsyntax
305 Warn if anything except blanks and comments follows an
306 .Ic .endif
307 or
308 .Ic .else
309 directive.
310 .El
311 .Pp
312 See also the
313 .Ic .WARN
314 special target.
315 .El
316 .Pp
317 There are seven different types of lines in a makefile: file dependency
318 specifications, shell commands, variable assignments, include statements,
319 conditional directives, for loops, and comments.
320 .Pp
321 In general, lines may be continued from one line to the next by ending
322 them with a backslash
323 .Pq Ql \e .
324 The trailing newline character and initial whitespace on the following
325 line are compressed into a single space.
326 .Sh FILE DEPENDENCY SPECIFICATIONS
327 Dependency lines consist of one or more targets, an operator, and zero
328 or more sources.
329 This creates a relationship where the targets
330 .Dq depend
331 on the sources
332 and are usually created from them.
333 The exact relationship between the target and the source is determined
334 by the operator that separates them.
335 The three operators are as follows:
336 .Bl -tag -width flag
337 .It Ic \&:
338 A target is considered out-of-date if its modification time is less than
339 those of any of its sources.
340 Sources for a target accumulate over dependency lines when this operator
341 is used.
342 The target is removed if
343 .Nm
344 is interrupted.
345 .It Ic \&!
346 Targets are always re-created, but not until all sources have been
347 examined and re-created as necessary.
348 Sources for a target accumulate over dependency lines when this operator
349 is used.
350 The target is removed if
351 .Nm
352 is interrupted.
353 .It Ic ::
354 If no sources are specified, the target is always re-created.
355 Otherwise, a target is considered out-of-date if any of its sources has
356 been modified more recently than the target.
357 Sources for a target do not accumulate over dependency lines when this
358 operator is used.
359 The target will not be removed if
360 .Nm
361 is interrupted.
362 .El
363 .Pp
364 Targets and sources may contain the shell wildcard expressions
365 .Ql \&? ,
366 .Ql * ,
367 .Ql []
368 and
369 .Ql {} .
370 The expressions
371 .Ql \&? ,
372 .Ql *
373 and
374 .Ql []
375 may only be used as part of the final
376 component of the target or source, and must be used to describe existing
377 files.
378 The expression
379 .Ql {}
380 need not necessarily be used to describe existing files.
381 Expansion is in directory order, not alphabetically as done in the shell.
382 .Sh SHELL COMMANDS
383 Each target may have associated with it a series of shell commands, normally
384 used to create the target.
385 Each of the commands in this script
386 .Em must
387 be preceded by a tab.
388 While any target may appear on a dependency line, only one of these
389 dependencies may be followed by a creation script, unless the
390 .Sq Ic ::
391 operator is used.
392 .Pp
393 If the first characters of the command line are
394 .Sq Ic @ ,
395 .Sq Ic \- ,
396 and/or
397 .Sq Ic + ,
398 the command is treated specially.
399 A
400 .Sq Ic @
401 causes the command not to be echoed before it is executed.
402 A
403 .Sq Ic \-
404 causes any non-zero exit status of the command line to be ignored.
405 A
406 .Sq Ic +
407 causes the command to be executed even if
408 .Fl n
409 is specified on the command line.
410 .Sh VARIABLE ASSIGNMENTS
411 Variables in
412 .Nm
413 are much like variables in the shell, and, by tradition,
414 consist of all upper-case letters.
415 The five operators that can be used to assign values to variables are as
416 follows:
417 .Bl -tag -width Ds
418 .It Ic =
419 Assign the value to the variable.
420 Any previous value is overridden.
421 .It Ic +=
422 Append the value to the current value of the variable.
423 .It Ic ?=
424 Assign the value to the variable if it is not already defined.
425 .It Ic :=
426 Assign with expansion, i.e., expand the value before assigning it
427 to the variable.
428 Normally, expansion is not done until the variable is referenced.
429 .It Ic !=
430 Expand the value and pass it to the shell for execution and assign
431 the result to the variable.
432 Any newlines in the result are replaced with spaces.
433 .El
434 .Pp
435 Any whitespace before the assigned
436 .Ar value
437 is removed; if the value is being appended, a single space is inserted
438 between the previous contents of the variable and the appended value.
439 .Pp
440 Variables are expanded by surrounding the variable name with either
441 curly braces
442 .Pq Ql {}
443 or parentheses
444 .Pq Ql ()
445 and preceding it with
446 a dollar sign
447 .Pq Ql $ .
448 If the variable name contains only a single letter, the surrounding
449 braces or parentheses are not required.
450 This shorter form is not recommended.
451 .Pp
452 Variable substitution occurs at two distinct times, depending on where
453 the variable is being used.
454 Variables in dependency lines are expanded as the line is read.
455 Variables in shell commands are expanded when the shell command is
456 executed.
457 .Pp
458 The four different classes of variables (in order of increasing precedence)
459 are:
460 .Bl -tag -width Ds
461 .It Environment variables
462 Variables defined as part of
463 .Nm Ns 's
464 environment.
465 .It Global variables
466 Variables defined in the makefile or in included makefiles.
467 .It Command line variables
468 Variables defined as part of the command line and variables
469 obtained from the
470 .Ev MAKEFLAGS
471 environment variable or the
472 .Ic .MAKEFLAGS
473 target.
474 .It Local variables
475 Variables that are defined specific to a certain target.
476 .El
477 .Pp
478 If the name of an environment variable appears in a makefile
479 on the left-hand side of an assignment,
480 a global variable with the same name is created, and the latter
481 shadows the former as per their relative precedences.
482 The environment is not changed in this case, and the change
483 is not exported to programs executed by
484 .Nm .
485 However, a command-line variable actually replaces
486 the environment variable of the same name if the latter exists,
487 which is visible to child programs.
488 .Pp
489 There are seven local variables in
490 .Nm :
491 .Bl -tag -width ".ARCHIVE"
492 .It Va .ALLSRC
493 The list of all sources for this target; also known as
494 .Sq Va > .
495 .It Va .ARCHIVE
496 The name of the archive file; also known as
497 .Sq Va \&! .
498 .It Va .IMPSRC
499 The name/path of the source from which the target is to be transformed
500 (the
501 .Dq implied
502 source); also known as
503 .Sq Va < .
504 .It Va .MEMBER
505 The name of the archive member; also known as
506 .Sq Va % .
507 .It Va .OODATE
508 The list of sources for this target that were deemed out-of-date; also
509 known as
510 .Sq Va \&? .
511 .It Va .PREFIX
512 The file prefix of the file, containing only the file portion, no suffix
513 or preceding directory components; also known as
514 .Sq Va * .
515 .It Va .TARGET
516 The name of the target; also known as
517 .Sq Va @ .
518 .El
519 .Pp
520 The shorter forms
521 .Sq Va @ ,
522 .Sq Va \&! ,
523 .Sq Va < ,
524 .Sq Va % ,
525 .Sq Va \&? ,
526 .Sq Va > ,
527 and
528 .Sq Va *
529 are permitted for backward
530 compatibility and are not recommended.
531 The six variables
532 .Sq Va @F ,
533 .Sq Va @D ,
534 .Sq Va <F ,
535 .Sq Va <D ,
536 .Sq Va *F ,
537 and
538 .Sq Va *D
539 are
540 permitted for compatibility with
541 .At V
542 makefiles and are not recommended.
543 .Pp
544 Four of the local variables may be used in sources on dependency lines
545 because they expand to the proper value for each target on the line.
546 These variables are
547 .Va .TARGET ,
548 .Va .PREFIX ,
549 .Va .ARCHIVE ,
550 and
551 .Va .MEMBER .
552 .Pp
553 In addition,
554 .Nm
555 sets or knows about the following internal variables or environment
556 variables:
557 .Bl -tag -width ".Va .MAKEFILE_LIST"
558 .It Va $
559 A single dollar sign
560 .Ql $ ,
561 i.e.\&
562 .Ql $$
563 expands to a single dollar
564 sign.
565 .It Va MAKE
566 The name that
567 .Nm
568 was executed with
569 .Pq Va argv Ns Op 0 .
570 .It Va .CURDIR
571 A path to the directory where
572 .Nm
573 was executed.
574 The
575 .Nm
576 utility sets
577 .Va .CURDIR
578 to the canonical path given by
579 .Xr getcwd 3 .
580 .It Va .OBJDIR
581 A path to the directory where the targets are built.
582 At startup,
583 .Nm
584 searches for an alternate directory to place target files.
585 It will attempt to change into this special directory
586 and will search this directory for makefiles
587 not found in the current directory.
588 The following directories are tried in order:
589 .Pp
590 .Bl -enum -compact
591 .It
592 ${MAKEOBJDIRPREFIX}/`pwd`
593 .It
594 ${MAKEOBJDIR}
595 .It
596 obj.${MACHINE}
597 .It
598 obj
599 .It
600 /usr/obj/`pwd`
601 .El
602 .Pp
603 The first directory that
604 .Nm
605 successfully changes into is used.
606 If either
607 .Ev MAKEOBJDIRPREFIX
608 or
609 .Ev MAKEOBJDIR
610 is set in the environment but
611 .Nm
612 is unable to change into the corresponding directory,
613 then the current directory is used
614 without checking the remainder of the list.
615 If they are undefined and
616 .Nm
617 is unable to change into any of the remaining three directories,
618 then the current directory is used.
619 Note, that
620 .Ev MAKEOBJDIRPREFIX
621 and
622 .Ev MAKEOBJDIR
623 must be environment variables and should not be set on
624 .Nm Ns 's
625 command line.
626 .Pp
627 The
628 .Nm
629 utility sets
630 .Va .OBJDIR
631 to the canonical path given by
632 .Xr getcwd 3 .
633 .It Va .MAKEFILE_LIST
634 As
635 .Nm
636 reads various makefiles, including the default files and any
637 obtained from the command line and
638 .Ic .include
639 and
640 .Ic .sinclude
641 directives, their names will be automatically appended to the
642 .Va .MAKEFILE_LIST
643 variable.
644 They are added right before
645 .Nm
646 begins to parse them, so that the name of the current makefile is the
647 last word in this variable.
648 .It Va .MAKEFLAGS
649 The environment variable
650 .Ev MAKEFLAGS
651 may contain anything that
652 may be specified on
653 .Nm Ns 's
654 command line,
655 including
656 .Fl f
657 option(s).
658 Its contents are stored in
659 .Nm Ns 's
660 .Va .MAKEFLAGS
661 variable.
662 All options and variable assignments specified on
663 .Nm Ns 's
664 command line, except for
665 .Fl f ,
666 are appended to the
667 .Va .MAKEFLAGS
668 variable which is then
669 entered into the environment as
670 .Ev MAKEFLAGS
671 for all programs which
672 .Nm
673 executes.
674 .Pp
675 By modifying the contents of the
676 .Va .MAKEFLAGS
677 variable, a makefile can alter the contents of the
678 .Ev MAKEFLAGS
679 environment variable made available for all programs which
680 .Nm
681 executes.
682 (This includes adding or modifying
683 .Fl f
684 option(s).)
685 Note that any options entered to
686 .Va .MAKEFLAGS
687 neither affect the current instance of
688 .Nm
689 nor show up in its own copy of
690 .Ev MAKEFLAGS
691 instantly.
692 However, they do show up in the
693 .Ev MAKEFLAGS
694 environment variable of programs executed by
695 .Nm .
696 On the other hand, a direct assignment to
697 .Ev MAKEFLAGS
698 neither affects the current instance of
699 .Nm
700 nor is passed down to
701 .Nm Ns 's
702 children.
703 Compare with the
704 .Ic .MAKEFLAGS
705 special target below.
706 .Pp
707 To sum up what was said on
708 .Fl f ,
709 it can appear in
710 .Va .MAKEFLAGS
711 and affect the current
712 .Nm
713 at the same time only if inherited from
714 .Ev MAKEFLAGS
715 in 
716 .Nm Ns 's
717 initial environment.
718 On the other hand, a
719 .Fl f
720 option from
721 .Nm Ns 's
722 command line
723 does affect
724 .Nm ,
725 but it is never transferred to
726 .Va .MAKEFLAGS
727 or further.
728 .Pp
729 When passing macro definitions and flag arguments in the
730 .Ev MAKEFLAGS
731 environment variable,
732 space and tab characters are quoted by preceding them with a backslash.
733 When reading the
734 .Ev MAKEFLAGS
735 variable from the environment,
736 all sequences of a backslash and one of space or tab
737 are replaced just with their second character
738 without causing a word break.
739 Any other occurrences of a backslash are retained.
740 Groups of unquoted space, tab and newline characters cause word
741 breaking.
742 .It Va MFLAGS
743 This variable is provided for backward compatibility and
744 contains all the options from the
745 .Ev MAKEFLAGS
746 environment variable plus any options specified on
747 .Nm Ns 's
748 command line.
749 .It Va .TARGETS
750 List of targets
751 .Nm
752 is currently building.
753 .It Va .INCLUDES
754 See
755 .Ic .INCLUDES
756 special target.
757 .It Va .LIBS
758 See
759 .Ic .LIBS
760 special target.
761 .It Va MACHINE
762 Name of the machine architecture
763 .Nm
764 is running on, obtained from the
765 .Ev MACHINE
766 environment variable, or through
767 .Xr uname 3
768 if not defined.
769 .It Va MACHINE_ARCH
770 Name of the machine architecture
771 .Nm
772 was compiled for, defined at compilation time.
773 .It Va VPATH
774 Makefiles may assign a colon-delimited list of directories to
775 .Va VPATH .
776 These directories will be searched for source files by
777 .Nm
778 after it has finished parsing all input makefiles.
779 .El
780 .Pp
781 Variable expansion may be modified to select or modify each word of the
782 variable (where a
783 .Dq word
784 is whitespace-delimited sequence of characters).
785 The general format of a variable expansion is as follows:
786 .Pp
787 .Dl {variable[:modifier[:...]]}
788 .Pp
789 Each modifier begins with a colon and one of the following
790 special characters.
791 The colon may be escaped with a backslash
792 .Pq Ql \e .
793 .Bl -tag -width Cm
794 .Sm off
795 .It Cm C No / Ar pattern Xo
796 .No / Ar replacement
797 .No / Op Cm 1g
798 .Xc
799 .Sm on
800 Modify each word of the value,
801 substituting every match of the extended regular expression
802 .Ar pattern
803 (see
804 .Xr re_format 7 )
805 with the
806 .Xr ed 1 Ns \-style
807 .Ar replacement
808 string.
809 Normally, the first occurrence of the pattern in
810 each word of the value is changed.
811 The
812 .Ql 1
813 modifier causes the substitution to apply to at most one word; the
814 .Ql g
815 modifier causes the substitution to apply to as many instances of the
816 search pattern as occur in the word or words it is found in.
817 Note that
818 .Ql 1
819 and
820 .Ql g
821 are orthogonal; the former specifies whether multiple words are
822 potentially affected, the latter whether multiple substitutions can
823 potentially occur within each affected word.
824 .It Cm E
825 Replaces each word in the variable with its suffix.
826 .It Cm H
827 Replaces each word in the variable with everything but the last component.
828 .It Cm L
829 Converts variable to lower-case letters.
830 .It Cm M Ns Ar pattern
831 Select only those words that match the rest of the modifier.
832 The standard shell wildcard characters
833 .Pf ( Ql * ,
834 .Ql \&? ,
835 and
836 .Ql [] )
837 may
838 be used.
839 The wildcard characters may be escaped with a backslash
840 .Pq Ql \e .
841 .It Cm N Ns Ar pattern
842 This is identical to
843 .Cm M ,
844 but selects all words which do not match
845 the rest of the modifier.
846 .It Cm O
847 Order every word in the variable alphabetically.
848 .It Cm Q
849 Quotes every shell meta-character in the variable, so that it can be passed
850 safely through recursive invocations of
851 .Nm .
852 .It Cm R
853 Replaces each word in the variable with everything but its suffix.
854 .Sm off
855 .It Cm S No / Ar old_string Xo
856 .No / Ar new_string
857 .No / Op Cm g
858 .Xc
859 .Sm on
860 Modify the first occurrence of
861 .Ar old_string
862 in each word of the variable's value, replacing it with
863 .Ar new_string .
864 If a
865 .Ql g
866 is appended to the last slash of the pattern, all occurrences
867 in each word are replaced.
868 If
869 .Ar old_string
870 begins with a caret
871 .Pq Ql ^ ,
872 .Ar old_string
873 is anchored at the beginning of each word.
874 If
875 .Ar old_string
876 ends with a dollar sign
877 .Pq Ql $ ,
878 it is anchored at the end of each word.
879 Inside
880 .Ar new_string ,
881 an ampersand
882 .Pq Ql &
883 is replaced by
884 .Ar old_string .
885 Any character may be used as a delimiter for the parts of the modifier
886 string.
887 The anchoring, ampersand, and delimiter characters may be escaped with a
888 backslash
889 .Pq Ql \e .
890 .Pp
891 Variable expansion occurs in the normal fashion inside both
892 .Ar old_string
893 and
894 .Ar new_string
895 with the single exception that a backslash is used to prevent the expansion
896 of a dollar sign
897 .Pq Ql $ ,
898 not a preceding dollar sign as is usual.
899 .It Ar old_string=new_string
900 This is the
901 .At V
902 style variable substitution.
903 It must be the last modifier specified.
904 If
905 .Ar old_string
906 or
907 .Ar new_string
908 do not contain the pattern matching character
909 .Ar %
910 then it is assumed that they are
911 anchored at the end of each word, so only suffixes or entire
912 words may be replaced.
913 Otherwise
914 .Ar %
915 is the substring of
916 .Ar old_string
917 to be replaced in
918 .Ar new_string
919 .It Cm T
920 Replaces each word in the variable with its last component.
921 .It Cm U
922 Converts variable to upper-case letters.
923 .It Cm u
924 Remove adjacent duplicate words (like
925 .Xr uniq 1 ) .
926 .El
927 .Sh DIRECTIVES, CONDITIONALS, AND FOR LOOPS
928 Directives, conditionals, and for loops reminiscent
929 of the C programming language are provided in
930 .Nm .
931 All such structures are identified by a line beginning with a single
932 dot
933 .Pq Ql \&.
934 character.
935 The following directives are supported:
936 .Bl -tag -width Ds
937 .It Ic .include Ar <file>
938 .It Ic .include Ar \*qfile\*q
939 Include the specified makefile.
940 Variables between the angle brackets
941 or double quotes are expanded to form the file name.
942 If angle brackets
943 are used, the included makefile is expected to be in the system
944 makefile directory.
945 If double quotes are used, the including
946 makefile's directory and any directories specified using the
947 .Fl I
948 option are searched before the system
949 makefile directory.
950 .It Ic .sinclude Ar <file>
951 .It Ic .sinclude Ar \*qfile\*q
952 Like
953 .Ic .include ,
954 but silently ignored if the file cannot be found and opened.
955 .It Ic .undef Ar variable
956 Un-define the specified global variable.
957 Only global variables may be un-defined.
958 .It Ic .error Ar message
959 Terminate processing of the makefile immediately.
960 The filename of the
961 makefile, the line on which the error was encountered and the specified
962 message are printed to the standard error output and
963 .Nm
964 terminates with exit code 1.
965 Variables in the message are expanded.
966 .It Ic .warning Ar message
967 Emit a warning message.
968 The filename of the makefile,
969 the line on which the warning was encountered,
970 and the specified message are printed to the standard error output.
971 Variables in the message are expanded.
972 .El
973 .Pp
974 Conditionals are used to determine which parts of the Makefile
975 to process.
976 They are used similarly to the conditionals supported
977 by the C pre-processor.
978 The following conditionals are supported:
979 .Bl -tag -width Ds
980 .It Xo
981 .Ic .if
982 .Oo \&! Oc Ns Ar expression
983 .Op Ar operator expression ...
984 .Xc
985 Test the value of an expression.
986 .It Xo
987 .Ic .ifdef
988 .Oo \&! Oc Ns Ar variable
989 .Op Ar operator variable ...
990 .Xc
991 Test the value of a variable.
992 .It Xo
993 .Ic .ifndef
994 .Oo \&! Oc Ns Ar variable
995 .Op Ar operator variable ...
996 .Xc
997 Test the value of a variable.
998 .It Xo
999 .Ic .ifmake
1000 .Oo \&! Oc Ns Ar target
1001 .Op Ar operator target ...
1002 .Xc
1003 Test the target being built.
1004 .It Xo
1005 .Ic .ifnmake
1006 .Oo \&! Oc Ns Ar target
1007 .Op Ar operator target ...
1008 .Xc
1009 Test the target being built.
1010 .It Ic .else
1011 Reverse the sense of the last conditional.
1012 .It Xo
1013 .Ic .elif
1014 .Oo \&! Oc Ns Ar expression
1015 .Op Ar operator expression ...
1016 .Xc
1017 A combination of
1018 .Ic .else
1019 followed by
1020 .Ic .if .
1021 .It Xo
1022 .Ic .elifdef
1023 .Oo \&! Oc Ns Ar variable
1024 .Op Ar operator variable ...
1025 .Xc
1026 A combination of
1027 .Ic .else
1028 followed by
1029 .Ic .ifdef .
1030 .It Xo
1031 .Ic .elifndef
1032 .Oo \&! Oc Ns Ar variable
1033 .Op Ar operator variable ...
1034 .Xc
1035 A combination of
1036 .Ic .else
1037 followed by
1038 .Ic .ifndef .
1039 .It Xo
1040 .Ic .elifmake
1041 .Oo \&! Oc Ns Ar target
1042 .Op Ar operator target ...
1043 .Xc
1044 A combination of
1045 .Ic .else
1046 followed by
1047 .Ic .ifmake .
1048 .It Xo
1049 .Ic .elifnmake
1050 .Oo \&! Oc Ns Ar target
1051 .Op Ar operator target ...
1052 .Xc
1053 A combination of
1054 .Ic .else
1055 followed by
1056 .Ic .ifnmake .
1057 .It Ic .endif
1058 End the body of the conditional.
1059 .El
1060 .Pp
1061 The
1062 .Ar operator
1063 may be any one of the following:
1064 .Bl -tag -width "Cm XX"
1065 .It Cm ||
1066 logical
1067 .Tn OR
1068 .It Cm &&
1069 Logical
1070 .Tn AND ;
1071 of higher precedence than
1072 .Sq Ic || .
1073 .El
1074 .Pp
1075 As in C,
1076 .Nm
1077 will only evaluate a conditional as far as is necessary to determine
1078 its value.
1079 Parentheses may be used to change the order of evaluation.
1080 The boolean operator
1081 .Sq Ic !\&
1082 may be used to logically negate an entire
1083 conditional.
1084 It is of higher precedence than
1085 .Sq Ic && .
1086 .Pp
1087 The value of
1088 .Ar expression
1089 may be any of the following:
1090 .Bl -tag -width Ic
1091 .It Ic defined
1092 Takes a variable name as an argument and evaluates to true if the variable
1093 has been defined.
1094 .It Ic make
1095 Takes a target name as an argument and evaluates to true if the target
1096 was specified as part of
1097 .Nm Ns 's
1098 command line or was declared the default target (either implicitly or
1099 explicitly, see
1100 .Va .MAIN )
1101 before the line containing the conditional.
1102 .It Ic empty
1103 Takes a variable, with possible modifiers, and evaluates to true if
1104 the expansion of the variable would result in an empty string.
1105 .It Ic exists
1106 Takes a file name as an argument and evaluates to true if the file exists.
1107 The file is searched for on the system search path (see
1108 .Va .PATH ) .
1109 .It Ic target
1110 Takes a target name as an argument and evaluates to true if the target
1111 has been defined.
1112 .El
1113 .Pp
1114 An
1115 .Ar expression
1116 may also be an arithmetic or string comparison, with the left-hand side
1117 being a variable expansion.
1118 Variable expansion is
1119 performed on both sides of the comparison, after which the integral
1120 values are compared.
1121 A value is interpreted as hexadecimal if it is
1122 preceded by 0x, otherwise it is decimal; octal numbers are not supported.
1123 The standard C relational operators are all supported.
1124 If after
1125 variable expansion, either the left or right hand side of a
1126 .Sq Ic ==
1127 or
1128 .Sq Ic !=
1129 operator is not an integral value, then
1130 string comparison is performed between the expanded
1131 variables.
1132 If no relational operator is given, it is assumed that the expanded
1133 variable is being compared against 0.
1134 .Pp
1135 When
1136 .Nm
1137 is evaluating one of these conditional expressions, and it encounters
1138 a word it does not recognize, either the
1139 .Dq make
1140 or
1141 .Dq defined
1142 expression is applied to it, depending on the form of the conditional.
1143 If the form is
1144 .Ic .if ,
1145 .Ic .ifdef
1146 or
1147 .Ic .ifndef ,
1148 the
1149 .Dq defined
1150 expression is applied.
1151 Similarly, if the form is
1152 .Ic .ifmake
1153 or
1154 .Ic .ifnmake ,
1155 the
1156 .Dq make
1157 expression is applied.
1158 .Pp
1159 If the conditional evaluates to true the parsing of the makefile continues
1160 as before.
1161 If it evaluates to false, the following lines are skipped.
1162 In both cases this continues until a
1163 .Ic .else
1164 or
1165 .Ic .endif
1166 is found.
1167 .Pp
1168 For loops are typically used to apply a set of rules to a list of files.
1169 The syntax of a for loop is:
1170 .Pp
1171 .Bl -tag -width indent -compact
1172 .It Ic .for Ar variable Ic in Ar expression
1173 .It <make-rules>
1174 .It Ic .endfor
1175 .El
1176 .Pp
1177 After the for
1178 .Ar expression
1179 is evaluated, it is split into words.
1180 The
1181 iteration
1182 .Ar variable
1183 is successively set to each word, and substituted in the
1184 .Ic make-rules
1185 inside the body of the for loop.
1186 .Sh COMMENTS
1187 Comments begin with a hash
1188 .Pq Ql #
1189 character, anywhere but in a shell
1190 command line, and continue to the end of the line.
1191 .Sh SPECIAL SOURCES
1192 .Bl -tag -width Ic
1193 .It Ic .IGNORE
1194 Ignore any errors from the commands associated with this target, exactly
1195 as if they all were preceded by a dash
1196 .Pq Ql \- .
1197 .It Ic .MAKE
1198 Execute the commands associated with this target even if the
1199 .Fl n
1200 or
1201 .Fl t
1202 options were specified.
1203 Normally used to mark recursive
1204 .Nm Ns 's .
1205 .It Ic .NOTMAIN
1206 Normally
1207 .Nm
1208 selects the first target it encounters as the default target to be built
1209 if no target was specified.
1210 This source prevents this target from being selected.
1211 .It Ic .OPTIONAL
1212 If a target is marked with this attribute and
1213 .Nm
1214 cannot figure out how to create it, it will ignore this fact and assume
1215 the file is not needed or already exists.
1216 .It Ic .PRECIOUS
1217 When
1218 .Nm
1219 is interrupted, it removes any partially made targets.
1220 This source prevents the target from being removed.
1221 .It Ic .SILENT
1222 Do not echo any of the commands associated with this target, exactly
1223 as if they all were preceded by an at sign
1224 .Pq Ql @ .
1225 .It Ic .USE
1226 Turn the target into
1227 .Nm Ns 's
1228 version of a macro.
1229 When the target is used as a source for another target, the other target
1230 acquires the commands, sources, and attributes (except for
1231 .Ic .USE )
1232 of the
1233 source.
1234 If the target already has commands, the
1235 .Ic .USE
1236 target's commands are appended
1237 to them.
1238 .It Ic .WAIT
1239 If special
1240 .Ic .WAIT
1241 source appears in a dependency line, the sources that precede it are
1242 made before the sources that succeed it in the line.
1243 Loops are not being
1244 detected and targets that form loops will be silently ignored.
1245 .El
1246 .Sh "SPECIAL TARGETS"
1247 Special targets may not be included with other targets, i.e., they must be
1248 the only target specified.
1249 .Bl -tag -width Ic
1250 .It Ic .BEGIN
1251 Any command lines attached to this target are executed before anything
1252 else is done.
1253 .It Ic .DEFAULT
1254 This is sort of a
1255 .Ic .USE
1256 rule for any target (that was used only as a
1257 source) that
1258 .Nm
1259 cannot figure out any other way to create.
1260 Only the shell script is used.
1261 The
1262 .Ic .IMPSRC
1263 variable of a target that inherits
1264 .Ic .DEFAULT Ns 's
1265 commands is set
1266 to the target's own name.
1267 .It Ic .END
1268 Any command lines attached to this target are executed after everything
1269 else is done.
1270 .It Ic .IGNORE
1271 Mark each of the sources with the
1272 .Ic .IGNORE
1273 attribute.
1274 If no sources are specified, this is the equivalent of specifying the
1275 .Fl i
1276 option.
1277 .It Ic .INCLUDES
1278 A list of suffixes that indicate files that can be included in a source
1279 file.
1280 The suffix must have already been declared with
1281 .Ic .SUFFIXES ;
1282 any suffix so declared will have the directories on its search path (see
1283 .Ic .PATH )
1284 placed in the
1285 .Va .INCLUDES
1286 special variable, each preceded by a
1287 .Fl I
1288 flag.
1289 .It Ic .INTERRUPT
1290 If
1291 .Nm
1292 is interrupted, the commands for this target will be executed.
1293 .It Ic .LIBS
1294 This does for libraries what
1295 .Ic .INCLUDES
1296 does for include files, except that the flag used is
1297 .Fl L .
1298 .It Ic .MAIN
1299 If no target is specified when
1300 .Nm
1301 is invoked, this target will be built.
1302 This is always set, either
1303 explicitly, or implicitly when
1304 .Nm
1305 selects the default target, to give the user a way to refer to the default
1306 target on the command line.
1307 .It Ic .MAKEFLAGS
1308 This target provides a way to specify flags for
1309 .Nm
1310 when the makefile is used.
1311 The flags are as if typed to the shell, though the
1312 .Fl f
1313 option will have
1314 no effect.
1315 Flags (except for
1316 .Fl f )
1317 and variable assignments specified as the source
1318 for this target are also appended to the
1319 .Va .MAKEFLAGS
1320 internal variable.
1321 Please note the difference between this target and the
1322 .Va .MAKEFLAGS
1323 internal variable: specifying an option or variable
1324 assignment as the source for this target will affect
1325 .Em both
1326 the current makefile and all processes that
1327 .Nm
1328 executes.
1329 .It Ic .MFLAGS
1330 Same as above, for backward compatibility.
1331 .\" XXX: NOT YET!!!!
1332 .\" .It Ic .NOTPARALLEL
1333 .\" The named targets are executed in non parallel mode. If no targets are
1334 .\" specified, then all targets are executed in non parallel mode.
1335 .It Ic .NOTPARALLEL
1336 Disable parallel mode.
1337 .It Ic .NO_PARALLEL
1338 Same as above, for compatibility with other
1339 .Nm pmake
1340 variants.
1341 .It Ic .ORDER
1342 The named targets are made in sequence.
1343 .\" XXX: NOT YET!!!!
1344 .\" .It Ic .PARALLEL
1345 .\" The named targets are executed in parallel mode. If no targets are
1346 .\" specified, then all targets are executed in parallel mode.
1347 .It Ic .PATH
1348 The sources are directories which are to be searched for files not
1349 found in the current directory.
1350 If no sources are specified, any previously specified directories are
1351 deleted.
1352 Where possible, use of
1353 .Ic .PATH
1354 is preferred over use of the
1355 .Va VPATH
1356 variable.
1357 .It Ic .PATH\fIsuffix\fR
1358 The sources are directories which are to be searched for suffixed files
1359 not found in the current directory.
1360 The
1361 .Nm
1362 utility
1363 first searches the suffixed search path, before reverting to the default
1364 path if the file is not found there.
1365 This form is required for
1366 .Ic .LIBS
1367 and
1368 .Ic .INCLUDES
1369 to work.
1370 .It Ic .PHONY
1371 Apply the
1372 .Ic .PHONY
1373 attribute to any specified sources.
1374 Targets with this attribute are always
1375 considered to be out of date.
1376 .It Ic .PRECIOUS
1377 Apply the
1378 .Ic .PRECIOUS
1379 attribute to any specified sources.
1380 If no sources are specified, the
1381 .Ic .PRECIOUS
1382 attribute is applied to every
1383 target in the file.
1384 .It Ic .SHELL
1385 Select another shell.
1386 The sources of this target have the format
1387 .Ar key Ns = Ns Ar value .
1388 The
1389 .Ar key
1390 is one of:
1391 .Bl -tag -width ".Va hasErrCtl"
1392 .It Va path
1393 Specify the path to the new shell.
1394 .It Va name
1395 Specify the name of the new shell.
1396 This may be either one of the three builtin shells (see below) or any
1397 other name.
1398 .It Va quiet
1399 Specify the shell command to turn echoing off.
1400 .It Va echo
1401 Specify the shell command to turn echoing on.
1402 .It Va filter
1403 Usually shells print the echo off command before turning echoing off.
1404 This is the exact string that will be printed by the shell and is used
1405 to filter the shell output to remove the echo off command.
1406 .It Va echoFlag
1407 The shell option that turns echoing on.
1408 .It Va errFlag
1409 The shell option to turn on error checking.
1410 If error checking is on, the shell should exit if a command returns
1411 a non-zero status.
1412 .It Va hasErrCtl
1413 True if the shell has error control.
1414 .It Va check
1415 If
1416 .Va hasErrCtl
1417 is true then this is the shell command to turn error checking on.
1418 If
1419 .Va hasErrCtl
1420 is false then this is a command template to echo commands for which error
1421 checking is disabled.
1422 The template must contain a
1423 .Ql %s .
1424 .It Va ignore
1425 If
1426 .Va hasErrCtl
1427 is true, this is the shell command to turn error checking off.
1428 If
1429 .Va hasErrCtl
1430 is false, this is a command template to execute a command so that errors
1431 are ignored.
1432 The template must contain a
1433 .Ql %s .
1434 .It Va meta
1435 This is a string of meta characters of the shell.
1436 .It Va builtins
1437 This is a string holding all the shell's builtin commands separated by blanks.
1438 The
1439 .Va meta
1440 and
1441 .Va builtins
1442 strings are used in compat mode.
1443 When a command line contains neither a meta
1444 character nor starts with a shell builtin, it is executed directly without
1445 invoking a shell.
1446 When one of these strings (or both) is empty all commands are executed
1447 through a shell.
1448 .It Va unsetenv
1449 If true, remove the
1450 .Ev ENV
1451 environment variable before executing any command.
1452 This is useful for the Korn-shell
1453 .Pq Nm ksh .
1454 .El
1455 .Pp
1456 Values that are strings must be surrounded by double quotes.
1457 Boolean values are specified as
1458 .Ql T
1459 or
1460 .Ql Y
1461 (in either case) to mean true.
1462 Any other value is taken to mean false.
1463 .Pp
1464 There are several uses of the
1465 .Ic .SHELL
1466 target:
1467 .Bl -bullet
1468 .It
1469 Selecting one of the builtin shells.
1470 This is done by just specifying the name of the shell with the
1471 .Va name
1472 keyword.
1473 It is also possible to modify the parameters of the builtin shell by just
1474 specifying other keywords (except for
1475 .Va path ) .
1476 .It
1477 Using another executable for one of the builtin shells.
1478 This is done by specifying the path to the executable with the
1479 .Va path
1480 keyword.
1481 If the last component is the same as the name of the builtin shell, no
1482 name needs to be specified; if it is different, the name must be given:
1483 .Bd -literal -offset indent
1484 \&.SHELL: path="/usr/local/bin/sh"
1485 .Ed
1486 .Pp
1487 selects the builtin shell
1488 .Dq Li sh
1489 but will execute it from
1490 .Pa /usr/local/bin/sh .
1491 Like in the previous case, it is possible to modify parameters of the builtin
1492 shell by just specifying them.
1493 .It
1494 Using an entirely different shell.
1495 This is done by specifying all keywords.
1496 .El
1497 .Pp
1498 The builtin shells are
1499 .Dq Li sh ,
1500 .Dq Li csh
1501 and
1502 .Dq Li ksh .
1503 Because
1504 .Fx
1505 has no
1506 .Nm ksh
1507 in
1508 .Pa /bin ,
1509 it is unwise to specify
1510 .Va name Ns = Ns Qq Li ksh
1511 without also specifying a path.
1512 .It Ic .SILENT
1513 Apply the
1514 .Ic .SILENT
1515 attribute to any specified sources.
1516 If no sources are specified, the
1517 .Ic .SILENT
1518 attribute is applied to every
1519 command in the file.
1520 .It Ic .SUFFIXES
1521 Each source specifies a suffix to
1522 .Nm .
1523 If no sources are specified, any previous specified suffices are deleted.
1524 .It Ic .WARN
1525 Each source specifies a warning flag as previously described for the
1526 .Fl x
1527 command line option.
1528 Warning flags specified on the command line take precedence over flags
1529 specified in the makefile.
1530 Also, command line warning flags are pushed to sub-makes through the
1531 .Ev MAKEFLAGS
1532 environment variables so that a warning flag specified on the command
1533 line will influence all sub-makes.
1534 Several flags can be specified on a single
1535 .Ic .WARN
1536 target by seperating them with blanks.
1537 .El
1538 .Sh REMAKING MAKEFILES
1539 After reading Makefile and all the files that are included using
1540 .Ic .include
1541 or
1542 .Ic .sinclude
1543 directives (source Makefiles)
1544 .Nm
1545 considers each source Makefile as a target and tries to rebuild it.
1546 Both explicit and implicit rules are checked and all source Makefiles
1547 are updated if necessary. If any of the source Makefiles were rebuilt,
1548 .Nm
1549 restarts from clean state.
1550 .Pp
1551 To prevent infinite loops the following source Makefile targets are ignored:
1552 .Bl -bullet
1553 .It
1554 .Ic ::
1555 targets that have no prerequisites but have commands
1556 .It
1557 .Ic !
1558 targets
1559 .It
1560 targets that have
1561 .Ic .PHONY
1562 or
1563 .Ic .EXEC
1564 attributes
1565 .It
1566 targets without prerequisites and without commands
1567 .El
1568 .Pp
1569 When remaking a source Makefile options
1570 .Ic -t
1571 (touch target),
1572 .Ic -q
1573 (query mode), and
1574 .Ic -n
1575 (no exec) do not take effect, unless source Makefile is specified
1576 explicitly as a target in
1577 .Nm
1578 command line.
1579 .Pp
1580 Additionally, system makefiles and
1581 .Ic .depend
1582 are not considered as Makefiles that can be rebuilt.
1583 .Sh ENVIRONMENT
1584 The
1585 .Nm
1586 utility uses the following environment variables, if they exist:
1587 .Ev MACHINE ,
1588 .Ev MAKE ,
1589 .Ev MAKEFLAGS ,
1590 .Ev MAKEOBJDIR ,
1591 and
1592 .Ev MAKEOBJDIRPREFIX .
1593 .Sh FILES
1594 .Bl -tag -width /usr/share/doc/psd/12.make -compact
1595 .It Pa .depend
1596 list of dependencies
1597 .It Pa Makefile
1598 list of dependencies
1599 .It Pa makefile
1600 list of dependencies
1601 .It Pa obj
1602 object directory
1603 .It Pa sys.mk
1604 system makefile
1605 .It Pa /usr/share/mk
1606 default system makefile directory
1607 .It Pa /usr/share/doc/psd/12.make
1608 PMake tutorial
1609 .It Pa /usr/obj
1610 default
1611 .Ev MAKEOBJDIRPREFIX
1612 directory.
1613 .It Pa /etc/make.conf
1614 default path to
1615 .Xr make.conf 5
1616 .El
1617 .Sh EXAMPLES
1618 List all included makefiles in order visited:
1619 .Pp
1620 .Dl "make -V .MAKEFILE_LIST | tr \e\  \e\en"
1621 .Sh COMPATIBILITY
1622 Older versions of
1623 .Nm
1624 used
1625 .Ev MAKE
1626 instead of
1627 .Ev MAKEFLAGS .
1628 This was removed for POSIX compatibility.
1629 The internal variable
1630 .Va MAKE
1631 is set to the same value as
1632 .Va .MAKE ;
1633 support for this may be removed in the future.
1634 .Pp
1635 Most of the more esoteric features of
1636 .Nm
1637 should probably be avoided for greater compatibility.
1638 .Sh SEE ALSO
1639 .Xr mkdep 1 ,
1640 .Xr make.conf 5
1641 .Rs
1642 .%T "PMake - A Tutorial"
1643 .Re
1644 in
1645 .Pa /usr/share/doc/psd/12.make
1646 .Sh HISTORY
1647 A
1648 .Nm
1649 command appeared in PWB UNIX.
1650 .Sh BUGS
1651 The determination of
1652 .Va .OBJDIR
1653 is contorted to the point of absurdity.
1654 .Pp
1655 In the presence of several
1656 .Ic .MAIN
1657 special targets,
1658 .Nm
1659 silently ignores all but the first.
1660 .Pp
1661 .Va .TARGETS
1662 is not set to the default target when
1663 .Nm
1664 is invoked without a target name and no
1665 .Ic .MAIN
1666 special target exists.
1667 .Pp
1668 The evaluation of
1669 .Ar expression
1670 in a test is very simple-minded.
1671 Currently, the only form that works is
1672 .Ql .if ${VAR} op something
1673 For instance, you should write tests as
1674 .Ql .if ${VAR} == "string"
1675 not the other way around, which would give you an error.
1676 .Pp
1677 For loops are expanded before tests, so a fragment such as:
1678 .Bd -literal -offset indent
1679 \&.for ARCH in ${SHARED_ARCHS}
1680 \&.if ${ARCH} == ${MACHINE}
1681      ...
1682 \&.endif
1683 \&.endfor
1684 .Ed
1685 .Pp
1686 will not work, and should be rewritten as:
1687 .Bd -literal -offset indent
1688 \&.for ARCH in ${SHARED_ARCHS}
1689 \&.if ${MACHINE} == ${ARCH}
1690      ...
1691 \&.endif
1692 \&.endfor
1693 .Ed
1694 .Pp
1695 The parsing code is broken with respect to handling a semicolon
1696 after a colon, so a fragment like this will fail:
1697 .Bd -literal -offset indent
1698 HDRS=   foo.h bar.h
1699
1700 all:
1701 \&.for h in ${HDRS:S;^;${.CURDIR}/;}
1702      ...
1703 \&.endfor
1704 .Ed
1705 .Pp
1706 A trailing backslash in a variable value defined on the command line causes
1707 the delimiting space in the
1708 .Ev MAKEFLAGS
1709 environment variable to be preceded by that backslash.
1710 That causes a submake to not treat that space as a word delimiter.
1711 Fixing this requires a larger rewrite of the code handling command line
1712 macros and assignments to
1713 .Va .MAKEFLAGS .