boostcpp.jam 21 KB

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