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)
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.
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
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
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 binaries
68 # include the Boost version number, name and
69 # version of the compiler and encoded build
70 # properties. Boost headers are installed in a
71 # subdirectory of <HDRDIR> whose name contains
72 # the Boost version number.
74 # tagged -- Names of boost binaries include the
75 # encoded build properties such as variant and
76 # threading, but do not including compiler name
77 # and version, or Boost version. This option is
78 # useful if you build several variants of Boost,
79 # using the same compiler.
81 # system - Binaries names do not include the
82 # Boost version number or the name and version
83 # number of the compiler. Boost headers are
84 # installed directly into <HDRDIR>. This option
85 # is intended for system integrators who are
86 # building distribution packages.
88 # --buildid=ID Adds the specified ID to the name of built
89 # libraries. The default is to not add anything.
91 # --help This message.
93 # --with-<library> Build and install the specified <library>
94 # If this option is used, only libraries
95 # specified using this option will be built.
97 # --without-<library> Do not build, stage, or install the specified
98 # <library>. By default, all libraries are built.
102 # toolset=toolset Indicates the toolset to build with.
104 # variant=debug|release Select the build variant
106 # link=static|shared Whether to build static or shared libraries
108 # threading=single|multi Whether to build single or multithreaded binaries
110 # runtime-link=static|shared
111 # Whether to link to static or shared C and C++ runtime.
115 # - handle boost version
116 # - handle python options such as pydebug
128 import "class" : new ;
135 path-constant BOOST_ROOT : . ;
136 constant BOOST_VERSION : 1.40.0 ;
137 constant BOOST_JAMROOT_MODULE : $(__name__) ;
139 local version-tag = [ MATCH "^([^.]+)[.]([^.]+)[.]([^.]+)" : $(BOOST_VERSION) ]
141 if $(version-tag[3]) = 0
143 version-tag = $(version-tag[1-2]) ;
146 constant BOOST_VERSION_TAG : $(version-tag:J="_") ;
148 # Option to choose how many variants to build. The default is "minimal".
149 local build-type = [ MATCH "^--build-type=(.*)" : [ modules.peek : ARGV ] ] ;
150 build-type ?= minimal ;
151 if ! ( $(build-type) in minimal complete )
153 ECHO "The value of the --build-type option should be either 'complete' or 'minimal'" ;
157 rule handle-static-runtime ( properties * )
159 # Using static runtime with shared libraries is impossible on Linux,
160 # and dangerous on Windows. Therefore, we disallow it. This might
161 # be drastic, but it was disabled for a while with nobody complaining.
163 # For CW, static runtime is needed so that std::locale works.
164 if <link>shared in $(properties) && <runtime-link>static in $(properties) &&
165 ! ( <toolset>cw in $(properties) )
167 ECHO "error: link=shared together with runtime-link=static is not allowed" ;
168 ECHO "error: such property combination is either impossible " ;
169 ECHO "error: or too dangerious to be of any use" ;
176 : requirements <include>.
177 # Disable auto-linking for all targets here, primarily because it caused
179 <define>BOOST_ALL_NO_LIB=1
180 # Used to encode variant in target name. See the 'tag' rule below.
181 <tag>@$(__name__).tag
182 <conditional>@handle-static-runtime
183 # The standard library Sun compilers use by default has no chance
184 # of working with Boost. Override it.
185 <toolset>sun:<stdlib>sun-stlport
186 : usage-requirements <include>.
191 # Setup convenient aliases for all libraries.
193 all-libraries = [ MATCH .*libs/(.*)/build/.* : [ glob libs/*/build/Jamfile.v2 ]
194 [ glob libs/*/build/Jamfile ] ]
197 all-libraries = [ sequence.unique $(all-libraries) ] ;
198 # The function_types library has a Jamfile, but it's used for maintenance
199 # purposes, there's no library to build and install.
200 all-libraries = [ set.difference $(all-libraries) : function_types ] ;
203 local rule explicit-alias ( id : targets + )
205 alias $(id) : $(targets) ;
210 # First, the complicated libraries: where the target name in Jamfile is
211 # different from its directory name.
212 explicit-alias prg_exec_monitor : libs/test/build//boost_prg_exec_monitor ;
213 explicit-alias test_exec_monitor : libs/test/build//boost_test_exec_monitor ;
214 explicit-alias unit_test_framework : libs/test/build//boost_unit_test_framework ;
215 explicit-alias bgl-vis : libs/graps/build//bgl-vis ;
216 explicit-alias serialization : libs/serialization/build//boost_serialization ;
217 explicit-alias wserialization : libs/serialization/build//boost_wserialization ;
218 for local l in $(all-libraries)
220 if ! $(l) in test graph serialization
222 explicit-alias $(l) : libs/$(l)/build//boost_$(l) ;
226 alias headers : : : : <include>. ;
229 # Decides which libraries are to be installed by looking at --with-<library>
230 # --without-<library> arguments. Returns the list of directories under "libs"
231 # which must be built and installed.
233 rule libraries-to-install ( existing-libraries * )
235 local argv = [ modules.peek : ARGV ] ;
236 local with-parameter = [ MATCH --with-(.*) : $(argv) ] ;
237 local without-parameter = [ MATCH --without-(.*) : $(argv) ] ;
239 if ! $(with-parameter) && ! $(without-parameter)
241 # Nothing is specified on command line. See if maybe
242 # project-config.jam has some choices.
243 local project-config-libs = [ modules.peek project-config : libraries ] ;
244 with-parameter = [ MATCH --with-(.*) : $(project-config-libs) ] ;
245 without-parameter = [ MATCH --without-(.*) : $(project-config-libs) ] ;
249 if $(with-parameter) && $(without-parameter)
251 ECHO "error: both --with-<library> and --without-<library> specified" ;
255 local wrong = [ set.difference $(with-parameter) : $(existing-libraries) ] ;
258 ECHO "error: wrong library name '$(wrong[1])' in the --with-<library> option." ;
261 local wrong = [ set.difference $(without-parameter) : $(existing-libraries) ] ;
264 ECHO "error: wrong library name '$(wrong[1])' in the --without-<library> option." ;
270 return [ set.intersection $(existing-libraries) : $(with-parameter) ] ;
274 return [ set.difference $(existing-libraries) : $(without-parameter) ] ;
279 # What kind of layout are we doing?
280 layout = [ MATCH "^--layout=(.*)" : [ modules.peek : ARGV ] ] ;
281 layout ?= versioned ;
282 layout-$(layout) = true ;
285 # Possible stage only location.
286 local stage-locate = [ MATCH "^--stagedir=(.*)" : [ modules.peek : ARGV ] ] ;
287 stage-locate ?= stage ;
288 path-constant BOOST_STAGE_LOCATE : $(stage-locate) ;
292 local python-root = [ MATCH "^--with-python-root=(.*)" : [ modules.peek : ARGV ]
294 PYTHON_ROOT ?= $(python-root) ;
297 # Select the libraries to install.
298 libraries = [ libraries-to-install $(all-libraries) ] ;
300 if --show-libraries in [ modules.peek : ARGV ]
302 ECHO "The following libraries require building:" ;
303 for local l in $(libraries)
311 local build-id = [ MATCH "^--buildid=(.*)" : [ modules.peek : ARGV ] ] ;
314 constant BUILD_ID : [ regex.replace $(build-id) "[*\\/:.\"\' ]" "_" ] ;
318 # This rule is called by Boost.Build to determine the name of target. We use it
319 # to encode the build variant, compiler name and boost version in the target
322 rule tag ( name : type ? : property-set )
324 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
327 if $(layout) = versioned
329 result = [ common.format-name
330 <base> <toolset> <threading> <runtime> -$(BOOST_VERSION_TAG)
332 : $(name) : $(type) : $(property-set) ] ;
334 else if $(layout) = tagged
336 result = [ common.format-name
337 <base> <threading> <runtime>
339 : $(name) : $(type) : $(property-set) ] ;
341 else if $(layout) = system
343 result = [ common.format-name
346 : $(name) : $(type) : $(property-set) ] ;
350 ECHO "error: invalid layout '$(layout)'" ;
354 # Optionally add version suffix. On NT, library with version suffix
355 # will not be recognized by linkers. On CYGWIN, we get strage
356 # duplicate symbol errors when library is generated with version
357 # suffix. On OSX, version suffix is not needed -- the linker expects
358 # the libFoo.1.2.3.dylib format. AIX linkers do not accept version
359 # suffixes either. Pgi compilers can not accept library with version
361 if $(type) = SHARED_LIB &&
362 ( ! ( [ $(property-set).get <target-os> ] in windows cygwin darwin aix ) &&
363 ! ( [ $(property-set).get <toolset> ] in pgi ) )
365 result = $(result).$(BOOST_VERSION) ;
373 # Install to system location.
375 install-requirements = <install-source-root>$(BOOST_ROOT)/boost ;
377 if $(layout-versioned)
379 install-requirements += <install-header-subdir>boost-$(BOOST_VERSION_TAG)/boost ;
383 install-requirements += <install-header-subdir>boost ;
385 if [ modules.peek : NT ]
387 install-requirements += <install-default-prefix>C:/Boost ;
389 else if [ modules.peek : UNIX ]
391 install-requirements += <install-default-prefix>/usr/local ;
395 # The .SUNWCCh files are present in tr1 include directory and have to be installed,
396 # see http://lists.boost.org/Archives/boost/2007/05/121430.php
397 [ path.glob-tree $(BOOST_ROOT)/boost : *.hpp *.ipp *.h *.inc *.SUNWCCh : CVS .svn ]
398 [ path.glob-tree $(BOOST_ROOT)/boost/compatibility/cpp_c_headers : c* : CVS .svn ]
399 [ path.glob boost/tr1/tr1 : * : bcc32 sun CVS .svn ]
403 package.install install-proper
404 : $(install-requirements) <install-no-version-symlinks>on
406 : libs/$(libraries)/build
409 explicit install-proper ;
411 # Install just library.
413 : libs/$(libraries)/build
414 : <location>$(stage-locate)/lib
415 <install-dependencies>on <install-type>LIB
416 <install-no-version-symlinks>on
418 explicit stage-proper ;
421 if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] )
423 rule make-unversioned-links ( project name ? : property-set : sources * )
428 local nt = [ modules.peek : NT ] ;
430 # Collect the libraries that have the version number in 'filtered'.
431 for local s in $(sources)
436 m = [ MATCH "(.*[.]lib)" : [ $(s).name ] ] ;
440 m = [ MATCH "(.*[.]so[.0-9]+)" "(.*[.]dylib)" "(.*[.]a)" :
449 # Create links without version.
450 for local s in $(filtered)
452 local name = [ $(s).name ] ;
453 local ea = [ $(s).action ] ;
454 local ep = [ $(ea).properties ] ;
455 local a = [ new non-scanning-action $(s) : symlink.ln : $(ep) ] ;
457 local noversion-file ;
460 noversion-file = [ MATCH "(.*)-[0-9_]+(.*[.]lib)" : $(name) ] ;
465 [ MATCH "(.*)-[0-9_]+(.*[.]so)[.0-9]*" : $(name) ]
466 [ MATCH "(.*)-[0-9_]+(.*[.]dylib)" : $(name) ]
467 [ MATCH "(.*)-[0-9_]+(.*[.]a)" : $(name) ]
468 [ MATCH "(.*)-[0-9_]+(.*[.]dll[.]a)" : $(name) ] ;
472 $(noversion-file[1])$(noversion-file[2]) ;
473 result += [ new file-target $(new-name) exact : [ $(s).type ] : $(project)
480 generate stage-unversioned : stage-proper :
481 <generating-rule>@make-unversioned-links ;
482 explicit stage-unversioned ;
484 generate install-unversioned : install-proper :
485 <generating-rule>@make-unversioned-links ;
486 explicit install-unversioned ;
490 # Create do-nothing aliases.
491 alias stage-unversioned ;
492 explicit stage-unversioned ;
493 alias install-unversioned ;
494 explicit install-unversioned ;
497 # This is a special metatarget class that handles the --build-type=complete
499 class top-level-target : alias-target-class
504 rule __init__ ( name : project : sources * : requirements *
505 : default-build * : usage-requirements * )
507 alias-target-class.__init__ $(name) : $(project) : $(sources) :
508 $(requirements) : $(default-build) : $(usage-requirements) ;
510 local m = [ $(project).project-module ] ;
511 self.build-type = [ modules.peek $(m) : build-type ] ;
512 # On Linux, we build release variant by default, since few users will
513 # ever want to debug C++ Boost libraries, and there's no ABI
514 # incompatibility between debug and release variants. We build
515 # shared and static libraries since that's what most packages
516 # seem to provide (.so in libfoo and .a in libfoo-dev).
517 self.minimal-properties = [ property-set.create
518 <variant>release <threading>multi <link>shared <link>static <runtime-link>shared ] ;
519 # On Windows, new IDE projects use:
521 # runtime-link=dynamic, threading=multi, variant=(debug|release)
523 # and in addition, C++ Boost's autolink defaults to static linking.
524 self.minimal-properties-win = [ property-set.create
525 <variant>debug <variant>release <threading>multi <link>static <runtime-link>shared ] ;
527 self.complete-properties = [ property-set.create
528 <variant>debug <variant>release
529 <threading>single <threading>multi
530 <link>shared <link>static
531 <runtime-link>shared <runtime-link>static ] ;
534 rule generate ( property-set )
536 if $(self.build-type) = minimal
540 local os = [ $(property-set).get <target-os> ] ;
541 # Because we completely override parent's 'generate'
542 # we need to check for default value of feature ourself.
545 os = [ feature.defaults <target-os> ] ;
551 expanded = [ targets.apply-default-build $(property-set)
552 : $(self.minimal-properties-win) ] ;
556 expanded = [ targets.apply-default-build $(property-set)
557 : $(self.minimal-properties) ] ;
559 return [ build-multiple $(expanded) ] ;
561 else if $(self.build-type) = complete
563 local expanded = [ targets.apply-default-build $(property-set)
564 : $(self.complete-properties) ] ;
566 # Filter inappopriate combinations
568 for local p in $(expanded)
570 # See comment in handle-static-runtime regarding this logic.
571 if [ $(p).get <link> ] = shared && [ $(p).get <runtime-link> ] = static
572 && [ $(p).get <toolset> ] != cw
581 return [ build-multiple $(filtered) ] ;
585 errors.error "Unknown build type" ;
589 rule build-multiple ( property-sets * )
591 local usage-requirements = [ property-set.empty ] ;
593 for local p in $(property-sets)
595 local r = [ alias-target-class.generate $(p) ] ;
598 usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
602 return $(usage-requirements) [ sequence.unique $(result) ] ;
607 targets.create-metatarget top-level-target : [ project.current ]
609 : install-proper install-unversioned
611 targets.create-metatarget top-level-target : [ project.current ]
613 : stage-proper stage-unversioned
619 stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ;
621 # This target is built by default, and will forward to 'stage'
622 # after producing some explanations.
623 targets.create-metatarget top-level-target : [ project.current ]
630 "\nBuilding C++ Boost.
632 After the build, the headers will be located at
636 The libraries will be located at
640 Use 'bjam install --prefix=<path>' if you wish to install headers and
641 libraries to a different location and remove the source tree.\n\n"
645 # Just build the libraries, don't install them anywhere. This is what happens
646 # with just "bjam --v2".
647 alias build_all : libs/$(libraries)/build ;
650 # This rule should be called from libraries' Jamfiles and will create two
651 # targets, "install" and "stage", that will install or stage that library. The
652 # --prefix option is respected, but --with and --without options, naturally, are
655 # - libraries -- list of library targets to install.
657 rule boost-install ( libraries * )
659 package.install install
660 : <dependency>/boost//install-proper-headers $(install-requirements)
663 : # No headers, it is handled by the dependency.
666 install stage : $(libraries) : <location>$(BOOST_STAGE_LOCATE) ;
668 local c = [ project.current ] ;
669 local project-module = [ $(c).project-module ] ;
670 module $(project-module)
678 # Make project ids of all libraries known.
679 for local l in $(all-libraries)
681 use-project /boost/$(l) : libs/$(l)/build ;