[libgda] Moved MDB detection to mdbtools.m4 and M4 files in m4/ dir



commit b14e9197a25151082f1e6e52f6216d6c853386f5
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Sep 24 22:07:27 2010 +0200

    Moved MDB detection to mdbtools.m4 and M4 files in m4/ dir

 configure.ac                            |   88 +------------
 introspection.m4 => m4/introspection.m4 |    0
 m4/mdbtools.m4                          |  213 +++++++++++++++++++++++++++++++
 3 files changed, 218 insertions(+), 83 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index c0a3041..06d768e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,8 @@ m4_define(minor, 1)
 m4_define(micro, 11)
 m4_define([gda_stable],
 	m4_if(m4_eval(minor % 2), [0], [yes], [no])) 
-m4_include(introspection.m4)
+m4_include(m4/introspection.m4)
+m4_include(m4/mdbtools.m4)
 
 AC_INIT(GNU Data Access, major.minor.micro, gnome-db-list gnome org, libgda)
 AC_PREREQ(2.59)
@@ -12,7 +13,6 @@ AM_INIT_AUTOMAKE(1.8 -Wall no-define dist-bzip2)
 
 m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
 
-
 AC_SUBST(GDA_VERSION, major.minor.micro)
 
 # ABI version:
@@ -33,7 +33,7 @@ m4_undefine([minor])
 m4_undefine([micro])
 
 dnl required versions of other tools.
-m4_define([req_ver_glib],	[2.12.11])
+m4_define([req_ver_glib],[2.12.11])
 
 #
 # Making releases:
@@ -1195,83 +1195,7 @@ fi
 AM_CONDITIONAL(XBASE, test x$xbasedir != x)
 
 dnl Test for MDB Tools (for MS Access files)
-try_mdb=true
-AC_ARG_WITH(mdb,
-[  --with-mdb=<directory>     use MDB tools library in <directory>],[
-if test $withval = no
-then
-	try_mdb=false
-elif test $withval = yes
-then
-	dir="/usr/local"
-else
-	dir=$withval
-fi
-])
-if test $try_mdb = true
-then
-	AC_MSG_CHECKING(for MDB Tools files)
-	mdbdir=""
-	for d in $dir /usr /usr/local /opt/gnome
-	do
-		if test -f $d/include/mdbtools.h -a -f $d/$lib/libmdb$linklibext -o -f $d/include/mdbtools.h -a -f $d/$lib/libmdb.a
-		then
-			AC_MSG_RESULT(found MDB Tools in $d)
-			mdbdir=$d
-			break
-		fi
-	done
-	if test x$mdbdir = x
-	then
-		AC_MSG_WARN(MDB backend not used)
-	else
-		MDB_CFLAGS=-I${mdbdir}/include
-		MDB_LIBS="-L${mdbdir}/lib -lmdb"
-		AC_DEFINE(HAVE_MDB, 1, [Have MDB])
-
-		save_CFLAGS="$CFLAGS"
-		CFLAGS="$CFLAGS $MDB_CFLAGS $TST_CFLAGS"
-
-		AC_MSG_CHECKING([whether mdb_open takes one or two arguments])
-
-		AC_COMPILE_IFELSE([[
-#include <mdbtools.h>
-int main() {
-    const char *filename;
-	mdb_open(filename, MDB_WRITABLE);
-	return 0;
-}
-]], mdb_open_args=two, mdb_open_args=one)
-
-		AC_MSG_RESULT($mdb_open_args)
-		if test "$mdb_open_args" = "two"; then
-			AC_DEFINE(MDB_WITH_WRITE_SUPPORT, 1, [define if mdb_open accepts MDB_WRITABLE])
-		fi
-
-		AC_MSG_CHECKING([whether mdb_bind_column takes three or four arguments])
-
-		AC_COMPILE_IFELSE([[
-#include <mdbtools.h>
-int main() {
-	MdbHandle *mdb;
-	int c;
-	char *bound_data[256];
-	int len;
-	mdb_bind_column(mdb, c, bound_data[c], &len);
-	return 0;
-}
-]], mdb_bind_column_args=four, mdb_bind_column_args=three)
-
-		AC_MSG_RESULT($mdb_bind_column_args)
-		if test "$mdb_bind_column_args" = "four"; then
-			AC_DEFINE(MDB_BIND_COLUMN_FOUR_ARGS, 1, [define if mdb_bind_column accepts four args])
-		fi
-
-		CFLAGS="$save_CFLAGS"
-	fi
-fi
-
-AM_CONDITIONAL(MDB, test x$mdbdir != x)
+MDBTOOLS_CHECK([$lib])
 
 dnl Test for LDAP
 try_ldap=true
@@ -1733,8 +1657,6 @@ AC_SUBST(ORACLE_LIBS)
 AC_SUBST(ORACLE_CFLAGS)
 AC_SUBST(FIREBIRD_LIBS)
 AC_SUBST(FIREBIRD_CFLAGS)
-AC_SUBST(MDB_LIBS)
-AC_SUBST(MDB_CFLAGS)
 AC_SUBST(CAMEL_LIBS)
 AC_SUBST(CAMEL_CFLAGS)
 AC_SUBST(XBASE_LIBS)
@@ -1904,7 +1826,7 @@ echo "      Berkeley DB SQL = `if test x$bdbsqldir = x; then echo no; else echo
 dnl echo "      FireBird = `if test x$firebirddir != x; then echo yes; else echo no; fi`"
 dnl echo "      FreeTDS = `if test x$freetdsdir != x; then echo yes; else echo no; fi`"
 dnl echo "      IBM DB2 = `if test x$ibmdb2dir != x; then echo yes; else echo no; fi`"
-echo "      MDB (MS Access) = `if test x$mdbdir != x; then echo yes; else echo no; fi`"
+echo "      MDB (MS Access) = $mdbtools_found"
 echo "      MySQL = `if test x$mysqldir != x; then echo yes; else echo no; fi`"
 dnl echo "      mSQL = `if test x$msqldir != x; then echo yes; else echo no; fi`"
 dnl echo "      ODBC = `if test x$odbcdir != x; then echo yes; else echo no; fi`"
diff --git a/introspection.m4 b/m4/introspection.m4
similarity index 100%
rename from introspection.m4
rename to m4/introspection.m4
diff --git a/m4/mdbtools.m4 b/m4/mdbtools.m4
new file mode 100644
index 0000000..2421ef4
--- /dev/null
+++ b/m4/mdbtools.m4
@@ -0,0 +1,213 @@
+dnl -*- mode: autoconf -*-
+dnl Copyright 2010 Vivien Malerba
+dnl
+dnl SYNOPSIS
+dnl
+dnl   MDBTOOLS_CHECK([libdirname],[GLib's CFLAGS],[GLib's LIBS])
+dnl
+dnl   [libdirname]: defaults to "lib". Can be overridden by the --with-mdb-libdir-name option
+dnl   [GLib's CFLAGS]: default to `$PKG_CONFIG --cflags glib-2.0`
+dnl   [GLib's LIBS]: default to `$PKG_CONFIG --libs glib-2.0`, used when pkg-config is not
+dnl                  used to find the mdbtools package
+dnl
+dnl
+dnl DESCRIPTION
+dnl
+dnl   This macro tries to find the MDBTools libraries and header files
+dnl
+dnl   It defined two options:
+dnl   --with-mdb=yes/no/<directory>
+dnl   --with-mdb-libdir-name=<dir. name>
+dnl
+dnl   If the 1st option is "yes" then the macro tries to use pkg-config to locate
+dnl   the "libmdb" package, and if it fails, it tries in several well known directories
+dnl
+dnl   If the 1st option is "no" then the macro does not attempt at locating the
+dnl   mdbtools package
+dnl
+dnl   If the 1st option is a drectory name, then the macro tries to locate the mdbtools package
+dnl   in the specified directory.
+dnl
+dnl   If the macro has to try to locate the mdbtools package in one or more directories, it will
+dnl   try to locate the header files in $dir/include and the library files in $dir/lib, unless
+dnl   the second option is used to specify a directory name to be used instead of "lib" (for
+dnl   example lib64).
+dnl
+dnl USED VARIABLES
+dnl
+dnl   $linklibext: contains the library suffix (like ".so"). If not specified ".so" is used.
+dnl
+dnl
+dnl DEFINED VARIABLES
+dnl
+dnl   This macro always calls:
+dnl
+dnl    AC_SUBST(MDB_LIBS)
+dnl    AC_SUBST(MDB_CFLAGS)
+dnl    mdbtools_found=yes/no
+dnl
+dnl   and if the mdbtools package is found:
+dnl
+dnl    AC_DEFINE(HAVE_MDB, 1, [Have MDB])
+dnl    AM_CONDITIONAL(MDB, true)
+dnl    AC_DEFINE(MDB_WITH_WRITE_SUPPORT,[1],[define if mdb_open accepts MDB_WRITABLE])
+dnl    AC_DEFINE(MDB_BIND_COLUMN_FOUR_ARGS,[1],[define if mdb_bind_column accepts four args])
+dnl
+dnl
+dnl LICENSE
+dnl
+dnl This file is free software; the author(s) gives unlimited
+dnl permission to copy and/or distribute it, with or without
+dnl modifications, as long as this notice is preserved.
+dnl
+
+m4_define([_MDBTOOLS_CHECK_INTERNAL],
+[
+    AC_BEFORE([AC_PROG_LIBTOOL],[$0])dnl setup libtool first
+    AC_BEFORE([AM_PROG_LIBTOOL],[$0])dnl setup libtool first
+    AC_BEFORE([LT_INIT],[$0])dnl setup libtool first
+
+    m4_if([$1],[],[mdb_loclibdir=lib],[mdb_loclibdir=$1])
+    m4_if([$2],[],[mdb_glib_cflags=`$PKG_CONFIG --cflags glib-2.0`],[mdb_glib_cflags=$1])
+    m4_if([$3],[],[mdb_glib_libs=`$PKG_CONFIG --libs glib-2.0`],[mdb_glib_libs=$2])
+
+    # determine if MDBTools should be searched for
+    # and use pkg-config if the "yes" option is used
+    mdbtools_found=no
+    try_mdb=true
+    pkgmdb=no
+    MDB_LIBS=""
+    mdb_test_dir=""
+    AC_ARG_WITH(mdb,
+              AS_HELP_STRING([--with-mdb[=@<:@yes/no/<directory>@:>@]],
+                             [Locate MDBTools files for the MS Access backend (read only)]),[
+			     if test $withval = no
+			     then
+			         try_mdb=false
+			     elif test $withval != yes
+			     then
+			         mdb_test_dir=$withval
+			     fi])
+    AC_ARG_WITH(mdb-libdir-name,
+              AS_HELP_STRING([--with-mdb-libdir-name[=@<:@<dir. name>@:>@]],
+                             [Locate MDBTools library file, related to the MDB prefix specified from --with-mdb]),
+			     [mdb_loclibdir=$withval])
+
+    # try with pkgconfig
+    if test $try_mdb = true -a "x$mdb_test_dir" = x
+    then
+	PKG_CHECK_MODULES(MDB, "libmdb",[pkgmdb=yes],[pkgmdb=no])
+	if test $pkgmdb = no
+	then
+	    mdb_test_dir="/usr /usr/local /opt/gnome"
+	fi
+    fi
+
+    # try to locate files if pkg-config did not already do its job
+    if test $try_mdb = true
+    then
+	if test $pkgmdb = no
+	then
+	    if test "x$linklibext" = x
+	    then
+	        mdb_libext=".so"
+	    else
+	        mdb_libext="$linklibext"
+	    fi
+	    mdbdir=""
+	    for d in $mdb_test_dir
+	    do
+	        AC_MSG_CHECKING([for MDB Tools files in $d])
+	        if test -f $d/include/mdbtools.h -a -f $d/$mdb_loclibdir/libmdb$mdb_libext -o -f $d/include/mdbtools.h -a -f $d/$mdb_loclibdir/libmdb.a
+	        then
+  	            save_CFLAGS="$CFLAGS"
+	            CFLAGS="$CFLAGS -I$d/include $mdb_glib_cflags"
+  	            save_LIBS="$LIBS"
+	            LIBS="$LIBS -L$d/$mdb_loclibdir -lmdb $mdb_glib_libs"
+   	            AC_LINK_IFELSE([[
+#include <mdbtools.h>
+int main() {
+    printf("%p", mdb_open);
+    return 0;
+}
+]],
+	                         mdbdir=$d)
+	            CFLAGS="$save_CFLAGS"
+  	            LIBS="$save_LIBS"
+	            if test x$mdbdir != x
+		    then
+		        AC_MSG_RESULT([found])
+			MDB_CFLAGS=-I${mdbdir}/include
+	    		MDB_LIBS="-L${mdbdir}/lib -lmdb"
+		        break
+  		    else
+		        AC_MSG_RESULT([not found])
+		    fi
+	        else
+	            AC_MSG_RESULT([not found])
+	        fi
+	    done
+        fi
+
+	if test "x$MDB_LIBS" = x
+	then
+	    AC_MSG_NOTICE([MDB backend not used])
+	    AM_CONDITIONAL(MDB,[false])
+	else
+	    AC_DEFINE(HAVE_MDB,[1],[Have MDB])
+	    AM_CONDITIONAL(MDB,[true])
+    	    mdbtools_found=yes
+
+  	    save_CFLAGS="$CFLAGS"
+	    CFLAGS="$CFLAGS $MDB_CFLAGS $mdb_glib_cflags"
+
+	    AC_MSG_CHECKING([whether mdb_open takes one or two arguments])
+   	    AC_COMPILE_IFELSE([[
+#include <mdbtools.h>
+int main() {
+    const char *filename;
+    mdb_open(filename, MDB_WRITABLE);
+    return 0;
+}
+]],
+	                     mdb_open_args=two, mdb_open_args=one)
+
+	    AC_MSG_RESULT($mdb_open_args)
+	    if test "$mdb_open_args" = "two"; then
+		AC_DEFINE(MDB_WITH_WRITE_SUPPORT,[1],[define if mdb_open accepts MDB_WRITABLE])
+	    fi
+
+	    AC_MSG_CHECKING([whether mdb_bind_column takes three or four arguments])
+	    AC_COMPILE_IFELSE([[
+#include <mdbtools.h>
+int main() {
+	MdbHandle *mdb;
+	int c;
+	char *bound_data[256];
+	int len;
+	mdb_bind_column(mdb, c, bound_data[c], &len);
+	return 0;
+}
+]],
+	                      mdb_bind_column_args=four, mdb_bind_column_args=three)
+
+	    AC_MSG_RESULT($mdb_bind_column_args)
+	    if test "$mdb_bind_column_args" = "four"; then
+		AC_DEFINE(MDB_BIND_COLUMN_FOUR_ARGS,[1],[define if mdb_bind_column accepts four args])
+	    fi
+	    CFLAGS="$save_CFLAGS"
+	fi
+    fi
+
+    AC_SUBST(MDB_LIBS)
+    AC_SUBST(MDB_CFLAGS)
+])
+
+
+dnl Usage:
+dnl   MDBTOOLS_CHECK([libdirname],[GLib's CFLAGS],[GLib's LIBS])
+
+AC_DEFUN([MDBTOOLS_CHECK],
+[
+    _MDBTOOLS_CHECK_INTERNAL([$1],[$2],[$3])
+])



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