4 #this script is only intended for building from git, not for building from the released tarball, which already includes all necessary files
12 from process_in_win32 import get_version, process_in, get_srcroot
14 def process_include(src, dest, includes):
15 RE_INCLUDE = re.compile(r'^\s*#include\s+"(.*)"')
16 with open(src, 'r') as s:
17 with open(dest, 'w') as d:
19 mo = RE_INCLUDE.search(i)
23 #print "searching in ", j
24 if mo.group(1) in os.listdir(j):
25 target = os.path.join(j, mo.group(1))
28 raise Exception("Couldn't fine include file %s" % mo.group(1))
30 with open(target, 'r') as t:
31 for inc in t.readlines():
36 def generate_libgio_sourcefiles(srcroot, dest, stype):
37 vars = read_vars_from_AM(os.path.join(srcroot, 'gio', 'Makefile.am'),
38 vars = {'top_srcdir': srcroot},
39 conds = {'OS_WIN32': True},
40 filters = ['libgio_2_0_la_SOURCES', 'win32_more_sources_for_vcproj'])
42 files = vars['libgio_2_0_la_SOURCES'].split() + \
43 vars['win32_more_sources_for_vcproj'].split()
45 sources = [i for i in files \
46 if i != 'gdesktopappinfo.c' and \
47 not (i.startswith('gunix') and i.endswith('.c')) \
48 and i.endswith('.c') ]
50 with open(dest, 'w') as d:
52 d.write('\t\t\t<File RelativePath="..\\..\\..\\gio\\' + i.replace('/', '\\') + '"/>\n')
54 with open(dest, 'w') as d:
56 d.write('\t\t\t<ClCompile Include="..\\..\\..\\gio\\' + i.replace('/', '\\') + '"/>\n')
58 with open(dest, 'w') as d:
60 d.write('\t\t\t<ClCompile Include="..\\..\\..\\gio\\' + i.replace('/', '\\') + '"><Filter>Source Files</Filter></ClCompile>\n')
62 raise Exception("Must specify project type (9, 10 or 10f)")
64 def generate_libgio_enumtypes(srcroot, perl):
65 vars = read_vars_from_AM(os.path.join(srcroot, 'gio', 'Makefile.am'),
66 vars = {'top_srcdir': srcroot},
67 conds = {'OS_WIN32': True},
68 filters = ['gio_headers'])
70 os.chdir(os.path.join(srcroot, 'gio'))
71 for suffix in ['.c', '.h']:
72 cmd = [perl, os.path.join(srcroot, 'gobject', 'glib-mkenums'),
73 '--template', 'gioenumtypes' + suffix + '.template'] + vars['gio_headers'].split()
74 with open('gioenumtypes' + suffix, 'w') as d:
75 subprocess.Popen(cmd, stdout = d).communicate()
77 def generate_libglib_sourcefiles(srcroot, dest, stype):
78 vars = read_vars_from_AM(os.path.join(srcroot, 'glib', 'Makefile.am'),
79 vars = {'top_srcdir': srcroot},
80 conds = {'OS_WIN32': True,
81 'ENABLE_REGEX': True},
82 filters = ['libglib_2_0_la_SOURCES'])
84 files = vars['libglib_2_0_la_SOURCES'].split()
86 sources = [i for i in files \
87 if not (i.endswith('-gcc.c') or i.endswith('-unix.c')) \
88 and i.endswith('.c') ]
90 with open(dest, 'w') as d:
92 d.write('\t\t\t<File RelativePath="..\\..\\..\\glib\\' + i.replace('/', '\\') + '"/>\n')
94 with open(dest, 'w') as d:
96 d.write('\t\t\t<ClCompile Include="..\\..\\..\\glib\\' + i.replace('/', '\\') + '"/>\n')
98 with open(dest, 'w') as d:
100 d.write('\t\t\t<ClCompile Include="..\\..\\..\\glib\\' + i.replace('/', '\\') + '"><Filter>Source Files</Filter></ClCompile>\n')
102 raise Exception("Must specify project type (9, 10 or 10f)")
104 def generate_libgobject_sourcefiles(srcroot, dest, stype):
105 vars = read_vars_from_AM(os.path.join(srcroot, 'gobject', 'Makefile.am'),
106 vars = {'top_srcdir': srcroot},
107 conds = {'OS_WIN32': True},
108 filters = ['libgobject_2_0_la_SOURCES'])
110 files = vars['libgobject_2_0_la_SOURCES'].split()
112 sources = [i for i in files if i.endswith('.c') ]
114 with open(dest, 'w') as d:
116 d.write('\t\t\t<File RelativePath="..\\..\\..\\gobject\\' + i.replace('/', '\\') + '"/>\n')
118 with open(dest, 'w') as d:
120 d.write('\t\t\t<ClCompile Include="..\\..\\..\\gobject\\' + i.replace('/', '\\') + '"/>\n')
122 with open(dest, 'w') as d:
124 d.write('\t\t\t<ClCompile Include="..\\..\\..\\gobject\\' + i.replace('/', '\\') + '"><Filter>Source Files</Filter></ClCompile>\n')
126 raise Exception("Must specify project type (9, 10 or 10f)")
128 def read_vars_from_AM(path, vars = {}, conds = {}, filters = None):
130 path: path to the Makefile.am
131 vars: predefined variables
132 conds: condition variables for Makefile
133 filters: if None, all variables defined are returned,
134 otherwise, it is a list contains that variables should be returned
136 cur_vars = vars.copy()
137 RE_AM_VAR_REF = re.compile(r'\$\((\w+?)\)')
138 RE_AM_VAR = re.compile(r'^\s*(\w+)\s*=(.*)$')
139 RE_AM_INCLUDE = re.compile(r'^\s*include\s+(\w+)')
140 RE_AM_CONTINUING = re.compile(r'\\\s*$')
141 RE_AM_IF = re.compile(r'^\s*if\s+(\w+)')
142 RE_AM_ELSE = re.compile(r'^\s*else')
143 RE_AM_ENDIF = re.compile(r'^\s*endif')
145 return RE_AM_VAR_REF.sub(lambda x: cur_vars.get(x.group(1), ''), cont)
146 with open(path, 'r') as f:
147 contents = f.readlines()
148 #combine continuing lines
151 while i < len(contents):
153 if RE_AM_CONTINUING.search(line):
154 line = RE_AM_CONTINUING.sub('', line)
156 while j < len(contents) and RE_AM_CONTINUING.search(contents[j]):
157 line += RE_AM_CONTINUING.sub('', contents[j])
160 if j < len(contents):
167 #include, var define, var evaluation
171 while i < len(ncont) - 1:
174 mo = RE_AM_IF.search(line)
177 skip = False if mo.group(1) in conds and conds[mo.group(1)] \
180 mo = RE_AM_ELSE.search(line)
184 mo = RE_AM_ENDIF.search(line)
189 mo = RE_AM_INCLUDE.search(line)
191 cur_vars.update(read_vars_from_AM(am_eval(mo.group(1)), cur_vars, conds, None))
193 mo = RE_AM_VAR.search(line)
195 cur_vars[mo.group(1)] = am_eval(mo.group(2).strip())
202 ret[i] = cur_vars.get(i, '')
208 parser = optparse.OptionParser()
209 parser.add_option('-p', '--perl', dest='perl', metavar='PATH', default='C:\\Perl\\bin\\perl.exe', action='store', help='path to the perl interpretor (default: C:\\Perl\\bin\\perl.exe)')
210 opt, args = parser.parse_args(argv)
211 srcroot = get_srcroot()
212 #print 'srcroot', srcroot
213 ver = get_version(srcroot)
215 config_vars = ver.copy()
216 config_vars['GETTEXT_PACKAGE'] = 'Glib'
217 process_in(os.path.join(srcroot, 'config.h.win32.in'),
218 os.path.join(srcroot, 'config.h'),
220 glibconfig_vars = ver.copy()
221 glibconfig_vars['GLIB_WIN32_STATIC_COMPILATION_DEFINE'] = ''
222 process_in(os.path.join(srcroot, 'glib', 'glibconfig.h.win32.in'),
223 os.path.join(srcroot, 'glib', 'glibconfig.h'),
226 for submodule in ['glib', 'gobject', 'gthread', 'gmodule', 'gio']:
227 process_in(os.path.join(srcroot, submodule, submodule + '.rc.in'),
228 os.path.join(srcroot, submodule, submodule + '.rc'),
231 #------------ submodule gobject -------------------
232 generate_libglib_sourcefiles(srcroot,
233 os.path.join(srcroot, 'build', 'win32', 'libglib.sourcefiles'), '9')
234 generate_libglib_sourcefiles(srcroot,
235 os.path.join(srcroot, 'build', 'win32', 'libglib.vs10.sourcefiles'), '10')
236 generate_libglib_sourcefiles(srcroot,
237 os.path.join(srcroot, 'build', 'win32', 'libglib.vs10.sourcefiles.filters'), '10f')
238 process_include(os.path.join(srcroot, 'build', 'win32', 'vs9', 'glib.vcprojin'),
239 os.path.join(srcroot, 'build', 'win32', 'vs9', 'glib.vcproj'),
240 includes = [os.path.join(srcroot, 'build', 'win32')])
241 process_include(os.path.join(srcroot, 'build', 'win32', 'vs10', 'glib.vcxprojin'),
242 os.path.join(srcroot, 'build', 'win32', 'vs10', 'glib.vcxproj'),
243 includes = [os.path.join(srcroot, 'build', 'win32')])
244 process_include(os.path.join(srcroot, 'build', 'win32', 'vs10', 'glib.vcxproj.filtersin'),
245 os.path.join(srcroot, 'build', 'win32', 'vs10', 'glib.vcxproj.filters'),
246 includes = [os.path.join(srcroot, 'build', 'win32')])
247 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libglib.sourcefiles'))
248 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libglib.vs10.sourcefiles'))
249 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libglib.vs10.sourcefiles.filters'))
250 with open(os.path.join(srcroot, 'glib', 'gspawn-win32-helper-console.c'), 'w') as c:
251 c.write('#define HELPER_CONSOLE\n')
252 c.write('#include "gspawn-win32-helper.c"\n')
253 with open(os.path.join(srcroot, 'glib', 'gspawn-win64-helper-console.c'), 'w') as c:
254 c.write('#define HELPER_CONSOLE\n')
255 c.write('#include "gspawn-win32-helper.c"\n')
256 with open(os.path.join(srcroot, 'glib', 'gspawn-win64-helper.c'), 'w') as c:
257 c.write('#include "gspawn-win32-helper.c"\n')
258 #------------ end of submodule glib -------------------
260 #------------ submodule gobject -------------------
261 mkenums_vars = ver.copy()
262 mkenums_vars.update({'PERL_PATH': opt.perl})
263 process_in(os.path.join(srcroot, 'gobject', 'glib-mkenums.in'),
264 os.path.join(srcroot, 'gobject', 'glib-mkenums'),
269 os.chdir(os.path.join(srcroot, 'gobject'))
270 with open(os.path.join(srcroot, 'gobject', 'gmarshal.strings'), 'w') as d:
271 with open(os.path.join(srcroot, 'gobject', 'gmarshal.list'), 'r') as s:
273 if i[0] not in string.ascii_uppercase: #^[A-Z]
275 line = '"g_cclosure_marshal_' # s/^/"g_cclosure_marshal_/
278 line += '__' # s/:/__
281 elif c not in '\r\n':
283 d.write(line + '",\n')
284 #subprocess.Popen([opt.perl, 'marshal-genstrings.pl'], stdout=d).communicate()
287 generate_libgobject_sourcefiles(srcroot,
288 os.path.join(srcroot, 'build', 'win32', 'libgobject.sourcefiles'), '9')
289 generate_libgobject_sourcefiles(srcroot,
290 os.path.join(srcroot, 'build', 'win32', 'libgobject.vs10.sourcefiles'), '10')
291 generate_libgobject_sourcefiles(srcroot,
292 os.path.join(srcroot, 'build', 'win32', 'libgobject.vs10.sourcefiles.filters'), '10f')
293 process_include(os.path.join(srcroot, 'build', 'win32', 'vs9', 'gobject.vcprojin'),
294 os.path.join(srcroot, 'build', 'win32', 'vs9', 'gobject.vcproj'),
295 includes = [os.path.join(srcroot, 'build', 'win32')])
296 process_include(os.path.join(srcroot, 'build', 'win32', 'vs10', 'gobject.vcxprojin'),
297 os.path.join(srcroot, 'build', 'win32', 'vs10', 'gobject.vcxproj'),
298 includes = [os.path.join(srcroot, 'build', 'win32')])
299 process_include(os.path.join(srcroot, 'build', 'win32', 'vs10', 'gobject.vcxproj.filtersin'),
300 os.path.join(srcroot, 'build', 'win32', 'vs10', 'gobject.vcxproj.filters'),
301 includes = [os.path.join(srcroot, 'build', 'win32')])
302 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libgobject.sourcefiles'))
303 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libgobject.vs10.sourcefiles'))
304 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libgobject.vs10.sourcefiles.filters'))
305 #------------ end of submodule gobject -------------------
307 #------------ submodule gio -------------------
308 #depends on glib-mkenums
309 generate_libgio_sourcefiles(srcroot,
310 os.path.join(srcroot, 'build', 'win32', 'libgio.sourcefiles'), '9')
311 generate_libgio_sourcefiles(srcroot,
312 os.path.join(srcroot, 'build', 'win32', 'libgio.vs10.sourcefiles'), '10')
313 generate_libgio_sourcefiles(srcroot,
314 os.path.join(srcroot, 'build', 'win32', 'libgio.vs10.sourcefiles.filters'), '10f')
315 process_include(os.path.join(srcroot, 'build', 'win32', 'vs9', 'gio.vcprojin'),
316 os.path.join(srcroot, 'build', 'win32', 'vs9', 'gio.vcproj'),
317 includes = [os.path.join(srcroot, 'build', 'win32')])
318 process_include(os.path.join(srcroot, 'build', 'win32', 'vs10', 'gio.vcxprojin'),
319 os.path.join(srcroot, 'build', 'win32', 'vs10', 'gio.vcxproj'),
320 includes = [os.path.join(srcroot, 'build', 'win32')])
321 process_include(os.path.join(srcroot, 'build', 'win32', 'vs10', 'gio.vcxproj.filtersin'),
322 os.path.join(srcroot, 'build', 'win32', 'vs10', 'gio.vcxproj.filters'),
323 includes = [os.path.join(srcroot, 'build', 'win32')])
324 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libgio.sourcefiles'))
325 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libgio.vs10.sourcefiles'))
326 os.unlink(os.path.join(srcroot, 'build', 'win32', 'libgio.vs10.sourcefiles.filters'))
327 generate_libgio_enumtypes(srcroot, opt.perl)
328 #------------ end of submodule gio -------------------
330 #------------ submodule gmodule -------------------
331 #------------ end of submodule gmodule -------------------
334 if __name__ == '__main__':
335 sys.exit(main(sys.argv))