[gsettings-desktop-schemas] build: Enable build/installation with Visual Studio



commit fe157979911830e4758585854d3754158d386f2a
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Oct 5 12:01:37 2015 +0800

    build: Enable build/installation with Visual Studio
    
    This adds a set of NMake Makefiles, along with some support files,
    is used to generate and compile the gschema.xml files from their
    templates, generate the enums.xml using glib-mkenums, and, optionally,
    generate the introspection files.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723734

 Makefile.am                                       |    2 +-
 build/Makefile.am                                 |    3 +
 build/win32/Makefile.am                           |   31 +++++++
 build/win32/detectenv-msvc.mak                    |   68 ++++++++++++++
 build/win32/gsettings-desktop-schemas-msvc.mak.in |   93 +++++++++++++++++++
 build/win32/introspection-msvc.mak                |   66 ++++++++++++++
 build/win32/replace.py                            |   98 +++++++++++++++++++++
 build/win32/uri.py                                |   30 ++++++
 configure.ac                                      |    3 +
 headers/Makefile.am                               |   19 ++++
 10 files changed, 412 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index c0d7008..96e6f6c 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = headers schemas po
+SUBDIRS = headers schemas po build
 
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
diff --git a/build/Makefile.am b/build/Makefile.am
new file mode 100644
index 0000000..73e7a6f
--- /dev/null
+++ b/build/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = win32
+
+-include $(top_srcdir)/git.mk
diff --git a/build/win32/Makefile.am b/build/win32/Makefile.am
new file mode 100644
index 0000000..6025eef
--- /dev/null
+++ b/build/win32/Makefile.am
@@ -0,0 +1,31 @@
+if HAVE_INTROSPECTION
+GENERATED_ITEMS = \
+       introspection.body.mak  \
+       GDesktopEnums_3_0_gir_list
+
+introspection.body.mak: GDesktopEnums-3.0.gir.msvc.introspect
+       -$(RM) introspection.body.mak
+       for F in `ls *.msvc.introspect`; do \
+               case $$F in \
+                       *)      cat $$F >>introspection.body.mak \
+                       ;; \
+               esac; \
+       done
+       $(RM) GDesktopEnums-3.0.gir.msvc.introspect
+
+DISTCLEANFILES = $(GENERATED_ITEMS)
+
+else
+GENERATED_ITEMS =
+endif
+
+EXTRA_DIST = \
+       detectenv-msvc.mak                      \
+       gsettings-desktop-schemas-msvc.mak.in   \
+       gsettings-desktop-schemas-msvc.mak      \
+       introspection-msvc.mak                  \
+       replace.py                              \
+       uri.py                                  \
+       $(GENERATED_ITEMS)
+
+-include $(top_srcdir)/git.mk
diff --git a/build/win32/detectenv-msvc.mak b/build/win32/detectenv-msvc.mak
new file mode 100644
index 0000000..975e11d
--- /dev/null
+++ b/build/win32/detectenv-msvc.mak
@@ -0,0 +1,68 @@
+# Check to see we are configured to build with MSVC (MSDEVDIR, MSVCDIR or
+# VCINSTALLDIR) or with the MS Platform SDK (MSSDK or WindowsSDKDir)
+!if !defined(VCINSTALLDIR) && !defined(WINDOWSSDKDIR)
+MSG = ^
+This Makefile is only for Visual Studio 2008 and later.^
+You need to ensure that the Visual Studio Environment is properly set up^
+before running this Makefile.
+!error $(MSG)
+!endif
+
+ERRNUL  = 2>NUL
+_HASH=^#
+
+!if ![echo VCVERSION=_MSC_VER > vercl.x] \
+    && ![echo $(_HASH)if defined(_M_IX86) >> vercl.x] \
+    && ![echo PLAT=Win32 >> vercl.x] \
+    && ![echo $(_HASH)elif defined(_M_AMD64) >> vercl.x] \
+    && ![echo PLAT=x64 >> vercl.x] \
+    && ![echo $(_HASH)endif >> vercl.x] \
+    && ![cl -nologo -TC -P vercl.x $(ERRNUL)]
+!include vercl.i
+!if ![echo VCVER= ^\> vercl.vc] \
+    && ![set /a $(VCVERSION) / 100 - 6 >> vercl.vc]
+!include vercl.vc
+!endif
+!endif
+!if ![del $(ERRNUL) /q/f vercl.x vercl.i vercl.vc]
+!endif
+
+!if $(VCVERSION) > 1499 && $(VCVERSION) < 1600
+VSVER = 9
+!elseif $(VCVERSION) > 1599 && $(VCVERSION) < 1700
+VSVER = 10
+!elseif $(VCVERSION) > 1699 && $(VCVERSION) < 1800
+VSVER = 11
+!elseif $(VCVERSION) > 1799 && $(VCVERSION) < 1900
+VSVER = 12
+!elseif $(VCVERSION) > 1899 && $(VCVERSION) < 2000
+VSVER = 14
+!else
+VSVER = 0
+!endif
+
+!if "$(VSVER)" == "0"
+MSG = ^
+This NMake Makefile set supports Visual Studio^
+9 (2008) through 14 (2015).  Your Visual Studio^
+version is not supported.  Note that there is no^
+Visual Studio 13.
+!error $(MSG)
+!endif
+
+VALID_CFGSET = FALSE
+!if "$(CFG)" == "release" || "$(CFG)" == "debug"
+VALID_CFGSET = TRUE
+!endif
+
+!if "$(CFG)" == "release"
+CFLAGS_ADD = /MD /O2
+!else
+CFLAGS_ADD = /MDd /Od /Zi
+!endif
+
+!if "$(PLAT)" == "x64"
+LDFLAGS_ARCH = /machine:x64
+!else
+LDFLAGS_ARCH = /machine:x86
+!endif
diff --git a/build/win32/gsettings-desktop-schemas-msvc.mak.in 
b/build/win32/gsettings-desktop-schemas-msvc.mak.in
new file mode 100644
index 0000000..fd78eee
--- /dev/null
+++ b/build/win32/gsettings-desktop-schemas-msvc.mak.in
@@ -0,0 +1,93 @@
+# NMake Makefile to Generate The
+# Complete gschema.xml Files, create the
+# enums.xml file, and install the schemas
+
+!include detectenv-msvc.mak
+
+CHECK_PACKAGE=gio-2.0
+
+# Python.exe either needs to be in your PATH or you need to pass
+# in PYTHON=<full-path-to-your-Python-executable> for this to work
+# Python 3.x can be used unless introspection files are to be built,
+# where only Python 2.7.x is supported
+
+PYTHON=python
+PYTHON2=$(PYTHON)
+
+# Prefix of your installation.  Pass in PREFIX=<your-installation-prefix>
+# if needed.  glib-compile-schemas.exe and glib-mkenums need to be found
+# in $(PREFIX)\bin
+PREFIX=..\..\..\vs$(VSVER)\$(PLAT)
+
+!include introspection-msvc.mak
+
+# The PERL interpretor is required as we need to run the glib-mkenums
+# PERL script to generate the schemas from the enumerations.  It needs to
+# be in your path or you need to pass in PERL=<full-path-to-your-PERL-executable>
+
+PERL=perl.exe
+
+ERRNUL  = 2>NUL
+_HASH=^#
+
+# Get the Full URI representation of the PREFIX
+!if ![echo PREFIX_URI= ^\> uri.x] \
+&& ![$(PYTHON) uri.py $(PREFIX) >> uri.x]
+!include uri.x
+!endif
+
+!if ![del $(ERRNUL) /q/f uri.x]
+!endif
+
+!include ..\..\schemas\Makefile-schemas.include
+
+!if ![ echo gschemas = ^\> schemas.files] \
+&&  ![for %f in ($(desktop_gschemas_in)) do @echo.  %~nf ^\>> schemas.files]
+!endif
+
+!include schemas.files
+
+!if ![del schemas.files]
+!endif
+
+all: $(gschemas) org.gnome.desktop.enums.xml
+
+.SUFFIXES: .xml.in .xml
+
+{..\..\schemas\}.xml.in{}.xml:
+       $(PYTHON) replace.py --action=replace-var --input=$< --output=$  tmp --var=GETTEXT_PACKAGE 
--outstring= GETTEXT_PACKAGE@
+       $(PYTHON) replace.py --action=replace-var --input=$  tmp --output=$@ --var=datadir 
--outstring=$(PREFIX_URI)/share
+       @-del $  tmp
+
+org.gnome.desktop.enums.xml:
+       $(PERL) $(PREFIX)\bin\glib-mkenums --comments "<!-- @comment@ -->"      \
+       --fhead "<schemalist>"  \
+       --vhead "  <@type@ id='org gnome desktop  EnumName@'>"  \
+       --vprod "    <value nick='@valuenick@' value='@valuenum@'/>"    \
+       --vtail "  </@type@>" --ftail "</schemalist>" ..\..\headers\gdesktop-enums.h    \
+       > $@
+
+introspection: setgirbuildenv GDesktopEnums-3.0.gir GDesktopEnums-3.0.typelib
+
+setgirbuildenv:
+       @set PYTHONPATH=$(BASEDIR)\lib\gobject-introspection
+       @set PATH=$(BASEDIR)\bin;$(PATH)
+       @set PKG_CONFIG_PATH=$(PKG_CONFIG_PATH)
+
+!include introspection.body.mak
+
+install: $(gschemas) org.gnome.desktop.enums.xml
+       @-if not exist $(PREFIX)\share\glib-2.0\schemas mkdir $(PREFIX)\share\glib-2.0\schemas
+       @-copy *.gschema.xml $(PREFIX)\share\glib-2.0\schemas
+       @-copy org.gnome.desktop.enums.xml $(PREFIX)\share\glib-2.0\schemas
+       @-if not exist $(PREFIX)\include\gsettings-desktop-schemas mkdir 
$(PREFIX)\include\gsettings-desktop-schemas
+       @-copy ..\..\headers\gdesktop-enums.h $(PREFIX)\include\gsettings-desktop-schemas
+       @-if exist *.gir @copy *.gir $(PREFIX)\share\gir-1.0
+       @-if exist *.typelib @copy *.typelib $(PREFIX)\lib\girepository-1.0
+       $(PREFIX)\bin\glib-compile-schemas.exe $(PREFIX)\share\glib-2.0\schemas
+
+clean:
+       @-if exist *.typelib @del *.typelib
+       @-if exist *.gir @del *.gir
+       @-del $(gschemas)
+       @-del org.gnome.desktop.enums.xml
diff --git a/build/win32/introspection-msvc.mak b/build/win32/introspection-msvc.mak
new file mode 100644
index 0000000..ca6813e
--- /dev/null
+++ b/build/win32/introspection-msvc.mak
@@ -0,0 +1,66 @@
+# Common Utility NMake Makefile Template
+# Used to Generate Introspection files for various Projects
+
+# Can Override with env vars as needed
+# You will need to have built gobject-introspection for this to work.
+# Change or pass in or set the following to suit your environment
+
+BASEDIR = $(PREFIX)
+GIR_SUBDIR = share\gir-1.0
+GIR_TYPELIBDIR = lib\girepository-1.0
+G_IR_SCANNER = $(BASEDIR)\bin\g-ir-scanner
+G_IR_COMPILER = $(BASEDIR)\bin\g-ir-compiler.exe
+G_IR_INCLUDEDIR = $(BASEDIR)\$(GIR_SUBDIR)
+G_IR_TYPELIBDIR = $(BASEDIR)\$(GIR_TYPELIBDIR)
+
+# Note: The PYTHON2 must be a Python 2.6.x or 2.7.x Interpretor!
+# Either having python.exe from Python 2.6.x/2.7.x in your PATH will work
+# or passing in PYTHON2=<full path to your Python 2.6.x/2.7.x interpretor> will do
+
+# This is required, and gobject-introspection needs to be built
+# before this can be successfully run.
+!if "$(PYTHON2)" == ""
+PYTHON2=python
+!endif
+
+# Don't change anything following this line!
+VALID_PKG_CONFIG_PATH = FALSE
+
+MSG_INVALID_PKGCONFIG = You must set or specifiy a valid PKG_CONFIG_PATH
+MSG_INVALID_CFG = You need to specify or set CFG to be release or debug to use this Makefile to build the 
Introspection Files
+
+ERROR_MSG =
+
+BUILD_INTROSPECTION = TRUE
+
+!if ![pkg-config --print-errors --errors-to-stdout $(CHECK_PACKAGE) > pkgconfig.x]     \
+       && ![setlocal]  \
+       && ![set file="pkgconfig.x"]    \
+       && ![FOR %A IN (%file%) DO @echo PKG_CHECK_SIZE=%~zA > pkgconfig.chksize]       \
+       && ![del $(ERRNUL) /q/f pkgconfig.x]
+!endif
+
+!include pkgconfig.chksize
+!if "$(PKG_CHECK_SIZE)" == "0"
+VALID_PKG_CONFIG_PATH = TRUE
+!else
+VALID_PKG_CONFIG_PATH = FALSE
+!endif
+
+!if ![del $(ERRNUL) /q/f pkgconfig.chksize]
+!endif
+
+VALID_CFGSET = FALSE
+!if "$(CFG)" == "release" || "$(CFG)" == "debug"
+VALID_CFGSET = TRUE
+!endif
+
+!if "$(VALID_PKG_CONFIG_PATH)" != "TRUE"
+BUILD_INTROSPECTION = FALSE
+ERROR_MSG = $(MSG_INVALID_PKGCONFIG)
+!endif
+
+!if "$(VALID_CFGSET)" != "TRUE"
+BUILD_INTROSPECTION = FALSE
+ERROR_MSG = $(MSG_INVALID_CFG)
+!endif
diff --git a/build/win32/replace.py b/build/win32/replace.py
new file mode 100644
index 0000000..ea75daf
--- /dev/null
+++ b/build/win32/replace.py
@@ -0,0 +1,98 @@
+#!/usr/bin/python
+#
+# Simple utility script to manipulate
+# certain types of strings in a file
+#
+# Author: Fan, Chun-wei
+# Date: September 03, 2014
+
+import os
+import sys
+import re
+import string
+import argparse
+
+valid_actions = ['remove-prefix',
+                 'replace-var',
+                 'replace-str',
+                 'remove-str']
+
+def replace(src, dest, instring, outstring):
+    with open(src, 'r') as s:
+        with open(dest, 'w') as d:
+            for line in s:
+                i = line.replace(instring, outstring)
+                d.write(i)
+
+def check_required_args(args, params):
+    for param in params:
+        if getattr(args, param, None) is None:
+            raise SystemExit('%s: error: --%s argument is required' % (__file__, param))
+
+def warn_ignored_args(args, params):
+    for param in params:
+        if getattr(args, param, None) is not None:
+            print('%s: warning: --%s argument is ignored' % (__file__, param))
+
+def main(argv):
+
+    parser = argparse.ArgumentParser(description='Process strings in a file.')
+    parser.add_argument('-a',
+                        '--action',
+                        help='Action to carry out.  Can be one of:\n'
+                             'remove-prefix\n'
+                             'replace-var\n'
+                             'replace-str\n'
+                             'remove-str',
+                        choices=valid_actions)
+    parser.add_argument('-i', '--input', help='Input file')
+    parser.add_argument('-o', '--output', help='Output file')
+    parser.add_argument('--instring', help='String to replace or remove')
+    parser.add_argument('--var', help='Autotools variable name to replace')
+    parser.add_argument('--outstring',
+                        help='New String to replace specified string or variable')
+    parser.add_argument('--removeprefix', help='Prefix of string to remove')
+
+    args = parser.parse_args()
+
+    input_string = ''
+    output_string = ''
+
+    # We must have action, input, output for all operations
+    check_required_args(args, ['action','input','output'])
+
+    # Build the arguments by the operation that is to be done,
+    # to be fed into replace()
+
+    # Get rid of prefixes from a string
+    if args.action == 'remove-prefix':
+        check_required_args(args, ['instring','removeprefix'])
+        warn_ignored_args(args, ['outstring','var'])
+        input_string = args.removeprefix + args.instring
+        output_string = args.instring
+
+    # Replace an m4-style variable (those surrounded by @...@)
+    if args.action == 'replace-var':
+        check_required_args(args, ['var','outstring'])
+        warn_ignored_args(args, ['instring','removeprefix'])
+        input_string = '@' + args.var + '@'
+        output_string = args.outstring
+
+    # Replace a string
+    if args.action == 'replace-str':
+        check_required_args(args, ['instring','outstring'])
+        warn_ignored_args(args, ['var','removeprefix'])
+        input_string = args.instring
+        output_string = args.outstring
+
+    # Remove a string
+    if args.action == 'remove-str':
+        check_required_args(args, ['instring'])
+        warn_ignored_args(args, ['var','outstring','removeprefix'])
+        input_string = args.instring
+        output_string = ''
+
+    replace(args.input, args.output, input_string, output_string)
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
diff --git a/build/win32/uri.py b/build/win32/uri.py
new file mode 100644
index 0000000..ec6d600
--- /dev/null
+++ b/build/win32/uri.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+#
+# Simple utility script to get URI from a given path
+#
+# Author: Fan, Chun-wei
+# Date: September 03, 2014
+
+import os
+import sys
+import string
+
+def get_abs_path(path):
+    return os.path.abspath(path)
+
+def get_abs_path_posix(path):
+    path_mid = get_abs_path(path)
+    return path_mid.replace('\\','/')
+
+def get_uri_from_path(path):
+    return '/' + get_abs_path_posix(path)
+
+def main(argv):
+    if len(argv) != 2:
+        raise SystemExit('Error: Usage: python %s <path>' % __file__)
+    if not os.path.exists(argv[1]):
+        raise SystemExit('Error: Entered path does not exist')
+    print(get_uri_from_path(argv[1]))
+
+if __name__ == '__main__':
+    sys.exit(main(sys.argv))
diff --git a/configure.ac b/configure.ac
index 448b74f..9469e0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -25,6 +25,9 @@ IT_PROG_INTLTOOL([0.50.1])
 AC_OUTPUT([
 Makefile
 gsettings-desktop-schemas.pc
+build/Makefile
+build/win32/Makefile
+build/win32/gsettings-desktop-schemas-msvc.mak
 headers/Makefile
 schemas/Makefile
 po/Makefile.in
diff --git a/headers/Makefile.am b/headers/Makefile.am
index 27264d5..530a488 100644
--- a/headers/Makefile.am
+++ b/headers/Makefile.am
@@ -22,6 +22,25 @@ typelibdir = $(libdir)/girepository-1.0
 typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
 
 CLEANFILES += $(gir_DATA) $(typelib_DATA)
+
+# -------------------------- Introspection MSVC Build Files ---------
+MSVC_INTROSPECT_GIRS = $(INTROSPECTION_GIRS)
+
+INTROSPECTION_INTERMEDIATE_ITEMS = \
+       $(top_builddir)/build/win32/GDesktopEnums-3.0.gir.msvc.introspect       \
+       $(top_builddir)/build/win32/GDesktopEnums_3_0_gir_list
+
+GDesktopEnums_3_0_gir_MSVC_FILES = \
+    $(GDesktopEnums_3_0_gir_FILES)
+
+GDesktopEnums_3_0_gir_MSVC_SCANNERFLAGS = $(GDesktopEnums_3_0_gir_SCANNERFLAGS)
+
+GDesktopEnums_3_0_gir_MSVC_CFLAGS = -I..\\headers
+
+include $(top_srcdir)/build/Makefile.msvc-introspection
+
+dist-hook: $(INTROSPECTION_INTERMEDIATE_ITEMS)
+# --------------------------------------------------------------------
 endif
 
 -include $(top_srcdir)/git.mk


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