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 ##############################################################################
30 # 0. General setup. Parse options, check them.
32 ##############################################################################
34 BOOST_ROOT = [ modules.binding $(__name__) ] ;
35 BOOST_ROOT = $(BOOST_ROOT:D) ;
37 rule set-version ( version )
39 BOOST_VERSION = $(version) ;
41 local version-tag = [ MATCH ^([^.]+)[.]([^.]+)[.]([^.]+) : $(BOOST_VERSION)
43 if $(version-tag[3]) = 0
45 version-tag = $(version-tag[1-2]) ;
47 BOOST_VERSION_TAG = $(version-tag:J=_) ;
50 # Option to choose how many variants to build. The default is "minimal".
51 build-type = [ option.get build-type ] ;
52 build-type ?= minimal ;
53 if ! ( $(build-type) in complete minimal )
55 EXIT The value of the --build-type option should be either 'complete' or
59 # What kind of layout are we doing?
60 layout = [ option.get layout : "" ] ;
61 # On Windows, we used versioned layout by default in order to be compatible with
62 # autolink. On other systems, we use system layout which is what every other
63 # program uses. Note that the Windows check is static, and will not be affected
64 # by specific build properties used.
76 layout-$(layout) = true ;
78 if $(layout) = system && $(build-type) = complete
80 ECHO error: Cannot use --layout=system with --build-type complete. ;
81 ECHO error: Please use either --layout=versioned or --layout=tagged ;
82 ECHO error: if you wish to build multiple variants. ;
85 ECHO error: Note that --layout=system is used by default on Unix
86 starting with Boost 1.40. ;
91 # Possible stage only location.
92 stage-locate = [ option.get stagedir ] ;
93 stage-locate ?= stage ;
94 BOOST_STAGE_LOCATE = $(stage-locate) ;
97 build-id = [ option.get buildid ] ;
100 BUILD_ID = [ regex.replace $(build-id) "[*\\/:.\"\' ]" _ ] ;
103 # Python build id (for Python libraries only).
104 python-id = [ option.get "python-buildid" ] ;
107 PYTHON_ID = [ regex.replace $(python-id) [*\\/:.\"\'] _ ] ;
111 ################################################################################
113 # 1. 'tag' function adding decorations suitable to the properties if versioned
114 # or tagged layout is requested. Called from Jamroot.
116 ################################################################################
118 rule tag ( name : type ? : property-set )
120 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
123 if $(layout) = versioned
125 result = [ common.format-name
126 <base> <toolset> <threading> <runtime> <arch-and-model> -$(BOOST_VERSION_TAG)
128 : $(name) : $(type) : $(property-set) ] ;
130 else if $(layout) = tagged
132 result = [ common.format-name
133 <base> <threading> <runtime>
135 : $(name) : $(type) : $(property-set) ] ;
137 else if $(layout) = system
139 result = [ common.format-name
142 : $(name) : $(type) : $(property-set) ] ;
146 EXIT error: invalid layout '$(layout:E=)' ;
149 # Optionally add version suffix. On NT, library with version suffix will
150 # not be recognized by linkers. On CYGWIN, we get strage duplicate
151 # symbol errors when library is generated with version suffix. On OSX,
152 # version suffix is not needed -- the linker expects the
153 # libFoo.1.2.3.dylib format. AIX linkers do not accept version suffixes
154 # either. Pgi compilers can not accept a library with version suffix.
155 if $(type) = SHARED_LIB &&
156 ! [ $(property-set).get <target-os> ] in windows cygwin darwin aix &&
157 ! [ $(property-set).get <toolset> ] in pgi
159 result = $(result).$(BOOST_VERSION) ;
166 # Specialized tag function to use for libraries linking to Python.
167 # Appends value of --python-buildid if provided.
168 rule python-tag ( name : type ? : property-set )
170 local result = $(name) ;
171 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB && $(PYTHON_ID)
173 result = $(result)-$(PYTHON_ID) ;
176 # forward to the boost tagging rule
177 return [ tag $(result) : $(type) : $(property-set) ] ;
180 ################################################################################
182 # 2. Declare targets that build and install all libraries. Specifically:
184 # - 'stage-proper' that puts all libraries in stage/lib
185 # - 'install-proper' that install libraries and headers to system location
186 # - 'stage-unversioned' that creates links to libraries without boost version
188 # - 'install-unversioned' which creates unversioned linked to installed
191 ################################################################################
193 # Worker function suitable to the 'generate' metatarget. Creates a link to
194 # 'source', striping any version number information from the name.
195 rule make-unversioned-links ( project name ? : property-set : sources * )
198 if [ modules.peek : NT ]
200 filter = (.*[.]lib) ;
211 for local s in $(sources)
213 local m = [ MATCH ^(.*)-[0-9_]+$(filter)$ : [ $(s).name ] ] ;
216 local ea = [ $(s).action ] ;
217 local ep = [ $(ea).properties ] ;
218 local a = [ new non-scanning-action $(s) : symlink.ln : $(ep) ] ;
219 result += [ new file-target $(m:J=) exact : [ $(s).type ] :
220 $(project) : $(a) ] ;
226 rule filtered-target ( name : message + : sources + : requirements * )
228 message $(name)-message : warning: $(message) ;
229 alias $(name) : $(sources) : $(requirements) ;
230 alias $(name) : $(name)-message ;
232 local p = [ project.current ] ;
233 $(p).mark-target-as-explicit $(name) ;
234 $(p).mark-target-as-explicit $(name)-message ;
237 rule declare_install_and_stage_proper_targets ( libraries * : headers * )
239 local p = [ project.current ] ;
240 for local l in $(libraries)
244 filtered-target $(l)-for-install :
245 Skipping Boost.Locale library with threading=single. :
246 libs/$(l)/build : <threading>multi ;
250 filtered-target $(l)-for-install :
251 Skipping Boost.Wave library with threading=single. :
252 libs/$(l)/build : <threading>multi ;
254 else if $(l) = thread
256 filtered-target $(l)-for-install :
257 Skipping Boost.Thread library with threading=single. :
258 libs/$(l)/build : <threading>multi ;
262 alias $(l)-for-install : libs/$(l)/build ;
263 $(p).mark-target-as-explicit $(l)-for-install ;
266 local library-targets = $(libraries)-for-install ;
268 install-requirements = <install-source-root>$(BOOST_ROOT)/boost ;
270 if $(layout-versioned)
272 install-requirements +=
273 <install-header-subdir>boost-$(BOOST_VERSION_TAG)/boost ;
277 install-requirements += <install-header-subdir>boost ;
282 install-requirements += <install-default-prefix>C:/Boost ;
286 install-requirements += <install-default-prefix>/usr/local ;
289 p = [ project.current ] ;
292 package.install install-proper
293 : $(install-requirements) <install-no-version-symlinks>on
295 : $(libraries)-for-install
298 $(p).mark-target-as-explicit install-proper ;
300 # Install just library.
302 : $(libraries)-for-install
303 : <location>$(stage-locate)/lib
304 <install-dependencies>on <install-type>LIB
305 <install-no-version-symlinks>on
307 $(p).mark-target-as-explicit stage-proper ;
309 # Commented out as it does not seem to work. Whoever wrote this originally,
310 # left some typos in the code, but when that got corrected and the code got
311 # enabled - it started reporting ambiguous/duplicate target Boost Build
312 # errors. Anyone requiring unversioned staged libraries needs to correct
313 # those errors before reenabling this code. For more detailed information
314 # see the related Boost library development mailing list thread at
315 # 'http://lists.boost.org/Archives/boost/2012/06/194312.php'.
316 # (06.07.2012.) (Jurko)
317 #~ if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] )
319 #~ generate stage-unversioned : stage-proper :
320 #~ <generating-rule>@boostcpp.make-unversioned-links ;
321 #~ $(p).mark-target-as-explicit stage-unversioned ;
323 #~ generate install-unversioned : install-proper :
324 #~ <generating-rule>@boostcpp.make-unversioned-links ;
325 #~ $(p).mark-target-as-explicit install-unversioned ;
329 # Create do-nothing aliases.
330 alias stage-unversioned ;
331 $(p).mark-target-as-explicit stage-unversioned ;
332 alias install-unversioned ;
333 $(p).mark-target-as-explicit install-unversioned ;
338 ################################################################################
340 # 3. Declare top-level targets 'stage' and 'install'. These examine the
341 # --build-type option and, in case it is 'complete', build the 'install-proper'
342 # and 'stage-proper' targets with a number of property sets.
344 ################################################################################
346 class top-level-target : alias-target-class
350 rule __init__ ( name : project : sources * : requirements *
351 : default-build * : usage-requirements * )
353 alias-target-class.__init__ $(name) : $(project) : $(sources) :
354 $(requirements) : $(default-build) : $(usage-requirements) ;
356 self.build-type = [ modules.peek boostcpp : build-type ] ;
357 # On Linux, we build the release variant by default, since few users
358 # will ever want to debug C++ Boost libraries, and there is no ABI
359 # incompatibility between debug and release variants. We build shared
360 # and static libraries since that is what most packages seem to provide
361 # (.so in libfoo and .a in libfoo-dev).
363 self.minimal-properties = [ property-set.create <variant>release
364 <threading>multi <link>shared <link>static <runtime-link>shared ] ;
366 # On Windows, new IDE projects use:
368 # runtime-link=dynamic, threading=multi, variant=(debug|release)
370 # and in addition, C++ Boost's autolink defaults to static linking.
372 self.minimal-properties-win = [ property-set.create <variant>debug
373 <variant>release <threading>multi <link>static <runtime-link>shared
374 <address-model>32 <address-model>64 ] ;
376 self.complete-properties = [ property-set.create
377 <variant>debug <variant>release
379 <link>shared <link>static
380 <runtime-link>shared <runtime-link>static ] ;
382 self.complete-properties-win = [ property-set.create
383 <variant>debug <variant>release
385 <link>shared <link>static
386 <runtime-link>shared <runtime-link>static
387 <address-model>32 <address-model>64 ] ;
390 rule generate ( property-set )
392 modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
395 local os = [ $(property-set).get <target-os> ] ;
397 # Because we completely override the parent's 'generate' we need to
398 # check for default feature values ourselves.
402 os = [ feature.defaults <target-os> ] ;
406 local build-type-set ;
408 if $(self.build-type) = minimal
412 build-type-set = $(self.minimal-properties-win) ;
416 build-type-set = $(self.minimal-properties) ;
419 else if $(self.build-type) = complete
423 build-type-set = $(self.complete-properties-win) ;
427 build-type-set = $(self.complete-properties) ;
433 errors.error "Unknown build type" ;
438 local expanded = [ targets.apply-default-build $(property-set)
439 : $(build-type-set) ] ;
441 # Filter inappopriate combinations.
443 for local p in $(expanded)
445 # See comment in handle-static-runtime regarding this logic.
446 if [ $(p).get <link> ] = shared
447 && [ $(p).get <runtime-link> ] = static
448 && [ $(p).get <toolset> ] != cw
458 return [ build-multiple $(filtered) ] ;
462 rule build-multiple ( property-sets * )
464 local usage-requirements = [ property-set.empty ] ;
466 for local p in $(property-sets)
468 local r = [ alias-target-class.generate $(p) ] ;
471 usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
475 return $(usage-requirements) [ sequence.unique $(result) ] ;
479 rule declare_top_level_targets ( libraries * : headers * )
481 declare_install_and_stage_proper_targets $(libraries) : $(headers) ;
483 targets.create-metatarget top-level-target : [ project.current ]
485 : install-proper install-unversioned
487 targets.create-metatarget top-level-target : [ project.current ]
489 : stage-proper stage-unversioned
492 p = [ project.current ] ;
493 $(p).mark-target-as-explicit install stage ;
495 # This target is built by default, and will forward to 'stage' after
496 # producing some explanations.
497 targets.create-metatarget top-level-target : [ project.current ]
504 stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ;
507 ################################################################################
509 # 4. Add hook to report configuration before the build, and confirmation with
510 # setup instructions after the build.
512 ################################################################################
514 message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
515 local p = [ project.current ] ;
516 $(p).mark-target-as-explicit explain ;
520 local tl = [ modules.peek : top-level-targets ] ;
521 if stage in $(tl) || install in $(tl)
523 # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
524 if PAD in [ RULENAMES ]
526 configure.print-component-configuration ;
530 IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
531 build-system.set-pre-build-hook $(__name__).pre-build ;
533 # FIXME: Revise stage_abs.
534 rule post-build ( ok ? )
536 if forward in [ modules.peek : top-level-targets ]
540 local include-path = [ path.native $(BOOST_ROOT) ] ;
543 The Boost C++ Libraries were successfully built!
545 The following directory should be added to compiler include paths:
549 The following directory should be added to linker library paths:
556 IMPORT $(__name__) : post-build : : $(__name__).post-build ;
557 build-system.set-post-build-hook $(__name__).post-build ;
560 ################################################################################
562 # 5. Top-level setup.
564 ################################################################################
566 # Decides which libraries are to be installed by looking at --with-<library>
567 # --without-<library> arguments. Returns the list of directories under "libs"
568 # which must be built and installed.
570 rule libraries-to-install ( existing-libs * )
572 local argv = [ modules.peek : ARGV ] ;
573 local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
574 local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
576 if ! $(with-parameter) && ! $(without-parameter)
578 # Nothing is specified on command line. See if maybe project-config.jam
580 local libs = [ modules.peek project-config : libraries ] ;
581 with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
582 without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
586 if $(with-parameter) && $(without-parameter)
588 EXIT error: both --with-<library> and --without-<library> specified ;
591 local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
594 EXIT error: wrong library name '$(wrong[1])' in the --with-<library>
597 local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
600 EXIT error: wrong library name '$(wrong[1])' in the --without-<library>
606 return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
610 return [ set.difference $(existing-libs) : $(without-parameter) ] ;
614 rule declare-targets ( all-libraries * : headers * )
616 configure.register-components $(all-libraries) ;
618 # Select the libraries to install.
619 libraries = [ libraries-to-install $(all-libraries) ] ;
620 configure.components-building $(libraries) ;
622 if [ option.get "show-libraries" : : true ]
624 ECHO The following libraries require building: ;
625 for local l in $(libraries)
632 declare_top_level_targets $(libraries) : $(headers) ;
635 # Returns the properties identifying the toolset. We'll use them
636 # below to configure checks. These are essentially same as in
637 # configure.builds, except we don't use address-model and
638 # architecture - as we're trying to detect them here.
640 rule toolset-properties ( properties * )
642 local toolset = [ property.select <toolset> : $(properties) ] ;
643 local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
644 return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
647 feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ;
648 feature.compose <deduced-address-model>32 : <address-model>32 ;
649 feature.compose <deduced-address-model>64 : <address-model>64 ;
651 rule deduce-address-model ( properties * )
654 local filtered = [ toolset-properties $(properties) ] ;
656 if [ configure.builds /boost/architecture//32 : $(filtered) : 32-bit ]
660 else if [ configure.builds /boost/architecture//64 : $(filtered) : 64-bit ]
667 # Normally, returning composite feature here is equivalent to forcing
668 # consituent properties as well. But we only want to indicate toolset
669 # deduced default, so also pick whatever address-model is explicitly
671 result = <deduced-address-model>$(result) [ property.select <address-model> : $(properties) ] ;
676 rule address-model ( )
678 return <conditional>@boostcpp.deduce-address-model ;
681 local deducable-architectures = arm mips1 power sparc x86 combined ;
682 feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ;
683 for a in $(deducable-architectures)
685 feature.compose <deduced-architecture>$(a) : <architecture>$(a) ;
688 rule deduce-architecture ( properties * )
691 local filtered = [ toolset-properties $(properties) ] ;
692 if [ configure.builds /boost/architecture//arm : $(filtered) : arm ]
696 else if [ configure.builds /boost/architecture//mips1 : $(filtered) : mips1 ]
700 else if [ configure.builds /boost/architecture//power : $(filtered) : power ]
704 else if [ configure.builds /boost/architecture//sparc : $(filtered) : sparc ]
708 else if [ configure.builds /boost/architecture//x86 : $(filtered) : x86 ]
712 else if [ configure.builds /boost/architecture//combined : $(filtered) : combined ]
719 # See comment in deduce-address-model.
720 result = <deduced-architecture>$(result) [ property.select <architecture> : $(properties) ] ;
725 rule architecture ( )
727 return <conditional>@boostcpp.deduce-architecture ;