]> git.openstreetmap.org Git - nominatim.git/blob - m4/ax_lib_postgresql_svr.m4
Merge remote-tracking branch 'mtmail/mobile-responsive'
[nominatim.git] / m4 / ax_lib_postgresql_svr.m4
1 # SYNOPSIS
2 #
3 #   AX_LIB_POSTGRESQL_SVR([MINIMUM-VERSION])
4 #
5 # DESCRIPTION
6 #
7 #   This macro provides tests of availability of PostgreSQL server library
8 #
9 #   This macro calls:
10 #
11 #     AC_SUBST(POSTGRESQL_PGXS)
12 #     AC_SUBST(POSTGRESQL_SERVER_CFLAGS)
13 #
14 # LICENSE
15 #
16 #   Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
17 #   Copyright (c) 2015 Sarah Hoffmann <lonia@denofr.de>
18 #
19 #   Copying and distribution of this file, with or without modification, are
20 #   permitted in any medium without royalty provided the copyright notice
21 #   and this notice are preserved.
22
23 AC_DEFUN([AX_LIB_POSTGRESQL_SVR],
24 [
25     AC_ARG_WITH([postgresql],
26         AC_HELP_STRING([--with-postgresql-svr=@<:@ARG@:>@],
27             [use PostgreSQL server library @<:@default=yes@:>@, optionally specify path to pg_config]
28         ),
29         [
30         if test "$withval" = "no"; then
31             want_postgresql="no"
32         elif test "$withval" = "yes"; then
33             want_postgresql="yes"
34         else
35             want_postgresql="yes"
36             PG_CONFIG="$withval"
37         fi
38         ],
39         [want_postgresql="yes"]
40     )
41
42     dnl
43     dnl Check PostgreSQL server libraries
44     dnl
45
46     if test "$want_postgresql" = "yes"; then
47
48         if test -z "$PG_CONFIG" -o test; then
49             AC_PATH_PROG([PG_CONFIG], [pg_config], [])
50         fi
51
52         if test ! -x "$PG_CONFIG"; then
53             AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an exectuable file])
54             PG_CONFIG="no"
55             found_postgresql="no"
56         fi
57
58         if test "$PG_CONFIG" != "no"; then
59             AC_MSG_CHECKING([for PostgreSQL server libraries])
60
61             POSTGRESQL_SERVER_CFLAGS="-I`$PG_CONFIG --includedir-server`"
62
63             POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
64
65             POSTGRESQL_PGXS=`$PG_CONFIG --pgxs`
66         if test -f "$POSTGRESQL_PGXS"
67         then
68           found_postgresql="yes"
69               AC_MSG_RESULT([yes])
70         fi
71         else
72             found_postgresql="no"
73             AC_MSG_RESULT([no])
74         fi
75     fi
76
77     dnl
78     dnl Check if required version of PostgreSQL is available
79     dnl
80
81
82     postgresql_version_req=ifelse([$1], [], [], [$1])
83
84     if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
85
86         AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
87
88         dnl Decompose required version string of PostgreSQL
89         dnl and calculate its number representation
90         postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
91         postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
92         postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
93         if test "x$postgresql_version_req_micro" = "x"; then
94             postgresql_version_req_micro="0"
95         fi
96
97         postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
98                                    \+ $postgresql_version_req_minor \* 1000 \
99                                    \+ $postgresql_version_req_micro`
100
101         dnl Decompose version string of installed PostgreSQL
102         dnl and calculate its number representation
103         postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
104         postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
105         postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
106         if test "x$postgresql_version_micro" = "x"; then
107             postgresql_version_micro="0"
108         fi
109
110         postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
111                                    \+ $postgresql_version_minor \* 1000 \
112                                    \+ $postgresql_version_micro`
113
114         postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
115         if test "$postgresql_version_check" = "1"; then
116             AC_MSG_RESULT([yes])
117         else
118             AC_MSG_RESULT([no])
119         fi
120     fi
121
122     AC_SUBST([POSTGRESQL_PGXS])
123     AC_SUBST([POSTGRESQL_SERVER_CFLAGS])
124 ])
125