summaryrefslogtreecommitdiff
path: root/m4/ax_check_postgres_db.m4
diff options
context:
space:
mode:
authorOlivier Mehani <olivier.mehani@nicta.com.au>2012-08-16 17:28:35 +1000
committerPeter Simons <simons@cryp.to>2012-09-07 10:51:04 +0200
commit96209d066670dc81aa50ee1bfa4e5690a546e861 (patch)
treede844ec6c566a4aecbc71ce71317dfc70c1e6592 /m4/ax_check_postgres_db.m4
parente381c32954e6dc899d76d30c68fa9a3b9cf086f3 (diff)
downloadautoconf-archive-96209d066670dc81aa50ee1bfa4e5690a546e861.tar.gz
Substantial rewrite of AX_CHECK_POSTGRES_DB.
It still behaves the same by default, AC_DEFINing HAVE_LIBPQ and setting variables PQINCPATH and PQLIBPATH, while erroring when either header or library is found in the default or specified paths. The logic is however different, where the specified prefixes and/or incdir and libdir are temporarily added to CFLAGS and LDFLAGS. The normal detection logic (AC_CHECK_HEADER and AC_CHECK_LIB) is used next, only, and once. In addition, two optional arguments to the macro, ACTION-IF-FOUND and ACTION-IF-NOT-FOUND are now available to extend the logic. The default ACTION-IF-FOUND is to do nothing (apart from defining the variables and substitutions, which is always done). The default ACTION-IF-NOT-FOUND is to error out; it is replaced by the ACTION-IF-NOT-FOUND if specified to, e.g., gracefully remove configure PGSQL out when it's only optional. Bump serial from 5 to 6. Signed-off-by: Olivier Mehani <olivier.mehani@nicta.com.au>
Diffstat (limited to 'm4/ax_check_postgres_db.m4')
-rw-r--r--m4/ax_check_postgres_db.m4112
1 files changed, 63 insertions, 49 deletions
diff --git a/m4/ax_check_postgres_db.m4 b/m4/ax_check_postgres_db.m4
index 9e21c8f..0d8aef6 100644
--- a/m4/ax_check_postgres_db.m4
+++ b/m4/ax_check_postgres_db.m4
@@ -4,31 +4,47 @@
#
# SYNOPSIS
#
-# AX_CHECK_POSTGRES_DB
+# AX_CHECK_POSTGRES_DB([ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
#
# DESCRIPTION
#
-# This macro tries to find the headers and librarys for the PostgreSQL
+# This macro tries to find the headers and libraries for the PostgreSQL
# database to build client applications.
#
-# If includes are found, the variable PQINCPATH will be set. If librarys
-# are found, the variable PQLIBPATH will be set. if no check was
-# successful, the script exits with a error message.
+# If includes are found, the variable PQINCPATH will be set, and have_pqinc
+# will be 'yes'. If libraries are found, the variable PQLIBPATH will be set,
+# and have_pqlib will be 'yes'. If both PQINCPATH and PQLIBPATH are found,
+# HAVE_LIBPQ will be set to 'yes' (and AC_DEFINEd), and -lpq will be added to
+# the beginning of LIBS. If their respective conditions are not met,
+# have_pqinc, have_pqlib, HAVE_LIBPQ, will be 'no'.
+#
+# This macro does fails if either the headers or the library are
+# not found, unless ACTION-IF-NOT-FOUND is not empty. When both are found,
+# ACTION-IF-FOUND, if defined, is exectued after the variables have been
+# defined. If --with-pgsql=no (or equivalents) is given, nothing happens.
+#
+# An automake conditional can be subsequently defined as
+# AM_CONDITIONAL([HAVE_LIBPQ], [test x$HAVE_LIBPQ = x$yes])
+# in configure.ac.
#
# LICENSE
#
# Copyright (c) 2008 Christian Toepp <c.toepp@gmail.com>
+# Copyright (c) 2012 Olivier Mehani <shtrom-ax@ssji.net>
#
# 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. This file is offered as-is, without any
# warranty.
-#serial 5
+#serial 6
AU_ALIAS([CT_CHECK_POSTGRES_DB], [AX_CHECK_POSTGRES_DB])
AC_DEFUN([AX_CHECK_POSTGRES_DB], [
+pushdef([ACTION_IF_FOUND],$1)
+pushdef([ACTION_IF_NOT_FOUND],$2)
+
AC_ARG_WITH(pgsql,
[AS_HELP_STRING([--with-pgsql[[=PREFIX]]],
[Prefix of your PostgreSQL installation @<:@PREFIX@:>@])],
@@ -42,51 +58,49 @@ AC_ARG_WITH(pgsql-lib,
[Path to the libraries of PostgreSQL @<:@LIBDIR@:>@])],
[pg_lib=$withval], [pg_lib=])
+have_pqinc=no
+have_pqlib=no
+HAVE_LIBPQ=no
+
+AS_IF([test "$pg_prefix" != "no"],[
+ AS_IF([test "$pg_prefix" != "yes" && test "$pg_prefix" != ""], [
+ PQINCPATH="-I$pg_prefix/include $PQINCPATH"
+ PQLIBPATH="-L$pg_prefix/lib $PQLIBPATH"
+ ])
+ AS_IF([test "$pg_inc" != ""], [PQINCPATH="-I$pg_inc $PQINCPATH"])
+ AS_IF([test "$pg_lib" != ""], [PQLIBPATH="-L$pg_lib $PQLIBPATH"])
+
+ oldCFLAGS=$CFLAGS
+ oldLDFLAGS=$LDFLAGS
-AC_SUBST(PQINCPATH)
-AC_SUBST(PQLIBPATH)
+ CFLAGS="$PQINCPATH $CFLAGS"
+ LDFLAGS="$PQLIBPATH $LDFLAGS"
-if test "$pg_prefix" != ""; then
- AC_MSG_CHECKING([for PostgreSQL includes in $pg_prefix/include])
- if test -f "$pg_prefix/include/libpq-fe.h" ; then
- PQINCPATH="-I$pg_prefix/include"
- AC_MSG_RESULT([yes])
- else
- AC_MSG_ERROR(libpq-fe.h not found)
- fi
- AC_MSG_CHECKING([for PostgreSQL librarys in $pg_prefix/lib])
- if test -f "$pg_prefix/lib/libpq.so" ; then
- PQLIBPATH="-L$pg_prefix/lib"
- AC_MSG_RESULT([yes])
- else
- AC_MSG_ERROR(libpq.so not found)
- fi
-else
- if test "$pg_inc" != ""; then
- AC_MSG_CHECKING([for PostgreSQL includes in $pg_inc])
- if test -f "$pg_inc/libpq-fe.h" ; then
- PQINCPATH="-I$pg_inc"
- AC_MSG_RESULT([yes])
- else
- AC_MSG_ERROR(libpq-fe.h not found)
- fi
- fi
- if test "$pg_lib" != ""; then
- AC_MSG_CHECKING([for PostgreSQL librarys in $pg_lib])
- if test -f "$pg_lib/libpq.so" ; then
- PQLIBPATH="-L$pg_lib"
- AC_MSG_RESULT([yes])
- else
- AC_MSG_ERROR(libpq.so not found)
- fi
- fi
-fi
+ AC_CHECK_HEADER([libpq-fe.h], [have_pqinc=yes])
+ AC_CHECK_LIB([pq], [PQconnectdb], [
+ dnl We only search for libpq, so we know why we're here
+ LIBPQ_LIBS=-lpq
+ have_pqlib=yes
+ ])
+
+ HAVE_LIBPQ=`(test x$have_pqinc = xyes && test x$have_pqlib = xyes && echo yes) || echo no`
+
+ CFLAGS=$oldCFLAGS
+ LDFLAGS=$oldLDFLAGS
+
+ AC_SUBST(PQINCPATH)
+ AC_SUBST(PQLIBPATH)
+ AC_SUBST(LIBPQ_LIBS)
+
+ AS_IF([test x$HAVE_LIBPQ = xyes],[
+ AC_DEFINE([HAVE_LIBPQ], [1], [Define if libpq is installed])
+ ACTION_IF_FOUND
+ ],
+ [m4_ifset([ACTION_IF_NOT_FOUND],[ACTION_IF_NOT_FOUND],
+ [AC_MSG_ERROR(some support files for PostgreSQL were missing)])])
+])
-if test "$PQINCPATH" = "" ; then
- AC_CHECK_HEADER([libpq-fe.h], [], AC_MSG_ERROR(libpq-fe.h not found))
-fi
-if test "$PQLIBPATH" = "" ; then
- AC_CHECK_LIB(pq, PQconnectdb, [], AC_MSG_ERROR(libpq.so not found))
-fi
+popdef([ACTION_IF_FOUND])
+popdef([ACTION_IF_NOT_FOUND])
])