Support global variable reference in boostbook.
[boost.git] / Jamroot
blob506eb33a05e0e64a32097e6eadb76de9ff1fb453
1 # Copyright Vladimir Prus 2002-2006.
2 # Copyright Dave Abrahams 2005-2006.
3 # Copyright Rene Rivera 2005-2007.
4 # Copyright Douglas Gregor 2005.
6 # Distributed under the Boost Software License, Version 1.0.
7 #    (See accompanying file LICENSE_1_0.txt or copy at
8 #          http://www.boost.org/LICENSE_1_0.txt)
10 # Usage:
12 #   bjam [options] [properties] [install|stage]
14 #   Builds and installs Boost.
16 # Targets and Related Options:
18 #   install                 Install headers and compiled library files to the
19 #   =======                 configured locations (below).
21 #   --prefix=<PREFIX>       Install architecture independent files here.
22 #                           Default; C:\Boost on Win32
23 #                           Default; /usr/local on Unix. Linux, etc.
25 #   --exec-prefix=<EPREFIX> Install architecture dependent files here.
26 #                           Default; <PREFIX>
28 #   --libdir=<DIR>          Install library files here.
29 #                           Default; <EPREFIX>/lib
31 #   --includedir=<HDRDIR>   Install header files here.
32 #                           Default; <PREFIX>/include
34 #   stage                   Build and install only compiled library files
35 #   =====                   to the stage directory.
37 #   --stagedir=<STAGEDIR>   Install library files here
38 #                           Default; ./stage
40 # Other Options:
42 #   --build-type=<type>     Build the specified pre-defined set of variations
43 #                           of the libraries. Note, that which variants get
44 #                           built depends on what each library supports.
46 #                               minimal (default) - Builds the single
47 #                               "release" version of the libraries. This
48 #                               release corresponds to specifying:
49 #                               "release <threading>multi <link>shared
50 #                               <link>static <runtime-link>shared" as the
51 #                               Boost.Build variant to build.
53 #                               complete - Attempts to build all possible
54 #                               variations.
56 #   --build-dir=DIR         Build in this location instead of building
57 #                           within the distribution tree. Recommended!
59 #   --show-libraries        Displays the list of Boost libraries that require
60 #                           build and installation steps, then exit.
62 #   --layout=<layout>       Determines whether to choose library names
63 #                           and header locations such that multiple
64 #                           versions of Boost or multiple compilers can
65 #                           be used on the same system.
67 #                               versioned (default) - Names of boost
68 #                               binaries include the Boost version
69 #                               number and the name and version of the
70 #                               compiler.  Boost headers are installed
71 #                               in a subdirectory of <HDRDIR> whose
72 #                               name contains the Boost version
73 #                               number.
75 #                               system - Binaries names do not include
76 #                               the Boost version number or the name
77 #                               and version number of the compiler.
78 #                               Boost headers are installed directly
79 #                               into <HDRDIR>.  This option is
80 #                               intended for system integrators who
81 #                               are building distribution packages.
83 #   --buildid=ID            Adds the specified ID to the name of built
84 #                           libraries.  The default is to not add anything.
86 #   --help                  This message.
88 #   --with-<library>        Build and install the specified <library>
89 #                           If this option is used, only libraries
90 #                           specified using this option will be built.
92 #   --without-<library>     Do not build, stage, or install the specified
93 #                           <library>. By default, all libraries are built.
95 # Properties:
97 #   toolset=toolset         Indicates the toolset to build with.
99 #   variant=debug|release   Select the build variant
101 #   link=static|shared      Whether to build static or shared libraries
103 #   threading=single|multi  Whether to build single or multithreaded binaries
105 #   runtime-link=static|shared      
106 #                           Whether to link to static or shared C and C++ runtime.
107 #   
109 # TODO:
110 #  - handle boost version
111 #  - handle python options such as pydebug
113 import generate ;
114 import modules ;
115 import set ;
116 import stage ;
117 import package ;
118 import path ;
119 import common ;
120 import os ;
121 import regex ;
122 import errors ;
123 import "class" : new ;
124 import common ;
125 import sequence ;
126 import symlink ;
128 path-constant BOOST_ROOT : . ;
129 constant BOOST_VERSION : 1.39.0 ;
130 constant BOOST_JAMROOT_MODULE : $(__name__) ;
132 local version-tag = [ MATCH "^([^.]+)[.]([^.]+)[.]([^.]+)" : $(BOOST_VERSION) ]
133     ;
134 if $(version-tag[3]) = 0
136     version-tag = $(version-tag[1-2]) ;
139 constant BOOST_VERSION_TAG : $(version-tag:J="_") ;
141 # Option to choose how many variants to build. The default is "minimal".
142 local build-type = [ MATCH "^--build-type=(.*)" : [ modules.peek : ARGV ] ] ;
143 build-type ?= minimal ;
144 if ! ( $(build-type) in minimal complete )
146     build-type = minimal ;
149 # Specify the build variants keyed on the build-type.
150 local default-build,minimal =
151     release
152     <threading>multi
153     <link>shared <link>static
154     <runtime-link>shared
155     ;
156 local default-build,complete =
157     debug release
158     <threading>single <threading>multi
159     <link>shared <link>static
160     <runtime-link>shared <runtime-link>static
161     ;
163 # Set the default build.
164 local default-build = $(default-build,$(build-type)) ;
166 # We only use the default build when building at the root to avoid having it
167 # impact the default regression testing of "debug".
168 # TODO: Consider having a "testing" build type instead of this check.
169 if $(__file__:D) != ""
171     default-build = debug ;
175 rule handle-static-runtime ( properties * )
177     # This property combination is dangerous. Ideally, we would add a constraint
178     # to default build, so that user can build this property combination only if
179     # requested directly. But we do not have any 'constraint' system for
180     # default-build, so we disable such builds in requirements.
182     # For CW, static runtime is needed so that std::locale works.
183     if <link>shared in $(properties) && <runtime-link>static in $(properties) &&
184         ! ( <toolset>cw in $(properties) )
185     {
186         return <build>no ;
187     }
191 project boost
192     : requirements <include>.
193       # Disable auto-linking for all targets here, primarily because it caused
194       # troubles with V2.
195       <define>BOOST_ALL_NO_LIB=1
196       # Used to encode variant in target name. See the 'tag' rule below.
197       <tag>@$(__name__).tag
198       <conditional>@handle-static-runtime
199       # The standard library Sun compilers use by default has no chance
200       # of working with Boost. Override it.
201       <toolset>sun:<stdlib>sun-stlport
202     : usage-requirements <include>.
203     : build-dir bin.v2
204     : default-build $(default-build)
205     ;
208 # Setup convenient aliases for all libraries.
210 all-libraries = [ MATCH .*libs/(.*)/build/.* : [ glob libs/*/build/Jamfile.v2 ]
211     [ glob libs/*/build/Jamfile ] ]
212     ;
214 all-libraries = [ sequence.unique $(all-libraries) ] ;
215 # The function_types library has a Jamfile, but it's used for maintenance
216 # purposes, there's no library to build and install.
217 all-libraries = [ set.difference $(all-libraries) : function_types ] ;
220 local rule explicit-alias ( id : targets + )
222     alias $(id) : $(targets) ;
223     explicit $(id) ;
227 # First, the complicated libraries: where the target name in Jamfile is
228 # different from its directory name.
229 explicit-alias prg_exec_monitor : libs/test/build//boost_prg_exec_monitor ;
230 explicit-alias test_exec_monitor : libs/test/build//boost_test_exec_monitor ;
231 explicit-alias unit_test_framework : libs/test/build//boost_unit_test_framework ;
232 explicit-alias bgl-vis : libs/graps/build//bgl-vis ;
233 explicit-alias serialization : libs/serialization/build//boost_serialization ;
234 explicit-alias wserialization : libs/serialization/build//boost_wserialization ;
235 for local l in $(all-libraries)
237     if ! $(l) in test graph serialization
238     {
239         explicit-alias $(l) : libs/$(l)/build//boost_$(l) ;
240     }
243 alias headers : : : : <include>. ;
246 # Decides which libraries are to be installed by looking at --with-<library>
247 # --without-<library> arguments. Returns the list of directories under "libs"
248 # which must be built and installed.
250 rule libraries-to-install ( existing-libraries * )
252    local argv = [ modules.peek : ARGV ] ;
253    local with-parameter = [ MATCH --with-(.*) : $(argv) ] ;
254    local without-parameter = [ MATCH --without-(.*) : $(argv) ] ;
256    # Do some checks.
257    if $(with-parameter) && $(without-parameter)
258    {
259        ECHO "error: both --with-<library> and --without-<library> specified" ;
260        EXIT ;
261    }
263    local wrong = [ set.difference $(with-parameter) : $(existing-libraries) ] ;
264    if $(wrong)
265    {
266        ECHO "error: wrong library name '$(wrong[1])' in the --with-<library> option." ;
267        EXIT ;
268    }
269    local wrong = [ set.difference $(without-parameter) : $(existing-libraries) ] ;
270    if $(wrong)
271    {
272        ECHO "error: wrong library name '$(wrong[1])' in the --without-<library> option." ;
273        EXIT ;
274    }
276    if $(with-parameter)
277    {
278        return [ set.intersection $(existing-libraries) : $(with-parameter) ] ;
279    }
280    else
281    {
282        return [ set.difference $(existing-libraries) : $(without-parameter) ] ;
283    }
287 # What kind of layout are we doing?
288 layout = [ MATCH "^--layout=(.*)" : [ modules.peek : ARGV ] ] ;
289 layout ?= versioned ;
290 layout-$(layout) = true ;
293 # Possible stage only location.
294 local stage-locate = [ MATCH "^--stagedir=(.*)" : [ modules.peek : ARGV ] ] ;
295 stage-locate ?= stage ;
296 path-constant BOOST_STAGE_LOCATE : $(stage-locate) ;
299 # Python location.
300 local python-root = [ MATCH "^--with-python-root=(.*)" : [ modules.peek : ARGV ]
301     ] ;
302 PYTHON_ROOT ?= $(python-root) ;
305 # Select the libraries to install.
306 libraries = [ libraries-to-install $(all-libraries) ] ;
308 if --show-libraries in [ modules.peek : ARGV ]
310     ECHO "The following libraries require building:" ;
311     for local l in $(libraries)
312     {
313         ECHO "    - $(l)" ;
314     }
315     EXIT ;
318 # Custom build ID.
319 local build-id = [ MATCH "^--buildid=(.*)" : [ modules.peek : ARGV ] ] ;
320 if $(build-id)
322     constant BUILD_ID : [ regex.replace $(build-id) "[*\\/:.\"\' ]" "_" ] ;
326 # This rule is called by Boost.Build to determine the name of target. We use it
327 # to encode the build variant, compiler name and boost version in the target
328 # name.
330 rule tag ( name : type ? : property-set )
332     if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
333     {
334         if $(layout) = versioned
335         {
336             local result = [ common.format-name
337                 <base> <toolset> <threading> <runtime> -$(BOOST_VERSION_TAG)
338                 -$(BUILD_ID)
339                 : $(name) : $(type) : $(property-set) ] ;
341             # Optionally add version suffix. On NT, library with version suffix
342             # will not be recognized by linkers. On CYGWIN, we get strage
343             # duplicate symbol errors when library is generated with version
344             # suffix. On OSX, version suffix is not needed -- the linker expects
345             # the libFoo.1.2.3.dylib format. AIX linkers do not accept version
346             # suffixes either. Pgi compilers can not accept library with version
347             # suffix.
348             if $(type) = SHARED_LIB &&
349               ( ! ( [ $(property-set).get <target-os> ] in windows cygwin darwin aix ) &&
350                 ! ( [ $(property-set).get <toolset> ] in pgi ) )
351             {
352                 result = $(result).$(BOOST_VERSION)  ;
353             }
355             return $(result) ;
356         }
357         else
358         {
359             local result = [ common.format-name
360                 <base> 
361                 -$(BUILD_ID)
362                 : $(name) : $(type) : $(property-set) ] ;
364             # Optionally add version suffix. On NT, library with version suffix
365             # will not be recognized by linkers. On CYGWIN, we get strage
366             # duplicate symbol errors when library is generated with version
367             # suffix. On OSX, version suffix is not needed -- the linker expects
368             # the libFoo.1.2.3.dylib format. AIX linkers do not accept version
369             # suffixes either. Pgi compilers can not accept library with version
370             # suffix.
371             if $(type) = SHARED_LIB &&
372               ( ! ( [ $(property-set).get <target-os> ] in windows cygwin darwin aix ) &&
373                 ! ( [ $(property-set).get <toolset> ] in pgi ) )
374             {
375                 result = $(result).$(BOOST_VERSION)  ;
376             }
378             return $(result) ;
379         }
380     }
384 # Install to system location.
386 install-requirements = <install-source-root>$(BOOST_ROOT)/boost ;
388 if $(layout-versioned)
390     install-requirements += <install-header-subdir>boost-$(BOOST_VERSION_TAG)/boost ;
392 else
394     install-requirements += <install-header-subdir>boost ;
396 if [ modules.peek : NT ]
398     install-requirements += <install-default-prefix>C:/Boost ;
400 else if [ modules.peek : UNIX ]
402     install-requirements += <install-default-prefix>/usr/local ;
405 local headers =
406     # The .SUNWCCh files are present in tr1 include directory and have to be installed,
407     # see http://lists.boost.org/Archives/boost/2007/05/121430.php
408     [ path.glob-tree $(BOOST_ROOT)/boost : *.hpp *.ipp *.h *.inc *.SUNWCCh : CVS .svn ]
409     [ path.glob-tree $(BOOST_ROOT)/boost/compatibility/cpp_c_headers : c* : CVS .svn ] 
410     [ path.glob boost/tr1/tr1 : * : bcc32 sun CVS .svn ]
411           ;
413 # Complete install.
414 package.install install-proper
415     : $(install-requirements) <install-no-version-symlinks>on
416     :
417     : libs/$(libraries)/build
418     : $(headers)
419     ;
420 explicit install-proper ;
422 # Install just library.
423 install stage-proper
424     : libs/$(libraries)/build
425     : <location>$(stage-locate)/lib
426       <install-dependencies>on <install-type>LIB
427       <install-no-version-symlinks>on
428     ;
429 explicit stage-proper ;
432 if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] )
434     rule make-unversioned-links ( project name ? : property-set : sources * )
435     {
436         local result ;
437         local filtered ;
438         local pattern ;
439         local nt = [ modules.peek : NT ] ;
441         # Collect the libraries that have the version number in 'filtered'.
442         for local s in $(sources)
443         {
444             local m ;
445             if $(nt)
446             {
447                 m = [ MATCH "(.*[.]lib)" : [ $(s).name ] ] ;
448             }
449             else
450             {
451                 m = [ MATCH "(.*[.]so[.0-9]+)" "(.*[.]dylib)" "(.*[.]a)" :
452                     [ $(s).name ] ] ;
453             }
454             if $(m)
455             {
456                 filtered += $(s) ;
457             }
458         }
460         # Create links without version.
461         for local s in $(filtered)
462         {
463             local name = [ $(s).name ] ;
464             local ea = [ $(s).action ] ;
465             local ep = [ $(ea).properties ] ;
466             local a  = [ new non-scanning-action $(s) : symlink.ln : $(ep) ] ;
468             local noversion-file ;
469             if $(nt)
470             {
471                 noversion-file = [ MATCH "(.*)-[0-9_]+(.*[.]lib)" : $(name) ] ;
472             }
473             else
474             {
475                 noversion-file =
476                   [ MATCH "(.*)-[0-9_]+(.*[.]so)[.0-9]*" : $(name) ]
477                   [ MATCH "(.*)-[0-9_]+(.*[.]dylib)" : $(name) ]
478                   [ MATCH "(.*)-[0-9_]+(.*[.]a)" : $(name) ]
479                   [ MATCH "(.*)-[0-9_]+(.*[.]dll[.]a)" : $(name) ] ;
480             }
482             local new-name =
483                $(noversion-file[1])$(noversion-file[2]) ;
484             result += [ new file-target $(new-name) exact : [ $(s).type ] : $(project)
485                     : $(a) ] ;
487         }
488         return $(result) ;
489     }
491     generate stage-unversioned : stage-proper :
492         <generating-rule>@make-unversioned-links ;
493     explicit stage-unversioned ;
495     generate install-unversioned : install-proper :
496         <generating-rule>@make-unversioned-links ;
497     explicit install-unversioned ;
499 else
501     # Create do-nothing aliases.
502     alias stage-unversioned ;
503     explicit stage-unversioned ;
504     alias install-unversioned ;
505     explicit install-unversioned ;
508 alias install : install-proper install-unversioned ;
509 alias stage : stage-proper stage-unversioned ;
510 explicit install ;
511 explicit stage ;
514 # Just build the libraries, don't install them anywhere. This is what happens
515 # with just "bjam --v2".
516 alias build_all : libs/$(libraries)/build ;
519 # This rule should be called from libraries' Jamfiles and will create two
520 # targets, "install" and "stage", that will install or stage that library. The
521 # --prefix option is respected, but --with and --without options, naturally, are
522 # ignored.
524 # - libraries -- list of library targets to install.
526 rule boost-install ( libraries * )
528     package.install install
529         : <dependency>/boost//install-proper-headers $(install-requirements)
530         : # No binaries
531         : $(libraries)
532         : # No headers, it is handled by the dependency.
533     ;
535     install stage : $(libraries) : <location>$(BOOST_STAGE_LOCATE) ;
537     local c = [ project.current ] ;
538     local project-module = [ $(c).project-module ] ;
539     module $(project-module)
540     {
541         explicit stage ;
542         explicit install ;
543     }
547 # Make project ids of all libraries known.
548 for local l in $(all-libraries)
550     use-project /boost/$(l) : libs/$(l)/build ;