[json-glib] Visual Studio Builds: Support building introspection files
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [json-glib] Visual Studio Builds: Support building introspection files
- Date: Thu, 7 Mar 2013 09:30:19 +0000 (UTC)
commit 522a8b40915531ce6fe3075f5f83e6aea984e019
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Thu Mar 7 17:28:12 2013 +0800
Visual Studio Builds: Support building introspection files
Add a Windows .bat and a python script to create a file list of headers
and sources to be processed by g-ir-scanner, and to call g-ir-scanner to
build the introspection files for JSON-GLib. This will enable one to build
the introspection files with Visual Studio builds without needing a
BASH-style shell like MSYS.
Also add utility Visual Studio projects that can be used to call the
Windows .bat to build the introspection files, for convenience
build/win32/Makefile.am | 6 +-
build/win32/gen-file-list-jsonglib.py | 114 ++++++++++++++++++++++++++++
build/win32/gengir_jsonglib.bat | 132 +++++++++++++++++++++++++++++++++
build/win32/vs10/Makefile.am | 1 +
build/win32/vs10/gengir.vcxproj | 104 ++++++++++++++++++++++++++
build/win32/vs9/Makefile.am | 1 +
build/win32/vs9/gengir.vcproj | 77 +++++++++++++++++++
7 files changed, 434 insertions(+), 1 deletions(-)
---
diff --git a/build/win32/Makefile.am b/build/win32/Makefile.am
index 6f2c047..75f9332 100644
--- a/build/win32/Makefile.am
+++ b/build/win32/Makefile.am
@@ -1,3 +1,7 @@
SUBDIRS = vs9 vs10
-EXTRA_DIST = config.h.win32.in config.h.win32
+EXTRA_DIST = \
+ config.h.win32.in \
+ config.h.win32 \
+ gen-file-list-jsonglib.py \
+ gengir_jsonglib.bat
diff --git a/build/win32/gen-file-list-jsonglib.py b/build/win32/gen-file-list-jsonglib.py
new file mode 100644
index 0000000..eed85f3
--- /dev/null
+++ b/build/win32/gen-file-list-jsonglib.py
@@ -0,0 +1,114 @@
+#!/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_jsonglib_filelist(srcroot, subdir, dest):
+ vars = read_vars_from_AM(os.path.join(srcroot, subdir, 'Makefile.am'),
+ vars = {'srcdir':'../json-glib',
+ 'top_srcdir':'..'},
+ conds = {'HAVE_INTROSPECTION':True},
+ filters = ['Json_1_0_gir_FILES'])
+
+ files = vars['Json_1_0_gir_FILES'].split()
+ if (srcroot == '..\\..'):
+ relative_srcdir = '..'
+ else:
+ relative_srcdir = 'srcroot'
+
+ with open(dest, 'w') as d:
+ for i in files:
+ d.write(relative_srcdir + '\\' + 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 = 'json-glib'
+ gen_jsonglib_filelist(srcroot, subdir, 'json_list')
+ return 0
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
diff --git a/build/win32/gengir_jsonglib.bat b/build/win32/gengir_jsonglib.bat
new file mode 100644
index 0000000..ec70dc2
--- /dev/null
+++ b/build/win32/gengir_jsonglib.bat
@@ -0,0 +1,132 @@
+ 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 and filelist for generating Json-1.0.gir...
+
+call python gen-file-list-jsonglib.py
+
+rem ===============================================================================
+rem Begin setup of json_gir.bat to create Json-1.0.gir
+rem (The ^^ is necessary to span the command to multiple lines on Windows cmd.exe!)
+rem ===============================================================================
+
+echo echo Generating Json-1.0.gir...> json_gir.bat
+echo @echo off>> json_gir.bat
+echo.>> json_gir.bat
+
+echo copy /b %BINDIR%\json-glib-1.0.lib %BINDIR%\json-1.0.lib>> json_gir.bat
+echo.>> json_gir.bat
+rem ================================================================
+rem Setup the command line flags to g-ir-scanner for Json-1.0.gir...
+rem ================================================================
+echo python %BASEDIR%\bin\g-ir-scanner --verbose -I..\.. ^^>> json_gir.bat
+echo -I%BASEDIR%\include\glib-2.0 -I%BASEDIR%\lib\glib-2.0\include ^^>> json_gir.bat
+echo --namespace=Json --nsversion=1.0 ^^>> json_gir.bat
+echo --include=GObject-2.0 --include=Gio-2.0 ^^>> json_gir.bat
+echo --no-libtool --library=json-glib-1-vs%VSVER% ^^>> json_gir.bat
+echo --reparse-validate --add-include-path=%BASEDIR%\share\gir-1.0 --add-include-path=. ^^>> json_gir.bat
+echo --warn-all --pkg-export json-glib-1.0 --c-include "json-glib/json-glib.h" ^^>> json_gir.bat
+echo -I..\.. -DJSON_COMPILATION=1 -DG_LOG_DOMAIN=\"Json\" ^^>> json_gir.bat
+echo --filelist=json_list ^^>> json_gir.bat
+echo -o Json-1.0.gir>> json_gir.bat
+echo.>> json_gir.bat
+
+echo del %BINDIR%\json-1.0.lib>> json_gir.bat
+echo.>> json_gir.bat
+
+echo Completed setup of .bat for generating Json-1.0.gir.
+echo.>> json_gir.bat
+
+rem =======================
+rem Now generate the .gir's
+rem =======================
+CALL json_gir.bat
+
+rem Clean up the .bat and filelist for generating the .gir files...
+del json_gir.bat
+del json_list
+
+rem Now compile the generated .gir files
+%BASEDIR%\bin\g-ir-compiler --includedir=. --debug --verbose Json-1.0.gir -o Json-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 72bd7b0..4c287c8 100644
--- a/build/win32/vs10/Makefile.am
+++ b/build/win32/vs10/Makefile.am
@@ -35,4 +35,5 @@ EXTRA_DIST = \
serialize-simple.vcxproj \
serialize-simple.vcxproj.filters \
README.txt \
+ gengir.vcxproj \
$(NULL)
diff --git a/build/win32/vs10/gengir.vcxproj b/build/win32/vs10/gengir.vcxproj
new file mode 100644
index 0000000..12c32a2
--- /dev/null
+++ b/build/win32/vs10/gengir.vcxproj
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectGuid>{2093D218-190E-4194-9421-3BA7CBF33B15}</ProjectGuid>
+ <RootNamespace>gengir</RootNamespace>
+ <Keyword>Win32Proj</Keyword>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>Utility</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>Utility</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>Utility</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>Utility</ConfigurationType>
+ <CharacterSet>MultiByte</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="json-glib.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="json-glib.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="json-glib.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props"
Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="json-glib.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(GlibEtcInstallRoot)\</OutDir>
+ <ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(GlibEtcInstallRoot)\</OutDir>
+ <ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(GlibEtcInstallRoot)\</OutDir>
+ <ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(GlibEtcInstallRoot)\</OutDir>
+ <ExtensionsToDeleteOnClean Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <PreBuildEvent>
+ <Command>$(DoGenGir)</Command>
+ </PreBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <PreBuildEvent>
+ <Command>$(DoGenGir)</Command>
+ </PreBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <PreBuildEvent>
+ <Command>$(DoGenGir)</Command>
+ </PreBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <PreBuildEvent>
+ <Command>$(DoGenGir)</Command>
+ </PreBuildEvent>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ProjectReference Include="json-glib.vcxproj">
+ <Project>{469db0a8-e33e-4112-a38c-52a168ecdc03}</Project>
+ <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/build/win32/vs9/Makefile.am b/build/win32/vs9/Makefile.am
index b8cb751..24a1ada 100644
--- a/build/win32/vs9/Makefile.am
+++ b/build/win32/vs9/Makefile.am
@@ -20,4 +20,5 @@ EXTRA_DIST = \
serialize-full.vcproj \
serialize-simple.vcproj \
README.txt \
+ gengir.vcproj \
$(NULL)
diff --git a/build/win32/vs9/gengir.vcproj b/build/win32/vs9/gengir.vcproj
new file mode 100644
index 0000000..a5cc540
--- /dev/null
+++ b/build/win32/vs9/gengir.vcproj
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="gengir"
+ ProjectGUID="{2093D218-190E-4194-9421-3BA7CBF33B15}"
+ RootNamespace="gengir"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ InheritedPropertySheets=".\json-glib.vsprops"
+ OutputDirectory="$(GlibEtcInstallRoot)"
+ ConfigurationType="10"
+ CharacterSet="2"
+ DeleteExtensionsOnClean=""
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine="$(DoGenGir)"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ InheritedPropertySheets=".\json-glib.vsprops"
+ OutputDirectory="$(GlibEtcInstallRoot)"
+ ConfigurationType="10"
+ CharacterSet="2"
+ DeleteExtensionsOnClean=""
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine="$(DoGenGir)"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ InheritedPropertySheets=".\json-glib.vsprops"
+ OutputDirectory="$(GlibEtcInstallRoot)"
+ ConfigurationType="10"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ DeleteExtensionsOnClean=""
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine="$(DoGenGir)"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ InheritedPropertySheets=".\json-glib.vsprops"
+ OutputDirectory="$(GlibEtcInstallRoot)"
+ ConfigurationType="10"
+ CharacterSet="2"
+ WholeProgramOptimization="1"
+ DeleteExtensionsOnClean=""
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ CommandLine="$(DoGenGir)"
+ />
+ </Configuration>
+ </Configurations>
+</VisualStudioProject>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]