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