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> -$(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).
362 self.minimal-properties = [ property-set.create <variant>release
363 <threading>multi <link>shared <link>static <runtime-link>shared ] ;
364 # On Windows, new IDE projects use:
366 # runtime-link=dynamic, threading=multi, variant=(debug|release)
368 # and in addition, C++ Boost's autolink defaults to static linking.
369 self.minimal-properties-win = [ property-set.create <variant>debug
370 <variant>release <threading>multi <link>static <runtime-link>shared
373 self.complete-properties = [ property-set.create
374 <variant>debug <variant>release
375 <threading>single <threading>multi
376 <link>shared <link>static
377 <runtime-link>shared <runtime-link>static ] ;
380 rule generate ( property-set )
382 modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
384 if $(self.build-type) = minimal
388 local os = [ $(property-set).get <target-os> ] ;
389 # Because we completely override the parent's 'generate' we need to
390 # check for default feature values ourselves.
393 os = [ feature.defaults <target-os> ] ;
399 expanded = [ targets.apply-default-build $(property-set)
400 : $(self.minimal-properties-win) ] ;
404 expanded = [ targets.apply-default-build $(property-set)
405 : $(self.minimal-properties) ] ;
407 return [ build-multiple $(expanded) ] ;
409 else if $(self.build-type) = complete
411 local expanded = [ targets.apply-default-build $(property-set)
412 : $(self.complete-properties) ] ;
414 # Filter inappopriate combinations.
416 for local p in $(expanded)
418 # See comment in handle-static-runtime regarding this logic.
419 if [ $(p).get <link> ] = shared
420 && [ $(p).get <runtime-link> ] = static
421 && [ $(p).get <toolset> ] != cw
430 return [ build-multiple $(filtered) ] ;
435 errors.error "Unknown build type" ;
439 rule build-multiple ( property-sets * )
441 local usage-requirements = [ property-set.empty ] ;
443 for local p in $(property-sets)
445 local r = [ alias-target-class.generate $(p) ] ;
448 usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
452 return $(usage-requirements) [ sequence.unique $(result) ] ;
456 rule declare_top_level_targets ( libraries * : headers * )
458 declare_install_and_stage_proper_targets $(libraries) : $(headers) ;
460 targets.create-metatarget top-level-target : [ project.current ]
462 : install-proper install-unversioned
464 targets.create-metatarget top-level-target : [ project.current ]
466 : stage-proper stage-unversioned
469 p = [ project.current ] ;
470 $(p).mark-target-as-explicit install stage ;
472 # This target is built by default, and will forward to 'stage' after
473 # producing some explanations.
474 targets.create-metatarget top-level-target : [ project.current ]
481 stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ;
484 ################################################################################
486 # 4. Add hook to report configuration before the build, and confirmation with
487 # setup instructions after the build.
489 ################################################################################
491 message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
492 local p = [ project.current ] ;
493 $(p).mark-target-as-explicit explain ;
497 local tl = [ modules.peek : top-level-targets ] ;
498 if stage in $(tl) || install in $(tl)
500 # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
501 if PAD in [ RULENAMES ]
503 configure.print-component-configuration ;
507 IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
508 build-system.set-pre-build-hook $(__name__).pre-build ;
510 # FIXME: Revise stage_abs.
511 rule post-build ( ok ? )
513 if forward in [ modules.peek : top-level-targets ]
517 local include-path = [ path.native $(BOOST_ROOT) ] ;
520 The Boost C++ Libraries were successfully built!
522 The following directory should be added to compiler include paths:
526 The following directory should be added to linker library paths:
533 IMPORT $(__name__) : post-build : : $(__name__).post-build ;
534 build-system.set-post-build-hook $(__name__).post-build ;
537 ################################################################################
539 # 5. Top-level setup.
541 ################################################################################
543 # Decides which libraries are to be installed by looking at --with-<library>
544 # --without-<library> arguments. Returns the list of directories under "libs"
545 # which must be built and installed.
547 rule libraries-to-install ( existing-libs * )
549 local argv = [ modules.peek : ARGV ] ;
550 local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
551 local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
553 if ! $(with-parameter) && ! $(without-parameter)
555 # Nothing is specified on command line. See if maybe project-config.jam
557 local libs = [ modules.peek project-config : libraries ] ;
558 with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
559 without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
563 if $(with-parameter) && $(without-parameter)
565 EXIT error: both --with-<library> and --without-<library> specified ;
568 local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
571 EXIT error: wrong library name '$(wrong[1])' in the --with-<library>
574 local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
577 EXIT error: wrong library name '$(wrong[1])' in the --without-<library>
583 return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
587 return [ set.difference $(existing-libs) : $(without-parameter) ] ;
591 rule declare-targets ( all-libraries * : headers * )
593 configure.register-components $(all-libraries) ;
595 # Select the libraries to install.
596 libraries = [ libraries-to-install $(all-libraries) ] ;
597 configure.components-building $(libraries) ;
599 if [ option.get "show-libraries" : : true ]
601 ECHO The following libraries require building: ;
602 for local l in $(libraries)
609 declare_top_level_targets $(libraries) : $(headers) ;
612 # Returns the properties identifying the toolset. We'll use them
613 # below to configure checks. These are essentially same as in
614 # configure.builds, except we don't use address-model and
615 # architecture - as we're trying to detect them here.
617 rule toolset-properties ( properties * )
619 local toolset = [ property.select <toolset> : $(properties) ] ;
620 local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
621 return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
624 feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ;
625 feature.compose <deduced-address-model>32 : <address-model>32 ;
626 feature.compose <deduced-address-model>64 : <address-model>64 ;
628 rule deduce-address-model ( properties * )
631 local filtered = [ toolset-properties $(properties) ] ;
633 if [ configure.builds /boost/architecture//32 : $(filtered) : 32-bit ]
637 else if [ configure.builds /boost/architecture//64 : $(filtered) : 64-bit ]
644 # Normally, returning composite feature here is equivalent to forcing
645 # consituent properties as well. But we only want to indicate toolset
646 # deduced default, so also pick whatever address-model is explicitly
648 result = <deduced-address-model>$(result) [ property.select <address-model> : $(properties) ] ;
653 rule address-model ( )
655 return <conditional>@boostcpp.deduce-address-model ;
658 local deducable-architectures = arm mips1 power sparc x86 combined ;
659 feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ;
660 for a in $(deducable-architectures)
662 feature.compose <deduced-architecture>$(a) : <architecture>$(a) ;
665 rule deduce-architecture ( properties * )
668 local filtered = [ toolset-properties $(properties) ] ;
669 if [ configure.builds /boost/architecture//arm : $(filtered) : arm ]
673 else if [ configure.builds /boost/architecture//mips1 : $(filtered) : mips1 ]
677 else if [ configure.builds /boost/architecture//power : $(filtered) : power ]
681 else if [ configure.builds /boost/architecture//sparc : $(filtered) : sparc ]
685 else if [ configure.builds /boost/architecture//x86 : $(filtered) : x86 ]
689 else if [ configure.builds /boost/architecture//combined : $(filtered) : combined ]
696 # See comment in deduce-address-model.
697 result = <deduced-architecture>$(result) [ property.select <architecture> : $(properties) ] ;
702 rule architecture ( )
704 return <conditional>@boostcpp.deduce-architecture ;