1 | [article Boost.Jam |
---|
2 | [quickbook 1.3] |
---|
3 | [version: 3.1.14] |
---|
4 | [authors [Rivera, Rene], [Abrahams, David], [Prus, Vladimir]] |
---|
5 | [copyright 2003 2004 2005 2006 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.14] |
---|
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 | [section:intro Introduction] |
---|
39 | |
---|
40 | Boost.Jam (BJam) is a build tool based on FTJam, which in turn is based on :Perforce_Jam:. It contains significant improvements made to facilitate its use in the Boost Build System, but should be backward compatible with :Perforce_Jam:. |
---|
41 | |
---|
42 | This is version :version: of BJam and is based on version 2.4 of Jam/MR: |
---|
43 | |
---|
44 | [pre |
---|
45 | /+\ |
---|
46 | +\ Copyright 1993-2002 Christopher Seiwald and Perforce Software, Inc. |
---|
47 | \+/ |
---|
48 | This is Release 2.4 of Jam/MR, a make-like program. |
---|
49 | License is hereby granted to use this software and distribute it |
---|
50 | freely, as long as this copyright notice is retained and modifications |
---|
51 | are clearly marked. |
---|
52 | ALL WARRANTIES ARE HEREBY DISCLAIMED. |
---|
53 | ] |
---|
54 | |
---|
55 | [section:features Features] |
---|
56 | |
---|
57 | Jam is a make(1) replacement that makes building simple things simple and building complicated things manageable. |
---|
58 | |
---|
59 | Jam's language is expressive, making Jamfiles (c.f. Makefiles) compact. |
---|
60 | |
---|
61 | Jam handles header file dependencies automatically and on-the-fly. |
---|
62 | |
---|
63 | Jam is very portable: it runs on UNIX, VMS, Mac, and NT. Most Jamfiles themselves are portable. |
---|
64 | |
---|
65 | Jam is unintrusive: it is small, it has negligible CPU overhead, and it doesn't create any of its own funny files (c.f. Odin, nmake, SunOS make). |
---|
66 | |
---|
67 | Jam can build large projects spread across many directories in one pass, without recursing, tracking the relationships among all files. Jam can do this with multiple, concurrent processes. |
---|
68 | |
---|
69 | Jam isn't under the blinkin GNU copyright, so you can incorporate it into commercial products. |
---|
70 | |
---|
71 | [endsect] |
---|
72 | |
---|
73 | [endsect] |
---|
74 | |
---|
75 | [section:building Building BJam] |
---|
76 | |
---|
77 | Installing =BJam= after building it is simply a matter of copying the |
---|
78 | generated executables someplace in your =PATH=. For building the executables |
---|
79 | there are a set of =build= bootstrap scripts to accomodate particular |
---|
80 | environments. The scripts take one optional argument, the name of the toolset |
---|
81 | to build with. When the toolset is not given an attempt is made to detect an |
---|
82 | available toolset and use that. The build scripts accept these arguments: |
---|
83 | |
---|
84 | [pre |
---|
85 | /build/ \[/toolset/\] |
---|
86 | ] |
---|
87 | |
---|
88 | Running the scripts without arguments will give you the best chance of success. On Windows platforms from a command console do: |
---|
89 | |
---|
90 | [pre |
---|
91 | cd /jam source location/ |
---|
92 | .\\build.bat |
---|
93 | ] |
---|
94 | |
---|
95 | On Unix type platforms do: |
---|
96 | |
---|
97 | [pre |
---|
98 | cd /jam source location/ |
---|
99 | sh ./build.sh |
---|
100 | ] |
---|
101 | |
---|
102 | For the Boost.Jam source included with the Boost distribution the /jam source location/ is =BOOST_ROOT/tools/jam/src=. |
---|
103 | |
---|
104 | 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=. |
---|
105 | |
---|
106 | [note |
---|
107 | 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. |
---|
108 | ] |
---|
109 | |
---|
110 | The supported toolsets, and wether they are auto-detected, are: |
---|
111 | |
---|
112 | [table Supported Toolsets |
---|
113 | |
---|
114 | [[Script] [Platform] [Toolset] [Detection]] |
---|
115 | |
---|
116 | [ [=build.bat=] [Windows NT, 2000, and XP] |
---|
117 | [ [@http://www.borland.com/bcppbuilder/freecompiler =borland=]\n |
---|
118 | [@http://www.borland.com/ Borland] C++Builder (BCC 5.5)] |
---|
119 | [ * Common install location: "=C:\Borland\BCC55="\n |
---|
120 | * =BCC32.EXE= in =PATH= |
---|
121 | ] ] |
---|
122 | |
---|
123 | [ [] [] |
---|
124 | [ [@http://www.comeaucomputing.com/ =como=]\n |
---|
125 | Comeau Computing C/C++] |
---|
126 | [ |
---|
127 | ] ] |
---|
128 | |
---|
129 | [ [] [] |
---|
130 | [ [@http://gcc.gnu.org/ =gcc=]\n |
---|
131 | GNU GCC] |
---|
132 | [ |
---|
133 | ] ] |
---|
134 | |
---|
135 | [ [] [] |
---|
136 | [ [@http://gcc.gnu.org/ =gcc-nocygwin=]\n |
---|
137 | GNU GCC] |
---|
138 | [ |
---|
139 | ] ] |
---|
140 | |
---|
141 | [ [] [] |
---|
142 | [ [@http://www.intel.com/software/products/compilers/c60 =intel-win32=]\n |
---|
143 | Intel C++ Compiler for Windows] |
---|
144 | [ * =ICL.EXE= in =PATH= |
---|
145 | ] ] |
---|
146 | |
---|
147 | [ [] [] |
---|
148 | [ [@http://www.metrowerks.com/ =metrowerks=]\n |
---|
149 | MetroWerks CodeWarrior C/C++ 7.x, 8.x, 9.x] |
---|
150 | [ * =CWFolder= variable configured |
---|
151 | * =MWCC.EXE= in =PATH= |
---|
152 | ] ] |
---|
153 | |
---|
154 | [ [] [] |
---|
155 | [ [@http://www.mingw.org/ =mingw=]\n |
---|
156 | GNU [@http://gcc.gnu.org/ GCC] as the [@http://www.mingw.org/ MinGW] configuration] |
---|
157 | [ * Common install location: "=C:\MinGW=" |
---|
158 | ] ] |
---|
159 | |
---|
160 | [ [] [] |
---|
161 | [ [@http://msdn.microsoft.com/visualc/ =msvc=]\n |
---|
162 | Microsoft Visual C++ 6.x] |
---|
163 | [ * =VCVARS32.BAT= already configured\n |
---|
164 | * =%MSVCDir%= is present in environment\n |
---|
165 | * Common install locations: "=%ProgramFiles%\Microsoft Visual Studio=", "=%ProgramFiles%\Microsoft Visual C++="\n |
---|
166 | * =CL.EXE= in =PATH=\n |
---|
167 | * =VCVARS32.BAT= in =PATH= |
---|
168 | ] ] |
---|
169 | |
---|
170 | [ [] [] |
---|
171 | [ [@http://msdn.microsoft.com/visualc/ =vc7=]\n |
---|
172 | Microsoft Visual C++ 7.x] |
---|
173 | [ * =VCVARS32.BAT= or =VSVARS32.BAT= already configured |
---|
174 | * =%VS71COMNTOOLS%= is present in environment\n |
---|
175 | * =%VCINSTALLDIR%= is present in environment\n |
---|
176 | * Common install locations: "=%ProgramFiles%\Microsoft Visual Studio .NET=", "=%ProgramFiles%\Microsoft Visual Studio .NET 2003="\n |
---|
177 | * =CL.EXE= in =PATH=\n |
---|
178 | * =VCVARS32.BAT= in =PATH= |
---|
179 | ] ] |
---|
180 | |
---|
181 | [ [] [] |
---|
182 | [ [@http://msdn.microsoft.com/visualc/ =vc8=]\n |
---|
183 | Microsoft Visual C++ 8.x] |
---|
184 | [ * =VCVARS32.BAT= or =VSVARS32.BAT= already configured\n |
---|
185 | * =%VS80COMNTOOLS%= is present in environment\n |
---|
186 | * Common install location: "=%ProgramFiles%\Microsoft Visual Studio 8="\n |
---|
187 | * =CL.EXE= in =PATH=\n |
---|
188 | * =VCVARS32.BAT= in =PATH= |
---|
189 | ] ] |
---|
190 | |
---|
191 | [ [=build.sh=] [Unix, Linux, Cygwin, etc.] |
---|
192 | [ [@http://www.hp.com/go/c++ =acc=]\n |
---|
193 | HP-UX aCC] |
---|
194 | [ * =aCC= in =PATH=\n |
---|
195 | * =uname= is "HP-UX" |
---|
196 | ] ] |
---|
197 | |
---|
198 | [ [] [] |
---|
199 | [ [@http://www.comeaucomputing.com/ =como=]\n |
---|
200 | Comeau Computing C/C++] |
---|
201 | [ * como in =PATH= |
---|
202 | ] ] |
---|
203 | |
---|
204 | [ [] [] |
---|
205 | [ [@http://gcc.gnu.org/ =gcc=]\n |
---|
206 | GNU GCC] |
---|
207 | [ * gcc in =PATH= |
---|
208 | ] ] |
---|
209 | |
---|
210 | [ [] [] |
---|
211 | [ [@http://www.intel.com/software/products/compilers/c60l/ =intel-linux=]\n |
---|
212 | Intel C++ for Linux] |
---|
213 | [ * =icc= in =PATH=\n |
---|
214 | * Common install locations: "=/opt/intel/cc/9.0=", "=/opt/intel_cc_80=", "=/opt/intel/compiler70=", "=/opt/intel/compiler60=", "=/opt/intel/compiler50=" |
---|
215 | ] ] |
---|
216 | |
---|
217 | [ [] [] |
---|
218 | [ =kcc=\n |
---|
219 | Intel KAI C++] |
---|
220 | [ * =KCC= in =PATH= |
---|
221 | ] ] |
---|
222 | |
---|
223 | [ [] [] |
---|
224 | [ [@http://www.borland.com/bcppbuilder/freecompiler =kylix=]\n |
---|
225 | [@http://www.borland.com/ Borland] C++Builder] |
---|
226 | [ * bc++ in PATH |
---|
227 | ] ] |
---|
228 | |
---|
229 | [ [] [] |
---|
230 | [ [@http://www.sgi.com/developers/devtools/languages/mipspro.html =mipspro=]\n |
---|
231 | SGI MIPSpro C] |
---|
232 | [ * =uname= is "=IRIX=" or "=IRIX64=" |
---|
233 | ] ] |
---|
234 | |
---|
235 | [ [] [] |
---|
236 | [ =sunpro=\n |
---|
237 | Sun Workshop 6 C++] |
---|
238 | [ * Standard install location: "=/opt/SUNWspro=" |
---|
239 | ] ] |
---|
240 | |
---|
241 | [ [] [] |
---|
242 | [ =qcc=\n |
---|
243 | [@http://www.qnx.com/ QNX Neutrino]] |
---|
244 | [ * =uname= is "=QNX=" and =qcc= in =PATH= |
---|
245 | ] ] |
---|
246 | |
---|
247 | [ [] [] |
---|
248 | [ [@http://www.tru64unix.compaq.com/cplus/ =true64cxx=]\n |
---|
249 | Compaq C++ Compiler for True64 UNIX] |
---|
250 | [ * =uname= is "=OSF1=" |
---|
251 | ] ] |
---|
252 | |
---|
253 | [ [] [] |
---|
254 | [ [@http://www-3.ibm.com/software/ad/vacpp/ =vacpp=]\n |
---|
255 | IBM VisualAge C++] |
---|
256 | [ * =xlc= in =PATH= |
---|
257 | ] ] |
---|
258 | |
---|
259 | [ [] [MacOS X] |
---|
260 | [ [@http://developer.apple.com/tools/compilers.html =darwin=]\n |
---|
261 | Apple MacOS X GCC] |
---|
262 | [ * =uname= is "=Darwin=" |
---|
263 | ] ] |
---|
264 | |
---|
265 | [ [] [Windows NT, 2000, and XP] |
---|
266 | [ [@http://www.mingw.org/ =mingw=]\n |
---|
267 | GNU [@http://gcc.gnu.org/ GCC] as the [@http://www.mingw.org/ MinGW] configuration with the MSYS shell] |
---|
268 | [ * Common install location: "=/mingw=" |
---|
269 | ] ] |
---|
270 | |
---|
271 | ] |
---|
272 | |
---|
273 | 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 =bjam[.exe]= executable can be used to invoke Boost.Build. |
---|
274 | |
---|
275 | The build scripts support additional invocation arguments for use by developers of Boost.Jam. The extra arguments come after the toolset, and can take the form of "=--option=" or targets for the =build.jam= script: |
---|
276 | |
---|
277 | [pre |
---|
278 | /build/ \[/toolset/\] \[--/option/+ /target/*\] |
---|
279 | ] |
---|
280 | |
---|
281 | There is currently only one available option, "=--debug=", which builds debugging versions of the executable. When built they are placed in their own directory "=bin./platform/.debug=". To specify targets without options, one can suply a special ignore option "=---=". |
---|
282 | |
---|
283 | Currently there are two targets supported: =dist=, and =clean=. Respectively they: generate packages (compressed archives) as appropriate for distribution in the platform, or remove all the built executables and objects. |
---|
284 | |
---|
285 | [endsect] |
---|
286 | |
---|
287 | [section:usage Using BJam] |
---|
288 | |
---|
289 | If /target/ is provided on the command line, =bjam= builds /target/; otherwise =bjam= builds the target =all=. |
---|
290 | |
---|
291 | [pre |
---|
292 | bjam ( -option \[value\] | target ) * |
---|
293 | ] |
---|
294 | |
---|
295 | [section:options Options] |
---|
296 | |
---|
297 | Options are either singular or have an accompanying value. When a value is allowed, or required, it can be either given as an argument following the option argument, or it can be given immediately after the option as part of the option argument. The allowed options are: |
---|
298 | |
---|
299 | [variablelist |
---|
300 | |
---|
301 | [ [[^-a]] |
---|
302 | [Build all targets anyway, even if they are up-to-date.] ] |
---|
303 | |
---|
304 | [ [[^-d''' '''/n/]] |
---|
305 | [ |
---|
306 | Enable cummulative debugging levels from 1 to n. Values are:\n |
---|
307 | |
---|
308 | 1 - Show the actions taken for building targets, as they are executed (the default).\n |
---|
309 | 2 - Show "quiet" actions and display all action text, as they are executed.\n |
---|
310 | 3 - Show dependency analysis, and target/source timestamps/paths.\n |
---|
311 | 4 - Show arguments and timming of shell invocations.\n |
---|
312 | 5 - Show rule invocations and variable expansions.\n |
---|
313 | 6 - Show directory/header file/archive scans, and attempts at binding to targets.\n |
---|
314 | 7 - Show variable settings.\n |
---|
315 | 8 - Show variable fetches, variable expansions, and evaluation of '"if"' expressions.\n |
---|
316 | 9 - Show variable manipulation, scanner tokens, and memory usage.\n |
---|
317 | 10 - Show profile information for rules, both timing and memory.\n |
---|
318 | 11 - Show parsing progress of Jamfiles.\n |
---|
319 | 12 - Show graph of target dependencies.\n |
---|
320 | 13 - Show change target status (fate). |
---|
321 | ] ] |
---|
322 | |
---|
323 | [ [[^-d''' '''+/n/]] |
---|
324 | [Enable debugging level /n/.] ] |
---|
325 | |
---|
326 | [ [[^-d''' '''0]] |
---|
327 | [Turn off all debugging levels. Only errors are reported.] ] |
---|
328 | |
---|
329 | [ [[^-f''' '''/Jambase/]] [Read /Jambase/ instead of using the built-in |
---|
330 | Jambase. Only one -f flag is permitted, but the /Jambase/ may explicitly |
---|
331 | include other files. A /Jambase/ name of "-" is allowed, in which case |
---|
332 | console input is read until it is closed, at which point the input is |
---|
333 | treated as the Jambase.] ] |
---|
334 | |
---|
335 | [ [[^-j''' '''/n/]] |
---|
336 | [Run up to /n/ shell commands concurrently (UNIX and NT only). The default is 1.] ] |
---|
337 | |
---|
338 | [ [[^-l''' '''/n/]] |
---|
339 | [Limit actions to running for /n/ number of seconds, after which they are stopped. Note: Windows only.] ] |
---|
340 | |
---|
341 | [ [[^-n]] |
---|
342 | [Don't actually execute the updating actions, but do everything else. This changes the debug level default to =-d 2=.] ] |
---|
343 | |
---|
344 | [ [[^-o''' '''/file/]] |
---|
345 | [Write the updating actions to the specified file instead of running them.] ] |
---|
346 | |
---|
347 | [ [[^-q]] |
---|
348 | [Quit quickly (as if an interrupt was received) as soon as *any* target fails.] ] |
---|
349 | |
---|
350 | [ [[^-s''' '''/var/=/value/]] |
---|
351 | [Set the variable /var/ to /value/, overriding both internal variables and variables imported from the environment.] ] |
---|
352 | |
---|
353 | [ [[^-t''' '''/target/]] |
---|
354 | [Rebuild /target/ and everything that depends on it, even if it is up-to-date.] ] |
---|
355 | |
---|
356 | [ [[^--''' '''/value/]] |
---|
357 | [The option and /value/ is ignored, but is available from the =$(ARGV)= variable. ]] |
---|
358 | |
---|
359 | [ [[^-v]] |
---|
360 | [Print the version of =bjam= and exit.] ] |
---|
361 | ] |
---|
362 | |
---|
363 | [section Command-line and Environment Variable Quoting] |
---|
364 | |
---|
365 | Classic Jam had an odd behavior with respect to command-line variable (=-s...=) and environment variable settings which made it impossible to define an arbitrary variable with spaces in the value. Boost Jam remedies that by treating all such settings as a single string if they are surrounded by double-quotes. Uses of this feature can look interesting, since shells require quotes to keep characters separated by whitespace from being treated as separate arguments: |
---|
366 | |
---|
367 | [pre |
---|
368 | jam -sMSVCNT="\\"\\"C:\\Program Files\\Microsoft Visual C++\\VC98\\"\\"" ... |
---|
369 | ] |
---|
370 | |
---|
371 | The outer quote is for the shell. The middle quote is for Jam, to tell it to take everything within those quotes literally, and the inner quotes are for the shell again when paths are passed as arguments to build actions. Under NT, it looks a lot more sane to use environment variables before invoking jam when you have to do this sort of quoting: |
---|
372 | |
---|
373 | [pre |
---|
374 | set MSVCNT=""C:\\Program Files\\Microsoft Visual C++\\VC98\\"" |
---|
375 | ] |
---|
376 | |
---|
377 | [endsect] |
---|
378 | |
---|
379 | [endsect] |
---|
380 | |
---|
381 | [section:operation Operation] |
---|
382 | |
---|
383 | BJam has four phases of operation: start-up, parsing, binding, and updating. |
---|
384 | |
---|
385 | [section:startup Start-up] |
---|
386 | |
---|
387 | Upon start-up, =bjam= imports environment variable settings into =bjam= variables. Environment variables are split at blanks with each word becoming an element in the variable's list of values. Environment variables whose names end in =PATH= are split at =$(SPLITPATH)= characters (e.g., =":"= for Unix). |
---|
388 | |
---|
389 | To set a variable's value on the command line, overriding the variable's environment value, use the =-s= option. To see variable assignments made during bjam's execution, use the =-d+7= option. |
---|
390 | |
---|
391 | The Boost.Build v2 initialization behavior has been implemented. This behavior only applies when the executable being invoked is called "=bjam=" or, for backward-compatibility, when the =BOOST_ROOT= variable is set. |
---|
392 | |
---|
393 | # We attempt to load "=boost-build.jam=" by searching from the current invocation directory up to the root of the file system. This file is expected to invoke the =boost-build= rule to indicate where the Boost.Build system files are, and to load them. |
---|
394 | |
---|
395 | # If =boost-build.jam= is not found we error and exit, giving brief instructions on possible errors. As a backward-compatibility measure for older versions of Boost.Build, when the =BOOST_ROOT= variable is set, we first search for =boost-build.jam= in =$(BOOST_ROOT)/tools/build= and =$(BOOST_BUILD_PATH)=. If found, it is loaded and initialization is complete. |
---|
396 | |
---|
397 | # The =boost-build= rule adds its (optional) argument to the front of =BOOST_BUILD_PATH=, and attempts to load =bootstrap.jam= from those directories. If a relative path is specified as an argument, it is treated as though it was relative to the =boost-build.jam= file. |
---|
398 | |
---|
399 | # If the =bootstrap.jam= file was not found, we print a likely error message and exit. |
---|
400 | |
---|
401 | [endsect] |
---|
402 | |
---|
403 | [section:parsing Parsing] |
---|
404 | |
---|
405 | In the parsing phase, =bjam= reads and parses the =Jambase= file, by default the built-in one. It is written in the [link jam.language jam language]. The last action of the =Jambase= is to read (via the "include" rule) a user-provided file called "=Jamfile=". |
---|
406 | |
---|
407 | Collectively, the purpose of the =Jambase= and the =Jamfile= is to name build targets and source files, construct the dependency graph among them, and associate build actions with targets. The =Jambase= defines boilerplate rules and variable assignments, and the =Jamfile= uses these to specify the actual relationship among the target and source files. |
---|
408 | |
---|
409 | [endsect] |
---|
410 | |
---|
411 | [section:binding Binding] |
---|
412 | |
---|
413 | After parsing, =bjam= recursively descends the dependency graph and binds every file target with a location in the filesystem. If =bjam= detects a circular dependency in the graph, it issues a warning. |
---|
414 | |
---|
415 | File target names are given as absolute or relative path names in the filesystem. If the path name is absolute, it is bound as is. If the path name is relative, it is normally bound as is, and thus relative to the current directory. This can be modified by the settings of the =$(SEARCH)= and =$(LOCATE)= variables, which enable jam to find and build targets spread across a directory tree. See [link jam.language.variables.builtins.search SEARCH and LOCATE Variables] below. |
---|
416 | |
---|
417 | [section:fate Update Determination] |
---|
418 | |
---|
419 | After binding each target, =bjam= determines whether the target needs updating, and if so marks the target for the updating phase. A target is normally so marked if it is missing, it is older than any of its sources, or any of its sources are marked for updating. This behavior can be modified by the application of special built-in rules, =ALWAYS=, =LEAVES=, =NOCARE=, =NOTFILE=, =NOUPDATE=, and =TEMPORARY=. See [link jam.language.rules.builtins.modifying_binding Modifying Binding] below. |
---|
420 | |
---|
421 | [endsect] |
---|
422 | |
---|
423 | [section:headerscan Header File Scanning] |
---|
424 | |
---|
425 | During the binding phase, =bjam= also performs header file scanning, where it looks inside source files for the implicit dependencies on other files caused by C's #include syntax. This is controlled by the special variables $(HDRSCAN) and $(HDRRULE). The result of the scan is formed into a rule invocation, with the scanned file as the target and the found included file names as the sources. Note that this is the only case where rules are invoked outside the parsing phase. See [link jam.language.variables.builtins.hdrscan HDRSCAN and HDRRULE Variables] below. |
---|
426 | |
---|
427 | [endsect] |
---|
428 | |
---|
429 | [endsect] |
---|
430 | |
---|
431 | [section:updating Updating] |
---|
432 | |
---|
433 | After binding, =bjam= again recursively descends the dependency graph, this time executing the update actions for each target marked for update during the binding phase. If a target's updating actions fail, then all other targets which depend on that target are skipped. |
---|
434 | |
---|
435 | The =-j= flag instructs =bjam= to build more than one target at a time. If there are multiple actions on a single target, they are run sequentially. |
---|
436 | |
---|
437 | [endsect] |
---|
438 | |
---|
439 | [endsect] |
---|
440 | |
---|
441 | [endsect] |
---|
442 | |
---|
443 | [section:language Language] |
---|
444 | |
---|
445 | =BJam= has an interpreted, procedural language. Statements in =bjam= are rule (procedure) definitions, rule invocations, flow-of-control structures, variable assignments, and sundry language support. |
---|
446 | |
---|
447 | [section:lexical Lexical Features] |
---|
448 | |
---|
449 | =BJam= 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. |
---|
450 | |
---|
451 | =BJam= requires whitespace (blanks, tabs, or newlines) to surround all tokens, including the colon (:) and semicolon (;) tokens. |
---|
452 | |
---|
453 | =BJam= keywords (an mentioned in this document) are reserved and generally |
---|
454 | must be quoted with double quotes (") to be used as arbitrary tokens, such as |
---|
455 | variable or target names. |
---|
456 | |
---|
457 | Comments start with the [^#] character and extend until the end of line. |
---|
458 | |
---|
459 | [endsect] |
---|
460 | |
---|
461 | [section:target Targets] |
---|
462 | |
---|
463 | The essential =bjam= 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 which represent dependencies on other targets, but which are not themselves associated with any real file. |
---|
464 | |
---|
465 | A file target's identifier is generally the file's name, which can be absolutely rooted, relative to the directory of =bjam='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). |
---|
466 | |
---|
467 | [section Binding Detection] |
---|
468 | |
---|
469 | 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: |
---|
470 | |
---|
471 | [pre |
---|
472 | rule /bind-rule/ ( /target/ : /path/ ) |
---|
473 | ] |
---|
474 | |
---|
475 | 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. |
---|
476 | |
---|
477 | [endsect] |
---|
478 | |
---|
479 | [endsect] |
---|
480 | |
---|
481 | [section:rules Rules] |
---|
482 | |
---|
483 | The basic =bjam= 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. |
---|
484 | |
---|
485 | 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). Note that 'return' doesn't actually cause a return, i.e., is a no-op unless it is the last statement of the last block executed within rule body. |
---|
486 | |
---|
487 | The =bjam= statements for defining and invoking rules are as follows: |
---|
488 | |
---|
489 | Define a rule's procedure, replacing any previous definition. |
---|
490 | |
---|
491 | [pre |
---|
492 | rule /rulename/ { /statements/ } |
---|
493 | ] |
---|
494 | |
---|
495 | Define a rule's updating actions, replacing any previous definition. |
---|
496 | |
---|
497 | [pre |
---|
498 | actions \[ /modifiers/ \] /rulename/ { /commands/ } |
---|
499 | ] |
---|
500 | |
---|
501 | Invoke a rule. |
---|
502 | |
---|
503 | [pre |
---|
504 | /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ ; |
---|
505 | ] |
---|
506 | |
---|
507 | Invoke a rule under the influence of target's specific variables.. |
---|
508 | |
---|
509 | [pre |
---|
510 | on /target/ /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ ; |
---|
511 | ] |
---|
512 | |
---|
513 | Used as an argument, expands to the return value of the rule invoked. |
---|
514 | |
---|
515 | [pre |
---|
516 | \[ /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ \] |
---|
517 | \[ on /target/ /rulename/ /field1/ : /field2/ : /.../ : /fieldN/ \] |
---|
518 | ] |
---|
519 | |
---|
520 | 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)]. |
---|
521 | |
---|
522 | 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. |
---|
523 | |
---|
524 | 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. |
---|
525 | |
---|
526 | Rule invocation may be indirected through a variable: |
---|
527 | |
---|
528 | [pre |
---|
529 | $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ ; |
---|
530 | |
---|
531 | on /target/ $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ ; |
---|
532 | |
---|
533 | \[ $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ \] |
---|
534 | \[ on /target/ $(/var/) /field1/ : /field2/ : /.../ : /fieldN/ \] |
---|
535 | ] |
---|
536 | |
---|
537 | The variable's value names the rule (or rules) to be invoked. A rule is |
---|
538 | invoked for each element in the list of [^$(/var/)]'s values. The fields |
---|
539 | [^/field1/ : /field2/ : /.../] are passed as arguments for each |
---|
540 | invokation. For the [ ... ] forms, the return value is the concatenation of |
---|
541 | the return values for all of the invocations. |
---|
542 | |
---|
543 | [section Action Modifiers] |
---|
544 | |
---|
545 | The following action modifiers are understood: |
---|
546 | |
---|
547 | [variablelist |
---|
548 | |
---|
549 | [[[^actions bind /vars/]] |
---|
550 | [[^$(/vars/)] will be replaced with bound values.]] |
---|
551 | |
---|
552 | [[[^actions existing]] |
---|
553 | [[^$(>)] includes only source targets currently existing.]] |
---|
554 | |
---|
555 | [[[^actions ignore]] |
---|
556 | [The return status of the commands is ignored.]] |
---|
557 | |
---|
558 | [[[^actions piecemeal]] |
---|
559 | [commands are repeatedly invoked with a subset of [^$(>)] small enough to fit in the command buffer on this OS.]] |
---|
560 | |
---|
561 | [[[^actions quietly]] |
---|
562 | [The action is not echoed to the standard output.]] |
---|
563 | |
---|
564 | [[[^actions together]] |
---|
565 | [The [^$(>)] from multiple invocations of the same action on the same built target are glommed together.]] |
---|
566 | |
---|
567 | [[[^actions updated]] |
---|
568 | [[^$(>)] includes only source targets themselves marked for updating.]] |
---|
569 | |
---|
570 | ] |
---|
571 | |
---|
572 | [endsect] |
---|
573 | |
---|
574 | [section Argument lists] |
---|
575 | |
---|
576 | 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: |
---|
577 | |
---|
578 | [pre |
---|
579 | rule report ( pronoun index ? : state : names + ) |
---|
580 | { |
---|
581 | local he.suffix she.suffix it.suffix = s ; |
---|
582 | local I.suffix = m ; |
---|
583 | local they.suffix you.suffix = re ; |
---|
584 | ECHO $(pronoun)'$($(pronoun).suffix) $(state), $(names\[$(index)\]) ; |
---|
585 | } |
---|
586 | report I 2 : sorry : Joe Dave Pete ; |
---|
587 | ] |
---|
588 | |
---|
589 | 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: |
---|
590 | |
---|
591 | [table |
---|
592 | [[Symbol] [Semantics of preceding symbol]] |
---|
593 | [[=?=] [optional]] |
---|
594 | [[=*=] [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.]] |
---|
595 | [[=+=] [Bind to one or more unbound elements of the actual argument.]] |
---|
596 | ] |
---|
597 | |
---|
598 | The actual and formal arguments are checked for inconsistencies, which cause Jam to exit with an error code: |
---|
599 | |
---|
600 | [pre |
---|
601 | ### argument error |
---|
602 | # rule report ( pronoun index ? : state : names + ) |
---|
603 | # called with: ( I 2 foo : sorry : Joe Dave Pete ) |
---|
604 | # extra argument foo |
---|
605 | ### argument error |
---|
606 | # rule report ( pronoun index ? : state : names + ) |
---|
607 | # called with: ( I 2 : sorry ) |
---|
608 | # missing argument names |
---|
609 | ] |
---|
610 | |
---|
611 | 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. |
---|
612 | |
---|
613 | [endsect] |
---|
614 | |
---|
615 | [section:builtins Built-in Rules] |
---|
616 | |
---|
617 | =BJam= 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. |
---|
618 | |
---|
619 | [section Dependency Building] |
---|
620 | |
---|
621 | [pre |
---|
622 | DEPENDS /targets1/ : /targets2/ ; |
---|
623 | ] |
---|
624 | |
---|
625 | Builds a direct dependency: makes each of /targets1/ depend on each of /targets2/. Generally, /targets1/ will be rebuilt if /targets2/ are themselves rebuilt are or are newer than /targets1/. |
---|
626 | |
---|
627 | [pre |
---|
628 | INCLUDES /targets1/ : /targets2/ ; |
---|
629 | ] |
---|
630 | |
---|
631 | 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: |
---|
632 | |
---|
633 | [pre |
---|
634 | DEPENDS foo.o : foo.c ; |
---|
635 | INCLUDES foo.c : foo.h ; |
---|
636 | ] |
---|
637 | |
---|
638 | "=foo.o=" depends on "=foo.c=" and "=foo.h=" in this example. |
---|
639 | |
---|
640 | [endsect] |
---|
641 | |
---|
642 | [section Modifying Binding] |
---|
643 | |
---|
644 | The six rules =ALWAYS=, =LEAVES=, =NOCARE=, =NOTFILE=, =NOUPDATE=, and =TEMPORARY= modify the dependency graph so that =bjam= treats the targets differently during its target binding phase. See Binding above. Normally, =bjam= 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: |
---|
645 | |
---|
646 | [pre |
---|
647 | ALWAYS /targets/ ; |
---|
648 | ] |
---|
649 | |
---|
650 | 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. |
---|
651 | |
---|
652 | [pre |
---|
653 | LEAVES /targets/ ; |
---|
654 | ] |
---|
655 | |
---|
656 | 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. |
---|
657 | |
---|
658 | [pre |
---|
659 | NOCARE /targets/ ; |
---|
660 | ] |
---|
661 | |
---|
662 | Causes =bjam= to ignore /targets/ that neither can be found nor have updating actions to build them. Normally for such targets =bjam= 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 =bjam= 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. |
---|
663 | |
---|
664 | [warning For targets with build actions: if their build actions exit with a nonzero return code, dependent targets will still be built.] |
---|
665 | |
---|
666 | [pre |
---|
667 | NOTFILE /targets/ ; |
---|
668 | ] |
---|
669 | |
---|
670 | 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 =bjam= target "=all=" is a pseudotarget. In =Jambase=, =NOTFILE= is used to define several addition convenient pseudotargets. |
---|
671 | |
---|
672 | [pre |
---|
673 | NOUPDATE /targets/ ; |
---|
674 | ] |
---|
675 | |
---|
676 | 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. |
---|
677 | |
---|
678 | [pre |
---|
679 | TEMPORARY /targets/ ; |
---|
680 | ] |
---|
681 | |
---|
682 | 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, =bjam= 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. |
---|
683 | |
---|
684 | [pre |
---|
685 | FAIL_EXPECTED /targets/ ; |
---|
686 | ] |
---|
687 | |
---|
688 | For handling targets whose build actions are expected to fail (e.g. when testing that assertions or compile-time type checkin work properly), Boost Jam supplies the =FAIL_EXPECTED= rule in the same style as =NOCARE=, et. al. During target updating, the return code of the build actions for arguments to =FAIL_EXPECTED= is inverted: if it fails, building of dependent targets continues as though it succeeded. If it succeeds, dependent targets are skipped. |
---|
689 | |
---|
690 | [pre |
---|
691 | RMOLD /targets/ ; |
---|
692 | ] |
---|
693 | |
---|
694 | =BJam= 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. |
---|
695 | |
---|
696 | [pre |
---|
697 | rule ISFILE ( /targets/ * ) |
---|
698 | ] |
---|
699 | |
---|
700 | =ISFILE= marks targets as required to be files. This changes the way =bjam= searches for the target such that it ignores mathes for file system items that are not file, 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. |
---|
701 | |
---|
702 | [warning This is currently not fully implemented.] |
---|
703 | |
---|
704 | [endsect] |
---|
705 | |
---|
706 | [section Utility] |
---|
707 | |
---|
708 | The two rules =ECHO= and =EXIT= are utility rules, used only in =bjam='s parsing phase. |
---|
709 | |
---|
710 | [pre |
---|
711 | ECHO /args/ ; |
---|
712 | ] |
---|
713 | |
---|
714 | Blurts out the message /args/ to stdout. |
---|
715 | |
---|
716 | [pre |
---|
717 | rule EXIT ( /message/ * : /result-value/ ? ) |
---|
718 | ] |
---|
719 | |
---|
720 | 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/. |
---|
721 | |
---|
722 | "=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=". |
---|
723 | |
---|
724 | The =GLOB= rule does filename globbing. |
---|
725 | |
---|
726 | [pre |
---|
727 | GLOB /directories/ : /patterns/ : /downcase-opt/ |
---|
728 | ] |
---|
729 | |
---|
730 | 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. |
---|
731 | |
---|
732 | 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, filenames are always downcased before matching. |
---|
733 | |
---|
734 | The =MATCH= rule does pattern matching. |
---|
735 | |
---|
736 | [pre |
---|
737 | MATCH /regexps/ : /list/ |
---|
738 | ] |
---|
739 | |
---|
740 | Matches the =egrep=(1) style regular expressions /regexps/ against the strings in /list/. The result is the concatenation of matching =()= subexpressions for each string in /list/, and for each regular expression in /regexps/. Only useful within the "=[ ]=" construct, to change the result into a list. |
---|
741 | |
---|
742 | [pre |
---|
743 | rule BACKTRACE ( ) |
---|
744 | ] |
---|
745 | |
---|
746 | 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. |
---|
747 | |
---|
748 | [pre |
---|
749 | rule UPDATE ( /targets/ * ) |
---|
750 | ] |
---|
751 | |
---|
752 | 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: |
---|
753 | |
---|
754 | # It clears the list of targets to update, and |
---|
755 | # Causes the specified targets to be updated. |
---|
756 | |
---|
757 | If no target was specified with the =UPDATE= rule, no targets will be updated. To support changing of the update list in more usefull ways, the rule also returns the targets previously in the update list. This makes it possible to add targets as such: |
---|
758 | |
---|
759 | [pre |
---|
760 | local previous-updates = \[ UPDATE \] ; |
---|
761 | UPDATE $(previous-updates) a-new-target ; |
---|
762 | ] |
---|
763 | |
---|
764 | [pre |
---|
765 | rule W32_GETREG ( /path/ : /data/ ? ) |
---|
766 | ] |
---|
767 | |
---|
768 | 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, |
---|
769 | |
---|
770 | * '=HKLM=' is equivalent to '=HKEY_LOCAL_MACHINE='. |
---|
771 | * '=HKCU=' is equivalent to '=HKEY_CURRENT_USER='. |
---|
772 | * '=HKCR=' is equivalent to '=HKEY_CLASSES_ROOT='. |
---|
773 | |
---|
774 | Other predefined root keys are not supported. |
---|
775 | |
---|
776 | 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, |
---|
777 | |
---|
778 | [pre |
---|
779 | local PSDK-location = |
---|
780 | \[ W32_GETREG HKEY_LOCAL_MACHINE\\\\SOFTWARE\\\\Microsoft\\\\MicrosoftSDK\\\\Directories : "Install Dir" \] ; |
---|
781 | ] |
---|
782 | |
---|
783 | [pre |
---|
784 | rule SHELL ( /command/ : * ) |
---|
785 | ] |
---|
786 | |
---|
787 | =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: |
---|
788 | |
---|
789 | [variablelist |
---|
790 | [[=exit-status=] [In addition to the output the result status of the executed command is returned as a second element of the result.]] |
---|
791 | [[=no-output=] [Don't capture the output of the command. Instead an empty ("") string value is returned in place of the output.]] |
---|
792 | ] |
---|
793 | |
---|
794 | Because the Perforce/Jambase defines a =SHELL= rule which hides the |
---|
795 | builtin rule, =COMMAND= can be used as an alias for =SHELL= in such a case. |
---|
796 | |
---|
797 | [endsect] |
---|
798 | |
---|
799 | [endsect] |
---|
800 | |
---|
801 | [endsect] |
---|
802 | |
---|
803 | [section Flow-of-Control] |
---|
804 | |
---|
805 | =BJam= has several simple flow-of-control statements: |
---|
806 | |
---|
807 | [pre |
---|
808 | for /var/ in /list/ { /statements/ } |
---|
809 | ] |
---|
810 | |
---|
811 | Executes /statements/ for each element in /list/, setting the variable /var/ to the element value. |
---|
812 | |
---|
813 | [pre |
---|
814 | if /cond/ { /statements/ } |
---|
815 | \[ else { /statements/ } \] |
---|
816 | ] |
---|
817 | |
---|
818 | Does the obvious; the =else= clause is optional. /cond/ is built of: |
---|
819 | |
---|
820 | [variablelist |
---|
821 | |
---|
822 | [[[^['a]]] |
---|
823 | [true if any ['a] element is a non-zero-length string]] |
---|
824 | |
---|
825 | [[[^['a] = ['b]]] |
---|
826 | [list ['a] matches list ['b] string-for-string]] |
---|
827 | |
---|
828 | [[[^['a] != ['b]]] |
---|
829 | [list ['a] does not match list ['b]]] |
---|
830 | |
---|
831 | [[[^['a] < ['b]]] |
---|
832 | [['a\[i\]] string is less than ['b\[i\]] string, where ['i] is first mismatched element in lists ['a] and ['b]]] |
---|
833 | |
---|
834 | [[[^['a] <= ['b]]] |
---|
835 | [every ['a] string is less than or equal to its ['b] counterpart]] |
---|
836 | |
---|
837 | [[[^['a] > ['b]]] |
---|
838 | [['a\[i\]] string is greater than ['b\[i\]] string, where ['i] is first mismatched element]] |
---|
839 | |
---|
840 | [[[^['a] >= ['b]]] |
---|
841 | [every ['a] string is greater than or equal to its ['b] counterpart]] |
---|
842 | |
---|
843 | [[[^['a] in ['b]]] |
---|
844 | [true if all elements of ['a] can be found in ['b], or if ['a] has no elements]] |
---|
845 | |
---|
846 | [[[^! ['cond]]] |
---|
847 | [condition not true]] |
---|
848 | |
---|
849 | [[[^['cond] && ['cond]]] |
---|
850 | [conjunction]] |
---|
851 | |
---|
852 | [[[^['cond] || ['cond]]] |
---|
853 | [disjunction]] |
---|
854 | |
---|
855 | [[[^( ['cond] )]] |
---|
856 | [precedence grouping]] |
---|
857 | |
---|
858 | ] |
---|
859 | |
---|
860 | [pre |
---|
861 | include /file/ ; |
---|
862 | ] |
---|
863 | |
---|
864 | Causes =bjam= 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. |
---|
865 | |
---|
866 | 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, jam infers no scope boundaries from included files. |
---|
867 | |
---|
868 | [pre |
---|
869 | local /vars/ \[ = /values/ \] ; |
---|
870 | ] |
---|
871 | |
---|
872 | 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. |
---|
873 | |
---|
874 | [pre |
---|
875 | return /values/ ; |
---|
876 | ] |
---|
877 | |
---|
878 | Within a rule body, the return statement sets the return value for an invocation of the rule. It does *not* cause the rule to return; a rule's value is actually the value of the last statement executed, so a return should be the last statement executed before the rule "naturally" returns. |
---|
879 | |
---|
880 | [pre |
---|
881 | switch /value/ |
---|
882 | { |
---|
883 | case /pattern1/ : /statements/ ; |
---|
884 | case /pattern2/ : /statements/ ; |
---|
885 | ... |
---|
886 | } |
---|
887 | ] |
---|
888 | |
---|
889 | 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: |
---|
890 | |
---|
891 | [variablelist |
---|
892 | |
---|
893 | [[[^?]] |
---|
894 | [match any single character]] |
---|
895 | |
---|
896 | [[[^*]] |
---|
897 | [match zero or more characters]] |
---|
898 | |
---|
899 | [[[^\[/chars/\]]] |
---|
900 | [match any single character in /chars/]] |
---|
901 | |
---|
902 | [[[^\[\^/chars/\]]] |
---|
903 | [match any single character not in /chars/]] |
---|
904 | |
---|
905 | [[[^\\/x/]] |
---|
906 | [match /x/ (escapes the other wildcards)]] |
---|
907 | |
---|
908 | ] |
---|
909 | |
---|
910 | [pre |
---|
911 | while /cond/ { /statements/ } |
---|
912 | ] |
---|
913 | |
---|
914 | Repeatedly execute /statements/ while /cond/ remains true upon entry. (See the description of /cond/ expression syntax under if, above). |
---|
915 | |
---|
916 | [endsect] |
---|
917 | |
---|
918 | [section Variables] |
---|
919 | |
---|
920 | =BJam= 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/)]. |
---|
921 | |
---|
922 | 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. |
---|
923 | |
---|
924 | A variable is defined with: |
---|
925 | |
---|
926 | [pre |
---|
927 | /variable/ = /elements/ ; |
---|
928 | /variable/ += /elements/ ; |
---|
929 | /variable/ on /targets/ = /elements/ ; |
---|
930 | /variable/ on /targets/ += /elements/ ; |
---|
931 | /variable/ default = /elements/ ; |
---|
932 | /variable/ ?= /elements/ ; |
---|
933 | ] |
---|
934 | |
---|
935 | 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. |
---|
936 | |
---|
937 | 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. |
---|
938 | |
---|
939 | =BJam= variables are not re-exported to the environment of the shell that executes the updating actions, but the updating actions can reference =bjam= variables with [^$(/variable/)]. |
---|
940 | |
---|
941 | [section:expansion Variable Expansion] |
---|
942 | |
---|
943 | During parsing, =bjam= 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. |
---|
944 | |
---|
945 | 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. |
---|
946 | |
---|
947 | 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: |
---|
948 | |
---|
949 | [pre |
---|
950 | $(X) -> a b c |
---|
951 | t$(X) -> ta tb tc |
---|
952 | $(X)z -> az bz cz |
---|
953 | $(X)-$(X) -> a-a a-b a-c b-a b-b b-c c-a c-b c-c |
---|
954 | ] |
---|
955 | |
---|
956 | The variable name and modifiers can themselves contain a variable reference, and this partakes of the product as well: |
---|
957 | |
---|
958 | [pre |
---|
959 | $(X) -> a b c |
---|
960 | $(Y) -> 1 2 |
---|
961 | $(Z) -> X Y |
---|
962 | $($(Z)) -> a b c 1 2 |
---|
963 | ] |
---|
964 | |
---|
965 | 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: |
---|
966 | |
---|
967 | [pre |
---|
968 | $(X) -> a "" |
---|
969 | $(Y) -> "" 1 |
---|
970 | $(Z) -> |
---|
971 | -$(X)$(Y)- -> -a- -a1- -- -1- |
---|
972 | -$(X)$(Z)- -> |
---|
973 | ] |
---|
974 | |
---|
975 | 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: |
---|
976 | |
---|
977 | [variablelist |
---|
978 | |
---|
979 | [[[^\[['n]\]]] [Select element number ['n] (starting at 1). If the variable |
---|
980 | contains fewer than ['n] elements, the result is a zero-element list. ['n] |
---|
981 | can be negative in which case the element number ['n] from the last leftward |
---|
982 | is returned.]] |
---|
983 | |
---|
984 | [[[^\[['n]-['m]\]]] |
---|
985 | [Select elements number ['n] through ['m]. ['n] and ['m] can be negative in which case they refer to elements counting from the last leftward.]] |
---|
986 | |
---|
987 | [[[^\[['n]-\]]] |
---|
988 | [Select elements number ['n] through the last. ['n] can be negative in which case it refers to the element counting from the last leftward.]] |
---|
989 | |
---|
990 | [[[^:B]] |
---|
991 | [Select filename base.]] |
---|
992 | |
---|
993 | [[[^:S]] |
---|
994 | [Select (last) filename suffix.]] |
---|
995 | |
---|
996 | [[[^:M]] |
---|
997 | [Select archive member name.]] |
---|
998 | |
---|
999 | [[[^:D]] |
---|
1000 | [Select directory path.]] |
---|
1001 | |
---|
1002 | [[[^:P]] |
---|
1003 | [Select parent directory.]] |
---|
1004 | |
---|
1005 | [[[^:G]] |
---|
1006 | [Select grist.]] |
---|
1007 | |
---|
1008 | [[[^:U]] |
---|
1009 | [Replace lowercase characters with uppercase.]] |
---|
1010 | |
---|
1011 | [[[^:L]] |
---|
1012 | [Replace uppercase characters with lowercase.]] |
---|
1013 | |
---|
1014 | [[[^:W]] |
---|
1015 | [When invoking Windows-based tools from [@http://www.cygwin.com/ Cygwin] |
---|
1016 | it can be important to pass them true windows-style paths. The =:W= |
---|
1017 | modifier, *under Cygwin only*, turns a cygwin path into a Win32 path using |
---|
1018 | the [@http://www.cygwin.com/cygwin-api/func-cygwin-conv-to-win32-path.html |
---|
1019 | =cygwin_conv_to_win32_path=] function. On other platforms, the string is |
---|
1020 | unchanged. For example |
---|
1021 | `` |
---|
1022 | x = "/cygdrive/c/Program Files/Borland" ; ECHO $(x:W) ; |
---|
1023 | `` |
---|
1024 | prints [^"C:\\Program Files\\Borland"] on Cygwin |
---|
1025 | ]] |
---|
1026 | |
---|
1027 | [[[^:['chars]]] |
---|
1028 | [Select the components listed in ['chars].]] |
---|
1029 | |
---|
1030 | [[[^:G=['grist]]] |
---|
1031 | [Replace grist with ['grist].]] |
---|
1032 | |
---|
1033 | [[[^:D=['path]]] |
---|
1034 | [Replace directory with ['path].]] |
---|
1035 | |
---|
1036 | [[[^:B=['base]]] |
---|
1037 | [Replace the base part of file name with ['base].]] |
---|
1038 | |
---|
1039 | [[[^:S=['suf]]] |
---|
1040 | [Replace the suffix of file name with ['suf].]] |
---|
1041 | |
---|
1042 | [[[^:M=['mem]]] |
---|
1043 | [Replace the archive member name with ['mem].]] |
---|
1044 | |
---|
1045 | [[[^:R=['root]]] |
---|
1046 | [Prepend ['root] to the whole file name, if not already rooted.]] |
---|
1047 | |
---|
1048 | [[[^:E=['value]]] |
---|
1049 | [Assign ['value] to the variable if it is unset.]] |
---|
1050 | |
---|
1051 | [[[^:J=['joinval]]] |
---|
1052 | [Concatentate list elements into single element, separated by ['joinval]'.]] |
---|
1053 | |
---|
1054 | ] |
---|
1055 | |
---|
1056 | On VMS, [^$(var:P)] is the parent directory of [^$(var:D)]. |
---|
1057 | |
---|
1058 | [endsect] |
---|
1059 | |
---|
1060 | [section Local For Loop Variables] |
---|
1061 | |
---|
1062 | Boost Jam allows you to declare a local for loop control variable right in the loop: |
---|
1063 | |
---|
1064 | [pre |
---|
1065 | x = 1 2 3 ; |
---|
1066 | y = 4 5 6 ; |
---|
1067 | for *local* y in $(x) |
---|
1068 | { |
---|
1069 | ECHO $(y) ; # prints "1", "2", or "3" |
---|
1070 | } |
---|
1071 | ECHO $(y) ; # prints "4 5 6" |
---|
1072 | ] |
---|
1073 | |
---|
1074 | [endsect] |
---|
1075 | |
---|
1076 | [section:builtins Built-in Variables] |
---|
1077 | |
---|
1078 | This section discusses variables that have special meaning to =bjam=. |
---|
1079 | |
---|
1080 | [section:search SEARCH and LOCATE] |
---|
1081 | |
---|
1082 | These two variables control the binding of file target names to locations in |
---|
1083 | the file system. Generally, =$(SEARCH)= is used to find existing sources |
---|
1084 | while =$(LOCATE)= is used to fix the location for built targets. |
---|
1085 | |
---|
1086 | 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: |
---|
1087 | |
---|
1088 | * If =$(LOCATE)= is set then the target is bound relative to the first directory in =$(LOCATE)=. Only the first element is used for binding. |
---|
1089 | * If =$(SEARCH)= is set then the target is bound to the first directory in =$(SEARCH)= where the target file already exists. |
---|
1090 | * If the =$(SEARCH)= search fails, the target is bound relative to the current directory anyhow. |
---|
1091 | |
---|
1092 | Both =$(SEARCH)= and =$(LOCATE)= should be set target-specific and not globally. If they were set globally, =bjam= 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. |
---|
1093 | |
---|
1094 | [endsect] |
---|
1095 | |
---|
1096 | [section:hdrscan HDRSCAN and HDRRULE] |
---|
1097 | |
---|
1098 | These two variables control header file scanning. =$(HDRSCAN)= is an |
---|
1099 | =egrep(1)= pattern, with ()'s surrounding the file name, used to find file |
---|
1100 | inclusion statements in source files. =Jambase= uses =$(HDRPATTERN)= as the |
---|
1101 | pattern for =$(HDRSCAN)=. =$(HDRRULE)= is the name of a rule to invoke with |
---|
1102 | the results of the scan: the scanned file is the target, the found files are |
---|
1103 | the sources. This is the only place where =bjam= invokes a rule through a |
---|
1104 | variable setting. |
---|
1105 | |
---|
1106 | 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. |
---|
1107 | |
---|
1108 | 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, =bjam= won't care. |
---|
1109 | |
---|
1110 | 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). |
---|
1111 | |
---|
1112 | [endsect] |
---|
1113 | |
---|
1114 | [section Semaphores] |
---|
1115 | |
---|
1116 | It is sometimes desirable to disallow parallel execution of some actions. For example: |
---|
1117 | |
---|
1118 | * Old versions of yacc use files with fixed names. So, running two yacc actions is dangerous. |
---|
1119 | * One might want to perform parallel compiling, but not do parallel linking, because linking is i/o bound and only gets slower. |
---|
1120 | |
---|
1121 | Craig McPeeters has extended Perforce Jam to solve such problems, and that extension was integrated in Boost.Jam. |
---|
1122 | |
---|
1123 | 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. |
---|
1124 | |
---|
1125 | 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. |
---|
1126 | |
---|
1127 | [endsect] |
---|
1128 | |
---|
1129 | [section Platform Identifier] |
---|
1130 | |
---|
1131 | A number of Jam built-in variables can be used to identify runtime platform: |
---|
1132 | |
---|
1133 | [variablelist |
---|
1134 | [[=OS=] [OS identifier string]] |
---|
1135 | [[=OSPLAT=] [Underlying architecture, when applicable]] |
---|
1136 | [[=MAC=] [true on MAC platform]] |
---|
1137 | [[=NT=] [true on NT platform]] |
---|
1138 | [[=OS2=] [true on OS2 platform]] |
---|
1139 | [[=UNIX=] [true on Unix platforms]] |
---|
1140 | [[=VMS=] [true on VMS platform]] |
---|
1141 | ] |
---|
1142 | |
---|
1143 | [endsect] |
---|
1144 | |
---|
1145 | [section Jam Version] |
---|
1146 | |
---|
1147 | [variablelist |
---|
1148 | [[=JAMDATE=] [Time and date at =bjam= start-up.]] |
---|
1149 | [[=JAMUNAME=] [Ouput of uname(1) command (Unix only)]] |
---|
1150 | [[=JAMVERSION=] [=bjam= version, currently ":version:"]] |
---|
1151 | [[=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=.]] |
---|
1152 | ] |
---|
1153 | |
---|
1154 | [endsect] |
---|
1155 | |
---|
1156 | [section JAMSHELL] |
---|
1157 | |
---|
1158 | When =bjam= 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: |
---|
1159 | |
---|
1160 | [pre |
---|
1161 | JAMSHELL = /bin/sh -c % ; |
---|
1162 | ] |
---|
1163 | |
---|
1164 | The =%= is replaced with the text of the action block. |
---|
1165 | |
---|
1166 | =BJam= 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. |
---|
1167 | |
---|
1168 | Just as =bjam= 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: |
---|
1169 | |
---|
1170 | [pre |
---|
1171 | #!/bin/sh |
---|
1172 | |
---|
1173 | # This sample JAMSHELL uses the SunOS on(1) command to execute a |
---|
1174 | # command string with an identical environment on another host. |
---|
1175 | |
---|
1176 | # Set JAMSHELL = jamshell ! % |
---|
1177 | # |
---|
1178 | # where jamshell is the name of this shell file. |
---|
1179 | # |
---|
1180 | # This version handles up to -j6; after that they get executed |
---|
1181 | # locally. |
---|
1182 | |
---|
1183 | case $1 in |
---|
1184 | 1|4) on winken sh -c "$2";; |
---|
1185 | 2|5) on blinken sh -c "$2";; |
---|
1186 | 3|6) on nod sh -c "$2";; |
---|
1187 | *) eval "$2";; |
---|
1188 | esac |
---|
1189 | ] |
---|
1190 | |
---|
1191 | [endsect] |
---|
1192 | |
---|
1193 | [endsect] |
---|
1194 | |
---|
1195 | [endsect] |
---|
1196 | |
---|
1197 | [section Modules] |
---|
1198 | |
---|
1199 | 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. |
---|
1200 | |
---|
1201 | [section Declaration] |
---|
1202 | |
---|
1203 | [pre |
---|
1204 | module /expression/ { ... } |
---|
1205 | ] |
---|
1206 | |
---|
1207 | 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: |
---|
1208 | |
---|
1209 | [pre |
---|
1210 | *module my_module* |
---|
1211 | *{* |
---|
1212 | rule salute ( x ) { ECHO $(x), world ; } |
---|
1213 | rule greet ( ) { salute hello ; } |
---|
1214 | greet ; |
---|
1215 | *}* |
---|
1216 | *my_module.salute* goodbye ; |
---|
1217 | ] |
---|
1218 | |
---|
1219 | 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: |
---|
1220 | |
---|
1221 | [pre |
---|
1222 | module your_module |
---|
1223 | { |
---|
1224 | rule bedtime ( ) { *my_module.salute* goodnight ; } |
---|
1225 | } |
---|
1226 | ] |
---|
1227 | |
---|
1228 | [endsect] |
---|
1229 | |
---|
1230 | [section Variable Scope] |
---|
1231 | |
---|
1232 | 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: |
---|
1233 | |
---|
1234 | [pre |
---|
1235 | module A |
---|
1236 | { |
---|
1237 | x = 1 ; |
---|
1238 | rule f ( ) |
---|
1239 | { |
---|
1240 | local y = 999 ; # becomes visible again when B.f calls A.g |
---|
1241 | B.f ; |
---|
1242 | } |
---|
1243 | rule g ( ) |
---|
1244 | { |
---|
1245 | ECHO $(y) ; # prints "999" |
---|
1246 | } |
---|
1247 | } |
---|
1248 | module B |
---|
1249 | { |
---|
1250 | y = 2 ; |
---|
1251 | rule f ( ) |
---|
1252 | { |
---|
1253 | ECHO $(y) ; # always prints "2" |
---|
1254 | A.g ; |
---|
1255 | } |
---|
1256 | } |
---|
1257 | ] |
---|
1258 | |
---|
1259 | The only way to access another module's variables is by entering that module: |
---|
1260 | |
---|
1261 | [pre |
---|
1262 | rule peek ( module-name ? : variables + ) |
---|
1263 | { |
---|
1264 | module $(module-name) |
---|
1265 | { |
---|
1266 | return $($(>)) ; |
---|
1267 | } |
---|
1268 | } |
---|
1269 | ] |
---|
1270 | |
---|
1271 | 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. |
---|
1272 | |
---|
1273 | [endsect] |
---|
1274 | |
---|
1275 | [section Local Rules] |
---|
1276 | |
---|
1277 | [pre |
---|
1278 | local rule /rulename/... |
---|
1279 | ] |
---|
1280 | |
---|
1281 | 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: |
---|
1282 | |
---|
1283 | [pre |
---|
1284 | \[ RULENAMES /module-name/ \] |
---|
1285 | ] |
---|
1286 | |
---|
1287 | [endsect] |
---|
1288 | |
---|
1289 | [section The =RULENAMES= Rule] |
---|
1290 | |
---|
1291 | [pre |
---|
1292 | rule RULENAMES ( /module/ ? ) |
---|
1293 | ] |
---|
1294 | |
---|
1295 | 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. |
---|
1296 | |
---|
1297 | [endsect] |
---|
1298 | |
---|
1299 | [section The =VARNAMES= Rule] |
---|
1300 | |
---|
1301 | [pre |
---|
1302 | rule VARNAMES ( /module/ ? ) |
---|
1303 | ] |
---|
1304 | |
---|
1305 | 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. |
---|
1306 | |
---|
1307 | [note This includes any local variables in rules from the call stack which have not returned at the time of the =VARNAMES= invocation.] |
---|
1308 | |
---|
1309 | [endsect] |
---|
1310 | |
---|
1311 | [section The =IMPORT= Rule] |
---|
1312 | |
---|
1313 | =IMPORT= allows rule name aliasing across modules: |
---|
1314 | |
---|
1315 | [pre |
---|
1316 | rule IMPORT ( /source_module/ ? : /source_rules/ * |
---|
1317 | : /target_module/ ? : /target_rules/ * ) |
---|
1318 | ] |
---|
1319 | |
---|
1320 | 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, |
---|
1321 | |
---|
1322 | [pre |
---|
1323 | # import m1.rule1 into m2 as local rule m1-rule1. |
---|
1324 | IMPORT m1 : rule1 : m2 : m1-rule1 ; |
---|
1325 | # import all non-local rules from m1 into m2 |
---|
1326 | IMPORT m1 : \[ RULENAMES m1 \] : m2 : \[ RULENAMES m1 \] ; |
---|
1327 | ] |
---|
1328 | |
---|
1329 | [endsect] |
---|
1330 | |
---|
1331 | [section The =EXPORT= Rule] |
---|
1332 | |
---|
1333 | =EXPORT= allows rule name aliasing across modules: |
---|
1334 | |
---|
1335 | [pre |
---|
1336 | rule EXPORT ( /module/ ? : /rules/ * ) |
---|
1337 | ] |
---|
1338 | |
---|
1339 | 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, |
---|
1340 | |
---|
1341 | [pre |
---|
1342 | module X { |
---|
1343 | local rule r { ECHO X.r ; } |
---|
1344 | } |
---|
1345 | IMPORT X : r : : r ; # error - r is local in X |
---|
1346 | EXPORT X : r ; |
---|
1347 | IMPORT X : r : : r ; # OK. |
---|
1348 | ] |
---|
1349 | |
---|
1350 | [endsect] |
---|
1351 | |
---|
1352 | [section The =CALLER_MODULE= Rule] |
---|
1353 | |
---|
1354 | [pre |
---|
1355 | rule CALLER_MODULE ( /levels/ ? ) |
---|
1356 | ] |
---|
1357 | |
---|
1358 | =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}": |
---|
1359 | |
---|
1360 | [pre |
---|
1361 | module X { |
---|
1362 | rule get-caller { return \[ CALLER_MODULE \] ; } |
---|
1363 | rule get-caller's-caller { return \[ CALLER_MODULE 1 \] ; } |
---|
1364 | rule call-Y { return Y.call-X2 ; } |
---|
1365 | } |
---|
1366 | module Y { |
---|
1367 | rule call-X { return X.get-caller ; } |
---|
1368 | rule call-X2 { return X.get-caller's-caller ; } |
---|
1369 | } |
---|
1370 | callers = \[ X.get-caller \] \[ Y.call-X \] \[ X.call-Y \] ; |
---|
1371 | ECHO {$(callers)} ; |
---|
1372 | ] |
---|
1373 | |
---|
1374 | [endsect] |
---|
1375 | |
---|
1376 | [section The =DELETE_MODULE= Rule] |
---|
1377 | |
---|
1378 | [pre |
---|
1379 | rule DELETE_MODULE ( /module/ ? ) |
---|
1380 | ] |
---|
1381 | |
---|
1382 | =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. |
---|
1383 | |
---|
1384 | [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.] |
---|
1385 | |
---|
1386 | [endsect] |
---|
1387 | |
---|
1388 | [endsect] |
---|
1389 | |
---|
1390 | [endsect] |
---|
1391 | |
---|
1392 | [section Miscellaneous] |
---|
1393 | |
---|
1394 | [section Diagnostics] |
---|
1395 | |
---|
1396 | In addition to generic error messages, =bjam= may emit one of the following: |
---|
1397 | |
---|
1398 | [pre warning: unknown rule X] |
---|
1399 | |
---|
1400 | A rule was invoked that has not been defined with an "=actions=" or "=rule=" statement. |
---|
1401 | |
---|
1402 | [pre using N temp target(s)] |
---|
1403 | |
---|
1404 | Targets marked as being temporary (but nonetheless present) have been found. |
---|
1405 | |
---|
1406 | [pre updating N target(s)] |
---|
1407 | |
---|
1408 | Targets are out-of-date and will be updated. |
---|
1409 | |
---|
1410 | [pre can't find N target(s)] |
---|
1411 | |
---|
1412 | Source files can't be found and there are no actions to create them. |
---|
1413 | |
---|
1414 | [pre can't make N target(s)] |
---|
1415 | |
---|
1416 | Due to sources not being found, other targets cannot be made. |
---|
1417 | |
---|
1418 | [pre warning: X depends on itself] |
---|
1419 | |
---|
1420 | A target depends on itself either directly or through its sources. |
---|
1421 | |
---|
1422 | [pre don't know how to make X] |
---|
1423 | |
---|
1424 | A target is not present and no actions have been defined to create it. |
---|
1425 | |
---|
1426 | [pre X skipped for lack of Y] |
---|
1427 | |
---|
1428 | A source failed to build, and thus a target cannot be built. |
---|
1429 | |
---|
1430 | [pre warning: using independent target X] |
---|
1431 | |
---|
1432 | A target that is not a dependency of any other target is being referenced with =$(<)= or =$(>)=. |
---|
1433 | |
---|
1434 | [pre X removed] |
---|
1435 | |
---|
1436 | =BJam= removed a partially built target after being interrupted. |
---|
1437 | |
---|
1438 | [endsect] |
---|
1439 | |
---|
1440 | [section Bugs, Limitations] |
---|
1441 | |
---|
1442 | The =-j= flag can cause =bjam= to get confused when single actions update more than one target at a time. =bjam= may proceed as if the targets were built even though they are still under construction. |
---|
1443 | |
---|
1444 | 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. |
---|
1445 | |
---|
1446 | With the =-j= flag, errors from failed commands can get staggeringly mixed up. |
---|
1447 | |
---|
1448 | A poorly set =$(JAMSHELL)= is likely to result in silent failure. |
---|
1449 | |
---|
1450 | [endsect] |
---|
1451 | |
---|
1452 | [section Fundamentals] |
---|
1453 | |
---|
1454 | 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. |
---|
1455 | |
---|
1456 | * Jam "=rules=" are actually simple procedural entities. Think of them as functions. Arguments are separated by colons. |
---|
1457 | |
---|
1458 | * 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. |
---|
1459 | |
---|
1460 | * 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/. |
---|
1461 | |
---|
1462 | * 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. |
---|
1463 | |
---|
1464 | * 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. |
---|
1465 | |
---|
1466 | * 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: |
---|
1467 | |
---|
1468 | * 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. |
---|
1469 | * Binding is controlled /entirely/ by the target-specific setting of the =SEARCH= and =LOCATE= variables, as described here. |
---|
1470 | * 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). |
---|
1471 | |
---|
1472 | * 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. |
---|
1473 | |
---|
1474 | * 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". |
---|
1475 | |
---|
1476 | * "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: |
---|
1477 | |
---|
1478 | # 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. |
---|
1479 | # 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. |
---|
1480 | |
---|
1481 | * 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. |
---|
1482 | |
---|
1483 | * 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. |
---|
1484 | |
---|
1485 | * A variable whose value is an empty list or which consists entirely of empty |
---|
1486 | strings has a negative logical value. Thus, for example, code like the |
---|
1487 | following allows a sensible non-empty default which can easily be overridden |
---|
1488 | by the user: |
---|
1489 | `` |
---|
1490 | MESSAGE ?\= starting jam... ; |
---|
1491 | if $(MESSAGE) { ECHO The message is: $(MESSAGE) ; } |
---|
1492 | `` |
---|
1493 | 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. |
---|
1494 | |
---|
1495 | * 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: |
---|
1496 | |
---|
1497 | # =-xvalue=, and |
---|
1498 | # =-x value=. |
---|
1499 | |
---|
1500 | [endsect] |
---|
1501 | |
---|
1502 | [endsect] |
---|