3 # Generate the file lists for processing with g-ir-scanner
11 def gen_gdk_filelist(srcroot, subdir, dest):
12 vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'),
15 filters = ['gdk_public_h_sources', 'gdk_c_sources'])
17 vars['gdk_enums'] = 'gdkenumtypes.c gdkenumtypes.h'
19 files = vars['gdk_public_h_sources'].split() + \
20 vars['gdk_c_sources'].split() + \
21 vars['gdk_enums'].split()
23 sources = [i for i in files if (i != 'gdkkeysyms-compat.h')]
25 with open(dest, 'w') as d:
27 d.write(srcroot + '\\' + subdir + '\\' + i.replace('/', '\\') + '\n')
29 def gen_filelist_gtk(srcroot, subdir, dest):
30 vars = read_vars_from_AM(os.path.join(srcroot, 'gtk', 'Makefile.am'),
32 conds = {'USE_WIN32':True},
33 filters = ['gtkinclude_HEADERS',
34 'deprecatedinclude_HEADERS',
35 'gtk_base_c_sources'])
37 vars['gtk_other_src'] = 'gtkprintoperation-win32.c gtktypebuiltins.h gtktypebuiltins.c'
39 files = vars['gtkinclude_HEADERS'].split() + \
40 vars['deprecatedinclude_HEADERS'].split() + \
41 vars['gtk_base_c_sources'].split() + \
42 vars['gtk_other_src'].split()
44 sources = [i for i in files if not (i.endswith('private.h')) and i != 'gtktextdisplay.h' and i != 'gtktextlayout.h']
46 with open(dest, 'w') as d:
48 d.write(srcroot + '\\' + subdir + '\\' + i.replace('/', '\\') + '\n')
50 def read_vars_from_AM(path, vars = {}, conds = {}, filters = None):
52 path: path to the Makefile.am
53 vars: predefined variables
54 conds: condition variables for Makefile
55 filters: if None, all variables defined are returned,
56 otherwise, it is a list contains that variables should be returned
58 cur_vars = vars.copy()
59 RE_AM_VAR_REF = re.compile(r'\$\((\w+?)\)')
60 RE_AM_VAR = re.compile(r'^\s*(\w+)\s*=(.*)$')
61 RE_AM_INCLUDE = re.compile(r'^\s*include\s+(\w+)')
62 RE_AM_CONTINUING = re.compile(r'\\\s*$')
63 RE_AM_IF = re.compile(r'^\s*if\s+(\w+)')
64 RE_AM_ELSE = re.compile(r'^\s*else')
65 RE_AM_ENDIF = re.compile(r'^\s*endif')
67 return RE_AM_VAR_REF.sub(lambda x: cur_vars.get(x.group(1), ''), cont)
68 with open(path, 'r') as f:
69 contents = f.readlines()
70 #combine continuing lines
73 while i < len(contents):
75 if RE_AM_CONTINUING.search(line):
76 line = RE_AM_CONTINUING.sub('', line)
78 while j < len(contents) and RE_AM_CONTINUING.search(contents[j]):
79 line += RE_AM_CONTINUING.sub('', contents[j])
89 #include, var define, var evaluation
93 while i < len(ncont) - 1:
96 mo = RE_AM_IF.search(line)
99 skip = False if mo.group(1) in conds and conds[mo.group(1)] \
102 mo = RE_AM_ELSE.search(line)
106 mo = RE_AM_ENDIF.search(line)
112 mo = RE_AM_INCLUDE.search(line)
114 cur_vars.update(read_vars_from_AM(am_eval(mo.group(1)), cur_vars, conds, None))
116 mo = RE_AM_VAR.search(line)
118 cur_vars[mo.group(1)] = am_eval(mo.group(2).strip())
125 ret[i] = cur_vars.get(i, '')
135 gen_gdk_filelist(srcroot, subdir_gdk, 'gdk_list')
136 gen_filelist_gtk(srcroot, subdir_gtk, 'gtk_list')
139 if __name__ == '__main__':
140 sys.exit(main(sys.argv))