]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | # Copyright 2002-2017 Rene Rivera |
2 | # Copyright 2002-2017 Vladimir Prus | |
3 | # Distributed under the Boost Software License, Version 1.0. | |
4 | # (See accompanying file LICENSE_1_0.txt or copy at | |
5 | # http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7 | import "class" : new ; | |
8 | import generators ; | |
11fdf7f2 | 9 | import param ; |
b32b8144 FG |
10 | import project ; |
11 | import targets ; | |
12 | ||
13 | # The generator class for libraries (target type LIB). Depending on properties | |
14 | # it will request building of the appropriate specific library type -- | |
15 | # -- SHARED_LIB, STATIC_LIB or SHARED_LIB. | |
16 | # | |
17 | class lib-generator : generator | |
18 | { | |
19 | rule __init__ ( * : * ) | |
20 | { | |
21 | generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) | |
22 | : $(9) : $(10) : $(11) : $(12) : $(13) : $(14) : $(15) : $(16) : | |
23 | $(17) : $(18) : $(19) ; | |
24 | } | |
25 | ||
26 | rule run ( project name ? : property-set : sources * ) | |
27 | { | |
28 | # The lib generator is composing, and can be only invoked with an | |
29 | # explicit name. This check is present in generator.run (and so in | |
30 | # builtin.linking-generator) but duplicated here to avoid doing extra | |
31 | # work. | |
32 | if $(name) | |
33 | { | |
34 | local properties = [ $(property-set).raw ] ; | |
35 | # Determine the needed target type. | |
36 | local actual-type ; | |
37 | # <source>files can be generated by <conditional>@rule feature | |
38 | # in which case we do not consider it a SEARCHED_LIB type. | |
39 | if ! <source> in $(properties:G) && | |
40 | ( <search> in $(properties:G) || <name> in $(properties:G) ) | |
41 | { | |
42 | actual-type = SEARCHED_LIB ; | |
43 | } | |
44 | else if <file> in $(properties:G) | |
45 | { | |
46 | actual-type = LIB ; | |
47 | } | |
48 | else if <link>shared in $(properties) | |
49 | { | |
50 | actual-type = SHARED_LIB ; | |
51 | } | |
52 | else | |
53 | { | |
54 | actual-type = STATIC_LIB ; | |
55 | } | |
11fdf7f2 | 56 | property-set = [ $(property-set).add-raw <main-target-type>LIB <relevant>link ] ; |
b32b8144 | 57 | # Construct the target. |
11fdf7f2 | 58 | local result = [ generators.construct $(project) $(name) : $(actual-type) |
b32b8144 | 59 | : $(property-set) : $(sources) ] ; |
11fdf7f2 | 60 | return [ $(result[1]).add-raw <relevant>link ] $(result[2-]) ; |
b32b8144 FG |
61 | } |
62 | } | |
63 | ||
64 | rule viable-source-types ( ) | |
65 | { | |
66 | return * ; | |
67 | } | |
68 | } | |
69 | ||
70 | generators.register [ new lib-generator builtin.lib-generator : : LIB ] ; | |
71 | ||
72 | # The implementation of the 'lib' rule. Beyond standard syntax that rule allows | |
73 | # simplified: "lib a b c ;". | |
74 | # | |
75 | rule lib ( names + : sources * : requirements * : default-build * : | |
76 | usage-requirements * ) | |
77 | { | |
11fdf7f2 TL |
78 | param.handle-named-params |
79 | sources requirements default-build usage-requirements ; | |
b32b8144 FG |
80 | if $(names[2]) |
81 | { | |
82 | if <name> in $(requirements:G) | |
83 | { | |
92f5a8d4 | 84 | import errors ; |
b32b8144 FG |
85 | errors.user-error "When several names are given to the 'lib' rule" : |
86 | "it is not allowed to specify the <name> feature." ; | |
87 | } | |
88 | if $(sources) | |
89 | { | |
92f5a8d4 | 90 | import errors ; |
b32b8144 FG |
91 | errors.user-error "When several names are given to the 'lib' rule" : |
92 | "it is not allowed to specify sources." ; | |
93 | } | |
94 | } | |
95 | ||
96 | # This is a circular module dependency so it must be imported here. | |
97 | import targets ; | |
98 | ||
99 | local project = [ project.current ] ; | |
100 | local result ; | |
101 | ||
102 | for local name in $(names) | |
103 | { | |
104 | local r = $(requirements) ; | |
105 | # Support " lib a ; " and " lib a b c ; " syntax. | |
106 | if ! $(sources) && ! <name> in $(requirements:G) | |
107 | && ! <file> in $(requirements:G) | |
108 | { | |
109 | r += <name>$(name) ; | |
110 | } | |
111 | result += [ targets.main-target-alternative | |
112 | [ new typed-target $(name) : $(project) : LIB | |
113 | : [ targets.main-target-sources $(sources) : $(name) ] | |
114 | : [ targets.main-target-requirements $(r) : $(project) ] | |
115 | : [ targets.main-target-default-build $(default-build) : $(project) ] | |
116 | : [ targets.main-target-usage-requirements $(usage-requirements) : $(project) ] | |
117 | ] ] ; | |
118 | } | |
119 | return $(result) ; | |
120 | } | |
121 | IMPORT $(__name__) : lib : : lib ; |