akmhoque | fa8ee9b | 2014-03-14 09:06:24 -0500 | [diff] [blame^] | 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: |
| 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 | if getattr(y,'export_defines',None): |
| 201 | self.env.append_value('DEFINES',self.to_list(y.export_defines)) |
| 202 | for x in names: |
| 203 | try: |
| 204 | y=self.bld.get_tgen_by_name(x) |
| 205 | except Exception: |
| 206 | if not self.env['STLIB_'+x]and not x in self.uselib: |
| 207 | self.uselib.append(x) |
| 208 | else: |
| 209 | for k in self.to_list(getattr(y,'uselib',[])): |
| 210 | if not self.env['STLIB_'+k]and not k in self.uselib: |
| 211 | self.uselib.append(k) |
| 212 | @taskgen_method |
| 213 | def accept_node_to_link(self,node): |
| 214 | return not node.name.endswith('.pdb') |
| 215 | @taskgen_method |
| 216 | def add_objects_from_tgen(self,tg): |
| 217 | try: |
| 218 | link_task=self.link_task |
| 219 | except AttributeError: |
| 220 | pass |
| 221 | else: |
| 222 | for tsk in getattr(tg,'compiled_tasks',[]): |
| 223 | for x in tsk.outputs: |
| 224 | if self.accept_node_to_link(x): |
| 225 | link_task.inputs.append(x) |
| 226 | @taskgen_method |
| 227 | def get_uselib_vars(self): |
| 228 | _vars=set([]) |
| 229 | for x in self.features: |
| 230 | if x in USELIB_VARS: |
| 231 | _vars|=USELIB_VARS[x] |
| 232 | return _vars |
| 233 | @feature('c','cxx','d','fc','javac','cs','uselib','asm') |
| 234 | @after_method('process_use') |
| 235 | def propagate_uselib_vars(self): |
| 236 | _vars=self.get_uselib_vars() |
| 237 | env=self.env |
| 238 | for x in _vars: |
| 239 | y=x.lower() |
| 240 | env.append_unique(x,self.to_list(getattr(self,y,[]))) |
| 241 | for x in self.features: |
| 242 | for var in _vars: |
| 243 | compvar='%s_%s'%(var,x) |
| 244 | env.append_value(var,env[compvar]) |
| 245 | for x in self.to_list(getattr(self,'uselib',[])): |
| 246 | for v in _vars: |
| 247 | env.append_value(v,env[v+'_'+x]) |
| 248 | @feature('cshlib','cxxshlib','fcshlib') |
| 249 | @after_method('apply_link') |
| 250 | def apply_implib(self): |
| 251 | if not self.env.DEST_BINFMT=='pe': |
| 252 | return |
| 253 | dll=self.link_task.outputs[0] |
| 254 | if isinstance(self.target,Node.Node): |
| 255 | name=self.target.name |
| 256 | else: |
| 257 | name=os.path.split(self.target)[1] |
| 258 | implib=self.env['implib_PATTERN']%name |
| 259 | implib=dll.parent.find_or_declare(implib) |
| 260 | self.env.append_value('LINKFLAGS',self.env['IMPLIB_ST']%implib.bldpath()) |
| 261 | self.link_task.outputs.append(implib) |
| 262 | if getattr(self,'defs',None)and self.env.DEST_BINFMT=='pe': |
| 263 | node=self.path.find_resource(self.defs) |
| 264 | if not node: |
| 265 | raise Errors.WafError('invalid def file %r'%self.defs) |
| 266 | if'msvc'in(self.env.CC_NAME,self.env.CXX_NAME): |
| 267 | self.env.append_value('LINKFLAGS','/def:%s'%node.path_from(self.bld.bldnode)) |
| 268 | self.link_task.dep_nodes.append(node) |
| 269 | else: |
| 270 | self.link_task.inputs.append(node) |
| 271 | try: |
| 272 | inst_to=self.install_path |
| 273 | except AttributeError: |
| 274 | inst_to=self.link_task.__class__.inst_to |
| 275 | if not inst_to: |
| 276 | return |
| 277 | self.implib_install_task=self.bld.install_as('${LIBDIR}/%s'%implib.name,implib,self.env) |
| 278 | re_vnum=re.compile('^([1-9]\\d*|0)[.]([1-9]\\d*|0)[.]([1-9]\\d*|0)$') |
| 279 | @feature('cshlib','cxxshlib','dshlib','fcshlib','vnum') |
| 280 | @after_method('apply_link','propagate_uselib_vars') |
| 281 | def apply_vnum(self): |
| 282 | if not getattr(self,'vnum','')or os.name!='posix'or self.env.DEST_BINFMT not in('elf','mac-o'): |
| 283 | return |
| 284 | link=self.link_task |
| 285 | if not re_vnum.match(self.vnum): |
| 286 | raise Errors.WafError('Invalid version %r for %r'%(self.vnum,self)) |
| 287 | nums=self.vnum.split('.') |
| 288 | node=link.outputs[0] |
| 289 | libname=node.name |
| 290 | if libname.endswith('.dylib'): |
| 291 | name3=libname.replace('.dylib','.%s.dylib'%self.vnum) |
| 292 | name2=libname.replace('.dylib','.%s.dylib'%nums[0]) |
| 293 | else: |
| 294 | name3=libname+'.'+self.vnum |
| 295 | name2=libname+'.'+nums[0] |
| 296 | if self.env.SONAME_ST: |
| 297 | v=self.env.SONAME_ST%name2 |
| 298 | self.env.append_value('LINKFLAGS',v.split()) |
| 299 | self.create_task('vnum',node,[node.parent.find_or_declare(name2),node.parent.find_or_declare(name3)]) |
| 300 | if getattr(self,'install_task',None): |
| 301 | self.install_task.hasrun=Task.SKIP_ME |
| 302 | bld=self.bld |
| 303 | path=self.install_task.dest |
| 304 | t1=bld.install_as(path+os.sep+name3,node,env=self.env,chmod=self.link_task.chmod) |
| 305 | t2=bld.symlink_as(path+os.sep+name2,name3) |
| 306 | t3=bld.symlink_as(path+os.sep+libname,name3) |
| 307 | self.vnum_install_task=(t1,t2,t3) |
| 308 | if'-dynamiclib'in self.env['LINKFLAGS']: |
| 309 | try: |
| 310 | inst_to=self.install_path |
| 311 | except AttributeError: |
| 312 | inst_to=self.link_task.__class__.inst_to |
| 313 | if inst_to: |
| 314 | p=Utils.subst_vars(inst_to,self.env) |
| 315 | path=os.path.join(p,self.link_task.outputs[0].name) |
| 316 | self.env.append_value('LINKFLAGS',['-install_name',path]) |
| 317 | class vnum(Task.Task): |
| 318 | color='CYAN' |
| 319 | quient=True |
| 320 | ext_in=['.bin'] |
| 321 | def run(self): |
| 322 | for x in self.outputs: |
| 323 | path=x.abspath() |
| 324 | try: |
| 325 | os.remove(path) |
| 326 | except OSError: |
| 327 | pass |
| 328 | try: |
| 329 | os.symlink(self.inputs[0].name,path) |
| 330 | except OSError: |
| 331 | return 1 |
| 332 | class fake_shlib(link_task): |
| 333 | def runnable_status(self): |
| 334 | for t in self.run_after: |
| 335 | if not t.hasrun: |
| 336 | return Task.ASK_LATER |
| 337 | for x in self.outputs: |
| 338 | x.sig=Utils.h_file(x.abspath()) |
| 339 | return Task.SKIP_ME |
| 340 | class fake_stlib(stlink_task): |
| 341 | def runnable_status(self): |
| 342 | for t in self.run_after: |
| 343 | if not t.hasrun: |
| 344 | return Task.ASK_LATER |
| 345 | for x in self.outputs: |
| 346 | x.sig=Utils.h_file(x.abspath()) |
| 347 | return Task.SKIP_ME |
| 348 | @conf |
| 349 | def read_shlib(self,name,paths=[],export_includes=[],export_defines=[]): |
| 350 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='shlib',export_includes=export_includes,export_defines=export_defines) |
| 351 | @conf |
| 352 | def read_stlib(self,name,paths=[],export_includes=[],export_defines=[]): |
| 353 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='stlib',export_includes=export_includes,export_defines=export_defines) |
| 354 | 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'],} |
| 355 | @feature('fake_lib') |
| 356 | def process_lib(self): |
| 357 | node=None |
| 358 | names=[x%self.name for x in lib_patterns[self.lib_type]] |
| 359 | for x in self.lib_paths+[self.path]+SYSTEM_LIB_PATHS: |
| 360 | if not isinstance(x,Node.Node): |
| 361 | x=self.bld.root.find_node(x)or self.path.find_node(x) |
| 362 | if not x: |
| 363 | continue |
| 364 | for y in names: |
| 365 | node=x.find_node(y) |
| 366 | if node: |
| 367 | node.sig=Utils.h_file(node.abspath()) |
| 368 | break |
| 369 | else: |
| 370 | continue |
| 371 | break |
| 372 | else: |
| 373 | raise Errors.WafError('could not find library %r'%self.name) |
| 374 | self.link_task=self.create_task('fake_%s'%self.lib_type,[],[node]) |
| 375 | self.target=self.name |
| 376 | class fake_o(Task.Task): |
| 377 | def runnable_status(self): |
| 378 | return Task.SKIP_ME |
| 379 | @extension('.o','.obj') |
| 380 | def add_those_o_files(self,node): |
| 381 | tsk=self.create_task('fake_o',[],node) |
| 382 | try: |
| 383 | self.compiled_tasks.append(tsk) |
| 384 | except AttributeError: |
| 385 | self.compiled_tasks=[tsk] |
| 386 | @feature('fake_obj') |
| 387 | @before_method('process_source') |
| 388 | def process_objs(self): |
| 389 | for node in self.to_nodes(self.source): |
| 390 | self.add_those_o_files(node) |
| 391 | self.source=[] |
| 392 | @conf |
| 393 | def read_object(self,obj): |
| 394 | if not isinstance(obj,self.path.__class__): |
| 395 | obj=self.path.find_resource(obj) |
| 396 | return self(features='fake_obj',source=obj,name=obj.name) |