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