[gtksourceview/gnome-3-24] MSVC builds: Adapt to Pythonfied glib-mkenums



commit 00ac7368383cdc05c6a85503ed8450da592f6bf0
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Sep 8 19:35:26 2017 +0800

    MSVC builds: Adapt to Pythonfied glib-mkenums
    
    glib-mkenums has been re-written in Python in the latest GLib that will
    be in the next stable release 2.54.0, so we need to adapt to it.
    
    The issue is that the standard Windows cmd.exe (where the Visual Studio
    projects make use of) does not support shebang lines, and we still
    support GLib versions that use the PERL glib-mkenums, we need to first
    try to run that script with Python (which we already use during the
    build) and see whether that was successful by seeing whether the
    generated file is not empty (as calling the PERL glib-mkenums would
    cause an error and results in the generated file being 0 in size).
    
    If calling glib-mkenums with Python failed, call that script with PERL,
    as we did before.

 win32/gen-enums.batin                    |   64 +++++++++++++++++++++++++++++-
 win32/vs10/gtksourceview-gen-srcs.props  |    9 ++++-
 win32/vs10/gtksourceview.vcxprojin       |   10 ++---
 win32/vs9/gtksourceview-gen-srcs.vsprops |   10 ++++-
 win32/vs9/gtksourceview.vcprojin         |    4 +-
 5 files changed, 85 insertions(+), 12 deletions(-)
---
diff --git a/win32/gen-enums.batin b/win32/gen-enums.batin
index 04a6513..649f6a9 100644
--- a/win32/gen-enums.batin
+++ b/win32/gen-enums.batin
@@ -5,6 +5,47 @@ cd ..\gtksourceview
 if exist gtksourceview-enumtypes.h del gtksourceview-enumtypes.h
 if exist gtksourceview-enumtypes.c del gtksourceview-enumtypes.c
 
+set PYTHON=%2
+
+if "%PYTHON%" == "" goto use_perl
+
+call %PYTHON% %1\bin\glib-mkenums ^
+--fhead "#ifdef HAVE_CONFIG_H\n" ^
+--fhead "#include \"config.h\"\n" ^
+--fhead "#endif\n\n" ^
+--fhead "#include <glib-object.h>\n" ^
+--fhead "#include \"gtksourceview-enumtypes.h\"\n\n" ^
+--fprod "\n/* enumerations from \"@filename@\" */" ^
+--vhead "static const G@Type@Value _@enum_name@_values[] = {" ^
+--vprod "  { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," ^
+--vtail "  { 0, NULL, NULL }\n};\n\n" ^
+--vtail "GType\n@enum_name@_get_type (void)\n{\n" ^
+--vtail "  static GType type = 0;\n\n" ^
+--vtail "  if (!type)\n" ^
+--vtail "    type = g_@type@_register_static (\"@EnumName@\", _@enum_name@_values);\n\n" ^
+--vtail "  return type;\n}\n\n" ^
+#include "enum.headers"
+&1> gtksourceview-enumtypes.c
+
+call %PYTHON% %1\bin\glib-mkenums ^
+--fhead "#ifndef GTKSOURCEVIEW_ENUMTYPES_H\n" ^
+--fhead "#define GTKSOURCEVIEW_ENUMTYPES_H\n\n" ^
+--ftail "#endif /* GTKSOURCEVIEW_ENUMTYPES_H */\n" ^
+--fprod "#include <gtksourceview/@filename@>\n" ^
+--eprod "G_BEGIN_DECLS\n" ^
+--eprod "#define GTK_TYPE_@ENUMSHORT@ @enum_name@_get_type()\n" ^
+--eprod "GTK_SOURCE_ENUM_EXTERN\nGType @enum_name@_get_type (void);\n" ^
+--eprod "G_END_DECLS\n\n" ^
+# include "enum.headers"
+&1> gtksourceview-enumtypes.h.tmp
+
+:use_perl
+set f=gtksourceview-enumtypes.c
+if not exist %f% goto do_enum_c
+for %%x in (%f%) do if %%~zx gtr 0 goto done_enum_c
+
+:do_enum_c
+
 call perl %1\bin\glib-mkenums ^
 --fhead "#ifdef HAVE_CONFIG_H\n" ^
 --fhead "#include \"config.h\"\n" ^
@@ -23,6 +64,13 @@ call perl %1\bin\glib-mkenums ^
 #include "enum.headers"
 &1> gtksourceview-enumtypes.c
 
+:done_enum_c
+set f=gtksourceview-enumtypes.h.tmp
+
+if not exist %f% goto do_enum_h
+for %%x in (%f%) do if %%~zx gtr 0 goto done_enum_h
+
+:do_enum_h
 call perl %1\bin\glib-mkenums ^
 --fhead "#ifndef GTKSOURCEVIEW_ENUMTYPES_H\n" ^
 --fhead "#define GTKSOURCEVIEW_ENUMTYPES_H\n\n" ^
@@ -33,8 +81,20 @@ call perl %1\bin\glib-mkenums ^
 --eprod "GTK_SOURCE_ENUM_EXTERN\nGType @enum_name@_get_type (void);\n" ^
 --eprod "G_END_DECLS\n\n" ^
 # include "enum.headers"
-&1> gtksourceview-enumtypes.h
+&1> gtksourceview-enumtypes.h.tmp
+
+:done_enum_h
+
+if "%PYTHON%" == "" goto replace_perl
+call %PYTHON% ..\win32\replace.py --action=replace-str ^
+-i=gtksourceview-enumtypes.h.tmp ^
+-o=gtksourceview-enumtypes.h ^
+--instring=GTK_TYPE_SOURCE_ ^
+--outstring=GTK_SOURCE_TYPE_
 
+goto cleanup
+:replace_perl
+call perl -p -e "s/GTK_TYPE_SOURCE_/GTK_SOURCE_TYPE_/g" < gtksourceview-enumtypes.h.tmp > 
gtksourceview-enumtypes.h
 
-call perl -p -i.tmp -e "s/GTK_TYPE_SOURCE_/GTK_SOURCE_TYPE_/g" gtksourceview-enumtypes.h
+:cleanup
 del gtksourceview-enumtypes.h.tmp
diff --git a/win32/vs10/gtksourceview-gen-srcs.props b/win32/vs10/gtksourceview-gen-srcs.props
index dd1356d..49e5e12 100644
--- a/win32/vs10/gtksourceview-gen-srcs.props
+++ b/win32/vs10/gtksourceview-gen-srcs.props
@@ -6,9 +6,13 @@
   <PropertyGroup Label="UserMacros">
     <CopyConfigH>copy ..\..\config.h.win32 ..\..\config.h</CopyConfigH>
     <GenerateEnums>cd ..
-CALL gen-enums.bat $(GlibEtcInstallRoot)
+CALL gen-enums.bat $(GlibEtcInstallRoot) $(PythonDir)\python.exe
 cd $(SolutionDir)
     </GenerateEnums>
+    <GenerateEnumsX64>cd ..
+CALL gen-enums.bat $(GlibEtcInstallRoot) $(PythonDirX64)\python.exe
+cd $(SolutionDir)
+    </GenerateEnumsX64>
     <GenerateRsrcSrc>$(GlibEtcInstallRoot)\bin\glib-compile-resources 
--target=..\..\gtksourceview\gtksourceview-resources.c --generate-source --sourcedir=..\..\gtksourceview 
..\..\gtksourceview\gtksourceview.gresource.xml</GenerateRsrcSrc>
     <GenGtksourceVersionH>$(PythonDir)\python.exe ..\gtksource_version_h.py 
--version=$(GtkSourceviewMajorVersion).$(GtkSourceviewMinorVersion).$(GtkSourceviewMicroVersion)</GenGtksourceVersionH>
     <GenGtksourceVersionHX64>$(PythonDirX64)\python.exe ..\gtksource_version_h.py 
--version=$(GtkSourceviewMajorVersion).$(GtkSourceviewMinorVersion).$(GtkSourceviewMicroVersion)</GenGtksourceVersionHX64>
@@ -23,6 +27,9 @@ cd $(SolutionDir)
     <BuildMacro Include="GenerateEnums">
       <Value>$(GenerateEnums)</Value>
     </BuildMacro>
+    <BuildMacro Include="GenerateEnumsX64">
+      <Value>$(GenerateEnumsX64)</Value>
+    </BuildMacro>
     <BuildMacro Include="GenerateRsrcSrc">
       <Value>$(GenerateRsrcSrc)</Value>
     </BuildMacro>
diff --git a/win32/vs10/gtksourceview.vcxprojin b/win32/vs10/gtksourceview.vcxprojin
index ad331f4..1317d19 100644
--- a/win32/vs10/gtksourceview.vcxprojin
+++ b/win32/vs10/gtksourceview.vcxprojin
@@ -180,12 +180,10 @@
       <Outputs>..\..\gtksourceview\gtksourceversion.h;%(Outputs)</Outputs>
     </CustomBuild>
     <CustomBuild Include="..\gen-enums.bat">
-      <Message Condition="'$(Configuration)'=='Debug'">Generating Enumeration sources...</Message>
-      <Command Condition="'$(Configuration)'=='Debug'">$(GenerateEnums)</Command>
-      <Outputs 
Condition="'$(Configuration)'=='Debug'">..\..\gtksourceview\gtksourceview-enumtypes.c;..\..\gtksourceview\gtksourceview-enumtypes.h;%(Outputs)</Outputs>
-      <Message Condition="'$(Configuration)'=='Release'">Generating Enumeration sources...</Message>
-      <Command Condition="'$(Configuration)'=='Release'">$(GenerateEnums)</Command>
-      <Outputs 
Condition="'$(Configuration)'=='Release'">..\..\gtksourceview\gtksourceview-enumtypes.c;..\..\gtksourceview\gtksourceview-enumtypes.h;%(Outputs)</Outputs>
+      <Message>Generating Enumeration sources...</Message>
+      <Command Condition="'$(Platform)'=='Win32'">$(GenerateEnums)</Command>
+      <Command Condition="'$(Platform)'=='x64'">$(GenerateEnumsX64)</Command>
+      
<Outputs>..\..\gtksourceview\gtksourceview-enumtypes.c;..\..\gtksourceview\gtksourceview-enumtypes.h;%(Outputs)</Outputs>
     </CustomBuild>
     <CustomBuild Include="..\..\gtksourceview\gtksourceview.gresource.xml">
       <Message>Generating GResource sources...</Message>
diff --git a/win32/vs9/gtksourceview-gen-srcs.vsprops b/win32/vs9/gtksourceview-gen-srcs.vsprops
index 2a92d21..97211c0 100644
--- a/win32/vs9/gtksourceview-gen-srcs.vsprops
+++ b/win32/vs9/gtksourceview-gen-srcs.vsprops
@@ -13,7 +13,15 @@
                Name="GenerateEnums"
                Value="
 cd ..&#x0D;&#x0A;
-CALL gen-enums.bat $(GlibEtcInstallRoot)&#x0D;&#x0A;
+CALL gen-enums.bat $(GlibEtcInstallRoot) $(PythonDir)\python.exe&#x0D;&#x0A;
+cd $(SolutionDir)&#x0D;&#x0A;
+                     "
+       />
+       <UserMacro
+               Name="GenerateEnumsX64"
+               Value="
+cd ..&#x0D;&#x0A;
+CALL gen-enums.bat $(GlibEtcInstallRoot) $(PythonDirX64)\python.exe&#x0D;&#x0A;
 cd $(SolutionDir)&#x0D;&#x0A;
                      "
        />
diff --git a/win32/vs9/gtksourceview.vcprojin b/win32/vs9/gtksourceview.vcprojin
index 97a9e58..38afe21 100644
--- a/win32/vs9/gtksourceview.vcprojin
+++ b/win32/vs9/gtksourceview.vcprojin
@@ -258,14 +258,14 @@
                                <FileConfiguration Name="Debug|x64">
                                        <Tool Name="VCCustomBuildTool"
                                                Description="Generating Enumeration sources..."
-                                               CommandLine="$(GenerateEnums)"
+                                               CommandLine="$(GenerateEnumsX64)"
                                                
Outputs="..\..\gtksourceview\gtksourceview-enumtypes.c;..\..\gtksourceview\gtksourceview-enumtypes.h"
                                        />
                                </FileConfiguration>
                                <FileConfiguration Name="Release|x64">
                                        <Tool Name="VCCustomBuildTool"
                                                Description="Generating Enumeration sources..."
-                                               CommandLine="$(GenerateEnums)"
+                                               CommandLine="$(GenerateEnumsX64)"
                                                
Outputs="..\..\gtksourceview\gtksourceview-enumtypes.c;..\..\gtksourceview\gtksourceview-enumtypes.h"
                                        />
                                </FileConfiguration>


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