boostcpp.jam 17 KB

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