Imported Upstream version 1.57.0
[platform/upstream/boost.git] / tools / build / src / tools / convert.jam
1 # Copyright (c) 2009 Vladimir Prus
2 #
3 # Use, modification and distribution is subject to the Boost Software
4 # License Version 1.0. (See accompanying file LICENSE_1_0.txt or
5 # http://www.boost.org/LICENSE_1_0.txt)
6
7 # Implements 'convert' target that takes a bunch of source and
8 # tries to convert each one to the specified type.
9 #
10 # For example:
11 #
12 #   convert objects obj : a.cpp b.cpp ;
13 #
14
15 import targets ;
16 import generators ;
17 import project ;
18 import type ;
19 import "class" : new ;
20
21 class convert-target-class : typed-target
22 {
23     rule __init__ ( name : project : type
24     : sources * : requirements * : default-build * : usage-requirements * )
25     {
26         typed-target.__init__ $(name) : $(project) : $(type)
27           : $(sources) : $(requirements) : $(default-build) : $(usage-requirements) ;
28     }
29
30     rule construct ( name : source-targets * : property-set )
31     {
32         local r = [ generators.construct $(self.project) : $(self.type)
33           : [ property-set.create [ $(property-set).raw ] # [ feature.expand
34               <main-target-type>$(self.type) ]
35           # ]
36             : $(source-targets) ] ;
37         if ! $(r)
38         {
39             errors.error "unable to construct" [ full-name ] ;
40         }
41
42         return $(r) ;
43     }
44
45 }
46
47 rule convert ( name type : sources * : requirements * : default-build *
48     : usage-requirements * )
49 {
50     local project = [ project.current ] ;
51
52     # This is a circular module dependency, so it must be imported here
53     modules.import targets ;
54     targets.main-target-alternative
55       [ new convert-target-class $(name) : $(project) : [ type.type-from-rule-name $(type) ]
56         : [ targets.main-target-sources $(sources) : $(name) ]
57         : [ targets.main-target-requirements $(requirements) : $(project) ]
58         : [ targets.main-target-default-build $(default-build) : $(project) ]
59         : [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ]
60       ] ;
61 }
62 IMPORT $(__name__) : convert : : convert ;