1 | #! /usr/bin/env python |
---|
2 | # encoding: utf-8 |
---|
3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
4 | |
---|
5 | import os,re,shlex,sys |
---|
6 | from waflib import Build,Utils,Task,Options,Logs,Errors,ConfigSet,Runner |
---|
7 | from waflib.TaskGen import after_method,feature |
---|
8 | from waflib.Configure import conf |
---|
9 | WAF_CONFIG_H='config.h' |
---|
10 | DEFKEYS='define_key' |
---|
11 | INCKEYS='include_key' |
---|
12 | cfg_ver={'atleast-version':'>=','exact-version':'==','max-version':'<=',} |
---|
13 | SNIP_FUNCTION=''' |
---|
14 | int main(int argc, char **argv) { |
---|
15 | void *p; |
---|
16 | (void)argc; (void)argv; |
---|
17 | p=(void*)(%s); |
---|
18 | return 0; |
---|
19 | } |
---|
20 | ''' |
---|
21 | SNIP_TYPE=''' |
---|
22 | int main(int argc, char **argv) { |
---|
23 | (void)argc; (void)argv; |
---|
24 | if ((%(type_name)s *) 0) return 0; |
---|
25 | if (sizeof (%(type_name)s)) return 0; |
---|
26 | return 1; |
---|
27 | } |
---|
28 | ''' |
---|
29 | SNIP_EMPTY_PROGRAM=''' |
---|
30 | int main(int argc, char **argv) { |
---|
31 | (void)argc; (void)argv; |
---|
32 | return 0; |
---|
33 | } |
---|
34 | ''' |
---|
35 | SNIP_FIELD=''' |
---|
36 | int main(int argc, char **argv) { |
---|
37 | char *off; |
---|
38 | (void)argc; (void)argv; |
---|
39 | off = (char*) &((%(type_name)s*)0)->%(field_name)s; |
---|
40 | return (size_t) off < sizeof(%(type_name)s); |
---|
41 | } |
---|
42 | ''' |
---|
43 | MACRO_TO_DESTOS={'__linux__':'linux','__GNU__':'gnu','__FreeBSD__':'freebsd','__NetBSD__':'netbsd','__OpenBSD__':'openbsd','__sun':'sunos','__hpux':'hpux','__sgi':'irix','_AIX':'aix','__CYGWIN__':'cygwin','__MSYS__':'msys','_UWIN':'uwin','_WIN64':'win32','_WIN32':'win32','__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__':'darwin','__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__':'darwin','__QNX__':'qnx','__native_client__':'nacl'} |
---|
44 | MACRO_TO_DEST_CPU={'__x86_64__':'x86_64','__amd64__':'x86_64','__i386__':'x86','__ia64__':'ia','__mips__':'mips','__sparc__':'sparc','__alpha__':'alpha','__aarch64__':'aarch64','__thumb__':'thumb','__arm__':'arm','__hppa__':'hppa','__powerpc__':'powerpc','__ppc__':'powerpc','__convex__':'convex','__m68k__':'m68k','__s390x__':'s390x','__s390__':'s390','__sh__':'sh',} |
---|
45 | @conf |
---|
46 | def parse_flags(self,line,uselib_store,env=None,force_static=False): |
---|
47 | assert(isinstance(line,str)) |
---|
48 | env=env or self.env |
---|
49 | app=env.append_value |
---|
50 | appu=env.append_unique |
---|
51 | lex=shlex.shlex(line,posix=False) |
---|
52 | lex.whitespace_split=True |
---|
53 | lex.commenters='' |
---|
54 | lst=list(lex) |
---|
55 | uselib=uselib_store |
---|
56 | while lst: |
---|
57 | x=lst.pop(0) |
---|
58 | st=x[:2] |
---|
59 | ot=x[2:] |
---|
60 | if st=='-I'or st=='/I': |
---|
61 | if not ot:ot=lst.pop(0) |
---|
62 | appu('INCLUDES_'+uselib,[ot]) |
---|
63 | elif st=='-include': |
---|
64 | tmp=[x,lst.pop(0)] |
---|
65 | app('CFLAGS',tmp) |
---|
66 | app('CXXFLAGS',tmp) |
---|
67 | elif st=='-D'or(env.CXX_NAME=='msvc'and st=='/D'): |
---|
68 | if not ot:ot=lst.pop(0) |
---|
69 | app('DEFINES_'+uselib,[ot]) |
---|
70 | elif st=='-l': |
---|
71 | if not ot:ot=lst.pop(0) |
---|
72 | prefix=force_static and'STLIB_'or'LIB_' |
---|
73 | appu(prefix+uselib,[ot]) |
---|
74 | elif st=='-L': |
---|
75 | if not ot:ot=lst.pop(0) |
---|
76 | appu('LIBPATH_'+uselib,[ot]) |
---|
77 | elif x.startswith('/LIBPATH:'): |
---|
78 | appu('LIBPATH_'+uselib,[x.replace('/LIBPATH:','')]) |
---|
79 | elif x=='-pthread'or x.startswith('+')or x.startswith('-std'): |
---|
80 | app('CFLAGS_'+uselib,[x]) |
---|
81 | app('CXXFLAGS_'+uselib,[x]) |
---|
82 | app('LINKFLAGS_'+uselib,[x]) |
---|
83 | elif x=='-framework': |
---|
84 | appu('FRAMEWORK_'+uselib,[lst.pop(0)]) |
---|
85 | elif x.startswith('-F'): |
---|
86 | appu('FRAMEWORKPATH_'+uselib,[x[2:]]) |
---|
87 | elif x.startswith('-Wl'): |
---|
88 | app('LINKFLAGS_'+uselib,[x]) |
---|
89 | elif x.startswith('-m')or x.startswith('-f')or x.startswith('-dynamic'): |
---|
90 | app('CFLAGS_'+uselib,[x]) |
---|
91 | app('CXXFLAGS_'+uselib,[x]) |
---|
92 | elif x.startswith('-bundle'): |
---|
93 | app('LINKFLAGS_'+uselib,[x]) |
---|
94 | elif x.startswith('-undefined'): |
---|
95 | arg=lst.pop(0) |
---|
96 | app('LINKFLAGS_'+uselib,[x,arg]) |
---|
97 | elif x.startswith('-arch')or x.startswith('-isysroot'): |
---|
98 | tmp=[x,lst.pop(0)] |
---|
99 | app('CFLAGS_'+uselib,tmp) |
---|
100 | app('CXXFLAGS_'+uselib,tmp) |
---|
101 | app('LINKFLAGS_'+uselib,tmp) |
---|
102 | elif x.endswith('.a')or x.endswith('.so')or x.endswith('.dylib')or x.endswith('.lib'): |
---|
103 | appu('LINKFLAGS_'+uselib,[x]) |
---|
104 | @conf |
---|
105 | def ret_msg(self,f,kw): |
---|
106 | if isinstance(f,str): |
---|
107 | return f |
---|
108 | return f(kw) |
---|
109 | @conf |
---|
110 | def validate_cfg(self,kw): |
---|
111 | if not'path'in kw: |
---|
112 | if not self.env.PKGCONFIG: |
---|
113 | self.find_program('pkg-config',var='PKGCONFIG') |
---|
114 | kw['path']=self.env.PKGCONFIG |
---|
115 | if'atleast_pkgconfig_version'in kw: |
---|
116 | if not'msg'in kw: |
---|
117 | kw['msg']='Checking for pkg-config version >= %r'%kw['atleast_pkgconfig_version'] |
---|
118 | return |
---|
119 | if not'okmsg'in kw: |
---|
120 | kw['okmsg']='yes' |
---|
121 | if not'errmsg'in kw: |
---|
122 | kw['errmsg']='not found' |
---|
123 | if'modversion'in kw: |
---|
124 | if not'msg'in kw: |
---|
125 | kw['msg']='Checking for %r version'%kw['modversion'] |
---|
126 | return |
---|
127 | for x in cfg_ver.keys(): |
---|
128 | y=x.replace('-','_') |
---|
129 | if y in kw: |
---|
130 | if not'package'in kw: |
---|
131 | raise ValueError('%s requires a package'%x) |
---|
132 | if not'msg'in kw: |
---|
133 | kw['msg']='Checking for %r %s %s'%(kw['package'],cfg_ver[x],kw[y]) |
---|
134 | return |
---|
135 | if not'msg'in kw: |
---|
136 | kw['msg']='Checking for %r'%(kw['package']or kw['path']) |
---|
137 | @conf |
---|
138 | def exec_cfg(self,kw): |
---|
139 | def define_it(): |
---|
140 | self.define(self.have_define(kw.get('uselib_store',kw['package'])),1,0) |
---|
141 | if'atleast_pkgconfig_version'in kw: |
---|
142 | cmd=[kw['path'],'--atleast-pkgconfig-version=%s'%kw['atleast_pkgconfig_version']] |
---|
143 | self.cmd_and_log(cmd) |
---|
144 | if not'okmsg'in kw: |
---|
145 | kw['okmsg']='yes' |
---|
146 | return |
---|
147 | for x in cfg_ver: |
---|
148 | y=x.replace('-','_') |
---|
149 | if y in kw: |
---|
150 | self.cmd_and_log([kw['path'],'--%s=%s'%(x,kw[y]),kw['package']]) |
---|
151 | if not'okmsg'in kw: |
---|
152 | kw['okmsg']='yes' |
---|
153 | define_it() |
---|
154 | break |
---|
155 | if'modversion'in kw: |
---|
156 | version=self.cmd_and_log([kw['path'],'--modversion',kw['modversion']]).strip() |
---|
157 | self.define('%s_VERSION'%Utils.quote_define_name(kw.get('uselib_store',kw['modversion'])),version) |
---|
158 | return version |
---|
159 | lst=[kw['path']] |
---|
160 | defi=kw.get('define_variable',None) |
---|
161 | if not defi: |
---|
162 | defi=self.env.PKG_CONFIG_DEFINES or{} |
---|
163 | for key,val in defi.items(): |
---|
164 | lst.append('--define-variable=%s=%s'%(key,val)) |
---|
165 | static=False |
---|
166 | if'args'in kw: |
---|
167 | args=Utils.to_list(kw['args']) |
---|
168 | if'--static'in args or'--static-libs'in args: |
---|
169 | static=True |
---|
170 | lst+=args |
---|
171 | lst.extend(Utils.to_list(kw['package'])) |
---|
172 | if'variables'in kw: |
---|
173 | env=kw.get('env',self.env) |
---|
174 | uselib=kw.get('uselib_store',kw['package'].upper()) |
---|
175 | vars=Utils.to_list(kw['variables']) |
---|
176 | for v in vars: |
---|
177 | val=self.cmd_and_log(lst+['--variable='+v]).strip() |
---|
178 | var='%s_%s'%(uselib,v) |
---|
179 | env[var]=val |
---|
180 | if not'okmsg'in kw: |
---|
181 | kw['okmsg']='yes' |
---|
182 | return |
---|
183 | ret=self.cmd_and_log(lst) |
---|
184 | if not'okmsg'in kw: |
---|
185 | kw['okmsg']='yes' |
---|
186 | define_it() |
---|
187 | self.parse_flags(ret,kw.get('uselib_store',kw['package'].upper()),kw.get('env',self.env),force_static=static) |
---|
188 | return ret |
---|
189 | @conf |
---|
190 | def check_cfg(self,*k,**kw): |
---|
191 | if k: |
---|
192 | lst=k[0].split() |
---|
193 | kw['package']=lst[0] |
---|
194 | kw['args']=' '.join(lst[1:]) |
---|
195 | self.validate_cfg(kw) |
---|
196 | if'msg'in kw: |
---|
197 | self.start_msg(kw['msg']) |
---|
198 | ret=None |
---|
199 | try: |
---|
200 | ret=self.exec_cfg(kw) |
---|
201 | except self.errors.WafError: |
---|
202 | if'errmsg'in kw: |
---|
203 | self.end_msg(kw['errmsg'],'YELLOW') |
---|
204 | if Logs.verbose>1: |
---|
205 | raise |
---|
206 | else: |
---|
207 | self.fatal('The configuration failed') |
---|
208 | else: |
---|
209 | kw['success']=ret |
---|
210 | if'okmsg'in kw: |
---|
211 | self.end_msg(self.ret_msg(kw['okmsg'],kw)) |
---|
212 | return ret |
---|
213 | @conf |
---|
214 | def validate_c(self,kw): |
---|
215 | if not'env'in kw: |
---|
216 | kw['env']=self.env.derive() |
---|
217 | env=kw['env'] |
---|
218 | if not'compiler'in kw and not'features'in kw: |
---|
219 | kw['compiler']='c' |
---|
220 | if env['CXX_NAME']and Task.classes.get('cxx',None): |
---|
221 | kw['compiler']='cxx' |
---|
222 | if not self.env['CXX']: |
---|
223 | self.fatal('a c++ compiler is required') |
---|
224 | else: |
---|
225 | if not self.env['CC']: |
---|
226 | self.fatal('a c compiler is required') |
---|
227 | if not'compile_mode'in kw: |
---|
228 | kw['compile_mode']='c' |
---|
229 | if'cxx'in Utils.to_list(kw.get('features',[]))or kw.get('compiler','')=='cxx': |
---|
230 | kw['compile_mode']='cxx' |
---|
231 | if not'type'in kw: |
---|
232 | kw['type']='cprogram' |
---|
233 | if not'features'in kw: |
---|
234 | kw['features']=[kw['compile_mode'],kw['type']] |
---|
235 | else: |
---|
236 | kw['features']=Utils.to_list(kw['features']) |
---|
237 | if not'compile_filename'in kw: |
---|
238 | kw['compile_filename']='test.c'+((kw['compile_mode']=='cxx')and'pp'or'') |
---|
239 | def to_header(dct): |
---|
240 | if'header_name'in dct: |
---|
241 | dct=Utils.to_list(dct['header_name']) |
---|
242 | return''.join(['#include <%s>\n'%x for x in dct]) |
---|
243 | return'' |
---|
244 | if'framework_name'in kw: |
---|
245 | fwkname=kw['framework_name'] |
---|
246 | if not'uselib_store'in kw: |
---|
247 | kw['uselib_store']=fwkname.upper() |
---|
248 | if not kw.get('no_header',False): |
---|
249 | if not'header_name'in kw: |
---|
250 | kw['header_name']=[] |
---|
251 | fwk='%s/%s.h'%(fwkname,fwkname) |
---|
252 | if kw.get('remove_dot_h',None): |
---|
253 | fwk=fwk[:-2] |
---|
254 | kw['header_name']=Utils.to_list(kw['header_name'])+[fwk] |
---|
255 | kw['msg']='Checking for framework %s'%fwkname |
---|
256 | kw['framework']=fwkname |
---|
257 | if'function_name'in kw: |
---|
258 | fu=kw['function_name'] |
---|
259 | if not'msg'in kw: |
---|
260 | kw['msg']='Checking for function %s'%fu |
---|
261 | kw['code']=to_header(kw)+SNIP_FUNCTION%fu |
---|
262 | if not'uselib_store'in kw: |
---|
263 | kw['uselib_store']=fu.upper() |
---|
264 | if not'define_name'in kw: |
---|
265 | kw['define_name']=self.have_define(fu) |
---|
266 | elif'type_name'in kw: |
---|
267 | tu=kw['type_name'] |
---|
268 | if not'header_name'in kw: |
---|
269 | kw['header_name']='stdint.h' |
---|
270 | if'field_name'in kw: |
---|
271 | field=kw['field_name'] |
---|
272 | kw['code']=to_header(kw)+SNIP_FIELD%{'type_name':tu,'field_name':field} |
---|
273 | if not'msg'in kw: |
---|
274 | kw['msg']='Checking for field %s in %s'%(field,tu) |
---|
275 | if not'define_name'in kw: |
---|
276 | kw['define_name']=self.have_define((tu+'_'+field).upper()) |
---|
277 | else: |
---|
278 | kw['code']=to_header(kw)+SNIP_TYPE%{'type_name':tu} |
---|
279 | if not'msg'in kw: |
---|
280 | kw['msg']='Checking for type %s'%tu |
---|
281 | if not'define_name'in kw: |
---|
282 | kw['define_name']=self.have_define(tu.upper()) |
---|
283 | elif'header_name'in kw: |
---|
284 | if not'msg'in kw: |
---|
285 | kw['msg']='Checking for header %s'%kw['header_name'] |
---|
286 | l=Utils.to_list(kw['header_name']) |
---|
287 | assert len(l)>0,'list of headers in header_name is empty' |
---|
288 | kw['code']=to_header(kw)+SNIP_EMPTY_PROGRAM |
---|
289 | if not'uselib_store'in kw: |
---|
290 | kw['uselib_store']=l[0].upper() |
---|
291 | if not'define_name'in kw: |
---|
292 | kw['define_name']=self.have_define(l[0]) |
---|
293 | if'lib'in kw: |
---|
294 | if not'msg'in kw: |
---|
295 | kw['msg']='Checking for library %s'%kw['lib'] |
---|
296 | if not'uselib_store'in kw: |
---|
297 | kw['uselib_store']=kw['lib'].upper() |
---|
298 | if'stlib'in kw: |
---|
299 | if not'msg'in kw: |
---|
300 | kw['msg']='Checking for static library %s'%kw['stlib'] |
---|
301 | if not'uselib_store'in kw: |
---|
302 | kw['uselib_store']=kw['stlib'].upper() |
---|
303 | if'fragment'in kw: |
---|
304 | kw['code']=kw['fragment'] |
---|
305 | if not'msg'in kw: |
---|
306 | kw['msg']='Checking for code snippet' |
---|
307 | if not'errmsg'in kw: |
---|
308 | kw['errmsg']='no' |
---|
309 | for(flagsname,flagstype)in[('cxxflags','compiler'),('cflags','compiler'),('linkflags','linker')]: |
---|
310 | if flagsname in kw: |
---|
311 | if not'msg'in kw: |
---|
312 | kw['msg']='Checking for %s flags %s'%(flagstype,kw[flagsname]) |
---|
313 | if not'errmsg'in kw: |
---|
314 | kw['errmsg']='no' |
---|
315 | if not'execute'in kw: |
---|
316 | kw['execute']=False |
---|
317 | if kw['execute']: |
---|
318 | kw['features'].append('test_exec') |
---|
319 | if not'errmsg'in kw: |
---|
320 | kw['errmsg']='not found' |
---|
321 | if not'okmsg'in kw: |
---|
322 | kw['okmsg']='yes' |
---|
323 | if not'code'in kw: |
---|
324 | kw['code']=SNIP_EMPTY_PROGRAM |
---|
325 | if self.env[INCKEYS]: |
---|
326 | kw['code']='\n'.join(['#include <%s>'%x for x in self.env[INCKEYS]])+'\n'+kw['code'] |
---|
327 | if not kw.get('success'):kw['success']=None |
---|
328 | if'define_name'in kw: |
---|
329 | self.undefine(kw['define_name']) |
---|
330 | if not'msg'in kw: |
---|
331 | self.fatal('missing "msg" in conf.check(...)') |
---|
332 | @conf |
---|
333 | def post_check(self,*k,**kw): |
---|
334 | is_success=0 |
---|
335 | if kw['execute']: |
---|
336 | if kw['success']is not None: |
---|
337 | if kw.get('define_ret',False): |
---|
338 | is_success=kw['success'] |
---|
339 | else: |
---|
340 | is_success=(kw['success']==0) |
---|
341 | else: |
---|
342 | is_success=(kw['success']==0) |
---|
343 | if'define_name'in kw: |
---|
344 | if'header_name'in kw or'function_name'in kw or'type_name'in kw or'fragment'in kw: |
---|
345 | if kw['execute']and kw.get('define_ret',None)and isinstance(is_success,str): |
---|
346 | self.define(kw['define_name'],is_success,quote=kw.get('quote',1)) |
---|
347 | else: |
---|
348 | self.define_cond(kw['define_name'],is_success) |
---|
349 | else: |
---|
350 | self.define_cond(kw['define_name'],is_success) |
---|
351 | if'header_name'in kw: |
---|
352 | if kw.get('auto_add_header_name',False): |
---|
353 | self.env.append_value(INCKEYS,Utils.to_list(kw['header_name'])) |
---|
354 | if is_success and'uselib_store'in kw: |
---|
355 | from waflib.Tools import ccroot |
---|
356 | _vars=set([]) |
---|
357 | for x in kw['features']: |
---|
358 | if x in ccroot.USELIB_VARS: |
---|
359 | _vars|=ccroot.USELIB_VARS[x] |
---|
360 | for k in _vars: |
---|
361 | lk=k.lower() |
---|
362 | if lk in kw: |
---|
363 | val=kw[lk] |
---|
364 | if isinstance(val,str): |
---|
365 | val=val.rstrip(os.path.sep) |
---|
366 | self.env.append_unique(k+'_'+kw['uselib_store'],Utils.to_list(val)) |
---|
367 | return is_success |
---|
368 | @conf |
---|
369 | def check(self,*k,**kw): |
---|
370 | self.validate_c(kw) |
---|
371 | self.start_msg(kw['msg']) |
---|
372 | ret=None |
---|
373 | try: |
---|
374 | ret=self.run_c_code(*k,**kw) |
---|
375 | except self.errors.ConfigurationError: |
---|
376 | self.end_msg(kw['errmsg'],'YELLOW') |
---|
377 | if Logs.verbose>1: |
---|
378 | raise |
---|
379 | else: |
---|
380 | self.fatal('The configuration failed') |
---|
381 | else: |
---|
382 | kw['success']=ret |
---|
383 | ret=self.post_check(*k,**kw) |
---|
384 | if not ret: |
---|
385 | self.end_msg(kw['errmsg'],'YELLOW') |
---|
386 | self.fatal('The configuration failed %r'%ret) |
---|
387 | else: |
---|
388 | self.end_msg(self.ret_msg(kw['okmsg'],kw)) |
---|
389 | return ret |
---|
390 | class test_exec(Task.Task): |
---|
391 | color='PINK' |
---|
392 | def run(self): |
---|
393 | if getattr(self.generator,'rpath',None): |
---|
394 | if getattr(self.generator,'define_ret',False): |
---|
395 | self.generator.bld.retval=self.generator.bld.cmd_and_log([self.inputs[0].abspath()]) |
---|
396 | else: |
---|
397 | self.generator.bld.retval=self.generator.bld.exec_command([self.inputs[0].abspath()]) |
---|
398 | else: |
---|
399 | env=self.env.env or{} |
---|
400 | env.update(dict(os.environ)) |
---|
401 | for var in('LD_LIBRARY_PATH','DYLD_LIBRARY_PATH','PATH'): |
---|
402 | env[var]=self.inputs[0].parent.abspath()+os.path.pathsep+env.get(var,'') |
---|
403 | if getattr(self.generator,'define_ret',False): |
---|
404 | self.generator.bld.retval=self.generator.bld.cmd_and_log([self.inputs[0].abspath()],env=env) |
---|
405 | else: |
---|
406 | self.generator.bld.retval=self.generator.bld.exec_command([self.inputs[0].abspath()],env=env) |
---|
407 | @feature('test_exec') |
---|
408 | @after_method('apply_link') |
---|
409 | def test_exec_fun(self): |
---|
410 | self.create_task('test_exec',self.link_task.outputs[0]) |
---|
411 | CACHE_RESULTS=1 |
---|
412 | COMPILE_ERRORS=2 |
---|
413 | @conf |
---|
414 | def run_c_code(self,*k,**kw): |
---|
415 | lst=[str(v)for(p,v)in kw.items()if p!='env'] |
---|
416 | h=Utils.h_list(lst) |
---|
417 | dir=self.bldnode.abspath()+os.sep+(not Utils.is_win32 and'.'or'')+'conf_check_'+Utils.to_hex(h) |
---|
418 | try: |
---|
419 | os.makedirs(dir) |
---|
420 | except OSError: |
---|
421 | pass |
---|
422 | try: |
---|
423 | os.stat(dir) |
---|
424 | except OSError: |
---|
425 | self.fatal('cannot use the configuration test folder %r'%dir) |
---|
426 | cachemode=getattr(Options.options,'confcache',None) |
---|
427 | if cachemode==CACHE_RESULTS: |
---|
428 | try: |
---|
429 | proj=ConfigSet.ConfigSet(os.path.join(dir,'cache_run_c_code')) |
---|
430 | except OSError: |
---|
431 | pass |
---|
432 | else: |
---|
433 | ret=proj['cache_run_c_code'] |
---|
434 | if isinstance(ret,str)and ret.startswith('Test does not build'): |
---|
435 | self.fatal(ret) |
---|
436 | return ret |
---|
437 | bdir=os.path.join(dir,'testbuild') |
---|
438 | if not os.path.exists(bdir): |
---|
439 | os.makedirs(bdir) |
---|
440 | self.test_bld=bld=Build.BuildContext(top_dir=dir,out_dir=bdir) |
---|
441 | bld.init_dirs() |
---|
442 | bld.progress_bar=0 |
---|
443 | bld.targets='*' |
---|
444 | if kw['compile_filename']: |
---|
445 | node=bld.srcnode.make_node(kw['compile_filename']) |
---|
446 | node.write(kw['code']) |
---|
447 | bld.logger=self.logger |
---|
448 | bld.all_envs.update(self.all_envs) |
---|
449 | bld.env=kw['env'] |
---|
450 | o=bld(features=kw['features'],source=kw['compile_filename'],target='testprog') |
---|
451 | for k,v in kw.items(): |
---|
452 | setattr(o,k,v) |
---|
453 | self.to_log("==>\n%s\n<=="%kw['code']) |
---|
454 | bld.targets='*' |
---|
455 | ret=-1 |
---|
456 | try: |
---|
457 | try: |
---|
458 | bld.compile() |
---|
459 | except Errors.WafError: |
---|
460 | ret='Test does not build: %s'%Utils.ex_stack() |
---|
461 | self.fatal(ret) |
---|
462 | else: |
---|
463 | ret=getattr(bld,'retval',0) |
---|
464 | finally: |
---|
465 | proj=ConfigSet.ConfigSet() |
---|
466 | proj['cache_run_c_code']=ret |
---|
467 | proj.store(os.path.join(dir,'cache_run_c_code')) |
---|
468 | return ret |
---|
469 | @conf |
---|
470 | def check_cxx(self,*k,**kw): |
---|
471 | kw['compiler']='cxx' |
---|
472 | return self.check(*k,**kw) |
---|
473 | @conf |
---|
474 | def check_cc(self,*k,**kw): |
---|
475 | kw['compiler']='c' |
---|
476 | return self.check(*k,**kw) |
---|
477 | @conf |
---|
478 | def define(self,key,val,quote=True): |
---|
479 | assert key and isinstance(key,str) |
---|
480 | if val is True: |
---|
481 | val=1 |
---|
482 | elif val in(False,None): |
---|
483 | val=0 |
---|
484 | if isinstance(val,int)or isinstance(val,float): |
---|
485 | s='%s=%s' |
---|
486 | else: |
---|
487 | s=quote and'%s="%s"'or'%s=%s' |
---|
488 | app=s%(key,str(val)) |
---|
489 | ban=key+'=' |
---|
490 | lst=self.env['DEFINES'] |
---|
491 | for x in lst: |
---|
492 | if x.startswith(ban): |
---|
493 | lst[lst.index(x)]=app |
---|
494 | break |
---|
495 | else: |
---|
496 | self.env.append_value('DEFINES',app) |
---|
497 | self.env.append_unique(DEFKEYS,key) |
---|
498 | @conf |
---|
499 | def undefine(self,key): |
---|
500 | assert key and isinstance(key,str) |
---|
501 | ban=key+'=' |
---|
502 | lst=[x for x in self.env['DEFINES']if not x.startswith(ban)] |
---|
503 | self.env['DEFINES']=lst |
---|
504 | self.env.append_unique(DEFKEYS,key) |
---|
505 | @conf |
---|
506 | def define_cond(self,key,val): |
---|
507 | assert key and isinstance(key,str) |
---|
508 | if val: |
---|
509 | self.define(key,1) |
---|
510 | else: |
---|
511 | self.undefine(key) |
---|
512 | @conf |
---|
513 | def is_defined(self,key): |
---|
514 | assert key and isinstance(key,str) |
---|
515 | ban=key+'=' |
---|
516 | for x in self.env['DEFINES']: |
---|
517 | if x.startswith(ban): |
---|
518 | return True |
---|
519 | return False |
---|
520 | @conf |
---|
521 | def get_define(self,key): |
---|
522 | assert key and isinstance(key,str) |
---|
523 | ban=key+'=' |
---|
524 | for x in self.env['DEFINES']: |
---|
525 | if x.startswith(ban): |
---|
526 | return x[len(ban):] |
---|
527 | return None |
---|
528 | @conf |
---|
529 | def have_define(self,key): |
---|
530 | return(self.env.HAVE_PAT or'HAVE_%s')%Utils.quote_define_name(key) |
---|
531 | @conf |
---|
532 | def write_config_header(self,configfile='',guard='',top=False,env=None,defines=True,headers=False,remove=True,define_prefix=''): |
---|
533 | if env: |
---|
534 | Logs.warn('Cannot pass env to write_config_header') |
---|
535 | if not configfile:configfile=WAF_CONFIG_H |
---|
536 | waf_guard=guard or'W_%s_WAF'%Utils.quote_define_name(configfile) |
---|
537 | node=top and self.bldnode or self.path.get_bld() |
---|
538 | node=node.make_node(configfile) |
---|
539 | node.parent.mkdir() |
---|
540 | lst=['/* WARNING! All changes made to this file will be lost! */\n'] |
---|
541 | lst.append('#ifndef %s\n#define %s\n'%(waf_guard,waf_guard)) |
---|
542 | lst.append(self.get_config_header(defines,headers,define_prefix=define_prefix)) |
---|
543 | lst.append('\n#endif /* %s */\n'%waf_guard) |
---|
544 | node.write('\n'.join(lst)) |
---|
545 | self.env.append_unique(Build.CFG_FILES,[node.abspath()]) |
---|
546 | if remove: |
---|
547 | for key in self.env[DEFKEYS]: |
---|
548 | self.undefine(key) |
---|
549 | self.env[DEFKEYS]=[] |
---|
550 | @conf |
---|
551 | def get_config_header(self,defines=True,headers=False,define_prefix=''): |
---|
552 | lst=[] |
---|
553 | if headers: |
---|
554 | for x in self.env[INCKEYS]: |
---|
555 | lst.append('#include <%s>'%x) |
---|
556 | if defines: |
---|
557 | for x in self.env[DEFKEYS]: |
---|
558 | if self.is_defined(x): |
---|
559 | val=self.get_define(x) |
---|
560 | lst.append('#define %s %s'%(define_prefix+x,val)) |
---|
561 | else: |
---|
562 | lst.append('/* #undef %s */'%(define_prefix+x)) |
---|
563 | return"\n".join(lst) |
---|
564 | @conf |
---|
565 | def cc_add_flags(conf): |
---|
566 | conf.add_os_flags('CPPFLAGS','CFLAGS') |
---|
567 | conf.add_os_flags('CFLAGS') |
---|
568 | @conf |
---|
569 | def cxx_add_flags(conf): |
---|
570 | conf.add_os_flags('CPPFLAGS','CXXFLAGS') |
---|
571 | conf.add_os_flags('CXXFLAGS') |
---|
572 | @conf |
---|
573 | def link_add_flags(conf): |
---|
574 | conf.add_os_flags('LINKFLAGS') |
---|
575 | conf.add_os_flags('LDFLAGS','LINKFLAGS') |
---|
576 | @conf |
---|
577 | def cc_load_tools(conf): |
---|
578 | if not conf.env.DEST_OS: |
---|
579 | conf.env.DEST_OS=Utils.unversioned_sys_platform() |
---|
580 | conf.load('c') |
---|
581 | @conf |
---|
582 | def cxx_load_tools(conf): |
---|
583 | if not conf.env.DEST_OS: |
---|
584 | conf.env.DEST_OS=Utils.unversioned_sys_platform() |
---|
585 | conf.load('cxx') |
---|
586 | @conf |
---|
587 | def get_cc_version(conf,cc,gcc=False,icc=False): |
---|
588 | cmd=cc+['-dM','-E','-'] |
---|
589 | env=conf.env.env or None |
---|
590 | try: |
---|
591 | p=Utils.subprocess.Popen(cmd,stdin=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE,stderr=Utils.subprocess.PIPE,env=env) |
---|
592 | p.stdin.write('\n') |
---|
593 | out=p.communicate()[0] |
---|
594 | except Exception: |
---|
595 | conf.fatal('Could not determine the compiler version %r'%cmd) |
---|
596 | if not isinstance(out,str): |
---|
597 | out=out.decode(sys.stdout.encoding or'iso8859-1') |
---|
598 | if gcc: |
---|
599 | if out.find('__INTEL_COMPILER')>=0: |
---|
600 | conf.fatal('The intel compiler pretends to be gcc') |
---|
601 | if out.find('__GNUC__')<0 and out.find('__clang__')<0: |
---|
602 | conf.fatal('Could not determine the compiler type') |
---|
603 | if icc and out.find('__INTEL_COMPILER')<0: |
---|
604 | conf.fatal('Not icc/icpc') |
---|
605 | k={} |
---|
606 | if icc or gcc: |
---|
607 | out=out.splitlines() |
---|
608 | for line in out: |
---|
609 | lst=shlex.split(line) |
---|
610 | if len(lst)>2: |
---|
611 | key=lst[1] |
---|
612 | val=lst[2] |
---|
613 | k[key]=val |
---|
614 | def isD(var): |
---|
615 | return var in k |
---|
616 | def isT(var): |
---|
617 | return var in k and k[var]!='0' |
---|
618 | if not conf.env.DEST_OS: |
---|
619 | conf.env.DEST_OS='' |
---|
620 | for i in MACRO_TO_DESTOS: |
---|
621 | if isD(i): |
---|
622 | conf.env.DEST_OS=MACRO_TO_DESTOS[i] |
---|
623 | break |
---|
624 | else: |
---|
625 | if isD('__APPLE__')and isD('__MACH__'): |
---|
626 | conf.env.DEST_OS='darwin' |
---|
627 | elif isD('__unix__'): |
---|
628 | conf.env.DEST_OS='generic' |
---|
629 | if isD('__ELF__'): |
---|
630 | conf.env.DEST_BINFMT='elf' |
---|
631 | elif isD('__WINNT__')or isD('__CYGWIN__')or isD('_WIN32'): |
---|
632 | conf.env.DEST_BINFMT='pe' |
---|
633 | conf.env.LIBDIR=conf.env.BINDIR |
---|
634 | elif isD('__APPLE__'): |
---|
635 | conf.env.DEST_BINFMT='mac-o' |
---|
636 | if not conf.env.DEST_BINFMT: |
---|
637 | conf.env.DEST_BINFMT=Utils.destos_to_binfmt(conf.env.DEST_OS) |
---|
638 | for i in MACRO_TO_DEST_CPU: |
---|
639 | if isD(i): |
---|
640 | conf.env.DEST_CPU=MACRO_TO_DEST_CPU[i] |
---|
641 | break |
---|
642 | Logs.debug('ccroot: dest platform: '+' '.join([conf.env[x]or'?'for x in('DEST_OS','DEST_BINFMT','DEST_CPU')])) |
---|
643 | if icc: |
---|
644 | ver=k['__INTEL_COMPILER'] |
---|
645 | conf.env['CC_VERSION']=(ver[:-2],ver[-2],ver[-1]) |
---|
646 | else: |
---|
647 | if isD('__clang__'): |
---|
648 | conf.env['CC_VERSION']=(k['__clang_major__'],k['__clang_minor__'],k['__clang_patchlevel__']) |
---|
649 | else: |
---|
650 | conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__']) |
---|
651 | return k |
---|
652 | @conf |
---|
653 | def get_xlc_version(conf,cc): |
---|
654 | cmd=cc+['-qversion'] |
---|
655 | try: |
---|
656 | out,err=conf.cmd_and_log(cmd,output=0) |
---|
657 | except Errors.WafError: |
---|
658 | conf.fatal('Could not find xlc %r'%cmd) |
---|
659 | for v in(r"IBM XL C/C\+\+.* V(?P<major>\d*)\.(?P<minor>\d*)",): |
---|
660 | version_re=re.compile(v,re.I).search |
---|
661 | match=version_re(out or err) |
---|
662 | if match: |
---|
663 | k=match.groupdict() |
---|
664 | conf.env['CC_VERSION']=(k['major'],k['minor']) |
---|
665 | break |
---|
666 | else: |
---|
667 | conf.fatal('Could not determine the XLC version.') |
---|
668 | @conf |
---|
669 | def get_suncc_version(conf,cc): |
---|
670 | cmd=cc+['-V'] |
---|
671 | try: |
---|
672 | out,err=conf.cmd_and_log(cmd,output=0) |
---|
673 | except Errors.WafError ,e: |
---|
674 | if not(hasattr(e,'returncode')and hasattr(e,'stdout')and hasattr(e,'stderr')): |
---|
675 | conf.fatal('Could not find suncc %r'%cmd) |
---|
676 | out=e.stdout |
---|
677 | err=e.stderr |
---|
678 | version=(out or err) |
---|
679 | version=version.split('\n')[0] |
---|
680 | version_re=re.compile(r'cc:\s+sun\s+(c\+\+|c)\s+(?P<major>\d*)\.(?P<minor>\d*)',re.I).search |
---|
681 | match=version_re(version) |
---|
682 | if match: |
---|
683 | k=match.groupdict() |
---|
684 | conf.env['CC_VERSION']=(k['major'],k['minor']) |
---|
685 | else: |
---|
686 | conf.fatal('Could not determine the suncc version.') |
---|
687 | @conf |
---|
688 | def add_as_needed(self): |
---|
689 | if self.env.DEST_BINFMT=='elf'and'gcc'in(self.env.CXX_NAME,self.env.CC_NAME): |
---|
690 | self.env.append_unique('LINKFLAGS','--as-needed') |
---|
691 | class cfgtask(Task.TaskBase): |
---|
692 | def display(self): |
---|
693 | return'' |
---|
694 | def runnable_status(self): |
---|
695 | return Task.RUN_ME |
---|
696 | def uid(self): |
---|
697 | return Utils.SIG_NIL |
---|
698 | def run(self): |
---|
699 | conf=self.conf |
---|
700 | bld=Build.BuildContext(top_dir=conf.srcnode.abspath(),out_dir=conf.bldnode.abspath()) |
---|
701 | bld.env=conf.env |
---|
702 | bld.init_dirs() |
---|
703 | bld.in_msg=1 |
---|
704 | bld.logger=self.logger |
---|
705 | try: |
---|
706 | bld.check(**self.args) |
---|
707 | except Exception: |
---|
708 | return 1 |
---|
709 | @conf |
---|
710 | def multicheck(self,*k,**kw): |
---|
711 | self.start_msg(kw.get('msg','Executing %d configuration tests'%len(k))) |
---|
712 | class par(object): |
---|
713 | def __init__(self): |
---|
714 | self.keep=False |
---|
715 | self.cache_global=Options.cache_global |
---|
716 | self.nocache=Options.options.nocache |
---|
717 | self.returned_tasks=[] |
---|
718 | self.task_sigs={} |
---|
719 | def total(self): |
---|
720 | return len(tasks) |
---|
721 | def to_log(self,*k,**kw): |
---|
722 | return |
---|
723 | bld=par() |
---|
724 | tasks=[] |
---|
725 | for dct in k: |
---|
726 | x=cfgtask(bld=bld) |
---|
727 | tasks.append(x) |
---|
728 | x.args=dct |
---|
729 | x.bld=bld |
---|
730 | x.conf=self |
---|
731 | x.args=dct |
---|
732 | x.logger=Logs.make_mem_logger(str(id(x)),self.logger) |
---|
733 | def it(): |
---|
734 | yield tasks |
---|
735 | while 1: |
---|
736 | yield[] |
---|
737 | p=Runner.Parallel(bld,Options.options.jobs) |
---|
738 | p.biter=it() |
---|
739 | p.start() |
---|
740 | for x in tasks: |
---|
741 | x.logger.memhandler.flush() |
---|
742 | for x in tasks: |
---|
743 | if x.hasrun!=Task.SUCCESS: |
---|
744 | self.end_msg(kw.get('errmsg','no'),color='YELLOW') |
---|
745 | self.fatal(kw.get('fatalmsg',None)or'One of the tests has failed, see the config.log for more information') |
---|
746 | self.end_msg('ok') |
---|