boostcpp.jam 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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 declare_install_and_stage_proper_targets ( libraries * : headers * )
  193. {
  194. install-requirements = <install-source-root>$(BOOST_ROOT)/boost ;
  195. if $(layout-versioned)
  196. {
  197. install-requirements +=
  198. <install-header-subdir>boost-$(BOOST_VERSION_TAG)/boost ;
  199. }
  200. else
  201. {
  202. install-requirements += <install-header-subdir>boost ;
  203. }
  204. if [ os.name ] = NT
  205. {
  206. install-requirements += <install-default-prefix>C:/Boost ;
  207. }
  208. else
  209. {
  210. install-requirements += <install-default-prefix>/usr/local ;
  211. }
  212. p = [ project.current ] ;
  213. # Complete install.
  214. package.install install-proper
  215. : $(install-requirements) <install-no-version-symlinks>on
  216. :
  217. : libs/$(libraries)/build
  218. : $(headers)
  219. ;
  220. $(p).mark-target-as-explicit install-proper ;
  221. # Install just library.
  222. install stage-proper
  223. : libs/$(libraries)/build
  224. : <location>$(stage-locate)/lib
  225. <install-dependencies>on <install-type>LIB
  226. <install-no-version-symlinks>on
  227. ;
  228. $(p).mark-target-as-explicit stage-proper ;
  229. # Commented out as it does not seem to work. Whoever wrote this originally,
  230. # left some typos in the code, but when that got corrected and the code got
  231. # enabled - it started reporting ambiguous/duplicate target Boost Build
  232. # errors. Anyone requiring unversioned staged libraries needs to correct
  233. # those errors before reenabling this code. For more detailed information
  234. # see the related Boost library development mailing list thread at
  235. # 'http://lists.boost.org/Archives/boost/2012/06/194312.php'.
  236. # (06.07.2012.) (Jurko)
  237. #~ if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] )
  238. #~ {
  239. #~ generate stage-unversioned : stage-proper :
  240. #~ <generating-rule>@boostcpp.make-unversioned-links ;
  241. #~ $(p).mark-target-as-explicit stage-unversioned ;
  242. #~
  243. #~ generate install-unversioned : install-proper :
  244. #~ <generating-rule>@boostcpp.make-unversioned-links ;
  245. #~ $(p).mark-target-as-explicit install-unversioned ;
  246. #~ }
  247. #~ else
  248. {
  249. # Create do-nothing aliases.
  250. alias stage-unversioned ;
  251. $(p).mark-target-as-explicit stage-unversioned ;
  252. alias install-unversioned ;
  253. $(p).mark-target-as-explicit install-unversioned ;
  254. }
  255. }
  256. ################################################################################
  257. #
  258. # 3. Declare top-level targets 'stage' and 'install'. These examine the
  259. # --build-type option and, in case it is 'complete', build the 'install-proper'
  260. # and 'stage-proper' targets with a number of property sets.
  261. #
  262. ################################################################################
  263. class top-level-target : alias-target-class
  264. {
  265. import modules ;
  266. rule __init__ ( name : project : sources * : requirements *
  267. : default-build * : usage-requirements * )
  268. {
  269. alias-target-class.__init__ $(name) : $(project) : $(sources) :
  270. $(requirements) : $(default-build) : $(usage-requirements) ;
  271. self.build-type = [ modules.peek boostcpp : build-type ] ;
  272. # On Linux, we build the release variant by default, since few users
  273. # will ever want to debug C++ Boost libraries, and there is no ABI
  274. # incompatibility between debug and release variants. We build shared
  275. # and static libraries since that is what most packages seem to provide
  276. # (.so in libfoo and .a in libfoo-dev).
  277. self.minimal-properties = [ property-set.create <variant>release
  278. <threading>multi <link>shared <link>static <runtime-link>shared ] ;
  279. # On Windows, new IDE projects use:
  280. #
  281. # runtime-link=dynamic, threading=multi, variant=(debug|release)
  282. #
  283. # and in addition, C++ Boost's autolink defaults to static linking.
  284. self.minimal-properties-win = [ property-set.create <variant>debug
  285. <variant>release <threading>multi <link>static <runtime-link>shared
  286. ] ;
  287. self.complete-properties = [ property-set.create
  288. <variant>debug <variant>release
  289. <threading>single <threading>multi
  290. <link>shared <link>static
  291. <runtime-link>shared <runtime-link>static ] ;
  292. }
  293. rule generate ( property-set )
  294. {
  295. modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
  296. $(self.name) ;
  297. if $(self.build-type) = minimal
  298. {
  299. local expanded ;
  300. local os = [ $(property-set).get <target-os> ] ;
  301. # Because we completely override the parent's 'generate' we need to
  302. # check for default feature values ourselves.
  303. if ! $(os)
  304. {
  305. os = [ feature.defaults <target-os> ] ;
  306. os = $(os:G=) ;
  307. }
  308. if $(os) = windows
  309. {
  310. expanded = [ targets.apply-default-build $(property-set)
  311. : $(self.minimal-properties-win) ] ;
  312. }
  313. else
  314. {
  315. expanded = [ targets.apply-default-build $(property-set)
  316. : $(self.minimal-properties) ] ;
  317. }
  318. return [ build-multiple $(expanded) ] ;
  319. }
  320. else if $(self.build-type) = complete
  321. {
  322. local expanded = [ targets.apply-default-build $(property-set)
  323. : $(self.complete-properties) ] ;
  324. # Filter inappopriate combinations.
  325. local filtered ;
  326. for local p in $(expanded)
  327. {
  328. # See comment in handle-static-runtime regarding this logic.
  329. if [ $(p).get <link> ] = shared
  330. && [ $(p).get <runtime-link> ] = static
  331. && [ $(p).get <toolset> ] != cw
  332. {
  333. # Skip this.
  334. }
  335. else
  336. {
  337. filtered += $(p) ;
  338. }
  339. }
  340. return [ build-multiple $(filtered) ] ;
  341. }
  342. else
  343. {
  344. import errors ;
  345. errors.error "Unknown build type" ;
  346. }
  347. }
  348. rule build-multiple ( property-sets * )
  349. {
  350. local usage-requirements = [ property-set.empty ] ;
  351. local result ;
  352. for local p in $(property-sets)
  353. {
  354. local r = [ alias-target-class.generate $(p) ] ;
  355. if $(r)
  356. {
  357. usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
  358. result += $(r[2-]) ;
  359. }
  360. }
  361. return $(usage-requirements) [ sequence.unique $(result) ] ;
  362. }
  363. }
  364. rule declare_top_level_targets ( libraries * : headers * )
  365. {
  366. declare_install_and_stage_proper_targets $(libraries) : $(headers) ;
  367. targets.create-metatarget top-level-target : [ project.current ]
  368. : install
  369. : install-proper install-unversioned
  370. ;
  371. targets.create-metatarget top-level-target : [ project.current ]
  372. : stage
  373. : stage-proper stage-unversioned
  374. ;
  375. p = [ project.current ] ;
  376. $(p).mark-target-as-explicit install stage ;
  377. # This target is built by default, and will forward to 'stage' after
  378. # producing some explanations.
  379. targets.create-metatarget top-level-target : [ project.current ]
  380. : forward
  381. : explain stage
  382. ;
  383. }
  384. stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ;
  385. ################################################################################
  386. #
  387. # 4. Add hook to report configuration before the build, and confirmation with
  388. # setup instructions after the build.
  389. #
  390. ################################################################################
  391. message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
  392. local p = [ project.current ] ;
  393. $(p).mark-target-as-explicit explain ;
  394. rule pre-build ( )
  395. {
  396. local tl = [ modules.peek : top-level-targets ] ;
  397. if stage in $(tl) || install in $(tl)
  398. {
  399. # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
  400. if PAD in [ RULENAMES ]
  401. {
  402. configure.print-component-configuration ;
  403. }
  404. }
  405. }
  406. IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
  407. build-system.set-pre-build-hook $(__name__).pre-build ;
  408. # FIXME: Revise stage_abs.
  409. rule post-build ( ok ? )
  410. {
  411. if forward in [ modules.peek : top-level-targets ]
  412. {
  413. if $(ok)
  414. {
  415. ECHO "
  416. The Boost C++ Libraries were successfully built!
  417. The following directory should be added to compiler include paths:
  418. $(BOOST_ROOT)
  419. The following directory should be added to linker library paths:
  420. $(stage-abs)
  421. " ;
  422. }
  423. }
  424. }
  425. IMPORT $(__name__) : post-build : : $(__name__).post-build ;
  426. build-system.set-post-build-hook $(__name__).post-build ;
  427. ################################################################################
  428. #
  429. # 5. Top-level setup.
  430. #
  431. ################################################################################
  432. # Decides which libraries are to be installed by looking at --with-<library>
  433. # --without-<library> arguments. Returns the list of directories under "libs"
  434. # which must be built and installed.
  435. #
  436. rule libraries-to-install ( existing-libs * )
  437. {
  438. local argv = [ modules.peek : ARGV ] ;
  439. local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
  440. local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
  441. if ! $(with-parameter) && ! $(without-parameter)
  442. {
  443. # Nothing is specified on command line. See if maybe project-config.jam
  444. # has some choices.
  445. local libs = [ modules.peek project-config : libraries ] ;
  446. with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
  447. without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
  448. }
  449. # Do some checks.
  450. if $(with-parameter) && $(without-parameter)
  451. {
  452. EXIT error: both --with-<library> and --without-<library> specified ;
  453. }
  454. local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
  455. if $(wrong)
  456. {
  457. EXIT error: wrong library name '$(wrong[1])' in the --with-<library>
  458. option. ;
  459. }
  460. local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
  461. if $(wrong)
  462. {
  463. EXIT error: wrong library name '$(wrong[1])' in the --without-<library>
  464. option. ;
  465. }
  466. if $(with-parameter)
  467. {
  468. return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
  469. }
  470. else
  471. {
  472. return [ set.difference $(existing-libs) : $(without-parameter) ] ;
  473. }
  474. }
  475. rule declare-targets ( all-libraries * : headers * )
  476. {
  477. configure.register-components $(all-libraries) ;
  478. # Select the libraries to install.
  479. libraries = [ libraries-to-install $(all-libraries) ] ;
  480. configure.components-building $(libraries) ;
  481. if [ option.get "show-libraries" : : true ]
  482. {
  483. ECHO The following libraries require building: ;
  484. for local l in $(libraries)
  485. {
  486. ECHO " - $(l)" ;
  487. }
  488. EXIT ;
  489. }
  490. declare_top_level_targets $(libraries) : $(headers) ;
  491. }
  492. # Returns the properties identifying the toolset. We'll use them
  493. # below to configure checks. These are essentially same as in
  494. # configure.builds, except we don't use address-model and
  495. # architecture - as we're trying to detect them here.
  496. #
  497. rule toolset-properties ( properties * )
  498. {
  499. local toolset = [ property.select <toolset> : $(properties) ] ;
  500. local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
  501. return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
  502. }
  503. feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ;
  504. feature.compose <deduced-address-model>32 : <address-model>32 ;
  505. feature.compose <deduced-address-model>64 : <address-model>64 ;
  506. rule deduce-address-model ( properties * )
  507. {
  508. local result ;
  509. local filtered = [ toolset-properties $(properties) ] ;
  510. if [ configure.builds /boost/architecture//32 : $(filtered) : 32-bit ]
  511. {
  512. result = 32 ;
  513. }
  514. else if [ configure.builds /boost/architecture//64 : $(filtered) : 64-bit ]
  515. {
  516. result = 64 ;
  517. }
  518. if $(result)
  519. {
  520. # Normally, returning composite feature here is equivalent to forcing
  521. # consituent properties as well. But we only want to indicate toolset
  522. # deduced default, so also pick whatever address-model is explicitly
  523. # specified, if any.
  524. result = <deduced-address-model>$(result) [ property.select <address-model> : $(properties) ] ;
  525. }
  526. return $(result) ;
  527. }
  528. rule address-model ( )
  529. {
  530. return <conditional>@boostcpp.deduce-address-model ;
  531. }
  532. local deducable-architectures = arm mips1 power sparc x86 combined ;
  533. feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ;
  534. for a in $(deducable-architectures)
  535. {
  536. feature.compose <deduced-architecture>$(a) : <architecture>$(a) ;
  537. }
  538. rule deduce-architecture ( properties * )
  539. {
  540. local result ;
  541. local filtered = [ toolset-properties $(properties) ] ;
  542. if [ configure.builds /boost/architecture//arm : $(filtered) : arm ]
  543. {
  544. result = arm ;
  545. }
  546. else if [ configure.builds /boost/architecture//mips1 : $(filtered) : mips1 ]
  547. {
  548. result = mips1 ;
  549. }
  550. else if [ configure.builds /boost/architecture//power : $(filtered) : power ]
  551. {
  552. result = power ;
  553. }
  554. else if [ configure.builds /boost/architecture//sparc : $(filtered) : sparc ]
  555. {
  556. result = sparc ;
  557. }
  558. else if [ configure.builds /boost/architecture//x86 : $(filtered) : x86 ]
  559. {
  560. result = x86 ;
  561. }
  562. else if [ configure.builds /boost/architecture//combined : $(filtered) : combined ]
  563. {
  564. result = combined ;
  565. }
  566. if $(result)
  567. {
  568. # See comment in deduce-address-model.
  569. result = <deduced-architecture>$(result) [ property.select <architecture> : $(properties) ] ;
  570. }
  571. return $(result) ;
  572. }
  573. rule architecture ( )
  574. {
  575. return <conditional>@boostcpp.deduce-architecture ;
  576. }
粤ICP备19079148号