Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
odep_info.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 import sys, os, re
4 
5 obj_files = sys.argv[1:]
6 
7 defined = dict((x,set([])) for x in obj_files)
8 undefined = dict((x,set([])) for x in obj_files)
9 nm_re = re.compile("[0-9a-fA-F]*\s*([BCDRTU])\s+([A-Za-z_][A-Za-z_0-9]*)\s*")
10 def nm_match(x): return ( nm_re.match(line) for line in os.popen('nm -g '+x) )
11 def nm_line(x,m):
12  if m.group(1)=='U': undefined[x].add(m.group(2))
13  else: defined[x].add(m.group(2))
14 [ [ nm_line(x,m) for m in nm_match(x) if m!=None ] for x in obj_files ]
15 
16 def closure(seq,f):
17  v = [], [x for x in seq], set(x for x in seq)
18  while len(v[1]): [(v[1].append(y),v[2].add(y)) for y in
19  f((lambda x: (v[0].append(x),x)[1])(v[1].pop())) if not y in v[2]]
20  return v[0]
21 
22 needs={}
23 def get_needs(x):
24  if not needs.has_key(x):
25  needs[x]=[y for y in obj_files if len(defined[y]&undefined[x])]
26  return needs[x]
27 deps = dict((x,closure(get_needs(x),get_needs)) for x in obj_files)
28 
29 for x in deps:
30  print x,'depends on',reduce((lambda a,b: a+" "+b),deps[x],"")
31 print
32 
33 results = [ os.path.splitext(x)[0] for x in obj_files if 'main' in defined[x] ]
34 print "RESULTS="+reduce((lambda a,b: a+" "+b),results,"")
35 print
36 
37 def need_X(objs):
38  for x in objs:
39  if "XOpenDisplay" in undefined[x]: return True
40  return False
41 
42 for x in results:
43  objs = deps[x+'.o'];
44  if not (x+'.o') in objs: objs.append(x+'.o')
45  sobjs = reduce((lambda a,b: a+" "+b),objs,"")
46  if need_X(objs):
47  print x+":"+sobjs+" ; @echo LINK $@; $(LINKCMD) $^ -lX11 -o $@"
48  else:
49  print x+":"+sobjs+" ; @echo LINK $@; $(LINKCMD) $^ -o $@"
50 
def closure
Definition: odep_info.py:16
def nm_line
Definition: odep_info.py:11
def nm_match
Definition: odep_info.py:10
def get_needs
Definition: odep_info.py:23
def need_X
Definition: odep_info.py:37