]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/tools/build/src/build/ac.jam
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / tools / build / src / build / ac.jam
1 # Copyright (c) 2010 Vladimir Prus.
2 # Copyright (c) 2013 Steven Watanabe
3 # Copyright (c) 2021 Rene Ferdinand Rivera Morell
4 #
5 # Use, modification and distribution is subject to the Boost Software
6 # License Version 1.0. (See accompanying file LICENSE.txt or
7 # https://www.bfgroup.xyz/b2/LICENSE.txt)
8
9 import property-set ;
10 import path ;
11 import modules ;
12 import "class" ;
13 import errors ;
14 import configure ;
15 import feature ;
16 import project ;
17 import virtual-target ;
18 import generators ;
19 import property ;
20 import print ;
21 import regex ;
22
23 project.initialize $(__name__) ;
24 .project = [ project.current ] ;
25 project ac ;
26
27 feature.feature ac.print-text : : free ;
28
29 rule generate-include ( target : sources * : properties * )
30 {
31 print.output $(target) ;
32 local text = [ property.select <ac.print-text> : $(properties) ] ;
33 if $(text)
34 {
35 print.text $(text:G=) : true ;
36 }
37 else
38 {
39 local header = [ property.select <include> : $(properties) ] ;
40 print.text "#include <$(header:G=)>\n" : true ;
41 }
42 }
43
44 rule generate-main ( target : sources * : properties * )
45 {
46 print.output $(target) ;
47 print.text "int main() {}" : true ;
48 }
49
50 rule find-include-path ( properties : header : provided-path ? : test-source ? )
51 {
52 if $(provided-path) && [ path.exists [ path.root $(header) $(provided-path) ] ]
53 {
54 return $(provided-path) ;
55 }
56 else
57 {
58 local a = [ class.new action : ac.generate-include : [ property-set.create <include>$(header) <ac.print-text>$(test-source) ] ] ;
59 # Create a new CPP target named after the header.
60 # Replace dots (".") in target basename for portability.
61 local basename = [ regex.replace $(header:D=) "[.]" "_" ] ;
62 local header-target = $(header:S=:B=$(basename)) ;
63 local cpp = [ class.new file-target $(header-target:S=.cpp) exact : CPP : $(.project) : $(a) ] ;
64 cpp = [ virtual-target.register $(cpp) ] ;
65 $(cpp).root true ;
66 local result = [ generators.construct $(.project) $(header-target) : OBJ : $(properties) : $(cpp) : true ] ;
67 configure.maybe-force-rebuild $(result[2-]) ;
68 local jam-targets ;
69 for local t in $(result[2-])
70 {
71 jam-targets += [ $(t).actualize ] ;
72 }
73 if [ UPDATE_NOW $(jam-targets) : [ modules.peek configure : .log-fd ]
74 : ignore-minus-n ]
75 {
76 return %default ;
77 }
78 }
79 }
80
81 rule construct-library ( name : property-set : provided-path ? )
82 {
83 local lib-props = [ $(property-set).add-raw <name>$(name) <search>$(provided-path) ] ;
84 return [ generators.construct $(.project) lib-$(name)
85 : SEARCHED_LIB : $(lib-props) : : true ] ;
86 }
87
88
89 rule find-library ( properties : names + : provided-path ? )
90 {
91 local result ;
92 if [ $(properties).get <link> ] = shared
93 {
94 link-opts = <link>shared <link>static ;
95 }
96 else
97 {
98 link-opts = <link>static <link>shared ;
99 }
100 while $(link-opts)
101 {
102 local names-iter = $(names) ;
103 properties = [ $(properties).refine [ property-set.create $(link-opts[1]) ] ] ;
104 while $(names-iter)
105 {
106 local name = $(names-iter[1]) ;
107 local lib = [ construct-library $(name) : $(properties) : $(provided-path) ] ;
108 local a = [ class.new action : ac.generate-main :
109 [ property-set.empty ] ] ;
110 local main.cpp = [ virtual-target.register
111 [ class.new file-target main-$(name).cpp exact : CPP : $(.project) : $(a) ] ] ;
112 $(main.cpp).root true ;
113 local test = [ generators.construct $(.project) $(name) : EXE
114 : [ $(properties).add $(lib[1]) ] : $(main.cpp) $(lib[2-])
115 : true ] ;
116 configure.maybe-force-rebuild $(test[2-]) ;
117 local jam-targets ;
118 for t in $(test[2-])
119 {
120 jam-targets += [ $(t).actualize ] ;
121 }
122 if [ UPDATE_NOW $(jam-targets) : [ modules.peek configure : .log-fd ]
123 : ignore-minus-n ]
124 {
125 result = $(name) $(link-opts[1]) ;
126 names-iter = ; link-opts = ; # break
127 }
128 names-iter = $(names-iter[2-]) ;
129 }
130 link-opts = $(link-opts[2-]) ;
131 }
132 return $(result) ;
133 }
134
135 class ac-library : basic-target
136 {
137 import errors ;
138 import indirect ;
139 import virtual-target ;
140 import ac ;
141 import configure ;
142 import config-cache ;
143 import os ;
144
145 rule __init__ ( name : project : requirements * : include-path ? : library-path ? : library-name ? )
146 {
147 basic-target.__init__ $(name) : $(project) : : $(requirements) ;
148
149 reconfigure $(include-path) : $(library-path) : $(library-name) ;
150 }
151
152 rule set-header ( header )
153 {
154 self.header = $(header) ;
155 }
156
157 rule set-default-names ( names + )
158 {
159 self.default-names = $(names) ;
160 }
161
162 rule set-header-test ( source )
163 {
164 self.header-test = $(source) ;
165 }
166
167 rule reconfigure ( include-path ? : library-path ? : library-name ? )
168 {
169 if $(include-path) || $(library-path) || $(library-name)
170 {
171 check-not-configured ;
172
173 self.include-path = $(include-path) ;
174 self.library-path = $(library-path) ;
175 self.library-name = $(library-name) ;
176 }
177 }
178
179 rule set-target ( target )
180 {
181 check-not-configured ;
182 self.target = $(target) ;
183 }
184
185 rule check-not-configured ( )
186 {
187 if $(self.include-path) || $(self.library-path) || $(self.library-name) || $(self.target)
188 {
189 errors.user-error [ name ] "is already configured" ;
190 }
191 }
192
193 rule construct ( name : sources * : property-set )
194 {
195 if $(self.target)
196 {
197 return [ $(self.target).generate $(property-set) ] ;
198 }
199 else
200 {
201 local use-environment ;
202 if ! $(self.library-name) && ! $(self.include-path) && ! $(self.library-path)
203 {
204 use-environment = true ;
205 }
206 local libnames = $(self.library-name) ;
207 if ! $(libnames) && $(use-environment)
208 {
209 libnames = [ os.environ $(name:U)_NAME ] ;
210 # Backward compatibility only.
211 libnames ?= [ os.environ $(name:U)_BINARY ] ;
212 }
213 libnames ?= $(self.default-names) ;
214
215 local include-path = $(self.include-path) ;
216 if ! $(include-path) && $(use-environment)
217 {
218 include-path = [ os.environ $(name:U)_INCLUDE ] ;
219 }
220
221 local library-path = $(self.library-path) ;
222 if ! $(library-path) && $(use-environment)
223 {
224 library-path = [ os.environ $(name:U)_LIBRARY_PATH ] ;
225 # Backwards compatibility only
226 library-path ?= [ os.environ $(name:U)_LIBPATH ] ;
227 }
228
229 local relevant = [ property.select [ configure.get-relevant-features ] <link> :
230 [ $(property-set).raw ] ] ;
231 local min = [ property.as-path [ SORT [ feature.minimize $(relevant) ] ] ] ;
232
233 local key = ac-library-$(name)-$(relevant:J=-) ;
234 local lookup = [ config-cache.get $(key) ] ;
235
236 if $(lookup)
237 {
238 if $(lookup) = missing
239 {
240 configure.log-library-search-result $(name) : "no (cached)" $(min) ;
241 return [ property-set.empty ] ;
242 }
243 else
244 {
245 local includes = $(lookup[1]) ;
246 if $(includes) = %default
247 {
248 includes = ;
249 }
250 local library = [ ac.construct-library $(lookup[2]) :
251 [ $(property-set).refine [ property-set.create $(lookup[3]) ] ] : $(library-path) ] ;
252 configure.log-library-search-result $(name) : "yes (cached)" $(min) ;
253 return [ $(library[1]).add-raw <include>$(includes) ] $(library[2-]) ;
254 }
255 }
256 else
257 {
258 local includes = [ ac.find-include-path $(property-set) : $(self.header) : $(include-path) : $(self.header-test) ] ;
259 local library = [ ac.find-library $(property-set) : $(libnames) : $(library-path) ] ;
260 if $(includes) && $(library)
261 {
262 config-cache.set $(key) : $(includes) $(library) ;
263 if $(includes) = %default
264 {
265 includes = ;
266 }
267 library = [ ac.construct-library $(library[1]) :
268 [ $(property-set).refine [ property-set.create $(library[2]) ] ] : $(library-path) ] ;
269 configure.log-library-search-result $(name) : "yes" $(min) ;
270 return [ $(library[1]).add-raw <include>$(includes) ] $(library[2-]) ;
271 }
272 else
273 {
274 config-cache.set $(key) : missing ;
275 configure.log-library-search-result $(name) : "no" $(min) ;
276 return [ property-set.empty ] ;
277 }
278 }
279 }
280 }
281 }
282
283 class check-library-worker
284 {
285 import property-set ;
286 import targets ;
287 import property ;
288
289 rule __init__ ( target : true-properties * : false-properties * )
290 {
291 self.target = $(target) ;
292 self.true-properties = $(true-properties) ;
293 self.false-properties = $(false-properties) ;
294 }
295
296 rule check ( properties * )
297 {
298 local choosen ;
299 local t = [ targets.current ] ;
300 local p = [ $(t).project ] ;
301 local ps = [ property-set.create $(properties) ] ;
302 ps = [ $(ps).propagated ] ;
303 local generated =
304 [ targets.generate-from-reference $(self.target) : $(p) : $(ps) ] ;
305 if $(generated[2])
306 {
307 choosen = $(self.true-properties) ;
308 }
309 else
310 {
311 choosen = $(self.false-properties) ;
312 }
313 return [ property.evaluate-conditionals-in-context $(choosen) :
314 $(properties) ] ;
315 }
316 }
317
318 rule check-library ( target : true-properties * : false-properties * )
319 {
320 local instance = [ class.new check-library-worker $(target) :
321 $(true-properties) : $(false-properties) ] ;
322 return <conditional>@$(instance).check
323 [ property.evaluate-conditional-relevance
324 $(true-properties) $(false-properties)
325 : [ configure.get-relevant-features ] <link> ] ;
326 }