Imported Upstream version 1.9.8~dfsg.4+20120529git007cdc37
Adrian Knoth
11 years ago
0 | #!/usr/bin/env python | |
1 | # encoding: ISO8859-1 | |
2 | # Thomas Nagy, 2005-2011 | |
3 | ||
4 | """ | |
5 | Redistribution and use in source and binary forms, with or without | |
6 | modification, are permitted provided that the following conditions | |
7 | are met: | |
8 | ||
9 | 1. Redistributions of source code must retain the above copyright | |
10 | notice, this list of conditions and the following disclaimer. | |
11 | ||
12 | 2. Redistributions in binary form must reproduce the above copyright | |
13 | notice, this list of conditions and the following disclaimer in the | |
14 | documentation and/or other materials provided with the distribution. | |
15 | ||
16 | 3. The name of the author may not be used to endorse or promote products | |
17 | derived from this software without specific prior written permission. | |
18 | ||
19 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR | |
20 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
22 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
23 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
27 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
28 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | POSSIBILITY OF SUCH DAMAGE. | |
30 | """ | |
31 | ||
32 | import os, sys | |
33 | ||
34 | VERSION="1.6.11" | |
35 | REVISION="x" | |
36 | INSTALL="x" | |
37 | C1='x' | |
38 | C2='x' | |
39 | cwd = os.getcwd() | |
40 | join = os.path.join | |
41 | ||
42 | if sys.hexversion<0x206000f: | |
43 | raise ImportError('Python >= 2.6 is required to create the waf file') | |
44 | ||
45 | WAF='waf' | |
46 | def b(x): | |
47 | return x | |
48 | if sys.hexversion>0x300000f: | |
49 | WAF='waf3' | |
50 | def b(x): | |
51 | return x.encode() | |
52 | ||
53 | def err(m): | |
54 | print(('\033[91mError: %s\033[0m' % m)) | |
55 | sys.exit(1) | |
56 | ||
57 | def unpack_wafdir(dir): | |
58 | f = open(sys.argv[0],'rb') | |
59 | c = 'corrupt archive (%d)' | |
60 | while 1: | |
61 | line = f.readline() | |
62 | if not line: err('run waf-light from a folder containing waflib') | |
63 | if line == b('#==>\n'): | |
64 | txt = f.readline() | |
65 | if not txt: err(c % 1) | |
66 | if f.readline() != b('#<==\n'): err(c % 2) | |
67 | break | |
68 | if not txt: err(c % 3) | |
69 | txt = txt[1:-1].replace(b(C1), b('\n')).replace(b(C2), b('\r')) | |
70 | ||
71 | import shutil, tarfile | |
72 | try: shutil.rmtree(dir) | |
73 | except OSError: pass | |
74 | try: | |
75 | for x in ['Tools', 'extras']: | |
76 | os.makedirs(join(dir, 'waflib', x)) | |
77 | except OSError: | |
78 | err("Cannot unpack waf lib into %s\nMove waf into a writeable directory" % dir) | |
79 | ||
80 | os.chdir(dir) | |
81 | tmp = 't.bz2' | |
82 | t = open(tmp,'wb') | |
83 | t.write(txt) | |
84 | t.close() | |
85 | ||
86 | try: | |
87 | t = tarfile.open(tmp) | |
88 | except: | |
89 | try: | |
90 | os.system('bunzip2 t.bz2') | |
91 | t = tarfile.open('t') | |
92 | tmp = 't' | |
93 | except: | |
94 | os.chdir(cwd) | |
95 | try: shutil.rmtree(dir) | |
96 | except OSError: pass | |
97 | err("Waf cannot be unpacked, check that bzip2 support is present") | |
98 | ||
99 | for x in t: t.extract(x) | |
100 | t.close() | |
101 | ||
102 | for x in ['Tools', 'extras']: | |
103 | os.chmod(join('waflib',x), 493) | |
104 | ||
105 | if sys.hexversion<0x300000f: | |
106 | sys.path = [join(dir, 'waflib')] + sys.path | |
107 | import fixpy2 | |
108 | fixpy2.fixdir(dir) | |
109 | ||
110 | os.unlink(tmp) | |
111 | os.chdir(cwd) | |
112 | ||
113 | try: dir = unicode(dir, 'mbcs') | |
114 | except: pass | |
115 | try: | |
116 | from ctypes import windll | |
117 | windll.kernel32.SetFileAttributesW(dir, 2) | |
118 | except: | |
119 | pass | |
120 | ||
121 | def test(dir): | |
122 | try: | |
123 | os.stat(join(dir, 'waflib')) | |
124 | return os.path.abspath(dir) | |
125 | except OSError: | |
126 | pass | |
127 | ||
128 | def find_lib(): | |
129 | name = sys.argv[0] | |
130 | base = os.path.dirname(os.path.abspath(name)) | |
131 | ||
132 | #devs use $WAFDIR | |
133 | w=test(os.environ.get('WAFDIR', '')) | |
134 | if w: return w | |
135 | ||
136 | #waf-light | |
137 | if name.endswith('waf-light'): | |
138 | w = test(base) | |
139 | if w: return w | |
140 | err('waf-light requires waflib -> export WAFDIR=/folder') | |
141 | ||
142 | dirname = '%s-%s-%s' % (WAF, VERSION, REVISION) | |
143 | for i in [INSTALL,'/usr','/usr/local','/opt']: | |
144 | w = test(i + '/lib/' + dirname) | |
145 | if w: return w | |
146 | ||
147 | #waf-local | |
148 | dir = join(base, (sys.platform != 'win32' and '.' or '') + dirname) | |
149 | w = test(dir) | |
150 | if w: return w | |
151 | ||
152 | #unpack | |
153 | unpack_wafdir(dir) | |
154 | return dir | |
155 | ||
156 | wafdir = find_lib() | |
157 | sys.path.insert(0, wafdir) | |
158 | ||
159 | if __name__ == '__main__': | |
160 | import waflib.extras.compat15#PRELUDE | |
161 | from waflib import Scripting | |
162 | Scripting.waf_entry_point(cwd, VERSION, wafdir) | |
163 |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,errno,re,shutil | |
5 | try:import cPickle | |
6 | except:import pickle as cPickle | |
7 | from waflib import Runner,TaskGen,Utils,ConfigSet,Task,Logs,Options,Context,Errors | |
8 | import waflib.Node | |
9 | CACHE_DIR='c4che' | |
10 | CACHE_SUFFIX='_cache.py' | |
11 | INSTALL=1337 | |
12 | UNINSTALL=-1337 | |
13 | SAVED_ATTRS='root node_deps raw_deps task_sigs'.split() | |
14 | CFG_FILES='cfg_files' | |
15 | POST_AT_ONCE=0 | |
16 | POST_LAZY=1 | |
17 | POST_BOTH=2 | |
18 | class BuildContext(Context.Context): | |
19 | '''executes the build''' | |
20 | cmd='build' | |
21 | variant='' | |
22 | def __init__(self,**kw): | |
23 | super(BuildContext,self).__init__(**kw) | |
24 | self.is_install=0 | |
25 | self.top_dir=kw.get('top_dir',Context.top_dir) | |
26 | self.run_dir=kw.get('run_dir',Context.run_dir) | |
27 | self.post_mode=POST_AT_ONCE | |
28 | self.out_dir=kw.get('out_dir',Context.out_dir) | |
29 | self.cache_dir=kw.get('cache_dir',None) | |
30 | if not self.cache_dir: | |
31 | self.cache_dir=self.out_dir+os.sep+CACHE_DIR | |
32 | self.all_envs={} | |
33 | self.task_sigs={} | |
34 | self.node_deps={} | |
35 | self.raw_deps={} | |
36 | self.cache_dir_contents={} | |
37 | self.task_gen_cache_names={} | |
38 | self.launch_dir=Context.launch_dir | |
39 | self.jobs=Options.options.jobs | |
40 | self.targets=Options.options.targets | |
41 | self.keep=Options.options.keep | |
42 | self.cache_global=Options.cache_global | |
43 | self.nocache=Options.options.nocache | |
44 | self.progress_bar=Options.options.progress_bar | |
45 | self.deps_man=Utils.defaultdict(list) | |
46 | self.current_group=0 | |
47 | self.groups=[] | |
48 | self.group_names={} | |
49 | def get_variant_dir(self): | |
50 | if not self.variant: | |
51 | return self.out_dir | |
52 | return os.path.join(self.out_dir,self.variant) | |
53 | variant_dir=property(get_variant_dir,None) | |
54 | def __call__(self,*k,**kw): | |
55 | kw['bld']=self | |
56 | ret=TaskGen.task_gen(*k,**kw) | |
57 | self.task_gen_cache_names={} | |
58 | self.add_to_group(ret,group=kw.get('group',None)) | |
59 | return ret | |
60 | def __copy__(self): | |
61 | raise Errors.WafError('build contexts are not supposed to be copied') | |
62 | def install_files(self,*k,**kw): | |
63 | pass | |
64 | def install_as(self,*k,**kw): | |
65 | pass | |
66 | def symlink_as(self,*k,**kw): | |
67 | pass | |
68 | def load_envs(self): | |
69 | node=self.root.find_node(self.cache_dir) | |
70 | if not node: | |
71 | raise Errors.WafError('The project was not configured: run "waf configure" first!') | |
72 | lst=node.ant_glob('**/*%s'%CACHE_SUFFIX,quiet=True) | |
73 | if not lst: | |
74 | raise Errors.WafError('The cache directory is empty: reconfigure the project') | |
75 | for x in lst: | |
76 | name=x.path_from(node).replace(CACHE_SUFFIX,'').replace('\\','/') | |
77 | env=ConfigSet.ConfigSet(x.abspath()) | |
78 | self.all_envs[name]=env | |
79 | for f in env[CFG_FILES]: | |
80 | newnode=self.root.find_resource(f) | |
81 | try: | |
82 | h=Utils.h_file(newnode.abspath()) | |
83 | except(IOError,AttributeError): | |
84 | Logs.error('cannot find %r'%f) | |
85 | h=Utils.SIG_NIL | |
86 | newnode.sig=h | |
87 | def init_dirs(self): | |
88 | if not(os.path.isabs(self.top_dir)and os.path.isabs(self.out_dir)): | |
89 | raise Errors.WafError('The project was not configured: run "waf configure" first!') | |
90 | self.path=self.srcnode=self.root.find_dir(self.top_dir) | |
91 | self.bldnode=self.root.make_node(self.variant_dir) | |
92 | self.bldnode.mkdir() | |
93 | def execute(self): | |
94 | self.restore() | |
95 | if not self.all_envs: | |
96 | self.load_envs() | |
97 | self.execute_build() | |
98 | def execute_build(self): | |
99 | Logs.info("Waf: Entering directory `%s'"%self.variant_dir) | |
100 | self.recurse([self.run_dir]) | |
101 | self.pre_build() | |
102 | self.timer=Utils.Timer() | |
103 | if self.progress_bar: | |
104 | sys.stderr.write(Logs.colors.cursor_off) | |
105 | try: | |
106 | self.compile() | |
107 | finally: | |
108 | if self.progress_bar==1: | |
109 | c=len(self.returned_tasks)or 1 | |
110 | self.to_log(self.progress_line(c,c,Logs.colors.BLUE,Logs.colors.NORMAL)) | |
111 | print('') | |
112 | sys.stdout.flush() | |
113 | sys.stderr.write(Logs.colors.cursor_on) | |
114 | Logs.info("Waf: Leaving directory `%s'"%self.variant_dir) | |
115 | self.post_build() | |
116 | def restore(self): | |
117 | try: | |
118 | env=ConfigSet.ConfigSet(os.path.join(self.cache_dir,'build.config.py')) | |
119 | except(IOError,OSError): | |
120 | pass | |
121 | else: | |
122 | if env['version']<Context.HEXVERSION: | |
123 | raise Errors.WafError('Version mismatch! reconfigure the project') | |
124 | for t in env['tools']: | |
125 | self.setup(**t) | |
126 | f=None | |
127 | try: | |
128 | dbfn=os.path.join(self.variant_dir,Context.DBFILE) | |
129 | try: | |
130 | f=open(dbfn,'rb') | |
131 | except(IOError,EOFError): | |
132 | Logs.debug('build: could not load the build cache %s (missing)'%dbfn) | |
133 | else: | |
134 | try: | |
135 | waflib.Node.pickle_lock.acquire() | |
136 | waflib.Node.Nod3=self.node_class | |
137 | try: | |
138 | data=cPickle.load(f) | |
139 | except Exception ,e: | |
140 | Logs.debug('build: could not pickle the build cache %s: %r'%(dbfn,e)) | |
141 | else: | |
142 | for x in SAVED_ATTRS: | |
143 | setattr(self,x,data[x]) | |
144 | finally: | |
145 | waflib.Node.pickle_lock.release() | |
146 | finally: | |
147 | if f: | |
148 | f.close() | |
149 | self.init_dirs() | |
150 | def store(self): | |
151 | data={} | |
152 | for x in SAVED_ATTRS: | |
153 | data[x]=getattr(self,x) | |
154 | db=os.path.join(self.variant_dir,Context.DBFILE) | |
155 | try: | |
156 | waflib.Node.pickle_lock.acquire() | |
157 | waflib.Node.Nod3=self.node_class | |
158 | f=None | |
159 | try: | |
160 | f=open(db+'.tmp','wb') | |
161 | cPickle.dump(data,f) | |
162 | finally: | |
163 | if f: | |
164 | f.close() | |
165 | finally: | |
166 | waflib.Node.pickle_lock.release() | |
167 | try: | |
168 | st=os.stat(db) | |
169 | os.unlink(db) | |
170 | if not Utils.is_win32: | |
171 | os.chown(db+'.tmp',st.st_uid,st.st_gid) | |
172 | except(AttributeError,OSError): | |
173 | pass | |
174 | os.rename(db+'.tmp',db) | |
175 | def compile(self): | |
176 | Logs.debug('build: compile()') | |
177 | self.producer=Runner.Parallel(self,self.jobs) | |
178 | self.producer.biter=self.get_build_iterator() | |
179 | self.returned_tasks=[] | |
180 | try: | |
181 | self.producer.start() | |
182 | except KeyboardInterrupt: | |
183 | self.store() | |
184 | raise | |
185 | else: | |
186 | if self.producer.dirty: | |
187 | self.store() | |
188 | if self.producer.error: | |
189 | raise Errors.BuildError(self.producer.error) | |
190 | def setup(self,tool,tooldir=None,funs=None): | |
191 | if isinstance(tool,list): | |
192 | for i in tool:self.setup(i,tooldir) | |
193 | return | |
194 | module=Context.load_tool(tool,tooldir) | |
195 | if hasattr(module,"setup"):module.setup(self) | |
196 | def get_env(self): | |
197 | try: | |
198 | return self.all_envs[self.variant] | |
199 | except KeyError: | |
200 | return self.all_envs[''] | |
201 | def set_env(self,val): | |
202 | self.all_envs[self.variant]=val | |
203 | env=property(get_env,set_env) | |
204 | def add_manual_dependency(self,path,value): | |
205 | if isinstance(path,waflib.Node.Node): | |
206 | node=path | |
207 | elif os.path.isabs(path): | |
208 | node=self.root.find_resource(path) | |
209 | else: | |
210 | node=self.path.find_resource(path) | |
211 | self.deps_man[id(node)].append(value) | |
212 | def launch_node(self): | |
213 | try: | |
214 | return self.p_ln | |
215 | except AttributeError: | |
216 | self.p_ln=self.root.find_dir(self.launch_dir) | |
217 | return self.p_ln | |
218 | def hash_env_vars(self,env,vars_lst): | |
219 | if not env.table: | |
220 | env=env.parent | |
221 | if not env: | |
222 | return Utils.SIG_NIL | |
223 | idx=str(id(env))+str(vars_lst) | |
224 | try: | |
225 | cache=self.cache_env | |
226 | except AttributeError: | |
227 | cache=self.cache_env={} | |
228 | else: | |
229 | try: | |
230 | return self.cache_env[idx] | |
231 | except KeyError: | |
232 | pass | |
233 | lst=[env[a]for a in vars_lst] | |
234 | ret=Utils.h_list(lst) | |
235 | Logs.debug('envhash: %s %r',Utils.to_hex(ret),lst) | |
236 | cache[idx]=ret | |
237 | return ret | |
238 | def get_tgen_by_name(self,name): | |
239 | cache=self.task_gen_cache_names | |
240 | if not cache: | |
241 | for g in self.groups: | |
242 | for tg in g: | |
243 | try: | |
244 | cache[tg.name]=tg | |
245 | except AttributeError: | |
246 | pass | |
247 | try: | |
248 | return cache[name] | |
249 | except KeyError: | |
250 | raise Errors.WafError('Could not find a task generator for the name %r'%name) | |
251 | def progress_line(self,state,total,col1,col2): | |
252 | n=len(str(total)) | |
253 | Utils.rot_idx+=1 | |
254 | ind=Utils.rot_chr[Utils.rot_idx%4] | |
255 | pc=(100.*state)/total | |
256 | eta=str(self.timer) | |
257 | fs="[%%%dd/%%%dd][%%s%%2d%%%%%%s][%s]["%(n,n,ind) | |
258 | left=fs%(state,total,col1,pc,col2) | |
259 | right='][%s%s%s]'%(col1,eta,col2) | |
260 | cols=Logs.get_term_cols()-len(left)-len(right)+2*len(col1)+2*len(col2) | |
261 | if cols<7:cols=7 | |
262 | ratio=((cols*state)//total)-1 | |
263 | bar=('='*ratio+'>').ljust(cols) | |
264 | msg=Utils.indicator%(left,bar,right) | |
265 | return msg | |
266 | def declare_chain(self,*k,**kw): | |
267 | return TaskGen.declare_chain(*k,**kw) | |
268 | def pre_build(self): | |
269 | for m in getattr(self,'pre_funs',[]): | |
270 | m(self) | |
271 | def post_build(self): | |
272 | for m in getattr(self,'post_funs',[]): | |
273 | m(self) | |
274 | def add_pre_fun(self,meth): | |
275 | try: | |
276 | self.pre_funs.append(meth) | |
277 | except AttributeError: | |
278 | self.pre_funs=[meth] | |
279 | def add_post_fun(self,meth): | |
280 | try: | |
281 | self.post_funs.append(meth) | |
282 | except AttributeError: | |
283 | self.post_funs=[meth] | |
284 | def get_group(self,x): | |
285 | if not self.groups: | |
286 | self.add_group() | |
287 | if x is None: | |
288 | return self.groups[self.current_group] | |
289 | if x in self.group_names: | |
290 | return self.group_names[x] | |
291 | return self.groups[x] | |
292 | def add_to_group(self,tgen,group=None): | |
293 | assert(isinstance(tgen,TaskGen.task_gen)or isinstance(tgen,Task.TaskBase)) | |
294 | tgen.bld=self | |
295 | self.get_group(group).append(tgen) | |
296 | def get_group_name(self,g): | |
297 | if not isinstance(g,list): | |
298 | g=self.groups[g] | |
299 | for x in self.group_names: | |
300 | if id(self.group_names[x])==id(g): | |
301 | return x | |
302 | return'' | |
303 | def get_group_idx(self,tg): | |
304 | se=id(tg) | |
305 | for i in range(len(self.groups)): | |
306 | for t in self.groups[i]: | |
307 | if id(t)==se: | |
308 | return i | |
309 | return None | |
310 | def add_group(self,name=None,move=True): | |
311 | if name and name in self.group_names: | |
312 | Logs.error('add_group: name %s already present'%name) | |
313 | g=[] | |
314 | self.group_names[name]=g | |
315 | self.groups.append(g) | |
316 | if move: | |
317 | self.current_group=len(self.groups)-1 | |
318 | def set_group(self,idx): | |
319 | if isinstance(idx,str): | |
320 | g=self.group_names[idx] | |
321 | for i in range(len(self.groups)): | |
322 | if id(g)==id(self.groups[i]): | |
323 | self.current_group=i | |
324 | else: | |
325 | self.current_group=idx | |
326 | def total(self): | |
327 | total=0 | |
328 | for group in self.groups: | |
329 | for tg in group: | |
330 | try: | |
331 | total+=len(tg.tasks) | |
332 | except AttributeError: | |
333 | total+=1 | |
334 | return total | |
335 | def get_targets(self): | |
336 | to_post=[] | |
337 | min_grp=0 | |
338 | for name in self.targets.split(','): | |
339 | tg=self.get_tgen_by_name(name) | |
340 | if not tg: | |
341 | raise Errors.WafError('target %r does not exist'%name) | |
342 | m=self.get_group_idx(tg) | |
343 | if m>min_grp: | |
344 | min_grp=m | |
345 | to_post=[tg] | |
346 | elif m==min_grp: | |
347 | to_post.append(tg) | |
348 | return(min_grp,to_post) | |
349 | def post_group(self): | |
350 | if self.targets=='*': | |
351 | for tg in self.groups[self.cur]: | |
352 | try: | |
353 | f=tg.post | |
354 | except AttributeError: | |
355 | pass | |
356 | else: | |
357 | f() | |
358 | elif self.targets: | |
359 | if self.cur<self._min_grp: | |
360 | for tg in self.groups[self.cur]: | |
361 | try: | |
362 | f=tg.post | |
363 | except AttributeError: | |
364 | pass | |
365 | else: | |
366 | f() | |
367 | else: | |
368 | for tg in self._exact_tg: | |
369 | tg.post() | |
370 | else: | |
371 | ln=self.launch_node() | |
372 | for tg in self.groups[self.cur]: | |
373 | try: | |
374 | f=tg.post | |
375 | except AttributeError: | |
376 | pass | |
377 | else: | |
378 | if tg.path.is_child_of(ln): | |
379 | f() | |
380 | def get_tasks_group(self,idx): | |
381 | tasks=[] | |
382 | for tg in self.groups[idx]: | |
383 | if isinstance(tg,Task.TaskBase): | |
384 | tasks.append(tg) | |
385 | else: | |
386 | tasks.extend(tg.tasks) | |
387 | return tasks | |
388 | def get_build_iterator(self): | |
389 | self.cur=0 | |
390 | if self.targets and self.targets!='*': | |
391 | (self._min_grp,self._exact_tg)=self.get_targets() | |
392 | global lazy_post | |
393 | if self.post_mode!=POST_LAZY: | |
394 | while self.cur<len(self.groups): | |
395 | self.post_group() | |
396 | self.cur+=1 | |
397 | self.cur=0 | |
398 | while self.cur<len(self.groups): | |
399 | if self.post_mode!=POST_AT_ONCE: | |
400 | self.post_group() | |
401 | tasks=self.get_tasks_group(self.cur) | |
402 | Task.set_file_constraints(tasks) | |
403 | Task.set_precedence_constraints(tasks) | |
404 | self.cur_tasks=tasks | |
405 | self.cur+=1 | |
406 | if not tasks: | |
407 | continue | |
408 | yield tasks | |
409 | while 1: | |
410 | yield[] | |
411 | class inst(Task.Task): | |
412 | color='CYAN' | |
413 | def post(self): | |
414 | buf=[] | |
415 | for x in self.source: | |
416 | if isinstance(x,waflib.Node.Node): | |
417 | y=x | |
418 | else: | |
419 | y=self.path.find_resource(x) | |
420 | if not y: | |
421 | if Logs.verbose: | |
422 | Logs.warn('Could not find %s immediately (may cause broken builds)'%x) | |
423 | idx=self.generator.bld.get_group_idx(self) | |
424 | for tg in self.generator.bld.groups[idx]: | |
425 | if not isinstance(tg,inst)and id(tg)!=id(self): | |
426 | tg.post() | |
427 | y=self.path.find_resource(x) | |
428 | if y: | |
429 | break | |
430 | else: | |
431 | raise Errors.WafError('could not find %r in %r'%(x,self.path)) | |
432 | buf.append(y) | |
433 | self.inputs=buf | |
434 | def runnable_status(self): | |
435 | ret=super(inst,self).runnable_status() | |
436 | if ret==Task.SKIP_ME: | |
437 | return Task.RUN_ME | |
438 | return ret | |
439 | def __str__(self): | |
440 | return'' | |
441 | def run(self): | |
442 | return self.generator.exec_task() | |
443 | def get_install_path(self,destdir=True): | |
444 | dest=Utils.subst_vars(self.dest,self.env) | |
445 | dest=dest.replace('/',os.sep) | |
446 | if destdir and Options.options.destdir: | |
447 | dest=os.path.join(Options.options.destdir,os.path.splitdrive(dest)[1].lstrip(os.sep)) | |
448 | return dest | |
449 | def exec_install_files(self): | |
450 | destpath=self.get_install_path() | |
451 | if not destpath: | |
452 | raise Errors.WafError('unknown installation path %r'%self.generator) | |
453 | for x,y in zip(self.source,self.inputs): | |
454 | if self.relative_trick: | |
455 | destfile=os.path.join(destpath,y.path_from(self.path)) | |
456 | Utils.check_dir(os.path.dirname(destfile)) | |
457 | else: | |
458 | destfile=os.path.join(destpath,y.name) | |
459 | self.generator.bld.do_install(y.abspath(),destfile,self.chmod) | |
460 | def exec_install_as(self): | |
461 | destfile=self.get_install_path() | |
462 | self.generator.bld.do_install(self.inputs[0].abspath(),destfile,self.chmod) | |
463 | def exec_symlink_as(self): | |
464 | destfile=self.get_install_path() | |
465 | self.generator.bld.do_link(self.link,destfile) | |
466 | class InstallContext(BuildContext): | |
467 | '''installs the targets on the system''' | |
468 | cmd='install' | |
469 | def __init__(self,**kw): | |
470 | super(InstallContext,self).__init__(**kw) | |
471 | self.uninstall=[] | |
472 | self.is_install=INSTALL | |
473 | def do_install(self,src,tgt,chmod=Utils.O644): | |
474 | d,_=os.path.split(tgt) | |
475 | if not d: | |
476 | raise Errors.WafError('Invalid installation given %r->%r'%(src,tgt)) | |
477 | Utils.check_dir(d) | |
478 | srclbl=src.replace(self.srcnode.abspath()+os.sep,'') | |
479 | if not Options.options.force: | |
480 | try: | |
481 | st1=os.stat(tgt) | |
482 | st2=os.stat(src) | |
483 | except OSError: | |
484 | pass | |
485 | else: | |
486 | if st1.st_mtime+2>=st2.st_mtime and st1.st_size==st2.st_size: | |
487 | if not self.progress_bar: | |
488 | Logs.info('- install %s (from %s)'%(tgt,srclbl)) | |
489 | return False | |
490 | if not self.progress_bar: | |
491 | Logs.info('+ install %s (from %s)'%(tgt,srclbl)) | |
492 | try: | |
493 | os.remove(tgt) | |
494 | except OSError: | |
495 | pass | |
496 | try: | |
497 | shutil.copy2(src,tgt) | |
498 | os.chmod(tgt,chmod) | |
499 | except IOError: | |
500 | try: | |
501 | os.stat(src) | |
502 | except(OSError,IOError): | |
503 | Logs.error('File %r does not exist'%src) | |
504 | raise Errors.WafError('Could not install the file %r'%tgt) | |
505 | def do_link(self,src,tgt): | |
506 | d,_=os.path.split(tgt) | |
507 | Utils.check_dir(d) | |
508 | link=False | |
509 | if not os.path.islink(tgt): | |
510 | link=True | |
511 | elif os.readlink(tgt)!=src: | |
512 | link=True | |
513 | if link: | |
514 | try:os.remove(tgt) | |
515 | except OSError:pass | |
516 | if not self.progress_bar: | |
517 | Logs.info('+ symlink %s (to %s)'%(tgt,src)) | |
518 | os.symlink(src,tgt) | |
519 | else: | |
520 | if not self.progress_bar: | |
521 | Logs.info('- symlink %s (to %s)'%(tgt,src)) | |
522 | def run_task_now(self,tsk,postpone): | |
523 | tsk.post() | |
524 | if not postpone: | |
525 | if tsk.runnable_status()==Task.ASK_LATER: | |
526 | raise self.WafError('cannot post the task %r'%tsk) | |
527 | tsk.run() | |
528 | def install_files(self,dest,files,env=None,chmod=Utils.O644,relative_trick=False,cwd=None,add=True,postpone=True): | |
529 | tsk=inst(env=env or self.env) | |
530 | tsk.bld=self | |
531 | tsk.path=cwd or self.path | |
532 | tsk.chmod=chmod | |
533 | if isinstance(files,waflib.Node.Node): | |
534 | tsk.source=[files] | |
535 | else: | |
536 | tsk.source=Utils.to_list(files) | |
537 | tsk.dest=dest | |
538 | tsk.exec_task=tsk.exec_install_files | |
539 | tsk.relative_trick=relative_trick | |
540 | if add:self.add_to_group(tsk) | |
541 | self.run_task_now(tsk,postpone) | |
542 | return tsk | |
543 | def install_as(self,dest,srcfile,env=None,chmod=Utils.O644,cwd=None,add=True,postpone=True): | |
544 | tsk=inst(env=env or self.env) | |
545 | tsk.bld=self | |
546 | tsk.path=cwd or self.path | |
547 | tsk.chmod=chmod | |
548 | tsk.source=[srcfile] | |
549 | tsk.dest=dest | |
550 | tsk.exec_task=tsk.exec_install_as | |
551 | if add:self.add_to_group(tsk) | |
552 | self.run_task_now(tsk,postpone) | |
553 | return tsk | |
554 | def symlink_as(self,dest,src,env=None,cwd=None,add=True,postpone=True): | |
555 | if Utils.is_win32: | |
556 | return | |
557 | tsk=inst(env=env or self.env) | |
558 | tsk.bld=self | |
559 | tsk.dest=dest | |
560 | tsk.path=cwd or self.path | |
561 | tsk.source=[] | |
562 | tsk.link=src | |
563 | tsk.exec_task=tsk.exec_symlink_as | |
564 | if add:self.add_to_group(tsk) | |
565 | self.run_task_now(tsk,postpone) | |
566 | return tsk | |
567 | class UninstallContext(InstallContext): | |
568 | '''removes the targets installed''' | |
569 | cmd='uninstall' | |
570 | def __init__(self,**kw): | |
571 | super(UninstallContext,self).__init__(**kw) | |
572 | self.is_install=UNINSTALL | |
573 | def do_install(self,src,tgt,chmod=Utils.O644): | |
574 | if not self.progress_bar: | |
575 | Logs.info('- remove %s'%tgt) | |
576 | self.uninstall.append(tgt) | |
577 | try: | |
578 | os.remove(tgt) | |
579 | except OSError ,e: | |
580 | if e.errno!=errno.ENOENT: | |
581 | if not getattr(self,'uninstall_error',None): | |
582 | self.uninstall_error=True | |
583 | Logs.warn('build: some files could not be uninstalled (retry with -vv to list them)') | |
584 | if Logs.verbose>1: | |
585 | Logs.warn('could not remove %s (error code %r)'%(e.filename,e.errno)) | |
586 | while tgt: | |
587 | tgt=os.path.dirname(tgt) | |
588 | try: | |
589 | os.rmdir(tgt) | |
590 | except OSError: | |
591 | break | |
592 | def do_link(self,src,tgt): | |
593 | try: | |
594 | if not self.progress_bar: | |
595 | Logs.info('- unlink %s'%tgt) | |
596 | os.remove(tgt) | |
597 | except OSError: | |
598 | pass | |
599 | while tgt: | |
600 | tgt=os.path.dirname(tgt) | |
601 | try: | |
602 | os.rmdir(tgt) | |
603 | except OSError: | |
604 | break | |
605 | def execute(self): | |
606 | try: | |
607 | def runnable_status(self): | |
608 | return Task.SKIP_ME | |
609 | setattr(Task.Task,'runnable_status_back',Task.Task.runnable_status) | |
610 | setattr(Task.Task,'runnable_status',runnable_status) | |
611 | super(UninstallContext,self).execute() | |
612 | finally: | |
613 | setattr(Task.Task,'runnable_status',Task.Task.runnable_status_back) | |
614 | class CleanContext(BuildContext): | |
615 | '''cleans the project''' | |
616 | cmd='clean' | |
617 | def execute(self): | |
618 | self.restore() | |
619 | if not self.all_envs: | |
620 | self.load_envs() | |
621 | self.recurse([self.run_dir]) | |
622 | try: | |
623 | self.clean() | |
624 | finally: | |
625 | self.store() | |
626 | def clean(self): | |
627 | Logs.debug('build: clean called') | |
628 | if self.bldnode!=self.srcnode: | |
629 | lst=[self.root.find_or_declare(f)for f in self.env[CFG_FILES]] | |
630 | for n in self.bldnode.ant_glob('**/*',excl='lock* *conf_check_*/** config.log c4che/*',quiet=True): | |
631 | if n in lst: | |
632 | continue | |
633 | n.delete() | |
634 | self.root.children={} | |
635 | for v in'node_deps task_sigs raw_deps'.split(): | |
636 | setattr(self,v,{}) | |
637 | class ListContext(BuildContext): | |
638 | '''lists the targets to execute''' | |
639 | cmd='list' | |
640 | def execute(self): | |
641 | self.restore() | |
642 | if not self.all_envs: | |
643 | self.load_envs() | |
644 | self.recurse([self.run_dir]) | |
645 | self.pre_build() | |
646 | self.timer=Utils.Timer() | |
647 | for g in self.groups: | |
648 | for tg in g: | |
649 | try: | |
650 | f=tg.post | |
651 | except AttributeError: | |
652 | pass | |
653 | else: | |
654 | f() | |
655 | try: | |
656 | self.get_tgen_by_name('') | |
657 | except: | |
658 | pass | |
659 | lst=list(self.task_gen_cache_names.keys()) | |
660 | lst.sort() | |
661 | for k in lst: | |
662 | Logs.pprint('GREEN',k) | |
663 | class StepContext(BuildContext): | |
664 | '''executes tasks in a step-by-step fashion, for debugging''' | |
665 | cmd='step' | |
666 | def __init__(self,**kw): | |
667 | super(StepContext,self).__init__(**kw) | |
668 | self.files=Options.options.files | |
669 | def compile(self): | |
670 | if not self.files: | |
671 | Logs.warn('Add a pattern for the debug build, for example "waf step --files=main.c,app"') | |
672 | BuildContext.compile(self) | |
673 | return | |
674 | for g in self.groups: | |
675 | for tg in g: | |
676 | try: | |
677 | f=tg.post | |
678 | except AttributeError: | |
679 | pass | |
680 | else: | |
681 | f() | |
682 | for pat in self.files.split(','): | |
683 | matcher=self.get_matcher(pat) | |
684 | for tg in g: | |
685 | if isinstance(tg,Task.TaskBase): | |
686 | lst=[tg] | |
687 | else: | |
688 | lst=tg.tasks | |
689 | for tsk in lst: | |
690 | do_exec=False | |
691 | for node in getattr(tsk,'inputs',[]): | |
692 | if matcher(node,output=False): | |
693 | do_exec=True | |
694 | break | |
695 | for node in getattr(tsk,'outputs',[]): | |
696 | if matcher(node,output=True): | |
697 | do_exec=True | |
698 | break | |
699 | if do_exec: | |
700 | ret=tsk.run() | |
701 | Logs.info('%s -> exit %r'%(str(tsk),ret)) | |
702 | def get_matcher(self,pat): | |
703 | inn=True | |
704 | out=True | |
705 | if pat.startswith('in:'): | |
706 | out=False | |
707 | pat=pat.replace('in:','') | |
708 | elif pat.startswith('out:'): | |
709 | inn=False | |
710 | pat=pat.replace('out:','') | |
711 | anode=self.root.find_node(pat) | |
712 | pattern=None | |
713 | if not anode: | |
714 | if not pat.startswith('^'): | |
715 | pat='^.+?%s'%pat | |
716 | if not pat.endswith('$'): | |
717 | pat='%s$'%pat | |
718 | pattern=re.compile(pat) | |
719 | def match(node,output): | |
720 | if output==True and not out: | |
721 | return False | |
722 | if output==False and not inn: | |
723 | return False | |
724 | if anode: | |
725 | return anode==node | |
726 | else: | |
727 | return pattern.match(node.abspath()) | |
728 | return match | |
729 | BuildContext.store=Utils.nogc(BuildContext.store) | |
730 | BuildContext.restore=Utils.nogc(BuildContext.restore) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import copy,re,os | |
7 | from waflib import Logs,Utils | |
8 | re_imp=re.compile('^(#)*?([^#=]*?)\ =\ (.*?)$',re.M) | |
9 | class ConfigSet(object): | |
10 | __slots__=('table','parent') | |
11 | def __init__(self,filename=None): | |
12 | self.table={} | |
13 | if filename: | |
14 | self.load(filename) | |
15 | def __contains__(self,key): | |
16 | if key in self.table:return True | |
17 | try:return self.parent.__contains__(key) | |
18 | except AttributeError:return False | |
19 | def keys(self): | |
20 | keys=set() | |
21 | cur=self | |
22 | while cur: | |
23 | keys.update(cur.table.keys()) | |
24 | cur=getattr(cur,'parent',None) | |
25 | keys=list(keys) | |
26 | keys.sort() | |
27 | return keys | |
28 | def __str__(self): | |
29 | return"\n".join(["%r %r"%(x,self.__getitem__(x))for x in self.keys()]) | |
30 | def __getitem__(self,key): | |
31 | try: | |
32 | while 1: | |
33 | x=self.table.get(key,None) | |
34 | if not x is None: | |
35 | return x | |
36 | self=self.parent | |
37 | except AttributeError: | |
38 | return[] | |
39 | def __setitem__(self,key,value): | |
40 | self.table[key]=value | |
41 | def __delitem__(self,key): | |
42 | self[key]=[] | |
43 | def __getattr__(self,name): | |
44 | if name in self.__slots__: | |
45 | return object.__getattr__(self,name) | |
46 | else: | |
47 | return self[name] | |
48 | def __setattr__(self,name,value): | |
49 | if name in self.__slots__: | |
50 | object.__setattr__(self,name,value) | |
51 | else: | |
52 | self[name]=value | |
53 | def __delattr__(self,name): | |
54 | if name in self.__slots__: | |
55 | object.__delattr__(self,name) | |
56 | else: | |
57 | del self[name] | |
58 | def derive(self): | |
59 | newenv=ConfigSet() | |
60 | newenv.parent=self | |
61 | return newenv | |
62 | def detach(self): | |
63 | tbl=self.get_merged_dict() | |
64 | try: | |
65 | delattr(self,'parent') | |
66 | except AttributeError: | |
67 | pass | |
68 | else: | |
69 | keys=tbl.keys() | |
70 | for x in keys: | |
71 | tbl[x]=copy.deepcopy(tbl[x]) | |
72 | self.table=tbl | |
73 | def get_flat(self,key): | |
74 | s=self[key] | |
75 | if isinstance(s,str):return s | |
76 | return' '.join(s) | |
77 | def _get_list_value_for_modification(self,key): | |
78 | try: | |
79 | value=self.table[key] | |
80 | except KeyError: | |
81 | try:value=self.parent[key] | |
82 | except AttributeError:value=[] | |
83 | if isinstance(value,list): | |
84 | value=value[:] | |
85 | else: | |
86 | value=[value] | |
87 | else: | |
88 | if not isinstance(value,list): | |
89 | value=[value] | |
90 | self.table[key]=value | |
91 | return value | |
92 | def append_value(self,var,val): | |
93 | current_value=self._get_list_value_for_modification(var) | |
94 | if isinstance(val,str): | |
95 | val=[val] | |
96 | current_value.extend(val) | |
97 | def prepend_value(self,var,val): | |
98 | if isinstance(val,str): | |
99 | val=[val] | |
100 | self.table[var]=val+self._get_list_value_for_modification(var) | |
101 | def append_unique(self,var,val): | |
102 | if isinstance(val,str): | |
103 | val=[val] | |
104 | current_value=self._get_list_value_for_modification(var) | |
105 | for x in val: | |
106 | if x not in current_value: | |
107 | current_value.append(x) | |
108 | def get_merged_dict(self): | |
109 | table_list=[] | |
110 | env=self | |
111 | while 1: | |
112 | table_list.insert(0,env.table) | |
113 | try:env=env.parent | |
114 | except AttributeError:break | |
115 | merged_table={} | |
116 | for table in table_list: | |
117 | merged_table.update(table) | |
118 | return merged_table | |
119 | def store(self,filename): | |
120 | try: | |
121 | os.makedirs(os.path.split(filename)[0]) | |
122 | except OSError: | |
123 | pass | |
124 | f=None | |
125 | try: | |
126 | f=open(filename,'w') | |
127 | merged_table=self.get_merged_dict() | |
128 | keys=list(merged_table.keys()) | |
129 | keys.sort() | |
130 | for k in keys: | |
131 | if k!='undo_stack': | |
132 | f.write('%s = %r\n'%(k,merged_table[k])) | |
133 | finally: | |
134 | if f: | |
135 | f.close() | |
136 | def load(self,filename): | |
137 | tbl=self.table | |
138 | code=Utils.readf(filename) | |
139 | for m in re_imp.finditer(code): | |
140 | g=m.group | |
141 | tbl[g(2)]=eval(g(3)) | |
142 | Logs.debug('env: %s'%str(self.table)) | |
143 | def update(self,d): | |
144 | for k,v in d.items(): | |
145 | self[k]=v | |
146 | def stash(self): | |
147 | self.undo_stack=self.undo_stack+[self.table] | |
148 | self.table=self.table.copy() | |
149 | def revert(self): | |
150 | self.table=self.undo_stack.pop(-1) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,shlex,sys,time | |
5 | from waflib import ConfigSet,Utils,Options,Logs,Context,Build,Errors | |
6 | try: | |
7 | from urllib import request | |
8 | except: | |
9 | from urllib import urlopen | |
10 | else: | |
11 | urlopen=request.urlopen | |
12 | BREAK='break' | |
13 | CONTINUE='continue' | |
14 | WAF_CONFIG_LOG='config.log' | |
15 | autoconfig=False | |
16 | conf_template='''# project %(app)s configured on %(now)s by | |
17 | # waf %(wafver)s (abi %(abi)s, python %(pyver)x on %(systype)s) | |
18 | # using %(args)s | |
19 | #''' | |
20 | def download_check(node): | |
21 | pass | |
22 | def download_tool(tool,force=False,ctx=None): | |
23 | for x in Utils.to_list(Context.remote_repo): | |
24 | for sub in Utils.to_list(Context.remote_locs): | |
25 | url='/'.join((x,sub,tool+'.py')) | |
26 | try: | |
27 | web=urlopen(url) | |
28 | try: | |
29 | if web.getcode()!=200: | |
30 | continue | |
31 | except AttributeError: | |
32 | pass | |
33 | except Exception: | |
34 | continue | |
35 | else: | |
36 | tmp=ctx.root.make_node(os.sep.join((Context.waf_dir,'waflib','extras',tool+'.py'))) | |
37 | tmp.write(web.read()) | |
38 | Logs.warn('Downloaded %s from %s'%(tool,url)) | |
39 | download_check(tmp) | |
40 | try: | |
41 | module=Context.load_tool(tool) | |
42 | except: | |
43 | Logs.warn('The tool %s from %s is unusable'%(tool,url)) | |
44 | try: | |
45 | tmp.delete() | |
46 | except: | |
47 | pass | |
48 | continue | |
49 | return module | |
50 | raise Errors.WafError('Could not load the Waf tool') | |
51 | class ConfigurationContext(Context.Context): | |
52 | '''configures the project''' | |
53 | cmd='configure' | |
54 | error_handlers=[] | |
55 | def __init__(self,**kw): | |
56 | super(ConfigurationContext,self).__init__(**kw) | |
57 | self.environ=dict(os.environ) | |
58 | self.all_envs={} | |
59 | self.top_dir=None | |
60 | self.out_dir=None | |
61 | self.tools=[] | |
62 | self.hash=0 | |
63 | self.files=[] | |
64 | self.tool_cache=[] | |
65 | self.setenv('') | |
66 | def setenv(self,name,env=None): | |
67 | if name not in self.all_envs or env: | |
68 | if not env: | |
69 | env=ConfigSet.ConfigSet() | |
70 | self.prepare_env(env) | |
71 | else: | |
72 | env=env.derive() | |
73 | self.all_envs[name]=env | |
74 | self.variant=name | |
75 | def get_env(self): | |
76 | return self.all_envs[self.variant] | |
77 | def set_env(self,val): | |
78 | self.all_envs[self.variant]=val | |
79 | env=property(get_env,set_env) | |
80 | def init_dirs(self): | |
81 | top=self.top_dir | |
82 | if not top: | |
83 | top=Options.options.top | |
84 | if not top: | |
85 | top=getattr(Context.g_module,Context.TOP,None) | |
86 | if not top: | |
87 | top=self.path.abspath() | |
88 | top=os.path.abspath(top) | |
89 | self.srcnode=(os.path.isabs(top)and self.root or self.path).find_dir(top) | |
90 | assert(self.srcnode) | |
91 | out=self.out_dir | |
92 | if not out: | |
93 | out=Options.options.out | |
94 | if not out: | |
95 | out=getattr(Context.g_module,Context.OUT,None) | |
96 | if not out: | |
97 | out=Options.lockfile.replace('.lock-waf_%s_'%sys.platform,'').replace('.lock-waf','') | |
98 | self.bldnode=(os.path.isabs(out)and self.root or self.path).make_node(out) | |
99 | self.bldnode.mkdir() | |
100 | if not os.path.isdir(self.bldnode.abspath()): | |
101 | conf.fatal('could not create the build directory %s'%self.bldnode.abspath()) | |
102 | def execute(self): | |
103 | self.init_dirs() | |
104 | self.cachedir=self.bldnode.make_node(Build.CACHE_DIR) | |
105 | self.cachedir.mkdir() | |
106 | path=os.path.join(self.bldnode.abspath(),WAF_CONFIG_LOG) | |
107 | self.logger=Logs.make_logger(path,'cfg') | |
108 | app=getattr(Context.g_module,'APPNAME','') | |
109 | if app: | |
110 | ver=getattr(Context.g_module,'VERSION','') | |
111 | if ver: | |
112 | app="%s (%s)"%(app,ver) | |
113 | now=time.ctime() | |
114 | pyver=sys.hexversion | |
115 | systype=sys.platform | |
116 | args=" ".join(sys.argv) | |
117 | wafver=Context.WAFVERSION | |
118 | abi=Context.ABI | |
119 | self.to_log(conf_template%vars()) | |
120 | self.msg('Setting top to',self.srcnode.abspath()) | |
121 | self.msg('Setting out to',self.bldnode.abspath()) | |
122 | if id(self.srcnode)==id(self.bldnode): | |
123 | Logs.warn('Setting top == out (remember to use "update_outputs")') | |
124 | elif id(self.path)!=id(self.srcnode): | |
125 | if self.srcnode.is_child_of(self.path): | |
126 | Logs.warn('Are you certain that you do not want to set top="." ?') | |
127 | super(ConfigurationContext,self).execute() | |
128 | self.store() | |
129 | Context.top_dir=self.srcnode.abspath() | |
130 | Context.out_dir=self.bldnode.abspath() | |
131 | env=ConfigSet.ConfigSet() | |
132 | env['argv']=sys.argv | |
133 | env['options']=Options.options.__dict__ | |
134 | env.run_dir=Context.run_dir | |
135 | env.top_dir=Context.top_dir | |
136 | env.out_dir=Context.out_dir | |
137 | env['hash']=self.hash | |
138 | env['files']=self.files | |
139 | env['environ']=dict(self.environ) | |
140 | if not self.env.NO_LOCK_IN_RUN: | |
141 | env.store(Context.run_dir+os.sep+Options.lockfile) | |
142 | if not self.env.NO_LOCK_IN_TOP: | |
143 | env.store(Context.top_dir+os.sep+Options.lockfile) | |
144 | if not self.env.NO_LOCK_IN_OUT: | |
145 | env.store(Context.out_dir+os.sep+Options.lockfile) | |
146 | def prepare_env(self,env): | |
147 | if not env.PREFIX: | |
148 | env.PREFIX=os.path.abspath(os.path.expanduser(Options.options.prefix)) | |
149 | if not env.BINDIR: | |
150 | env.BINDIR=Utils.subst_vars('${PREFIX}/bin',env) | |
151 | if not env.LIBDIR: | |
152 | env.LIBDIR=Utils.subst_vars('${PREFIX}/lib',env) | |
153 | def store(self): | |
154 | n=self.cachedir.make_node('build.config.py') | |
155 | n.write('version = 0x%x\ntools = %r\n'%(Context.HEXVERSION,self.tools)) | |
156 | if not self.all_envs: | |
157 | self.fatal('nothing to store in the configuration context!') | |
158 | for key in self.all_envs: | |
159 | tmpenv=self.all_envs[key] | |
160 | tmpenv.store(os.path.join(self.cachedir.abspath(),key+Build.CACHE_SUFFIX)) | |
161 | def load(self,input,tooldir=None,funs=None,download=True): | |
162 | tools=Utils.to_list(input) | |
163 | if tooldir:tooldir=Utils.to_list(tooldir) | |
164 | for tool in tools: | |
165 | mag=(tool,id(self.env),funs) | |
166 | if mag in self.tool_cache: | |
167 | self.to_log('(tool %s is already loaded, skipping)'%tool) | |
168 | continue | |
169 | self.tool_cache.append(mag) | |
170 | module=None | |
171 | try: | |
172 | module=Context.load_tool(tool,tooldir) | |
173 | except ImportError ,e: | |
174 | if Options.options.download: | |
175 | module=download_tool(tool,ctx=self) | |
176 | if not module: | |
177 | self.fatal('Could not load the Waf tool %r or download a suitable replacement from the repository (sys.path %r)\n%s'%(tool,sys.path,e)) | |
178 | else: | |
179 | self.fatal('Could not load the Waf tool %r from %r (try the --download option?):\n%s'%(tool,sys.path,e)) | |
180 | except Exception ,e: | |
181 | self.to_log('imp %r (%r & %r)'%(tool,tooldir,funs)) | |
182 | self.to_log(Utils.ex_stack()) | |
183 | raise | |
184 | if funs is not None: | |
185 | self.eval_rules(funs) | |
186 | else: | |
187 | func=getattr(module,'configure',None) | |
188 | if func: | |
189 | if type(func)is type(Utils.readf):func(self) | |
190 | else:self.eval_rules(func) | |
191 | self.tools.append({'tool':tool,'tooldir':tooldir,'funs':funs}) | |
192 | def post_recurse(self,node): | |
193 | super(ConfigurationContext,self).post_recurse(node) | |
194 | self.hash=hash((self.hash,node.read('rb'))) | |
195 | self.files.append(node.abspath()) | |
196 | def eval_rules(self,rules): | |
197 | self.rules=Utils.to_list(rules) | |
198 | for x in self.rules: | |
199 | f=getattr(self,x) | |
200 | if not f:self.fatal("No such method '%s'."%x) | |
201 | try: | |
202 | f() | |
203 | except Exception ,e: | |
204 | ret=self.err_handler(x,e) | |
205 | if ret==BREAK: | |
206 | break | |
207 | elif ret==CONTINUE: | |
208 | continue | |
209 | else: | |
210 | raise | |
211 | def err_handler(self,fun,error): | |
212 | pass | |
213 | def conf(f): | |
214 | def fun(*k,**kw): | |
215 | mandatory=True | |
216 | if'mandatory'in kw: | |
217 | mandatory=kw['mandatory'] | |
218 | del kw['mandatory'] | |
219 | try: | |
220 | return f(*k,**kw) | |
221 | except Errors.ConfigurationError ,e: | |
222 | if mandatory: | |
223 | raise e | |
224 | setattr(ConfigurationContext,f.__name__,fun) | |
225 | setattr(Build.BuildContext,f.__name__,fun) | |
226 | return f | |
227 | def add_os_flags(self,var,dest=None): | |
228 | try:self.env.append_value(dest or var,shlex.split(self.environ[var])) | |
229 | except KeyError:pass | |
230 | def cmd_to_list(self,cmd): | |
231 | if isinstance(cmd,str)and cmd.find(' '): | |
232 | try: | |
233 | os.stat(cmd) | |
234 | except OSError: | |
235 | return shlex.split(cmd) | |
236 | else: | |
237 | return[cmd] | |
238 | return cmd | |
239 | def check_waf_version(self,mini='1.6.0',maxi='1.7.0'): | |
240 | self.start_msg('Checking for waf version in %s-%s'%(str(mini),str(maxi))) | |
241 | ver=Context.HEXVERSION | |
242 | if Utils.num2ver(mini)>ver: | |
243 | self.fatal('waf version should be at least %r (%r found)'%(Utils.num2ver(mini),ver)) | |
244 | if Utils.num2ver(maxi)<ver: | |
245 | self.fatal('waf version should be at most %r (%r found)'%(Utils.num2ver(maxi),ver)) | |
246 | self.end_msg('ok') | |
247 | def find_file(self,filename,path_list=[]): | |
248 | for n in Utils.to_list(filename): | |
249 | for d in Utils.to_list(path_list): | |
250 | p=os.path.join(d,n) | |
251 | if os.path.exists(p): | |
252 | return p | |
253 | self.fatal('Could not find %r'%filename) | |
254 | def find_program(self,filename,**kw): | |
255 | exts=kw.get('exts',Utils.is_win32 and'.exe,.com,.bat,.cmd'or',.sh,.pl,.py') | |
256 | environ=kw.get('environ',os.environ) | |
257 | ret='' | |
258 | filename=Utils.to_list(filename) | |
259 | var=kw.get('var','') | |
260 | if not var: | |
261 | var=filename[0].upper() | |
262 | if self.env[var]: | |
263 | ret=self.env[var] | |
264 | elif var in environ: | |
265 | ret=environ[var] | |
266 | path_list=kw.get('path_list','') | |
267 | if not ret: | |
268 | if path_list: | |
269 | path_list=Utils.to_list(path_list) | |
270 | else: | |
271 | path_list=environ.get('PATH','').split(os.pathsep) | |
272 | if not isinstance(filename,list): | |
273 | filename=[filename] | |
274 | for a in exts.split(','): | |
275 | if ret: | |
276 | break | |
277 | for b in filename: | |
278 | if ret: | |
279 | break | |
280 | for c in path_list: | |
281 | if ret: | |
282 | break | |
283 | x=os.path.expanduser(os.path.join(c,b+a)) | |
284 | if os.path.isfile(x): | |
285 | ret=x | |
286 | if not ret and Utils.winreg: | |
287 | ret=Utils.get_registry_app_path(Utils.winreg.HKEY_CURRENT_USER,filename) | |
288 | if not ret and Utils.winreg: | |
289 | ret=Utils.get_registry_app_path(Utils.winreg.HKEY_LOCAL_MACHINE,filename) | |
290 | self.msg('Checking for program '+','.join(filename),ret or False) | |
291 | self.to_log('find program=%r paths=%r var=%r -> %r'%(filename,path_list,var,ret)) | |
292 | if not ret: | |
293 | self.fatal(kw.get('errmsg','')or'Could not find the program %s'%','.join(filename)) | |
294 | if var: | |
295 | self.env[var]=ret | |
296 | return ret | |
297 | def find_perl_program(self,filename,path_list=[],var=None,environ=None,exts=''): | |
298 | try: | |
299 | app=self.find_program(filename,path_list=path_list,var=var,environ=environ,exts=exts) | |
300 | except: | |
301 | self.find_program('perl',var='PERL') | |
302 | app=self.find_file(filename,os.environ['PATH'].split(os.pathsep)) | |
303 | if not app: | |
304 | raise | |
305 | if var: | |
306 | self.env[var]=Utils.to_list(self.env['PERL'])+[app] | |
307 | self.msg('Checking for %r'%filename,app) | |
308 | ||
309 | conf(add_os_flags) | |
310 | conf(cmd_to_list) | |
311 | conf(check_waf_version) | |
312 | conf(find_file) | |
313 | conf(find_program) | |
314 | conf(find_perl_program)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,imp,sys | |
5 | from waflib import Utils,Errors,Logs | |
6 | import waflib.Node | |
7 | HEXVERSION=0x1060b00 | |
8 | WAFVERSION="1.6.11" | |
9 | WAFREVISION="a7e69d6b81b04729804754c4d5214da063779a65" | |
10 | ABI=98 | |
11 | DBFILE='.wafpickle-%d'%ABI | |
12 | APPNAME='APPNAME' | |
13 | VERSION='VERSION' | |
14 | TOP='top' | |
15 | OUT='out' | |
16 | WSCRIPT_FILE='wscript' | |
17 | launch_dir='' | |
18 | run_dir='' | |
19 | top_dir='' | |
20 | out_dir='' | |
21 | waf_dir='' | |
22 | local_repo='' | |
23 | remote_repo='http://waf.googlecode.com/git/' | |
24 | remote_locs=['waflib/extras','waflib/Tools'] | |
25 | g_module=None | |
26 | STDOUT=1 | |
27 | STDERR=-1 | |
28 | BOTH=0 | |
29 | classes=[] | |
30 | def create_context(cmd_name,*k,**kw): | |
31 | global classes | |
32 | for x in classes: | |
33 | if x.cmd==cmd_name: | |
34 | return x(*k,**kw) | |
35 | ctx=Context(*k,**kw) | |
36 | ctx.fun=cmd_name | |
37 | return ctx | |
38 | class store_context(type): | |
39 | def __init__(cls,name,bases,dict): | |
40 | super(store_context,cls).__init__(name,bases,dict) | |
41 | name=cls.__name__ | |
42 | if name=='ctx'or name=='Context': | |
43 | return | |
44 | try: | |
45 | cls.cmd | |
46 | except AttributeError: | |
47 | raise Errors.WafError('Missing command for the context class %r (cmd)'%name) | |
48 | if not getattr(cls,'fun',None): | |
49 | cls.fun=cls.cmd | |
50 | global classes | |
51 | classes.insert(0,cls) | |
52 | ctx=store_context('ctx',(object,),{}) | |
53 | class Context(ctx): | |
54 | errors=Errors | |
55 | tools={} | |
56 | def __init__(self,**kw): | |
57 | try: | |
58 | rd=kw['run_dir'] | |
59 | except KeyError: | |
60 | global run_dir | |
61 | rd=run_dir | |
62 | class node_class(waflib.Node.Node): | |
63 | pass | |
64 | self.node_class=node_class | |
65 | self.node_class.__module__="waflib.Node" | |
66 | self.node_class.__name__="Nod3" | |
67 | self.node_class.ctx=self | |
68 | self.root=self.node_class('',None) | |
69 | self.cur_script=None | |
70 | self.path=self.root.find_dir(rd) | |
71 | self.stack_path=[] | |
72 | self.exec_dict={'ctx':self,'conf':self,'bld':self,'opt':self} | |
73 | self.logger=None | |
74 | def __hash__(self): | |
75 | return id(self) | |
76 | def load(self,tool_list,*k,**kw): | |
77 | tools=Utils.to_list(tool_list) | |
78 | path=Utils.to_list(kw.get('tooldir','')) | |
79 | for t in tools: | |
80 | module=load_tool(t,path) | |
81 | fun=getattr(module,kw.get('name',self.fun),None) | |
82 | if fun: | |
83 | fun(self) | |
84 | def execute(self): | |
85 | global g_module | |
86 | self.recurse([os.path.dirname(g_module.root_path)]) | |
87 | def pre_recurse(self,node): | |
88 | self.stack_path.append(self.cur_script) | |
89 | self.cur_script=node | |
90 | self.path=node.parent | |
91 | def post_recurse(self,node): | |
92 | self.cur_script=self.stack_path.pop() | |
93 | if self.cur_script: | |
94 | self.path=self.cur_script.parent | |
95 | def recurse(self,dirs,name=None,mandatory=True,once=True): | |
96 | try: | |
97 | cache=self.recurse_cache | |
98 | except: | |
99 | cache=self.recurse_cache={} | |
100 | for d in Utils.to_list(dirs): | |
101 | if not os.path.isabs(d): | |
102 | d=os.path.join(self.path.abspath(),d) | |
103 | WSCRIPT=os.path.join(d,WSCRIPT_FILE) | |
104 | WSCRIPT_FUN=WSCRIPT+'_'+(name or self.fun) | |
105 | node=self.root.find_node(WSCRIPT_FUN) | |
106 | if node and(not once or node not in cache): | |
107 | cache[node]=True | |
108 | self.pre_recurse(node) | |
109 | try: | |
110 | function_code=node.read('rU') | |
111 | exec(compile(function_code,node.abspath(),'exec'),self.exec_dict) | |
112 | finally: | |
113 | self.post_recurse(node) | |
114 | elif not node: | |
115 | node=self.root.find_node(WSCRIPT) | |
116 | tup=(node,name or self.fun) | |
117 | if node and(not once or tup not in cache): | |
118 | cache[tup]=True | |
119 | self.pre_recurse(node) | |
120 | try: | |
121 | wscript_module=load_module(node.abspath()) | |
122 | user_function=getattr(wscript_module,(name or self.fun),None) | |
123 | if not user_function: | |
124 | if not mandatory: | |
125 | continue | |
126 | raise Errors.WafError('No function %s defined in %s'%(name or self.fun,node.abspath())) | |
127 | user_function(self) | |
128 | finally: | |
129 | self.post_recurse(node) | |
130 | elif not node: | |
131 | if not mandatory: | |
132 | continue | |
133 | raise Errors.WafError('No wscript file in directory %s'%d) | |
134 | def exec_command(self,cmd,**kw): | |
135 | subprocess=Utils.subprocess | |
136 | kw['shell']=isinstance(cmd,str) | |
137 | Logs.debug('runner: %r'%cmd) | |
138 | Logs.debug('runner_env: kw=%s'%kw) | |
139 | try: | |
140 | if self.logger: | |
141 | self.logger.info(cmd) | |
142 | kw['stdout']=kw['stderr']=subprocess.PIPE | |
143 | p=subprocess.Popen(cmd,**kw) | |
144 | (out,err)=p.communicate() | |
145 | if out: | |
146 | self.logger.debug('out: %s'%out.decode(sys.stdout.encoding or'iso8859-1')) | |
147 | if err: | |
148 | self.logger.error('err: %s'%err.decode(sys.stdout.encoding or'iso8859-1')) | |
149 | return p.returncode | |
150 | else: | |
151 | p=subprocess.Popen(cmd,**kw) | |
152 | return p.wait() | |
153 | except OSError: | |
154 | return-1 | |
155 | def cmd_and_log(self,cmd,**kw): | |
156 | subprocess=Utils.subprocess | |
157 | kw['shell']=isinstance(cmd,str) | |
158 | Logs.debug('runner: %r'%cmd) | |
159 | if'quiet'in kw: | |
160 | quiet=kw['quiet'] | |
161 | del kw['quiet'] | |
162 | else: | |
163 | quiet=None | |
164 | if'output'in kw: | |
165 | to_ret=kw['output'] | |
166 | del kw['output'] | |
167 | else: | |
168 | to_ret=STDOUT | |
169 | kw['stdout']=kw['stderr']=subprocess.PIPE | |
170 | if quiet is None: | |
171 | self.to_log(cmd) | |
172 | try: | |
173 | p=subprocess.Popen(cmd,**kw) | |
174 | (out,err)=p.communicate() | |
175 | except Exception ,e: | |
176 | raise Errors.WafError('Execution failure: %s'%str(e),ex=e) | |
177 | if not isinstance(out,str): | |
178 | out=out.decode(sys.stdout.encoding or'iso8859-1') | |
179 | if not isinstance(err,str): | |
180 | err=err.decode(sys.stdout.encoding or'iso8859-1') | |
181 | if out and quiet!=STDOUT and quiet!=BOTH: | |
182 | self.to_log('out: %s'%out) | |
183 | if err and quiet!=STDERR and quiet!=BOTH: | |
184 | self.to_log('err: %s'%err) | |
185 | if p.returncode: | |
186 | e=Errors.WafError('Command %r returned %r'%(cmd,p.returncode)) | |
187 | e.returncode=p.returncode | |
188 | e.stderr=err | |
189 | e.stdout=out | |
190 | raise e | |
191 | if to_ret==BOTH: | |
192 | return(out,err) | |
193 | elif to_ret==STDERR: | |
194 | return err | |
195 | return out | |
196 | def fatal(self,msg,ex=None): | |
197 | if self.logger: | |
198 | self.logger.info('from %s: %s'%(self.path.abspath(),msg)) | |
199 | try: | |
200 | msg='%s\n(complete log in %s)'%(msg,self.logger.handlers[0].baseFilename) | |
201 | except: | |
202 | pass | |
203 | raise self.errors.ConfigurationError(msg,ex=ex) | |
204 | def to_log(self,msg): | |
205 | if not msg: | |
206 | return | |
207 | if self.logger: | |
208 | self.logger.info(msg) | |
209 | else: | |
210 | sys.stderr.write(str(msg)) | |
211 | sys.stderr.flush() | |
212 | def msg(self,msg,result,color=None): | |
213 | self.start_msg(msg) | |
214 | if not isinstance(color,str): | |
215 | color=result and'GREEN'or'YELLOW' | |
216 | self.end_msg(result,color) | |
217 | def start_msg(self,msg): | |
218 | try: | |
219 | if self.in_msg: | |
220 | self.in_msg+=1 | |
221 | return | |
222 | except: | |
223 | self.in_msg=0 | |
224 | self.in_msg+=1 | |
225 | try: | |
226 | self.line_just=max(self.line_just,len(msg)) | |
227 | except AttributeError: | |
228 | self.line_just=max(40,len(msg)) | |
229 | for x in(self.line_just*'-',msg): | |
230 | self.to_log(x) | |
231 | Logs.pprint('NORMAL',"%s :"%msg.ljust(self.line_just),sep='') | |
232 | def end_msg(self,result,color=None): | |
233 | self.in_msg-=1 | |
234 | if self.in_msg: | |
235 | return | |
236 | defcolor='GREEN' | |
237 | if result==True: | |
238 | msg='ok' | |
239 | elif result==False: | |
240 | msg='not found' | |
241 | defcolor='YELLOW' | |
242 | else: | |
243 | msg=str(result) | |
244 | self.to_log(msg) | |
245 | Logs.pprint(color or defcolor,msg) | |
246 | def load_special_tools(self,var,ban=[]): | |
247 | global waf_dir | |
248 | lst=self.root.find_node(waf_dir).find_node('waflib/extras').ant_glob(var) | |
249 | for x in lst: | |
250 | if not x.name in ban: | |
251 | load_tool(x.name.replace('.py','')) | |
252 | cache_modules={} | |
253 | def load_module(path): | |
254 | try: | |
255 | return cache_modules[path] | |
256 | except KeyError: | |
257 | pass | |
258 | module=imp.new_module(WSCRIPT_FILE) | |
259 | try: | |
260 | code=Utils.readf(path,m='rU') | |
261 | except(IOError,OSError): | |
262 | raise Errors.WafError('Could not read the file %r'%path) | |
263 | module_dir=os.path.dirname(path) | |
264 | sys.path.insert(0,module_dir) | |
265 | exec(compile(code,path,'exec'),module.__dict__) | |
266 | sys.path.remove(module_dir) | |
267 | cache_modules[path]=module | |
268 | return module | |
269 | def load_tool(tool,tooldir=None): | |
270 | tool=tool.replace('++','xx') | |
271 | tool=tool.replace('java','javaw') | |
272 | tool=tool.replace('compiler_cc','compiler_c') | |
273 | if tooldir: | |
274 | assert isinstance(tooldir,list) | |
275 | sys.path=tooldir+sys.path | |
276 | try: | |
277 | __import__(tool) | |
278 | ret=sys.modules[tool] | |
279 | Context.tools[tool]=ret | |
280 | return ret | |
281 | finally: | |
282 | for d in tooldir: | |
283 | sys.path.remove(d) | |
284 | else: | |
285 | global waf_dir | |
286 | try: | |
287 | os.stat(os.path.join(waf_dir,'waflib','extras',tool+'.py')) | |
288 | d='waflib.extras.%s'%tool | |
289 | except: | |
290 | try: | |
291 | os.stat(os.path.join(waf_dir,'waflib','Tools',tool+'.py')) | |
292 | d='waflib.Tools.%s'%tool | |
293 | except: | |
294 | d=tool | |
295 | __import__(d) | |
296 | ret=sys.modules[d] | |
297 | Context.tools[tool]=ret | |
298 | return ret |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import traceback,sys | |
5 | class WafError(Exception): | |
6 | def __init__(self,msg='',ex=None): | |
7 | self.msg=msg | |
8 | assert not isinstance(msg,Exception) | |
9 | self.stack=[] | |
10 | if ex: | |
11 | if not msg: | |
12 | self.msg=str(ex) | |
13 | if isinstance(ex,WafError): | |
14 | self.stack=ex.stack | |
15 | else: | |
16 | self.stack=traceback.extract_tb(sys.exc_info()[2]) | |
17 | self.stack+=traceback.extract_stack()[:-1] | |
18 | self.verbose_msg=''.join(traceback.format_list(self.stack)) | |
19 | def __str__(self): | |
20 | return str(self.msg) | |
21 | class BuildError(WafError): | |
22 | def __init__(self,error_tasks=[]): | |
23 | self.tasks=error_tasks | |
24 | WafError.__init__(self,self.format_error()) | |
25 | def format_error(self): | |
26 | lst=['Build failed'] | |
27 | for tsk in self.tasks: | |
28 | txt=tsk.format_error() | |
29 | if txt:lst.append(txt) | |
30 | return'\n'.join(lst) | |
31 | class ConfigurationError(WafError): | |
32 | pass | |
33 | class TaskRescan(WafError): | |
34 | pass | |
35 | class TaskNotReady(WafError): | |
36 | pass |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,re,traceback,sys | |
5 | _nocolor=os.environ.get('NOCOLOR','no')not in('no','0','false') | |
6 | try: | |
7 | if not _nocolor: | |
8 | import waflib.ansiterm | |
9 | except: | |
10 | pass | |
11 | import logging | |
12 | LOG_FORMAT="%(asctime)s %(c1)s%(zone)s%(c2)s %(message)s" | |
13 | HOUR_FORMAT="%H:%M:%S" | |
14 | zones='' | |
15 | verbose=0 | |
16 | colors_lst={'USE':True,'BOLD':'\x1b[01;1m','RED':'\x1b[01;31m','GREEN':'\x1b[32m','YELLOW':'\x1b[33m','PINK':'\x1b[35m','BLUE':'\x1b[01;34m','CYAN':'\x1b[36m','NORMAL':'\x1b[0m','cursor_on':'\x1b[?25h','cursor_off':'\x1b[?25l',} | |
17 | got_tty=not os.environ.get('TERM','dumb')in['dumb','emacs'] | |
18 | if got_tty: | |
19 | try: | |
20 | got_tty=sys.stderr.isatty() | |
21 | except AttributeError: | |
22 | got_tty=False | |
23 | if(not got_tty and os.environ.get('TERM','dumb')!='msys')or _nocolor: | |
24 | colors_lst['USE']=False | |
25 | def get_term_cols(): | |
26 | return 80 | |
27 | try: | |
28 | import struct,fcntl,termios | |
29 | except ImportError: | |
30 | pass | |
31 | else: | |
32 | if got_tty: | |
33 | def get_term_cols_real(): | |
34 | dummy_lines,cols=struct.unpack("HHHH",fcntl.ioctl(sys.stderr.fileno(),termios.TIOCGWINSZ,struct.pack("HHHH",0,0,0,0)))[:2] | |
35 | return cols | |
36 | try: | |
37 | get_term_cols_real() | |
38 | except: | |
39 | pass | |
40 | else: | |
41 | get_term_cols=get_term_cols_real | |
42 | get_term_cols.__doc__=""" | |
43 | Get the console width in characters. | |
44 | ||
45 | :return: the number of characters per line | |
46 | :rtype: int | |
47 | """ | |
48 | def get_color(cl): | |
49 | if not colors_lst['USE']:return'' | |
50 | return colors_lst.get(cl,'') | |
51 | class color_dict(object): | |
52 | def __getattr__(self,a): | |
53 | return get_color(a) | |
54 | def __call__(self,a): | |
55 | return get_color(a) | |
56 | colors=color_dict() | |
57 | re_log=re.compile(r'(\w+): (.*)',re.M) | |
58 | class log_filter(logging.Filter): | |
59 | def __init__(self,name=None): | |
60 | pass | |
61 | def filter(self,rec): | |
62 | rec.c1=colors.PINK | |
63 | rec.c2=colors.NORMAL | |
64 | rec.zone=rec.module | |
65 | if rec.levelno>=logging.INFO: | |
66 | if rec.levelno>=logging.ERROR: | |
67 | rec.c1=colors.RED | |
68 | elif rec.levelno>=logging.WARNING: | |
69 | rec.c1=colors.YELLOW | |
70 | else: | |
71 | rec.c1=colors.GREEN | |
72 | return True | |
73 | m=re_log.match(rec.msg) | |
74 | if m: | |
75 | rec.zone=m.group(1) | |
76 | rec.msg=m.group(2) | |
77 | if zones: | |
78 | return getattr(rec,'zone','')in zones or'*'in zones | |
79 | elif not verbose>2: | |
80 | return False | |
81 | return True | |
82 | class formatter(logging.Formatter): | |
83 | def __init__(self): | |
84 | logging.Formatter.__init__(self,LOG_FORMAT,HOUR_FORMAT) | |
85 | def format(self,rec): | |
86 | if rec.levelno>=logging.WARNING or rec.levelno==logging.INFO: | |
87 | try: | |
88 | msg=rec.msg.decode('utf-8') | |
89 | except: | |
90 | msg=rec.msg | |
91 | return'%s%s%s'%(rec.c1,msg,rec.c2) | |
92 | return logging.Formatter.format(self,rec) | |
93 | log=None | |
94 | def debug(*k,**kw): | |
95 | if verbose: | |
96 | k=list(k) | |
97 | k[0]=k[0].replace('\n',' ') | |
98 | global log | |
99 | log.debug(*k,**kw) | |
100 | def error(*k,**kw): | |
101 | global log | |
102 | log.error(*k,**kw) | |
103 | if verbose>2: | |
104 | st=traceback.extract_stack() | |
105 | if st: | |
106 | st=st[:-1] | |
107 | buf=[] | |
108 | for filename,lineno,name,line in st: | |
109 | buf.append(' File "%s", line %d, in %s'%(filename,lineno,name)) | |
110 | if line: | |
111 | buf.append(' %s'%line.strip()) | |
112 | if buf:log.error("\n".join(buf)) | |
113 | def warn(*k,**kw): | |
114 | global log | |
115 | log.warn(*k,**kw) | |
116 | def info(*k,**kw): | |
117 | global log | |
118 | log.info(*k,**kw) | |
119 | def init_log(): | |
120 | global log | |
121 | log=logging.getLogger('waflib') | |
122 | log.handlers=[] | |
123 | log.filters=[] | |
124 | hdlr=logging.StreamHandler() | |
125 | hdlr.setFormatter(formatter()) | |
126 | log.addHandler(hdlr) | |
127 | log.addFilter(log_filter()) | |
128 | log.setLevel(logging.DEBUG) | |
129 | def make_logger(path,name): | |
130 | logger=logging.getLogger(name) | |
131 | hdlr=logging.FileHandler(path,'w') | |
132 | formatter=logging.Formatter('%(message)s') | |
133 | hdlr.setFormatter(formatter) | |
134 | logger.addHandler(hdlr) | |
135 | logger.setLevel(logging.DEBUG) | |
136 | return logger | |
137 | def make_mem_logger(name,to_log,size=10000): | |
138 | from logging.handlers import MemoryHandler | |
139 | logger=logging.getLogger(name) | |
140 | hdlr=MemoryHandler(size,target=to_log) | |
141 | formatter=logging.Formatter('%(message)s') | |
142 | hdlr.setFormatter(formatter) | |
143 | logger.addHandler(hdlr) | |
144 | logger.memhandler=hdlr | |
145 | logger.setLevel(logging.DEBUG) | |
146 | return logger | |
147 | def pprint(col,str,label='',sep='\n'): | |
148 | sys.stderr.write("%s%s%s %s%s"%(colors(col),str,colors.NORMAL,label,sep)) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import os,re,sys,shutil | |
7 | from waflib import Utils,Errors | |
8 | exclude_regs=''' | |
9 | **/*~ | |
10 | **/#*# | |
11 | **/.#* | |
12 | **/%*% | |
13 | **/._* | |
14 | **/CVS | |
15 | **/CVS/** | |
16 | **/.cvsignore | |
17 | **/SCCS | |
18 | **/SCCS/** | |
19 | **/vssver.scc | |
20 | **/.svn | |
21 | **/.svn/** | |
22 | **/BitKeeper | |
23 | **/.git | |
24 | **/.git/** | |
25 | **/.gitignore | |
26 | **/.bzr | |
27 | **/.bzrignore | |
28 | **/.bzr/** | |
29 | **/.hg | |
30 | **/.hg/** | |
31 | **/_MTN | |
32 | **/_MTN/** | |
33 | **/.arch-ids | |
34 | **/{arch} | |
35 | **/_darcs | |
36 | **/_darcs/** | |
37 | **/.DS_Store''' | |
38 | def split_path(path): | |
39 | return path.split('/') | |
40 | def split_path_cygwin(path): | |
41 | if path.startswith('//'): | |
42 | ret=path.split('/')[2:] | |
43 | ret[0]='/'+ret[0] | |
44 | return ret | |
45 | return path.split('/') | |
46 | re_sp=re.compile('[/\\\\]') | |
47 | def split_path_win32(path): | |
48 | if path.startswith('\\\\'): | |
49 | ret=re.split(re_sp,path)[2:] | |
50 | ret[0]='\\'+ret[0] | |
51 | return ret | |
52 | return re.split(re_sp,path) | |
53 | if sys.platform=='cygwin': | |
54 | split_path=split_path_cygwin | |
55 | elif Utils.is_win32: | |
56 | split_path=split_path_win32 | |
57 | class Node(object): | |
58 | __slots__=('name','sig','children','parent','cache_abspath','cache_isdir') | |
59 | def __init__(self,name,parent): | |
60 | self.name=name | |
61 | self.parent=parent | |
62 | if parent: | |
63 | if name in parent.children: | |
64 | raise Errors.WafError('node %s exists in the parent files %r already'%(name,parent)) | |
65 | parent.children[name]=self | |
66 | def __setstate__(self,data): | |
67 | self.name=data[0] | |
68 | self.parent=data[1] | |
69 | if data[2]is not None: | |
70 | self.children=data[2] | |
71 | if data[3]is not None: | |
72 | self.sig=data[3] | |
73 | def __getstate__(self): | |
74 | return(self.name,self.parent,getattr(self,'children',None),getattr(self,'sig',None)) | |
75 | def __str__(self): | |
76 | return self.name | |
77 | def __repr__(self): | |
78 | return self.abspath() | |
79 | def __hash__(self): | |
80 | return id(self) | |
81 | def __eq__(self,node): | |
82 | return id(self)==id(node) | |
83 | def __copy__(self): | |
84 | raise Errors.WafError('nodes are not supposed to be copied') | |
85 | def read(self,flags='r'): | |
86 | return Utils.readf(self.abspath(),flags) | |
87 | def write(self,data,flags='w'): | |
88 | f=None | |
89 | try: | |
90 | f=open(self.abspath(),flags) | |
91 | f.write(data) | |
92 | finally: | |
93 | if f: | |
94 | f.close() | |
95 | def chmod(self,val): | |
96 | os.chmod(self.abspath(),val) | |
97 | def delete(self): | |
98 | try: | |
99 | if getattr(self,'children',None): | |
100 | shutil.rmtree(self.abspath()) | |
101 | else: | |
102 | os.unlink(self.abspath()) | |
103 | except: | |
104 | pass | |
105 | try: | |
106 | delattr(self,'children') | |
107 | except: | |
108 | pass | |
109 | def suffix(self): | |
110 | k=max(0,self.name.rfind('.')) | |
111 | return self.name[k:] | |
112 | def height(self): | |
113 | d=self | |
114 | val=-1 | |
115 | while d: | |
116 | d=d.parent | |
117 | val+=1 | |
118 | return val | |
119 | def listdir(self): | |
120 | lst=Utils.listdir(self.abspath()) | |
121 | lst.sort() | |
122 | return lst | |
123 | def mkdir(self): | |
124 | if getattr(self,'cache_isdir',None): | |
125 | return | |
126 | try: | |
127 | self.parent.mkdir() | |
128 | except: | |
129 | pass | |
130 | if self.name: | |
131 | try: | |
132 | os.makedirs(self.abspath()) | |
133 | except OSError: | |
134 | pass | |
135 | if not os.path.isdir(self.abspath()): | |
136 | raise Errors.WafError('Could not create the directory %s'%self.abspath()) | |
137 | try: | |
138 | self.children | |
139 | except: | |
140 | self.children={} | |
141 | self.cache_isdir=True | |
142 | def find_node(self,lst): | |
143 | if isinstance(lst,str): | |
144 | lst=[x for x in split_path(lst)if x and x!='.'] | |
145 | cur=self | |
146 | for x in lst: | |
147 | if x=='..': | |
148 | cur=cur.parent or cur | |
149 | continue | |
150 | try: | |
151 | if x in cur.children: | |
152 | cur=cur.children[x] | |
153 | continue | |
154 | except: | |
155 | cur.children={} | |
156 | cur=self.__class__(x,cur) | |
157 | try: | |
158 | os.stat(cur.abspath()) | |
159 | except: | |
160 | del cur.parent.children[x] | |
161 | return None | |
162 | ret=cur | |
163 | try: | |
164 | os.stat(ret.abspath()) | |
165 | except: | |
166 | del ret.parent.children[ret.name] | |
167 | return None | |
168 | try: | |
169 | while not getattr(cur.parent,'cache_isdir',None): | |
170 | cur=cur.parent | |
171 | cur.cache_isdir=True | |
172 | except AttributeError: | |
173 | pass | |
174 | return ret | |
175 | def make_node(self,lst): | |
176 | if isinstance(lst,str): | |
177 | lst=[x for x in split_path(lst)if x and x!='.'] | |
178 | cur=self | |
179 | for x in lst: | |
180 | if x=='..': | |
181 | cur=cur.parent or cur | |
182 | continue | |
183 | if getattr(cur,'children',{}): | |
184 | if x in cur.children: | |
185 | cur=cur.children[x] | |
186 | continue | |
187 | else: | |
188 | cur.children={} | |
189 | cur=self.__class__(x,cur) | |
190 | return cur | |
191 | def search(self,lst): | |
192 | if isinstance(lst,str): | |
193 | lst=[x for x in split_path(lst)if x and x!='.'] | |
194 | cur=self | |
195 | try: | |
196 | for x in lst: | |
197 | if x=='..': | |
198 | cur=cur.parent or cur | |
199 | else: | |
200 | cur=cur.children[x] | |
201 | return cur | |
202 | except: | |
203 | pass | |
204 | def path_from(self,node): | |
205 | c1=self | |
206 | c2=node | |
207 | c1h=c1.height() | |
208 | c2h=c2.height() | |
209 | lst=[] | |
210 | up=0 | |
211 | while c1h>c2h: | |
212 | lst.append(c1.name) | |
213 | c1=c1.parent | |
214 | c1h-=1 | |
215 | while c2h>c1h: | |
216 | up+=1 | |
217 | c2=c2.parent | |
218 | c2h-=1 | |
219 | while id(c1)!=id(c2): | |
220 | lst.append(c1.name) | |
221 | up+=1 | |
222 | c1=c1.parent | |
223 | c2=c2.parent | |
224 | for i in range(up): | |
225 | lst.append('..') | |
226 | lst.reverse() | |
227 | return os.sep.join(lst)or'.' | |
228 | def abspath(self): | |
229 | try: | |
230 | return self.cache_abspath | |
231 | except: | |
232 | pass | |
233 | if os.sep=='/': | |
234 | if not self.parent: | |
235 | val=os.sep | |
236 | elif not self.parent.name: | |
237 | val=os.sep+self.name | |
238 | else: | |
239 | val=self.parent.abspath()+os.sep+self.name | |
240 | else: | |
241 | if not self.parent: | |
242 | val='' | |
243 | elif not self.parent.name: | |
244 | val=self.name+os.sep | |
245 | else: | |
246 | val=self.parent.abspath().rstrip(os.sep)+os.sep+self.name | |
247 | self.cache_abspath=val | |
248 | return val | |
249 | def is_child_of(self,node): | |
250 | p=self | |
251 | diff=self.height()-node.height() | |
252 | while diff>0: | |
253 | diff-=1 | |
254 | p=p.parent | |
255 | return id(p)==id(node) | |
256 | def ant_iter(self,accept=None,maxdepth=25,pats=[],dir=False,src=True,remove=True): | |
257 | dircont=self.listdir() | |
258 | dircont.sort() | |
259 | try: | |
260 | lst=set(self.children.keys()) | |
261 | if remove: | |
262 | for x in lst-set(dircont): | |
263 | del self.children[x] | |
264 | except: | |
265 | self.children={} | |
266 | for name in dircont: | |
267 | npats=accept(name,pats) | |
268 | if npats and npats[0]: | |
269 | accepted=[]in npats[0] | |
270 | node=self.make_node([name]) | |
271 | isdir=os.path.isdir(node.abspath()) | |
272 | if accepted: | |
273 | if isdir: | |
274 | if dir: | |
275 | yield node | |
276 | else: | |
277 | if src: | |
278 | yield node | |
279 | if getattr(node,'cache_isdir',None)or isdir: | |
280 | node.cache_isdir=True | |
281 | if maxdepth: | |
282 | for k in node.ant_iter(accept=accept,maxdepth=maxdepth-1,pats=npats,dir=dir,src=src,remove=remove): | |
283 | yield k | |
284 | raise StopIteration | |
285 | def ant_glob(self,*k,**kw): | |
286 | src=kw.get('src',True) | |
287 | dir=kw.get('dir',False) | |
288 | excl=kw.get('excl',exclude_regs) | |
289 | incl=k and k[0]or kw.get('incl','**') | |
290 | def to_pat(s): | |
291 | lst=Utils.to_list(s) | |
292 | ret=[] | |
293 | for x in lst: | |
294 | x=x.replace('\\','/').replace('//','/') | |
295 | if x.endswith('/'): | |
296 | x+='**' | |
297 | lst2=x.split('/') | |
298 | accu=[] | |
299 | for k in lst2: | |
300 | if k=='**': | |
301 | accu.append(k) | |
302 | else: | |
303 | k=k.replace('.','[.]').replace('*','.*').replace('?','.').replace('+','\\+') | |
304 | k='^%s$'%k | |
305 | try: | |
306 | accu.append(re.compile(k)) | |
307 | except Exception ,e: | |
308 | raise Errors.WafError("Invalid pattern: %s"%k,e) | |
309 | ret.append(accu) | |
310 | return ret | |
311 | def filtre(name,nn): | |
312 | ret=[] | |
313 | for lst in nn: | |
314 | if not lst: | |
315 | pass | |
316 | elif lst[0]=='**': | |
317 | ret.append(lst) | |
318 | if len(lst)>1: | |
319 | if lst[1].match(name): | |
320 | ret.append(lst[2:]) | |
321 | else: | |
322 | ret.append([]) | |
323 | elif lst[0].match(name): | |
324 | ret.append(lst[1:]) | |
325 | return ret | |
326 | def accept(name,pats): | |
327 | nacc=filtre(name,pats[0]) | |
328 | nrej=filtre(name,pats[1]) | |
329 | if[]in nrej: | |
330 | nacc=[] | |
331 | return[nacc,nrej] | |
332 | ret=[x for x in self.ant_iter(accept=accept,pats=[to_pat(incl),to_pat(excl)],maxdepth=25,dir=dir,src=src,remove=kw.get('remove',True))] | |
333 | if kw.get('flat',False): | |
334 | return' '.join([x.path_from(self)for x in ret]) | |
335 | return ret | |
336 | def find_nodes(self,find_dirs=True,find_files=True,match_fun=lambda x:True): | |
337 | x=""" | |
338 | Recursively finds nodes:: | |
339 | ||
340 | def configure(cnf): | |
341 | cnf.find_nodes() | |
342 | ||
343 | :param find_dirs: whether to return directories | |
344 | :param find_files: whether to return files | |
345 | :param match_fun: matching function, taking a node as parameter | |
346 | :rtype generator | |
347 | :return: a generator that iterates over all the requested files | |
348 | """ | |
349 | files=self.listdir() | |
350 | for f in files: | |
351 | node=self.make_node([f]) | |
352 | if os.path.isdir(node.abspath()): | |
353 | if find_dirs and match_fun(node): | |
354 | yield node | |
355 | gen=node.find_nodes(find_dirs,find_files,match_fun) | |
356 | for g in gen: | |
357 | yield g | |
358 | else: | |
359 | if find_files and match_fun(node): | |
360 | yield node | |
361 | def is_src(self): | |
362 | cur=self | |
363 | x=id(self.ctx.srcnode) | |
364 | y=id(self.ctx.bldnode) | |
365 | while cur.parent: | |
366 | if id(cur)==y: | |
367 | return False | |
368 | if id(cur)==x: | |
369 | return True | |
370 | cur=cur.parent | |
371 | return False | |
372 | def is_bld(self): | |
373 | cur=self | |
374 | y=id(self.ctx.bldnode) | |
375 | while cur.parent: | |
376 | if id(cur)==y: | |
377 | return True | |
378 | cur=cur.parent | |
379 | return False | |
380 | def get_src(self): | |
381 | cur=self | |
382 | x=id(self.ctx.srcnode) | |
383 | y=id(self.ctx.bldnode) | |
384 | lst=[] | |
385 | while cur.parent: | |
386 | if id(cur)==y: | |
387 | lst.reverse() | |
388 | return self.ctx.srcnode.make_node(lst) | |
389 | if id(cur)==x: | |
390 | return self | |
391 | lst.append(cur.name) | |
392 | cur=cur.parent | |
393 | return self | |
394 | def get_bld(self): | |
395 | cur=self | |
396 | x=id(self.ctx.srcnode) | |
397 | y=id(self.ctx.bldnode) | |
398 | lst=[] | |
399 | while cur.parent: | |
400 | if id(cur)==y: | |
401 | return self | |
402 | if id(cur)==x: | |
403 | lst.reverse() | |
404 | return self.ctx.bldnode.make_node(lst) | |
405 | lst.append(cur.name) | |
406 | cur=cur.parent | |
407 | lst.reverse() | |
408 | if lst and Utils.is_win32 and len(lst[0])==2 and lst[0].endswith(':'): | |
409 | lst[0]=lst[0][0] | |
410 | return self.ctx.bldnode.make_node(['__root__']+lst) | |
411 | def find_resource(self,lst): | |
412 | if isinstance(lst,str): | |
413 | lst=[x for x in split_path(lst)if x and x!='.'] | |
414 | node=self.get_bld().search(lst) | |
415 | if not node: | |
416 | self=self.get_src() | |
417 | node=self.find_node(lst) | |
418 | try: | |
419 | pat=node.abspath() | |
420 | if os.path.isdir(pat): | |
421 | return None | |
422 | except: | |
423 | pass | |
424 | return node | |
425 | def find_or_declare(self,lst): | |
426 | if isinstance(lst,str): | |
427 | lst=[x for x in split_path(lst)if x and x!='.'] | |
428 | node=self.get_bld().search(lst) | |
429 | if node: | |
430 | if not os.path.isfile(node.abspath()): | |
431 | node.sig=None | |
432 | try: | |
433 | node.parent.mkdir() | |
434 | except: | |
435 | pass | |
436 | return node | |
437 | self=self.get_src() | |
438 | node=self.find_node(lst) | |
439 | if node: | |
440 | if not os.path.isfile(node.abspath()): | |
441 | node.sig=None | |
442 | try: | |
443 | node.parent.mkdir() | |
444 | except: | |
445 | pass | |
446 | return node | |
447 | node=self.get_bld().make_node(lst) | |
448 | node.parent.mkdir() | |
449 | return node | |
450 | def find_dir(self,lst): | |
451 | if isinstance(lst,str): | |
452 | lst=[x for x in split_path(lst)if x and x!='.'] | |
453 | node=self.find_node(lst) | |
454 | try: | |
455 | if not os.path.isdir(node.abspath()): | |
456 | return None | |
457 | except(OSError,AttributeError): | |
458 | return None | |
459 | return node | |
460 | def change_ext(self,ext,ext_in=None): | |
461 | name=self.name | |
462 | if ext_in is None: | |
463 | k=name.rfind('.') | |
464 | if k>=0: | |
465 | name=name[:k]+ext | |
466 | else: | |
467 | name=name+ext | |
468 | else: | |
469 | name=name[:-len(ext_in)]+ext | |
470 | return self.parent.find_or_declare([name]) | |
471 | def nice_path(self,env=None): | |
472 | return self.path_from(self.ctx.launch_node()) | |
473 | def bldpath(self): | |
474 | return self.path_from(self.ctx.bldnode) | |
475 | def srcpath(self): | |
476 | return self.path_from(self.ctx.srcnode) | |
477 | def relpath(self): | |
478 | cur=self | |
479 | x=id(self.ctx.bldnode) | |
480 | while cur.parent: | |
481 | if id(cur)==x: | |
482 | return self.bldpath() | |
483 | cur=cur.parent | |
484 | return self.srcpath() | |
485 | def bld_dir(self): | |
486 | return self.parent.bldpath() | |
487 | def bld_base(self): | |
488 | s=os.path.splitext(self.name)[0] | |
489 | return self.bld_dir()+os.sep+s | |
490 | def get_bld_sig(self): | |
491 | try: | |
492 | ret=self.ctx.hash_cache[id(self)] | |
493 | except KeyError: | |
494 | pass | |
495 | except AttributeError: | |
496 | self.ctx.hash_cache={} | |
497 | else: | |
498 | return ret | |
499 | if not self.is_bld()or self.ctx.bldnode is self.ctx.srcnode: | |
500 | self.sig=Utils.h_file(self.abspath()) | |
501 | self.ctx.hash_cache[id(self)]=ret=self.sig | |
502 | return ret | |
503 | pickle_lock=Utils.threading.Lock() | |
504 | class Nod3(Node): | |
505 | pass |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,tempfile,optparse,sys,re | |
5 | from waflib import Logs,Utils,Context | |
6 | cmds='distclean configure build install clean uninstall check dist distcheck'.split() | |
7 | options={} | |
8 | commands=[] | |
9 | lockfile=os.environ.get('WAFLOCK','.lock-waf_%s_build'%sys.platform) | |
10 | try:cache_global=os.path.abspath(os.environ['WAFCACHE']) | |
11 | except KeyError:cache_global='' | |
12 | platform=Utils.unversioned_sys_platform() | |
13 | class opt_parser(optparse.OptionParser): | |
14 | def __init__(self,ctx): | |
15 | optparse.OptionParser.__init__(self,conflict_handler="resolve",version='waf %s (%s)'%(Context.WAFVERSION,Context.WAFREVISION)) | |
16 | self.formatter.width=Logs.get_term_cols() | |
17 | p=self.add_option | |
18 | self.ctx=ctx | |
19 | jobs=ctx.jobs() | |
20 | p('-j','--jobs',dest='jobs',default=jobs,type='int',help='amount of parallel jobs (%r)'%jobs) | |
21 | p('-k','--keep',dest='keep',default=0,action='count',help='keep running happily even if errors are found') | |
22 | p('-v','--verbose',dest='verbose',default=0,action='count',help='verbosity level -v -vv or -vvv [default: 0]') | |
23 | p('--nocache',dest='nocache',default=False,action='store_true',help='ignore the WAFCACHE (if set)') | |
24 | p('--zones',dest='zones',default='',action='store',help='debugging zones (task_gen, deps, tasks, etc)') | |
25 | gr=optparse.OptionGroup(self,'configure options') | |
26 | self.add_option_group(gr) | |
27 | gr.add_option('-o','--out',action='store',default='',help='build dir for the project',dest='out') | |
28 | gr.add_option('-t','--top',action='store',default='',help='src dir for the project',dest='top') | |
29 | default_prefix=os.environ.get('PREFIX') | |
30 | if not default_prefix: | |
31 | if platform=='win32': | |
32 | d=tempfile.gettempdir() | |
33 | default_prefix=d[0].upper()+d[1:] | |
34 | else: | |
35 | default_prefix='/usr/local/' | |
36 | gr.add_option('--prefix',dest='prefix',default=default_prefix,help='installation prefix [default: %r]'%default_prefix) | |
37 | gr.add_option('--download',dest='download',default=False,action='store_true',help='try to download the tools if missing') | |
38 | gr=optparse.OptionGroup(self,'build and install options') | |
39 | self.add_option_group(gr) | |
40 | gr.add_option('-p','--progress',dest='progress_bar',default=0,action='count',help='-p: progress bar; -pp: ide output') | |
41 | gr.add_option('--targets',dest='targets',default='',action='store',help='task generators, e.g. "target1,target2"') | |
42 | gr=optparse.OptionGroup(self,'step options') | |
43 | self.add_option_group(gr) | |
44 | gr.add_option('--files',dest='files',default='',action='store',help='files to process, by regexp, e.g. "*/main.c,*/test/main.o"') | |
45 | default_destdir=os.environ.get('DESTDIR','') | |
46 | gr=optparse.OptionGroup(self,'install/uninstall options') | |
47 | self.add_option_group(gr) | |
48 | gr.add_option('--destdir',help='installation root [default: %r]'%default_destdir,default=default_destdir,dest='destdir') | |
49 | gr.add_option('-f','--force',dest='force',default=False,action='store_true',help='force file installation') | |
50 | def get_usage(self): | |
51 | cmds_str={} | |
52 | for cls in Context.classes: | |
53 | if not cls.cmd or cls.cmd=='options': | |
54 | continue | |
55 | s=cls.__doc__ or'' | |
56 | cmds_str[cls.cmd]=s | |
57 | if Context.g_module: | |
58 | for(k,v)in Context.g_module.__dict__.items(): | |
59 | if k in['options','init','shutdown']: | |
60 | continue | |
61 | if type(v)is type(Context.create_context): | |
62 | if v.__doc__ and not k.startswith('_'): | |
63 | cmds_str[k]=v.__doc__ | |
64 | just=0 | |
65 | for k in cmds_str: | |
66 | just=max(just,len(k)) | |
67 | lst=[' %s: %s'%(k.ljust(just),v)for(k,v)in cmds_str.items()] | |
68 | lst.sort() | |
69 | ret='\n'.join(lst) | |
70 | return'''waf [commands] [options] | |
71 | ||
72 | Main commands (example: ./waf build -j4) | |
73 | %s | |
74 | '''%ret | |
75 | class OptionsContext(Context.Context): | |
76 | cmd='options' | |
77 | fun='options' | |
78 | def __init__(self,**kw): | |
79 | super(OptionsContext,self).__init__(**kw) | |
80 | self.parser=opt_parser(self) | |
81 | self.option_groups={} | |
82 | def jobs(self): | |
83 | count=int(os.environ.get('JOBS',0)) | |
84 | if count<1: | |
85 | if'NUMBER_OF_PROCESSORS'in os.environ: | |
86 | count=int(os.environ.get('NUMBER_OF_PROCESSORS',1)) | |
87 | else: | |
88 | if hasattr(os,'sysconf_names'): | |
89 | if'SC_NPROCESSORS_ONLN'in os.sysconf_names: | |
90 | count=int(os.sysconf('SC_NPROCESSORS_ONLN')) | |
91 | elif'SC_NPROCESSORS_CONF'in os.sysconf_names: | |
92 | count=int(os.sysconf('SC_NPROCESSORS_CONF')) | |
93 | if not count and os.name not in('nt','java'): | |
94 | try: | |
95 | tmp=self.cmd_and_log(['sysctl','-n','hw.ncpu'],quiet=0) | |
96 | except Exception: | |
97 | pass | |
98 | else: | |
99 | if re.match('^[0-9]+$',tmp): | |
100 | count=int(tmp) | |
101 | if count<1: | |
102 | count=1 | |
103 | elif count>1024: | |
104 | count=1024 | |
105 | return count | |
106 | def add_option(self,*k,**kw): | |
107 | self.parser.add_option(*k,**kw) | |
108 | def add_option_group(self,*k,**kw): | |
109 | try: | |
110 | gr=self.option_groups[k[0]] | |
111 | except: | |
112 | gr=self.parser.add_option_group(*k,**kw) | |
113 | self.option_groups[k[0]]=gr | |
114 | return gr | |
115 | def get_option_group(self,opt_str): | |
116 | try: | |
117 | return self.option_groups[opt_str] | |
118 | except KeyError: | |
119 | for group in self.parser.option_groups: | |
120 | if group.title==opt_str: | |
121 | return group | |
122 | return None | |
123 | def parse_args(self,_args=None): | |
124 | global options,commands | |
125 | (options,leftover_args)=self.parser.parse_args(args=_args) | |
126 | commands=leftover_args | |
127 | if options.destdir: | |
128 | options.destdir=os.path.abspath(os.path.expanduser(options.destdir)) | |
129 | if options.verbose>=1: | |
130 | self.load('errcheck') | |
131 | def execute(self): | |
132 | super(OptionsContext,self).execute() | |
133 | self.parse_args() |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import random,atexit | |
5 | try: | |
6 | from queue import Queue | |
7 | except: | |
8 | from Queue import Queue | |
9 | from waflib import Utils,Task,Errors,Logs | |
10 | GAP=10 | |
11 | class TaskConsumer(Utils.threading.Thread): | |
12 | def __init__(self): | |
13 | Utils.threading.Thread.__init__(self) | |
14 | self.ready=Queue() | |
15 | self.setDaemon(1) | |
16 | self.start() | |
17 | def run(self): | |
18 | try: | |
19 | self.loop() | |
20 | except: | |
21 | pass | |
22 | def loop(self): | |
23 | while 1: | |
24 | tsk=self.ready.get() | |
25 | if not isinstance(tsk,Task.TaskBase): | |
26 | tsk(self) | |
27 | else: | |
28 | tsk.process() | |
29 | pool=Queue() | |
30 | def get_pool(): | |
31 | try: | |
32 | return pool.get(False) | |
33 | except: | |
34 | return TaskConsumer() | |
35 | def put_pool(x): | |
36 | pool.put(x) | |
37 | def _free_resources(): | |
38 | global pool | |
39 | lst=[] | |
40 | while pool.qsize(): | |
41 | lst.append(pool.get()) | |
42 | for x in lst: | |
43 | x.ready.put(None) | |
44 | for x in lst: | |
45 | x.join() | |
46 | pool=None | |
47 | atexit.register(_free_resources) | |
48 | class Parallel(object): | |
49 | def __init__(self,bld,j=2): | |
50 | self.numjobs=j | |
51 | self.bld=bld | |
52 | self.outstanding=[] | |
53 | self.frozen=[] | |
54 | self.out=Queue(0) | |
55 | self.count=0 | |
56 | self.processed=1 | |
57 | self.stop=False | |
58 | self.error=[] | |
59 | self.biter=None | |
60 | self.dirty=False | |
61 | def get_next_task(self): | |
62 | if not self.outstanding: | |
63 | return None | |
64 | return self.outstanding.pop(0) | |
65 | def postpone(self,tsk): | |
66 | if random.randint(0,1): | |
67 | self.frozen.insert(0,tsk) | |
68 | else: | |
69 | self.frozen.append(tsk) | |
70 | def refill_task_list(self): | |
71 | while self.count>self.numjobs*GAP: | |
72 | self.get_out() | |
73 | while not self.outstanding: | |
74 | if self.count: | |
75 | self.get_out() | |
76 | elif self.frozen: | |
77 | try: | |
78 | cond=self.deadlock==self.processed | |
79 | except: | |
80 | pass | |
81 | else: | |
82 | if cond: | |
83 | msg='check the build order for the tasks' | |
84 | for tsk in self.frozen: | |
85 | if not tsk.run_after: | |
86 | msg='check the methods runnable_status' | |
87 | break | |
88 | lst=[] | |
89 | for tsk in self.frozen: | |
90 | lst.append('%s\t-> %r'%(repr(tsk),[id(x)for x in tsk.run_after])) | |
91 | raise Errors.WafError('Deadlock detected: %s%s'%(msg,''.join(lst))) | |
92 | self.deadlock=self.processed | |
93 | if self.frozen: | |
94 | self.outstanding+=self.frozen | |
95 | self.frozen=[] | |
96 | elif not self.count: | |
97 | self.outstanding.extend(self.biter.next()) | |
98 | self.total=self.bld.total() | |
99 | break | |
100 | def add_more_tasks(self,tsk): | |
101 | if getattr(tsk,'more_tasks',None): | |
102 | self.outstanding+=tsk.more_tasks | |
103 | self.total+=len(tsk.more_tasks) | |
104 | def get_out(self): | |
105 | tsk=self.out.get() | |
106 | if not self.stop: | |
107 | self.add_more_tasks(tsk) | |
108 | self.count-=1 | |
109 | self.dirty=True | |
110 | return tsk | |
111 | def error_handler(self,tsk): | |
112 | if not self.bld.keep: | |
113 | self.stop=True | |
114 | self.error.append(tsk) | |
115 | def add_task(self,tsk): | |
116 | try: | |
117 | self.pool | |
118 | except AttributeError: | |
119 | self.init_task_pool() | |
120 | self.ready.put(tsk) | |
121 | def init_task_pool(self): | |
122 | pool=self.pool=[get_pool()for i in range(self.numjobs)] | |
123 | self.ready=Queue(0) | |
124 | def setq(consumer): | |
125 | consumer.ready=self.ready | |
126 | for x in pool: | |
127 | x.ready.put(setq) | |
128 | return pool | |
129 | def free_task_pool(self): | |
130 | def setq(consumer): | |
131 | consumer.ready=Queue(0) | |
132 | self.out.put(self) | |
133 | try: | |
134 | pool=self.pool | |
135 | except: | |
136 | pass | |
137 | else: | |
138 | for x in pool: | |
139 | self.ready.put(setq) | |
140 | for x in pool: | |
141 | self.get_out() | |
142 | for x in pool: | |
143 | put_pool(x) | |
144 | self.pool=[] | |
145 | def start(self): | |
146 | self.total=self.bld.total() | |
147 | while not self.stop: | |
148 | self.refill_task_list() | |
149 | tsk=self.get_next_task() | |
150 | if not tsk: | |
151 | if self.count: | |
152 | continue | |
153 | else: | |
154 | break | |
155 | if tsk.hasrun: | |
156 | self.processed+=1 | |
157 | continue | |
158 | if self.stop: | |
159 | break | |
160 | try: | |
161 | st=tsk.runnable_status() | |
162 | except Exception: | |
163 | self.processed+=1 | |
164 | tsk.err_msg=Utils.ex_stack() | |
165 | if not self.stop and self.bld.keep: | |
166 | tsk.hasrun=Task.SKIPPED | |
167 | if self.bld.keep==1: | |
168 | if Logs.verbose>1 or not self.error: | |
169 | self.error.append(tsk) | |
170 | self.stop=True | |
171 | else: | |
172 | if Logs.verbose>1: | |
173 | self.error.append(tsk) | |
174 | continue | |
175 | tsk.hasrun=Task.EXCEPTION | |
176 | self.error_handler(tsk) | |
177 | continue | |
178 | if st==Task.ASK_LATER: | |
179 | self.postpone(tsk) | |
180 | elif st==Task.SKIP_ME: | |
181 | self.processed+=1 | |
182 | tsk.hasrun=Task.SKIPPED | |
183 | self.add_more_tasks(tsk) | |
184 | else: | |
185 | tsk.position=(self.processed,self.total) | |
186 | self.count+=1 | |
187 | tsk.master=self | |
188 | self.processed+=1 | |
189 | if self.numjobs==1: | |
190 | tsk.process() | |
191 | else: | |
192 | self.add_task(tsk) | |
193 | while self.error and self.count: | |
194 | self.get_out() | |
195 | assert(self.count==0 or self.stop) | |
196 | self.free_task_pool() |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,shutil,traceback,errno,sys,stat | |
5 | from waflib import Utils,Configure,Logs,Options,ConfigSet,Context,Errors,Build,Node | |
6 | build_dir_override=None | |
7 | no_climb_commands=['configure'] | |
8 | default_cmd="build" | |
9 | def waf_entry_point(current_directory,version,wafdir): | |
10 | Logs.init_log() | |
11 | if Context.WAFVERSION!=version: | |
12 | Logs.error('Waf script %r and library %r do not match (directory %r)'%(version,Context.WAFVERSION,wafdir)) | |
13 | sys.exit(1) | |
14 | if'--version'in sys.argv: | |
15 | Context.run_dir=current_directory | |
16 | ctx=Context.create_context('options') | |
17 | ctx.curdir=current_directory | |
18 | ctx.parse_args() | |
19 | sys.exit(0) | |
20 | Context.waf_dir=wafdir | |
21 | Context.launch_dir=current_directory | |
22 | no_climb=os.environ.get('NOCLIMB',None) | |
23 | if not no_climb: | |
24 | for k in no_climb_commands: | |
25 | if k in sys.argv: | |
26 | no_climb=True | |
27 | break | |
28 | cur=current_directory | |
29 | while cur: | |
30 | lst=os.listdir(cur) | |
31 | if Options.lockfile in lst: | |
32 | env=ConfigSet.ConfigSet() | |
33 | try: | |
34 | env.load(os.path.join(cur,Options.lockfile)) | |
35 | ino=os.stat(cur)[stat.ST_INO] | |
36 | except Exception: | |
37 | pass | |
38 | else: | |
39 | for x in[env.run_dir,env.top_dir,env.out_dir]: | |
40 | if Utils.is_win32: | |
41 | if cur==x: | |
42 | load=True | |
43 | break | |
44 | else: | |
45 | try: | |
46 | ino2=os.stat(x)[stat.ST_INO] | |
47 | except: | |
48 | pass | |
49 | else: | |
50 | if ino==ino2: | |
51 | load=True | |
52 | break | |
53 | else: | |
54 | Logs.warn('invalid lock file in %s'%cur) | |
55 | load=False | |
56 | if load: | |
57 | Context.run_dir=env.run_dir | |
58 | Context.top_dir=env.top_dir | |
59 | Context.out_dir=env.out_dir | |
60 | break | |
61 | if not Context.run_dir: | |
62 | if Context.WSCRIPT_FILE in lst: | |
63 | Context.run_dir=cur | |
64 | next=os.path.dirname(cur) | |
65 | if next==cur: | |
66 | break | |
67 | cur=next | |
68 | if no_climb: | |
69 | break | |
70 | if not Context.run_dir: | |
71 | if'-h'in sys.argv or'--help'in sys.argv: | |
72 | Logs.warn('No wscript file found: the help message may be incomplete') | |
73 | Context.run_dir=current_directory | |
74 | ctx=Context.create_context('options') | |
75 | ctx.curdir=current_directory | |
76 | ctx.parse_args() | |
77 | sys.exit(0) | |
78 | Logs.error('Waf: Run from a directory containing a file named %r'%Context.WSCRIPT_FILE) | |
79 | sys.exit(1) | |
80 | try: | |
81 | os.chdir(Context.run_dir) | |
82 | except OSError: | |
83 | Logs.error('Waf: The folder %r is unreadable'%Context.run_dir) | |
84 | sys.exit(1) | |
85 | try: | |
86 | set_main_module(Context.run_dir+os.sep+Context.WSCRIPT_FILE) | |
87 | except Errors.WafError ,e: | |
88 | Logs.pprint('RED',e.verbose_msg) | |
89 | Logs.error(str(e)) | |
90 | sys.exit(1) | |
91 | except Exception ,e: | |
92 | Logs.error('Waf: The wscript in %r is unreadable'%Context.run_dir,e) | |
93 | traceback.print_exc(file=sys.stdout) | |
94 | sys.exit(2) | |
95 | try: | |
96 | run_commands() | |
97 | except Errors.WafError ,e: | |
98 | if Logs.verbose>1: | |
99 | Logs.pprint('RED',e.verbose_msg) | |
100 | Logs.error(e.msg) | |
101 | sys.exit(1) | |
102 | except Exception ,e: | |
103 | traceback.print_exc(file=sys.stdout) | |
104 | sys.exit(2) | |
105 | except KeyboardInterrupt: | |
106 | Logs.pprint('RED','Interrupted') | |
107 | sys.exit(68) | |
108 | def set_main_module(file_path): | |
109 | Context.g_module=Context.load_module(file_path) | |
110 | Context.g_module.root_path=file_path | |
111 | def set_def(obj): | |
112 | name=obj.__name__ | |
113 | if not name in Context.g_module.__dict__: | |
114 | setattr(Context.g_module,name,obj) | |
115 | for k in[update,dist,distclean,distcheck,update]: | |
116 | set_def(k) | |
117 | if not'init'in Context.g_module.__dict__: | |
118 | Context.g_module.init=Utils.nada | |
119 | if not'shutdown'in Context.g_module.__dict__: | |
120 | Context.g_module.shutdown=Utils.nada | |
121 | if not'options'in Context.g_module.__dict__: | |
122 | Context.g_module.options=Utils.nada | |
123 | def parse_options(): | |
124 | Context.create_context('options').execute() | |
125 | if not Options.commands: | |
126 | Options.commands=[default_cmd] | |
127 | Options.commands=[x for x in Options.commands if x!='options'] | |
128 | Logs.verbose=Options.options.verbose | |
129 | Logs.init_log() | |
130 | if Options.options.zones: | |
131 | Logs.zones=Options.options.zones.split(',') | |
132 | if not Logs.verbose: | |
133 | Logs.verbose=1 | |
134 | elif Logs.verbose>0: | |
135 | Logs.zones=['runner'] | |
136 | if Logs.verbose>2: | |
137 | Logs.zones=['*'] | |
138 | def run_command(cmd_name): | |
139 | ctx=Context.create_context(cmd_name) | |
140 | ctx.options=Options.options | |
141 | ctx.cmd=cmd_name | |
142 | ctx.execute() | |
143 | return ctx | |
144 | def run_commands(): | |
145 | parse_options() | |
146 | run_command('init') | |
147 | while Options.commands: | |
148 | cmd_name=Options.commands.pop(0) | |
149 | timer=Utils.Timer() | |
150 | run_command(cmd_name) | |
151 | if not Options.options.progress_bar: | |
152 | elapsed=' (%s)'%str(timer) | |
153 | Logs.info('%r finished successfully%s'%(cmd_name,elapsed)) | |
154 | run_command('shutdown') | |
155 | def _can_distclean(name): | |
156 | for k in'.o .moc .exe'.split(): | |
157 | if name.endswith(k): | |
158 | return True | |
159 | return False | |
160 | def distclean_dir(dirname): | |
161 | for(root,dirs,files)in os.walk(dirname): | |
162 | for f in files: | |
163 | if _can_distclean(f): | |
164 | fname=root+os.sep+f | |
165 | try: | |
166 | os.unlink(fname) | |
167 | except: | |
168 | Logs.warn('could not remove %r'%fname) | |
169 | for x in[Context.DBFILE,'config.log']: | |
170 | try: | |
171 | os.unlink(x) | |
172 | except: | |
173 | pass | |
174 | try: | |
175 | shutil.rmtree('c4che') | |
176 | except: | |
177 | pass | |
178 | def distclean(ctx): | |
179 | '''removes the build directory''' | |
180 | lst=os.listdir('.') | |
181 | for f in lst: | |
182 | if f==Options.lockfile: | |
183 | try: | |
184 | proj=ConfigSet.ConfigSet(f) | |
185 | except: | |
186 | Logs.warn('could not read %r'%f) | |
187 | continue | |
188 | if proj['out_dir']!=proj['top_dir']: | |
189 | try: | |
190 | shutil.rmtree(proj['out_dir']) | |
191 | except IOError: | |
192 | pass | |
193 | except OSError ,e: | |
194 | if e.errno!=errno.ENOENT: | |
195 | Logs.warn('project %r cannot be removed'%proj[Context.OUT]) | |
196 | else: | |
197 | distclean_dir(proj['out_dir']) | |
198 | for k in(proj['out_dir'],proj['top_dir'],proj['run_dir']): | |
199 | try: | |
200 | os.remove(os.path.join(k,Options.lockfile)) | |
201 | except OSError ,e: | |
202 | if e.errno!=errno.ENOENT: | |
203 | Logs.warn('file %r cannot be removed'%f) | |
204 | if f.startswith('.waf')and not Options.commands: | |
205 | shutil.rmtree(f,ignore_errors=True) | |
206 | class Dist(Context.Context): | |
207 | cmd='dist' | |
208 | fun='dist' | |
209 | algo='tar.bz2' | |
210 | ext_algo={} | |
211 | def execute(self): | |
212 | self.recurse([os.path.dirname(Context.g_module.root_path)]) | |
213 | self.archive() | |
214 | def archive(self): | |
215 | import tarfile | |
216 | arch_name=self.get_arch_name() | |
217 | try: | |
218 | self.base_path | |
219 | except: | |
220 | self.base_path=self.path | |
221 | node=self.base_path.make_node(arch_name) | |
222 | try: | |
223 | node.delete() | |
224 | except: | |
225 | pass | |
226 | files=self.get_files() | |
227 | if self.algo.startswith('tar.'): | |
228 | tar=tarfile.open(arch_name,'w:'+self.algo.replace('tar.','')) | |
229 | for x in files: | |
230 | self.add_tar_file(x,tar) | |
231 | tar.close() | |
232 | elif self.algo=='zip': | |
233 | import zipfile | |
234 | zip=zipfile.ZipFile(arch_name,'w',compression=zipfile.ZIP_DEFLATED) | |
235 | for x in files: | |
236 | archive_name=self.get_base_name()+'/'+x.path_from(self.base_path) | |
237 | zip.write(x.abspath(),archive_name,zipfile.ZIP_DEFLATED) | |
238 | zip.close() | |
239 | else: | |
240 | self.fatal('Valid algo types are tar.bz2, tar.gz or zip') | |
241 | try: | |
242 | from hashlib import sha1 as sha | |
243 | except ImportError: | |
244 | from sha import sha | |
245 | try: | |
246 | digest=" (sha=%r)"%sha(node.read()).hexdigest() | |
247 | except: | |
248 | digest='' | |
249 | Logs.info('New archive created: %s%s'%(self.arch_name,digest)) | |
250 | def get_tar_path(self,node): | |
251 | return node.abspath() | |
252 | def add_tar_file(self,x,tar): | |
253 | p=self.get_tar_path(x) | |
254 | tinfo=tar.gettarinfo(name=p,arcname=self.get_tar_prefix()+'/'+x.path_from(self.base_path)) | |
255 | tinfo.uid=0 | |
256 | tinfo.gid=0 | |
257 | tinfo.uname='root' | |
258 | tinfo.gname='root' | |
259 | fu=None | |
260 | try: | |
261 | fu=open(p,'rb') | |
262 | tar.addfile(tinfo,fileobj=fu) | |
263 | finally: | |
264 | if fu: | |
265 | fu.close() | |
266 | def get_tar_prefix(self): | |
267 | try: | |
268 | return self.tar_prefix | |
269 | except: | |
270 | return self.get_base_name() | |
271 | def get_arch_name(self): | |
272 | try: | |
273 | self.arch_name | |
274 | except: | |
275 | self.arch_name=self.get_base_name()+'.'+self.ext_algo.get(self.algo,self.algo) | |
276 | return self.arch_name | |
277 | def get_base_name(self): | |
278 | try: | |
279 | self.base_name | |
280 | except: | |
281 | appname=getattr(Context.g_module,Context.APPNAME,'noname') | |
282 | version=getattr(Context.g_module,Context.VERSION,'1.0') | |
283 | self.base_name=appname+'-'+version | |
284 | return self.base_name | |
285 | def get_excl(self): | |
286 | try: | |
287 | return self.excl | |
288 | except: | |
289 | self.excl=Node.exclude_regs+' **/waf-1.6.* **/.waf-1.6* **/waf3-1.6.* **/.waf3-1.6* **/*~ **/*.rej **/*.orig **/*.pyc **/*.pyo **/*.bak **/*.swp **/.lock-w*' | |
290 | nd=self.root.find_node(Context.out_dir) | |
291 | if nd: | |
292 | self.excl+=' '+nd.path_from(self.base_path) | |
293 | return self.excl | |
294 | def get_files(self): | |
295 | try: | |
296 | files=self.files | |
297 | except: | |
298 | files=self.base_path.ant_glob('**/*',excl=self.get_excl()) | |
299 | return files | |
300 | def dist(ctx): | |
301 | '''makes a tarball for redistributing the sources''' | |
302 | pass | |
303 | class DistCheck(Dist): | |
304 | fun='distcheck' | |
305 | cmd='distcheck' | |
306 | def execute(self): | |
307 | self.recurse([os.path.dirname(Context.g_module.root_path)]) | |
308 | self.archive() | |
309 | self.check() | |
310 | def check(self): | |
311 | import tempfile,tarfile | |
312 | t=None | |
313 | try: | |
314 | t=tarfile.open(self.get_arch_name()) | |
315 | for x in t: | |
316 | t.extract(x) | |
317 | finally: | |
318 | if t: | |
319 | t.close() | |
320 | instdir=tempfile.mkdtemp('.inst',self.get_base_name()) | |
321 | ret=Utils.subprocess.Popen([sys.argv[0],'configure','install','uninstall','--destdir='+instdir],cwd=self.get_base_name()).wait() | |
322 | if ret: | |
323 | raise Errors.WafError('distcheck failed with code %i'%ret) | |
324 | if os.path.exists(instdir): | |
325 | raise Errors.WafError('distcheck succeeded, but files were left in %s'%instdir) | |
326 | shutil.rmtree(self.get_base_name()) | |
327 | def distcheck(ctx): | |
328 | '''checks if the project compiles (tarball from 'dist')''' | |
329 | pass | |
330 | def update(ctx): | |
331 | '''updates the plugins from the *waflib/extras* directory''' | |
332 | lst=Options.options.files.split(',') | |
333 | if not lst: | |
334 | lst=[x for x in Utils.listdir(Context.waf_dir+'/waflib/extras')if x.endswith('.py')] | |
335 | for x in lst: | |
336 | tool=x.replace('.py','') | |
337 | try: | |
338 | Configure.download_tool(tool,force=True,ctx=ctx) | |
339 | except Errors.WafError: | |
340 | Logs.error('Could not find the tool %s in the remote repository'%x) | |
341 | def autoconfigure(execute_method): | |
342 | def execute(self): | |
343 | if not Configure.autoconfig: | |
344 | return execute_method(self) | |
345 | env=ConfigSet.ConfigSet() | |
346 | do_config=False | |
347 | try: | |
348 | env.load(os.path.join(Context.top_dir,Options.lockfile)) | |
349 | except Exception: | |
350 | Logs.warn('Configuring the project') | |
351 | do_config=True | |
352 | else: | |
353 | if env.run_dir!=Context.run_dir: | |
354 | do_config=True | |
355 | else: | |
356 | h=0 | |
357 | for f in env['files']: | |
358 | h=hash((h,Utils.readf(f,'rb'))) | |
359 | do_config=h!=env.hash | |
360 | if do_config: | |
361 | Options.commands.insert(0,self.cmd) | |
362 | Options.commands.insert(0,'configure') | |
363 | return | |
364 | return execute_method(self) | |
365 | return execute | |
366 | Build.BuildContext.execute=autoconfigure(Build.BuildContext.execute) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import os,shutil,re,tempfile | |
7 | from waflib import Utils,Logs,Errors | |
8 | NOT_RUN=0 | |
9 | MISSING=1 | |
10 | CRASHED=2 | |
11 | EXCEPTION=3 | |
12 | SKIPPED=8 | |
13 | SUCCESS=9 | |
14 | ASK_LATER=-1 | |
15 | SKIP_ME=-2 | |
16 | RUN_ME=-3 | |
17 | COMPILE_TEMPLATE_SHELL=''' | |
18 | def f(tsk): | |
19 | env = tsk.env | |
20 | gen = tsk.generator | |
21 | bld = gen.bld | |
22 | wd = getattr(tsk, 'cwd', None) | |
23 | p = env.get_flat | |
24 | tsk.last_cmd = cmd = \'\'\' %s \'\'\' % s | |
25 | return tsk.exec_command(cmd, cwd=wd, env=env.env or None) | |
26 | ''' | |
27 | COMPILE_TEMPLATE_NOSHELL=''' | |
28 | def f(tsk): | |
29 | env = tsk.env | |
30 | gen = tsk.generator | |
31 | bld = gen.bld | |
32 | wd = getattr(tsk, 'cwd', None) | |
33 | def to_list(xx): | |
34 | if isinstance(xx, str): return [xx] | |
35 | return xx | |
36 | tsk.last_cmd = lst = [] | |
37 | %s | |
38 | lst = [x for x in lst if x] | |
39 | return tsk.exec_command(lst, cwd=wd, env=env.env or None) | |
40 | ''' | |
41 | def cache_outputs(cls): | |
42 | m1=cls.run | |
43 | def run(self): | |
44 | bld=self.generator.bld | |
45 | if bld.cache_global and not bld.nocache: | |
46 | if self.can_retrieve_cache(): | |
47 | return 0 | |
48 | return m1(self) | |
49 | cls.run=run | |
50 | m2=cls.post_run | |
51 | def post_run(self): | |
52 | bld=self.generator.bld | |
53 | ret=m2(self) | |
54 | if bld.cache_global and not bld.nocache: | |
55 | self.put_files_cache() | |
56 | return ret | |
57 | cls.post_run=post_run | |
58 | return cls | |
59 | classes={} | |
60 | class store_task_type(type): | |
61 | def __init__(cls,name,bases,dict): | |
62 | super(store_task_type,cls).__init__(name,bases,dict) | |
63 | name=cls.__name__ | |
64 | if name.endswith('_task'): | |
65 | name=name.replace('_task','') | |
66 | if name!='evil'and name!='TaskBase': | |
67 | global classes | |
68 | if getattr(cls,'run_str',None): | |
69 | (f,dvars)=compile_fun(cls.run_str,cls.shell) | |
70 | cls.hcode=cls.run_str | |
71 | cls.run_str=None | |
72 | cls.run=f | |
73 | cls.vars=list(set(cls.vars+dvars)) | |
74 | cls.vars.sort() | |
75 | elif getattr(cls,'run',None)and not'hcode'in cls.__dict__: | |
76 | cls.hcode=Utils.h_fun(cls.run) | |
77 | if not getattr(cls,'nocache',None): | |
78 | cls=cache_outputs(cls) | |
79 | classes[name]=cls | |
80 | evil=store_task_type('evil',(object,),{}) | |
81 | class TaskBase(evil): | |
82 | color='GREEN' | |
83 | ext_in=[] | |
84 | ext_out=[] | |
85 | before=[] | |
86 | after=[] | |
87 | hcode='' | |
88 | def __init__(self,*k,**kw): | |
89 | self.hasrun=NOT_RUN | |
90 | try: | |
91 | self.generator=kw['generator'] | |
92 | except KeyError: | |
93 | self.generator=self | |
94 | def __repr__(self): | |
95 | return'\n\t{task %r: %s %s}'%(self.__class__.__name__,id(self),str(getattr(self,'fun',''))) | |
96 | def __str__(self): | |
97 | if hasattr(self,'fun'): | |
98 | return'executing: %s\n'%self.fun.__name__ | |
99 | return self.__class__.__name__+'\n' | |
100 | def __hash__(self): | |
101 | return id(self) | |
102 | def exec_command(self,cmd,**kw): | |
103 | bld=self.generator.bld | |
104 | try: | |
105 | if not kw.get('cwd',None): | |
106 | kw['cwd']=bld.cwd | |
107 | except AttributeError: | |
108 | bld.cwd=kw['cwd']=bld.variant_dir | |
109 | return bld.exec_command(cmd,**kw) | |
110 | def runnable_status(self): | |
111 | return RUN_ME | |
112 | def process(self): | |
113 | m=self.master | |
114 | if m.stop: | |
115 | m.out.put(self) | |
116 | return | |
117 | try: | |
118 | del self.generator.bld.task_sigs[self.uid()] | |
119 | except: | |
120 | pass | |
121 | try: | |
122 | self.generator.bld.returned_tasks.append(self) | |
123 | self.log_display(self.generator.bld) | |
124 | ret=self.run() | |
125 | except Exception: | |
126 | self.err_msg=Utils.ex_stack() | |
127 | self.hasrun=EXCEPTION | |
128 | m.error_handler(self) | |
129 | m.out.put(self) | |
130 | return | |
131 | if ret: | |
132 | self.err_code=ret | |
133 | self.hasrun=CRASHED | |
134 | else: | |
135 | try: | |
136 | self.post_run() | |
137 | except Errors.WafError: | |
138 | pass | |
139 | except Exception: | |
140 | self.err_msg=Utils.ex_stack() | |
141 | self.hasrun=EXCEPTION | |
142 | else: | |
143 | self.hasrun=SUCCESS | |
144 | if self.hasrun!=SUCCESS: | |
145 | m.error_handler(self) | |
146 | m.out.put(self) | |
147 | def run(self): | |
148 | if hasattr(self,'fun'): | |
149 | return self.fun(self) | |
150 | return 0 | |
151 | def post_run(self): | |
152 | pass | |
153 | def log_display(self,bld): | |
154 | bld.to_log(self.display()) | |
155 | def display(self): | |
156 | col1=Logs.colors(self.color) | |
157 | col2=Logs.colors.NORMAL | |
158 | master=self.master | |
159 | def cur(): | |
160 | tmp=-1 | |
161 | if hasattr(master,'ready'): | |
162 | tmp-=master.ready.qsize() | |
163 | return master.processed+tmp | |
164 | if self.generator.bld.progress_bar==1: | |
165 | return self.generator.bld.progress_line(cur(),master.total,col1,col2) | |
166 | if self.generator.bld.progress_bar==2: | |
167 | ela=str(self.generator.bld.timer) | |
168 | try: | |
169 | ins=','.join([n.name for n in self.inputs]) | |
170 | except AttributeError: | |
171 | ins='' | |
172 | try: | |
173 | outs=','.join([n.name for n in self.outputs]) | |
174 | except AttributeError: | |
175 | outs='' | |
176 | return'|Total %s|Current %s|Inputs %s|Outputs %s|Time %s|\n'%(master.total,cur(),ins,outs,ela) | |
177 | s=str(self) | |
178 | if not s: | |
179 | return None | |
180 | total=master.total | |
181 | n=len(str(total)) | |
182 | fs='[%%%dd/%%%dd] %%s%%s%%s'%(n,n) | |
183 | return fs%(cur(),total,col1,s,col2) | |
184 | def attr(self,att,default=None): | |
185 | ret=getattr(self,att,self) | |
186 | if ret is self:return getattr(self.__class__,att,default) | |
187 | return ret | |
188 | def hash_constraints(self): | |
189 | cls=self.__class__ | |
190 | tup=(str(cls.before),str(cls.after),str(cls.ext_in),str(cls.ext_out),cls.__name__,cls.hcode) | |
191 | h=hash(tup) | |
192 | return h | |
193 | def format_error(self): | |
194 | msg=getattr(self,'last_cmd','') | |
195 | name=getattr(self.generator,'name','') | |
196 | if getattr(self,"err_msg",None): | |
197 | return self.err_msg | |
198 | elif not self.hasrun: | |
199 | return'task in %r was not executed for some reason: %r'%(name,self) | |
200 | elif self.hasrun==CRASHED: | |
201 | try: | |
202 | return' -> task in %r failed (exit status %r): %r\n%r'%(name,self.err_code,self,msg) | |
203 | except AttributeError: | |
204 | return' -> task in %r failed: %r\n%r'%(name,self,msg) | |
205 | elif self.hasrun==MISSING: | |
206 | return' -> missing files in %r: %r\n%r'%(name,self,msg) | |
207 | else: | |
208 | return'invalid status for task in %r: %r'%(name,self.hasrun) | |
209 | def colon(self,var1,var2): | |
210 | tmp=self.env[var1] | |
211 | if isinstance(var2,str): | |
212 | it=self.env[var2] | |
213 | else: | |
214 | it=var2 | |
215 | if isinstance(tmp,str): | |
216 | return[tmp%x for x in it] | |
217 | else: | |
218 | if Logs.verbose and not tmp and it: | |
219 | Logs.warn('Missing env variable %r for task %r (generator %r)'%(var1,self,self.generator)) | |
220 | lst=[] | |
221 | for y in it: | |
222 | lst.extend(tmp) | |
223 | lst.append(y) | |
224 | return lst | |
225 | class Task(TaskBase): | |
226 | vars=[] | |
227 | shell=False | |
228 | def __init__(self,*k,**kw): | |
229 | TaskBase.__init__(self,*k,**kw) | |
230 | self.env=kw['env'] | |
231 | self.inputs=[] | |
232 | self.outputs=[] | |
233 | self.dep_nodes=[] | |
234 | self.run_after=set([]) | |
235 | def __str__(self): | |
236 | env=self.env | |
237 | src_str=' '.join([a.nice_path(env)for a in self.inputs]) | |
238 | tgt_str=' '.join([a.nice_path(env)for a in self.outputs]) | |
239 | if self.outputs:sep=' -> ' | |
240 | else:sep='' | |
241 | return'%s: %s%s%s\n'%(self.__class__.__name__.replace('_task',''),src_str,sep,tgt_str) | |
242 | def __repr__(self): | |
243 | return"".join(['\n\t{task %r: '%id(self),self.__class__.__name__," ",",".join([x.name for x in self.inputs])," -> ",",".join([x.name for x in self.outputs]),'}']) | |
244 | def uid(self): | |
245 | try: | |
246 | return self.uid_ | |
247 | except AttributeError: | |
248 | m=Utils.md5() | |
249 | up=m.update | |
250 | up(self.__class__.__name__) | |
251 | for x in self.inputs+self.outputs: | |
252 | up(x.abspath()) | |
253 | self.uid_=m.digest() | |
254 | return self.uid_ | |
255 | def set_inputs(self,inp): | |
256 | if isinstance(inp,list):self.inputs+=inp | |
257 | else:self.inputs.append(inp) | |
258 | def set_outputs(self,out): | |
259 | if isinstance(out,list):self.outputs+=out | |
260 | else:self.outputs.append(out) | |
261 | def set_run_after(self,task): | |
262 | assert isinstance(task,TaskBase) | |
263 | self.run_after.add(task) | |
264 | def signature(self): | |
265 | try:return self.cache_sig | |
266 | except AttributeError:pass | |
267 | self.m=Utils.md5() | |
268 | self.m.update(self.hcode) | |
269 | self.sig_explicit_deps() | |
270 | self.sig_vars() | |
271 | if self.scan: | |
272 | try: | |
273 | self.sig_implicit_deps() | |
274 | except Errors.TaskRescan: | |
275 | return self.signature() | |
276 | ret=self.cache_sig=self.m.digest() | |
277 | return ret | |
278 | def runnable_status(self): | |
279 | for t in self.run_after: | |
280 | if not t.hasrun: | |
281 | return ASK_LATER | |
282 | bld=self.generator.bld | |
283 | try: | |
284 | new_sig=self.signature() | |
285 | except Errors.TaskNotReady: | |
286 | return ASK_LATER | |
287 | key=self.uid() | |
288 | try: | |
289 | prev_sig=bld.task_sigs[key] | |
290 | except KeyError: | |
291 | Logs.debug("task: task %r must run as it was never run before or the task code changed"%self) | |
292 | return RUN_ME | |
293 | for node in self.outputs: | |
294 | try: | |
295 | if node.sig!=new_sig: | |
296 | return RUN_ME | |
297 | except AttributeError: | |
298 | Logs.debug("task: task %r must run as the output nodes do not exist"%self) | |
299 | return RUN_ME | |
300 | if new_sig!=prev_sig: | |
301 | return RUN_ME | |
302 | return SKIP_ME | |
303 | def post_run(self): | |
304 | bld=self.generator.bld | |
305 | sig=self.signature() | |
306 | for node in self.outputs: | |
307 | try: | |
308 | os.stat(node.abspath()) | |
309 | except OSError: | |
310 | self.hasrun=MISSING | |
311 | self.err_msg='-> missing file: %r'%node.abspath() | |
312 | raise Errors.WafError(self.err_msg) | |
313 | node.sig=sig | |
314 | bld.task_sigs[self.uid()]=self.cache_sig | |
315 | def sig_explicit_deps(self): | |
316 | bld=self.generator.bld | |
317 | upd=self.m.update | |
318 | for x in self.inputs+self.dep_nodes: | |
319 | try: | |
320 | upd(x.get_bld_sig()) | |
321 | except(AttributeError,TypeError): | |
322 | raise Errors.WafError('Missing node signature for %r (required by %r)'%(x,self)) | |
323 | if bld.deps_man: | |
324 | additional_deps=bld.deps_man | |
325 | for x in self.inputs+self.outputs: | |
326 | try: | |
327 | d=additional_deps[id(x)] | |
328 | except KeyError: | |
329 | continue | |
330 | for v in d: | |
331 | if isinstance(v,bld.root.__class__): | |
332 | try: | |
333 | v=v.get_bld_sig() | |
334 | except AttributeError: | |
335 | raise Errors.WafError('Missing node signature for %r (required by %r)'%(v,self)) | |
336 | elif hasattr(v,'__call__'): | |
337 | v=v() | |
338 | upd(v) | |
339 | return self.m.digest() | |
340 | def sig_vars(self): | |
341 | bld=self.generator.bld | |
342 | env=self.env | |
343 | upd=self.m.update | |
344 | act_sig=bld.hash_env_vars(env,self.__class__.vars) | |
345 | upd(act_sig) | |
346 | dep_vars=getattr(self,'dep_vars',None) | |
347 | if dep_vars: | |
348 | upd(bld.hash_env_vars(env,dep_vars)) | |
349 | return self.m.digest() | |
350 | scan=None | |
351 | def sig_implicit_deps(self): | |
352 | bld=self.generator.bld | |
353 | key=self.uid() | |
354 | prev=bld.task_sigs.get((key,'imp'),[]) | |
355 | if prev: | |
356 | try: | |
357 | if prev==self.compute_sig_implicit_deps(): | |
358 | return prev | |
359 | except: | |
360 | for x in bld.node_deps.get(self.uid(),[]): | |
361 | if x.is_child_of(bld.srcnode): | |
362 | try: | |
363 | os.stat(x.abspath()) | |
364 | except: | |
365 | try: | |
366 | del x.parent.children[x.name] | |
367 | except: | |
368 | pass | |
369 | del bld.task_sigs[(key,'imp')] | |
370 | raise Errors.TaskRescan('rescan') | |
371 | (nodes,names)=self.scan() | |
372 | if Logs.verbose: | |
373 | Logs.debug('deps: scanner for %s returned %s %s'%(str(self),str(nodes),str(names))) | |
374 | bld.node_deps[key]=nodes | |
375 | bld.raw_deps[key]=names | |
376 | self.are_implicit_nodes_ready() | |
377 | try: | |
378 | bld.task_sigs[(key,'imp')]=sig=self.compute_sig_implicit_deps() | |
379 | except: | |
380 | if Logs.verbose: | |
381 | for k in bld.node_deps.get(self.uid(),[]): | |
382 | try: | |
383 | k.get_bld_sig() | |
384 | except: | |
385 | Logs.warn('Missing signature for node %r (may cause rebuilds)'%k) | |
386 | else: | |
387 | return sig | |
388 | def compute_sig_implicit_deps(self): | |
389 | upd=self.m.update | |
390 | bld=self.generator.bld | |
391 | self.are_implicit_nodes_ready() | |
392 | for k in bld.node_deps.get(self.uid(),[]): | |
393 | upd(k.get_bld_sig()) | |
394 | return self.m.digest() | |
395 | def are_implicit_nodes_ready(self): | |
396 | bld=self.generator.bld | |
397 | try: | |
398 | cache=bld.dct_implicit_nodes | |
399 | except: | |
400 | bld.dct_implicit_nodes=cache={} | |
401 | try: | |
402 | dct=cache[bld.cur] | |
403 | except KeyError: | |
404 | dct=cache[bld.cur]={} | |
405 | for tsk in bld.cur_tasks: | |
406 | for x in tsk.outputs: | |
407 | dct[x]=tsk | |
408 | modified=False | |
409 | for x in bld.node_deps.get(self.uid(),[]): | |
410 | if x in dct: | |
411 | self.run_after.add(dct[x]) | |
412 | modified=True | |
413 | if modified: | |
414 | for tsk in self.run_after: | |
415 | if not tsk.hasrun: | |
416 | raise Errors.TaskNotReady('not ready') | |
417 | def can_retrieve_cache(self): | |
418 | if not getattr(self,'outputs',None): | |
419 | return None | |
420 | sig=self.signature() | |
421 | ssig=Utils.to_hex(self.uid())+Utils.to_hex(sig) | |
422 | dname=os.path.join(self.generator.bld.cache_global,ssig) | |
423 | try: | |
424 | t1=os.stat(dname).st_mtime | |
425 | except OSError: | |
426 | return None | |
427 | for node in self.outputs: | |
428 | orig=os.path.join(dname,node.name) | |
429 | try: | |
430 | shutil.copy2(orig,node.abspath()) | |
431 | os.utime(orig,None) | |
432 | except(OSError,IOError): | |
433 | Logs.debug('task: failed retrieving file') | |
434 | return None | |
435 | try: | |
436 | t2=os.stat(dname).st_mtime | |
437 | except OSError: | |
438 | return None | |
439 | if t1!=t2: | |
440 | return None | |
441 | for node in self.outputs: | |
442 | node.sig=sig | |
443 | if self.generator.bld.progress_bar<1: | |
444 | self.generator.bld.to_log('restoring from cache %r\n'%node.abspath()) | |
445 | self.cached=True | |
446 | return True | |
447 | def put_files_cache(self): | |
448 | if getattr(self,'cached',None): | |
449 | return None | |
450 | if not getattr(self,'outputs',None): | |
451 | return None | |
452 | sig=self.signature() | |
453 | ssig=Utils.to_hex(self.uid())+Utils.to_hex(sig) | |
454 | dname=os.path.join(self.generator.bld.cache_global,ssig) | |
455 | tmpdir=tempfile.mkdtemp(prefix=self.generator.bld.cache_global+os.sep+'waf') | |
456 | try: | |
457 | shutil.rmtree(dname) | |
458 | except: | |
459 | pass | |
460 | try: | |
461 | for node in self.outputs: | |
462 | dest=os.path.join(tmpdir,node.name) | |
463 | shutil.copy2(node.abspath(),dest) | |
464 | except(OSError,IOError): | |
465 | try: | |
466 | shutil.rmtree(tmpdir) | |
467 | except: | |
468 | pass | |
469 | else: | |
470 | try: | |
471 | os.rename(tmpdir,dname) | |
472 | except OSError: | |
473 | try: | |
474 | shutil.rmtree(tmpdir) | |
475 | except: | |
476 | pass | |
477 | else: | |
478 | try: | |
479 | os.chmod(dname,Utils.O755) | |
480 | except: | |
481 | pass | |
482 | def is_before(t1,t2): | |
483 | to_list=Utils.to_list | |
484 | for k in to_list(t2.ext_in): | |
485 | if k in to_list(t1.ext_out): | |
486 | return 1 | |
487 | if t1.__class__.__name__ in to_list(t2.after): | |
488 | return 1 | |
489 | if t2.__class__.__name__ in to_list(t1.before): | |
490 | return 1 | |
491 | return 0 | |
492 | def set_file_constraints(tasks): | |
493 | ins=Utils.defaultdict(set) | |
494 | outs=Utils.defaultdict(set) | |
495 | for x in tasks: | |
496 | for a in getattr(x,'inputs',[])+getattr(x,'dep_nodes',[]): | |
497 | ins[id(a)].add(x) | |
498 | for a in getattr(x,'outputs',[]): | |
499 | outs[id(a)].add(x) | |
500 | links=set(ins.keys()).intersection(outs.keys()) | |
501 | for k in links: | |
502 | for a in ins[k]: | |
503 | a.run_after.update(outs[k]) | |
504 | def set_precedence_constraints(tasks): | |
505 | cstr_groups=Utils.defaultdict(list) | |
506 | for x in tasks: | |
507 | h=x.hash_constraints() | |
508 | cstr_groups[h].append(x) | |
509 | keys=list(cstr_groups.keys()) | |
510 | maxi=len(keys) | |
511 | for i in range(maxi): | |
512 | t1=cstr_groups[keys[i]][0] | |
513 | for j in range(i+1,maxi): | |
514 | t2=cstr_groups[keys[j]][0] | |
515 | if is_before(t1,t2): | |
516 | a=i | |
517 | b=j | |
518 | elif is_before(t2,t1): | |
519 | a=j | |
520 | b=i | |
521 | else: | |
522 | continue | |
523 | for x in cstr_groups[keys[b]]: | |
524 | x.run_after.update(cstr_groups[keys[a]]) | |
525 | def funex(c): | |
526 | dc={} | |
527 | exec(c,dc) | |
528 | return dc['f'] | |
529 | reg_act=re.compile(r"(?P<backslash>\\)|(?P<dollar>\$\$)|(?P<subst>\$\{(?P<var>\w+)(?P<code>.*?)\})",re.M) | |
530 | def compile_fun_shell(line): | |
531 | extr=[] | |
532 | def repl(match): | |
533 | g=match.group | |
534 | if g('dollar'):return"$" | |
535 | elif g('backslash'):return'\\\\' | |
536 | elif g('subst'):extr.append((g('var'),g('code')));return"%s" | |
537 | return None | |
538 | line=reg_act.sub(repl,line)or line | |
539 | parm=[] | |
540 | dvars=[] | |
541 | app=parm.append | |
542 | for(var,meth)in extr: | |
543 | if var=='SRC': | |
544 | if meth:app('tsk.inputs%s'%meth) | |
545 | else:app('" ".join([a.path_from(bld.bldnode) for a in tsk.inputs])') | |
546 | elif var=='TGT': | |
547 | if meth:app('tsk.outputs%s'%meth) | |
548 | else:app('" ".join([a.path_from(bld.bldnode) for a in tsk.outputs])') | |
549 | elif meth: | |
550 | if meth.startswith(':'): | |
551 | m=meth[1:] | |
552 | if m=='SRC': | |
553 | m='[a.path_from(bld.bldnode) for a in tsk.inputs]' | |
554 | elif m=='TGT': | |
555 | m='[a.path_from(bld.bldnode) for a in tsk.outputs]' | |
556 | elif m[:3]not in('tsk','gen','bld'): | |
557 | dvars.extend([var,meth[1:]]) | |
558 | m='%r'%m | |
559 | app('" ".join(tsk.colon(%r, %s))'%(var,m)) | |
560 | else: | |
561 | app('%s%s'%(var,meth)) | |
562 | else: | |
563 | if not var in dvars:dvars.append(var) | |
564 | app("p('%s')"%var) | |
565 | if parm:parm="%% (%s) "%(',\n\t\t'.join(parm)) | |
566 | else:parm='' | |
567 | c=COMPILE_TEMPLATE_SHELL%(line,parm) | |
568 | Logs.debug('action: %s'%c) | |
569 | return(funex(c),dvars) | |
570 | def compile_fun_noshell(line): | |
571 | extr=[] | |
572 | def repl(match): | |
573 | g=match.group | |
574 | if g('dollar'):return"$" | |
575 | elif g('subst'):extr.append((g('var'),g('code')));return"<<|@|>>" | |
576 | return None | |
577 | line2=reg_act.sub(repl,line) | |
578 | params=line2.split('<<|@|>>') | |
579 | assert(extr) | |
580 | buf=[] | |
581 | dvars=[] | |
582 | app=buf.append | |
583 | for x in range(len(extr)): | |
584 | params[x]=params[x].strip() | |
585 | if params[x]: | |
586 | app("lst.extend(%r)"%params[x].split()) | |
587 | (var,meth)=extr[x] | |
588 | if var=='SRC': | |
589 | if meth:app('lst.append(tsk.inputs%s)'%meth) | |
590 | else:app("lst.extend([a.path_from(bld.bldnode) for a in tsk.inputs])") | |
591 | elif var=='TGT': | |
592 | if meth:app('lst.append(tsk.outputs%s)'%meth) | |
593 | else:app("lst.extend([a.path_from(bld.bldnode) for a in tsk.outputs])") | |
594 | elif meth: | |
595 | if meth.startswith(':'): | |
596 | m=meth[1:] | |
597 | if m=='SRC': | |
598 | m='[a.path_from(bld.bldnode) for a in tsk.inputs]' | |
599 | elif m=='TGT': | |
600 | m='[a.path_from(bld.bldnode) for a in tsk.outputs]' | |
601 | elif m[:3]not in('tsk','gen','bld'): | |
602 | dvars.extend([var,m]) | |
603 | m='%r'%m | |
604 | app('lst.extend(tsk.colon(%r, %s))'%(var,m)) | |
605 | else: | |
606 | app('lst.extend(gen.to_list(%s%s))'%(var,meth)) | |
607 | else: | |
608 | app('lst.extend(to_list(env[%r]))'%var) | |
609 | if not var in dvars:dvars.append(var) | |
610 | if extr: | |
611 | if params[-1]: | |
612 | app("lst.extend(%r)"%params[-1].split()) | |
613 | fun=COMPILE_TEMPLATE_NOSHELL%"\n\t".join(buf) | |
614 | Logs.debug('action: %s'%fun) | |
615 | return(funex(fun),dvars) | |
616 | def compile_fun(line,shell=False): | |
617 | if line.find('<')>0 or line.find('>')>0 or line.find('&&')>0: | |
618 | shell=True | |
619 | if shell: | |
620 | return compile_fun_shell(line) | |
621 | else: | |
622 | return compile_fun_noshell(line) | |
623 | def task_factory(name,func=None,vars=None,color='GREEN',ext_in=[],ext_out=[],before=[],after=[],shell=False,scan=None): | |
624 | params={'vars':vars or[],'color':color,'name':name,'ext_in':Utils.to_list(ext_in),'ext_out':Utils.to_list(ext_out),'before':Utils.to_list(before),'after':Utils.to_list(after),'shell':shell,'scan':scan,} | |
625 | if isinstance(func,str): | |
626 | params['run_str']=func | |
627 | else: | |
628 | params['run']=func | |
629 | cls=type(Task)(name,(Task,),params) | |
630 | global classes | |
631 | classes[name]=cls | |
632 | return cls | |
633 | def always_run(cls): | |
634 | old=cls.runnable_status | |
635 | def always(self): | |
636 | ret=old(self) | |
637 | if ret==SKIP_ME: | |
638 | ret=RUN_ME | |
639 | return ret | |
640 | cls.runnable_status=always | |
641 | return cls | |
642 | def update_outputs(cls): | |
643 | old_post_run=cls.post_run | |
644 | def post_run(self): | |
645 | old_post_run(self) | |
646 | for node in self.outputs: | |
647 | node.sig=Utils.h_file(node.abspath()) | |
648 | self.generator.bld.task_sigs[node.abspath()]=self.uid() | |
649 | cls.post_run=post_run | |
650 | old_runnable_status=cls.runnable_status | |
651 | def runnable_status(self): | |
652 | status=old_runnable_status(self) | |
653 | if status!=RUN_ME: | |
654 | return status | |
655 | try: | |
656 | bld=self.generator.bld | |
657 | prev_sig=bld.task_sigs[self.uid()] | |
658 | if prev_sig==self.signature(): | |
659 | for x in self.outputs: | |
660 | if not x.sig or bld.task_sigs[x.abspath()]!=self.uid(): | |
661 | return RUN_ME | |
662 | return SKIP_ME | |
663 | except KeyError: | |
664 | pass | |
665 | except IndexError: | |
666 | pass | |
667 | except AttributeError: | |
668 | pass | |
669 | return RUN_ME | |
670 | cls.runnable_status=runnable_status | |
671 | return cls |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import copy,re,os | |
7 | from waflib import Task,Utils,Logs,Errors,ConfigSet | |
8 | feats=Utils.defaultdict(set) | |
9 | class task_gen(object): | |
10 | mappings={} | |
11 | prec=Utils.defaultdict(list) | |
12 | def __init__(self,*k,**kw): | |
13 | self.source='' | |
14 | self.target='' | |
15 | self.meths=[] | |
16 | self.prec=Utils.defaultdict(list) | |
17 | self.mappings={} | |
18 | self.features=[] | |
19 | self.tasks=[] | |
20 | if not'bld'in kw: | |
21 | self.env=ConfigSet.ConfigSet() | |
22 | self.idx=0 | |
23 | self.path=None | |
24 | else: | |
25 | self.bld=kw['bld'] | |
26 | self.env=self.bld.env.derive() | |
27 | self.path=self.bld.path | |
28 | try: | |
29 | self.idx=self.bld.idx[id(self.path)]=self.bld.idx.get(id(self.path),0)+1 | |
30 | except AttributeError: | |
31 | self.bld.idx={} | |
32 | self.idx=self.bld.idx[id(self.path)]=1 | |
33 | for key,val in kw.items(): | |
34 | setattr(self,key,val) | |
35 | def __str__(self): | |
36 | return"<task_gen %r declared in %s>"%(self.name,self.path.abspath()) | |
37 | def __repr__(self): | |
38 | lst=[] | |
39 | for x in self.__dict__.keys(): | |
40 | if x not in['env','bld','compiled_tasks','tasks']: | |
41 | lst.append("%s=%s"%(x,repr(getattr(self,x)))) | |
42 | return"bld(%s) in %s"%(", ".join(lst),self.path.abspath()) | |
43 | def get_name(self): | |
44 | try: | |
45 | return self._name | |
46 | except AttributeError: | |
47 | if isinstance(self.target,list): | |
48 | lst=[str(x)for x in self.target] | |
49 | name=self._name=','.join(lst) | |
50 | else: | |
51 | name=self._name=str(self.target) | |
52 | return name | |
53 | def set_name(self,name): | |
54 | self._name=name | |
55 | name=property(get_name,set_name) | |
56 | def to_list(self,val): | |
57 | if isinstance(val,str):return val.split() | |
58 | else:return val | |
59 | def post(self): | |
60 | if getattr(self,'posted',None): | |
61 | return False | |
62 | self.posted=True | |
63 | keys=set(self.meths) | |
64 | self.features=Utils.to_list(self.features) | |
65 | for x in self.features+['*']: | |
66 | st=feats[x] | |
67 | if not st: | |
68 | if not x in Task.classes: | |
69 | Logs.warn('feature %r does not exist - bind at least one method to it'%x) | |
70 | keys.update(list(st)) | |
71 | prec={} | |
72 | prec_tbl=self.prec or task_gen.prec | |
73 | for x in prec_tbl: | |
74 | if x in keys: | |
75 | prec[x]=prec_tbl[x] | |
76 | tmp=[] | |
77 | for a in keys: | |
78 | for x in prec.values(): | |
79 | if a in x:break | |
80 | else: | |
81 | tmp.append(a) | |
82 | out=[] | |
83 | while tmp: | |
84 | e=tmp.pop() | |
85 | if e in keys:out.append(e) | |
86 | try: | |
87 | nlst=prec[e] | |
88 | except KeyError: | |
89 | pass | |
90 | else: | |
91 | del prec[e] | |
92 | for x in nlst: | |
93 | for y in prec: | |
94 | if x in prec[y]: | |
95 | break | |
96 | else: | |
97 | tmp.append(x) | |
98 | if prec: | |
99 | raise Errors.WafError('Cycle detected in the method execution %r'%prec) | |
100 | out.reverse() | |
101 | self.meths=out | |
102 | Logs.debug('task_gen: posting %s %d'%(self,id(self))) | |
103 | for x in out: | |
104 | try: | |
105 | v=getattr(self,x) | |
106 | except AttributeError: | |
107 | raise Errors.WafError('%r is not a valid task generator method'%x) | |
108 | Logs.debug('task_gen: -> %s (%d)'%(x,id(self))) | |
109 | v() | |
110 | Logs.debug('task_gen: posted %s'%self.name) | |
111 | return True | |
112 | def get_hook(self,node): | |
113 | name=node.name | |
114 | for k in self.mappings: | |
115 | if name.endswith(k): | |
116 | return self.mappings[k] | |
117 | for k in task_gen.mappings: | |
118 | if name.endswith(k): | |
119 | return task_gen.mappings[k] | |
120 | raise Errors.WafError("File %r has no mapping in %r (did you forget to load a waf tool?)"%(node,task_gen.mappings.keys())) | |
121 | def create_task(self,name,src=None,tgt=None): | |
122 | task=Task.classes[name](env=self.env.derive(),generator=self) | |
123 | if src: | |
124 | task.set_inputs(src) | |
125 | if tgt: | |
126 | task.set_outputs(tgt) | |
127 | self.tasks.append(task) | |
128 | return task | |
129 | def clone(self,env): | |
130 | newobj=self.bld() | |
131 | for x in self.__dict__: | |
132 | if x in['env','bld']: | |
133 | continue | |
134 | elif x in['path','features']: | |
135 | setattr(newobj,x,getattr(self,x)) | |
136 | else: | |
137 | setattr(newobj,x,copy.copy(getattr(self,x))) | |
138 | newobj.posted=False | |
139 | if isinstance(env,str): | |
140 | newobj.env=self.bld.all_envs[env].derive() | |
141 | else: | |
142 | newobj.env=env.derive() | |
143 | return newobj | |
144 | def declare_chain(name='',rule=None,reentrant=None,color='BLUE',ext_in=[],ext_out=[],before=[],after=[],decider=None,scan=None,install_path=None,shell=False): | |
145 | ext_in=Utils.to_list(ext_in) | |
146 | ext_out=Utils.to_list(ext_out) | |
147 | if not name: | |
148 | name=rule | |
149 | cls=Task.task_factory(name,rule,color=color,ext_in=ext_in,ext_out=ext_out,before=before,after=after,scan=scan,shell=shell) | |
150 | def x_file(self,node): | |
151 | ext=decider and decider(self,node)or cls.ext_out | |
152 | if ext_in: | |
153 | _ext_in=ext_in[0] | |
154 | tsk=self.create_task(name,node) | |
155 | cnt=0 | |
156 | keys=self.mappings.keys()+self.__class__.mappings.keys() | |
157 | for x in ext: | |
158 | k=node.change_ext(x,ext_in=_ext_in) | |
159 | tsk.outputs.append(k) | |
160 | if reentrant!=None: | |
161 | if cnt<int(reentrant): | |
162 | self.source.append(k) | |
163 | else: | |
164 | for y in keys: | |
165 | if k.name.endswith(y): | |
166 | self.source.append(k) | |
167 | break | |
168 | cnt+=1 | |
169 | if install_path: | |
170 | self.bld.install_files(install_path,tsk.outputs) | |
171 | return tsk | |
172 | for x in cls.ext_in: | |
173 | task_gen.mappings[x]=x_file | |
174 | return x_file | |
175 | def taskgen_method(func): | |
176 | setattr(task_gen,func.__name__,func) | |
177 | return func | |
178 | def feature(*k): | |
179 | def deco(func): | |
180 | setattr(task_gen,func.__name__,func) | |
181 | for name in k: | |
182 | feats[name].update([func.__name__]) | |
183 | return func | |
184 | return deco | |
185 | def before_method(*k): | |
186 | def deco(func): | |
187 | setattr(task_gen,func.__name__,func) | |
188 | for fun_name in k: | |
189 | if not func.__name__ in task_gen.prec[fun_name]: | |
190 | task_gen.prec[fun_name].append(func.__name__) | |
191 | return func | |
192 | return deco | |
193 | before=before_method | |
194 | def after_method(*k): | |
195 | def deco(func): | |
196 | setattr(task_gen,func.__name__,func) | |
197 | for fun_name in k: | |
198 | if not fun_name in task_gen.prec[func.__name__]: | |
199 | task_gen.prec[func.__name__].append(fun_name) | |
200 | return func | |
201 | return deco | |
202 | after=after_method | |
203 | def extension(*k): | |
204 | def deco(func): | |
205 | setattr(task_gen,func.__name__,func) | |
206 | for x in k: | |
207 | task_gen.mappings[x]=func | |
208 | return func | |
209 | return deco | |
210 | def to_nodes(self,lst,path=None): | |
211 | tmp=[] | |
212 | path=path or self.path | |
213 | find=path.find_resource | |
214 | if isinstance(lst,self.path.__class__): | |
215 | lst=[lst] | |
216 | for x in Utils.to_list(lst): | |
217 | if isinstance(x,str): | |
218 | node=find(x) | |
219 | else: | |
220 | node=x | |
221 | if not node: | |
222 | raise Errors.WafError("source not found: %r in %r"%(x,self)) | |
223 | tmp.append(node) | |
224 | return tmp | |
225 | def process_source(self): | |
226 | self.source=self.to_nodes(getattr(self,'source',[])) | |
227 | for node in self.source: | |
228 | self.get_hook(node)(self,node) | |
229 | def process_rule(self): | |
230 | if not getattr(self,'rule',None): | |
231 | return | |
232 | name=str(getattr(self,'name',None)or self.target or self.rule) | |
233 | cls=Task.task_factory(name,self.rule,getattr(self,'vars',[]),shell=getattr(self,'shell',True),color=getattr(self,'color','BLUE')) | |
234 | tsk=self.create_task(name) | |
235 | if getattr(self,'target',None): | |
236 | if isinstance(self.target,str): | |
237 | self.target=self.target.split() | |
238 | if not isinstance(self.target,list): | |
239 | self.target=[self.target] | |
240 | for x in self.target: | |
241 | if isinstance(x,str): | |
242 | tsk.outputs.append(self.path.find_or_declare(x)) | |
243 | else: | |
244 | x.parent.mkdir() | |
245 | tsk.outputs.append(x) | |
246 | if getattr(self,'install_path',None): | |
247 | self.bld.install_files(self.install_path,tsk.outputs) | |
248 | if getattr(self,'source',None): | |
249 | tsk.inputs=self.to_nodes(self.source) | |
250 | self.source=[] | |
251 | if getattr(self,'scan',None): | |
252 | cls.scan=self.scan | |
253 | elif getattr(self,'deps',None): | |
254 | def scan(self): | |
255 | nodes=[] | |
256 | for x in self.generator.to_list(self.generator.deps): | |
257 | node=self.generator.path.find_resource(x) | |
258 | if not node: | |
259 | self.generator.bld.fatal('Could not find %r (was it declared?)'%x) | |
260 | nodes.append(node) | |
261 | return[nodes,[]] | |
262 | cls.scan=scan | |
263 | if getattr(self,'cwd',None): | |
264 | tsk.cwd=self.cwd | |
265 | if getattr(self,'update_outputs',None)or getattr(self,'on_results',None): | |
266 | Task.update_outputs(cls) | |
267 | if getattr(self,'always',None): | |
268 | Task.always_run(cls) | |
269 | for x in['after','before','ext_in','ext_out']: | |
270 | setattr(cls,x,getattr(self,x,[])) | |
271 | def sequence_order(self): | |
272 | if self.meths and self.meths[-1]!='sequence_order': | |
273 | self.meths.append('sequence_order') | |
274 | return | |
275 | if getattr(self,'seq_start',None): | |
276 | return | |
277 | if getattr(self.bld,'prev',None): | |
278 | self.bld.prev.post() | |
279 | for x in self.bld.prev.tasks: | |
280 | for y in self.tasks: | |
281 | y.set_run_after(x) | |
282 | self.bld.prev=self | |
283 | re_m4=re.compile('@(\w+)@',re.M) | |
284 | class subst_pc(Task.Task): | |
285 | def run(self): | |
286 | code=self.inputs[0].read() | |
287 | code=code.replace('%','%%') | |
288 | lst=[] | |
289 | def repl(match): | |
290 | g=match.group | |
291 | if g(1): | |
292 | lst.append(g(1)) | |
293 | return"%%(%s)s"%g(1) | |
294 | return'' | |
295 | code=re_m4.sub(repl,code) | |
296 | try: | |
297 | d=self.generator.dct | |
298 | except AttributeError: | |
299 | d={} | |
300 | for x in lst: | |
301 | tmp=getattr(self.generator,x,'')or self.env.get_flat(x)or self.env.get_flat(x.upper()) | |
302 | d[x]=str(tmp) | |
303 | self.outputs[0].write(code%d) | |
304 | self.generator.bld.raw_deps[self.uid()]=self.dep_vars=lst | |
305 | try:delattr(self,'cache_sig') | |
306 | except AttributeError:pass | |
307 | if getattr(self.generator,'chmod',None): | |
308 | os.chmod(self.outputs[0].abspath(),self.generator.chmod) | |
309 | def sig_vars(self): | |
310 | bld=self.generator.bld | |
311 | env=self.env | |
312 | upd=self.m.update | |
313 | vars=self.generator.bld.raw_deps.get(self.uid(),[]) | |
314 | act_sig=bld.hash_env_vars(env,vars) | |
315 | upd(act_sig) | |
316 | lst=[getattr(self.generator,x,'')for x in vars] | |
317 | upd(Utils.h_list(lst)) | |
318 | return self.m.digest() | |
319 | def add_pcfile(self,node): | |
320 | tsk=self.create_task('subst_pc',node,node.change_ext('.pc','.pc.in')) | |
321 | self.bld.install_files(getattr(self,'install_path','${LIBDIR}/pkgconfig/'),tsk.outputs) | |
322 | class subst(subst_pc): | |
323 | pass | |
324 | def process_subst(self): | |
325 | src=self.to_nodes(getattr(self,'source',[])) | |
326 | tgt=getattr(self,'target',[]) | |
327 | if isinstance(tgt,self.path.__class__): | |
328 | tgt=[tgt] | |
329 | tgt=[isinstance(x,self.path.__class__)and x or self.path.find_or_declare(x)for x in Utils.to_list(tgt)] | |
330 | if len(src)!=len(tgt): | |
331 | raise Errors.WafError('invalid source or target for %r'%self) | |
332 | for x,y in zip(src,tgt): | |
333 | if not(x and y): | |
334 | raise Errors.WafError('invalid source or target for %r'%self) | |
335 | tsk=self.create_task('subst',x,y) | |
336 | for a in('after','before','ext_in','ext_out'): | |
337 | val=getattr(self,a,None) | |
338 | if val: | |
339 | setattr(tsk,a,val) | |
340 | inst_to=getattr(self,'install_path',None) | |
341 | if inst_to: | |
342 | self.bld.install_files(inst_to,tgt,chmod=getattr(self,'chmod',Utils.O644)) | |
343 | self.source=[] | |
344 | ||
345 | taskgen_method(to_nodes) | |
346 | feature('*')(process_source) | |
347 | feature('*')(process_rule) | |
348 | before_method('process_source')(process_rule) | |
349 | feature('seq')(sequence_order) | |
350 | extension('.pc.in')(add_pcfile) | |
351 | feature('subst')(process_subst) | |
352 | before_method('process_source','process_rule')(process_subst)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib.Configure import conf | |
5 | def find_ar(conf): | |
6 | conf.load('ar') | |
7 | def configure(conf): | |
8 | conf.find_program('ar',var='AR') | |
9 | conf.env.ARFLAGS='rcs' | |
10 | ||
11 | conf(find_ar)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib import Task,Utils | |
6 | import waflib.Task | |
7 | from waflib.Tools.ccroot import link_task,stlink_task | |
8 | from waflib.TaskGen import extension,feature | |
9 | class asm(Task.Task): | |
10 | color='BLUE' | |
11 | run_str='${AS} ${ASFLAGS} ${CPPPATH_ST:INCPATHS} ${AS_SRC_F}${SRC} ${AS_TGT_F}${TGT}' | |
12 | def asm_hook(self,node): | |
13 | return self.create_compiled_task('asm',node) | |
14 | class asmprogram(link_task): | |
15 | run_str='${ASLINK} ${ASLINKFLAGS} ${ASLNK_TGT_F}${TGT} ${ASLNK_SRC_F}${SRC}' | |
16 | ext_out=['.bin'] | |
17 | inst_to='${BINDIR}' | |
18 | chmod=Utils.O755 | |
19 | class asmshlib(asmprogram): | |
20 | inst_to='${LIBDIR}' | |
21 | class asmstlib(stlink_task): | |
22 | pass | |
23 | ||
24 | extension('.s','.S','.asm','.ASM','.spp','.SPP')(asm_hook)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import Task | |
5 | from waflib.TaskGen import extension | |
6 | class bison(Task.Task): | |
7 | color='BLUE' | |
8 | run_str='${BISON} ${BISONFLAGS} ${SRC[0].abspath()} -o ${TGT[0].name}' | |
9 | ext_out=['.h'] | |
10 | def big_bison(self,node): | |
11 | has_h='-d'in self.env['BISONFLAGS'] | |
12 | outs=[] | |
13 | if node.name.endswith('.yc'): | |
14 | outs.append(node.change_ext('.tab.cc')) | |
15 | if has_h: | |
16 | outs.append(node.change_ext('.tab.hh')) | |
17 | else: | |
18 | outs.append(node.change_ext('.tab.c')) | |
19 | if has_h: | |
20 | outs.append(node.change_ext('.tab.h')) | |
21 | tsk=self.create_task('bison',node,outs) | |
22 | tsk.cwd=node.parent.get_bld().abspath() | |
23 | self.source.append(outs[0]) | |
24 | def configure(conf): | |
25 | conf.find_program('bison',var='BISON') | |
26 | conf.env.BISONFLAGS=['-d'] | |
27 | ||
28 | extension('.y','.yc','.yy')(big_bison)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import TaskGen,Task,Utils | |
5 | from waflib.Tools import c_preproc | |
6 | from waflib.Tools.ccroot import link_task,stlink_task | |
7 | def c_hook(self,node): | |
8 | return self.create_compiled_task('c',node) | |
9 | class c(Task.Task): | |
10 | run_str='${CC} ${ARCH_ST:ARCH} ${CFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CC_SRC_F}${SRC} ${CC_TGT_F}${TGT}' | |
11 | vars=['CCDEPS'] | |
12 | ext_in=['.h'] | |
13 | scan=c_preproc.scan | |
14 | Task.classes['cc']=cc=c | |
15 | class cprogram(link_task): | |
16 | run_str='${LINK_CC} ${LINKFLAGS} ${CCLNK_SRC_F}${SRC} ${CCLNK_TGT_F}${TGT[0].abspath()} ${RPATH_ST:RPATH} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${FRAMEWORK_ST:FRAMEWORK} ${ARCH_ST:ARCH} ${STLIB_MARKER} ${STLIBPATH_ST:STLIBPATH} ${STLIB_ST:STLIB} ${SHLIB_MARKER} ${LIBPATH_ST:LIBPATH} ${LIB_ST:LIB}' | |
17 | ext_out=['.bin'] | |
18 | vars=['LINKDEPS'] | |
19 | inst_to='${BINDIR}' | |
20 | chmod=Utils.O755 | |
21 | class cshlib(cprogram): | |
22 | inst_to='${LIBDIR}' | |
23 | class cstlib(stlink_task): | |
24 | pass | |
25 | ||
26 | TaskGen.extension('.c')(c_hook)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,re | |
5 | from waflib import Utils,Build | |
6 | from waflib.Configure import conf | |
7 | def get_extensions(lst): | |
8 | ret=[] | |
9 | for x in Utils.to_list(lst): | |
10 | try: | |
11 | if not isinstance(x,str): | |
12 | x=x.name | |
13 | ret.append(x[x.rfind('.')+1:]) | |
14 | except: | |
15 | pass | |
16 | return ret | |
17 | def sniff_features(**kw): | |
18 | exts=get_extensions(kw['source']) | |
19 | type=kw['_type'] | |
20 | feats=[] | |
21 | if'cxx'in exts or'cpp'in exts or'c++'in exts or'cc'in exts or'C'in exts: | |
22 | feats.append('cxx') | |
23 | if'c'in exts or'vala'in exts: | |
24 | feats.append('c') | |
25 | if'd'in exts: | |
26 | feats.append('d') | |
27 | if'java'in exts: | |
28 | feats.append('java') | |
29 | if'java'in exts: | |
30 | return'java' | |
31 | if type in['program','shlib','stlib']: | |
32 | for x in feats: | |
33 | if x in['cxx','d','c']: | |
34 | feats.append(x+type) | |
35 | return feats | |
36 | def set_features(kw,_type): | |
37 | kw['_type']=_type | |
38 | kw['features']=Utils.to_list(kw.get('features',[]))+Utils.to_list(sniff_features(**kw)) | |
39 | def program(bld,*k,**kw): | |
40 | set_features(kw,'program') | |
41 | return bld(*k,**kw) | |
42 | def shlib(bld,*k,**kw): | |
43 | set_features(kw,'shlib') | |
44 | return bld(*k,**kw) | |
45 | def stlib(bld,*k,**kw): | |
46 | set_features(kw,'stlib') | |
47 | return bld(*k,**kw) | |
48 | def objects(bld,*k,**kw): | |
49 | set_features(kw,'objects') | |
50 | return bld(*k,**kw) | |
51 | ||
52 | conf(program) | |
53 | conf(shlib) | |
54 | conf(stlib) | |
55 | conf(objects)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import os,imp,sys,re,shlex,shutil | |
7 | from waflib import Build,Utils,Configure,Task,Options,Logs,TaskGen,Errors,ConfigSet,Runner | |
8 | from waflib.TaskGen import before_method,after_method,feature | |
9 | from waflib.Configure import conf | |
10 | WAF_CONFIG_H='config.h' | |
11 | DEFKEYS='define_key' | |
12 | INCKEYS='include_key' | |
13 | cfg_ver={'atleast-version':'>=','exact-version':'==','max-version':'<=',} | |
14 | SNIP_FUNCTION=''' | |
15 | int main() { | |
16 | void *p; | |
17 | p=(void*)(%s); | |
18 | return 0; | |
19 | } | |
20 | ''' | |
21 | SNIP_TYPE=''' | |
22 | int main() { | |
23 | if ((%(type_name)s *) 0) return 0; | |
24 | if (sizeof (%(type_name)s)) return 0; | |
25 | } | |
26 | ''' | |
27 | SNIP_CLASS=''' | |
28 | int main() { | |
29 | if ( | |
30 | } | |
31 | ''' | |
32 | SNIP_EMPTY_PROGRAM=''' | |
33 | int main() { | |
34 | return 0; | |
35 | } | |
36 | ''' | |
37 | SNIP_FIELD=''' | |
38 | int main() { | |
39 | char *off; | |
40 | off = (char*) &((%(type_name)s*)0)->%(field_name)s; | |
41 | return (size_t) off < sizeof(%(type_name)s); | |
42 | } | |
43 | ''' | |
44 | 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'} | |
45 | MACRO_TO_DEST_CPU={'__x86_64__':'x86_64','__i386__':'x86','__ia64__':'ia','__mips__':'mips','__sparc__':'sparc','__alpha__':'alpha','__arm__':'arm','__hppa__':'hppa','__powerpc__':'powerpc',} | |
46 | def parse_flags(self,line,uselib,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 | while lst: | |
56 | x=lst.pop(0) | |
57 | st=x[:2] | |
58 | ot=x[2:] | |
59 | if st=='-I'or st=='/I': | |
60 | if not ot:ot=lst.pop(0) | |
61 | appu('INCLUDES_'+uselib,[ot]) | |
62 | elif st=='-include': | |
63 | tmp=[x,lst.pop(0)] | |
64 | app('CFLAGS',tmp) | |
65 | app('CXXFLAGS',tmp) | |
66 | elif st=='-D'or(self.env.CXX_NAME=='msvc'and st=='/D'): | |
67 | if not ot:ot=lst.pop(0) | |
68 | app('DEFINES_'+uselib,[ot]) | |
69 | elif st=='-l': | |
70 | if not ot:ot=lst.pop(0) | |
71 | prefix=force_static and'STLIB_'or'LIB_' | |
72 | appu(prefix+uselib,[ot]) | |
73 | elif st=='-L': | |
74 | if not ot:ot=lst.pop(0) | |
75 | appu('LIBPATH_'+uselib,[ot]) | |
76 | elif x=='-pthread'or x.startswith('+')or x.startswith('-std'): | |
77 | app('CFLAGS_'+uselib,[x]) | |
78 | app('CXXFLAGS_'+uselib,[x]) | |
79 | app('LINKFLAGS_'+uselib,[x]) | |
80 | elif x=='-framework': | |
81 | appu('FRAMEWORK_'+uselib,[lst.pop(0)]) | |
82 | elif x.startswith('-F'): | |
83 | appu('FRAMEWORKPATH_'+uselib,[x[2:]]) | |
84 | elif x.startswith('-Wl'): | |
85 | app('LINKFLAGS_'+uselib,[x]) | |
86 | elif x.startswith('-m')or x.startswith('-f')or x.startswith('-dynamic'): | |
87 | app('CFLAGS_'+uselib,[x]) | |
88 | app('CXXFLAGS_'+uselib,[x]) | |
89 | elif x.startswith('-bundle'): | |
90 | app('LINKFLAGS_'+uselib,[x]) | |
91 | elif x.startswith('-undefined'): | |
92 | arg=lst.pop(0) | |
93 | app('LINKFLAGS_'+uselib,[x,arg]) | |
94 | elif x.startswith('-arch')or x.startswith('-isysroot'): | |
95 | tmp=[x,lst.pop(0)] | |
96 | app('CFLAGS_'+uselib,tmp) | |
97 | app('CXXFLAGS_'+uselib,tmp) | |
98 | app('LINKFLAGS_'+uselib,tmp) | |
99 | elif x.endswith('.a')or x.endswith('.so')or x.endswith('.dylib'): | |
100 | appu('LINKFLAGS_'+uselib,[x]) | |
101 | def ret_msg(self,f,kw): | |
102 | if isinstance(f,str): | |
103 | return f | |
104 | return f(kw) | |
105 | def validate_cfg(self,kw): | |
106 | if not'path'in kw: | |
107 | if not self.env.PKGCONFIG: | |
108 | self.find_program('pkg-config',var='PKGCONFIG') | |
109 | kw['path']=self.env.PKGCONFIG | |
110 | if'atleast_pkgconfig_version'in kw: | |
111 | if not'msg'in kw: | |
112 | kw['msg']='Checking for pkg-config version >= %r'%kw['atleast_pkgconfig_version'] | |
113 | return | |
114 | if not'okmsg'in kw: | |
115 | kw['okmsg']='yes' | |
116 | if not'errmsg'in kw: | |
117 | kw['errmsg']='not found' | |
118 | if'modversion'in kw: | |
119 | if not'msg'in kw: | |
120 | kw['msg']='Checking for %r version'%kw['modversion'] | |
121 | return | |
122 | for x in cfg_ver.keys(): | |
123 | y=x.replace('-','_') | |
124 | if y in kw: | |
125 | if not'package'in kw: | |
126 | raise ValueError('%s requires a package'%x) | |
127 | if not'msg'in kw: | |
128 | kw['msg']='Checking for %r %s %s'%(kw['package'],cfg_ver[x],kw[y]) | |
129 | return | |
130 | if not'msg'in kw: | |
131 | kw['msg']='Checking for %r'%(kw['package']or kw['path']) | |
132 | def exec_cfg(self,kw): | |
133 | if'atleast_pkgconfig_version'in kw: | |
134 | cmd=[kw['path'],'--atleast-pkgconfig-version=%s'%kw['atleast_pkgconfig_version']] | |
135 | self.cmd_and_log(cmd) | |
136 | if not'okmsg'in kw: | |
137 | kw['okmsg']='yes' | |
138 | return | |
139 | for x in cfg_ver: | |
140 | y=x.replace('-','_') | |
141 | if y in kw: | |
142 | self.cmd_and_log([kw['path'],'--%s=%s'%(x,kw[y]),kw['package']]) | |
143 | if not'okmsg'in kw: | |
144 | kw['okmsg']='yes' | |
145 | self.define(self.have_define(kw.get('uselib_store',kw['package'])),1,0) | |
146 | break | |
147 | if'modversion'in kw: | |
148 | version=self.cmd_and_log([kw['path'],'--modversion',kw['modversion']]).strip() | |
149 | self.define('%s_VERSION'%Utils.quote_define_name(kw.get('uselib_store',kw['modversion'])),version) | |
150 | return version | |
151 | lst=[kw['path']] | |
152 | defi=kw.get('define_variable',None) | |
153 | if not defi: | |
154 | defi=self.env.PKG_CONFIG_DEFINES or{} | |
155 | for key,val in defi.items(): | |
156 | lst.append('--define-variable=%s=%s'%(key,val)) | |
157 | if kw['package']: | |
158 | lst.extend(Utils.to_list(kw['package'])) | |
159 | if'variables'in kw: | |
160 | env=kw.get('env',self.env) | |
161 | uselib=kw.get('uselib_store',kw['package'].upper()) | |
162 | vars=Utils.to_list(kw['variables']) | |
163 | for v in vars: | |
164 | val=self.cmd_and_log(lst+['--variable='+v]).strip() | |
165 | var='%s_%s'%(uselib,v) | |
166 | env[var]=val | |
167 | if not'okmsg'in kw: | |
168 | kw['okmsg']='yes' | |
169 | return | |
170 | static=False | |
171 | if'args'in kw: | |
172 | args=Utils.to_list(kw['args']) | |
173 | if'--static'in args or'--static-libs'in args: | |
174 | static=True | |
175 | lst+=args | |
176 | ret=self.cmd_and_log(lst) | |
177 | if not'okmsg'in kw: | |
178 | kw['okmsg']='yes' | |
179 | self.define(self.have_define(kw.get('uselib_store',kw['package'])),1,0) | |
180 | self.parse_flags(ret,kw.get('uselib_store',kw['package'].upper()),kw.get('env',self.env),force_static=static) | |
181 | return ret | |
182 | def check_cfg(self,*k,**kw): | |
183 | if k: | |
184 | lst=k[0].split() | |
185 | kw['package']=lst[0] | |
186 | kw['args']=' '.join(lst[1:]) | |
187 | self.validate_cfg(kw) | |
188 | if'msg'in kw: | |
189 | self.start_msg(kw['msg']) | |
190 | ret=None | |
191 | try: | |
192 | ret=self.exec_cfg(kw) | |
193 | except self.errors.WafError ,e: | |
194 | if'errmsg'in kw: | |
195 | self.end_msg(kw['errmsg'],'YELLOW') | |
196 | if Logs.verbose>1: | |
197 | raise | |
198 | else: | |
199 | self.fatal('The configuration failed') | |
200 | else: | |
201 | kw['success']=ret | |
202 | if'okmsg'in kw: | |
203 | self.end_msg(self.ret_msg(kw['okmsg'],kw)) | |
204 | return ret | |
205 | def validate_c(self,kw): | |
206 | if not'env'in kw: | |
207 | kw['env']=self.env.derive() | |
208 | env=kw['env'] | |
209 | if not'compiler'in kw and not'features'in kw: | |
210 | kw['compiler']='c' | |
211 | if env['CXX_NAME']and Task.classes.get('cxx',None): | |
212 | kw['compiler']='cxx' | |
213 | if not self.env['CXX']: | |
214 | self.fatal('a c++ compiler is required') | |
215 | else: | |
216 | if not self.env['CC']: | |
217 | self.fatal('a c compiler is required') | |
218 | if not'compile_mode'in kw: | |
219 | kw['compile_mode']='c' | |
220 | if'cxx'in Utils.to_list(kw.get('features',[]))or kw.get('compiler','')=='cxx': | |
221 | kw['compile_mode']='cxx' | |
222 | if not'type'in kw: | |
223 | kw['type']='cprogram' | |
224 | if not'features'in kw: | |
225 | kw['features']=[kw['compile_mode'],kw['type']] | |
226 | else: | |
227 | kw['features']=Utils.to_list(kw['features']) | |
228 | if not'compile_filename'in kw: | |
229 | kw['compile_filename']='test.c'+((kw['compile_mode']=='cxx')and'pp'or'') | |
230 | def to_header(dct): | |
231 | if'header_name'in dct: | |
232 | dct=Utils.to_list(dct['header_name']) | |
233 | return''.join(['#include <%s>\n'%x for x in dct]) | |
234 | return'' | |
235 | if'framework_name'in kw: | |
236 | fwkname=kw['framework_name'] | |
237 | if not'uselib_store'in kw: | |
238 | kw['uselib_store']=fwkname.upper() | |
239 | if not kw.get('no_header',False): | |
240 | if not'header_name'in kw: | |
241 | kw['header_name']=[] | |
242 | fwk='%s/%s.h'%(fwkname,fwkname) | |
243 | if kw.get('remove_dot_h',None): | |
244 | fwk=fwk[:-2] | |
245 | kw['header_name']=Utils.to_list(kw['header_name'])+[fwk] | |
246 | kw['msg']='Checking for framework %s'%fwkname | |
247 | kw['framework']=fwkname | |
248 | if'function_name'in kw: | |
249 | fu=kw['function_name'] | |
250 | if not'msg'in kw: | |
251 | kw['msg']='Checking for function %s'%fu | |
252 | kw['code']=to_header(kw)+SNIP_FUNCTION%fu | |
253 | if not'uselib_store'in kw: | |
254 | kw['uselib_store']=fu.upper() | |
255 | if not'define_name'in kw: | |
256 | kw['define_name']=self.have_define(fu) | |
257 | elif'type_name'in kw: | |
258 | tu=kw['type_name'] | |
259 | if not'header_name'in kw: | |
260 | kw['header_name']='stdint.h' | |
261 | if'field_name'in kw: | |
262 | field=kw['field_name'] | |
263 | kw['code']=to_header(kw)+SNIP_FIELD%{'type_name':tu,'field_name':field} | |
264 | if not'msg'in kw: | |
265 | kw['msg']='Checking for field %s in %s'%(field,tu) | |
266 | if not'define_name'in kw: | |
267 | kw['define_name']=self.have_define((tu+'_'+field).upper()) | |
268 | else: | |
269 | kw['code']=to_header(kw)+SNIP_TYPE%{'type_name':tu} | |
270 | if not'msg'in kw: | |
271 | kw['msg']='Checking for type %s'%tu | |
272 | if not'define_name'in kw: | |
273 | kw['define_name']=self.have_define(tu.upper()) | |
274 | elif'header_name'in kw: | |
275 | if not'msg'in kw: | |
276 | kw['msg']='Checking for header %s'%kw['header_name'] | |
277 | l=Utils.to_list(kw['header_name']) | |
278 | assert len(l)>0,'list of headers in header_name is empty' | |
279 | kw['code']=to_header(kw)+SNIP_EMPTY_PROGRAM | |
280 | if not'uselib_store'in kw: | |
281 | kw['uselib_store']=l[0].upper() | |
282 | if not'define_name'in kw: | |
283 | kw['define_name']=self.have_define(l[0]) | |
284 | if'lib'in kw: | |
285 | if not'msg'in kw: | |
286 | kw['msg']='Checking for library %s'%kw['lib'] | |
287 | if not'uselib_store'in kw: | |
288 | kw['uselib_store']=kw['lib'].upper() | |
289 | if'stlib'in kw: | |
290 | if not'msg'in kw: | |
291 | kw['msg']='Checking for static library %s'%kw['stlib'] | |
292 | if not'uselib_store'in kw: | |
293 | kw['uselib_store']=kw['stlib'].upper() | |
294 | if'fragment'in kw: | |
295 | kw['code']=kw['fragment'] | |
296 | if not'msg'in kw: | |
297 | kw['msg']='Checking for code snippet' | |
298 | if not'errmsg'in kw: | |
299 | kw['errmsg']='no' | |
300 | for(flagsname,flagstype)in[('cxxflags','compiler'),('cflags','compiler'),('linkflags','linker')]: | |
301 | if flagsname in kw: | |
302 | if not'msg'in kw: | |
303 | kw['msg']='Checking for %s flags %s'%(flagstype,kw[flagsname]) | |
304 | if not'errmsg'in kw: | |
305 | kw['errmsg']='no' | |
306 | if not'execute'in kw: | |
307 | kw['execute']=False | |
308 | if kw['execute']: | |
309 | kw['features'].append('test_exec') | |
310 | if not'errmsg'in kw: | |
311 | kw['errmsg']='not found' | |
312 | if not'okmsg'in kw: | |
313 | kw['okmsg']='yes' | |
314 | if not'code'in kw: | |
315 | kw['code']=SNIP_EMPTY_PROGRAM | |
316 | if self.env[INCKEYS]: | |
317 | kw['code']='\n'.join(['#include <%s>'%x for x in self.env[INCKEYS]])+'\n'+kw['code'] | |
318 | if not kw.get('success'):kw['success']=None | |
319 | if'define_name'in kw: | |
320 | self.undefine(kw['define_name']) | |
321 | assert'msg'in kw,'invalid parameters, read http://freehackers.org/~tnagy/wafbook/single.html#config_helpers_c' | |
322 | def post_check(self,*k,**kw): | |
323 | is_success=0 | |
324 | if kw['execute']: | |
325 | if kw['success']is not None: | |
326 | if kw.get('define_ret',False): | |
327 | is_success=kw['success'] | |
328 | else: | |
329 | is_success=(kw['success']==0) | |
330 | else: | |
331 | is_success=(kw['success']==0) | |
332 | if'define_name'in kw: | |
333 | if'header_name'in kw or'function_name'in kw or'type_name'in kw or'fragment'in kw: | |
334 | nm=kw['define_name'] | |
335 | if kw['execute']and kw.get('define_ret',None)and isinstance(is_success,str): | |
336 | self.define(kw['define_name'],is_success,quote=kw.get('quote',1)) | |
337 | else: | |
338 | self.define_cond(kw['define_name'],is_success) | |
339 | else: | |
340 | self.define_cond(kw['define_name'],is_success) | |
341 | if'header_name'in kw: | |
342 | if kw.get('auto_add_header_name',False): | |
343 | self.env.append_value(INCKEYS,Utils.to_list(kw['header_name'])) | |
344 | if is_success and'uselib_store'in kw: | |
345 | from waflib.Tools import ccroot | |
346 | _vars=set([]) | |
347 | for x in kw['features']: | |
348 | if x in ccroot.USELIB_VARS: | |
349 | _vars|=ccroot.USELIB_VARS[x] | |
350 | for k in _vars: | |
351 | lk=k.lower() | |
352 | if k=='INCLUDES':lk='includes' | |
353 | if k=='DEFINES':lk='defines' | |
354 | if lk in kw: | |
355 | val=kw[lk] | |
356 | if isinstance(val,str): | |
357 | val=val.rstrip(os.path.sep) | |
358 | self.env.append_unique(k+'_'+kw['uselib_store'],val) | |
359 | return is_success | |
360 | def check(self,*k,**kw): | |
361 | self.validate_c(kw) | |
362 | self.start_msg(kw['msg']) | |
363 | ret=None | |
364 | try: | |
365 | ret=self.run_c_code(*k,**kw) | |
366 | except self.errors.ConfigurationError ,e: | |
367 | self.end_msg(kw['errmsg'],'YELLOW') | |
368 | if Logs.verbose>1: | |
369 | raise | |
370 | else: | |
371 | self.fatal('The configuration failed') | |
372 | else: | |
373 | kw['success']=ret | |
374 | self.end_msg(self.ret_msg(kw['okmsg'],kw)) | |
375 | ret=self.post_check(*k,**kw) | |
376 | if not ret: | |
377 | self.fatal('The configuration failed %r'%ret) | |
378 | return ret | |
379 | class test_exec(Task.Task): | |
380 | color='PINK' | |
381 | def run(self): | |
382 | if getattr(self.generator,'rpath',None): | |
383 | if getattr(self.generator,'define_ret',False): | |
384 | self.generator.bld.retval=self.generator.bld.cmd_and_log([self.inputs[0].abspath()]) | |
385 | else: | |
386 | self.generator.bld.retval=self.generator.bld.exec_command([self.inputs[0].abspath()]) | |
387 | else: | |
388 | env=self.env.env or{} | |
389 | env.update(dict(os.environ)) | |
390 | for var in('LD_LIBRARY_PATH','DYLD_LIBRARY_PATH','PATH'): | |
391 | env[var]=self.inputs[0].parent.abspath()+os.path.pathsep+env.get(var,'') | |
392 | if getattr(self.generator,'define_ret',False): | |
393 | self.generator.bld.retval=self.generator.bld.cmd_and_log([self.inputs[0].abspath()],env=env) | |
394 | else: | |
395 | self.generator.bld.retval=self.generator.bld.exec_command([self.inputs[0].abspath()],env=env) | |
396 | def test_exec_fun(self): | |
397 | self.create_task('test_exec',self.link_task.outputs[0]) | |
398 | CACHE_RESULTS=1 | |
399 | COMPILE_ERRORS=2 | |
400 | def run_c_code(self,*k,**kw): | |
401 | lst=[str(v)for(p,v)in kw.items()if p!='env'] | |
402 | h=Utils.h_list(lst) | |
403 | dir=self.bldnode.abspath()+os.sep+(not Utils.is_win32 and'.'or'')+'conf_check_'+Utils.to_hex(h) | |
404 | try: | |
405 | os.makedirs(dir) | |
406 | except: | |
407 | pass | |
408 | try: | |
409 | os.stat(dir) | |
410 | except: | |
411 | self.fatal('cannot use the configuration test folder %r'%dir) | |
412 | cachemode=getattr(Options.options,'confcache',None) | |
413 | if cachemode==CACHE_RESULTS: | |
414 | try: | |
415 | proj=ConfigSet.ConfigSet(os.path.join(dir,'cache_run_c_code')) | |
416 | ret=proj['cache_run_c_code'] | |
417 | except: | |
418 | pass | |
419 | else: | |
420 | if isinstance(ret,str)and ret.startswith('Test does not build'): | |
421 | self.fatal(ret) | |
422 | return ret | |
423 | bdir=os.path.join(dir,'testbuild') | |
424 | if not os.path.exists(bdir): | |
425 | os.makedirs(bdir) | |
426 | self.test_bld=bld=Build.BuildContext(top_dir=dir,out_dir=bdir) | |
427 | bld.init_dirs() | |
428 | bld.progress_bar=0 | |
429 | bld.targets='*' | |
430 | if kw['compile_filename']: | |
431 | node=bld.srcnode.make_node(kw['compile_filename']) | |
432 | node.write(kw['code']) | |
433 | bld.logger=self.logger | |
434 | bld.all_envs.update(self.all_envs) | |
435 | bld.env=kw['env'] | |
436 | o=bld(features=kw['features'],source=kw['compile_filename'],target='testprog') | |
437 | for k,v in kw.items(): | |
438 | setattr(o,k,v) | |
439 | self.to_log("==>\n%s\n<=="%kw['code']) | |
440 | bld.targets='*' | |
441 | ret=-1 | |
442 | try: | |
443 | try: | |
444 | bld.compile() | |
445 | except Errors.WafError: | |
446 | ret='Test does not build: %s'%Utils.ex_stack() | |
447 | self.fatal(ret) | |
448 | else: | |
449 | ret=getattr(bld,'retval',0) | |
450 | finally: | |
451 | proj=ConfigSet.ConfigSet() | |
452 | proj['cache_run_c_code']=ret | |
453 | proj.store(os.path.join(dir,'cache_run_c_code')) | |
454 | return ret | |
455 | def check_cxx(self,*k,**kw): | |
456 | kw['compiler']='cxx' | |
457 | return self.check(*k,**kw) | |
458 | def check_cc(self,*k,**kw): | |
459 | kw['compiler']='c' | |
460 | return self.check(*k,**kw) | |
461 | def define(self,key,val,quote=True): | |
462 | assert key and isinstance(key,str) | |
463 | if isinstance(val,int)or isinstance(val,float): | |
464 | s='%s=%s' | |
465 | else: | |
466 | s=quote and'%s="%s"'or'%s=%s' | |
467 | app=s%(key,str(val)) | |
468 | ban=key+'=' | |
469 | lst=self.env['DEFINES'] | |
470 | for x in lst: | |
471 | if x.startswith(ban): | |
472 | lst[lst.index(x)]=app | |
473 | break | |
474 | else: | |
475 | self.env.append_value('DEFINES',app) | |
476 | self.env.append_unique(DEFKEYS,key) | |
477 | def undefine(self,key): | |
478 | assert key and isinstance(key,str) | |
479 | ban=key+'=' | |
480 | lst=[x for x in self.env['DEFINES']if not x.startswith(ban)] | |
481 | self.env['DEFINES']=lst | |
482 | self.env.append_unique(DEFKEYS,key) | |
483 | def define_cond(self,key,val): | |
484 | assert key and isinstance(key,str) | |
485 | if val: | |
486 | self.define(key,1) | |
487 | else: | |
488 | self.undefine(key) | |
489 | def is_defined(self,key): | |
490 | assert key and isinstance(key,str) | |
491 | ban=key+'=' | |
492 | for x in self.env['DEFINES']: | |
493 | if x.startswith(ban): | |
494 | return True | |
495 | return False | |
496 | def get_define(self,key): | |
497 | assert key and isinstance(key,str) | |
498 | ban=key+'=' | |
499 | for x in self.env['DEFINES']: | |
500 | if x.startswith(ban): | |
501 | return x[len(ban):] | |
502 | return None | |
503 | def have_define(self,key): | |
504 | return self.__dict__.get('HAVE_PAT','HAVE_%s')%Utils.quote_define_name(key) | |
505 | def write_config_header(self,configfile='',guard='',top=False,env=None,defines=True,headers=False,remove=True): | |
506 | if not configfile:configfile=WAF_CONFIG_H | |
507 | waf_guard=guard or'_%s_WAF'%Utils.quote_define_name(configfile) | |
508 | node=top and self.bldnode or self.path.get_bld() | |
509 | node=node.make_node(configfile) | |
510 | node.parent.mkdir() | |
511 | lst=['/* WARNING! All changes made to this file will be lost! */\n'] | |
512 | lst.append('#ifndef %s\n#define %s\n'%(waf_guard,waf_guard)) | |
513 | lst.append(self.get_config_header(defines,headers)) | |
514 | lst.append('\n#endif /* %s */\n'%waf_guard) | |
515 | node.write('\n'.join(lst)) | |
516 | env=env or self.env | |
517 | env.append_unique(Build.CFG_FILES,[node.abspath()]) | |
518 | if remove: | |
519 | for key in self.env[DEFKEYS]: | |
520 | self.undefine(key) | |
521 | self.env[DEFKEYS]=[] | |
522 | def get_config_header(self,defines=True,headers=False): | |
523 | lst=[] | |
524 | if headers: | |
525 | for x in self.env[INCKEYS]: | |
526 | lst.append('#include <%s>'%x) | |
527 | if defines: | |
528 | for x in self.env[DEFKEYS]: | |
529 | if self.is_defined(x): | |
530 | val=self.get_define(x) | |
531 | lst.append('#define %s %s'%(x,val)) | |
532 | else: | |
533 | lst.append('/* #undef %s */'%x) | |
534 | return"\n".join(lst) | |
535 | def cc_add_flags(conf): | |
536 | conf.add_os_flags('CPPFLAGS','CFLAGS') | |
537 | conf.add_os_flags('CFLAGS') | |
538 | def cxx_add_flags(conf): | |
539 | conf.add_os_flags('CPPFLAGS','CXXFLAGS') | |
540 | conf.add_os_flags('CXXFLAGS') | |
541 | def link_add_flags(conf): | |
542 | conf.add_os_flags('LINKFLAGS') | |
543 | conf.add_os_flags('LDFLAGS','LINKFLAGS') | |
544 | def cc_load_tools(conf): | |
545 | if not conf.env.DEST_OS: | |
546 | conf.env.DEST_OS=Utils.unversioned_sys_platform() | |
547 | conf.load('c') | |
548 | def cxx_load_tools(conf): | |
549 | if not conf.env.DEST_OS: | |
550 | conf.env.DEST_OS=Utils.unversioned_sys_platform() | |
551 | conf.load('cxx') | |
552 | def get_cc_version(conf,cc,gcc=False,icc=False): | |
553 | cmd=cc+['-dM','-E','-'] | |
554 | env=conf.env.env or None | |
555 | try: | |
556 | p=Utils.subprocess.Popen(cmd,stdin=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE,stderr=Utils.subprocess.PIPE,env=env) | |
557 | p.stdin.write('\n') | |
558 | out=p.communicate()[0] | |
559 | except: | |
560 | conf.fatal('Could not determine the compiler version %r'%cmd) | |
561 | if not isinstance(out,str): | |
562 | out=out.decode(sys.stdout.encoding) | |
563 | if gcc: | |
564 | if out.find('__INTEL_COMPILER')>=0: | |
565 | conf.fatal('The intel compiler pretends to be gcc') | |
566 | if out.find('__GNUC__')<0: | |
567 | conf.fatal('Could not determine the compiler type') | |
568 | if icc and out.find('__INTEL_COMPILER')<0: | |
569 | conf.fatal('Not icc/icpc') | |
570 | k={} | |
571 | if icc or gcc: | |
572 | out=out.split('\n') | |
573 | for line in out: | |
574 | lst=shlex.split(line) | |
575 | if len(lst)>2: | |
576 | key=lst[1] | |
577 | val=lst[2] | |
578 | k[key]=val | |
579 | def isD(var): | |
580 | return var in k | |
581 | def isT(var): | |
582 | return var in k and k[var]!='0' | |
583 | if not conf.env.DEST_OS: | |
584 | conf.env.DEST_OS='' | |
585 | for i in MACRO_TO_DESTOS: | |
586 | if isD(i): | |
587 | conf.env.DEST_OS=MACRO_TO_DESTOS[i] | |
588 | break | |
589 | else: | |
590 | if isD('__APPLE__')and isD('__MACH__'): | |
591 | conf.env.DEST_OS='darwin' | |
592 | elif isD('__unix__'): | |
593 | conf.env.DEST_OS='generic' | |
594 | if isD('__ELF__'): | |
595 | conf.env.DEST_BINFMT='elf' | |
596 | elif isD('__WINNT__')or isD('__CYGWIN__'): | |
597 | conf.env.DEST_BINFMT='pe' | |
598 | conf.env.LIBDIR=conf.env['PREFIX']+'/bin' | |
599 | elif isD('__APPLE__'): | |
600 | conf.env.DEST_BINFMT='mac-o' | |
601 | if not conf.env.DEST_BINFMT: | |
602 | conf.env.DEST_BINFMT=Utils.destos_to_binfmt(conf.env.DEST_OS) | |
603 | for i in MACRO_TO_DEST_CPU: | |
604 | if isD(i): | |
605 | conf.env.DEST_CPU=MACRO_TO_DEST_CPU[i] | |
606 | break | |
607 | Logs.debug('ccroot: dest platform: '+' '.join([conf.env[x]or'?'for x in('DEST_OS','DEST_BINFMT','DEST_CPU')])) | |
608 | if icc: | |
609 | ver=k['__INTEL_COMPILER'] | |
610 | conf.env['CC_VERSION']=(ver[:-2],ver[-2],ver[-1]) | |
611 | else: | |
612 | conf.env['CC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__']) | |
613 | return k | |
614 | def get_xlc_version(conf,cc): | |
615 | version_re=re.compile(r"IBM XL C/C\+\+.*, V(?P<major>\d*)\.(?P<minor>\d*)",re.I).search | |
616 | cmd=cc+['-qversion'] | |
617 | try: | |
618 | out,err=conf.cmd_and_log(cmd,output=0) | |
619 | except Errors.WafError: | |
620 | conf.fatal('Could not find xlc %r'%cmd) | |
621 | if out:match=version_re(out) | |
622 | else:match=version_re(err) | |
623 | if not match: | |
624 | conf.fatal('Could not determine the XLC version.') | |
625 | k=match.groupdict() | |
626 | conf.env['CC_VERSION']=(k['major'],k['minor']) | |
627 | def add_as_needed(self): | |
628 | if self.env.DEST_BINFMT=='elf'and'gcc'in(self.env.CXX_NAME,self.env.CC_NAME): | |
629 | self.env.append_unique('LINKFLAGS','--as-needed') | |
630 | class cfgtask(Task.TaskBase): | |
631 | def display(self): | |
632 | return'' | |
633 | def runnable_status(self): | |
634 | return Task.RUN_ME | |
635 | def run(self): | |
636 | conf=self.conf | |
637 | bld=Build.BuildContext(top_dir=conf.srcnode.abspath(),out_dir=conf.bldnode.abspath()) | |
638 | bld.env=conf.env | |
639 | bld.init_dirs() | |
640 | bld.in_msg=1 | |
641 | bld.logger=self.logger | |
642 | try: | |
643 | bld.check(**self.args) | |
644 | except: | |
645 | return 1 | |
646 | def multicheck(self,*k,**kw): | |
647 | self.start_msg(kw.get('msg','Executing %d configuration tests'%len(k))) | |
648 | class par(object): | |
649 | def __init__(self): | |
650 | self.keep=False | |
651 | self.cache_global=Options.cache_global | |
652 | self.nocache=Options.options.nocache | |
653 | self.returned_tasks=[] | |
654 | def total(self): | |
655 | return len(tasks) | |
656 | def to_log(self,*k,**kw): | |
657 | return | |
658 | bld=par() | |
659 | tasks=[] | |
660 | for dct in k: | |
661 | x=cfgtask(bld=bld) | |
662 | tasks.append(x) | |
663 | x.args=dct | |
664 | x.bld=bld | |
665 | x.conf=self | |
666 | x.args=dct | |
667 | x.logger=Logs.make_mem_logger(str(id(x)),self.logger) | |
668 | def it(): | |
669 | yield tasks | |
670 | while 1: | |
671 | yield[] | |
672 | p=Runner.Parallel(bld,Options.options.jobs) | |
673 | p.biter=it() | |
674 | p.start() | |
675 | for x in tasks: | |
676 | x.logger.memhandler.flush() | |
677 | for x in tasks: | |
678 | if x.hasrun!=Task.SUCCESS: | |
679 | self.end_msg(kw.get('errmsg','no'),color='YELLOW') | |
680 | self.fatal(kw.get('fatalmsg',None)or'One of the tests has failed, see the config.log for more information') | |
681 | self.end_msg('ok') | |
682 | ||
683 | conf(parse_flags) | |
684 | conf(ret_msg) | |
685 | conf(validate_cfg) | |
686 | conf(exec_cfg) | |
687 | conf(check_cfg) | |
688 | conf(validate_c) | |
689 | conf(post_check) | |
690 | conf(check) | |
691 | feature('test_exec')(test_exec_fun) | |
692 | after_method('apply_link')(test_exec_fun) | |
693 | conf(run_c_code) | |
694 | conf(check_cxx) | |
695 | conf(check_cc) | |
696 | conf(define) | |
697 | conf(undefine) | |
698 | conf(define_cond) | |
699 | conf(is_defined) | |
700 | conf(get_define) | |
701 | conf(have_define) | |
702 | conf(write_config_header) | |
703 | conf(get_config_header) | |
704 | conf(cc_add_flags) | |
705 | conf(cxx_add_flags) | |
706 | conf(link_add_flags) | |
707 | conf(cc_load_tools) | |
708 | conf(cxx_load_tools) | |
709 | conf(get_cc_version) | |
710 | conf(get_xlc_version) | |
711 | conf(add_as_needed) | |
712 | conf(multicheck)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,shutil,sys,platform | |
5 | from waflib import TaskGen,Task,Build,Options,Utils,Errors | |
6 | from waflib.TaskGen import taskgen_method,feature,after_method,before_method | |
7 | app_info=''' | |
8 | <?xml version="1.0" encoding="UTF-8"?> | |
9 | <!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd"> | |
10 | <plist version="0.9"> | |
11 | <dict> | |
12 | <key>CFBundlePackageType</key> | |
13 | <string>APPL</string> | |
14 | <key>CFBundleGetInfoString</key> | |
15 | <string>Created by Waf</string> | |
16 | <key>CFBundleSignature</key> | |
17 | <string>????</string> | |
18 | <key>NOTE</key> | |
19 | <string>THIS IS A GENERATED FILE, DO NOT MODIFY</string> | |
20 | <key>CFBundleExecutable</key> | |
21 | <string>%s</string> | |
22 | </dict> | |
23 | </plist> | |
24 | ''' | |
25 | def set_macosx_deployment_target(self): | |
26 | if self.env['MACOSX_DEPLOYMENT_TARGET']: | |
27 | os.environ['MACOSX_DEPLOYMENT_TARGET']=self.env['MACOSX_DEPLOYMENT_TARGET'] | |
28 | elif'MACOSX_DEPLOYMENT_TARGET'not in os.environ: | |
29 | if Utils.unversioned_sys_platform()=='darwin': | |
30 | os.environ['MACOSX_DEPLOYMENT_TARGET']='.'.join(platform.mac_ver()[0].split('.')[:2]) | |
31 | def create_bundle_dirs(self,name,out): | |
32 | bld=self.bld | |
33 | dir=out.parent.find_or_declare(name) | |
34 | dir.mkdir() | |
35 | macos=dir.find_or_declare(['Contents','MacOS']) | |
36 | macos.mkdir() | |
37 | return dir | |
38 | def bundle_name_for_output(out): | |
39 | name=out.name | |
40 | k=name.rfind('.') | |
41 | if k>=0: | |
42 | name=name[:k]+'.app' | |
43 | else: | |
44 | name=name+'.app' | |
45 | return name | |
46 | def create_task_macapp(self): | |
47 | if self.env['MACAPP']or getattr(self,'mac_app',False): | |
48 | out=self.link_task.outputs[0] | |
49 | name=bundle_name_for_output(out) | |
50 | dir=self.create_bundle_dirs(name,out) | |
51 | n1=dir.find_or_declare(['Contents','MacOS',out.name]) | |
52 | self.apptask=self.create_task('macapp',self.link_task.outputs,n1) | |
53 | inst_to=getattr(self,'install_path','/Applications')+'/%s/Contents/MacOS/'%name | |
54 | self.bld.install_files(inst_to,n1,chmod=Utils.O755) | |
55 | if getattr(self,'mac_resources',None): | |
56 | res_dir=n1.parent.parent.make_node('Resources') | |
57 | inst_to=getattr(self,'install_path','/Applications')+'/%s/Resources'%name | |
58 | for x in self.to_list(self.mac_resources): | |
59 | node=self.path.find_node(x) | |
60 | if not node: | |
61 | raise Errors.WafError('Missing mac_resource %r in %r'%(x,self)) | |
62 | parent=node.parent | |
63 | if os.path.isdir(node.abspath()): | |
64 | nodes=node.ant_glob('**') | |
65 | else: | |
66 | nodes=[node] | |
67 | for node in nodes: | |
68 | rel=node.path_from(parent) | |
69 | tsk=self.create_task('macapp',node,res_dir.make_node(rel)) | |
70 | self.bld.install_as(inst_to+'/%s'%rel,node) | |
71 | if getattr(self.bld,'is_install',None): | |
72 | self.install_task.hasrun=Task.SKIP_ME | |
73 | def create_task_macplist(self): | |
74 | if self.env['MACAPP']or getattr(self,'mac_app',False): | |
75 | out=self.link_task.outputs[0] | |
76 | name=bundle_name_for_output(out) | |
77 | dir=self.create_bundle_dirs(name,out) | |
78 | n1=dir.find_or_declare(['Contents','Info.plist']) | |
79 | self.plisttask=plisttask=self.create_task('macplist',[],n1) | |
80 | if getattr(self,'mac_plist',False): | |
81 | node=self.path.find_resource(self.mac_plist) | |
82 | if node: | |
83 | plisttask.inputs.append(node) | |
84 | else: | |
85 | plisttask.code=self.mac_plist | |
86 | else: | |
87 | plisttask.code=app_info%self.link_task.outputs[0].name | |
88 | inst_to=getattr(self,'install_path','/Applications')+'/%s/Contents/'%name | |
89 | self.bld.install_files(inst_to,n1) | |
90 | def apply_bundle(self): | |
91 | if self.env['MACBUNDLE']or getattr(self,'mac_bundle',False): | |
92 | self.env['LINKFLAGS_cshlib']=self.env['LINKFLAGS_cxxshlib']=[] | |
93 | self.env['cshlib_PATTERN']=self.env['cxxshlib_PATTERN']=self.env['macbundle_PATTERN'] | |
94 | use=self.use=self.to_list(getattr(self,'use',[])) | |
95 | if not'MACBUNDLE'in use: | |
96 | use.append('MACBUNDLE') | |
97 | app_dirs=['Contents','Contents/MacOS','Contents/Resources'] | |
98 | class macapp(Task.Task): | |
99 | color='PINK' | |
100 | def run(self): | |
101 | self.outputs[0].parent.mkdir() | |
102 | shutil.copy2(self.inputs[0].srcpath(),self.outputs[0].abspath()) | |
103 | class macplist(Task.Task): | |
104 | color='PINK' | |
105 | ext_in=['.bin'] | |
106 | def run(self): | |
107 | if getattr(self,'code',None): | |
108 | txt=self.code | |
109 | else: | |
110 | txt=self.inputs[0].read() | |
111 | self.outputs[0].write(txt) | |
112 | ||
113 | feature('c','cxx')(set_macosx_deployment_target) | |
114 | taskgen_method(create_bundle_dirs) | |
115 | feature('cprogram','cxxprogram')(create_task_macapp) | |
116 | after_method('apply_link')(create_task_macapp) | |
117 | feature('cprogram','cxxprogram')(create_task_macplist) | |
118 | after_method('apply_link')(create_task_macplist) | |
119 | feature('cshlib','cxxshlib')(apply_bundle) | |
120 | before_method('apply_link','propagate_uselib_vars')(apply_bundle)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import re,sys,os,string,traceback | |
7 | from waflib import Logs,Build,Utils,Errors | |
8 | from waflib.Logs import debug,error | |
9 | class PreprocError(Errors.WafError): | |
10 | pass | |
11 | POPFILE='-' | |
12 | recursion_limit=150 | |
13 | go_absolute=False | |
14 | standard_includes=['/usr/include'] | |
15 | if Utils.is_win32: | |
16 | standard_includes=[] | |
17 | use_trigraphs=0 | |
18 | strict_quotes=0 | |
19 | g_optrans={'not':'!','and':'&&','bitand':'&','and_eq':'&=','or':'||','bitor':'|','or_eq':'|=','xor':'^','xor_eq':'^=','compl':'~',} | |
20 | re_lines=re.compile('^[ \t]*(#|%:)[ \t]*(ifdef|ifndef|if|else|elif|endif|include|import|define|undef|pragma)[ \t]*(.*)\r*$',re.IGNORECASE|re.MULTILINE) | |
21 | re_mac=re.compile("^[a-zA-Z_]\w*") | |
22 | re_fun=re.compile('^[a-zA-Z_][a-zA-Z0-9_]*[(]') | |
23 | re_pragma_once=re.compile('^\s*once\s*',re.IGNORECASE) | |
24 | re_nl=re.compile('\\\\\r*\n',re.MULTILINE) | |
25 | re_cpp=re.compile(r"""(/\*[^*]*\*+([^/*][^*]*\*+)*/)|//[^\n]*|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)""",re.MULTILINE) | |
26 | trig_def=[('??'+a,b)for a,b in zip("=-/!'()<>",r'#~\|^[]{}')] | |
27 | chr_esc={'0':0,'a':7,'b':8,'t':9,'n':10,'f':11,'v':12,'r':13,'\\':92,"'":39} | |
28 | NUM='i' | |
29 | OP='O' | |
30 | IDENT='T' | |
31 | STR='s' | |
32 | CHAR='c' | |
33 | tok_types=[NUM,STR,IDENT,OP] | |
34 | exp_types=[r"""0[xX](?P<hex>[a-fA-F0-9]+)(?P<qual1>[uUlL]*)|L*?'(?P<char>(\\.|[^\\'])+)'|(?P<n1>\d+)[Ee](?P<exp0>[+-]*?\d+)(?P<float0>[fFlL]*)|(?P<n2>\d*\.\d+)([Ee](?P<exp1>[+-]*?\d+))?(?P<float1>[fFlL]*)|(?P<n4>\d+\.\d*)([Ee](?P<exp2>[+-]*?\d+))?(?P<float2>[fFlL]*)|(?P<oct>0*)(?P<n0>\d+)(?P<qual2>[uUlL]*)""",r'L?"([^"\\]|\\.)*"',r'[a-zA-Z_]\w*',r'%:%:|<<=|>>=|\.\.\.|<<|<%|<:|<=|>>|>=|\+\+|\+=|--|->|-=|\*=|/=|%:|%=|%>|==|&&|&=|\|\||\|=|\^=|:>|!=|##|[\(\)\{\}\[\]<>\?\|\^\*\+&=:!#;,%/\-\?\~\.]',] | |
35 | re_clexer=re.compile('|'.join(["(?P<%s>%s)"%(name,part)for name,part in zip(tok_types,exp_types)]),re.M) | |
36 | accepted='a' | |
37 | ignored='i' | |
38 | undefined='u' | |
39 | skipped='s' | |
40 | def repl(m): | |
41 | s=m.group(1) | |
42 | if s: | |
43 | return' ' | |
44 | return m.group(3)or'' | |
45 | def filter_comments(filename): | |
46 | code=Utils.readf(filename) | |
47 | if use_trigraphs: | |
48 | for(a,b)in trig_def:code=code.split(a).join(b) | |
49 | code=re_nl.sub('',code) | |
50 | code=re_cpp.sub(repl,code) | |
51 | return[(m.group(2),m.group(3))for m in re.finditer(re_lines,code)] | |
52 | prec={} | |
53 | ops=['* / %','+ -','<< >>','< <= >= >','== !=','& | ^','&& ||',','] | |
54 | for x in range(len(ops)): | |
55 | syms=ops[x] | |
56 | for u in syms.split(): | |
57 | prec[u]=x | |
58 | def trimquotes(s): | |
59 | if not s:return'' | |
60 | s=s.rstrip() | |
61 | if s[0]=="'"and s[-1]=="'":return s[1:-1] | |
62 | return s | |
63 | def reduce_nums(val_1,val_2,val_op): | |
64 | try:a=0+val_1 | |
65 | except TypeError:a=int(val_1) | |
66 | try:b=0+val_2 | |
67 | except TypeError:b=int(val_2) | |
68 | d=val_op | |
69 | if d=='%':c=a%b | |
70 | elif d=='+':c=a+b | |
71 | elif d=='-':c=a-b | |
72 | elif d=='*':c=a*b | |
73 | elif d=='/':c=a/b | |
74 | elif d=='^':c=a^b | |
75 | elif d=='|':c=a|b | |
76 | elif d=='||':c=int(a or b) | |
77 | elif d=='&':c=a&b | |
78 | elif d=='&&':c=int(a and b) | |
79 | elif d=='==':c=int(a==b) | |
80 | elif d=='!=':c=int(a!=b) | |
81 | elif d=='<=':c=int(a<=b) | |
82 | elif d=='<':c=int(a<b) | |
83 | elif d=='>':c=int(a>b) | |
84 | elif d=='>=':c=int(a>=b) | |
85 | elif d=='^':c=int(a^b) | |
86 | elif d=='<<':c=a<<b | |
87 | elif d=='>>':c=a>>b | |
88 | else:c=0 | |
89 | return c | |
90 | def get_num(lst): | |
91 | if not lst:raise PreprocError("empty list for get_num") | |
92 | (p,v)=lst[0] | |
93 | if p==OP: | |
94 | if v=='(': | |
95 | count_par=1 | |
96 | i=1 | |
97 | while i<len(lst): | |
98 | (p,v)=lst[i] | |
99 | if p==OP: | |
100 | if v==')': | |
101 | count_par-=1 | |
102 | if count_par==0: | |
103 | break | |
104 | elif v=='(': | |
105 | count_par+=1 | |
106 | i+=1 | |
107 | else: | |
108 | raise PreprocError("rparen expected %r"%lst) | |
109 | (num,_)=get_term(lst[1:i]) | |
110 | return(num,lst[i+1:]) | |
111 | elif v=='+': | |
112 | return get_num(lst[1:]) | |
113 | elif v=='-': | |
114 | num,lst=get_num(lst[1:]) | |
115 | return(reduce_nums('-1',num,'*'),lst) | |
116 | elif v=='!': | |
117 | num,lst=get_num(lst[1:]) | |
118 | return(int(not int(num)),lst) | |
119 | elif v=='~': | |
120 | return(~int(num),lst) | |
121 | else: | |
122 | raise PreprocError("Invalid op token %r for get_num"%lst) | |
123 | elif p==NUM: | |
124 | return v,lst[1:] | |
125 | elif p==IDENT: | |
126 | return 0,lst[1:] | |
127 | else: | |
128 | raise PreprocError("Invalid token %r for get_num"%lst) | |
129 | def get_term(lst): | |
130 | if not lst:raise PreprocError("empty list for get_term") | |
131 | num,lst=get_num(lst) | |
132 | if not lst: | |
133 | return(num,[]) | |
134 | (p,v)=lst[0] | |
135 | if p==OP: | |
136 | if v=='&&'and not num: | |
137 | return(num,[]) | |
138 | elif v=='||'and num: | |
139 | return(num,[]) | |
140 | elif v==',': | |
141 | return get_term(lst[1:]) | |
142 | elif v=='?': | |
143 | count_par=0 | |
144 | i=1 | |
145 | while i<len(lst): | |
146 | (p,v)=lst[i] | |
147 | if p==OP: | |
148 | if v==')': | |
149 | count_par-=1 | |
150 | elif v=='(': | |
151 | count_par+=1 | |
152 | elif v==':': | |
153 | if count_par==0: | |
154 | break | |
155 | i+=1 | |
156 | else: | |
157 | raise PreprocError("rparen expected %r"%lst) | |
158 | if int(num): | |
159 | return get_term(lst[1:i]) | |
160 | else: | |
161 | return get_term(lst[i+1:]) | |
162 | else: | |
163 | num2,lst=get_num(lst[1:]) | |
164 | if not lst: | |
165 | num2=reduce_nums(num,num2,v) | |
166 | return get_term([(NUM,num2)]+lst) | |
167 | p2,v2=lst[0] | |
168 | if p2!=OP: | |
169 | raise PreprocError("op expected %r"%lst) | |
170 | if prec[v2]>=prec[v]: | |
171 | num2=reduce_nums(num,num2,v) | |
172 | return get_term([(NUM,num2)]+lst) | |
173 | else: | |
174 | num3,lst=get_num(lst[1:]) | |
175 | num3=reduce_nums(num2,num3,v2) | |
176 | return get_term([(NUM,num),(p,v),(NUM,num3)]+lst) | |
177 | raise PreprocError("cannot reduce %r"%lst) | |
178 | def reduce_eval(lst): | |
179 | num,lst=get_term(lst) | |
180 | return(NUM,num) | |
181 | def stringize(lst): | |
182 | lst=[str(v2)for(p2,v2)in lst] | |
183 | return"".join(lst) | |
184 | def paste_tokens(t1,t2): | |
185 | p1=None | |
186 | if t1[0]==OP and t2[0]==OP: | |
187 | p1=OP | |
188 | elif t1[0]==IDENT and(t2[0]==IDENT or t2[0]==NUM): | |
189 | p1=IDENT | |
190 | elif t1[0]==NUM and t2[0]==NUM: | |
191 | p1=NUM | |
192 | if not p1: | |
193 | raise PreprocError('tokens do not make a valid paste %r and %r'%(t1,t2)) | |
194 | return(p1,t1[1]+t2[1]) | |
195 | def reduce_tokens(lst,defs,ban=[]): | |
196 | i=0 | |
197 | while i<len(lst): | |
198 | (p,v)=lst[i] | |
199 | if p==IDENT and v=="defined": | |
200 | del lst[i] | |
201 | if i<len(lst): | |
202 | (p2,v2)=lst[i] | |
203 | if p2==IDENT: | |
204 | if v2 in defs: | |
205 | lst[i]=(NUM,1) | |
206 | else: | |
207 | lst[i]=(NUM,0) | |
208 | elif p2==OP and v2=='(': | |
209 | del lst[i] | |
210 | (p2,v2)=lst[i] | |
211 | del lst[i] | |
212 | if v2 in defs: | |
213 | lst[i]=(NUM,1) | |
214 | else: | |
215 | lst[i]=(NUM,0) | |
216 | else: | |
217 | raise PreprocError("Invalid define expression %r"%lst) | |
218 | elif p==IDENT and v in defs: | |
219 | if isinstance(defs[v],str): | |
220 | a,b=extract_macro(defs[v]) | |
221 | defs[v]=b | |
222 | macro_def=defs[v] | |
223 | to_add=macro_def[1] | |
224 | if isinstance(macro_def[0],list): | |
225 | del lst[i] | |
226 | for x in range(len(to_add)): | |
227 | lst.insert(i,to_add[x]) | |
228 | i+=1 | |
229 | else: | |
230 | args=[] | |
231 | del lst[i] | |
232 | if i>=len(lst): | |
233 | raise PreprocError("expected '(' after %r (got nothing)"%v) | |
234 | (p2,v2)=lst[i] | |
235 | if p2!=OP or v2!='(': | |
236 | raise PreprocError("expected '(' after %r"%v) | |
237 | del lst[i] | |
238 | one_param=[] | |
239 | count_paren=0 | |
240 | while i<len(lst): | |
241 | p2,v2=lst[i] | |
242 | del lst[i] | |
243 | if p2==OP and count_paren==0: | |
244 | if v2=='(': | |
245 | one_param.append((p2,v2)) | |
246 | count_paren+=1 | |
247 | elif v2==')': | |
248 | if one_param:args.append(one_param) | |
249 | break | |
250 | elif v2==',': | |
251 | if not one_param:raise PreprocError("empty param in funcall %s"%p) | |
252 | args.append(one_param) | |
253 | one_param=[] | |
254 | else: | |
255 | one_param.append((p2,v2)) | |
256 | else: | |
257 | one_param.append((p2,v2)) | |
258 | if v2=='(':count_paren+=1 | |
259 | elif v2==')':count_paren-=1 | |
260 | else: | |
261 | raise PreprocError('malformed macro') | |
262 | accu=[] | |
263 | arg_table=macro_def[0] | |
264 | j=0 | |
265 | while j<len(to_add): | |
266 | (p2,v2)=to_add[j] | |
267 | if p2==OP and v2=='#': | |
268 | if j+1<len(to_add)and to_add[j+1][0]==IDENT and to_add[j+1][1]in arg_table: | |
269 | toks=args[arg_table[to_add[j+1][1]]] | |
270 | accu.append((STR,stringize(toks))) | |
271 | j+=1 | |
272 | else: | |
273 | accu.append((p2,v2)) | |
274 | elif p2==OP and v2=='##': | |
275 | if accu and j+1<len(to_add): | |
276 | t1=accu[-1] | |
277 | if to_add[j+1][0]==IDENT and to_add[j+1][1]in arg_table: | |
278 | toks=args[arg_table[to_add[j+1][1]]] | |
279 | if toks: | |
280 | accu[-1]=paste_tokens(t1,toks[0]) | |
281 | accu.extend(toks[1:]) | |
282 | else: | |
283 | accu.append((p2,v2)) | |
284 | accu.extend(toks) | |
285 | elif to_add[j+1][0]==IDENT and to_add[j+1][1]=='__VA_ARGS__': | |
286 | va_toks=[] | |
287 | st=len(macro_def[0]) | |
288 | pt=len(args) | |
289 | for x in args[pt-st+1:]: | |
290 | va_toks.extend(x) | |
291 | va_toks.append((OP,',')) | |
292 | if va_toks:va_toks.pop() | |
293 | if len(accu)>1: | |
294 | (p3,v3)=accu[-1] | |
295 | (p4,v4)=accu[-2] | |
296 | if v3=='##': | |
297 | accu.pop() | |
298 | if v4==','and pt<st: | |
299 | accu.pop() | |
300 | accu+=va_toks | |
301 | else: | |
302 | accu[-1]=paste_tokens(t1,to_add[j+1]) | |
303 | j+=1 | |
304 | else: | |
305 | accu.append((p2,v2)) | |
306 | elif p2==IDENT and v2 in arg_table: | |
307 | toks=args[arg_table[v2]] | |
308 | reduce_tokens(toks,defs,ban+[v]) | |
309 | accu.extend(toks) | |
310 | else: | |
311 | accu.append((p2,v2)) | |
312 | j+=1 | |
313 | reduce_tokens(accu,defs,ban+[v]) | |
314 | for x in range(len(accu)-1,-1,-1): | |
315 | lst.insert(i,accu[x]) | |
316 | i+=1 | |
317 | def eval_macro(lst,defs): | |
318 | reduce_tokens(lst,defs,[]) | |
319 | if not lst:raise PreprocError("missing tokens to evaluate") | |
320 | (p,v)=reduce_eval(lst) | |
321 | return int(v)!=0 | |
322 | def extract_macro(txt): | |
323 | t=tokenize(txt) | |
324 | if re_fun.search(txt): | |
325 | p,name=t[0] | |
326 | p,v=t[1] | |
327 | if p!=OP:raise PreprocError("expected open parenthesis") | |
328 | i=1 | |
329 | pindex=0 | |
330 | params={} | |
331 | prev='(' | |
332 | while 1: | |
333 | i+=1 | |
334 | p,v=t[i] | |
335 | if prev=='(': | |
336 | if p==IDENT: | |
337 | params[v]=pindex | |
338 | pindex+=1 | |
339 | prev=p | |
340 | elif p==OP and v==')': | |
341 | break | |
342 | else: | |
343 | raise PreprocError("unexpected token (3)") | |
344 | elif prev==IDENT: | |
345 | if p==OP and v==',': | |
346 | prev=v | |
347 | elif p==OP and v==')': | |
348 | break | |
349 | else: | |
350 | raise PreprocError("comma or ... expected") | |
351 | elif prev==',': | |
352 | if p==IDENT: | |
353 | params[v]=pindex | |
354 | pindex+=1 | |
355 | prev=p | |
356 | elif p==OP and v=='...': | |
357 | raise PreprocError("not implemented (1)") | |
358 | else: | |
359 | raise PreprocError("comma or ... expected (2)") | |
360 | elif prev=='...': | |
361 | raise PreprocError("not implemented (2)") | |
362 | else: | |
363 | raise PreprocError("unexpected else") | |
364 | return(name,[params,t[i+1:]]) | |
365 | else: | |
366 | (p,v)=t[0] | |
367 | return(v,[[],t[1:]]) | |
368 | re_include=re.compile('^\s*(<(?P<a>.*)>|"(?P<b>.*)")') | |
369 | def extract_include(txt,defs): | |
370 | m=re_include.search(txt) | |
371 | if m: | |
372 | if m.group('a'):return'<',m.group('a') | |
373 | if m.group('b'):return'"',m.group('b') | |
374 | toks=tokenize(txt) | |
375 | reduce_tokens(toks,defs,['waf_include']) | |
376 | if not toks: | |
377 | raise PreprocError("could not parse include %s"%txt) | |
378 | if len(toks)==1: | |
379 | if toks[0][0]==STR: | |
380 | return'"',toks[0][1] | |
381 | else: | |
382 | if toks[0][1]=='<'and toks[-1][1]=='>': | |
383 | return stringize(toks).lstrip('<').rstrip('>') | |
384 | raise PreprocError("could not parse include %s."%txt) | |
385 | def parse_char(txt): | |
386 | if not txt:raise PreprocError("attempted to parse a null char") | |
387 | if txt[0]!='\\': | |
388 | return ord(txt) | |
389 | c=txt[1] | |
390 | if c=='x': | |
391 | if len(txt)==4 and txt[3]in string.hexdigits:return int(txt[2:],16) | |
392 | return int(txt[2:],16) | |
393 | elif c.isdigit(): | |
394 | if c=='0'and len(txt)==2:return 0 | |
395 | for i in 3,2,1: | |
396 | if len(txt)>i and txt[1:1+i].isdigit(): | |
397 | return(1+i,int(txt[1:1+i],8)) | |
398 | else: | |
399 | try:return chr_esc[c] | |
400 | except KeyError:raise PreprocError("could not parse char literal '%s'"%txt) | |
401 | def tokenize(s): | |
402 | ret=[] | |
403 | for match in re_clexer.finditer(s): | |
404 | m=match.group | |
405 | for name in tok_types: | |
406 | v=m(name) | |
407 | if v: | |
408 | if name==IDENT: | |
409 | try:v=g_optrans[v];name=OP | |
410 | except KeyError: | |
411 | if v.lower()=="true": | |
412 | v=1 | |
413 | name=NUM | |
414 | elif v.lower()=="false": | |
415 | v=0 | |
416 | name=NUM | |
417 | elif name==NUM: | |
418 | if m('oct'):v=int(v,8) | |
419 | elif m('hex'):v=int(m('hex'),16) | |
420 | elif m('n0'):v=m('n0') | |
421 | else: | |
422 | v=m('char') | |
423 | if v:v=parse_char(v) | |
424 | else:v=m('n2')or m('n4') | |
425 | elif name==OP: | |
426 | if v=='%:':v='#' | |
427 | elif v=='%:%:':v='##' | |
428 | elif name==STR: | |
429 | v=v[1:-1] | |
430 | ret.append((name,v)) | |
431 | break | |
432 | return ret | |
433 | def define_name(line): | |
434 | return re_mac.match(line).group(0) | |
435 | class c_parser(object): | |
436 | def __init__(self,nodepaths=None,defines=None): | |
437 | self.lines=[] | |
438 | if defines is None: | |
439 | self.defs={} | |
440 | else: | |
441 | self.defs=dict(defines) | |
442 | self.state=[] | |
443 | self.count_files=0 | |
444 | self.currentnode_stack=[] | |
445 | self.nodepaths=nodepaths or[] | |
446 | self.nodes=[] | |
447 | self.names=[] | |
448 | self.curfile='' | |
449 | self.ban_includes=set([]) | |
450 | def cached_find_resource(self,node,filename): | |
451 | try: | |
452 | nd=node.ctx.cache_nd | |
453 | except: | |
454 | nd=node.ctx.cache_nd={} | |
455 | tup=(node,filename) | |
456 | try: | |
457 | return nd[tup] | |
458 | except KeyError: | |
459 | ret=node.find_resource(filename) | |
460 | if ret: | |
461 | if getattr(ret,'children',None): | |
462 | ret=None | |
463 | elif ret.is_child_of(node.ctx.bldnode): | |
464 | tmp=node.ctx.srcnode.search(ret.path_from(node.ctx.bldnode)) | |
465 | if tmp and getattr(tmp,'children',None): | |
466 | ret=None | |
467 | nd[tup]=ret | |
468 | return ret | |
469 | def tryfind(self,filename): | |
470 | self.curfile=filename | |
471 | found=self.cached_find_resource(self.currentnode_stack[-1],filename) | |
472 | for n in self.nodepaths: | |
473 | if found: | |
474 | break | |
475 | found=self.cached_find_resource(n,filename) | |
476 | if found: | |
477 | self.nodes.append(found) | |
478 | if filename[-4:]!='.moc': | |
479 | self.addlines(found) | |
480 | else: | |
481 | if not filename in self.names: | |
482 | self.names.append(filename) | |
483 | return found | |
484 | def addlines(self,node): | |
485 | self.currentnode_stack.append(node.parent) | |
486 | filepath=node.abspath() | |
487 | self.count_files+=1 | |
488 | if self.count_files>recursion_limit: | |
489 | raise PreprocError("recursion limit exceeded") | |
490 | pc=self.parse_cache | |
491 | debug('preproc: reading file %r',filepath) | |
492 | try: | |
493 | lns=pc[filepath] | |
494 | except KeyError: | |
495 | pass | |
496 | else: | |
497 | self.lines.extend(lns) | |
498 | return | |
499 | try: | |
500 | lines=filter_comments(filepath) | |
501 | lines.append((POPFILE,'')) | |
502 | lines.reverse() | |
503 | pc[filepath]=lines | |
504 | self.lines.extend(lines) | |
505 | except IOError: | |
506 | raise PreprocError("could not read the file %s"%filepath) | |
507 | except Exception: | |
508 | if Logs.verbose>0: | |
509 | error("parsing %s failed"%filepath) | |
510 | traceback.print_exc() | |
511 | def start(self,node,env): | |
512 | debug('preproc: scanning %s (in %s)',node.name,node.parent.name) | |
513 | bld=node.ctx | |
514 | try: | |
515 | self.parse_cache=bld.parse_cache | |
516 | except AttributeError: | |
517 | bld.parse_cache={} | |
518 | self.parse_cache=bld.parse_cache | |
519 | self.addlines(node) | |
520 | if env['DEFINES']: | |
521 | try: | |
522 | lst=['%s %s'%(x[0],trimquotes('='.join(x[1:])))for x in[y.split('=')for y in env['DEFINES']]] | |
523 | lst.reverse() | |
524 | self.lines.extend([('define',x)for x in lst]) | |
525 | except AttributeError: | |
526 | pass | |
527 | while self.lines: | |
528 | (token,line)=self.lines.pop() | |
529 | if token==POPFILE: | |
530 | self.count_files-=1 | |
531 | self.currentnode_stack.pop() | |
532 | continue | |
533 | try: | |
534 | ve=Logs.verbose | |
535 | if ve:debug('preproc: line is %s - %s state is %s',token,line,self.state) | |
536 | state=self.state | |
537 | if token[:2]=='if': | |
538 | state.append(undefined) | |
539 | elif token=='endif': | |
540 | state.pop() | |
541 | if token[0]!='e': | |
542 | if skipped in self.state or ignored in self.state: | |
543 | continue | |
544 | if token=='if': | |
545 | ret=eval_macro(tokenize(line),self.defs) | |
546 | if ret:state[-1]=accepted | |
547 | else:state[-1]=ignored | |
548 | elif token=='ifdef': | |
549 | m=re_mac.match(line) | |
550 | if m and m.group(0)in self.defs:state[-1]=accepted | |
551 | else:state[-1]=ignored | |
552 | elif token=='ifndef': | |
553 | m=re_mac.match(line) | |
554 | if m and m.group(0)in self.defs:state[-1]=ignored | |
555 | else:state[-1]=accepted | |
556 | elif token=='include'or token=='import': | |
557 | (kind,inc)=extract_include(line,self.defs) | |
558 | if inc in self.ban_includes: | |
559 | continue | |
560 | if token=='import':self.ban_includes.add(inc) | |
561 | if ve:debug('preproc: include found %s (%s) ',inc,kind) | |
562 | if kind=='"'or not strict_quotes: | |
563 | self.tryfind(inc) | |
564 | elif token=='elif': | |
565 | if state[-1]==accepted: | |
566 | state[-1]=skipped | |
567 | elif state[-1]==ignored: | |
568 | if eval_macro(tokenize(line),self.defs): | |
569 | state[-1]=accepted | |
570 | elif token=='else': | |
571 | if state[-1]==accepted:state[-1]=skipped | |
572 | elif state[-1]==ignored:state[-1]=accepted | |
573 | elif token=='define': | |
574 | try: | |
575 | self.defs[define_name(line)]=line | |
576 | except: | |
577 | raise PreprocError("Invalid define line %s"%line) | |
578 | elif token=='undef': | |
579 | m=re_mac.match(line) | |
580 | if m and m.group(0)in self.defs: | |
581 | self.defs.__delitem__(m.group(0)) | |
582 | elif token=='pragma': | |
583 | if re_pragma_once.match(line.lower()): | |
584 | self.ban_includes.add(self.curfile) | |
585 | except Exception ,e: | |
586 | if Logs.verbose: | |
587 | debug('preproc: line parsing failed (%s): %s %s',e,line,Utils.ex_stack()) | |
588 | def scan(task): | |
589 | global go_absolute | |
590 | try: | |
591 | incn=task.generator.includes_nodes | |
592 | except AttributeError: | |
593 | raise Errors.WafError('%r is missing a feature such as "c", "cxx" or "includes": '%task.generator) | |
594 | if go_absolute: | |
595 | nodepaths=incn+standard_includes | |
596 | else: | |
597 | nodepaths=[x for x in incn if x.is_child_of(x.ctx.srcnode)or x.is_child_of(x.ctx.bldnode)] | |
598 | tmp=c_parser(nodepaths) | |
599 | tmp.start(task.inputs[0],task.env) | |
600 | if Logs.verbose: | |
601 | debug('deps: deps for %r: %r; unresolved %r'%(task.inputs,tmp.nodes,tmp.names)) | |
602 | return(tmp.nodes,tmp.names) | |
603 | ||
604 | Utils.run_once(tokenize) | |
605 | Utils.run_once(define_name)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import Task | |
5 | from waflib.Configure import conf | |
6 | from waflib.TaskGen import feature,before_method,after_method | |
7 | import sys | |
8 | LIB_CODE=''' | |
9 | #ifdef _MSC_VER | |
10 | #define testEXPORT __declspec(dllexport) | |
11 | #else | |
12 | #define testEXPORT | |
13 | #endif | |
14 | testEXPORT int lib_func(void) { return 9; } | |
15 | ''' | |
16 | MAIN_CODE=''' | |
17 | #ifdef _MSC_VER | |
18 | #define testEXPORT __declspec(dllimport) | |
19 | #else | |
20 | #define testEXPORT | |
21 | #endif | |
22 | testEXPORT int lib_func(void); | |
23 | int main(void) {return !(lib_func() == 9);} | |
24 | ''' | |
25 | def link_lib_test_fun(self): | |
26 | def write_test_file(task): | |
27 | task.outputs[0].write(task.generator.code) | |
28 | rpath=[] | |
29 | if getattr(self,'add_rpath',False): | |
30 | rpath=[self.bld.path.get_bld().abspath()] | |
31 | mode=self.mode | |
32 | m='%s %s'%(mode,mode) | |
33 | ex=self.test_exec and'test_exec'or'' | |
34 | bld=self.bld | |
35 | bld(rule=write_test_file,target='test.'+mode,code=LIB_CODE) | |
36 | bld(rule=write_test_file,target='main.'+mode,code=MAIN_CODE) | |
37 | bld(features='%sshlib'%m,source='test.'+mode,target='test') | |
38 | bld(features='%sprogram %s'%(m,ex),source='main.'+mode,target='app',use='test',rpath=rpath) | |
39 | def check_library(self,mode=None,test_exec=True): | |
40 | if not mode: | |
41 | mode='c' | |
42 | if self.env.CXX: | |
43 | mode='cxx' | |
44 | self.check(compile_filename=[],features='link_lib_test',msg='Checking for libraries',mode=mode,test_exec=test_exec,) | |
45 | INLINE_CODE=''' | |
46 | typedef int foo_t; | |
47 | static %s foo_t static_foo () {return 0; } | |
48 | %s foo_t foo () { | |
49 | return 0; | |
50 | } | |
51 | ''' | |
52 | INLINE_VALUES=['inline','__inline__','__inline'] | |
53 | def check_inline(self,**kw): | |
54 | self.start_msg('Checking for inline') | |
55 | if not'define_name'in kw: | |
56 | kw['define_name']='INLINE_MACRO' | |
57 | if not'features'in kw: | |
58 | if self.env.CXX: | |
59 | kw['features']=['cxx'] | |
60 | else: | |
61 | kw['features']=['c'] | |
62 | for x in INLINE_VALUES: | |
63 | kw['fragment']=INLINE_CODE%(x,x) | |
64 | try: | |
65 | self.check(**kw) | |
66 | except self.errors.ConfigurationError: | |
67 | continue | |
68 | else: | |
69 | self.end_msg(x) | |
70 | if x!='inline': | |
71 | self.define('inline',x,quote=False) | |
72 | return x | |
73 | self.fatal('could not use inline functions') | |
74 | LARGE_FRAGMENT='#include <unistd.h>\nint main() { return !(sizeof(off_t) >= 8); }\n' | |
75 | def check_large_file(self,**kw): | |
76 | if not'define_name'in kw: | |
77 | kw['define_name']='HAVE_LARGEFILE' | |
78 | if not'execute'in kw: | |
79 | kw['execute']=True | |
80 | if not'features'in kw: | |
81 | if self.env.CXX: | |
82 | kw['features']=['cxx','cxxprogram'] | |
83 | else: | |
84 | kw['features']=['c','cprogram'] | |
85 | kw['fragment']=LARGE_FRAGMENT | |
86 | kw['msg']='Checking for large file support' | |
87 | ret=True | |
88 | try: | |
89 | if self.env.DEST_BINFMT!='pe': | |
90 | ret=self.check(**kw) | |
91 | except self.errors.ConfigurationError: | |
92 | pass | |
93 | else: | |
94 | if ret: | |
95 | return True | |
96 | kw['msg']='Checking for -D_FILE_OFFSET_BITS=64' | |
97 | kw['defines']=['_FILE_OFFSET_BITS=64'] | |
98 | try: | |
99 | ret=self.check(**kw) | |
100 | except self.errors.ConfigurationError: | |
101 | pass | |
102 | else: | |
103 | self.define('_FILE_OFFSET_BITS',64) | |
104 | return ret | |
105 | self.fatal('There is no support for large files') | |
106 | ENDIAN_FRAGMENT=''' | |
107 | short int ascii_mm[] = { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 }; | |
108 | short int ascii_ii[] = { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 }; | |
109 | int use_ascii (int i) { | |
110 | return ascii_mm[i] + ascii_ii[i]; | |
111 | } | |
112 | short int ebcdic_ii[] = { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 }; | |
113 | short int ebcdic_mm[] = { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 }; | |
114 | int use_ebcdic (int i) { | |
115 | return ebcdic_mm[i] + ebcdic_ii[i]; | |
116 | } | |
117 | extern int foo; | |
118 | ''' | |
119 | class grep_for_endianness(Task.Task): | |
120 | color='PINK' | |
121 | def run(self): | |
122 | txt=self.inputs[0].read(flags='rb').decode('iso8859-1') | |
123 | if txt.find('LiTTleEnDian')>-1: | |
124 | self.generator.tmp.append('little') | |
125 | elif txt.find('BIGenDianSyS')>-1: | |
126 | self.generator.tmp.append('big') | |
127 | else: | |
128 | return-1 | |
129 | def grep_for_endianness_fun(self): | |
130 | self.create_task('grep_for_endianness',self.compiled_tasks[0].outputs[0]) | |
131 | def check_endianness(self): | |
132 | tmp=[] | |
133 | def check_msg(self): | |
134 | return tmp[0] | |
135 | self.check(fragment=ENDIAN_FRAGMENT,features='c grep_for_endianness',msg="Checking for endianness",define='ENDIANNESS',tmp=tmp,okmsg=check_msg) | |
136 | return tmp[0] | |
137 | ||
138 | feature('link_lib_test')(link_lib_test_fun) | |
139 | before_method('process_source')(link_lib_test_fun) | |
140 | conf(check_library) | |
141 | conf(check_inline) | |
142 | conf(check_large_file) | |
143 | feature('grep_for_endianness')(grep_for_endianness_fun) | |
144 | after_method('process_source')(grep_for_endianness_fun) | |
145 | conf(check_endianness)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import os,sys,re | |
7 | from waflib import TaskGen,Task,Utils,Logs,Build,Options,Node,Errors | |
8 | from waflib.Logs import error,debug,warn | |
9 | from waflib.TaskGen import after_method,before_method,feature,taskgen_method,extension | |
10 | from waflib.Tools import c_aliases,c_preproc,c_config,c_osx,c_tests | |
11 | from waflib.Configure import conf | |
12 | USELIB_VARS=Utils.defaultdict(set) | |
13 | USELIB_VARS['c']=set(['INCLUDES','FRAMEWORKPATH','DEFINES','CPPFLAGS','CCDEPS','CFLAGS','ARCH']) | |
14 | USELIB_VARS['cxx']=set(['INCLUDES','FRAMEWORKPATH','DEFINES','CPPFLAGS','CXXDEPS','CXXFLAGS','ARCH']) | |
15 | USELIB_VARS['d']=set(['INCLUDES','DFLAGS']) | |
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['go']=set(['GOCFLAGS']) | |
23 | USELIB_VARS['goprogram']=set(['GOLFLAGS']) | |
24 | USELIB_VARS['asm']=set(['ASFLAGS']) | |
25 | def create_compiled_task(self,name,node): | |
26 | out='%s.%d.o'%(node.name,self.idx) | |
27 | task=self.create_task(name,node,node.parent.find_or_declare(out)) | |
28 | try: | |
29 | self.compiled_tasks.append(task) | |
30 | except AttributeError: | |
31 | self.compiled_tasks=[task] | |
32 | return task | |
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 | def apply_incpaths(self): | |
58 | lst=self.to_incnodes(self.to_list(getattr(self,'includes',[]))+self.env['INCLUDES']) | |
59 | self.includes_nodes=lst | |
60 | self.env['INCPATHS']=[x.abspath()for x in lst] | |
61 | class link_task(Task.Task): | |
62 | color='YELLOW' | |
63 | inst_to=None | |
64 | chmod=Utils.O644 | |
65 | def add_target(self,target): | |
66 | if isinstance(target,str): | |
67 | pattern=self.env[self.__class__.__name__+'_PATTERN'] | |
68 | if not pattern: | |
69 | pattern='%s' | |
70 | folder,name=os.path.split(target) | |
71 | if self.__class__.__name__.find('shlib')>0: | |
72 | if self.env.DEST_BINFMT=='pe'and getattr(self.generator,'vnum',None): | |
73 | name=name+'-'+self.generator.vnum.split('.')[0] | |
74 | tmp=folder+os.sep+pattern%name | |
75 | target=self.generator.path.find_or_declare(tmp) | |
76 | self.set_outputs(target) | |
77 | class stlink_task(link_task): | |
78 | run_str='${AR} ${ARFLAGS} ${AR_TGT_F}${TGT} ${AR_SRC_F}${SRC}' | |
79 | def rm_tgt(cls): | |
80 | old=cls.run | |
81 | def wrap(self): | |
82 | try:os.remove(self.outputs[0].abspath()) | |
83 | except OSError:pass | |
84 | return old(self) | |
85 | setattr(cls,'run',wrap) | |
86 | rm_tgt(stlink_task) | |
87 | def apply_link(self): | |
88 | for x in self.features: | |
89 | if x=='cprogram'and'cxx'in self.features: | |
90 | x='cxxprogram' | |
91 | elif x=='cshlib'and'cxx'in self.features: | |
92 | x='cxxshlib' | |
93 | if x in Task.classes: | |
94 | if issubclass(Task.classes[x],link_task): | |
95 | link=x | |
96 | break | |
97 | else: | |
98 | return | |
99 | objs=[t.outputs[0]for t in getattr(self,'compiled_tasks',[])] | |
100 | self.link_task=self.create_task(link,objs) | |
101 | self.link_task.add_target(self.target) | |
102 | try: | |
103 | inst_to=self.install_path | |
104 | except AttributeError: | |
105 | inst_to=self.link_task.__class__.inst_to | |
106 | if inst_to: | |
107 | self.install_task=self.bld.install_files(inst_to,self.link_task.outputs[:],env=self.env,chmod=self.link_task.chmod) | |
108 | def use_rec(self,name,**kw): | |
109 | if name in self.tmp_use_not or name in self.tmp_use_seen: | |
110 | return | |
111 | try: | |
112 | y=self.bld.get_tgen_by_name(name) | |
113 | except Errors.WafError: | |
114 | self.uselib.append(name) | |
115 | self.tmp_use_not.add(name) | |
116 | return | |
117 | self.tmp_use_seen.append(name) | |
118 | y.post() | |
119 | y.tmp_use_objects=objects=kw.get('objects',True) | |
120 | y.tmp_use_stlib=stlib=kw.get('stlib',True) | |
121 | try: | |
122 | link_task=y.link_task | |
123 | except AttributeError: | |
124 | y.tmp_use_var='' | |
125 | else: | |
126 | objects=False | |
127 | if not isinstance(y.link_task,stlink_task): | |
128 | stlib=False | |
129 | y.tmp_use_var='LIB' | |
130 | else: | |
131 | y.tmp_use_var='STLIB' | |
132 | p=self.tmp_use_prec | |
133 | for x in self.to_list(getattr(y,'use',[])): | |
134 | try: | |
135 | p[x].append(name) | |
136 | except: | |
137 | p[x]=[name] | |
138 | self.use_rec(x,objects=objects,stlib=stlib) | |
139 | def process_use(self): | |
140 | use_not=self.tmp_use_not=set([]) | |
141 | use_seen=self.tmp_use_seen=[] | |
142 | use_prec=self.tmp_use_prec={} | |
143 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
144 | self.includes=self.to_list(getattr(self,'includes',[])) | |
145 | names=self.to_list(getattr(self,'use',[])) | |
146 | for x in names: | |
147 | self.use_rec(x) | |
148 | for x in use_not: | |
149 | if x in use_prec: | |
150 | del use_prec[x] | |
151 | out=[] | |
152 | tmp=[] | |
153 | for x in self.tmp_use_seen: | |
154 | for k in use_prec.values(): | |
155 | if x in k: | |
156 | break | |
157 | else: | |
158 | tmp.append(x) | |
159 | while tmp: | |
160 | e=tmp.pop() | |
161 | out.append(e) | |
162 | try: | |
163 | nlst=use_prec[e] | |
164 | except KeyError: | |
165 | pass | |
166 | else: | |
167 | del use_prec[e] | |
168 | for x in nlst: | |
169 | for y in use_prec: | |
170 | if x in use_prec[y]: | |
171 | break | |
172 | else: | |
173 | tmp.append(x) | |
174 | if use_prec: | |
175 | raise Errors.WafError('Cycle detected in the use processing %r'%use_prec) | |
176 | out.reverse() | |
177 | link_task=getattr(self,'link_task',None) | |
178 | for x in out: | |
179 | y=self.bld.get_tgen_by_name(x) | |
180 | var=y.tmp_use_var | |
181 | if var and link_task: | |
182 | if var=='LIB'or y.tmp_use_stlib: | |
183 | self.env.append_value(var,[y.target[y.target.rfind(os.sep)+1:]]) | |
184 | self.link_task.dep_nodes.extend(y.link_task.outputs) | |
185 | tmp_path=y.link_task.outputs[0].parent.path_from(self.bld.bldnode) | |
186 | self.env.append_value(var+'PATH',[tmp_path]) | |
187 | else: | |
188 | if y.tmp_use_objects: | |
189 | self.add_objects_from_tgen(y) | |
190 | if getattr(y,'export_includes',None): | |
191 | self.includes.extend(y.to_incnodes(y.export_includes)) | |
192 | for x in names: | |
193 | try: | |
194 | y=self.bld.get_tgen_by_name(x) | |
195 | except: | |
196 | if not self.env['STLIB_'+x]and not x in self.uselib: | |
197 | self.uselib.append(x) | |
198 | else: | |
199 | for k in self.to_list(getattr(y,'uselib',[])): | |
200 | if not self.env['STLIB_'+k]and not k in self.uselib: | |
201 | self.uselib.append(k) | |
202 | def add_objects_from_tgen(self,tg): | |
203 | try: | |
204 | link_task=self.link_task | |
205 | except AttributeError: | |
206 | pass | |
207 | else: | |
208 | for tsk in getattr(tg,'compiled_tasks',[]): | |
209 | for x in tsk.outputs: | |
210 | if x.name.endswith('.o')or x.name.endswith('.obj'): | |
211 | link_task.inputs.append(x) | |
212 | def get_uselib_vars(self): | |
213 | _vars=set([]) | |
214 | for x in self.features: | |
215 | if x in USELIB_VARS: | |
216 | _vars|=USELIB_VARS[x] | |
217 | return _vars | |
218 | def propagate_uselib_vars(self): | |
219 | _vars=self.get_uselib_vars() | |
220 | env=self.env | |
221 | for x in _vars: | |
222 | y=x.lower() | |
223 | env.append_unique(x,self.to_list(getattr(self,y,[]))) | |
224 | for x in self.features: | |
225 | for var in _vars: | |
226 | compvar='%s_%s'%(var,x) | |
227 | env.append_value(var,env[compvar]) | |
228 | for x in self.to_list(getattr(self,'uselib',[])): | |
229 | for v in _vars: | |
230 | env.append_value(v,env[v+'_'+x]) | |
231 | def apply_implib(self): | |
232 | if not self.env.DEST_BINFMT=='pe': | |
233 | return | |
234 | dll=self.link_task.outputs[0] | |
235 | if isinstance(self.target,Node.Node): | |
236 | name=self.target.name | |
237 | else: | |
238 | name=os.path.split(self.target)[1] | |
239 | implib=self.env['implib_PATTERN']%name | |
240 | implib=dll.parent.find_or_declare(implib) | |
241 | self.env.append_value('LINKFLAGS',self.env['IMPLIB_ST']%implib.bldpath()) | |
242 | self.link_task.outputs.append(implib) | |
243 | if getattr(self,'defs',None)and self.env.DEST_BINFMT=='pe': | |
244 | node=self.path.find_resource(self.defs) | |
245 | if not node: | |
246 | raise Errors.WafError('invalid def file %r'%self.defs) | |
247 | if'msvc'in(self.env.CC_NAME,self.env.CXX_NAME): | |
248 | self.env.append_value('LINKFLAGS','/def:%s'%node.path_from(self.bld.bldnode)) | |
249 | self.link_task.dep_nodes.append(node) | |
250 | else: | |
251 | self.link_task.inputs.append(node) | |
252 | try: | |
253 | inst_to=self.install_path | |
254 | except AttributeError: | |
255 | inst_to=self.link_task.__class__.inst_to | |
256 | if not inst_to: | |
257 | return | |
258 | self.implib_install_task=self.bld.install_as('${PREFIX}/lib/%s'%implib.name,implib,self.env) | |
259 | def apply_vnum(self): | |
260 | if not getattr(self,'vnum','')or os.name!='posix'or self.env.DEST_BINFMT not in('elf','mac-o'): | |
261 | return | |
262 | link=self.link_task | |
263 | nums=self.vnum.split('.') | |
264 | node=link.outputs[0] | |
265 | libname=node.name | |
266 | if libname.endswith('.dylib'): | |
267 | name3=libname.replace('.dylib','.%s.dylib'%self.vnum) | |
268 | name2=libname.replace('.dylib','.%s.dylib'%nums[0]) | |
269 | else: | |
270 | name3=libname+'.'+self.vnum | |
271 | name2=libname+'.'+nums[0] | |
272 | if self.env.SONAME_ST: | |
273 | v=self.env.SONAME_ST%name2 | |
274 | self.env.append_value('LINKFLAGS',v.split()) | |
275 | tsk=self.create_task('vnum',node,[node.parent.find_or_declare(name2),node.parent.find_or_declare(name3)]) | |
276 | if getattr(self.bld,'is_install',None): | |
277 | self.install_task.hasrun=Task.SKIP_ME | |
278 | bld=self.bld | |
279 | path=self.install_task.dest | |
280 | t1=bld.install_as(path+os.sep+name3,node,env=self.env,chmod=self.link_task.chmod) | |
281 | t2=bld.symlink_as(path+os.sep+name2,name3) | |
282 | t3=bld.symlink_as(path+os.sep+libname,name3) | |
283 | self.vnum_install_task=(t1,t2,t3) | |
284 | if'-dynamiclib'in self.env['LINKFLAGS']and getattr(self,'install_task',None): | |
285 | path=os.path.join(self.install_task.get_install_path(),self.link_task.outputs[0].name) | |
286 | self.env.append_value('LINKFLAGS',['-install_name',path]) | |
287 | class vnum(Task.Task): | |
288 | color='CYAN' | |
289 | quient=True | |
290 | ext_in=['.bin'] | |
291 | def run(self): | |
292 | for x in self.outputs: | |
293 | path=x.abspath() | |
294 | try: | |
295 | os.remove(path) | |
296 | except OSError: | |
297 | pass | |
298 | try: | |
299 | os.symlink(self.inputs[0].name,path) | |
300 | except OSError: | |
301 | return 1 | |
302 | class fake_shlib(link_task): | |
303 | def runnable_status(self): | |
304 | for t in self.run_after: | |
305 | if not t.hasrun: | |
306 | return Task.ASK_LATER | |
307 | for x in self.outputs: | |
308 | x.sig=Utils.h_file(x.abspath()) | |
309 | return Task.SKIP_ME | |
310 | class fake_stlib(stlink_task): | |
311 | def runnable_status(self): | |
312 | for t in self.run_after: | |
313 | if not t.hasrun: | |
314 | return Task.ASK_LATER | |
315 | for x in self.outputs: | |
316 | x.sig=Utils.h_file(x.abspath()) | |
317 | return Task.SKIP_ME | |
318 | def read_shlib(self,name,paths=[]): | |
319 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='shlib') | |
320 | def read_stlib(self,name,paths=[]): | |
321 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='stlib') | |
322 | lib_patterns={'shlib':['lib%s.so','%s.so','lib%s.dll','%s.dll'],'stlib':['lib%s.a','%s.a','lib%s.dll','%s.dll','lib%s.lib','%s.lib'],} | |
323 | def process_lib(self): | |
324 | node=None | |
325 | names=[x%self.name for x in lib_patterns[self.lib_type]] | |
326 | for x in self.lib_paths+[self.path,'/usr/lib64','/usr/lib','/usr/local/lib64','/usr/local/lib']: | |
327 | if not isinstance(x,Node.Node): | |
328 | x=self.bld.root.find_node(x)or self.path.find_node(x) | |
329 | if not x: | |
330 | continue | |
331 | for y in names: | |
332 | node=x.find_node(y) | |
333 | if node: | |
334 | node.sig=Utils.h_file(node.abspath()) | |
335 | break | |
336 | else: | |
337 | continue | |
338 | break | |
339 | else: | |
340 | raise Errors.WafError('could not find library %r'%self.name) | |
341 | self.link_task=self.create_task('fake_%s'%self.lib_type,[],[node]) | |
342 | self.target=self.name | |
343 | class fake_o(Task.Task): | |
344 | def runnable_status(self): | |
345 | return Task.SKIP_ME | |
346 | def add_those_o_files(self,node): | |
347 | tsk=self.create_task('fake_o',[],node) | |
348 | try: | |
349 | self.compiled_tasks.append(tsk) | |
350 | except AttributeError: | |
351 | self.compiled_tasks=[tsk] | |
352 | ||
353 | taskgen_method(create_compiled_task) | |
354 | taskgen_method(to_incnodes) | |
355 | feature('c','cxx','d','go','asm','fc','includes')(apply_incpaths) | |
356 | after_method('propagate_uselib_vars','process_source')(apply_incpaths) | |
357 | feature('c','cxx','d','go','fc','asm')(apply_link) | |
358 | after_method('process_source')(apply_link) | |
359 | taskgen_method(use_rec) | |
360 | feature('c','cxx','d','use','fc')(process_use) | |
361 | before_method('apply_incpaths','propagate_uselib_vars')(process_use) | |
362 | after_method('apply_link','process_source')(process_use) | |
363 | taskgen_method(add_objects_from_tgen) | |
364 | taskgen_method(get_uselib_vars) | |
365 | feature('c','cxx','d','fc','javac','cs','uselib')(propagate_uselib_vars) | |
366 | after_method('process_use')(propagate_uselib_vars) | |
367 | feature('cshlib','cxxshlib','fcshlib')(apply_implib) | |
368 | after_method('apply_link')(apply_implib) | |
369 | feature('cshlib','cxxshlib','dshlib','fcshlib','vnum')(apply_vnum) | |
370 | after_method('apply_link')(apply_vnum) | |
371 | conf(read_shlib) | |
372 | conf(read_stlib) | |
373 | feature('fake_lib')(process_lib) | |
374 | extension('.o','.obj')(add_those_o_files)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,imp,types | |
5 | from waflib.Tools import ccroot | |
6 | from waflib import Utils,Configure | |
7 | from waflib.Logs import debug | |
8 | c_compiler={'win32':['msvc','gcc'],'cygwin':['gcc'],'darwin':['gcc'],'aix':['xlc','gcc'],'linux':['gcc','icc'],'sunos':['suncc','gcc'],'irix':['gcc','irixcc'],'hpux':['gcc'],'gnu':['gcc'],'java':['gcc','msvc','icc'],'default':['gcc'],} | |
9 | def configure(conf): | |
10 | try:test_for_compiler=conf.options.check_c_compiler | |
11 | except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_c')") | |
12 | for compiler in test_for_compiler.split(): | |
13 | conf.env.stash() | |
14 | conf.start_msg('Checking for %r (c compiler)'%compiler) | |
15 | try: | |
16 | conf.load(compiler) | |
17 | except conf.errors.ConfigurationError ,e: | |
18 | conf.env.revert() | |
19 | conf.end_msg(False) | |
20 | debug('compiler_c: %r'%e) | |
21 | else: | |
22 | if conf.env['CC']: | |
23 | conf.end_msg(conf.env.get_flat('CC')) | |
24 | conf.env['COMPILER_CC']=compiler | |
25 | break | |
26 | conf.end_msg(False) | |
27 | else: | |
28 | conf.fatal('could not configure a c compiler!') | |
29 | def options(opt): | |
30 | opt.load_special_tools('c_*.py',ban=['c_dumbpreproc.py']) | |
31 | global c_compiler | |
32 | build_platform=Utils.unversioned_sys_platform() | |
33 | possible_compiler_list=c_compiler[build_platform in c_compiler and build_platform or'default'] | |
34 | test_for_compiler=' '.join(possible_compiler_list) | |
35 | cc_compiler_opts=opt.add_option_group("C Compiler Options") | |
36 | cc_compiler_opts.add_option('--check-c-compiler',default="%s"%test_for_compiler,help='On this platform (%s) the following C-Compiler will be checked by default: "%s"'%(build_platform,test_for_compiler),dest="check_c_compiler") | |
37 | for x in test_for_compiler.split(): | |
38 | opt.load('%s'%x) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,imp,types | |
5 | from waflib.Tools import ccroot | |
6 | from waflib import Utils,Configure | |
7 | from waflib.Logs import debug | |
8 | cxx_compiler={'win32':['msvc','g++'],'cygwin':['g++'],'darwin':['g++'],'aix':['xlc++','g++'],'linux':['g++','icpc'],'sunos':['sunc++','g++'],'irix':['g++'],'hpux':['g++'],'gnu':['g++'],'java':['g++','msvc','icpc'],'default':['g++']} | |
9 | def configure(conf): | |
10 | try:test_for_compiler=conf.options.check_cxx_compiler | |
11 | except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_cxx')") | |
12 | for compiler in test_for_compiler.split(): | |
13 | conf.env.stash() | |
14 | conf.start_msg('Checking for %r (c++ compiler)'%compiler) | |
15 | try: | |
16 | conf.load(compiler) | |
17 | except conf.errors.ConfigurationError ,e: | |
18 | conf.env.revert() | |
19 | conf.end_msg(False) | |
20 | debug('compiler_cxx: %r'%e) | |
21 | else: | |
22 | if conf.env['CXX']: | |
23 | conf.end_msg(conf.env.get_flat('CXX')) | |
24 | conf.env['COMPILER_CXX']=compiler | |
25 | break | |
26 | conf.end_msg(False) | |
27 | else: | |
28 | conf.fatal('could not configure a c++ compiler!') | |
29 | def options(opt): | |
30 | opt.load_special_tools('cxx_*.py') | |
31 | global cxx_compiler | |
32 | build_platform=Utils.unversioned_sys_platform() | |
33 | possible_compiler_list=cxx_compiler[build_platform in cxx_compiler and build_platform or'default'] | |
34 | test_for_compiler=' '.join(possible_compiler_list) | |
35 | cxx_compiler_opts=opt.add_option_group('C++ Compiler Options') | |
36 | cxx_compiler_opts.add_option('--check-cxx-compiler',default="%s"%test_for_compiler,help='On this platform (%s) the following C++ Compiler will be checked by default: "%s"'%(build_platform,test_for_compiler),dest="check_cxx_compiler") | |
37 | for x in test_for_compiler.split(): | |
38 | opt.load('%s'%x) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,imp,types | |
5 | from waflib import Utils,Configure,Options,Logs | |
6 | def configure(conf): | |
7 | for compiler in conf.options.dcheck.split(','): | |
8 | conf.env.stash() | |
9 | conf.start_msg('Checking for %r (d compiler)'%compiler) | |
10 | try: | |
11 | conf.load(compiler) | |
12 | except conf.errors.ConfigurationError ,e: | |
13 | conf.env.revert() | |
14 | conf.end_msg(False) | |
15 | Logs.debug('compiler_cxx: %r'%e) | |
16 | else: | |
17 | if conf.env.D: | |
18 | conf.end_msg(conf.env.get_flat('D')) | |
19 | conf.env['COMPILER_D']=compiler | |
20 | conf.env.D_COMPILER=conf.env.D | |
21 | break | |
22 | conf.end_msg(False) | |
23 | else: | |
24 | conf.fatal('no suitable d compiler was found') | |
25 | def options(opt): | |
26 | d_compiler_opts=opt.add_option_group('D Compiler Options') | |
27 | d_compiler_opts.add_option('--check-d-compiler',default='gdc,dmd',action='store',help='check for the compiler [Default:gdc,dmd]',dest='dcheck') | |
28 | for d_compiler in['gdc','dmd']: | |
29 | opt.load('%s'%d_compiler) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,imp,types | |
5 | from waflib import Utils,Configure,Options,Logs,Errors | |
6 | from waflib.Tools import fc | |
7 | fc_compiler={'win32':['gfortran','ifort'],'darwin':['gfortran','g95','ifort'],'linux':['gfortran','g95','ifort'],'java':['gfortran','g95','ifort'],'default':['gfortran'],'aix':['gfortran']} | |
8 | def __list_possible_compiler(platform): | |
9 | try: | |
10 | return fc_compiler[platform] | |
11 | except KeyError: | |
12 | return fc_compiler["default"] | |
13 | def configure(conf): | |
14 | try:test_for_compiler=conf.options.check_fc | |
15 | except AttributeError:conf.fatal("Add options(opt): opt.load('compiler_fc')") | |
16 | for compiler in test_for_compiler.split(): | |
17 | conf.env.stash() | |
18 | conf.start_msg('Checking for %r (fortran compiler)'%compiler) | |
19 | try: | |
20 | conf.load(compiler) | |
21 | except conf.errors.ConfigurationError ,e: | |
22 | conf.env.revert() | |
23 | conf.end_msg(False) | |
24 | Logs.debug('compiler_fortran: %r'%e) | |
25 | else: | |
26 | if conf.env['FC']: | |
27 | conf.end_msg(conf.env.get_flat('FC')) | |
28 | conf.env.COMPILER_FORTRAN=compiler | |
29 | break | |
30 | conf.end_msg(False) | |
31 | else: | |
32 | conf.fatal('could not configure a fortran compiler!') | |
33 | def options(opt): | |
34 | opt.load_special_tools('fc_*.py') | |
35 | build_platform=Utils.unversioned_sys_platform() | |
36 | detected_platform=Options.platform | |
37 | possible_compiler_list=__list_possible_compiler(detected_platform) | |
38 | test_for_compiler=' '.join(possible_compiler_list) | |
39 | fortran_compiler_opts=opt.add_option_group("Fortran Compiler Options") | |
40 | fortran_compiler_opts.add_option('--check-fortran-compiler',default="%s"%test_for_compiler,help='On this platform (%s) the following Fortran Compiler will be checked by default: "%s"'%(detected_platform,test_for_compiler),dest="check_fc") | |
41 | for compiler in test_for_compiler.split(): | |
42 | opt.load('%s'%compiler) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | from waflib import Utils,Task,Options,Logs,Errors | |
7 | from waflib.TaskGen import before_method,after_method,feature | |
8 | from waflib.Tools import ccroot | |
9 | from waflib.Configure import conf | |
10 | ccroot.USELIB_VARS['cs']=set(['CSFLAGS','ASSEMBLIES','RESOURCES']) | |
11 | ccroot.lib_patterns['csshlib']=['%s'] | |
12 | def apply_cs(self): | |
13 | cs_nodes=[] | |
14 | no_nodes=[] | |
15 | for x in self.to_nodes(self.source): | |
16 | if x.name.endswith('.cs'): | |
17 | cs_nodes.append(x) | |
18 | else: | |
19 | no_nodes.append(x) | |
20 | self.source=no_nodes | |
21 | bintype=getattr(self,'type',self.gen.endswith('.dll')and'library'or'exe') | |
22 | self.cs_task=tsk=self.create_task('mcs',cs_nodes,self.path.find_or_declare(self.gen)) | |
23 | tsk.env.CSTYPE='/target:%s'%bintype | |
24 | tsk.env.OUT='/out:%s'%tsk.outputs[0].abspath() | |
25 | inst_to=getattr(self,'install_path',bintype=='exe'and'${BINDIR}'or'${LIBDIR}') | |
26 | if inst_to: | |
27 | mod=getattr(self,'chmod',bintype=='exe'and Utils.O755 or Utils.O644) | |
28 | self.install_task=self.bld.install_files(inst_to,self.cs_task.outputs[:],env=self.env,chmod=mod) | |
29 | def use_cs(self): | |
30 | names=self.to_list(getattr(self,'use',[])) | |
31 | get=self.bld.get_tgen_by_name | |
32 | for x in names: | |
33 | try: | |
34 | y=get(x) | |
35 | except Errors.WafError: | |
36 | self.cs_task.env.append_value('CSFLAGS','/reference:%s'%x) | |
37 | continue | |
38 | y.post() | |
39 | tsk=getattr(y,'cs_task',None)or getattr(y,'link_task',None) | |
40 | if not tsk: | |
41 | self.bld.fatal('cs task has no link task for use %r'%self) | |
42 | self.cs_task.dep_nodes.extend(tsk.outputs) | |
43 | self.cs_task.set_run_after(tsk) | |
44 | self.cs_task.env.append_value('CSFLAGS','/reference:%s'%tsk.outputs[0].abspath()) | |
45 | def debug_cs(self): | |
46 | csdebug=getattr(self,'csdebug',self.env.CSDEBUG) | |
47 | if not csdebug: | |
48 | return | |
49 | node=self.cs_task.outputs[0] | |
50 | if self.env.CS_NAME=='mono': | |
51 | out=node.parent.find_or_declare(node.name+'.mdb') | |
52 | else: | |
53 | out=node.change_ext('.pdb') | |
54 | self.cs_task.outputs.append(out) | |
55 | try: | |
56 | self.install_task.source.append(out) | |
57 | except AttributeError: | |
58 | pass | |
59 | if csdebug=='pdbonly': | |
60 | val=['/debug+','/debug:pdbonly'] | |
61 | elif csdebug=='full': | |
62 | val=['/debug+','/debug:full'] | |
63 | else: | |
64 | val=['/debug-'] | |
65 | self.cs_task.env.append_value('CSFLAGS',val) | |
66 | class mcs(Task.Task): | |
67 | color='YELLOW' | |
68 | run_str='${MCS} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}' | |
69 | def configure(conf): | |
70 | csc=getattr(Options.options,'cscbinary',None) | |
71 | if csc: | |
72 | conf.env.MCS=csc | |
73 | conf.find_program(['csc','mcs','gmcs'],var='MCS') | |
74 | conf.env.ASS_ST='/r:%s' | |
75 | conf.env.RES_ST='/resource:%s' | |
76 | conf.env.CS_NAME='csc' | |
77 | if str(conf.env.MCS).lower().find('mcs')>-1: | |
78 | conf.env.CS_NAME='mono' | |
79 | def options(opt): | |
80 | opt.add_option('--with-csc-binary',type='string',dest='cscbinary') | |
81 | class fake_csshlib(Task.Task): | |
82 | color='YELLOW' | |
83 | inst_to=None | |
84 | def runnable_status(self): | |
85 | for x in self.outputs: | |
86 | x.sig=Utils.h_file(x.abspath()) | |
87 | return Task.SKIP_ME | |
88 | def read_csshlib(self,name,paths=[]): | |
89 | return self(name=name,features='fake_lib',lib_paths=paths,lib_type='csshlib') | |
90 | ||
91 | feature('cs')(apply_cs) | |
92 | before_method('process_source')(apply_cs) | |
93 | feature('cs')(use_cs) | |
94 | after_method('apply_cs')(use_cs) | |
95 | feature('cs')(debug_cs) | |
96 | after_method('apply_cs','use_cs')(debug_cs) | |
97 | conf(read_csshlib)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import TaskGen,Task,Utils | |
5 | from waflib.Tools import c_preproc | |
6 | from waflib.Tools.ccroot import link_task,stlink_task | |
7 | def cxx_hook(self,node): | |
8 | return self.create_compiled_task('cxx',node) | |
9 | TaskGen.extension('.cpp','.cc','.cxx','.C','.c++')(cxx_hook) | |
10 | if not'.c'in TaskGen.task_gen.mappings: | |
11 | TaskGen.task_gen.mappings['.c']=TaskGen.task_gen.mappings['.cpp'] | |
12 | class cxx(Task.Task): | |
13 | run_str='${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${CPPFLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXX_SRC_F}${SRC} ${CXX_TGT_F}${TGT}' | |
14 | vars=['CXXDEPS'] | |
15 | ext_in=['.h'] | |
16 | scan=c_preproc.scan | |
17 | class cxxprogram(link_task): | |
18 | run_str='${LINK_CXX} ${LINKFLAGS} ${CXXLNK_SRC_F}${SRC} ${CXXLNK_TGT_F}${TGT[0].abspath()} ${RPATH_ST:RPATH} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${FRAMEWORK_ST:FRAMEWORK} ${ARCH_ST:ARCH} ${STLIB_MARKER} ${STLIBPATH_ST:STLIBPATH} ${STLIB_ST:STLIB} ${SHLIB_MARKER} ${LIBPATH_ST:LIBPATH} ${LIB_ST:LIB}' | |
19 | vars=['LINKDEPS'] | |
20 | ext_out=['.bin'] | |
21 | inst_to='${BINDIR}' | |
22 | chmod=Utils.O755 | |
23 | class cxxshlib(cxxprogram): | |
24 | inst_to='${LIBDIR}' | |
25 | class cxxstlib(stlink_task): | |
26 | pass |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import Utils,Task,Errors | |
5 | from waflib.TaskGen import taskgen_method,feature,extension | |
6 | from waflib.Tools import d_scan,d_config | |
7 | from waflib.Tools.ccroot import link_task,stlink_task | |
8 | class d(Task.Task): | |
9 | color='GREEN' | |
10 | run_str='${D} ${DFLAGS} ${DINC_ST:INCPATHS} ${D_SRC_F:SRC} ${D_TGT_F:TGT}' | |
11 | scan=d_scan.scan | |
12 | class d_with_header(d): | |
13 | run_str='${D} ${DFLAGS} ${DINC_ST:INCPATHS} ${D_HDR_F:tgt.outputs[1].bldpath()} ${D_SRC_F:SRC} ${D_TGT_F:tgt.outputs[0].bldpath()}' | |
14 | class d_header(Task.Task): | |
15 | color='BLUE' | |
16 | run_str='${D} ${D_HEADER} ${SRC}' | |
17 | class dprogram(link_task): | |
18 | run_str='${D_LINKER} ${LINKFLAGS} ${DLNK_SRC_F}${SRC} ${DLNK_TGT_F:TGT} ${RPATH_ST:RPATH} ${DSTLIB_MARKER} ${DSTLIBPATH_ST:STLIBPATH} ${DSTLIB_ST:STLIB} ${DSHLIB_MARKER} ${DLIBPATH_ST:LIBPATH} ${DSHLIB_ST:LIB}' | |
19 | inst_to='${BINDIR}' | |
20 | chmod=Utils.O755 | |
21 | class dshlib(dprogram): | |
22 | inst_to='${LIBDIR}' | |
23 | class dstlib(stlink_task): | |
24 | pass | |
25 | def d_hook(self,node): | |
26 | ext=Utils.destos_to_binfmt(self.env.DEST_OS)=='pe'and'obj'or'o' | |
27 | out='%s.%d.%s'%(node.name,self.idx,ext) | |
28 | def create_compiled_task(self,name,node): | |
29 | task=self.create_task(name,node,node.parent.find_or_declare(out)) | |
30 | try: | |
31 | self.compiled_tasks.append(task) | |
32 | except AttributeError: | |
33 | self.compiled_tasks=[task] | |
34 | return task | |
35 | if getattr(self,'generate_headers',None): | |
36 | tsk=create_compiled_task(self,'d_with_header',node) | |
37 | tsk.outputs.append(node.change_ext(self.env['DHEADER_ext'])) | |
38 | else: | |
39 | tsk=create_compiled_task(self,'d',node) | |
40 | return tsk | |
41 | def generate_header(self,filename,install_path=None): | |
42 | try: | |
43 | self.header_lst.append([filename,install_path]) | |
44 | except AttributeError: | |
45 | self.header_lst=[[filename,install_path]] | |
46 | def process_header(self): | |
47 | for i in getattr(self,'header_lst',[]): | |
48 | node=self.path.find_resource(i[0]) | |
49 | if not node: | |
50 | raise Errors.WafError('file %r not found on d obj'%i[0]) | |
51 | self.create_task('d_header',node,node.change_ext('.di')) | |
52 | ||
53 | extension('.d','.di','.D')(d_hook) | |
54 | taskgen_method(generate_header) | |
55 | feature('d')(process_header)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import Utils | |
5 | from waflib.Configure import conf | |
6 | def d_platform_flags(self): | |
7 | v=self.env | |
8 | if not v.DEST_OS: | |
9 | v.DEST_OS=Utils.unversioned_sys_platform() | |
10 | if Utils.destos_to_binfmt(self.env.DEST_OS)=='pe': | |
11 | v['dprogram_PATTERN']='%s.exe' | |
12 | v['dshlib_PATTERN']='lib%s.dll' | |
13 | v['dstlib_PATTERN']='lib%s.a' | |
14 | else: | |
15 | v['dprogram_PATTERN']='%s' | |
16 | v['dshlib_PATTERN']='lib%s.so' | |
17 | v['dstlib_PATTERN']='lib%s.a' | |
18 | DLIB=''' | |
19 | version(D_Version2) { | |
20 | import std.stdio; | |
21 | int main() { | |
22 | writefln("phobos2"); | |
23 | return 0; | |
24 | } | |
25 | } else { | |
26 | version(Tango) { | |
27 | import tango.stdc.stdio; | |
28 | int main() { | |
29 | printf("tango"); | |
30 | return 0; | |
31 | } | |
32 | } else { | |
33 | import std.stdio; | |
34 | int main() { | |
35 | writefln("phobos1"); | |
36 | return 0; | |
37 | } | |
38 | } | |
39 | } | |
40 | ''' | |
41 | def check_dlibrary(self): | |
42 | ret=self.check_cc(features='d dprogram',fragment=DLIB,compile_filename='test.d',execute=True,define_ret=True) | |
43 | self.env.DLIBRARY=ret.strip() | |
44 | ||
45 | conf(d_platform_flags) | |
46 | conf(check_dlibrary)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import re | |
5 | from waflib import Utils,Logs | |
6 | def filter_comments(filename): | |
7 | txt=Utils.readf(filename) | |
8 | i=0 | |
9 | buf=[] | |
10 | max=len(txt) | |
11 | begin=0 | |
12 | while i<max: | |
13 | c=txt[i] | |
14 | if c=='"'or c=="'": | |
15 | buf.append(txt[begin:i]) | |
16 | delim=c | |
17 | i+=1 | |
18 | while i<max: | |
19 | c=txt[i] | |
20 | if c==delim:break | |
21 | elif c=='\\': | |
22 | i+=1 | |
23 | i+=1 | |
24 | i+=1 | |
25 | begin=i | |
26 | elif c=='/': | |
27 | buf.append(txt[begin:i]) | |
28 | i+=1 | |
29 | if i==max:break | |
30 | c=txt[i] | |
31 | if c=='+': | |
32 | i+=1 | |
33 | nesting=1 | |
34 | c=None | |
35 | while i<max: | |
36 | prev=c | |
37 | c=txt[i] | |
38 | if prev=='/'and c=='+': | |
39 | nesting+=1 | |
40 | c=None | |
41 | elif prev=='+'and c=='/': | |
42 | nesting-=1 | |
43 | if nesting==0:break | |
44 | c=None | |
45 | i+=1 | |
46 | elif c=='*': | |
47 | i+=1 | |
48 | c=None | |
49 | while i<max: | |
50 | prev=c | |
51 | c=txt[i] | |
52 | if prev=='*'and c=='/':break | |
53 | i+=1 | |
54 | elif c=='/': | |
55 | i+=1 | |
56 | while i<max and txt[i]!='\n': | |
57 | i+=1 | |
58 | else: | |
59 | begin=i-1 | |
60 | continue | |
61 | i+=1 | |
62 | begin=i | |
63 | buf.append(' ') | |
64 | else: | |
65 | i+=1 | |
66 | buf.append(txt[begin:]) | |
67 | return buf | |
68 | class d_parser(object): | |
69 | def __init__(self,env,incpaths): | |
70 | self.allnames=[] | |
71 | self.re_module=re.compile("module\s+([^;]+)") | |
72 | self.re_import=re.compile("import\s+([^;]+)") | |
73 | self.re_import_bindings=re.compile("([^:]+):(.*)") | |
74 | self.re_import_alias=re.compile("[^=]+=(.+)") | |
75 | self.env=env | |
76 | self.nodes=[] | |
77 | self.names=[] | |
78 | self.incpaths=incpaths | |
79 | def tryfind(self,filename): | |
80 | found=0 | |
81 | for n in self.incpaths: | |
82 | found=n.find_resource(filename.replace('.','/')+'.d') | |
83 | if found: | |
84 | self.nodes.append(found) | |
85 | self.waiting.append(found) | |
86 | break | |
87 | if not found: | |
88 | if not filename in self.names: | |
89 | self.names.append(filename) | |
90 | def get_strings(self,code): | |
91 | self.module='' | |
92 | lst=[] | |
93 | mod_name=self.re_module.search(code) | |
94 | if mod_name: | |
95 | self.module=re.sub('\s+','',mod_name.group(1)) | |
96 | import_iterator=self.re_import.finditer(code) | |
97 | if import_iterator: | |
98 | for import_match in import_iterator: | |
99 | import_match_str=re.sub('\s+','',import_match.group(1)) | |
100 | bindings_match=self.re_import_bindings.match(import_match_str) | |
101 | if bindings_match: | |
102 | import_match_str=bindings_match.group(1) | |
103 | matches=import_match_str.split(',') | |
104 | for match in matches: | |
105 | alias_match=self.re_import_alias.match(match) | |
106 | if alias_match: | |
107 | match=alias_match.group(1) | |
108 | lst.append(match) | |
109 | return lst | |
110 | def start(self,node): | |
111 | self.waiting=[node] | |
112 | while self.waiting: | |
113 | nd=self.waiting.pop(0) | |
114 | self.iter(nd) | |
115 | def iter(self,node): | |
116 | path=node.abspath() | |
117 | code="".join(filter_comments(path)) | |
118 | names=self.get_strings(code) | |
119 | for x in names: | |
120 | if x in self.allnames:continue | |
121 | self.allnames.append(x) | |
122 | self.tryfind(x) | |
123 | def scan(self): | |
124 | env=self.env | |
125 | gruik=d_parser(env,self.generator.includes_nodes) | |
126 | node=self.inputs[0] | |
127 | gruik.start(node) | |
128 | nodes=gruik.nodes | |
129 | names=gruik.names | |
130 | if Logs.verbose: | |
131 | Logs.debug('deps: deps for %s: %r; unresolved %r'%(str(node),nodes,names)) | |
132 | return(nodes,names) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import Task,Errors | |
5 | from waflib.TaskGen import taskgen_method,before_method | |
6 | def add_dbus_file(self,filename,prefix,mode): | |
7 | if not hasattr(self,'dbus_lst'): | |
8 | self.dbus_lst=[] | |
9 | if not'process_dbus'in self.meths: | |
10 | self.meths.append('process_dbus') | |
11 | self.dbus_lst.append([filename,prefix,mode]) | |
12 | def process_dbus(self): | |
13 | for filename,prefix,mode in getattr(self,'dbus_lst',[]): | |
14 | node=self.path.find_resource(filename) | |
15 | if not node: | |
16 | raise Errors.WafError('file not found '+filename) | |
17 | tsk=self.create_task('dbus_binding_tool',node,node.change_ext('.h')) | |
18 | tsk.env.DBUS_BINDING_TOOL_PREFIX=prefix | |
19 | tsk.env.DBUS_BINDING_TOOL_MODE=mode | |
20 | class dbus_binding_tool(Task.Task): | |
21 | color='BLUE' | |
22 | ext_out=['.h'] | |
23 | run_str='${DBUS_BINDING_TOOL} --prefix=${DBUS_BINDING_TOOL_PREFIX} --mode=${DBUS_BINDING_TOOL_MODE} --output=${TGT} ${SRC}' | |
24 | shell=True | |
25 | def configure(conf): | |
26 | dbus_binding_tool=conf.find_program('dbus-binding-tool',var='DBUS_BINDING_TOOL') | |
27 | ||
28 | taskgen_method(add_dbus_file) | |
29 | before_method('apply_core')(process_dbus)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | from waflib.Tools import ar,d | |
6 | from waflib.Configure import conf | |
7 | def find_dmd(conf): | |
8 | conf.find_program(['dmd','ldc'],var='D') | |
9 | def common_flags_ldc(conf): | |
10 | v=conf.env | |
11 | v['DFLAGS']=['-d-version=Posix'] | |
12 | v['LINKFLAGS']=[] | |
13 | v['DFLAGS_dshlib']=['-relocation-model=pic'] | |
14 | def common_flags_dmd(conf): | |
15 | v=conf.env | |
16 | v['D_SRC_F']=['-c'] | |
17 | v['D_TGT_F']='-of%s' | |
18 | v['D_LINKER']=v['D'] | |
19 | v['DLNK_SRC_F']='' | |
20 | v['DLNK_TGT_F']='-of%s' | |
21 | v['DINC_ST']='-I%s' | |
22 | v['DSHLIB_MARKER']=v['DSTLIB_MARKER']='' | |
23 | v['DSTLIB_ST']=v['DSHLIB_ST']='-L-l%s' | |
24 | v['DSTLIBPATH_ST']=v['DLIBPATH_ST']='-L-L%s' | |
25 | v['LINKFLAGS_dprogram']=['-quiet'] | |
26 | v['DFLAGS_dshlib']=['-fPIC'] | |
27 | v['LINKFLAGS_dshlib']=['-L-shared'] | |
28 | v['DHEADER_ext']='.di' | |
29 | v.DFLAGS_d_with_header=['-H','-Hf'] | |
30 | v['D_HDR_F']='%s' | |
31 | def configure(conf): | |
32 | conf.find_dmd() | |
33 | if sys.platform=='win32': | |
34 | out=conf.cmd_and_log([conf.env.D,'--help']) | |
35 | if out.find("D Compiler v2.")>-1: | |
36 | conf.fatal('dmd2 on Windows is not supported, use gdc or ldc instead') | |
37 | conf.load('ar') | |
38 | conf.load('d') | |
39 | conf.common_flags_dmd() | |
40 | conf.d_platform_flags() | |
41 | if str(conf.env.D).find('ldc')>-1: | |
42 | conf.common_flags_ldc() | |
43 | ||
44 | conf(find_dmd) | |
45 | conf(common_flags_ldc) | |
46 | conf(common_flags_dmd)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | typos={'feature':'features','sources':'source','targets':'target','include':'includes','export_include':'export_includes','define':'defines','importpath':'includes','installpath':'install_path',} | |
7 | meths_typos=['__call__','program','shlib','stlib','objects'] | |
8 | from waflib import Logs,Build,Node,Task,TaskGen,ConfigSet,Errors,Utils | |
9 | import waflib.Tools.ccroot | |
10 | def check_same_targets(self): | |
11 | mp=Utils.defaultdict(list) | |
12 | uids={} | |
13 | def check_task(tsk): | |
14 | if not isinstance(tsk,Task.Task): | |
15 | return | |
16 | for node in tsk.outputs: | |
17 | mp[node].append(tsk) | |
18 | try: | |
19 | uids[tsk.uid()].append(tsk) | |
20 | except: | |
21 | uids[tsk.uid()]=[tsk] | |
22 | for g in self.groups: | |
23 | for tg in g: | |
24 | try: | |
25 | for tsk in tg.tasks: | |
26 | check_task(tsk) | |
27 | except AttributeError: | |
28 | check_task(tg) | |
29 | dupe=False | |
30 | for(k,v)in mp.items(): | |
31 | if len(v)>1: | |
32 | dupe=True | |
33 | msg='* Node %r is created by more than once%s. The task generators are:'%(k,Logs.verbose==1 and" (full message on 'waf -v -v')"or"") | |
34 | Logs.error(msg) | |
35 | for x in v: | |
36 | if Logs.verbose>1: | |
37 | Logs.error(' %d. %r'%(1+v.index(x),x.generator)) | |
38 | else: | |
39 | Logs.error(' %d. %r in %r'%(1+v.index(x),x.generator.name,getattr(x.generator,'path',None))) | |
40 | if not dupe: | |
41 | for(k,v)in uids.items(): | |
42 | if len(v)>1: | |
43 | Logs.error('* Several tasks use the same identifier. Please check the information on\n http://waf.googlecode.com/git/docs/apidocs/Task.html#waflib.Task.Task.uid') | |
44 | for tsk in v: | |
45 | Logs.error(' - object %r (%r) defined in %r'%(tsk.__class__.__name__,tsk,tsk.generator)) | |
46 | def check_invalid_constraints(self): | |
47 | feat=set([]) | |
48 | for x in list(TaskGen.feats.values()): | |
49 | feat.union(set(x)) | |
50 | for(x,y)in TaskGen.task_gen.prec.items(): | |
51 | feat.add(x) | |
52 | feat.union(set(y)) | |
53 | ext=set([]) | |
54 | for x in TaskGen.task_gen.mappings.values(): | |
55 | ext.add(x.__name__) | |
56 | invalid=ext&feat | |
57 | if invalid: | |
58 | Logs.error('The methods %r have invalid annotations: @extension <-> @feature/@before_method/@after_method'%list(invalid)) | |
59 | for cls in list(Task.classes.values()): | |
60 | for x in('before','after'): | |
61 | for y in Utils.to_list(getattr(cls,x,[])): | |
62 | if not Task.classes.get(y,None): | |
63 | Logs.error('Erroneous order constraint %r=%r on task class %r'%(x,y,cls.__name__)) | |
64 | if getattr(cls,'rule',None): | |
65 | Logs.error('Erroneous attribute "rule" on task class %r (rename to "run_str")'%cls.__name__) | |
66 | def replace(m): | |
67 | oldcall=getattr(Build.BuildContext,m) | |
68 | def call(self,*k,**kw): | |
69 | ret=oldcall(self,*k,**kw) | |
70 | for x in typos: | |
71 | if x in kw: | |
72 | err=True | |
73 | Logs.error('Fix the typo %r -> %r on %r'%(x,typos[x],ret)) | |
74 | return ret | |
75 | setattr(Build.BuildContext,m,call) | |
76 | def enhance_lib(): | |
77 | for m in meths_typos: | |
78 | replace(m) | |
79 | def ant_glob(self,*k,**kw): | |
80 | if k: | |
81 | lst=Utils.to_list(k[0]) | |
82 | for pat in lst: | |
83 | if'..'in pat.split('/'): | |
84 | Logs.error("In ant_glob pattern %r: '..' means 'two dots', not 'parent directory'"%k[0]) | |
85 | if kw.get('remove',True): | |
86 | try: | |
87 | if self.is_child_of(self.ctx.bldnode)and not kw.get('quiet',False): | |
88 | Logs.error('Using ant_glob on the build folder (%r) is dangerous (quiet=True to disable this warning)'%self) | |
89 | except AttributeError: | |
90 | pass | |
91 | return self.old_ant_glob(*k,**kw) | |
92 | Node.Node.old_ant_glob=Node.Node.ant_glob | |
93 | Node.Node.ant_glob=ant_glob | |
94 | old=Task.is_before | |
95 | def is_before(t1,t2): | |
96 | ret=old(t1,t2) | |
97 | if ret and old(t2,t1): | |
98 | Logs.error('Contradictory order constraints in classes %r %r'%(t1,t2)) | |
99 | return ret | |
100 | Task.is_before=is_before | |
101 | def check_err_features(self): | |
102 | lst=self.to_list(self.features) | |
103 | if'shlib'in lst: | |
104 | Logs.error('feature shlib -> cshlib, dshlib or cxxshlib') | |
105 | for x in('c','cxx','d','fc'): | |
106 | if not x in lst and lst and lst[0]in[x+y for y in('program','shlib','stlib')]: | |
107 | Logs.error('%r features is probably missing %r'%(self,x)) | |
108 | TaskGen.feature('*')(check_err_features) | |
109 | def check_err_order(self): | |
110 | if not hasattr(self,'rule'): | |
111 | for x in('before','after','ext_in','ext_out'): | |
112 | if hasattr(self,x): | |
113 | Logs.warn('Erroneous order constraint %r on non-rule based task generator %r'%(x,self)) | |
114 | else: | |
115 | for x in('before','after'): | |
116 | for y in self.to_list(getattr(self,x,[])): | |
117 | if not Task.classes.get(y,None): | |
118 | Logs.error('Erroneous order constraint %s=%r on %r'%(x,y,self)) | |
119 | TaskGen.feature('*')(check_err_order) | |
120 | def check_compile(self): | |
121 | check_invalid_constraints(self) | |
122 | try: | |
123 | ret=self.orig_compile() | |
124 | finally: | |
125 | check_same_targets(self) | |
126 | return ret | |
127 | Build.BuildContext.orig_compile=Build.BuildContext.compile | |
128 | Build.BuildContext.compile=check_compile | |
129 | def use_rec(self,name,**kw): | |
130 | try: | |
131 | y=self.bld.get_tgen_by_name(name) | |
132 | except Errors.WafError: | |
133 | pass | |
134 | else: | |
135 | idx=self.bld.get_group_idx(self) | |
136 | odx=self.bld.get_group_idx(y) | |
137 | if odx>idx: | |
138 | msg="Invalid 'use' across build groups:" | |
139 | if Logs.verbose>1: | |
140 | msg+='\n target %r\n uses:\n %r'%(self,y) | |
141 | else: | |
142 | msg+=" %r uses %r (try 'waf -v -v' for the full error)"%(self.name,name) | |
143 | raise Errors.WafError(msg) | |
144 | self.orig_use_rec(name,**kw) | |
145 | TaskGen.task_gen.orig_use_rec=TaskGen.task_gen.use_rec | |
146 | TaskGen.task_gen.use_rec=use_rec | |
147 | def getattri(self,name,default=None): | |
148 | if name=='append'or name=='add': | |
149 | raise Errors.WafError('env.append and env.add do not exist: use env.append_value/env.append_unique') | |
150 | elif name=='prepend': | |
151 | raise Errors.WafError('env.prepend does not exist: use env.prepend_value') | |
152 | if name in self.__slots__: | |
153 | return object.__getattr__(self,name,default) | |
154 | else: | |
155 | return self[name] | |
156 | ConfigSet.ConfigSet.__getattr__=getattri | |
157 | def options(opt): | |
158 | enhance_lib() | |
159 | def configure(conf): | |
160 | pass |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import re | |
7 | from waflib import Utils,Task,TaskGen,Logs | |
8 | from waflib.Tools import ccroot,fc_config,fc_scan | |
9 | from waflib.TaskGen import feature,before_method,after_method,extension | |
10 | from waflib.Configure import conf | |
11 | ccroot.USELIB_VARS['fc']=set(['FCFLAGS','DEFINES','INCLUDES']) | |
12 | ccroot.USELIB_VARS['fcprogram_test']=ccroot.USELIB_VARS['fcprogram']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS']) | |
13 | ccroot.USELIB_VARS['fcshlib']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS']) | |
14 | ccroot.USELIB_VARS['fcstlib']=set(['ARFLAGS','LINKDEPS']) | |
15 | def dummy(self): | |
16 | pass | |
17 | def fc_hook(self,node): | |
18 | return self.create_compiled_task('fc',node) | |
19 | def modfile(conf,name): | |
20 | return{'lower':name.lower()+'.mod','lower.MOD':name.upper()+'.MOD','UPPER.mod':name.upper()+'.mod','UPPER':name.upper()+'.MOD'}[conf.env.FC_MOD_CAPITALIZATION or'lower'] | |
21 | def get_fortran_tasks(tsk): | |
22 | bld=tsk.generator.bld | |
23 | tasks=bld.get_tasks_group(bld.get_group_idx(tsk.generator)) | |
24 | return[x for x in tasks if isinstance(x,fc)and not getattr(x,'nomod',None)and not getattr(x,'mod_fortran_done',None)] | |
25 | class fc(Task.Task): | |
26 | color='GREEN' | |
27 | run_str='${FC} ${FCFLAGS} ${FCINCPATH_ST:INCPATHS} ${FCDEFINES_ST:DEFINES} ${_FCMODOUTFLAGS} ${FC_TGT_F}${TGT[0].abspath()} ${FC_SRC_F}${SRC[0].abspath()}' | |
28 | vars=["FORTRANMODPATHFLAG"] | |
29 | def scan(self): | |
30 | tmp=fc_scan.fortran_parser(self.generator.includes_nodes) | |
31 | tmp.task=self | |
32 | tmp.start(self.inputs[0]) | |
33 | if Logs.verbose: | |
34 | Logs.debug('deps: deps for %r: %r; unresolved %r'%(self.inputs,tmp.nodes,tmp.names)) | |
35 | return(tmp.nodes,tmp.names) | |
36 | def runnable_status(self): | |
37 | if getattr(self,'mod_fortran_done',None): | |
38 | return super(fc,self).runnable_status() | |
39 | bld=self.generator.bld | |
40 | lst=get_fortran_tasks(self) | |
41 | for tsk in lst: | |
42 | tsk.mod_fortran_done=True | |
43 | for tsk in lst: | |
44 | ret=tsk.runnable_status() | |
45 | if ret==Task.ASK_LATER: | |
46 | for x in lst: | |
47 | x.mod_fortran_done=None | |
48 | return Task.ASK_LATER | |
49 | ins=Utils.defaultdict(set) | |
50 | outs=Utils.defaultdict(set) | |
51 | for tsk in lst: | |
52 | key=tsk.uid() | |
53 | for x in bld.raw_deps[key]: | |
54 | if x.startswith('MOD@'): | |
55 | name=bld.modfile(x.replace('MOD@','')) | |
56 | node=bld.srcnode.find_or_declare(name) | |
57 | tsk.set_outputs(node) | |
58 | outs[id(node)].add(tsk) | |
59 | for tsk in lst: | |
60 | key=tsk.uid() | |
61 | for x in bld.raw_deps[key]: | |
62 | if x.startswith('USE@'): | |
63 | name=bld.modfile(x.replace('USE@','')) | |
64 | node=bld.srcnode.find_resource(name) | |
65 | if node and node not in tsk.outputs: | |
66 | if not node in bld.node_deps[key]: | |
67 | bld.node_deps[key].append(node) | |
68 | ins[id(node)].add(tsk) | |
69 | for k in ins.keys(): | |
70 | for a in ins[k]: | |
71 | a.run_after.update(outs[k]) | |
72 | tmp=[] | |
73 | for t in outs[k]: | |
74 | tmp.extend(t.outputs) | |
75 | a.dep_nodes.extend(tmp) | |
76 | try: | |
77 | a.dep_nodes.sort(key=lambda x:x.abspath()) | |
78 | except: | |
79 | a.dep_nodes.sort(lambda x,y:cmp(x.abspath(),y.abspath())) | |
80 | for tsk in lst: | |
81 | try: | |
82 | delattr(tsk,'cache_sig') | |
83 | except AttributeError: | |
84 | pass | |
85 | return super(fc,self).runnable_status() | |
86 | class fcprogram(ccroot.link_task): | |
87 | color='YELLOW' | |
88 | run_str='${FC} ${LINKFLAGS} ${FCLNK_SRC_F}${SRC} ${FCLNK_TGT_F}${TGT[0].abspath()} ${RPATH_ST:RPATH} ${FCSTLIB_MARKER} ${FCSTLIBPATH_ST:STLIBPATH} ${FCSTLIB_ST:STLIB} ${FCSHLIB_MARKER} ${FCLIBPATH_ST:LIBPATH} ${FCLIB_ST:LIB}' | |
89 | inst_to='${BINDIR}' | |
90 | chmod=Utils.O755 | |
91 | class fcshlib(fcprogram): | |
92 | inst_to='${LIBDIR}' | |
93 | class fcprogram_test(fcprogram): | |
94 | def can_retrieve_cache(self): | |
95 | return False | |
96 | def runnable_status(self): | |
97 | ret=super(fcprogram_test,self).runnable_status() | |
98 | if ret==Task.SKIP_ME: | |
99 | ret=Task.RUN_ME | |
100 | return ret | |
101 | def exec_command(self,cmd,**kw): | |
102 | bld=self.generator.bld | |
103 | kw['shell']=isinstance(cmd,str) | |
104 | kw['stdout']=kw['stderr']=Utils.subprocess.PIPE | |
105 | kw['cwd']=bld.variant_dir | |
106 | bld.out=bld.err='' | |
107 | bld.to_log('command: %s\n'%cmd) | |
108 | kw['output']=0 | |
109 | try: | |
110 | (bld.out,bld.err)=bld.cmd_and_log(cmd,**kw) | |
111 | except Exception ,e: | |
112 | return-1 | |
113 | if bld.out: | |
114 | bld.to_log("out: %s\n"%bld.out) | |
115 | if bld.err: | |
116 | bld.to_log("err: %s\n"%bld.err) | |
117 | class fcstlib(ccroot.stlink_task): | |
118 | pass | |
119 | ||
120 | feature('fcprogram','fcshlib','fcstlib','fcprogram_test')(dummy) | |
121 | extension('.f','.f90','.F','.F90','.for','.FOR')(fc_hook) | |
122 | conf(modfile)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import re,shutil,os,sys,string,shlex | |
5 | from waflib.Configure import conf | |
6 | from waflib.TaskGen import feature,after_method,before_method | |
7 | from waflib import Build,Utils | |
8 | FC_FRAGMENT=' program main\n end program main\n' | |
9 | FC_FRAGMENT2=' PROGRAM MAIN\n END\n' | |
10 | def fc_flags(conf): | |
11 | v=conf.env | |
12 | v['FC_SRC_F']=[] | |
13 | v['FC_TGT_F']=['-c','-o'] | |
14 | v['FCINCPATH_ST']='-I%s' | |
15 | v['FCDEFINES_ST']='-D%s' | |
16 | if not v['LINK_FC']:v['LINK_FC']=v['FC'] | |
17 | v['FCLNK_SRC_F']=[] | |
18 | v['FCLNK_TGT_F']=['-o'] | |
19 | v['FCFLAGS_fcshlib']=['-fpic'] | |
20 | v['LINKFLAGS_fcshlib']=['-shared'] | |
21 | v['fcshlib_PATTERN']='lib%s.so' | |
22 | v['fcstlib_PATTERN']='lib%s.a' | |
23 | v['FCLIB_ST']='-l%s' | |
24 | v['FCLIBPATH_ST']='-L%s' | |
25 | v['FCSTLIB_ST']='-l%s' | |
26 | v['FCSTLIBPATH_ST']='-L%s' | |
27 | v['FCSTLIB_MARKER']='-Wl,-Bstatic' | |
28 | v['FCSHLIB_MARKER']='-Wl,-Bdynamic' | |
29 | v['SONAME_ST']='-Wl,-h,%s' | |
30 | def check_fortran(self,*k,**kw): | |
31 | self.check_cc(fragment=FC_FRAGMENT,compile_filename='test.f',features='fc fcprogram',msg='Compiling a simple fortran app') | |
32 | def check_fc(self,*k,**kw): | |
33 | kw['compiler']='fc' | |
34 | if not'compile_mode'in kw: | |
35 | kw['compile_mode']='fc' | |
36 | if not'type'in kw: | |
37 | kw['type']='fcprogram' | |
38 | if not'compile_filename'in kw: | |
39 | kw['compile_filename']='test.f90' | |
40 | if not'code'in kw: | |
41 | kw['code']=FC_FRAGMENT | |
42 | return self.check(*k,**kw) | |
43 | def fortran_modifier_darwin(conf): | |
44 | v=conf.env | |
45 | v['FCFLAGS_fcshlib']=['-fPIC','-compatibility_version','1','-current_version','1'] | |
46 | v['LINKFLAGS_fcshlib']=['-dynamiclib'] | |
47 | v['fcshlib_PATTERN']='lib%s.dylib' | |
48 | v['FRAMEWORKPATH_ST']='-F%s' | |
49 | v['FRAMEWORK_ST']='-framework %s' | |
50 | v['LINKFLAGS_fcstlib']=[] | |
51 | v['FCSHLIB_MARKER']='' | |
52 | v['FCSTLIB_MARKER']='' | |
53 | v['SONAME_ST']='' | |
54 | def fortran_modifier_win32(conf): | |
55 | v=conf.env | |
56 | v['fcprogram_PATTERN']=v['fcprogram_test_PATTERN']='%s.exe' | |
57 | v['fcshlib_PATTERN']='%s.dll' | |
58 | v['implib_PATTERN']='lib%s.dll.a' | |
59 | v['IMPLIB_ST']='-Wl,--out-implib,%s' | |
60 | v['FCFLAGS_fcshlib']=[] | |
61 | v.append_value('FCFLAGS_fcshlib',['-DDLL_EXPORT']) | |
62 | v.append_value('LINKFLAGS',['-Wl,--enable-auto-import']) | |
63 | def fortran_modifier_cygwin(conf): | |
64 | fortran_modifier_win32(conf) | |
65 | v=conf.env | |
66 | v['fcshlib_PATTERN']='cyg%s.dll' | |
67 | v.append_value('LINKFLAGS_fcshlib',['-Wl,--enable-auto-image-base']) | |
68 | v['FCFLAGS_fcshlib']=[] | |
69 | def check_fortran_dummy_main(self,*k,**kw): | |
70 | if not self.env.CC: | |
71 | self.fatal('A c compiler is required for check_fortran_dummy_main') | |
72 | lst=['MAIN__','__MAIN','_MAIN','MAIN_','MAIN'] | |
73 | lst.extend([m.lower()for m in lst]) | |
74 | lst.append('') | |
75 | self.start_msg('Detecting whether we need a dummy main') | |
76 | for main in lst: | |
77 | kw['fortran_main']=main | |
78 | try: | |
79 | self.check_cc(fragment='int %s() { return 0; }\n'%(main or'test'),features='c fcprogram',mandatory=True) | |
80 | if not main: | |
81 | self.env.FC_MAIN=-1 | |
82 | self.end_msg('no') | |
83 | else: | |
84 | self.env.FC_MAIN=main | |
85 | self.end_msg('yes %s'%main) | |
86 | break | |
87 | except self.errors.ConfigurationError: | |
88 | pass | |
89 | else: | |
90 | self.end_msg('not found') | |
91 | self.fatal('could not detect whether fortran requires a dummy main, see the config.log') | |
92 | GCC_DRIVER_LINE=re.compile('^Driving:') | |
93 | POSIX_STATIC_EXT=re.compile('\S+\.a') | |
94 | POSIX_LIB_FLAGS=re.compile('-l\S+') | |
95 | def is_link_verbose(self,txt): | |
96 | assert isinstance(txt,str) | |
97 | for line in txt.splitlines(): | |
98 | if not GCC_DRIVER_LINE.search(line): | |
99 | if POSIX_STATIC_EXT.search(line)or POSIX_LIB_FLAGS.search(line): | |
100 | return True | |
101 | return False | |
102 | def check_fortran_verbose_flag(self,*k,**kw): | |
103 | self.start_msg('fortran link verbose flag') | |
104 | for x in['-v','--verbose','-verbose','-V']: | |
105 | try: | |
106 | self.check_cc(features='fc fcprogram_test',fragment=FC_FRAGMENT2,compile_filename='test.f',linkflags=[x],mandatory=True) | |
107 | except self.errors.ConfigurationError: | |
108 | pass | |
109 | else: | |
110 | if self.is_link_verbose(self.test_bld.err)or self.is_link_verbose(self.test_bld.out): | |
111 | self.end_msg(x) | |
112 | break | |
113 | else: | |
114 | self.end_msg('failure') | |
115 | self.fatal('Could not obtain the fortran link verbose flag (see config.log)') | |
116 | self.env.FC_VERBOSE_FLAG=x | |
117 | return x | |
118 | LINKFLAGS_IGNORED=[r'-lang*',r'-lcrt[a-zA-Z0-9\.]*\.o',r'-lc$',r'-lSystem',r'-libmil',r'-LIST:*',r'-LNO:*'] | |
119 | if os.name=='nt': | |
120 | LINKFLAGS_IGNORED.extend([r'-lfrt*',r'-luser32',r'-lkernel32',r'-ladvapi32',r'-lmsvcrt',r'-lshell32',r'-lmingw',r'-lmoldname']) | |
121 | else: | |
122 | LINKFLAGS_IGNORED.append(r'-lgcc*') | |
123 | RLINKFLAGS_IGNORED=[re.compile(f)for f in LINKFLAGS_IGNORED] | |
124 | def _match_ignore(line): | |
125 | for i in RLINKFLAGS_IGNORED: | |
126 | if i.match(line): | |
127 | return True | |
128 | return False | |
129 | def parse_fortran_link(lines): | |
130 | final_flags=[] | |
131 | for line in lines: | |
132 | if not GCC_DRIVER_LINE.match(line): | |
133 | _parse_flink_line(line,final_flags) | |
134 | return final_flags | |
135 | SPACE_OPTS=re.compile('^-[LRuYz]$') | |
136 | NOSPACE_OPTS=re.compile('^-[RL]') | |
137 | def _parse_flink_line(line,final_flags): | |
138 | lexer=shlex.shlex(line,posix=True) | |
139 | lexer.whitespace_split=True | |
140 | t=lexer.get_token() | |
141 | tmp_flags=[] | |
142 | while t: | |
143 | def parse(token): | |
144 | if _match_ignore(token): | |
145 | pass | |
146 | elif token.startswith('-lkernel32')and sys.platform=='cygwin': | |
147 | tmp_flags.append(token) | |
148 | elif SPACE_OPTS.match(token): | |
149 | t=lexer.get_token() | |
150 | if t.startswith('P,'): | |
151 | t=t[2:] | |
152 | for opt in t.split(os.pathsep): | |
153 | tmp_flags.append('-L%s'%opt) | |
154 | elif NOSPACE_OPTS.match(token): | |
155 | tmp_flags.append(token) | |
156 | elif POSIX_LIB_FLAGS.match(token): | |
157 | tmp_flags.append(token) | |
158 | else: | |
159 | pass | |
160 | t=lexer.get_token() | |
161 | return t | |
162 | t=parse(t) | |
163 | final_flags.extend(tmp_flags) | |
164 | return final_flags | |
165 | def check_fortran_clib(self,autoadd=True,*k,**kw): | |
166 | if not self.env.FC_VERBOSE_FLAG: | |
167 | self.fatal('env.FC_VERBOSE_FLAG is not set: execute check_fortran_verbose_flag?') | |
168 | self.start_msg('Getting fortran runtime link flags') | |
169 | try: | |
170 | self.check_cc(fragment=FC_FRAGMENT2,compile_filename='test.f',features='fc fcprogram_test',linkflags=[self.env.FC_VERBOSE_FLAG]) | |
171 | except: | |
172 | self.end_msg(False) | |
173 | if kw.get('mandatory',True): | |
174 | conf.fatal('Could not find the c library flags') | |
175 | else: | |
176 | out=self.test_bld.err | |
177 | flags=parse_fortran_link(out.splitlines()) | |
178 | self.end_msg('ok (%s)'%' '.join(flags)) | |
179 | self.env.LINKFLAGS_CLIB=flags | |
180 | return flags | |
181 | return[] | |
182 | def getoutput(conf,cmd,stdin=False): | |
183 | if stdin: | |
184 | stdin=Utils.subprocess.PIPE | |
185 | else: | |
186 | stdin=None | |
187 | env=conf.env.env or None | |
188 | try: | |
189 | p=Utils.subprocess.Popen(cmd,stdin=stdin,stdout=Utils.subprocess.PIPE,stderr=Utils.subprocess.PIPE,env=env) | |
190 | if stdin: | |
191 | p.stdin.write('\n') | |
192 | stdout,stderr=p.communicate() | |
193 | except: | |
194 | conf.fatal('could not determine the compiler version %r'%cmd) | |
195 | else: | |
196 | if not isinstance(stdout,str): | |
197 | stdout=stdout.decode(sys.stdout.encoding) | |
198 | if not isinstance(stderr,str): | |
199 | stderr=stderr.decode(sys.stdout.encoding) | |
200 | return stdout,stderr | |
201 | ROUTINES_CODE="""\ | |
202 | subroutine foobar() | |
203 | return | |
204 | end | |
205 | subroutine foo_bar() | |
206 | return | |
207 | end | |
208 | """ | |
209 | MAIN_CODE=""" | |
210 | void %(dummy_func_nounder)s(void); | |
211 | void %(dummy_func_under)s(void); | |
212 | int %(main_func_name)s() { | |
213 | %(dummy_func_nounder)s(); | |
214 | %(dummy_func_under)s(); | |
215 | return 0; | |
216 | } | |
217 | """ | |
218 | def link_main_routines_tg_method(self): | |
219 | def write_test_file(task): | |
220 | task.outputs[0].write(task.generator.code) | |
221 | bld=self.bld | |
222 | bld(rule=write_test_file,target='main.c',code=MAIN_CODE%self.__dict__) | |
223 | bld(rule=write_test_file,target='test.f',code=ROUTINES_CODE) | |
224 | bld(features='fc fcstlib',source='test.f',target='test') | |
225 | bld(features='c fcprogram',source='main.c',target='app',use='test') | |
226 | def mangling_schemes(): | |
227 | for u in['_','']: | |
228 | for du in['','_']: | |
229 | for c in["lower","upper"]: | |
230 | yield(u,du,c) | |
231 | def mangle_name(u,du,c,name): | |
232 | return getattr(name,c)()+u+(name.find('_')!=-1 and du or'') | |
233 | def check_fortran_mangling(self,*k,**kw): | |
234 | if not self.env.CC: | |
235 | self.fatal('A c compiler is required for link_main_routines') | |
236 | if not self.env.FC: | |
237 | self.fatal('A fortran compiler is required for link_main_routines') | |
238 | if not self.env.FC_MAIN: | |
239 | self.fatal('Checking for mangling requires self.env.FC_MAIN (execute "check_fortran_dummy_main" first?)') | |
240 | self.start_msg('Getting fortran mangling scheme') | |
241 | for(u,du,c)in mangling_schemes(): | |
242 | try: | |
243 | self.check_cc(compile_filename=[],features='link_main_routines_func',msg='nomsg',errmsg='nomsg',mandatory=True,dummy_func_nounder=mangle_name(u,du,c,"foobar"),dummy_func_under=mangle_name(u,du,c,"foo_bar"),main_func_name=self.env.FC_MAIN) | |
244 | except self.errors.ConfigurationError: | |
245 | pass | |
246 | else: | |
247 | self.end_msg("ok ('%s', '%s', '%s-case')"%(u,du,c)) | |
248 | self.env.FORTRAN_MANGLING=(u,du,c) | |
249 | break | |
250 | else: | |
251 | self.end_msg(False) | |
252 | self.fatal('mangler not found') | |
253 | return(u,du,c) | |
254 | def set_lib_pat(self): | |
255 | self.env['fcshlib_PATTERN']=self.env['pyext_PATTERN'] | |
256 | def detect_openmp(self): | |
257 | for x in['-fopenmp','-openmp','-mp','-xopenmp','-omp','-qsmp=omp']: | |
258 | try: | |
259 | self.check_fc(msg='Checking for OpenMP flag %s'%x,fragment='program main\n call omp_get_num_threads()\nend program main',fcflags=x,linkflags=x,uselib_store='OPENMP') | |
260 | except self.errors.ConfigurationError: | |
261 | pass | |
262 | else: | |
263 | break | |
264 | else: | |
265 | self.fatal('Could not find OpenMP') | |
266 | ||
267 | conf(fc_flags) | |
268 | conf(check_fortran) | |
269 | conf(check_fc) | |
270 | conf(fortran_modifier_darwin) | |
271 | conf(fortran_modifier_win32) | |
272 | conf(fortran_modifier_cygwin) | |
273 | conf(check_fortran_dummy_main) | |
274 | conf(is_link_verbose) | |
275 | conf(check_fortran_verbose_flag) | |
276 | conf(check_fortran_clib) | |
277 | feature('link_main_routines_func')(link_main_routines_tg_method) | |
278 | before_method('process_source')(link_main_routines_tg_method) | |
279 | conf(check_fortran_mangling) | |
280 | feature('pyext')(set_lib_pat) | |
281 | before_method('propagate_uselib_vars','apply_link')(set_lib_pat) | |
282 | conf(detect_openmp)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import re | |
5 | from waflib import Utils,Task,TaskGen,Logs | |
6 | from waflib.TaskGen import feature,before_method,after_method,extension | |
7 | from waflib.Configure import conf | |
8 | INC_REGEX="""(?:^|['">]\s*;)\s*INCLUDE\s+(?:\w+_)?[<"'](.+?)(?=["'>])""" | |
9 | USE_REGEX="""(?:^|;)\s*USE(?:\s+|(?:(?:\s*,\s*(?:NON_)?INTRINSIC)?\s*::))\s*(\w+)""" | |
10 | MOD_REGEX="""(?:^|;)\s*MODULE(?!\s*PROCEDURE)(?:\s+|(?:(?:\s*,\s*(?:NON_)?INTRINSIC)?\s*::))\s*(\w+)""" | |
11 | re_inc=re.compile(INC_REGEX,re.I) | |
12 | re_use=re.compile(USE_REGEX,re.I) | |
13 | re_mod=re.compile(MOD_REGEX,re.I) | |
14 | class fortran_parser(object): | |
15 | def __init__(self,incpaths): | |
16 | self.seen=[] | |
17 | self.nodes=[] | |
18 | self.names=[] | |
19 | self.incpaths=incpaths | |
20 | def find_deps(self,node): | |
21 | txt=node.read() | |
22 | incs=[] | |
23 | uses=[] | |
24 | mods=[] | |
25 | for line in txt.splitlines(): | |
26 | m=re_inc.search(line) | |
27 | if m: | |
28 | incs.append(m.group(1)) | |
29 | m=re_use.search(line) | |
30 | if m: | |
31 | uses.append(m.group(1)) | |
32 | m=re_mod.search(line) | |
33 | if m: | |
34 | mods.append(m.group(1)) | |
35 | return(incs,uses,mods) | |
36 | def start(self,node): | |
37 | self.waiting=[node] | |
38 | while self.waiting: | |
39 | nd=self.waiting.pop(0) | |
40 | self.iter(nd) | |
41 | def iter(self,node): | |
42 | path=node.abspath() | |
43 | incs,uses,mods=self.find_deps(node) | |
44 | for x in incs: | |
45 | if x in self.seen: | |
46 | continue | |
47 | self.seen.append(x) | |
48 | self.tryfind_header(x) | |
49 | for x in uses: | |
50 | name="USE@%s"%x | |
51 | if not name in self.names: | |
52 | self.names.append(name) | |
53 | for x in mods: | |
54 | name="MOD@%s"%x | |
55 | if not name in self.names: | |
56 | self.names.append(name) | |
57 | def tryfind_header(self,filename): | |
58 | found=None | |
59 | for n in self.incpaths: | |
60 | found=n.find_resource(filename) | |
61 | if found: | |
62 | self.nodes.append(found) | |
63 | self.waiting.append(found) | |
64 | break | |
65 | if not found: | |
66 | if not filename in self.names: | |
67 | self.names.append(filename) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import waflib.TaskGen | |
5 | def decide_ext(self,node): | |
6 | if'cxx'in self.features: | |
7 | return['.lex.cc'] | |
8 | return['.lex.c'] | |
9 | def flexfun(tsk): | |
10 | env=tsk.env | |
11 | bld=tsk.generator.bld | |
12 | wd=bld.variant_dir | |
13 | def to_list(xx): | |
14 | if isinstance(xx,str):return[xx] | |
15 | return xx | |
16 | tsk.last_cmd=lst=[] | |
17 | lst.extend(to_list(env['FLEX'])) | |
18 | lst.extend(to_list(env['FLEXFLAGS'])) | |
19 | lst.extend([a.path_from(bld.bldnode)for a in tsk.inputs]) | |
20 | lst=[x for x in lst if x] | |
21 | txt=bld.cmd_and_log(lst,cwd=wd,env=env.env or None,quiet=0) | |
22 | tsk.outputs[0].write(txt) | |
23 | waflib.TaskGen.declare_chain(name='flex',rule=flexfun,ext_in='.l',decider=decide_ext,) | |
24 | def configure(conf): | |
25 | conf.find_program('flex',var='FLEX') | |
26 | conf.env.FLEXFLAGS=['-t'] |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import re | |
5 | from waflib import Utils | |
6 | from waflib.Tools import fc,fc_config,fc_scan | |
7 | from waflib.Configure import conf | |
8 | def find_g95(conf): | |
9 | fc=conf.find_program('g95',var='FC') | |
10 | fc=conf.cmd_to_list(fc) | |
11 | conf.get_g95_version(fc) | |
12 | conf.env.FC_NAME='G95' | |
13 | def g95_flags(conf): | |
14 | v=conf.env | |
15 | v['FCFLAGS_fcshlib']=['-fPIC'] | |
16 | v['FORTRANMODFLAG']=['-fmod=',''] | |
17 | v['FCFLAGS_DEBUG']=['-Werror'] | |
18 | def g95_modifier_win32(conf): | |
19 | fc_config.fortran_modifier_win32(conf) | |
20 | def g95_modifier_cygwin(conf): | |
21 | fc_config.fortran_modifier_cygwin(conf) | |
22 | def g95_modifier_darwin(conf): | |
23 | fc_config.fortran_modifier_darwin(conf) | |
24 | def g95_modifier_platform(conf): | |
25 | dest_os=conf.env['DEST_OS']or Utils.unversioned_sys_platform() | |
26 | g95_modifier_func=getattr(conf,'g95_modifier_'+dest_os,None) | |
27 | if g95_modifier_func: | |
28 | g95_modifier_func() | |
29 | def get_g95_version(conf,fc): | |
30 | version_re=re.compile(r"g95\s*(?P<major>\d*)\.(?P<minor>\d*)").search | |
31 | cmd=fc+['--version'] | |
32 | out,err=fc_config.getoutput(conf,cmd,stdin=False) | |
33 | if out: | |
34 | match=version_re(out) | |
35 | else: | |
36 | match=version_re(err) | |
37 | if not match: | |
38 | conf.fatal('cannot determine g95 version') | |
39 | k=match.groupdict() | |
40 | conf.env['FC_VERSION']=(k['major'],k['minor']) | |
41 | def configure(conf): | |
42 | conf.find_g95() | |
43 | conf.find_ar() | |
44 | conf.fc_flags() | |
45 | conf.g95_flags() | |
46 | conf.g95_modifier_platform() | |
47 | ||
48 | conf(find_g95) | |
49 | conf(g95_flags) | |
50 | conf(g95_modifier_win32) | |
51 | conf(g95_modifier_cygwin) | |
52 | conf(g95_modifier_darwin) | |
53 | conf(g95_modifier_platform) | |
54 | conf(get_g95_version)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import waflib.Tools.asm | |
5 | from waflib.Tools import ar | |
6 | def configure(conf): | |
7 | conf.find_program(['gas','as','gcc'],var='AS') | |
8 | conf.env.AS_TGT_F=['-o'] | |
9 | conf.env.ASLNK_TGT_F=['-o'] | |
10 | conf.find_ar() |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib import Configure,Options,Utils | |
6 | from waflib.Tools import ccroot,ar | |
7 | from waflib.Configure import conf | |
8 | def find_gcc(conf): | |
9 | cc=conf.find_program(['gcc','cc'],var='CC') | |
10 | cc=conf.cmd_to_list(cc) | |
11 | conf.get_cc_version(cc,gcc=True) | |
12 | conf.env.CC_NAME='gcc' | |
13 | conf.env.CC=cc | |
14 | def gcc_common_flags(conf): | |
15 | v=conf.env | |
16 | v['CC_SRC_F']=[] | |
17 | v['CC_TGT_F']=['-c','-o'] | |
18 | if not v['LINK_CC']:v['LINK_CC']=v['CC'] | |
19 | v['CCLNK_SRC_F']=[] | |
20 | v['CCLNK_TGT_F']=['-o'] | |
21 | v['CPPPATH_ST']='-I%s' | |
22 | v['DEFINES_ST']='-D%s' | |
23 | v['LIB_ST']='-l%s' | |
24 | v['LIBPATH_ST']='-L%s' | |
25 | v['STLIB_ST']='-l%s' | |
26 | v['STLIBPATH_ST']='-L%s' | |
27 | v['RPATH_ST']='-Wl,-rpath,%s' | |
28 | v['SONAME_ST']='-Wl,-h,%s' | |
29 | v['SHLIB_MARKER']='-Wl,-Bdynamic' | |
30 | v['STLIB_MARKER']='-Wl,-Bstatic' | |
31 | v['cprogram_PATTERN']='%s' | |
32 | v['CFLAGS_cshlib']=['-fPIC'] | |
33 | v['LINKFLAGS_cshlib']=['-shared'] | |
34 | v['cshlib_PATTERN']='lib%s.so' | |
35 | v['LINKFLAGS_cstlib']=['-Wl,-Bstatic'] | |
36 | v['cstlib_PATTERN']='lib%s.a' | |
37 | v['LINKFLAGS_MACBUNDLE']=['-bundle','-undefined','dynamic_lookup'] | |
38 | v['CFLAGS_MACBUNDLE']=['-fPIC'] | |
39 | v['macbundle_PATTERN']='%s.bundle' | |
40 | def gcc_modifier_win32(conf): | |
41 | v=conf.env | |
42 | v['cprogram_PATTERN']='%s.exe' | |
43 | v['cshlib_PATTERN']='%s.dll' | |
44 | v['implib_PATTERN']='lib%s.dll.a' | |
45 | v['IMPLIB_ST']='-Wl,--out-implib,%s' | |
46 | v['CFLAGS_cshlib']=[] | |
47 | v.append_value('CFLAGS_cshlib',['-DDLL_EXPORT']) | |
48 | v.append_value('LINKFLAGS',['-Wl,--enable-auto-import']) | |
49 | def gcc_modifier_cygwin(conf): | |
50 | gcc_modifier_win32(conf) | |
51 | v=conf.env | |
52 | v['cshlib_PATTERN']='cyg%s.dll' | |
53 | v.append_value('LINKFLAGS_cshlib',['-Wl,--enable-auto-image-base']) | |
54 | v['CFLAGS_cshlib']=[] | |
55 | def gcc_modifier_darwin(conf): | |
56 | v=conf.env | |
57 | v['CFLAGS_cshlib']=['-fPIC','-compatibility_version','1','-current_version','1'] | |
58 | v['LINKFLAGS_cshlib']=['-dynamiclib'] | |
59 | v['cshlib_PATTERN']='lib%s.dylib' | |
60 | v['FRAMEWORKPATH_ST']='-F%s' | |
61 | v['FRAMEWORK_ST']=['-framework'] | |
62 | v['ARCH_ST']=['-arch'] | |
63 | v['LINKFLAGS_cstlib']=[] | |
64 | v['SHLIB_MARKER']=[] | |
65 | v['STLIB_MARKER']=[] | |
66 | v['SONAME_ST']=[] | |
67 | def gcc_modifier_aix(conf): | |
68 | v=conf.env | |
69 | v['LINKFLAGS_cprogram']=['-Wl,-brtl'] | |
70 | v['LINKFLAGS_cshlib']=['-shared','-Wl,-brtl,-bexpfull'] | |
71 | v['SHLIB_MARKER']=[] | |
72 | def gcc_modifier_hpux(conf): | |
73 | v=conf.env | |
74 | v['SHLIB_MARKER']=[] | |
75 | v['CFLAGS_cshlib']=['-fPIC','-DPIC'] | |
76 | v['cshlib_PATTERN']='lib%s.sl' | |
77 | def gcc_modifier_platform(conf): | |
78 | gcc_modifier_func=getattr(conf,'gcc_modifier_'+conf.env.DEST_OS,None) | |
79 | if gcc_modifier_func: | |
80 | gcc_modifier_func() | |
81 | def configure(conf): | |
82 | conf.find_gcc() | |
83 | conf.find_ar() | |
84 | conf.gcc_common_flags() | |
85 | conf.gcc_modifier_platform() | |
86 | conf.cc_load_tools() | |
87 | conf.cc_add_flags() | |
88 | conf.link_add_flags() | |
89 | ||
90 | conf(find_gcc) | |
91 | conf(gcc_common_flags) | |
92 | conf(gcc_modifier_win32) | |
93 | conf(gcc_modifier_cygwin) | |
94 | conf(gcc_modifier_darwin) | |
95 | conf(gcc_modifier_aix) | |
96 | conf(gcc_modifier_hpux) | |
97 | conf(gcc_modifier_platform)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | from waflib.Tools import ar,d | |
6 | from waflib.Configure import conf | |
7 | def find_gdc(conf): | |
8 | conf.find_program('gdc',var='D') | |
9 | def common_flags_gdc(conf): | |
10 | v=conf.env | |
11 | v['DFLAGS']=[] | |
12 | v['D_SRC_F']=['-c'] | |
13 | v['D_TGT_F']='-o%s' | |
14 | v['D_LINKER']=v['D'] | |
15 | v['DLNK_SRC_F']='' | |
16 | v['DLNK_TGT_F']='-o%s' | |
17 | v['DINC_ST']='-I%s' | |
18 | v['DSHLIB_MARKER']=v['DSTLIB_MARKER']='' | |
19 | v['DSTLIB_ST']=v['DSHLIB_ST']='-l%s' | |
20 | v['DSTLIBPATH_ST']=v['DLIBPATH_ST']='-L%s' | |
21 | v['LINKFLAGS_dshlib']=['-shared'] | |
22 | v['DHEADER_ext']='.di' | |
23 | v.DFLAGS_d_with_header='-fintfc' | |
24 | v['D_HDR_F']='-fintfc-file=%s' | |
25 | def configure(conf): | |
26 | conf.find_gdc() | |
27 | conf.load('ar') | |
28 | conf.load('d') | |
29 | conf.common_flags_gdc() | |
30 | conf.d_platform_flags() | |
31 | ||
32 | conf(find_gdc) | |
33 | conf(common_flags_gdc)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import re | |
5 | from waflib import Utils | |
6 | from waflib.Tools import fc,fc_config,fc_scan | |
7 | from waflib.Configure import conf | |
8 | def find_gfortran(conf): | |
9 | fc=conf.find_program(['gfortran','g77'],var='FC') | |
10 | fc=conf.cmd_to_list(fc) | |
11 | conf.get_gfortran_version(fc) | |
12 | conf.env.FC_NAME='GFORTRAN' | |
13 | def gfortran_flags(conf): | |
14 | v=conf.env | |
15 | v['FCFLAGS_fcshlib']=['-fPIC'] | |
16 | v['FORTRANMODFLAG']=['-J',''] | |
17 | v['FCFLAGS_DEBUG']=['-Werror'] | |
18 | def gfortran_modifier_win32(conf): | |
19 | fc_config.fortran_modifier_win32(conf) | |
20 | def gfortran_modifier_cygwin(conf): | |
21 | fc_config.fortran_modifier_cygwin(conf) | |
22 | def gfortran_modifier_darwin(conf): | |
23 | fc_config.fortran_modifier_darwin(conf) | |
24 | def gfortran_modifier_platform(conf): | |
25 | dest_os=conf.env['DEST_OS']or Utils.unversioned_sys_platform() | |
26 | gfortran_modifier_func=getattr(conf,'gfortran_modifier_'+dest_os,None) | |
27 | if gfortran_modifier_func: | |
28 | gfortran_modifier_func() | |
29 | def get_gfortran_version(conf,fc): | |
30 | version_re=re.compile(r"GNU\s*Fortran",re.I).search | |
31 | cmd=fc+['--version'] | |
32 | out,err=fc_config.getoutput(conf,cmd,stdin=False) | |
33 | if out:match=version_re(out) | |
34 | else:match=version_re(err) | |
35 | if not match: | |
36 | conf.fatal('Could not determine the compiler type') | |
37 | cmd=fc+['-dM','-E','-'] | |
38 | out,err=fc_config.getoutput(conf,cmd,stdin=True) | |
39 | if out.find('__GNUC__')<0: | |
40 | conf.fatal('Could not determine the compiler type') | |
41 | k={} | |
42 | out=out.split('\n') | |
43 | import shlex | |
44 | for line in out: | |
45 | lst=shlex.split(line) | |
46 | if len(lst)>2: | |
47 | key=lst[1] | |
48 | val=lst[2] | |
49 | k[key]=val | |
50 | def isD(var): | |
51 | return var in k | |
52 | def isT(var): | |
53 | return var in k and k[var]!='0' | |
54 | conf.env['FC_VERSION']=(k['__GNUC__'],k['__GNUC_MINOR__'],k['__GNUC_PATCHLEVEL__']) | |
55 | def configure(conf): | |
56 | conf.find_gfortran() | |
57 | conf.find_ar() | |
58 | conf.fc_flags() | |
59 | conf.gfortran_flags() | |
60 | conf.gfortran_modifier_platform() | |
61 | ||
62 | conf(find_gfortran) | |
63 | conf(gfortran_flags) | |
64 | conf(gfortran_modifier_win32) | |
65 | conf(gfortran_modifier_cygwin) | |
66 | conf(gfortran_modifier_darwin) | |
67 | conf(gfortran_modifier_platform) | |
68 | conf(get_gfortran_version)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Task,Utils,Options,Errors,Logs | |
6 | from waflib.TaskGen import taskgen_method,before_method,after_method,feature | |
7 | def add_marshal_file(self,filename,prefix): | |
8 | if not hasattr(self,'marshal_list'): | |
9 | self.marshal_list=[] | |
10 | self.meths.append('process_marshal') | |
11 | self.marshal_list.append((filename,prefix)) | |
12 | def process_marshal(self): | |
13 | for f,prefix in getattr(self,'marshal_list',[]): | |
14 | node=self.path.find_resource(f) | |
15 | if not node: | |
16 | raise Errors.WafError('file not found %r'%f) | |
17 | h_node=node.change_ext('.h') | |
18 | c_node=node.change_ext('.c') | |
19 | task=self.create_task('glib_genmarshal',node,[h_node,c_node]) | |
20 | task.env.GLIB_GENMARSHAL_PREFIX=prefix | |
21 | self.source=self.to_nodes(getattr(self,'source',[])) | |
22 | self.source.append(c_node) | |
23 | class glib_genmarshal(Task.Task): | |
24 | def run(self): | |
25 | bld=self.inputs[0].__class__.ctx | |
26 | get=self.env.get_flat | |
27 | cmd1="%s %s --prefix=%s --header > %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[0].abspath()) | |
28 | ret=bld.exec_command(cmd1) | |
29 | if ret:return ret | |
30 | c='''#include "%s"\n'''%self.outputs[0].name | |
31 | self.outputs[1].write(c) | |
32 | cmd2="%s %s --prefix=%s --body >> %s"%(get('GLIB_GENMARSHAL'),self.inputs[0].srcpath(),get('GLIB_GENMARSHAL_PREFIX'),self.outputs[1].abspath()) | |
33 | return bld.exec_command(cmd2) | |
34 | vars=['GLIB_GENMARSHAL_PREFIX','GLIB_GENMARSHAL'] | |
35 | color='BLUE' | |
36 | ext_out=['.h'] | |
37 | def add_enums_from_template(self,source='',target='',template='',comments=''): | |
38 | if not hasattr(self,'enums_list'): | |
39 | self.enums_list=[] | |
40 | self.meths.append('process_enums') | |
41 | self.enums_list.append({'source':source,'target':target,'template':template,'file-head':'','file-prod':'','file-tail':'','enum-prod':'','value-head':'','value-prod':'','value-tail':'','comments':comments}) | |
42 | def add_enums(self,source='',target='',file_head='',file_prod='',file_tail='',enum_prod='',value_head='',value_prod='',value_tail='',comments=''): | |
43 | if not hasattr(self,'enums_list'): | |
44 | self.enums_list=[] | |
45 | self.meths.append('process_enums') | |
46 | self.enums_list.append({'source':source,'template':'','target':target,'file-head':file_head,'file-prod':file_prod,'file-tail':file_tail,'enum-prod':enum_prod,'value-head':value_head,'value-prod':value_prod,'value-tail':value_tail,'comments':comments}) | |
47 | def process_enums(self): | |
48 | for enum in getattr(self,'enums_list',[]): | |
49 | task=self.create_task('glib_mkenums') | |
50 | env=task.env | |
51 | inputs=[] | |
52 | source_list=self.to_list(enum['source']) | |
53 | if not source_list: | |
54 | raise Errors.WafError('missing source '+str(enum)) | |
55 | source_list=[self.path.find_resource(k)for k in source_list] | |
56 | inputs+=source_list | |
57 | env['GLIB_MKENUMS_SOURCE']=[k.abspath()for k in source_list] | |
58 | if not enum['target']: | |
59 | raise Errors.WafError('missing target '+str(enum)) | |
60 | tgt_node=self.path.find_or_declare(enum['target']) | |
61 | if tgt_node.name.endswith('.c'): | |
62 | self.source.append(tgt_node) | |
63 | env['GLIB_MKENUMS_TARGET']=tgt_node.abspath() | |
64 | options=[] | |
65 | if enum['template']: | |
66 | template_node=self.path.find_resource(enum['template']) | |
67 | options.append('--template %s'%(template_node.abspath())) | |
68 | inputs.append(template_node) | |
69 | params={'file-head':'--fhead','file-prod':'--fprod','file-tail':'--ftail','enum-prod':'--eprod','value-head':'--vhead','value-prod':'--vprod','value-tail':'--vtail','comments':'--comments'} | |
70 | for param,option in params.items(): | |
71 | if enum[param]: | |
72 | options.append('%s %r'%(option,enum[param])) | |
73 | env['GLIB_MKENUMS_OPTIONS']=' '.join(options) | |
74 | task.set_inputs(inputs) | |
75 | task.set_outputs(tgt_node) | |
76 | class glib_mkenums(Task.Task): | |
77 | run_str='${GLIB_MKENUMS} ${GLIB_MKENUMS_OPTIONS} ${GLIB_MKENUMS_SOURCE} > ${GLIB_MKENUMS_TARGET}' | |
78 | color='PINK' | |
79 | ext_out=['.h'] | |
80 | def add_settings_schemas(self,filename_list): | |
81 | if not hasattr(self,'settings_schema_files'): | |
82 | self.settings_schema_files=[] | |
83 | if not isinstance(filename_list,list): | |
84 | filename_list=[filename_list] | |
85 | self.settings_schema_files.extend(filename_list) | |
86 | def add_settings_enums(self,namespace,filename_list): | |
87 | if hasattr(self,'settings_enum_namespace'): | |
88 | raise Errors.WafError("Tried to add gsettings enums to '%s' more than once"%self.name) | |
89 | self.settings_enum_namespace=namespace | |
90 | if type(filename_list)!='list': | |
91 | filename_list=[filename_list] | |
92 | self.settings_enum_files=filename_list | |
93 | def r_change_ext(self,ext): | |
94 | name=self.name | |
95 | k=name.rfind('.') | |
96 | if k>=0: | |
97 | name=name[:k]+ext | |
98 | else: | |
99 | name=name+ext | |
100 | return self.parent.find_or_declare([name]) | |
101 | def process_settings(self): | |
102 | enums_tgt_node=[] | |
103 | install_files=[] | |
104 | settings_schema_files=getattr(self,'settings_schema_files',[]) | |
105 | if settings_schema_files and not self.env['GLIB_COMPILE_SCHEMAS']: | |
106 | raise Errors.WafError("Unable to process GSettings schemas - glib-compile-schemas was not found during configure") | |
107 | if hasattr(self,'settings_enum_files'): | |
108 | enums_task=self.create_task('glib_mkenums') | |
109 | source_list=self.settings_enum_files | |
110 | source_list=[self.path.find_resource(k)for k in source_list] | |
111 | enums_task.set_inputs(source_list) | |
112 | enums_task.env['GLIB_MKENUMS_SOURCE']=[k.abspath()for k in source_list] | |
113 | target=self.settings_enum_namespace+'.enums.xml' | |
114 | tgt_node=self.path.find_or_declare(target) | |
115 | enums_task.set_outputs(tgt_node) | |
116 | enums_task.env['GLIB_MKENUMS_TARGET']=tgt_node.abspath() | |
117 | enums_tgt_node=[tgt_node] | |
118 | install_files.append(tgt_node) | |
119 | options='--comments "<!-- @comment@ -->" --fhead "<schemalist>" --vhead " <@type@ id=\\"%s.@EnumName@\\">" --vprod " <value nick=\\"@valuenick@\\" value=\\"@valuenum@\\"/>" --vtail " </@type@>" --ftail "</schemalist>" '%(self.settings_enum_namespace) | |
120 | enums_task.env['GLIB_MKENUMS_OPTIONS']=options | |
121 | for schema in settings_schema_files: | |
122 | schema_task=self.create_task('glib_validate_schema') | |
123 | schema_node=self.path.find_resource(schema) | |
124 | if not schema_node: | |
125 | raise Errors.WafError("Cannot find the schema file '%s'"%schema) | |
126 | install_files.append(schema_node) | |
127 | source_list=enums_tgt_node+[schema_node] | |
128 | schema_task.set_inputs(source_list) | |
129 | schema_task.env['GLIB_COMPILE_SCHEMAS_OPTIONS']=[("--schema-file="+k.abspath())for k in source_list] | |
130 | target_node=r_change_ext(schema_node,'.xml.valid') | |
131 | schema_task.set_outputs(target_node) | |
132 | schema_task.env['GLIB_VALIDATE_SCHEMA_OUTPUT']=target_node.abspath() | |
133 | def compile_schemas_callback(bld): | |
134 | if not bld.is_install:return | |
135 | Logs.pprint('YELLOW','Updating GSettings schema cache') | |
136 | command=Utils.subst_vars("${GLIB_COMPILE_SCHEMAS} ${GSETTINGSSCHEMADIR}",bld.env) | |
137 | ret=self.bld.exec_command(command) | |
138 | if self.bld.is_install: | |
139 | if not self.env['GSETTINGSSCHEMADIR']: | |
140 | raise Errors.WafError('GSETTINGSSCHEMADIR not defined (should have been set up automatically during configure)') | |
141 | if install_files: | |
142 | self.bld.install_files(self.env['GSETTINGSSCHEMADIR'],install_files) | |
143 | if not hasattr(self.bld,'_compile_schemas_registered'): | |
144 | self.bld.add_post_fun(compile_schemas_callback) | |
145 | self.bld._compile_schemas_registered=True | |
146 | class glib_validate_schema(Task.Task): | |
147 | run_str='rm -f ${GLIB_VALIDATE_SCHEMA_OUTPUT} && ${GLIB_COMPILE_SCHEMAS} --dry-run ${GLIB_COMPILE_SCHEMAS_OPTIONS} && touch ${GLIB_VALIDATE_SCHEMA_OUTPUT}' | |
148 | color='PINK' | |
149 | def configure(conf): | |
150 | conf.find_program('glib-genmarshal',var='GLIB_GENMARSHAL') | |
151 | conf.find_perl_program('glib-mkenums',var='GLIB_MKENUMS') | |
152 | conf.find_program('glib-compile-schemas',var='GLIB_COMPILE_SCHEMAS',mandatory=False) | |
153 | def getstr(varname): | |
154 | return getattr(Options.options,varname,getattr(conf.env,varname,'')) | |
155 | gsettingsschemadir=getstr('GSETTINGSSCHEMADIR') | |
156 | if not gsettingsschemadir: | |
157 | datadir=getstr('DATADIR') | |
158 | if not datadir: | |
159 | prefix=conf.env['PREFIX'] | |
160 | datadir=os.path.join(prefix,'share') | |
161 | gsettingsschemadir=os.path.join(datadir,'glib-2.0','schemas') | |
162 | conf.env['GSETTINGSSCHEMADIR']=gsettingsschemadir | |
163 | def options(opt): | |
164 | opt.add_option('--gsettingsschemadir',help='GSettings schema location [Default: ${datadir}/glib-2.0/schemas]',default='',dest='GSETTINGSSCHEMADIR') | |
165 | ||
166 | taskgen_method(add_marshal_file) | |
167 | before_method('process_source')(process_marshal) | |
168 | taskgen_method(add_enums_from_template) | |
169 | taskgen_method(add_enums) | |
170 | before_method('process_source')(process_enums) | |
171 | taskgen_method(add_settings_schemas) | |
172 | taskgen_method(add_settings_enums) | |
173 | feature('glib2')(process_settings)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Utils,Options,Context | |
6 | _options=[x.split(', ')for x in''' | |
7 | bindir, user executables, ${EXEC_PREFIX}/bin | |
8 | sbindir, system admin executables, ${EXEC_PREFIX}/sbin | |
9 | libexecdir, program executables, ${EXEC_PREFIX}/libexec | |
10 | sysconfdir, read-only single-machine data, ${PREFIX}/etc | |
11 | sharedstatedir, modifiable architecture-independent data, ${PREFIX}/com | |
12 | localstatedir, modifiable single-machine data, ${PREFIX}/var | |
13 | libdir, object code libraries, ${EXEC_PREFIX}/lib | |
14 | includedir, C header files, ${PREFIX}/include | |
15 | oldincludedir, C header files for non-gcc, /usr/include | |
16 | datarootdir, read-only arch.-independent data root, ${PREFIX}/share | |
17 | datadir, read-only architecture-independent data, ${DATAROOTDIR} | |
18 | infodir, info documentation, ${DATAROOTDIR}/info | |
19 | localedir, locale-dependent data, ${DATAROOTDIR}/locale | |
20 | mandir, man documentation, ${DATAROOTDIR}/man | |
21 | docdir, documentation root, ${DATAROOTDIR}/doc/${PACKAGE} | |
22 | htmldir, html documentation, ${DOCDIR} | |
23 | dvidir, dvi documentation, ${DOCDIR} | |
24 | pdfdir, pdf documentation, ${DOCDIR} | |
25 | psdir, ps documentation, ${DOCDIR} | |
26 | '''.split('\n')if x] | |
27 | def configure(conf): | |
28 | def get_param(varname,default): | |
29 | return getattr(Options.options,varname,'')or default | |
30 | env=conf.env | |
31 | conf.env.LIBDIR=conf.env.BINDIR=[] | |
32 | env['EXEC_PREFIX']=get_param('EXEC_PREFIX',env['PREFIX']) | |
33 | env['PACKAGE']=getattr(Context.g_module,'APPNAME',None)or env['PACKAGE'] | |
34 | complete=False | |
35 | iter=0 | |
36 | while not complete and iter<len(_options)+1: | |
37 | iter+=1 | |
38 | complete=True | |
39 | for name,help,default in _options: | |
40 | name=name.upper() | |
41 | if not env[name]: | |
42 | try: | |
43 | env[name]=Utils.subst_vars(get_param(name,default).replace('/',os.sep),env) | |
44 | except TypeError: | |
45 | complete=False | |
46 | if not complete: | |
47 | lst=[name for name,_,_ in _options if not env[name.upper()]] | |
48 | raise conf.errors.WafError('Variable substitution failure %r'%lst) | |
49 | def options(opt): | |
50 | inst_dir=opt.add_option_group('Installation directories','By default, "waf install" will put the files in\ | |
51 | "/usr/local/bin", "/usr/local/lib" etc. An installation prefix other\ | |
52 | than "/usr/local" can be given using "--prefix", for example "--prefix=$HOME"') | |
53 | for k in('--prefix','--destdir'): | |
54 | option=opt.parser.get_option(k) | |
55 | if option: | |
56 | opt.parser.remove_option(k) | |
57 | inst_dir.add_option(option) | |
58 | inst_dir.add_option('--exec-prefix',help='installation prefix [Default: ${PREFIX}]',default='',dest='EXEC_PREFIX') | |
59 | dirs_options=opt.add_option_group('Pre-defined installation directories','') | |
60 | for name,help,default in _options: | |
61 | option_name='--'+name | |
62 | str_default=default | |
63 | str_help='%s [Default: %s]'%(help,str_default) | |
64 | dirs_options.add_option(option_name,help=str_help,default='',dest=name.upper()) |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib import Configure,Options,Utils | |
6 | from waflib.Tools import ccroot,ar | |
7 | from waflib.Configure import conf | |
8 | def find_gxx(conf): | |
9 | cxx=conf.find_program(['g++','c++'],var='CXX') | |
10 | cxx=conf.cmd_to_list(cxx) | |
11 | conf.get_cc_version(cxx,gcc=True) | |
12 | conf.env.CXX_NAME='gcc' | |
13 | conf.env.CXX=cxx | |
14 | def gxx_common_flags(conf): | |
15 | v=conf.env | |
16 | v['CXX_SRC_F']=[] | |
17 | v['CXX_TGT_F']=['-c','-o'] | |
18 | if not v['LINK_CXX']:v['LINK_CXX']=v['CXX'] | |
19 | v['CXXLNK_SRC_F']=[] | |
20 | v['CXXLNK_TGT_F']=['-o'] | |
21 | v['CPPPATH_ST']='-I%s' | |
22 | v['DEFINES_ST']='-D%s' | |
23 | v['LIB_ST']='-l%s' | |
24 | v['LIBPATH_ST']='-L%s' | |
25 | v['STLIB_ST']='-l%s' | |
26 | v['STLIBPATH_ST']='-L%s' | |
27 | v['RPATH_ST']='-Wl,-rpath,%s' | |
28 | v['SONAME_ST']='-Wl,-h,%s' | |
29 | v['SHLIB_MARKER']='-Wl,-Bdynamic' | |
30 | v['STLIB_MARKER']='-Wl,-Bstatic' | |
31 | v['cxxprogram_PATTERN']='%s' | |
32 | v['CXXFLAGS_cxxshlib']=['-fPIC'] | |
33 | v['LINKFLAGS_cxxshlib']=['-shared'] | |
34 | v['cxxshlib_PATTERN']='lib%s.so' | |
35 | v['LINKFLAGS_cxxstlib']=['-Wl,-Bstatic'] | |
36 | v['cxxstlib_PATTERN']='lib%s.a' | |
37 | v['LINKFLAGS_MACBUNDLE']=['-bundle','-undefined','dynamic_lookup'] | |
38 | v['CXXFLAGS_MACBUNDLE']=['-fPIC'] | |
39 | v['macbundle_PATTERN']='%s.bundle' | |
40 | def gxx_modifier_win32(conf): | |
41 | v=conf.env | |
42 | v['cxxprogram_PATTERN']='%s.exe' | |
43 | v['cxxshlib_PATTERN']='%s.dll' | |
44 | v['implib_PATTERN']='lib%s.dll.a' | |
45 | v['IMPLIB_ST']='-Wl,--out-implib,%s' | |
46 | v['CXXFLAGS_cxxshlib']=[] | |
47 | v.append_value('CXXFLAGS_cxxshlib',['-DDLL_EXPORT']) | |
48 | v.append_value('LINKFLAGS',['-Wl,--enable-auto-import']) | |
49 | def gxx_modifier_cygwin(conf): | |
50 | gxx_modifier_win32(conf) | |
51 | v=conf.env | |
52 | v['cxxshlib_PATTERN']='cyg%s.dll' | |
53 | v.append_value('LINKFLAGS_cxxshlib',['-Wl,--enable-auto-image-base']) | |
54 | v['CXXFLAGS_cxxshlib']=[] | |
55 | def gxx_modifier_darwin(conf): | |
56 | v=conf.env | |
57 | v['CXXFLAGS_cxxshlib']=['-fPIC','-compatibility_version','1','-current_version','1'] | |
58 | v['LINKFLAGS_cxxshlib']=['-dynamiclib'] | |
59 | v['cxxshlib_PATTERN']='lib%s.dylib' | |
60 | v['FRAMEWORKPATH_ST']='-F%s' | |
61 | v['FRAMEWORK_ST']=['-framework'] | |
62 | v['ARCH_ST']=['-arch'] | |
63 | v['LINKFLAGS_cxxstlib']=[] | |
64 | v['SHLIB_MARKER']=[] | |
65 | v['STLIB_MARKER']=[] | |
66 | v['SONAME_ST']=[] | |
67 | def gxx_modifier_aix(conf): | |
68 | v=conf.env | |
69 | v['LINKFLAGS_cxxprogram']=['-Wl,-brtl'] | |
70 | v['LINKFLAGS_cxxshlib']=['-shared','-Wl,-brtl,-bexpfull'] | |
71 | v['SHLIB_MARKER']=[] | |
72 | def gxx_modifier_hpux(conf): | |
73 | v=conf.env | |
74 | v['SHLIB_MARKER']=[] | |
75 | v['CFLAGS_cxxshlib']=['-fPIC','-DPIC'] | |
76 | v['cxxshlib_PATTERN']='lib%s.sl' | |
77 | def gxx_modifier_platform(conf): | |
78 | gxx_modifier_func=getattr(conf,'gxx_modifier_'+conf.env.DEST_OS,None) | |
79 | if gxx_modifier_func: | |
80 | gxx_modifier_func() | |
81 | def configure(conf): | |
82 | conf.find_gxx() | |
83 | conf.find_ar() | |
84 | conf.gxx_common_flags() | |
85 | conf.gxx_modifier_platform() | |
86 | conf.cxx_load_tools() | |
87 | conf.cxx_add_flags() | |
88 | conf.link_add_flags() | |
89 | ||
90 | conf(find_gxx) | |
91 | conf(gxx_common_flags) | |
92 | conf(gxx_modifier_win32) | |
93 | conf(gxx_modifier_cygwin) | |
94 | conf(gxx_modifier_darwin) | |
95 | conf(gxx_modifier_aix) | |
96 | conf(gxx_modifier_hpux) | |
97 | conf(gxx_modifier_platform)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib.Tools import ccroot,ar,gcc | |
6 | from waflib.Configure import conf | |
7 | def find_icc(conf): | |
8 | if sys.platform=='cygwin': | |
9 | conf.fatal('The Intel compiler does not work on Cygwin') | |
10 | v=conf.env | |
11 | cc=None | |
12 | if v['CC']:cc=v['CC'] | |
13 | elif'CC'in conf.environ:cc=conf.environ['CC'] | |
14 | if not cc:cc=conf.find_program('icc',var='CC') | |
15 | if not cc:cc=conf.find_program('ICL',var='CC') | |
16 | if not cc:conf.fatal('Intel C Compiler (icc) was not found') | |
17 | cc=conf.cmd_to_list(cc) | |
18 | conf.get_cc_version(cc,icc=True) | |
19 | v['CC']=cc | |
20 | v['CC_NAME']='icc' | |
21 | def configure(conf): | |
22 | conf.find_icc() | |
23 | conf.find_ar() | |
24 | conf.gcc_common_flags() | |
25 | conf.gcc_modifier_platform() | |
26 | conf.cc_load_tools() | |
27 | conf.cc_add_flags() | |
28 | conf.link_add_flags() | |
29 | ||
30 | conf(find_icc)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib.Tools import ccroot,ar,gxx | |
6 | from waflib.Configure import conf | |
7 | def find_icpc(conf): | |
8 | if sys.platform=='cygwin': | |
9 | conf.fatal('The Intel compiler does not work on Cygwin') | |
10 | v=conf.env | |
11 | cxx=None | |
12 | if v['CXX']:cxx=v['CXX'] | |
13 | elif'CXX'in conf.environ:cxx=conf.environ['CXX'] | |
14 | if not cxx:cxx=conf.find_program('icpc',var='CXX') | |
15 | if not cxx:conf.fatal('Intel C++ Compiler (icpc) was not found') | |
16 | cxx=conf.cmd_to_list(cxx) | |
17 | conf.get_cc_version(cxx,icc=True) | |
18 | v['CXX']=cxx | |
19 | v['CXX_NAME']='icc' | |
20 | def configure(conf): | |
21 | conf.find_icpc() | |
22 | conf.find_ar() | |
23 | conf.gxx_common_flags() | |
24 | conf.gxx_modifier_platform() | |
25 | conf.cxx_load_tools() | |
26 | conf.cxx_add_flags() | |
27 | conf.link_add_flags() | |
28 | ||
29 | conf(find_icpc)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import re | |
5 | from waflib import Utils | |
6 | from waflib.Tools import fc,fc_config,fc_scan | |
7 | from waflib.Configure import conf | |
8 | def find_ifort(conf): | |
9 | fc=conf.find_program('ifort',var='FC') | |
10 | fc=conf.cmd_to_list(fc) | |
11 | conf.get_ifort_version(fc) | |
12 | conf.env.FC_NAME='IFORT' | |
13 | def ifort_modifier_cygwin(conf): | |
14 | raise NotImplementedError("Ifort on cygwin not yet implemented") | |
15 | def ifort_modifier_win32(conf): | |
16 | fc_config.fortran_modifier_win32(conf) | |
17 | def ifort_modifier_darwin(conf): | |
18 | fc_config.fortran_modifier_darwin(conf) | |
19 | def ifort_modifier_platform(conf): | |
20 | dest_os=conf.env['DEST_OS']or Utils.unversioned_sys_platform() | |
21 | ifort_modifier_func=getattr(conf,'ifort_modifier_'+dest_os,None) | |
22 | if ifort_modifier_func: | |
23 | ifort_modifier_func() | |
24 | def get_ifort_version(conf,fc): | |
25 | version_re=re.compile(r"ifort\s*\(IFORT\)\s*(?P<major>\d*)\.(?P<minor>\d*)",re.I).search | |
26 | cmd=fc+['--version'] | |
27 | out,err=fc_config.getoutput(conf,cmd,stdin=False) | |
28 | if out: | |
29 | match=version_re(out) | |
30 | else: | |
31 | match=version_re(err) | |
32 | if not match: | |
33 | conf.fatal('cannot determine ifort version.') | |
34 | k=match.groupdict() | |
35 | conf.env['FC_VERSION']=(k['major'],k['minor']) | |
36 | def configure(conf): | |
37 | conf.find_ifort() | |
38 | conf.find_program('xiar',var='AR') | |
39 | conf.env.ARFLAGS='rcs' | |
40 | conf.fc_flags() | |
41 | conf.ifort_modifier_platform() | |
42 | ||
43 | conf(find_ifort) | |
44 | conf(ifort_modifier_cygwin) | |
45 | conf(ifort_modifier_win32) | |
46 | conf(ifort_modifier_darwin) | |
47 | conf(ifort_modifier_platform) | |
48 | conf(get_ifort_version)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,re | |
5 | from waflib import Configure,TaskGen,Task,Utils,Runner,Options,Build,Logs | |
6 | import waflib.Tools.ccroot | |
7 | from waflib.TaskGen import feature,before_method | |
8 | from waflib.Logs import error | |
9 | def apply_intltool_in_f(self): | |
10 | try:self.meths.remove('process_source') | |
11 | except ValueError:pass | |
12 | if not self.env.LOCALEDIR: | |
13 | self.env.LOCALEDIR=self.env.PREFIX+'/share/locale' | |
14 | for i in self.to_list(self.source): | |
15 | node=self.path.find_resource(i) | |
16 | podir=getattr(self,'podir','po') | |
17 | podirnode=self.path.find_dir(podir) | |
18 | if not podirnode: | |
19 | error("could not find the podir %r"%podir) | |
20 | continue | |
21 | cache=getattr(self,'intlcache','.intlcache') | |
22 | self.env['INTLCACHE']=os.path.join(self.path.bldpath(),podir,cache) | |
23 | self.env['INTLPODIR']=podirnode.bldpath() | |
24 | self.env['INTLFLAGS']=getattr(self,'flags',['-q','-u','-c']) | |
25 | task=self.create_task('intltool',node,node.change_ext('')) | |
26 | inst=getattr(self,'install_path','${LOCALEDIR}') | |
27 | if inst: | |
28 | self.bld.install_files(inst,task.outputs) | |
29 | def apply_intltool_po(self): | |
30 | try:self.meths.remove('process_source') | |
31 | except ValueError:pass | |
32 | if not self.env.LOCALEDIR: | |
33 | self.env.LOCALEDIR=self.env.PREFIX+'/share/locale' | |
34 | appname=getattr(self,'appname','set_your_app_name') | |
35 | podir=getattr(self,'podir','') | |
36 | inst=getattr(self,'install_path','${LOCALEDIR}') | |
37 | linguas=self.path.find_node(os.path.join(podir,'LINGUAS')) | |
38 | if linguas: | |
39 | file=open(linguas.abspath()) | |
40 | langs=[] | |
41 | for line in file.readlines(): | |
42 | if not line.startswith('#'): | |
43 | langs+=line.split() | |
44 | file.close() | |
45 | re_linguas=re.compile('[-a-zA-Z_@.]+') | |
46 | for lang in langs: | |
47 | if re_linguas.match(lang): | |
48 | node=self.path.find_resource(os.path.join(podir,re_linguas.match(lang).group()+'.po')) | |
49 | task=self.create_task('po',node,node.change_ext('.mo')) | |
50 | if inst: | |
51 | filename=task.outputs[0].name | |
52 | (langname,ext)=os.path.splitext(filename) | |
53 | inst_file=inst+os.sep+langname+os.sep+'LC_MESSAGES'+os.sep+appname+'.mo' | |
54 | self.bld.install_as(inst_file,task.outputs[0],chmod=getattr(self,'chmod',Utils.O644),env=task.env) | |
55 | else: | |
56 | Logs.pprint('RED',"Error no LINGUAS file found in po directory") | |
57 | class po(Task.Task): | |
58 | run_str='${MSGFMT} -o ${TGT} ${SRC}' | |
59 | color='BLUE' | |
60 | class intltool(Task.Task): | |
61 | run_str='${INTLTOOL} ${INTLFLAGS} ${INTLCACHE} ${INTLPODIR} ${SRC} ${TGT}' | |
62 | color='BLUE' | |
63 | def configure(conf): | |
64 | conf.find_program('msgfmt',var='MSGFMT') | |
65 | conf.find_perl_program('intltool-merge',var='INTLTOOL') | |
66 | prefix=conf.env.PREFIX | |
67 | datadir=conf.env.DATADIR | |
68 | if not datadir: | |
69 | datadir=os.path.join(prefix,'share') | |
70 | conf.define('LOCALEDIR',os.path.join(datadir,'locale').replace('\\','\\\\')) | |
71 | conf.define('DATADIR',datadir.replace('\\','\\\\')) | |
72 | if conf.env.CC or conf.env.CXX: | |
73 | conf.check(header_name='locale.h') | |
74 | ||
75 | before_method('process_source')(apply_intltool_in_f) | |
76 | feature('intltool_in')(apply_intltool_in_f) | |
77 | feature('intltool_po')(apply_intltool_po)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Utils | |
6 | from waflib.Tools import ccroot,ar | |
7 | from waflib.Configure import conf | |
8 | def find_irixcc(conf): | |
9 | v=conf.env | |
10 | cc=None | |
11 | if v['CC']:cc=v['CC'] | |
12 | elif'CC'in conf.environ:cc=conf.environ['CC'] | |
13 | if not cc:cc=conf.find_program('cc',var='CC') | |
14 | if not cc:conf.fatal('irixcc was not found') | |
15 | cc=conf.cmd_to_list(cc) | |
16 | try: | |
17 | conf.cmd_and_log(cc+['-version']) | |
18 | except: | |
19 | conf.fatal('%r -version could not be executed'%cc) | |
20 | v['CC']=cc | |
21 | v['CC_NAME']='irix' | |
22 | def irixcc_common_flags(conf): | |
23 | v=conf.env | |
24 | v['CC_SRC_F']='' | |
25 | v['CC_TGT_F']=['-c','-o'] | |
26 | v['CPPPATH_ST']='-I%s' | |
27 | v['DEFINES_ST']='-D%s' | |
28 | if not v['LINK_CC']:v['LINK_CC']=v['CC'] | |
29 | v['CCLNK_SRC_F']='' | |
30 | v['CCLNK_TGT_F']=['-o'] | |
31 | v['LIB_ST']='-l%s' | |
32 | v['LIBPATH_ST']='-L%s' | |
33 | v['STLIB_ST']='-l%s' | |
34 | v['STLIBPATH_ST']='-L%s' | |
35 | v['cprogram_PATTERN']='%s' | |
36 | v['cshlib_PATTERN']='lib%s.so' | |
37 | v['cstlib_PATTERN']='lib%s.a' | |
38 | def configure(conf): | |
39 | conf.find_irixcc() | |
40 | conf.find_cpp() | |
41 | conf.find_ar() | |
42 | conf.irixcc_common_flags() | |
43 | conf.cc_load_tools() | |
44 | conf.cc_add_flags() | |
45 | conf.link_add_flags() | |
46 | ||
47 | conf(find_irixcc) | |
48 | conf(irixcc_common_flags)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import os,re,tempfile,shutil | |
7 | from waflib.Configure import conf | |
8 | from waflib import TaskGen,Task,Utils,Options,Build,Errors,Node,Logs | |
9 | from waflib.TaskGen import feature,before_method,after_method | |
10 | from waflib.Tools import ccroot | |
11 | ccroot.USELIB_VARS['javac']=set(['CLASSPATH','JAVACFLAGS']) | |
12 | SOURCE_RE='**/*.java' | |
13 | JAR_RE='**/*' | |
14 | class_check_source=''' | |
15 | public class Test { | |
16 | public static void main(String[] argv) { | |
17 | Class lib; | |
18 | if (argv.length < 1) { | |
19 | System.err.println("Missing argument"); | |
20 | System.exit(77); | |
21 | } | |
22 | try { | |
23 | lib = Class.forName(argv[0]); | |
24 | } catch (ClassNotFoundException e) { | |
25 | System.err.println("ClassNotFoundException"); | |
26 | System.exit(1); | |
27 | } | |
28 | lib = null; | |
29 | System.exit(0); | |
30 | } | |
31 | } | |
32 | ''' | |
33 | def apply_java(self): | |
34 | Utils.def_attrs(self,jarname='',classpath='',sourcepath='.',srcdir='.',jar_mf_attributes={},jar_mf_classpath=[]) | |
35 | nodes_lst=[] | |
36 | outdir=getattr(self,'outdir',None) | |
37 | if outdir: | |
38 | if not isinstance(outdir,Node.Node): | |
39 | outdir=self.path.get_bld().make_node(self.outdir) | |
40 | else: | |
41 | outdir=self.path.get_bld() | |
42 | outdir.mkdir() | |
43 | self.outdir=outdir | |
44 | self.env['OUTDIR']=outdir.abspath() | |
45 | self.javac_task=tsk=self.create_task('javac') | |
46 | tmp=[] | |
47 | srcdir=getattr(self,'srcdir','') | |
48 | if isinstance(srcdir,Node.Node): | |
49 | srcdir=[srcdir] | |
50 | for x in Utils.to_list(srcdir): | |
51 | if isinstance(x,Node.Node): | |
52 | y=x | |
53 | else: | |
54 | y=self.path.find_dir(x) | |
55 | if not y: | |
56 | self.bld.fatal('Could not find the folder %s from %s'%(x,self.path)) | |
57 | tmp.append(y) | |
58 | tsk.srcdir=tmp | |
59 | if getattr(self,'compat',None): | |
60 | tsk.env.append_value('JAVACFLAGS',['-source',self.compat]) | |
61 | if hasattr(self,'sourcepath'): | |
62 | fold=[isinstance(x,Node.Node)and x or self.path.find_dir(x)for x in self.to_list(self.sourcepath)] | |
63 | names=os.pathsep.join([x.srcpath()for x in fold]) | |
64 | else: | |
65 | names=[x.srcpath()for x in tsk.srcdir] | |
66 | if names: | |
67 | tsk.env.append_value('JAVACFLAGS',['-sourcepath',names]) | |
68 | def use_javac_files(self): | |
69 | lst=[] | |
70 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
71 | names=self.to_list(getattr(self,'use',[])) | |
72 | get=self.bld.get_tgen_by_name | |
73 | for x in names: | |
74 | try: | |
75 | y=get(x) | |
76 | except: | |
77 | self.uselib.append(x) | |
78 | else: | |
79 | y.post() | |
80 | lst.append(y.jar_task.outputs[0].abspath()) | |
81 | self.javac_task.set_run_after(y.jar_task) | |
82 | if lst: | |
83 | self.env.append_value('CLASSPATH',lst) | |
84 | def set_classpath(self): | |
85 | self.env.append_value('CLASSPATH',getattr(self,'classpath',[])) | |
86 | for x in self.tasks: | |
87 | x.env.CLASSPATH=os.pathsep.join(self.env.CLASSPATH)+os.pathsep | |
88 | def jar_files(self): | |
89 | destfile=getattr(self,'destfile','test.jar') | |
90 | jaropts=getattr(self,'jaropts',[]) | |
91 | manifest=getattr(self,'manifest',None) | |
92 | basedir=getattr(self,'basedir',None) | |
93 | if basedir: | |
94 | if not isinstance(self.basedir,Node.Node): | |
95 | basedir=self.path.get_bld().make_node(basedir) | |
96 | else: | |
97 | basedir=self.path.get_bld() | |
98 | if not basedir: | |
99 | self.bld.fatal('Could not find the basedir %r for %r'%(self.basedir,self)) | |
100 | self.jar_task=tsk=self.create_task('jar_create') | |
101 | if manifest: | |
102 | jarcreate=getattr(self,'jarcreate','cfm') | |
103 | node=self.path.find_node(manifest) | |
104 | tsk.dep_nodes.append(node) | |
105 | jaropts.insert(0,node.abspath()) | |
106 | else: | |
107 | jarcreate=getattr(self,'jarcreate','cf') | |
108 | if not isinstance(destfile,Node.Node): | |
109 | destfile=self.path.find_or_declare(destfile) | |
110 | if not destfile: | |
111 | self.bld.fatal('invalid destfile %r for %r'%(destfile,self)) | |
112 | tsk.set_outputs(destfile) | |
113 | tsk.basedir=basedir | |
114 | jaropts.append('-C') | |
115 | jaropts.append(basedir.bldpath()) | |
116 | jaropts.append('.') | |
117 | tsk.env['JAROPTS']=jaropts | |
118 | tsk.env['JARCREATE']=jarcreate | |
119 | if getattr(self,'javac_task',None): | |
120 | tsk.set_run_after(self.javac_task) | |
121 | def use_jar_files(self): | |
122 | lst=[] | |
123 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
124 | names=self.to_list(getattr(self,'use',[])) | |
125 | get=self.bld.get_tgen_by_name | |
126 | for x in names: | |
127 | try: | |
128 | y=get(x) | |
129 | except: | |
130 | self.uselib.append(x) | |
131 | else: | |
132 | y.post() | |
133 | self.jar_task.run_after.update(y.tasks) | |
134 | class jar_create(Task.Task): | |
135 | color='GREEN' | |
136 | run_str='${JAR} ${JARCREATE} ${TGT} ${JAROPTS}' | |
137 | def runnable_status(self): | |
138 | for t in self.run_after: | |
139 | if not t.hasrun: | |
140 | return Task.ASK_LATER | |
141 | if not self.inputs: | |
142 | global JAR_RE | |
143 | try: | |
144 | self.inputs=[x for x in self.basedir.ant_glob(JAR_RE,remove=False)if id(x)!=id(self.outputs[0])] | |
145 | except: | |
146 | raise Errors.WafError('Could not find the basedir %r for %r'%(self.basedir,self)) | |
147 | return super(jar_create,self).runnable_status() | |
148 | class javac(Task.Task): | |
149 | color='BLUE' | |
150 | nocache=True | |
151 | vars=['CLASSPATH','JAVACFLAGS','JAVAC','OUTDIR'] | |
152 | def runnable_status(self): | |
153 | for t in self.run_after: | |
154 | if not t.hasrun: | |
155 | return Task.ASK_LATER | |
156 | if not self.inputs: | |
157 | global SOURCE_RE | |
158 | self.inputs=[] | |
159 | for x in self.srcdir: | |
160 | self.inputs.extend(x.ant_glob(SOURCE_RE,remove=False)) | |
161 | return super(javac,self).runnable_status() | |
162 | def run(self): | |
163 | env=self.env | |
164 | gen=self.generator | |
165 | bld=gen.bld | |
166 | wd=bld.bldnode.abspath() | |
167 | def to_list(xx): | |
168 | if isinstance(xx,str):return[xx] | |
169 | return xx | |
170 | cmd=[] | |
171 | cmd.extend(to_list(env['JAVAC'])) | |
172 | cmd.extend(['-classpath']) | |
173 | cmd.extend(to_list(env['CLASSPATH'])) | |
174 | cmd.extend(['-d']) | |
175 | cmd.extend(to_list(env['OUTDIR'])) | |
176 | cmd.extend(to_list(env['JAVACFLAGS'])) | |
177 | files=[a.path_from(bld.bldnode)for a in self.inputs] | |
178 | tmp=None | |
179 | try: | |
180 | if len(str(files))+len(str(cmd))>8192: | |
181 | (fd,tmp)=tempfile.mkstemp(dir=bld.bldnode.abspath()) | |
182 | try: | |
183 | os.write(fd,'\n'.join(files)) | |
184 | finally: | |
185 | if tmp: | |
186 | os.close(fd) | |
187 | if Logs.verbose: | |
188 | Logs.debug('runner: %r'%(cmd+files)) | |
189 | cmd.append('@'+tmp) | |
190 | else: | |
191 | cmd+=files | |
192 | ret=self.exec_command(cmd,cwd=wd,env=env.env or None) | |
193 | finally: | |
194 | if tmp: | |
195 | os.unlink(tmp) | |
196 | return ret | |
197 | def post_run(self): | |
198 | for n in self.generator.outdir.ant_glob('**/*.class'): | |
199 | n.sig=Utils.h_file(n.abspath()) | |
200 | self.generator.bld.task_sigs[self.uid()]=self.cache_sig | |
201 | def configure(self): | |
202 | java_path=self.environ['PATH'].split(os.pathsep) | |
203 | v=self.env | |
204 | if'JAVA_HOME'in self.environ: | |
205 | java_path=[os.path.join(self.environ['JAVA_HOME'],'bin')]+java_path | |
206 | self.env['JAVA_HOME']=[self.environ['JAVA_HOME']] | |
207 | for x in'javac java jar'.split(): | |
208 | self.find_program(x,var=x.upper(),path_list=java_path) | |
209 | self.env[x.upper()]=self.cmd_to_list(self.env[x.upper()]) | |
210 | if'CLASSPATH'in self.environ: | |
211 | v['CLASSPATH']=self.environ['CLASSPATH'] | |
212 | if not v['JAR']:self.fatal('jar is required for making java packages') | |
213 | if not v['JAVAC']:self.fatal('javac is required for compiling java classes') | |
214 | v['JARCREATE']='cf' | |
215 | v['JAVACFLAGS']=[] | |
216 | def check_java_class(self,classname,with_classpath=None): | |
217 | javatestdir='.waf-javatest' | |
218 | classpath=javatestdir | |
219 | if self.env['CLASSPATH']: | |
220 | classpath+=os.pathsep+self.env['CLASSPATH'] | |
221 | if isinstance(with_classpath,str): | |
222 | classpath+=os.pathsep+with_classpath | |
223 | shutil.rmtree(javatestdir,True) | |
224 | os.mkdir(javatestdir) | |
225 | java_file=open(os.path.join(javatestdir,'Test.java'),'w') | |
226 | java_file.write(class_check_source) | |
227 | java_file.close() | |
228 | self.exec_command(self.env['JAVAC']+[os.path.join(javatestdir,'Test.java')],shell=False) | |
229 | cmd=self.env['JAVA']+['-cp',classpath,'Test',classname] | |
230 | self.to_log("%s\n"%str(cmd)) | |
231 | found=self.exec_command(cmd,shell=False) | |
232 | self.msg('Checking for java class %s'%classname,not found) | |
233 | shutil.rmtree(javatestdir,True) | |
234 | return found | |
235 | def check_jni_headers(conf): | |
236 | if not conf.env.CC_NAME and not conf.env.CXX_NAME: | |
237 | conf.fatal('load a compiler first (gcc, g++, ..)') | |
238 | if not conf.env.JAVA_HOME: | |
239 | conf.fatal('set JAVA_HOME in the system environment') | |
240 | javaHome=conf.env['JAVA_HOME'][0] | |
241 | dir=conf.root.find_dir(conf.env.JAVA_HOME[0]+'/include') | |
242 | if dir is None: | |
243 | conf.fatal('JAVA_HOME does not seem to be set properly') | |
244 | f=dir.ant_glob('**/(jni|jni_md).h') | |
245 | incDirs=[x.parent.abspath()for x in f] | |
246 | dir=conf.root.find_dir(conf.env.JAVA_HOME[0]) | |
247 | f=dir.ant_glob('**/*jvm.(so|dll|dylib)') | |
248 | libDirs=[x.parent.abspath()for x in f]or[javaHome] | |
249 | f=dir.ant_glob('**/*jvm.(lib)') | |
250 | if f: | |
251 | libDirs=[[x,y.parent.abspath()]for x in libDirs for y in f] | |
252 | for d in libDirs: | |
253 | try: | |
254 | conf.check(header_name='jni.h',define_name='HAVE_JNI_H',lib='jvm',libpath=d,includes=incDirs,uselib_store='JAVA',uselib='JAVA') | |
255 | except: | |
256 | pass | |
257 | else: | |
258 | break | |
259 | else: | |
260 | conf.fatal('could not find lib jvm in %r (see config.log)'%libDirs) | |
261 | ||
262 | feature('javac')(apply_java) | |
263 | before_method('process_source')(apply_java) | |
264 | feature('javac')(use_javac_files) | |
265 | after_method('apply_java')(use_javac_files) | |
266 | feature('javac')(set_classpath) | |
267 | after_method('apply_java','propagate_uselib_vars','use_javac_files')(set_classpath) | |
268 | feature('jar')(jar_files) | |
269 | after_method('apply_java','use_javac_files')(jar_files) | |
270 | before_method('process_source')(jar_files) | |
271 | feature('jar')(use_jar_files) | |
272 | after_method('jar_files')(use_jar_files) | |
273 | conf(check_java_class) | |
274 | conf(check_jni_headers)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,re | |
5 | from waflib import Options,TaskGen,Task,Utils | |
6 | from waflib.TaskGen import feature,after_method | |
7 | def apply_msgfmt(self): | |
8 | for lang in self.to_list(self.langs): | |
9 | node=self.path.find_resource(lang+'.po') | |
10 | task=self.create_task('msgfmt',node,node.change_ext('.mo')) | |
11 | langname=lang.split('/') | |
12 | langname=langname[-1] | |
13 | inst=getattr(self,'install_path','${KDE4_LOCALE_INSTALL_DIR}') | |
14 | self.bld.install_as(inst+os.sep+langname+os.sep+'LC_MESSAGES'+os.sep+getattr(self,'appname','set_your_appname')+'.mo',task.outputs[0],chmod=getattr(self,'chmod',Utils.O644)) | |
15 | class msgfmt(Task.Task): | |
16 | color='BLUE' | |
17 | run_str='${MSGFMT} ${SRC} -o ${TGT}' | |
18 | def configure(self): | |
19 | kdeconfig=self.find_program('kde4-config') | |
20 | prefix=self.cmd_and_log('%s --prefix'%kdeconfig).strip() | |
21 | fname='%s/share/apps/cmake/modules/KDELibsDependencies.cmake'%prefix | |
22 | try:os.stat(fname) | |
23 | except OSError: | |
24 | fname='%s/share/kde4/apps/cmake/modules/KDELibsDependencies.cmake'%prefix | |
25 | try:os.stat(fname) | |
26 | except OSError:self.fatal('could not open %s'%fname) | |
27 | try: | |
28 | txt=Utils.readf(fname) | |
29 | except(OSError,IOError): | |
30 | self.fatal('could not read %s'%fname) | |
31 | txt=txt.replace('\\\n','\n') | |
32 | fu=re.compile('#(.*)\n') | |
33 | txt=fu.sub('',txt) | |
34 | setregexp=re.compile('([sS][eE][tT]\s*\()\s*([^\s]+)\s+\"([^"]+)\"\)') | |
35 | found=setregexp.findall(txt) | |
36 | for(_,key,val)in found: | |
37 | self.env[key]=val | |
38 | self.env['LIB_KDECORE']=['kdecore'] | |
39 | self.env['LIB_KDEUI']=['kdeui'] | |
40 | self.env['LIB_KIO']=['kio'] | |
41 | self.env['LIB_KHTML']=['khtml'] | |
42 | self.env['LIB_KPARTS']=['kparts'] | |
43 | self.env['LIBPATH_KDECORE']=[self.env['KDE4_LIB_INSTALL_DIR']] | |
44 | self.env['INCLUDES_KDECORE']=[self.env['KDE4_INCLUDE_INSTALL_DIR']] | |
45 | self.env.append_value('INCLUDES_KDECORE',[self.env['KDE4_INCLUDE_INSTALL_DIR']+os.sep+'KDE']) | |
46 | self.find_program('msgfmt',var='MSGFMT') | |
47 | ||
48 | feature('msgfmt')(apply_msgfmt)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib.TaskGen import extension | |
5 | from waflib import Task,Utils | |
6 | def add_lua(self,node): | |
7 | tsk=self.create_task('luac',node,node.change_ext('.luac')) | |
8 | inst_to=getattr(self,'install_path',self.env.LUADIR and'${LUADIR}'or None) | |
9 | if inst_to: | |
10 | self.bld.install_files(inst_to,tsk.outputs) | |
11 | return tsk | |
12 | class luac(Task.Task): | |
13 | run_str='${LUAC} -s -o ${TGT} ${SRC}' | |
14 | color='PINK' | |
15 | def configure(conf): | |
16 | conf.find_program('luac',var='LUAC') | |
17 | ||
18 | extension('.lua')(add_lua)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,re,tempfile | |
5 | try: | |
6 | import _winreg | |
7 | except: | |
8 | try: | |
9 | import winreg as _winreg | |
10 | except: | |
11 | _winreg=None | |
12 | from waflib import Utils,TaskGen,Runner,Configure,Task,Options | |
13 | from waflib.Logs import debug,info,warn,error | |
14 | from waflib.TaskGen import after_method,before_method,feature | |
15 | from waflib.Configure import conf | |
16 | from waflib.Tools import ccroot,c,cxx,ar,winres | |
17 | g_msvc_systemlibs=''' | |
18 | aclui activeds ad1 adptif adsiid advapi32 asycfilt authz bhsupp bits bufferoverflowu cabinet | |
19 | cap certadm certidl ciuuid clusapi comctl32 comdlg32 comsupp comsuppd comsuppw comsuppwd comsvcs | |
20 | credui crypt32 cryptnet cryptui d3d8thk daouuid dbgeng dbghelp dciman32 ddao35 ddao35d | |
21 | ddao35u ddao35ud delayimp dhcpcsvc dhcpsapi dlcapi dnsapi dsprop dsuiext dtchelp | |
22 | faultrep fcachdll fci fdi framedyd framedyn gdi32 gdiplus glauxglu32 gpedit gpmuuid | |
23 | gtrts32w gtrtst32hlink htmlhelp httpapi icm32 icmui imagehlp imm32 iphlpapi iprop | |
24 | kernel32 ksguid ksproxy ksuser libcmt libcmtd libcpmt libcpmtd loadperf lz32 mapi | |
25 | mapi32 mgmtapi minidump mmc mobsync mpr mprapi mqoa mqrt msacm32 mscms mscoree | |
26 | msdasc msimg32 msrating mstask msvcmrt msvcurt msvcurtd mswsock msxml2 mtx mtxdm | |
27 | netapi32 nmapinmsupp npptools ntdsapi ntdsbcli ntmsapi ntquery odbc32 odbcbcp | |
28 | odbccp32 oldnames ole32 oleacc oleaut32 oledb oledlgolepro32 opends60 opengl32 | |
29 | osptk parser pdh penter pgobootrun pgort powrprof psapi ptrustm ptrustmd ptrustu | |
30 | ptrustud qosname rasapi32 rasdlg rassapi resutils riched20 rpcndr rpcns4 rpcrt4 rtm | |
31 | rtutils runtmchk scarddlg scrnsave scrnsavw secur32 sensapi setupapi sfc shell32 | |
32 | shfolder shlwapi sisbkup snmpapi sporder srclient sti strsafe svcguid tapi32 thunk32 | |
33 | traffic unicows url urlmon user32 userenv usp10 uuid uxtheme vcomp vcompd vdmdbg | |
34 | version vfw32 wbemuuid webpost wiaguid wininet winmm winscard winspool winstrm | |
35 | wintrust wldap32 wmiutils wow32 ws2_32 wsnmp32 wsock32 wst wtsapi32 xaswitch xolehlp | |
36 | '''.split() | |
37 | all_msvc_platforms=[('x64','amd64'),('x86','x86'),('ia64','ia64'),('x86_amd64','amd64'),('x86_ia64','ia64')] | |
38 | all_wince_platforms=[('armv4','arm'),('armv4i','arm'),('mipsii','mips'),('mipsii_fp','mips'),('mipsiv','mips'),('mipsiv_fp','mips'),('sh4','sh'),('x86','cex86')] | |
39 | all_icl_platforms=[('intel64','amd64'),('em64t','amd64'),('ia32','x86'),('Itanium','ia64')] | |
40 | def options(opt): | |
41 | opt.add_option('--msvc_version',type='string',help='msvc version, eg: "msvc 10.0,msvc 9.0"',default='') | |
42 | opt.add_option('--msvc_targets',type='string',help='msvc targets, eg: "x64,arm"',default='') | |
43 | def setup_msvc(conf,versions): | |
44 | platforms=getattr(Options.options,'msvc_targets','').split(',') | |
45 | if platforms==['']: | |
46 | platforms=Utils.to_list(conf.env['MSVC_TARGETS'])or[i for i,j in all_msvc_platforms+all_icl_platforms+all_wince_platforms] | |
47 | desired_versions=getattr(Options.options,'msvc_version','').split(',') | |
48 | if desired_versions==['']: | |
49 | desired_versions=conf.env['MSVC_VERSIONS']or[v for v,_ in versions][::-1] | |
50 | versiondict=dict(versions) | |
51 | for version in desired_versions: | |
52 | try: | |
53 | targets=dict(versiondict[version]) | |
54 | for target in platforms: | |
55 | try: | |
56 | arch,(p1,p2,p3)=targets[target] | |
57 | compiler,revision=version.rsplit(' ',1) | |
58 | return compiler,revision,p1,p2,p3 | |
59 | except KeyError:continue | |
60 | except KeyError:continue | |
61 | conf.fatal('msvc: Impossible to find a valid architecture for building (in setup_msvc)') | |
62 | def get_msvc_version(conf,compiler,version,target,vcvars): | |
63 | debug('msvc: get_msvc_version: %r %r %r',compiler,version,target) | |
64 | batfile=conf.bldnode.make_node('waf-print-msvc.bat') | |
65 | batfile.write("""@echo off | |
66 | set INCLUDE= | |
67 | set LIB= | |
68 | call "%s" %s | |
69 | echo PATH=%%PATH%% | |
70 | echo INCLUDE=%%INCLUDE%% | |
71 | echo LIB=%%LIB%% | |
72 | """%(vcvars,target)) | |
73 | sout=conf.cmd_and_log(['cmd','/E:on','/V:on','/C',batfile.abspath()]) | |
74 | lines=sout.splitlines() | |
75 | if not lines[0]:lines=lines[1:] | |
76 | for x in('Setting environment','Setting SDK environment','Intel(R) C++ Compiler','Intel Parallel Studio'): | |
77 | if lines[0].find(x)!=-1: | |
78 | break | |
79 | else: | |
80 | debug('msvc: get_msvc_version: %r %r %r -> not found',compiler,version,target) | |
81 | conf.fatal('msvc: Impossible to find a valid architecture for building (in get_msvc_version)') | |
82 | for line in lines[1:]: | |
83 | if line.startswith('PATH='): | |
84 | path=line[5:] | |
85 | MSVC_PATH=path.split(';') | |
86 | elif line.startswith('INCLUDE='): | |
87 | MSVC_INCDIR=[i for i in line[8:].split(';')if i] | |
88 | elif line.startswith('LIB='): | |
89 | MSVC_LIBDIR=[i for i in line[4:].split(';')if i] | |
90 | env={} | |
91 | env.update(os.environ) | |
92 | env.update(PATH=path) | |
93 | compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler) | |
94 | cxx=conf.find_program(compiler_name,path_list=MSVC_PATH) | |
95 | cxx=conf.cmd_to_list(cxx) | |
96 | if'CL'in env: | |
97 | del(env['CL']) | |
98 | try: | |
99 | try: | |
100 | conf.cmd_and_log(cxx+['/help'],env=env) | |
101 | except Exception ,e: | |
102 | debug('msvc: get_msvc_version: %r %r %r -> failure'%(compiler,version,target)) | |
103 | debug(str(e)) | |
104 | conf.fatal('msvc: cannot run the compiler (in get_msvc_version)') | |
105 | else: | |
106 | debug('msvc: get_msvc_version: %r %r %r -> OK',compiler,version,target) | |
107 | finally: | |
108 | conf.env[compiler_name]='' | |
109 | return(MSVC_PATH,MSVC_INCDIR,MSVC_LIBDIR) | |
110 | def gather_wsdk_versions(conf,versions): | |
111 | version_pattern=re.compile('^v..?.?\...?.?') | |
112 | try: | |
113 | all_versions=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432node\\Microsoft\\Microsoft SDKs\\Windows') | |
114 | except WindowsError: | |
115 | try: | |
116 | all_versions=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows') | |
117 | except WindowsError: | |
118 | return | |
119 | index=0 | |
120 | while 1: | |
121 | try: | |
122 | version=_winreg.EnumKey(all_versions,index) | |
123 | except WindowsError: | |
124 | break | |
125 | index=index+1 | |
126 | if not version_pattern.match(version): | |
127 | continue | |
128 | try: | |
129 | msvc_version=_winreg.OpenKey(all_versions,version) | |
130 | path,type=_winreg.QueryValueEx(msvc_version,'InstallationFolder') | |
131 | except WindowsError: | |
132 | continue | |
133 | if os.path.isfile(os.path.join(path,'bin','SetEnv.cmd')): | |
134 | targets=[] | |
135 | for target,arch in all_msvc_platforms: | |
136 | try: | |
137 | targets.append((target,(arch,conf.get_msvc_version('wsdk',version,'/'+target,os.path.join(path,'bin','SetEnv.cmd'))))) | |
138 | except conf.errors.ConfigurationError: | |
139 | pass | |
140 | versions.append(('wsdk '+version[1:],targets)) | |
141 | def gather_wince_supported_platforms(): | |
142 | supported_wince_platforms=[] | |
143 | try: | |
144 | ce_sdk=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432node\\Microsoft\\Windows CE Tools\\SDKs') | |
145 | except WindowsError: | |
146 | try: | |
147 | ce_sdk=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Microsoft\\Windows CE Tools\\SDKs') | |
148 | except WindowsError: | |
149 | ce_sdk='' | |
150 | if not ce_sdk: | |
151 | return supported_wince_platforms | |
152 | ce_index=0 | |
153 | while 1: | |
154 | try: | |
155 | sdk_device=_winreg.EnumKey(ce_sdk,ce_index) | |
156 | except WindowsError: | |
157 | break | |
158 | ce_index=ce_index+1 | |
159 | sdk=_winreg.OpenKey(ce_sdk,sdk_device) | |
160 | try: | |
161 | path,type=_winreg.QueryValueEx(sdk,'SDKRootDir') | |
162 | except WindowsError: | |
163 | try: | |
164 | path,type=_winreg.QueryValueEx(sdk,'SDKInformation') | |
165 | path,xml=os.path.split(path) | |
166 | except WindowsError: | |
167 | continue | |
168 | path=str(path) | |
169 | path,device=os.path.split(path) | |
170 | if not device: | |
171 | path,device=os.path.split(path) | |
172 | for arch,compiler in all_wince_platforms: | |
173 | platforms=[] | |
174 | if os.path.isdir(os.path.join(path,device,'Lib',arch)): | |
175 | platforms.append((arch,compiler,os.path.join(path,device,'Include',arch),os.path.join(path,device,'Lib',arch))) | |
176 | if platforms: | |
177 | supported_wince_platforms.append((device,platforms)) | |
178 | return supported_wince_platforms | |
179 | def gather_msvc_detected_versions(): | |
180 | version_pattern=re.compile('^(\d\d?\.\d\d?)(Exp)?$') | |
181 | detected_versions=[] | |
182 | for vcver,vcvar in[('VCExpress','Exp'),('VisualStudio','')]: | |
183 | try: | |
184 | prefix='SOFTWARE\\Wow6432node\\Microsoft\\'+vcver | |
185 | all_versions=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,prefix) | |
186 | except WindowsError: | |
187 | try: | |
188 | prefix='SOFTWARE\\Microsoft\\'+vcver | |
189 | all_versions=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,prefix) | |
190 | except WindowsError: | |
191 | continue | |
192 | index=0 | |
193 | while 1: | |
194 | try: | |
195 | version=_winreg.EnumKey(all_versions,index) | |
196 | except WindowsError: | |
197 | break | |
198 | index=index+1 | |
199 | match=version_pattern.match(version) | |
200 | if not match: | |
201 | continue | |
202 | else: | |
203 | versionnumber=float(match.group(1)) | |
204 | detected_versions.append((versionnumber,version+vcvar,prefix+"\\"+version)) | |
205 | def fun(tup): | |
206 | return tup[0] | |
207 | try: | |
208 | detected_versions.sort(key=fun) | |
209 | except: | |
210 | detected_versions.sort(lambda x,y:cmp(x[0],y[0])) | |
211 | return detected_versions | |
212 | def gather_msvc_targets(conf,versions,version,vc_path): | |
213 | targets=[] | |
214 | if os.path.isfile(os.path.join(vc_path,'vcvarsall.bat')): | |
215 | for target,realtarget in all_msvc_platforms[::-1]: | |
216 | try: | |
217 | targets.append((target,(realtarget,conf.get_msvc_version('msvc',version,target,os.path.join(vc_path,'vcvarsall.bat'))))) | |
218 | except conf.errors.ConfigurationError: | |
219 | pass | |
220 | elif os.path.isfile(os.path.join(vc_path,'Common7','Tools','vsvars32.bat')): | |
221 | try: | |
222 | targets.append(('x86',('x86',conf.get_msvc_version('msvc',version,'x86',os.path.join(vc_path,'Common7','Tools','vsvars32.bat'))))) | |
223 | except conf.errors.ConfigurationError: | |
224 | pass | |
225 | elif os.path.isfile(os.path.join(vc_path,'Bin','vcvars32.bat')): | |
226 | try: | |
227 | targets.append(('x86',('x86',conf.get_msvc_version('msvc',version,'',os.path.join(vc_path,'Bin','vcvars32.bat'))))) | |
228 | except conf.errors.ConfigurationError: | |
229 | pass | |
230 | versions.append(('msvc '+version,targets)) | |
231 | def gather_wince_targets(conf,versions,version,vc_path,vsvars,supported_platforms): | |
232 | for device,platforms in supported_platforms: | |
233 | cetargets=[] | |
234 | for platform,compiler,include,lib in platforms: | |
235 | winCEpath=os.path.join(vc_path,'ce') | |
236 | if not os.path.isdir(winCEpath): | |
237 | continue | |
238 | try: | |
239 | common_bindirs,_1,_2=conf.get_msvc_version('msvc',version,'x86',vsvars) | |
240 | except conf.errors.ConfigurationError: | |
241 | continue | |
242 | if os.path.isdir(os.path.join(winCEpath,'lib',platform)): | |
243 | bindirs=[os.path.join(winCEpath,'bin',compiler),os.path.join(winCEpath,'bin','x86_'+compiler)]+common_bindirs | |
244 | incdirs=[os.path.join(winCEpath,'include'),os.path.join(winCEpath,'atlmfc','include'),include] | |
245 | libdirs=[os.path.join(winCEpath,'lib',platform),os.path.join(winCEpath,'atlmfc','lib',platform),lib] | |
246 | cetargets.append((platform,(platform,(bindirs,incdirs,libdirs)))) | |
247 | if cetargets: | |
248 | versions.append((device+' '+version,cetargets)) | |
249 | def gather_msvc_versions(conf,versions): | |
250 | vc_paths=[] | |
251 | for(v,version,reg)in gather_msvc_detected_versions(): | |
252 | try: | |
253 | try: | |
254 | msvc_version=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,reg+"\\Setup\\VC") | |
255 | except WindowsError: | |
256 | msvc_version=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,reg+"\\Setup\\Microsoft Visual C++") | |
257 | path,type=_winreg.QueryValueEx(msvc_version,'ProductDir') | |
258 | vc_paths.append((version,os.path.abspath(str(path)))) | |
259 | except WindowsError: | |
260 | continue | |
261 | wince_supported_platforms=gather_wince_supported_platforms() | |
262 | for version,vc_path in vc_paths: | |
263 | vs_path=os.path.dirname(vc_path) | |
264 | vsvars=os.path.join(vs_path,'Common7','Tools','vsvars32.bat') | |
265 | if wince_supported_platforms and os.path.isfile(vsvars): | |
266 | conf.gather_wince_targets(versions,version,vc_path,vsvars,wince_supported_platforms) | |
267 | for version,vc_path in vc_paths: | |
268 | vs_path=os.path.dirname(vc_path) | |
269 | conf.gather_msvc_targets(versions,version,vc_path) | |
270 | def gather_icl_versions(conf,versions): | |
271 | version_pattern=re.compile('^...?.?\....?.?') | |
272 | try: | |
273 | all_versions=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Wow6432node\\Intel\\Compilers\\C++') | |
274 | except WindowsError: | |
275 | try: | |
276 | all_versions=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,'SOFTWARE\\Intel\\Compilers\\C++') | |
277 | except WindowsError: | |
278 | return | |
279 | index=0 | |
280 | while 1: | |
281 | try: | |
282 | version=_winreg.EnumKey(all_versions,index) | |
283 | except WindowsError: | |
284 | break | |
285 | index=index+1 | |
286 | if not version_pattern.match(version): | |
287 | continue | |
288 | targets=[] | |
289 | for target,arch in all_icl_platforms: | |
290 | try: | |
291 | if target=='intel64':targetDir='EM64T_NATIVE' | |
292 | else:targetDir=target | |
293 | _winreg.OpenKey(all_versions,version+'\\'+targetDir) | |
294 | icl_version=_winreg.OpenKey(all_versions,version) | |
295 | path,type=_winreg.QueryValueEx(icl_version,'ProductDir') | |
296 | if os.path.isfile(os.path.join(path,'bin','iclvars.bat')): | |
297 | try: | |
298 | targets.append((target,(arch,conf.get_msvc_version('intel',version,target,os.path.join(path,'bin','iclvars.bat'))))) | |
299 | except conf.errors.ConfigurationError: | |
300 | pass | |
301 | except WindowsError: | |
302 | pass | |
303 | for target,arch in all_icl_platforms: | |
304 | try: | |
305 | icl_version=_winreg.OpenKey(all_versions,version+'\\'+target) | |
306 | path,type=_winreg.QueryValueEx(icl_version,'ProductDir') | |
307 | if os.path.isfile(os.path.join(path,'bin','iclvars.bat')): | |
308 | try: | |
309 | targets.append((target,(arch,conf.get_msvc_version('intel',version,target,os.path.join(path,'bin','iclvars.bat'))))) | |
310 | except conf.errors.ConfigurationError: | |
311 | pass | |
312 | except WindowsError: | |
313 | continue | |
314 | major=version[0:2] | |
315 | versions.append(('intel '+major,targets)) | |
316 | def get_msvc_versions(conf): | |
317 | if not conf.env['MSVC_INSTALLED_VERSIONS']: | |
318 | lst=[] | |
319 | conf.gather_icl_versions(lst) | |
320 | conf.gather_wsdk_versions(lst) | |
321 | conf.gather_msvc_versions(lst) | |
322 | conf.env['MSVC_INSTALLED_VERSIONS']=lst | |
323 | return conf.env['MSVC_INSTALLED_VERSIONS'] | |
324 | def print_all_msvc_detected(conf): | |
325 | for version,targets in conf.env['MSVC_INSTALLED_VERSIONS']: | |
326 | info(version) | |
327 | for target,l in targets: | |
328 | info("\t"+target) | |
329 | def detect_msvc(conf): | |
330 | versions=get_msvc_versions(conf) | |
331 | return setup_msvc(conf,versions) | |
332 | def find_lt_names_msvc(self,libname,is_static=False): | |
333 | lt_names=['lib%s.la'%libname,'%s.la'%libname,] | |
334 | for path in self.env['LIBPATH']: | |
335 | for la in lt_names: | |
336 | laf=os.path.join(path,la) | |
337 | dll=None | |
338 | if os.path.exists(laf): | |
339 | ltdict=Utils.read_la_file(laf) | |
340 | lt_libdir=None | |
341 | if ltdict.get('libdir',''): | |
342 | lt_libdir=ltdict['libdir'] | |
343 | if not is_static and ltdict.get('library_names',''): | |
344 | dllnames=ltdict['library_names'].split() | |
345 | dll=dllnames[0].lower() | |
346 | dll=re.sub('\.dll$','',dll) | |
347 | return(lt_libdir,dll,False) | |
348 | elif ltdict.get('old_library',''): | |
349 | olib=ltdict['old_library'] | |
350 | if os.path.exists(os.path.join(path,olib)): | |
351 | return(path,olib,True) | |
352 | elif lt_libdir!=''and os.path.exists(os.path.join(lt_libdir,olib)): | |
353 | return(lt_libdir,olib,True) | |
354 | else: | |
355 | return(None,olib,True) | |
356 | else: | |
357 | raise self.errors.WafError('invalid libtool object file: %s'%laf) | |
358 | return(None,None,None) | |
359 | def libname_msvc(self,libname,is_static=False): | |
360 | lib=libname.lower() | |
361 | lib=re.sub('\.lib$','',lib) | |
362 | if lib in g_msvc_systemlibs: | |
363 | return lib | |
364 | lib=re.sub('^lib','',lib) | |
365 | if lib=='m': | |
366 | return None | |
367 | (lt_path,lt_libname,lt_static)=self.find_lt_names_msvc(lib,is_static) | |
368 | if lt_path!=None and lt_libname!=None: | |
369 | if lt_static==True: | |
370 | return os.path.join(lt_path,lt_libname) | |
371 | if lt_path!=None: | |
372 | _libpaths=[lt_path]+self.env['LIBPATH'] | |
373 | else: | |
374 | _libpaths=self.env['LIBPATH'] | |
375 | static_libs=['lib%ss.lib'%lib,'lib%s.lib'%lib,'%ss.lib'%lib,'%s.lib'%lib,] | |
376 | dynamic_libs=['lib%s.dll.lib'%lib,'lib%s.dll.a'%lib,'%s.dll.lib'%lib,'%s.dll.a'%lib,'lib%s_d.lib'%lib,'%s_d.lib'%lib,'%s.lib'%lib,] | |
377 | libnames=static_libs | |
378 | if not is_static: | |
379 | libnames=dynamic_libs+static_libs | |
380 | for path in _libpaths: | |
381 | for libn in libnames: | |
382 | if os.path.exists(os.path.join(path,libn)): | |
383 | debug('msvc: lib found: %s'%os.path.join(path,libn)) | |
384 | return re.sub('\.lib$','',libn) | |
385 | self.fatal("The library %r could not be found"%libname) | |
386 | return re.sub('\.lib$','',libname) | |
387 | def check_lib_msvc(self,libname,is_static=False,uselib_store=None): | |
388 | libn=self.libname_msvc(libname,is_static) | |
389 | if not uselib_store: | |
390 | uselib_store=libname.upper() | |
391 | if False and is_static: | |
392 | self.env['STLIB_'+uselib_store]=[libn] | |
393 | else: | |
394 | self.env['LIB_'+uselib_store]=[libn] | |
395 | def check_libs_msvc(self,libnames,is_static=False): | |
396 | for libname in Utils.to_list(libnames): | |
397 | self.check_lib_msvc(libname,is_static) | |
398 | def configure(conf): | |
399 | conf.autodetect() | |
400 | conf.find_msvc() | |
401 | conf.msvc_common_flags() | |
402 | conf.cc_load_tools() | |
403 | conf.cxx_load_tools() | |
404 | conf.cc_add_flags() | |
405 | conf.cxx_add_flags() | |
406 | conf.link_add_flags() | |
407 | conf.visual_studio_add_flags() | |
408 | def no_autodetect(conf): | |
409 | conf.env.NO_MSVC_DETECT=1 | |
410 | configure(conf) | |
411 | def autodetect(conf): | |
412 | v=conf.env | |
413 | if v.NO_MSVC_DETECT: | |
414 | return | |
415 | compiler,version,path,includes,libdirs=conf.detect_msvc() | |
416 | v['PATH']=path | |
417 | v['INCLUDES']=includes | |
418 | v['LIBPATH']=libdirs | |
419 | v['MSVC_COMPILER']=compiler | |
420 | try: | |
421 | v['MSVC_VERSION']=float(version) | |
422 | except: | |
423 | v['MSVC_VERSION']=float(version[:-3]) | |
424 | def _get_prog_names(conf,compiler): | |
425 | if compiler=='intel': | |
426 | compiler_name='ICL' | |
427 | linker_name='XILINK' | |
428 | lib_name='XILIB' | |
429 | else: | |
430 | compiler_name='CL' | |
431 | linker_name='LINK' | |
432 | lib_name='LIB' | |
433 | return compiler_name,linker_name,lib_name | |
434 | def find_msvc(conf): | |
435 | if sys.platform=='cygwin': | |
436 | conf.fatal('MSVC module does not work under cygwin Python!') | |
437 | v=conf.env | |
438 | path=v['PATH'] | |
439 | compiler=v['MSVC_COMPILER'] | |
440 | version=v['MSVC_VERSION'] | |
441 | compiler_name,linker_name,lib_name=_get_prog_names(conf,compiler) | |
442 | v.MSVC_MANIFEST=(compiler=='msvc'and version>=8)or(compiler=='wsdk'and version>=6)or(compiler=='intel'and version>=11) | |
443 | cxx=None | |
444 | if v['CXX']:cxx=v['CXX'] | |
445 | elif'CXX'in conf.environ:cxx=conf.environ['CXX'] | |
446 | cxx=conf.find_program(compiler_name,var='CXX',path_list=path) | |
447 | cxx=conf.cmd_to_list(cxx) | |
448 | env=dict(conf.environ) | |
449 | if path:env.update(PATH=';'.join(path)) | |
450 | if not conf.cmd_and_log(cxx+['/nologo','/help'],env=env): | |
451 | conf.fatal('the msvc compiler could not be identified') | |
452 | v['CC']=v['CXX']=cxx | |
453 | v['CC_NAME']=v['CXX_NAME']='msvc' | |
454 | if not v['LINK_CXX']: | |
455 | link=conf.find_program(linker_name,path_list=path) | |
456 | if link:v['LINK_CXX']=link | |
457 | else:conf.fatal('%s was not found (linker)'%linker_name) | |
458 | v['LINK']=link | |
459 | if not v['LINK_CC']: | |
460 | v['LINK_CC']=v['LINK_CXX'] | |
461 | if not v['AR']: | |
462 | stliblink=conf.find_program(lib_name,path_list=path,var='AR') | |
463 | if not stliblink:return | |
464 | v['ARFLAGS']=['/NOLOGO'] | |
465 | if v.MSVC_MANIFEST: | |
466 | mt=conf.find_program('MT',path_list=path,var='MT') | |
467 | v['MTFLAGS']=['/NOLOGO'] | |
468 | conf.load('winres') | |
469 | if not conf.env['WINRC']: | |
470 | warn('Resource compiler not found. Compiling resource file is disabled') | |
471 | def visual_studio_add_flags(self): | |
472 | v=self.env | |
473 | try:v.prepend_value('INCLUDES',self.environ['INCLUDE'].split(';')) | |
474 | except:pass | |
475 | try:v.prepend_value('LIBPATH',self.environ['LIB'].split(';')) | |
476 | except:pass | |
477 | def msvc_common_flags(conf): | |
478 | v=conf.env | |
479 | v['DEST_BINFMT']='pe' | |
480 | v.append_value('CFLAGS',['/nologo']) | |
481 | v.append_value('CXXFLAGS',['/nologo']) | |
482 | v['DEFINES_ST']='/D%s' | |
483 | v['CC_SRC_F']='' | |
484 | v['CC_TGT_F']=['/c','/Fo'] | |
485 | if v['MSVC_VERSION']>=8: | |
486 | v['CC_TGT_F']=['/FC']+v['CC_TGT_F'] | |
487 | v['CXX_SRC_F']='' | |
488 | v['CXX_TGT_F']=['/c','/Fo'] | |
489 | if v['MSVC_VERSION']>=8: | |
490 | v['CXX_TGT_F']=['/FC']+v['CXX_TGT_F'] | |
491 | v['CPPPATH_ST']='/I%s' | |
492 | v['AR_TGT_F']=v['CCLNK_TGT_F']=v['CXXLNK_TGT_F']='/OUT:' | |
493 | v['CFLAGS_CONSOLE']=v['CXXFLAGS_CONSOLE']=['/SUBSYSTEM:CONSOLE'] | |
494 | v['CFLAGS_NATIVE']=v['CXXFLAGS_NATIVE']=['/SUBSYSTEM:NATIVE'] | |
495 | v['CFLAGS_POSIX']=v['CXXFLAGS_POSIX']=['/SUBSYSTEM:POSIX'] | |
496 | v['CFLAGS_WINDOWS']=v['CXXFLAGS_WINDOWS']=['/SUBSYSTEM:WINDOWS'] | |
497 | v['CFLAGS_WINDOWSCE']=v['CXXFLAGS_WINDOWSCE']=['/SUBSYSTEM:WINDOWSCE'] | |
498 | v['CFLAGS_CRT_MULTITHREADED']=v['CXXFLAGS_CRT_MULTITHREADED']=['/MT'] | |
499 | v['CFLAGS_CRT_MULTITHREADED_DLL']=v['CXXFLAGS_CRT_MULTITHREADED_DLL']=['/MD'] | |
500 | v['CFLAGS_CRT_MULTITHREADED_DBG']=v['CXXFLAGS_CRT_MULTITHREADED_DBG']=['/MTd'] | |
501 | v['CFLAGS_CRT_MULTITHREADED_DLL_DBG']=v['CXXFLAGS_CRT_MULTITHREADED_DLL_DBG']=['/MDd'] | |
502 | v['LIB_ST']='%s.lib' | |
503 | v['LIBPATH_ST']='/LIBPATH:%s' | |
504 | v['STLIB_ST']='lib%s.lib' | |
505 | v['STLIBPATH_ST']='/LIBPATH:%s' | |
506 | v.append_value('LINKFLAGS',['/NOLOGO']) | |
507 | if v['MSVC_MANIFEST']: | |
508 | v.append_value('LINKFLAGS',['/MANIFEST']) | |
509 | v['CFLAGS_cshlib']=[] | |
510 | v['CXXFLAGS_cxxshlib']=[] | |
511 | v['LINKFLAGS_cshlib']=v['LINKFLAGS_cxxshlib']=['/DLL'] | |
512 | v['cshlib_PATTERN']=v['cxxshlib_PATTERN']='%s.dll' | |
513 | v['implib_PATTERN']='%s.lib' | |
514 | v['IMPLIB_ST']='/IMPLIB:%s' | |
515 | v['LINKFLAGS_cstlib']=[] | |
516 | v['cstlib_PATTERN']=v['cxxstlib_PATTERN']='lib%s.lib' | |
517 | v['cprogram_PATTERN']=v['cxxprogram_PATTERN']='%s.exe' | |
518 | def apply_flags_msvc(self): | |
519 | if self.env.CC_NAME!='msvc'or not getattr(self,'link_task',None): | |
520 | return | |
521 | is_static=isinstance(self.link_task,ccroot.stlink_task) | |
522 | subsystem=getattr(self,'subsystem','') | |
523 | if subsystem: | |
524 | subsystem='/subsystem:%s'%subsystem | |
525 | flags=is_static and'ARFLAGS'or'LINKFLAGS' | |
526 | self.env.append_value(flags,subsystem) | |
527 | if not is_static: | |
528 | for f in self.env.LINKFLAGS: | |
529 | d=f.lower() | |
530 | if d[1:]=='debug': | |
531 | pdbnode=self.link_task.outputs[0].change_ext('.pdb') | |
532 | self.link_task.outputs.append(pdbnode) | |
533 | try: | |
534 | self.install_task.source.append(pdbnode) | |
535 | except AttributeError: | |
536 | pass | |
537 | break | |
538 | def apply_manifest(self): | |
539 | if self.env.CC_NAME=='msvc'and self.env.MSVC_MANIFEST and getattr(self,'link_task',None): | |
540 | out_node=self.link_task.outputs[0] | |
541 | man_node=out_node.parent.find_or_declare(out_node.name+'.manifest') | |
542 | self.link_task.outputs.append(man_node) | |
543 | self.link_task.do_manifest=True | |
544 | def exec_mf(self): | |
545 | env=self.env | |
546 | mtool=env['MT'] | |
547 | if not mtool: | |
548 | return 0 | |
549 | self.do_manifest=False | |
550 | outfile=self.outputs[0].abspath() | |
551 | manifest=None | |
552 | for out_node in self.outputs: | |
553 | if out_node.name.endswith('.manifest'): | |
554 | manifest=out_node.abspath() | |
555 | break | |
556 | if manifest is None: | |
557 | return 0 | |
558 | mode='' | |
559 | if'cprogram'in self.generator.features or'cxxprogram'in self.generator.features: | |
560 | mode='1' | |
561 | elif'cshlib'in self.generator.features or'cxxshlib'in self.generator.features: | |
562 | mode='2' | |
563 | debug('msvc: embedding manifest in mode %r'%mode) | |
564 | lst=[] | |
565 | lst.append(env['MT']) | |
566 | lst.extend(Utils.to_list(env['MTFLAGS'])) | |
567 | lst.extend(['-manifest',manifest]) | |
568 | lst.append('-outputresource:%s;%s'%(outfile,mode)) | |
569 | lst=[lst] | |
570 | return self.exec_command(*lst) | |
571 | def quote_response_command(self,flag): | |
572 | if flag.find(' ')>-1: | |
573 | for x in('/LIBPATH:','/IMPLIB:','/OUT:','/I'): | |
574 | if flag.startswith(x): | |
575 | flag='%s"%s"'%(x,flag[len(x):]) | |
576 | break | |
577 | else: | |
578 | flag='"%s"'%flag | |
579 | return flag | |
580 | def exec_response_command(self,cmd,**kw): | |
581 | try: | |
582 | tmp=None | |
583 | if sys.platform.startswith('win')and isinstance(cmd,list)and len(' '.join(cmd))>=8192: | |
584 | program=cmd[0] | |
585 | cmd=[self.quote_response_command(x)for x in cmd] | |
586 | (fd,tmp)=tempfile.mkstemp() | |
587 | os.write(fd,'\r\n'.join(i.replace('\\','\\\\')for i in cmd[1:])) | |
588 | os.close(fd) | |
589 | cmd=[program,'@'+tmp] | |
590 | ret=self.generator.bld.exec_command(cmd,**kw) | |
591 | finally: | |
592 | if tmp: | |
593 | try: | |
594 | os.remove(tmp) | |
595 | except: | |
596 | pass | |
597 | return ret | |
598 | def exec_command_msvc(self,*k,**kw): | |
599 | if self.env['CC_NAME']=='msvc': | |
600 | if isinstance(k[0],list): | |
601 | lst=[] | |
602 | carry='' | |
603 | for a in k[0]: | |
604 | if a=='/Fo'or a=='/doc'or a[-1]==':': | |
605 | carry=a | |
606 | else: | |
607 | lst.append(carry+a) | |
608 | carry='' | |
609 | k=[lst] | |
610 | if self.env['PATH']: | |
611 | env=dict(os.environ) | |
612 | env.update(PATH=';'.join(self.env['PATH'])) | |
613 | kw['env']=env | |
614 | bld=self.generator.bld | |
615 | try: | |
616 | if not kw.get('cwd',None): | |
617 | kw['cwd']=bld.cwd | |
618 | except AttributeError: | |
619 | bld.cwd=kw['cwd']=bld.variant_dir | |
620 | ret=self.exec_response_command(k[0],**kw) | |
621 | if not ret and getattr(self,'do_manifest',None): | |
622 | ret=self.exec_mf() | |
623 | return ret | |
624 | for k in'c cxx cprogram cxxprogram cshlib cxxshlib cstlib cxxstlib'.split(): | |
625 | cls=Task.classes.get(k,None) | |
626 | if cls: | |
627 | cls.exec_command=exec_command_msvc | |
628 | cls.exec_response_command=exec_response_command | |
629 | cls.quote_response_command=quote_response_command | |
630 | cls.exec_mf=exec_mf | |
631 | ||
632 | conf(get_msvc_version) | |
633 | conf(gather_wsdk_versions) | |
634 | conf(gather_msvc_targets) | |
635 | conf(gather_wince_targets) | |
636 | conf(gather_msvc_versions) | |
637 | conf(gather_icl_versions) | |
638 | conf(get_msvc_versions) | |
639 | conf(print_all_msvc_detected) | |
640 | conf(detect_msvc) | |
641 | conf(find_lt_names_msvc) | |
642 | conf(libname_msvc) | |
643 | conf(check_lib_msvc) | |
644 | conf(check_libs_msvc) | |
645 | conf(no_autodetect) | |
646 | conf(autodetect) | |
647 | conf(find_msvc) | |
648 | conf(visual_studio_add_flags) | |
649 | conf(msvc_common_flags) | |
650 | after_method('apply_link')(apply_flags_msvc) | |
651 | feature('c','cxx')(apply_flags_msvc) | |
652 | feature('cprogram','cshlib','cxxprogram','cxxshlib')(apply_manifest) | |
653 | after_method('apply_link')(apply_manifest)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import waflib.Tools.asm | |
5 | from waflib.TaskGen import feature | |
6 | def apply_nasm_vars(self): | |
7 | self.env.append_value('ASFLAGS',self.to_list(getattr(self,'nasm_flags',[]))) | |
8 | def configure(conf): | |
9 | nasm=conf.find_program(['nasm','yasm'],var='AS') | |
10 | conf.env.AS_TGT_F=['-o'] | |
11 | conf.env.ASLNK_TGT_F=['-o'] | |
12 | ||
13 | feature('asm')(apply_nasm_vars)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Task,Options,Utils | |
6 | from waflib.Configure import conf | |
7 | from waflib.TaskGen import extension,feature,before_method | |
8 | def init_perlext(self): | |
9 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
10 | if not'PERLEXT'in self.uselib:self.uselib.append('PERLEXT') | |
11 | self.env['cshlib_PATTERN']=self.env['cxxshlib_PATTERN']=self.env['perlext_PATTERN'] | |
12 | def xsubpp_file(self,node): | |
13 | outnode=node.change_ext('.c') | |
14 | self.create_task('xsubpp',node,outnode) | |
15 | self.source.append(outnode) | |
16 | class xsubpp(Task.Task): | |
17 | run_str='${PERL} ${XSUBPP} -noprototypes -typemap ${EXTUTILS_TYPEMAP} ${SRC} > ${TGT}' | |
18 | color='BLUE' | |
19 | ext_out=['.h'] | |
20 | def check_perl_version(self,minver=None): | |
21 | res=True | |
22 | if minver: | |
23 | cver='.'.join(map(str,minver)) | |
24 | else: | |
25 | cver='' | |
26 | self.start_msg('Checking for minimum perl version %s'%cver) | |
27 | perl=getattr(Options.options,'perlbinary',None) | |
28 | if not perl: | |
29 | perl=self.find_program('perl',var='PERL') | |
30 | if not perl: | |
31 | self.end_msg("Perl not found",color="YELLOW") | |
32 | return False | |
33 | self.env['PERL']=perl | |
34 | version=self.cmd_and_log([perl,"-e",'printf \"%vd\", $^V']) | |
35 | if not version: | |
36 | res=False | |
37 | version="Unknown" | |
38 | elif not minver is None: | |
39 | ver=tuple(map(int,version.split("."))) | |
40 | if ver<minver: | |
41 | res=False | |
42 | self.end_msg(version,color=res and"GREEN"or"YELLOW") | |
43 | return res | |
44 | def check_perl_module(self,module): | |
45 | cmd=[self.env['PERL'],'-e','use %s'%module] | |
46 | self.start_msg('perl module %s'%module) | |
47 | try: | |
48 | r=self.cmd_and_log(cmd) | |
49 | except: | |
50 | self.end_msg(False) | |
51 | return None | |
52 | self.end_msg(r or True) | |
53 | return r | |
54 | def check_perl_ext_devel(self): | |
55 | env=self.env | |
56 | perl=env.PERL | |
57 | if not perl: | |
58 | self.fatal('find perl first') | |
59 | def read_out(cmd): | |
60 | return Utils.to_list(self.cmd_and_log(perl+cmd)) | |
61 | env['LINKFLAGS_PERLEXT']=read_out(" -MConfig -e'print $Config{lddlflags}'") | |
62 | env['INCLUDES_PERLEXT']=read_out(" -MConfig -e'print \"$Config{archlib}/CORE\"'") | |
63 | env['CFLAGS_PERLEXT']=read_out(" -MConfig -e'print \"$Config{ccflags} $Config{cccdlflags}\"'") | |
64 | env['XSUBPP']=read_out(" -MConfig -e'print \"$Config{privlib}/ExtUtils/xsubpp$Config{exe_ext}\"'") | |
65 | env['EXTUTILS_TYPEMAP']=read_out(" -MConfig -e'print \"$Config{privlib}/ExtUtils/typemap\"'") | |
66 | if not getattr(Options.options,'perlarchdir',None): | |
67 | env['ARCHDIR_PERL']=self.cmd_and_log(perl+" -MConfig -e'print $Config{sitearch}'") | |
68 | else: | |
69 | env['ARCHDIR_PERL']=getattr(Options.options,'perlarchdir') | |
70 | env['perlext_PATTERN']='%s.'+self.cmd_and_log(perl+" -MConfig -e'print $Config{dlext}'") | |
71 | def options(opt): | |
72 | opt.add_option('--with-perl-binary',type='string',dest='perlbinary',help='Specify alternate perl binary',default=None) | |
73 | opt.add_option('--with-perl-archdir',type='string',dest='perlarchdir',help='Specify directory where to install arch specific files',default=None) | |
74 | ||
75 | before_method('apply_incpaths','apply_link','propagate_uselib_vars')(init_perlext) | |
76 | feature('perlext')(init_perlext) | |
77 | extension('.xs')(xsubpp_file) | |
78 | conf(check_perl_version) | |
79 | conf(check_perl_module) | |
80 | conf(check_perl_ext_devel)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib import Utils,Options,Errors | |
6 | from waflib.Logs import debug,warn,info,error | |
7 | from waflib.TaskGen import extension,before_method,after_method,feature | |
8 | from waflib.Configure import conf | |
9 | FRAG=''' | |
10 | #include <Python.h> | |
11 | #ifdef __cplusplus | |
12 | extern "C" { | |
13 | #endif | |
14 | void Py_Initialize(void); | |
15 | void Py_Finalize(void); | |
16 | #ifdef __cplusplus | |
17 | } | |
18 | #endif | |
19 | int main() | |
20 | { | |
21 | Py_Initialize(); | |
22 | Py_Finalize(); | |
23 | return 0; | |
24 | } | |
25 | ''' | |
26 | INST=''' | |
27 | import sys, py_compile | |
28 | py_compile.compile(sys.argv[1], sys.argv[2], sys.argv[3]) | |
29 | ''' | |
30 | DISTUTILS_IMP=['from distutils.sysconfig import get_config_var, get_python_lib'] | |
31 | def process_py(self,node): | |
32 | try: | |
33 | if not self.bld.is_install: | |
34 | return | |
35 | except: | |
36 | return | |
37 | try: | |
38 | if not self.install_path: | |
39 | return | |
40 | except AttributeError: | |
41 | self.install_path='${PYTHONDIR}' | |
42 | def inst_py(ctx): | |
43 | install_from=getattr(self,'install_from',None) | |
44 | if install_from: | |
45 | install_from=self.path.find_dir(install_from) | |
46 | install_pyfile(self,node,install_from) | |
47 | self.bld.add_post_fun(inst_py) | |
48 | def install_pyfile(self,node,install_from=None): | |
49 | from_node=install_from or node.parent | |
50 | tsk=self.bld.install_as(self.install_path+'/'+node.path_from(from_node),node,postpone=False) | |
51 | path=tsk.get_install_path() | |
52 | if self.bld.is_install<0: | |
53 | info("+ removing byte compiled python files") | |
54 | for x in'co': | |
55 | try: | |
56 | os.remove(path+x) | |
57 | except OSError: | |
58 | pass | |
59 | if self.bld.is_install>0: | |
60 | try: | |
61 | st1=os.stat(path) | |
62 | except: | |
63 | error('The python file is missing, this should not happen') | |
64 | for x in['c','o']: | |
65 | do_inst=self.env['PY'+x.upper()] | |
66 | try: | |
67 | st2=os.stat(path+x) | |
68 | except OSError: | |
69 | pass | |
70 | else: | |
71 | if st1.st_mtime<=st2.st_mtime: | |
72 | do_inst=False | |
73 | if do_inst: | |
74 | lst=(x=='o')and[self.env['PYFLAGS_OPT']]or[] | |
75 | (a,b,c)=(path,path+x,tsk.get_install_path(destdir=False)+x) | |
76 | argv=self.env['PYTHON']+lst+['-c',INST,a,b,c] | |
77 | info('+ byte compiling %r'%(path+x)) | |
78 | env=self.env.env or None | |
79 | ret=Utils.subprocess.Popen(argv,env=env).wait() | |
80 | if ret: | |
81 | raise Errors.WafError('py%s compilation failed %r'%(x,path)) | |
82 | def feature_py(self): | |
83 | pass | |
84 | def init_pyext(self): | |
85 | try: | |
86 | if not self.install_path: | |
87 | return | |
88 | except AttributeError: | |
89 | self.install_path='${PYTHONARCHDIR}' | |
90 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
91 | if not'PYEXT'in self.uselib: | |
92 | self.uselib.append('PYEXT') | |
93 | self.env['cshlib_PATTERN']=self.env['cxxshlib_PATTERN']=self.env['macbundle_PATTERN']=self.env['pyext_PATTERN'] | |
94 | def set_bundle(self): | |
95 | if Utils.unversioned_sys_platform()=='darwin': | |
96 | self.mac_bundle=True | |
97 | def init_pyembed(self): | |
98 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
99 | if not'PYEMBED'in self.uselib: | |
100 | self.uselib.append('PYEMBED') | |
101 | def get_python_variables(self,variables,imports=None): | |
102 | if not imports: | |
103 | try: | |
104 | imports=self.python_imports | |
105 | except AttributeError: | |
106 | imports=DISTUTILS_IMP | |
107 | program=list(imports) | |
108 | program.append('') | |
109 | for v in variables: | |
110 | program.append("print(repr(%s))"%v) | |
111 | os_env=dict(os.environ) | |
112 | try: | |
113 | del os_env['MACOSX_DEPLOYMENT_TARGET'] | |
114 | except KeyError: | |
115 | pass | |
116 | try: | |
117 | out=self.cmd_and_log(self.env.PYTHON+['-c','\n'.join(program)],env=os_env) | |
118 | except Errors.WafError: | |
119 | self.fatal('The distutils module is unusable: install "python-devel"?') | |
120 | return_values=[] | |
121 | for s in out.split('\n'): | |
122 | s=s.strip() | |
123 | if not s: | |
124 | continue | |
125 | if s=='None': | |
126 | return_values.append(None) | |
127 | elif s[0]=="'"and s[-1]=="'": | |
128 | return_values.append(s[1:-1]) | |
129 | elif s[0].isdigit(): | |
130 | return_values.append(int(s)) | |
131 | else:break | |
132 | return return_values | |
133 | def check_python_headers(conf): | |
134 | if not conf.env['CC_NAME']and not conf.env['CXX_NAME']: | |
135 | conf.fatal('load a compiler first (gcc, g++, ..)') | |
136 | if not conf.env['PYTHON_VERSION']: | |
137 | conf.check_python_version() | |
138 | env=conf.env | |
139 | pybin=conf.env.PYTHON | |
140 | if not pybin: | |
141 | conf.fatal('could not find the python executable') | |
142 | v='prefix SO LDFLAGS LIBDIR LIBPL INCLUDEPY Py_ENABLE_SHARED MACOSX_DEPLOYMENT_TARGET LDSHARED CFLAGS'.split() | |
143 | try: | |
144 | lst=conf.get_python_variables(["get_config_var('%s') or ''"%x for x in v]) | |
145 | except RuntimeError: | |
146 | conf.fatal("Python development headers not found (-v for details).") | |
147 | vals=['%s = %r'%(x,y)for(x,y)in zip(v,lst)] | |
148 | conf.to_log("Configuration returned from %r:\n%r\n"%(pybin,'\n'.join(vals))) | |
149 | dct=dict(zip(v,lst)) | |
150 | x='MACOSX_DEPLOYMENT_TARGET' | |
151 | if dct[x]: | |
152 | conf.env[x]=conf.environ[x]=dct[x] | |
153 | env['pyext_PATTERN']='%s'+dct['SO'] | |
154 | all_flags=dct['LDFLAGS']+' '+dct['CFLAGS'] | |
155 | conf.parse_flags(all_flags,'PYEMBED') | |
156 | all_flags=dct['LDFLAGS']+' '+dct['LDSHARED']+' '+dct['CFLAGS'] | |
157 | conf.parse_flags(all_flags,'PYEXT') | |
158 | result=None | |
159 | for name in('python'+env['PYTHON_VERSION'],'python'+env['PYTHON_VERSION'].replace('.','')): | |
160 | if not result and env['LIBPATH_PYEMBED']: | |
161 | path=env['LIBPATH_PYEMBED'] | |
162 | conf.to_log("\n\n# Trying default LIBPATH_PYEMBED: %r\n"%path) | |
163 | result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBPATH_PYEMBED'%name) | |
164 | if not result and dct['LIBDIR']: | |
165 | path=[dct['LIBDIR']] | |
166 | conf.to_log("\n\n# try again with -L$python_LIBDIR: %r\n"%path) | |
167 | result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in LIBDIR'%name) | |
168 | if not result and dct['LIBPL']: | |
169 | path=[dct['LIBPL']] | |
170 | conf.to_log("\n\n# try again with -L$python_LIBPL (some systems don't install the python library in $prefix/lib)\n") | |
171 | result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in python_LIBPL'%name) | |
172 | if not result: | |
173 | path=[os.path.join(dct['prefix'],"libs")] | |
174 | conf.to_log("\n\n# try again with -L$prefix/libs, and pythonXY name rather than pythonX.Y (win32)\n") | |
175 | result=conf.check(lib=name,uselib='PYEMBED',libpath=path,mandatory=False,msg='Checking for library %s in $prefix/libs'%name) | |
176 | if result: | |
177 | break | |
178 | if result: | |
179 | env['LIBPATH_PYEMBED']=path | |
180 | env.append_value('LIB_PYEMBED',[name]) | |
181 | else: | |
182 | conf.to_log("\n\n### LIB NOT FOUND\n") | |
183 | if(Utils.is_win32 or sys.platform.startswith('os2')or dct['Py_ENABLE_SHARED']): | |
184 | env['LIBPATH_PYEXT']=env['LIBPATH_PYEMBED'] | |
185 | env['LIB_PYEXT']=env['LIB_PYEMBED'] | |
186 | num='.'.join(env['PYTHON_VERSION'].split('.')[:2]) | |
187 | conf.find_program(['python%s-config'%num,'python-config-%s'%num,'python%sm-config'%num],var='PYTHON_CONFIG',mandatory=False) | |
188 | includes=[] | |
189 | if conf.env.PYTHON_CONFIG: | |
190 | for incstr in conf.cmd_and_log([conf.env.PYTHON_CONFIG,'--includes']).strip().split(): | |
191 | if(incstr.startswith('-I')or incstr.startswith('/I')): | |
192 | incstr=incstr[2:] | |
193 | if incstr not in includes: | |
194 | includes.append(incstr) | |
195 | conf.to_log("Include path for Python extensions (found via python-config --includes): %r\n"%(includes,)) | |
196 | env['INCLUDES_PYEXT']=includes | |
197 | env['INCLUDES_PYEMBED']=includes | |
198 | else: | |
199 | conf.to_log("Include path for Python extensions ""(found via distutils module): %r\n"%(dct['INCLUDEPY'],)) | |
200 | env['INCLUDES_PYEXT']=[dct['INCLUDEPY']] | |
201 | env['INCLUDES_PYEMBED']=[dct['INCLUDEPY']] | |
202 | if env['CC_NAME']=='gcc': | |
203 | env.append_value('CFLAGS_PYEMBED',['-fno-strict-aliasing']) | |
204 | env.append_value('CFLAGS_PYEXT',['-fno-strict-aliasing']) | |
205 | if env['CXX_NAME']=='gcc': | |
206 | env.append_value('CXXFLAGS_PYEMBED',['-fno-strict-aliasing']) | |
207 | env.append_value('CXXFLAGS_PYEXT',['-fno-strict-aliasing']) | |
208 | if env.CC_NAME=="msvc": | |
209 | from distutils.msvccompiler import MSVCCompiler | |
210 | dist_compiler=MSVCCompiler() | |
211 | dist_compiler.initialize() | |
212 | env.append_value('CFLAGS_PYEXT',dist_compiler.compile_options) | |
213 | env.append_value('CXXFLAGS_PYEXT',dist_compiler.compile_options) | |
214 | env.append_value('LINKFLAGS_PYEXT',dist_compiler.ldflags_shared) | |
215 | try: | |
216 | conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',uselib='PYEMBED',fragment=FRAG,errmsg='Could not find the python development headers') | |
217 | except conf.errors.ConfigurationError: | |
218 | conf.check_cfg(path=conf.env.PYTHON_CONFIG,package='',uselib_store='PYEMBED',args=['--cflags','--libs']) | |
219 | conf.check(header_name='Python.h',define_name='HAVE_PYTHON_H',msg='Getting the python flags from python-config',uselib='PYEMBED',fragment=FRAG,errmsg='Could not find the python development headers elsewhere') | |
220 | def check_python_version(conf,minver=None): | |
221 | assert minver is None or isinstance(minver,tuple) | |
222 | pybin=conf.env['PYTHON'] | |
223 | if not pybin: | |
224 | conf.fatal('could not find the python executable') | |
225 | cmd=pybin+['-c','import sys\nfor x in sys.version_info: print(str(x))'] | |
226 | debug('python: Running python command %r'%cmd) | |
227 | lines=conf.cmd_and_log(cmd).split() | |
228 | assert len(lines)==5,"found %i lines, expected 5: %r"%(len(lines),lines) | |
229 | pyver_tuple=(int(lines[0]),int(lines[1]),int(lines[2]),lines[3],int(lines[4])) | |
230 | result=(minver is None)or(pyver_tuple>=minver) | |
231 | if result: | |
232 | pyver='.'.join([str(x)for x in pyver_tuple[:2]]) | |
233 | conf.env['PYTHON_VERSION']=pyver | |
234 | if'PYTHONDIR'in conf.environ: | |
235 | pydir=conf.environ['PYTHONDIR'] | |
236 | else: | |
237 | if Utils.is_win32: | |
238 | (python_LIBDEST,pydir)=conf.get_python_variables(["get_config_var('LIBDEST') or ''","get_python_lib(standard_lib=0, prefix=%r) or ''"%conf.env['PREFIX']]) | |
239 | else: | |
240 | python_LIBDEST=None | |
241 | (pydir,)=conf.get_python_variables(["get_python_lib(standard_lib=0, prefix=%r) or ''"%conf.env['PREFIX']]) | |
242 | if python_LIBDEST is None: | |
243 | if conf.env['LIBDIR']: | |
244 | python_LIBDEST=os.path.join(conf.env['LIBDIR'],"python"+pyver) | |
245 | else: | |
246 | python_LIBDEST=os.path.join(conf.env['PREFIX'],"lib","python"+pyver) | |
247 | if'PYTHONARCHDIR'in conf.environ: | |
248 | pyarchdir=conf.environ['PYTHONARCHDIR'] | |
249 | else: | |
250 | (pyarchdir,)=conf.get_python_variables(["get_python_lib(plat_specific=1, standard_lib=0, prefix=%r) or ''"%conf.env['PREFIX']]) | |
251 | if not pyarchdir: | |
252 | pyarchdir=pydir | |
253 | if hasattr(conf,'define'): | |
254 | conf.define('PYTHONDIR',pydir) | |
255 | conf.define('PYTHONARCHDIR',pyarchdir) | |
256 | conf.env['PYTHONDIR']=pydir | |
257 | conf.env['PYTHONARCHDIR']=pyarchdir | |
258 | pyver_full='.'.join(map(str,pyver_tuple[:3])) | |
259 | if minver is None: | |
260 | conf.msg('Checking for python version',pyver_full) | |
261 | else: | |
262 | minver_str='.'.join(map(str,minver)) | |
263 | conf.msg('Checking for python version',pyver_tuple,">= %s"%(minver_str,)and'GREEN'or'YELLOW') | |
264 | if not result: | |
265 | conf.fatal('The python version is too old, expecting %r'%(minver,)) | |
266 | PYTHON_MODULE_TEMPLATE=''' | |
267 | import %s as current_module | |
268 | version = getattr(current_module, '__version__', None) | |
269 | if version is not None: | |
270 | print(str(version)) | |
271 | else: | |
272 | print('unknown version') | |
273 | ''' | |
274 | def check_python_module(conf,module_name,condition=''): | |
275 | msg='Python module %s'%module_name | |
276 | if condition: | |
277 | msg='%s (%s)'%(msg,condition) | |
278 | conf.start_msg(msg) | |
279 | try: | |
280 | ret=conf.cmd_and_log(conf.env['PYTHON']+['-c',PYTHON_MODULE_TEMPLATE%module_name]) | |
281 | except Exception: | |
282 | conf.end_msg(False) | |
283 | conf.fatal('Could not find the python module %r'%module_name) | |
284 | ret=ret.strip() | |
285 | if condition: | |
286 | conf.end_msg(ret) | |
287 | if ret=='unknown version': | |
288 | conf.fatal('Could not check the %s version'%module_name) | |
289 | from distutils.version import LooseVersion | |
290 | def num(*k): | |
291 | if isinstance(k[0],int): | |
292 | return LooseVersion('.'.join([str(x)for x in k])) | |
293 | else: | |
294 | return LooseVersion(k[0]) | |
295 | d={'num':num,'ver':LooseVersion(ret)} | |
296 | ev=eval(condition,{},d) | |
297 | if not ev: | |
298 | conf.fatal('The %s version does not satisfy the requirements'%module_name) | |
299 | else: | |
300 | if ret=='unknown version': | |
301 | conf.end_msg(True) | |
302 | else: | |
303 | conf.end_msg(ret) | |
304 | def configure(conf): | |
305 | try: | |
306 | conf.find_program('python',var='PYTHON') | |
307 | except conf.errors.ConfigurationError: | |
308 | warn("could not find a python executable, setting to sys.executable '%s'"%sys.executable) | |
309 | conf.env.PYTHON=sys.executable | |
310 | if conf.env.PYTHON!=sys.executable: | |
311 | warn("python executable '%s' different from sys.executable '%s'"%(conf.env.PYTHON,sys.executable)) | |
312 | conf.env.PYTHON=conf.cmd_to_list(conf.env.PYTHON) | |
313 | v=conf.env | |
314 | v['PYCMD']='"import sys, py_compile;py_compile.compile(sys.argv[1], sys.argv[2])"' | |
315 | v['PYFLAGS']='' | |
316 | v['PYFLAGS_OPT']='-O' | |
317 | v['PYC']=getattr(Options.options,'pyc',1) | |
318 | v['PYO']=getattr(Options.options,'pyo',1) | |
319 | def options(opt): | |
320 | opt.add_option('--nopyc',action='store_false',default=1,help='Do not install bytecode compiled .pyc files (configuration) [Default:install]',dest='pyc') | |
321 | opt.add_option('--nopyo',action='store_false',default=1,help='Do not install optimised compiled .pyo files (configuration) [Default:install]',dest='pyo') | |
322 | ||
323 | extension('.py')(process_py) | |
324 | feature('py')(feature_py) | |
325 | feature('pyext')(init_pyext) | |
326 | before_method('propagate_uselib_vars','apply_link')(init_pyext) | |
327 | after_method('apply_bundle')(init_pyext) | |
328 | feature('pyext')(set_bundle) | |
329 | before_method('apply_link','apply_bundle')(set_bundle) | |
330 | before_method('propagate_uselib_vars')(init_pyembed) | |
331 | feature('pyembed')(init_pyembed) | |
332 | conf(get_python_variables) | |
333 | conf(check_python_headers) | |
334 | conf(check_python_version) | |
335 | conf(check_python_module)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | try: | |
7 | from xml.sax import make_parser | |
8 | from xml.sax.handler import ContentHandler | |
9 | except ImportError: | |
10 | has_xml=False | |
11 | ContentHandler=object | |
12 | else: | |
13 | has_xml=True | |
14 | import os,sys | |
15 | from waflib.Tools import c_preproc,cxx | |
16 | from waflib import Task,Utils,Options,Errors | |
17 | from waflib.TaskGen import feature,after_method,extension | |
18 | from waflib.Configure import conf | |
19 | from waflib import Logs | |
20 | MOC_H=['.h','.hpp','.hxx','.hh'] | |
21 | EXT_RCC=['.qrc'] | |
22 | EXT_UI=['.ui'] | |
23 | EXT_QT4=['.cpp','.cc','.cxx','.C'] | |
24 | QT4_LIBS="QtCore QtGui QtUiTools QtNetwork QtOpenGL QtSql QtSvg QtTest QtXml QtXmlPatterns QtWebKit Qt3Support QtHelp QtScript QtDeclarative" | |
25 | class qxx(cxx.cxx): | |
26 | def __init__(self,*k,**kw): | |
27 | Task.Task.__init__(self,*k,**kw) | |
28 | self.moc_done=0 | |
29 | def scan(self): | |
30 | (nodes,names)=c_preproc.scan(self) | |
31 | for x in nodes: | |
32 | if x.name.endswith('.moc'): | |
33 | nodes.remove(x) | |
34 | names.append(x.path_from(self.inputs[0].parent.get_bld())) | |
35 | return(nodes,names) | |
36 | def runnable_status(self): | |
37 | if self.moc_done: | |
38 | return Task.Task.runnable_status(self) | |
39 | else: | |
40 | for t in self.run_after: | |
41 | if not t.hasrun: | |
42 | return Task.ASK_LATER | |
43 | self.add_moc_tasks() | |
44 | return Task.Task.runnable_status(self) | |
45 | def add_moc_tasks(self): | |
46 | node=self.inputs[0] | |
47 | bld=self.generator.bld | |
48 | try: | |
49 | self.signature() | |
50 | except KeyError: | |
51 | pass | |
52 | else: | |
53 | delattr(self,'cache_sig') | |
54 | moctasks=[] | |
55 | mocfiles=[] | |
56 | try: | |
57 | tmp_lst=bld.raw_deps[self.uid()] | |
58 | bld.raw_deps[self.uid()]=[] | |
59 | except KeyError: | |
60 | tmp_lst=[] | |
61 | for d in tmp_lst: | |
62 | if not d.endswith('.moc'): | |
63 | continue | |
64 | if d in mocfiles: | |
65 | Logs.error("paranoia owns") | |
66 | continue | |
67 | mocfiles.append(d) | |
68 | h_node=None | |
69 | try:ext=Options.options.qt_header_ext.split() | |
70 | except AttributeError:pass | |
71 | if not ext:ext=MOC_H | |
72 | base2=d[:-4] | |
73 | for x in[node.parent]+self.generator.includes_nodes: | |
74 | for e in ext: | |
75 | h_node=x.find_node(base2+e) | |
76 | if h_node: | |
77 | break | |
78 | if h_node: | |
79 | m_node=h_node.change_ext('.moc') | |
80 | break | |
81 | else: | |
82 | for k in EXT_QT4: | |
83 | if base2.endswith(k): | |
84 | for x in[node.parent]+self.generator.includes_nodes: | |
85 | h_node=x.find_node(base2) | |
86 | if h_node: | |
87 | break | |
88 | if h_node: | |
89 | m_node=h_node.change_ext(k+'.moc') | |
90 | break | |
91 | if not h_node: | |
92 | raise Errors.WafError('no header found for %r which is a moc file'%d) | |
93 | bld.node_deps[(self.inputs[0].parent.abspath(),m_node.name)]=h_node | |
94 | task=Task.classes['moc'](env=self.env,generator=self.generator) | |
95 | task.set_inputs(h_node) | |
96 | task.set_outputs(m_node) | |
97 | gen=bld.producer | |
98 | gen.outstanding.insert(0,task) | |
99 | gen.total+=1 | |
100 | moctasks.append(task) | |
101 | tmp_lst=bld.raw_deps[self.uid()]=mocfiles | |
102 | lst=bld.node_deps.get(self.uid(),()) | |
103 | for d in lst: | |
104 | name=d.name | |
105 | if name.endswith('.moc'): | |
106 | task=Task.classes['moc'](env=self.env,generator=self.generator) | |
107 | task.set_inputs(bld.node_deps[(self.inputs[0].parent.abspath(),name)]) | |
108 | task.set_outputs(d) | |
109 | gen=bld.producer | |
110 | gen.outstanding.insert(0,task) | |
111 | gen.total+=1 | |
112 | moctasks.append(task) | |
113 | self.run_after.update(set(moctasks)) | |
114 | self.moc_done=1 | |
115 | run=Task.classes['cxx'].__dict__['run'] | |
116 | class trans_update(Task.Task): | |
117 | run_str='${QT_LUPDATE} ${SRC} -ts ${TGT}' | |
118 | color='BLUE' | |
119 | Task.update_outputs(trans_update) | |
120 | class XMLHandler(ContentHandler): | |
121 | def __init__(self): | |
122 | self.buf=[] | |
123 | self.files=[] | |
124 | def startElement(self,name,attrs): | |
125 | if name=='file': | |
126 | self.buf=[] | |
127 | def endElement(self,name): | |
128 | if name=='file': | |
129 | self.files.append(str(''.join(self.buf))) | |
130 | def characters(self,cars): | |
131 | self.buf.append(cars) | |
132 | def create_rcc_task(self,node): | |
133 | rcnode=node.change_ext('_rc.cpp') | |
134 | rcctask=self.create_task('rcc',node,rcnode) | |
135 | cpptask=self.create_task('cxx',rcnode,rcnode.change_ext('.o')) | |
136 | try: | |
137 | self.compiled_tasks.append(cpptask) | |
138 | except AttributeError: | |
139 | self.compiled_tasks=[cpptask] | |
140 | return cpptask | |
141 | def create_uic_task(self,node): | |
142 | uictask=self.create_task('ui4',node) | |
143 | uictask.outputs=[self.path.find_or_declare(self.env['ui_PATTERN']%node.name[:-3])] | |
144 | def add_lang(self,node): | |
145 | self.lang=self.to_list(getattr(self,'lang',[]))+[node] | |
146 | def apply_qt4(self): | |
147 | if getattr(self,'lang',None): | |
148 | qmtasks=[] | |
149 | for x in self.to_list(self.lang): | |
150 | if isinstance(x,str): | |
151 | x=self.path.find_resource(x+'.ts') | |
152 | qmtasks.append(self.create_task('ts2qm',x,x.change_ext('.qm'))) | |
153 | if getattr(self,'update',None)and Options.options.trans_qt4: | |
154 | cxxnodes=[a.inputs[0]for a in self.compiled_tasks]+[a.inputs[0]for a in self.tasks if getattr(a,'inputs',None)and a.inputs[0].name.endswith('.ui')] | |
155 | for x in qmtasks: | |
156 | self.create_task('trans_update',cxxnodes,x.inputs) | |
157 | if getattr(self,'langname',None): | |
158 | qmnodes=[x.outputs[0]for x in qmtasks] | |
159 | rcnode=self.langname | |
160 | if isinstance(rcnode,str): | |
161 | rcnode=self.path.find_or_declare(rcnode+'.qrc') | |
162 | t=self.create_task('qm2rcc',qmnodes,rcnode) | |
163 | k=create_rcc_task(self,t.outputs[0]) | |
164 | self.link_task.inputs.append(k.outputs[0]) | |
165 | lst=[] | |
166 | for flag in self.to_list(self.env['CXXFLAGS']): | |
167 | if len(flag)<2:continue | |
168 | f=flag[0:2] | |
169 | if f in['-D','-I','/D','/I']: | |
170 | if(f[0]=='/'): | |
171 | lst.append('-'+flag[1:]) | |
172 | else: | |
173 | lst.append(flag) | |
174 | self.env['MOC_FLAGS']=lst | |
175 | def cxx_hook(self,node): | |
176 | return self.create_compiled_task('qxx',node) | |
177 | class rcc(Task.Task): | |
178 | color='BLUE' | |
179 | run_str='${QT_RCC} -name ${SRC[0].name} ${SRC[0].abspath()} ${RCC_ST} -o ${TGT}' | |
180 | ext_out=['.h'] | |
181 | def scan(self): | |
182 | node=self.inputs[0] | |
183 | if not has_xml: | |
184 | Logs.error('no xml support was found, the rcc dependencies will be incomplete!') | |
185 | return([],[]) | |
186 | parser=make_parser() | |
187 | curHandler=XMLHandler() | |
188 | parser.setContentHandler(curHandler) | |
189 | fi=open(self.inputs[0].abspath()) | |
190 | parser.parse(fi) | |
191 | fi.close() | |
192 | nodes=[] | |
193 | names=[] | |
194 | root=self.inputs[0].parent | |
195 | for x in curHandler.files: | |
196 | nd=root.find_resource(x) | |
197 | if nd:nodes.append(nd) | |
198 | else:names.append(x) | |
199 | return(nodes,names) | |
200 | class moc(Task.Task): | |
201 | color='BLUE' | |
202 | run_str='${QT_MOC} ${MOC_FLAGS} ${MOCCPPPATH_ST:INCPATHS} ${MOCDEFINES_ST:DEFINES} ${SRC} ${MOC_ST} ${TGT}' | |
203 | class ui4(Task.Task): | |
204 | color='BLUE' | |
205 | run_str='${QT_UIC} ${SRC} -o ${TGT}' | |
206 | ext_out=['.h'] | |
207 | class ts2qm(Task.Task): | |
208 | color='BLUE' | |
209 | run_str='${QT_LRELEASE} ${QT_LRELEASE_FLAGS} ${SRC} -qm ${TGT}' | |
210 | class qm2rcc(Task.Task): | |
211 | color='BLUE' | |
212 | after='ts2qm' | |
213 | def run(self): | |
214 | txt='\n'.join(['<file>%s</file>'%k.path_from(self.outputs[0].parent)for k in self.inputs]) | |
215 | code='<!DOCTYPE RCC><RCC version="1.0">\n<qresource>\n%s\n</qresource>\n</RCC>'%txt | |
216 | self.outputs[0].write(code) | |
217 | def configure(self): | |
218 | self.find_qt4_binaries() | |
219 | self.set_qt4_libs_to_check() | |
220 | self.find_qt4_libraries() | |
221 | self.add_qt4_rpath() | |
222 | self.simplify_qt4_libs() | |
223 | def find_qt4_binaries(self): | |
224 | env=self.env | |
225 | opt=Options.options | |
226 | qtdir=getattr(opt,'qtdir','') | |
227 | qtbin=getattr(opt,'qtbin','') | |
228 | paths=[] | |
229 | if qtdir: | |
230 | qtbin=os.path.join(qtdir,'bin') | |
231 | if not qtdir: | |
232 | qtdir=self.environ.get('QT4_ROOT','') | |
233 | qtbin=os.path.join(qtdir,'bin') | |
234 | if qtbin: | |
235 | paths=[qtbin] | |
236 | if not qtdir: | |
237 | paths=os.environ.get('PATH','').split(os.pathsep) | |
238 | paths.append('/usr/share/qt4/bin/') | |
239 | try: | |
240 | lst=Utils.listdir('/usr/local/Trolltech/') | |
241 | except OSError: | |
242 | pass | |
243 | else: | |
244 | if lst: | |
245 | lst.sort() | |
246 | lst.reverse() | |
247 | qtdir='/usr/local/Trolltech/%s/'%lst[0] | |
248 | qtbin=os.path.join(qtdir,'bin') | |
249 | paths.append(qtbin) | |
250 | cand=None | |
251 | prev_ver=['4','0','0'] | |
252 | for qmk in['qmake-qt4','qmake4','qmake']: | |
253 | try: | |
254 | qmake=self.find_program(qmk,path_list=paths) | |
255 | except self.errors.ConfigurationError: | |
256 | pass | |
257 | else: | |
258 | try: | |
259 | version=self.cmd_and_log([qmake,'-query','QT_VERSION']).strip() | |
260 | except self.errors.ConfigurationError: | |
261 | pass | |
262 | else: | |
263 | if version: | |
264 | new_ver=version.split('.') | |
265 | if new_ver>prev_ver: | |
266 | cand=qmake | |
267 | prev_ver=new_ver | |
268 | if cand: | |
269 | self.env.QMAKE=cand | |
270 | else: | |
271 | self.fatal('Could not find qmake for qt4') | |
272 | qtbin=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_BINS']).strip()+os.sep | |
273 | def find_bin(lst,var): | |
274 | for f in lst: | |
275 | try: | |
276 | ret=self.find_program(f,path_list=paths) | |
277 | except self.errors.ConfigurationError: | |
278 | pass | |
279 | else: | |
280 | env[var]=ret | |
281 | break | |
282 | find_bin(['uic-qt3','uic3'],'QT_UIC3') | |
283 | find_bin(['uic-qt4','uic'],'QT_UIC') | |
284 | if not env['QT_UIC']: | |
285 | self.fatal('cannot find the uic compiler for qt4') | |
286 | try: | |
287 | uicver=self.cmd_and_log(env['QT_UIC']+" -version 2>&1").strip() | |
288 | except self.errors.ConfigurationError: | |
289 | self.fatal('this uic compiler is for qt3, add uic for qt4 to your path') | |
290 | uicver=uicver.replace('Qt User Interface Compiler ','').replace('User Interface Compiler for Qt','') | |
291 | self.msg('Checking for uic version','%s'%uicver) | |
292 | if uicver.find(' 3.')!=-1: | |
293 | self.fatal('this uic compiler is for qt3, add uic for qt4 to your path') | |
294 | find_bin(['moc-qt4','moc'],'QT_MOC') | |
295 | find_bin(['rcc'],'QT_RCC') | |
296 | find_bin(['lrelease-qt4','lrelease'],'QT_LRELEASE') | |
297 | find_bin(['lupdate-qt4','lupdate'],'QT_LUPDATE') | |
298 | env['UIC3_ST']='%s -o %s' | |
299 | env['UIC_ST']='%s -o %s' | |
300 | env['MOC_ST']='-o' | |
301 | env['ui_PATTERN']='ui_%s.h' | |
302 | env['QT_LRELEASE_FLAGS']=['-silent'] | |
303 | env.MOCCPPPATH_ST='-I%s' | |
304 | env.MOCDEFINES_ST='-D%s' | |
305 | def find_qt4_libraries(self): | |
306 | qtlibs=getattr(Options.options,'qtlibs','') | |
307 | if not qtlibs: | |
308 | try: | |
309 | qtlibs=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_LIBS']).strip() | |
310 | except Errors.WafError: | |
311 | qtdir=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_PREFIX']).strip()+os.sep | |
312 | qtlibs=os.path.join(qtdir,'lib') | |
313 | self.msg('Found the Qt4 libraries in',qtlibs) | |
314 | qtincludes=self.cmd_and_log([self.env.QMAKE,'-query','QT_INSTALL_HEADERS']).strip() | |
315 | env=self.env | |
316 | if not'PKG_CONFIG_PATH'in os.environ: | |
317 | os.environ['PKG_CONFIG_PATH']='%s:%s/pkgconfig:/usr/lib/qt4/lib/pkgconfig:/opt/qt4/lib/pkgconfig:/usr/lib/qt4/lib:/opt/qt4/lib'%(qtlibs,qtlibs) | |
318 | try: | |
319 | self.check_cfg(atleast_pkgconfig_version='0.1') | |
320 | except self.errors.ConfigurationError: | |
321 | for i in self.qt4_vars: | |
322 | uselib=i.upper() | |
323 | if Utils.unversioned_sys_platform()=="darwin": | |
324 | frameworkName=i+".framework" | |
325 | qtDynamicLib=os.path.join(qtlibs,frameworkName,i) | |
326 | if os.path.exists(qtDynamicLib): | |
327 | env.append_unique('FRAMEWORK_'+uselib,i) | |
328 | self.msg('Checking for %s'%i,qtDynamicLib,'GREEN') | |
329 | else: | |
330 | self.msg('Checking for %s'%i,False,'YELLOW') | |
331 | env.append_unique('INCLUDES_'+uselib,os.path.join(qtlibs,frameworkName,'Headers')) | |
332 | elif sys.platform!="win32": | |
333 | qtDynamicLib=os.path.join(qtlibs,"lib"+i+".so") | |
334 | qtStaticLib=os.path.join(qtlibs,"lib"+i+".a") | |
335 | if os.path.exists(qtDynamicLib): | |
336 | env.append_unique('LIB_'+uselib,i) | |
337 | self.msg('Checking for %s'%i,qtDynamicLib,'GREEN') | |
338 | elif os.path.exists(qtStaticLib): | |
339 | env.append_unique('LIB_'+uselib,i) | |
340 | self.msg('Checking for %s'%i,qtStaticLib,'GREEN') | |
341 | else: | |
342 | self.msg('Checking for %s'%i,False,'YELLOW') | |
343 | env.append_unique('LIBPATH_'+uselib,qtlibs) | |
344 | env.append_unique('INCLUDES_'+uselib,qtincludes) | |
345 | env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i)) | |
346 | else: | |
347 | for k in("lib%s.a","lib%s4.a","%s.lib","%s4.lib"): | |
348 | lib=os.path.join(qtlibs,k%i) | |
349 | if os.path.exists(lib): | |
350 | env.append_unique('LIB_'+uselib,i+k[k.find("%s")+2:k.find('.')]) | |
351 | self.msg('Checking for %s'%i,lib,'GREEN') | |
352 | break | |
353 | else: | |
354 | self.msg('Checking for %s'%i,False,'YELLOW') | |
355 | env.append_unique('LIBPATH_'+uselib,qtlibs) | |
356 | env.append_unique('INCLUDES_'+uselib,qtincludes) | |
357 | env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i)) | |
358 | uselib=i.upper()+"_debug" | |
359 | for k in("lib%sd.a","lib%sd4.a","%sd.lib","%sd4.lib"): | |
360 | lib=os.path.join(qtlibs,k%i) | |
361 | if os.path.exists(lib): | |
362 | env.append_unique('LIB_'+uselib,i+k[k.find("%s")+2:k.find('.')]) | |
363 | self.msg('Checking for %s'%i,lib,'GREEN') | |
364 | break | |
365 | else: | |
366 | self.msg('Checking for %s'%i,False,'YELLOW') | |
367 | env.append_unique('LIBPATH_'+uselib,qtlibs) | |
368 | env.append_unique('INCLUDES_'+uselib,qtincludes) | |
369 | env.append_unique('INCLUDES_'+uselib,os.path.join(qtincludes,i)) | |
370 | else: | |
371 | for i in self.qt4_vars_debug+self.qt4_vars: | |
372 | self.check_cfg(package=i,args='--cflags --libs',mandatory=False) | |
373 | def simplify_qt4_libs(self): | |
374 | env=self.env | |
375 | def process_lib(vars_,coreval): | |
376 | for d in vars_: | |
377 | var=d.upper() | |
378 | if var=='QTCORE': | |
379 | continue | |
380 | value=env['LIBPATH_'+var] | |
381 | if value: | |
382 | core=env[coreval] | |
383 | accu=[] | |
384 | for lib in value: | |
385 | if lib in core: | |
386 | continue | |
387 | accu.append(lib) | |
388 | env['LIBPATH_'+var]=accu | |
389 | process_lib(self.qt4_vars,'LIBPATH_QTCORE') | |
390 | process_lib(self.qt4_vars_debug,'LIBPATH_QTCORE_DEBUG') | |
391 | def add_qt4_rpath(self): | |
392 | env=self.env | |
393 | if Options.options.want_rpath: | |
394 | def process_rpath(vars_,coreval): | |
395 | for d in vars_: | |
396 | var=d.upper() | |
397 | value=env['LIBPATH_'+var] | |
398 | if value: | |
399 | core=env[coreval] | |
400 | accu=[] | |
401 | for lib in value: | |
402 | if var!='QTCORE': | |
403 | if lib in core: | |
404 | continue | |
405 | accu.append('-Wl,--rpath='+lib) | |
406 | env['RPATH_'+var]=accu | |
407 | process_rpath(self.qt4_vars,'LIBPATH_QTCORE') | |
408 | process_rpath(self.qt4_vars_debug,'LIBPATH_QTCORE_DEBUG') | |
409 | def set_qt4_libs_to_check(self): | |
410 | if not hasattr(self,'qt4_vars'): | |
411 | self.qt4_vars=QT4_LIBS | |
412 | self.qt4_vars=Utils.to_list(self.qt4_vars) | |
413 | if not hasattr(self,'qt4_vars_debug'): | |
414 | self.qt4_vars_debug=[a+'_debug'for a in self.qt4_vars] | |
415 | self.qt4_vars_debug=Utils.to_list(self.qt4_vars_debug) | |
416 | def options(opt): | |
417 | opt.add_option('--want-rpath',action='store_true',default=False,dest='want_rpath',help='enable the rpath for qt libraries') | |
418 | opt.add_option('--header-ext',type='string',default='',help='header extension for moc files',dest='qt_header_ext') | |
419 | for i in'qtdir qtbin qtlibs'.split(): | |
420 | opt.add_option('--'+i,type='string',default='',dest=i) | |
421 | opt.add_option('--translate',action="store_true",help="collect translation strings",dest="trans_qt4",default=False) | |
422 | ||
423 | extension(*EXT_RCC)(create_rcc_task) | |
424 | extension(*EXT_UI)(create_uic_task) | |
425 | extension('.ts')(add_lang) | |
426 | feature('qt4')(apply_qt4) | |
427 | after_method('apply_link')(apply_qt4) | |
428 | extension(*EXT_QT4)(cxx_hook) | |
429 | conf(find_qt4_binaries) | |
430 | conf(find_qt4_libraries) | |
431 | conf(simplify_qt4_libs) | |
432 | conf(add_qt4_rpath) | |
433 | conf(set_qt4_libs_to_check)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Task,Options,Utils | |
6 | from waflib.TaskGen import before_method,feature,after_method,Task,extension | |
7 | from waflib.Configure import conf | |
8 | def init_rubyext(self): | |
9 | self.install_path='${ARCHDIR_RUBY}' | |
10 | self.uselib=self.to_list(getattr(self,'uselib','')) | |
11 | if not'RUBY'in self.uselib: | |
12 | self.uselib.append('RUBY') | |
13 | if not'RUBYEXT'in self.uselib: | |
14 | self.uselib.append('RUBYEXT') | |
15 | def apply_ruby_so_name(self): | |
16 | self.env['cshlib_PATTERN']=self.env['cxxshlib_PATTERN']=self.env['rubyext_PATTERN'] | |
17 | def check_ruby_version(self,minver=()): | |
18 | if Options.options.rubybinary: | |
19 | self.env.RUBY=Options.options.rubybinary | |
20 | else: | |
21 | self.find_program('ruby',var='RUBY') | |
22 | ruby=self.env.RUBY | |
23 | try: | |
24 | version=self.cmd_and_log([ruby,'-e','puts defined?(VERSION) ? VERSION : RUBY_VERSION']).strip() | |
25 | except: | |
26 | self.fatal('could not determine ruby version') | |
27 | self.env.RUBY_VERSION=version | |
28 | try: | |
29 | ver=tuple(map(int,version.split("."))) | |
30 | except: | |
31 | self.fatal('unsupported ruby version %r'%version) | |
32 | cver='' | |
33 | if minver: | |
34 | if ver<minver: | |
35 | self.fatal('ruby is too old %r'%ver) | |
36 | cver='.'.join([str(x)for x in minver]) | |
37 | else: | |
38 | cver=ver | |
39 | self.msg('Checking for ruby version %s'%str(minver or''),cver) | |
40 | def check_ruby_ext_devel(self): | |
41 | if not self.env.RUBY: | |
42 | self.fatal('ruby detection is required first') | |
43 | if not self.env.CC_NAME and not self.env.CXX_NAME: | |
44 | self.fatal('load a c/c++ compiler first') | |
45 | version=tuple(map(int,self.env.RUBY_VERSION.split("."))) | |
46 | def read_out(cmd): | |
47 | return Utils.to_list(self.cmd_and_log([self.env.RUBY,'-rrbconfig','-e',cmd])) | |
48 | def read_config(key): | |
49 | return read_out('puts Config::CONFIG[%r]'%key) | |
50 | ruby=self.env['RUBY'] | |
51 | archdir=read_config('archdir') | |
52 | cpppath=archdir | |
53 | if version>=(1,9,0): | |
54 | ruby_hdrdir=read_config('rubyhdrdir') | |
55 | cpppath+=ruby_hdrdir | |
56 | cpppath+=[os.path.join(ruby_hdrdir[0],read_config('arch')[0])] | |
57 | self.check(header_name='ruby.h',includes=cpppath,errmsg='could not find ruby header file') | |
58 | self.env.LIBPATH_RUBYEXT=read_config('libdir') | |
59 | self.env.LIBPATH_RUBYEXT+=archdir | |
60 | self.env.INCLUDES_RUBYEXT=cpppath | |
61 | self.env.CFLAGS_RUBYEXT=read_config('CCDLFLAGS') | |
62 | self.env.rubyext_PATTERN='%s.'+read_config('DLEXT')[0] | |
63 | flags=read_config('LDSHARED') | |
64 | while flags and flags[0][0]!='-': | |
65 | flags=flags[1:] | |
66 | if len(flags)>1 and flags[1]=="ppc": | |
67 | flags=flags[2:] | |
68 | self.env.LINKFLAGS_RUBYEXT=flags | |
69 | self.env.LINKFLAGS_RUBYEXT+=read_config('LIBS') | |
70 | self.env.LINKFLAGS_RUBYEXT+=read_config('LIBRUBYARG_SHARED') | |
71 | if Options.options.rubyarchdir: | |
72 | self.env.ARCHDIR_RUBY=Options.options.rubyarchdir | |
73 | else: | |
74 | self.env.ARCHDIR_RUBY=read_config('sitearchdir')[0] | |
75 | if Options.options.rubylibdir: | |
76 | self.env.LIBDIR_RUBY=Options.options.rubylibdir | |
77 | else: | |
78 | self.env.LIBDIR_RUBY=read_config('sitelibdir')[0] | |
79 | def check_ruby_module(self,module_name): | |
80 | self.start_msg('Ruby module %s'%module_name) | |
81 | try: | |
82 | self.cmd_and_log([self.env['RUBY'],'-e','require \'%s\';puts 1'%module_name]) | |
83 | except: | |
84 | self.end_msg(False) | |
85 | self.fatal('Could not find the ruby module %r'%module_name) | |
86 | self.end_msg(True) | |
87 | def process(self,node): | |
88 | tsk=self.create_task('run_ruby',node) | |
89 | class run_ruby(Task.Task): | |
90 | run_str='${RUBY} ${RBFLAGS} -I ${SRC[0].parent.abspath()} ${SRC}' | |
91 | def options(opt): | |
92 | opt.add_option('--with-ruby-archdir',type='string',dest='rubyarchdir',help='Specify directory where to install arch specific files') | |
93 | opt.add_option('--with-ruby-libdir',type='string',dest='rubylibdir',help='Specify alternate ruby library path') | |
94 | opt.add_option('--with-ruby-binary',type='string',dest='rubybinary',help='Specify alternate ruby binary') | |
95 | ||
96 | feature('rubyext')(init_rubyext) | |
97 | before_method('apply_incpaths','apply_lib_vars','apply_bundle','apply_link')(init_rubyext) | |
98 | feature('rubyext')(apply_ruby_so_name) | |
99 | before_method('apply_link','propagate_uselib')(apply_ruby_so_name) | |
100 | conf(check_ruby_version) | |
101 | conf(check_ruby_ext_devel) | |
102 | conf(check_ruby_module) | |
103 | extension('.rb')(process)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Utils | |
6 | from waflib.Tools import ccroot,ar | |
7 | from waflib.Configure import conf | |
8 | def find_scc(conf): | |
9 | v=conf.env | |
10 | cc=None | |
11 | if v['CC']:cc=v['CC'] | |
12 | elif'CC'in conf.environ:cc=conf.environ['CC'] | |
13 | if not cc:cc=conf.find_program('cc',var='CC') | |
14 | if not cc:conf.fatal('Could not find a Sun C compiler') | |
15 | cc=conf.cmd_to_list(cc) | |
16 | try: | |
17 | conf.cmd_and_log(cc+['-flags']) | |
18 | except: | |
19 | conf.fatal('%r is not a Sun compiler'%cc) | |
20 | v['CC']=cc | |
21 | v['CC_NAME']='sun' | |
22 | def scc_common_flags(conf): | |
23 | v=conf.env | |
24 | v['CC_SRC_F']=[] | |
25 | v['CC_TGT_F']=['-c','-o'] | |
26 | if not v['LINK_CC']:v['LINK_CC']=v['CC'] | |
27 | v['CCLNK_SRC_F']='' | |
28 | v['CCLNK_TGT_F']=['-o'] | |
29 | v['CPPPATH_ST']='-I%s' | |
30 | v['DEFINES_ST']='-D%s' | |
31 | v['LIB_ST']='-l%s' | |
32 | v['LIBPATH_ST']='-L%s' | |
33 | v['STLIB_ST']='-l%s' | |
34 | v['STLIBPATH_ST']='-L%s' | |
35 | v['SONAME_ST']='-Wl,-h,%s' | |
36 | v['SHLIB_MARKER']='-Bdynamic' | |
37 | v['STLIB_MARKER']='-Bstatic' | |
38 | v['cprogram_PATTERN']='%s' | |
39 | v['CFLAGS_cshlib']=['-Kpic','-DPIC'] | |
40 | v['LINKFLAGS_cshlib']=['-G'] | |
41 | v['cshlib_PATTERN']='lib%s.so' | |
42 | v['LINKFLAGS_cstlib']=['-Bstatic'] | |
43 | v['cstlib_PATTERN']='lib%s.a' | |
44 | def configure(conf): | |
45 | conf.find_scc() | |
46 | conf.find_ar() | |
47 | conf.scc_common_flags() | |
48 | conf.cc_load_tools() | |
49 | conf.cc_add_flags() | |
50 | conf.link_add_flags() | |
51 | ||
52 | conf(find_scc) | |
53 | conf(scc_common_flags)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | from waflib import Utils | |
6 | from waflib.Tools import ccroot,ar | |
7 | from waflib.Configure import conf | |
8 | def find_sxx(conf): | |
9 | v=conf.env | |
10 | cc=None | |
11 | if v['CXX']:cc=v['CXX'] | |
12 | elif'CXX'in conf.environ:cc=conf.environ['CXX'] | |
13 | if not cc:cc=conf.find_program('CC',var='CXX') | |
14 | if not cc:cc=conf.find_program('c++',var='CXX') | |
15 | if not cc:conf.fatal('Could not find a Sun C++ compiler') | |
16 | cc=conf.cmd_to_list(cc) | |
17 | try: | |
18 | conf.cmd_and_log(cc+['-flags']) | |
19 | except: | |
20 | conf.fatal('%r is not a Sun compiler'%cc) | |
21 | v['CXX']=cc | |
22 | v['CXX_NAME']='sun' | |
23 | def sxx_common_flags(conf): | |
24 | v=conf.env | |
25 | v['CXX_SRC_F']=[] | |
26 | v['CXX_TGT_F']=['-c','-o'] | |
27 | if not v['LINK_CXX']:v['LINK_CXX']=v['CXX'] | |
28 | v['CXXLNK_SRC_F']=[] | |
29 | v['CXXLNK_TGT_F']=['-o'] | |
30 | v['CPPPATH_ST']='-I%s' | |
31 | v['DEFINES_ST']='-D%s' | |
32 | v['LIB_ST']='-l%s' | |
33 | v['LIBPATH_ST']='-L%s' | |
34 | v['STLIB_ST']='-l%s' | |
35 | v['STLIBPATH_ST']='-L%s' | |
36 | v['SONAME_ST']='-Wl,-h,%s' | |
37 | v['SHLIB_MARKER']='-Bdynamic' | |
38 | v['STLIB_MARKER']='-Bstatic' | |
39 | v['cxxprogram_PATTERN']='%s' | |
40 | v['CXXFLAGS_cxxshlib']=['-Kpic','-DPIC'] | |
41 | v['LINKFLAGS_cxxshlib']=['-G'] | |
42 | v['cxxshlib_PATTERN']='lib%s.so' | |
43 | v['LINKFLAGS_cxxstlib']=['-Bstatic'] | |
44 | v['cxxstlib_PATTERN']='lib%s.a' | |
45 | def configure(conf): | |
46 | conf.find_sxx() | |
47 | conf.find_ar() | |
48 | conf.sxx_common_flags() | |
49 | conf.cxx_load_tools() | |
50 | conf.cxx_add_flags() | |
51 | conf.link_add_flags() | |
52 | ||
53 | conf(find_sxx) | |
54 | conf(sxx_common_flags)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,re | |
5 | from waflib import Utils,Task,Errors | |
6 | from waflib.TaskGen import feature,before_method | |
7 | from waflib.Logs import error,warn,debug | |
8 | re_bibunit=re.compile(r'\\(?P<type>putbib)\[(?P<file>[^\[\]]*)\]',re.M) | |
9 | def bibunitscan(self): | |
10 | node=self.inputs[0] | |
11 | nodes=[] | |
12 | if not node:return nodes | |
13 | code=Utils.readf(node.abspath()) | |
14 | for match in re_bibunit.finditer(code): | |
15 | path=match.group('file') | |
16 | if path: | |
17 | for k in['','.bib']: | |
18 | debug('tex: trying %s%s'%(path,k)) | |
19 | fi=node.parent.find_resource(path+k) | |
20 | if fi: | |
21 | nodes.append(fi) | |
22 | else: | |
23 | debug('tex: could not find %s'%path) | |
24 | debug("tex: found the following bibunit files: %s"%nodes) | |
25 | return nodes | |
26 | exts_deps_tex=['','.ltx','.tex','.bib','.pdf','.png','.eps','.ps'] | |
27 | exts_tex=['.ltx','.tex'] | |
28 | re_tex=re.compile(r'\\(?P<type>include|bibliography|putbib|includegraphics|input|import|bringin|lstinputlisting)(\[[^\[\]]*\])?{(?P<file>[^{}]*)}',re.M) | |
29 | g_bibtex_re=re.compile('bibdata',re.M) | |
30 | class tex(Task.Task): | |
31 | bibtex_fun,_=Task.compile_fun('${BIBTEX} ${BIBTEXFLAGS} ${SRCFILE}',shell=False) | |
32 | bibtex_fun.__doc__=""" | |
33 | Execute the program **bibtex** | |
34 | """ | |
35 | makeindex_fun,_=Task.compile_fun('${MAKEINDEX} ${MAKEINDEXFLAGS} ${SRCFILE}',shell=False) | |
36 | makeindex_fun.__doc__=""" | |
37 | Execute the program **makeindex** | |
38 | """ | |
39 | def scan_aux(self,node): | |
40 | nodes=[node] | |
41 | re_aux=re.compile(r'\\@input{(?P<file>[^{}]*)}',re.M) | |
42 | def parse_node(node): | |
43 | code=node.read() | |
44 | for match in re_aux.finditer(code): | |
45 | path=match.group('file') | |
46 | found=node.parent.find_or_declare(path) | |
47 | if found and found not in nodes: | |
48 | debug('tex: found aux node '+found.abspath()) | |
49 | nodes.append(found) | |
50 | parse_node(found) | |
51 | parse_node(node) | |
52 | return nodes | |
53 | def scan(self): | |
54 | node=self.inputs[0] | |
55 | nodes=[] | |
56 | names=[] | |
57 | seen=[] | |
58 | if not node:return(nodes,names) | |
59 | def parse_node(node): | |
60 | if node in seen: | |
61 | return | |
62 | seen.append(node) | |
63 | code=node.read() | |
64 | global re_tex | |
65 | for match in re_tex.finditer(code): | |
66 | for path in match.group('file').split(','): | |
67 | if path: | |
68 | add_name=True | |
69 | found=None | |
70 | for k in exts_deps_tex: | |
71 | debug('tex: trying %s%s'%(path,k)) | |
72 | found=node.parent.find_resource(path+k) | |
73 | if found and not found in self.outputs: | |
74 | nodes.append(found) | |
75 | add_name=False | |
76 | for ext in exts_tex: | |
77 | if found.name.endswith(ext): | |
78 | parse_node(found) | |
79 | break | |
80 | if add_name: | |
81 | names.append(path) | |
82 | parse_node(node) | |
83 | for x in nodes: | |
84 | x.parent.get_bld().mkdir() | |
85 | debug("tex: found the following : %s and names %s"%(nodes,names)) | |
86 | return(nodes,names) | |
87 | def check_status(self,msg,retcode): | |
88 | if retcode!=0: | |
89 | raise Errors.WafError("%r command exit status %r"%(msg,retcode)) | |
90 | def bibfile(self): | |
91 | need_bibtex=False | |
92 | try: | |
93 | for aux_node in self.aux_nodes: | |
94 | ct=aux_node.read() | |
95 | if g_bibtex_re.findall(ct): | |
96 | need_bibtex=True | |
97 | break | |
98 | except(OSError,IOError): | |
99 | error('error bibtex scan') | |
100 | else: | |
101 | if need_bibtex: | |
102 | warn('calling bibtex') | |
103 | self.env.env={} | |
104 | self.env.env.update(os.environ) | |
105 | self.env.env.update({'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS}) | |
106 | self.env.SRCFILE=self.aux_nodes[0].name[:-4] | |
107 | self.check_status('error when calling bibtex',self.bibtex_fun()) | |
108 | def bibunits(self): | |
109 | try: | |
110 | bibunits=bibunitscan(self) | |
111 | except FSError: | |
112 | error('error bibunitscan') | |
113 | else: | |
114 | if bibunits: | |
115 | fn=['bu'+str(i)for i in xrange(1,len(bibunits)+1)] | |
116 | if fn: | |
117 | warn('calling bibtex on bibunits') | |
118 | for f in fn: | |
119 | self.env.env={'BIBINPUTS':self.TEXINPUTS,'BSTINPUTS':self.TEXINPUTS} | |
120 | self.env.SRCFILE=f | |
121 | self.check_status('error when calling bibtex',self.bibtex_fun()) | |
122 | def makeindex(self): | |
123 | try: | |
124 | idx_path=self.idx_node.abspath() | |
125 | os.stat(idx_path) | |
126 | except OSError: | |
127 | warn('index file %s absent, not calling makeindex'%idx_path) | |
128 | else: | |
129 | warn('calling makeindex') | |
130 | self.env.SRCFILE=self.idx_node.name | |
131 | self.env.env={} | |
132 | self.check_status('error when calling makeindex %s'%idx_path,self.makeindex_fun()) | |
133 | def run(self): | |
134 | env=self.env | |
135 | if not env['PROMPT_LATEX']: | |
136 | env.append_value('LATEXFLAGS','-interaction=batchmode') | |
137 | env.append_value('PDFLATEXFLAGS','-interaction=batchmode') | |
138 | env.append_value('XELATEXFLAGS','-interaction=batchmode') | |
139 | fun=self.texfun | |
140 | node=self.inputs[0] | |
141 | srcfile=node.abspath() | |
142 | texinputs=self.env.TEXINPUTS or'' | |
143 | self.TEXINPUTS=node.parent.get_bld().abspath()+os.pathsep+node.parent.get_src().abspath()+os.pathsep+texinputs+os.pathsep | |
144 | self.aux_node=node.change_ext('.aux') | |
145 | self.cwd=self.inputs[0].parent.get_bld().abspath() | |
146 | warn('first pass on %s'%self.__class__.__name__) | |
147 | self.env.env={} | |
148 | self.env.env.update(os.environ) | |
149 | self.env.env.update({'TEXINPUTS':self.TEXINPUTS}) | |
150 | self.env.SRCFILE=srcfile | |
151 | self.check_status('error when calling latex',fun()) | |
152 | self.aux_nodes=self.scan_aux(node.change_ext('.aux')) | |
153 | self.idx_node=node.change_ext('.idx') | |
154 | self.bibfile() | |
155 | self.bibunits() | |
156 | self.makeindex() | |
157 | hash='' | |
158 | for i in range(10): | |
159 | prev_hash=hash | |
160 | try: | |
161 | hashes=[Utils.h_file(x.abspath())for x in self.aux_nodes] | |
162 | hash=Utils.h_list(hashes) | |
163 | except(OSError,IOError): | |
164 | error('could not read aux.h') | |
165 | pass | |
166 | if hash and hash==prev_hash: | |
167 | break | |
168 | warn('calling %s'%self.__class__.__name__) | |
169 | self.env.env={} | |
170 | self.env.env.update(os.environ) | |
171 | self.env.env.update({'TEXINPUTS':self.TEXINPUTS}) | |
172 | self.env.SRCFILE=srcfile | |
173 | self.check_status('error when calling %s'%self.__class__.__name__,fun()) | |
174 | class latex(tex): | |
175 | texfun,vars=Task.compile_fun('${LATEX} ${LATEXFLAGS} ${SRCFILE}',shell=False) | |
176 | class pdflatex(tex): | |
177 | texfun,vars=Task.compile_fun('${PDFLATEX} ${PDFLATEXFLAGS} ${SRCFILE}',shell=False) | |
178 | class xelatex(tex): | |
179 | texfun,vars=Task.compile_fun('${XELATEX} ${XELATEXFLAGS} ${SRCFILE}',shell=False) | |
180 | class dvips(Task.Task): | |
181 | run_str='${DVIPS} ${DVIPSFLAGS} ${SRC} -o ${TGT}' | |
182 | color='BLUE' | |
183 | after=['latex','pdflatex','xelatex'] | |
184 | class dvipdf(Task.Task): | |
185 | run_str='${DVIPDF} ${DVIPDFFLAGS} ${SRC} ${TGT}' | |
186 | color='BLUE' | |
187 | after=['latex','pdflatex','xelatex'] | |
188 | class pdf2ps(Task.Task): | |
189 | run_str='${PDF2PS} ${PDF2PSFLAGS} ${SRC} ${TGT}' | |
190 | color='BLUE' | |
191 | after=['latex','pdflatex','xelatex'] | |
192 | def apply_tex(self): | |
193 | if not getattr(self,'type',None)in['latex','pdflatex','xelatex']: | |
194 | self.type='pdflatex' | |
195 | tree=self.bld | |
196 | outs=Utils.to_list(getattr(self,'outs',[])) | |
197 | self.env['PROMPT_LATEX']=getattr(self,'prompt',1) | |
198 | deps_lst=[] | |
199 | if getattr(self,'deps',None): | |
200 | deps=self.to_list(self.deps) | |
201 | for filename in deps: | |
202 | n=self.path.find_resource(filename) | |
203 | if not n in deps_lst:deps_lst.append(n) | |
204 | for node in self.to_nodes(self.source): | |
205 | if self.type=='latex': | |
206 | task=self.create_task('latex',node,node.change_ext('.dvi')) | |
207 | elif self.type=='pdflatex': | |
208 | task=self.create_task('pdflatex',node,node.change_ext('.pdf')) | |
209 | elif self.type=='xelatex': | |
210 | task=self.create_task('xelatex',node,node.change_ext('.pdf')) | |
211 | task.env=self.env | |
212 | if deps_lst: | |
213 | try: | |
214 | lst=tree.node_deps[task.uid()] | |
215 | for n in deps_lst: | |
216 | if not n in lst: | |
217 | lst.append(n) | |
218 | except KeyError: | |
219 | tree.node_deps[task.uid()]=deps_lst | |
220 | if self.type=='latex': | |
221 | if'ps'in outs: | |
222 | tsk=self.create_task('dvips',task.outputs,node.change_ext('.ps')) | |
223 | tsk.env.env={'TEXINPUTS':node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()} | |
224 | if'pdf'in outs: | |
225 | tsk=self.create_task('dvipdf',task.outputs,node.change_ext('.pdf')) | |
226 | tsk.env.env={'TEXINPUTS':node.parent.abspath()+os.pathsep+self.path.abspath()+os.pathsep+self.path.get_bld().abspath()} | |
227 | elif self.type=='pdflatex': | |
228 | if'ps'in outs: | |
229 | self.create_task('pdf2ps',task.outputs,node.change_ext('.ps')) | |
230 | self.source=[] | |
231 | def configure(self): | |
232 | v=self.env | |
233 | for p in'tex latex pdflatex xelatex bibtex dvips dvipdf ps2pdf makeindex pdf2ps'.split(): | |
234 | try: | |
235 | self.find_program(p,var=p.upper()) | |
236 | except self.errors.ConfigurationError: | |
237 | pass | |
238 | v['DVIPSFLAGS']='-Ppdf' | |
239 | ||
240 | feature('tex')(apply_tex) | |
241 | before_method('process_source')(apply_tex)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os.path,shutil,re | |
5 | from waflib import Context,Task,Utils,Logs,Options,Errors | |
6 | from waflib.TaskGen import extension | |
7 | from waflib.Configure import conf | |
8 | class valac(Task.Task): | |
9 | vars=["VALAC","VALAC_VERSION","VALAFLAGS"] | |
10 | ext_out=['.h'] | |
11 | def run(self): | |
12 | env=self.env | |
13 | cmd=[env['VALAC'],'-C','--quiet'] | |
14 | cmd.extend(Utils.to_list(env['VALAFLAGS'])) | |
15 | if self.threading: | |
16 | cmd.append('--thread') | |
17 | if self.profile: | |
18 | cmd.append('--profile=%s'%self.profile) | |
19 | if self.target_glib: | |
20 | cmd.append('--target-glib=%s'%self.target_glib) | |
21 | if self.is_lib: | |
22 | cmd.append('--library='+self.target) | |
23 | for x in self.outputs: | |
24 | if x.name.endswith('.h'): | |
25 | cmd.append('--header='+x.name) | |
26 | if self.gir: | |
27 | cmd.append('--gir=%s.gir'%self.gir) | |
28 | for vapi_dir in self.vapi_dirs: | |
29 | cmd.append('--vapidir=%s'%vapi_dir) | |
30 | for package in self.packages: | |
31 | cmd.append('--pkg=%s'%package) | |
32 | for package in self.packages_private: | |
33 | cmd.append('--pkg=%s'%package) | |
34 | for define in self.vala_defines: | |
35 | cmd.append('--define=%s'%define) | |
36 | cmd.extend([a.abspath()for a in self.inputs]) | |
37 | ret=self.exec_command(cmd,cwd=self.outputs[0].parent.abspath()) | |
38 | if ret: | |
39 | return ret | |
40 | for x in self.outputs: | |
41 | if id(x.parent)!=id(self.outputs[0].parent): | |
42 | shutil.move(self.outputs[0].parent.abspath()+os.sep+x.name,x.abspath()) | |
43 | if self.packages and getattr(self,'deps_node',None): | |
44 | self.deps_node.write('\n'.join(self.packages)) | |
45 | return ret | |
46 | def vala_file(self,node): | |
47 | valatask=getattr(self,"valatask",None) | |
48 | if not valatask: | |
49 | def _get_api_version(): | |
50 | api_version='1.0' | |
51 | if hasattr(Context.g_module,'API_VERSION'): | |
52 | version=Context.g_module.API_VERSION.split(".") | |
53 | if version[0]=="0": | |
54 | api_version="0."+version[1] | |
55 | else: | |
56 | api_version=version[0]+".0" | |
57 | return api_version | |
58 | valatask=self.create_task('valac') | |
59 | self.valatask=valatask | |
60 | self.includes=Utils.to_list(getattr(self,'includes',[])) | |
61 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
62 | valatask.packages=[] | |
63 | valatask.packages_private=Utils.to_list(getattr(self,'packages_private',[])) | |
64 | valatask.vapi_dirs=[] | |
65 | valatask.target=self.target | |
66 | valatask.threading=False | |
67 | valatask.install_path=getattr(self,'install_path','') | |
68 | valatask.profile=getattr(self,'profile','gobject') | |
69 | valatask.vala_defines=getattr(self,'vala_defines',[]) | |
70 | valatask.target_glib=None | |
71 | valatask.gir=getattr(self,'gir',None) | |
72 | valatask.gir_path=getattr(self,'gir_path','${DATAROOTDIR}/gir-1.0') | |
73 | valatask.vapi_path=getattr(self,'vapi_path','${DATAROOTDIR}/vala/vapi') | |
74 | valatask.pkg_name=getattr(self,'pkg_name',self.env['PACKAGE']) | |
75 | valatask.header_path=getattr(self,'header_path','${INCLUDEDIR}/%s-%s'%(valatask.pkg_name,_get_api_version())) | |
76 | valatask.install_binding=getattr(self,'install_binding',True) | |
77 | valatask.is_lib=False | |
78 | if not'cprogram'in self.features: | |
79 | valatask.is_lib=True | |
80 | packages=Utils.to_list(getattr(self,'packages',[])) | |
81 | vapi_dirs=Utils.to_list(getattr(self,'vapi_dirs',[])) | |
82 | includes=[] | |
83 | if hasattr(self,'use'): | |
84 | local_packages=Utils.to_list(self.use)[:] | |
85 | seen=[] | |
86 | while len(local_packages)>0: | |
87 | package=local_packages.pop() | |
88 | if package in seen: | |
89 | continue | |
90 | seen.append(package) | |
91 | try: | |
92 | package_obj=self.bld.get_tgen_by_name(package) | |
93 | except Errors.WafError: | |
94 | continue | |
95 | package_name=package_obj.target | |
96 | package_node=package_obj.path | |
97 | package_dir=package_node.path_from(self.path) | |
98 | for task in package_obj.tasks: | |
99 | for output in task.outputs: | |
100 | if output.name==package_name+".vapi": | |
101 | valatask.set_run_after(task) | |
102 | if package_name not in packages: | |
103 | packages.append(package_name) | |
104 | if package_dir not in vapi_dirs: | |
105 | vapi_dirs.append(package_dir) | |
106 | if package_dir not in includes: | |
107 | includes.append(package_dir) | |
108 | if hasattr(package_obj,'use'): | |
109 | lst=self.to_list(package_obj.use) | |
110 | lst.reverse() | |
111 | local_packages=[pkg for pkg in lst if pkg not in seen]+local_packages | |
112 | valatask.packages=packages | |
113 | for vapi_dir in vapi_dirs: | |
114 | try: | |
115 | valatask.vapi_dirs.append(self.path.find_dir(vapi_dir).abspath()) | |
116 | valatask.vapi_dirs.append(self.path.find_dir(vapi_dir).get_bld().abspath()) | |
117 | except AttributeError: | |
118 | Logs.warn("Unable to locate Vala API directory: '%s'"%vapi_dir) | |
119 | self.includes.append(self.bld.srcnode.abspath()) | |
120 | self.includes.append(self.bld.bldnode.abspath()) | |
121 | for include in includes: | |
122 | try: | |
123 | self.includes.append(self.path.find_dir(include).abspath()) | |
124 | self.includes.append(self.path.find_dir(include).get_bld().abspath()) | |
125 | except AttributeError: | |
126 | Logs.warn("Unable to locate include directory: '%s'"%include) | |
127 | if valatask.profile=='gobject': | |
128 | if hasattr(self,'target_glib'): | |
129 | Logs.warn('target_glib on vala tasks is not supported --vala-target-glib=MAJOR.MINOR from the vala tool options') | |
130 | if getattr(Options.options,'vala_target_glib',None): | |
131 | valatask.target_glib=Options.options.vala_target_glib | |
132 | if not'GOBJECT'in self.uselib: | |
133 | self.uselib.append('GOBJECT') | |
134 | if hasattr(self,'threading'): | |
135 | if valatask.profile=='gobject': | |
136 | valatask.threading=self.threading | |
137 | if not'GTHREAD'in self.uselib: | |
138 | self.uselib.append('GTHREAD') | |
139 | else: | |
140 | Logs.warn("Profile %s does not have threading support"%valatask.profile) | |
141 | if valatask.is_lib: | |
142 | valatask.outputs.append(self.path.find_or_declare('%s.h'%self.target)) | |
143 | valatask.outputs.append(self.path.find_or_declare('%s.vapi'%self.target)) | |
144 | if valatask.gir: | |
145 | valatask.outputs.append(self.path.find_or_declare('%s.gir'%self.gir)) | |
146 | if valatask.packages: | |
147 | d=self.path.find_or_declare('%s.deps'%self.target) | |
148 | valatask.outputs.append(d) | |
149 | valatask.deps_node=d | |
150 | valatask.inputs.append(node) | |
151 | c_node=node.change_ext('.c') | |
152 | valatask.outputs.append(c_node) | |
153 | self.source.append(c_node) | |
154 | if valatask.is_lib and valatask.install_binding: | |
155 | headers_list=[o for o in valatask.outputs if o.suffix()==".h"] | |
156 | try: | |
157 | self.install_vheader.source=headers_list | |
158 | except AttributeError: | |
159 | self.install_vheader=self.bld.install_files(valatask.header_path,headers_list,self.env) | |
160 | vapi_list=[o for o in valatask.outputs if(o.suffix()in(".vapi",".deps"))] | |
161 | try: | |
162 | self.install_vapi.source=vapi_list | |
163 | except AttributeError: | |
164 | self.install_vapi=self.bld.install_files(valatask.vapi_path,vapi_list,self.env) | |
165 | gir_list=[o for o in valatask.outputs if o.suffix()==".gir"] | |
166 | try: | |
167 | self.install_gir.source=gir_list | |
168 | except AttributeError: | |
169 | self.install_gir=self.bld.install_files(valatask.gir_path,gir_list,self.env) | |
170 | valac=Task.update_outputs(valac) | |
171 | def find_valac(self,valac_name,min_version): | |
172 | valac=self.find_program(valac_name,var='VALAC') | |
173 | try: | |
174 | output=self.cmd_and_log(valac+' --version') | |
175 | except Exception: | |
176 | valac_version=None | |
177 | else: | |
178 | ver=re.search(r'\d+.\d+.\d+',output).group(0).split('.') | |
179 | valac_version=tuple([int(x)for x in ver]) | |
180 | self.msg('Checking for %s version >= %r'%(valac_name,min_version),valac_version,valac_version and valac_version>=min_version) | |
181 | if valac and valac_version<min_version: | |
182 | self.fatal("%s version %r is too old, need >= %r"%(valac_name,valac_version,min_version)) | |
183 | self.env['VALAC_VERSION']=valac_version | |
184 | return valac | |
185 | def check_vala(self,min_version=(0,8,0),branch=None): | |
186 | if not branch: | |
187 | branch=min_version[:2] | |
188 | try: | |
189 | find_valac(self,'valac-%d.%d'%(branch[0],branch[1]),min_version) | |
190 | except self.errors.ConfigurationError: | |
191 | find_valac(self,'valac',min_version) | |
192 | def check_vala_deps(self): | |
193 | if not self.env['HAVE_GOBJECT']: | |
194 | pkg_args={'package':'gobject-2.0','uselib_store':'GOBJECT','args':'--cflags --libs'} | |
195 | if getattr(Options.options,'vala_target_glib',None): | |
196 | pkg_args['atleast_version']=Options.options.vala_target_glib | |
197 | self.check_cfg(**pkg_args) | |
198 | if not self.env['HAVE_GTHREAD']: | |
199 | pkg_args={'package':'gthread-2.0','uselib_store':'GTHREAD','args':'--cflags --libs'} | |
200 | if getattr(Options.options,'vala_target_glib',None): | |
201 | pkg_args['atleast_version']=Options.options.vala_target_glib | |
202 | self.check_cfg(**pkg_args) | |
203 | def configure(self): | |
204 | self.load('gnu_dirs') | |
205 | self.check_vala_deps() | |
206 | self.check_vala() | |
207 | def options(opt): | |
208 | opt.load('gnu_dirs') | |
209 | valaopts=opt.add_option_group('Vala Compiler Options') | |
210 | valaopts.add_option('--vala-target-glib',default=None,dest='vala_target_glib',metavar='MAJOR.MINOR',help='Target version of glib for Vala GObject code generation') | |
211 | ||
212 | extension('.vala','.gs')(vala_file) | |
213 | conf(find_valac) | |
214 | conf(check_vala) | |
215 | conf(check_vala_deps)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys | |
5 | from waflib.TaskGen import feature,after_method | |
6 | from waflib import Utils,Task,Logs,Options | |
7 | testlock=Utils.threading.Lock() | |
8 | def make_test(self): | |
9 | if getattr(self,'link_task',None): | |
10 | self.create_task('utest',self.link_task.outputs) | |
11 | class utest(Task.Task): | |
12 | color='PINK' | |
13 | after=['vnum','inst'] | |
14 | vars=[] | |
15 | def runnable_status(self): | |
16 | ret=super(utest,self).runnable_status() | |
17 | if ret==Task.SKIP_ME: | |
18 | if getattr(Options.options,'all_tests',False): | |
19 | return Task.RUN_ME | |
20 | return ret | |
21 | def run(self): | |
22 | filename=self.inputs[0].abspath() | |
23 | self.ut_exec=getattr(self,'ut_exec',[filename]) | |
24 | if getattr(self.generator,'ut_fun',None): | |
25 | self.generator.ut_fun(self) | |
26 | try: | |
27 | fu=getattr(self.generator.bld,'all_test_paths') | |
28 | except AttributeError: | |
29 | fu=os.environ.copy() | |
30 | self.generator.bld.all_test_paths=fu | |
31 | lst=[] | |
32 | for g in self.generator.bld.groups: | |
33 | for tg in g: | |
34 | if getattr(tg,'link_task',None): | |
35 | lst.append(tg.link_task.outputs[0].parent.abspath()) | |
36 | def add_path(dct,path,var): | |
37 | dct[var]=os.pathsep.join(Utils.to_list(path)+[os.environ.get(var,'')]) | |
38 | if Utils.is_win32: | |
39 | add_path(fu,lst,'PATH') | |
40 | elif Utils.unversioned_sys_platform()=='darwin': | |
41 | add_path(fu,lst,'DYLD_LIBRARY_PATH') | |
42 | add_path(fu,lst,'LD_LIBRARY_PATH') | |
43 | else: | |
44 | add_path(fu,lst,'LD_LIBRARY_PATH') | |
45 | cwd=getattr(self.generator,'ut_cwd','')or self.inputs[0].parent.abspath() | |
46 | proc=Utils.subprocess.Popen(self.ut_exec,cwd=cwd,env=fu,stderr=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE) | |
47 | (stdout,stderr)=proc.communicate() | |
48 | tup=(filename,proc.returncode,stdout,stderr) | |
49 | self.generator.utest_result=tup | |
50 | testlock.acquire() | |
51 | try: | |
52 | bld=self.generator.bld | |
53 | Logs.debug("ut: %r",tup) | |
54 | try: | |
55 | bld.utest_results.append(tup) | |
56 | except AttributeError: | |
57 | bld.utest_results=[tup] | |
58 | finally: | |
59 | testlock.release() | |
60 | def summary(bld): | |
61 | lst=getattr(bld,'utest_results',[]) | |
62 | if lst: | |
63 | Logs.pprint('CYAN','execution summary') | |
64 | total=len(lst) | |
65 | tfail=len([x for x in lst if x[1]]) | |
66 | Logs.pprint('CYAN',' tests that pass %d/%d'%(total-tfail,total)) | |
67 | for(f,code,out,err)in lst: | |
68 | if not code: | |
69 | Logs.pprint('CYAN',' %s'%f) | |
70 | Logs.pprint('CYAN',' tests that fail %d/%d'%(tfail,total)) | |
71 | for(f,code,out,err)in lst: | |
72 | if code: | |
73 | Logs.pprint('CYAN',' %s'%f) | |
74 | def options(opt): | |
75 | opt.add_option('--alltests',action='store_true',default=False,help='Exec all unit tests',dest='all_tests') | |
76 | ||
77 | feature('test')(make_test) | |
78 | after_method('apply_link')(make_test)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib import Task | |
5 | from waflib.TaskGen import extension | |
6 | def rc_file(self,node): | |
7 | obj_ext='.rc.o' | |
8 | if self.env['WINRC_TGT_F']=='/fo': | |
9 | obj_ext='.res' | |
10 | rctask=self.create_task('winrc',node,node.change_ext(obj_ext)) | |
11 | try: | |
12 | self.compiled_tasks.append(rctask) | |
13 | except AttributeError: | |
14 | self.compiled_tasks=[rctask] | |
15 | class winrc(Task.Task): | |
16 | run_str='${WINRC} ${WINRCFLAGS} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${WINRC_TGT_F} ${TGT} ${WINRC_SRC_F} ${SRC}' | |
17 | color='BLUE' | |
18 | def configure(conf): | |
19 | v=conf.env | |
20 | v['WINRC_TGT_F']='-o' | |
21 | v['WINRC_SRC_F']='-i' | |
22 | if not conf.env.WINRC: | |
23 | if v.CC_NAME=='msvc': | |
24 | conf.find_program('RC',var='WINRC',path_list=v['PATH']) | |
25 | v['WINRC_TGT_F']='/fo' | |
26 | v['WINRC_SRC_F']='' | |
27 | else: | |
28 | conf.find_program('windres',var='WINRC',path_list=v['PATH']) | |
29 | if not conf.env.WINRC: | |
30 | conf.fatal('winrc was not found!') | |
31 | v['WINRCFLAGS']=[] | |
32 | ||
33 | extension('.rc')(rc_file)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib.Tools import ccroot,ar | |
5 | from waflib.Configure import conf | |
6 | def find_xlc(conf): | |
7 | cc=conf.find_program(['xlc_r','xlc'],var='CC') | |
8 | cc=conf.cmd_to_list(cc) | |
9 | conf.get_xlc_version(cc) | |
10 | conf.env.CC_NAME='xlc' | |
11 | conf.env.CC=cc | |
12 | def xlc_common_flags(conf): | |
13 | v=conf.env | |
14 | v['CC_SRC_F']=[] | |
15 | v['CC_TGT_F']=['-c','-o'] | |
16 | if not v['LINK_CC']:v['LINK_CC']=v['CC'] | |
17 | v['CCLNK_SRC_F']=[] | |
18 | v['CCLNK_TGT_F']=['-o'] | |
19 | v['CPPPATH_ST']='-I%s' | |
20 | v['DEFINES_ST']='-D%s' | |
21 | v['LIB_ST']='-l%s' | |
22 | v['LIBPATH_ST']='-L%s' | |
23 | v['STLIB_ST']='-l%s' | |
24 | v['STLIBPATH_ST']='-L%s' | |
25 | v['RPATH_ST']='-Wl,-rpath,%s' | |
26 | v['SONAME_ST']=[] | |
27 | v['SHLIB_MARKER']=[] | |
28 | v['STLIB_MARKER']=[] | |
29 | v['LINKFLAGS_cprogram']=['-Wl,-brtl'] | |
30 | v['cprogram_PATTERN']='%s' | |
31 | v['CFLAGS_cshlib']=['-fPIC'] | |
32 | v['LINKFLAGS_cshlib']=['-G','-Wl,-brtl,-bexpfull'] | |
33 | v['cshlib_PATTERN']='lib%s.so' | |
34 | v['LINKFLAGS_cstlib']=[] | |
35 | v['cstlib_PATTERN']='lib%s.a' | |
36 | def configure(conf): | |
37 | conf.find_xlc() | |
38 | conf.find_ar() | |
39 | conf.xlc_common_flags() | |
40 | conf.cc_load_tools() | |
41 | conf.cc_add_flags() | |
42 | conf.link_add_flags() | |
43 | ||
44 | conf(find_xlc) | |
45 | conf(xlc_common_flags)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | from waflib.Tools import ccroot,ar | |
5 | from waflib.Configure import conf | |
6 | def find_xlcxx(conf): | |
7 | cxx=conf.find_program(['xlc++_r','xlc++'],var='CXX') | |
8 | cxx=conf.cmd_to_list(cxx) | |
9 | conf.get_xlc_version(cxx) | |
10 | conf.env.CXX_NAME='xlc++' | |
11 | conf.env.CXX=cxx | |
12 | def xlcxx_common_flags(conf): | |
13 | v=conf.env | |
14 | v['CXX_SRC_F']=[] | |
15 | v['CXX_TGT_F']=['-c','-o'] | |
16 | if not v['LINK_CXX']:v['LINK_CXX']=v['CXX'] | |
17 | v['CXXLNK_SRC_F']=[] | |
18 | v['CXXLNK_TGT_F']=['-o'] | |
19 | v['CPPPATH_ST']='-I%s' | |
20 | v['DEFINES_ST']='-D%s' | |
21 | v['LIB_ST']='-l%s' | |
22 | v['LIBPATH_ST']='-L%s' | |
23 | v['STLIB_ST']='-l%s' | |
24 | v['STLIBPATH_ST']='-L%s' | |
25 | v['RPATH_ST']='-Wl,-rpath,%s' | |
26 | v['SONAME_ST']=[] | |
27 | v['SHLIB_MARKER']=[] | |
28 | v['STLIB_MARKER']=[] | |
29 | v['LINKFLAGS_cxxprogram']=['-Wl,-brtl'] | |
30 | v['cxxprogram_PATTERN']='%s' | |
31 | v['CXXFLAGS_cxxshlib']=['-fPIC'] | |
32 | v['LINKFLAGS_cxxshlib']=['-G','-Wl,-brtl,-bexpfull'] | |
33 | v['cxxshlib_PATTERN']='lib%s.so' | |
34 | v['LINKFLAGS_cxxstlib']=[] | |
35 | v['cxxstlib_PATTERN']='lib%s.a' | |
36 | def configure(conf): | |
37 | conf.find_xlcxx() | |
38 | conf.find_ar() | |
39 | conf.xlcxx_common_flags() | |
40 | conf.cxx_load_tools() | |
41 | conf.cxx_add_flags() | |
42 | conf.link_add_flags() | |
43 | ||
44 | conf(find_xlcxx) | |
45 | conf(xlcxx_common_flags)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os,sys,errno,traceback,inspect,re,shutil,datetime,gc | |
5 | try: | |
6 | import subprocess | |
7 | except: | |
8 | try: | |
9 | import waflib.extras.subprocess as subprocess | |
10 | except: | |
11 | print("The subprocess module is missing (python2.3?):\n try calling 'waf update --files=subprocess'\n or add a copy of subprocess.py to the python libraries") | |
12 | try: | |
13 | from collections import deque | |
14 | except ImportError: | |
15 | class deque(list): | |
16 | def popleft(self): | |
17 | return self.pop(0) | |
18 | try: | |
19 | import _winreg as winreg | |
20 | except: | |
21 | try: | |
22 | import winreg | |
23 | except: | |
24 | winreg=None | |
25 | from waflib import Errors | |
26 | try: | |
27 | from collections import UserDict | |
28 | except: | |
29 | from UserDict import UserDict | |
30 | try: | |
31 | from hashlib import md5 | |
32 | except: | |
33 | try: | |
34 | from md5 import md5 | |
35 | except: | |
36 | pass | |
37 | try: | |
38 | import threading | |
39 | except: | |
40 | class threading(object): | |
41 | pass | |
42 | class Lock(object): | |
43 | def acquire(self): | |
44 | pass | |
45 | def release(self): | |
46 | pass | |
47 | threading.Lock=threading.Thread=Lock | |
48 | else: | |
49 | run_old=threading.Thread.run | |
50 | def run(*args,**kwargs): | |
51 | try: | |
52 | run_old(*args,**kwargs) | |
53 | except(KeyboardInterrupt,SystemExit): | |
54 | raise | |
55 | except: | |
56 | sys.excepthook(*sys.exc_info()) | |
57 | threading.Thread.run=run | |
58 | SIG_NIL='iluvcuteoverload' | |
59 | O644=420 | |
60 | O755=493 | |
61 | rot_chr=['\\','|','/','-'] | |
62 | rot_idx=0 | |
63 | try: | |
64 | from collections import defaultdict | |
65 | except ImportError: | |
66 | class defaultdict(dict): | |
67 | def __init__(self,default_factory): | |
68 | super(defaultdict,self).__init__() | |
69 | self.default_factory=default_factory | |
70 | def __getitem__(self,key): | |
71 | try: | |
72 | return super(defaultdict,self).__getitem__(key) | |
73 | except KeyError: | |
74 | value=self.default_factory() | |
75 | self[key]=value | |
76 | return value | |
77 | is_win32=sys.platform in('win32','cli') | |
78 | indicator='\x1b[K%s%s%s\r' | |
79 | if is_win32 and'NOCOLOR'in os.environ: | |
80 | indicator='%s%s%s\r' | |
81 | def readf(fname,m='r'): | |
82 | f=open(fname,m) | |
83 | try: | |
84 | txt=f.read() | |
85 | finally: | |
86 | f.close() | |
87 | return txt | |
88 | def h_file(filename): | |
89 | f=open(filename,'rb') | |
90 | m=md5() | |
91 | try: | |
92 | while filename: | |
93 | filename=f.read(100000) | |
94 | m.update(filename) | |
95 | finally: | |
96 | f.close() | |
97 | return m.digest() | |
98 | try: | |
99 | x=''.encode('hex') | |
100 | except: | |
101 | import binascii | |
102 | def to_hex(s): | |
103 | ret=binascii.hexlify(s) | |
104 | if not isinstance(ret,str): | |
105 | ret=ret.decode('utf-8') | |
106 | return ret | |
107 | else: | |
108 | def to_hex(s): | |
109 | return s.encode('hex') | |
110 | to_hex.__doc__=""" | |
111 | Return the hexadecimal representation of a string | |
112 | ||
113 | :param s: string to convert | |
114 | :type s: string | |
115 | """ | |
116 | listdir=os.listdir | |
117 | if is_win32: | |
118 | def listdir_win32(s): | |
119 | if not s: | |
120 | try: | |
121 | import ctypes | |
122 | except: | |
123 | return[x+':\\'for x in list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')] | |
124 | else: | |
125 | dlen=4 | |
126 | maxdrives=26 | |
127 | buf=ctypes.create_string_buffer(maxdrives*dlen) | |
128 | ndrives=ctypes.windll.kernel32.GetLogicalDriveStringsA(maxdrives,ctypes.byref(buf)) | |
129 | return[buf.raw[4*i:4*i+3].decode('ascii')for i in range(int(ndrives/dlen))] | |
130 | if len(s)==2 and s[1]==":": | |
131 | s+=os.sep | |
132 | if not os.path.isdir(s): | |
133 | e=OSError() | |
134 | e.errno=errno.ENOENT | |
135 | raise e | |
136 | return os.listdir(s) | |
137 | listdir=listdir_win32 | |
138 | def num2ver(ver): | |
139 | if isinstance(ver,str): | |
140 | ver=tuple(ver.split('.')) | |
141 | if isinstance(ver,tuple): | |
142 | ret=0 | |
143 | for i in range(4): | |
144 | if i<len(ver): | |
145 | ret+=256**(3-i)*int(ver[i]) | |
146 | return ret | |
147 | return ver | |
148 | def ex_stack(): | |
149 | exc_type,exc_value,tb=sys.exc_info() | |
150 | exc_lines=traceback.format_exception(exc_type,exc_value,tb) | |
151 | return''.join(exc_lines) | |
152 | def to_list(sth): | |
153 | if isinstance(sth,str): | |
154 | return sth.split() | |
155 | else: | |
156 | return sth | |
157 | re_nl=re.compile('\r*\n',re.M) | |
158 | def str_to_dict(txt): | |
159 | tbl={} | |
160 | lines=re_nl.split(txt) | |
161 | for x in lines: | |
162 | x=x.strip() | |
163 | if not x or x.startswith('#')or x.find('=')<0: | |
164 | continue | |
165 | tmp=x.split('=') | |
166 | tbl[tmp[0].strip()]='='.join(tmp[1:]).strip() | |
167 | return tbl | |
168 | def split_path(path): | |
169 | return path.split('/') | |
170 | def split_path_cygwin(path): | |
171 | if path.startswith('//'): | |
172 | ret=path.split('/')[2:] | |
173 | ret[0]='/'+ret[0] | |
174 | return ret | |
175 | return path.split('/') | |
176 | re_sp=re.compile('[/\\\\]') | |
177 | def split_path_win32(path): | |
178 | if path.startswith('\\\\'): | |
179 | ret=re.split(re_sp,path)[2:] | |
180 | ret[0]='\\'+ret[0] | |
181 | return ret | |
182 | return re.split(re_sp,path) | |
183 | if sys.platform=='cygwin': | |
184 | split_path=split_path_cygwin | |
185 | elif is_win32: | |
186 | split_path=split_path_win32 | |
187 | split_path.__doc__=""" | |
188 | Split a path by / or \\. This function is not like os.path.split | |
189 | ||
190 | :type path: string | |
191 | :param path: path to split | |
192 | :return: list of strings | |
193 | """ | |
194 | def check_dir(path): | |
195 | if not os.path.isdir(path): | |
196 | try: | |
197 | os.makedirs(path) | |
198 | except OSError ,e: | |
199 | if not os.path.isdir(path): | |
200 | raise Errors.WafError('Cannot create the folder %r'%path,ex=e) | |
201 | def def_attrs(cls,**kw): | |
202 | for k,v in kw.items(): | |
203 | if not hasattr(cls,k): | |
204 | setattr(cls,k,v) | |
205 | def quote_define_name(s): | |
206 | fu=re.compile("[^a-zA-Z0-9]").sub("_",s) | |
207 | fu=fu.upper() | |
208 | return fu | |
209 | def h_list(lst): | |
210 | m=md5() | |
211 | m.update(str(lst)) | |
212 | return m.digest() | |
213 | def h_fun(fun): | |
214 | try: | |
215 | return fun.code | |
216 | except AttributeError: | |
217 | try: | |
218 | h=inspect.getsource(fun) | |
219 | except IOError: | |
220 | h="nocode" | |
221 | try: | |
222 | fun.code=h | |
223 | except AttributeError: | |
224 | pass | |
225 | return h | |
226 | reg_subst=re.compile(r"(\\\\)|(\$\$)|\$\{([^}]+)\}") | |
227 | def subst_vars(expr,params): | |
228 | def repl_var(m): | |
229 | if m.group(1): | |
230 | return'\\' | |
231 | if m.group(2): | |
232 | return'$' | |
233 | try: | |
234 | return params.get_flat(m.group(3)) | |
235 | except AttributeError: | |
236 | return params[m.group(3)] | |
237 | return reg_subst.sub(repl_var,expr) | |
238 | def destos_to_binfmt(key): | |
239 | if key=='darwin': | |
240 | return'mac-o' | |
241 | elif key in('win32','cygwin','uwin','msys'): | |
242 | return'pe' | |
243 | return'elf' | |
244 | def unversioned_sys_platform(): | |
245 | s=sys.platform | |
246 | if s=='java': | |
247 | from java.lang import System | |
248 | s=System.getProperty('os.name') | |
249 | if s=='Mac OS X': | |
250 | return'darwin' | |
251 | elif s.startswith('Windows '): | |
252 | return'win32' | |
253 | elif s=='OS/2': | |
254 | return'os2' | |
255 | elif s=='HP-UX': | |
256 | return'hpux' | |
257 | elif s in('SunOS','Solaris'): | |
258 | return'sunos' | |
259 | else:s=s.lower() | |
260 | if s=='powerpc': | |
261 | return'darwin' | |
262 | if s=='win32'or s.endswith('os2')and s!='sunos2':return s | |
263 | return re.split('\d+$',s)[0] | |
264 | def nada(*k,**kw): | |
265 | pass | |
266 | class Timer(object): | |
267 | def __init__(self): | |
268 | self.start_time=datetime.datetime.utcnow() | |
269 | def __str__(self): | |
270 | delta=datetime.datetime.utcnow()-self.start_time | |
271 | days=int(delta.days) | |
272 | hours=delta.seconds//3600 | |
273 | minutes=(delta.seconds-hours*3600)//60 | |
274 | seconds=delta.seconds-hours*3600-minutes*60+float(delta.microseconds)/1000/1000 | |
275 | result='' | |
276 | if days: | |
277 | result+='%dd'%days | |
278 | if days or hours: | |
279 | result+='%dh'%hours | |
280 | if days or hours or minutes: | |
281 | result+='%dm'%minutes | |
282 | return'%s%.3fs'%(result,seconds) | |
283 | if is_win32: | |
284 | old=shutil.copy2 | |
285 | def copy2(src,dst): | |
286 | old(src,dst) | |
287 | shutil.copystat(src,dst) | |
288 | setattr(shutil,'copy2',copy2) | |
289 | if os.name=='java': | |
290 | try: | |
291 | gc.disable() | |
292 | gc.enable() | |
293 | except NotImplementedError: | |
294 | gc.disable=gc.enable | |
295 | def read_la_file(path): | |
296 | sp=re.compile(r'^([^=]+)=\'(.*)\'$') | |
297 | dc={} | |
298 | for line in readf(path).splitlines(): | |
299 | try: | |
300 | _,left,right,_=sp.split(line.strip()) | |
301 | dc[left]=right | |
302 | except ValueError: | |
303 | pass | |
304 | return dc | |
305 | def nogc(fun): | |
306 | def f(*k,**kw): | |
307 | try: | |
308 | gc.disable() | |
309 | ret=fun(*k,**kw) | |
310 | finally: | |
311 | gc.enable() | |
312 | return ret | |
313 | f.__doc__=fun.__doc__ | |
314 | return f | |
315 | def run_once(fun): | |
316 | cache={} | |
317 | def wrap(k): | |
318 | try: | |
319 | return cache[k] | |
320 | except KeyError: | |
321 | ret=fun(k) | |
322 | cache[k]=ret | |
323 | return ret | |
324 | wrap.__cache__=cache | |
325 | return wrap | |
326 | def get_registry_app_path(key,filename): | |
327 | if not winreg: | |
328 | return None | |
329 | try: | |
330 | result=winreg.QueryValue(key,"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s.exe"%filename[0]) | |
331 | except WindowsError: | |
332 | pass | |
333 | else: | |
334 | if os.path.isfile(result): | |
335 | return result |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys,os | |
5 | try: | |
6 | if not(sys.stderr.isatty()and sys.stdout.isatty()): | |
7 | raise ValueError('not a tty') | |
8 | from ctypes import* | |
9 | class COORD(Structure): | |
10 | _fields_=[("X",c_short),("Y",c_short)] | |
11 | class SMALL_RECT(Structure): | |
12 | _fields_=[("Left",c_short),("Top",c_short),("Right",c_short),("Bottom",c_short)] | |
13 | class CONSOLE_SCREEN_BUFFER_INFO(Structure): | |
14 | _fields_=[("Size",COORD),("CursorPosition",COORD),("Attributes",c_short),("Window",SMALL_RECT),("MaximumWindowSize",COORD)] | |
15 | class CONSOLE_CURSOR_INFO(Structure): | |
16 | _fields_=[('dwSize',c_ulong),('bVisible',c_int)] | |
17 | sbinfo=CONSOLE_SCREEN_BUFFER_INFO() | |
18 | csinfo=CONSOLE_CURSOR_INFO() | |
19 | hconsole=windll.kernel32.GetStdHandle(-11) | |
20 | windll.kernel32.GetConsoleScreenBufferInfo(hconsole,byref(sbinfo)) | |
21 | if sbinfo.Size.X<9 or sbinfo.Size.Y<9:raise ValueError('small console') | |
22 | windll.kernel32.GetConsoleCursorInfo(hconsole,byref(csinfo)) | |
23 | except Exception: | |
24 | pass | |
25 | else: | |
26 | import re,threading | |
27 | is_vista=getattr(sys,"getwindowsversion",None)and sys.getwindowsversion()[0]>=6 | |
28 | try: | |
29 | _type=unicode | |
30 | except: | |
31 | _type=str | |
32 | to_int=lambda number,default:number and int(number)or default | |
33 | wlock=threading.Lock() | |
34 | STD_OUTPUT_HANDLE=-11 | |
35 | STD_ERROR_HANDLE=-12 | |
36 | class AnsiTerm(object): | |
37 | def __init__(self): | |
38 | self.encoding=sys.stdout.encoding | |
39 | self.hconsole=windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) | |
40 | self.cursor_history=[] | |
41 | self.orig_sbinfo=CONSOLE_SCREEN_BUFFER_INFO() | |
42 | self.orig_csinfo=CONSOLE_CURSOR_INFO() | |
43 | windll.kernel32.GetConsoleScreenBufferInfo(self.hconsole,byref(self.orig_sbinfo)) | |
44 | windll.kernel32.GetConsoleCursorInfo(hconsole,byref(self.orig_csinfo)) | |
45 | def screen_buffer_info(self): | |
46 | sbinfo=CONSOLE_SCREEN_BUFFER_INFO() | |
47 | windll.kernel32.GetConsoleScreenBufferInfo(self.hconsole,byref(sbinfo)) | |
48 | return sbinfo | |
49 | def clear_line(self,param): | |
50 | mode=param and int(param)or 0 | |
51 | sbinfo=self.screen_buffer_info() | |
52 | if mode==1: | |
53 | line_start=COORD(0,sbinfo.CursorPosition.Y) | |
54 | line_length=sbinfo.Size.X | |
55 | elif mode==2: | |
56 | line_start=COORD(sbinfo.CursorPosition.X,sbinfo.CursorPosition.Y) | |
57 | line_length=sbinfo.Size.X-sbinfo.CursorPosition.X | |
58 | else: | |
59 | line_start=sbinfo.CursorPosition | |
60 | line_length=sbinfo.Size.X-sbinfo.CursorPosition.X | |
61 | chars_written=c_int() | |
62 | windll.kernel32.FillConsoleOutputCharacterA(self.hconsole,c_wchar(' '),line_length,line_start,byref(chars_written)) | |
63 | windll.kernel32.FillConsoleOutputAttribute(self.hconsole,sbinfo.Attributes,line_length,line_start,byref(chars_written)) | |
64 | def clear_screen(self,param): | |
65 | mode=to_int(param,0) | |
66 | sbinfo=self.screen_buffer_info() | |
67 | if mode==1: | |
68 | clear_start=COORD(0,0) | |
69 | clear_length=sbinfo.CursorPosition.X*sbinfo.CursorPosition.Y | |
70 | elif mode==2: | |
71 | clear_start=COORD(0,0) | |
72 | clear_length=sbinfo.Size.X*sbinfo.Size.Y | |
73 | windll.kernel32.SetConsoleCursorPosition(self.hconsole,clear_start) | |
74 | else: | |
75 | clear_start=sbinfo.CursorPosition | |
76 | clear_length=((sbinfo.Size.X-sbinfo.CursorPosition.X)+sbinfo.Size.X*(sbinfo.Size.Y-sbinfo.CursorPosition.Y)) | |
77 | chars_written=c_int() | |
78 | windll.kernel32.FillConsoleOutputCharacterA(self.hconsole,c_wchar(' '),clear_length,clear_start,byref(chars_written)) | |
79 | windll.kernel32.FillConsoleOutputAttribute(self.hconsole,sbinfo.Attributes,clear_length,clear_start,byref(chars_written)) | |
80 | def push_cursor(self,param): | |
81 | sbinfo=self.screen_buffer_info() | |
82 | self.cursor_history.append(sbinfo.CursorPosition) | |
83 | def pop_cursor(self,param): | |
84 | if self.cursor_history: | |
85 | old_pos=self.cursor_history.pop() | |
86 | windll.kernel32.SetConsoleCursorPosition(self.hconsole,old_pos) | |
87 | def set_cursor(self,param): | |
88 | y,sep,x=param.partition(';') | |
89 | x=to_int(x,1)-1 | |
90 | y=to_int(y,1)-1 | |
91 | sbinfo=self.screen_buffer_info() | |
92 | new_pos=COORD(min(max(0,x),sbinfo.Size.X),min(max(0,y),sbinfo.Size.Y)) | |
93 | windll.kernel32.SetConsoleCursorPosition(self.hconsole,new_pos) | |
94 | def set_column(self,param): | |
95 | x=to_int(param,1)-1 | |
96 | sbinfo=self.screen_buffer_info() | |
97 | new_pos=COORD(min(max(0,x),sbinfo.Size.X),sbinfo.CursorPosition.Y) | |
98 | windll.kernel32.SetConsoleCursorPosition(self.hconsole,new_pos) | |
99 | def move_cursor(self,x_offset=0,y_offset=0): | |
100 | sbinfo=self.screen_buffer_info() | |
101 | new_pos=COORD(min(max(0,sbinfo.CursorPosition.X+x_offset),sbinfo.Size.X),min(max(0,sbinfo.CursorPosition.Y+y_offset),sbinfo.Size.Y)) | |
102 | windll.kernel32.SetConsoleCursorPosition(self.hconsole,new_pos) | |
103 | def move_up(self,param): | |
104 | self.move_cursor(y_offset=-to_int(param,1)) | |
105 | def move_down(self,param): | |
106 | self.move_cursor(y_offset=to_int(param,1)) | |
107 | def move_left(self,param): | |
108 | self.move_cursor(x_offset=-to_int(param,1)) | |
109 | def move_right(self,param): | |
110 | self.move_cursor(x_offset=to_int(param,1)) | |
111 | def next_line(self,param): | |
112 | sbinfo=self.screen_buffer_info() | |
113 | self.move_cursor(x_offset=-sbinfo.CursorPosition.X,y_offset=to_int(param,1)) | |
114 | def prev_line(self,param): | |
115 | sbinfo=self.screen_buffer_info() | |
116 | self.move_cursor(x_offset=-sbinfo.CursorPosition.X,y_offset=-to_int(param,1)) | |
117 | def rgb2bgr(self,c): | |
118 | return((c&1)<<2)|(c&2)|((c&4)>>2) | |
119 | def set_color(self,param): | |
120 | cols=param.split(';') | |
121 | sbinfo=CONSOLE_SCREEN_BUFFER_INFO() | |
122 | windll.kernel32.GetConsoleScreenBufferInfo(self.hconsole,byref(sbinfo)) | |
123 | attr=sbinfo.Attributes | |
124 | for c in cols: | |
125 | if is_vista: | |
126 | c=int(c) | |
127 | else: | |
128 | c=to_int(c,0) | |
129 | if c in range(30,38): | |
130 | attr=(attr&0xfff0)|self.rgb2bgr(c-30) | |
131 | elif c in range(40,48): | |
132 | attr=(attr&0xff0f)|(self.rgb2bgr(c-40)<<4) | |
133 | elif c==0: | |
134 | attr=self.orig_sbinfo.Attributes | |
135 | elif c==1: | |
136 | attr|=0x08 | |
137 | elif c==4: | |
138 | attr|=0x80 | |
139 | elif c==7: | |
140 | attr=(attr&0xff88)|((attr&0x70)>>4)|((attr&0x07)<<4) | |
141 | windll.kernel32.SetConsoleTextAttribute(self.hconsole,attr) | |
142 | def show_cursor(self,param): | |
143 | csinfo.bVisible=1 | |
144 | windll.kernel32.SetConsoleCursorInfo(self.hconsole,byref(csinfo)) | |
145 | def hide_cursor(self,param): | |
146 | csinfo.bVisible=0 | |
147 | windll.kernel32.SetConsoleCursorInfo(self.hconsole,byref(csinfo)) | |
148 | ansi_command_table={'A':move_up,'B':move_down,'C':move_right,'D':move_left,'E':next_line,'F':prev_line,'G':set_column,'H':set_cursor,'f':set_cursor,'J':clear_screen,'K':clear_line,'h':show_cursor,'l':hide_cursor,'m':set_color,'s':push_cursor,'u':pop_cursor,} | |
149 | ansi_tokens=re.compile('(?:\x1b\[([0-9?;]*)([a-zA-Z])|([^\x1b]+))') | |
150 | def write(self,text): | |
151 | try: | |
152 | wlock.acquire() | |
153 | for param,cmd,txt in self.ansi_tokens.findall(text): | |
154 | if cmd: | |
155 | cmd_func=self.ansi_command_table.get(cmd) | |
156 | if cmd_func: | |
157 | cmd_func(self,param) | |
158 | else: | |
159 | self.writeconsole(txt) | |
160 | finally: | |
161 | wlock.release() | |
162 | def writeconsole(self,txt): | |
163 | chars_written=c_int() | |
164 | writeconsole=windll.kernel32.WriteConsoleA | |
165 | if isinstance(txt,_type): | |
166 | writeconsole=windll.kernel32.WriteConsoleW | |
167 | TINY_STEP=3000 | |
168 | for x in range(0,len(txt),TINY_STEP): | |
169 | tiny=txt[x:x+TINY_STEP] | |
170 | writeconsole(self.hconsole,tiny,len(tiny),byref(chars_written),None) | |
171 | def flush(self): | |
172 | pass | |
173 | def isatty(self): | |
174 | return True | |
175 | sys.stderr=sys.stdout=AnsiTerm() | |
176 | os.environ['TERM']='vt100' |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import sys | |
5 | if sys.hexversion < 0x020400f0: from sets import Set as set | |
6 | import sys | |
7 | from waflib import ConfigSet,Logs,Options,Scripting,Task,Build,Configure,Node,Runner,TaskGen,Utils,Errors,Context | |
8 | sys.modules['Environment']=ConfigSet | |
9 | ConfigSet.Environment=ConfigSet.ConfigSet | |
10 | sys.modules['Logs']=Logs | |
11 | sys.modules['Options']=Options | |
12 | sys.modules['Scripting']=Scripting | |
13 | sys.modules['Task']=Task | |
14 | sys.modules['Build']=Build | |
15 | sys.modules['Configure']=Configure | |
16 | sys.modules['Node']=Node | |
17 | sys.modules['Runner']=Runner | |
18 | sys.modules['TaskGen']=TaskGen | |
19 | sys.modules['Utils']=Utils | |
20 | from waflib.Tools import c_preproc | |
21 | sys.modules['preproc']=c_preproc | |
22 | from waflib.Tools import c_config | |
23 | sys.modules['config_c']=c_config | |
24 | ConfigSet.ConfigSet.copy=ConfigSet.ConfigSet.derive | |
25 | ConfigSet.ConfigSet.set_variant=Utils.nada | |
26 | Build.BuildContext.add_subdirs=Build.BuildContext.recurse | |
27 | Build.BuildContext.new_task_gen=Build.BuildContext.__call__ | |
28 | Build.BuildContext.is_install=0 | |
29 | Node.Node.relpath_gen=Node.Node.path_from | |
30 | def name_to_obj(self,s,env=None): | |
31 | Logs.warn('compat: change "name_to_obj(name, env)" by "get_tgen_by_name(name)"') | |
32 | return self.get_tgen_by_name(s) | |
33 | Build.BuildContext.name_to_obj=name_to_obj | |
34 | def env_of_name(self,name): | |
35 | try: | |
36 | return self.all_envs[name] | |
37 | except KeyError: | |
38 | Logs.error('no such environment: '+name) | |
39 | return None | |
40 | Build.BuildContext.env_of_name=env_of_name | |
41 | def set_env_name(self,name,env): | |
42 | self.all_envs[name]=env | |
43 | return env | |
44 | Configure.ConfigurationContext.set_env_name=set_env_name | |
45 | def retrieve(self,name,fromenv=None): | |
46 | try: | |
47 | env=self.all_envs[name] | |
48 | except KeyError: | |
49 | env=ConfigSet.ConfigSet() | |
50 | self.prepare_env(env) | |
51 | self.all_envs[name]=env | |
52 | else: | |
53 | if fromenv:Logs.warn("The environment %s may have been configured already"%name) | |
54 | return env | |
55 | Configure.ConfigurationContext.retrieve=retrieve | |
56 | Configure.ConfigurationContext.sub_config=Configure.ConfigurationContext.recurse | |
57 | Configure.ConfigurationContext.check_tool=Configure.ConfigurationContext.load | |
58 | Configure.conftest=Configure.conf | |
59 | Configure.ConfigurationError=Errors.ConfigurationError | |
60 | Options.OptionsContext.sub_options=Options.OptionsContext.recurse | |
61 | Options.OptionsContext.tool_options=Context.Context.load | |
62 | Options.Handler=Options.OptionsContext | |
63 | Task.simple_task_type=Task.task_type_from_func=Task.task_factory | |
64 | Task.TaskBase.classes=Task.classes | |
65 | def setitem(self,key,value): | |
66 | if key.startswith('CCFLAGS'): | |
67 | key=key[1:] | |
68 | self.table[key]=value | |
69 | ConfigSet.ConfigSet.__setitem__=setitem | |
70 | def old_importpaths(self): | |
71 | if getattr(self,'importpaths',[]): | |
72 | self.includes=self.importpaths | |
73 | from waflib import Context | |
74 | eld=Context.load_tool | |
75 | def load_tool(*k,**kw): | |
76 | ret=eld(*k,**kw) | |
77 | if'set_options'in ret.__dict__: | |
78 | Logs.warn('compat: rename "set_options" to options') | |
79 | ret.options=ret.set_options | |
80 | if'detect'in ret.__dict__: | |
81 | Logs.warn('compat: rename "detect" to "configure"') | |
82 | ret.configure=ret.detect | |
83 | return ret | |
84 | Context.load_tool=load_tool | |
85 | rev=Context.load_module | |
86 | def load_module(path): | |
87 | ret=rev(path) | |
88 | if'set_options'in ret.__dict__: | |
89 | Logs.warn('compat: rename "set_options" to "options" (%r)'%path) | |
90 | ret.options=ret.set_options | |
91 | if'srcdir'in ret.__dict__: | |
92 | Logs.warn('compat: rename "srcdir" to "top" (%r)'%path) | |
93 | ret.top=ret.srcdir | |
94 | if'blddir'in ret.__dict__: | |
95 | Logs.warn('compat: rename "blddir" to "out" (%r)'%path) | |
96 | ret.out=ret.blddir | |
97 | return ret | |
98 | Context.load_module=load_module | |
99 | old_post=TaskGen.task_gen.post | |
100 | def post(self): | |
101 | self.features=self.to_list(self.features) | |
102 | if'cc'in self.features: | |
103 | Logs.warn('compat: the feature cc does not exist anymore (use "c")') | |
104 | self.features.remove('cc') | |
105 | self.features.append('c') | |
106 | if'cstaticlib'in self.features: | |
107 | Logs.warn('compat: the feature cstaticlib does not exist anymore (use "cstlib" or "cxxstlib")') | |
108 | self.features.remove('cstaticlib') | |
109 | self.features.append(('cxx'in self.features)and'cxxstlib'or'cstlib') | |
110 | if getattr(self,'ccflags',None): | |
111 | Logs.warn('compat: "ccflags" was renamed to "cflags"') | |
112 | self.cflags=self.ccflags | |
113 | return old_post(self) | |
114 | TaskGen.task_gen.post=post | |
115 | def waf_version(*k,**kw): | |
116 | Logs.warn('wrong version (waf_version was removed in waf 1.6)') | |
117 | Utils.waf_version=waf_version | |
118 | import os | |
119 | def apply_uselib_local(self): | |
120 | env=self.env | |
121 | from waflib.Tools.ccroot import stlink_task | |
122 | self.uselib=self.to_list(getattr(self,'uselib',[])) | |
123 | self.includes=self.to_list(getattr(self,'includes',[])) | |
124 | names=self.to_list(getattr(self,'uselib_local',[])) | |
125 | get=self.bld.get_tgen_by_name | |
126 | seen=set([]) | |
127 | tmp=Utils.deque(names) | |
128 | if tmp: | |
129 | Logs.warn('compat: "uselib_local" is deprecated, replace by "use"') | |
130 | while tmp: | |
131 | lib_name=tmp.popleft() | |
132 | if lib_name in seen: | |
133 | continue | |
134 | y=get(lib_name) | |
135 | y.post() | |
136 | seen.add(lib_name) | |
137 | if getattr(y,'uselib_local',None): | |
138 | for x in self.to_list(getattr(y,'uselib_local',[])): | |
139 | obj=get(x) | |
140 | obj.post() | |
141 | if getattr(obj,'link_task',None): | |
142 | if not isinstance(obj.link_task,stlink_task): | |
143 | tmp.append(x) | |
144 | if getattr(y,'link_task',None): | |
145 | link_name=y.target[y.target.rfind(os.sep)+1:] | |
146 | if isinstance(y.link_task,stlink_task): | |
147 | env.append_value('STLIB',[link_name]) | |
148 | else: | |
149 | env.append_value('LIB',[link_name]) | |
150 | self.link_task.set_run_after(y.link_task) | |
151 | self.link_task.dep_nodes+=y.link_task.outputs | |
152 | tmp_path=y.link_task.outputs[0].parent.bldpath() | |
153 | if not tmp_path in env['LIBPATH']: | |
154 | env.prepend_value('LIBPATH',[tmp_path]) | |
155 | for v in self.to_list(getattr(y,'uselib',[])): | |
156 | if not env['STLIB_'+v]: | |
157 | if not v in self.uselib: | |
158 | self.uselib.insert(0,v) | |
159 | if getattr(y,'export_includes',None): | |
160 | self.includes.extend(y.to_incnodes(y.export_includes)) | |
161 | def apply_objdeps(self): | |
162 | names=getattr(self,'add_objects',[]) | |
163 | if not names: | |
164 | return | |
165 | names=self.to_list(names) | |
166 | get=self.bld.get_tgen_by_name | |
167 | seen=[] | |
168 | while names: | |
169 | x=names[0] | |
170 | if x in seen: | |
171 | names=names[1:] | |
172 | continue | |
173 | y=get(x) | |
174 | if getattr(y,'add_objects',None): | |
175 | added=0 | |
176 | lst=y.to_list(y.add_objects) | |
177 | lst.reverse() | |
178 | for u in lst: | |
179 | if u in seen:continue | |
180 | added=1 | |
181 | names=[u]+names | |
182 | if added:continue | |
183 | y.post() | |
184 | seen.append(x) | |
185 | for t in getattr(y,'compiled_tasks',[]): | |
186 | self.link_task.inputs.extend(t.outputs) | |
187 | def process_obj_files(self): | |
188 | if not hasattr(self,'obj_files'): | |
189 | return | |
190 | for x in self.obj_files: | |
191 | node=self.path.find_resource(x) | |
192 | self.link_task.inputs.append(node) | |
193 | def add_obj_file(self,file): | |
194 | if not hasattr(self,'obj_files'):self.obj_files=[] | |
195 | if not'process_obj_files'in self.meths:self.meths.append('process_obj_files') | |
196 | self.obj_files.append(file) | |
197 | old_define=Configure.ConfigurationContext.__dict__['define'] | |
198 | def define(self,key,val,quote=True): | |
199 | old_define(self,key,val,quote) | |
200 | if key.startswith('HAVE_'): | |
201 | self.env[key]=1 | |
202 | old_undefine=Configure.ConfigurationContext.__dict__['undefine'] | |
203 | def undefine(self,key): | |
204 | old_undefine(self,key) | |
205 | if key.startswith('HAVE_'): | |
206 | self.env[key]=0 | |
207 | def set_incdirs(self,val): | |
208 | Logs.warn('compat: change "export_incdirs" by "export_includes"') | |
209 | self.export_includes=val | |
210 | TaskGen.task_gen.export_incdirs=property(None,set_incdirs) | |
211 | ||
212 | TaskGen.feature('d')(old_importpaths) | |
213 | TaskGen.before('apply_incpaths')(old_importpaths) | |
214 | TaskGen.feature('c','cxx','d')(apply_uselib_local) | |
215 | TaskGen.before('apply_incpaths','propagate_uselib_vars')(apply_uselib_local) | |
216 | TaskGen.after('apply_link','process_source')(apply_uselib_local) | |
217 | TaskGen.feature('cprogram','cxxprogram','cstlib','cxxstlib','cshlib','cxxshlib','dprogram','dstlib','dshlib')(apply_objdeps) | |
218 | TaskGen.after('apply_link')(apply_objdeps) | |
219 | TaskGen.after('apply_link')(process_obj_files) | |
220 | TaskGen.taskgen_method(add_obj_file) | |
221 | Configure.conf(define) | |
222 | Configure.conf(undefine)⏎ |
0 | #! /usr/bin/env python | |
1 | # encoding: utf-8 | |
2 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file | |
3 | ||
4 | import os | |
5 | all_modifs={} | |
6 | def fixdir(dir): | |
7 | global all_modifs | |
8 | for k in all_modifs: | |
9 | for v in all_modifs[k]: | |
10 | modif(os.path.join(dir,'waflib'),k,v) | |
11 | def modif(dir,name,fun): | |
12 | if name=='*': | |
13 | lst=[] | |
14 | for y in'. Tools extras'.split(): | |
15 | for x in os.listdir(os.path.join(dir,y)): | |
16 | if x.endswith('.py'): | |
17 | lst.append(y+os.sep+x) | |
18 | for x in lst: | |
19 | modif(dir,x,fun) | |
20 | return | |
21 | filename=os.path.join(dir,name) | |
22 | f=open(filename,'r') | |
23 | txt=f.read() | |
24 | f.close() | |
25 | txt=fun(txt) | |
26 | f=open(filename,'w') | |
27 | f.write(txt) | |
28 | f.close() | |
29 | def subst(*k): | |
30 | def do_subst(fun): | |
31 | global all_modifs | |
32 | for x in k: | |
33 | try: | |
34 | all_modifs[x].append(fun) | |
35 | except KeyError: | |
36 | all_modifs[x]=[fun] | |
37 | return fun | |
38 | return do_subst | |
39 | def r1(code): | |
40 | code=code.replace(',e:',',e:') | |
41 | code=code.replace("",'') | |
42 | code=code.replace('','') | |
43 | return code | |
44 | def r4(code): | |
45 | code=code.replace('next(self.biter)','self.biter.next()') | |
46 | return code | |
47 | ||
48 | subst('*')(r1) | |
49 | subst('Runner.py')(r4)⏎ |