boostcpp.jam 18 KB

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