forked from boost-cmake/boost
-
Notifications
You must be signed in to change notification settings - Fork 1
/
boostcpp.jam
705 lines (626 loc) · 21.8 KB
/
boostcpp.jam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
# Boost.Build support specific for the Boost C++ Libraries.
# Copyright Vladimir Prus 2002-2010.
# Copyright Dave Abrahams 2005-2006.
# Copyright Rene Rivera 2005-2007.
# Copyright Douglas Gregor 2005.
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import "class" : new ;
import common ;
import configure ;
import build-system ;
import generate ;
import modules ;
import option ;
import os ;
import package ;
import path ;
import project ;
import regex ;
import set ;
import targets ;
import feature ;
import property ;
##############################################################################
#
# 0. General setup. Parse options, check them.
#
##############################################################################
BOOST_ROOT = [ modules.binding $(__name__) ] ;
BOOST_ROOT = $(BOOST_ROOT:D) ;
rule set-version ( version )
{
BOOST_VERSION = $(version) ;
local version-tag = [ MATCH ^([^.]+)[.]([^.]+)[.]([^.]+) : $(BOOST_VERSION)
] ;
if $(version-tag[3]) = 0
{
version-tag = $(version-tag[1-2]) ;
}
BOOST_VERSION_TAG = $(version-tag:J=_) ;
}
# Option to choose how many variants to build. The default is "minimal".
build-type = [ option.get build-type ] ;
build-type ?= minimal ;
if ! ( $(build-type) in complete minimal )
{
EXIT The value of the --build-type option should be either 'complete' or
'minimal' ;
}
# What kind of layout are we doing?
layout = [ option.get layout : "" ] ;
# On Windows, we used versioned layout by default in order to be compatible with
# autolink. On other systems, we use system layout which is what every other
# program uses. Note that the Windows check is static, and will not be affected
# by specific build properties used.
if ! $(layout)
{
if [ os.name ] = NT
{
layout = versioned ;
}
else
{
layout = system ;
}
}
layout-$(layout) = true ;
if $(layout) = system && $(build-type) = complete
{
ECHO error: Cannot use --layout=system with --build-type complete. ;
ECHO error: Please use either --layout=versioned or --layout=tagged ;
ECHO error: if you wish to build multiple variants. ;
if [ os.name ] != NT
{
ECHO error: Note that --layout=system is used by default on Unix
starting with Boost 1.40. ;
}
EXIT ;
}
# Possible stage only location.
stage-locate = [ option.get stagedir ] ;
stage-locate ?= stage ;
BOOST_STAGE_LOCATE = $(stage-locate) ;
# Custom build ID.
build-id = [ option.get buildid ] ;
if $(build-id)
{
BUILD_ID = [ regex.replace $(build-id) "[*\\/:.\"\' ]" _ ] ;
}
# Python build id (for Python libraries only).
python-id = [ option.get "python-buildid" ] ;
if $(python-id)
{
PYTHON_ID = [ regex.replace $(python-id) [*\\/:.\"\'] _ ] ;
}
################################################################################
#
# 1. 'tag' function adding decorations suitable to the properties if versioned
# or tagged layout is requested. Called from Jamroot.
#
################################################################################
rule tag ( name : type ? : property-set )
{
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB
{
local result ;
if $(layout) = versioned
{
result = [ common.format-name
<base> <toolset> <threading> <runtime> -$(BOOST_VERSION_TAG)
-$(BUILD_ID)
: $(name) : $(type) : $(property-set) ] ;
}
else if $(layout) = tagged
{
result = [ common.format-name
<base> <threading> <runtime>
-$(BUILD_ID)
: $(name) : $(type) : $(property-set) ] ;
}
else if $(layout) = system
{
result = [ common.format-name
<base>
-$(BUILD_ID)
: $(name) : $(type) : $(property-set) ] ;
}
else
{
EXIT error: invalid layout '$(layout:E=)' ;
}
# Optionally add version suffix. On NT, library with version suffix will
# not be recognized by linkers. On CYGWIN, we get strage duplicate
# symbol errors when library is generated with version suffix. On OSX,
# version suffix is not needed -- the linker expects the
# libFoo.1.2.3.dylib format. AIX linkers do not accept version suffixes
# either. Pgi compilers can not accept a library with version suffix.
if $(type) = SHARED_LIB &&
! [ $(property-set).get <target-os> ] in windows cygwin darwin aix &&
! [ $(property-set).get <toolset> ] in pgi
{
result = $(result).$(BOOST_VERSION) ;
}
return $(result) ;
}
}
# Specialized tag function to use for libraries linking to Python.
# Appends value of --python-buildid if provided.
rule python-tag ( name : type ? : property-set )
{
local result = $(name) ;
if $(type) in STATIC_LIB SHARED_LIB IMPORT_LIB && $(PYTHON_ID)
{
result = $(result)-$(PYTHON_ID) ;
}
# forward to the boost tagging rule
return [ tag $(result) : $(type) : $(property-set) ] ;
}
################################################################################
#
# 2. Declare targets that build and install all libraries. Specifically:
#
# - 'stage-proper' that puts all libraries in stage/lib
# - 'install-proper' that install libraries and headers to system location
# - 'stage-unversioned' that creates links to libraries without boost version
# in name
# - 'install-unversioned' which creates unversioned linked to installed
# libraries.
#
################################################################################
# Worker function suitable to the 'generate' metatarget. Creates a link to
# 'source', striping any version number information from the name.
rule make-unversioned-links ( project name ? : property-set : sources * )
{
local filter ;
if [ modules.peek : NT ]
{
filter = (.*[.]lib) ;
}
else
{
filter =
(.*[.]so)[.0-9]*
(.*[.]dylib)
(.*[.]a) ;
}
local result ;
for local s in $(sources)
{
local m = [ MATCH ^(.*)-[0-9_]+$(filter)$ : [ $(s).name ] ] ;
if $(m)
{
local ea = [ $(s).action ] ;
local ep = [ $(ea).properties ] ;
local a = [ new non-scanning-action $(s) : symlink.ln : $(ep) ] ;
result += [ new file-target $(m:J=) exact : [ $(s).type ] :
$(project) : $(a) ] ;
}
}
return $(result) ;
}
rule filtered-target ( name : message + : sources + : requirements * )
{
message $(name)-message : warning: $(message) ;
alias $(name) : $(sources) : $(requirements) ;
alias $(name) : $(name)-message ;
local p = [ project.current ] ;
$(p).mark-target-as-explicit $(name) ;
$(p).mark-target-as-explicit $(name)-message ;
}
rule declare_install_and_stage_proper_targets ( libraries * : headers * )
{
local p = [ project.current ] ;
for local l in $(libraries)
{
if $(l) = locale
{
filtered-target $(l)-for-install :
Skipping Boost.Locale library with threading=single. :
libs/$(l)/build : <threading>multi ;
}
else if $(l) = wave
{
filtered-target $(l)-for-install :
Skipping Boost.Wave library with threading=single. :
libs/$(l)/build : <threading>multi ;
}
else if $(l) = thread
{
filtered-target $(l)-for-install :
Skipping Boost.Thread library with threading=single. :
libs/$(l)/build : <threading>multi ;
}
else
{
alias $(l)-for-install : libs/$(l)/build ;
$(p).mark-target-as-explicit $(l)-for-install ;
}
}
local library-targets = $(libraries)-for-install ;
install-requirements = <install-source-root>$(BOOST_ROOT)/boost ;
if $(layout-versioned)
{
install-requirements +=
<install-header-subdir>boost-$(BOOST_VERSION_TAG)/boost ;
}
else
{
install-requirements += <install-header-subdir>boost ;
}
if [ os.name ] = NT
{
install-requirements += <install-default-prefix>C:/Boost ;
}
else
{
install-requirements += <install-default-prefix>/usr/local ;
}
p = [ project.current ] ;
# Complete install.
package.install install-proper
: $(install-requirements) <install-no-version-symlinks>on
:
: $(libraries)-for-install
: $(headers)
;
$(p).mark-target-as-explicit install-proper ;
# Install just library.
install stage-proper
: $(libraries)-for-install
: <location>$(stage-locate)/lib
<install-dependencies>on <install-type>LIB
<install-no-version-symlinks>on
;
$(p).mark-target-as-explicit stage-proper ;
# Commented out as it does not seem to work. Whoever wrote this originally,
# left some typos in the code, but when that got corrected and the code got
# enabled - it started reporting ambiguous/duplicate target Boost Build
# errors. Anyone requiring unversioned staged libraries needs to correct
# those errors before reenabling this code. For more detailed information
# see the related Boost library development mailing list thread at
# 'http://lists.boost.org/Archives/boost/2012/06/194312.php'.
# (06.07.2012.) (Jurko)
#~ if $(layout-versioned) && ( [ modules.peek : NT ] || [ modules.peek : UNIX ] )
#~ {
#~ generate stage-unversioned : stage-proper :
#~ <generating-rule>@boostcpp.make-unversioned-links ;
#~ $(p).mark-target-as-explicit stage-unversioned ;
#~
#~ generate install-unversioned : install-proper :
#~ <generating-rule>@boostcpp.make-unversioned-links ;
#~ $(p).mark-target-as-explicit install-unversioned ;
#~ }
#~ else
{
# Create do-nothing aliases.
alias stage-unversioned ;
$(p).mark-target-as-explicit stage-unversioned ;
alias install-unversioned ;
$(p).mark-target-as-explicit install-unversioned ;
}
}
################################################################################
#
# 3. Declare top-level targets 'stage' and 'install'. These examine the
# --build-type option and, in case it is 'complete', build the 'install-proper'
# and 'stage-proper' targets with a number of property sets.
#
################################################################################
class top-level-target : alias-target-class
{
import modules ;
rule __init__ ( name : project : sources * : requirements *
: default-build * : usage-requirements * )
{
alias-target-class.__init__ $(name) : $(project) : $(sources) :
$(requirements) : $(default-build) : $(usage-requirements) ;
self.build-type = [ modules.peek boostcpp : build-type ] ;
# On Linux, we build the release variant by default, since few users
# will ever want to debug C++ Boost libraries, and there is no ABI
# incompatibility between debug and release variants. We build shared
# and static libraries since that is what most packages seem to provide
# (.so in libfoo and .a in libfoo-dev).
self.minimal-properties = [ property-set.create <variant>release
<threading>multi <link>shared <link>static <runtime-link>shared ] ;
# On Windows, new IDE projects use:
#
# runtime-link=dynamic, threading=multi, variant=(debug|release)
#
# and in addition, C++ Boost's autolink defaults to static linking.
self.minimal-properties-win = [ property-set.create <variant>debug
<variant>release <threading>multi <link>static <runtime-link>shared
] ;
self.complete-properties = [ property-set.create
<variant>debug <variant>release
<threading>multi
<link>shared <link>static
<runtime-link>shared <runtime-link>static ] ;
}
rule generate ( property-set )
{
modules.poke : top-level-targets : [ modules.peek : top-level-targets ]
$(self.name) ;
if $(self.build-type) = minimal
{
local expanded ;
local os = [ $(property-set).get <target-os> ] ;
# Because we completely override the parent's 'generate' we need to
# check for default feature values ourselves.
if ! $(os)
{
os = [ feature.defaults <target-os> ] ;
os = $(os:G=) ;
}
if $(os) = windows
{
expanded = [ targets.apply-default-build $(property-set)
: $(self.minimal-properties-win) ] ;
}
else
{
expanded = [ targets.apply-default-build $(property-set)
: $(self.minimal-properties) ] ;
}
return [ build-multiple $(expanded) ] ;
}
else if $(self.build-type) = complete
{
local expanded = [ targets.apply-default-build $(property-set)
: $(self.complete-properties) ] ;
# Filter inappopriate combinations.
local filtered ;
for local p in $(expanded)
{
# See comment in handle-static-runtime regarding this logic.
if [ $(p).get <link> ] = shared
&& [ $(p).get <runtime-link> ] = static
&& [ $(p).get <toolset> ] != cw
{
# Skip this.
}
else
{
filtered += $(p) ;
}
}
return [ build-multiple $(filtered) ] ;
}
else
{
import errors ;
errors.error "Unknown build type" ;
}
}
rule build-multiple ( property-sets * )
{
local usage-requirements = [ property-set.empty ] ;
local result ;
for local p in $(property-sets)
{
local r = [ alias-target-class.generate $(p) ] ;
if $(r)
{
usage-requirements = [ $(usage-requirements).add $(r[1]) ] ;
result += $(r[2-]) ;
}
}
return $(usage-requirements) [ sequence.unique $(result) ] ;
}
}
rule declare_top_level_targets ( libraries * : headers * )
{
declare_install_and_stage_proper_targets $(libraries) : $(headers) ;
targets.create-metatarget top-level-target : [ project.current ]
: install
: install-proper install-unversioned
;
targets.create-metatarget top-level-target : [ project.current ]
: stage
: stage-proper stage-unversioned
;
p = [ project.current ] ;
$(p).mark-target-as-explicit install stage ;
# This target is built by default, and will forward to 'stage' after
# producing some explanations.
targets.create-metatarget top-level-target : [ project.current ]
: forward
: explain stage
;
}
stage-abs = [ path.native [ path.root $(stage-locate)/lib [ path.pwd ] ] ] ;
################################################################################
#
# 4. Add hook to report configuration before the build, and confirmation with
# setup instructions after the build.
#
################################################################################
message explain : "\nBuilding the Boost C++ Libraries.\n\n" ;
local p = [ project.current ] ;
$(p).mark-target-as-explicit explain ;
rule pre-build ( )
{
local tl = [ modules.peek : top-level-targets ] ;
if stage in $(tl) || install in $(tl)
{
# FIXME: Remove 'if' when Boost regression tests start using trunk bjam.
if PAD in [ RULENAMES ]
{
configure.print-component-configuration ;
}
}
}
IMPORT $(__name__) : pre-build : : $(__name__).pre-build ;
build-system.set-pre-build-hook $(__name__).pre-build ;
# FIXME: Revise stage_abs.
rule post-build ( ok ? )
{
if forward in [ modules.peek : top-level-targets ]
{
if $(ok)
{
local include-path = [ path.native $(BOOST_ROOT) ] ;
ECHO "
The Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
$(include-path)
The following directory should be added to linker library paths:
$(stage-abs)
" ;
}
}
}
IMPORT $(__name__) : post-build : : $(__name__).post-build ;
build-system.set-post-build-hook $(__name__).post-build ;
################################################################################
#
# 5. Top-level setup.
#
################################################################################
# Decides which libraries are to be installed by looking at --with-<library>
# --without-<library> arguments. Returns the list of directories under "libs"
# which must be built and installed.
#
rule libraries-to-install ( existing-libs * )
{
local argv = [ modules.peek : ARGV ] ;
local with-parameter = [ MATCH ^--with-(.*) : $(argv) ] ;
local without-parameter = [ MATCH ^--without-(.*) : $(argv) ] ;
if ! $(with-parameter) && ! $(without-parameter)
{
# Nothing is specified on command line. See if maybe project-config.jam
# has some choices.
local libs = [ modules.peek project-config : libraries ] ;
with-parameter = [ MATCH ^--with-(.*) : $(libs) ] ;
without-parameter = [ MATCH ^--without-(.*) : $(libs) ] ;
}
# Do some checks.
if $(with-parameter) && $(without-parameter)
{
EXIT error: both --with-<library> and --without-<library> specified ;
}
local wrong = [ set.difference $(with-parameter) : $(existing-libs) ] ;
if $(wrong)
{
EXIT error: wrong library name '$(wrong[1])' in the --with-<library>
option. ;
}
local wrong = [ set.difference $(without-parameter) : $(existing-libs) ] ;
if $(wrong)
{
EXIT error: wrong library name '$(wrong[1])' in the --without-<library>
option. ;
}
if $(with-parameter)
{
return [ set.intersection $(existing-libs) : $(with-parameter) ] ;
}
else
{
return [ set.difference $(existing-libs) : $(without-parameter) ] ;
}
}
rule declare-targets ( all-libraries * : headers * )
{
configure.register-components $(all-libraries) ;
# Select the libraries to install.
libraries = [ libraries-to-install $(all-libraries) ] ;
configure.components-building $(libraries) ;
if [ option.get "show-libraries" : : true ]
{
ECHO The following libraries require building: ;
for local l in $(libraries)
{
ECHO " - $(l)" ;
}
EXIT ;
}
declare_top_level_targets $(libraries) : $(headers) ;
}
# Returns the properties identifying the toolset. We'll use them
# below to configure checks. These are essentially same as in
# configure.builds, except we don't use address-model and
# architecture - as we're trying to detect them here.
#
rule toolset-properties ( properties * )
{
local toolset = [ property.select <toolset> : $(properties) ] ;
local toolset-version-property = "<toolset-$(toolset:G=):version>" ;
return [ property.select <target-os> <toolset> $(toolset-version-property) : $(properties) ] ;
}
feature.feature deduced-address-model : 32 64 : propagated optional composite hidden ;
feature.compose <deduced-address-model>32 : <address-model>32 ;
feature.compose <deduced-address-model>64 : <address-model>64 ;
rule deduce-address-model ( properties * )
{
local result ;
local filtered = [ toolset-properties $(properties) ] ;
if [ configure.builds /boost/architecture//32 : $(filtered) : 32-bit ]
{
result = 32 ;
}
else if [ configure.builds /boost/architecture//64 : $(filtered) : 64-bit ]
{
result = 64 ;
}
if $(result)
{
# Normally, returning composite feature here is equivalent to forcing
# consituent properties as well. But we only want to indicate toolset
# deduced default, so also pick whatever address-model is explicitly
# specified, if any.
result = <deduced-address-model>$(result) [ property.select <address-model> : $(properties) ] ;
}
return $(result) ;
}
rule address-model ( )
{
return <conditional>@boostcpp.deduce-address-model ;
}
local deducable-architectures = arm mips1 power sparc x86 combined ;
feature.feature deduced-architecture : $(deducable-architectures) : propagated optional composite hidden ;
for a in $(deducable-architectures)
{
feature.compose <deduced-architecture>$(a) : <architecture>$(a) ;
}
rule deduce-architecture ( properties * )
{
local result ;
local filtered = [ toolset-properties $(properties) ] ;
if [ configure.builds /boost/architecture//arm : $(filtered) : arm ]
{
result = arm ;
}
else if [ configure.builds /boost/architecture//mips1 : $(filtered) : mips1 ]
{
result = mips1 ;
}
else if [ configure.builds /boost/architecture//power : $(filtered) : power ]
{
result = power ;
}
else if [ configure.builds /boost/architecture//sparc : $(filtered) : sparc ]
{
result = sparc ;
}
else if [ configure.builds /boost/architecture//x86 : $(filtered) : x86 ]
{
result = x86 ;
}
else if [ configure.builds /boost/architecture//combined : $(filtered) : combined ]
{
result = combined ;
}
if $(result)
{
# See comment in deduce-address-model.
result = <deduced-architecture>$(result) [ property.select <architecture> : $(properties) ] ;
}
return $(result) ;
}
rule architecture ( )
{
return <conditional>@boostcpp.deduce-architecture ;
}