[template-glib] vala: add support for generating vala vapi



commit 878f0ac775406bf7dd65ae2e7b4130925889cbb3
Author: Christian Hergert <christian hergert me>
Date:   Sat Jan 23 11:44:19 2016 -0800

    vala: add support for generating vala vapi

 Makefile.am          |    2 +
 build-aux/vala.m4    |  135 ++++++++++++++++++++++++++++++++++++++++++++++++++
 build-aux/vapigen.m4 |  101 +++++++++++++++++++++++++++++++++++++
 configure.ac         |    3 +
 src/Makefile.am      |   22 ++++++++
 5 files changed, 263 insertions(+), 0 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index b27de56..73f3d60 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,7 @@
 SUBDIRS = data src tests po doc examples
 
+ACLOCAL_AMFLAGS = -I build-aux
+
 EXTRA_DIST = \
        AUTHORS \
        $(NULL)
diff --git a/build-aux/vala.m4 b/build-aux/vala.m4
new file mode 100644
index 0000000..4393866
--- /dev/null
+++ b/build-aux/vala.m4
@@ -0,0 +1,135 @@
+dnl vala.m4
+dnl
+dnl Copyright 2010 Marc-Andre Lureau
+dnl Copyright 2011 Rodney Dawes <dobey pwns gmail com>
+dnl
+dnl This library is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU Lesser General Public
+dnl License as published by the Free Software Foundation; either
+dnl version 2.1 of the License, or (at your option) any later version.
+dnl
+dnl This library is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl Lesser General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU Lesser General Public
+dnl License along with this library; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+
+# _VALA_CHECK_COMPILE_WITH_ARGS(ARGS, [ACTION-IF-TRUE],
+#   [ACTION-IF-FALSE])
+# --------------------------------------
+# Check that Vala compile with ARGS.
+#
+AC_DEFUN([_VALA_CHECK_COMPILE_WITH_ARGS],
+[AC_REQUIRE([AM_PROG_VALAC])[]dnl
+
+  cat <<_ACEOF >conftest.vala
+void main(){}
+_ACEOF
+
+  AS_IF([vala_error=`$VALAC $1 -q --cc="${CC} ${CPPFLAGS} ${CFLAGS} ${LDFLAGS}" -o conftest$ac_exeext 
conftest.vala 2>&1`],
+        [$2], [$3])
+])
+
+])# _VALA_CHECK_COMPILE_WITH_ARGS
+
+# VALA_CHECK_PACKAGES(PKGS, [ACTION-IF-FOUND],
+#   [ACTION-IF-NOT-FOUND])
+# --------------------------------------
+# Check that PKGS Vala bindings are installed and usable.
+#
+AC_DEFUN([VALA_CHECK_PACKAGES],
+[
+  unset vala_pkgs
+  unset vala_bindings
+  ac_save_ifs="$IFS"; unset IFS
+  for vala_pkg in $(echo "$1"); do
+      vala_pkgs="${vala_pkgs:+$vala_pkgs }--pkg $vala_pkg"
+      vala_bindings="${vala_bindings:+$vala_bindings }$vala_pkg"
+  done
+  IFS="$ac_save_ifs"
+  AC_MSG_CHECKING([for $vala_bindings vala bindings])
+  _VALA_CHECK_COMPILE_WITH_ARGS([$vala_pkgs],
+    [vala_pkg_exists=yes],
+    [vala_pkg_exists=no])
+
+AS_IF([test x${vala_pkg_exists} = xno],[
+  ifelse([$3], , [AC_MSG_ERROR([]dnl
+[Package requirements were not met: $1
+
+$vala_error
+
+Consider adjusting the XDG_DATA_DIRS environment variable if you
+installed bindings in a non-standard prefix.
+])],
+  [AC_MSG_RESULT([no])
+$3])],[
+  AC_MSG_RESULT([yes])
+  ifelse([$2], , :, [$2])[]dnl
+])
+
+])# VALA_CHECK_PACKAGES
+
+
+# Check for Vala bindings for a package, as well as the pkg-config
+# CFLAGS and LIBS for the package. The arguments here work the
+# same as those for PKG_CHECK_MODULES, which is called internally.
+# As a result, the _CFLAGS, _LIBS, and _VALAFLAGS variables will
+# all be declared, rather than only _VALAFLAGS.
+#
+# VALA_CHECK_MODULES(VARIABLE-PREFIX, MODULES, [ACTION-IF-FOUND],
+# [ACTION-IF-NOT-FOUND])
+# --------------------------------------------------------------
+AC_DEFUN([VALA_CHECK_MODULES],
+[
+               AC_REQUIRE([AM_PROG_VALAC])dnl
+               AC_REQUIRE([PKG_PROG_PKG_CONFIG])dnl
+        AC_REQUIRE([_VALA_CHECK_COMPILE_WITH_ARGS])dnl
+               AC_ARG_VAR([$1][_VALAFLAGS], [Vala compiler flags for $1])dnl
+
+        VALA_MODULES="`echo $2 | sed -e 's/ [[=<>]]\+ [[0-9.]]\+//g'`"
+        for MODULE in $VALA_MODULES; do
+            $1[]_VALAFLAGS="$[]$1[]_VALAFLAGS --pkg $MODULE"
+        done
+
+        PKG_CHECK_MODULES([$1], [$2], [$3], [$4])
+
+        pkg_failed=no
+               AC_MSG_CHECKING([for $1 vala modules])
+
+        _VALA_CHECK_COMPILE_WITH_ARGS([$1][_VALAFLAGS],
+                                      [pkg_failed=yes],
+                                      [pkg_failed=no])
+
+               if test $pkg_failed = yes; then
+                  AC_MSG_RESULT([no])
+                  m4_default([$4], [AC_MSG_ERROR(
+                                                       [Package requirements ($2) were not met.])dnl
+                  ])
+               else
+                       AC_MSG_RESULT([yes])
+                       m4_default([$3], [:])
+               fi[]dnl
+])
+
+# Check whether the Vala API Generator exists in `PATH'. If it is found,
+# the variable VAPIGEN is set. Optionally a minimum release number of the
+# generator can be requested.
+#
+# VALA_PROG_VAPIGEN([MINIMUM-VERSION])
+# ------------------------------------
+AC_DEFUN([VALA_PROG_VAPIGEN],
+[AC_PATH_PROG([VAPIGEN], [vapigen], [])
+  AS_IF([test -z "$VAPIGEN"],
+    [AC_MSG_WARN([No Vala API Generator found. You will not be able to generate .vapi files.])],
+    [AS_IF([test -n "$1"],
+        [AC_MSG_CHECKING([$VAPIGEN is at least version $1])
+         am__vapigen_version=`$VAPIGEN --version | sed 's/Vala API Generator  *//'`
+         AS_VERSION_COMPARE([$1], ["$am__vapigen_version"],
+           [AC_MSG_RESULT([yes])],
+           [AC_MSG_RESULT([yes])],
+           [AC_MSG_RESULT([no])
+            AC_MSG_ERROR([Vala API Generator $1 not found.])])])])
+])
diff --git a/build-aux/vapigen.m4 b/build-aux/vapigen.m4
new file mode 100644
index 0000000..2c435e7
--- /dev/null
+++ b/build-aux/vapigen.m4
@@ -0,0 +1,101 @@
+dnl vapigen.m4
+dnl
+dnl Copyright 2012 Evan Nemerson
+dnl
+dnl This library is free software; you can redistribute it and/or
+dnl modify it under the terms of the GNU Lesser General Public
+dnl License as published by the Free Software Foundation; either
+dnl version 2.1 of the License, or (at your option) any later version.
+dnl
+dnl This library is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+dnl Lesser General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU Lesser General Public
+dnl License along with this library; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+
+# VAPIGEN_CHECK([VERSION], [API_VERSION], [FOUND_INTROSPECTION], [DEFAULT])
+# --------------------------------------
+# Check vapigen existence and version
+#
+# See http://live.gnome.org/Vala/UpstreamGuide for detailed documentation
+AC_DEFUN([VAPIGEN_CHECK],
+[
+  AS_IF([test "x$3" != "xyes"], [
+      m4_provide_if([GOBJECT_INTROSPECTION_CHECK], [], [
+          m4_provide_if([GOBJECT_INTROSPECTION_REQUIRE], [], [
+              AC_MSG_ERROR([[You must call GOBJECT_INTROSPECTION_CHECK or GOBJECT_INTROSPECTION_REQUIRE 
before using VAPIGEN_CHECK unless using the FOUND_INTROSPECTION argument is "yes"]])
+            ])
+        ])
+    ])
+
+  AC_ARG_ENABLE([vala],
+    [AS_HELP_STRING([--enable-vala[=@<:@no/auto/yes@:>@]],[build Vala bindings 
@<:@default=]ifelse($4,,auto,$4)[@:>@])],,[
+      AS_IF([test "x$4" = "x"], [
+          enable_vala=auto
+        ], [
+          enable_vala=$4
+        ])
+    ])
+
+  AS_CASE([$enable_vala], [no], [enable_vala=no],
+      [yes], [
+        AS_IF([test "x$3" != "xyes" -a "x$found_introspection" != "xyes"], [
+            AC_MSG_ERROR([Vala bindings require GObject Introspection])
+          ])
+      ], [auto], [
+        AS_IF([test "x$3" != "xyes" -a "x$found_introspection" != "xyes"], [
+            enable_vala=no
+          ])
+      ], [
+        AC_MSG_ERROR([Invalid argument passed to --enable-vala, should be one of @<:@no/auto/yes@:>@])
+      ])
+
+  AS_IF([test "x$2" = "x"], [
+      vapigen_pkg_name=vapigen
+    ], [
+      vapigen_pkg_name=vapigen-$2
+    ])
+  AS_IF([test "x$1" = "x"], [
+      vapigen_pkg="$vapigen_pkg_name"
+    ], [
+      vapigen_pkg="$vapigen_pkg_name >= $1"
+    ])
+
+  PKG_PROG_PKG_CONFIG
+
+  PKG_CHECK_EXISTS([$vapigen_pkg], [
+      AS_IF([test "$enable_vala" = "auto"], [
+          enable_vala=yes
+        ])
+    ], [
+      AS_CASE([$enable_vala], [yes], [
+          AC_MSG_ERROR([$vapigen_pkg not found])
+        ], [auto], [
+          enable_vala=no
+        ])
+    ])
+
+  AC_MSG_CHECKING([for vapigen])
+
+  AS_CASE([$enable_vala],
+    [yes], [
+      VAPIGEN=`$PKG_CONFIG --variable=vapigen $vapigen_pkg_name`
+      VAPIGEN_MAKEFILE=`$PKG_CONFIG --variable=datadir $vapigen_pkg_name`/vala/Makefile.vapigen
+      AS_IF([test "x$2" = "x"], [
+          VAPIGEN_VAPIDIR=`$PKG_CONFIG --variable=vapidir $vapigen_pkg_name`
+        ], [
+          VAPIGEN_VAPIDIR=`$PKG_CONFIG --variable=vapidir_versioned $vapigen_pkg_name`
+        ])
+    ])
+
+  AC_MSG_RESULT([$enable_vala])
+
+  AC_SUBST([VAPIGEN])
+  AC_SUBST([VAPIGEN_VAPIDIR])
+  AC_SUBST([VAPIGEN_MAKEFILE])
+
+  AM_CONDITIONAL(ENABLE_VAPIGEN, test "x$enable_vala" = "xyes")
+])
diff --git a/configure.ac b/configure.ac
index dbf2b2c..608a7b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -63,12 +63,14 @@ AC_PROG_CC
 AC_PROG_INSTALL
 AM_PROG_LEX
 AC_PROG_YACC
+AM_PROG_VALAC
 AC_PATH_PROG([GLIB_GENMARSHAL], [glib-genmarshal])
 AC_PATH_PROG([GLIB_MKENUMS], [glib-mkenums])
 AC_PATH_PROG([GLIB_COMPILE_RESOURCES], [glib-compile-resources])
 PKG_PROG_PKG_CONFIG([0.22])
 GOBJECT_INTROSPECTION_CHECK([1.42.0])
 GLIB_GSETTINGS
+VAPIGEN_CHECK
 
 
 dnl ***********************************************************************
@@ -272,5 +274,6 @@ echo "  Enable Profiling (-pg)................ : ${enable_profiling}"
 echo "  Build Test Suite ..................... : ${enable_tests}"
 echo "  Build API reference .................. : ${enable_gtk_doc}"
 echo "  Use cross-referencing in API docs .... : ${enable_doc_cross_references}"
+echo "  Vala support ......................... : ${enable_vala}"
 echo ""
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 3469ca9..24bfc4e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -131,6 +131,28 @@ typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
 CLEANFILES += $(gir_DATA) $(typelib_DATA)
 endif
 
+if ENABLE_VAPIGEN
+-include $(VAPIGEN_MAKEFILE)
+
+template-glib-1.0.vapi: Template-1.0.gir
+
+VAPIGEN_VAPIS = template-glib-1.0.vapi
+
+template_glib_1_0_vapi_DEPS = gio-2.0
+template_glib_1_0_vapi_METADATADIRS = $(srcdir)
+template_glib_1_0_vapi_FILES = Template-1.0.gir
+
+template-glib-1.0.deps: Makefile
+       $(AM_V_GEN) echo $(template_glib_1_0_vapi_DEPS) | tr ' ' '\n' > $@
+
+vapidir = $(datadir)/vala/vapi/
+vapi_DATA = $(VAPIGEN_VAPIS) $(VAPIGEN_VAPIS:.vapi=.deps)
+
+EXTRA_DIST += template-glib-1.0.deps
+
+DISTCLEANFILES += $(vapi_DATA)
+endif
+
 GITIGNOREFILES = \
        tmpl-expr-parser.c \
        tmpl-expr-parser.h \


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