3 # http://ac-archive.sourceforge.net/ac-archive/ax_lib_postgresql.html
5 # FC_CHECK_POSTGRES([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND[, VERSION]]])
7 AC_DEFUN([FC_CHECK_POSTGRES],
9 AC_ARG_WITH([postgres-prefix],
10 AS_HELP_STRING([--with-postgres-prefix=PFX], [Prefix where PostgreSQL is installed (optional)]),
11 [postgres_prefix="$withval"], [postgres_prefix=""])
15 POSTGRESQL_POSTGRESQL=""
18 dnl Check PostgreSQL libraries (libpq)
21 if test -z "$PG_CONFIG" -o test; then
22 AC_PATH_PROG([PG_CONFIG], [pg_config], [no])
25 if test "$PG_CONFIG" != "no"; then
26 AC_MSG_CHECKING([for PostgreSQL libraries])
28 postgresql_cflags="-I`$PG_CONFIG --includedir`"
29 postgresql_ldflags="-L`$PG_CONFIG --libdir` -lpq"
30 POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
32 found_postgresql="yes"
37 dnl Check if required version of PostgreSQL is available
41 postgresql_version_req=ifelse([$3], [], [], [$3])
43 if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
45 AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
47 dnl Decompose required version string of PostgreSQL
48 dnl and calculate its number representation
49 postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
50 postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
51 postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
52 if test "x$postgresql_version_req_micro" = "x"; then
53 postgresql_version_req_micro="0"
56 postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
57 \+ $postgresql_version_req_minor \* 1000 \
58 \+ $postgresql_version_req_micro`
60 dnl Decompose version string of installed PostgreSQL
61 dnl and calculate its number representation
62 postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
63 postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
64 postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
65 if test "x$postgresql_version_micro" = "x"; then
66 postgresql_version_micro="0"
69 postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
70 \+ $postgresql_version_minor \* 1000 \
71 \+ $postgresql_version_micro`
73 postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
74 if test "$postgresql_version_check" = "1"; then
81 AC_SUBST([POSTGRESQL_VERSION])
82 AC_SUBST([postgresql_cflags])
83 AC_SUBST([postgresql_ldflags])
85 if test "x$found_postgresql" = "xyes" ; then
86 ifelse([$1], , :, [$1])
88 ifelse([$2], , :, [$2])