boostcpp.jam 18 KB

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