From eae9d1da36bc432b6396faac01d9dc86aba68aa3 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 20 Feb 2013 18:13:11 +0800 Subject: [PATCH] Enable the building of introspection files for Visual C++ builds This adds the utility Python/.bat scripts to the distribution for building the introspection files for ATK, and adds utility projects to build those files when needed. This makes use of Python Regex functionality so that we can read directly from the autotools files to create the file list that is necessary to build the introspection files, without needing to modify the autotools files to create the file list. --- build/win32/Makefile.am | 4 ++ build/win32/gen-file-list-atk.py | 112 +++++++++++++++++++++++++++++++++++++++ build/win32/gengir.bat | 6 ++- build/win32/vs10/Makefile.am | 3 +- build/win32/vs10/gengir.vcxproj | 104 ++++++++++++++++++++++++++++++++++++ build/win32/vs9/Makefile.am | 3 +- build/win32/vs9/gengir.vcproj | 77 +++++++++++++++++++++++++++ 7 files changed, 306 insertions(+), 3 deletions(-) create mode 100644 build/win32/gen-file-list-atk.py create mode 100644 build/win32/vs10/gengir.vcxproj create mode 100644 build/win32/vs9/gengir.vcproj diff --git a/build/win32/Makefile.am b/build/win32/Makefile.am index e013d16..4eff83d 100644 --- a/build/win32/Makefile.am +++ b/build/win32/Makefile.am @@ -1,3 +1,7 @@ SUBDIRS = \ vs9 \ vs10 + +EXTRA_DIST = \ + gengir.bat \ + gen-file-list-atk.py diff --git a/build/win32/gen-file-list-atk.py b/build/win32/gen-file-list-atk.py new file mode 100644 index 0000000..8729c90 --- /dev/null +++ b/build/win32/gen-file-list-atk.py @@ -0,0 +1,112 @@ +#!/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_atk_filelist(srcroot, subdir, dest): + vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'), + vars = {'top_builddir':'.'}, + conds = {'HAVE_INTROSPECTION':True}, + filters = ['introspection_sources', 'introspection_generated_sources']) + + files = vars['introspection_sources'].split() + \ + vars['introspection_generated_sources'].split() + + with open(dest, 'w') as d: + for i in files: + if (i.startswith('./atk/')): + i = i.replace('./atk/','') + 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 = 'atk' + gen_atk_filelist(srcroot, subdir, 'atk_list') + return 0 + +if __name__ == '__main__': + sys.exit(main(sys.argv)) diff --git a/build/win32/gengir.bat b/build/win32/gengir.bat index f85adc6..b843415 100644 --- a/build/win32/gengir.bat +++ b/build/win32/gengir.bat @@ -46,6 +46,9 @@ set LIB=%BINDIR%;%BASEDIR%\lib;%LIB% set PATH=%BINDIR%;%BASEDIR%\bin;%PATH%;%MINGWDIR%\bin set PYTHONPATH=%BASEDIR%\lib\gobject-introspection;%BINDIR% +echo Create filelist for generating ATK .gir's... +call python gen-file-list-atk.py + echo Setup .bat for generating ATK .gir's... rem ================================================================================================= @@ -81,8 +84,9 @@ rem Now generate the .gir's rem ======================= CALL atk_gir.bat -rem Clean up the .bat for generating the .gir files... +rem Clean up the .bat/filelist for generating the .gir files... del atk_gir.bat +del atk_list rem Now compile the generated .gir files %BASEDIR%\bin\g-ir-compiler --includedir=. --debug --verbose Atk-1.0.gir -o Atk-1.0.typelib diff --git a/build/win32/vs10/Makefile.am b/build/win32/vs10/Makefile.am index 217d7d2..ef3f2b4 100644 --- a/build/win32/vs10/Makefile.am +++ b/build/win32/vs10/Makefile.am @@ -6,4 +6,5 @@ EXTRA_DIST = \ atk.vcxprojin \ atk.vcxproj.filters \ atk.vcxproj.filtersin \ - install.vcxproj + install.vcxproj \ + gengir.vcxproj diff --git a/build/win32/vs10/gengir.vcxproj b/build/win32/vs10/gengir.vcxproj new file mode 100644 index 0000000..b0692fd --- /dev/null +++ b/build/win32/vs10/gengir.vcxproj @@ -0,0 +1,104 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2093D218-190E-4194-9421-3BA7CBF33B15} + gengir + Win32Proj + + + + Utility + MultiByte + true + + + Utility + MultiByte + + + Utility + MultiByte + true + + + Utility + MultiByte + + + + + + + + + + + + + + + + + + + + + + + $(GlibEtcInstallRoot)\ + + $(GlibEtcInstallRoot)\ + + $(GlibEtcInstallRoot)\ + + $(GlibEtcInstallRoot)\ + + + + + $(DoGenGir) + + + + + $(DoGenGir) + + + + + $(DoGenGir) + + + + + $(DoGenGir) + + + + + {86eacd59-f69f-4aad-854b-aa03d5447360} + false + + + + + + \ No newline at end of file diff --git a/build/win32/vs9/Makefile.am b/build/win32/vs9/Makefile.am index f215e4b..b707f2c 100644 --- a/build/win32/vs9/Makefile.am +++ b/build/win32/vs9/Makefile.am @@ -4,4 +4,5 @@ EXTRA_DIST = \ atk.vsprops \ atk.vcproj \ atk.vcprojin \ - install.vcproj + install.vcproj \ + gengir.vcproj diff --git a/build/win32/vs9/gengir.vcproj b/build/win32/vs9/gengir.vcproj new file mode 100644 index 0000000..5534388 --- /dev/null +++ b/build/win32/vs9/gengir.vcproj @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + -- 2.11.4.GIT