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. 6# 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) 10 11import "class" : new ; 12import common ; 13import configure ; 14import build-system ; 15import generate ; 16import modules ; 17import option ; 18import os ; 19import package ; 20import path ; 21import project ; 22import regex ; 23import set ; 24import targets ; 25import feature ; 26import property ; 27 28############################################################################## 29# 30# 0. General setup. Parse options, check them. 31# 32############################################################################## 33 34BOOST_ROOT = [ modules.binding $(__name__) ] ; 35BOOST_ROOT = $(BOOST_ROOT:D) ; 36 37rule set-version ( version ) 38{ 39 BOOST_VERSION = $(version) ; 40 41 local version-tag = [ MATCH ^([^.]+)[.]([^.]+)[.]([^.]+) : $(BOOST_VERSION) 42 ] ; 43 if $(version-tag[3]) = 0 44 { 45 version-tag = $(version-tag[1-2]) ; 46 } 47 BOOST_VERSION_TAG = $(version-tag:J=_) ; 48} 49 50# Option to choose how many variants to build. The default is "minimal". 51build-type = [ option.get build-type ] ; 52build-type ?= minimal ; 53if ! ( $(build-type) in complete minimal ) 54{ 55 EXIT The value of the --build-type option should be either 'complete' or 56 'minimal' ; 57} 58 59# What kind of layout are we doing? 60layout = [ 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. 65if ! $(layout) 66{ 67 if [ os.name ] = NT 68 { 69 layout = versioned ; 70 } 71 else 72 { 73 layout = system ; 74 } 75} 76layout-$(layout) = true ; 77 78if $(layout) = system && $(build-type) = complete 79{ 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. ; 83 if [ os.name ] != NT 84 { 85 ECHO error: Note that --layout=system is used by default on Unix 86 starting with Boost 1.40. ; 87 } 88 EXIT ; 89} 90 91# Possible stage only location. 92stage-locate = [ option.get stagedir ] ; 93stage-locate ?= stage ; 94BOOST_STAGE_LOCATE = $(stage-locate) ; 95 96# Custom build ID. 97build-id = [ option.get buildid ] ; 98if $(build-id) 99{ 100 BUILD_ID = [ regex.replace $(build-id) "[*\\/:.\"\' ]" _ ] ; 101} 102 103# Python build id (for Python libraries only). 104python-id = [ option.get "python-buildid" ] ; 105if $(python-id) 106{ 107 PYTHON_ID = [ regex.replace $(python-id) [*\\/:.\"\'] _ ] ; 108} 109 110 111################################################################################ 112# 113# 1. 'tag' function adding decorations suitable to the properties if versioned 114# or tagged layout is requested. Called from Jamroot. 115# 116################################################################################ 117 118rule tag ( name : type ? : property-set ) 119{ 120 if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB 121 { 122 local result ; 123 if $(layout) = versioned 124 { 125 result = [ common.format-name 126 <base> <toolset> <threading> <runtime> -$(BOOST_VERSION_TAG) 127 -$(BUILD_ID) 128 : $(name) : $(type) : $(property-set) ] ; 129 } 130 else if $(layout) = tagged 131 { 132 result = [ common.format-name 133 <base> <threading> <runtime> 134 -$(BUILD_ID) 135 : $(name) : $(type) : $(property-set) ] ; 136 } 137 else if $(layout) = system 138 { 139 result = [ common.format-name 140 <base> 141 -$(BUILD_ID) 142 : $(name) : $(type) : $(property-set) ] ; 143 } 144 else 145 { 146 EXIT error: invalid layout '$(layout:E=)' ; 147 } 148 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 158 { 159 result = $(result).$(BOOST_VERSION) ; 160 } 161 162 return $(result) ; 163 } 164} 165 166 167################################################################################ 168# 169# 2. Declare targets that build and install all libraries. Specifically: 170# 171# - 'stage-proper' that puts all libraries in stage/lib 172# - 'install-proper' that install libraries and headers to system location 173# - 'stage-unversioned' that creates links to libraries without boost version 174# in name 175# - 'install-unversioned' which creates unversioned linked to installed 176# libraries. 177# 178################################################################################ 179 180# Worker function suitable to the 'generate' metatarget. Creates a link to 181# 'source', striping any version number information from the name. 182rule make-unversioned-links ( project name ? : property-set : sources * ) 183{ 184 local filter ; 185 if [ modules.peek : NT ] 186 { 187 filter = (.*[.]lib) ; 188 } 189 else 190 { 191 filter = 192 (.*[.]so)[.0-9]* 193 (.*[.]dylib) 194 (.*[.]a) ; 195 } 196 197 local result ; 198 for local s in $(sources) 199 { 200 local m = [ MATCH ^(.*)-[0-9_]+$(filter)$ : [ $(s).name ] ] ; 201 if $(m) 202 { 203 local ea = [ $(s).action ] ; 204 local ep = [ $(ea).properties ] ; 205 local a = [ new non-scanning-action $(s) : symlink.ln : $(ep) ] ; 206 result += [ new file-target $(m:J=) exact : [ $(s).type ] : 207 $(project) : $(a) ] ; 208 } 209 } 210 return $(result) ; 211} 212 213rule filtered-target ( name : message + : sources + : requirements * ) 214{ 215 message $(name)-message : warning: $(message) ; 216 alias $(name) : $(sources) : $(requirements) ; 217 alias $(name) : $(name)-message ; 218 219 local p = [ project.current ] ; 220 $(p).mark-target-as-explicit $(name) ; 221 $(p).mark-target-as-explicit $(name)-message ; 222} 223 224rule declare_install_and_stage_proper_targets ( libraries * : headers * ) 225{ 226 local p = [ project.current ] ; 227 for local l in $(libraries) 228 { 229 if $(l) = locale 230 { 231 filtered-target $(l)-for-install : 232 Skipping Boost.Locale library with threading=single. : 233 libs/$(l)/build : <threading>multi ; 234 } 235 else if $(l) = wave 236 { 237 filtered-target $(l)-for-install : 238 Skipping Boost.Wave library with threading=single. : 239 libs/$(l)/build : <threading>multi ; 240 } 241 else if $(l) = thread 242 { 243 filtered-target $(l)-for-install : 244 Skipping Boost.Thread library with threading=single. : 245 libs/$(l)/build : <threading>multi ; 246 } 247 else 248 { 249 alias $(l)-for-install : libs/$(l)/build ; 250 $(p).mark-target-as-explicit $(l)-for-install ; 251 } 252 } 253 local library-targets = $(libraries)-for-install ; 254 255 install-requirements = <install-source-root>$(BOOST_ROOT)/boost ; 256 257 if $(layout-versioned) 258 { 259 install-requirements += 260 <install-header-subdir>boost-$(BOOST_VERSION_TAG)/boost ; 261 } 262 else 263 { 264 install-requirements += <install-header-subdir>boost ; 265 } 266 267 if [ os.name ] = NT 268 { 269 install-requirements += <install-default-prefix>C:/Boost ; 270 } 271 else 272 { 273 install-requirements += <install-default-prefix>/usr/local ; 274 } 275 276 p = [ project.current ] ; 277 278 # Complete install. 279 package.install install-proper 280 : $(install-requirements) <install-no-version-symlinks>on 281 : 282 : $(libraries)-for-install 283 : $(headers) 284 ; 285 $(p).mark-target-as-explicit install-proper ; 286 287 # Install just library. 288 install stage-proper 289 : $(libraries)-for-install 290 : <location>$(stage-locate)/lib 291 <install-dependencies>on <install-type>LIB 292 <install-no-version-symlinks>on 293 ; 294 $(p).mark-target-as-explicit stage-proper ; 295 296 # Commented out as it does not seem to work. Whoever wrote this originally, 297 # left some typos in the code, but when that got corrected and the code got 298 # enabled - it started reporting ambiguous/duplicate target Boost Build 299 # errors. Anyone requiring unversioned staged libraries needs to correct 300 # those errors before reenabling this code. For more detailed information 301 # see the related Boost library development mailing list thread at 302 # 'http://lists.boost.org/Archives/boost/2012/06/194312.php'. 303 # (06.07.2012.) (Jurko) 304 #~ if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] ) 305 #~ { 306 #~ generate stage-unversioned : stage-proper : 307 #~ <generating-rule>@boostcpp.make-unversioned-links ; 308 #~ $(p).mark-target-as-explicit stage-unversioned ; 309 #~ 310 #~ generate install-unversioned : install-proper : 311 #~ <generating-rule>@boostcpp.make-unversioned-links ; 312 #~ $(p).mark-target-as-explicit install-unversioned ; 313 #~ } 314 #~ else 315 { 316 # Create do-nothing aliases. 317 alias stage-unversioned ; 318 $(p).mark-target-as-explicit stage-unversioned ; 319 alias install-unversioned ; 320 $(p).mark-target-as-explicit install-unversioned ; 321 } 322} 323 324 325################################################################################ 326# 327# 3. Declare top-level targets 'stage' and 'install'. These examine the 328# --build-type option and, in case it is 'complete', build the 'install-proper' 329# and 'stage-proper' targets with a number of property sets. 330# 331################################################################################ 332 333class top-level-target : alias-target-class 334{ 335 import modules ; 336 337 rule __init__ ( name : project : sources * : requirements * 338 : default-build * : usage-requirements * ) 339 { 340 alias-target-class.__init__ $(name) : $(project) : $(sources) : 341 $(requirements) : $(default-build) : $(usage-requirements) ; 342 343 self.build-type = [ modules.peek boostcpp : build-type ] ; 344 # On Linux, we build the release variant by default, since few users 345 # will ever want to debug C++ Boost libraries, and there is no ABI 346 # incompatibility between debug and release variants. We build shared 347 # and static libraries since that is what most packages seem to provide 348 # (.so in libfoo and .a in libfoo-dev). 349 self.minimal-properties = [ property-set.create <variant>release 350 <threading>multi <link>shared <link>static <runtime-link>shared ] ; 351 # On Windows, new IDE projects use: 352 # 353 # runtime-link=dynamic, threading=multi, variant=(debug|release) 354 # 355 # and in addition, C++ Boost's autolink defaults to static linking. 356 self.minimal-properties-win = [ property-set.create <variant>debug 357 <variant>release <threading>multi <link>static <runtime-link>shared 358 ] ; 359 360 self.complete-properties = [ property-set.create 361 <variant>debug <variant>release 362 <threading>single <threading>multi 363 <link>shared <link>static 364 <runtime-link>shared <runtime-link>static ] ; 365 } 366 367 rule generate ( property-set ) 368 { 369 modules.poke : top-level-targets : [ modules.peek : top-level-targets ] 370 $(self.name) ; 371 if $(self.build-type) = minimal 372 { 373 local expanded ; 374 375 local os = [ $(property-set).get <target-os> ] ; 376 # Because we completely override the parent's 'generate' we need to 377 # check for default feature values ourselves. 378 if ! $(os) 379 { 380 os = [ feature.defaults <target-os> ] ; 381 os = $(os:G=) ; 382 } 383 384 if $(os) = windows 385 { 386 expanded = [ targets.apply-default-build $(property-set) 387 : $(self.minimal-properties-win) ] ; 388 } 389 else 390 { 391 expanded = [ targets.apply-default-build $(property-set) 392 : $(self.minimal-properties) ] ; 393 } 394 return [ build-multiple $(expanded) ] ; 395 } 396 else if $(self.build-type) = complete 397 { 398 local expanded = [ targets.apply-default-build $(property-set) 399 : $(self.complete-properties) ] ; 400 401 # Filter inappopriate combinations. 402 local filtered ; 403 for local p in $(expanded) 404 { 405 # See comment in handle-static-runtime regarding this logic. 406 if [ $(p).get <link> ] = shared 407 && [ $(p).get <runtime-link> ] = static 408 && [ $(p).get <toolset> ] != cw 409 { 410 # Skip this. 411 } 412 else 413 { 414 filtered += $(p) ; 415 } 416 } 417 return [ build-multiple $(filtered) ] ; 418 } 419 else 420 { 421 import errors ; 422 errors.error "Unknown build type" ; 423 } 424 } 425 426 rule build-multiple ( property-sets * ) 427 { 428 local usage-requirements = [ property-set.empty ] ; 429 local result ; 430 for local p in $(property-sets) 431 { 432 local r = [ alias-target-class.generate $(p) ] ; 433 if $(r) 434 { 435 usage-requirements = [ $(usage-requirements).add $(r[1]) ] ; 436 result += $(r[2-]) ; 437 } 438 } 439 return $(usage-requirements) [ sequence.unique $(result) ] ; 440 } 441} 442 443rule declare_top_level_targets ( libraries * : headers * ) 444{ 445 declare_install_and_stage_proper_targets $(libraries) : $(headers) ; 446 447 targets.create-metatarget top-level-target : [ project.current ] 448 : install 449 : install-proper install-unversioned 450 ; 451 targets.create-metatarget top-level-target : [ project.current ] 452 : stage 453 : stage-proper stage-unversioned 454 ; 455 456 p = [ project.current ] ; 457 $(p).mark-target-as-explicit install stage ; 458 459 # This target is built by default, and will forward to 'stage' after 460 # producing some explanations. 461 targets.create-metatarget top-level-target : [ project.current ] 462 : forward 463 : explain stage 464 ; 465} 466 467 468stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ; 469 470 471################################################################################ 472# 473# 4. Add hook to report configuration before the build, and confirmation with 474# setup instructions after the build. 475# 476################################################################################ 477 478message explain : "\nBuilding the Boost C++ Libraries.\n\n" ; 479local p = [ project.current ] ; 480$(p).mark-target-as-explicit explain ; 481 482rule pre-build ( ) 483{ 484 local tl = [ modules.peek : top-level-targets ] ; 485 if stage in $(tl) || install in $(tl) 486 { 487 # FIXME: Remove 'if' when Boost regression tests start using trunk bjam. 488 if PAD in [ RULENAMES ] 489 { 490 configure.print-component-configuration ; 491 } 492 } 493} 494IMPORT $(__name__) : pre-build : : $(__name__).pre-build ; 495build-system.set-pre-build-hook $(__name__).pre-build ; 496 497# FIXME: Revise stage_abs. 498rule post-build ( ok ? ) 499{ 500 if forward in [ modules.peek : top-level-targets ] 501 { 502 if $(ok) 503 { 504 local include-path = [ path.native $(BOOST_ROOT) ] ; 505 ECHO " 506 507The Boost C++ Libraries were successfully built! 508 509The following directory should be added to compiler include paths: 510 511 $(include-path) 512 513The following directory should be added to linker library paths: 514 515 $(stage-abs) 516" ; 517 } 518 } 519} 520IMPORT $(__name__) : post-build : : $(__name__).post-build ; 521build-system.set-post-build-hook $(__name__).post-build ; 522 523 524################################################################################ 525# 526# 5. Top-level setup. 527# 528################################################################################ 529 530# Decides which libraries are to be installed by looking at --with-<library> 531# --without-<library> arguments. Returns the list of directories under "libs" 532# which must be built and installed. 533# 534rule libraries-to-install ( existing-libs * ) 535{ 536 local argv = [ modules.peek : ARGV ] ; 537 local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ; 538 local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ; 539 540 if ! $(with-parameter) && ! $(without-parameter) 541 { 542 # Nothing is specified on command line. See if maybe project-config.jam 543 # has some choices. 544 local libs = [ modules.peek project-config : libraries ] ; 545 with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ; 546 without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ; 547 } 548 549 # Do some checks. 550 if $(with-parameter) && $(without-parameter) 551 { 552 EXIT error: both --with-<library> and --without-<library> specified ; 553 } 554 555 local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ; 556 if $(wrong) 557 { 558 EXIT error: wrong library name '$(wrong[1])' in the --with-<library> 559 option. ; 560 } 561 local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ; 562 if $(wrong) 563 { 564 EXIT error: wrong library name '$(wrong[1])' in the --without-<library> 565 option. ; 566 } 567 568 if $(with-parameter) 569 { 570 return [ set.intersection $(existing-libs) : $(with-parameter) ] ; 571 } 572 else 573 { 574 return [ set.difference $(existing-libs) : $(without-parameter) ] ; 575 } 576} 577 578rule declare-targets ( all-libraries * : headers * ) 579{ 580 configure.register-components $(all-libraries) ; 581 582 # Select the libraries to install. 583 libraries = [ libraries-to-install $(all-libraries) ] ; 584 configure.components-building $(libraries) ; 585 586 if [ option.get "show-libraries" : : true ] 587 { 588 ECHO The following libraries require building: ; 589 for local l in $(libraries) 590 { 591 ECHO " - $(l)" ; 592 } 593 EXIT ; 594 } 595 596 declare_top_level_targets $(libraries) : $(headers) ; 597} 598 599# Returns the properties identifying the toolset. We'll use them 600# below to configure checks. These are essentially same as in 601# configure.builds, except we don't use address-model and 602# architecture - as we're trying to detect them here. 603# 604rule toolset-properties ( properties * ) 605{ 606 local toolset = [ property.select <toolset> : $(properties) ] ; 607 local toolset-version-property = "<toolset-$(toolset:G=):version>" ; 608 return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ; 609} 610 611feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ; 612feature.compose <deduced-address-model>32 : <address-model>32 ; 613feature.compose <deduced-address-model>64 : <address-model>64 ; 614 615rule deduce-address-model ( properties * ) 616{ 617 local result ; 618 local filtered = [ toolset-properties $(properties) ] ; 619 620 if [ configure.builds /boost/architecture//32 : $(filtered) : 32-bit ] 621 { 622 result = 32 ; 623 } 624 else if [ configure.builds /boost/architecture//64 : $(filtered) : 64-bit ] 625 { 626 result = 64 ; 627 } 628 629 if $(result) 630 { 631 # Normally, returning composite feature here is equivalent to forcing 632 # consituent properties as well. But we only want to indicate toolset 633 # deduced default, so also pick whatever address-model is explicitly 634 # specified, if any. 635 result = <deduced-address-model>$(result) [ property.select <address-model> : $(properties) ] ; 636 } 637 return $(result) ; 638} 639 640rule address-model ( ) 641{ 642 return <conditional>@boostcpp.deduce-address-model ; 643} 644 645local deducable-architectures = arm mips1 power sparc x86 combined ; 646feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ; 647for a in $(deducable-architectures) 648{ 649 feature.compose <deduced-architecture>$(a) : <architecture>$(a) ; 650} 651 652rule deduce-architecture ( properties * ) 653{ 654 local result ; 655 local filtered = [ toolset-properties $(properties) ] ; 656 if [ configure.builds /boost/architecture//arm : $(filtered) : arm ] 657 { 658 result = arm ; 659 } 660 else if [ configure.builds /boost/architecture//mips1 : $(filtered) : mips1 ] 661 { 662 result = mips1 ; 663 } 664 else if [ configure.builds /boost/architecture//power : $(filtered) : power ] 665 { 666 result = power ; 667 } 668 else if [ configure.builds /boost/architecture//sparc : $(filtered) : sparc ] 669 { 670 result = sparc ; 671 } 672 else if [ configure.builds /boost/architecture//x86 : $(filtered) : x86 ] 673 { 674 result = x86 ; 675 } 676 else if [ configure.builds /boost/architecture//combined : $(filtered) : combined ] 677 { 678 result = combined ; 679 } 680 681 if $(result) 682 { 683 # See comment in deduce-address-model. 684 result = <deduced-architecture>$(result) [ property.select <architecture> : $(properties) ] ; 685 } 686 return $(result) ; 687} 688 689rule architecture ( ) 690{ 691 return <conditional>@boostcpp.deduce-architecture ; 692} 693