1BMAKE(1) BSD General Commands Manual BMAKE(1)
2
4 bmake — maintain program dependencies
5
7 bmake [-BeikNnqrSstWwX] [-C directory] [-D variable] [-d flags]
8 [-f makefile] [-I directory] [-J private] [-j max_jobs]
9 [-m directory] [-T file] [-V variable] [-v variable]
10 [variable=value] [target ...]
11
13 bmake is a program designed to simplify the maintenance of other pro‐
14 grams. Its input is a list of specifications as to the files upon which
15 programs and other files depend. If no -f makefile option is given,
16 bmake tries to open ‘makefile’ then ‘Makefile’ in order to find the spec‐
17 ifications. If the file ‘.depend’ exists, it is read, see mkdep(1).
18
19 This manual page is intended as a reference document only. For a more
20 thorough description of bmake and makefiles, please refer to PMake - A
21 Tutorial (from 1993).
22
23 bmake prepends the contents of the MAKEFLAGS environment variable to the
24 command line arguments before parsing them.
25
26 The options are as follows:
27
28 -B Try to be backwards compatible by executing a single shell per
29 command and by making the sources of a dependency line in se‐
30 quence.
31
32 -C directory
33 Change to directory before reading the makefiles or doing any‐
34 thing else. If multiple -C options are specified, each is inter‐
35 preted relative to the previous one: -C / -C etc is equivalent to
36 -C /etc.
37
38 -D variable
39 Define variable to be 1, in the global scope.
40
41 -d [-]flags
42 Turn on debugging, and specify which portions of bmake are to
43 print debugging information. Unless the flags are preceded by
44 ‘-’, they are added to the MAKEFLAGS environment variable and are
45 passed on to any child make processes. By default, debugging in‐
46 formation is printed to standard error, but this can be changed
47 using the F debugging flag. The debugging output is always un‐
48 buffered; in addition, if debugging is enabled but debugging out‐
49 put is not directed to standard output, the standard output is
50 line buffered. The available flags are:
51
52 A Print all possible debugging information; equivalent to
53 specifying all of the debugging flags.
54
55 a Print debugging information about archive searching and
56 caching.
57
58 C Print debugging information about the current working di‐
59 rectory.
60
61 c Print debugging information about conditional evaluation.
62
63 d Print debugging information about directory searching and
64 caching.
65
66 e Print debugging information about failed commands and
67 targets.
68
69 F[+]filename
70 Specify where debugging output is written. This must be
71 the last flag, because it consumes the remainder of the
72 argument. If the character immediately after the F flag
73 is ‘+’, the file is opened in append mode; otherwise the
74 file is overwritten. If the file name is ‘stdout’ or
75 ‘stderr’, debugging output is written to the standard
76 output or standard error output respectively (and the ‘+’
77 option has no effect). Otherwise, the output is written
78 to the named file. If the file name ends with ‘.%d’, the
79 ‘%d’ is replaced by the pid.
80
81 f Print debugging information about loop evaluation.
82
83 g1 Print the input graph before making anything.
84
85 g2 Print the input graph after making everything, or before
86 exiting on error.
87
88 g3 Print the input graph before exiting on error.
89
90 h Print debugging information about hash table operations.
91
92 j Print debugging information about running multiple
93 shells.
94
95 L Turn on lint checks. This throws errors for variable as‐
96 signments that do not parse correctly, at the time of as‐
97 signment, so the file and line number are available.
98
99 l Print commands in Makefiles regardless of whether or not
100 they are prefixed by ‘@’ or other “quiet” flags. Also
101 known as “loud” behavior.
102
103 M Print debugging information about “meta” mode decisions
104 about targets.
105
106 m Print debugging information about making targets, includ‐
107 ing modification dates.
108
109 n Don't delete the temporary command scripts created when
110 running commands. These temporary scripts are created in
111 the directory referred to by the TMPDIR environment vari‐
112 able, or in /tmp if TMPDIR is unset or set to the empty
113 string. The temporary scripts are created by mkstemp(3),
114 and have names of the form makeXXXXXX. NOTE: This can
115 create many files in TMPDIR or /tmp, so use with care.
116
117 p Print debugging information about makefile parsing.
118
119 s Print debugging information about suffix-transformation
120 rules.
121
122 t Print debugging information about target list mainte‐
123 nance.
124
125 V Force the -V option to print raw values of variables,
126 overriding the default behavior set via
127 .MAKE.EXPAND_VARIABLES.
128
129 v Print debugging information about variable assignment and
130 expansion.
131
132 x Run shell commands with -x so the actual commands are
133 printed as they are executed.
134
135 -e Let environment variables override global variables within make‐
136 files.
137
138 -f makefile
139 Specify a makefile to read instead of the default makefile or
140 Makefile. If makefile is ‘-’, standard input is read. Multiple
141 makefiles may be specified, and are read in the order specified.
142
143 -I directory
144 Specify a directory in which to search for makefiles and included
145 makefiles. The system makefile directory (or directories, see
146 the -m option) is automatically included as part of this list.
147
148 -i Ignore non-zero exit of shell commands in the makefile. Equiva‐
149 lent to specifying ‘-’ before each command line in the makefile.
150
151 -J private
152 This option should not be specified by the user.
153
154 When the -j option is in use in a recursive build, this option is
155 passed by a make to child makes to allow all the make processes
156 in the build to cooperate to avoid overloading the system.
157
158 -j max_jobs
159 Specify the maximum number of jobs that bmake may have running at
160 any one time. The value is saved in .MAKE.JOBS. Turns compati‐
161 bility mode off, unless the -B option is also specified. When
162 compatibility mode is off, all commands associated with a target
163 are executed in a single shell invocation as opposed to the tra‐
164 ditional one shell invocation per line. This can break tradi‐
165 tional scripts which change directories on each command invoca‐
166 tion and then expect to start with a fresh environment on the
167 next line. It is more efficient to correct the scripts rather
168 than turn backwards compatibility on.
169
170 -k Continue processing after errors are encountered, but only on
171 those targets that do not depend on the target whose creation
172 caused the error.
173
174 -m directory
175 Specify a directory in which to search for sys.mk and makefiles
176 included via the <file>-style include statement. The -m option
177 can be used multiple times to form a search path. This path
178 overrides the default system include path /usr/share/mk. Fur‐
179 thermore, the system include path is appended to the search path
180 used for "file"-style include statements (see the -I option).
181
182 If a directory name in the -m argument (or the MAKESYSPATH envi‐
183 ronment variable) starts with the string ‘.../’, bmake searches
184 for the specified file or directory named in the remaining part
185 of the argument string. The search starts with the current di‐
186 rectory and then works upward towards the root of the file sys‐
187 tem. If the search is successful, the resulting directory re‐
188 places the ‘.../’ specification in the -m argument. This feature
189 allows bmake to easily search in the current source tree for cus‐
190 tomized sys.mk files (e.g., by using ‘.../mk/sys.mk’ as an argu‐
191 ment).
192
193 -n Display the commands that would have been executed, but do not
194 actually execute them unless the target depends on the .MAKE spe‐
195 cial source (see below) or the command is prefixed with ‘+’.
196
197 -N Display the commands that would have been executed, but do not
198 actually execute any of them; useful for debugging top-level
199 makefiles without descending into subdirectories.
200
201 -q Do not execute any commands, instead exit 0 if the specified tar‐
202 gets are up to date, and 1 otherwise.
203
204 -r Do not use the built-in rules specified in the system makefile.
205
206 -S Stop processing if an error is encountered. This is the default
207 behavior and the opposite of -k.
208
209 -s Do not echo any commands as they are executed. Equivalent to
210 specifying ‘@’ before each command line in the makefile.
211
212 -T tracefile
213 When used with the -j flag, append a trace record to tracefile
214 for each job started and completed.
215
216 -t Rather than re-building a target as specified in the makefile,
217 create it or update its modification time to make it appear up-
218 to-date.
219
220 -V variable
221 Print the value of variable. Do not build any targets. Multiple
222 instances of this option may be specified; the variables are
223 printed one per line, with a blank line for each null or unde‐
224 fined variable. The value printed is extracted from the global
225 scope after all makefiles have been read.
226
227 By default, the raw variable contents (which may include addi‐
228 tional unexpanded variable references) are shown. If variable
229 contains a ‘$’, it is not interpreted as a variable name but
230 rather as an expression. Its value is expanded before printing.
231 The value is also expanded before printing if
232 .MAKE.EXPAND_VARIABLES is set to true and the -dV option has not
233 been used to override it.
234
235 Note that loop-local and target-local variables, as well as val‐
236 ues taken temporarily by global variables during makefile pro‐
237 cessing, are not accessible via this option. The -dv debug mode
238 can be used to see these at the cost of generating substantial
239 extraneous output.
240
241 -v variable
242 Like -V, but all printed variables are always expanded to their
243 complete value. The last occurrence of -V or -v decides whether
244 all variables are expanded or not.
245
246 -W Treat any warnings during makefile parsing as errors.
247
248 -w Print entering and leaving directory messages, pre and post pro‐
249 cessing.
250
251 -X Don't export variables passed on the command line to the environ‐
252 ment individually. Variables passed on the command line are
253 still exported via the MAKEFLAGS environment variable. This op‐
254 tion may be useful on systems which have a small limit on the
255 size of command arguments.
256
257 variable=value
258 Set the value of the variable variable to value. Normally, all
259 values passed on the command line are also exported to sub-makes
260 in the environment. The -X flag disables this behavior. Vari‐
261 able assignments should follow options for POSIX compatibility
262 but no ordering is enforced.
263
264 There are several different types of lines in a makefile: dependency
265 specifications, shell commands, variable assignments, include statements,
266 conditional directives, for loops, other directives, and comments.
267
268 Lines may be continued from one line to the next by ending them with a
269 backslash (‘\’). The trailing newline character and initial whitespace
270 on the following line are compressed into a single space.
271
273 Dependency lines consist of one or more targets, an operator, and zero or
274 more sources. This creates a relationship where the targets “depend” on
275 the sources and are customarily created from them. A target is consid‐
276 ered out of date if it does not exist, or if its modification time is
277 less than that of any of its sources. An out-of-date target is re-cre‐
278 ated, but not until all sources have been examined and themselves re-cre‐
279 ated as needed. Three operators may be used:
280
281 : Many dependency lines may name this target but only one may have
282 attached shell commands. All sources named in all dependency lines
283 are considered together, and if needed the attached shell commands
284 are run to create or re-create the target. If bmake is inter‐
285 rupted, the target is removed.
286
287 ! The same, but the target is always re-created whether or not it is
288 out of date.
289
290 :: Any dependency line may have attached shell commands, but each one
291 is handled independently: its sources are considered and the at‐
292 tached shell commands are run if the target is out of date with re‐
293 spect to (only) those sources. Thus, different groups of the at‐
294 tached shell commands may be run depending on the circumstances.
295 Furthermore, unlike :, for dependency lines with no sources, the
296 attached shell commands are always run. Also unlike :, the target
297 is not removed if bmake is interrupted.
298
299 All dependency lines mentioning a particular target must use the same op‐
300 erator.
301
302 Targets and sources may contain the shell wildcard values ‘?’, ‘*’, ‘[]’,
303 and ‘{}’. The values ‘?’, ‘*’, and ‘[]’ may only be used as part of the
304 final component of the target or source, and only match existing files.
305 The value ‘{}’ need not necessarily be used to describe existing files.
306 Expansion is in directory order, not alphabetically as done in the shell.
307
309 Each target may have associated with it one or more lines of shell com‐
310 mands, normally used to create the target. Each of the lines in this
311 script must be preceded by a tab. (For historical reasons, spaces are
312 not accepted.) While targets can occur in many dependency lines if de‐
313 sired, by default only one of these rules may be followed by a creation
314 script. If the ‘::’ operator is used, however, all rules may include
315 scripts, and the respective scripts are executed in the order found.
316
317 Each line is treated as a separate shell command, unless the end of line
318 is escaped with a backslash ‘\’, in which case that line and the next are
319 combined. If the first characters of the command are any combination of
320 ‘@’, ‘+’, or ‘-’, the command is treated specially.
321
322 @ causes the command not to be echoed before it is executed.
323
324 + causes the command to be executed even when -n is given.
325 This is similar to the effect of the .MAKE special source,
326 except that the effect can be limited to a single line of a
327 script.
328
329 - in compatibility mode causes any non-zero exit status of
330 the command line to be ignored.
331
332 When bmake is run in jobs mode with -j max_jobs, the entire script for
333 the target is fed to a single instance of the shell. In compatibility
334 (non-jobs) mode, each command is run in a separate process. If the com‐
335 mand contains any shell meta characters (‘#=|^(){};&<>*?[]:$`\\n’), it is
336 passed to the shell; otherwise bmake attempts direct execution. If a
337 line starts with ‘-’ and the shell has ErrCtl enabled, failure of the
338 command line is ignored as in compatibility mode. Otherwise ‘-’ affects
339 the entire job; the script stops at the first command line that fails,
340 but the target is not deemed to have failed.
341
342 Makefiles should be written so that the mode of bmake operation does not
343 change their behavior. For example, any command which uses “cd” or
344 “chdir” without the intention of changing the directory for subsequent
345 commands should be put in parentheses so it executes in a subshell. To
346 force the use of a single shell, escape the line breaks so as to make the
347 whole script one command. For example:
348
349 avoid-chdir-side-effects:
350 @echo "Building $@ in $$(pwd)"
351 @(cd ${.CURDIR} && ${MAKE} $@)
352 @echo "Back in $$(pwd)"
353
354 ensure-one-shell-regardless-of-mode:
355 @echo "Building $@ in $$(pwd)"; \
356 (cd ${.CURDIR} && ${MAKE} $@); \
357 echo "Back in $$(pwd)"
358
359 Since bmake changes the current working directory to ‘.OBJDIR’ before ex‐
360 ecuting any targets, each child process starts with that as its current
361 working directory.
362
364 Variables in make behave much like macros in the C preprocessor.
365
366 Variable assignments have the form ‘NAME op value’, where:
367
368 NAME is a single-word variable name, consisting, by tradition,
369 of all upper-case letters,
370
371 op is one of the variable assignment operators described be‐
372 low, and
373
374 value is interpreted according to the variable assignment opera‐
375 tor.
376
377 Whitespace around NAME, op and value is discarded.
378
379 Variable assignment operators
380 The five operators that assign values to variables are:
381
382 = Assign the value to the variable. Any previous value is over‐
383 written.
384
385 += Append the value to the current value of the variable, separating
386 them by a single space.
387
388 ?= Assign the value to the variable if it is not already defined.
389
390 := Expand the value, then assign it to the variable.
391
392 NOTE: References to undefined variables are not expanded. This
393 can cause problems when variable modifiers are used.
394
395 != Expand the value and pass it to the shell for execution, then as‐
396 sign the output from the child's standard output to the variable.
397 Any newlines in the result are replaced with spaces.
398
399 Expansion of variables
400 In most contexts where variables are expanded, ‘$$’ expands to a single
401 dollar sign. In other contexts (most variable modifiers, string literals
402 in conditions), ‘\$’ expands to a single dollar sign.
403
404 References to variables have the form ${name[:modifiers]} or
405 $(name[:modifiers]). If the variable name consists of only a single
406 character and the expression contains no modifiers, the surrounding curly
407 braces or parentheses are not required. This shorter form is not recom‐
408 mended.
409
410 If the variable name contains a dollar, the name itself is expanded
411 first. This allows almost arbitrary variable names, however names con‐
412 taining dollar, braces, parentheses or whitespace are really best
413 avoided.
414
415 If the result of expanding a nested variable expression contains a dollar
416 sign (‘$’), the result is subject to further expansion.
417
418 Variable substitution occurs at four distinct times, depending on where
419 the variable is being used.
420
421 1. Variables in dependency lines are expanded as the line is read.
422
423 2. Variables in conditionals are expanded individually, but only as far
424 as necessary to determine the result of the conditional.
425
426 3. Variables in shell commands are expanded when the shell command is
427 executed.
428
429 4. .for loop index variables are expanded on each loop iteration. Note
430 that other variables are not expanded when composing the body of a
431 loop, so the following example code:
432
433 .for i in 1 2 3
434 a+= ${i}
435 j= ${i}
436 b+= ${j}
437 .endfor
438
439 all:
440 @echo ${a}
441 @echo ${b}
442
443 prints:
444
445 1 2 3
446 3 3 3
447
448 After the loop is executed:
449
450 a contains ‘${:U1} ${:U2} ${:U3}’, which expands to ‘1 2
451 3’.
452
453 j contains ‘${:U3}’, which expands to ‘3’.
454
455 b contains ‘${j} ${j} ${j}’, which expands to ‘${:U3}
456 ${:U3} ${:U3}’ and further to ‘3 3 3’.
457
458 Variable classes
459 The four different classes of variables (in order of increasing prece‐
460 dence) are:
461
462 Environment variables
463 Variables defined as part of bmake's environment.
464
465 Global variables
466 Variables defined in the makefile or in included makefiles.
467
468 Command line variables
469 Variables defined as part of the command line.
470
471 Local variables
472 Variables that are defined specific to a certain target.
473
474 Local variables can be set on a dependency line, unless
475 .MAKE.TARGET_LOCAL_VARIABLES is set to ‘false’. The rest of the line
476 (which already has had global variables expanded) is the variable value.
477 For example:
478
479 COMPILER_WRAPPERS= ccache distcc icecc
480
481 ${OBJS}: .MAKE.META.CMP_FILTER=${COMPILER_WRAPPERS:S,^,N,}
482
483 Only the targets ‘${OBJS}’ are impacted by that filter (in “meta” mode)
484 and simply enabling/disabling any of the compiler wrappers does not ren‐
485 der all of those targets out-of-date.
486
487 NOTE: target-local variable assignments behave differently in that;
488
489 += Only appends to a previous local assignment for the same
490 target and variable.
491
492 := Is redundant with respect to global variables, which have
493 already been expanded.
494
495 The seven built-in local variables are:
496
497 .ALLSRC The list of all sources for this target; also known as
498 ‘>’.
499
500 .ARCHIVE The name of the archive file; also known as ‘!’.
501
502 .IMPSRC In suffix-transformation rules, the name/path of the
503 source from which the target is to be transformed (the
504 “implied” source); also known as ‘<’. It is not defined
505 in explicit rules.
506
507 .MEMBER The name of the archive member; also known as ‘%’.
508
509 .OODATE The list of sources for this target that were deemed out-
510 of-date; also known as ‘?’.
511
512 .PREFIX The file prefix of the target, containing only the file
513 portion, no suffix or preceding directory components;
514 also known as ‘*’. The suffix must be one of the known
515 suffixes declared with .SUFFIXES, or it is not recog‐
516 nized.
517
518 .TARGET The name of the target; also known as ‘@’. For compati‐
519 bility with other makes this is an alias for .ARCHIVE in
520 archive member rules.
521
522 The shorter forms (‘>’, ‘!’, ‘<’, ‘%’, ‘?’, ‘*’, and ‘@’) are permitted
523 for backward compatibility with historical makefiles and legacy POSIX
524 make and are not recommended.
525
526 Variants of these variables with the punctuation followed immediately by
527 ‘D’ or ‘F’, e.g. ‘$(@D)’, are legacy forms equivalent to using the ‘:H’
528 and ‘:T’ modifiers. These forms are accepted for compatibility with AT&T
529 System V UNIX makefiles and POSIX but are not recommended.
530
531 Four of the local variables may be used in sources on dependency lines
532 because they expand to the proper value for each target on the line.
533 These variables are ‘.TARGET’, ‘.PREFIX’, ‘.ARCHIVE’, and ‘.MEMBER’.
534
535 Additional built-in variables
536 In addition, bmake sets or knows about the following variables:
537
538 .ALLTARGETS
539 The list of all targets encountered in the makefiles. If evalu‐
540 ated during makefile parsing, lists only those targets encoun‐
541 tered thus far.
542
543 .CURDIR
544 A path to the directory where bmake was executed. Refer to the
545 description of ‘PWD’ for more details.
546
547 .ERROR_CMD
548 Is used in error handling, see MAKE_PRINT_VAR_ON_ERROR.
549
550 .ERROR_CWD
551 Is used in error handling, see MAKE_PRINT_VAR_ON_ERROR.
552
553 .ERROR_META_FILE
554 Is used in error handling in “meta” mode, see
555 MAKE_PRINT_VAR_ON_ERROR.
556
557 .ERROR_TARGET
558 Is used in error handling, see MAKE_PRINT_VAR_ON_ERROR.
559
560 .INCLUDEDFROMDIR
561 The directory of the file this makefile was included from.
562
563 .INCLUDEDFROMFILE
564 The filename of the file this makefile was included from.
565
566 MACHINE
567 The machine hardware name, see uname(1).
568
569 MACHINE_ARCH
570 The machine processor architecture name, see uname(1).
571
572 MAKE The name that bmake was executed with (argv[0]).
573
574 .MAKE The same as MAKE, for compatibility. The preferred variable to
575 use is the environment variable MAKE because it is more compati‐
576 ble with other make variants and cannot be confused with the spe‐
577 cial target with the same name.
578
579 .MAKE.DEPENDFILE
580 Names the makefile (default ‘.depend’) from which generated de‐
581 pendencies are read.
582
583 .MAKE.DIE_QUIETLY
584 If set to ‘true’, do not print error information at the end.
585
586 .MAKE.EXPAND_VARIABLES
587 A boolean that controls the default behavior of the -V option.
588 If true, variable values printed with -V are fully expanded; if
589 false, the raw variable contents (which may include additional
590 unexpanded variable references) are shown.
591
592 .MAKE.EXPORTED
593 The list of variables exported by bmake.
594
595 MAKEFILE
596 The top-level makefile that is currently read, as given in the
597 command line.
598
599 .MAKEFLAGS
600 The environment variable ‘MAKEFLAGS’ may contain anything that
601 may be specified on bmake's command line. Anything specified on
602 bmake's command line is appended to the .MAKEFLAGS variable,
603 which is then added to the environment for all programs that
604 bmake executes.
605
606 .MAKE.GID
607 The numeric group ID of the user running bmake.
608
609 .MAKE.JOB.PREFIX
610 If bmake is run with -j, the output for each target is prefixed
611 with a token
612 --- target ---
613 the first part of which can be controlled via .MAKE.JOB.PREFIX.
614 If .MAKE.JOB.PREFIX is empty, no token is printed. For example,
615 setting .MAKE.JOB.PREFIX to
616 ‘${.newline}---${.MAKE:T}[${.MAKE.PID}]’ would produce tokens
617 like
618 ---make[1234] target ---
619 making it easier to track the degree of parallelism being
620 achieved.
621
622 .MAKE.JOBS
623 The argument to the -j option.
624
625 .MAKE.LEVEL
626 The recursion depth of bmake. The top-level instance of bmake
627 has level 0, and each child make has its parent level plus 1.
628 This allows tests like: .if ${.MAKE.LEVEL} == 0 to protect things
629 which should only be evaluated in the top-level instance of
630 bmake.
631
632 .MAKE.LEVEL.ENV
633 The name of the environment variable that stores the level of
634 nested calls to bmake.
635
636 .MAKE.MAKEFILE_PREFERENCE
637 The ordered list of makefile names (default ‘makefile’,
638 ‘Makefile’) that bmake looks for.
639
640 .MAKE.MAKEFILES
641 The list of makefiles read by bmake, which is useful for tracking
642 dependencies. Each makefile is recorded only once, regardless of
643 the number of times read.
644
645 .MAKE.META.BAILIWICK
646 In “meta” mode, provides a list of prefixes which match the di‐
647 rectories controlled by bmake. If a file that was generated out‐
648 side of .OBJDIR but within said bailiwick is missing, the current
649 target is considered out-of-date.
650
651 .MAKE.META.CMP_FILTER
652 In “meta” mode, it can (very rarely!) be useful to filter command
653 lines before comparison. This variable can be set to a set of
654 modifiers that are applied to each line of the old and new com‐
655 mand that differ, if the filtered commands still differ, the tar‐
656 get is considered out-of-date.
657
658 .MAKE.META.CREATED
659 In “meta” mode, this variable contains a list of all the meta
660 files updated. If not empty, it can be used to trigger process‐
661 ing of .MAKE.META.FILES.
662
663 .MAKE.META.FILES
664 In “meta” mode, this variable contains a list of all the meta
665 files used (updated or not). This list can be used to process
666 the meta files to extract dependency information.
667
668 .MAKE.META.IGNORE_FILTER
669 Provides a list of variable modifiers to apply to each pathname.
670 Ignore if the expansion is an empty string.
671
672 .MAKE.META.IGNORE_PATHS
673 Provides a list of path prefixes that should be ignored; because
674 the contents are expected to change over time. The default list
675 includes: ‘/dev /etc /proc /tmp /var/run /var/tmp’
676
677 .MAKE.META.IGNORE_PATTERNS
678 Provides a list of patterns to match against pathnames. Ignore
679 any that match.
680
681 .MAKE.META.PREFIX
682 Defines the message printed for each meta file updated in “meta
683 verbose” mode. The default value is:
684 Building ${.TARGET:H:tA}/${.TARGET:T}
685
686 .MAKE.MODE
687 Processed after reading all makefiles. Affects the mode that
688 bmake runs in. It can contain these keywords:
689
690 compat Like -B, puts bmake into “compat” mode.
691
692 meta Puts bmake into “meta” mode, where meta files are created
693 for each target to capture the command run, the output
694 generated, and if filemon(4) is available, the system
695 calls which are of interest to bmake. The captured out‐
696 put can be useful when diagnosing errors.
697
698 curdirOk=bf
699 By default, bmake does not create .meta files in
700 ‘.CURDIR’. This can be overridden by setting bf to a
701 value which represents true.
702
703 missing-meta=bf
704 If bf is true, a missing .meta file makes the target out-
705 of-date.
706
707 missing-filemon=bf
708 If bf is true, missing filemon data makes the target out-
709 of-date.
710
711 nofilemon
712 Do not use filemon(4).
713
714 env For debugging, it can be useful to include the environ‐
715 ment in the .meta file.
716
717 verbose
718 If in “meta” mode, print a clue about the target being
719 built. This is useful if the build is otherwise running
720 silently. The message printed is the expanded value of
721 .MAKE.META.PREFIX.
722
723 ignore-cmd
724 Some makefiles have commands which are simply not stable.
725 This keyword causes them to be ignored for determining
726 whether a target is out of date in “meta” mode. See also
727 .NOMETA_CMP.
728
729 silent=bf
730 If bf is true, when a .meta file is created, mark the
731 target .SILENT.
732
733 randomize-targets
734 In both compat and parallel mode, do not make the targets
735 in the usual order, but instead randomize their order.
736 This mode can be used to detect undeclared dependencies
737 between files.
738
739 MAKEOBJDIR
740 Used to create files in a separate directory, see .OBJDIR.
741
742 MAKE_OBJDIR_CHECK_WRITABLE
743 Used to force a separate directory for the created files, even if
744 that directory is not writable, see .OBJDIR.
745
746 MAKEOBJDIRPREFIX
747 Used to create files in a separate directory, see .OBJDIR.
748
749 .MAKE.OS
750 The name of the operating system, see uname(1).
751
752 .MAKEOVERRIDES
753 This variable is used to record the names of variables assigned
754 to on the command line, so that they may be exported as part of
755 ‘MAKEFLAGS’. This behavior can be disabled by assigning an empty
756 value to ‘.MAKEOVERRIDES’ within a makefile. Extra variables can
757 be exported from a makefile by appending their names to
758 ‘.MAKEOVERRIDES’. ‘MAKEFLAGS’ is re-exported whenever
759 ‘.MAKEOVERRIDES’ is modified.
760
761 .MAKE.PATH_FILEMON
762 If bmake was built with filemon(4) support, this is set to the
763 path of the device node. This allows makefiles to test for this
764 support.
765
766 .MAKE.PID
767 The process ID of bmake.
768
769 .MAKE.PPID
770 The parent process ID of bmake.
771
772 MAKE_PRINT_VAR_ON_ERROR
773 When bmake stops due to an error, it sets ‘.ERROR_TARGET’ to the
774 name of the target that failed, ‘.ERROR_CMD’ to the commands of
775 the failed target, and in “meta” mode, it also sets ‘.ERROR_CWD’
776 to the getcwd(3), and ‘.ERROR_META_FILE’ to the path of the meta
777 file (if any) describing the failed target. It then prints its
778 name and the value of ‘.CURDIR’ as well as the value of any vari‐
779 ables named in ‘MAKE_PRINT_VAR_ON_ERROR’.
780
781 .MAKE.SAVE_DOLLARS
782 If true, ‘$$’ are preserved when doing ‘:=’ assignments. The de‐
783 fault is false, for backwards compatibility. Set to true for
784 compatability with other makes. If set to false, ‘$$’ becomes
785 ‘$’ per normal evaluation rules.
786
787 .MAKE.TARGET_LOCAL_VARIABLES
788 If set to ‘false’, apparent variable assignments in dependency
789 lines are treated as normal sources.
790
791 .MAKE.UID
792 The numeric ID of the user running bmake.
793
794 .newline
795 This variable is simply assigned a newline character as its
796 value. This allows expansions using the :@ modifier to put a
797 newline between iterations of the loop rather than a space. For
798 example, in case of an error, bmake prints the variable names and
799 their values using:
800 ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
801
802 .OBJDIR
803 A path to the directory where the targets are built. Its value
804 is determined by trying to chdir(2) to the following directories
805 in order and using the first match:
806
807 1. ${MAKEOBJDIRPREFIX}${.CURDIR}
808
809 (Only if ‘MAKEOBJDIRPREFIX’ is set in the environment or on
810 the command line.)
811
812 2. ${MAKEOBJDIR}
813
814 (Only if ‘MAKEOBJDIR’ is set in the environment or on the
815 command line.)
816
817 3. ${.CURDIR}/obj.${MACHINE}
818
819 4. ${.CURDIR}/obj
820
821 5. /usr/obj/${.CURDIR}
822
823 6. ${.CURDIR}
824
825 Variable expansion is performed on the value before it is used,
826 so expressions such as ${.CURDIR:S,^/usr/src,/var/obj,} may be
827 used. This is especially useful with ‘MAKEOBJDIR’.
828
829 ‘.OBJDIR’ may be modified in the makefile via the special target
830 ‘.OBJDIR’. In all cases, bmake changes to the specified direc‐
831 tory if it exists, and sets ‘.OBJDIR’ and ‘PWD’ to that directory
832 before executing any targets.
833
834 Except in the case of an explicit ‘.OBJDIR’ target, bmake checks
835 that the specified directory is writable and ignores it if not.
836 This check can be skipped by setting the environment variable
837 ‘MAKE_OBJDIR_CHECK_WRITABLE’ to “no”.
838
839 .PARSEDIR
840 The directory name of the current makefile being parsed.
841
842 .PARSEFILE
843 The basename of the current makefile being parsed. This variable
844 and ‘.PARSEDIR’ are both set only while the makefiles are being
845 parsed. To retain their current values, assign them to a vari‐
846 able using assignment with expansion ‘:=’.
847
848 .PATH The space-separated list of directories that bmake searches for
849 files. To update this search list, use the special target
850 ‘.PATH’ rather than modifying the variable directly.
851
852 %POSIX Is set in POSIX mode, see the special ‘.POSIX’ target.
853
854 PWD Alternate path to the current directory. bmake normally sets
855 ‘.CURDIR’ to the canonical path given by getcwd(3). However, if
856 the environment variable ‘PWD’ is set and gives a path to the
857 current directory, bmake sets ‘.CURDIR’ to the value of ‘PWD’ in‐
858 stead. This behavior is disabled if ‘MAKEOBJDIRPREFIX’ is set or
859 ‘MAKEOBJDIR’ contains a variable transform. ‘PWD’ is set to the
860 value of ‘.OBJDIR’ for all programs which bmake executes.
861
862 .SHELL The pathname of the shell used to run target scripts. It is
863 read-only.
864
865 .SUFFIXES
866 The list of known suffixes. It is read-only.
867
868 .TARGETS
869 The list of targets explicitly specified on the command line, if
870 any.
871
872 VPATH The colon-separated (“:”) list of directories that bmake searches
873 for files. This variable is supported for compatibility with old
874 make programs only, use ‘.PATH’ instead.
875
876 Variable modifiers
877 The general format of a variable expansion is:
878
879 ${variable[:modifier[:...]]}
880
881 Each modifier begins with a colon. To escape a colon, precede it with a
882 backslash ‘\’.
883
884 A list of indirect modifiers can be specified via a variable, as follows:
885
886 modifier_variable = modifier[:...]
887
888 ${variable:${modifier_variable}[:...]}
889
890 In this case, the first modifier in the modifier_variable does not start
891 with a colon, since that colon already occurs in the referencing vari‐
892 able. If any of the modifiers in the modifier_variable contains a dollar
893 sign (‘$’), these must be doubled to avoid early expansion.
894
895 Some modifiers interpret the expression value as a single string, others
896 treat the expression value as a whitespace-separated list of words. When
897 splitting a string into words, whitespace can be escaped using double
898 quotes, single quotes and backslashes, like in the shell. The quotes and
899 backslashes are retained in the words.
900
901 The supported modifiers are:
902
903 :E Replaces each word with its suffix.
904
905 :H Replaces each word with its dirname.
906
907 :Mpattern
908 Selects only those words that match pattern. The standard shell
909 wildcard characters (‘*’, ‘?’, and ‘[]’) may be used. The wildcard
910 characters may be escaped with a backslash (‘\’). As a consequence
911 of the way values are split into words, matched, and then joined,
912 the construct ‘${VAR:M*}’ removes all leading and trailing white‐
913 space and normalizes the inter-word spacing to a single space.
914
915 :Npattern
916 This is the opposite of ‘:M’, selecting all words which do not match
917 pattern.
918
919 :O Orders the words lexicographically.
920
921 :On Orders the words numerically. A number followed by one of ‘k’, ‘M’
922 or ‘G’ is multiplied by the appropriate factor, which is 1024 for
923 ‘k’, 1048576 for ‘M’, or 1073741824 for ‘G’. Both upper- and lower-
924 case letters are accepted.
925
926 :Or Orders the words in reverse lexicographical order.
927
928 :Orn
929 Orders the words in reverse numerical order.
930
931 :Ox Shuffles the words. The results are different each time you are re‐
932 ferring to the modified variable; use the assignment with expansion
933 ‘:=’ to prevent such behavior. For example,
934
935 LIST= uno due tre quattro
936 RANDOM_LIST= ${LIST:Ox}
937 STATIC_RANDOM_LIST:= ${LIST:Ox}
938
939 all:
940 @echo "${RANDOM_LIST}"
941 @echo "${RANDOM_LIST}"
942 @echo "${STATIC_RANDOM_LIST}"
943 @echo "${STATIC_RANDOM_LIST}"
944 may produce output similar to:
945
946 quattro due tre uno
947 tre due quattro uno
948 due uno quattro tre
949 due uno quattro tre
950
951 :Q Quotes every shell meta-character in the value, so that it can be
952 passed safely to the shell.
953
954 :q Quotes every shell meta-character in the value, and also doubles ‘$’
955 characters so that it can be passed safely through recursive invoca‐
956 tions of bmake. This is equivalent to ‘:S/\$/&&/g:Q’.
957
958 :R Replaces each word with everything but its suffix.
959
960 :range[=count]
961 The value is an integer sequence representing the words of the orig‐
962 inal value, or the supplied count.
963
964 :gmtime[=timestamp]
965 The value is interpreted as a format string for strftime(3), using
966 gmtime(3), producing the formatted timestamp. If a timestamp value
967 is not provided or is 0, the current time is used.
968
969 :hash
970 Computes a 32-bit hash of the value and encodes it as 8 hex digits.
971
972 :localtime[=timestamp]
973 The value is interpreted as a format string for strftime(3), using
974 localtime(3), producing the formatted timestamp. If a timestamp
975 value is not provided or is 0, the current time is used.
976
977 :tA Attempts to convert the value to an absolute path using realpath(3).
978 If that fails, the value is unchanged.
979
980 :tl Converts the value to lower-case letters.
981
982 :tsc
983 When joining the words after a modifier that treats the value as
984 words, the words are normally separated by a space. This modifier
985 changes the separator to the character c. If c is omitted, no sepa‐
986 rator is used. The common escapes (including octal numeric codes)
987 work as expected.
988
989 :tu Converts the value to upper-case letters.
990
991 :tW Causes subsequent modifiers to treat the value as a single word
992 (possibly containing embedded whitespace). See also ‘:[*]’.
993
994 :tw Causes the value to be treated as a list of words. See also ‘:[@]’.
995
996 :S/old_string/new_string/[1gW]
997 Modifies the first occurrence of old_string in each word of the
998 value, replacing it with new_string. If a ‘g’ is appended to the
999 last delimiter of the pattern, all occurrences in each word are re‐
1000 placed. If a ‘1’ is appended to the last delimiter of the pattern,
1001 only the first occurrence is affected. If a ‘W’ is appended to the
1002 last delimiter of the pattern, the value is treated as a single
1003 word. If old_string begins with a caret (‘^’), old_string is an‐
1004 chored at the beginning of each word. If old_string ends with a
1005 dollar sign (‘$’), it is anchored at the end of each word. Inside
1006 new_string, an ampersand (‘&’) is replaced by old_string (without
1007 the anchoring ‘^’ or ‘$’). Any character may be used as the delim‐
1008 iter for the parts of the modifier string. The anchoring, ampersand
1009 and delimiter characters can be escaped with a backslash (‘\’).
1010
1011 Both old_string and new_string may contain nested expressions. To
1012 prevent a dollar sign from starting a nested expression, escape it
1013 with a backslash.
1014
1015 :C/pattern/replacement/[1gW]
1016 The :C modifier works like the :S modifier except that the old and
1017 new strings, instead of being simple strings, are an extended regu‐
1018 lar expression pattern (see regex(3)) and an ed(1)-style
1019 replacement. Normally, the first occurrence of the pattern pattern
1020 in each word of the value is substituted with replacement. The ‘1’
1021 modifier causes the substitution to apply to at most one word; the
1022 ‘g’ modifier causes the substitution to apply to as many instances
1023 of the search pattern pattern as occur in the word or words it is
1024 found in; the ‘W’ modifier causes the value to be treated as a sin‐
1025 gle word (possibly containing embedded whitespace).
1026
1027 As for the :S modifier, the pattern and replacement are subjected to
1028 variable expansion before being parsed as regular expressions.
1029
1030 :T Replaces each word with its last path component (basename).
1031
1032 :u Removes adjacent duplicate words (like uniq(1)).
1033
1034 :?true_string:false_string
1035 If the variable name (not its value), when parsed as a .if condi‐
1036 tional expression, evaluates to true, return as its value the
1037 true_string, otherwise return the false_string. Since the variable
1038 name is used as the expression, :? must be the first modifier after
1039 the variable name itself—which, of course, usually contains variable
1040 expansions. A common error is trying to use expressions like
1041 ${NUMBERS:M42:?match:no}
1042 which actually tests defined(NUMBERS). To determine if any words
1043 match “42”, you need to use something like:
1044 ${"${NUMBERS:M42}" != "":?match:no}.
1045
1046 :old_string=new_string
1047 This is the AT&T System V UNIX style substitution. It can only be
1048 the last modifier specified, as a ‘:’ in either old_string or
1049 new_string is treated as a regular character, not as the end of the
1050 modifier.
1051
1052 If old_string does not contain the pattern matching character ‘%’,
1053 and the word ends with old_string or equals it, that suffix is re‐
1054 placed with new_string.
1055
1056 Otherwise, the first ‘%’ in old_string matches a possibly empty sub‐
1057 string of arbitrary characters, and if the whole pattern is found in
1058 the word, the matching part is replaced with new_string, and the
1059 first occurrence of ‘%’ in new_string (if any) is replaced with the
1060 substring matched by the ‘%’.
1061
1062 Both old_string and new_string may contain nested expressions. To
1063 prevent a dollar sign from starting a nested expression, escape it
1064 with a backslash.
1065
1066 :@varname@string@
1067 This is the loop expansion mechanism from the OSF Development Envi‐
1068 ronment (ODE) make. Unlike .for loops, expansion occurs at the time
1069 of reference. For each word in the value, assign the word to the
1070 variable named varname and evaluate string. The ODE convention is
1071 that varname should start and end with a period, for example:
1072 ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@}
1073
1074 However, a single-letter variable is often more readable:
1075 ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
1076
1077 :_[=var]
1078 Saves the current variable value in ‘$_’ or the named var for later
1079 reference. Example usage:
1080
1081 M_cmpv.units = 1 1000 1000000
1082 M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \
1083 \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
1084
1085 .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
1086
1087 Here ‘$_’ is used to save the result of the ‘:S’ modifier which is
1088 later referenced using the index values from ‘:range’.
1089
1090 :Unewval
1091 If the variable is undefined, newval is the value. If the variable
1092 is defined, the existing value is returned. This is another ODE
1093 make feature. It is handy for setting per-target CFLAGS for in‐
1094 stance:
1095 ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}}
1096 If a value is only required if the variable is undefined, use:
1097 ${VAR:D:Unewval}
1098
1099 :Dnewval
1100 If the variable is defined, newval is the value.
1101
1102 :L The name of the variable is the value.
1103
1104 :P The path of the node which has the same name as the variable is the
1105 value. If no such node exists or its path is null, the name of the
1106 variable is used. In order for this modifier to work, the name
1107 (node) must at least have appeared on the right-hand side of a de‐
1108 pendency.
1109
1110 :!cmd!
1111 The output of running cmd is the value.
1112
1113 :sh The value is run as a command, and the output becomes the new value.
1114
1115 ::=str
1116 The variable is assigned the value str after substitution. This
1117 modifier and its variations are useful in obscure situations such as
1118 wanting to set a variable at a point where a target's shell commands
1119 are being parsed. These assignment modifiers always expand to noth‐
1120 ing.
1121
1122 The ‘::’ helps avoid false matches with the AT&T System V UNIX style
1123 ‘:=’ modifier and since substitution always occurs, the ‘::=’ form
1124 is vaguely appropriate.
1125
1126 ::?=str
1127 As for ::= but only if the variable does not already have a value.
1128
1129 ::+=str
1130 Append str to the variable.
1131
1132 ::!=cmd
1133 Assign the output of cmd to the variable.
1134
1135 :[range]
1136 Selects one or more words from the value, or performs other opera‐
1137 tions related to the way in which the value is split into words.
1138
1139 An empty value, or a value that consists entirely of white-space, is
1140 treated as a single word. For the purposes of the ‘:[]’ modifier,
1141 the words are indexed both forwards using positive integers (where
1142 index 1 represents the first word), and backwards using negative in‐
1143 tegers (where index -1 represents the last word).
1144
1145 The range is subjected to variable expansion, and the expanded re‐
1146 sult is then interpreted as follows:
1147
1148 index Selects a single word from the value.
1149
1150 start..end
1151 Selects all words from start to end, inclusive. For example,
1152 ‘:[2..-1]’ selects all words from the second word to the last
1153 word. If start is greater than end, the words are output in
1154 reverse order. For example, ‘:[-1..1]’ selects all the words
1155 from last to first. If the list is already ordered, this ef‐
1156 fectively reverses the list, but it is more efficient to use
1157 ‘:Or’ instead of ‘:O:[-1..1]’.
1158
1159 * Causes subsequent modifiers to treat the value as a single
1160 word (possibly containing embedded whitespace). Analogous to
1161 the effect of $* in Bourne shell.
1162
1163 0 Means the same as ‘:[*]’.
1164
1165 @ Causes subsequent modifiers to treat the value as a sequence
1166 of words delimited by whitespace. Analogous to the effect of
1167 $@ in Bourne shell.
1168
1169 # Returns the number of words in the value.
1170
1172 bmake offers directives for including makefiles, conditionals and for
1173 loops. All these directives are identified by a line beginning with a
1174 single dot (‘.’) character, followed by the keyword of the directive,
1175 such as include or if.
1176
1177 File inclusion
1178 Files are included with either .include <file> or .include "file". Vari‐
1179 ables between the angle brackets or double quotes are expanded to form
1180 the file name. If angle brackets are used, the included makefile is ex‐
1181 pected to be in the system makefile directory. If double quotes are
1182 used, the including makefile's directory and any directories specified
1183 using the -I option are searched before the system makefile directory.
1184
1185 For compatibility with other make variants, ‘include file ...’ (without
1186 leading dot) is also accepted.
1187
1188 If the include statement is written as .-include or as .sinclude, errors
1189 locating and/or opening include files are ignored.
1190
1191 If the include statement is written as .dinclude, not only are errors lo‐
1192 cating and/or opening include files ignored, but stale dependencies
1193 within the included file are ignored just like in .MAKE.DEPENDFILE.
1194
1195 Exporting variables
1196 The directives for exporting and unexporting variables are:
1197
1198 .export variable ...
1199 Export the specified global variable. If no variable list is
1200 provided, all globals are exported except for internal variables
1201 (those that start with ‘.’). This is not affected by the -X
1202 flag, so should be used with caution. For compatibility with
1203 other make programs, export variable=value (without leading dot)
1204 is also accepted.
1205
1206 Appending a variable name to .MAKE.EXPORTED is equivalent to ex‐
1207 porting a variable.
1208
1209 .export-env variable ...
1210 The same as ‘.export’, except that the variable is not appended
1211 to .MAKE.EXPORTED. This allows exporting a value to the environ‐
1212 ment which is different from that used by bmake internally.
1213
1214 .export-literal variable ...
1215 The same as ‘.export-env’, except that variables in the value are
1216 not expanded.
1217
1218 .unexport variable ...
1219 The opposite of ‘.export’. The specified global variable is re‐
1220 moved from .MAKE.EXPORTED. If no variable list is provided, all
1221 globals are unexported, and .MAKE.EXPORTED deleted.
1222
1223 .unexport-env
1224 Unexport all globals previously exported and clear the environ‐
1225 ment inherited from the parent. This operation causes a memory
1226 leak of the original environment, so should be used sparingly.
1227 Testing for .MAKE.LEVEL being 0 would make sense. Also note that
1228 any variables which originated in the parent environment should
1229 be explicitly preserved if desired. For example:
1230
1231 .if ${.MAKE.LEVEL} == 0
1232 PATH := ${PATH}
1233 .unexport-env
1234 .export PATH
1235 .endif
1236
1237 Would result in an environment containing only ‘PATH’, which is
1238 the minimal useful environment. Actually ‘.MAKE.LEVEL’ is also
1239 pushed into the new environment.
1240
1241 Messages
1242 The directives for printing messages to the output are:
1243
1244 .info message
1245 The message is printed along with the name of the makefile and
1246 line number.
1247
1248 .warning message
1249 The message prefixed by ‘warning:’ is printed along with the name
1250 of the makefile and line number.
1251
1252 .error message
1253 The message is printed along with the name of the makefile and
1254 line number, bmake exits immediately.
1255
1256 Conditionals
1257 The directives for conditionals are:
1258
1259 .if [!]expression [operator expression ...]
1260 Test the value of an expression.
1261
1262 .ifdef [!]variable [operator variable ...]
1263 Test whether a variable is defined.
1264
1265 .ifndef [!]variable [operator variable ...]
1266 Test whether a variable is not defined.
1267
1268 .ifmake [!]target [operator target ...]
1269 Test the target being requested.
1270
1271 .ifnmake [!]target [operator target ...]
1272 Test the target being requested.
1273
1274 .else Reverse the sense of the last conditional.
1275
1276 .elif [!]expression [operator expression ...]
1277 A combination of ‘.else’ followed by ‘.if’.
1278
1279 .elifdef [!]variable [operator variable ...]
1280 A combination of ‘.else’ followed by ‘.ifdef’.
1281
1282 .elifndef [!]variable [operator variable ...]
1283 A combination of ‘.else’ followed by ‘.ifndef’.
1284
1285 .elifmake [!]target [operator target ...]
1286 A combination of ‘.else’ followed by ‘.ifmake’.
1287
1288 .elifnmake [!]target [operator target ...]
1289 A combination of ‘.else’ followed by ‘.ifnmake’.
1290
1291 .endif End the body of the conditional.
1292
1293 The operator may be any one of the following:
1294
1295 || Logical OR.
1296
1297 && Logical AND; of higher precedence than ‘||’.
1298
1299 bmake only evaluates a conditional as far as is necessary to determine
1300 its value. Parentheses can be used to override the operator precedence.
1301 The boolean operator ‘!’ may be used to logically negate an entire condi‐
1302 tional. It is of higher precedence than ‘&&’.
1303
1304 The value of expression may be any of the following function call expres‐
1305 sions:
1306
1307 defined(varname)
1308 Evaluates to true if the variable varname has been defined.
1309
1310 make(target)
1311 Evaluates to true if the target was specified as part of bmake's
1312 command line or was declared the default target (either implic‐
1313 itly or explicitly, see .MAIN) before the line containing the
1314 conditional.
1315
1316 empty(varname[:modifiers])
1317 Evaluates to true if the expansion of the variable, after apply‐
1318 ing the modifiers, results in an empty string.
1319
1320 exists(pathname)
1321 Evaluates to true if the given pathname exists. If relative, the
1322 pathname is searched for on the system search path (see .PATH).
1323
1324 target(target)
1325 Evaluates to true if the target has been defined.
1326
1327 commands(target)
1328 Evaluates to true if the target has been defined and has commands
1329 associated with it.
1330
1331 Expression may also be an arithmetic or string comparison. Variable ex‐
1332 pansion is performed on both sides of the comparison. If both sides are
1333 numeric and neither is enclosed in quotes, the comparison is done numeri‐
1334 cally, otherwise lexicographically. A string is interpreted as hexadeci‐
1335 mal integer if it is preceded by 0x, otherwise it is a decimal floating-
1336 point number; octal numbers are not supported.
1337
1338 All comparisons may use the operators ‘==’ and ‘!=’. Numeric comparisons
1339 may also use the operators ‘<’, ‘<=’, ‘>’ and ‘>=’.
1340
1341 If the comparison has neither a comparison operator nor a right side, the
1342 expression evaluates to true if it is nonempty and its numeric value (if
1343 any) is not zero.
1344
1345 When bmake is evaluating one of these conditional expressions, and it en‐
1346 counters a (whitespace separated) word it doesn't recognize, either the
1347 “make” or “defined” function is applied to it, depending on the form of
1348 the conditional. If the form is ‘.ifdef’, ‘.ifndef’ or ‘.if’, the
1349 “defined” function is applied. Similarly, if the form is ‘.ifmake’ or
1350 ‘.ifnmake’, the “make” function is applied.
1351
1352 If the conditional evaluates to true, parsing of the makefile continues
1353 as before. If it evaluates to false, the following lines are skipped.
1354 In both cases, this continues until the corresponding ‘.else’ or ‘.endif’
1355 is found.
1356
1357 For loops
1358 For loops are typically used to apply a set of rules to a list of files.
1359 The syntax of a for loop is:
1360
1361 .for variable [variable ...] in expression
1362 ⟨make-lines⟩
1363 .endfor
1364
1365 The expression is expanded and then split into words. On each iteration
1366 of the loop, one word is taken and assigned to each variable, in order,
1367 and these variables are substituted into the make-lines inside the body
1368 of the for loop. The number of words must come out even; that is, if
1369 there are three iteration variables, the number of words provided must be
1370 a multiple of three.
1371
1372 If ‘.break’ is encountered within a .for loop, it causes early termina‐
1373 tion of the loop, otherwise a parse error.
1374
1375 Other directives
1376 .undef variable ...
1377 Un-define the specified global variables. Only global variables
1378 can be un-defined.
1379
1381 Comments begin with a hash (‘#’) character, anywhere but in a shell com‐
1382 mand line, and continue to the end of an unescaped new line.
1383
1385 .EXEC Target is never out of date, but always execute commands any‐
1386 way.
1387
1388 .IGNORE Ignore any errors from the commands associated with this tar‐
1389 get, exactly as if they all were preceded by a dash (‘-’).
1390
1391 .MADE Mark all sources of this target as being up to date.
1392
1393 .MAKE Execute the commands associated with this target even if the -n
1394 or -t options were specified. Normally used to mark recursive
1395 bmakes.
1396
1397 .META Create a meta file for the target, even if it is flagged as
1398 .PHONY, .MAKE, or .SPECIAL. Usage in conjunction with .MAKE is
1399 the most likely case. In “meta” mode, the target is out-of-
1400 date if the meta file is missing.
1401
1402 .NOMETA Do not create a meta file for the target. Meta files are also
1403 not created for .PHONY, .MAKE, or .SPECIAL targets.
1404
1405 .NOMETA_CMP
1406 Ignore differences in commands when deciding if target is out
1407 of date. This is useful if the command contains a value which
1408 always changes. If the number of commands change, though, the
1409 target is still considered out of date. The same effect ap‐
1410 plies to any command line that uses the variable .OODATE, which
1411 can be used for that purpose even when not otherwise needed or
1412 desired:
1413
1414
1415 skip-compare-for-some:
1416 @echo this is compared
1417 @echo this is not ${.OODATE:M.NOMETA_CMP}
1418 @echo this is also compared
1419
1420 The :M pattern suppresses any expansion of the unwanted vari‐
1421 able.
1422
1423 .NOPATH Do not search for the target in the directories specified by
1424 .PATH.
1425
1426 .NOTMAIN Normally bmake selects the first target it encounters as the
1427 default target to be built if no target was specified. This
1428 source prevents this target from being selected.
1429
1430 .OPTIONAL
1431 If a target is marked with this attribute and bmake can't fig‐
1432 ure out how to create it, it ignores this fact and assumes the
1433 file isn't needed or already exists.
1434
1435 .PHONY The target does not correspond to an actual file; it is always
1436 considered to be out of date, and is not created with the -t
1437 option. Suffix-transformation rules are not applied to .PHONY
1438 targets.
1439
1440 .PRECIOUS
1441 When bmake is interrupted, it normally removes any partially
1442 made targets. This source prevents the target from being re‐
1443 moved.
1444
1445 .RECURSIVE
1446 Synonym for .MAKE.
1447
1448 .SILENT Do not echo any of the commands associated with this target,
1449 exactly as if they all were preceded by an at sign (‘@’).
1450
1451 .USE Turn the target into bmake's version of a macro. When the tar‐
1452 get is used as a source for another target, the other target
1453 acquires the commands, sources, and attributes (except for
1454 .USE) of the source. If the target already has commands, the
1455 .USE target's commands are appended to them.
1456
1457 .USEBEFORE
1458 Like .USE, but instead of appending, prepend the .USEBEFORE
1459 target commands to the target.
1460
1461 .WAIT If .WAIT appears in a dependency line, the sources that precede
1462 it are made before the sources that succeed it in the line.
1463 Since the dependents of files are not made until the file it‐
1464 self could be made, this also stops the dependents being built
1465 unless they are needed for another branch of the dependency
1466 tree. So given:
1467
1468 x: a .WAIT b
1469 echo x
1470 a:
1471 echo a
1472 b: b1
1473 echo b
1474 b1:
1475 echo b1
1476
1477 the output is always ‘a’, ‘b1’, ‘b’, ‘x’.
1478
1479 The ordering imposed by .WAIT is only relevant for parallel
1480 makes.
1481
1483 Special targets may not be included with other targets, i.e. they must be
1484 the only target specified.
1485
1486 .BEGIN Any command lines attached to this target are executed before
1487 anything else is done.
1488
1489 .DEFAULT
1490 This is sort of a .USE rule for any target (that was used only
1491 as a source) that bmake can't figure out any other way to cre‐
1492 ate. Only the shell script is used. The .IMPSRC variable of a
1493 target that inherits .DEFAULT's commands is set to the target's
1494 own name.
1495
1496 .DELETE_ON_ERROR
1497 If this target is present in the makefile, it globally causes
1498 make to delete targets whose commands fail. (By default, only
1499 targets whose commands are interrupted during execution are
1500 deleted. This is the historical behavior.) This setting can be
1501 used to help prevent half-finished or malformed targets from be‐
1502 ing left around and corrupting future rebuilds.
1503
1504 .END Any command lines attached to this target are executed after ev‐
1505 erything else is done successfully.
1506
1507 .ERROR Any command lines attached to this target are executed when an‐
1508 other target fails. The .ERROR_TARGET variable is set to the
1509 target that failed. See also MAKE_PRINT_VAR_ON_ERROR.
1510
1511 .IGNORE Mark each of the sources with the .IGNORE attribute. If no
1512 sources are specified, this is the equivalent of specifying the
1513 -i option.
1514
1515 .INTERRUPT
1516 If bmake is interrupted, the commands for this target are exe‐
1517 cuted.
1518
1519 .MAIN If no target is specified when bmake is invoked, this target is
1520 built.
1521
1522 .MAKEFLAGS
1523 This target provides a way to specify flags for bmake at the
1524 time when the makefiles are read. The flags are as if typed to
1525 the shell, though the -f option has no effect.
1526
1527 .NOPATH Apply the .NOPATH attribute to any specified sources.
1528
1529 .NOTPARALLEL
1530 Disable parallel mode.
1531
1532 .NO_PARALLEL
1533 Synonym for .NOTPARALLEL, for compatibility with other pmake
1534 variants.
1535
1536 .OBJDIR The source is a new value for ‘.OBJDIR’. If it exists, bmake
1537 changes the current working directory to it and updates the
1538 value of ‘.OBJDIR’.
1539
1540 .ORDER In parallel mode, the named targets are made in sequence. This
1541 ordering does not add targets to the list of targets to be made.
1542
1543 Since the dependents of a target do not get built until the tar‐
1544 get itself could be built, unless ‘a’ is built by another part
1545 of the dependency graph, the following is a dependency loop:
1546
1547 .ORDER: b a
1548 b: a
1549
1550 .PATH The sources are directories which are to be searched for files
1551 not found in the current directory. If no sources are speci‐
1552 fied, any previously specified directories are removed from the
1553 search path. If the source is the special .DOTLAST target, the
1554 current working directory is searched last.
1555
1556 .PATH.suffix
1557 Like .PATH but applies only to files with a particular suffix.
1558 The suffix must have been previously declared with .SUFFIXES.
1559
1560 .PHONY Apply the .PHONY attribute to any specified sources.
1561
1562 .POSIX If this is the first non-comment line in the main makefile, the
1563 variable %POSIX is set to the value ‘1003.2’ and the makefile
1564 ‘<posix.mk>’ is included if it exists, to provide POSIX-compati‐
1565 ble default rules. If bmake is run with the -r flag, only
1566 ‘posix.mk’ contributes to the default rules.
1567
1568 .PRECIOUS
1569 Apply the .PRECIOUS attribute to any specified sources. If no
1570 sources are specified, the .PRECIOUS attribute is applied to ev‐
1571 ery target in the file.
1572
1573 .SHELL Sets the shell that bmake uses to execute commands in jobs mode.
1574 The sources are a set of field=value pairs.
1575
1576 name This is the minimal specification, used to select
1577 one of the built-in shell specs; sh, ksh, and csh.
1578
1579 path Specifies the absolute path to the shell.
1580
1581 hasErrCtl Indicates whether the shell supports exit on error.
1582
1583 check The command to turn on error checking.
1584
1585 ignore The command to disable error checking.
1586
1587 echo The command to turn on echoing of commands executed.
1588
1589 quiet The command to turn off echoing of commands exe‐
1590 cuted.
1591
1592 filter The output to filter after issuing the quiet com‐
1593 mand. It is typically identical to quiet.
1594
1595 errFlag The flag to pass the shell to enable error checking.
1596
1597 echoFlag The flag to pass the shell to enable command echo‐
1598 ing.
1599
1600 newline The string literal to pass the shell that results in
1601 a single newline character when used outside of any
1602 quoting characters.
1603 Example:
1604
1605 .SHELL: name=ksh path=/bin/ksh hasErrCtl=true \
1606 check="set -e" ignore="set +e" \
1607 echo="set -v" quiet="set +v" filter="set +v" \
1608 echoFlag=v errFlag=e newline="'\n'"
1609
1610 .SILENT Apply the .SILENT attribute to any specified sources. If no
1611 sources are specified, the .SILENT attribute is applied to every
1612 command in the file.
1613
1614 .STALE This target gets run when a dependency file contains stale en‐
1615 tries, having .ALLSRC set to the name of that dependency file.
1616
1617 .SUFFIXES
1618 Each source specifies a suffix to bmake. If no sources are
1619 specified, any previously specified suffixes are deleted. It
1620 allows the creation of suffix-transformation rules.
1621
1622 Example:
1623
1624 .SUFFIXES: .c .o
1625 .c.o:
1626 cc -o ${.TARGET} -c ${.IMPSRC}
1627
1629 bmake uses the following environment variables, if they exist: MACHINE,
1630 MACHINE_ARCH, MAKE, MAKEFLAGS, MAKEOBJDIR, MAKEOBJDIRPREFIX, MAKESYSPATH,
1631 PWD, and TMPDIR.
1632
1633 MAKEOBJDIRPREFIX and MAKEOBJDIR may only be set in the environment or on
1634 the command line to bmake and not as makefile variables; see the descrip‐
1635 tion of ‘.OBJDIR’ for more details.
1636
1638 .depend list of dependencies
1639 makefile first default makefile if no makefile is specified on the
1640 command line
1641 Makefile second default makefile if no makefile is specified on the
1642 command line
1643 sys.mk system makefile
1644 /usr/share/mk system makefile directory
1645
1647 The basic make syntax is compatible between different make variants; how‐
1648 ever the special variables, variable modifiers and conditionals are not.
1649
1650 Older versions
1651 An incomplete list of changes in older versions of bmake:
1652
1653 The way that .for loop variables are substituted changed after NetBSD 5.0
1654 so that they still appear to be variable expansions. In particular this
1655 stops them being treated as syntax, and removes some obscure problems us‐
1656 ing them in .if statements.
1657
1658 The way that parallel makes are scheduled changed in NetBSD 4.0 so that
1659 .ORDER and .WAIT apply recursively to the dependent nodes. The algo‐
1660 rithms used may change again in the future.
1661
1662 Other make dialects
1663 Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not sup‐
1664 port most of the features of bmake as described in this manual. Most no‐
1665 tably:
1666
1667 • The .WAIT and .ORDER declarations and most functionality per‐
1668 taining to parallelization. (GNU make supports parallelization
1669 but lacks the features needed to control it effectively.)
1670
1671 • Directives, including for loops and conditionals and most of
1672 the forms of include files. (GNU make has its own incompatible
1673 and less powerful syntax for conditionals.)
1674
1675 • All built-in variables that begin with a dot.
1676
1677 • Most of the special sources and targets that begin with a dot,
1678 with the notable exception of .PHONY, .PRECIOUS, and .SUFFIXES.
1679
1680 • Variable modifiers, except for the ‘:old=new’ string substitu‐
1681 tion, which does not portably support globbing with ‘%’ and
1682 historically only works on declared suffixes.
1683
1684 • The $> variable even in its short form; most makes support this
1685 functionality but its name varies.
1686
1687 Some features are somewhat more portable, such as assignment with +=, ?=,
1688 and !=. The .PATH functionality is based on an older feature VPATH found
1689 in GNU make and many versions of SVR4 make; however, historically its be‐
1690 havior is too ill-defined (and too buggy) to rely upon.
1691
1692 The $@ and $< variables are more or less universally portable, as is the
1693 $(MAKE) variable. Basic use of suffix rules (for files only in the cur‐
1694 rent directory, not trying to chain transformations together, etc.) is
1695 also reasonably portable.
1696
1698 mkdep(1)
1699
1701 bmake is derived from NetBSD make(1). It uses autoconf to facilitate
1702 portability to other platforms.
1703
1704 A make command appeared in Version 7 AT&T UNIX. This make implementation
1705 is based on Adam de Boor's pmake program, which was written for Sprite at
1706 Berkeley. It was designed to be a parallel distributed make running jobs
1707 on different machines using a daemon called “customs”.
1708
1709 Historically the target/dependency FRC has been used to FoRCe rebuilding
1710 (since the target/dependency does not exist ... unless someone creates an
1711 FRC file).
1712
1714 The make syntax is difficult to parse. For instance, finding the end of
1715 a variable's use should involve scanning each of the modifiers, using the
1716 correct terminator for each field. In many places make just counts {}
1717 and () in order to find the end of a variable expansion.
1718
1719 There is no way of escaping a space character in a filename.
1720
1721BSD January 1, 2023 BSD