PageRenderTime 248ms CodeModel.GetById 121ms app.highlight 7ms RepoModel.GetById 114ms app.codeStats 0ms

/m4/ax_lib_postgresql.m4

http://github.com/mozy/mordor
m4 | 152 lines | 86 code | 22 blank | 44 comment | 0 complexity | a4d69012d99fe944b518f6f152fd162f MD5 | raw file
  1# ===========================================================================
  2#           http://autoconf-archive.cryp.to/ax_lib_postgresql.html
  3# ===========================================================================
  4#
  5# SYNOPSIS
  6#
  7#   AX_LIB_POSTGRESQL([MINIMUM-VERSION])
  8#
  9# DESCRIPTION
 10#
 11#   This macro provides tests of availability of PostgreSQL 'libpq' library
 12#   of particular version or newer.
 13#
 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
 16#   test.
 17#
 18#   The --with-postgresql option takes one of three possible values:
 19#
 20#   no - do not check for PostgreSQL client library
 21#
 22#   yes - do check for PostgreSQL library in standard locations (pg_config
 23#   should be in the PATH)
 24#
 25#   path - complete path to pg_config utility, use this option if pg_config
 26#   can't be found in the PATH
 27#
 28#   This macro calls:
 29#
 30#     AC_SUBST(POSTGRESQL_CFLAGS)
 31#     AC_SUBST(POSTGRESQL_LDFLAGS)
 32#     AC_SUBST(POSTGRESQL_VERSION)
 33#
 34#   And sets:
 35#
 36#     HAVE_POSTGRESQL
 37#
 38# LICENSE
 39#
 40#   Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
 41#
 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.
 45
 46AC_DEFUN([AX_LIB_POSTGRESQL],
 47[
 48    AC_ARG_WITH([postgresql],
 49        AC_HELP_STRING([--with-postgresql=@<:@ARG@:>@],
 50            [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config]
 51        ),
 52        [
 53        if test "$withval" = "no"; then
 54            want_postgresql="no"
 55        elif test "$withval" = "yes"; then
 56            want_postgresql="yes"
 57        else
 58            want_postgresql="yes"
 59            PG_CONFIG="$withval"
 60        fi
 61        ],
 62        [want_postgresql="yes"]
 63    )
 64
 65    POSTGRESQL_CFLAGS=""
 66    POSTGRESQL_LDFLAGS=""
 67    POSTGRESQL_VERSION=""
 68
 69    dnl
 70    dnl Check PostgreSQL libraries (libpq)
 71    dnl
 72
 73    if test "$want_postgresql" = "yes"; then
 74
 75        if test -z "$PG_CONFIG" -o test; then
 76            AC_PATH_PROG([PG_CONFIG], [pg_config], [])
 77        fi
 78
 79        if test ! -x "$PG_CONFIG"; then
 80            AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an exectuable file])
 81            PG_CONFIG="no"
 82            found_postgresql="no"
 83        fi
 84
 85        if test "$PG_CONFIG" != "no"; then
 86            AC_MSG_CHECKING([for PostgreSQL libraries])
 87
 88            POSTGRESQL_CFLAGS="-I`$PG_CONFIG --includedir`"
 89            POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir` -lpq"
 90
 91            POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
 92
 93            AC_DEFINE([HAVE_POSTGRESQL], [1],
 94                [Define to 1 if PostgreSQL libraries are available])
 95
 96            found_postgresql="yes"
 97            AC_MSG_RESULT([yes])
 98        else
 99            found_postgresql="no"
100            AC_MSG_RESULT([no])
101        fi
102    fi
103
104    dnl
105    dnl Check if required version of PostgreSQL is available
106    dnl
107
108
109    postgresql_version_req=ifelse([$1], [], [], [$1])
110
111    if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
112
113        AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
114
115        dnl Decompose required version string of PostgreSQL
116        dnl and calculate its number representation
117        postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
118        postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
119        postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
120        if test "x$postgresql_version_req_micro" = "x"; then
121            postgresql_version_req_micro="0"
122        fi
123
124        postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
125                                   \+ $postgresql_version_req_minor \* 1000 \
126                                   \+ $postgresql_version_req_micro`
127
128        dnl Decompose version string of installed PostgreSQL
129        dnl and calculate its number representation
130        postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
131        postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
132        postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
133        if test "x$postgresql_version_micro" = "x"; then
134            postgresql_version_micro="0"
135        fi
136
137        postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
138                                   \+ $postgresql_version_minor \* 1000 \
139                                   \+ $postgresql_version_micro`
140
141        postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
142        if test "$postgresql_version_check" = "1"; then
143            AC_MSG_RESULT([yes])
144        else
145            AC_MSG_RESULT([no])
146        fi
147    fi
148
149    AC_SUBST([POSTGRESQL_VERSION])
150    AC_SUBST([POSTGRESQL_CFLAGS])
151    AC_SUBST([POSTGRESQL_LDFLAGS])
152])