]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/tools/generators/linking-generator.jam
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / boost / tools / build / src / tools / generators / linking-generator.jam
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 ;
9
10 # The generator class for handling EXE and SHARED_LIB creation.
11 #
12 class linking-generator : generator
13 {
14 import path ;
15 import project ;
16 import property-set ;
17 import type ;
18
19 rule __init__ ( id
20 composing ? : # The generator will be composing if a non-empty
21 # string is passed or the parameter is not given. To
22 # make the generator non-composing, pass an empty
23 # string ("").
24 source-types + :
25 target-types + :
26 requirements * )
27 {
28 composing ?= true ;
29 generator.__init__ $(id) $(composing) : $(source-types)
30 : $(target-types) : $(requirements) ;
31 }
32
33 rule run ( project name ? : property-set : sources + )
34 {
35 sources += [ $(property-set).get <library> ] ;
36
37 # Add <library-path> properties for all searched libraries.
38 local extra = <relevant>link ;
39 for local s in $(sources)
40 {
41 if [ $(s).type ] = SEARCHED_LIB
42 {
43 local search = [ $(s).search ] ;
44 extra += <library-path>$(search) ;
45 }
46 }
47
48 # It is possible that sources include shared libraries that did not came
49 # from 'lib' targets, e.g. .so files specified as sources. In this case
50 # we have to add extra dll-path properties and propagate extra xdll-path
51 # properties so that application linking to us will get xdll-path to
52 # those libraries.
53 local extra-xdll-paths ;
54 for local s in $(sources)
55 {
56 if [ $(s).type ] && [ type.is-derived [ $(s).type ] SHARED_LIB ] && ! [ $(s).action ]
57 {
58 local location = [ path.root [ $(s).name ]
59 [ $(s).path ] ] ;
60 extra-xdll-paths += [ path.parent $(location) ] ;
61 }
62 }
63
64 # Hardcode DLL paths only when linking executables.
65 # Pros: do not need to relink libraries when installing.
66 # Cons: "standalone" libraries (plugins, python extensions) can not
67 # hardcode paths to dependent libraries.
68 if [ $(property-set).get <hardcode-dll-paths> ] = true
69 && [ type.is-derived $(self.target-types[1]) EXE ]
70 {
71 local xdll-path = [ $(property-set).get <xdll-path> ] ;
72 extra += <dll-path>$(xdll-path) <dll-path>$(extra-xdll-paths) ;
73 }
74
75 if $(extra)
76 {
77 property-set = [ $(property-set).add-raw $(extra) ] ;
78 }
79
80 local result = [ generator.run $(project) $(name) : $(property-set)
81 : $(sources) ] ;
82
83 local ur ;
84 if $(result)
85 {
86 ur = [ extra-usage-requirements $(result[2-]) : $(property-set) ] ;
87 ur = [ $(ur).add-raw
88 <relevant>link <xdll-path>$(extra-xdll-paths) ] ;
89 ur = [ $(ur).add $(result[1]) ] ;
90 }
91 return $(ur) $(result[2-]) ;
92 }
93
94 rule extra-usage-requirements ( created-targets * : property-set )
95 {
96 local result = [ property-set.empty ] ;
97 local extra ;
98
99 # Add appropriate <xdll-path> usage requirements.
100 local raw = [ $(property-set).raw ] ;
101 if <link>shared in $(raw)
102 {
103 local paths ;
104 local pwd = [ path.pwd ] ;
105 for local t in $(created-targets)
106 {
107 if [ type.is-derived [ $(t).type ] SHARED_LIB ]
108 {
109 paths += [ path.root [ path.make [ $(t).path ] ] $(pwd) ] ;
110 }
111 }
112 extra += $(paths:G=<xdll-path>) ;
113 }
114
115 # We need to pass <xdll-path> features that we've got from sources,
116 # because if a shared library is built, exe using it needs to know paths
117 # to other shared libraries this one depends on in order to be able to
118 # find them all at runtime.
119
120 # Just pass all features in property-set, it is theoretically possible
121 # that we will propagate <xdll-path> features explicitly specified by
122 # the user, but then the user is to blame for using an internal feature.
123 local values = [ $(property-set).get <xdll-path> ] ;
124 extra += $(values:G=<xdll-path>) ;
125
126 if $(extra)
127 {
128 result = [ property-set.create $(extra) ] ;
129 }
130 return $(result) ;
131 }
132
133 rule generated-targets ( sources + : property-set : project name ? )
134 {
135 local sources2 ; # Sources to pass to inherited rule.
136 local properties2 ; # Properties to pass to inherited rule.
137 local libraries ; # Library sources.
138
139 # Searched libraries are not passed as arguments to the linker but via
140 # some option. So, we pass them to the action using a property.
141 properties2 = [ $(property-set).raw ] ;
142 local fsa ;
143 local fst ;
144 for local s in $(sources)
145 {
146 if [ $(s).type ] && [ type.is-derived [ $(s).type ] SEARCHED_LIB ]
147 {
148 local name = [ $(s).name ] ;
149 if [ $(s).shared ]
150 {
151 fsa += $(name) ;
152 }
153 else
154 {
155 fst += $(name) ;
156 }
157 }
158 else
159 {
160 sources2 += $(s) ;
161 }
162 }
163 properties2 += <find-shared-library>$(fsa:J=&&)
164 <find-static-library>$(fst:J=&&) ;
165
166 return [ generator.generated-targets $(sources2)
167 : [ property-set.create $(properties2) ] : $(project) $(name) ] ;
168 }
169 }
170
171
172 rule register-linker ( id composing ? : source-types + : target-types +
173 : requirements * )
174 {
175 generators.register [ new linking-generator $(id) $(composing)
176 : $(source-types) : $(target-types) : $(requirements) ] ;
177 }
178
179 IMPORT $(__name__) : register-linker : : generators.register-linker ;