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 |
---|
6 | from waflib import Task,Utils,Node,Errors |
---|
7 | from waflib.TaskGen import after_method,before_method,feature,taskgen_method,extension |
---|
8 | from waflib.Tools import c_aliases,c_preproc,c_config,c_osx,c_tests |
---|
9 | from waflib.Configure import conf |
---|
10 | SYSTEM_LIB_PATHS=['/usr/lib64','/usr/lib','/usr/local/lib64','/usr/local/lib'] |
---|
11 | USELIB_VARS=Utils.defaultdict(set) |
---|
12 | USELIB_VARS['c']=set(['INCLUDES','FRAMEWORKPATH','DEFINES','CPPFLAGS','CCDEPS','CFLAGS','ARCH']) |
---|
13 | USELIB_VARS['cxx']=set(['INCLUDES','FRAMEWORKPATH','DEFINES','CPPFLAGS','CXXDEPS','CXXFLAGS','ARCH']) |
---|
14 | USELIB_VARS['d']=set(['INCLUDES','DFLAGS']) |
---|
15 | USELIB_VARS['includes']=set(['INCLUDES','FRAMEWORKPATH','ARCH']) |
---|
16 | USELIB_VARS['cprogram']=USELIB_VARS['cxxprogram']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS','FRAMEWORK','FRAMEWORKPATH','ARCH']) |
---|
17 | USELIB_VARS['cshlib']=USELIB_VARS['cxxshlib']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS','FRAMEWORK','FRAMEWORKPATH','ARCH']) |
---|
18 | USELIB_VARS['cstlib']=USELIB_VARS['cxxstlib']=set(['ARFLAGS','LINKDEPS']) |
---|
19 | USELIB_VARS['dprogram']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS']) |
---|
20 | USELIB_VARS['dshlib']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS']) |
---|
21 | USELIB_VARS['dstlib']=set(['ARFLAGS','LINKDEPS']) |
---|
22 | USELIB_VARS['asm']=set(['ASFLAGS']) |
---|
23 | @taskgen_method |
---|
24 | def create_compiled_task(self,name,node): |
---|
25 | out='%s.%d.o'%(node.name,self.idx) |
---|
26 | task=self.create_task(name,node,node.parent.find_or_declare(out)) |
---|
27 | try: |
---|
28 | self.compiled_tasks.append(task) |
---|
29 | except AttributeError: |
---|
30 | self.compiled_tasks=[task] |
---|
31 | return task |
---|
32 | @taskgen_method |
---|
33 | def to_incnodes(self,inlst): |
---|
34 | lst=[] |
---|
35 | seen=set([]) |
---|
36 | for x in self.to_list(inlst): |
---|
37 | if x in seen or not x: |
---|
38 | continue |
---|
39 | seen.add(x) |
---|
40 | if isinstance(x,Node.Node): |
---|
41 | lst.append(x) |
---|
42 | else: |
---|
43 | if os.path.isabs(x): |
---|
44 | lst.append(self.bld.root.make_node(x)or x) |
---|
45 | else: |
---|
46 | if x[0]=='#': |
---|
47 | p=self.bld.bldnode.make_node(x[1:]) |
---|
48 | v=self.bld.srcnode.make_node(x[1:]) |
---|
49 | else: |
---|
50 | p=self.path.get_bld().make_node(x) |
---|
51 | v=self.path.make_node(x) |
---|
52 | if p.is_child_of(self.bld.bldnode): |
---|
53 | p.mkdir() |
---|
54 | lst.append(p) |
---|
55 | lst.append(v) |
---|
56 | return lst |
---|
57 | @feature('c','cxx','d','asm','fc','includes') |
---|
58 | @after_method('propagate_uselib_vars','process_source') |
---|
59 | def apply_incpaths(self): |
---|
60 | lst=self.to_incnodes(self.to_list(getattr(self,'includes',[]))+self.env['INCLUDES']) |
---|
61 | self.includes_nodes=lst |
---|
62 | self.env['INCPATHS']=[x.abspath()for x in lst] |
---|
63 | class link_task(Task.Task): |
---|
64 | color='YELLOW' |
---|
65 | inst_to=None |
---|
66 | chmod=Utils.O755 |
---|
67 | def add_target(self,target): |
---|
68 | if isinstance(target,str): |
---|
69 | pattern=self.env[self.__class__.__name__+'_PATTERN'] |
---|
70 | if not pattern: |
---|
71 | pattern='%s' |
---|
72 | folder,name=os.path.split(target) |
---|
73 | if self.__class__.__name__.find('shlib')>0 and getattr(self.generator,'vnum',None): |
---|
74 | nums=self.generator.vnum.split('.') |
---|
75 | if self.env.DEST_BINFMT=='pe': |
---|
76 | name=name+'-'+nums[0] |
---|
77 | elif self.env.DEST_OS=='openbsd': |
---|
78 | pattern='%s.%s.%s'%(pattern,nums[0],nums[1]) |
---|
79 | tmp=folder+os.sep+pattern%name |
---|
80 | target=self.generator.path.find_or_declare(tmp) |
---|
81 | self.set_outputs(target) |
---|
82 | class stlink_task(link_task): |
---|
83 | run_str='${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}' |
---|
84 | def rm_tgt(cls): |
---|
85 | old=cls.run |
---|
86 | def wrap(self): |
---|
87 | try:os.remove(self.outputs[0].abspath()) |
---|
88 | except OSError:pass |
---|
89 | return old(self) |
---|
90 | setattr(cls,'run',wrap) |
---|
91 | rm_tgt(stlink_task) |
---|
92 | @feature('c','cxx','d','fc','asm') |
---|
93 | @after_method('process_source') |
---|
94 | def apply_link(self): |
---|
95 | for x in self.features: |
---|
96 | if x=='cprogram'and'cxx'in self.features: |
---|
97 | x='cxxprogram' |
---|
98 | elif x=='cshlib'and'cxx'in self.features: |
---|
99 | x='cxxshlib' |
---|
100 | if x in Task.classes: |
---|
101 | if issubclass(Task.classes[x],link_task): |
---|
102 | link=x |
---|
103 | break |
---|
104 | else: |
---|
105 | return |
---|
106 | objs=[t.outputs[0]for t in getattr(self,'compiled_tasks',[])] |
---|
107 | self.link_task=self.create_task(link,objs) |
---|
108 | self.link_task.add_target(self.target) |
---|
109 | try: |
---|
110 | inst_to=self.install_path |
---|
111 | except AttributeError: |
---|
112 | inst_to=self.link_task.__class__.inst_to |
---|
113 | if inst_to: |
---|
114 | self.install_task=self.bld.install_files(inst_to,self.link_task.outputs[:],env=self.env,chmod=self.link_task.chmod) |
---|
115 | @taskgen_method |
---|
116 | def use_rec(self,name,**kw): |
---|
117 | if name in self.tmp_use_not or name in self.tmp_use_seen: |
---|
118 | return |
---|
119 | try: |
---|
120 | y=self.bld.get_tgen_by_name(name) |
---|
121 | except Errors.WafError: |
---|
122 | self.uselib.append(name) |
---|
123 | self.tmp_use_not.add(name) |
---|
124 | return |
---|
125 | self.tmp_use_seen.append(name) |
---|
126 | y.post() |
---|
127 | y.tmp_use_objects=objects=kw.get('objects',True) |
---|
128 | y.tmp_use_stlib=stlib=kw.get('stlib',True) |
---|
129 | try: |
---|
130 | link_task=y.link_task |
---|
131 | except AttributeError: |
---|
132 | y.tmp_use_var='' |
---|
133 | else: |
---|
134 | objects=False |
---|
135 | if not isinstance(link_task,stlink_task): |
---|
136 | stlib=False |
---|
137 | y.tmp_use_var='LIB' |
---|
138 | else: |
---|
139 | y.tmp_use_var='STLIB' |
---|
140 | p=self.tmp_use_prec |
---|
141 | for x in self.to_list(getattr(y,'use',[])): |
---|
142 | try: |
---|
143 | p[x].append(name) |
---|
144 | except KeyError: |
---|
145 | p[x]=[name] |
---|
146 | self.use_rec(x,objects=objects,stlib=stlib) |
---|
147 | @feature('c','cxx','d','use','fc') |
---|
148 | @before_method('apply_incpaths','propagate_uselib_vars') |
---|
149 | @after_method('apply_link','process_source') |
---|
150 | def process_use(self): |
---|
151 | use_not=self.tmp_use_not=set([]) |
---|
152 | self.tmp_use_seen=[] |
---|
153 | use_prec=self.tmp_use_prec={} |
---|
154 | self.uselib=self.to_list(getattr(self,'uselib',[])) |
---|
155 | self.includes=self.to_list(getattr(self,'includes',[])) |
---|
156 | names=self.to_list(getattr(self,'use',[])) |
---|
157 | for x in names: |
---|
158 | self.use_rec(x) |
---|
159 | for x in use_not: |
---|
160 | if x in use_prec: |
---|
161 | del use_prec[x] |
---|
162 | out=[] |
---|
163 | tmp=[] |
---|
164 | for x in self.tmp_use_seen: |
---|
165 | for k in use_prec.values(): |
---|
166 | if x in k: |
---|
167 | break |
---|
168 | else: |
---|
169 | tmp.append(x) |
---|
170 | while tmp: |
---|
171 | e=tmp.pop() |
---|
172 | out.append(e) |
---|
173 | try: |
---|
174 | nlst=use_prec[e] |
---|
175 | except KeyError: |
---|
176 | pass |
---|
177 | else: |
---|
178 | del use_prec[e] |
---|
179 | for x in nlst: |
---|
180 | for y in use_prec: |
---|
181 | if x in use_prec[y]: |
---|
182 | break |
---|
183 | else: |
---|
184 | tmp.append(x) |
---|
185 | if use_prec: |
---|
186 | raise Errors.WafError('Cycle detected in the use processing %r'%use_prec) |
---|
187 | out.reverse() |
---|
188 | link_task=getattr(self,'link_task',None) |
---|
189 | for x in out: |
---|
190 | y=self.bld.get_tgen_by_name(x) |
---|
191 | var=y.tmp_use_var |
---|
192 | if var and link_task: |
---|
193 | if var=='LIB'or y.tmp_use_stlib: |
---|
194 | self.env.append_value(var,[y.target[y.target.rfind(os.sep)+1:]]) |
---|
195 | self.link_task.dep_nodes.extend(y.link_task.outputs) |
---|
196 | tmp_path=y.link_task.outputs[0].parent.path_from(self.bld.bldnode) |
---|
197 | self.env.append_value(var+'PATH',[tmp_path]) |
---|
198 | else: |
---|
199 | if y.tmp_use_objects: |
---|
200 | self.add_objects_from_tgen(y) |
---|
201 | if getattr(y,'export_includes',None): |
---|
202 | self.includes.extend(y.to_incnodes(y.export_includes)) |
---|
203 | if getattr(y,'export_defines',None): |
---|
204 | self.env.append_value('DEFINES',self.to_list(y.export_defines)) |
---|
205 | for x in names: |
---|
206 | try: |
---|
207 | y=self.bld.get_tgen_by_name(x) |
---|
208 | except Exception: |
---|
209 | if not self.env['STLIB_'+x]and not x in self.uselib: |
---|
210 | self.uselib.append(x) |
---|
211 | else: |
---|
212 | for k in self.to_list(getattr(y,'uselib',[])): |
---|
213 | if not self.env['STLIB_'+k]and not k in self.uselib: |
---|
214 | self.uselib.append(k) |
---|
215 | @taskgen_method |
---|
216 | def accept_node_to_link(self,node): |
---|
217 | return not node.name.endswith('.pdb') |
---|
218 | @taskgen_method |
---|
219 | def add_objects_from_tgen(self,tg): |
---|
220 | try: |
---|
221 | link_task=self.link_task |
---|
222 | except AttributeError: |
---|
223 | pass |
---|
224 | else: |
---|
225 | for tsk in getattr(tg,'compiled_tasks',[]): |
---|
226 | for x in tsk.outputs: |
---|
227 | if self.accept_node_to_link(x): |
---|
228 | link_task.inputs.append(x) |
---|
229 | @taskgen_method |
---|
230 | def get_uselib_vars(self): |
---|
231 | _vars=set([]) |
---|
232 | for x in self.features: |
---|
233 | if x in USELIB_VARS: |
---|
234 | _vars|=USELIB_VARS[x] |
---|
235 | return _vars |
---|
236 | @feature('c','cxx','d','fc','javac','cs','uselib','asm') |
---|
237 | @after_method('process_use') |
---|
238 | def propagate_uselib_vars(self): |
---|
239 | _vars=self.get_uselib_vars() |
---|
240 | env=self.env |
---|
241 | for x in _vars: |
---|
242 | y=x.lower() |
---|
243 | env.append_unique(x,self.to_list(getattr(self,y,[]))) |
---|
244 | for x in self.features: |
---|
245 | for var in _vars: |
---|
246 | compvar='%s_%s'%(var,x) |
---|
247 | env.append_value(var,env[compvar]) |
---|
248 | for x in self.to_list(getattr(self,'uselib',[])): |
---|
249 | for v in _vars: |
---|
250 | env.append_value(v,env[v+'_'+x]) |
---|
251 | @feature('cshlib','cxxshlib','fcshlib') |
---|
252 | @after_method('apply_link') |
---|
253 | def apply_implib(self): |
---|
254 | if not self.env.DEST_BINFMT=='pe': |
---|
255 | return |
---|
256 | dll=self.link_task.outputs[0] |
---|
257 | if isinstance(self.target,Node.Node): |
---|
258 | name=self.target.name |
---|
259 | else: |
---|
260 | name=os.path.split(self.target)[1] |
---|
261 | implib=self.env['implib_PATTERN']%name |
---|
262 | implib=dll.parent.find_or_declare(implib) |
---|
263 | self.env.append_value('LINKFLAGS',self.env['IMPLIB_ST']%implib.bldpath()) |
---|
264 | self.link_task.outputs.append(implib) |
---|
265 | if getattr(self,'defs',None)and self.env.DEST_BINFMT=='pe': |
---|
266 | node=self.path.find_resource(self.defs) |
---|
267 | if not node: |
---|
268 | raise Errors.WafError('invalid def file %r'%self.defs) |
---|
269 | if'msvc'in(self.env.CC_NAME,self.env.CXX_NAME): |
---|
270 | self.env.append_value('LINKFLAGS','/def:%s'%node.path_from(self.bld.bldnode)) |
---|
271 | self.link_task.dep_nodes.append(node) |
---|
272 | else: |
---|
273 | self.link_task.inputs.append(node) |
---|
274 | try: |
---|
275 | inst_to=self.install_path |
---|
276 | except AttributeError: |
---|
277 | inst_to=self.link_task.__class__.inst_to |
---|
278 | if not inst_to: |
---|
279 | return |
---|
280 | self.implib_install_task=self.bld.install_as('${LIBDIR}/%s'%implib.name,implib,self.env) |
---|
281 | re_vnum=re.compile('^([1-9]\\d*|0)[.]([1-9]\\d*|0)[.]([1-9]\\d*|0)$') |
---|
282 | @feature('cshlib','cxxshlib','dshlib','fcshlib','vnum') |
---|
283 | @after_method('apply_link','propagate_uselib_vars') |
---|
284 | def apply_vnum(self): |
---|
285 | if not getattr(self,'vnum','')or os.name!='posix'or self.env.DEST_BINFMT not in('elf','mac-o'): |
---|
286 | return |
---|
287 | link=self.link_task |
---|
288 | if not re_vnum.match(self.vnum): |
---|
289 | raise Errors.WafError('Invalid version %r for %r'%(self.vnum,self)) |
---|
290 | nums=self.vnum.split('.') |
---|
291 | node=link.outputs[0] |
---|
292 | libname=node.name |
---|
293 | if libname.endswith('.dylib'): |
---|
294 | name3=libname.replace('.dylib','.%s.dylib'%self.vnum) |
---|
295 | name2=libname.replace('.dylib','.%s.dylib'%nums[0]) |
---|
296 | else: |
---|
297 | name3=libname+'.'+self.vnum |
---|
298 | name2=libname+'.'+nums[0] |
---|
299 | if self.env.SONAME_ST: |
---|
300 | v=self.env.SONAME_ST%name2 |
---|
301 | self.env.append_value('LINKFLAGS',v.split()) |
---|
302 | if self.env.DEST_OS!='openbsd': |
---|
303 | self.create_task('vnum',node,[node.parent.find_or_declare(name2),node.parent.find_or_declare(name3)]) |
---|
304 | if getattr(self,'install_task',None): |
---|
305 | self.install_task.hasrun=Task.SKIP_ME |
---|
306 | bld=self.bld |
---|
307 | path=self.install_task.dest |
---|
308 | if self.env.DEST_OS=='openbsd': |
---|
309 | libname=self.link_task.outputs[0].name |
---|
310 | t1=bld.install_as('%s%s%s'%(path,os.sep,libname),node,env=self.env,chmod=self.link_task.chmod) |
---|
311 | self.vnum_install_task=(t1,) |
---|
312 | else: |
---|
313 | t1=bld.install_as(path+os.sep+name3,node,env=self.env,chmod=self.link_task.chmod) |
---|
314 | t2=bld.symlink_as(path+os.sep+name2,name3) |
---|
315 | t3=bld.symlink_as(path+os.sep+libname,name3) |
---|
316 | self.vnum_install_task=(t1,t2,t3) |
---|
317 | if'-dynamiclib'in self.env['LINKFLAGS']: |
---|
318 | try: |
---|
319 | inst_to=self.install_path |
---|
320 | except AttributeError: |
---|
321 | inst_to=self.link_task.__class__.inst_to |
---|
322 | if inst_to: |
---|
323 | p=Utils.subst_vars(inst_to,self.env) |
---|
324 | path=os.path.join(p,self.link_task.outputs[0].name) |
---|
325 | self.env.append_value('LINKFLAGS',['-install_name',path]) |
---|
326 | class vnum(Task.Task): |
---|
327 | color='CYAN' |
---|
328 | quient=True |
---|
329 | ext_in=['.bin'] |
---|
330 | def run(self): |
---|
331 | for x in self.outputs: |
---|
332 | path=x.abspath() |
---|
333 | try: |
---|
334 | os.remove(path) |
---|
335 | except OSError: |
---|
336 | pass |
---|
337 | try: |
---|
338 | os.symlink(self.inputs[0].name,path) |
---|
339 | except OSError: |
---|
340 | return 1 |
---|
341 | class fake_shlib(link_task): |
---|
342 | def runnable_status(self): |
---|
343 | for t in self.run_after: |
---|
344 | if not t.hasrun: |
---|
345 | return Task.ASK_LATER |
---|
346 | for x in self.outputs: |
---|
347 | x.sig=Utils.h_file(x.abspath()) |
---|
348 | return Task.SKIP_ME |
---|
349 | class fake_stlib(stlink_task): |
---|
350 | def runnable_status(self): |
---|
351 | for t in self.run_after: |
---|
352 | if not t.hasrun: |
---|
353 | return Task.ASK_LATER |
---|
354 | for x in self.outputs: |
---|
355 | x.sig=Utils.h_file(x.abspath()) |
---|
356 | return Task.SKIP_ME |
---|
357 | @conf |
---|
358 | def read_shlib(self,name,paths=[],export_includes=[],export_defines=[]): |
---|
359 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='shlib',export_includes=export_includes,export_defines=export_defines) |
---|
360 | @conf |
---|
361 | def read_stlib(self,name,paths=[],export_includes=[],export_defines=[]): |
---|
362 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='stlib',export_includes=export_includes,export_defines=export_defines) |
---|
363 | lib_patterns={'shlib':['lib%s.so','%s.so','lib%s.dylib','lib%s.dll','%s.dll'],'stlib':['lib%s.a','%s.a','lib%s.dll','%s.dll','lib%s.lib','%s.lib'],} |
---|
364 | @feature('fake_lib') |
---|
365 | def process_lib(self): |
---|
366 | node=None |
---|
367 | names=[x%self.name for x in lib_patterns[self.lib_type]] |
---|
368 | for x in self.lib_paths+[self.path]+SYSTEM_LIB_PATHS: |
---|
369 | if not isinstance(x,Node.Node): |
---|
370 | x=self.bld.root.find_node(x)or self.path.find_node(x) |
---|
371 | if not x: |
---|
372 | continue |
---|
373 | for y in names: |
---|
374 | node=x.find_node(y) |
---|
375 | if node: |
---|
376 | node.sig=Utils.h_file(node.abspath()) |
---|
377 | break |
---|
378 | else: |
---|
379 | continue |
---|
380 | break |
---|
381 | else: |
---|
382 | raise Errors.WafError('could not find library %r'%self.name) |
---|
383 | self.link_task=self.create_task('fake_%s'%self.lib_type,[],[node]) |
---|
384 | self.target=self.name |
---|
385 | class fake_o(Task.Task): |
---|
386 | def runnable_status(self): |
---|
387 | return Task.SKIP_ME |
---|
388 | @extension('.o','.obj') |
---|
389 | def add_those_o_files(self,node): |
---|
390 | tsk=self.create_task('fake_o',[],node) |
---|
391 | try: |
---|
392 | self.compiled_tasks.append(tsk) |
---|
393 | except AttributeError: |
---|
394 | self.compiled_tasks=[tsk] |
---|
395 | @feature('fake_obj') |
---|
396 | @before_method('process_source') |
---|
397 | def process_objs(self): |
---|
398 | for node in self.to_nodes(self.source): |
---|
399 | self.add_those_o_files(node) |
---|
400 | self.source=[] |
---|
401 | @conf |
---|
402 | def read_object(self,obj): |
---|
403 | if not isinstance(obj,self.path.__class__): |
---|
404 | obj=self.path.find_resource(obj) |
---|
405 | return self(features='fake_obj',source=obj,name=obj.name) |
---|