1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
#!/usr/bin/python
# vim: encoding=utf-8
# Generate the file lists for processing with g-ir-scanner
import os
import sys
import re
import string
import subprocess
import optparse
def gen_pango_filelist(srcroot, subdir, dest):
vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'),
vars = {},
conds = {},
filters = ['pango_introspection_files'])
files = vars['pango_introspection_files'].split()
sources = [i for i in files \
if not (i.endswith('-private.h')) \
and i != 'pango-color-table.h' ]
with open(dest, 'w') as d:
for i in sources:
d.write(srcroot + '\\' + subdir + '\\' + i.replace('/', '\\') + '\n')
def gen_pangoft_filelist(srcroot, subdir, dest):
vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'),
vars = {},
conds = {},
filters = ['pangoft2_introspection_files'])
files = vars['pangoft2_introspection_files'].split()
sources = [i for i in files \
if not (i.endswith('-private.h'))]
with open(dest, 'w') as d:
for i in sources:
d.write(srcroot + '\\' + subdir + '\\' + i.replace('/', '\\') + '\n')
def gen_pangocairo_filelist(srcroot, subdir, dest, is_fc_used):
vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'),
vars = {},
conds = {},
filters = ['libpangocairo_1_0_la_SOURCES', 'pangocairo_headers'])
vars['pangocairo_win32_introspection_files'] = 'pangocairo-win32font.c pangocairo-win32fontmap.c pangocairo-win32.h'
if is_fc_used == 1:
vars['pangocairo_ft2_introspection_files'] = 'pangocairo-fcfont.c pangocairo-fcfontmap.c pangocairo-fc.h'
else:
vars['pangocairo_ft2_introspection_files'] = ''
files = vars['libpangocairo_1_0_la_SOURCES'].split() + \
vars['pangocairo_win32_introspection_files'].split() + \
vars['pangocairo_ft2_introspection_files'].split() + \
vars['pangocairo_headers'].split()
sources = [i for i in files \
if not (i.endswith('-private.h'))]
with open(dest, 'w') as d:
for i in sources:
d.write(srcroot + '\\' + subdir + '\\' + i.replace('/', '\\') + '\n')
def read_vars_from_AM(path, vars = {}, conds = {}, filters = None):
'''
path: path to the Makefile.am
vars: predefined variables
conds: condition variables for Makefile
filters: if None, all variables defined are returned,
otherwise, it is a list contains that variables should be returned
'''
cur_vars = vars.copy()
RE_AM_VAR_REF = re.compile(r'\$\((\w+?)\)')
RE_AM_VAR = re.compile(r'^\s*(\w+)\s*=(.*)$')
RE_AM_INCLUDE = re.compile(r'^\s*include\s+(\w+)')
RE_AM_CONTINUING = re.compile(r'\\\s*$')
RE_AM_IF = re.compile(r'^\s*if\s+(\w+)')
RE_AM_ELSE = re.compile(r'^\s*else')
RE_AM_ENDIF = re.compile(r'^\s*endif')
def am_eval(cont):
return RE_AM_VAR_REF.sub(lambda x: cur_vars.get(x.group(1), ''), cont)
with open(path, 'r') as f:
contents = f.readlines()
#combine continuing lines
i = 0
ncont = []
while i < len(contents):
line = contents[i]
if RE_AM_CONTINUING.search(line):
line = RE_AM_CONTINUING.sub('', line)
j = i + 1
while j < len(contents) and RE_AM_CONTINUING.search(contents[j]):
line += RE_AM_CONTINUING.sub('', contents[j])
j += 1
else:
if j < len(contents):
line += contents[j]
i = j
else:
i += 1
ncont.append(line)
#include, var define, var evaluation
i = -1
skip = False
oldskip = []
while i < len(ncont) - 1:
i += 1
line = ncont[i]
mo = RE_AM_IF.search(line)
if mo:
oldskip.append(skip)
skip = False if mo.group(1) in conds and conds[mo.group(1)] \
else True
continue
mo = RE_AM_ELSE.search(line)
if mo:
skip = not skip
continue
mo = RE_AM_ENDIF.search(line)
if mo:
skip = oldskip.pop()
continue
if not skip:
mo = RE_AM_INCLUDE.search(line)
if mo:
cur_vars.update(read_vars_from_AM(am_eval(mo.group(1)), cur_vars, conds, None))
continue
mo = RE_AM_VAR.search(line)
if mo:
cur_vars[mo.group(1)] = am_eval(mo.group(2).strip())
continue
#filter:
if filters != None:
ret = {}
for i in filters:
ret[i] = cur_vars.get(i, '')
return ret
else:
return cur_vars
def main(argv):
srcroot = '..\\..'
subdir = 'pango'
gen_pango_filelist(srcroot, subdir, 'pango_list')
gen_pangoft_filelist(srcroot, subdir, 'pangoft_list')
gen_pangocairo_filelist(srcroot, subdir, 'pangocairo_list', 0)
gen_pangocairo_filelist(srcroot, subdir, 'pangocairoft_list', 1)
return 0
if __name__ == '__main__':
sys.exit(main(sys.argv))
|