source: npl/mailserver/dspam/dspam-3.10.2/m4/pgsql_drv.m4 @ 0105685

gcc484ntopperl-5.22
Last change on this file since 0105685 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 8.0 KB
Line 
1# $Id: pgsql_drv.m4,v 1.5 2011/09/30 20:52:14 sbajic Exp $
2# Autuconf macroses for checking for PostgreSQL
3#
4#   Public available macro:
5#       DS_PGSQL([pgsql_cppflags_out],
6#                [pgsql_libs_out],
7#                [pgsql_ldflags_out]
8#                [additional-action-if-found],
9#                [additional-action-if-not-found]
10#                )
11#
12#   Another macros are considered as private for implementation and
13#   sould not be used in the configure.ac.  At this time these are:
14#       DS_PGSQL_HEADERS()
15#       DS_PGSQL_LIBS()
16#
17
18#   DS_PGSQL_HEADERS([pgsql_cppflags_out],
19#                  [additional-action-if-found],
20#                  [additional-action-if-not-found]
21#                 )
22AC_DEFUN([DS_PGSQL_HEADERS],
23[
24pgsql_headers_save_CPPFLAGS="$CPPFLAGS"
25pgsql_headers_CPPFLAGS=''
26pgsql_headers_success=yes
27
28#
29#   virtual users
30#
31AC_ARG_ENABLE(virtual-users,
32    [AS_HELP_STRING([--enable-virtual-users],
33                    [Cause pgsql_drv to generate virtual uids for each user])])
34AC_MSG_CHECKING([whether to enable virtual users])
35case x"$enable_virtual_users" in
36    xyes)   # enabled explicity
37            ;;
38    xno)    # disabled explicity
39            ;;
40    x)      # disabled by default
41            enable_virtual_users=no
42            ;;
43    *)      AC_MSG_ERROR([unexpected value $enable_virtual_users for --{enable,disable}-virtual-users configure option])
44            ;;
45esac
46if test x"$enable_virtual_users" != xyes
47then
48    enable_virtual_users=no
49else
50    enable_virtual_users=yes    # overkill, but convenient
51    AC_DEFINE(VIRTUAL_USERS, 1, [Defined if homedir dotfiles is enabled])
52fi
53AC_MSG_RESULT([$enable_virtual_users])
54
55
56AC_ARG_WITH(pgsql-includes,
57    [AS_HELP_STRING([--with-pgsql-includes=DIR],
58                    [Where to find PostgreSQL headers])])
59AC_MSG_CHECKING([where to find PostgreSQL headers])
60if test x"$with_pgsql_includes" = x
61then
62    AC_MSG_RESULT([compiler default paths])
63else
64    AC_MSG_RESULT([$with_pgsql_includes])
65    if test -d "$with_pgsql_includes"
66    then
67        :
68    else
69        AC_MSG_ERROR([required include path for libpq headers $with_pgsql_includes is not a directory])
70    fi
71    pgsql_headers_CPPFLAGS="-I$with_pgsql_includes"
72    CPPFLAGS="$pgsql_headers_CPPFLAGS $CPPFLAGS"
73fi
74AC_CHECK_HEADER([libpq-fe.h],
75                [],
76                [ pgsql_headers_success=no ])
77if test x"$pgsql_headers_success" = xyes
78then
79    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
80    #include <libpq-fe.h>
81    #ifdef LIBPQ_FE_H
82    /* Success */
83    #else
84    #error Unsupported version of PgSQL
85    #endif
86            ]])],
87            [],
88            [
89                AC_MSG_FAILURE([Unsupported version of PostgreSQL (no LIBPQ_FE_H defined)])
90                pgsql_headers_success=no
91            ])
92fi
93
94CPPFLAGS="$pgsql_headers_save_CPPFLAGS"
95if test x"$pgsql_headers_success" = xyes
96then
97    ifelse([$1], [], [:], [$1="$pgsql_headers_CPPFLAGS"])
98    ifelse([$2], [], [:], [$2])
99else
100    ifelse([$3], [], [:], [$3])
101fi
102])
103
104#
105#   DS_PGSQL_LIBS([pgsql_ldflags_out], [pgsql_libs_out],
106#                  [additional-action-if-found],
107#                  [additional-action-if-not-found]
108#                 )
109AC_DEFUN([DS_PGSQL_LIBS],
110[
111pgsql_libs_save_LDFLAGS="$LDFLAGS"
112pgsql_libs_save_LIBS="$LIBS"
113pgsql_libs_LDFLAGS=''
114pgsql_libs_LIBS=''
115pgsql_libs_success=no
116pgsql_freemem_success=no
117pgsql_libs_netlibs=''
118pgsql_version_success=no
119pgsql_version_major=''
120pgsql_version_minor=''
121pgsql_version_micro=''
122pgsql_version_number=''
123pgsql_version_req_major=8
124pgsql_version_req_minor=1
125pgsql_version_req_micro=0
126pgsql_version_req_number=''
127
128AC_ARG_WITH(pgsql-libraries,
129    [AS_HELP_STRING([--with-pgsql-libraries=DIR],
130                    [Where to find PostgreSQL libraries])])
131AC_MSG_CHECKING([where to find PostgreSQL libraries])
132if test x"$with_pgsql_libraries" = x
133then
134    AC_MSG_RESULT([compiler default paths])
135else
136    AC_MSG_RESULT([$with_pgsql_libraries])
137    if test -d "$with_pgsql_libraries"
138    then
139        :
140    else
141        AC_MSG_ERROR([required path for libpq libraries ($with_pgsql_libraries) is not a directory])
142    fi
143    pgsql_libs_LDFLAGS="-L$with_pgsql_libraries"
144fi
145
146DS_NETLIBS([pgsql_libs_netlibs],
147           [pgsql_libs_success=yes],
148           [pgsql_libs_success=no])
149if test x"$pgsql_libs_success" = xyes
150then
151    AC_MSG_CHECKING([for PQconnectdb in libpq])
152    pgsql_libs_LIBS="-lpq $pgsql_libs_netlibs"
153    LIBS="$pgsql_libs_LIBS $pgsql_libs_save_LIBS"
154    LDFLAGS="$pgsql_libs_LDFLAGS $pgsql_libs_save_LDFLAGS"
155   
156    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
157            #include <stdlib.h>
158            #include <libpq-fe.h>
159        ]],
160        [[
161            PGconn *pgsql = PQconnectdb(NULL);
162            PQfinish(pgsql);
163        ]])],
164        [ pgsql_libs_success=yes ],
165        [ pgsql_libs_success=no ]
166        )
167    AC_MSG_RESULT([$pgsql_libs_success])
168
169fi
170
171if test x"$pgsql_libs_success" = xyes
172then
173    AC_MSG_CHECKING([if this version of Postgres supports PQfreemem])
174    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
175            #include <stdlib.h>
176            #include <libpq-fe.h>
177        ]],
178        [[
179            PQfreemem(NULL);
180        ]])],
181        [ pgsql_freemem_success=yes ],
182        [ pgsql_freemem_success=no ]
183        )
184    AC_MSG_RESULT([$pgsql_freemem_success])
185fi
186
187if test x"$pgsql_freemem_success" = xyes
188then
189  AC_DEFINE([HAVE_PQFREEMEM], 1, [Defined if PQfreemem is supported])
190fi
191
192if test x"$pgsql_libs_success" = xyes
193then
194  AC_PATH_PROG([pgsql_pg_config], [pg_config], [])
195  if test ! -x "$pgsql_pg_config"
196  then
197    pgsql_pg_config="no"
198    AC_MSG_ERROR([$pgsql_pg_config does not exist or it is not an exectuable file])
199  fi
200
201  if test x"$pgsql_pg_config" != xno
202  then
203    AC_MSG_CHECKING([for PostgreSQL client version >= $pgsql_version_req_major.$pgsql_version_req_minor.$pgsql_version_req_micro])
204
205    pgsql_version_req_number=`expr $pgsql_version_req_major \* 1000000 \
206                              \+ $pgsql_version_req_minor \* 1000 \
207                              \+ $pgsql_version_req_micro`
208
209    pgsql_version=`$pgsql_pg_config --version | sed -e 's:^PostgreSQL ::'`
210    pgsql_version_major=`expr $pgsql_version : '\([[0-9]]*\)'`
211    pgsql_version_minor=`expr $pgsql_version : '[[0-9]]*\.\([[0-9]]*\)'`
212    pgsql_version_micro=`expr $pgsql_version : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
213    if test "x$pgsql_version_micro" = x
214    then
215      pgsql_version_micro='0'
216    fi
217
218    pgsql_version_number=`expr $pgsql_version_major \* 1000000 \
219                              \+ $pgsql_version_minor \* 1000 \
220                              \+ $pgsql_version_micro`
221
222    pgsql_version_success=`expr $pgsql_version_number \>\= $pgsql_version_req_number`
223    if test x"$pgsql_version_success" = x1
224    then
225      pgsql_version_success='yes'
226      AC_MSG_RESULT([yes])
227    else
228      pgsql_version_success='no'
229      AC_MSG_RESULT([no])
230    fi
231  fi
232fi
233
234if test x"$pgsql_version_success" = xno
235then
236  pgsql_libs_success=no
237fi
238
239
240LIBS="$pgsql_libs_save_LIBS"
241LDFLAGS="$pgsql_libs_save_LDFLAGS"
242if test x"$pgsql_libs_success" = xyes
243then
244    ifelse([$1], [], [:], [$1="$pgsql_libs_LDFLAGS"])
245    ifelse([$2], [], [:], [$2="$pgsql_libs_LIBS"])
246    ifelse([$3], [], [:], [$3])
247else
248    ifelse([$4], [], [:], [$4])
249fi
250])
251
252#
253#   DS_PGSQL([db_cppflags_out], [db_ldflags_out], [db_libs_out],
254#                  [additional-action-if-found],
255#                  [additional-action-if-not-found]
256#                 )
257AC_DEFUN([DS_PGSQL],
258[
259pgsql_save_CPPFLAGS="$CPPFLAGS"
260pgsql_save_LDFLAGS="$LDFLAGS"
261pgsql_save_LIBS="$LIBS"
262
263pgsql_CPPFLAGS=''
264pgsql_LIBS=''
265
266pgsql_success=yes
267
268DS_PGSQL_HEADERS([pgsql_CPPFLAGS], [], [pgsql_success=no])
269
270if test x"$pgsql_success" = xyes
271then
272    CPPFLAGS="$pgsql_CPPFLAGS $CPPFLAGS"
273    DS_PGSQL_LIBS([pgsql_LDFLAGS], [pgsql_LIBS], [], [pgsql_success=no])
274fi
275
276CPPFLAGS="$pgsql_save_CPPFLAGS"
277LDFLAGS="$pgsql_save_LDFLAGS"
278LIBS="$pgsql_save_LIBS"
279
280if test x"$pgsql_success" = xyes
281then
282    ifelse([$1], [], [:], [$1="$pgsql_CPPFLAGS"])
283    ifelse([$2], [], [:], [$2="$pgsql_LDFLAGS"])
284    ifelse([$3], [], [:], [$3="$pgsql_LIBS"])
285    ifelse([$4], [], [:], [$4])
286else
287    ifelse([$5], [], [:], [$5])
288fi
289])
Note: See TracBrowser for help on using the repository browser.