[gtksourceview] MSVC builds: Adapt to Pythonfied glib-mkenums



commit 4d945928f664dec5950cd72f9b951b784475395a
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Oct 5 17:43:04 2018 +0800

    MSVC builds: Adapt to Pythonfied glib-mkenums
    
    glib-mkenums has been re-written in Python in the later GLib since 2.54,
    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/gtksourceview4-gen-srcs.props  |  2 +-
 win32/vs9/gtksourceview-4.vcprojin        |  4 +-
 win32/vs9/gtksourceview4-gen-srcs.vsprops | 10 ++++-
 4 files changed, 74 insertions(+), 6 deletions(-)
---
diff --git a/win32/gen-enums.batin b/win32/gen-enums.batin
index c22bd56c..092850cb 100644
--- a/win32/gen-enums.batin
+++ b/win32/gen-enums.batin
@@ -5,6 +5,47 @@ cd ..\gtksourceview
 if exist gtksource-enumtypes.h del gtksource-enumtypes.h
 if exist gtksource-enumtypes.c del gtksource-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 \"gtksource-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> gtksource-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> gtksource-enumtypes.h.tmp
+
+:use_perl
+set f=gtksource-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,14 @@ call perl %1\bin\glib-mkenums ^
 #include "enum.headers"
 &1> gtksource-enumtypes.c
 
+:done_enum_c
+set f=gtksource-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 +82,19 @@ 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> gtksource-enumtypes.h
+&1> gtksource-enumtypes.h.tmp
+
+:done_enum_h
+if "%PYTHON%" == "" goto replace_perl
+call %PYTHON% ..\win32\replace.py --action=replace-str ^
+-i=gtksource-enumtypes.h.tmp ^
+-o=gtksource-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" < gtksource-enumtypes.h.tmp > gtksource-enumtypes.h
 
-call perl -p -i.tmp -e "s/GTK_TYPE_SOURCE_/GTK_SOURCE_TYPE_/g" gtksource-enumtypes.h
+:cleanup
 del gtksource-enumtypes.h.tmp
diff --git a/win32/vs10/gtksourceview4-gen-srcs.props b/win32/vs10/gtksourceview4-gen-srcs.props
index 15f0bd37..7b7ebe8c 100644
--- a/win32/vs10/gtksourceview4-gen-srcs.props
+++ b/win32/vs10/gtksourceview4-gen-srcs.props
@@ -6,7 +6,7 @@
   <PropertyGroup Label="UserMacros">
     <CopyConfigH>copy ..\..\config.h.win32 ..\..\config.h</CopyConfigH>
     <GenerateEnums>cd ..
-CALL gen-enums.bat $(GlibEtcInstallRoot)
+CALL gen-enums.bat $(GlibEtcInstallRoot) $(PythonCmd)
 cd $(SolutionDir)
     </GenerateEnums>
     <GenerateRsrcSrc>$(GlibEtcInstallRoot)\bin\glib-compile-resources 
--target=..\..\gtksourceview\gtksourceview-resources.c --generate-source --sourcedir=..\..\gtksourceview 
..\..\gtksourceview\gtksourceview.gresource.xml</GenerateRsrcSrc>
diff --git a/win32/vs9/gtksourceview-4.vcprojin b/win32/vs9/gtksourceview-4.vcprojin
index c3937880..a366c83d 100644
--- a/win32/vs9/gtksourceview-4.vcprojin
+++ b/win32/vs9/gtksourceview-4.vcprojin
@@ -258,14 +258,14 @@
                                <FileConfiguration Name="Debug|x64">
                                        <Tool Name="VCCustomBuildTool"
                                                Description="Generating Enumeration sources..."
-                                               CommandLine="$(GenerateEnums)"
+                                               CommandLine="$(GenerateEnumsX64)"
                                                
Outputs="..\..\gtksourceview\gtksource-enumtypes.c;..\..\gtksourceview\gtksource-enumtypes.h"
                                        />
                                </FileConfiguration>
                                <FileConfiguration Name="Release|x64">
                                        <Tool Name="VCCustomBuildTool"
                                                Description="Generating Enumeration sources..."
-                                               CommandLine="$(GenerateEnums)"
+                                               CommandLine="$(GenerateEnumsX64)"
                                                
Outputs="..\..\gtksourceview\gtksource-enumtypes.c;..\..\gtksourceview\gtksource-enumtypes.h"
                                        />
                                </FileConfiguration>
diff --git a/win32/vs9/gtksourceview4-gen-srcs.vsprops b/win32/vs9/gtksourceview4-gen-srcs.vsprops
index 6a87e016..3055beef 100644
--- a/win32/vs9/gtksourceview4-gen-srcs.vsprops
+++ b/win32/vs9/gtksourceview4-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;
                      "
        />


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