libpreludedb/master: Update MySQL, PostgreSQL, and SQLite3 detection method

[email protected] Mon, 13 Jul 2009 12:02:02 +0200 (CEST)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit df9cb12498651abfa53ee456c92d1f82da6aff7b
Author: Yoann Vandoorselaere <[email protected]>
Date:   Mon Jul 13 10:49:54 2009 +0200

    Update MySQL, PostgreSQL, and SQLite3 detection method
    
    Update to newer detection method based on Autoconf Macros Archives macros.
    This should fixes a number of detection problem (64 bits libdir), and make
    it easier to cross compile libpreludedb.


========================================

 configure.in                    |  145 ++++++-------------------------------
 m4/ax_lib_mysql.m4              |  145 +++++++++++++++++++++++++++++++++++++
 m4/ax_lib_postgresql.m4         |  152 ++++++++++++++++++++++++++++++++++++++
 m4/ax_lib_sqlite3.m4            |  153 +++++++++++++++++++++++++++++++++++++++
 plugins/sql/mysql/Makefile.am   |    2 +-
 plugins/sql/pgsql/Makefile.am   |    4 +-
 plugins/sql/sqlite3/Makefile.am |    2 +-
 7 files changed, 476 insertions(+), 127 deletions(-)

========================================

diff --git a/configure.in b/configure.in
index f26cc08..5c36b87 100644
--- a/configure.in
+++ b/configure.in
@@ -108,151 +108,50 @@ AM_PATH_LIBPRELUDE(0.9.9, , AC_MSG_ERROR(Cannot find libprelude: Is libprelude-c
 dnl ***************************************************
 dnl * Check for the MySQL library (MySQL plugin       *
 dnl ***************************************************
-
-AC_ARG_WITH(mysql-prefix, AC_HELP_STRING(--with-mysql-prefix=@<:@=PATH@:>@, Enable MySQL plugin @<:@default=auto@:>@),
-            mysql_required=true, with_mysql=yes)
-
-if test x$with_mysql != xno; then
-   if test x$with_mysql != xyes; then mysql_path=$with_mysql/bin; else mysql_path=$PATH; fi
-   with_mysql=no
-
-   AC_PATH_PROG(MYSQL_CONFIG, mysql_config, no, $mysql_path)
-
-   if test x$MYSQL_CONFIG != xno; then
-      MYSQL_LIBS=`$MYSQL_CONFIG --libs`
-      MYSQL_CFLAGS=`$MYSQL_CONFIG --cflags`
-   else
-      for dir in /usr/lib /usr/lib/mysql /usr/local/lib /usr/local/lib/mysql; do
-          AC_CHECK_FILE($dir/libmysqlclient.$libext, MYSQL_LIBS="-L$dir -lmysqlclient")
-      done
-
-      for dir in /usr/include /usr/include/mysql /usr/local/include /usr/local/include/mysql; do
-          AC_CHECK_FILE($dir/mysql.h, MYSQL_CFLAGS="-I$dir")
-      done
-   fi
-
-   if test -n "$MYSQL_LIBS" && test -n "$MYSQL_CFLAGS"; then
-      # mysql_config --libs outputs -L'directory' instead of -Ldirectory
-      # and escaped version fools gcc in AC_CHECK_LIB so we must remove
-      # apostrophes
-      temp_mysql_libs=`echo $MYSQL_LIBS | sed -e s/\'//g`
-      temp_mysql_cppflags=`echo $MYSQL_CFLAGS | sed -e s/\'//g`
-
-      # this is needed for correct linking. If we don't add mysql library
-      # flags to CFLAGS the test will always fail due to a linker error
-      LIBS_bak=$LIBS
-      CPPFLAGS_bak=$CPPFLAGS
-
-      LIBS="$LIBS $temp_mysql_libs"
-      CPPFLAGS="$CPPFLAGS $temp_mysql_cppflags"
-
-      AC_CHECK_FUNC(mysql_real_escape_string, have_real_escape_string=yes)
-      if test x$have_real_escape_string = xyes; then
-        AC_DEFINE(HAVE_MYSQL_REAL_ESCAPE_STRING, , mysql_real_escape_string function present)
-      fi
-
-      AC_CHECK_HEADER(mysql.h, with_mysql=yes, with_mysql=no)
-
-      # restore the normal setting
-      LIBS=$LIBS_bak
-      CPPFLAGS=$CPPFLAGS_bak
-   fi
-
-   if test x$mysql_required = xtrue && test x$with_mysql != xyes; then
-      AC_MSG_ERROR(error activating MySQL support)
-   fi
+AX_LIB_MYSQL()
+with_mysql="no"
+if test x$MYSQL_CONFIG != x; then
+        with_mysql="yes"
+        LIBS_bkp=$LIBS
+        LIBS="$MYSQL_LDFLAGS"
+        AC_CHECK_FUNC(mysql_real_escape_string, AC_DEFINE(HAVE_MYSQL_REAL_ESCAPE_STRING, , mysql_real_escape_string function present))
+        LIBS=$LIBS_bkp
 fi
 
 AM_CONDITIONAL(HAVE_MYSQL, test x$with_mysql = xyes)
-AC_SUBST(MYSQL_LIBS)
-AC_SUBST(MYSQL_CFLAGS)
-
-
 
 
 dnl ********************************************************
 dnl * Check for the PostgreSQL library (PostgreSQL plugin) *
 dnl ********************************************************
-
-AC_ARG_WITH(pgsql-prefix, AC_HELP_STRING(--with-pgsql-prefix=@<:@=PFX@:>@, Enable PostgreSQL plugin @<:@default=auto@:>@),
-            pgsql_required=true, with_pgsql=yes)
-
-if test x$with_pgsql != xno; then
-   if test x$with_pgsql != xyes; then default_path=$with_pgsql; fi
-
-   AC_PATH_PROG(PG_CONFIG, pg_config, no, $PATH:$default_path/bin; fi)
-   with_pgsql=no
-
-   if test x$PG_CONFIG != xno; then
-        PGSQL_LIBDIR=`$PG_CONFIG --libdir`
-        PGSQL_INCLUDEDIR=`$PG_CONFIG --includedir`
-
-        AC_CHECK_HEADER($PGSQL_INCLUDEDIR/libpq-fe.h, with_pgsql=yes)
-        if test x$with_pgsql != xyes; then
-           PGSQL_INCLUDEDIR="$PGSQL_INCLUDEDIR/postgresql"
-           AC_CHECK_HEADER($PGSQL_INCLUDEDIR/libpq-fe.h, with_pgsql=yes)
-        fi
-   fi
-
-   if test x$pgsql_required = xtrue && (test x$PG_CONFIG = xno -o x$with_pgsql != xyes); then
-      AC_MSG_ERROR(error activating PostgreSQL support)
-   fi
+AX_LIB_POSTGRESQL()
+
+with_pgsql="no"
+if test x$POSTGRESQL_VERSION != x; then
+        with_pgsql="yes"
+        LIBS_bkp=$LIBS
+        LIBS="$POSTGRESQL_LDFLAGS"
+        AC_CHECK_FUNC(PQserverVersion, AC_DEFINE(HAVE_PQSERVERVERSION, , [Define if PQserverVersion function is available]))
+        LIBS=$LIBS_bkp;
 fi
 
 AM_CONDITIONAL(HAVE_PGSQL, test x$with_pgsql = xyes)
-AC_SUBST(PGSQL_LIBDIR)
-AC_SUBST(PGSQL_INCLUDEDIR)
-
-
-LIBS_bkp=$LIBS
-LIBS="-L$PGSQL_LIBDIR -lpq"
-AC_CHECK_FUNC(PQserverVersion, AC_DEFINE(HAVE_PQSERVERVERSION, , [Define if PQserverVersion function is available]))
-LIBS=$LIBS_bkp;
-
-
 
 dnl ********************************************************
 dnl * Check for the SQLite3 library (SQLite3 plugin)       *
 dnl ********************************************************
+AX_LIB_SQLITE3("3.0.0")
 
-AC_ARG_WITH(sqlite3-prefix, AC_HELP_STRING(--with-sqlite3-prefix=@<:@=PFX@:>@, Enable Sqlite3 plugin @<:@default=auto@:>@),
-            sqlite3_required=true, with_sqlite3=yes)
-
-if test x$with_sqlite3 != xno; then
-   default_path="/usr /usr/local"
-   if test x$with_sqlite3 != xyes; then default_path=$with_sqlite3; fi
-   with_sqlite3=no
-
-   for dir in $default_path; do
-       AC_CHECK_FILE($dir/lib/libsqlite3.$libext, SQLITE3_LIBS="-L$dir -lsqlite3")
-       if test -z "$SQLITE3_LIBS"; then
-          continue
-       fi
-
-       AC_CHECK_FILE($dir/include/sqlite3.h, SQLITE3_CFLAGS="-I$dir")
-       if test -n "$SQLITE3_CFLAGS"; then
-          with_sqlite3=yes
-          break
-       fi
-   done
-
-   if test x$sqlite3_required = xtrue && test -z "$SQLITE3_LIBS"; then
-      AC_MSG_ERROR(could not find libsqlite3.$libext)
-   fi
-
-   if test x$sqlite3_required = xtrue && test -z "$SQLITE3_CFLAGS"; then
-      AC_MSG_ERROR(could not find sqlite3.h)
-   fi
+if test x$SQLITE3_VERSION != x; then
+        with_sqlite3="yes"
+else
+        with_sqlite3="no"
 fi
 
-AC_SUBST(SQLITE3_LIBS)
-AC_SUBST(SQLITE3_CFLAGS)
-
 AM_CONDITIONAL(HAVE_SQLITE3, test x$with_sqlite3 = xyes)
 
 
 
-
 dnl **************************************************
 dnl * Swig support                                   *
 dnl **************************************************
diff --git a/m4/ax_lib_mysql.m4 b/m4/ax_lib_mysql.m4
new file mode 100644
index 0000000..13c02f4
--- /dev/null
+++ b/m4/ax_lib_mysql.m4
@@ -0,0 +1,145 @@
+# ===========================================================================
+#          http://www.nongnu.org/autoconf-archive/ax_lib_mysql.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_LIB_MYSQL([MINIMUM-VERSION])
+#
+# DESCRIPTION
+#
+#   This macro provides tests of availability of MySQL client library of
+#   particular version or newer.
+#
+#   AX_LIB_MYSQL macro takes only one argument which is optional. If there
+#   is no required version passed, then macro does not run version test.
+#
+#   The --with-mysql option takes one of three possible values:
+#
+#   no - do not check for MySQL client library
+#
+#   yes - do check for MySQL library in standard locations (mysql_config
+#   should be in the PATH)
+#
+#   path - complete path to mysql_config utility, use this option if
+#   mysql_config can't be found in the PATH
+#
+#   This macro calls:
+#
+#     AC_SUBST(MYSQL_CFLAGS)
+#     AC_SUBST(MYSQL_LDFLAGS)
+#     AC_SUBST(MYSQL_VERSION)
+#
+#   And sets:
+#
+#     HAVE_MYSQL
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Mateusz Loskot <[email protected]>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.
+
+AC_DEFUN([AX_LIB_MYSQL],
+[
+    AC_ARG_WITH([mysql],
+        AC_HELP_STRING([--with-mysql=@<:@ARG@:>@],
+            [use MySQL client library @<:@default=yes@:>@, optionally specify path to mysql_config]
+        ),
+        [
+        if test "$withval" = "no"; then
+            want_mysql="no"
+        elif test "$withval" = "yes"; then
+            want_mysql="yes"
+        else
+            want_mysql="yes"
+            MYSQL_CONFIG="$withval"
+        fi
+        ],
+        [want_mysql="yes"]
+    )
+
+    MYSQL_CFLAGS=""
+    MYSQL_LDFLAGS=""
+    MYSQL_VERSION=""
+
+    dnl
+    dnl Check MySQL libraries (libpq)
+    dnl
+
+    if test "$want_mysql" = "yes"; then
+
+        if test -z "$MYSQL_CONFIG" -o test; then
+            AC_PATH_PROG([MYSQL_CONFIG], [mysql_config], [no])
+        fi
+
+        if test "$MYSQL_CONFIG" != "no"; then
+            AC_MSG_CHECKING([for MySQL libraries])
+
+            MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
+            MYSQL_LDFLAGS="`$MYSQL_CONFIG --libs`"
+
+            MYSQL_VERSION=`$MYSQL_CONFIG --version`
+
+            AC_DEFINE([HAVE_MYSQL], [1],
+                [Define to 1 if MySQL libraries are available])
+
+            found_mysql="yes"
+            AC_MSG_RESULT([yes])
+        else
+            found_mysql="no"
+            AC_MSG_RESULT([no])
+        fi
+    fi
+
+    dnl
+    dnl Check if required version of MySQL is available
+    dnl
+
+
+    mysql_version_req=ifelse([$1], [], [], [$1])
+
+    if test "$found_mysql" = "yes" -a -n "$mysql_version_req"; then
+
+        AC_MSG_CHECKING([if MySQL version is >= $mysql_version_req])
+
+        dnl Decompose required version string of MySQL
+        dnl and calculate its number representation
+        mysql_version_req_major=`expr $mysql_version_req : '\([[0-9]]*\)'`
+        mysql_version_req_minor=`expr $mysql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+        mysql_version_req_micro=`expr $mysql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$mysql_version_req_micro" = "x"; then
+            mysql_version_req_micro="0"
+        fi
+
+        mysql_version_req_number=`expr $mysql_version_req_major \* 1000000 \
+                                   \+ $mysql_version_req_minor \* 1000 \
+                                   \+ $mysql_version_req_micro`
+
+        dnl Decompose version string of installed MySQL
+        dnl and calculate its number representation
+        mysql_version_major=`expr $MYSQL_VERSION : '\([[0-9]]*\)'`
+        mysql_version_minor=`expr $MYSQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
+        mysql_version_micro=`expr $MYSQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$mysql_version_micro" = "x"; then
+            mysql_version_micro="0"
+        fi
+
+        mysql_version_number=`expr $mysql_version_major \* 1000000 \
+                                   \+ $mysql_version_minor \* 1000 \
+                                   \+ $mysql_version_micro`
+
+        mysql_version_check=`expr $mysql_version_number \>\= $mysql_version_req_number`
+        if test "$mysql_version_check" = "1"; then
+            AC_MSG_RESULT([yes])
+        else
+            AC_MSG_RESULT([no])
+        fi
+    fi
+
+    AC_SUBST([MYSQL_VERSION])
+    AC_SUBST([MYSQL_CFLAGS])
+    AC_SUBST([MYSQL_LDFLAGS])
+])
diff --git a/m4/ax_lib_postgresql.m4 b/m4/ax_lib_postgresql.m4
new file mode 100644
index 0000000..9d01979
--- /dev/null
+++ b/m4/ax_lib_postgresql.m4
@@ -0,0 +1,152 @@
+# ===========================================================================
+#        http://www.nongnu.org/autoconf-archive/ax_lib_postgresql.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_LIB_POSTGRESQL([MINIMUM-VERSION])
+#
+# DESCRIPTION
+#
+#   This macro provides tests of availability of PostgreSQL 'libpq' library
+#   of particular version or newer.
+#
+#   AX_LIB_POSTGRESQL macro takes only one argument which is optional. If
+#   there is no required version passed, then macro does not run version
+#   test.
+#
+#   The --with-postgresql option takes one of three possible values:
+#
+#   no - do not check for PostgreSQL client library
+#
+#   yes - do check for PostgreSQL library in standard locations (pg_config
+#   should be in the PATH)
+#
+#   path - complete path to pg_config utility, use this option if pg_config
+#   can't be found in the PATH
+#
+#   This macro calls:
+#
+#     AC_SUBST(POSTGRESQL_CFLAGS)
+#     AC_SUBST(POSTGRESQL_LDFLAGS)
+#     AC_SUBST(POSTGRESQL_VERSION)
+#
+#   And sets:
+#
+#     HAVE_POSTGRESQL
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Mateusz Loskot <[email protected]>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.
+
+AC_DEFUN([AX_LIB_POSTGRESQL],
+[
+    AC_ARG_WITH([postgresql],
+        AC_HELP_STRING([--with-postgresql=@<:@ARG@:>@],
+            [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config]
+        ),
+        [
+        if test "$withval" = "no"; then
+            want_postgresql="no"
+        elif test "$withval" = "yes"; then
+            want_postgresql="yes"
+        else
+            want_postgresql="yes"
+            PG_CONFIG="$withval"
+        fi
+        ],
+        [want_postgresql="yes"]
+    )
+
+    POSTGRESQL_CFLAGS=""
+    POSTGRESQL_LDFLAGS=""
+    POSTGRESQL_VERSION=""
+
+    dnl
+    dnl Check PostgreSQL libraries (libpq)
+    dnl
+
+    if test "$want_postgresql" = "yes"; then
+
+        if test -z "$PG_CONFIG" -o test; then
+            AC_PATH_PROG([PG_CONFIG], [pg_config], [])
+        fi
+
+        if test ! -x "$PG_CONFIG"; then
+            AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an exectuable file])
+            PG_CONFIG="no"
+            found_postgresql="no"
+        fi
+
+        if test "$PG_CONFIG" != "no"; then
+            AC_MSG_CHECKING([for PostgreSQL libraries])
+
+            POSTGRESQL_CFLAGS="-I`$PG_CONFIG --includedir`"
+            POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir` -lpq"
+
+            POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
+
+            AC_DEFINE([HAVE_POSTGRESQL], [1],
+                [Define to 1 if PostgreSQL libraries are available])
+
+            found_postgresql="yes"
+            AC_MSG_RESULT([yes])
+        else
+            found_postgresql="no"
+            AC_MSG_RESULT([no])
+        fi
+    fi
+
+    dnl
+    dnl Check if required version of PostgreSQL is available
+    dnl
+
+
+    postgresql_version_req=ifelse([$1], [], [], [$1])
+
+    if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
+
+        AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
+
+        dnl Decompose required version string of PostgreSQL
+        dnl and calculate its number representation
+        postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
+        postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+        postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$postgresql_version_req_micro" = "x"; then
+            postgresql_version_req_micro="0"
+        fi
+
+        postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
+                                   \+ $postgresql_version_req_minor \* 1000 \
+                                   \+ $postgresql_version_req_micro`
+
+        dnl Decompose version string of installed PostgreSQL
+        dnl and calculate its number representation
+        postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
+        postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
+        postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$postgresql_version_micro" = "x"; then
+            postgresql_version_micro="0"
+        fi
+
+        postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
+                                   \+ $postgresql_version_minor \* 1000 \
+                                   \+ $postgresql_version_micro`
+
+        postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
+        if test "$postgresql_version_check" = "1"; then
+            AC_MSG_RESULT([yes])
+        else
+            AC_MSG_RESULT([no])
+        fi
+    fi
+
+    AC_SUBST([POSTGRESQL_VERSION])
+    AC_SUBST([POSTGRESQL_CFLAGS])
+    AC_SUBST([POSTGRESQL_LDFLAGS])
+])
diff --git a/m4/ax_lib_sqlite3.m4 b/m4/ax_lib_sqlite3.m4
new file mode 100644
index 0000000..22a4022
--- /dev/null
+++ b/m4/ax_lib_sqlite3.m4
@@ -0,0 +1,153 @@
+# ===========================================================================
+#         http://www.nongnu.org/autoconf-archive/ax_lib_sqlite3.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_LIB_SQLITE3([MINIMUM-VERSION])
+#
+# DESCRIPTION
+#
+#   Test for the SQLite 3 library of a particular version (or newer)
+#
+#   This macro takes only one optional argument, required version of SQLite
+#   3 library. If required version is not passed, 3.0.0 is used in the test
+#   of existance of SQLite 3.
+#
+#   If no intallation prefix to the installed SQLite library is given the
+#   macro searches under /usr, /usr/local, and /opt.
+#
+#   This macro calls:
+#
+#     AC_SUBST(SQLITE3_CFLAGS)
+#     AC_SUBST(SQLITE3_LDFLAGS)
+#     AC_SUBST(SQLITE3_VERSION)
+#
+#   And sets:
+#
+#     HAVE_SQLITE3
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Mateusz Loskot <[email protected]>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.
+
+AC_DEFUN([AX_LIB_SQLITE3],
+[
+    AC_ARG_WITH([sqlite3],
+        AC_HELP_STRING(
+            [--with-sqlite3=@<:@ARG@:>@],
+            [use SQLite 3 library @<:@default=yes@:>@, optionally specify the prefix for sqlite3 library]
+        ),
+        [
+        if test "$withval" = "no"; then
+            WANT_SQLITE3="no"
+        elif test "$withval" = "yes"; then
+            WANT_SQLITE3="yes"
+            ac_sqlite3_path=""
+        else
+            WANT_SQLITE3="yes"
+            ac_sqlite3_path="$withval"
+        fi
+        ],
+        [WANT_SQLITE3="yes"]
+    )
+
+    SQLITE3_CFLAGS=""
+    SQLITE3_LDFLAGS=""
+    SQLITE3_VERSION=""
+
+    if test "x$WANT_SQLITE3" = "xyes"; then
+
+        ac_sqlite3_header="sqlite3.h"
+
+        sqlite3_version_req=ifelse([$1], [], [3.0.0], [$1])
+        sqlite3_version_req_shorten=`expr $sqlite3_version_req : '\([[0-9]]*\.[[0-9]]*\)'`
+        sqlite3_version_req_major=`expr $sqlite3_version_req : '\([[0-9]]*\)'`
+        sqlite3_version_req_minor=`expr $sqlite3_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
+        sqlite3_version_req_micro=`expr $sqlite3_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
+        if test "x$sqlite3_version_req_micro" = "x" ; then
+            sqlite3_version_req_micro="0"
+        fi
+
+        sqlite3_version_req_number=`expr $sqlite3_version_req_major \* 1000000 \
+                                   \+ $sqlite3_version_req_minor \* 1000 \
+                                   \+ $sqlite3_version_req_micro`
+
+        AC_MSG_CHECKING([for SQLite3 library >= $sqlite3_version_req])
+
+        if test "$ac_sqlite3_path" != ""; then
+            ac_sqlite3_ldflags="-L$ac_sqlite3_path/lib"
+            ac_sqlite3_cppflags="-I$ac_sqlite3_path/include"
+        else
+            for ac_sqlite3_path_tmp in /usr /usr/local /opt ; do
+                if test -f "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header" \
+                    && test -r "$ac_sqlite3_path_tmp/include/$ac_sqlite3_header"; then
+                    ac_sqlite3_path=$ac_sqlite3_path_tmp
+                    ac_sqlite3_cppflags="-I$ac_sqlite3_path_tmp/include"
+                    ac_sqlite3_ldflags="-L$ac_sqlite3_path_tmp/lib"
+                    break;
+                fi
+            done
+        fi
+
+        ac_sqlite3_ldflags="$ac_sqlite3_ldflags -lsqlite3"
+
+        saved_CPPFLAGS="$CPPFLAGS"
+        CPPFLAGS="$CPPFLAGS $ac_sqlite3_cppflags"
+
+        AC_LANG_PUSH(C++)
+        AC_COMPILE_IFELSE(
+            [
+            AC_LANG_PROGRAM([[@%:@include <sqlite3.h>]],
+                [[
+#if (SQLITE_VERSION_NUMBER >= $sqlite3_version_req_number)
+// Everything is okay
+#else
+#  error SQLite version is too old
+#endif
+                ]]
+            )
+            ],
+            [
+            AC_MSG_RESULT([yes])
+            success="yes"
+            ],
+            [
+            AC_MSG_RESULT([not found])
+            succees="no"
+            ]
+        )
+        AC_LANG_POP([C++])
+
+        CPPFLAGS="$saved_CPPFLAGS"
+
+        if test "$success" = "yes"; then
+
+            SQLITE3_CFLAGS="$ac_sqlite3_cppflags"
+            SQLITE3_LDFLAGS="$ac_sqlite3_ldflags"
+
+            ac_sqlite3_header_path="$ac_sqlite3_path/include/$ac_sqlite3_header"
+
+            dnl Retrieve SQLite release version
+            if test "x$ac_sqlite3_header_path" != "x"; then
+                ac_sqlite3_version=`cat $ac_sqlite3_header_path \
+                    | grep '#define.*SQLITE_VERSION.*\"' | sed -e 's/.* "//' \
+                        | sed -e 's/"//'`
+                if test $ac_sqlite3_version != ""; then
+                    SQLITE3_VERSION=$ac_sqlite3_version
+                else
+                    AC_MSG_WARN([Can not find SQLITE_VERSION macro in sqlite3.h header to retrieve SQLite version!])
+                fi
+            fi
+
+            AC_SUBST(SQLITE3_CFLAGS)
+            AC_SUBST(SQLITE3_LDFLAGS)
+            AC_SUBST(SQLITE3_VERSION)
+            AC_DEFINE([HAVE_SQLITE3], [], [Have the SQLITE3 library])
+        fi
+    fi
+])
diff --git a/plugins/sql/mysql/Makefile.am b/plugins/sql/mysql/Makefile.am
index d7b2da3..e54b9e6 100644
--- a/plugins/sql/mysql/Makefile.am
+++ b/plugins/sql/mysql/Makefile.am
@@ -4,7 +4,7 @@ mysql_la_LDFLAGS = -module -avoid-version @LIBPRELUDE_LDFLAGS@
 if HAVE_MYSQL
 
 mysql_la_SOURCES = mysql.c
-mysql_la_LIBADD = $(top_builddir)/src/libpreludedb.la @LIBPRELUDE_LIBS@ @MYSQL_LIBS@
+mysql_la_LIBADD = $(top_builddir)/src/libpreludedb.la @LIBPRELUDE_LIBS@ @MYSQL_LDFLAGS@
 mysqldir = $(sql_plugin_dir)
 mysql_LTLIBRARIES = mysql.la
 
diff --git a/plugins/sql/pgsql/Makefile.am b/plugins/sql/pgsql/Makefile.am
index c417074..12ccf6c 100644
--- a/plugins/sql/pgsql/Makefile.am
+++ b/plugins/sql/pgsql/Makefile.am
@@ -1,10 +1,10 @@
-AM_CPPFLAGS=@PCFLAGS@ -I$(top_srcdir)/src/include -I$(top_srcdir)/libmissing -I$(top_builddir)/libmissing @LIBPRELUDE_CFLAGS@ -I@PGSQL_INCLUDEDIR@
+AM_CPPFLAGS=@PCFLAGS@ -I$(top_srcdir)/src/include -I$(top_srcdir)/libmissing -I$(top_builddir)/libmissing @LIBPRELUDE_CFLAGS@ @POSTGRESQL_CFLAGS@
 pgsql_la_LDFLAGS = -module -avoid-version @LIBPRELUDE_LDFLAGS@ 
 
 if HAVE_PGSQL
 
 pgsql_la_SOURCES = pgsql.c
-pgsql_la_LIBADD = $(top_builddir)/src/libpreludedb.la @LIBPRELUDE_LIBS@ -L@PGSQL_LIBDIR@ -lpq
+pgsql_la_LIBADD = $(top_builddir)/src/libpreludedb.la @LIBPRELUDE_LIBS@ @POSTGRESQL_LDFLAGS@
 pgsqldir = $(sql_plugin_dir)
 
 pgsql_LTLIBRARIES = pgsql.la
diff --git a/plugins/sql/sqlite3/Makefile.am b/plugins/sql/sqlite3/Makefile.am
index 36ade09..7cbd7b8 100644
--- a/plugins/sql/sqlite3/Makefile.am
+++ b/plugins/sql/sqlite3/Makefile.am
@@ -4,7 +4,7 @@ sqlite3_la_LDFLAGS = -module -avoid-version @LIBPRELUDE_LDFLAGS@
 if HAVE_SQLITE3
 
 sqlite3_la_SOURCES = sqlite3.c
-sqlite3_la_LIBADD = $(top_builddir)/src/libpreludedb.la @LIBPRELUDE_LIBS@ @SQLITE3_LIBS@
+sqlite3_la_LIBADD = $(top_builddir)/src/libpreludedb.la @LIBPRELUDE_LIBS@ @SQLITE3_LDFLAGS@
 sqlite3dir = $(sql_plugin_dir)
 sqlite3_LTLIBRARIES = sqlite3.la
 
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog