Enable the building of introspection files for Visual C++ builds
[atk.git] / build / win32 / gen-file-list-atk.py
blob8729c90492a2b6113a2ee76c6020084bfcba6e60
1 #!/usr/bin/python
2 # vim: encoding=utf-8
3 # Generate the file lists for processing with g-ir-scanner
4 import os
5 import sys
6 import re
7 import string
8 import subprocess
9 import optparse
11 def gen_atk_filelist(srcroot, subdir, dest):
12 vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'),
13 vars = {'top_builddir':'.'},
14 conds = {'HAVE_INTROSPECTION':True},
15 filters = ['introspection_sources', 'introspection_generated_sources'])
17 files = vars['introspection_sources'].split() + \
18 vars['introspection_generated_sources'].split()
20 with open(dest, 'w') as d:
21 for i in files:
22 if (i.startswith('./atk/')):
23 i = i.replace('./atk/','')
24 d.write(srcroot + '\\' + subdir + '\\' + i.replace('/', '\\') + '\n')
26 def read_vars_from_AM(path, vars = {}, conds = {}, filters = None):
27 '''
28 path: path to the Makefile.am
29 vars: predefined variables
30 conds: condition variables for Makefile
31 filters: if None, all variables defined are returned,
32 otherwise, it is a list contains that variables should be returned
33 '''
34 cur_vars = vars.copy()
35 RE_AM_VAR_REF = re.compile(r'\$\((\w+?)\)')
36 RE_AM_VAR = re.compile(r'^\s*(\w+)\s*=(.*)$')
37 RE_AM_INCLUDE = re.compile(r'^\s*include\s+(\w+)')
38 RE_AM_CONTINUING = re.compile(r'\\\s*$')
39 RE_AM_IF = re.compile(r'^\s*if\s+(\w+)')
40 RE_AM_ELSE = re.compile(r'^\s*else')
41 RE_AM_ENDIF = re.compile(r'^\s*endif')
42 def am_eval(cont):
43 return RE_AM_VAR_REF.sub(lambda x: cur_vars.get(x.group(1), ''), cont)
44 with open(path, 'r') as f:
45 contents = f.readlines()
46 #combine continuing lines
47 i = 0
48 ncont = []
49 while i < len(contents):
50 line = contents[i]
51 if RE_AM_CONTINUING.search(line):
52 line = RE_AM_CONTINUING.sub('', line)
53 j = i + 1
54 while j < len(contents) and RE_AM_CONTINUING.search(contents[j]):
55 line += RE_AM_CONTINUING.sub('', contents[j])
56 j += 1
57 else:
58 if j < len(contents):
59 line += contents[j]
60 i = j
61 else:
62 i += 1
63 ncont.append(line)
65 #include, var define, var evaluation
66 i = -1
67 skip = False
68 oldskip = []
69 while i < len(ncont) - 1:
70 i += 1
71 line = ncont[i]
72 mo = RE_AM_IF.search(line)
73 if mo:
74 oldskip.append(skip)
75 skip = False if mo.group(1) in conds and conds[mo.group(1)] \
76 else True
77 continue
78 mo = RE_AM_ELSE.search(line)
79 if mo:
80 skip = not skip
81 continue
82 mo = RE_AM_ENDIF.search(line)
83 if mo:
84 skip = oldskip.pop()
85 continue
86 if not skip:
87 mo = RE_AM_INCLUDE.search(line)
88 if mo:
89 cur_vars.update(read_vars_from_AM(am_eval(mo.group(1)), cur_vars, conds, None))
90 continue
91 mo = RE_AM_VAR.search(line)
92 if mo:
93 cur_vars[mo.group(1)] = am_eval(mo.group(2).strip())
94 continue
96 #filter:
97 if filters != None:
98 ret = {}
99 for i in filters:
100 ret[i] = cur_vars.get(i, '')
101 return ret
102 else:
103 return cur_vars
105 def main(argv):
106 srcroot = '..\\..'
107 subdir = 'atk'
108 gen_atk_filelist(srcroot, subdir, 'atk_list')
109 return 0
111 if __name__ == '__main__':
112 sys.exit(main(sys.argv))