From 44ad377d70724fc85be5965a9ee85aa58c9b5c04 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Wed, 6 Mar 2013 12:48:31 +0800 Subject: Visual Studio builds: Support building introspection files Add Windows .bat and Python utility script to call g-ir-scanner to build the introspection files for Pango/MSVC builds. This will read from pango/Makefile.am to determine the source and header files to process using Python REGEX capabilities, so the autotools files won't have to be updated except to distribute the necessary files under build/win32. Also add utility Visual Studio 2008/2010 projects to call the Windows .bat to create the introspection files. https://bugzilla.gnome.org/show_bug.cgi?id=692255 --- build/win32/Makefile.am | 5 +- build/win32/gen-file-list-pango.py | 154 +++++++++++++++++++++++++++++++++ build/win32/gengir_pango.bat | 169 +++++++++++++++++++++++++++++++++++++ build/win32/vs10/Makefile.am | 49 +++++------ build/win32/vs10/gengir.vcxproj | 108 ++++++++++++++++++++++++ build/win32/vs9/Makefile.am | 27 +++--- build/win32/vs9/gengir.vcproj | 77 +++++++++++++++++ 7 files changed, 551 insertions(+), 38 deletions(-) create mode 100644 build/win32/gen-file-list-pango.py create mode 100644 build/win32/gengir_pango.bat 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 a0b2d363..0823c592 100644 --- a/build/win32/Makefile.am +++ b/build/win32/Makefile.am @@ -1,5 +1,8 @@ SUBDIRS = vs9 vs10 -EXTRA_DIST = unistd.h +EXTRA_DIST = \ + unistd.h \ + gen-file-list-pango.py \ + gengir_pango.bat -include $(top_srcdir)/git.mk diff --git a/build/win32/gen-file-list-pango.py b/build/win32/gen-file-list-pango.py new file mode 100644 index 00000000..2515353b --- /dev/null +++ b/build/win32/gen-file-list-pango.py @@ -0,0 +1,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)) diff --git a/build/win32/gengir_pango.bat b/build/win32/gengir_pango.bat new file mode 100644 index 00000000..f1ca0efa --- /dev/null +++ b/build/win32/gengir_pango.bat @@ -0,0 +1,169 @@ +@echo off + +setlocal EnableDelayedExpansion + +rem Needed environmental variables: +rem PLAT: Windows platform-Win32 (i.e. x86) or x64 (i.e. x86-64) +rem CONF: Configuration Type, Release or Debug +rem VSVER: Visual C++ version used [9, 10 or 11] +rem BASEDIR: Where the dependent libraries/headers are located +rem PKG_CONFIG_PATH: Where the GLib and its dependent pkg-config .pc files can be found +rem MINGWDIR: Installation path of MINGW GCC, so gcc.exe can be found in %MINGWDIR%\bin. + +rem Note that the Python executable/installation and all the runtime dependencies of the +rem library/libraries need to be in your PATH or %BASEBIN%\bin. + +rem Check the environemental variables... +if /i "%PLAT%" == "Win32" goto PLAT_OK +if /i "%PLAT%" == "x64" goto PLAT_OK +if /i "%PLAT%" == "x86" ( + set PLAT=Win32 + goto PLAT_OK +) +if /i "%PLAT%" == "x86-64" ( + set PLAT=x64 + goto PLAT_OK +) +goto ERR_PLAT + +:PLAT_OK +if "%VSVER%" == "9" goto VSVER_OK +if "%VSVER%" == "10" goto VSVER_OK +if "%VSVER%" == "11" goto VSVER_OK +goto ERR_VSVER +:VSVER_OK +if /i "%CONF%" == "Release" goto CONF_OK +if /i "%CONF%" == "Debug" goto CONF_OK +goto ERR_CONF +:CONF_OK +if "%BASEDIR%" == "" goto ERR_BASEDIR +if not exist %BASEDIR% goto ERR_BASEDIR + +if "%PKG_CONFIG_PATH%" == "" goto ERR_PKGCONFIG +if not exist %PKG_CONFIG_PATH%\gobject-2.0.pc goto ERR_PKGCONFIG + +if "%MINGWDIR%" == "" goto ERR_MINGWDIR +if not exist %MINGWDIR%\bin\gcc.exe goto ERR_MINGWDIR + +set CC=cl +set BINDIR=%CD%\vs%VSVER%\%CONF%\%PLAT%\bin +set INCLUDE=%BASEDIR%\include\glib-2.0;%BASEDIR%\lib\glib-2.0\include;%INCLUDE% +set LIB=%BINDIR%;%BASEDIR%\lib;%LIB% +set PATH=%BINDIR%;%BASEDIR%\bin;%PATH%;%MINGWDIR%\bin +set PYTHONPATH=%BASEDIR%\lib\gobject-introspection;%BINDIR% + +echo Setup .bat for generating Pango .gir's... + +rem =============================================================================== +rem Begin setup of pango_gir.bat to create Pango-1.0.gir +rem (The ^^ is necessary to span the command to multiple lines on Windows cmd.exe!) +rem =============================================================================== + +echo python gen-file-list-pango.py> pango_gir.bat +echo echo Generating Pango-1.0.gir...>> pango_gir.bat +echo @echo off>> pango_gir.bat +echo.>> pango_gir.bat +rem ================================================================= +rem Setup the command line flags to g-ir-scanner for Pango-1.0.gir... +rem ================================================================= +echo python %BASEDIR%\bin\g-ir-scanner --verbose -I..\.. ^^>> pango_gir.bat +echo -I%BASEDIR%\include\glib-2.0 -I%BASEDIR%\lib\glib-2.0\include ^^>> pango_gir.bat +echo --namespace=Pango --nsversion=1.0 ^^>> pango_gir.bat +echo --include=GObject-2.0 --include=cairo-1.0 ^^>> pango_gir.bat +echo --no-libtool --pkg=gobject-2.0 --pkg=cairo --pkg=glib-2.0 --library=pango-1-vs%VSVER% ^^>> pango_gir.bat +echo --reparse-validate --add-include-path=%BASEDIR%\share\gir-1.0 --add-include-path=. ^^>> pango_gir.bat +echo --pkg-export pango --warn-all --c-include "pango/pango.h" ^^>> pango_gir.bat +echo -I..\.. -DG_LOG_DOMAIN=\"Pango\" -DPANGO_ENABLE_BACKEND -DPANGO_ENABLE_ENGINE ^^>> pango_gir.bat +echo -DSYSCONFDIR=\"/dummy/etc\" -DLIBDIR=\"/dummy/lib\" ^^>> pango_gir.bat +echo --filelist=pango_list ^^>> pango_gir.bat +echo -o Pango-1.0.gir>> pango_gir.bat +echo.>> pango_gir.bat + +echo Completed setup of .bat for generating Pango-1.0.gir. +echo.>> pango_gir.bat + +rem ===================================================== +rem Finish setup of pango_gir.bat to create Pango-1.0.gir +rem ===================================================== + +rem ========================================================= +rem Note that the .gir for PangoFT2 is not generated here +rem as FontConfig is not a concept originally meant for Win32 +rem ========================================================= + +rem =============================================================================== +rem Begin setup of pango_gir.bat to create PangoCairo-1.0.gir +rem (The ^^ is necessary to span the command to multiple lines on Windows cmd.exe!) +rem =============================================================================== + +echo echo Generating PangoCairo-1.0.gir...>> pango_gir.bat +echo.>> pango_gir.bat + +rem ====================================================================== +rem Setup the command line flags to g-ir-scanner for PangoCairo-1.0.gir... +rem ====================================================================== + +echo python %BASEDIR%\bin\g-ir-scanner --verbose -I..\.. ^^>> pango_gir.bat +echo -I%BASEDIR%\include\glib-2.0 -I%BASEDIR%\lib\glib-2.0\include -I%BASEDIR%\include ^^>> pango_gir.bat +echo --namespace=PangoCairo --nsversion=1.0 ^^>> pango_gir.bat +echo --include=GObject-2.0 --include=cairo-1.0 ^^>> pango_gir.bat +echo --no-libtool --pkg=gobject-2.0 --pkg=cairo --library=pangocairo-1-vs%VSVER% --library=pango-1-vs%VSVER% ^^>> pango_gir.bat +echo --reparse-validate --add-include-path=%BASEDIR%\share\gir-1.0 --add-include-path=. ^^>> pango_gir.bat +echo --pkg-export pangocairo --warn-all --include-uninstalled=./Pango-1.0.gir ^^>> pango_gir.bat +echo --c-include "pango/pangocairo.h" ^^>> pango_gir.bat +echo -I..\.. -DG_LOG_DOMAIN=\"Pango\" -DPANGO_ENABLE_BACKEND ^^>> pango_gir.bat +echo -DPANGO_ENABLE_ENGINE -DSYSCONFDIR=\"/dummy/etc\" -DLIBDIR=\"/dummy/lib\" ^^>> pango_gir.bat +echo --filelist=pangocairo_list ^^>> pango_gir.bat +echo -o PangoCairo-1.0.gir>> pango_gir.bat +echo.>> pango_gir.bat + +rem ========================================================== +rem Finish setup of pango_gir.bat to create PangoCairo-1.0.gir +rem ========================================================== + +rem ======================= +rem Now generate the .gir's +rem ======================= +CALL pango_gir.bat + +rem Clean up the .bat and filelists for generating the .gir files... +del pango_gir.bat +del pango_list +del pangoft_list +del pangocairo_list +del pangocairoft_list + +rem Now compile the generated .gir files +%BASEDIR%\bin\g-ir-compiler --includedir=. --debug --verbose Pango-1.0.gir -o Pango-1.0.typelib +%BASEDIR%\bin\g-ir-compiler --includedir=. --debug --verbose PangoCairo-1.0.gir -o PangoCairo-1.0.typelib + +rem Copy the generated .girs and .typelibs to their appropriate places + +mkdir ..\..\build\win32\vs%VSVER%\%CONF%\%PLAT%\share\gir-1.0 +move /y *.gir %BASEDIR%\share\gir-1.0\ + +mkdir ..\..\build\win32\vs%VSVER%\%CONF%\%PLAT%\lib\girepository-1.0 +move /y *.typelib %BASEDIR%\lib\girepository-1.0\ + +goto DONE + +:ERR_PLAT +echo You need to specify a valid Platform [set PLAT=Win32 or PLAT=x64] +goto DONE +:ERR_VSVER +echo You need to specify your Visual Studio version [set VSVER=9 or VSVER=10 or VSVER=11] +goto DONE +:ERR_CONF +echo You need to specify a valid Configuration [set CONF=Release or CONF=Debug] +goto DONE +:ERR_BASEDIR +echo You need to specify a valid BASEDIR. +goto DONE +:ERR_PKGCONFIG +echo You need to specify a valid PKG_CONFIG_PATH +goto DONE +:ERR_MINGWDIR +echo You need to specify a valid MINGWDIR, where a valid gcc installation can be found. +goto DONE +:DONE + diff --git a/build/win32/vs10/Makefile.am b/build/win32/vs10/Makefile.am index b52f9f19..8078d91b 100644 --- a/build/win32/vs10/Makefile.am +++ b/build/win32/vs10/Makefile.am @@ -1,27 +1,28 @@ -EXTRA_DIST = \ - pango.sln \ - pango_fc.sln \ - pango.propsin \ - pango.props \ - pango.vcxproj \ - pango.vcxproj.filters \ - pango.vcxprojin \ - pango.vcxproj.filtersin \ - pangoft2.vcxproj \ - pangoft2.vcxproj.filters \ - pangoft2.vcxprojin \ - pangoft2.vcxproj.filtersin \ - pangowin32.vcxproj \ - pangowin32.vcxproj.filters \ - pangocairo.vcxproj \ - pangocairo.vcxproj.filters \ - pangocairo.vcxprojin \ - pangocairo.vcxproj.filtersin \ - pangocairo_fc.vcxproj \ - pangocairo_fc.vcxproj.filters \ - pangocairo_fc.vcxprojin \ - pangocairo_fc.vcxproj.filtersin \ - install.vcxproj \ +EXTRA_DIST = \ + pango.sln \ + pango_fc.sln \ + pango.propsin \ + pango.props \ + pango.vcxproj \ + pango.vcxproj.filters \ + pango.vcxprojin \ + pango.vcxproj.filtersin \ + pangoft2.vcxproj \ + pangoft2.vcxproj.filters \ + pangoft2.vcxprojin \ + pangoft2.vcxproj.filtersin \ + pangowin32.vcxproj \ + pangowin32.vcxproj.filters \ + pangocairo.vcxproj \ + pangocairo.vcxproj.filters \ + pangocairo.vcxprojin \ + pangocairo.vcxproj.filtersin \ + pangocairo_fc.vcxproj \ + pangocairo_fc.vcxproj.filters \ + pangocairo_fc.vcxprojin \ + pangocairo_fc.vcxproj.filtersin \ + install.vcxproj \ + gengir.vcxproj \ README.txt pango.props: $(top_srcdir)/build/win32/vs10/pango.propsin pango.vs10.headers diff --git a/build/win32/vs10/gengir.vcxproj b/build/win32/vs10/gengir.vcxproj new file mode 100644 index 00000000..bbb37b2e --- /dev/null +++ b/build/win32/vs10/gengir.vcxproj @@ -0,0 +1,108 @@ + + + + + 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) + + + + + {68cc80b9-7225-4fb5-b9ab-9c1df50b6c72} + false + + + {68cc80b9-7225-4fb5-b9ab-9c1df50b6c76} + false + + + + + + \ No newline at end of file diff --git a/build/win32/vs9/Makefile.am b/build/win32/vs9/Makefile.am index 93d304cb..46a0ea48 100644 --- a/build/win32/vs9/Makefile.am +++ b/build/win32/vs9/Makefile.am @@ -1,17 +1,18 @@ -EXTRA_DIST = \ - pango.sln \ - pango_fc.sln \ - pango.vspropsin \ - pango.vsprops \ - pango.vcprojin \ - pango.vcproj \ - pangoft2.vcprojin \ - pangoft2.vcproj \ - pangocairo.vcprojin \ - pangocairo.vcproj \ - pangowin32.vcproj \ +EXTRA_DIST = \ + pango.sln \ + pango_fc.sln \ + pango.vspropsin \ + pango.vsprops \ + pango.vcprojin \ + pango.vcproj \ + pangoft2.vcprojin \ + pangoft2.vcproj \ + pangocairo.vcprojin \ + pangocairo.vcproj \ + pangowin32.vcproj \ install.vcproj \ - stdint.h \ + stdint.h \ + gengir.vcproj \ README.txt pango.vsprops: $(top_srcdir)/build/win32/vs9/pango.vspropsin pango.vs9.headers diff --git a/build/win32/vs9/gengir.vcproj b/build/win32/vs9/gengir.vcproj new file mode 100644 index 00000000..f45a91df --- /dev/null +++ b/build/win32/vs9/gengir.vcproj @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.1