Modernize vala binding generation
authorDaiki Ueno <ueno@unixuser.org>
Tue, 4 Dec 2012 21:11:54 +0000 (06:11 +0900)
committerDaiki Ueno <ueno@unixuser.org>
Tue, 4 Dec 2012 21:11:54 +0000 (06:11 +0900)
Use vapigen.m4 and Makefile.vapigen from vala to handle vapi file
generation.  Also generate vapi always when gir is updated.

BUG=none

Review URL: https://codereview.appspot.com/6849132

bindings/Makefile.am
bindings/vala/Makefile.am
configure.ac
m4/Makefile.am
m4/vapigen.m4 [new file with mode: 0644]

index 8a2854e..868474d 100644 (file)
@@ -20,7 +20,7 @@
 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 # Boston, MA  02111-1307  USA
 
-if ENABLE_VALA
+if ENABLE_VAPIGEN
 VALA_DIR = vala
 endif
 
index f293a84..aba3454 100644 (file)
 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 # Boston, MA  02111-1307  USA
 
-vapidir = $(datadir)/vala/vapi
-dist_vapi_DATA = \
-       ibus-@IBUS_API_VERSION@.vapi \
-       ibus-@IBUS_API_VERSION@.deps \
-       $(NULL)
+-include $(VAPIGEN_MAKEFILE)
 
-# Don't rebuild vapi every time gir is updated.
 vapi_deps = \
-       $(srcdir)/IBus-1.0.metadata \
+       IBus-1.0.metadata \
+       IBus-1.0-custom.vala \
+       $(top_builddir)/src/IBus-1.0.gir \
+       $(NULL)
+
+ibus-1.0.vapi: $(vapi_deps)
+
+VAPIGEN_VAPIS = ibus-1.0.vapi
+
+ibus_1_0_vapi_DEPS = gio-2.0
+ibus_1_0_vapi_METADATADIRS = $(srcdir)
+ibus_1_0_vapi_FILES = \
+       $(top_builddir)/src/IBus-1.0.gir \
        $(srcdir)/IBus-1.0-custom.vala \
-       | \
-       $(top_builddir)/src/IBus-@IBUS_API_VERSION@.gir \
        $(NULL)
 
-ibus-@IBUS_API_VERSION@.vapi: $(vapi_deps)
-       $(AM_V_GEN) $(VAPIGEN) --library ibus-@IBUS_API_VERSION@ \
-                       --pkg gio-2.0 \
-                       --metadatadir=$(srcdir) \
-                       $(top_builddir)/src/IBus-@IBUS_API_VERSION@.gir \
-                       $(srcdir)/IBus-1.0-custom.vala
+vapidir = $(datadir)/vala/vapi
+vapi_DATA = $(VAPIGEN_VAPIS) $(VAPIGEN_VAPIS:.vapi=.deps)
 
 EXTRA_DIST = \
        IBus-1.0.metadata \
        IBus-1.0-custom.vala \
+       ibus-1.0.deps \
        config.vapi \
        xi.vapi \
        $(NULL)
 
-MAINTAINERCLEANFILES = ibus-@IBUS_API_VERSION@.vapi
-
 -include $(top_srcdir)/git.mk
index e784889..0ebd642 100644 (file)
@@ -120,7 +120,7 @@ AC_SUBST(DATE_DISPLAY)
 AC_PROG_CC
 AM_PROG_CC_C_O
 AC_PROG_CC_STDC
-AM_PROG_VALAC([0.14])
+AM_PROG_VALAC([0.16])
 AC_PROG_INSTALL
 AC_PROG_MAKE_SET
 
@@ -192,21 +192,6 @@ AC_ARG_ENABLE(xim,
 )
 AM_CONDITIONAL([ENABLE_XIM], [test x"$enable_xim" = x"yes"])
 
-# --disable-vala option.
-AC_ARG_ENABLE(vala,
-    AS_HELP_STRING([--disable-vala],
-                   [Do not build ibus vala binding]),
-    [enable_vala=$enableval],
-    [enable_vala=yes]
-)
-if test x"$enable_vala" = x"yes"; then
-    AC_PATH_PROG([VAPIGEN], [vapigen], [false])
-fi
-AM_CONDITIONAL([ENABLE_VALA], [test x"$enable_vala" = x"yes"])
-if test x"$enable_vala" != x"yes"; then
-    enable_vala="no (disabled, use --enable-vala to enable)"
-fi
-
 if test x"$enable_gtk2" = x"yes" -o x"$enable_xim" = x"yes" ; then
     # check for gtk2
     PKG_CHECK_MODULES(GTK2, [
@@ -267,6 +252,9 @@ if test x"$found_introspection" = x"yes" ; then
 fi
 AC_SUBST(IBUS_GIR_SCANNERFLAGS)
 
+# Check vapigen.
+VAPIGEN_CHECK([0.16])
+
 # Check for gtk-doc.
 GTK_DOC_CHECK(1.9)
 if test x"$enable_gtk_doc" = x"no"; then
index 3454042..97b4a51 100644 (file)
@@ -22,6 +22,7 @@
 
 EXTRA_DIST = \
     as-version.m4 \
+    vapigen.m4 \
     $(NULL)
 
 GITIGNOREFILES = \
diff --git a/m4/vapigen.m4 b/m4/vapigen.m4
new file mode 100644 (file)
index 0000000..051ccd2
--- /dev/null
@@ -0,0 +1,96 @@
+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],
+[
+  AC_BEFORE([GOBJECT_INTROSPECTION_CHECK],[$0])
+  AC_BEFORE([GOBJECT_INTROSPECTION_REQUIRE],[$0])
+
+  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")
+])