1 | #! /usr/bin/env python |
---|
2 | # encoding: utf-8 |
---|
3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
4 | |
---|
5 | import re |
---|
6 | from waflib import Utils,Task,TaskGen,Logs |
---|
7 | from waflib.Tools import ccroot,fc_config,fc_scan |
---|
8 | from waflib.TaskGen import feature,before_method,after_method,extension |
---|
9 | from waflib.Configure import conf |
---|
10 | ccroot.USELIB_VARS['fc']=set(['FCFLAGS','DEFINES','INCLUDES']) |
---|
11 | ccroot.USELIB_VARS['fcprogram_test']=ccroot.USELIB_VARS['fcprogram']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS']) |
---|
12 | ccroot.USELIB_VARS['fcshlib']=set(['LIB','STLIB','LIBPATH','STLIBPATH','LINKFLAGS','RPATH','LINKDEPS']) |
---|
13 | ccroot.USELIB_VARS['fcstlib']=set(['ARFLAGS','LINKDEPS']) |
---|
14 | @feature('fcprogram','fcshlib','fcstlib','fcprogram_test') |
---|
15 | def dummy(self): |
---|
16 | pass |
---|
17 | @extension('.f','.f90','.F','.F90','.for','.FOR') |
---|
18 | def fc_hook(self,node): |
---|
19 | return self.create_compiled_task('fc',node) |
---|
20 | @conf |
---|
21 | def modfile(conf,name): |
---|
22 | 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'] |
---|
23 | def get_fortran_tasks(tsk): |
---|
24 | bld=tsk.generator.bld |
---|
25 | tasks=bld.get_tasks_group(bld.get_group_idx(tsk.generator)) |
---|
26 | return[x for x in tasks if isinstance(x,fc)and not getattr(x,'nomod',None)and not getattr(x,'mod_fortran_done',None)] |
---|
27 | class fc(Task.Task): |
---|
28 | color='GREEN' |
---|
29 | run_str='${FC} ${FCFLAGS} ${FCINCPATH_ST:INCPATHS} ${FCDEFINES_ST:DEFINES} ${_FCMODOUTFLAGS} ${FC_TGT_F}${TGT[0].abspath()} ${FC_SRC_F}${SRC[0].abspath()}' |
---|
30 | vars=["FORTRANMODPATHFLAG"] |
---|
31 | def scan(self): |
---|
32 | tmp=fc_scan.fortran_parser(self.generator.includes_nodes) |
---|
33 | tmp.task=self |
---|
34 | tmp.start(self.inputs[0]) |
---|
35 | if Logs.verbose: |
---|
36 | Logs.debug('deps: deps for %r: %r; unresolved %r'%(self.inputs,tmp.nodes,tmp.names)) |
---|
37 | return(tmp.nodes,tmp.names) |
---|
38 | def runnable_status(self): |
---|
39 | if getattr(self,'mod_fortran_done',None): |
---|
40 | return super(fc,self).runnable_status() |
---|
41 | bld=self.generator.bld |
---|
42 | lst=get_fortran_tasks(self) |
---|
43 | for tsk in lst: |
---|
44 | tsk.mod_fortran_done=True |
---|
45 | for tsk in lst: |
---|
46 | ret=tsk.runnable_status() |
---|
47 | if ret==Task.ASK_LATER: |
---|
48 | for x in lst: |
---|
49 | x.mod_fortran_done=None |
---|
50 | return Task.ASK_LATER |
---|
51 | ins=Utils.defaultdict(set) |
---|
52 | outs=Utils.defaultdict(set) |
---|
53 | for tsk in lst: |
---|
54 | key=tsk.uid() |
---|
55 | for x in bld.raw_deps[key]: |
---|
56 | if x.startswith('MOD@'): |
---|
57 | name=bld.modfile(x.replace('MOD@','')) |
---|
58 | node=bld.srcnode.find_or_declare(name) |
---|
59 | tsk.set_outputs(node) |
---|
60 | outs[id(node)].add(tsk) |
---|
61 | for tsk in lst: |
---|
62 | key=tsk.uid() |
---|
63 | for x in bld.raw_deps[key]: |
---|
64 | if x.startswith('USE@'): |
---|
65 | name=bld.modfile(x.replace('USE@','')) |
---|
66 | node=bld.srcnode.find_resource(name) |
---|
67 | if node and node not in tsk.outputs: |
---|
68 | if not node in bld.node_deps[key]: |
---|
69 | bld.node_deps[key].append(node) |
---|
70 | ins[id(node)].add(tsk) |
---|
71 | for k in ins.keys(): |
---|
72 | for a in ins[k]: |
---|
73 | a.run_after.update(outs[k]) |
---|
74 | tmp=[] |
---|
75 | for t in outs[k]: |
---|
76 | tmp.extend(t.outputs) |
---|
77 | a.dep_nodes.extend(tmp) |
---|
78 | a.dep_nodes.sort(key=lambda x:x.abspath()) |
---|
79 | for tsk in lst: |
---|
80 | try: |
---|
81 | delattr(tsk,'cache_sig') |
---|
82 | except AttributeError: |
---|
83 | pass |
---|
84 | return super(fc,self).runnable_status() |
---|
85 | class fcprogram(ccroot.link_task): |
---|
86 | color='YELLOW' |
---|
87 | 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}' |
---|
88 | inst_to='${BINDIR}' |
---|
89 | class fcshlib(fcprogram): |
---|
90 | inst_to='${LIBDIR}' |
---|
91 | class fcprogram_test(fcprogram): |
---|
92 | def can_retrieve_cache(self): |
---|
93 | return False |
---|
94 | def runnable_status(self): |
---|
95 | ret=super(fcprogram_test,self).runnable_status() |
---|
96 | if ret==Task.SKIP_ME: |
---|
97 | ret=Task.RUN_ME |
---|
98 | return ret |
---|
99 | def exec_command(self,cmd,**kw): |
---|
100 | bld=self.generator.bld |
---|
101 | kw['shell']=isinstance(cmd,str) |
---|
102 | kw['stdout']=kw['stderr']=Utils.subprocess.PIPE |
---|
103 | kw['cwd']=bld.variant_dir |
---|
104 | bld.out=bld.err='' |
---|
105 | bld.to_log('command: %s\n'%cmd) |
---|
106 | kw['output']=0 |
---|
107 | try: |
---|
108 | (bld.out,bld.err)=bld.cmd_and_log(cmd,**kw) |
---|
109 | except Exception ,e: |
---|
110 | return-1 |
---|
111 | if bld.out: |
---|
112 | bld.to_log("out: %s\n"%bld.out) |
---|
113 | if bld.err: |
---|
114 | bld.to_log("err: %s\n"%bld.err) |
---|
115 | class fcstlib(ccroot.stlink_task): |
---|
116 | pass |
---|