1# Check for postgres
2#
3# http://ac-archive.sourceforge.net/ac-archive/ax_lib_postgresql.html
4#
5# FC_CHECK_POSTGRES([ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND[, VERSION]]])
6
7AC_DEFUN([FC_CHECK_POSTGRES],
8[
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=""])
12
13  postgresql_cflags=""
14  postgresql_ldflags=""
15  POSTGRESQL_POSTGRESQL=""
16
17  dnl
18  dnl Check PostgreSQL libraries (libpq)
19  dnl
20
21  if test -z "$PG_CONFIG" -o test; then
22    AC_PATH_PROG([PG_CONFIG], [pg_config], [no])
23  fi
24
25  if test "$PG_CONFIG" != "no"; then
26    AC_MSG_CHECKING([for PostgreSQL libraries])
27
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 ##'`
31
32    found_postgresql="yes"
33    AC_MSG_RESULT([yes])
34  fi
35
36  dnl
37  dnl Check if required version of PostgreSQL is available
38  dnl
39
40
41  postgresql_version_req=ifelse([$3], [], [], [$3])
42
43  if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
44
45    AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
46
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"
54    fi
55
56    postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
57                                   \+ $postgresql_version_req_minor \* 1000 \
58                                   \+ $postgresql_version_req_micro`
59
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"
67    fi
68
69    postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
70                               \+ $postgresql_version_minor \* 1000 \
71                               \+ $postgresql_version_micro`
72
73    postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
74    if test "$postgresql_version_check" = "1"; then
75        AC_MSG_RESULT([yes])
76    else
77        AC_MSG_RESULT([no])
78    fi
79  fi
80
81  AC_SUBST([POSTGRESQL_VERSION])
82  AC_SUBST([postgresql_cflags])
83  AC_SUBST([postgresql_ldflags])
84
85  if test "x$found_postgresql" = "xyes" ; then
86    ifelse([$1], , :, [$1])
87  else
88    ifelse([$2], , :, [$2])
89  fi
90])
91