| 1 |
# Author: Fan, Chun-wei |
| 2 |
# Common autotools file for constructing the g-ir-scanner and |
| 3 |
# g-ir-compiler command lines for Visual Studio builds. |
| 4 |
|
| 5 |
# This is copied from $(srcroot)/build from the gobject-introspection |
| 6 |
# project, which may be included in projects that support both |
| 7 |
# Visual Studio builds and introspection. |
| 8 |
|
| 9 |
# * Input variables: |
| 10 |
# |
| 11 |
# MSVC_INTROSPECT_GIRS - List of .gir's that should be built |
| 12 |
# in the NMake Makefiles |
| 13 |
# |
| 14 |
# * Simple tutorial |
| 15 |
# |
| 16 |
# Add this to Makefile.am where your library/program is built: |
| 17 |
# (Either YourLib_1_0_gir_MSVC_LIBS or YourLib_1_0_gir_MSVC_PROGRAM |
| 18 |
# is required unless --headers-only is specified in |
| 19 |
# YourLib_1_0_gir__MSVC_SCANNERFLAGS) |
| 20 |
# |
| 21 |
# include $(top_srcdir)/build/Makefile.msvc-introspection |
| 22 |
# MSVC_INTROSPECT_GIRS = YourLib-1.0.gir |
| 23 |
# YourLib_1_0_gir_NAMESPACE = YourLib # This is optional |
| 24 |
# YourLib_1_0_gir_VERSION = 1.0 # This is optional |
| 25 |
# YourLib_1_0_gir_MSVC_LIBS = yourlib-1.0 |
| 26 |
# YourLib_1_0_gir_MSVC_FILES = $(libyourlib_1_0_SOURCES) |
| 27 |
# YourLib_1_0_gir_MSVC_PROGRAM = YourProgram |
| 28 |
# YourLib_1_0_gir_MSVC_PACKAGES = (Dependent .pc files) |
| 29 |
# YourLib_1_0_gir_MSVC_INCLUDE_GIRS = (Dependent external .gir's) |
| 30 |
# YourLiv_1_0_gir_MSVC_EXPORT_PACKAGES = (Packages exported by this .gir) |
| 31 |
|
| 32 |
# Private functions |
| 33 |
|
| 34 |
## Transform the MSVC project filename (no filename extensions) to something which can reference through a variable |
| 35 |
## without automake/make complaining, eg Gtk-2.0 -> Gtk_2_0 |
| 36 |
_gir_name=$(subst /,_,$(subst -,_,$(subst .,_,$(1)))) |
| 37 |
|
| 38 |
# Namespace and Version is either fetched from the gir filename |
| 39 |
# or the _NAMESPACE/_VERSION variable combo |
| 40 |
_gir_namespace_msvc = $(or $($(_gir_name)_NAMESPACE),$(firstword $(subst -, ,$(notdir $(1))))) |
| 41 |
_gir_version_msvc = $(or $($(_gir_name)_VERSION),$(lastword $(subst -, ,$(1:.gir=)))) |
| 42 |
_typelib_basename_msvc = $(_gir_namespace_msvc)'-'$(_gir_version_msvc) |
| 43 |
|
| 44 |
# _PROGRAM is an optional variable which needs its own --program argument |
| 45 |
_gir_program_msvc = $(if $($(_gir_name)_MSVC_PROGRAM),--program=$($(_gir_name)_MSVC_PROGRAM)) |
| 46 |
|
| 47 |
# Deduce the sub-folder from $(srcroot) where the sources reside in |
| 48 |
_gir_source_path_raw_msvc:=$(subst $(abs_top_srcdir),,$(abs_srcdir)) |
| 49 |
_gir_source_path_msvc=$(subst /,\\,$(_gir_source_path_raw_msvc)) |
| 50 |
_gir_source_subdir_int_msvc=$(subst \\\\,\\,\\$(_gir_source_path_msvc)\\) |
| 51 |
_gir_source_subdir_msvc=$(subst \\.\\,\\,$(_gir_source_subdir_int_msvc)) |
| 52 |
|
| 53 |
_gir_files_raw_msvc=$(subst /,\\,$($(_gir_name)_MSVC_FILES)) |
| 54 |
_gir_files_msvc=$(subst $(srcdir)\\,,$(subst $(builddir)\\,,$(subst $(top_builddir)\\$(_gir_source_path_msvc)\\,\\,$(_gir_files_raw_msvc)))) |
| 55 |
|
| 56 |
# Create a list of items for: |
| 57 |
# - Libraries |
| 58 |
# - Packages |
| 59 |
# - GIRs to include |
| 60 |
# - packages to export |
| 61 |
|
| 62 |
_gir_libraries_msvc = $(foreach lib,$($(_gir_name)_MSVC_LIBS),--library=$(lib)) |
| 63 |
_gir_packages_msvc = $(foreach pkg,$($(_gir_name)_MSVC_PACKAGES),--pkg=$(pkg)) |
| 64 |
_gir_includes_msvc = $(foreach include,$($(_gir_name)_MSVC_INCLUDE_GIRS),--include=$(include)) |
| 65 |
_gir_export_packages_msvc = $(foreach pkg,$($(_gir_name)_MSVC_EXPORT_PACKAGES),--pkg-export=$(pkg)) |
| 66 |
|
| 67 |
# |
| 68 |
# Create NMake Makefile Sections for Building Introspection files |
| 69 |
# from autotools files |
| 70 |
# $(1) - File Name of the .gir that is to be generated |
| 71 |
# |
| 72 |
|
| 73 |
define gir-nmake-builder |
| 74 |
|
| 75 |
# Basic sanity check, to make sure required variables are set |
| 76 |
$(if $($(_gir_name)_MSVC_FILES),,$(error Need to define $(_gir_name)_MSVC_FILES)) |
| 77 |
$(if $(or $(findstring --header-only,$($(_gir_name)_MSVC_SCANNERFLAGS)), |
| 78 |
$($(_gir_name)_MSVC_LIBS), |
| 79 |
$($(_gir_name)_MSVC_PROGRAM)),, |
| 80 |
$(error Need to define $(_gir_name)_MSVC_LIBS or $(_gir_name)_MSVC_PROGRAM)) |
| 81 |
|
| 82 |
$(top_builddir)/build/win32/$(_gir_name)_list: Makefile |
| 83 |
for F in $(_gir_files_msvc); do \ |
| 84 |
case $$$$F in \ |
| 85 |
*.c|*.cpp|*.cc|*.cxx|*.h|*.hpp|*.hh|*.hxx) \ |
| 86 |
echo '..\..'$(_gir_source_subdir_msvc)$$$$F >>$(top_builddir)/build/win32/$(_gir_name)_list \ |
| 87 |
;; \ |
| 88 |
esac; \ |
| 89 |
done |
| 90 |
|
| 91 |
$(top_builddir)/build/win32/$(1).msvc.introspect: Makefile |
| 92 |
-$(RM) $(top_builddir)/build/win32/$(1).msvc.introspect |
| 93 |
|
| 94 |
# Assemble the Command to Run g-ir-scanner |
| 95 |
echo 'vs$$$$(VSVER)\$$$$(CFG)\$$$$(PLAT)\bin\'$(1)': '$(_gir_name)'_list '$($(_gir_name)_MSVC_GIR_DEPS)>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 96 |
echo ' @-echo Generating $$$$@...'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 97 |
echo ' $$$$(PYTHON) $$$$(G_IR_SCANNER) \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 98 |
echo ' --verbose -no-libtool \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 99 |
echo ' --namespace='$(_gir_namespace_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 100 |
echo ' --nsversion='$(_gir_version_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 101 |
echo ' '$(_gir_packages_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 102 |
echo ' '$(_gir_libraries_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 103 |
echo ' '$(_gir_program_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 104 |
echo ' --add-include-path=./vs$$$$(VSVER)/$$$$(CFG)/$$$$(PLAT)/bin \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 105 |
echo ' --add-include-path=$$$$(G_IR_INCLUDEDIR) \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 106 |
echo ' '$(_gir_includes_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 107 |
echo ' '$(_gir_export_packages_msvc)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 108 |
echo ' --cflags-begin \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 109 |
echo ' '$($(_gir_name)_MSVC_CFLAGS)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 110 |
echo ' --cflags-end \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 111 |
echo ' '$($(_gir_name)_MSVC_SCANNERFLAGS)' \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 112 |
echo ' --filelist='$(_gir_name)'_list \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 113 |
echo ' -L.\vs$$$$(VSVER)\$$$$(CFG)\$$$$(PLAT)\bin \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 114 |
echo ' -o $$$$@'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 115 |
echo '' >>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 116 |
|
| 117 |
# Finally Assemble the Command to Compile the generated .gir |
| 118 |
echo 'vs$$$$(VSVER)\$$$$(CFG)\$$$$(PLAT)\bin\$(_typelib_basename_msvc).typelib: vs$$$$(VSVER)\$$$$(CFG)\$$$$(PLAT)\bin\'$(_typelib_basename_msvc)'.gir'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 119 |
echo ' @-echo Compiling $$$$@...'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 120 |
echo ' $$$$(G_IR_COMPILER) \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 121 |
echo ' --includedir=$$$$(@D:\=/) --debug --verbose \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 122 |
echo ' $$$$(@R:\=/).gir \'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 123 |
echo ' -o $$$$@'>>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 124 |
echo '' >>$(top_builddir)/build/win32/$(1).msvc.introspect |
| 125 |
endef |
| 126 |
|
| 127 |
$(foreach gir,$(MSVC_INTROSPECT_GIRS),$(eval $(call gir-nmake-builder,$(gir)))) |