1 # Boost.Build support specific for the Boost C++ Libraries.
2 # Copyright Vladimir Prus 2002-2010.
3 # Copyright Dave Abrahams 2005-2006.
4 # Copyright Rene Rivera 2005-2007.
5 # Copyright Douglas Gregor 2005.
7 # Distributed under the Boost Software License, Version 1.0.
8 # (See accompanying file LICENSE_1_0.txt or copy at
9 # http://www.boost.org/LICENSE_1_0.txt)
11 import "class" : new ;
28 import version : version-less ;
30 ##############################################################################
32 # 0. General setup. Parse options, check them.
34 ##############################################################################
36 BOOST_ROOT = [ modules.binding $(__name__) ] ;
37 BOOST_ROOT = $(BOOST_ROOT:D) ;
39 rule set-version ( version )
41 BOOST_VERSION = $(version) ;
44 [ MATCH "^([^.]+)[.]([^.]+)[.]([^.]+)" : $(BOOST_VERSION) ] ;
45 if $(version-tag[3]) = 0
47 version-tag = $(version-tag[1-2]) ;
49 BOOST_VERSION_TAG = $(version-tag:J=_) ;
52 # Option to choose how many variants to build. The default is "minimal".
53 build-type = [ option.get build-type ] ;
54 build-type ?= minimal ;
55 if ! ( $(build-type) in complete minimal )
57 EXIT The value of the --build-type option should be either 'complete' or
61 # What kind of layout are we doing?
62 layout = [ option.get layout : "" ] ;
64 layout = [ MATCH (versioned|tagged|system)(-(.+))? : $(layout) ] ;
67 layout-version = $(layout[3]) ;
68 layout = $(layout[1]) ;
69 if [ version-less [ regex.split $(layout-version) "[.]" ] : 1 66 ]
71 layout-version = 1.40 ;
73 else if [ version-less [ regex.split $(layout-version) "[.]" ] : 1 69 ]
75 layout-version = 1.66 ;
78 layout-version ?= 1.69 ;
80 # On Windows, we used versioned layout by default in order to be compatible with
81 # autolink. On other systems, we use system layout which is what every other
82 # program uses. Note that the Windows check is static, and will not be affected
83 # by specific build properties used.
95 layout-$(layout) = true ;
97 if $(layout) = system && $(build-type) = complete
99 ECHO error\: Cannot use --layout=system with --build-type complete. ;
100 ECHO error\: Please use either --layout=versioned or --layout=tagged ;
101 ECHO error\: if you wish to build multiple variants. ;
104 ECHO error\: Note that --layout=system is used by default on Unix
105 starting with Boost 1.40. ;
110 # Possible stage only location.
111 stage-locate = [ option.get stagedir ] ;
115 stage-locate = [ path.root [ path.make $(stage-locate) ] [ path.pwd ] ] ;
119 stage-locate = $(BOOST_ROOT)/stage ;
122 BOOST_STAGE_LOCATE = $(stage-locate) ;
125 build-id = [ option.get buildid ] ;
128 BUILD_ID = [ regex.replace $(build-id) "[*\\/:.\"\' ]" _ ] ;
131 # Python build id (for Python libraries only).
132 python-id = [ option.get "python-buildid" ] ;
135 PYTHON_ID = [ regex.replace $(python-id) "[*\\/:.\"\']" _ ] ;
139 if $(layout) = versioned
141 switch $(layout-version)
145 <base> <toolset> <threading> <runtime> ;
148 <base> <toolset> <threading> <runtime> <arch-and-model> ;
151 <base> <toolset> <threading> <runtime> <arch-and-model> ;
154 else if $(layout) = tagged
156 switch $(layout-version)
160 <base> <threading> <runtime> ;
163 <base> <threading> <runtime> ;
166 <base> <threading> <runtime> <arch-and-model> ;
169 else if $(layout) = system
171 .format-name-args = <base> ;
175 .format-name-error = true ;
179 ################################################################################
181 # 1. 'tag' function adding decorations suitable to the properties if versioned
182 # or tagged layout is requested. Called from Jamroot.
184 ################################################################################
186 rule tag ( name : type ? : property-set )
188 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
190 local args = $(.format-name-args) ;
191 if $(layout) = versioned
193 args += -$(BOOST_VERSION_TAG) ;
195 local result = [ common.format-name
197 : $(name) : $(type) : $(property-set) ] ;
198 if $(.format-name-error)
200 EXIT error\: invalid layout '$(layout:E=)' ;
203 # Optionally add version suffix. On NT, library with version suffix will
204 # not be recognized by linkers. On CYGWIN, we get strage duplicate
205 # symbol errors when library is generated with version suffix. On OSX,
206 # version suffix is not needed -- the linker expects the
207 # libFoo.1.2.3.dylib format. AIX linkers do not accept version suffixes
208 # either. Pgi compilers can not accept a library with version suffix.
209 if $(type) = SHARED_LIB &&
210 ! [ $(property-set).get <target-os> ] in windows cygwin darwin aix &&
211 ! [ $(property-set).get <toolset> ] in pgi
213 result = $(result).$(BOOST_VERSION) ;
220 # Specialized tag function to use for libraries linking to Python.
221 # Appends value of --python-buildid if provided.
222 rule python-tag ( name : type ? : property-set )
224 local result = $(name) ;
226 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
228 # Add Python version suffix
230 local version = [ $(property-set).get <python> ] ;
232 local major-minor = [ MATCH "^([0-9]+)\.([0-9]+)" : $(version) ] ;
233 local suffix = $(major-minor:J="") ;
237 result = $(result)$(suffix) ;
240 # Add PYTHON_ID if supplied
244 result = $(result)-$(PYTHON_ID) ;
248 # forward to the boost tagging rule
249 return [ tag $(result) : $(type) : $(property-set) ] ;
252 ################################################################################
254 # 2. Declare targets that build and install all libraries. Specifically:
256 # - 'stage-proper' that puts all libraries in stage/lib
257 # - 'install-proper' that install libraries and headers to system location
259 ################################################################################
261 rule declare_install_and_stage_proper_targets ( libraries * )
263 local p = [ project.current ] ;
265 alias install-proper : libs/$(libraries)/build//install ;
266 $(p).mark-target-as-explicit install-proper ;
268 alias stage-proper : libs/$(libraries)/build//stage ;
269 $(p).mark-target-as-explicit stage-proper ;
273 ################################################################################
275 # 3. Declare top-level targets 'stage' and 'install'. These examine the
276 # --build-type option and, in case it is 'complete', build the 'install-proper'
277 # and 'stage-proper' targets with a number of property sets.
279 ################################################################################
281 class top-level-target : alias-target-class
285 rule __init__ ( name : project : sources * : requirements *
286 : default-build * : usage-requirements * )
288 alias-target-class.__init__ $(name) : $(project) : $(sources) :
289 $(requirements) : $(default-build) : $(usage-requirements) ;
291 self.build-type = [ modules.peek boostcpp : build-type ] ;
292 # On Linux, we build the release variant by default, since few users
293 # will ever want to debug C++ Boost libraries, and there is no ABI
294 # incompatibility between debug and release variants. We build shared
295 # and static libraries since that is what most packages seem to provide
296 # (.so in libfoo and .a in libfoo-dev).
298 self.minimal-properties = [ property-set.create <variant>release
299 <threading>multi <link>shared <link>static <runtime-link>shared ] ;
301 # On Windows, new IDE projects use:
303 # runtime-link=dynamic, threading=multi, variant=(debug|release)
305 # and in addition, C++ Boost's autolink defaults to static linking.
307 self.minimal-properties-win = [ property-set.create <variant>debug
308 <variant>release <threading>multi <link>static <runtime-link>shared
309 <address-model>32 <address-model>64 ] ;
311 self.complete-properties = [ property-set.create
312 <variant>debug <variant>release
314 <link>shared <link>static
315 <runtime-link>shared <runtime-link>static ] ;
317 self.complete-properties-win = [ property-set.create
318 <variant>debug <variant>release
320 <link>shared <link>static
321 <runtime-link>shared <runtime-link>static
322 <address-model>32 <address-model>64 ] ;
325 rule generate ( property-set )
327 modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
330 local os = [ $(property-set).get <target-os> ] ;
332 # Because we completely override the parent's 'generate' we need to
333 # check for default feature values ourselves.
337 os = [ feature.defaults <target-os> ] ;
341 local build-type-set ;
343 if $(self.build-type) = minimal
347 build-type-set = $(self.minimal-properties-win) ;
351 build-type-set = $(self.minimal-properties) ;
354 else if $(self.build-type) = complete
358 build-type-set = $(self.complete-properties-win) ;
362 build-type-set = $(self.complete-properties) ;
368 errors.error "Unknown build type" ;
373 local expanded = [ targets.apply-default-build $(property-set)
374 : $(build-type-set) ] ;
376 # Filter inappopriate combinations.
378 for local p in $(expanded)
380 # See comment in handle-static-runtime regarding this logic.
381 if [ $(p).get <link> ] = shared
382 && [ $(p).get <runtime-link> ] = static
383 && [ $(p).get <toolset> ] != cw
393 return [ build-multiple $(filtered) ] ;
397 rule build-multiple ( property-sets * )
399 local usage-requirements = [ property-set.empty ] ;
401 for local p in $(property-sets)
403 local r = [ alias-target-class.generate $(p) ] ;
406 usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
410 return $(usage-requirements) [ sequence.unique $(result) ] ;
414 rule declare_top_level_targets ( libraries * )
416 declare_install_and_stage_proper_targets $(libraries) ;
418 targets.create-metatarget top-level-target : [ project.current ]
422 targets.create-metatarget top-level-target : [ project.current ]
424 : stage-proper headers
427 p = [ project.current ] ;
428 $(p).mark-target-as-explicit install stage ;
430 # This target is built by default, and will forward to 'stage' after
431 # producing some explanations.
432 targets.create-metatarget top-level-target : [ project.current ]
439 ################################################################################
441 # 4. Add hook to report configuration before the build, and confirmation with
442 # setup instructions after the build.
444 ################################################################################
446 message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
447 local p = [ project.current ] ;
448 $(p).mark-target-as-explicit explain ;
452 local tl = [ modules.peek : top-level-targets ] ;
453 if stage in $(tl) || install in $(tl)
455 # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
456 if PAD in [ RULENAMES ]
458 configure.print-component-configuration ;
462 IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
463 build-system.set-pre-build-hook $(__name__).pre-build ;
465 rule post-build ( ok ? )
467 if forward in [ modules.peek : top-level-targets ]
471 local include-path = [ path.native $(BOOST_ROOT) ] ;
472 local stage-abs = [ path.native $(stage-locate)/lib ] ;
476 The Boost C++ Libraries were successfully built!
478 The following directory should be added to compiler include paths:
482 The following directory should be added to linker library paths:
489 IMPORT $(__name__) : post-build : : $(__name__).post-build ;
490 build-system.set-post-build-hook $(__name__).post-build ;
493 ################################################################################
495 # 5. Top-level setup.
497 ################################################################################
499 # Decides which libraries are to be installed by looking at --with-<library>
500 # --without-<library> arguments. Returns the list of directories under "libs"
501 # which must be built and installed.
503 rule libraries-to-install ( existing-libs * )
505 local argv = [ modules.peek : ARGV ] ;
506 local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
507 local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
509 if ! $(with-parameter) && ! $(without-parameter)
511 # Nothing is specified on command line. See if maybe project-config.jam
513 local libs = [ modules.peek project-config : libraries ] ;
514 with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
515 without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
519 if $(with-parameter) && $(without-parameter)
521 EXIT error\: both --with-<library> and --without-<library> specified ;
524 local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
527 EXIT error\: wrong library name '$(wrong[1])' in the --with-<library>
530 local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
533 EXIT error\: wrong library name '$(wrong[1])' in the --without-<library>
539 return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
543 return [ set.difference $(existing-libs) : $(without-parameter) ] ;
547 rule declare-targets ( all-libraries * )
549 configure.register-components $(all-libraries) ;
551 # Select the libraries to install.
552 libraries = [ libraries-to-install $(all-libraries) ] ;
553 configure.components-building $(libraries) ;
555 if [ option.get "show-libraries" : : true ]
557 ECHO The following libraries require building\: ;
558 for local l in $(libraries)
565 declare_top_level_targets $(libraries) ;
568 # Returns the properties identifying the toolset. We'll use them
569 # below to configure checks. These are essentially same as in
570 # configure.builds, except we don't use address-model and
571 # architecture - as we're trying to detect them here.
573 rule toolset-properties ( properties * )
575 local toolset = [ property.select <toolset> : $(properties) ] ;
576 local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
577 return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
580 feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ;
581 feature.compose <deduced-address-model>32 : <address-model>32 ;
582 feature.compose <deduced-address-model>64 : <address-model>64 ;
584 rule deduce-address-model ( properties * )
587 local filtered = [ toolset-properties $(properties) ] ;
588 local names = 32 64 ;
589 local idx = [ configure.find-builds "default address-model" : $(filtered)
590 : /boost/architecture//32 "32-bit"
591 : /boost/architecture//64 "64-bit" ] ;
592 result = $(names[$(idx)]) ;
596 # Normally, returning composite feature here is equivalent to forcing
597 # consituent properties as well. But we only want to indicate toolset
598 # deduced default, so also pick whatever address-model is explicitly
600 result = <deduced-address-model>$(result) [ property.select <address-model> : $(properties) ] ;
605 rule address-model ( )
607 return <conditional>@boostcpp.deduce-address-model ;
610 local deducable-architectures = arm mips1 power riscv s390x sparc x86 combined ;
611 feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ;
612 for a in $(deducable-architectures)
614 feature.compose <deduced-architecture>$(a) : <architecture>$(a) ;
617 rule deduce-architecture ( properties * )
620 local filtered = [ toolset-properties $(properties) ] ;
621 local names = arm mips1 power riscv s390x sparc x86 combined ;
622 local idx = [ configure.find-builds "default architecture" : $(filtered)
623 : /boost/architecture//arm
624 : /boost/architecture//mips1
625 : /boost/architecture//power
626 : /boost/architecture//riscv
627 : /boost/architecture//s390x
628 : /boost/architecture//sparc
629 : /boost/architecture//x86
630 : /boost/architecture//combined ] ;
631 result = $(names[$(idx)]) ;
635 # See comment in deduce-address-model.
636 result = <deduced-architecture>$(result) [ property.select <architecture> : $(properties) ] ;
641 rule architecture ( )
643 return <conditional>@boostcpp.deduce-architecture ;