]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/doc/bjam.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / build / doc / bjam.qbk
1 [article Boost.Jam
2 [quickbook 1.3]
3 [version: 3.1.19]
4 [authors [Rivera, Rene], [Abrahams, David], [Prus, Vladimir]]
5 [copyright 2003 2004 2005 2006 2007 Rene Rivera, David Abrahams, Vladimir Prus]
6 [category tool-build]
7 [id jam]
8 [dirname jam]
9 [purpose
10 Jam is a make(1) replacement that makes building simple things simple
11 and building complicated things manageable.
12 ]
13 [license
14 Distributed under the Boost Software License, Version 1.0.
15 (See accompanying file LICENSE_1_0.txt or copy at
16 [@http://www.boost.org/LICENSE_1_0.txt])
17 ]
18 ]
19
20 [/ QuickBook Document version 1.3 ]
21
22 [/ Shortcuts ]
23
24 [def :version: 3.1.19]
25
26 [/ Images ]
27
28 [def :NOTE: [$images/note.png]]
29 [def :ALERT: [$images/caution.png]]
30 [def :DETAIL: [$images/note.png]]
31 [def :TIP: [$images/tip.png]]
32
33 [/ Links ]
34
35 [def :Boost: [@http://www.boost.org Boost]]
36 [def :Perforce_Jam: [@http://www.perforce.com/jam/jam.html Perforce Jam]]
37
38 [/ Templates ]
39
40 [template literal[text]'''<literallayout><literal>'''[text]'''</literal></literallayout>''']
41 [template list[items]'''<itemizedlist>'''[items]'''</itemizedlist>''']
42 [template orderedlist[items]'''<orderedlist>'''[items]'''</orderedlist>''']
43 [template li[text]'''<listitem>'''[text]'''</listitem>''']
44 [template lines[items]'''<simplelist type='vert' columns='1'>'''[items]'''</simplelist>''']
45 [template line[text]'''<member>'''[text]'''</member>''']
46
47 [section:building Building B2]
48
49 Installing =B2= after building it is simply a matter of copying the
50 generated executables someplace in your =PATH=. For building the executables
51 there are a set of =build= bootstrap scripts to accomodate particular
52 environments. The scripts take one optional argument, the name of the toolset
53 to build with. When the toolset is not given an attempt is made to detect an
54 available toolset and use that. The build scripts accept these arguments:
55
56 [pre
57 /build/ \[/toolset/\]
58 ]
59
60 Running the scripts without arguments will give you the best chance of success. On Windows platforms from a command console do:
61
62 [pre
63 cd /jam source location/
64 .\\build.bat
65 ]
66
67 On Unix type platforms do:
68
69 [pre
70 cd /jam source location/
71 sh ./build.sh
72 ]
73
74 For the Boost.Jam source included with the Boost distribution the /jam source location/ is =BOOST_ROOT/tools/build/src/engine=.
75
76 If the scripts fail to detect an appropriate toolset to build with your particular toolset may not be auto-detectable. In that case, you can specify the toolset as the first argument, this assumes that the toolset is readily available in the =PATH=.
77
78 [note
79 The toolset used to build Boost.Jam is independent of the toolsets used for Boost.Build. Only one version of Boost.Jam is needed to use Boost.Build.
80 ]
81
82 The supported toolsets, and whether they are auto-detected, are:
83
84 [table Supported Toolsets
85
86 [[Script] [Platform] [Toolset] [Detection and Notes]]
87
88 [ [=build.bat=] [Windows NT, 2000, and XP]
89 [[lines
90 [line [@http://www.codegear.com/downloads/free/cppbuilder =borland=]]
91 [line [@http://www.borland.com/ Borland] C++Builder (BCC 5.5)]
92 ]]
93 [[list
94 [li Common install location: "=C:\Borland\BCC55="]
95 [li =BCC32.EXE= in =PATH=]
96 ]]
97 ]
98
99 [ [] []
100 [[lines
101 [line [@http://www.comeaucomputing.com/ =como=]]
102 [line Comeau Computing C/C++]
103 ]]
104 []
105 ]
106
107 [ [] []
108 [[lines
109 [line [@http://gcc.gnu.org/ =gcc=]]
110 [line GNU GCC]
111 ]]
112 []
113 ]
114
115 [ [] []
116 [[lines
117 [line [@http://gcc.gnu.org/ =gcc-nocygwin=]]
118 [line GNU GCC]
119 ]]
120 []
121 ]
122
123 [ [] []
124 [[lines
125 [line [@http://www.intel.com/software/products/compilers/c60 =intel-win32=]]
126 [line Intel C++ Compiler for Windows]
127 ]]
128 [[list
129 [li =ICL.EXE= in =PATH=]
130 ]]
131 ]
132
133 [ [] []
134 [[lines
135 [line [@http://www.metrowerks.com/ =metrowerks=]]
136 [line MetroWerks CodeWarrior C/C++ 7.x, 8.x, 9.x]
137 ]]
138 [[list
139 [li =CWFolder= variable configured]
140 [li =MWCC.EXE= in =PATH=]
141 ]]
142 ]
143
144 [ [] []
145 [[lines
146 [line [@http://www.mingw.org/ =mingw=]]
147 [line GNU [@http://gcc.gnu.org/ GCC] as the [@http://www.mingw.org/ MinGW] configuration]
148 ]]
149 [[list
150 [li Common install location: "=C:\MinGW="]
151 ]]
152 ]
153
154 [ [] []
155 [[lines
156 [line [@http://msdn.microsoft.com/visualc/ =msvc=]]
157 [line Microsoft Visual C++ 6.x]
158 ]]
159 [[list
160 [li =VCVARS32.BAT= already configured]
161 [li =%MSVCDir%= is present in environment]
162 [li Common install locations: "=%ProgramFiles%\Microsoft Visual Studio=", "=%ProgramFiles%\Microsoft Visual C++="]
163 [li =CL.EXE= in =PATH=]
164 ]]
165 ]
166
167 [ [] []
168 [[lines
169 [line [@http://msdn.microsoft.com/visualc/ =vc7=]]
170 [line Microsoft Visual C++ 7.x]
171 ]]
172 [[list
173 [li =VCVARS32.BAT= or =VSVARS32.BAT= already configured]
174 [li =%VS71COMNTOOLS%= is present in environment]
175 [li =%VCINSTALLDIR%= is present in environment]
176 [li Common install locations: "=%ProgramFiles%\Microsoft Visual Studio .NET=", "=%ProgramFiles%\Microsoft Visual Studio .NET 2003="]
177 [li =CL.EXE= in =PATH=]
178 ]]
179 ]
180
181 [ [] []
182 [[lines
183 [line [@http://msdn.microsoft.com/visualc/ =vc8= and =vc9=]]
184 [line Microsoft Visual C++ 8.x and 9.x]
185 ]]
186 [Detection:
187 [list
188 [li =VCVARSALL.BAT= already configured]
189 [li =%VS90COMNTOOLS%= is present in environment]
190 [li Common install location: "=%ProgramFiles%\Microsoft Visual Studio 9="]
191 [li =%VS80COMNTOOLS%= is present in environment]
192 [li Common install location: "=%ProgramFiles%\Microsoft Visual Studio 8="]
193 [li =CL.EXE= in =PATH=]
194 ]
195
196 Notes:
197 [list
198 [li If =VCVARSALL.BAT= is called to set up the toolset, it is passed all the extra arguments, see below for what those arguments are. This can be used to build, for example, a Win64 specific version of =b2=. Consult the VisualStudio documentation for what the possible argument values to the =VCVARSALL.BAT= are.]
199 ]
200 ]
201 ]
202
203 [ [=build.sh=] [Unix, Linux, Cygwin, etc.]
204 [[lines
205 [line [@http://www.hp.com/go/c++ =acc=]]
206 [line HP-UX aCC]
207 ]]
208 [[list
209 [li =aCC= in =PATH=]
210 [li =uname= is "HP-UX"]
211 ]]
212 ]
213
214 [ [] []
215 [[lines
216 [line [@http://www.comeaucomputing.com/ =como=]]
217 [line Comeau Computing C/C++]
218 ]]
219 [[list
220 [li como in =PATH=]
221 ]]
222 ]
223
224 [ [] []
225 [[lines
226 [line [@http://gcc.gnu.org/ =gcc=]]
227 [line GNU GCC]
228 ]]
229 [[list
230 [li gcc in =PATH=]
231 ]]
232 ]
233
234 [ [] []
235 [[lines
236 [line [@http://www.intel.com/software/products/compilers/c60l/ =intel-linux=]]
237 [line Intel C++ for Linux]
238 ]]
239 [[list
240 [li =icc= in =PATH=]
241 [li Common install locations: "=/opt/intel/cc/9.0=", "=/opt/intel_cc_80=", "=/opt/intel/compiler70=", "=/opt/intel/compiler60=", "=/opt/intel/compiler50="]
242 ]]
243 ]
244
245 [ [] []
246 [[lines
247 [line =kcc=]
248 [line Intel KAI C++]
249 ]]
250 [[list
251 [li =KCC= in =PATH=]
252 ]]
253 ]
254
255 [ [] []
256 [[lines
257 [line [@http://www.codegear.com/downloads/free/cppbuilder =kylix=]]
258 [line [@http://www.borland.com/ Borland] C++Builder]
259 ]]
260 [[list
261 [li bc++ in PATH]
262 ]]
263 ]
264
265 [ [] []
266 [[lines
267 [line [@http://www.sgi.com/developers/devtools/languages/mipspro.html =mipspro=]]
268 [line SGI MIPSpro C]
269 ]]
270 [[list
271 [li =uname= is "=IRIX=" or "=IRIX64="]
272 ]]
273 ]
274
275 [ [] []
276 [[lines
277 [line =sunpro=]
278 [line Sun Workshop 6 C++]
279 ]]
280 [[list
281 [li Standard install location: "=/opt/SUNWspro="]
282 ]]
283 ]
284
285 [ [] []
286 [[lines
287 [line =qcc=]
288 [line [@http://www.qnx.com/ QNX Neutrino]]
289 ]]
290 [[list
291 [li =uname= is "=QNX=" and =qcc= in =PATH=]
292 ]]
293 ]
294
295 [ [] []
296 [[lines
297 [line [@http://www.tru64unix.compaq.com/cplus/ =true64cxx=]]
298 [line Compaq C++ Compiler for True64 UNIX]
299 ]]
300 [[list
301 [li =uname= is "=OSF1="]
302 ]]
303 ]
304
305 [ [] []
306 [[lines
307 [line [@http://www.ibm.com/software/awdtools/vacpp/ =vacpp=]]
308 [line IBM VisualAge C++]
309 ]]
310 [[list
311 [li =xlc= in =PATH=]
312 ]]
313 ]
314
315 [ [] [MacOS X]
316 [[lines
317 [line [@http://developer.apple.com/tools/compilers.html =darwin=]]
318 [line Apple MacOS X GCC]
319 ]]
320 [[list
321 [li =uname= is "=Darwin="]
322 ]]
323 ]
324
325 [ [] [Windows NT, 2000, and XP]
326 [[lines
327 [line [@http://www.mingw.org/ =mingw=]]
328 [line GNU [@http://gcc.gnu.org/ GCC] as the [@http://www.mingw.org/ MinGW] configuration with the MSYS shell]
329 ]]
330 [[list
331 [li Common install location: "=/mingw="]
332 ]]
333 ]
334
335 ]
336
337 The built executables are placed in a subdirectory specific to your platform. For example, in Linux running on an Intel x86 compatible chip, the executables are placed in: "=bin.linuxx86=". The =b2[.exe]= executable can be used to invoke Boost.Build.
338
339 The build scripts support additional invocation arguments for use by developers of Boost.Jam and for additional setup of the toolset. The extra arguments come after the toolset:
340
341 * Arguments not in the form of an option, before option arguments, are used for extra setup to toolset configuration scripts.
342 * Arguments of the form "=--option=", which are passed to the =build.jam= build script.
343 * Arguments not in the form of an option, after the options, which are targets for the =build.jam= script.
344
345 [pre
346 /build/ \[/toolset/\] \[/setup/\*\] \[--/option/+ /target/\*\]
347 ]
348
349 The arguments immediately after the toolset are passed directly to the setup script of the toolset, if available and if it needs to be invoked. This allows one to configure the toolset ass needed to do non-default builds of =b2=. For example to build a Win64 version with =vc8=. See the toolset descriptiona above for when particular toolsets support this.
350
351 The arguments starting with the "=--option=" forms are passed to the =build.jam= script and are used to further customize what gets built. Options and targets supported by the =build.jam= script:
352
353 [variablelist
354 [[[literal ---]]
355 [Empty option when one wants to only specify a target.]]
356 [[[literal --release]]
357 [The default, builds the optimized executable.]]
358 [[[literal --debug]]
359 [Builds debugging versions of the executable. When built they are placed in their own directory "=bin./platform/.debug=".]]
360 [[[literal --grammar]]
361 [Normally the Jam language grammar parsing files are not regenerated. This forces building of the grammar, although it may not force the regeneration of the grammar parser. If the parser is out of date it will be regenerated and subsequently built.]]
362 [[[literal --with-python=/path/]]
363 [Enables Python integration, given a path to the Python libraries.]]
364 [[[literal --gc]]
365 [Enables use of the Boehm Garbage Collector. The build will look for the Boehm-GC source in a "boehm_gc" subdirectory from the =b2= sources.]]
366 [[[literal --duma]]
367 [Enables use of the DUMA (Detect Unintended Memory Access) debugging memory allocator. The build expects to find the DUMA source files in a "duma" subdirectory from the =b2= sources.]]
368 [[[literal --toolset-root=/path/]]
369 [Indicates where the toolset used to build is located. This option is passed in by the bootstrap (=build.bat= or =build.sh=) script.]]
370 [[[literal --show-locate-target]]
371 [For information, prints out where it will put the built executable.]]
372 [[[literal --noassert]]
373 [Disable debug assertions, even if building the debug version of the executable.]]
374 [[[literal dist]]
375 [Generate packages (compressed archives) as appropriate for distribution in the platform, if possible.]]
376 [[[literal clean]]
377 [Remove all the built executables and objects.]]
378 ]
379
380 [endsect]
381
382 [section:language Language]
383
384 =B2= has an interpreted, procedural language. Statements in =b2= are rule (procedure) definitions, rule invocations, flow-of-control structures, variable assignments, and sundry language support.
385
386 [section:lexical Lexical Features]
387
388 =B2= treats its input files as whitespace-separated tokens, with two exceptions: double quotes (") can enclose whitespace to embed it into a token, and everything between the matching curly braces ({}) in the definition of a rule action is treated as a single string. A backslash (\\) can escape a double quote, or any single whitespace character.
389
390 =B2= requires whitespace (blanks, tabs, or newlines) to surround all tokens, including the colon (:) and semicolon (;) tokens.
391
392 =B2= keywords (an mentioned in this document) are reserved and generally
393 must be quoted with double quotes (") to be used as arbitrary tokens, such as
394 variable or target names.
395
396 Comments start with the [^#] character and extend until the end of line.
397
398 [endsect]
399
400 [section:target Targets]
401
402 The essential =b2= data entity is a target. Build targets are files to be updated. Source targets are the files used in updating built targets. Built targets and source targets are collectively referred to as file targets, and frequently built targets are source targets for other built targets. Pseudotargets are symbols representing dependencies on other targets, but which are not themselves associated with any real file.
403
404 A file target's identifier is generally the file's name, which can be absolutely rooted, relative to the directory of =b2='s invocation, or simply local (no directory). Most often it is the last case, and the actual file path is bound using the =$(SEARCH)= and =$(LOCATE)= special variables. See [link jam.language.variables.builtins.search SEARCH and LOCATE Variables] below. A local filename is optionally qualified with grist, a string value used to assure uniqueness. A file target with an identifier of the form /file(member)/ is a library member (usually an =ar=(1) archive on Unix).
405
406 [section Binding Detection]
407
408 Whenever a target is bound to a location in the filesystem, Boost Jam will look for a variable called =BINDRULE= (first "on" the target being bound, then in the global module). If non-empty, =$(BINDRULE[1])= names a rule which is called with the name of the target and the path it is being bound to. The signature of the rule named by =$(BINDRULE[1])= should match the following:
409
410 [pre
411 rule /bind-rule/ ( /target/ : /path/ )
412 ]
413
414 This facility is useful for correct header file scanning, since many compilers will search for `#include` files first in the directory containing the file doing the `#include` directive. =$(BINDRULE)= can be used to make a record of that directory.
415
416 [endsect]
417
418 [endsect]
419
420 [section:rules Rules]
421
422 The basic =b2= language entity is called a rule. A rule is defined in two parts: the procedure and the actions. The procedure is a body of jam statements to be run when the rule is invoked; the actions are the OS shell commands to execute when updating the built targets of the rule.
423
424 Rules can return values, which can be expanded into a list with "[ /rule/ /args/ ... ]". A rule's value is the value of its last statement, though only the following statements have values: 'if' (value of the leg chosen), 'switch' (value of the case chosen), set (value of the resulting variable), and 'return' (value of its arguments).
425
426 The =b2= statements for defining and invoking rules are as follows:
427
428 Define a rule's procedure, replacing any previous definition.
429
430 [pre
431 rule /rulename/ { /statements/ }
432 ]
433
434 Define a rule's updating actions, replacing any previous definition.
435
436 [pre
437 actions \[ /modifiers/ \] /rulename/ { /commands/ }
438 ]
439
440 Invoke a rule.
441
442 [pre
443 /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ ;
444 ]
445
446 Invoke a rule under the influence of target's specific variables..
447
448 [pre
449 on /target/ /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ ;
450 ]
451
452 Used as an argument, expands to the return value of the rule invoked.
453
454 [pre
455 \[ /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ \]
456 \[ on /target/ /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ \]
457 ]
458
459 A rule is invoked with values in /field1/ through /fieldN/. They may be referenced in the procedure's statements as [^$(1)] through [^$(['N])] (9 max), and the first two only may be referenced in the action's /commands/ as [^$(1)] and [^$(2)]. [^$(<)] and [^$(>)] are synonymous with [^$(1)] and [^$(2)].
460
461 Rules fall into two categories: updating rules (with actions), and pure procedure rules (without actions). Updating rules treat arguments [^$(1)] and [^$(2)] as built targets and sources, respectively, while pure procedure rules can take arbitrary arguments.
462
463 When an updating rule is invoked, its updating actions are added to those associated with its built targets ([^$(1)]) before the rule's procedure is run. Later, to build the targets in the updating phase, /commands/ are passed to the OS command shell, with [^$(1)] and [^$(2)] replaced by bound versions of the target names. See Binding above.
464
465 Rule invocation may be indirected through a variable:
466
467 [pre
468 $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ ;
469
470 on /target/ $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ ;
471
472 \[ $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ \]
473 \[ on /target/ $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ \]
474 ]
475
476 The variable's value names the rule (or rules) to be invoked. A rule is
477 invoked for each element in the list of [^$(/var/)]'s values. The fields
478 [^/field1/ : /field2/ : /.../] are passed as arguments for each
479 invokation. For the [ ... ] forms, the return value is the concatenation of
480 the return values for all of the invocations.
481
482 [section Action Modifiers]
483
484 The following action modifiers are understood:
485
486 [variablelist
487
488 [[[^actions bind /vars/]]
489 [[^$(/vars/)] will be replaced with bound values.]]
490
491 [[[^actions existing]]
492 [[^$(>)] includes only source targets currently existing.]]
493
494 [[[^actions ignore]]
495 [The return status of the commands is ignored.]]
496
497 [[[^actions piecemeal]]
498 [commands are repeatedly invoked with a subset of [^$(>)] small enough to fit in the command buffer on this OS.]]
499
500 [[[^actions quietly]]
501 [The action is not echoed to the standard output.]]
502
503 [[[^actions together]]
504 [The [^$(>)] from multiple invocations of the same action on the same built target are glommed together.]]
505
506 [[[^actions updated]]
507 [[^$(>)] includes only source targets themselves marked for updating.]]
508
509 ]
510
511 [endsect]
512
513 [section Argument lists]
514
515 You can describe the arguments accepted by a rule, and refer to them by name within the rule. For example, the following prints "I'm sorry, Dave" to the console:
516
517 [pre
518 rule report ( pronoun index ? : state : names + )
519 {
520 local he.suffix she.suffix it.suffix = s ;
521 local I.suffix = m ;
522 local they.suffix you.suffix = re ;
523 ECHO $(pronoun)'$($(pronoun).suffix) $(state), $(names\[$(index)\]) ;
524 }
525 report I 2 : sorry : Joe Dave Pete ;
526 ]
527
528 Each name in a list of formal arguments (separated by "=:=" in the rule declaration) is bound to a single element of the corresponding actual argument unless followed by one of these modifiers:
529
530 [table
531 [[Symbol] [Semantics of preceding symbol]]
532 [[=?=] [optional]]
533 [[=*=] [Bind to zero or more unbound elements of the actual argument. When =*= appears where an argument name is expected, any number of additional arguments are accepted. This feature can be used to implement "varargs" rules.]]
534 [[=+=] [Bind to one or more unbound elements of the actual argument.]]
535 ]
536
537 The actual and formal arguments are checked for inconsistencies, which cause =b2= to exit with an error code:
538
539 [pre
540 ### argument error
541 # rule report ( pronoun index ? : state : names + )
542 # called with: ( I 2 foo : sorry : Joe Dave Pete )
543 # extra argument foo
544 ### argument error
545 # rule report ( pronoun index ? : state : names + )
546 # called with: ( I 2 : sorry )
547 # missing argument names
548 ]
549
550 If you omit the list of formal arguments, all checking is bypassed as in "classic" Jam. Argument lists drastically improve the reliability and readability of your rules, however, and are *strongly recommended* for any new Jam code you write.
551
552 [endsect]
553
554 [section:builtins Built-in Rules]
555
556 =B2= has a growing set of built-in rules, all of which are pure procedure rules without updating actions. They are in three groups: the first builds the dependency graph; the second modifies it; and the third are just utility rules.
557
558 [section Dependency Building]
559
560 [section =DEPENDS= ]
561
562 [pre
563 rule DEPENDS ( /targets1/ * : /targets2/ * )
564 ]
565
566 Builds a direct dependency: makes each of /targets1/ depend on each of /targets2/. Generally, /targets1/ will be rebuilt if /targets2/ are themselves rebuilt or are newer than /targets1/.
567
568 [endsect]
569
570 [section =INCLUDES= ]
571
572 [pre
573 rule INCLUDES ( /targets1/ * : /targets2/ * )
574 ]
575
576 Builds a sibling dependency: makes any target that depends on any of /targets1/ also depend on each of /targets2/. This reflects the dependencies that arise when one source file includes another: the object built from the source file depends both on the original and included source file, but the two sources files don't depend on each other. For example:
577
578 [pre
579 DEPENDS foo.o : foo.c ;
580 INCLUDES foo.c : foo.h ;
581 ]
582
583 "=foo.o=" depends on "=foo.c=" and "=foo.h=" in this example.
584
585 [endsect]
586
587 [endsect]
588
589 [section Modifying Binding]
590
591 The six rules =ALWAYS=, =LEAVES=, =NOCARE=, =NOTFILE=, =NOUPDATE=, and =TEMPORARY= modify the dependency graph so that =b2= treats the targets differently during its target binding phase. See Binding above. Normally, =b2= updates a target if it is missing, if its filesystem modification time is older than any of its dependencies (recursively), or if any of its dependencies are being updated. This basic behavior can be changed by invoking the following rules:
592
593 [section =ALWAYS= ]
594
595 [pre
596 rule ALWAYS ( /targets/ * )
597 ]
598
599 Causes /targets/ to be rebuilt regardless of whether they are up-to-date (they must still be in the dependency graph). This is used for the clean and uninstall targets, as they have no dependencies and would otherwise appear never to need building. It is best applied to targets that are also =NOTFILE= targets, but it can also be used to force a real file to be updated as well.
600
601 [endsect]
602
603 [section =LEAVES= ]
604
605 [pre
606 rule LEAVES ( /targets/ * )
607 ]
608
609 Makes each of /targets/ depend only on its leaf sources, and not on any intermediate targets. This makes it immune to its dependencies being updated, as the "leaf" dependencies are those without their own dependencies and without updating actions. This allows a target to be updated only if original source files change.
610
611 [endsect]
612
613 [section =NOCARE= ]
614
615 [pre
616 rule NOCARE ( /targets/ * )
617 ]
618
619 Causes =b2= to ignore /targets/ that neither can be found nor have updating actions to build them. Normally for such targets =b2= issues a warning and then skips other targets that depend on these missing targets. The =HdrRule= in =Jambase= uses =NOCARE= on the header file names found during header file scanning, to let =b2= know that the included files may not exist. For example, if an `#include` is within an `#ifdef`, the included file may not actually be around.
620
621 [warning For targets with build actions: if their build actions exit with a nonzero return code, dependent targets will still be built.]
622
623 [endsect]
624
625 [section =NOTFILE= ]
626
627 [pre
628 rule NOTFILE ( /targets/ * )
629 ]
630
631 Marks /targets/ as pseudotargets and not real files. No timestamp is checked, and so the actions on such a target are only executed if the target's dependencies are updated, or if the target is also marked with =ALWAYS=. The default =b2= target "=all=" is a pseudotarget. In =Jambase=, =NOTFILE= is used to define several addition convenient pseudotargets.
632
633 [endsect]
634
635 [section =NOUPDATE= ]
636
637 [pre
638 rule NOUPDATE ( /targets/ * )
639 ]
640
641 Causes the timestamps on /targets/ to be ignored. This has two effects: first, once the target has been created it will never be updated; second, manually updating target will not cause other targets to be updated. In =Jambase=, for example, this rule is applied to directories by the =MkDir= rule, because =MkDir= only cares that the target directory exists, not when it has last been updated.
642
643 [endsect]
644
645 [section =TEMPORARY= ]
646
647 [pre
648 rule TEMPORARY ( /targets/ * )
649 ]
650
651 Marks /targets/ as temporary, allowing them to be removed after other targets that depend upon them have been updated. If a =TEMPORARY= target is missing, =b2= uses the timestamp of the target's parent. =Jambase= uses =TEMPORARY= to mark object files that are archived in a library after they are built, so that they can be deleted after they are archived.
652
653 [endsect]
654
655 [section =FAIL_EXPECTED= ]
656
657 [pre
658 rule FAIL_EXPECTED ( /targets/ * )
659 ]
660
661 For handling targets whose build actions are expected to fail (e.g. when testing
662 that assertions or compile-time type checking work properly), Boost Jam supplies
663 the =FAIL_EXPECTED= rule in the same style as =NOCARE=, et. al. During target
664 updating, the return code of the build actions for arguments to =FAIL_EXPECTED=
665 is inverted: if it fails, building of dependent targets continues as though it
666 succeeded. If it succeeds, dependent targets are skipped.
667
668 [endsect]
669
670 [section =RMOLD= ]
671
672 [pre
673 rule RMOLD ( /targets/ * )
674 ]
675
676 =B2= removes any target files that may exist on disk when the rule used to build those targets fails. However, targets whose dependencies fail to build are not removed by default. The =RMOLD= rule causes its arguments to be removed if any of their dependencies fail to build.
677
678 [endsect]
679
680 [section =ISFILE= ]
681
682 [pre
683 rule ISFILE ( /targets/ * )
684 ]
685
686 =ISFILE= marks targets as required to be files. This changes the way =b2= searches for the target such that it ignores matches for file system items that are not files, like directories. This makes it possible to avoid `#include "exception"` matching if one happens to have a directory named exception in the header search path.
687
688 [warning This is currently not fully implemented.]
689
690 [endsect]
691
692 [endsect]
693
694 [section Utility]
695
696 The two rules =ECHO= and =EXIT= are utility rules, used only in =b2='s parsing phase.
697
698 [section =ECHO= ]
699
700 [pre
701 rule ECHO ( /args/ * )
702 ]
703
704 Blurts out the message /args/ to stdout.
705
706 [endsect]
707
708 [section =EXIT= ]
709
710 [pre
711 rule EXIT ( /message/ * : /result-value/ ? )
712 ]
713
714 Blurts out the /message/ to stdout and then exits with a failure status if no /result-value/ is given, otherwise it exits with the given /result-value/.
715
716 "=Echo=", "=echo=", "=Exit=", and "=exit=" are accepted as aliases for =ECHO= and =EXIT=, since it is hard to tell that these are built-in rules and not part of the language, like "=include=".
717
718 [endsect]
719
720 [section =GLOB= ]
721
722 The =GLOB= rule does filename globbing.
723
724 [pre
725 rule GLOB ( /directories/ * : /patterns/ * : /downcase-opt/ ? )
726 ]
727
728 Using the same wildcards as for the patterns in the switch statement. It is invoked by being used as an argument to a rule invocation inside of "=[ ]=". For example: "[^FILES = \[ GLOB dir1 dir2 : *.c *.h \]]" sets =FILES= to the list of C source and header files in =dir1= and =dir2=. The resulting filenames are the full pathnames, including the directory, but the pattern is applied only to the file name without the directory.
729
730 If /downcase-opt/ is supplied, filenames are converted to all-lowercase before matching against the pattern; you can use this to do case-insensitive matching using lowercase patterns. The paths returned will still have mixed case if the OS supplies them. On Windows NT and Cygwin, and OpenVMS, filenames are always downcased before matching.
731
732 [endsect]
733
734 [section =GLOB_ARCHIVE= ]
735
736 The =GLOB_ARCHIVE= rule does name globbing of object archive members.
737
738 [pre
739 rule GLOB_ARCHIVE ( /archives/ * : /member-patterns/ * : /downcase-opt/ ? : /symbol-patterns/ ? )
740 ]
741
742 Similarly to =GLOB=, this rule is used to match names of member files in an archive (static object library). List of successfully matched members is returned or null otherwise. The resulting member names are qualified with pathname of the containing archive in the form =archive-path(member-name)=. Member patterns are for matching member name only; when no wildcards specified -- an exact match is assumed. Member names generally correspond to object file names and as such are platform-specific -- use of platform-defined object suffix in the matching patterns can allow for portability.
743
744 If /downcase-opt/ is supplied, the member names are converted to all-lowercase before matching against the pattern; you can use this to do case-insensitive matching using lowercase patterns. The paths returned will still have mixed case if the OS supplies them. On Windows NT, Cygwin, and OpenVMS, filenames are always downcased before matching.
745
746 Additionally, members can be matched with symbol/function patterns on supported platforms (currently, OpenVMS only). In this case, members containing the matching symbols are returned. Member and symbol patterns are applied as OR conditions, with member patterns taking precedence. On unsupported platforms, null is returned when any symbol patterns are specified.
747
748 [endsect]
749
750 [section =MATCH= ]
751
752 The =MATCH= rule does pattern matching.
753
754 [pre
755 rule MATCH ( /regexps/ + : /list/ * )
756 ]
757
758 Matches the =egrep=(1) style regular expressions /regexps/ against the strings in /list/. The result is a list of matching =()= subexpressions for each string in /list/, and for each regular expression in /regexps/.
759
760 [endsect]
761
762 [section =BACKTRACE= ]
763
764 [pre
765 rule BACKTRACE ( )
766 ]
767
768 Returns a list of quadruples: /filename/ /line/ /module/ /rulename/..., describing each shallower level of the call stack. This rule can be used to generate useful diagnostic messages from Jam rules.
769
770 [endsect]
771
772 [section =UPDATE= ]
773
774 [pre
775 rule UPDATE ( /targets/ * )
776 ]
777
778 Classic jam treats any non-option element of command line as a name of target to be updated. This prevented more sophisticated handling of command line. This is now enabled again but with additional changes to the =UPDATE= rule to allow for the flexibility of changing the list of targets to update. The UPDATE rule has two effects:
779
780 # It clears the list of targets to update, and
781 # Causes the specified targets to be updated.
782
783 If no target was specified with the =UPDATE= rule, no targets will be updated. To support changing of the update list in more useful ways, the rule also returns the targets previously in the update list. This makes it possible to add targets as such:
784
785 [pre
786 local previous-updates = \[ UPDATE \] ;
787 UPDATE $(previous-updates) a-new-target ;
788 ]
789
790 [endsect]
791
792 [section =W32_GETREG= ]
793
794 [pre
795 rule W32_GETREG ( /path/ : /data/ ? )
796 ]
797
798 Defined only for win32 platform. It reads the registry of Windows. '/path/' is the location of the information, and '/data/' is the name of the value which we want to get. If '/data/' is omitted, the default value of '/path/' will be returned. The '/path/' value must conform to MS key path format and must be prefixed with one of the predefined root keys. As usual,
799
800 * '=HKLM=' is equivalent to '=HKEY_LOCAL_MACHINE='.
801 * '=HKCU=' is equivalent to '=HKEY_CURRENT_USER='.
802 * '=HKCR=' is equivalent to '=HKEY_CLASSES_ROOT='.
803
804 Other predefined root keys are not supported.
805
806 Currently supported data types : '=REG_DWORD=', '=REG_SZ=', '=REG_EXPAND_SZ=', '=REG_MULTI_SZ='. The data with '=REG_DWORD=' type will be turned into a string, '=REG_MULTI_SZ=' into a list of strings, and for those with '=REG_EXPAND_SZ=' type environment variables in it will be replaced with their defined values. The data with '=REG_SZ=' type and other unsupported types will be put into a string without modification. If it can't receive the value of the data, it just return an empty list. For example,
807
808 [pre
809 local PSDK-location =
810 \[ W32_GETREG HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\MicrosoftSDK\\\\Directories : "Install Dir" \] ;
811 ]
812
813 [endsect]
814
815 [section =W32_GETREGNAMES= ]
816
817 [pre
818 rule W32_GETREGNAMES ( /path/ : /result-type/ )
819 ]
820
821 Defined only for win32 platform. It reads the registry of Windows. '/path/' is the location of the information, and '/result-type/' is either '=subkeys=' or '=values='. For more information on '/path/' format and constraints, please see =W32_GETREG=.
822
823 Depending on '/result-type/', the rule returns one of the following:
824
825 [variablelist
826 [[=subkeys=] [Names of all direct subkeys of '/path/'.]]
827 [[=values=] [Names of values contained in registry key given by '/path/'. The "default" value of the key appears in the returned list only if its value has been set in the registry.]]
828 ]
829
830 If '/result-type/' is not recognized, or requested data cannot be retrieved, the rule returns an empty list.
831 Example:
832
833 [pre
834 local key = "HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\App Paths" ;
835 local subkeys = \[ W32_GETREGNAMES "$(key)" : subkeys \] ;
836 for local subkey in $(subkeys)
837 {
838 local values = \[ W32_GETREGNAMES "$(key)\\\\$(subkey)" : values \] ;
839 for local value in $(values)
840 {
841 local data = \[ W32_GETREG "$(key)\\\\$(subkey)" : "$(value)" \] ;
842 ECHO "Registry path: " $(key)\\\\$(subkey) ":" $(value) "=" $(data) ;
843 }
844 }
845 ]
846
847 [endsect]
848
849 [section =SHELL= ]
850
851 [pre
852 rule SHELL ( /command/ : * )
853 ]
854
855 =SHELL= executes /command/, and then returns the standard output of /command/. =SHELL= only works on platforms with a =popen()= function in the C library. On platforms without a working =popen()= function, =SHELL= is implemented as a no-op. =SHELL= works on Unix, MacOS X, and most Windows compilers. =SHELL= is a no-op on Metrowerks compilers under Windows. There is a variable set of allowed options as additional arguments:
856
857 [variablelist
858 [[=exit-status=] [In addition to the output the result status of the executed command is returned as a second element of the result.]]
859 [[=no-output=] [Don't capture the output of the command. Instead an empty ("") string value is returned in place of the output.]]
860 [[=strip-eol=] [Remove trailing end-of-line character from output, if any.]]
861 ]
862
863 Because the Perforce/Jambase defines a =SHELL= rule which hides the
864 builtin rule, =COMMAND= can be used as an alias for =SHELL= in such a case.
865
866 [endsect]
867
868 [section =MD5= ]
869
870 [pre
871 rule MD5 ( /string/ )
872 ]
873
874 =MD5= computes the MD5 hash of the string passed as paramater and returns it.
875
876 [endsect]
877
878 [section =SPLIT_BY_CHARACTERS= ]
879
880 [pre
881 rule SPLIT_BY_CHARACTERS ( /string/ : /delimiters/ )
882 ]
883
884 =SPLIT_BY_CHARACTERS= splits the specified /string/ on any delimiter character
885 present in /delimiters/ and returns the resulting list.
886
887 [endsect]
888
889 [section =PRECIOUS= ]
890
891 [pre
892 rule PRECIOUS ( /targets/ * )
893 ]
894
895 The =PRECIOUS= rule specifies that each of the targets passed as the arguments
896 should not be removed even if the command updating that target fails.
897
898 [endsect]
899
900 [section =PAD= ]
901
902 [pre
903 rule PAD ( /string/ : /width/ )
904 ]
905
906 If /string/ is shorter than /width/ characters, pads it with whitespace
907 characters on the right, and returns the result. Otherwise, returns
908 /string/ unmodified.
909
910 [endsect]
911
912 [section =FILE_OPEN= ]
913
914 [pre
915 rule FILE_OPEN ( /filename/ : /mode/ )
916 ]
917
918 The =FILE_OPEN= rule opens the specified file and returns a file
919 descriptor. The /mode/ parameter can be either "w" or "r". Note
920 that at present, only the =UPDATE_NOW= rule can use the resulting
921 file descriptor number.
922
923 [endsect]
924
925 [section =UPDATE_NOW= ]
926
927 [pre
928 rule UPDATE_NOW ( /targets/ * : /log/ ? : /ignore-minus-n/ ? )
929 ]
930
931 The =UPDATE_NOW= caused the specified targets to be updated immediately.
932 If update was successfull, non-empty string is returned. The /log/ parameter,
933 if present, specifies a descriptor of a file where all output from building
934 is redirected. If the /ignore-minus-n/ parameter is specified, the targets
935 are updated even if the =-n= parameter is specified on the command line.
936
937 [endsect]
938
939 [endsect]
940
941 [endsect]
942
943 [endsect]
944
945 [section Flow-of-Control]
946
947 =B2= has several simple flow-of-control statements:
948
949 [pre
950 for /var/ in /list/ { /statements/ }
951 ]
952
953 Executes /statements/ for each element in /list/, setting the variable /var/ to the element value.
954
955 [pre
956 if /cond/ { /statements/ }
957 \[ else { /statements/ } \]
958 ]
959
960 Does the obvious; the =else= clause is optional. /cond/ is built of:
961
962 [variablelist
963
964 [[[^['a]]]
965 [true if any ['a] element is a non-zero-length string]]
966
967 [[[^['a] = ['b]]]
968 [list ['a] matches list ['b] string-for-string]]
969
970 [[[^['a] != ['b]]]
971 [list ['a] does not match list ['b]]]
972
973 [[[^['a] < ['b]]]
974 [['a\[i\]] string is less than ['b\[i\]] string, where ['i] is first mismatched element in lists ['a] and ['b]]]
975
976 [[[^['a] <= ['b]]]
977 [every ['a] string is less than or equal to its ['b] counterpart]]
978
979 [[[^['a] > ['b]]]
980 [['a\[i\]] string is greater than ['b\[i\]] string, where ['i] is first mismatched element]]
981
982 [[[^['a] >= ['b]]]
983 [every ['a] string is greater than or equal to its ['b] counterpart]]
984
985 [[[^['a] in ['b]]]
986 [true if all elements of ['a] can be found in ['b], or if ['a] has no elements]]
987
988 [[[^! ['cond]]]
989 [condition not true]]
990
991 [[[^['cond] && ['cond]]]
992 [conjunction]]
993
994 [[[^['cond] || ['cond]]]
995 [disjunction]]
996
997 [[[^( ['cond] )]]
998 [precedence grouping]]
999
1000 ]
1001
1002 [pre
1003 include /file/ ;
1004 ]
1005
1006 Causes =b2= to read the named /file/. The /file/ is bound like a regular target (see Binding above) but unlike a regular target the include /file/ cannot be built.
1007
1008 The include /file/ is inserted into the input stream during the parsing phase. The primary input file and all the included file(s) are treated as a single file; that is, =b2= infers no scope boundaries from included files.
1009
1010 [pre
1011 local /vars/ \[ = /values/ \] ;
1012 ]
1013
1014 Creates new /vars/ inside to the enclosing ={}= block, obscuring any previous values they might have. The previous values for vars are restored when the current block ends. Any rule called or file included will see the local and not the previous value (this is sometimes called Dynamic Scoping). The local statement may appear anywhere, even outside of a block (in which case the previous value is restored when the input ends). The /vars/ are initialized to /values/ if present, or left uninitialized otherwise.
1015
1016 [pre
1017 return /values/ ;
1018 ]
1019
1020 Within a rule body, the return statement sets the return value for an invocation of the rule and returns to the caller.
1021
1022 [pre
1023 switch /value/
1024 {
1025 case /pattern1/ : /statements/ ;
1026 case /pattern2/ : /statements/ ;
1027 ...
1028 }
1029 ]
1030
1031 The switch statement executes zero or one of the enclosed /statements/, depending on which, if any, is the first case whose /pattern/ matches /value/. The /pattern/ values are not variable-expanded. The pattern values may include the following wildcards:
1032
1033 [variablelist
1034
1035 [[[^?]]
1036 [match any single character]]
1037
1038 [[[^*]]
1039 [match zero or more characters]]
1040
1041 [[[^\[/chars/\]]]
1042 [match any single character in /chars/]]
1043
1044 [[[^\[\^/chars/\]]]
1045 [match any single character not in /chars/]]
1046
1047 [[[^\\/x/]]
1048 [match /x/ (escapes the other wildcards)]]
1049
1050 ]
1051
1052 [pre
1053 while /cond/ { /statements/ }
1054 ]
1055
1056 Repeatedly execute /statements/ while /cond/ remains true upon entry. (See the description of /cond/ expression syntax under if, above).
1057
1058 [pre
1059 break ;
1060 ]
1061
1062 Immediately exits the nearest enclosing while or for loop.
1063
1064 [pre
1065 continue ;
1066 ]
1067
1068 Jumps to the top of the nearest enclosing while or for loop.
1069
1070 [endsect]
1071
1072 [section Variables]
1073
1074 =B2= variables are lists of zero or more elements, with each element being a string value. An undefined variable is indistinguishable from a variable with an empty list, however, a defined variable may have one more elements which are null strings. All variables are referenced as [^$(/variable/)].
1075
1076 Variables are either global or target-specific. In the latter case, the variable takes on the given value only during the updating of the specific target.
1077
1078 A variable is defined with:
1079
1080 [pre
1081 /variable/ = /elements/ ;
1082 /variable/ += /elements/ ;
1083 /variable/ on /targets/ = /elements/ ;
1084 /variable/ on /targets/ += /elements/ ;
1085 /variable/ default = /elements/ ;
1086 /variable/ ?= /elements/ ;
1087 ]
1088
1089 The first two forms set /variable/ globally. The third and forth forms set a target-specific variable. The [^\=] operator replaces any previous elements of /variable/ with /elements/; the [^+=] operation adds /elements/ to /variable/'s list of elements. The final two forms are synonymous: they set /variable/ globally, but only if it was previously unset.
1090
1091 Variables referenced in updating commands will be replaced with their values; target-specific values take precedence over global values. Variables passed as arguments (=$(1)= and =$(2)=) to actions are replaced with their bound values; the "=bind=" modifier can be used on actions to cause other variables to be replaced with bound values. See Action Modifiers above.
1092
1093 =B2= variables are not re-exported to the environment of the shell that executes the updating actions, but the updating actions can reference =b2= variables with [^$(/variable/)].
1094
1095 [section:expansion Variable Expansion]
1096
1097 During parsing, =b2= performs variable expansion on each token that is not a keyword or rule name. Such tokens with embedded variable references are replaced with zero or more tokens. Variable references are of the form [^$(/v/)] or [^$(/vm/)], where ['v] is the variable name, and ['m] are optional modifiers.
1098
1099 Variable expansion in a rule's actions is similar to variable expansion in statements, except that the action string is tokenized at whitespace regardless of quoting.
1100
1101 The result of a token after variable expansion is the /product/ of the components of the token, where each component is a literal substring or a list substituting a variable reference. For example:
1102
1103 [pre
1104 $(X) -> a b c
1105 t$(X) -> ta tb tc
1106 $(X)z -> az bz cz
1107 $(X)-$(X) -> a-a a-b a-c b-a b-b b-c c-a c-b c-c
1108 ]
1109
1110 The variable name and modifiers can themselves contain a variable reference, and this partakes of the product as well:
1111
1112 [pre
1113 $(X) -> a b c
1114 $(Y) -> 1 2
1115 $(Z) -> X Y
1116 $($(Z)) -> a b c 1 2
1117 ]
1118
1119 Because of this product expansion, if any variable reference in a token is undefined, the result of the expansion is an empty list. If any variable element is a null string, the result propagates the non-null elements:
1120
1121 [pre
1122 $(X) -> a ""
1123 $(Y) -> "" 1
1124 $(Z) ->
1125 -$(X)$(Y)- -> -a- -a1- -- -1-
1126 -$(X)$(Z)- ->
1127 ]
1128
1129 A variable element's string value can be parsed into grist and filename-related components. Modifiers to a variable are used to select elements, select components, and replace components. The modifiers are:
1130
1131 [variablelist
1132
1133 [[[^\[['n]\]]] [Select element number ['n] (starting at 1). If the variable
1134 contains fewer than ['n] elements, the result is a zero-element list. ['n]
1135 can be negative in which case the element number ['n] from the last leftward
1136 is returned.]]
1137
1138 [[[^\[['n]-['m]\]]]
1139 [Select elements number ['n] through ['m]. ['n] and ['m] can be negative in which case they refer to elements counting from the last leftward.]]
1140
1141 [[[^\[['n]-\]]]
1142 [Select elements number ['n] through the last. ['n] can be negative in which case it refers to the element counting from the last leftward.]]
1143
1144 [[[^:B]]
1145 [Select filename base.]]
1146
1147 [[[^:S]]
1148 [Select (last) filename suffix.]]
1149
1150 [[[^:M]]
1151 [Select archive member name.]]
1152
1153 [[[^:D]]
1154 [Select directory path.]]
1155
1156 [[[^:P]]
1157 [Select parent directory.]]
1158
1159 [[[^:G]]
1160 [Select grist.]]
1161
1162 [[[^:U]]
1163 [Replace lowercase characters with uppercase.]]
1164
1165 [[[^:L]]
1166 [Replace uppercase characters with lowercase.]]
1167
1168 [[[^:T]]
1169 [Converts all back-slashes ("\\") to forward slashes ("/"). For example
1170 ``
1171 x = "C:\\Program Files\\Borland" ; ECHO $(x:T) ;
1172 ``
1173 prints [^"C:/Program Files/Borland"]
1174 ]]
1175
1176 [[[^:W]]
1177 [When invoking Windows-based tools from [@http://www.cygwin.com/ Cygwin]
1178 it can be important to pass them true windows-style paths. The =:W=
1179 modifier, *under Cygwin only*, turns a cygwin path into a Win32 path using
1180 the [@http://www.cygwin.com/cygwin-api/func-cygwin-conv-to-win32-path.html
1181 =cygwin_conv_to_win32_path=] function. For example
1182 ``
1183 x = "/cygdrive/c/Program Files/Borland" ; ECHO $(x:W) ;
1184 ``
1185 prints [^"C:\\Program Files\\Borland"] on Cygwin
1186
1187 Similarly, when used on OpenVMS, the =:W= modifier translates a POSIX-style path into native VMS-style format using =decc$to_vms= CRTL function. This modifier is generally used inside action blocks to properly specify file paths in VMS-specific commands. For example
1188 ``
1189 x = "subdir/filename.c" ; ECHO $(x:W) ;
1190 ``
1191 prints [^"\[.subdir\]filename.c"] on OpenVMS
1192
1193 On other platforms, the string is unchanged.
1194 ]]
1195
1196 [[[^:['chars]]]
1197 [Select the components listed in ['chars].]]
1198
1199 [[[^:G=['grist]]]
1200 [Replace grist with ['grist].]]
1201
1202 [[[^:D=['path]]]
1203 [Replace directory with ['path].]]
1204
1205 [[[^:B=['base]]]
1206 [Replace the base part of file name with ['base].]]
1207
1208 [[[^:S=['suf]]]
1209 [Replace the suffix of file name with ['suf].]]
1210
1211 [[[^:M=['mem]]]
1212 [Replace the archive member name with ['mem].]]
1213
1214 [[[^:R=['root]]]
1215 [Prepend ['root] to the whole file name, if not already rooted.]]
1216
1217 [[[^:E=['value]]]
1218 [Assign ['value] to the variable if it is unset.]]
1219
1220 [[[^:J=['joinval]]]
1221 [Concatentate list elements into single element, separated by ['joinval]'.]]
1222
1223 ]
1224
1225 On VMS, [^$(var:P)] is the parent directory of [^$(var:D)].
1226
1227 [endsect]
1228
1229 [section Local For Loop Variables]
1230
1231 Boost Jam allows you to declare a local for loop control variable right in the loop:
1232
1233 [pre
1234 x = 1 2 3 ;
1235 y = 4 5 6 ;
1236 for *local* y in $(x)
1237 {
1238 ECHO $(y) ; # prints "1", "2", or "3"
1239 }
1240 ECHO $(y) ; # prints "4 5 6"
1241 ]
1242
1243 [endsect]
1244
1245 [section:atfile Generated File Expansion]
1246
1247 During expansion of expressions =b2= also looks for subexpressions of the form
1248 =@(filename:E=filecontents)= and replaces the expression with =filename= after
1249 creating the given file with the contents set to =filecontents=. This is useful
1250 for creating compiler response files, and other "internal" files. The expansion
1251 works both during parsing and action execution. Hence it is possible to create
1252 files during any of the three build phases.
1253
1254 [endsect]
1255
1256 [section:builtins Built-in Variables]
1257
1258 This section discusses variables that have special meaning to =b2=. All of
1259 these must be defined or used in the global module -- using those variables
1260 inside a named module will not have the desired effect.
1261 See [link jam.language.modules Modules].
1262
1263 [section:search SEARCH and LOCATE]
1264
1265 These two variables control the binding of file target names to locations in
1266 the file system. Generally, =$(SEARCH)= is used to find existing sources
1267 while =$(LOCATE)= is used to fix the location for built targets.
1268
1269 Rooted (absolute path) file targets are bound as is. Unrooted file target names are also normally bound as is, and thus relative to the current directory, but the settings of =$(LOCATE)= and =$(SEARCH)= alter this:
1270
1271 * If =$(LOCATE)= is set then the target is bound relative to the first directory in =$(LOCATE)=. Only the first element is used for binding.
1272 * If =$(SEARCH)= is set then the target is bound to the first directory in =$(SEARCH)= where the target file already exists.
1273 * If the =$(SEARCH)= search fails, the target is bound relative to the current directory anyhow.
1274
1275 Both =$(SEARCH)= and =$(LOCATE)= should be set target-specific and not globally. If they were set globally, =b2= would use the same paths for all file binding, which is not likely to produce sane results. When writing your own rules, especially ones not built upon those in Jambase, you may need to set =$(SEARCH)= or =$(LOCATE)= directly. Almost all of the rules defined in Jambase set =$(SEARCH)= and =$(LOCATE)= to sensible values for sources they are looking for and targets they create, respectively.
1276
1277 [endsect]
1278
1279 [section:hdrscan HDRSCAN and HDRRULE]
1280
1281 These two variables control header file scanning. =$(HDRSCAN)= is an
1282 =egrep(1)= pattern, with ()'s surrounding the file name, used to find file
1283 inclusion statements in source files. =Jambase= uses =$(HDRPATTERN)= as the
1284 pattern for =$(HDRSCAN)=. =$(HDRRULE)= is the name of a rule to invoke with
1285 the results of the scan: the scanned file is the target, the found files are
1286 the sources. This is the only place where =b2= invokes a rule through a
1287 variable setting.
1288
1289 Both =$(HDRSCAN)= and =$(HDRRULE)= must be set for header file scanning to take place, and they should be set target-specific and not globally. If they were set globally, all files, including executables and libraries, would be scanned for header file include statements.
1290
1291 The scanning for header file inclusions is not exact, but it is at least dynamic, so there is no need to run something like =makedepend(GNU)= to create a static dependency file. The scanning mechanism errs on the side of inclusion (i.e., it is more likely to return filenames that are not actually used by the compiler than to miss include files) because it can't tell if `#include` lines are inside `#ifdefs` or other conditional logic. In =Jambase=, =HdrRule= applies the =NOCARE= rule to each header file found during scanning so that if the file isn't present yet doesn't cause the compilation to fail, =b2= won't care.
1292
1293 Also, scanning for regular expressions only works where the included file name is literally in the source file. It can't handle languages that allow including files using variable names (as the =Jam= language itself does).
1294
1295 [endsect]
1296
1297 [section Semaphores]
1298
1299 It is sometimes desirable to disallow parallel execution of some actions. For example:
1300
1301 * Old versions of yacc use files with fixed names. So, running two yacc actions is dangerous.
1302 * One might want to perform parallel compiling, but not do parallel linking, because linking is i/o bound and only gets slower.
1303
1304 Craig McPeeters has extended Perforce Jam to solve such problems, and that extension was integrated in Boost.Jam.
1305
1306 Any target can be assigned a /semaphore/, by setting a variable called =SEMAPHORE= on that target. The value of the variable is the semaphore name. It must be different from names of any declared target, but is arbitrary otherwise.
1307
1308 The semantic of semaphores is that in a group of targets which have the same semaphore, only one can be updated at the moment, regardless of "=-j=" option.
1309
1310 [endsect]
1311
1312 [section Platform Identifier]
1313
1314 A number of Jam built-in variables can be used to identify runtime platform:
1315
1316 [variablelist
1317 [[=OS=] [OS identifier string]]
1318 [[=OSPLAT=] [Underlying architecture, when applicable]]
1319 [[=MAC=] [true on MAC platform]]
1320 [[=NT=] [true on NT platform]]
1321 [[=OS2=] [true on OS2 platform]]
1322 [[=UNIX=] [true on Unix platforms]]
1323 [[=VMS=] [true on VMS platform]]
1324 ]
1325
1326 [endsect]
1327
1328 [section Jam Version]
1329
1330 [variablelist
1331 [[=JAMDATE=] [Time and date at =b2= start-up as an ISO-8601 UTC value.]]
1332 [[=JAMUNAME=] [Ouput of uname(1) command (Unix only)]]
1333 [[=JAMVERSION=] [=b2= version, currently ":version:"]]
1334 [[=JAM_VERSION=] [A predefined global variable with two elements indicates the version number of Boost Jam. Boost Jam versions start at "=03=" "=00=". Earlier versions of =Jam= do not automatically define =JAM_VERSION=.]]
1335 ]
1336
1337 [endsect]
1338
1339 [section JAMSHELL]
1340
1341 When =b2= executes a rule's action block, it forks and execs a shell, passing the action block as an argument to the shell. The invocation of the shell can be controlled by =$(JAMSHELL)=. The default on Unix is, for example:
1342
1343 [pre
1344 JAMSHELL = /bin/sh -c % ;
1345 ]
1346
1347 The =%= is replaced with the text of the action block.
1348
1349 =B2= does not directly support building in parallel across multiple hosts, since that is heavily dependent on the local environment. To build in parallel across multiple hosts, you need to write your own shell that provides access to the multiple hosts. You then reset =$(JAMSHELL)= to reference it.
1350
1351 Just as =b2= expands a =%= to be the text of the rule's action block, it expands a =!= to be the multi-process slot number. The slot number varies between 1 and the number of concurrent jobs permitted by the =-j= flag given on the command line. Armed with this, it is possible to write a multiple host shell. For example:
1352
1353 [pre
1354 #!/bin/sh
1355
1356 # This sample JAMSHELL uses the SunOS on(1) command to execute a
1357 # command string with an identical environment on another host.
1358
1359 # Set JAMSHELL = jamshell ! %
1360 #
1361 # where jamshell is the name of this shell file.
1362 #
1363 # This version handles up to -j6; after that they get executed
1364 # locally.
1365
1366 case $1 in
1367 1|4) on winken sh -c "$2";;
1368 2|5) on blinken sh -c "$2";;
1369 3|6) on nod sh -c "$2";;
1370 *) eval "$2";;
1371 esac
1372 ]
1373
1374 [endsect]
1375
1376 [section:actionrule =__TIMING_RULE__= and =__ACTION_RULE__=]
1377
1378 The =__TIMING_RULE__= and =__ACTION_RULE__= can be set to the name of a rule
1379 for =b2= to call *after* an action completes for a target. They both give
1380 diagnostic information about the action that completed. For =__TIMING_RULE__=
1381 the rule is called as:
1382
1383 rule timing-rule ( args * : target : start end user system )
1384
1385 And =__ACTION_RULE__= is called as:
1386
1387 rule action-rule ( args * : target : command status start end user system : output ? )
1388
1389 The arguments for both are:
1390
1391 [variablelist
1392 [[[^args]]
1393 [Any values following the rule name in the =__TIMING_RULE__= or =__ACTION_RULE__=
1394 are passed along here.]]
1395 [[[^target]]
1396 [The =b2= target that was built.]]
1397 [[[^command]]
1398 [The text of the executed command in the action body.]]
1399 [[[^status]]
1400 [The integer result of the executed command.]]
1401 [[[^start]]
1402 [The starting timestamp of the executed command as a ISO-8601 UTC value.]]
1403 [[[^end]]
1404 [The completion timestamp of the executed command as a ISO-8601 UTC value.]]
1405 [[[^user]]
1406 [The number of user CPU seconds the executed command spent as a floating
1407 point value.]]
1408 [[[^system]]
1409 [The number of system CPU seconds the executed command spent as a floating
1410 point value.]]
1411 [[[^output]]
1412 [The output of the command as a single string. The content of the output
1413 reflects the use of the =-pX= option.]]
1414 ]
1415
1416 [note
1417 If both variables are set for a target both are called, first =__TIMING_RULE__=
1418 then =__ACTION_RULE__=. ]
1419
1420 [endsect]
1421
1422 [endsect]
1423
1424 [endsect]
1425
1426 [section Modules]
1427
1428 Boost Jam introduces support for modules, which provide some rudimentary namespace protection for rules and variables. A new keyword, "=module=" was also introduced. The features described in this section are primitives, meaning that they are meant to provide the operations needed to write Jam rules which provide a more elegant module interface.
1429
1430 [section Declaration]
1431
1432 [pre
1433 module /expression/ { ... }
1434 ]
1435
1436 Code within the [^{ ... }] executes within the module named by evaluating expression. Rule definitions can be found in the module's own namespace, and in the namespace of the global module as /module-name/./rule-name/, so within a module, other rules in that module may always be invoked without qualification:
1437
1438 [pre
1439 *module my_module*
1440 *{*
1441 rule salute ( x ) { ECHO $(x), world ; }
1442 rule greet ( ) { salute hello ; }
1443 greet ;
1444 *}*
1445 *my_module.salute* goodbye ;
1446 ]
1447
1448 When an invoked rule is not found in the current module's namespace, it is looked up in the namespace of the global module, so qualified calls work across modules:
1449
1450 [pre
1451 module your_module
1452 {
1453 rule bedtime ( ) { *my_module.salute* goodnight ; }
1454 }
1455 ]
1456
1457 [endsect]
1458
1459 [section Variable Scope]
1460
1461 Each module has its own set of dynamically nested variable scopes. When execution passes from module A to module B, all the variable bindings from A become unavailable, and are replaced by the bindings that belong to B. This applies equally to local and global variables:
1462
1463 [pre
1464 module A
1465 {
1466 x = 1 ;
1467 rule f ( )
1468 {
1469 local y = 999 ; # becomes visible again when B.f calls A.g
1470 B.f ;
1471 }
1472 rule g ( )
1473 {
1474 ECHO $(y) ; # prints "999"
1475 }
1476 }
1477 module B
1478 {
1479 y = 2 ;
1480 rule f ( )
1481 {
1482 ECHO $(y) ; # always prints "2"
1483 A.g ;
1484 }
1485 }
1486 ]
1487
1488 The only way to access another module's variables is by entering that module:
1489
1490 [pre
1491 rule peek ( module-name ? : variables + )
1492 {
1493 module $(module-name)
1494 {
1495 return $($(>)) ;
1496 }
1497 }
1498 ]
1499
1500 Note that because existing variable bindings change whenever a new module scope is entered, argument bindings become unavailable. That explains the use of "=$(>)=" in the peek rule above.
1501
1502 [endsect]
1503
1504 [section Local Rules]
1505
1506 [pre
1507 local rule /rulename/...
1508 ]
1509
1510 The rule is declared locally to the current module. It is not entered in the global module with qualification, and its name will not appear in the result of:
1511
1512 [pre
1513 \[ RULENAMES /module-name/ \]
1514 ]
1515
1516 [endsect]
1517
1518 [section The =RULENAMES= Rule]
1519
1520 [pre
1521 rule RULENAMES ( /module/ ? )
1522 ]
1523
1524 Returns a list of the names of all non-local rules in the given module. If /module/ is omitted, the names of all non-local rules in the global module are returned.
1525
1526 [endsect]
1527
1528 [section The =VARNAMES= Rule]
1529
1530 [pre
1531 rule VARNAMES ( /module/ ? )
1532 ]
1533
1534 Returns a list of the names of all variable bindings in the given module. If /module/ is omitted, the names of all variable bindings in the global module are returned.
1535
1536 [note This includes any local variables in rules from the call stack which have not returned at the time of the =VARNAMES= invocation.]
1537
1538 [endsect]
1539
1540 [section The =IMPORT= Rule]
1541
1542 =IMPORT= allows rule name aliasing across modules:
1543
1544 [pre
1545 rule IMPORT ( /source_module/ ? : /source_rules/ *
1546 : /target_module/ ? : /target_rules/ * )
1547 ]
1548
1549 The =IMPORT= rule copies rules from the /source_module/ into the /target_module/ as local rules. If either /source_module/ or /target_module/ is not supplied, it refers to the global module. /source_rules/ specifies which rules from the /source_module/ to import; /target_rules/ specifies the names to give those rules in /target_module/. If /source_rules/ contains a name which doesn't correspond to a rule in /source_module/, or if it contains a different number of items than /target_rules/, an error is issued. For example,
1550
1551 [pre
1552 # import m1.rule1 into m2 as local rule m1-rule1.
1553 IMPORT m1 : rule1 : m2 : m1-rule1 ;
1554 # import all non-local rules from m1 into m2
1555 IMPORT m1 : \[ RULENAMES m1 \] : m2 : \[ RULENAMES m1 \] ;
1556 ]
1557
1558 [endsect]
1559
1560 [section The =EXPORT= Rule]
1561
1562 =EXPORT= allows rule name aliasing across modules:
1563
1564 [pre
1565 rule EXPORT ( /module/ ? : /rules/ * )
1566 ]
1567
1568 The =EXPORT= rule marks /rules/ from the =source_module= as non-local (and thus exportable). If an element of /rules/ does not name a rule in /module/, an error is issued. For example,
1569
1570 [pre
1571 module X {
1572 local rule r { ECHO X.r ; }
1573 }
1574 IMPORT X : r : : r ; # error - r is local in X
1575 EXPORT X : r ;
1576 IMPORT X : r : : r ; # OK.
1577 ]
1578
1579 [endsect]
1580
1581 [section The =CALLER_MODULE= Rule]
1582
1583 [pre
1584 rule CALLER_MODULE ( /levels/ ? )
1585 ]
1586
1587 =CALLER_MODULE= returns the name of the module scope enclosing the call to its caller (if levels is supplied, it is interpreted as an integer number of additional levels of call stack to traverse to locate the module). If the scope belongs to the global module, or if no such module exists, returns the empty list. For example, the following prints "{Y} {X}":
1588
1589 [pre
1590 module X {
1591 rule get-caller { return \[ CALLER_MODULE \] ; }
1592 rule get-caller's-caller { return \[ CALLER_MODULE 1 \] ; }
1593 rule call-Y { return Y.call-X2 ; }
1594 }
1595 module Y {
1596 rule call-X { return X.get-caller ; }
1597 rule call-X2 { return X.get-caller's-caller ; }
1598 }
1599 callers = \[ X.get-caller \] \[ Y.call-X \] \[ X.call-Y \] ;
1600 ECHO {$(callers)} ;
1601 ]
1602
1603 [endsect]
1604
1605 [section The =DELETE_MODULE= Rule]
1606
1607 [pre
1608 rule DELETE_MODULE ( /module/ ? )
1609 ]
1610
1611 =DELETE_MODULE= removes all of the variable bindings and otherwise-unreferenced rules from the given module (or the global module, if no module is supplied), and returns their memory to the system.
1612
1613 [note Though it won't affect rules that are currently executing until they complete, =DELETE_MODULE= should be used with extreme care because it will wipe out any others and all variable (including locals in that module) immediately. Because of the way dynamic binding works, variables which are shadowed by locals will not be destroyed, so the results can be really unpredictable.]
1614
1615 [endsect]
1616
1617 [endsect]
1618
1619 [endsect]
1620
1621 [section Miscellaneous]
1622
1623 [section Diagnostics]
1624
1625 In addition to generic error messages, =b2= may emit one of the following:
1626
1627 [pre warning: unknown rule X]
1628
1629 A rule was invoked that has not been defined with an "=actions=" or "=rule=" statement.
1630
1631 [pre using N temp target(s)]
1632
1633 Targets marked as being temporary (but nonetheless present) have been found.
1634
1635 [pre updating N target(s)]
1636
1637 Targets are out-of-date and will be updated.
1638
1639 [pre can't find N target(s)]
1640
1641 Source files can't be found and there are no actions to create them.
1642
1643 [pre can't make N target(s)]
1644
1645 Due to sources not being found, other targets cannot be made.
1646
1647 [pre warning: X depends on itself]
1648
1649 A target depends on itself either directly or through its sources.
1650
1651 [pre don't know how to make X]
1652
1653 A target is not present and no actions have been defined to create it.
1654
1655 [pre X skipped for lack of Y]
1656
1657 A source failed to build, and thus a target cannot be built.
1658
1659 [pre warning: using independent target X]
1660
1661 A target that is not a dependency of any other target is being referenced with =$(<)= or =$(>)=.
1662
1663 [pre X removed]
1664
1665 =B2= removed a partially built target after being interrupted.
1666
1667 [endsect]
1668
1669 [section Bugs, Limitations]
1670
1671 For parallel building to be successful, the dependencies among files must be properly spelled out, as targets tend to get built in a quickest-first ordering. Also, beware of un-parallelizable commands that drop fixed-named files into the current directory, like =yacc(1)= does.
1672
1673 A poorly set =$(JAMSHELL)= is likely to result in silent failure.
1674
1675 [endsect]
1676
1677 [section Fundamentals]
1678
1679 This section is derived from the official Jam documentation and from experience using it and reading the Jambase rules. We repeat the information here mostly because it is essential to understanding and using Jam, but is not consolidated in a single place. Some of it is missing from the official documentation altogether. We hope it will be useful to anyone wishing to become familiar with Jam and the Boost build system.
1680
1681 * Jam "=rules=" are actually simple procedural entities. Think of them as functions. Arguments are separated by colons.
1682
1683 * A Jam *target* is an abstract entity identified by an arbitrary string. The build-in =DEPENDS= rule creates a link in the dependency graph between the named targets.
1684
1685 * Note that the original Jam documentation for the built-in =INCLUDES= rule is incorrect: [^INCLUDES ['targets1] : ['targets2]] causes everything that depends on a member of /targets1/ to depend on all members of /targets2/. It does this in an odd way, by tacking /targets2/ onto a special tail section in the dependency list of everything in /targets1/. It seems to be OK to create circular dependencies this way; in fact, it appears to be the "right thing to do" when a single build action produces both /targets1/ and /targets2/.
1686
1687 * When a rule is invoked, if there are =actions= declared with the same name as the rule, the actions are added to the updating actions for the target identified by the rule's first argument. It is actually possible to invoke an undeclared rule if corresponding actions are declared: the rule is treated as empty.
1688
1689 * Targets (other than =NOTFILE= targets) are associated with paths in the file system through a process called binding. Binding is a process of searching for a file with the same name as the target (sans grist), based on the settings of the target-specific =SEARCH= and =LOCATE= variables.
1690
1691 * In addition to local and global variables, jam allows you to set a variable =on= a target. Target-specific variable values can usually not be read, and take effect only in the following contexts:
1692
1693 * In updating actions, variable values are first looked up =on= the target named by the first argument (the target being updated). Because Jam builds its entire dependency tree before executing actions, Jam rules make target-specific variable settings as a way of supplying parameters to the corresponding actions.
1694 * Binding is controlled /entirely/ by the target-specific setting of the =SEARCH= and =LOCATE= variables, as described here.
1695 * In the special rule used for header file scanning, variable values are first looked up =on= the target named by the rule's first argument (the source file being scanned).
1696
1697 * The "bound value" of a variable is the path associated with the target named by the variable. In build actions, the first two arguments are automatically replaced with their bound values. Target-specific variables can be selectively replaced by their bound values using the =bind= action modifier.
1698
1699 * Note that the term "binding" as used in the Jam documentation indicates a phase of processing that includes three sub-phases: /binding/ (yes!), update determination, and header file scanning. The repetition of the term "binding" can lead to some confusion. In particular, the Modifying Binding section in the Jam documentation should probably be titled "Modifying Update Determination".
1700
1701 * "Grist" is just a string prefix of the form </characters/>. It is used in Jam to create unique target names based on simpler names. For example, the file name "=test.exe=" may be used by targets in separate subprojects, or for the debug and release variants of the "same" abstract target. Each distinct target bound to a file called "test.exe" has its own unique grist prefix. The Boost build system also takes full advantage of Jam's ability to divide strings on grist boundaries, sometimes concatenating multiple gristed elements at the beginning of a string. Grist is used instead of identifying targets with absolute paths for two reasons:
1702
1703 # The location of targets cannot always be derived solely from what the user puts in a Jamfile, but sometimes depends also on the binding process. Some mechanism to distinctly identify targets with the same name is still needed.
1704 # Grist allows us to use a uniform abstract identifier for each built target, regardless of target file location (as allowed by setting ALL_LOCATE_TARGET).
1705
1706 * When grist is extracted from a name with $(var:G), the result includes the leading and trailing angle brackets. When grist is added to a name with $(var:G=expr), existing grist is first stripped. Then, if expr is non-empty, leading <s and trailing >s are added if necessary to form an expression of the form <expr2>; <expr2> is then prepended.
1707
1708 * When Jam is invoked it imports all environment variable settings into corresponding Jam variables, followed by all command-line (-s...) variable settings. Variables whose name ends in PATH, Path, or path are split into string lists on OS-specific path-list separator boundaries (e.g. ":" for UNIX and ";" for Windows). All other variables are split on space (" ") boundaries. Boost Jam modifies that behavior by allowing variables to be quoted.
1709
1710 * A variable whose value is an empty list or which consists entirely of empty
1711 strings has a negative logical value. Thus, for example, code like the
1712 following allows a sensible non-empty default which can easily be overridden
1713 by the user:
1714 ``
1715 MESSAGE ?\= starting jam... ;
1716 if $(MESSAGE) { ECHO The message is: $(MESSAGE) ; }
1717 ``
1718 If the user wants a specific message, he invokes jam with [^"-sMESSAGE\=message text"]. If he wants no message, he invokes jam with [^-sMESSAGE\=] and nothing at all is printed.
1719
1720 * The parsing of command line options in Jam can be rather unintuitive, with regards to how other Unix programs accept options. There are two variants accepted as valid for an option:
1721
1722 # =-xvalue=, and
1723 # =-x value=.
1724
1725 [endsect]
1726
1727 [endsect]
1728
1729
1730 [section History]
1731 [include history.qbk]
1732 [endsect]