[0fa325b] | 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 |
---|
| 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: |
---|
| 74 | if self.env.DEST_BINFMT=='pe'and getattr(self.generator,'vnum',None): |
---|
| 75 | name=name+'-'+self.generator.vnum.split('.')[0] |
---|
| 76 | tmp=folder+os.sep+pattern%name |
---|
| 77 | target=self.generator.path.find_or_declare(tmp) |
---|
| 78 | self.set_outputs(target) |
---|
| 79 | class stlink_task(link_task): |
---|
| 80 | run_str='${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}' |
---|
| 81 | def rm_tgt(cls): |
---|
| 82 | old=cls.run |
---|
| 83 | def wrap(self): |
---|
| 84 | try:os.remove(self.outputs[0].abspath()) |
---|
| 85 | except OSError:pass |
---|
| 86 | return old(self) |
---|
| 87 | setattr(cls,'run',wrap) |
---|
| 88 | rm_tgt(stlink_task) |
---|
| 89 | @feature('c','cxx','d','fc','asm') |
---|
| 90 | @after_method('process_source') |
---|
| 91 | def apply_link(self): |
---|
| 92 | for x in self.features: |
---|
| 93 | if x=='cprogram'and'cxx'in self.features: |
---|
| 94 | x='cxxprogram' |
---|
| 95 | elif x=='cshlib'and'cxx'in self.features: |
---|
| 96 | x='cxxshlib' |
---|
| 97 | if x in Task.classes: |
---|
| 98 | if issubclass(Task.classes[x],link_task): |
---|
| 99 | link=x |
---|
| 100 | break |
---|
| 101 | else: |
---|
| 102 | return |
---|
| 103 | objs=[t.outputs[0]for t in getattr(self,'compiled_tasks',[])] |
---|
| 104 | self.link_task=self.create_task(link,objs) |
---|
| 105 | self.link_task.add_target(self.target) |
---|
| 106 | try: |
---|
| 107 | inst_to=self.install_path |
---|
| 108 | except AttributeError: |
---|
| 109 | inst_to=self.link_task.__class__.inst_to |
---|
| 110 | if inst_to: |
---|
| 111 | self.install_task=self.bld.install_files(inst_to,self.link_task.outputs[:],env=self.env,chmod=self.link_task.chmod) |
---|
| 112 | @taskgen_method |
---|
| 113 | def use_rec(self,name,**kw): |
---|
| 114 | if name in self.tmp_use_not or name in self.tmp_use_seen: |
---|
| 115 | return |
---|
| 116 | try: |
---|
| 117 | y=self.bld.get_tgen_by_name(name) |
---|
| 118 | except Errors.WafError: |
---|
| 119 | self.uselib.append(name) |
---|
| 120 | self.tmp_use_not.add(name) |
---|
| 121 | return |
---|
| 122 | self.tmp_use_seen.append(name) |
---|
| 123 | y.post() |
---|
| 124 | y.tmp_use_objects=objects=kw.get('objects',True) |
---|
| 125 | y.tmp_use_stlib=stlib=kw.get('stlib',True) |
---|
| 126 | try: |
---|
| 127 | link_task=y.link_task |
---|
| 128 | except AttributeError: |
---|
| 129 | y.tmp_use_var='' |
---|
| 130 | else: |
---|
| 131 | objects=False |
---|
| 132 | if not isinstance(link_task,stlink_task): |
---|
| 133 | stlib=False |
---|
| 134 | y.tmp_use_var='LIB' |
---|
| 135 | else: |
---|
| 136 | y.tmp_use_var='STLIB' |
---|
| 137 | p=self.tmp_use_prec |
---|
| 138 | for x in self.to_list(getattr(y,'use',[])): |
---|
| 139 | try: |
---|
| 140 | p[x].append(name) |
---|
| 141 | except KeyError: |
---|
| 142 | p[x]=[name] |
---|
| 143 | self.use_rec(x,objects=objects,stlib=stlib) |
---|
| 144 | @feature('c','cxx','d','use','fc') |
---|
| 145 | @before_method('apply_incpaths','propagate_uselib_vars') |
---|
| 146 | @after_method('apply_link','process_source') |
---|
| 147 | def process_use(self): |
---|
| 148 | use_not=self.tmp_use_not=set([]) |
---|
| 149 | self.tmp_use_seen=[] |
---|
| 150 | use_prec=self.tmp_use_prec={} |
---|
| 151 | self.uselib=self.to_list(getattr(self,'uselib',[])) |
---|
| 152 | self.includes=self.to_list(getattr(self,'includes',[])) |
---|
| 153 | names=self.to_list(getattr(self,'use',[])) |
---|
| 154 | for x in names: |
---|
| 155 | self.use_rec(x) |
---|
| 156 | for x in use_not: |
---|
| 157 | if x in use_prec: |
---|
| 158 | del use_prec[x] |
---|
| 159 | out=[] |
---|
| 160 | tmp=[] |
---|
| 161 | for x in self.tmp_use_seen: |
---|
| 162 | for k in use_prec.values(): |
---|
| 163 | if x in k: |
---|
| 164 | break |
---|
| 165 | else: |
---|
| 166 | tmp.append(x) |
---|
| 167 | while tmp: |
---|
| 168 | e=tmp.pop() |
---|
| 169 | out.append(e) |
---|
| 170 | try: |
---|
| 171 | nlst=use_prec[e] |
---|
| 172 | except KeyError: |
---|
| 173 | pass |
---|
| 174 | else: |
---|
| 175 | del use_prec[e] |
---|
| 176 | for x in nlst: |
---|
| 177 | for y in use_prec: |
---|
| 178 | if x in use_prec[y]: |
---|
| 179 | break |
---|
| 180 | else: |
---|
| 181 | tmp.append(x) |
---|
| 182 | if use_prec: |
---|
| 183 | raise Errors.WafError('Cycle detected in the use processing %r'%use_prec) |
---|
| 184 | out.reverse() |
---|
| 185 | link_task=getattr(self,'link_task',None) |
---|
| 186 | for x in out: |
---|
| 187 | y=self.bld.get_tgen_by_name(x) |
---|
| 188 | var=y.tmp_use_var |
---|
| 189 | if var and link_task: |
---|
| 190 | if var=='LIB'or y.tmp_use_stlib: |
---|
| 191 | self.env.append_value(var,[y.target[y.target.rfind(os.sep)+1:]]) |
---|
| 192 | self.link_task.dep_nodes.extend(y.link_task.outputs) |
---|
| 193 | tmp_path=y.link_task.outputs[0].parent.path_from(self.bld.bldnode) |
---|
| 194 | self.env.append_value(var+'PATH',[tmp_path]) |
---|
| 195 | else: |
---|
| 196 | if y.tmp_use_objects: |
---|
| 197 | self.add_objects_from_tgen(y) |
---|
| 198 | if getattr(y,'export_includes',None): |
---|
| 199 | self.includes.extend(y.to_incnodes(y.export_includes)) |
---|
| 200 | for x in names: |
---|
| 201 | try: |
---|
| 202 | y=self.bld.get_tgen_by_name(x) |
---|
| 203 | except Exception: |
---|
| 204 | if not self.env['STLIB_'+x]and not x in self.uselib: |
---|
| 205 | self.uselib.append(x) |
---|
| 206 | else: |
---|
| 207 | for k in self.to_list(getattr(y,'uselib',[])): |
---|
| 208 | if not self.env['STLIB_'+k]and not k in self.uselib: |
---|
| 209 | self.uselib.append(k) |
---|
| 210 | @taskgen_method |
---|
| 211 | def accept_node_to_link(self,node): |
---|
| 212 | return not node.name.endswith('.pdb') |
---|
| 213 | @taskgen_method |
---|
| 214 | def add_objects_from_tgen(self,tg): |
---|
| 215 | try: |
---|
| 216 | link_task=self.link_task |
---|
| 217 | except AttributeError: |
---|
| 218 | pass |
---|
| 219 | else: |
---|
| 220 | for tsk in getattr(tg,'compiled_tasks',[]): |
---|
| 221 | for x in tsk.outputs: |
---|
| 222 | if self.accept_node_to_link(x): |
---|
| 223 | link_task.inputs.append(x) |
---|
| 224 | @taskgen_method |
---|
| 225 | def get_uselib_vars(self): |
---|
| 226 | _vars=set([]) |
---|
| 227 | for x in self.features: |
---|
| 228 | if x in USELIB_VARS: |
---|
| 229 | _vars|=USELIB_VARS[x] |
---|
| 230 | return _vars |
---|
| 231 | @feature('c','cxx','d','fc','javac','cs','uselib','asm') |
---|
| 232 | @after_method('process_use') |
---|
| 233 | def propagate_uselib_vars(self): |
---|
| 234 | _vars=self.get_uselib_vars() |
---|
| 235 | env=self.env |
---|
| 236 | for x in _vars: |
---|
| 237 | y=x.lower() |
---|
| 238 | env.append_unique(x,self.to_list(getattr(self,y,[]))) |
---|
| 239 | for x in self.features: |
---|
| 240 | for var in _vars: |
---|
| 241 | compvar='%s_%s'%(var,x) |
---|
| 242 | env.append_value(var,env[compvar]) |
---|
| 243 | for x in self.to_list(getattr(self,'uselib',[])): |
---|
| 244 | for v in _vars: |
---|
| 245 | env.append_value(v,env[v+'_'+x]) |
---|
| 246 | @feature('cshlib','cxxshlib','fcshlib') |
---|
| 247 | @after_method('apply_link') |
---|
| 248 | def apply_implib(self): |
---|
| 249 | if not self.env.DEST_BINFMT=='pe': |
---|
| 250 | return |
---|
| 251 | dll=self.link_task.outputs[0] |
---|
| 252 | if isinstance(self.target,Node.Node): |
---|
| 253 | name=self.target.name |
---|
| 254 | else: |
---|
| 255 | name=os.path.split(self.target)[1] |
---|
| 256 | implib=self.env['implib_PATTERN']%name |
---|
| 257 | implib=dll.parent.find_or_declare(implib) |
---|
| 258 | self.env.append_value('LINKFLAGS',self.env['IMPLIB_ST']%implib.bldpath()) |
---|
| 259 | self.link_task.outputs.append(implib) |
---|
| 260 | if getattr(self,'defs',None)and self.env.DEST_BINFMT=='pe': |
---|
| 261 | node=self.path.find_resource(self.defs) |
---|
| 262 | if not node: |
---|
| 263 | raise Errors.WafError('invalid def file %r'%self.defs) |
---|
| 264 | if'msvc'in(self.env.CC_NAME,self.env.CXX_NAME): |
---|
| 265 | self.env.append_value('LINKFLAGS','/def:%s'%node.path_from(self.bld.bldnode)) |
---|
| 266 | self.link_task.dep_nodes.append(node) |
---|
| 267 | else: |
---|
| 268 | self.link_task.inputs.append(node) |
---|
| 269 | try: |
---|
| 270 | inst_to=self.install_path |
---|
| 271 | except AttributeError: |
---|
| 272 | inst_to=self.link_task.__class__.inst_to |
---|
| 273 | if not inst_to: |
---|
| 274 | return |
---|
| 275 | self.implib_install_task=self.bld.install_as('${LIBDIR}/%s'%implib.name,implib,self.env) |
---|
| 276 | @feature('cshlib','cxxshlib','dshlib','fcshlib','vnum') |
---|
| 277 | @after_method('apply_link','propagate_uselib_vars') |
---|
| 278 | def apply_vnum(self): |
---|
| 279 | if not getattr(self,'vnum','')or os.name!='posix'or self.env.DEST_BINFMT not in('elf','mac-o'): |
---|
| 280 | return |
---|
| 281 | link=self.link_task |
---|
| 282 | nums=self.vnum.split('.') |
---|
| 283 | node=link.outputs[0] |
---|
| 284 | libname=node.name |
---|
| 285 | if libname.endswith('.dylib'): |
---|
| 286 | name3=libname.replace('.dylib','.%s.dylib'%self.vnum) |
---|
| 287 | name2=libname.replace('.dylib','.%s.dylib'%nums[0]) |
---|
| 288 | else: |
---|
| 289 | name3=libname+'.'+self.vnum |
---|
| 290 | name2=libname+'.'+nums[0] |
---|
| 291 | if self.env.SONAME_ST: |
---|
| 292 | v=self.env.SONAME_ST%name2 |
---|
| 293 | self.env.append_value('LINKFLAGS',v.split()) |
---|
| 294 | self.create_task('vnum',node,[node.parent.find_or_declare(name2),node.parent.find_or_declare(name3)]) |
---|
| 295 | if getattr(self,'install_task',None): |
---|
| 296 | self.install_task.hasrun=Task.SKIP_ME |
---|
| 297 | bld=self.bld |
---|
| 298 | path=self.install_task.dest |
---|
| 299 | t1=bld.install_as(path+os.sep+name3,node,env=self.env,chmod=self.link_task.chmod) |
---|
| 300 | t2=bld.symlink_as(path+os.sep+name2,name3) |
---|
| 301 | t3=bld.symlink_as(path+os.sep+libname,name3) |
---|
| 302 | self.vnum_install_task=(t1,t2,t3) |
---|
| 303 | if'-dynamiclib'in self.env['LINKFLAGS']: |
---|
| 304 | try: |
---|
| 305 | inst_to=self.install_path |
---|
| 306 | except AttributeError: |
---|
| 307 | inst_to=self.link_task.__class__.inst_to |
---|
| 308 | if inst_to: |
---|
| 309 | p=Utils.subst_vars(inst_to,self.env) |
---|
| 310 | path=os.path.join(p,self.link_task.outputs[0].name) |
---|
| 311 | self.env.append_value('LINKFLAGS',['-install_name',path]) |
---|
| 312 | class vnum(Task.Task): |
---|
| 313 | color='CYAN' |
---|
| 314 | quient=True |
---|
| 315 | ext_in=['.bin'] |
---|
| 316 | def run(self): |
---|
| 317 | for x in self.outputs: |
---|
| 318 | path=x.abspath() |
---|
| 319 | try: |
---|
| 320 | os.remove(path) |
---|
| 321 | except OSError: |
---|
| 322 | pass |
---|
| 323 | try: |
---|
| 324 | os.symlink(self.inputs[0].name,path) |
---|
| 325 | except OSError: |
---|
| 326 | return 1 |
---|
| 327 | class fake_shlib(link_task): |
---|
| 328 | def runnable_status(self): |
---|
| 329 | for t in self.run_after: |
---|
| 330 | if not t.hasrun: |
---|
| 331 | return Task.ASK_LATER |
---|
| 332 | for x in self.outputs: |
---|
| 333 | x.sig=Utils.h_file(x.abspath()) |
---|
| 334 | return Task.SKIP_ME |
---|
| 335 | class fake_stlib(stlink_task): |
---|
| 336 | def runnable_status(self): |
---|
| 337 | for t in self.run_after: |
---|
| 338 | if not t.hasrun: |
---|
| 339 | return Task.ASK_LATER |
---|
| 340 | for x in self.outputs: |
---|
| 341 | x.sig=Utils.h_file(x.abspath()) |
---|
| 342 | return Task.SKIP_ME |
---|
| 343 | @conf |
---|
| 344 | def read_shlib(self,name,paths=[]): |
---|
| 345 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='shlib') |
---|
| 346 | @conf |
---|
| 347 | def read_stlib(self,name,paths=[]): |
---|
| 348 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='stlib') |
---|
| 349 | 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'],} |
---|
| 350 | @feature('fake_lib') |
---|
| 351 | def process_lib(self): |
---|
| 352 | node=None |
---|
| 353 | names=[x%self.name for x in lib_patterns[self.lib_type]] |
---|
| 354 | for x in self.lib_paths+[self.path]+SYSTEM_LIB_PATHS: |
---|
| 355 | if not isinstance(x,Node.Node): |
---|
| 356 | x=self.bld.root.find_node(x)or self.path.find_node(x) |
---|
| 357 | if not x: |
---|
| 358 | continue |
---|
| 359 | for y in names: |
---|
| 360 | node=x.find_node(y) |
---|
| 361 | if node: |
---|
| 362 | node.sig=Utils.h_file(node.abspath()) |
---|
| 363 | break |
---|
| 364 | else: |
---|
| 365 | continue |
---|
| 366 | break |
---|
| 367 | else: |
---|
| 368 | raise Errors.WafError('could not find library %r'%self.name) |
---|
| 369 | self.link_task=self.create_task('fake_%s'%self.lib_type,[],[node]) |
---|
| 370 | self.target=self.name |
---|
| 371 | class fake_o(Task.Task): |
---|
| 372 | def runnable_status(self): |
---|
| 373 | return Task.SKIP_ME |
---|
| 374 | @extension('.o','.obj') |
---|
| 375 | def add_those_o_files(self,node): |
---|
| 376 | tsk=self.create_task('fake_o',[],node) |
---|
| 377 | try: |
---|
| 378 | self.compiled_tasks.append(tsk) |
---|
| 379 | except AttributeError: |
---|
| 380 | self.compiled_tasks=[tsk] |
---|
| 381 | @feature('fake_obj') |
---|
| 382 | @before_method('process_source') |
---|
| 383 | def process_objs(self): |
---|
| 384 | for node in self.to_nodes(self.source): |
---|
| 385 | self.add_those_o_files(node) |
---|
| 386 | self.source=[] |
---|
| 387 | @conf |
---|
| 388 | def read_object(self,obj): |
---|
| 389 | if not isinstance(obj,self.path.__class__): |
---|
| 390 | obj=self.path.find_resource(obj) |
---|
| 391 | return self(features='fake_obj',source=obj,name=obj.name) |
---|