File: pgsql_drv.m4

package info (click to toggle)
dspam 3.6.8-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,372 kB
  • ctags: 1,457
  • sloc: ansic: 24,738; sh: 9,860; perl: 2,378; makefile: 546; sql: 327
file content (233 lines) | stat: -rw-r--r-- 6,449 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# $Id: pgsql_drv.m4,v 1.3 2006/05/13 13:28:30 jonz Exp $
# Autuconf macroses for checking for PostgreSQL
# Rustam Aliyev <rustam@azernews.com>
# Jonathan Zdziarski <jonathan@nuclearelephant.com>
#
#   Public available macro:
#       DS_PGSQL([pgsql_cppflags_out],
#                [pgsql_libs_out],
#                [pgsql_ldflags_out]
#                [additional-action-if-found],
#                [additional-action-if-not-found]
#                )
#
#   Another macros are considered as private for implementation and
#   sould not be used in the configure.ac.  At this time these are:
#       DS_PGSQL_HEADERS()
#       DS_PGSQL_LIBS()
#

#   DS_PGSQL_HEADERS([pgsql_cppflags_out],
#                  [additional-action-if-found],
#                  [additional-action-if-not-found]
#                 )
AC_DEFUN([DS_PGSQL_HEADERS],
[
pgsql_headers_save_CPPFLAGS="$CPPFLAGS"
pgsql_headers_CPPFLAGS=''
pgsql_headers_success=yes

#
#   virtual users
#
AC_ARG_ENABLE(virtual-users,
    [AS_HELP_STRING([--enable-virtual-users],
                    [Cause pgsql_drv to generate virtual uids for each user])])
AC_MSG_CHECKING([whether to enable virtual users])
case x"$enable_virtual_users" in
    xyes)   # enabled explicity
            ;;
    xno)    # disabled explicity
            ;;
    x)      # disabled by default
            enable_virtual_users=no
            ;;
    *)      AC_MSG_ERROR([unexpected value $enable_virtual_users for --{enable,disable}-virtual-users configure option])
            ;;
esac
if test x"$enable_virtual_users" != xyes
then
    enable_virtual_users=no
else
    enable_virtual_users=yes    # overkill, but convenient
    AC_DEFINE(VIRTUAL_USERS, 1, [Defined if homedir dotfiles is enabled])
fi
AC_MSG_RESULT([$enable_virtual_users])


AC_ARG_WITH(pgsql-includes,
    [AS_HELP_STRING([--with-pgsql-includes=DIR],
                    [Where to find PostgreSQL headers])])
AC_MSG_CHECKING([where to find PostgreSQL headers])
if test x"$with_pgsql_includes" = x
then
    AC_MSG_RESULT([compiler default paths])
else
    AC_MSG_RESULT([$with_pgsql_includes])
    if test -d "$with_pgsql_includes"
    then
        :
    else
        AC_MSG_ERROR([required include path for libpq headers $with_pgsql_includes is not a directory])
    fi
    pgsql_headers_CPPFLAGS="-I$with_pgsql_includes"
    CPPFLAGS="$pgsql_headers_CPPFLAGS $CPPFLAGS"
fi
AC_CHECK_HEADER([libpq-fe.h],
                [],
                [ pgsql_headers_success=no ])
if test x"$pgsql_headers_success" = xyes
then
    AC_PREPROC_IFELSE([AC_LANG_SOURCE([[
    #include <libpq-fe.h>
    #ifdef LIBPQ_FE_H
    /* Success */
    #else
    #error Unsupported version of PgSQL 
    #endif
            ]])],
            [],
            [
                AC_MSG_FAILURE([Unsupported version of PostgreSQL (no LIBPQ_FE_H defined)])
                pgsql_headers_success=no
            ])
fi

CPPFLAGS="$pgsql_headers_save_CPPFLAGS"
if test x"$pgsql_headers_success" = xyes
then
    ifelse([$1], [], [:], [$1="$pgsql_headers_CPPFLAGS"])
    ifelse([$2], [], [:], [$2])
else
    ifelse([$3], [], [:], [$3])
fi
])

#
#   DS_PGSQL_LIBS([pgsql_ldflags_out], [pgsql_libs_out],
#                  [additional-action-if-found],
#                  [additional-action-if-not-found]
#                 )
AC_DEFUN([DS_PGSQL_LIBS],
[
pgsql_libs_save_LDFLAGS="$LDFLAGS"
pgsql_libs_save_LIBS="$LIBS"
pgsql_libs_LDFLAGS=''
pgsql_libs_LIBS=''
pgsql_libs_success=no
pgsql_freemem_success=no
pgsql_libs_netlibs=''

AC_ARG_WITH(pgsql-libraries,
    [AS_HELP_STRING([--with-pgsql-libraries=DIR],
                    [Where to find PostgreSQL libraries])])
AC_MSG_CHECKING([where to find PostgreSQL libraries])
if test x"$with_pgsql_libraries" = x
then
    AC_MSG_RESULT([compiler default paths])
else
    AC_MSG_RESULT([$with_pgsql_libraries])
    if test -d "$with_pgsql_libraries"
    then
        :
    else
        AC_MSG_ERROR([required path for libpq libraries ($with_pgsql_libraries) is not a directory])
    fi
    pgsql_libs_LDFLAGS="-L$with_pgsql_libraries"
fi

DS_NETLIBS([pgsql_libs_netlibs],
           [pgsql_libs_success=yes],
           [pgsql_libs_success=no])
if test x"$pgsql_libs_success" = xyes
then
    AC_MSG_CHECKING([for PQconnectdb in libpq])
    pgsql_libs_LIBS="-lpq $pgsql_libs_netlibs"
    LIBS="$pgsql_libs_LIBS $pgsql_libs_save_LIBS"
    LDFLAGS="$pgsql_libs_LDFLAGS $pgsql_libs_save_LDFLAGS"
    
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
            #include <stdlib.h>
            #include <libpq-fe.h>
        ]],
        [[
            PGconn *pgsql = PQconnectdb(NULL);
        ]])],
        [ pgsql_libs_success=yes ],
        [ pgsql_libs_success=no ]
        )
    AC_MSG_RESULT([$pgsql_libs_success])

fi

if test x"$pgsql_libs_success" = xyes
then
    AC_MSG_CHECKING([if this version of Postgres supports PQfreemem])
    AC_LINK_IFELSE([AC_LANG_PROGRAM([[
            #include <stdlib.h>
            #include <libpq-fe.h>
        ]],
        [[
            PQfreemem(NULL);
        ]])],
        [ pgsql_freemem_success=yes ],
        [ pgsql_freemem_success=no ]
        )
    AC_MSG_RESULT([$pgsql_freemem_success])
fi

if test x"$pgsql_freemem_success" = xyes
then
  AC_DEFINE([HAVE_PQFREEMEM], 1, [Defined if PQfreemem is supported])
fi

LIBS="$pgsql_libs_save_LIBS"
LDFLAGS="$pgsql_libs_save_LDFLAGS"
if test x"$pgsql_libs_success" = xyes
then
    ifelse([$1], [], [:], [$1="$pgsql_libs_LDFLAGS"])
    ifelse([$2], [], [:], [$2="$pgsql_libs_LIBS"])
    ifelse([$3], [], [:], [$3])
else
    ifelse([$4], [], [:], [$4])
fi
])

#
#   DS_PGSQL([db_cppflags_out], [db_ldflags_out], [db_libs_out],
#                  [additional-action-if-found],
#                  [additional-action-if-not-found]
#                 )
AC_DEFUN([DS_PGSQL],
[
pgsql_save_CPPFLAGS="$CPPFLAGS"
pgsql_save_LDFLAGS="$LDFLAGS"
pgsql_save_LIBS="$LIBS"

pgsql_CPPFLAGS=''
pgsql_LIBS=''

pgsql_success=yes

DS_PGSQL_HEADERS([pgsql_CPPFLAGS], [], [pgsql_success=no])

if test x"$pgsql_success" = xyes
then
    CPPFLAGS="$pgsql_CPPFLAGS $CPPFLAGS"
    DS_PGSQL_LIBS([pgsql_LDFLAGS], [pgsql_LIBS], [], [pgsql_success=no])
fi

CPPFLAGS="$pgsql_save_CPPFLAGS"
LDFLAGS="$pgsql_save_LDFLAGS"
LIBS="$pgsql_save_LIBS"

if test x"$pgsql_success" = xyes
then
    ifelse([$1], [], [:], [$1="$pgsql_CPPFLAGS"])
    ifelse([$2], [], [:], [$2="$pgsql_LDFLAGS"])
    ifelse([$3], [], [:], [$3="$pgsql_LIBS"])
    ifelse([$4], [], [:], [$4])
else
    ifelse([$5], [], [:], [$5])
fi
])