build: Add/use m4 magic for checking Vala bindings
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Mon, 9 Aug 2010 14:01:13 +0000 (17:01 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 10 Aug 2010 12:26:26 +0000 (15:26 +0300)
m4 script from Marc-Andre Lureau <marcandre.lureau@gmail.com>.

configure.ac
m4/vala.m4 [new file with mode: 0644]

index f9f15cb..e0fa157 100644 (file)
@@ -105,49 +105,19 @@ if test x$enable_vala = xyes ; then
     fi
 
     PKG_CHECK_MODULES(GUPNP_VALA, gupnp-vala-1.0 >= $GUPNP_VALA_REQUIRED)
-    VAPIDIR=`pkg-config --variable=vapidir vala-0.10`
-
-    # FIXME: Whats the proper way for checking for particular Vala bindings
-    AC_CHECK_FILE("${VAPIDIR}/gupnp-1.0.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gupnp-1.0")])
-
-    AC_CHECK_FILE("${VAPIDIR}/gupnp-av-1.0.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gupnp-av-1.0")])
-
-    AC_CHECK_FILE("${VAPIDIR}/gupnp-dlna-1.0.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gupnp-dlna-1.0")])
-
-    AC_CHECK_FILE("${VAPIDIR}/dbus-glib-1.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for dbus-glib-1")])
-
-    AC_CHECK_FILE("${VAPIDIR}/gstreamer-0.10.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gstreamer-0.10")])
-
-    AC_CHECK_FILE("${VAPIDIR}/gstreamer-discoverer-gupnp-dlna-0.10.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gstreamer-discoverer-gupnp-dlna-0.10")])
-
-    AC_CHECK_FILE("${VAPIDIR}/gio-2.0.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gio-2.0")])
-
-    AC_CHECK_FILE("${VAPIDIR}/gee-1.0.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for gee-1.0")])
-
-    AC_CHECK_FILE("${VAPIDIR}/sqlite3.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for sqlite3")])
-    AC_CHECK_FILE("${VAPIDIR}/posix.vapi",
-                  true,
-                  [AC_MSG_ERROR("Unable to find Vala bindings for POSIX")])
+
+    VALA_CHECK_PACKAGES([gupnp-1.0
+                         gupnp-av-1.0
+                         gupnp-dlna-1.0
+                         dbus-glib-1
+                         gstreamer-0.10
+                         gstreamer-discoverer-gupnp-dlna-0.10
+                         gio-2.0
+                         gee-1.0
+                         sqlite3
+                         posix])
 else
-    VAPIDIR=`echo ${datadir}/vala-0.10/vapi`
+    VAPIDIR=`echo ${datadir}/vala/vapi`
 fi
 
 AC_SUBST(VAPIDIR)
@@ -196,14 +166,7 @@ if test x$try_ui = xyes ; then
         AC_SUBST(GTK_CFLAGS)
         AC_SUBST(GTK_LIBS)
         if test x$enable_vala = xyes ; then
-                AC_CHECK_FILE("${VAPIDIR}/gtk+-$GTK_VAPI_VERSION.vapi",
-                  [
-                        HAVE_GTK=yes
-                  ],
-                  [
-                        HAVE_GTK=no
-                        AC_MSG_ERROR("Unable to find Vala bindings for gtk+")
-                  ])
+                VALA_CHECK_PACKAGES([gtk+-$GTK_VAPI_VERSION])
         else
                 HAVE_GTK=yes
         fi
diff --git a/m4/vala.m4 b/m4/vala.m4
new file mode 100644 (file)
index 0000000..3735948
--- /dev/null
@@ -0,0 +1,70 @@
+dnl vala.m4
+dnl
+dnl Copyright 2010 Marc-Andre Lureau
+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 -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],
+[
+  ac_save_ifs="$IFS"; unset IFS
+  for vala_pkg in $(echo "$1"); do
+      vala_pkgs="$vala_pkgs --pkg $vala_pkg"
+      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