[json-glib] build: Add common autotools modules for MSVC build files



commit d1119d775c5c2c7d630b77ee6855b67f66d92e31
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jan 4 13:49:53 2016 +0800

    build: Add common autotools modules for MSVC build files
    
    This adds autotools modules that are directly copied from (and shared with)
    the ones that are in GLib and GObject-introspection, where:
    
    Makefile.msvcproj: Creates the complete MSVC 2008/2010 project files for
                       building the main JSON-GLib DLL and the property sheets
                       for "installing" JSON-GLib, in particular the headers,
                       aimed to clean up the json-glib/Makefile.am in particular.
    
    Makefile-newvs.am: Copies the MSVC 2010 projects and replace the necessary
                       items so that we can support Visual Studio 2012-2015 out
                       of the box.
    
    Makefile.msvc-introspection: Creates the full NMake Makefile snippet that
                                 contains the full command lines for g-ir-scanner
                                 and g-ir-compiler to build the introspection
                                 files for JSON-GLib for MSVC builds.

 build/Makefile-newvs.am           |   45 +++++++++++++
 build/Makefile.msvc-introspection |  125 +++++++++++++++++++++++++++++++++++++
 build/Makefile.msvcproj           |  107 +++++++++++++++++++++++++++++++
 3 files changed, 277 insertions(+), 0 deletions(-)
---
diff --git a/build/Makefile-newvs.am b/build/Makefile-newvs.am
new file mode 100644
index 0000000..97b2459
--- /dev/null
+++ b/build/Makefile-newvs.am
@@ -0,0 +1,45 @@
+# Centralized autotools file
+# Create the Visual Studio 2012/2013/2015 project files
+# from the Visual Studio 2010 project files
+
+# This autotools file, from GLib, can be used in other projects
+# that have Visual Studio build support, and is copied into
+# $(srcroot)/build/.
+
+# Author: Fan, Chun-wei
+# November 05, 2012
+
+# MSVC_VER_LONG: Long Version of Visual Studio (2012, 2013, 14 and so on)
+# MSVC_VER: Short Version of Visual Studio (11 for 2012, 12 for 2013, 14 for 2015 and so on)
+# MSVC_FORMAT_VER: Use 12 for MSVC 2012 through 2015
+
+%.sln:
+       sed 's/11\.00/$(MSVC_FORMAT_VER)\.00/g' < $(top_srcdir)/build/win32/vs10/$@ > 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$  tmp
+       sed 's/2010/$(MSVC_VER_LONG)/g' < $(top_builddir)/build/win32/vs$(MSVC_VER)/$  tmp > 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$@
+       rm $(top_builddir)/build/win32/vs$(MSVC_VER)/$  tmp
+
+%.txt:
+       sed 's/vs10/vs$(MSVC_VER)/g' < $(top_srcdir)/build/win32/vs10/$@ > 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$  tmp
+       sed 's/VS10/VS$(MSVC_VER)/g' < $(top_builddir)/build/win32/vs$(MSVC_VER)/$  tmp > 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$@
+       rm $(top_builddir)/build/win32/vs$(MSVC_VER)/$  tmp
+
+%.vcxproj:
+       if test -e $(top_srcdir)/build/win32/vs10/$@; then \
+               sed 's/v100/v$(MSVC_VER)0/g' < $(top_srcdir)/build/win32/vs10/$@ > 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$@; \
+       else \
+               sed 's/v100/v$(MSVC_VER)0/g' < $(top_builddir)/build/win32/vs10/$@ > 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$@; \
+       fi
+
+%.props:
+       if test -e $(top_srcdir)/build/win32/vs10/$@; then \
+               sed 's/<VSVer>10<\/VSVer>/<VSVer>$(MSVC_VER)<\/VSVer>/g' < $(top_srcdir)/build/win32/vs10/$@ 
$(top_builddir)/build/win32/vs$(MSVC_VER)/$@; \
+       else \
+               sed 's/<VSVer>10<\/VSVer>/<VSVer>$(MSVC_VER)<\/VSVer>/g' < 
$(top_builddir)/build/win32/vs10/$@ > $(top_builddir)/build/win32/vs$(MSVC_VER)/$@; \
+       fi
+
+%.vcxproj.filters:
+       if test -e $(top_srcdir)/build/win32/vs10/$@; then \
+               cp $(top_srcdir)/build/win32/vs10/$@ $(top_builddir)/build/win32/vs$(MSVC_VER)/$@; \
+       else \
+               cp $(top_builddir)/build/win32/vs10/$@ $(top_builddir)/build/win32/vs$(MSVC_VER)/$@; \
+       fi
diff --git a/build/Makefile.msvc-introspection b/build/Makefile.msvc-introspection
new file mode 100644
index 0000000..6c90964
--- /dev/null
+++ b/build/Makefile.msvc-introspection
@@ -0,0 +1,125 @@
+# Author: Fan, Chun-wei
+# Common autotools file for constructing the g-ir-scanner and
+# g-ir-compiler command lines for Visual Studio builds.
+
+# This is copied from $(srcroot)/build from the gobject-introspection
+# project, which may be included in projects that support both
+# Visual Studio builds and introspection.
+
+# * Input variables:
+#
+#   MSVC_INTROSPECT_GIRS - List of .gir's that should be built
+#                          in the NMake Makefiles
+#
+# * Simple tutorial
+#
+# Add this to Makefile.am where your library/program is built:
+#   (Either YourLib_1_0_gir_MSVC_LIBS or YourLib_1_0_gir_MSVC_PROGRAM
+#    is required unless --headers-only is specified in
+#    YourLib_1_0_gir__MSVC_SCANNERFLAGS)
+#
+#   include $(top_srcdir)/build/Makefile.msvc-introspection
+#   MSVC_INTROSPECT_GIRS = YourLib-1.0.gir
+#   YourLib_1_0_gir_NAMESPACE = YourLib # This is optional
+#   YourLib_1_0_gir_VERSION = 1.0 # This is optional
+#   YourLib_1_0_gir_MSVC_LIBS = yourlib-1.0
+#   YourLib_1_0_gir_MSVC_FILES = $(libyourlib_1_0_SOURCES)
+#   YourLib_1_0_gir_MSVC_PROGRAM = YourProgram
+#   YourLib_1_0_gir_MSVC_PACKAGES = (Dependent .pc files)
+#   YourLib_1_0_gir_MSVC_INCLUDE_GIRS = (Dependent external .gir's)
+#   YourLiv_1_0_gir_MSVC_EXPORT_PACKAGES = (Packages exported by this .gir)
+
+# Private functions
+
+## Transform the MSVC project filename (no filename extensions) to something which can reference through a 
variable
+## without automake/make complaining, eg Gtk-2.0 -> Gtk_2_0
+_gir_name=$(subst /,_,$(subst -,_,$(subst .,_,$(1))))
+
+# Namespace and Version is either fetched from the gir filename
+# or the _NAMESPACE/_VERSION variable combo
+_gir_namespace_msvc = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(notdir $(1)))))
+_gir_version_msvc = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=))))
+_typelib_basename_msvc = $(_gir_namespace_msvc)'-'$(_gir_version_msvc)
+
+# _PROGRAM is an optional variable which needs its own --program argument
+_gir_program_msvc = $(if $($(_gir_name)_MSVC_PROGRAM),--program=$($(_gir_name)_MSVC_PROGRAM))
+
+# Deduce the sub-folder from $(srcroot) where the sources reside in
+_gir_source_path_raw_msvc:=$(subst $(abs_top_srcdir),,$(abs_srcdir))
+_gir_source_path_msvc=$(subst /,\\,$(_gir_source_path_raw_msvc))
+_gir_source_subdir_int_msvc=$(subst \\\\,\\,\\$(_gir_source_path_msvc)\\)
+_gir_source_subdir_msvc=$(subst \\.\\,\\,$(_gir_source_subdir_int_msvc))
+
+_gir_files_raw_msvc=$(subst /,\\,$($(_gir_name)_MSVC_FILES))
+_gir_files_msvc=$(subst $(srcdir)\\,,$(subst $(builddir)\\,,$(subst 
$(top_builddir)\\$(_gir_source_path_msvc)\\,\\,$(_gir_files_raw_msvc))))
+
+# Create a list of items for:
+# - Libraries
+# - Packages
+# - GIRs to include
+# - packages to export
+
+_gir_libraries_msvc = $(foreach lib,$($(_gir_name)_MSVC_LIBS),--library=$(lib))
+_gir_packages_msvc = $(foreach pkg,$($(_gir_name)_MSVC_PACKAGES),--pkg=$(pkg))
+_gir_includes_msvc = $(foreach include,$($(_gir_name)_MSVC_INCLUDE_GIRS),--include=$(include))
+_gir_export_packages_msvc = $(foreach pkg,$($(_gir_name)_MSVC_EXPORT_PACKAGES),--pkg-export=$(pkg))
+
+#
+# Create NMake Makefile Sections for Building Introspection files
+# from autotools files
+# $(1) - File Name of the .gir that is to be generated
+#
+
+define gir-nmake-builder
+
+# Basic sanity check, to make sure required variables are set
+$(if $($(_gir_name)_MSVC_FILES),,$(error Need to define $(_gir_name)_MSVC_FILES))
+$(if $(or $(findstring --header-only,$($(_gir_name)_MSVC_SCANNERFLAGS)),
+          $($(_gir_name)_MSVC_LIBS),
+          $($(_gir_name)_MSVC_PROGRAM)),,
+    $(error Need to define $(_gir_name)_MSVC_LIBS or $(_gir_name)_MSVC_PROGRAM))
+
+$(top_builddir)/build/win32/$(_gir_name)_list:
+       for F in $(_gir_files_msvc); do \
+               case $$$$F in \
+               *.c|*.cpp|*.cc|*.cxx|*.h|*.hpp|*.hh|*.hxx) \
+                       echo '..\..'$(_gir_source_subdir_msvc)$$$$F 
$(top_builddir)/build/win32/$(_gir_name)_list \
+                       ;; \
+               esac; \
+       done
+
+$(top_builddir)/build/win32/$(1).msvc.introspect:
+       -$(RM) $(top_builddir)/build/win32/$(1).msvc.introspect
+
+# Assemble the Command to Run g-ir-scanner
+       echo $(1)': '$(_gir_name)'_list 
'$($(_gir_name)_MSVC_GIR_DEPS)>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  @-echo Generating $$$$    '>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  $$$$(PYTHON) $$$$(G_IR_SCANNER) \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --verbose -no-libtool   \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --namespace='$(_gir_namespace_msvc)'    \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --nsversion='$(_gir_version_msvc)'      \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$(_gir_packages_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$(_gir_libraries_msvc)'        \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$(_gir_program_msvc)'  \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --add-include-path=$$$$(G_IR_INCLUDEDIR)        
\'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$(_gir_includes_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$(_gir_export_packages_msvc)'  \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --cflags-begin  \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$($(_gir_name)_MSVC_CFLAGS)'   \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --cflags-end    \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$($(_gir_name)_MSVC_SCANNERFLAGS)'     \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --filelist='$(_gir_name)'_list  \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  -o $$$$@'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '' >>$(top_builddir)/build/win32/$(1).msvc.introspect
+
+# Finally Assemble the Command to Compile the generated .gir
+       echo '$(_typelib_basename_msvc).typelib: 
'$(_typelib_basename_msvc)'.gir'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  @-echo Compiling $$$$    '>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  $$$$(G_IR_COMPILER)     \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  --includedir=. --debug --verbose        \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  '$(1)'  \'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '  -o $$$$@'>>$(top_builddir)/build/win32/$(1).msvc.introspect
+       echo '' >>$(top_builddir)/build/win32/$(1).msvc.introspect
+endef
+
+$(foreach gir,$(MSVC_INTROSPECT_GIRS),$(eval $(call gir-nmake-builder,$(gir))))
diff --git a/build/Makefile.msvcproj b/build/Makefile.msvcproj
new file mode 100644
index 0000000..9449a5b
--- /dev/null
+++ b/build/Makefile.msvcproj
@@ -0,0 +1,107 @@
+# Author: Fan, Chun-wei
+# Common Autotools file used to generate Visual Studio 2008+
+# Projects from their templates
+
+# This autotools file, from GLib, can be used in other projects
+# that have Visual Studio build support, and is copied into
+# $(srcroot)/build/.
+
+# * Input variables:
+#
+#   MSVCPROJS - List of Projects that should be generated
+#
+# * Simple tutorial
+#
+# Add this to Makefile.am where your library/program is built:
+#   include $(top_srcdir)/build/Makefile.msvcproj
+#   MSVCPROJS = YourProject (can be multiple projects in a single srcdir)
+#   YourProject_FILES = $(libyourlib_1_0_SOURCES)
+#   YourProject_EXCLUDES = ... # list of sources to exclude, separated by '|', wildcards allowed; use random 
unsed value if none
+#   YourProject_HEADERS_DIR = $(libyourlibincludedir)
+#   YourProject_HEADERS_INST = $(libyourlib_1_0_HEADERS)
+#   YourProject_HEADERS_EXCLUDES = ... # <list of headers to exclude from installation, separated by '|', 
wildcards allowed; use random unsed value if none>
+#
+#   dist-hook: \ # (or add to it if it is already there, note the vs9 items will also call the vs10 items in 
the process)
+#      $(top_builddir)/build/win32/vs9/YourProject.vcproj      \
+#      $(top_builddir)/build/win32/vs9/YourProject.headers
+
+
+# Private functions
+
+## Transform the MSVC project filename (no filename extensions) to something which can reference through a 
variable
+## without automake/make complaining, eg Gtk-2.0 -> Gtk_2_0
+_proj_name=$(subst /,_,$(subst -,_,$(subst .,_,$(1))))
+_proj_path_raw:=$(subst $(abs_top_srcdir),,$(abs_srcdir))
+_proj_path=$(subst /,\\,$(_proj_path_raw))
+_proj_subdir_int=$(subst \\\\,\\,\\$(_proj_path)\\)
+_proj_subdir=$(subst \\.\\,\\,$(_proj_subdir_int))
+
+_proj_files_raw=$(subst /,\\,$($(_proj_name)_FILES))
+_proj_files=$(subst $(srcdir)\\,,$(subst $(builddir)\\,,$(subst 
$(top_builddir)\\$(_proj_path)\\,\\,$(_proj_files_raw))))
+_proj_filters=$($(_proj_name)_EXCLUDES)
+
+_proj_headers_raw=$(subst /,\\,$($(_proj_name)_HEADERS_INST))
+_proj_headers=$(subst $(srcdir)\\,,$(subst $(builddir)\\,,$(subst 
$(top_builddir)\\$(_proj_path)\\,\\,$(_proj_headers_raw))))
+_proj_headers_excludes=$($(_proj_name)_HEADERS_EXCLUDES)
+
+_headers_dest_posix=$(subst $(includedir),,$($(_proj_name)_HEADERS_DIR))
+_headers_destdir=$(subst /,\\,$(_headers_dest_posix))
+
+#
+# Creates Visual Studio 2008/2010 projects from items passed in from autotools files
+# $(1) - Base Name of the MSVC project files (outputs)
+#
+
+define msvcproj-builder
+
+$(top_builddir)/build/win32/vs10/$(1).vcxproj: $(top_builddir)/build/win32/vs9/$(1).vcproj
+$(top_builddir)/build/win32/vs10/$(1).vcxproj.filters: $(top_builddir)/build/win32/vs9/$(1).vcproj
+$(1).sourcefiles: $(top_builddir)/build/win32/vs9/$(1).vcproj
+$(1).vs10.sourcefiles: $(top_builddir)/build/win32/vs9/$(1).vcproj
+$(1).vs10.sourcefiles.filters: $(top_builddir)/build/win32/vs9/$(1).vcproj
+
+$(top_builddir)/build/win32/vs9/$(1).vcproj:
+       -$(RM) $(top_builddir)/build/win32/vs9/$(1).vcproj
+       -$(RM) $(top_builddir)/build/win32/vs10/$(1).vcxproj
+       -$(RM) $(top_builddir)/build/win32/vs10/$(1).vcxproj.filters
+
+       for F in $(_proj_files); do \
+               case $$$$F in \
+               $(_proj_filters)) \
+                       ;; \
+               *.c|*.cpp|*.cc|*.cxx) \
+                       echo '   <File RelativePath="..\..\..'$(_proj_subdir)$$$$F'" />' >>$(1).sourcefiles 
&& \
+                       echo '   <ClCompile Include="..\..\..'$(_proj_subdir)$$$$F'" />' 
$(1).vs10.sourcefiles && \
+                       echo '   <ClCompile Include="..\..\..'$(_proj_subdir)$$$$F'"><Filter>Source 
Files</Filter></ClCompile>' >>$(1).vs10.sourcefiles.filters \
+                       ;; \
+               esac;   \
+       done
+
+
+       $(CPP) -P - <$(top_srcdir)/build/win32/vs9/$(1).vcprojin >$(top_builddir)/build/win32/vs9/$(1).vcproj
+       $(CPP) -P - <$(top_srcdir)/build/win32/vs10/$(1).vcxprojin 
$(top_builddir)/build/win32/vs10/$(1).vcxproj
+       $(CPP) -P - <$(top_srcdir)/build/win32/vs10/$(1).vcxproj.filtersin 
$(top_builddir)/build/win32/vs10/$(1).vcxproj.filters
+       $(RM) $(1).sourcefiles
+       $(RM) $(1).vs10.sourcefiles
+       $(RM) $(1).vs10.sourcefiles.filters
+
+$(top_builddir)/build/win32/vs10/$(1).vs10.headers: $(top_builddir)/build/win32/vs9/$(1).headers
+
+$(top_builddir)/build/win32/vs9/$(1).headers:
+       -$(RM) $(top_builddir)/build/win32/vs9/$(1).headers
+       -$(RM) $(top_builddir)/build/win32/vs10/$(1).vs10.headers
+
+       for F in $(_proj_headers); do \
+               case $$$$F in \
+               $(_proj_headers_excludes)) \
+                       ;; \
+               *.h|*.hpp|*.hh|*.hxx) \
+                       echo 'copy ..\..\..'$(_proj_subdir)$$$$F' 
$$$$(CopyDir)\include'$(_headers_destdir)'\'$$$$F'&#x0D;&#x0A;' 
$(top_builddir)/build/win32/vs9/$(1).headers && \
+                       echo 'copy ..\..\..'$(_proj_subdir)$$$$F' 
$$$$(CopyDir)\include'$(_headers_destdir)'\'$$$$F >>$(top_builddir)/build/win32/vs10/$(1).vs10.headers \
+                       ;; \
+               esac;   \
+       done
+
+endef
+
+$(foreach proj,$(MSVCPROJS),$(eval $(call msvcproj-builder,$(proj))))


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