[gtk+] MSVC Builds: Add Script to Generate gtk-win32.rc



commit d62bd12b861742ba5aa6549aebb33d541b0cad1e
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Aug 4 13:34:15 2014 +0800

    MSVC Builds: Add Script to Generate gtk-win32.rc
    
    In bug 733773, gtk-win32.rc was removed from the dist in the attempt to
    make the print dialog on Windows themed, so this script was added so that
    the gtk-win32.rc file can be generated during the Visual Studio builds of
    GTK+ from the autotools scripts.  This is also intended for filling in the
    arch of the build for MSVC builds for the manifest that is also required
    for fixing bug 733773.  Python is used as it is already needed for
    
    This is done as a custom build rule in the Visual Studio projects so that
    it is easy to clean and rebuild gtk-win32.rc upon an update.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733773

 build/win32/Makefile.am                |    2 +
 build/win32/process-in-win32.py        |  100 ++++++++++++++++++++++++++++++++
 build/win32/vs10/gtk-gen-srcs.props    |   10 ++-
 build/win32/vs10/gtk.vcxproj.filtersin |    1 +
 build/win32/vs10/gtk.vcxprojin         |   14 +++++
 build/win32/vs9/gtk-gen-srcs.vsprops   |   10 ++-
 build/win32/vs9/gtk.vcprojin           |   30 ++++++++++
 7 files changed, 159 insertions(+), 8 deletions(-)
---
diff --git a/build/win32/Makefile.am b/build/win32/Makefile.am
index b72d35d..6cbb596 100644
--- a/build/win32/Makefile.am
+++ b/build/win32/Makefile.am
@@ -7,4 +7,6 @@ SUBDIRS =       \
        vs11    \
        vs12
 
+EXTRA_DIST += process-in-win32.py
+
 -include $(top_srcdir)/git.mk
diff --git a/build/win32/process-in-win32.py b/build/win32/process-in-win32.py
new file mode 100644
index 0000000..00c4c01
--- /dev/null
+++ b/build/win32/process-in-win32.py
@@ -0,0 +1,100 @@
+#!/usr/bin/python
+# vim: encoding=utf-8
+# expand Windows-specific *.in files
+# for Visual Studio Builds
+
+import os
+import sys
+import re
+import string
+import argparse
+
+
+def open_compat(src, mode):
+    if (sys.version_info.major < 3):
+        return open(src, mode)
+    else:
+        return open(src, mode, encoding='utf-8', errors='surrogateescape')
+
+def get_version(srcroot):
+    ver = {}
+    RE_VERSION = re.compile(r'^m4_define\(\[(gtk_\w+)\],\s*\[(\d+)\]\)')
+    RE_FLOAT_VERSION = re.compile(r'^m4_define\(\[(gtk_\w+)\],\s*\[(\d+\.\d*)\]\)')
+    with open(os.path.join(srcroot, 'configure.ac'), 'r') as ac:
+        for i in ac:
+            mo = RE_VERSION.search(i)
+            if mo:
+                ver[mo.group(1).upper()] = int(mo.group(2))
+            mo = RE_FLOAT_VERSION.search(i)
+            if mo:
+                ver[mo.group(1).upper()] = float(mo.group(2))
+
+    ver['GTK_BINARY_AGE'] = 100 * ver['GTK_MINOR_VERSION'] + ver['GTK_MICRO_VERSION']
+    ver['GTK_VERSION'] = '%d.%d.%d' % (ver['GTK_MAJOR_VERSION'],
+                                        ver['GTK_MINOR_VERSION'],
+                                        ver['GTK_MICRO_VERSION'])
+    ver['LT_RELEASE'] = '%d.%d' % (ver['GTK_MAJOR_VERSION'], ver['GTK_MINOR_VERSION'])
+    ver['LT_CURRENT'] = 100 * \
+                        ver['GTK_MINOR_VERSION'] + \
+                        ver['GTK_MICRO_VERSION'] - \
+                        ver['GTK_INTERFACE_AGE']
+    ver['LT_REVISION'] = ver['GTK_INTERFACE_AGE']
+    ver['LT_AGE'] = ver['GTK_BINARY_AGE'] - ver['GTK_INTERFACE_AGE']
+    ver['LT_CURRENT_MINUS_AGE'] = ver['LT_CURRENT'] - ver['LT_AGE']
+    return ver
+
+def process_in(src, dest, vars):
+    RE_VARS = re.compile(r'@(\w+?)@')
+
+    with open_compat(src, 'r') as s:
+        with open_compat(dest, 'w') as d:
+            for i in s:
+                i = RE_VARS.sub(lambda x: str(vars[x.group(1)]), i)
+                d.write(i)
+
+def get_srcroot():
+    if not os.path.isabs(__file__):
+        path = os.path.abspath(__file__)
+    else:
+        path = __file__
+    dirname = os.path.dirname(path)
+    return os.path.abspath(os.path.join(dirname, '..', '..'))
+
+def main(argv):
+    prog_desc = 'Create Various autogenerated Win32-specific Source Files'
+    parser = argparse.ArgumentParser(description=prog_desc)
+    parser.add_argument('--gtkwin32rc', dest='gtkwin32rc', action='store_const',
+                        const=1,
+                        help='Generate gtk-win32.rc')
+
+    parser.add_argument('--gtk3manifest', dest='gtk3manifest', action='store_const',
+                   const=1,
+                   help='Generate libgtk3.manifest (Not used now)')
+
+    args = parser.parse_args()
+    no_args = True
+
+    if args.gtkwin32rc is not None:
+        srcroot = get_srcroot()
+
+        ver = get_version(srcroot)
+
+        process_in(os.path.join(srcroot, 'gtk', 'gtk-win32.rc.in'),
+                   os.path.join(srcroot, 'gtk', 'gtk-win32.rc'),
+                   ver)
+        no_args = False
+
+    if args.gtk3manifest is not None:
+        print('Not Used... Will add once gtk/libgtk3.manifest.in is added')
+        #manifest = {}
+        #manifest['EXE_MANIFEST_ARCHITECTURE'] = '*'
+        #process_in(os.path.join(srcroot, 'gtk', 'libgtk3.manifest.in',
+        #           os.path.join(srcroot, 'gtk', 'libgtk3.manifest',
+        #           manifest)
+        no_args = False
+
+    if no_args is True:
+        raise SystemExit('Action argument required.  Please see %s --help for details.' % __file__)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
diff --git a/build/win32/vs10/gtk-gen-srcs.props b/build/win32/vs10/gtk-gen-srcs.props
index 7afca8a..c86b6b0 100644
--- a/build/win32/vs10/gtk-gen-srcs.props
+++ b/build/win32/vs10/gtk-gen-srcs.props
@@ -58,14 +58,13 @@ echo $(Configuration) &gt; ..\..\..\MSVC_$(Configuration)
 :DONE_GDKCONFIG_H
     </GenGdkConfigHBroadway>
     <GenerateGtkDbusBuiltSources>
-set PATH=$(PATH);$(PythonPath)
-
 cd ..\..\..\gtk
 
-python $(GlibEtcInstallRoot)\bin\gdbus-codegen --interface-prefix org.Gtk. --c-namespace _Gtk 
--generate-c-code gtkdbusgenerated ./gtkdbusinterfaces.xml
+$(PythonPath)\python $(GlibEtcInstallRoot)\bin\gdbus-codegen --interface-prefix org.Gtk. --c-namespace _Gtk 
--generate-c-code gtkdbusgenerated ./gtkdbusinterfaces.xml
 
 cd $(SolutionDir)
     </GenerateGtkDbusBuiltSources>
+    <GenerateGtkWin32RC>$(PythonPath)\python ..\process-in-win32.py --gtkwin32rc</GenerateGtkWin32RC>
   </PropertyGroup>
   <PropertyGroup>
     <_PropertySheetDisplayName>gtkgensrcsprops</_PropertySheetDisplayName>
@@ -83,5 +82,8 @@ cd $(SolutionDir)
     <BuildMacro Include="GenerateGtkDbusBuiltSources">
       <Value>$(GenerateGtkDbusBuiltSources)</Value>
     </BuildMacro>
+    <BuildMacro Include="GenerateGtkWin32RC">
+      <Value>$(GenerateGtkWin32RC)</Value>
+    </BuildMacro>
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/build/win32/vs10/gtk.vcxproj.filtersin b/build/win32/vs10/gtk.vcxproj.filtersin
index f6be805..da93511 100644
--- a/build/win32/vs10/gtk.vcxproj.filtersin
+++ b/build/win32/vs10/gtk.vcxproj.filtersin
@@ -19,6 +19,7 @@
   </ItemGroup>
   <ItemGroup>
     <CustomBuild Include="..\..\..\gtk\gtkdbusinterfaces.xml"><Filter>Resource Files</Filter></CustomBuild>
+    <CustomBuild Include="..\..\..\gtk\gtk-win32.rc.in"><Filter>Resource Files</Filter></CustomBuild>
   </ItemGroup>
   <ItemGroup>
 #include "libgtk.vs10.sourcefiles.filters"
diff --git a/build/win32/vs10/gtk.vcxprojin b/build/win32/vs10/gtk.vcxprojin
index 0686775..80af761 100644
--- a/build/win32/vs10/gtk.vcxprojin
+++ b/build/win32/vs10/gtk.vcxprojin
@@ -173,6 +173,20 @@
       <Command 
Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(GenerateGtkDbusBuiltSources)</Command>
       <Outputs 
Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\gtk\gtkdbusgenerated.c;..\..\..\gtk\gtkdbusgenerated.h;%(Outputs)</Outputs>
     </CustomBuild>
+    <CustomBuild Include="..\..\..\gtk\gtk-win32.rc.in">
+      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Generating GTK+ Win32 Version 
Resource...</Message>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(GenerateGtkWin32RC)</Command>
+      <Outputs 
Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">..\..\..\gtk\gtk-win32.rc;%(Outputs)</Outputs>
+      <Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Generating GTK+ Win32 Version 
Resource...</Message>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(GenerateGtkWin32RC)</Command>
+      <Outputs 
Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">..\..\..\gtk\gtk-win32.rc;%(Outputs)</Outputs>
+      <Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Generating GTK+ Win32 Version 
Resource...</Message>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(GenerateGtkWin32RC)</Command>
+      <Outputs 
Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\..\..\gtk\gtk-win32.rc;%(Outputs)</Outputs>
+      <Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Generating GTK+ Win32 Version 
Resource...</Message>
+      <Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(GenerateGtkWin32RC)</Command>
+      <Outputs 
Condition="'$(Configuration)|$(Platform)'=='Release|x64'">..\..\..\gtk\gtk-win32.rc;%(Outputs)</Outputs>
+    </CustomBuild>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="..\..\..\gtk\gtk-win32.rc" />
diff --git a/build/win32/vs9/gtk-gen-srcs.vsprops b/build/win32/vs9/gtk-gen-srcs.vsprops
index 7b1d0db..24ac945 100644
--- a/build/win32/vs9/gtk-gen-srcs.vsprops
+++ b/build/win32/vs9/gtk-gen-srcs.vsprops
@@ -57,11 +57,13 @@ echo $(ConfigurationName) &gt; ..\..\..\MSVC_$(ConfigurationName)&#x0D;&#x0A;
        <UserMacro
                Name="GenerateGtkDbusBuiltSources"
                Value="
-set PATH=$(PATH);$(PythonPath)&#x0D;&#x0A;
-
 cd ..\..\..\gtk&#x0D;&#x0A;
-python $(GlibEtcInstallRoot)\bin\gdbus-codegen --interface-prefix org.Gtk. --c-namespace _Gtk 
--generate-c-code gtkdbusgenerated ./gtkdbusinterfaces.xml&#x0D;&#x0A;
+$(PythonPath)\python $(GlibEtcInstallRoot)\bin\gdbus-codegen --interface-prefix org.Gtk. --c-namespace _Gtk 
--generate-c-code gtkdbusgenerated ./gtkdbusinterfaces.xml&#x0D;&#x0A;
 cd $(SolutionDir)&#x0D;&#x0A;
                      "
        />
-</VisualStudioPropertySheet>
\ No newline at end of file
+       <UserMacro
+               Name="GenerateGtkWin32RC"
+               Value="$(PythonPath)\python ..\process-in-win32.py --gtkwin32rc"
+       />
+</VisualStudioPropertySheet>
diff --git a/build/win32/vs9/gtk.vcprojin b/build/win32/vs9/gtk.vcprojin
index b7e40c7..3dc5477 100644
--- a/build/win32/vs9/gtk.vcprojin
+++ b/build/win32/vs9/gtk.vcprojin
@@ -192,6 +192,36 @@
                                        />
                                </FileConfiguration>
                        </File>
+                       <File RelativePath="..\..\..\gtk\gtk-win32.rc.in">
+                               <FileConfiguration Name="Debug|Win32">
+                               <Tool Name="VCCustomBuildTool"
+                                               Description="Generating GTK+ Win32 Version Resource..."
+                                               CommandLine="$(GenerateGtkWin32RC)"
+                                               Outputs="..\..\..\gtk\gtk-win32.rc"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration Name="Release|Win32">
+                                       <Tool Name="VCCustomBuildTool"
+                                               Description="Generating GTK+ Win32 Version Resource..."
+                                               CommandLine="$(GenerateGtkWin32RC)"
+                                               Outputs="..\..\..\gtk\gtk-win32.rc"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration Name="Debug|x64">
+                                       <Tool Name="VCCustomBuildTool"
+                                               Description="Generating GTK+ Win32 Version Resource..."
+                                               CommandLine="$(GenerateGtkWin32RC)"
+                                               Outputs="..\..\..\gtk\gtk-win32.rc"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration Name="Release|x64">
+                                       <Tool Name="VCCustomBuildTool"
+                                               Description="Generating GTK+ Win32 Version Resource..."
+                                               CommandLine="$(GenerateGtkWin32RC)"
+                                               Outputs="..\..\..\gtk\gtk-win32.rc"
+                                       />
+                               </FileConfiguration>
+                       </File>
                        <File RelativePath="..\..\..\gtk\gtk-win32.rc" />
                </Filter>
                <Filter


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]