1321964SsjgBMAKE(1)                NetBSD General Commands Manual                BMAKE(1)
2236769Sobrien
3236769SobrienNNAAMMEE
4236769Sobrien     bbmmaakkee -- maintain program dependencies
5236769Sobrien
6236769SobrienSSYYNNOOPPSSIISS
7253883Ssjg     bbmmaakkee [--BBeeiikkNNnnqqrrssttWWwwXX] [--CC _d_i_r_e_c_t_o_r_y] [--DD _v_a_r_i_a_b_l_e] [--dd _f_l_a_g_s]
8236769Sobrien           [--ff _m_a_k_e_f_i_l_e] [--II _d_i_r_e_c_t_o_r_y] [--JJ _p_r_i_v_a_t_e] [--jj _m_a_x___j_o_b_s]
9321964Ssjg           [--mm _d_i_r_e_c_t_o_r_y] [--TT _f_i_l_e] [--VV _v_a_r_i_a_b_l_e] [--vv _v_a_r_i_a_b_l_e]
10321964Ssjg           [_v_a_r_i_a_b_l_e_=_v_a_l_u_e] [_t_a_r_g_e_t _._._.]
11236769Sobrien
12236769SobrienDDEESSCCRRIIPPTTIIOONN
13236769Sobrien     bbmmaakkee is a program designed to simplify the maintenance of other pro-
14236769Sobrien     grams.  Its input is a list of specifications as to the files upon which
15236769Sobrien     programs and other files depend.  If no --ff _m_a_k_e_f_i_l_e makefile option is
16236769Sobrien     given, bbmmaakkee will try to open `_m_a_k_e_f_i_l_e' then `_M_a_k_e_f_i_l_e' in order to find
17236769Sobrien     the specifications.  If the file `_._d_e_p_e_n_d' exists, it is read (see
18236769Sobrien     mkdep(1)).
19236769Sobrien
20236769Sobrien     This manual page is intended as a reference document only.  For a more
21236769Sobrien     thorough description of bbmmaakkee and makefiles, please refer to _P_M_a_k_e _- _A
22236769Sobrien     _T_u_t_o_r_i_a_l.
23236769Sobrien
24236769Sobrien     bbmmaakkee will prepend the contents of the _M_A_K_E_F_L_A_G_S environment variable to
25236769Sobrien     the command line arguments before parsing them.
26236769Sobrien
27236769Sobrien     The options are as follows:
28236769Sobrien
29236769Sobrien     --BB      Try to be backwards compatible by executing a single shell per
30236769Sobrien             command and by executing the commands to make the sources of a
31236769Sobrien             dependency line in sequence.
32236769Sobrien
33236769Sobrien     --CC _d_i_r_e_c_t_o_r_y
34236769Sobrien             Change to _d_i_r_e_c_t_o_r_y before reading the makefiles or doing any-
35236769Sobrien             thing else.  If multiple --CC options are specified, each is inter-
36236769Sobrien             preted relative to the previous one: --CC _/ --CC _e_t_c is equivalent to
37236769Sobrien             --CC _/_e_t_c.
38236769Sobrien
39236769Sobrien     --DD _v_a_r_i_a_b_l_e
40236769Sobrien             Define _v_a_r_i_a_b_l_e to be 1, in the global context.
41236769Sobrien
42236769Sobrien     --dd _[_-_]_f_l_a_g_s
43236769Sobrien             Turn on debugging, and specify which portions of bbmmaakkee are to
44236769Sobrien             print debugging information.  Unless the flags are preceded by
45236769Sobrien             `-' they are added to the _M_A_K_E_F_L_A_G_S environment variable and will
46236769Sobrien             be processed by any child make processes.  By default, debugging
47236769Sobrien             information is printed to standard error, but this can be changed
48236769Sobrien             using the _F debugging flag.  The debugging output is always
49236769Sobrien             unbuffered; in addition, if debugging is enabled but debugging
50236769Sobrien             output is not directed to standard output, then the standard out-
51236769Sobrien             put is line buffered.  _F_l_a_g_s is one or more of the following:
52236769Sobrien
53236769Sobrien             _A       Print all possible debugging information; equivalent to
54236769Sobrien                     specifying all of the debugging flags.
55236769Sobrien
56236769Sobrien             _a       Print debugging information about archive searching and
57236769Sobrien                     caching.
58236769Sobrien
59236769Sobrien             _C       Print debugging information about current working direc-
60236769Sobrien                     tory.
61236769Sobrien
62236769Sobrien             _c       Print debugging information about conditional evaluation.
63236769Sobrien
64236769Sobrien             _d       Print debugging information about directory searching and
65236769Sobrien                     caching.
66236769Sobrien
67236769Sobrien             _e       Print debugging information about failed commands and
68236769Sobrien                     targets.
69236769Sobrien
70236769Sobrien             _F[++]_f_i_l_e_n_a_m_e
71236769Sobrien                     Specify where debugging output is written.  This must be
72236769Sobrien                     the last flag, because it consumes the remainder of the
73236769Sobrien                     argument.  If the character immediately after the `F'
74236769Sobrien                     flag is `+', then the file will be opened in append mode;
75236769Sobrien                     otherwise the file will be overwritten.  If the file name
76236769Sobrien                     is `stdout' or `stderr' then debugging output will be
77236769Sobrien                     written to the standard output or standard error output
78236769Sobrien                     file descriptors respectively (and the `+' option has no
79236769Sobrien                     effect).  Otherwise, the output will be written to the
80236769Sobrien                     named file.  If the file name ends `.%d' then the `%d' is
81236769Sobrien                     replaced by the pid.
82236769Sobrien
83236769Sobrien             _f       Print debugging information about loop evaluation.
84236769Sobrien
85236769Sobrien             _g_1      Print the input graph before making anything.
86236769Sobrien
87236769Sobrien             _g_2      Print the input graph after making everything, or before
88236769Sobrien                     exiting on error.
89236769Sobrien
90236769Sobrien             _g_3      Print the input graph before exiting on error.
91236769Sobrien
92236769Sobrien             _j       Print debugging information about running multiple
93236769Sobrien                     shells.
94236769Sobrien
95236769Sobrien             _l       Print commands in Makefiles regardless of whether or not
96236769Sobrien                     they are prefixed by `@' or other "quiet" flags.  Also
97236769Sobrien                     known as "loud" behavior.
98236769Sobrien
99236769Sobrien             _M       Print debugging information about "meta" mode decisions
100236769Sobrien                     about targets.
101236769Sobrien
102236769Sobrien             _m       Print debugging information about making targets, includ-
103236769Sobrien                     ing modification dates.
104236769Sobrien
105236769Sobrien             _n       Don't delete the temporary command scripts created when
106236769Sobrien                     running commands.  These temporary scripts are created in
107236769Sobrien                     the directory referred to by the TMPDIR environment vari-
108236769Sobrien                     able, or in _/_t_m_p if TMPDIR is unset or set to the empty
109236769Sobrien                     string.  The temporary scripts are created by mkstemp(3),
110236769Sobrien                     and have names of the form _m_a_k_e_X_X_X_X_X_X.  _N_O_T_E: This can
111236769Sobrien                     create many files in TMPDIR or _/_t_m_p, so use with care.
112236769Sobrien
113236769Sobrien             _p       Print debugging information about makefile parsing.
114236769Sobrien
115236769Sobrien             _s       Print debugging information about suffix-transformation
116236769Sobrien                     rules.
117236769Sobrien
118236769Sobrien             _t       Print debugging information about target list mainte-
119236769Sobrien                     nance.
120236769Sobrien
121321964Ssjg             _V       Force the --VV option to print raw values of variables,
122321964Ssjg                     overriding the default behavior set via
123321964Ssjg                     _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S.
124240330Smarcel
125236769Sobrien             _v       Print debugging information about variable assignment.
126236769Sobrien
127236769Sobrien             _x       Run shell commands with --xx so the actual commands are
128236769Sobrien                     printed as they are executed.
129236769Sobrien
130236769Sobrien     --ee      Specify that environment variables override macro assignments
131236769Sobrien             within makefiles.
132236769Sobrien
133236769Sobrien     --ff _m_a_k_e_f_i_l_e
134236769Sobrien             Specify a makefile to read instead of the default `_m_a_k_e_f_i_l_e'.  If
135236769Sobrien             _m_a_k_e_f_i_l_e is `--', standard input is read.  Multiple makefiles may
136236769Sobrien             be specified, and are read in the order specified.
137236769Sobrien
138236769Sobrien     --II _d_i_r_e_c_t_o_r_y
139236769Sobrien             Specify a directory in which to search for makefiles and included
140236769Sobrien             makefiles.  The system makefile directory (or directories, see
141236769Sobrien             the --mm option) is automatically included as part of this list.
142236769Sobrien
143236769Sobrien     --ii      Ignore non-zero exit of shell commands in the makefile.  Equiva-
144236769Sobrien             lent to specifying `--' before each command line in the makefile.
145236769Sobrien
146236769Sobrien     --JJ _p_r_i_v_a_t_e
147236769Sobrien             This option should _n_o_t be specified by the user.
148236769Sobrien
149236769Sobrien             When the _j option is in use in a recursive build, this option is
150236769Sobrien             passed by a make to child makes to allow all the make processes
151236769Sobrien             in the build to cooperate to avoid overloading the system.
152236769Sobrien
153236769Sobrien     --jj _m_a_x___j_o_b_s
154236769Sobrien             Specify the maximum number of jobs that bbmmaakkee may have running at
155236769Sobrien             any one time.  The value is saved in _._M_A_K_E_._J_O_B_S.  Turns compati-
156236769Sobrien             bility mode off, unless the _B flag is also specified.  When com-
157236769Sobrien             patibility mode is off, all commands associated with a target are
158236769Sobrien             executed in a single shell invocation as opposed to the tradi-
159236769Sobrien             tional one shell invocation per line.  This can break traditional
160236769Sobrien             scripts which change directories on each command invocation and
161236769Sobrien             then expect to start with a fresh environment on the next line.
162236769Sobrien             It is more efficient to correct the scripts rather than turn
163236769Sobrien             backwards compatibility on.
164236769Sobrien
165236769Sobrien     --kk      Continue processing after errors are encountered, but only on
166236769Sobrien             those targets that do not depend on the target whose creation
167236769Sobrien             caused the error.
168236769Sobrien
169236769Sobrien     --mm _d_i_r_e_c_t_o_r_y
170236769Sobrien             Specify a directory in which to search for sys.mk and makefiles
171236769Sobrien             included via the <_f_i_l_e>-style include statement.  The --mm option
172236769Sobrien             can be used multiple times to form a search path.  This path will
173236769Sobrien             override the default system include path: /usr/share/mk.  Fur-
174236769Sobrien             thermore the system include path will be appended to the search
175236769Sobrien             path used for "_f_i_l_e"-style include statements (see the --II
176236769Sobrien             option).
177236769Sobrien
178236769Sobrien             If a file or directory name in the --mm argument (or the
179236769Sobrien             MAKESYSPATH environment variable) starts with the string ".../"
180236769Sobrien             then bbmmaakkee will search for the specified file or directory named
181236769Sobrien             in the remaining part of the argument string.  The search starts
182236769Sobrien             with the current directory of the Makefile and then works upward
183321964Ssjg             towards the root of the file system.  If the search is success-
184321964Ssjg             ful, then the resulting directory replaces the ".../" specifica-
185321964Ssjg             tion in the --mm argument.  If used, this feature allows bbmmaakkee to
186321964Ssjg             easily search in the current source tree for customized sys.mk
187321964Ssjg             files (e.g., by using ".../mk/sys.mk" as an argument).
188236769Sobrien
189236769Sobrien     --nn      Display the commands that would have been executed, but do not
190236769Sobrien             actually execute them unless the target depends on the .MAKE spe-
191236769Sobrien             cial source (see below).
192236769Sobrien
193236769Sobrien     --NN      Display the commands which would have been executed, but do not
194236769Sobrien             actually execute any of them; useful for debugging top-level
195236769Sobrien             makefiles without descending into subdirectories.
196236769Sobrien
197236769Sobrien     --qq      Do not execute any commands, but exit 0 if the specified targets
198236769Sobrien             are up-to-date and 1, otherwise.
199236769Sobrien
200236769Sobrien     --rr      Do not use the built-in rules specified in the system makefile.
201236769Sobrien
202236769Sobrien     --ss      Do not echo any commands as they are executed.  Equivalent to
203236769Sobrien             specifying `@@' before each command line in the makefile.
204236769Sobrien
205236769Sobrien     --TT _t_r_a_c_e_f_i_l_e
206236769Sobrien             When used with the --jj flag, append a trace record to _t_r_a_c_e_f_i_l_e
207236769Sobrien             for each job started and completed.
208236769Sobrien
209236769Sobrien     --tt      Rather than re-building a target as specified in the makefile,
210236769Sobrien             create it or update its modification time to make it appear up-
211236769Sobrien             to-date.
212236769Sobrien
213236769Sobrien     --VV _v_a_r_i_a_b_l_e
214321964Ssjg             Print the value of _v_a_r_i_a_b_l_e.  Do not build any targets.  Multiple
215321964Ssjg             instances of this option may be specified; the variables will be
216321964Ssjg             printed one per line, with a blank line for each null or unde-
217321964Ssjg             fined variable.  The value printed is extracted from the global
218321964Ssjg             context after all makefiles have been read.  By default, the raw
219321964Ssjg             variable contents (which may include additional unexpanded vari-
220321964Ssjg             able references) are shown.  If _v_a_r_i_a_b_l_e contains a `$' then the
221321964Ssjg             value will be recursively expanded to its complete resultant text
222321964Ssjg             before printing.  The expanded value will also be printed if
223321964Ssjg             _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S is set to true and the --ddVV option has not
224321964Ssjg             been used to override it.  Note that loop-local and target-local
225321964Ssjg             variables, as well as values taken temporarily by global vari-
226321964Ssjg             ables during makefile processing, are not accessible via this
227321964Ssjg             option.  The --ddvv debug mode can be used to see these at the cost
228321964Ssjg             of generating substantial extraneous output.
229236769Sobrien
230321964Ssjg     --vv _v_a_r_i_a_b_l_e
231321964Ssjg             Like --VV but the variable is always expanded to its complete
232321964Ssjg             value.
233321964Ssjg
234236769Sobrien     --WW      Treat any warnings during makefile parsing as errors.
235236769Sobrien
236292068Ssjg     --ww      Print entering and leaving directory messages, pre and post pro-
237292068Ssjg             cessing.
238292068Ssjg
239236769Sobrien     --XX      Don't export variables passed on the command line to the environ-
240236769Sobrien             ment individually.  Variables passed on the command line are
241236769Sobrien             still exported via the _M_A_K_E_F_L_A_G_S environment variable.  This
242236769Sobrien             option may be useful on systems which have a small limit on the
243236769Sobrien             size of command arguments.
244236769Sobrien
245236769Sobrien     _v_a_r_i_a_b_l_e_=_v_a_l_u_e
246236769Sobrien             Set the value of the variable _v_a_r_i_a_b_l_e to _v_a_l_u_e.  Normally, all
247236769Sobrien             values passed on the command line are also exported to sub-makes
248236769Sobrien             in the environment.  The --XX flag disables this behavior.  Vari-
249236769Sobrien             able assignments should follow options for POSIX compatibility
250236769Sobrien             but no ordering is enforced.
251236769Sobrien
252236769Sobrien     There are seven different types of lines in a makefile: file dependency
253236769Sobrien     specifications, shell commands, variable assignments, include statements,
254236769Sobrien     conditional directives, for loops, and comments.
255236769Sobrien
256236769Sobrien     In general, lines may be continued from one line to the next by ending
257236769Sobrien     them with a backslash (`\').  The trailing newline character and initial
258236769Sobrien     whitespace on the following line are compressed into a single space.
259236769Sobrien
260236769SobrienFFIILLEE DDEEPPEENNDDEENNCCYY SSPPEECCIIFFIICCAATTIIOONNSS
261236769Sobrien     Dependency lines consist of one or more targets, an operator, and zero or
262236769Sobrien     more sources.  This creates a relationship where the targets ``depend''
263236769Sobrien     on the sources and are usually created from them.  The exact relationship
264236769Sobrien     between the target and the source is determined by the operator that sep-
265236769Sobrien     arates them.  The three operators are as follows:
266236769Sobrien
267236769Sobrien     ::     A target is considered out-of-date if its modification time is less
268236769Sobrien           than those of any of its sources.  Sources for a target accumulate
269236769Sobrien           over dependency lines when this operator is used.  The target is
270236769Sobrien           removed if bbmmaakkee is interrupted.
271236769Sobrien
272236769Sobrien     !!     Targets are always re-created, but not until all sources have been
273236769Sobrien           examined and re-created as necessary.  Sources for a target accumu-
274236769Sobrien           late over dependency lines when this operator is used.  The target
275236769Sobrien           is removed if bbmmaakkee is interrupted.
276236769Sobrien
277236769Sobrien     ::::    If no sources are specified, the target is always re-created.  Oth-
278236769Sobrien           erwise, a target is considered out-of-date if any of its sources
279236769Sobrien           has been modified more recently than the target.  Sources for a
280236769Sobrien           target do not accumulate over dependency lines when this operator
281236769Sobrien           is used.  The target will not be removed if bbmmaakkee is interrupted.
282236769Sobrien
283236769Sobrien     Targets and sources may contain the shell wildcard values `?', `*', `[]',
284236769Sobrien     and `{}'.  The values `?', `*', and `[]' may only be used as part of the
285236769Sobrien     final component of the target or source, and must be used to describe
286236769Sobrien     existing files.  The value `{}' need not necessarily be used to describe
287236769Sobrien     existing files.  Expansion is in directory order, not alphabetically as
288236769Sobrien     done in the shell.
289236769Sobrien
290236769SobrienSSHHEELLLL CCOOMMMMAANNDDSS
291292068Ssjg     Each target may have associated with it one or more lines of shell com-
292292068Ssjg     mands, normally used to create the target.  Each of the lines in this
293292068Ssjg     script _m_u_s_t be preceded by a tab.  (For historical reasons, spaces are
294292068Ssjg     not accepted.)  While targets can appear in many dependency lines if
295292068Ssjg     desired, by default only one of these rules may be followed by a creation
296292068Ssjg     script.  If the `::::' operator is used, however, all rules may include
297292068Ssjg     scripts and the scripts are executed in the order found.
298236769Sobrien
299292068Ssjg     Each line is treated as a separate shell command, unless the end of line
300292068Ssjg     is escaped with a backslash (`\') in which case that line and the next
301292068Ssjg     are combined.  If the first characters of the command are any combination
302292068Ssjg     of `@@', `++', or `--', the command is treated specially.  A `@@' causes the
303292068Ssjg     command not to be echoed before it is executed.  A `++' causes the command
304292068Ssjg     to be executed even when --nn is given.  This is similar to the effect of
305292068Ssjg     the .MAKE special source, except that the effect can be limited to a sin-
306292068Ssjg     gle line of a script.  A `--' in compatibility mode causes any non-zero
307292068Ssjg     exit status of the command line to be ignored.
308236769Sobrien
309246223Ssjg     When bbmmaakkee is run in jobs mode with --jj _m_a_x___j_o_b_s, the entire script for
310292068Ssjg     the target is fed to a single instance of the shell.  In compatibility
311292068Ssjg     (non-jobs) mode, each command is run in a separate process.  If the com-
312292068Ssjg     mand contains any shell meta characters (`#=|^(){};&<>*?[]:$`\\n') it
313292068Ssjg     will be passed to the shell; otherwise bbmmaakkee will attempt direct execu-
314292068Ssjg     tion.  If a line starts with `--' and the shell has ErrCtl enabled then
315292068Ssjg     failure of the command line will be ignored as in compatibility mode.
316292068Ssjg     Otherwise `--' affects the entire job; the script will stop at the first
317292068Ssjg     command line that fails, but the target will not be deemed to have
318292068Ssjg     failed.
319246223Ssjg
320246223Ssjg     Makefiles should be written so that the mode of bbmmaakkee operation does not
321246223Ssjg     change their behavior.  For example, any command which needs to use
322292068Ssjg     ``cd'' or ``chdir'' without potentially changing the directory for subse-
323292068Ssjg     quent commands should be put in parentheses so it executes in a subshell.
324292068Ssjg     To force the use of one shell, escape the line breaks so as to make the
325292068Ssjg     whole script one command.  For example:
326246223Ssjg
327246223Ssjg           avoid-chdir-side-effects:
328246223Ssjg                   @echo Building $@ in `pwd`
329292068Ssjg                   @(cd ${.CURDIR} && ${MAKE} $@)
330246223Ssjg                   @echo Back in `pwd`
331246223Ssjg
332246223Ssjg           ensure-one-shell-regardless-of-mode:
333246223Ssjg                   @echo Building $@ in `pwd`; \
334292068Ssjg                   (cd ${.CURDIR} && ${MAKE} $@); \
335246223Ssjg                   echo Back in `pwd`
336246223Ssjg
337292068Ssjg     Since bbmmaakkee will chdir(2) to `_._O_B_J_D_I_R' before executing any targets, each
338292068Ssjg     child process starts with that as its current working directory.
339292068Ssjg
340236769SobrienVVAARRIIAABBLLEE AASSSSIIGGNNMMEENNTTSS
341236769Sobrien     Variables in make are much like variables in the shell, and, by tradi-
342236769Sobrien     tion, consist of all upper-case letters.
343236769Sobrien
344236769Sobrien   VVaarriiaabbllee aassssiiggnnmmeenntt mmooddiiffiieerrss
345236769Sobrien     The five operators that can be used to assign values to variables are as
346236769Sobrien     follows:
347236769Sobrien
348236769Sobrien     ==       Assign the value to the variable.  Any previous value is overrid-
349236769Sobrien             den.
350236769Sobrien
351236769Sobrien     ++==      Append the value to the current value of the variable.
352236769Sobrien
353236769Sobrien     ??==      Assign the value to the variable if it is not already defined.
354236769Sobrien
355236769Sobrien     ::==      Assign with expansion, i.e. expand the value before assigning it
356236769Sobrien             to the variable.  Normally, expansion is not done until the vari-
357236769Sobrien             able is referenced.  _N_O_T_E: References to undefined variables are
358236769Sobrien             _n_o_t expanded.  This can cause problems when variable modifiers
359236769Sobrien             are used.
360236769Sobrien
361236769Sobrien     !!==      Expand the value and pass it to the shell for execution and
362236769Sobrien             assign the result to the variable.  Any newlines in the result
363236769Sobrien             are replaced with spaces.
364236769Sobrien
365236769Sobrien     Any white-space before the assigned _v_a_l_u_e is removed; if the value is
366236769Sobrien     being appended, a single space is inserted between the previous contents
367236769Sobrien     of the variable and the appended value.
368236769Sobrien
369236769Sobrien     Variables are expanded by surrounding the variable name with either curly
370236769Sobrien     braces (`{}') or parentheses (`()') and preceding it with a dollar sign
371236769Sobrien     (`$').  If the variable name contains only a single letter, the surround-
372236769Sobrien     ing braces or parentheses are not required.  This shorter form is not
373236769Sobrien     recommended.
374236769Sobrien
375236769Sobrien     If the variable name contains a dollar, then the name itself is expanded
376236769Sobrien     first.  This allows almost arbitrary variable names, however names con-
377236769Sobrien     taining dollar, braces, parenthesis, or whitespace are really best
378236769Sobrien     avoided!
379236769Sobrien
380236769Sobrien     If the result of expanding a variable contains a dollar sign (`$') the
381236769Sobrien     string is expanded again.
382236769Sobrien
383236769Sobrien     Variable substitution occurs at three distinct times, depending on where
384236769Sobrien     the variable is being used.
385236769Sobrien
386236769Sobrien     1.   Variables in dependency lines are expanded as the line is read.
387236769Sobrien
388236769Sobrien     2.   Variables in shell commands are expanded when the shell command is
389236769Sobrien          executed.
390236769Sobrien
391236769Sobrien     3.   ``.for'' loop index variables are expanded on each loop iteration.
392236769Sobrien          Note that other variables are not expanded inside loops so the fol-
393236769Sobrien          lowing example code:
394236769Sobrien
395236769Sobrien
396236769Sobrien                .for i in 1 2 3
397236769Sobrien                a+=     ${i}
398236769Sobrien                j=      ${i}
399236769Sobrien                b+=     ${j}
400236769Sobrien                .endfor
401236769Sobrien
402236769Sobrien                all:
403236769Sobrien                        @echo ${a}
404236769Sobrien                        @echo ${b}
405236769Sobrien
406236769Sobrien          will print:
407236769Sobrien
408236769Sobrien                1 2 3
409236769Sobrien                3 3 3
410236769Sobrien
411236769Sobrien          Because while ${a} contains ``1 2 3'' after the loop is executed,
412236769Sobrien          ${b} contains ``${j} ${j} ${j}'' which expands to ``3 3 3'' since
413236769Sobrien          after the loop completes ${j} contains ``3''.
414236769Sobrien
415236769Sobrien   VVaarriiaabbllee ccllaasssseess
416236769Sobrien     The four different classes of variables (in order of increasing prece-
417236769Sobrien     dence) are:
418236769Sobrien
419236769Sobrien     Environment variables
420236769Sobrien             Variables defined as part of bbmmaakkee's environment.
421236769Sobrien
422236769Sobrien     Global variables
423236769Sobrien             Variables defined in the makefile or in included makefiles.
424236769Sobrien
425236769Sobrien     Command line variables
426236769Sobrien             Variables defined as part of the command line.
427236769Sobrien
428236769Sobrien     Local variables
429292068Ssjg             Variables that are defined specific to a certain target.
430236769Sobrien
431292068Ssjg     Local variables are all built in and their values vary magically from
432292068Ssjg     target to target.  It is not currently possible to define new local vari-
433292068Ssjg     ables.  The seven local variables are as follows:
434236769Sobrien
435292068Ssjg           _._A_L_L_S_R_C   The list of all sources for this target; also known as
436292068Ssjg                     `_>'.
437236769Sobrien
438292068Ssjg           _._A_R_C_H_I_V_E  The name of the archive file; also known as `_!'.
439236769Sobrien
440292068Ssjg           _._I_M_P_S_R_C   In suffix-transformation rules, the name/path of the
441292068Ssjg                     source from which the target is to be transformed (the
442292068Ssjg                     ``implied'' source); also known as `_<'.  It is not
443292068Ssjg                     defined in explicit rules.
444236769Sobrien
445292068Ssjg           _._M_E_M_B_E_R   The name of the archive member; also known as `_%'.
446236769Sobrien
447292068Ssjg           _._O_O_D_A_T_E   The list of sources for this target that were deemed out-
448292068Ssjg                     of-date; also known as `_?'.
449236769Sobrien
450292068Ssjg           _._P_R_E_F_I_X   The file prefix of the target, containing only the file
451292068Ssjg                     portion, no suffix or preceding directory components;
452292068Ssjg                     also known as `_*'.  The suffix must be one of the known
453292068Ssjg                     suffixes declared with ..SSUUFFFFIIXXEESS or it will not be recog-
454292068Ssjg                     nized.
455236769Sobrien
456321964Ssjg           _._T_A_R_G_E_T   The name of the target; also known as `_@'.  For compati-
457321964Ssjg                     bility with other makes this is an alias for ..AARRCCHHIIVVEE in
458321964Ssjg                     archive member rules.
459236769Sobrien
460292068Ssjg     The shorter forms (`_>', `_!', `_<', `_%', `_?', `_*', and `_@') are permitted
461292068Ssjg     for backward compatibility with historical makefiles and legacy POSIX
462292068Ssjg     make and are not recommended.
463236769Sobrien
464292068Ssjg     Variants of these variables with the punctuation followed immediately by
465292068Ssjg     `D' or `F', e.g.  `_$_(_@_D_)', are legacy forms equivalent to using the `:H'
466292068Ssjg     and `:T' modifiers.  These forms are accepted for compatibility with AT&T
467292068Ssjg     System V UNIX makefiles and POSIX but are not recommended.
468292068Ssjg
469292068Ssjg     Four of the local variables may be used in sources on dependency lines
470292068Ssjg     because they expand to the proper value for each target on the line.
471292068Ssjg     These variables are `_._T_A_R_G_E_T', `_._P_R_E_F_I_X', `_._A_R_C_H_I_V_E', and `_._M_E_M_B_E_R'.
472292068Ssjg
473236769Sobrien   AAddddiittiioonnaall bbuuiilltt--iinn vvaarriiaabblleess
474236769Sobrien     In addition, bbmmaakkee sets or knows about the following variables:
475236769Sobrien
476236769Sobrien     _$               A single dollar sign `$', i.e.  `$$' expands to a single
477236769Sobrien                     dollar sign.
478236769Sobrien
479236769Sobrien     _._A_L_L_T_A_R_G_E_T_S     The list of all targets encountered in the Makefile.  If
480236769Sobrien                     evaluated during Makefile parsing, lists only those tar-
481236769Sobrien                     gets encountered thus far.
482236769Sobrien
483236769Sobrien     _._C_U_R_D_I_R         A path to the directory where bbmmaakkee was executed.  Refer
484236769Sobrien                     to the description of `PWD' for more details.
485236769Sobrien
486276305Sngie     _._I_N_C_L_U_D_E_D_F_R_O_M_D_I_R
487276305Sngie                     The directory of the file this Makefile was included
488276305Sngie                     from.
489276305Sngie
490276305Sngie     _._I_N_C_L_U_D_E_D_F_R_O_M_F_I_L_E
491276305Sngie                     The filename of the file this Makefile was included from.
492276305Sngie
493236769Sobrien     MAKE            The name that bbmmaakkee was executed with (_a_r_g_v_[_0_]).  For
494236769Sobrien                     compatibility bbmmaakkee also sets _._M_A_K_E with the same value.
495236769Sobrien                     The preferred variable to use is the environment variable
496236769Sobrien                     MAKE because it is more compatible with other versions of
497236769Sobrien                     bbmmaakkee and cannot be confused with the special target with
498236769Sobrien                     the same name.
499236769Sobrien
500236769Sobrien     _._M_A_K_E_._D_E_P_E_N_D_F_I_L_E
501236769Sobrien                     Names the makefile (default `_._d_e_p_e_n_d') from which gener-
502236769Sobrien                     ated dependencies are read.
503236769Sobrien
504240330Smarcel     _._M_A_K_E_._E_X_P_A_N_D___V_A_R_I_A_B_L_E_S
505240330Smarcel                     A boolean that controls the default behavior of the --VV
506321964Ssjg                     option.  If true, variable values printed with --VV are
507321964Ssjg                     fully expanded; if false, the raw variable contents
508321964Ssjg                     (which may include additional unexpanded variable refer-
509321964Ssjg                     ences) are shown.
510240330Smarcel
511236769Sobrien     _._M_A_K_E_._E_X_P_O_R_T_E_D  The list of variables exported by bbmmaakkee.
512236769Sobrien
513236769Sobrien     _._M_A_K_E_._J_O_B_S      The argument to the --jj option.
514236769Sobrien
515236769Sobrien     _._M_A_K_E_._J_O_B_._P_R_E_F_I_X
516236769Sobrien                     If bbmmaakkee is run with _j then output for each target is
517236769Sobrien                     prefixed with a token `--- target ---' the first part of
518253883Ssjg                     which can be controlled via _._M_A_K_E_._J_O_B_._P_R_E_F_I_X.  If
519253883Ssjg                     _._M_A_K_E_._J_O_B_._P_R_E_F_I_X is empty, no token is printed.
520236769Sobrien                     For example:
521236769Sobrien                     .MAKE.JOB.PREFIX=${.newline}---${.MAKE:T}[${.MAKE.PID}]
522236769Sobrien                     would produce tokens like `---make[1234] target ---' mak-
523236769Sobrien                     ing it easier to track the degree of parallelism being
524236769Sobrien                     achieved.
525236769Sobrien
526236769Sobrien     MAKEFLAGS       The environment variable `MAKEFLAGS' may contain anything
527236769Sobrien                     that may be specified on bbmmaakkee's command line.  Anything
528236769Sobrien                     specified on bbmmaakkee's command line is appended to the
529236769Sobrien                     `MAKEFLAGS' variable which is then entered into the envi-
530236769Sobrien                     ronment for all programs which bbmmaakkee executes.
531236769Sobrien
532236769Sobrien     _._M_A_K_E_._L_E_V_E_L     The recursion depth of bbmmaakkee.  The initial instance of
533236769Sobrien                     bbmmaakkee will be 0, and an incremented value is put into the
534236769Sobrien                     environment to be seen by the next generation.  This
535236769Sobrien                     allows tests like: .if ${.MAKE.LEVEL} == 0 to protect
536236769Sobrien                     things which should only be evaluated in the initial
537236769Sobrien                     instance of bbmmaakkee.
538236769Sobrien
539236769Sobrien     _._M_A_K_E_._M_A_K_E_F_I_L_E___P_R_E_F_E_R_E_N_C_E
540236769Sobrien                     The ordered list of makefile names (default `_m_a_k_e_f_i_l_e',
541236769Sobrien                     `_M_a_k_e_f_i_l_e') that bbmmaakkee will look for.
542236769Sobrien
543236769Sobrien     _._M_A_K_E_._M_A_K_E_F_I_L_E_S
544236769Sobrien                     The list of makefiles read by bbmmaakkee, which is useful for
545236769Sobrien                     tracking dependencies.  Each makefile is recorded only
546236769Sobrien                     once, regardless of the number of times read.
547236769Sobrien
548236769Sobrien     _._M_A_K_E_._M_O_D_E      Processed after reading all makefiles.  Can affect the
549236769Sobrien                     mode that bbmmaakkee runs in.  It can contain a number of key-
550236769Sobrien                     words:
551236769Sobrien
552321964Ssjg                     _c_o_m_p_a_t               Like --BB, puts bbmmaakkee into "compat"
553321964Ssjg                                          mode.
554236769Sobrien
555321964Ssjg                     _m_e_t_a                 Puts bbmmaakkee into "meta" mode, where
556321964Ssjg                                          meta files are created for each tar-
557321964Ssjg                                          get to capture the command run, the
558321964Ssjg                                          output generated and if filemon(4)
559321964Ssjg                                          is available, the system calls which
560321964Ssjg                                          are of interest to bbmmaakkee.  The cap-
561321964Ssjg                                          tured output can be very useful when
562321964Ssjg                                          diagnosing errors.
563236769Sobrien
564321964Ssjg                     _c_u_r_d_i_r_O_k_= _b_f         Normally bbmmaakkee will not create .meta
565321964Ssjg                                          files in `_._C_U_R_D_I_R'.  This can be
566321964Ssjg                                          overridden by setting _b_f to a value
567321964Ssjg                                          which represents True.
568236769Sobrien
569321964Ssjg                     _m_i_s_s_i_n_g_-_m_e_t_a_= _b_f     If _b_f is True, then a missing .meta
570321964Ssjg                                          file makes the target out-of-date.
571236769Sobrien
572321964Ssjg                     _m_i_s_s_i_n_g_-_f_i_l_e_m_o_n_= _b_f  If _b_f is True, then missing filemon
573321964Ssjg                                          data makes the target out-of-date.
574236769Sobrien
575321964Ssjg                     _n_o_f_i_l_e_m_o_n            Do not use filemon(4).
576236769Sobrien
577321964Ssjg                     _e_n_v                  For debugging, it can be useful to
578321964Ssjg                                          include the environment in the .meta
579321964Ssjg                                          file.
580236769Sobrien
581321964Ssjg                     _v_e_r_b_o_s_e              If in "meta" mode, print a clue
582321964Ssjg                                          about the target being built.  This
583321964Ssjg                                          is useful if the build is otherwise
584321964Ssjg                                          running silently.  The message
585321964Ssjg                                          printed the value of:
586321964Ssjg                                          _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X.
587321964Ssjg
588321964Ssjg                     _i_g_n_o_r_e_-_c_m_d           Some makefiles have commands which
589321964Ssjg                                          are simply not stable.  This keyword
590321964Ssjg                                          causes them to be ignored for deter-
591321964Ssjg                                          mining whether a target is out of
592321964Ssjg                                          date in "meta" mode.  See also
593321964Ssjg                                          ..NNOOMMEETTAA__CCMMPP.
594321964Ssjg
595321964Ssjg                     _s_i_l_e_n_t_= _b_f           If _b_f is True, when a .meta file is
596321964Ssjg                                          created, mark the target ..SSIILLEENNTT.
597321964Ssjg
598236769Sobrien     _._M_A_K_E_._M_E_T_A_._B_A_I_L_I_W_I_C_K
599236769Sobrien                     In "meta" mode, provides a list of prefixes which match
600236769Sobrien                     the directories controlled by bbmmaakkee.  If a file that was
601236769Sobrien                     generated outside of _._O_B_J_D_I_R but within said bailiwick is
602236769Sobrien                     missing, the current target is considered out-of-date.
603236769Sobrien
604236769Sobrien     _._M_A_K_E_._M_E_T_A_._C_R_E_A_T_E_D
605236769Sobrien                     In "meta" mode, this variable contains a list of all the
606236769Sobrien                     meta files updated.  If not empty, it can be used to
607236769Sobrien                     trigger processing of _._M_A_K_E_._M_E_T_A_._F_I_L_E_S.
608236769Sobrien
609236769Sobrien     _._M_A_K_E_._M_E_T_A_._F_I_L_E_S
610236769Sobrien                     In "meta" mode, this variable contains a list of all the
611236769Sobrien                     meta files used (updated or not).  This list can be used
612236769Sobrien                     to process the meta files to extract dependency informa-
613236769Sobrien                     tion.
614236769Sobrien
615253883Ssjg     _._M_A_K_E_._M_E_T_A_._I_G_N_O_R_E___P_A_T_H_S
616253883Ssjg                     Provides a list of path prefixes that should be ignored;
617253883Ssjg                     because the contents are expected to change over time.
618253883Ssjg                     The default list includes: `_/_d_e_v _/_e_t_c _/_p_r_o_c _/_t_m_p _/_v_a_r_/_r_u_n
619253883Ssjg                     _/_v_a_r_/_t_m_p'
620253883Ssjg
621321964Ssjg     _._M_A_K_E_._M_E_T_A_._I_G_N_O_R_E___P_A_T_T_E_R_N_S
622321964Ssjg                     Provides a list of patterns to match against pathnames.
623321964Ssjg                     Ignore any that match.
624321964Ssjg
625321964Ssjg     _._M_A_K_E_._M_E_T_A_._I_G_N_O_R_E___F_I_L_T_E_R
626321964Ssjg                     Provides a list of variable modifiers to apply to each
627321964Ssjg                     pathname.  Ignore if the expansion is an empty string.
628321964Ssjg
629236769Sobrien     _._M_A_K_E_._M_E_T_A_._P_R_E_F_I_X
630236769Sobrien                     Defines the message printed for each meta file updated in
631236769Sobrien                     "meta verbose" mode.  The default value is:
632236769Sobrien                           Building ${.TARGET:H:tA}/${.TARGET:T}
633236769Sobrien
634236769Sobrien     _._M_A_K_E_O_V_E_R_R_I_D_E_S  This variable is used to record the names of variables
635236769Sobrien                     assigned to on the command line, so that they may be
636321964Ssjg                     exported as part of `MAKEFLAGS'.  This behavior can be
637236769Sobrien                     disabled by assigning an empty value to `_._M_A_K_E_O_V_E_R_R_I_D_E_S'
638236769Sobrien                     within a makefile.  Extra variables can be exported from
639236769Sobrien                     a makefile by appending their names to `_._M_A_K_E_O_V_E_R_R_I_D_E_S'.
640236769Sobrien                     `MAKEFLAGS' is re-exported whenever `_._M_A_K_E_O_V_E_R_R_I_D_E_S' is
641236769Sobrien                     modified.
642236769Sobrien
643249033Ssjg     _._M_A_K_E_._P_A_T_H___F_I_L_E_M_O_N
644249033Ssjg                     If bbmmaakkee was built with filemon(4) support, this is set
645249033Ssjg                     to the path of the device node.  This allows makefiles to
646249033Ssjg                     test for this support.
647249033Ssjg
648236769Sobrien     _._M_A_K_E_._P_I_D       The process-id of bbmmaakkee.
649236769Sobrien
650236769Sobrien     _._M_A_K_E_._P_P_I_D      The parent process-id of bbmmaakkee.
651236769Sobrien
652321964Ssjg     _._M_A_K_E_._S_A_V_E___D_O_L_L_A_R_S
653321964Ssjg                     value should be a boolean that controls whether `$$' are
654321964Ssjg                     preserved when doing `:=' assignments.  The default is
655321964Ssjg                     false, for backwards compatibility.  Set to true for com-
656321964Ssjg                     patability with other makes.  If set to false, `$$'
657321964Ssjg                     becomes `$' per normal evaluation rules.
658321964Ssjg
659236769Sobrien     _M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R
660321964Ssjg                     When bbmmaakkee stops due to an error, it sets `_._E_R_R_O_R___T_A_R_G_E_T'
661321964Ssjg                     to the name of the target that failed, `_._E_R_R_O_R___C_M_D' to
662321964Ssjg                     the commands of the failed target, and in "meta" mode, it
663321964Ssjg                     also sets `_._E_R_R_O_R___C_W_D' to the getcwd(3), and
664321964Ssjg                     `_._E_R_R_O_R___M_E_T_A___F_I_L_E' to the path of the meta file (if any)
665321964Ssjg                     describing the failed target.  It then prints its name
666321964Ssjg                     and the value of `_._C_U_R_D_I_R' as well as the value of any
667321964Ssjg                     variables named in `_M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R'.
668236769Sobrien
669236769Sobrien     _._n_e_w_l_i_n_e        This variable is simply assigned a newline character as
670236769Sobrien                     its value.  This allows expansions using the ::@@ modifier
671236769Sobrien                     to put a newline between iterations of the loop rather
672236769Sobrien                     than a space.  For example, the printing of
673236769Sobrien                     `_M_A_K_E___P_R_I_N_T___V_A_R___O_N___E_R_R_O_R' could be done as
674236769Sobrien                     ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}.
675236769Sobrien
676236769Sobrien     _._O_B_J_D_I_R         A path to the directory where the targets are built.  Its
677236769Sobrien                     value is determined by trying to chdir(2) to the follow-
678236769Sobrien                     ing directories in order and using the first match:
679236769Sobrien
680236769Sobrien                     1.   ${MAKEOBJDIRPREFIX}${.CURDIR}
681236769Sobrien
682236769Sobrien                          (Only if `MAKEOBJDIRPREFIX' is set in the environ-
683236769Sobrien                          ment or on the command line.)
684236769Sobrien
685236769Sobrien                     2.   ${MAKEOBJDIR}
686236769Sobrien
687236769Sobrien                          (Only if `MAKEOBJDIR' is set in the environment or
688236769Sobrien                          on the command line.)
689236769Sobrien
690236769Sobrien                     3.   ${.CURDIR}_/_o_b_j_.${MACHINE}
691236769Sobrien
692236769Sobrien                     4.   ${.CURDIR}_/_o_b_j
693236769Sobrien
694236769Sobrien                     5.   _/_u_s_r_/_o_b_j_/${.CURDIR}
695236769Sobrien
696236769Sobrien                     6.   ${.CURDIR}
697236769Sobrien
698236769Sobrien                     Variable expansion is performed on the value before it's
699236769Sobrien                     used, so expressions such as
700236769Sobrien                           ${.CURDIR:S,^/usr/src,/var/obj,}
701236769Sobrien                     may be used.  This is especially useful with
702236769Sobrien                     `MAKEOBJDIR'.
703236769Sobrien
704292068Ssjg                     `_._O_B_J_D_I_R' may be modified in the makefile via the special
705292068Ssjg                     target `..OOBBJJDDIIRR'.  In all cases, bbmmaakkee will chdir(2) to
706292068Ssjg                     the specified directory if it exists, and set `_._O_B_J_D_I_R'
707292068Ssjg                     and `PWD' to that directory before executing any targets.
708236769Sobrien
709236769Sobrien     _._P_A_R_S_E_D_I_R       A path to the directory of the current `_M_a_k_e_f_i_l_e' being
710236769Sobrien                     parsed.
711236769Sobrien
712236769Sobrien     _._P_A_R_S_E_F_I_L_E      The basename of the current `_M_a_k_e_f_i_l_e' being parsed.
713236769Sobrien                     This variable and `_._P_A_R_S_E_D_I_R' are both set only while the
714236769Sobrien                     `_M_a_k_e_f_i_l_e_s' are being parsed.  If you want to retain
715236769Sobrien                     their current values, assign them to a variable using
716236769Sobrien                     assignment with expansion: (`::==').
717236769Sobrien
718236769Sobrien     _._P_A_T_H           A variable that represents the list of directories that
719236769Sobrien                     bbmmaakkee will search for files.  The search list should be
720236769Sobrien                     updated using the target `_._P_A_T_H' rather than the vari-
721236769Sobrien                     able.
722236769Sobrien
723236769Sobrien     PWD             Alternate path to the current directory.  bbmmaakkee normally
724236769Sobrien                     sets `_._C_U_R_D_I_R' to the canonical path given by getcwd(3).
725236769Sobrien                     However, if the environment variable `PWD' is set and
726236769Sobrien                     gives a path to the current directory, then bbmmaakkee sets
727321964Ssjg                     `_._C_U_R_D_I_R' to the value of `PWD' instead.  This behavior
728236769Sobrien                     is disabled if `MAKEOBJDIRPREFIX' is set or `MAKEOBJDIR'
729236769Sobrien                     contains a variable transform.  `PWD' is set to the value
730236769Sobrien                     of `_._O_B_J_D_I_R' for all programs which bbmmaakkee executes.
731236769Sobrien
732236769Sobrien     .TARGETS        The list of targets explicitly specified on the command
733236769Sobrien                     line, if any.
734236769Sobrien
735236769Sobrien     VPATH           Colon-separated (``:'') lists of directories that bbmmaakkee
736236769Sobrien                     will search for files.  The variable is supported for
737236769Sobrien                     compatibility with old make programs only, use `_._P_A_T_H'
738236769Sobrien                     instead.
739236769Sobrien
740236769Sobrien   VVaarriiaabbllee mmooddiiffiieerrss
741236769Sobrien     Variable expansion may be modified to select or modify each word of the
742236769Sobrien     variable (where a ``word'' is white-space delimited sequence of charac-
743236769Sobrien     ters).  The general format of a variable expansion is as follows:
744236769Sobrien
745236769Sobrien           ${variable[:modifier[:...]]}
746236769Sobrien
747236769Sobrien     Each modifier begins with a colon, which may be escaped with a backslash
748236769Sobrien     (`\').
749236769Sobrien
750236769Sobrien     A set of modifiers can be specified via a variable, as follows:
751236769Sobrien
752236769Sobrien           modifier_variable=modifier[:...]
753236769Sobrien           ${variable:${modifier_variable}[:...]}
754236769Sobrien
755236769Sobrien     In this case the first modifier in the modifier_variable does not start
756236769Sobrien     with a colon, since that must appear in the referencing variable.  If any
757236769Sobrien     of the modifiers in the modifier_variable contain a dollar sign (`$'),
758236769Sobrien     these must be doubled to avoid early expansion.
759236769Sobrien
760236769Sobrien     The supported modifiers are:
761236769Sobrien
762236769Sobrien     ::EE   Replaces each word in the variable with its suffix.
763236769Sobrien
764236769Sobrien     ::HH   Replaces each word in the variable with everything but the last com-
765236769Sobrien          ponent.
766236769Sobrien
767236769Sobrien     ::MM_p_a_t_t_e_r_n
768236769Sobrien          Select only those words that match _p_a_t_t_e_r_n.  The standard shell
769236769Sobrien          wildcard characters (`*', `?', and `[]') may be used.  The wildcard
770276305Sngie          characters may be escaped with a backslash (`\').  As a consequence
771276305Sngie          of the way values are split into words, matched, and then joined, a
772276305Sngie          construct like
773276305Sngie                ${VAR:M*}
774321964Ssjg          will normalize the inter-word spacing, removing all leading and
775276305Sngie          trailing space, and converting multiple consecutive spaces to single
776276305Sngie          spaces.
777236769Sobrien
778236769Sobrien     ::NN_p_a_t_t_e_r_n
779236769Sobrien          This is identical to `::MM', but selects all words which do not match
780236769Sobrien          _p_a_t_t_e_r_n.
781236769Sobrien
782236769Sobrien     ::OO   Order every word in variable alphabetically.  To sort words in
783236769Sobrien          reverse order use the `::OO::[[--11....11]]' combination of modifiers.
784236769Sobrien
785236769Sobrien     ::OOxx  Randomize words in variable.  The results will be different each
786236769Sobrien          time you are referring to the modified variable; use the assignment
787321964Ssjg          with expansion (`::==') to prevent such behavior.  For example,
788236769Sobrien
789236769Sobrien                LIST=                   uno due tre quattro
790236769Sobrien                RANDOM_LIST=            ${LIST:Ox}
791236769Sobrien                STATIC_RANDOM_LIST:=    ${LIST:Ox}
792236769Sobrien
793236769Sobrien                all:
794236769Sobrien                        @echo "${RANDOM_LIST}"
795236769Sobrien                        @echo "${RANDOM_LIST}"
796236769Sobrien                        @echo "${STATIC_RANDOM_LIST}"
797236769Sobrien                        @echo "${STATIC_RANDOM_LIST}"
798236769Sobrien          may produce output similar to:
799236769Sobrien
800236769Sobrien                quattro due tre uno
801236769Sobrien                tre due quattro uno
802236769Sobrien                due uno quattro tre
803236769Sobrien                due uno quattro tre
804236769Sobrien
805236769Sobrien     ::QQ   Quotes every shell meta-character in the variable, so that it can be
806236769Sobrien          passed safely through recursive invocations of bbmmaakkee.
807236769Sobrien
808236769Sobrien     ::RR   Replaces each word in the variable with everything but its suffix.
809236769Sobrien
810321964Ssjg     ::rraannggee[[==ccoouunntt]]
811321964Ssjg          The value is an integer sequence representing the words of the orig-
812321964Ssjg          inal value, or the supplied _c_o_u_n_t.
813236769Sobrien
814321964Ssjg     ::ggmmttiimmee[[==uuttcc]]
815321964Ssjg          The value is a format string for strftime(3), using gmtime(3).  If a
816321964Ssjg          _u_t_c value is not provided or is 0, the current time is used.
817321964Ssjg
818236769Sobrien     ::hhaasshh
819321964Ssjg          Compute a 32-bit hash of the value and encode it as hex digits.
820236769Sobrien
821321964Ssjg     ::llooccaallttiimmee[[==uuttcc]]
822321964Ssjg          The value is a format string for strftime(3), using localtime(3).
823321964Ssjg          If a _u_t_c value is not provided or is 0, the current time is used.
824236769Sobrien
825236769Sobrien     ::ttAA  Attempt to convert variable to an absolute path using realpath(3),
826236769Sobrien          if that fails, the value is unchanged.
827236769Sobrien
828236769Sobrien     ::ttll  Converts variable to lower-case letters.
829236769Sobrien
830236769Sobrien     ::ttss_c
831236769Sobrien          Words in the variable are normally separated by a space on expan-
832236769Sobrien          sion.  This modifier sets the separator to the character _c.  If _c is
833236769Sobrien          omitted, then no separator is used.  The common escapes (including
834236769Sobrien          octal numeric codes), work as expected.
835236769Sobrien
836236769Sobrien     ::ttuu  Converts variable to upper-case letters.
837236769Sobrien
838236769Sobrien     ::ttWW  Causes the value to be treated as a single word (possibly containing
839236769Sobrien          embedded white space).  See also `::[[**]]'.
840236769Sobrien
841236769Sobrien     ::ttww  Causes the value to be treated as a sequence of words delimited by
842236769Sobrien          white space.  See also `::[[@@]]'.
843236769Sobrien
844236769Sobrien     ::SS/_o_l_d___s_t_r_i_n_g/_n_e_w___s_t_r_i_n_g/[11ggWW]
845236769Sobrien          Modify the first occurrence of _o_l_d___s_t_r_i_n_g in the variable's value,
846236769Sobrien          replacing it with _n_e_w___s_t_r_i_n_g.  If a `g' is appended to the last
847236769Sobrien          slash of the pattern, all occurrences in each word are replaced.  If
848236769Sobrien          a `1' is appended to the last slash of the pattern, only the first
849236769Sobrien          word is affected.  If a `W' is appended to the last slash of the
850236769Sobrien          pattern, then the value is treated as a single word (possibly con-
851236769Sobrien          taining embedded white space).  If _o_l_d___s_t_r_i_n_g begins with a caret
852236769Sobrien          (`^'), _o_l_d___s_t_r_i_n_g is anchored at the beginning of each word.  If
853236769Sobrien          _o_l_d___s_t_r_i_n_g ends with a dollar sign (`$'), it is anchored at the end
854236769Sobrien          of each word.  Inside _n_e_w___s_t_r_i_n_g, an ampersand (`&') is replaced by
855236769Sobrien          _o_l_d___s_t_r_i_n_g (without any `^' or `$').  Any character may be used as a
856236769Sobrien          delimiter for the parts of the modifier string.  The anchoring,
857236769Sobrien          ampersand and delimiter characters may be escaped with a backslash
858236769Sobrien          (`\').
859236769Sobrien
860236769Sobrien          Variable expansion occurs in the normal fashion inside both
861236769Sobrien          _o_l_d___s_t_r_i_n_g and _n_e_w___s_t_r_i_n_g with the single exception that a backslash
862236769Sobrien          is used to prevent the expansion of a dollar sign (`$'), not a pre-
863236769Sobrien          ceding dollar sign as is usual.
864236769Sobrien
865236769Sobrien     ::CC/_p_a_t_t_e_r_n/_r_e_p_l_a_c_e_m_e_n_t/[11ggWW]
866236769Sobrien          The ::CC modifier is just like the ::SS modifier except that the old and
867276305Sngie          new strings, instead of being simple strings, are an extended regu-
868276305Sngie          lar expression (see regex(3)) string _p_a_t_t_e_r_n and an ed(1)-style
869276305Sngie          string _r_e_p_l_a_c_e_m_e_n_t.  Normally, the first occurrence of the pattern
870276305Sngie          _p_a_t_t_e_r_n in each word of the value is substituted with _r_e_p_l_a_c_e_m_e_n_t.
871276305Sngie          The `1' modifier causes the substitution to apply to at most one
872276305Sngie          word; the `g' modifier causes the substitution to apply to as many
873276305Sngie          instances of the search pattern _p_a_t_t_e_r_n as occur in the word or
874276305Sngie          words it is found in; the `W' modifier causes the value to be
875276305Sngie          treated as a single word (possibly containing embedded white space).
876276305Sngie          Note that `1' and `g' are orthogonal; the former specifies whether
877276305Sngie          multiple words are potentially affected, the latter whether multiple
878276305Sngie          substitutions can potentially occur within each affected word.
879236769Sobrien
880276305Sngie          As for the ::SS modifier, the _p_a_t_t_e_r_n and _r_e_p_l_a_c_e_m_e_n_t are subjected to
881276305Sngie          variable expansion before being parsed as regular expressions.
882276305Sngie
883236769Sobrien     ::TT   Replaces each word in the variable with its last component.
884236769Sobrien
885236769Sobrien     ::uu   Remove adjacent duplicate words (like uniq(1)).
886236769Sobrien
887236769Sobrien     ::??_t_r_u_e___s_t_r_i_n_g::_f_a_l_s_e___s_t_r_i_n_g
888236769Sobrien          If the variable name (not its value), when parsed as a .if condi-
889236769Sobrien          tional expression, evaluates to true, return as its value the
890236769Sobrien          _t_r_u_e___s_t_r_i_n_g, otherwise return the _f_a_l_s_e___s_t_r_i_n_g.  Since the variable
891236769Sobrien          name is used as the expression, :? must be the first modifier after
892236769Sobrien          the variable name itself - which will, of course, usually contain
893236769Sobrien          variable expansions.  A common error is trying to use expressions
894236769Sobrien          like
895236769Sobrien                ${NUMBERS:M42:?match:no}
896236769Sobrien          which actually tests defined(NUMBERS), to determine is any words
897236769Sobrien          match "42" you need to use something like:
898236769Sobrien                ${"${NUMBERS:M42}" != "":?match:no}.
899236769Sobrien
900236769Sobrien     _:_o_l_d___s_t_r_i_n_g_=_n_e_w___s_t_r_i_n_g
901236769Sobrien          This is the AT&T System V UNIX style variable substitution.  It must
902236769Sobrien          be the last modifier specified.  If _o_l_d___s_t_r_i_n_g or _n_e_w___s_t_r_i_n_g do not
903236769Sobrien          contain the pattern matching character _% then it is assumed that
904236769Sobrien          they are anchored at the end of each word, so only suffixes or
905236769Sobrien          entire words may be replaced.  Otherwise _% is the substring of
906236769Sobrien          _o_l_d___s_t_r_i_n_g to be replaced in _n_e_w___s_t_r_i_n_g.
907236769Sobrien
908236769Sobrien          Variable expansion occurs in the normal fashion inside both
909236769Sobrien          _o_l_d___s_t_r_i_n_g and _n_e_w___s_t_r_i_n_g with the single exception that a backslash
910236769Sobrien          is used to prevent the expansion of a dollar sign (`$'), not a pre-
911236769Sobrien          ceding dollar sign as is usual.
912236769Sobrien
913236769Sobrien     ::@@_t_e_m_p@@_s_t_r_i_n_g@@
914236769Sobrien          This is the loop expansion mechanism from the OSF Development Envi-
915236769Sobrien          ronment (ODE) make.  Unlike ..ffoorr loops expansion occurs at the time
916236769Sobrien          of reference.  Assign _t_e_m_p to each word in the variable and evaluate
917236769Sobrien          _s_t_r_i_n_g.  The ODE convention is that _t_e_m_p should start and end with a
918236769Sobrien          period.  For example.
919236769Sobrien                ${LINKS:@.LINK.@${LN} ${TARGET} ${.LINK.}@}
920236769Sobrien
921253883Ssjg          However a single character variable is often more readable:
922236769Sobrien                ${MAKE_PRINT_VAR_ON_ERROR:@v@$v='${$v}'${.newline}@}
923236769Sobrien
924321964Ssjg     ::__[[==vvaarr]]
925321964Ssjg          Save the current variable value in `$_' or the named _v_a_r for later
926321964Ssjg          reference.  Example usage:
927321964Ssjg
928321964Ssjg                M_cmpv.units = 1 1000 1000000
929321964Ssjg                M_cmpv = S,., ,g:_:range:@i@+ $${_:[-$$i]} \
930321964Ssjg                \* $${M_cmpv.units:[$$i]}@:S,^,expr 0 ,1:sh
931321964Ssjg
932321964Ssjg                .if ${VERSION:${M_cmpv}} < ${3.1.12:L:${M_cmpv}}
933321964Ssjg
934321964Ssjg          Here `$_' is used to save the result of the `:S' modifier which is
935321964Ssjg          later referenced using the index values from `:range'.
936321964Ssjg
937236769Sobrien     ::UU_n_e_w_v_a_l
938236769Sobrien          If the variable is undefined _n_e_w_v_a_l is the value.  If the variable
939236769Sobrien          is defined, the existing value is returned.  This is another ODE
940236769Sobrien          make feature.  It is handy for setting per-target CFLAGS for
941236769Sobrien          instance:
942236769Sobrien                ${_${.TARGET:T}_CFLAGS:U${DEF_CFLAGS}}
943236769Sobrien          If a value is only required if the variable is undefined, use:
944236769Sobrien                ${VAR:D:Unewval}
945236769Sobrien
946236769Sobrien     ::DD_n_e_w_v_a_l
947236769Sobrien          If the variable is defined _n_e_w_v_a_l is the value.
948236769Sobrien
949236769Sobrien     ::LL   The name of the variable is the value.
950236769Sobrien
951236769Sobrien     ::PP   The path of the node which has the same name as the variable is the
952236769Sobrien          value.  If no such node exists or its path is null, then the name of
953236769Sobrien          the variable is used.  In order for this modifier to work, the name
954236769Sobrien          (node) must at least have appeared on the rhs of a dependency.
955236769Sobrien
956236769Sobrien     ::!!_c_m_d!!
957236769Sobrien          The output of running _c_m_d is the value.
958236769Sobrien
959236769Sobrien     ::sshh  If the variable is non-empty it is run as a command and the output
960236769Sobrien          becomes the new value.
961236769Sobrien
962236769Sobrien     ::::==_s_t_r
963236769Sobrien          The variable is assigned the value _s_t_r after substitution.  This
964236769Sobrien          modifier and its variations are useful in obscure situations such as
965236769Sobrien          wanting to set a variable when shell commands are being parsed.
966236769Sobrien          These assignment modifiers always expand to nothing, so if appearing
967236769Sobrien          in a rule line by themselves should be preceded with something to
968236769Sobrien          keep bbmmaakkee happy.
969236769Sobrien
970236769Sobrien          The `::::' helps avoid false matches with the AT&T System V UNIX style
971236769Sobrien          ::== modifier and since substitution always occurs the ::::== form is
972236769Sobrien          vaguely appropriate.
973236769Sobrien
974236769Sobrien     ::::??==_s_t_r
975236769Sobrien          As for ::::== but only if the variable does not already have a value.
976236769Sobrien
977236769Sobrien     ::::++==_s_t_r
978236769Sobrien          Append _s_t_r to the variable.
979236769Sobrien
980236769Sobrien     ::::!!==_c_m_d
981236769Sobrien          Assign the output of _c_m_d to the variable.
982236769Sobrien
983236769Sobrien     ::[[_r_a_n_g_e]]
984236769Sobrien          Selects one or more words from the value, or performs other opera-
985236769Sobrien          tions related to the way in which the value is divided into words.
986236769Sobrien
987236769Sobrien          Ordinarily, a value is treated as a sequence of words delimited by
988321964Ssjg          white space.  Some modifiers suppress this behavior, causing a value
989321964Ssjg          to be treated as a single word (possibly containing embedded white
990321964Ssjg          space).  An empty value, or a value that consists entirely of white-
991321964Ssjg          space, is treated as a single word.  For the purposes of the `::[[]]'
992321964Ssjg          modifier, the words are indexed both forwards using positive inte-
993321964Ssjg          gers (where index 1 represents the first word), and backwards using
994321964Ssjg          negative integers (where index -1 represents the last word).
995236769Sobrien
996236769Sobrien          The _r_a_n_g_e is subjected to variable expansion, and the expanded
997236769Sobrien          result is then interpreted as follows:
998236769Sobrien
999236769Sobrien          _i_n_d_e_x  Selects a single word from the value.
1000236769Sobrien
1001236769Sobrien          _s_t_a_r_t...._e_n_d
1002236769Sobrien                 Selects all words from _s_t_a_r_t to _e_n_d, inclusive.  For example,
1003236769Sobrien                 `::[[22....--11]]' selects all words from the second word to the last
1004236769Sobrien                 word.  If _s_t_a_r_t is greater than _e_n_d, then the words are out-
1005236769Sobrien                 put in reverse order.  For example, `::[[--11....11]]' selects all
1006236769Sobrien                 the words from last to first.
1007236769Sobrien
1008236769Sobrien          **      Causes subsequent modifiers to treat the value as a single
1009236769Sobrien                 word (possibly containing embedded white space).  Analogous
1010236769Sobrien                 to the effect of "$*" in Bourne shell.
1011236769Sobrien
1012236769Sobrien          0      Means the same as `::[[**]]'.
1013236769Sobrien
1014236769Sobrien          @@      Causes subsequent modifiers to treat the value as a sequence
1015236769Sobrien                 of words delimited by white space.  Analogous to the effect
1016236769Sobrien                 of "$@" in Bourne shell.
1017236769Sobrien
1018236769Sobrien          ##      Returns the number of words in the value.
1019236769Sobrien
1020236769SobrienIINNCCLLUUDDEE SSTTAATTEEMMEENNTTSS,, CCOONNDDIITTIIOONNAALLSS AANNDD FFOORR LLOOOOPPSS
1021236769Sobrien     Makefile inclusion, conditional structures and for loops  reminiscent of
1022236769Sobrien     the C programming language are provided in bbmmaakkee.  All such structures
1023236769Sobrien     are identified by a line beginning with a single dot (`.') character.
1024236769Sobrien     Files are included with either ..iinncclluuddee <_f_i_l_e> or ..iinncclluuddee "_f_i_l_e".  Vari-
1025236769Sobrien     ables between the angle brackets or double quotes are expanded to form
1026236769Sobrien     the file name.  If angle brackets are used, the included makefile is
1027236769Sobrien     expected to be in the system makefile directory.  If double quotes are
1028236769Sobrien     used, the including makefile's directory and any directories specified
1029236769Sobrien     using the --II option are searched before the system makefile directory.
1030236769Sobrien     For compatibility with other versions of bbmmaakkee `include file ...' is also
1031321964Ssjg     accepted.
1032236769Sobrien
1033321964Ssjg     If the include statement is written as ..--iinncclluuddee or as ..ssiinncclluuddee then
1034321964Ssjg     errors locating and/or opening include files are ignored.
1035321964Ssjg
1036321964Ssjg     If the include statement is written as ..ddiinncclluuddee not only are errors
1037321964Ssjg     locating and/or opening include files ignored, but stale dependencies
1038321964Ssjg     within the included file will be ignored just like _._M_A_K_E_._D_E_P_E_N_D_F_I_L_E.
1039321964Ssjg
1040236769Sobrien     Conditional expressions are also preceded by a single dot as the first
1041236769Sobrien     character of a line.  The possible conditionals are as follows:
1042236769Sobrien
1043236769Sobrien     ..eerrrroorr _m_e_s_s_a_g_e
1044236769Sobrien             The message is printed along with the name of the makefile and
1045236769Sobrien             line number, then bbmmaakkee will exit.
1046236769Sobrien
1047236769Sobrien     ..eexxppoorrtt _v_a_r_i_a_b_l_e _._._.
1048236769Sobrien             Export the specified global variable.  If no variable list is
1049236769Sobrien             provided, all globals are exported except for internal variables
1050236769Sobrien             (those that start with `.').  This is not affected by the --XX
1051236769Sobrien             flag, so should be used with caution.  For compatibility with
1052236769Sobrien             other bbmmaakkee programs `export variable=value' is also accepted.
1053236769Sobrien
1054236769Sobrien             Appending a variable name to _._M_A_K_E_._E_X_P_O_R_T_E_D is equivalent to
1055236769Sobrien             exporting a variable.
1056236769Sobrien
1057236769Sobrien     ..eexxppoorrtt--eennvv _v_a_r_i_a_b_l_e _._._.
1058236769Sobrien             The same as `.export', except that the variable is not appended
1059236769Sobrien             to _._M_A_K_E_._E_X_P_O_R_T_E_D.  This allows exporting a value to the environ-
1060236769Sobrien             ment which is different from that used by bbmmaakkee internally.
1061236769Sobrien
1062321964Ssjg     ..eexxppoorrtt--lliitteerraall _v_a_r_i_a_b_l_e _._._.
1063321964Ssjg             The same as `.export-env', except that variables in the value are
1064321964Ssjg             not expanded.
1065321964Ssjg
1066236769Sobrien     ..iinnffoo _m_e_s_s_a_g_e
1067236769Sobrien             The message is printed along with the name of the makefile and
1068236769Sobrien             line number.
1069236769Sobrien
1070236769Sobrien     ..uunnddeeff _v_a_r_i_a_b_l_e
1071236769Sobrien             Un-define the specified global variable.  Only global variables
1072236769Sobrien             may be un-defined.
1073236769Sobrien
1074236769Sobrien     ..uunneexxppoorrtt _v_a_r_i_a_b_l_e _._._.
1075236769Sobrien             The opposite of `.export'.  The specified global _v_a_r_i_a_b_l_e will be
1076236769Sobrien             removed from _._M_A_K_E_._E_X_P_O_R_T_E_D.  If no variable list is provided,
1077236769Sobrien             all globals are unexported, and _._M_A_K_E_._E_X_P_O_R_T_E_D deleted.
1078236769Sobrien
1079236769Sobrien     ..uunneexxppoorrtt--eennvv
1080236769Sobrien             Unexport all globals previously exported and clear the environ-
1081236769Sobrien             ment inherited from the parent.  This operation will cause a mem-
1082236769Sobrien             ory leak of the original environment, so should be used spar-
1083236769Sobrien             ingly.  Testing for _._M_A_K_E_._L_E_V_E_L being 0, would make sense.  Also
1084236769Sobrien             note that any variables which originated in the parent environ-
1085236769Sobrien             ment should be explicitly preserved if desired.  For example:
1086236769Sobrien
1087236769Sobrien                   .if ${.MAKE.LEVEL} == 0
1088236769Sobrien                   PATH := ${PATH}
1089236769Sobrien                   .unexport-env
1090236769Sobrien                   .export PATH
1091236769Sobrien                   .endif
1092236769Sobrien
1093236769Sobrien             Would result in an environment containing only `PATH', which is
1094236769Sobrien             the minimal useful environment.  Actually `.MAKE.LEVEL' will also
1095236769Sobrien             be pushed into the new environment.
1096236769Sobrien
1097236769Sobrien     ..wwaarrnniinngg _m_e_s_s_a_g_e
1098236769Sobrien             The message prefixed by `_w_a_r_n_i_n_g_:' is printed along with the name
1099236769Sobrien             of the makefile and line number.
1100236769Sobrien
1101236769Sobrien     ..iiff [!]_e_x_p_r_e_s_s_i_o_n [_o_p_e_r_a_t_o_r _e_x_p_r_e_s_s_i_o_n _._._.]
1102236769Sobrien             Test the value of an expression.
1103236769Sobrien
1104236769Sobrien     ..iiffddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.]
1105236769Sobrien             Test the value of a variable.
1106236769Sobrien
1107236769Sobrien     ..iiffnnddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.]
1108236769Sobrien             Test the value of a variable.
1109236769Sobrien
1110236769Sobrien     ..iiffmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.]
1111236769Sobrien             Test the target being built.
1112236769Sobrien
1113236769Sobrien     ..iiffnnmmaakkee [!] _t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.]
1114236769Sobrien             Test the target being built.
1115236769Sobrien
1116236769Sobrien     ..eellssee   Reverse the sense of the last conditional.
1117236769Sobrien
1118236769Sobrien     ..eelliiff [!] _e_x_p_r_e_s_s_i_o_n [_o_p_e_r_a_t_o_r _e_x_p_r_e_s_s_i_o_n _._._.]
1119236769Sobrien             A combination of `..eellssee' followed by `..iiff'.
1120236769Sobrien
1121236769Sobrien     ..eelliiffddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.]
1122236769Sobrien             A combination of `..eellssee' followed by `..iiffddeeff'.
1123236769Sobrien
1124236769Sobrien     ..eelliiffnnddeeff [!]_v_a_r_i_a_b_l_e [_o_p_e_r_a_t_o_r _v_a_r_i_a_b_l_e _._._.]
1125236769Sobrien             A combination of `..eellssee' followed by `..iiffnnddeeff'.
1126236769Sobrien
1127236769Sobrien     ..eelliiffmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.]
1128236769Sobrien             A combination of `..eellssee' followed by `..iiffmmaakkee'.
1129236769Sobrien
1130236769Sobrien     ..eelliiffnnmmaakkee [!]_t_a_r_g_e_t [_o_p_e_r_a_t_o_r _t_a_r_g_e_t _._._.]
1131236769Sobrien             A combination of `..eellssee' followed by `..iiffnnmmaakkee'.
1132236769Sobrien
1133236769Sobrien     ..eennddiiff  End the body of the conditional.
1134236769Sobrien
1135236769Sobrien     The _o_p_e_r_a_t_o_r may be any one of the following:
1136236769Sobrien
1137236769Sobrien     ||||     Logical OR.
1138236769Sobrien
1139236769Sobrien     &&&&     Logical AND; of higher precedence than ``||''.
1140236769Sobrien
1141236769Sobrien     As in C, bbmmaakkee will only evaluate a conditional as far as is necessary to
1142236769Sobrien     determine its value.  Parentheses may be used to change the order of
1143236769Sobrien     evaluation.  The boolean operator `!!' may be used to logically negate an
1144236769Sobrien     entire conditional.  It is of higher precedence than `&&&&'.
1145236769Sobrien
1146236769Sobrien     The value of _e_x_p_r_e_s_s_i_o_n may be any of the following:
1147236769Sobrien
1148236769Sobrien     ddeeffiinneedd  Takes a variable name as an argument and evaluates to true if
1149236769Sobrien              the variable has been defined.
1150236769Sobrien
1151236769Sobrien     mmaakkee     Takes a target name as an argument and evaluates to true if the
1152236769Sobrien              target was specified as part of bbmmaakkee's command line or was
1153236769Sobrien              declared the default target (either implicitly or explicitly,
1154236769Sobrien              see _._M_A_I_N) before the line containing the conditional.
1155236769Sobrien
1156236769Sobrien     eemmppttyy    Takes a variable, with possible modifiers, and evaluates to true
1157236769Sobrien              if the expansion of the variable would result in an empty
1158236769Sobrien              string.
1159236769Sobrien
1160236769Sobrien     eexxiissttss   Takes a file name as an argument and evaluates to true if the
1161236769Sobrien              file exists.  The file is searched for on the system search path
1162236769Sobrien              (see _._P_A_T_H).
1163236769Sobrien
1164236769Sobrien     ttaarrggeett   Takes a target name as an argument and evaluates to true if the
1165236769Sobrien              target has been defined.
1166236769Sobrien
1167236769Sobrien     ccoommmmaannddss
1168236769Sobrien              Takes a target name as an argument and evaluates to true if the
1169236769Sobrien              target has been defined and has commands associated with it.
1170236769Sobrien
1171236769Sobrien     _E_x_p_r_e_s_s_i_o_n may also be an arithmetic or string comparison.  Variable
1172236769Sobrien     expansion is performed on both sides of the comparison, after which the
1173236769Sobrien     integral values are compared.  A value is interpreted as hexadecimal if
1174236769Sobrien     it is preceded by 0x, otherwise it is decimal; octal numbers are not sup-
1175236769Sobrien     ported.  The standard C relational operators are all supported.  If after
1176236769Sobrien     variable expansion, either the left or right hand side of a `====' or `!!=='
1177236769Sobrien     operator is not an integral value, then string comparison is performed
1178236769Sobrien     between the expanded variables.  If no relational operator is given, it
1179236769Sobrien     is assumed that the expanded variable is being compared against 0 or an
1180236769Sobrien     empty string in the case of a string comparison.
1181236769Sobrien
1182236769Sobrien     When bbmmaakkee is evaluating one of these conditional expressions, and it
1183236769Sobrien     encounters a (white-space separated) word it doesn't recognize, either
1184236769Sobrien     the ``make'' or ``defined'' expression is applied to it, depending on the
1185236769Sobrien     form of the conditional.  If the form is `..iiffddeeff', `..iiffnnddeeff', or `..iiff'
1186236769Sobrien     the ``defined'' expression is applied.  Similarly, if the form is
1187236769Sobrien     `..iiffmmaakkee' or `..iiffnnmmaakkee, tthhee' ``make'' expression is applied.
1188236769Sobrien
1189236769Sobrien     If the conditional evaluates to true the parsing of the makefile contin-
1190236769Sobrien     ues as before.  If it evaluates to false, the following lines are
1191236769Sobrien     skipped.  In both cases this continues until a `..eellssee' or `..eennddiiff' is
1192236769Sobrien     found.
1193236769Sobrien
1194236769Sobrien     For loops are typically used to apply a set of rules to a list of files.
1195236769Sobrien     The syntax of a for loop is:
1196236769Sobrien
1197236769Sobrien     ..ffoorr _v_a_r_i_a_b_l_e [_v_a_r_i_a_b_l_e _._._.] iinn _e_x_p_r_e_s_s_i_o_n
1198236769Sobrien     <make-rules>
1199236769Sobrien     ..eennddffoorr
1200236769Sobrien
1201236769Sobrien     After the for eexxpprreessssiioonn is evaluated, it is split into words.  On each
1202236769Sobrien     iteration of the loop, one word is taken and assigned to each vvaarriiaabbllee,
1203236769Sobrien     in order, and these vvaarriiaabblleess are substituted into the mmaakkee--rruulleess inside
1204236769Sobrien     the body of the for loop.  The number of words must come out even; that
1205236769Sobrien     is, if there are three iteration variables, the number of words provided
1206236769Sobrien     must be a multiple of three.
1207236769Sobrien
1208236769SobrienCCOOMMMMEENNTTSS
1209236769Sobrien     Comments begin with a hash (`#') character, anywhere but in a shell com-
1210236769Sobrien     mand line, and continue to the end of an unescaped new line.
1211236769Sobrien
1212236769SobrienSSPPEECCIIAALL SSOOUURRCCEESS ((AATTTTRRIIBBUUTTEESS))
1213236769Sobrien     ..EEXXEECC     Target is never out of date, but always execute commands any-
1214236769Sobrien               way.
1215236769Sobrien
1216236769Sobrien     ..IIGGNNOORREE   Ignore any errors from the commands associated with this tar-
1217236769Sobrien               get, exactly as if they all were preceded by a dash (`-').
1218236769Sobrien
1219236769Sobrien     ..MMAADDEE     Mark all sources of this target as being up-to-date.
1220236769Sobrien
1221236769Sobrien     ..MMAAKKEE     Execute the commands associated with this target even if the --nn
1222236769Sobrien               or --tt options were specified.  Normally used to mark recursive
1223276305Sngie               bbmmaakkees.
1224236769Sobrien
1225236769Sobrien     ..MMEETTAA     Create a meta file for the target, even if it is flagged as
1226236769Sobrien               ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL.  Usage in conjunction with ..MMAAKKEE is
1227236769Sobrien               the most likely case.  In "meta" mode, the target is out-of-
1228236769Sobrien               date if the meta file is missing.
1229236769Sobrien
1230236769Sobrien     ..NNOOMMEETTAA   Do not create a meta file for the target.  Meta files are also
1231236769Sobrien               not created for ..PPHHOONNYY, ..MMAAKKEE, or ..SSPPEECCIIAALL targets.
1232236769Sobrien
1233236769Sobrien     ..NNOOMMEETTAA__CCMMPP
1234236769Sobrien               Ignore differences in commands when deciding if target is out
1235236769Sobrien               of date.  This is useful if the command contains a value which
1236236769Sobrien               always changes.  If the number of commands change, though, the
1237249033Ssjg               target will still be out of date.  The same effect applies to
1238249033Ssjg               any command line that uses the variable _._O_O_D_A_T_E, which can be
1239249033Ssjg               used for that purpose even when not otherwise needed or
1240249033Ssjg               desired:
1241236769Sobrien
1242249033Ssjg
1243249033Ssjg                     skip-compare-for-some:
1244249033Ssjg                             @echo this will be compared
1245249033Ssjg                             @echo this will not ${.OODATE:M.NOMETA_CMP}
1246249033Ssjg                             @echo this will also be compared
1247249033Ssjg
1248249033Ssjg               The ::MM pattern suppresses any expansion of the unwanted vari-
1249249033Ssjg               able.
1250249033Ssjg
1251236769Sobrien     ..NNOOPPAATTHH   Do not search for the target in the directories specified by
1252236769Sobrien               ..PPAATTHH.
1253236769Sobrien
1254236769Sobrien     ..NNOOTTMMAAIINN  Normally bbmmaakkee selects the first target it encounters as the
1255236769Sobrien               default target to be built if no target was specified.  This
1256236769Sobrien               source prevents this target from being selected.
1257236769Sobrien
1258236769Sobrien     ..OOPPTTIIOONNAALL
1259236769Sobrien               If a target is marked with this attribute and bbmmaakkee can't fig-
1260236769Sobrien               ure out how to create it, it will ignore this fact and assume
1261236769Sobrien               the file isn't needed or already exists.
1262236769Sobrien
1263236769Sobrien     ..PPHHOONNYY    The target does not correspond to an actual file; it is always
1264236769Sobrien               considered to be out of date, and will not be created with the
1265236769Sobrien               --tt option.  Suffix-transformation rules are not applied to
1266236769Sobrien               ..PPHHOONNYY targets.
1267236769Sobrien
1268236769Sobrien     ..PPRREECCIIOOUUSS
1269236769Sobrien               When bbmmaakkee is interrupted, it normally removes any partially
1270236769Sobrien               made targets.  This source prevents the target from being
1271236769Sobrien               removed.
1272236769Sobrien
1273236769Sobrien     ..RREECCUURRSSIIVVEE
1274236769Sobrien               Synonym for ..MMAAKKEE.
1275236769Sobrien
1276236769Sobrien     ..SSIILLEENNTT   Do not echo any of the commands associated with this target,
1277236769Sobrien               exactly as if they all were preceded by an at sign (`@').
1278236769Sobrien
1279236769Sobrien     ..UUSSEE      Turn the target into bbmmaakkee's version of a macro.  When the tar-
1280236769Sobrien               get is used as a source for another target, the other target
1281236769Sobrien               acquires the commands, sources, and attributes (except for
1282236769Sobrien               ..UUSSEE) of the source.  If the target already has commands, the
1283236769Sobrien               ..UUSSEE target's commands are appended to them.
1284236769Sobrien
1285236769Sobrien     ..UUSSEEBBEEFFOORREE
1286236769Sobrien               Exactly like ..UUSSEE, but prepend the ..UUSSEEBBEEFFOORREE target commands
1287236769Sobrien               to the target.
1288236769Sobrien
1289236769Sobrien     ..WWAAIITT     If ..WWAAIITT appears in a dependency line, the sources that precede
1290236769Sobrien               it are made before the sources that succeed it in the line.
1291236769Sobrien               Since the dependents of files are not made until the file
1292236769Sobrien               itself could be made, this also stops the dependents being
1293236769Sobrien               built unless they are needed for another branch of the depen-
1294236769Sobrien               dency tree.  So given:
1295236769Sobrien
1296236769Sobrien               x: a .WAIT b
1297236769Sobrien                       echo x
1298236769Sobrien               a:
1299236769Sobrien                       echo a
1300236769Sobrien               b: b1
1301236769Sobrien                       echo b
1302236769Sobrien               b1:
1303236769Sobrien                       echo b1
1304236769Sobrien
1305236769Sobrien               the output is always `a', `b1', `b', `x'.
1306236769Sobrien               The ordering imposed by ..WWAAIITT is only relevant for parallel
1307236769Sobrien               makes.
1308236769Sobrien
1309236769SobrienSSPPEECCIIAALL TTAARRGGEETTSS
1310236769Sobrien     Special targets may not be included with other targets, i.e. they must be
1311236769Sobrien     the only target specified.
1312236769Sobrien
1313236769Sobrien     ..BBEEGGIINN   Any command lines attached to this target are executed before
1314236769Sobrien              anything else is done.
1315236769Sobrien
1316236769Sobrien     ..DDEEFFAAUULLTT
1317236769Sobrien              This is sort of a ..UUSSEE rule for any target (that was used only
1318236769Sobrien              as a source) that bbmmaakkee can't figure out any other way to cre-
1319236769Sobrien              ate.  Only the shell script is used.  The ..IIMMPPSSRRCC variable of a
1320236769Sobrien              target that inherits ..DDEEFFAAUULLTT's commands is set to the target's
1321236769Sobrien              own name.
1322236769Sobrien
1323321964Ssjg     ..DDEELLEETTEE__OONN__EERRRROORR
1324321964Ssjg              If this target is present in the makefile, it globally causes
1325321964Ssjg              make to delete targets whose commands fail.  (By default, only
1326321964Ssjg              targets whose commands are interrupted during execution are
1327321964Ssjg              deleted.  This is the historical behavior.)  This setting can be
1328321964Ssjg              used to help prevent half-finished or malformed targets from
1329321964Ssjg              being left around and corrupting future rebuilds.
1330321964Ssjg
1331236769Sobrien     ..EENNDD     Any command lines attached to this target are executed after
1332236769Sobrien              everything else is done.
1333236769Sobrien
1334236769Sobrien     ..EERRRROORR   Any command lines attached to this target are executed when
1335236769Sobrien              another target fails.  The ..EERRRROORR__TTAARRGGEETT variable is set to the
1336236769Sobrien              target that failed.  See also MMAAKKEE__PPRRIINNTT__VVAARR__OONN__EERRRROORR.
1337236769Sobrien
1338236769Sobrien     ..IIGGNNOORREE  Mark each of the sources with the ..IIGGNNOORREE attribute.  If no
1339236769Sobrien              sources are specified, this is the equivalent of specifying the
1340236769Sobrien              --ii option.
1341236769Sobrien
1342236769Sobrien     ..IINNTTEERRRRUUPPTT
1343236769Sobrien              If bbmmaakkee is interrupted, the commands for this target will be
1344236769Sobrien              executed.
1345236769Sobrien
1346236769Sobrien     ..MMAAIINN    If no target is specified when bbmmaakkee is invoked, this target
1347236769Sobrien              will be built.
1348236769Sobrien
1349236769Sobrien     ..MMAAKKEEFFLLAAGGSS
1350236769Sobrien              This target provides a way to specify flags for bbmmaakkee when the
1351236769Sobrien              makefile is used.  The flags are as if typed to the shell,
1352236769Sobrien              though the --ff option will have no effect.
1353236769Sobrien
1354236769Sobrien     ..NNOOPPAATTHH  Apply the ..NNOOPPAATTHH attribute to any specified sources.
1355236769Sobrien
1356236769Sobrien     ..NNOOTTPPAARRAALLLLEELL
1357236769Sobrien              Disable parallel mode.
1358236769Sobrien
1359236769Sobrien     ..NNOO__PPAARRAALLLLEELL
1360236769Sobrien              Synonym for ..NNOOTTPPAARRAALLLLEELL, for compatibility with other pmake
1361236769Sobrien              variants.
1362236769Sobrien
1363292068Ssjg     ..OOBBJJDDIIRR  The source is a new value for `_._O_B_J_D_I_R'.  If it exists, bbmmaakkee
1364292068Ssjg              will chdir(2) to it and update the value of `_._O_B_J_D_I_R'.
1365292068Ssjg
1366236769Sobrien     ..OORRDDEERR   The named targets are made in sequence.  This ordering does not
1367236769Sobrien              add targets to the list of targets to be made.  Since the depen-
1368236769Sobrien              dents of a target do not get built until the target itself could
1369236769Sobrien              be built, unless `a' is built by another part of the dependency
1370236769Sobrien              graph, the following is a dependency loop:
1371236769Sobrien
1372236769Sobrien              .ORDER: b a
1373236769Sobrien              b: a
1374236769Sobrien
1375236769Sobrien              The ordering imposed by ..OORRDDEERR is only relevant for parallel
1376236769Sobrien              makes.
1377236769Sobrien
1378236769Sobrien     ..PPAATTHH    The sources are directories which are to be searched for files
1379236769Sobrien              not found in the current directory.  If no sources are speci-
1380236769Sobrien              fied, any previously specified directories are deleted.  If the
1381236769Sobrien              source is the special ..DDOOTTLLAASSTT target, then the current working
1382236769Sobrien              directory is searched last.
1383236769Sobrien
1384255253Ssjg     ..PPAATTHH.._s_u_f_f_i_x
1385255253Ssjg              Like ..PPAATTHH but applies only to files with a particular suffix.
1386255253Ssjg              The suffix must have been previously declared with ..SSUUFFFFIIXXEESS.
1387255253Ssjg
1388236769Sobrien     ..PPHHOONNYY   Apply the ..PPHHOONNYY attribute to any specified sources.
1389236769Sobrien
1390236769Sobrien     ..PPRREECCIIOOUUSS
1391236769Sobrien              Apply the ..PPRREECCIIOOUUSS attribute to any specified sources.  If no
1392236769Sobrien              sources are specified, the ..PPRREECCIIOOUUSS attribute is applied to
1393236769Sobrien              every target in the file.
1394236769Sobrien
1395236769Sobrien     ..SSHHEELLLL   Sets the shell that bbmmaakkee will use to execute commands.  The
1396236769Sobrien              sources are a set of _f_i_e_l_d_=_v_a_l_u_e pairs.
1397236769Sobrien
1398236769Sobrien              _n_a_m_e        This is the minimal specification, used to select
1399321964Ssjg                          one of the built-in shell specs; _s_h, _k_s_h, and _c_s_h.
1400236769Sobrien
1401236769Sobrien              _p_a_t_h        Specifies the path to the shell.
1402236769Sobrien
1403236769Sobrien              _h_a_s_E_r_r_C_t_l   Indicates whether the shell supports exit on error.
1404236769Sobrien
1405236769Sobrien              _c_h_e_c_k       The command to turn on error checking.
1406236769Sobrien
1407236769Sobrien              _i_g_n_o_r_e      The command to disable error checking.
1408236769Sobrien
1409236769Sobrien              _e_c_h_o        The command to turn on echoing of commands executed.
1410236769Sobrien
1411236769Sobrien              _q_u_i_e_t       The command to turn off echoing of commands exe-
1412236769Sobrien                          cuted.
1413236769Sobrien
1414236769Sobrien              _f_i_l_t_e_r      The output to filter after issuing the _q_u_i_e_t com-
1415236769Sobrien                          mand.  It is typically identical to _q_u_i_e_t.
1416236769Sobrien
1417236769Sobrien              _e_r_r_F_l_a_g     The flag to pass the shell to enable error checking.
1418236769Sobrien
1419236769Sobrien              _e_c_h_o_F_l_a_g    The flag to pass the shell to enable command echo-
1420236769Sobrien                          ing.
1421236769Sobrien
1422236769Sobrien              _n_e_w_l_i_n_e     The string literal to pass the shell that results in
1423236769Sobrien                          a single newline character when used outside of any
1424236769Sobrien                          quoting characters.
1425236769Sobrien              Example:
1426236769Sobrien
1427236769Sobrien              .SHELL: name=ksh path=/bin/ksh hasErrCtl=true \
1428236769Sobrien                      check="set -e" ignore="set +e" \
1429236769Sobrien                      echo="set -v" quiet="set +v" filter="set +v" \
1430236769Sobrien                      echoFlag=v errFlag=e newline="'\n'"
1431236769Sobrien
1432236769Sobrien     ..SSIILLEENNTT  Apply the ..SSIILLEENNTT attribute to any specified sources.  If no
1433236769Sobrien              sources are specified, the ..SSIILLEENNTT attribute is applied to every
1434236769Sobrien              command in the file.
1435236769Sobrien
1436249033Ssjg     ..SSTTAALLEE   This target gets run when a dependency file contains stale
1437249033Ssjg              entries, having _._A_L_L_S_R_C set to the name of that dependency file.
1438249033Ssjg
1439236769Sobrien     ..SSUUFFFFIIXXEESS
1440236769Sobrien              Each source specifies a suffix to bbmmaakkee.  If no sources are
1441236769Sobrien              specified, any previously specified suffixes are deleted.  It
1442236769Sobrien              allows the creation of suffix-transformation rules.
1443236769Sobrien
1444236769Sobrien              Example:
1445236769Sobrien
1446236769Sobrien              .SUFFIXES: .o
1447236769Sobrien              .c.o:
1448236769Sobrien                      cc -o ${.TARGET} -c ${.IMPSRC}
1449236769Sobrien
1450236769SobrienEENNVVIIRROONNMMEENNTT
1451236769Sobrien     bbmmaakkee uses the following environment variables, if they exist: MACHINE,
1452236769Sobrien     MACHINE_ARCH, MAKE, MAKEFLAGS, MAKEOBJDIR, MAKEOBJDIRPREFIX, MAKESYSPATH,
1453236769Sobrien     PWD, and TMPDIR.
1454236769Sobrien
1455236769Sobrien     MAKEOBJDIRPREFIX and MAKEOBJDIR may only be set in the environment or on
1456236769Sobrien     the command line to bbmmaakkee and not as makefile variables; see the descrip-
1457236769Sobrien     tion of `_._O_B_J_D_I_R' for more details.
1458236769Sobrien
1459236769SobrienFFIILLEESS
1460236769Sobrien     .depend        list of dependencies
1461236769Sobrien     Makefile       list of dependencies
1462236769Sobrien     makefile       list of dependencies
1463236769Sobrien     sys.mk         system makefile
1464236769Sobrien     /usr/share/mk  system makefile directory
1465236769Sobrien
1466236769SobrienCCOOMMPPAATTIIBBIILLIITTYY
1467292068Ssjg     The basic make syntax is compatible between different versions of make;
1468236769Sobrien     however the special variables, variable modifiers and conditionals are
1469236769Sobrien     not.
1470236769Sobrien
1471292068Ssjg   OOllddeerr vveerrssiioonnss
1472292068Ssjg     An incomplete list of changes in older versions of bbmmaakkee:
1473236769Sobrien
1474236769Sobrien     The way that .for loop variables are substituted changed after NetBSD 5.0
1475236769Sobrien     so that they still appear to be variable expansions.  In particular this
1476236769Sobrien     stops them being treated as syntax, and removes some obscure problems
1477236769Sobrien     using them in .if statements.
1478236769Sobrien
1479292068Ssjg     The way that parallel makes are scheduled changed in NetBSD 4.0 so that
1480292068Ssjg     .ORDER and .WAIT apply recursively to the dependent nodes.  The algo-
1481292068Ssjg     rithms used may change again in the future.
1482292068Ssjg
1483292068Ssjg   OOtthheerr mmaakkee ddiiaalleeccttss
1484292068Ssjg     Other make dialects (GNU make, SVR4 make, POSIX make, etc.) do not sup-
1485292068Ssjg     port most of the features of bbmmaakkee as described in this manual.  Most
1486292068Ssjg     notably:
1487292068Ssjg
1488292068Ssjg           ++oo   The ..WWAAIITT and ..OORRDDEERR declarations and most functionality per-
1489292068Ssjg               taining to parallelization.  (GNU make supports parallelization
1490292068Ssjg               but lacks these features needed to control it effectively.)
1491292068Ssjg
1492292068Ssjg           ++oo   Directives, including for loops and conditionals and most of
1493292068Ssjg               the forms of include files.  (GNU make has its own incompatible
1494292068Ssjg               and less powerful syntax for conditionals.)
1495292068Ssjg
1496292068Ssjg           ++oo   All built-in variables that begin with a dot.
1497292068Ssjg
1498292068Ssjg           ++oo   Most of the special sources and targets that begin with a dot,
1499292068Ssjg               with the notable exception of ..PPHHOONNYY, ..PPRREECCIIOOUUSS, and ..SSUUFFFFIIXXEESS.
1500292068Ssjg
1501292068Ssjg           ++oo   Variable modifiers, except for the
1502292068Ssjg                     :old=new
1503292068Ssjg               string substitution, which does not portably support globbing
1504292068Ssjg               with `%' and historically only works on declared suffixes.
1505292068Ssjg
1506292068Ssjg           ++oo   The $$>> variable even in its short form; most makes support this
1507292068Ssjg               functionality but its name varies.
1508292068Ssjg
1509292068Ssjg     Some features are somewhat more portable, such as assignment with ++==, ??==,
1510292068Ssjg     and !!==.  The ..PPAATTHH functionality is based on an older feature VVPPAATTHH found
1511292068Ssjg     in GNU make and many versions of SVR4 make; however, historically its
1512292068Ssjg     behavior is too ill-defined (and too buggy) to rely upon.
1513292068Ssjg
1514292068Ssjg     The $$@@ and $$<< variables are more or less universally portable, as is the
1515292068Ssjg     $$((MMAAKKEE)) variable.  Basic use of suffix rules (for files only in the cur-
1516292068Ssjg     rent directory, not trying to chain transformations together, etc.) is
1517292068Ssjg     also reasonably portable.
1518292068Ssjg
1519236769SobrienSSEEEE AALLSSOO
1520236769Sobrien     mkdep(1)
1521236769Sobrien
1522236769SobrienHHIISSTTOORRYY
1523236769Sobrien     bbmmaakkee is derived from NetBSD make(1).  It uses autoconf to facilitate
1524236769Sobrien     portability to other platforms.
1525236769Sobrien
1526242102Ssjg     A make command appeared in Version 7 AT&T UNIX.  This make implementation
1527242102Ssjg     is based on Adam De Boor's pmake program which was written for Sprite at
1528242102Ssjg     Berkeley.  It was designed to be a parallel distributed make running jobs
1529242102Ssjg     on different machines using a daemon called ``customs''.
1530240330Smarcel
1531253883Ssjg     Historically the target/dependency ``FRC'' has been used to FoRCe
1532253883Ssjg     rebuilding (since the target/dependency does not exist... unless someone
1533253883Ssjg     creates an ``FRC'' file).
1534253883Ssjg
1535242102SsjgBBUUGGSS
1536242102Ssjg     The make syntax is difficult to parse without actually acting of the
1537242102Ssjg     data.  For instance finding the end of a variable use should involve
1538242102Ssjg     scanning each the modifiers using the correct terminator for each field.
1539242102Ssjg     In many places make just counts {} and () in order to find the end of a
1540242102Ssjg     variable expansion.
1541240330Smarcel
1542242102Ssjg     There is no way of escaping a space character in a filename.
1543240330Smarcel
1544321964SsjgNetBSD 7.1_RC1                   June 22, 2017                  NetBSD 7.1_RC1
1545