1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_lib_postgresql.html
3 # ===========================================================================
7 # AX_LIB_POSTGRESQL([MINIMUM-VERSION])
11 # This macro provides tests of availability of PostgreSQL 'libpq' library
12 # of particular version or newer.
14 # AX_LIB_POSTGRESQL macro takes only one argument which is optional. If
15 # there is no required version passed, then macro does not run version
18 # The --with-postgresql option takes one of three possible values:
20 # no - do not check for PostgreSQL client library
22 # yes - do check for PostgreSQL library in standard locations (pg_config
23 # should be in the PATH)
25 # path - complete path to pg_config utility, use this option if pg_config
26 # can't be found in the PATH
30 # AC_SUBST(POSTGRESQL_CPPFLAGS)
31 # AC_SUBST(POSTGRESQL_LDFLAGS)
32 # AC_SUBST(POSTGRESQL_VERSION)
40 # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
42 # Copying and distribution of this file, with or without modification, are
43 # permitted in any medium without royalty provided the copyright notice
44 # and this notice are preserved. This file is offered as-is, without any
49 AC_DEFUN([AX_LIB_POSTGRESQL],
51 AC_ARG_WITH([postgresql],
52 AS_HELP_STRING([--with-postgresql=@<:@ARG@:>@],
53 [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config]
56 if test "$withval" = "no"; then
58 elif test "$withval" = "yes"; then
65 [want_postgresql="yes"]
68 POSTGRESQL_CPPFLAGS=""
73 dnl Check PostgreSQL libraries (libpq)
76 if test "$want_postgresql" = "yes"; then
78 if test -z "$PG_CONFIG" -o test; then
79 AC_PATH_PROG([PG_CONFIG], [pg_config], [])
82 if test ! -x "$PG_CONFIG"; then
83 dnl AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an exectuable file])
88 if test "$PG_CONFIG" != "no"; then
89 AC_MSG_CHECKING([for PostgreSQL libraries])
91 POSTGRESQL_CPPFLAGS="-I`$PG_CONFIG --includedir`"
92 POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir`"
94 POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
96 AC_DEFINE([HAVE_POSTGRESQL], [1],
97 [Define to 1 if PostgreSQL libraries are available])
99 found_postgresql="yes"
102 found_postgresql="no"
108 dnl Check if required version of PostgreSQL is available
112 postgresql_version_req=ifelse([$1], [], [], [$1])
114 if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
116 AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
118 dnl Decompose required version string of PostgreSQL
119 dnl and calculate its number representation
120 postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
121 postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
122 postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
123 if test "x$postgresql_version_req_micro" = "x"; then
124 postgresql_version_req_micro="0"
127 postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
128 \+ $postgresql_version_req_minor \* 1000 \
129 \+ $postgresql_version_req_micro`
131 dnl Decompose version string of installed PostgreSQL
132 dnl and calculate its number representation
133 postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
134 postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
135 postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
136 if test "x$postgresql_version_micro" = "x"; then
137 postgresql_version_micro="0"
140 postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
141 \+ $postgresql_version_minor \* 1000 \
142 \+ $postgresql_version_micro`
144 postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
145 if test "$postgresql_version_check" = "1"; then
152 AC_SUBST([POSTGRESQL_VERSION])
153 AC_SUBST([POSTGRESQL_CPPFLAGS])
154 AC_SUBST([POSTGRESQL_LDFLAGS])