]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/doc/src/overview.xml
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / tools / build / doc / src / overview.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE chapter PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
3 "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
4
5 <chapter id="bbv2.overview">
6 <title>Overview</title>
7
8 <para>
9 This section will provide the information necessary to create your own
10 projects using Boost.Build. The information provided here is relatively
11 high-level, and <xref linkend="bbv2.reference"/> as well as the on-line
12 help system must be used to obtain low-level documentation (see <xref
13 linkend="bbv2.reference.init.options.help"/>).
14 </para>
15
16 <para>
17 Boost.Build has two parts&mdash;a build engine
18 with its own interpreted language, and Boost.Build itself, implemented in
19 that language. The chain of events when you type
20 <command>b2</command> on the command line is as follows:
21 <orderedlist>
22 <listitem>
23 <para>
24 The Boost.Build executable tries to find Boost.Build modules and
25 loads the top-level module. The exact process is described in <xref linkend=
26 "bbv2.reference.init"/>
27 </para>
28 </listitem>
29 <listitem>
30 <para>
31 The top-level module loads user-defined configuration files,
32 <filename>user-config.jam</filename> and
33 <filename>site-config.jam</filename>, which define available toolsets.
34 </para>
35 </listitem>
36 <listitem>
37 <para>
38 The Jamfile in the current directory is read. That in turn might
39 cause reading of further Jamfiles. As a result, a tree of projects
40 is created, with targets inside projects.
41 </para>
42 </listitem>
43 <listitem>
44 <para>
45 Finally, using the build request specified on the command line,
46 Boost.Build decides which targets should be built and how. That
47 information is passed back to Boost.Jam, which takes care of
48 actually running the scheduled build action commands.
49 </para>
50 </listitem>
51 </orderedlist>
52 </para>
53
54 <para>
55 So, to be able to successfully use Boost.Build, you need to know only four
56 things:
57 <itemizedlist>
58 <listitem>
59 <para>
60 <link linkend="bbv2.overview.configuration">How to configure
61 Boost.Build</link>
62 </para>
63 </listitem>
64 <listitem>
65 <para>
66 <link linkend="bbv2.overview.targets">How to declare targets in
67 Jamfiles</link>
68 </para>
69 </listitem>
70 <listitem>
71 <para>
72 <link linkend="bbv2.overview.build_process">How the build process
73 works</link>
74 </para>
75 </listitem>
76 <listitem>
77 <para>
78 Some Basics about the Boost.Jam language. See <xref linkend=
79 "bbv2.overview.jam_language"/>.
80 </para>
81 </listitem>
82 </itemizedlist>
83 </para>
84
85 <section id="bbv2.overview.concepts">
86 <title>Concepts</title>
87
88 <para>Boost.Build has a few unique concepts that are introduced in this section. The best
89 way to explain the concepts is by comparison with more classical build tools.</para>
90
91 <para>
92 When using any flavour of make, you directly specify <firstterm>targets</firstterm>
93 and commands that are used to create them from other target. The below example
94 creates <filename>a.o</filename> from <filename>a.c</filename> using a hardcoded
95 compiler invocation command.
96 <programlisting>
97 a.o: a.c
98 g++ -o a.o -g a.c
99 </programlisting>
100 This is a rather low-level description mechanism and it's hard to adjust commands, options,
101 and sets of created targets depending on the compiler and operating system used.
102 </para>
103
104 <para>
105 To improve portability, most modern build system provide a set of higher-level
106 functions that can be used in build description files. Consider this example:
107 <programlisting>
108 add_program ("a", "a.c")
109 </programlisting>
110 This is a function call that creates the targets necessary to create an executable file
111 from the source file <filename>a.c</filename>. Depending on configured properties,
112 different command lines may be used. However, <code>add_program</code> is higher-level,
113 but rather thin level. All targets are created immediately when the build description
114 is parsed, which makes it impossible to perform multi-variant builds. Often, change
115 in any build property requires a complete reconfiguration of the build tree.
116 </para>
117
118 <para>
119 In order to support true multivariant builds, Boost.Build introduces the concept of a
120 <indexterm> <primary>metatarget</primary> <secondary>definition</secondary></indexterm>
121 <indexterm> <primary>main target</primary> <see>metataget</see> </indexterm>
122 <firstterm>metatarget</firstterm>&mdash;an object that is created when the build description
123 is parsed and can be called later with specific build properties to generate
124 actual targets.
125 </para>
126
127 <para>
128 Consider an example:
129 <programlisting>
130 exe a : a.cpp ;
131 </programlisting>
132 When this declaration is parsed, Boost.Build creates a metatarget, but does not
133 yet decide what files must be created, or what commands must be used. After
134 all build files are parsed, Boost.Build considers the properties requested on the
135 command line. Supposed you have invoked Boost.Build with:
136 <screen>
137 b2 toolset=gcc toolset=msvc
138 </screen>
139 In that case, the metatarget will be called twice, once with <code>toolset=gcc</code>
140 and once with <code>toolset=msvc</code>. Both invocations will produce concrete
141 targets, that will have different extensions and use different command lines.
142 </para>
143
144 <para>
145 Another key concept is
146 <indexterm><primary>property</primary><secondary>definition</secondary></indexterm>
147 <firstterm>build property</firstterm>. A build property is a variable
148 that affects the build process. It can be specified on the command line, and is
149 passed when calling a metatarget. While all build tools have a similar mechanism,
150 Boost.Build differs by requiring that all build properties are declared in advance,
151 and providing a large set of properties with portable semantics.
152 </para>
153
154 <para>
155 The final concept is <indexterm><primary>property</primary><secondary>propagation</secondary></indexterm>
156 <firstterm>property propagation</firstterm>. Boost.Build does not require that every
157 metatarget is called with the same properties. Instead, the
158 "top-level" metatargets are called with the properties specified on the command line.
159 Each metatarget can elect to augment or override some properties (in particular,
160 using the requirements mechanism, see <xref linkend="bbv2.overview.targets.requirements"/>).
161 Then, the dependency metatargets are called with the modified properties and produce
162 concrete targets that are then used in the build process. Of course, dependency metatargets
163 maybe in turn modify build properties and have dependencies of their own.
164 </para>
165
166 <para>For a more in-depth treatment of the requirements and concepts, you may refer
167 to <ulink url="http://syrcose.ispras.ru/2009/files/04_paper.pdf">SYRCoSE 2009 Boost.Build article</ulink>.
168 </para>
169
170 </section>
171
172 <section id="bbv2.overview.jam_language">
173 <title>Boost.Jam Language</title>
174
175 <para>
176 This section will describe the basics of the Boost.Jam language&#x2014;just
177 enough for writing Jamfiles. For more information, please see the
178 <link linkend="bbv2.jam">Boost.Jam</link> documentation.
179 </para>
180
181 <para>
182 <link linkend="bbv2.jam">Boost.Jam</link> has an interpreted, procedural
183 language. On the lowest level, a <link linkend="bbv2.jam">Boost.Jam
184 </link> program consists of variables and <indexterm><primary>rule
185 </primary></indexterm> <firstterm>rules</firstterm> (the Jam term for
186 functions). They are grouped into modules&#x2014;there is one global
187 module and a number of named modules. Besides that, a <link linkend=
188 "bbv2.jam">Boost.Jam</link> program contains classes and class
189 instances.
190 </para>
191
192 <para>
193 Syntantically, a <link linkend="bbv2.jam">Boost.Jam</link> program
194 consists of two kind of elements&#x2014;keywords (which have a special
195 meaning to <link linkend="bbv2.jam">Boost.Jam</link>) and literals.
196 Consider this code:
197 <programlisting>
198 a = b ;
199 </programlisting>
200 which assigns the value <literal>b</literal> to the variable <literal>a
201 </literal>. Here, <literal>=</literal> and <literal>;</literal> are
202 keywords, while <literal>a</literal> and <literal>b</literal> are
203 literals.
204 <warning>
205 <para>
206 All syntax elements, even keywords, must be separated by spaces. For
207 example, omitting the space character before <literal>;</literal>
208 will lead to a syntax error.
209 </para>
210 </warning>
211 If you want to use a literal value that is the same as some keyword, the
212 value can be quoted:
213 <programlisting>
214 a = "=" ;
215 </programlisting>
216 </para>
217
218 <para>
219 All variables in <link linkend="bbv2.jam">Boost.Jam</link> have the same
220 type&#x2014;list of strings. To define a variable one assigns a value to
221 it, like in the previous example. An undefined variable is the same as a
222 variable with an empty value. Variables can be accessed using the
223 <code>$(<replaceable>variable</replaceable>)</code> syntax. For example:
224 <programlisting>
225 a = $(b) $(c) ;
226 </programlisting>
227 </para>
228
229 <para>
230 Rules are defined by specifying the rule name, the parameter names, and
231 the allowed value list size for each parameter.
232 <programlisting>
233 rule <replaceable>example</replaceable>
234 (
235 <replaceable>parameter1</replaceable> :
236 <replaceable>parameter2 ?</replaceable> :
237 <replaceable>parameter3 +</replaceable> :
238 <replaceable>parameter4 *</replaceable>
239 )
240 {
241 # rule body
242 }
243 </programlisting>
244 When this rule is called, the list passed as the first argument must
245 have exactly one value. The list passed as the second argument can
246 either have one value of be empty. The two remaining arguments can be
247 arbitrarily long, but the third argument may not be empty.
248 </para>
249
250 <para>
251 The overview of <link linkend="bbv2.jam">Boost.Jam</link> language
252 statements is given below:
253 <programlisting>
254 helper 1 : 2 : 3 ;
255 x = [ helper 1 : 2 : 3 ] ;
256 </programlisting>
257 This code calls the named rule with the specified arguments. When the
258 result of the call must be used inside some expression, you need to add
259 brackets around the call, like shown on the second line.
260 <programlisting>
261 if cond { statements } [ else { statements } ]
262 </programlisting>
263 This is a regular if-statement. The condition is composed of:
264 <itemizedlist>
265 <listitem>
266 <para>
267 Literals (true if at least one string is not empty)
268 </para>
269 </listitem>
270 <listitem>
271 <para>
272 Comparisons: <code>a <replaceable>operator</replaceable> b</code>
273 where <replaceable>operator</replaceable> is one of
274 <code>=</code>, <code>!=</code>, <code>&lt;</code>,
275 <code>&gt;</code>, <code>&lt;=</code> or <code>&gt;=</code>. The
276 comparison is done pairwise between each string in the left and
277 the right arguments.
278 </para>
279 </listitem>
280 <listitem>
281 <para>
282 Logical operations: <code>! a</code>, <code>a &amp;&amp; b</code>,
283 <code>a || b</code>
284 </para>
285 </listitem>
286 <listitem>
287 <para>
288 Grouping: <code>( cond )</code>
289 </para>
290 </listitem>
291 </itemizedlist>
292 <programlisting>
293 for var in list { statements }
294 </programlisting>
295 Executes statements for each element in list, setting the variable
296 <varname>var</varname> to the element value.
297 <programlisting>
298 while cond { statements }
299 </programlisting>
300 Repeatedly execute statements while cond remains true upon entry.
301 <programlisting>
302 return values ;
303 </programlisting>
304 This statement should be used only inside a rule and assigns
305 <code>values</code> to the return value of the rule.
306 <warning>
307 <para>
308 The <code>return</code> statement does not exit the rule. For
309 example:
310 <programlisting>
311 rule test ( )
312 {
313 if 1 = 1
314 {
315 return "reasonable" ;
316 }
317 return "strange" ;
318 }
319 </programlisting>
320 will return <literal>strange</literal>, not
321 <literal>reasonable</literal>.
322 </para>
323 </warning>
324 <programlisting>
325 import <replaceable>module</replaceable> ;
326 import <replaceable>module</replaceable> : <replaceable>rule</replaceable> ;
327 </programlisting>
328 The first form imports the specified module. All rules from that
329 module are made available using the qualified name: <code><replaceable>
330 module</replaceable>.<replaceable>rule</replaceable></code>. The second
331 form imports the specified rules only, and they can be called using
332 unqualified names.
333 </para>
334
335 <para id="bbv2.overview.jam_language.actions">
336 Sometimes, you need to specify the actual command lines to be used
337 when creating targets. In the jam language, you use named actions to do
338 this. For example:
339 <programlisting>
340 actions create-file-from-another
341 {
342 create-file-from-another $(&lt;) $(&gt;)
343 }
344 </programlisting>
345 This specifies a named action called <literal>
346 create-file-from-another</literal>. The text inside braces is the
347 command to invoke. The <literal>$(&lt;)</literal> variable will be
348 expanded to a list of generated files, and the <literal>$(&gt;)
349 </literal> variable will be expanded to a list of source files.
350 </para>
351
352 <para>
353 To adjust the command line flexibly, you can define a rule with the same
354 name as the action and taking three parameters&mdash;targets, sources and
355 properties. For example:
356 <programlisting>
357 rule create-file-from-another ( targets * : sources * : properties * )
358 {
359 if &lt;variant&gt;debug in $(properties)
360 {
361 OPTIONS on $(targets) = --debug ;
362 }
363 }
364 actions create-file-from-another
365 {
366 create-file-from-another $(OPTIONS) $(&lt;) $(&gt;)
367 }
368 </programlisting>
369 In this example, the rule checks if a certain build property is specified.
370 If so, it sets the variable <varname>OPTIONS</varname> that is then used
371 inside the action. Note that the variables set "on a target" will be
372 visible only inside actions building that target, not globally. Were
373 they set globally, using variable named <varname>OPTIONS</varname> in
374 two unrelated actions would be impossible.
375 </para>
376
377 <para>
378 More details can be found in the Jam reference, <xref
379 linkend="jam.language.rules"/>.
380 </para>
381 </section>
382
383 <section id="bbv2.overview.configuration">
384 <title>Configuration</title>
385
386 <para>
387 On startup, Boost.Build searches and reads two configuration files:
388 <filename>site-config.jam</filename> and <filename>user-config.jam</filename>.
389 The first one is usually installed and maintained by a system administrator, and
390 the second is for the user to modify. You can edit the one in the top-level
391 directory of your Boost.Build installation or create a copy in your home
392 directory and edit the copy. The following table explains where both files
393 are searched.
394 </para>
395
396 <table id="bbv2.reference.init.config">
397 <title>Search paths for configuration files</title>
398
399 <tgroup cols="3">
400 <thead>
401
402 <row>
403 <entry></entry>
404
405 <entry>site-config.jam</entry>
406
407 <entry>user-config.jam</entry>
408 </row>
409
410 </thead>
411 <tbody>
412
413 <row>
414 <entry>Linux</entry>
415
416 <entry>
417 <simpara><code>/etc</code></simpara>
418 <simpara><code>$HOME</code></simpara>
419 <simpara><code>$BOOST_BUILD_PATH</code></simpara>
420 </entry>
421
422 <entry>
423 <simpara><code>$HOME</code></simpara>
424 <simpara><code>$BOOST_BUILD_PATH</code></simpara>
425 </entry>
426 </row>
427
428 <row>
429 <entry>Windows</entry>
430
431 <entry>
432 <simpara><code>%SystemRoot%</code></simpara>
433 <simpara><code>%HOMEDRIVE%%HOMEPATH%</code></simpara>
434 <simpara><code>%HOME%</code></simpara>
435 <simpara><code>%BOOST_BUILD_PATH%</code></simpara>
436 </entry>
437
438 <entry>
439 <simpara><code>%HOMEDRIVE%%HOMEPATH%</code></simpara>
440 <simpara><code>%HOME%</code></simpara>
441 <simpara><code>%BOOST_BUILD_PATH%</code></simpara>
442 </entry>
443 </row>
444 </tbody>
445 </tgroup>
446 </table>
447
448 <tip>
449 <para>
450 You can use the <command>--debug-configuration</command> option to
451 find which configuration files are actually loaded.
452 </para>
453 </tip>
454
455 <para>
456 Usually, <filename>user-config.jam</filename> just defines the available compilers
457 and other tools (see <xref linkend="bbv2.recipies.site-config"/> for more advanced
458 usage). A tool is configured using the following syntax:
459 </para>
460
461 <programlisting>
462 using <replaceable>tool-name</replaceable> : ... ;
463 </programlisting>
464 <para>
465 The <code language="jam">using</code> rule is given the name of tool, and
466 will make that tool available to Boost.Build. For example,
467 <programlisting>
468 using gcc ;
469 </programlisting> will make the <ulink url="http://gcc.gnu.org">GCC</ulink> compiler available.
470 </para>
471
472 <para>
473 All the supported tools are documented in <xref linkend="bbv2.reference.tools"/>,
474 including the specific options they take. Some general notes that apply to most
475 C++ compilers are below.
476 </para>
477
478 <para>
479 For all the C++ compiler toolsets that Boost.Build supports
480 out-of-the-box, the list of parameters to
481 <code language="jam">using</code> is the same: <parameter
482 class="function">toolset-name</parameter>, <parameter
483 class="function">version</parameter>, <parameter
484 class="function">invocation-command</parameter>, and <parameter
485 class="function">options</parameter>.
486 </para>
487
488 <para>If you have a single compiler, and the compiler executable
489 <itemizedlist>
490 <listitem><para>has its &#x201C;usual name&#x201D; and is in the
491 <envar>PATH</envar>, or</para></listitem>
492 <listitem><para>was installed in a standard &#x201C;installation
493 directory&#x201D;, or</para></listitem>
494 <listitem><para>can be found using a global system like the Windows
495 registry.</para></listitem>
496 </itemizedlist>
497 it can be configured by simply:</para>
498 <programlisting>
499 using <replaceable>tool-name</replaceable> ;
500 </programlisting>
501 <!-- TODO: mention auto-configuration? -->
502
503 <para>If the compiler is installed in a custom directory, you should provide the
504 command that invokes the compiler, for example:</para>
505 <programlisting>
506 using gcc : : g++-3.2 ;
507 using msvc : : "Z:/Programs/Microsoft Visual Studio/vc98/bin/cl" ;
508 </programlisting>
509 <para>
510 Some Boost.Build toolsets will use that path to take additional actions
511 required before invoking the compiler, such as calling vendor-supplied
512 scripts to set up its required environment variables. When the compiler
513 executables for C and C++ are different, the path to the C++ compiler
514 executable must be specified. The command can
515 be any command allowed by the operating system. For example:
516 <programlisting>
517 using msvc : : echo Compiling &#x26;&#x26; foo/bar/baz/cl ;
518 </programlisting>
519 will work.
520 </para>
521
522 <para>
523 To configure several versions of a toolset, simply invoke the
524 <code language="jam">using</code> rule multiple times:
525 <programlisting>
526 using gcc : 3.3 ;
527 using gcc : 3.4 : g++-3.4 ;
528 using gcc : 3.2 : g++-3.2 ;
529 </programlisting>
530 Note that in the first call to <code language="jam">using</code>, the
531 compiler found in the <envar>PATH</envar> will be used, and there is no
532 need to explicitly specify the command.
533 </para>
534
535 <!-- TODO: This is not actually relevant for gcc now, and we need to rethink this
536 <para>As shown above, both the <parameter
537 class="function">version</parameter> and <parameter
538 class="function">invocation-command</parameter> parameters are
539 optional, but there's an important restriction: if you configure
540 the same toolset more than once, you must pass the <parameter
541 class="function">version</parameter>
542 parameter every time. For example, the following is not allowed:
543 <programlisting>
544 using gcc ;
545 using gcc : 3.4 : g++-3.4 ;
546 </programlisting>
547 because the first <functionname>using</functionname> call does
548 not specify a <parameter class="function">version</parameter>.
549 </para> -->
550
551 <para>
552 Many of toolsets have an <parameter class="function">options</parameter>
553 parameter to fine-tune the configuration. All of
554 Boost.Build's standard compiler toolsets accept four options
555 <varname>cflags</varname>, <varname>cxxflags</varname>,
556 <varname>compileflags</varname> and <varname>linkflags</varname> as <parameter
557 class="function">options</parameter> specifying flags that will be
558 always passed to the corresponding tools. Values of the
559 <varname>cflags</varname> feature are passed directly to the C
560 compiler, values of the <varname>cxxflags</varname> feature are
561 passed directly to the C++ compiler, and values of the
562 <varname>compileflags</varname> feature are passed to both. For
563 example, to configure a <command>gcc</command> toolset so that it
564 always generates 64-bit code you could write:
565 <programlisting>
566 using gcc : 3.4 : : &lt;compileflags&gt;-m64 &lt;linkflags&gt;-m64 ;
567 </programlisting>
568 </para>
569
570 <warning>
571 <para>
572 Although the syntax used to specify toolset options is very similar
573 to syntax used to specify requirements in Jamfiles, the toolset options
574 are not the same as features. Don't try to specify a feature value
575 in toolset initialization.
576 </para>
577 </warning>
578
579 </section>
580
581 <section id="bbv2.overview.invocation">
582 <title>Invocation</title>
583
584 <para>To invoke Boost.Build, type <command>b2</command> on the command line. Three kinds
585 of command-line tokens are accepted, in any order:</para>
586 <variablelist>
587 <varlistentry>
588 <term>options</term>
589
590 <listitem><para>Options start with either one or two dashes. The standard options
591 are listed below, and each project may add additional options</para></listitem>
592 </varlistentry>
593
594 <varlistentry>
595 <term>properties</term>
596
597 <listitem><para>Properties specify details of what you want to build (e.g. debug
598 or release variant). Syntactically, all command line tokens with an equal sign in them
599 are considered to specify properties. In the simplest form, a property looks like
600 <command><replaceable>feature</replaceable>=<replaceable>value</replaceable></command>
601 </para></listitem>
602 </varlistentry>
603
604 <varlistentry>
605 <term>target</term>
606
607 <listitem><para>All tokens that are neither options nor properties specify
608 what targets to build. The available targets entirely depend on the project
609 you are building.</para></listitem>
610 </varlistentry>
611 </variablelist>
612
613 <section id="bbv2.overview.invocation.examples">
614 <title>Examples</title>
615
616 <para>To build all targets defined in the Jamfile in the current directory with the default properties, run:
617 <screen>
618 b2
619 </screen>
620 </para>
621
622 <para>To build specific targets, specify them on the command line:
623 <screen>
624 b2 lib1 subproject//lib2
625 </screen>
626 </para>
627
628 <para>To request a certain value for some property, add <literal>
629 <replaceable>property</replaceable>=<replaceable>value</replaceable></literal> to the command line:
630 <screen>
631 b2 toolset=gcc variant=debug optimization=space
632 </screen>
633 </para>
634 </section>
635
636 <section id="bbv2.overview.invocation.options">
637 <title>Options</title>
638
639 <para>Boost.Build recognizes the following command line options.</para>
640
641 <variablelist>
642
643 <varlistentry id="bbv2.reference.init.options.help">
644 <term><option>--help</option></term>
645 <listitem>
646 <para>Invokes the online help system. This prints general
647 information on how to use the help system with additional
648 --help* options.
649 </para>
650 </listitem>
651 </varlistentry>
652
653 <varlistentry>
654 <term><option>--clean</option></term>
655 <listitem>
656 <para>Cleans all targets in the current directory and
657 in any subprojects. Note that unlike the <literal>clean</literal>
658 target in make, you can use <literal>--clean</literal>
659 together with target names to clean specific targets.</para>
660 </listitem>
661 </varlistentry>
662
663 <varlistentry>
664 <term><option>--clean-all</option></term>
665 <listitem>
666 <para>Cleans all targets,
667 no matter where they are defined. In particular, it will clean targets
668 in parent Jamfiles, and targets defined under other project roots.
669 </para>
670 </listitem>
671 </varlistentry>
672
673 <varlistentry>
674 <term><option>--build-dir</option></term>
675 <listitem>
676 <para>Changes the build directories for all project roots being built. When
677 this option is specified, all Jamroot files must declare a project name.
678 The build directory for the project root will be computed by concatenating
679 the value of the <option>--build-dir</option> option, the project name
680 specified in Jamroot, and the build dir specified in Jamroot
681 (or <literal>bin</literal>, if none is specified).
682 </para>
683
684 <para>The option is primarily useful when building from read-only
685 media, when you can't modify Jamroot.
686 </para>
687 </listitem>
688 </varlistentry>
689
690 <varlistentry>
691 <term><option>--abbreviate-paths</option></term>
692 <listitem>
693 <para>Compresses target paths by abbreviating each component.
694 This option is useful to keep paths from becoming longer than
695 the filesystem supports. See also <xref linkend="bbv2.reference.buildprocess.targetpath"/>.
696 </para>
697 </listitem>
698 </varlistentry>
699
700 <varlistentry>
701 <term><option>--hash</option></term>
702 <listitem>
703 <para>Compresses target paths using an MD5 hash. This option is
704 useful to keep paths from becoming longer than the filesystem
705 supports. This option produces shorter paths than --abbreviate-paths
706 does, but at the cost of making them less understandable.
707 See also <xref linkend="bbv2.reference.buildprocess.targetpath"/>.
708 </para>
709 </listitem>
710 </varlistentry>
711
712 <varlistentry>
713 <term><option>--version</option></term>
714 <listitem>
715 <para>Prints information on the Boost.Build and Boost.Jam
716 versions.
717 </para>
718 </listitem>
719 </varlistentry>
720
721 <varlistentry>
722 <term><option>-a</option></term>
723 <listitem>
724 <para>Causes all files to be rebuilt.</para>
725 </listitem>
726 </varlistentry>
727
728 <varlistentry>
729 <term><option>-n</option></term>
730 <listitem>
731 <para>Do not execute the commands, only print them.</para>
732 </listitem>
733 </varlistentry>
734
735 <varlistentry>
736 <term><option>-q</option></term>
737 <listitem>
738 <para>Stop at the first error, as opposed to continuing to build targets
739 that don't depend on the failed ones.</para>
740 </listitem>
741 </varlistentry>
742
743 <varlistentry>
744 <term><option>-j <replaceable>N</replaceable></option></term>
745 <listitem>
746 <para>Run up to <replaceable>N</replaceable> commands in parallel.</para>
747 </listitem>
748 </varlistentry>
749
750 <varlistentry>
751 <term><option>--debug-configuration</option></term>
752 <listitem>
753 <para>Produces debug information about the loading of Boost.Build
754 and toolset files.</para>
755 </listitem>
756 </varlistentry>
757
758 <varlistentry>
759 <term><option>--debug-building</option></term>
760 <listitem>
761 <para>Prints what targets are being built and with what properties.
762 </para>
763 </listitem>
764 </varlistentry>
765
766 <varlistentry>
767 <term><option>--debug-generators</option></term>
768 <listitem>
769 <para>Produces debug output from the generator search process.
770 Useful for debugging custom generators.
771 </para>
772 </listitem>
773 </varlistentry>
774
775 <varlistentry>
776 <term><option>-d0</option></term>
777 <listitem>
778 <para>Suppress all informational messages.</para>
779 </listitem>
780 </varlistentry>
781
782 <varlistentry>
783 <term><option>-d <replaceable>N</replaceable></option></term>
784 <listitem>
785 <para>Enable cumulative debugging levels from 1 to n. Values are:
786 <orderedlist>
787 <listitem>Show the actions taken for building targets, as they are executed (the default).</listitem>
788 <listitem>Show "quiet" actions and display all action text, as they are executed.</listitem>
789 <listitem>Show dependency analysis, and target/source timestamps/paths.</listitem>
790 <listitem>Show arguments and timing of shell invocations.</listitem>
791 <listitem>Show rule invocations and variable expansions.</listitem>
792 <listitem>Show directory/header file/archive scans, and attempts at binding to targets.</listitem>
793 <listitem>Show variable settings.</listitem>
794 <listitem>Show variable fetches, variable expansions, and evaluation of '"if"' expressions.</listitem>
795 <listitem>Show variable manipulation, scanner tokens, and memory usage.</listitem>
796 <listitem>Show profile information for rules, both timing and memory.</listitem>
797 <listitem>Show parsing progress of Jamfiles.</listitem>
798 <listitem>Show graph of target dependencies.</listitem>
799 <listitem>Show change target status (fate).</listitem>
800 </orderedlist>
801 </para>
802 </listitem>
803 </varlistentry>
804
805 <varlistentry>
806 <term><option>-d +<replaceable>N</replaceable></option></term>
807 <listitem>
808 <para>Enable debugging level <replaceable>N</replaceable>.</para>
809 </listitem>
810 </varlistentry>
811
812 <varlistentry>
813 <term><option>-o <replaceable>file</replaceable></option></term>
814 <listitem>
815 <para>Write the updating actions to the specified file instead of running them.
816 </para>
817 </listitem>
818 </varlistentry>
819
820 <varlistentry>
821 <term><option>-s <replaceable>var</replaceable>=<replaceable>value</replaceable></option></term>
822 <listitem>
823 <para>Set the variable <replaceable>var</replaceable> to
824 <replaceable>value</replaceable> in the global scope of the jam
825 language interpreter, overriding variables imported from the
826 environment.
827 </para>
828 </listitem>
829 </varlistentry>
830 </variablelist>
831 </section>
832
833 <section id="bbv2.overview.invocation.properties">
834 <title>Properties</title>
835
836 <para>In the simplest case, the build is performed with a single set of properties,
837 that you specify on the command line with elements in the form
838 <command><replaceable>feature</replaceable>=<replaceable>value</replaceable></command>.
839 The complete list of features can be found in <xref linkend="bbv2.overview.builtins.features"/>.
840 The most common features are summarized below.</para>
841
842 <table>
843 <tgroup cols="3">
844 <thead>
845
846 <row>
847 <entry>Feature</entry>
848
849 <entry>Allowed values</entry>
850
851 <entry>Notes</entry>
852 </row>
853
854 </thead>
855 <tbody>
856
857 <row>
858 <entry>variant</entry>
859
860 <entry>debug,release</entry>
861
862 <entry></entry>
863 </row>
864
865 <row>
866 <entry>link</entry>
867
868 <entry>shared,static</entry>
869
870 <entry>Determines if Boost.Build creates shared or static libraries</entry>
871 </row>
872
873 <row>
874 <entry>threading</entry>
875
876 <entry>single,multi</entry>
877
878 <entry>Cause the produced binaries to be thread-safe. This requires proper support in the source code itself.</entry>
879 </row>
880
881 <row>
882 <entry>address-model</entry>
883
884 <entry>32,64</entry>
885
886 <entry>Explicitly request either 32-bit or 64-bit code generation. This typically
887 requires that your compiler is appropriately configured. Please refer to
888 <xref linkend="bbv2.reference.tools.compilers"/> and your compiler documentation
889 in case of problems.</entry>
890 </row>
891
892 <row>
893 <entry>toolset</entry>
894
895 <entry>(Depends on configuration)</entry>
896
897 <entry>The C++ compiler to use. See <xref linkend="bbv2.reference.tools.compilers"/> for a detailed list.</entry>
898 </row>
899
900 <row>
901 <entry>include</entry>
902
903 <entry>(Arbitrary string)</entry>
904
905 <entry>Additional include paths for C and C++ compilers.</entry>
906 </row>
907
908 <row>
909 <entry>define</entry>
910
911 <entry>(Arbitrary string)</entry>
912
913 <entry>Additional macro definitions for C and C++ compilers. The string should be either
914 <code>SYMBOL</code> or <code>SYMBOL=VALUE</code></entry>
915 </row>
916
917 <row>
918 <entry>cxxflags</entry>
919
920 <entry>(Arbitrary string)</entry>
921
922 <entry>Custom options to pass to the C++ compiler.</entry>
923 </row>
924
925 <row>
926 <entry>cflags</entry>
927
928 <entry>(Arbitrary string)</entry>
929
930 <entry>Custom options to pass to the C compiler.</entry>
931 </row>
932
933 <row>
934 <entry>linkflags</entry>
935
936 <entry>(Arbitrary string)</entry>
937
938 <entry>Custom options to pass to the C++ linker.</entry>
939 </row>
940
941 <row>
942 <entry>runtime-link</entry>
943
944 <entry>shared,static</entry>
945
946 <entry>Determines if shared or static version of C and C++ runtimes should be used.</entry>
947 </row>
948
949 </tbody>
950 </tgroup>
951 </table>
952
953 <para>If you have more than one version of a given C++ toolset (e.g. configured in
954 <filename>user-config.jam</filename>, or autodetected, as happens with msvc), you can
955 request the specific version by passing
956 <code><replaceable>toolset</replaceable>-<replaceable>version</replaceable></code> as
957 the value of the <code>toolset</code> feature, for example <code>toolset=msvc-8.0</code>.
958 </para>
959
960
961 <para>
962 If a feature has a fixed set of values it can be specified more than
963 once on the command line. <!-- define 'base' and link to it -->
964 In which case, everything will be built several times --
965 once for each specified value of a feature. For example, if you use
966 </para>
967 <screen>
968 b2 link=static link=shared threading=single threading=multi
969 </screen>
970 <para>
971 Then a total of 4 builds will be performed. For convenience,
972 instead of specifying all requested values of a feature in separate command line elements,
973 you can separate the values with commas, for example:
974 </para>
975 <screen>
976 b2 link=static,shared threading=single,multi
977 </screen>
978 <para>
979 The comma has this special meaning only if the feature has a fixed set of values, so
980 </para>
981 <screen>
982 b2 include=static,shared
983 </screen>
984 <para>is not treated specially.</para>
985
986 </section>
987
988 <section id="bbv2.overview.invocation.targets">
989 <title>Targets</title>
990
991 <para>All command line elements that are neither options nor properties are the names of the
992 targets to build. See <xref linkend="bbv2.reference.ids"/>. If no target is specified,
993 the project in the current directory is built.</para>
994 </section>
995
996 </section>
997
998 <section id="bbv2.overview.targets">
999 <title>Declaring Targets</title>
1000
1001 <para id="bbv2.overview.targets.main">
1002 A <firstterm>Main target</firstterm> is a user-defined named
1003 entity that can be built, for example an executable file.
1004 Declaring a main target is usually done using one of the main
1005 target rules described in <xref linkend=
1006 "bbv2.reference.rules"/>. The user can also declare
1007 custom main target rules as shown in <xref
1008 linkend="bbv2.extending.rules"/>.
1009 </para>
1010
1011 <indexterm><primary>main target</primary><secondary>declaration
1012 syntax</secondary></indexterm>
1013 <para>Most main target rules in Boost.Build have the same common
1014 signature:</para>
1015
1016 <!-- I think we maybe ought to be talking about a common
1017 _signature_ here, having already explained Boost.Jam function
1018 signatures at the beginning of this chapter. Then we could show
1019 ( main-target-name : sources * : requirements * : default-build * : usage-requirements * )
1020 instead. More precise.
1021
1022 Also, I suggest replacing "default-build" by "default-properties" everywhere.
1023 -->
1024
1025 <indexterm><primary>common signature</primary></indexterm>
1026 <anchor id="bbv2.main-target-rule-syntax"/>
1027 <programlisting>
1028 rule <replaceable>rule-name</replaceable> (
1029 main-target-name :
1030 sources + :
1031 requirements * :
1032 default-build * :
1033 usage-requirements * )
1034 </programlisting>
1035
1036 <itemizedlist>
1037 <listitem>
1038 <simpara>
1039 <parameter>main-target-name</parameter> is the name used
1040 to request the target on command line and to use it from
1041 other main targets. A main target name may contain
1042 alphanumeric characters, dashes
1043 (&#x2018;<code>-</code>&#x2019;), and underscores
1044 (&#x2018;<code>_</code>&#x2019;).
1045 </simpara>
1046 </listitem>
1047
1048 <listitem>
1049 <simpara>
1050 <parameter>sources</parameter> is the list of source files and other main
1051 targets that must be combined.
1052 </simpara>
1053 </listitem>
1054
1055 <listitem>
1056 <simpara>
1057 <parameter>requirements</parameter> is the list of properties that must always
1058 be present when this main target is built.
1059 </simpara>
1060 </listitem>
1061
1062 <listitem>
1063 <simpara>
1064 <parameter>default-build</parameter> is the list of properties that will be used
1065 unless some other value of the same feature is already
1066 specified, e.g. on the command line or by propagation from a dependent target.
1067 </simpara>
1068 </listitem>
1069
1070 <listitem>
1071 <simpara>
1072 <parameter>usage-requirements</parameter> is the list of properties that will be
1073 propagated to all main targets that use this one, i.e. to all its
1074 dependents.
1075 </simpara>
1076 </listitem>
1077 </itemizedlist>
1078
1079 <para>
1080 Some main target rules have a different list of parameters as explicitly
1081 stated in their documentation.
1082 </para>
1083
1084 <para>The actual requirements for a target are obtained by refining
1085 the requirements of the project where the target is declared with the
1086 explicitly specified requirements. The same is true for
1087 usage-requirements. More details can be found in
1088 <xref linkend="bbv2.reference.variants.proprefine"/>
1089 </para>
1090
1091 <section>
1092 <title>Name</title>
1093
1094 <!-- perphaps we should use 'name-target-name' to closer
1095 bind this description to the rule's signature. Here, and for
1096 other parameters. -->
1097 <para>The name of main target has two purposes. First, it's used to refer to this target from
1098 other targets and from command line. Second, it's used to compute the names of the generated files.
1099 Typically, filenames are obtained from main target name by appending system-dependent suffixes and
1100 prefixes.
1101 </para>
1102
1103 <para>The name of a main target can contain alphanumeric characters,
1104 dashes, undescores and dots. The entire
1105 name is significant when resolving references from other targets. For determining filenames, only the
1106 part before the first dot is taken. For example:</para>
1107 <programlisting>
1108 obj test.release : test.cpp : &lt;variant&gt;release ;
1109 obj test.debug : test.cpp : &lt;variant&gt;debug ;
1110 </programlisting>
1111 <para>will generate two files named <filename>test.obj</filename> (in two different directories), not
1112 two files named <filename>test.release.obj</filename> and <filename>test.debug.obj</filename>.
1113 </para>
1114
1115 </section>
1116
1117 <section>
1118 <title>Sources</title>
1119
1120 <para>The list of sources specifies what should be processed to
1121 get the resulting targets. Most of the time, it's just a list of
1122 files. Sometimes, you'll want to automatically construct the
1123 list of source files rather than having to spell it out
1124 manually, in which case you can use the
1125 <link linkend="bbv2.reference.rules.glob">glob</link> rule.
1126 Here are two examples:</para>
1127 <programlisting>
1128 exe a : a.cpp ; # a.cpp is the only source file
1129 exe b : [ glob *.cpp ] ; # all .cpp files in this directory are sources
1130 </programlisting>
1131 <para>
1132 Unless you specify a file with an absolute path, the name is
1133 considered relative to the source directory&#x200A;&#x2014;&#x200A;which is typically
1134 the directory where the Jamfile is located, but can be changed as
1135 described in <xref linkend=
1136 "bbv2.overview.projects.attributes.projectrule"/>.
1137 </para>
1138
1139 <para>
1140 <!-- use "project-id" here? -->
1141 The list of sources can also refer to other main targets. Targets in
1142 the same project can be referred to by name, while targets in other
1143 projects must be qualified with a directory or a symbolic project
1144 name. The directory/project name is separated from the target name by
1145 a double forward slash. There is no special syntax to distinguish the
1146 directory name from the project name&#x2014;the part before the double
1147 slash is first looked up as project name, and then as directory name.
1148 For example:
1149 </para>
1150 <programlisting>
1151 lib helper : helper.cpp ;
1152 exe a : a.cpp helper ;
1153 # Since all project ids start with slash, ".." is a directory name.
1154 exe b : b.cpp ..//utils ;
1155 exe c : c.cpp /boost/program_options//program_options ;
1156 </programlisting>
1157 <para>
1158 The first exe uses the library defined in the same project. The second
1159 one uses some target (most likely a library) defined by a Jamfile one
1160 level higher. Finally, the third target uses a <ulink url=
1161 "http://boost.org">C++ Boost</ulink> library, referring to it using
1162 its absolute symbolic name. More information about target references
1163 can be found in <xref linkend="bbv2.tutorial.libs"/> and <xref
1164 linkend="bbv2.reference.ids"/>.
1165 </para>
1166 </section>
1167
1168 <section id="bbv2.overview.targets.requirements">
1169 <title>Requirements</title>
1170 <indexterm><primary>requirements</primary></indexterm>
1171 <para>Requirements are the properties that should always be present when
1172 building a target. Typically, they are includes and defines:
1173 <programlisting>
1174 exe hello : hello.cpp : &lt;include&gt;/opt/boost &lt;define&gt;MY_DEBUG ;
1175 </programlisting>
1176 There are a number of other features, listed in
1177 <xref linkend="bbv2.overview.builtins.features"/>. For example if
1178 a library can only be built statically, or a file can't be compiled
1179 with optimization due to a compiler bug, one can use
1180 <programlisting>
1181 lib util : util.cpp : &lt;link&gt;static ;
1182 obj main : main.cpp : &lt;optimization&gt;off ;
1183 </programlisting>
1184 </para>
1185
1186 <para id="bbv2.overview.targets.requirements.conditional">
1187 <indexterm><primary>requirements</primary><secondary>conditional</secondary></indexterm>
1188 Sometimes, particular relationships need to be maintained
1189 among a target's build properties. This can be achieved with
1190 <firstterm>conditional
1191 requirements</firstterm>. For example, you might want to set
1192 specific <code>#defines</code> when a library is built as shared,
1193 or when a target's <code>release</code> variant is built in
1194 release mode.
1195 <programlisting>
1196 lib network : network.cpp
1197 : <emphasis role="bold">&lt;link&gt;shared:&lt;define&gt;NETWORK_LIB_SHARED</emphasis>
1198 &lt;variant&gt;release:&lt;define&gt;EXTRA_FAST
1199 ;
1200 </programlisting>
1201
1202 In the example above, whenever <filename>network</filename> is
1203 built with <code>&lt;link&gt;shared</code>,
1204 <code>&lt;define&gt;NETWORK_LIB_SHARED</code> will be in its
1205 properties, too.
1206 </para>
1207
1208 <para>You can use several properties in the condition, for example:
1209 <programlisting>
1210 lib network : network.cpp
1211 : &lt;toolset&gt;gcc,&lt;optimization&gt;speed:&lt;define&gt;USE_INLINE_ASSEMBLER
1212 ;
1213 </programlisting>
1214 </para>
1215
1216 <para id="bbv2.overview.targets.requirements.indirect">
1217 <indexterm><primary>requirements</primary><secondary>indirect</secondary></indexterm>
1218 A more powerful variant of conditional requirements
1219 is <firstterm>indirect conditional requirements</firstterm>.
1220 You can provide a rule that will be called with the current build properties and can compute additional properties
1221 to be added. For example:
1222 <programlisting>
1223 lib network : network.cpp
1224 : &lt;conditional&gt;@my-rule
1225 ;
1226 rule my-rule ( properties * )
1227 {
1228 local result ;
1229 if &lt;toolset&gt;gcc &lt;optimization&gt;speed in $(properties)
1230 {
1231 result += &lt;define&gt;USE_INLINE_ASSEMBLER ;
1232 }
1233 return $(result) ;
1234 }
1235 </programlisting>
1236 This example is equivalent to the previous one, but for complex cases, indirect conditional
1237 requirements can be easier to write and understand.
1238 </para>
1239
1240 <para>Requirements explicitly specified for a target are usually
1241 combined with the requirements specified for the containing project. You
1242 can cause a target to completely ignore a specific project requirement
1243 using the syntax by adding a minus sign before the property, for example:
1244 <programlisting>
1245 exe main : main.cpp : <emphasis role="bold">-&lt;define&gt;UNNECESSARY_DEFINE</emphasis> ;
1246 </programlisting>
1247 This syntax is the only way to ignore free properties, such as defines,
1248 from a parent. It can be also useful for ordinary properties. Consider
1249 this example:
1250 <programlisting>
1251 project test : requirements &lt;threading&gt;multi ;
1252 exe test1 : test1.cpp ;
1253 exe test2 : test2.cpp : &lt;threading&gt;single ;
1254 exe test3 : test3.cpp : -&lt;threading&gt;multi ;
1255 </programlisting>
1256 Here, <code>test1</code> inherits the project requirements and will always
1257 be built in multi-threaded mode. The <code>test2</code> target
1258 <emphasis>overrides</emphasis> the project's requirements and will
1259 always be built in single-threaded mode. In contrast, the
1260 <code>test3</code> target <emphasis>removes</emphasis> a property
1261 from the project requirements and will be built either in single-threaded or
1262 multi-threaded mode depending on which variant is requested by the
1263 user.</para>
1264
1265 <para>Note that the removal of requirements is completely textual:
1266 you need to specify exactly the same property to remove it.</para>
1267
1268 </section>
1269
1270 <section>
1271 <title>Default Build</title>
1272
1273 <para>The <varname>default-build</varname> parameter
1274 is a set of properties to be used if the build request does
1275 not otherwise specify a value for features in the set. For example:
1276 <programlisting>
1277 exe hello : hello.cpp : : &lt;threading&gt;multi ;
1278 </programlisting>
1279 would build a multi-threaded target unless the user
1280 explicitly requests a single-threaded version. The difference between
1281 the requirements and the default-build is that the requirements cannot be
1282 overridden in any way.
1283 </para>
1284 </section>
1285
1286 <section>
1287 <title>Additional Information</title>
1288
1289 <para>
1290 The ways a target is built can be so different that
1291 describing them using conditional requirements would be
1292 hard. For example, imagine that a library actually uses
1293 different source files depending on the toolset used to build
1294 it. We can express this situation using <firstterm>target
1295 alternatives</firstterm>:
1296 <programlisting>
1297 lib demangler : dummy_demangler.cpp ; # alternative 1
1298 lib demangler : demangler_gcc.cpp : &lt;toolset&gt;gcc ; # alternative 2
1299 lib demangler : demangler_msvc.cpp : &lt;toolset&gt;msvc ; # alternative 3
1300 </programlisting>
1301 In the example above, when built with <literal>gcc</literal>
1302 or <literal>msvc</literal>, <filename>demangler</filename>
1303 will use a source file specific to the toolset. Otherwise, it
1304 will use a generic source file,
1305 <filename>dummy_demangler.cpp</filename>.
1306 </para>
1307
1308 <para>It is possible to declare a target inline, i.e. the "sources"
1309 parameter may include calls to other main rules. For example:</para>
1310
1311 <programlisting>
1312 exe hello : hello.cpp
1313 [ obj helpers : helpers.cpp : &lt;optimization&gt;off ] ;</programlisting>
1314
1315 <para>
1316 Will cause "helpers.cpp" to be always compiled without
1317 optimization. When referring to an inline main target, its declared
1318 name must be prefixed by its parent target's name and two dots. In
1319 the example above, to build only helpers, one should run
1320 <code>b2 hello..helpers</code>.
1321 </para>
1322
1323 <para>When no target is requested on the command line, all targets in the
1324 current project will be built. If a target should be built only by
1325 explicit request, this can be expressed by the
1326 <link linkend="bbv2.reference.rules.explicit">explicit</link> rule:
1327 <programlisting>
1328 explicit install_programs ;</programlisting>
1329 </para>
1330
1331 </section>
1332 </section>
1333
1334 <section id="bbv2.overview.projects">
1335 <title>Projects</title>
1336
1337 <para>As mentioned before, targets are grouped into projects,
1338 and each Jamfile is a separate project. Projects are useful
1339 because they allow us to group related targets together, define
1340 properties common to all those targets, and assign a symbolic
1341 name to the project that can be used in referring to its
1342 targets.
1343 </para>
1344
1345 <para>Projects are named using the
1346 <code language="jam">project</code> rule, which has the
1347 following syntax:
1348 <programlisting>
1349 project <replaceable>id</replaceable> : <replaceable>attributes</replaceable> ;
1350 </programlisting>
1351 Here, <replaceable>attributes</replaceable> is a sequence of
1352 rule arguments, each of which begins with an attribute-name
1353 and is followed by any number of build properties. The list
1354 of attribute names along with its handling is also shown in
1355 the table below. For example, it is possible to write:
1356 <programlisting>
1357 project tennis
1358 : requirements &lt;threading&gt;multi
1359 : default-build release
1360 ;
1361 </programlisting>
1362 </para>
1363
1364 <para>The possible attributes are listed below.</para>
1365
1366 <para><emphasis>Project id</emphasis> is a short way to denote a project, as
1367 opposed to the Jamfile's pathname. It is a hierarchical path,
1368 unrelated to filesystem, such as "boost/thread". <link linkend=
1369 "bbv2.reference.ids">Target references</link> make use of project ids to
1370 specify a target.</para>
1371 <!--
1372 This is actually spelled "project-id," isn't it? You
1373 have to fix all of these and use a code font. Also below
1374 in the table.
1375 -->
1376
1377 <para><emphasis>Source location</emphasis> specifies the directory where sources
1378 for the project are located.</para>
1379
1380 <para><emphasis>Project requirements</emphasis> are requirements that apply to
1381 all the targets in the projects as well as all subprojects.</para>
1382
1383 <para><emphasis>Default build</emphasis> is the build request that should be
1384 used when no build request is specified explicitly.</para>
1385 <!--
1386 This contradicts your earlier description of default
1387 build and I believe it is incorrect. Specifying a build
1388 request does not neccessarily render default build
1389 ineffective, because it may cover different features.
1390 This description is repeated too many times in the
1391 documentation; you almost *had* to get it wrong once.
1392 -->
1393
1394 <para id="bbv2.overview.projects.attributes.projectrule">
1395 The default values for those attributes are
1396 given in the table below.
1397
1398 <table>
1399 <title/>
1400 <tgroup cols="4">
1401 <thead>
1402 <row>
1403 <entry>Attribute</entry>
1404
1405 <entry>Name</entry>
1406
1407 <entry>Default value</entry>
1408
1409 <entry>Handling by the <code language="jam">project</code>
1410 rule</entry>
1411
1412 </row>
1413 </thead>
1414
1415 <tbody>
1416
1417 <row>
1418 <entry>Project id</entry>
1419
1420 <entry>none</entry>
1421
1422 <entry>none</entry>
1423
1424 <entry>Assigned from the first parameter of the 'project' rule.
1425 It is assumed to denote absolute project id.</entry>
1426 </row>
1427
1428 <row>
1429 <entry>Source location</entry>
1430
1431 <entry><literal>source-location</literal></entry>
1432
1433 <entry>The location of jamfile for the project</entry>
1434
1435 <entry>Sets to the passed value</entry>
1436 </row>
1437
1438 <row>
1439 <entry>Requirements</entry>
1440
1441 <entry><literal>requirements</literal></entry>
1442
1443 <entry>The parent's requirements</entry>
1444
1445 <entry>The parent's requirements are refined with the passed
1446 requirement and the result is used as the project
1447 requirements.</entry>
1448 </row>
1449
1450 <row>
1451 <entry>Default build</entry>
1452
1453 <entry><literal>default-build</literal></entry>
1454
1455 <entry>none</entry>
1456
1457 <entry>Sets to the passed value</entry>
1458 </row>
1459
1460 <row>
1461 <entry>Build directory</entry>
1462
1463 <entry><literal>build-dir</literal></entry>
1464
1465 <entry>Empty if the parent has no build directory set.
1466 Otherwise, the parent's build directory with the
1467 relative path from parent to the current project
1468 appended to it.
1469 </entry>
1470
1471 <entry>Sets to the passed value, interpreted as relative to the
1472 project's location.</entry>
1473 </row>
1474 </tbody>
1475 </tgroup>
1476 </table>
1477 </para>
1478
1479 <para>Besides defining projects and main targets, Jamfiles
1480 often invoke various utility rules. For the full list of rules
1481 that can be directly used in Jamfile see
1482 <xref linkend="bbv2.reference.rules"/>.
1483 </para>
1484
1485 <para>Each subproject inherits attributes, constants and rules
1486 from its parent project, which is defined by the nearest
1487 Jamfile in an ancestor directory above
1488 the subproject. The top-level project is declared in a file
1489 called <filename>Jamroot</filename> rather than
1490 <filename>Jamfile</filename>. When loading a project,
1491 Boost.Build looks for either <filename>Jamroot</filename> or
1492 <code>Jamfile</code>. They are handled identically, except
1493 that if the file is called <filename>Jamroot</filename>, the
1494 search for a parent project is not performed.
1495 </para>
1496
1497 <para>Even when building in a subproject directory, parent
1498 project files are always loaded before those of their
1499 subprojects, so that every definition made in a parent project
1500 is always available to its children. The loading order of any
1501 other projects is unspecified. Even if one project refers to
1502 another via the <code>use-project</code> or a target reference,
1503 no specific order should be assumed.
1504 </para>
1505
1506 <note>
1507 <para>Giving the root project the special name
1508 &#x201C;<filename>Jamroot</filename>&#x201D; ensures that
1509 Boost.Build won't misinterpret a directory above it as the
1510 project root just because the directory contains a Jamfile.
1511 <!-- The logic of the previous reasoning didn't hang together -->
1512 </para>
1513 </note>
1514
1515 <!-- All this redundancy with the tutorial is bad. The tutorial
1516 should just be made into the introductory sections of this
1517 document, which should be called the "User Guide." It's
1518 perfectly appropriate to start a user guide with that kind
1519 of material. -->
1520 </section>
1521
1522 <section id="bbv2.overview.build_process">
1523 <title>The Build Process</title>
1524
1525 <para>When you've described your targets, you want Boost.Build to run the
1526 right tools and create the needed targets.
1527 <!-- That sentence is awkward and doesn't add much. -->
1528 This section will describe
1529 two things: how you specify what to build, and how the main targets are
1530 actually constructed.
1531 </para>
1532
1533 <para>The most important thing to note is that in Boost.Build, unlike
1534 other build tools, the targets you declare do not correspond to specific
1535 files. What you declare in a Jamfile is more like a “metatarget.”
1536 <!-- Do we need a new word? We already have “main target.” If
1537 you're going to introduce “metatarget” you should at least
1538 tie it together with the main target concept. It's too
1539 strange to have been saying “main target” all along and now
1540 suddenly start saying “what you declare in a jamfile” -->
1541 Depending on the properties you specify on the command line,
1542 each metatarget will produce a set of real targets corresponding
1543 to the requested properties. It is quite possible that the same
1544 metatarget is built several times with different properties,
1545 producing different files.
1546 </para>
1547 <tip>
1548 <para>
1549 This means that for Boost.Build, you cannot directly obtain a build
1550 variant from a Jamfile. There could be several variants requested by the
1551 user, and each target can be built with different properties.
1552 </para>
1553 </tip>
1554
1555 <section id="bbv2.overview.build_request">
1556 <title>Build Request</title>
1557
1558 <para>
1559 The command line specifies which targets to build and with which
1560 properties. For example:
1561 <programlisting>
1562 b2 app1 lib1//lib1 toolset=gcc variant=debug optimization=full
1563 </programlisting>
1564 would build two targets, "app1" and "lib1//lib1" with the specified
1565 properties. You can refer to any targets, using
1566 <link linkend="bbv2.reference.ids">target id</link> and specify arbitrary
1567 properties. Some of the properties are very common, and for them the name
1568 of the property can be omitted. For example, the above can be written as:
1569 <programlisting>
1570 b2 app1 lib1//lib1 gcc debug optimization=full
1571 </programlisting>
1572 The complete syntax, which has some additional shortcuts, is
1573 described in <xref linkend="bbv2.overview.invocation"/>.
1574 </para>
1575 </section>
1576
1577 <section><title>Building a main target</title>
1578
1579 <para>When you request, directly or indirectly, a build of a main target
1580 with specific requirements, the following steps are done. Some brief
1581 explanation is provided, and more details are given in <xref
1582 linkend="bbv2.reference.buildprocess"/>.
1583 <orderedlist>
1584
1585 <listitem><para>Applying default build. If the default-build
1586 property of a target specifies a value of a feature that is not
1587 present in the build request, that value is added.</para>
1588 <!--
1589 Added to what? Don't say “the build request!” The
1590 request is what was requested; if its meaning changes
1591 the reader will be confused.
1592 -->
1593 </listitem>
1594
1595 <listitem><para>Selecting the main target alternative to use. For
1596 each alternative we look how many properties are present both in
1597 alternative's requirements, and in build request. The
1598 alternative with largest number of matching properties is selected.
1599 </para></listitem>
1600
1601 <listitem><para>Determining "common" properties.
1602 <!-- It would be nice to have a better name for this. But
1603 even more importantly, unless you say something about
1604 the reason for choosing whatever term you use, the
1605 reader is going to wonder what it means. -->
1606 The build request
1607 is <link linkend="bbv2.reference.variants.proprefine">refined</link>
1608 with target's requirements.
1609 <!-- It's good that you have the links here and below,
1610 but I'm concerned that it doesn't communicate well
1611 in print and there's not enough information for the
1612 print reader. Maybe we need separate XSL for PDF
1613 printing that generates a readable footnote. -->
1614 The conditional properties in
1615 requirements are handled as well. Finally, default values of
1616 features are added.
1617 </para></listitem>
1618
1619 <listitem><para>Building targets referred by the sources list and
1620 dependency properties. The list of sources and the properties
1621 can refer to other target using <link
1622 linkend="bbv2.reference.ids">target references</link>. For each
1623 reference, we take all <link
1624 linkend="bbv2.reference.features.attributes.propagated">propagated</link>
1625 properties, refine them by explicit properties specified in the
1626 target reference, and pass the resulting properties as build
1627 request to the other target.
1628 </para></listitem>
1629
1630 <listitem><para>Adding the usage requirements produced when building
1631 dependencies to the "common" properties. When dependencies are
1632 built in the previous step, they return
1633 <!-- don't assume reader has a mental model for BB internals! -->
1634 both the set of created
1635 "real" targets, and usage requirements. The usage requirements
1636 are added to the common properties and the resulting property
1637 set will be used for building the current target.
1638 </para></listitem>
1639
1640 <listitem><para>Building the target using generators. To convert the
1641 sources to the desired type, Boost.Build uses "generators" ---
1642 objects that correspond to tools like compilers and linkers. Each
1643 generator declares what type of targets it can produce and what
1644 type of sources it requires. Using this information, Boost.Build
1645 determines which generators must be run to produce a specific
1646 target from specific sources. When generators are run, they return
1647 the "real" targets.
1648 </para></listitem>
1649
1650 <listitem><para>Computing the usage requirements to be returned. The
1651 conditional properties in usage requirements are expanded
1652 <!-- what does "expanded" mean? -->
1653 and the result is returned.</para></listitem>
1654 </orderedlist>
1655 </para>
1656 </section>
1657
1658 <section><title>Building a Project</title>
1659
1660 <para>Often, a user builds a complete project, not just one main
1661 target. In fact, invoking <command>b2</command> without
1662 arguments
1663 <!-- do you know the difference between parameters and
1664 arguments? I only learned this year -->
1665 builds the project defined in the current
1666 directory.</para>
1667
1668 <para>When a project is built, the build request is passed without
1669 modification to all main targets in that project.
1670 <!-- What does it mean to pass a build request to a target?
1671 -->
1672 It's is possible to
1673 prevent implicit building of a target in a project with the
1674 <code>explicit</code> rule:
1675 <programlisting>
1676 explicit hello_test ;
1677 </programlisting>
1678 would cause the <code>hello_test</code> target to be built only if
1679 explicitly requested by the user or by some other target.
1680 </para>
1681
1682 <para>The Jamfile for a project can include a number of
1683 <code>build-project</code> rule calls that specify additional projects to
1684 be built.
1685 </para>
1686
1687 </section>
1688
1689 </section>
1690
1691 </chapter>
1692
1693 <!--
1694 Local Variables:
1695 mode: nxml
1696 sgml-indent-data: t
1697 sgml-parent-document: ("userman.xml" "chapter")
1698 sgml-set-face: t
1699 End:
1700 -->