[c5c522c] | 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 | # ) |
---|
| 22 | AC_DEFUN([DS_PGSQL_HEADERS], |
---|
| 23 | [ |
---|
| 24 | pgsql_headers_save_CPPFLAGS="$CPPFLAGS" |
---|
| 25 | pgsql_headers_CPPFLAGS='' |
---|
| 26 | pgsql_headers_success=yes |
---|
| 27 | |
---|
| 28 | # |
---|
| 29 | # virtual users |
---|
| 30 | # |
---|
| 31 | AC_ARG_ENABLE(virtual-users, |
---|
| 32 | [AS_HELP_STRING([--enable-virtual-users], |
---|
| 33 | [Cause pgsql_drv to generate virtual uids for each user])]) |
---|
| 34 | AC_MSG_CHECKING([whether to enable virtual users]) |
---|
| 35 | case 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 | ;; |
---|
| 45 | esac |
---|
| 46 | if test x"$enable_virtual_users" != xyes |
---|
| 47 | then |
---|
| 48 | enable_virtual_users=no |
---|
| 49 | else |
---|
| 50 | enable_virtual_users=yes # overkill, but convenient |
---|
| 51 | AC_DEFINE(VIRTUAL_USERS, 1, [Defined if homedir dotfiles is enabled]) |
---|
| 52 | fi |
---|
| 53 | AC_MSG_RESULT([$enable_virtual_users]) |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | AC_ARG_WITH(pgsql-includes, |
---|
| 57 | [AS_HELP_STRING([--with-pgsql-includes=DIR], |
---|
| 58 | [Where to find PostgreSQL headers])]) |
---|
| 59 | AC_MSG_CHECKING([where to find PostgreSQL headers]) |
---|
| 60 | if test x"$with_pgsql_includes" = x |
---|
| 61 | then |
---|
| 62 | AC_MSG_RESULT([compiler default paths]) |
---|
| 63 | else |
---|
| 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" |
---|
| 73 | fi |
---|
| 74 | AC_CHECK_HEADER([libpq-fe.h], |
---|
| 75 | [], |
---|
| 76 | [ pgsql_headers_success=no ]) |
---|
| 77 | if test x"$pgsql_headers_success" = xyes |
---|
| 78 | then |
---|
| 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 | ]) |
---|
| 92 | fi |
---|
| 93 | |
---|
| 94 | CPPFLAGS="$pgsql_headers_save_CPPFLAGS" |
---|
| 95 | if test x"$pgsql_headers_success" = xyes |
---|
| 96 | then |
---|
| 97 | ifelse([$1], [], [:], [$1="$pgsql_headers_CPPFLAGS"]) |
---|
| 98 | ifelse([$2], [], [:], [$2]) |
---|
| 99 | else |
---|
| 100 | ifelse([$3], [], [:], [$3]) |
---|
| 101 | fi |
---|
| 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 | # ) |
---|
| 109 | AC_DEFUN([DS_PGSQL_LIBS], |
---|
| 110 | [ |
---|
| 111 | pgsql_libs_save_LDFLAGS="$LDFLAGS" |
---|
| 112 | pgsql_libs_save_LIBS="$LIBS" |
---|
| 113 | pgsql_libs_LDFLAGS='' |
---|
| 114 | pgsql_libs_LIBS='' |
---|
| 115 | pgsql_libs_success=no |
---|
| 116 | pgsql_freemem_success=no |
---|
| 117 | pgsql_libs_netlibs='' |
---|
| 118 | pgsql_version_success=no |
---|
| 119 | pgsql_version_major='' |
---|
| 120 | pgsql_version_minor='' |
---|
| 121 | pgsql_version_micro='' |
---|
| 122 | pgsql_version_number='' |
---|
| 123 | pgsql_version_req_major=8 |
---|
| 124 | pgsql_version_req_minor=1 |
---|
| 125 | pgsql_version_req_micro=0 |
---|
| 126 | pgsql_version_req_number='' |
---|
| 127 | |
---|
| 128 | AC_ARG_WITH(pgsql-libraries, |
---|
| 129 | [AS_HELP_STRING([--with-pgsql-libraries=DIR], |
---|
| 130 | [Where to find PostgreSQL libraries])]) |
---|
| 131 | AC_MSG_CHECKING([where to find PostgreSQL libraries]) |
---|
| 132 | if test x"$with_pgsql_libraries" = x |
---|
| 133 | then |
---|
| 134 | AC_MSG_RESULT([compiler default paths]) |
---|
| 135 | else |
---|
| 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" |
---|
| 144 | fi |
---|
| 145 | |
---|
| 146 | DS_NETLIBS([pgsql_libs_netlibs], |
---|
| 147 | [pgsql_libs_success=yes], |
---|
| 148 | [pgsql_libs_success=no]) |
---|
| 149 | if test x"$pgsql_libs_success" = xyes |
---|
| 150 | then |
---|
| 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 | |
---|
| 169 | fi |
---|
| 170 | |
---|
| 171 | if test x"$pgsql_libs_success" = xyes |
---|
| 172 | then |
---|
| 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]) |
---|
| 185 | fi |
---|
| 186 | |
---|
| 187 | if test x"$pgsql_freemem_success" = xyes |
---|
| 188 | then |
---|
| 189 | AC_DEFINE([HAVE_PQFREEMEM], 1, [Defined if PQfreemem is supported]) |
---|
| 190 | fi |
---|
| 191 | |
---|
| 192 | if test x"$pgsql_libs_success" = xyes |
---|
| 193 | then |
---|
| 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 |
---|
| 232 | fi |
---|
| 233 | |
---|
| 234 | if test x"$pgsql_version_success" = xno |
---|
| 235 | then |
---|
| 236 | pgsql_libs_success=no |
---|
| 237 | fi |
---|
| 238 | |
---|
| 239 | |
---|
| 240 | LIBS="$pgsql_libs_save_LIBS" |
---|
| 241 | LDFLAGS="$pgsql_libs_save_LDFLAGS" |
---|
| 242 | if test x"$pgsql_libs_success" = xyes |
---|
| 243 | then |
---|
| 244 | ifelse([$1], [], [:], [$1="$pgsql_libs_LDFLAGS"]) |
---|
| 245 | ifelse([$2], [], [:], [$2="$pgsql_libs_LIBS"]) |
---|
| 246 | ifelse([$3], [], [:], [$3]) |
---|
| 247 | else |
---|
| 248 | ifelse([$4], [], [:], [$4]) |
---|
| 249 | fi |
---|
| 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 | # ) |
---|
| 257 | AC_DEFUN([DS_PGSQL], |
---|
| 258 | [ |
---|
| 259 | pgsql_save_CPPFLAGS="$CPPFLAGS" |
---|
| 260 | pgsql_save_LDFLAGS="$LDFLAGS" |
---|
| 261 | pgsql_save_LIBS="$LIBS" |
---|
| 262 | |
---|
| 263 | pgsql_CPPFLAGS='' |
---|
| 264 | pgsql_LIBS='' |
---|
| 265 | |
---|
| 266 | pgsql_success=yes |
---|
| 267 | |
---|
| 268 | DS_PGSQL_HEADERS([pgsql_CPPFLAGS], [], [pgsql_success=no]) |
---|
| 269 | |
---|
| 270 | if test x"$pgsql_success" = xyes |
---|
| 271 | then |
---|
| 272 | CPPFLAGS="$pgsql_CPPFLAGS $CPPFLAGS" |
---|
| 273 | DS_PGSQL_LIBS([pgsql_LDFLAGS], [pgsql_LIBS], [], [pgsql_success=no]) |
---|
| 274 | fi |
---|
| 275 | |
---|
| 276 | CPPFLAGS="$pgsql_save_CPPFLAGS" |
---|
| 277 | LDFLAGS="$pgsql_save_LDFLAGS" |
---|
| 278 | LIBS="$pgsql_save_LIBS" |
---|
| 279 | |
---|
| 280 | if test x"$pgsql_success" = xyes |
---|
| 281 | then |
---|
| 282 | ifelse([$1], [], [:], [$1="$pgsql_CPPFLAGS"]) |
---|
| 283 | ifelse([$2], [], [:], [$2="$pgsql_LDFLAGS"]) |
---|
| 284 | ifelse([$3], [], [:], [$3="$pgsql_LIBS"]) |
---|
| 285 | ifelse([$4], [], [:], [$4]) |
---|
| 286 | else |
---|
| 287 | ifelse([$5], [], [:], [$5]) |
---|
| 288 | fi |
---|
| 289 | ]) |
---|