boostcpp.jam 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  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. if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] )
  228. {
  229. generate stage-unversioned : stage-proper :
  230. <generating-rule>@boostcpp.make-unversioned-links ;
  231. $(p).mark-target-as-explicit stage-unversioned ;
  232. generate install-unversioned : install-proper :
  233. <generating-rule>@boostcpp.make-unversioned-links ;
  234. $(p).mark-target-as-explicit install-unversioned ;
  235. }
  236. else
  237. {
  238. # Create do-nothing aliases.
  239. alias stage-unversioned ;
  240. $(p).mark-target-as-explicit stage-unversioned ;
  241. alias install-unversioned ;
  242. $(p).mark-target-as-explicit install-unversioned ;
  243. }
  244. }
  245. ################################################################################
  246. #
  247. # 3. Declare top-level targets 'stage' and 'install'. These examine the
  248. # --build-type option and, in case it is 'complete', build the 'install-proper'
  249. # and 'stage-proper' targets with a number of property sets.
  250. #
  251. ################################################################################
  252. class top-level-target : alias-target-class
  253. {
  254. import modules ;
  255. rule __init__ ( name : project : sources * : requirements *
  256. : default-build * : usage-requirements * )
  257. {
  258. alias-target-class.__init__ $(name) : $(project) : $(sources) :
  259. $(requirements) : $(default-build) : $(usage-requirements) ;
  260. self.build-type = [ modules.peek boostcpp : build-type ] ;
  261. # On Linux, we build the release variant by default, since few users
  262. # will ever want to debug C++ Boost libraries, and there is no ABI
  263. # incompatibility between debug and release variants. We build shared
  264. # and static libraries since that is what most packages seem to provide
  265. # (.so in libfoo and .a in libfoo-dev).
  266. self.minimal-properties = [ property-set.create <variant>release
  267. <threading>multi <link>shared <link>static <runtime-link>shared ] ;
  268. # On Windows, new IDE projects use:
  269. #
  270. # runtime-link=dynamic, threading=multi, variant=(debug|release)
  271. #
  272. # and in addition, C++ Boost's autolink defaults to static linking.
  273. self.minimal-properties-win = [ property-set.create <variant>debug
  274. <variant>release <threading>multi <link>static <runtime-link>shared
  275. ] ;
  276. self.complete-properties = [ property-set.create
  277. <variant>debug <variant>release
  278. <threading>single <threading>multi
  279. <link>shared <link>static
  280. <runtime-link>shared <runtime-link>static ] ;
  281. }
  282. rule generate ( property-set )
  283. {
  284. modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
  285. $(self.name) ;
  286. if $(self.build-type) = minimal
  287. {
  288. local expanded ;
  289. local os = [ $(property-set).get <target-os> ] ;
  290. # Because we completely override the parent's 'generate' we need to
  291. # check for default feature values ourselves.
  292. if ! $(os)
  293. {
  294. os = [ feature.defaults <target-os> ] ;
  295. os = $(os:G=) ;
  296. }
  297. if $(os) = windows
  298. {
  299. expanded = [ targets.apply-default-build $(property-set)
  300. : $(self.minimal-properties-win) ] ;
  301. }
  302. else
  303. {
  304. expanded = [ targets.apply-default-build $(property-set)
  305. : $(self.minimal-properties) ] ;
  306. }
  307. return [ build-multiple $(expanded) ] ;
  308. }
  309. else if $(self.build-type) = complete
  310. {
  311. local expanded = [ targets.apply-default-build $(property-set)
  312. : $(self.complete-properties) ] ;
  313. # Filter inappopriate combinations.
  314. local filtered ;
  315. for local p in $(expanded)
  316. {
  317. # See comment in handle-static-runtime regarding this logic.
  318. if [ $(p).get <link> ] = shared
  319. && [ $(p).get <runtime-link> ] = static
  320. && [ $(p).get <toolset> ] != cw
  321. {
  322. # Skip this.
  323. }
  324. else
  325. {
  326. filtered += $(p) ;
  327. }
  328. }
  329. return [ build-multiple $(filtered) ] ;
  330. }
  331. else
  332. {
  333. import errors ;
  334. errors.error "Unknown build type" ;
  335. }
  336. }
  337. rule build-multiple ( property-sets * )
  338. {
  339. local usage-requirements = [ property-set.empty ] ;
  340. local result ;
  341. for local p in $(property-sets)
  342. {
  343. local r = [ alias-target-class.generate $(p) ] ;
  344. if $(r)
  345. {
  346. usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
  347. result += $(r[2-]) ;
  348. }
  349. }
  350. return $(usage-requirements) [ sequence.unique $(result) ] ;
  351. }
  352. }
  353. rule declare_top_level_targets ( libraries * : headers * )
  354. {
  355. declare_install_and_stage_proper_targets $(libraries) : $(headers) ;
  356. targets.create-metatarget top-level-target : [ project.current ]
  357. : install
  358. : install-proper install-unversioned
  359. ;
  360. targets.create-metatarget top-level-target : [ project.current ]
  361. : stage
  362. : stage-proper stage-unversioned
  363. ;
  364. p = [ project.current ] ;
  365. $(p).mark-target-as-explicit install stage ;
  366. # This target is built by default, and will forward to 'stage' after
  367. # producing some explanations.
  368. targets.create-metatarget top-level-target : [ project.current ]
  369. : forward
  370. : explain stage
  371. ;
  372. }
  373. stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ;
  374. ################################################################################
  375. #
  376. # 4. Add hook to report configuration before the build, and confirmation with
  377. # setup instructions after the build.
  378. #
  379. ################################################################################
  380. message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
  381. local p = [ project.current ] ;
  382. $(p).mark-target-as-explicit explain ;
  383. rule pre-build ( )
  384. {
  385. local tl = [ modules.peek : top-level-targets ] ;
  386. if stage in $(tl) || install in $(tl)
  387. {
  388. # FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
  389. if PAD in [ RULENAMES ]
  390. {
  391. configure.print-component-configuration ;
  392. }
  393. }
  394. }
  395. IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
  396. build-system.set-pre-build-hook $(__name__).pre-build ;
  397. # FIXME: Revise stage_abs.
  398. rule post-build ( ok ? )
  399. {
  400. if forward in [ modules.peek : top-level-targets ]
  401. {
  402. if $(ok)
  403. {
  404. ECHO "
  405. The Boost C++ Libraries were successfully built!
  406. The following directory should be added to compiler include paths:
  407. $(BOOST_ROOT)
  408. The following directory should be added to linker library paths:
  409. $(stage-abs)
  410. " ;
  411. }
  412. }
  413. }
  414. IMPORT $(__name__) : post-build : : $(__name__).post-build ;
  415. build-system.set-post-build-hook $(__name__).post-build ;
  416. ################################################################################
  417. #
  418. # 5. Top-level setup.
  419. #
  420. ################################################################################
  421. # Decides which libraries are to be installed by looking at --with-<library>
  422. # --without-<library> arguments. Returns the list of directories under "libs"
  423. # which must be built and installed.
  424. #
  425. rule libraries-to-install ( existing-libs * )
  426. {
  427. local argv = [ modules.peek : ARGV ] ;
  428. local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
  429. local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
  430. if ! $(with-parameter) && ! $(without-parameter)
  431. {
  432. # Nothing is specified on command line. See if maybe project-config.jam
  433. # has some choices.
  434. local libs = [ modules.peek project-config : libraries ] ;
  435. with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
  436. without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
  437. }
  438. # Do some checks.
  439. if $(with-parameter) && $(without-parameter)
  440. {
  441. EXIT error: both --with-<library> and --without-<library> specified ;
  442. }
  443. local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
  444. if $(wrong)
  445. {
  446. EXIT error: wrong library name '$(wrong[1])' in the --with-<library>
  447. option. ;
  448. }
  449. local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
  450. if $(wrong)
  451. {
  452. EXIT error: wrong library name '$(wrong[1])' in the --without-<library>
  453. option. ;
  454. }
  455. if $(with-parameter)
  456. {
  457. return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
  458. }
  459. else
  460. {
  461. return [ set.difference $(existing-libs) : $(without-parameter) ] ;
  462. }
  463. }
  464. rule declare-targets ( all-libraries * : headers * )
  465. {
  466. configure.register-components $(all-libraries) ;
  467. # Select the libraries to install.
  468. libraries = [ libraries-to-install $(all-libraries) ] ;
  469. configure.components-building $(libraries) ;
  470. if [ option.get "show-libraries" : : true ]
  471. {
  472. ECHO The following libraries require building: ;
  473. for local l in $(libraries)
  474. {
  475. ECHO " - $(l)" ;
  476. }
  477. EXIT ;
  478. }
  479. declare_top_level_targets $(libraries) : $(headers) ;
  480. }
粤ICP备19079148号