Add pg_config --libs to pgsql_LDFLAGS.
[apr-util.git] / build / dbd.m4
blob485fc2309ec9e6a62ba2001b08629def76d1e4fa
1 dnl -------------------------------------------------------- -*- autoconf -*-
2 dnl Copyright 2005 The Apache Software Foundation or its licensors, as
3 dnl applicable.
4 dnl
5 dnl Licensed under the Apache License, Version 2.0 (the "License");
6 dnl you may not use this file except in compliance with the License.
7 dnl You may obtain a copy of the License at
8 dnl
9 dnl     http://www.apache.org/licenses/LICENSE-2.0
10 dnl
11 dnl Unless required by applicable law or agreed to in writing, software
12 dnl distributed under the License is distributed on an "AS IS" BASIS,
13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 dnl See the License for the specific language governing permissions and
15 dnl limitations under the License.
17 dnl
18 dnl DBD module
19 dnl
21 dnl
22 dnl APU_CHECK_DBD: compile backends for apr_dbd.
23 dnl
24 AC_DEFUN([APU_CHECK_DBD], [
25   apu_have_pgsql=0
27   old_libs="$LIBS"
28   old_cppflags="$CPPFLAGS"
29   old_ldflags="$LDFLAGS"
31   AC_ARG_WITH([pgsql], APR_HELP_STRING([--with-pgsql=DIR], [specify PostgreSQL location]),
32   [
33     if test "$withval" = "yes"; then
34       AC_PATH_PROG([PGSQL_CONFIG],[pg_config])
35       if test "x$PGSQL_CONFIG" != 'x'; then
36         pgsql_CPPFLAGS="-I`$PGSQL_CONFIG --includedir`"
37         pgsql_LDFLAGS="-L`$PGSQL_CONFIG --libdir` `$PGSQL_CONFIG --libs`"
39         APR_ADDTO(CPPFLAGS, [$pgsql_CPPFLAGS])
40         APR_ADDTO(LDFLAGS, [$pgsql_LDFLAGS])
41       fi
43       AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
44       if test "$apu_have_pgsql" = "0"; then
45         AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
46       fi
47       if test "$apu_have_pgsql" != "0" && test "x$PGSQL_CONFIG" != 'x'; then
48         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [$pgsql_CPPFLAGS])
49       fi
50     elif test "$withval" = "no"; then
51       :
52     else
53       AC_PATH_PROG([PGSQL_CONFIG],[pg_config],,[$withval/bin])
54       if test "x$PGSQL_CONFIG" != 'x'; then
55         pgsql_CPPFLAGS="-I`$PGSQL_CONFIG --includedir`"
56         pgsql_LDFLAGS="-L`$PGSQL_CONFIG --libdir` `$PGSQL_CONFIG --libs`"
57       else
58         pgsql_CPPFLAGS="-I$withval/include"
59         pgsql_LDFLAGS="-L$withval/lib "
60       fi
62       APR_ADDTO(CPPFLAGS, [$pgsql_CPPFLAGS])
63       APR_ADDTO(LDFLAGS, [$pgsql_LDFLAGS])
65       AC_MSG_NOTICE(checking for pgsql in $withval)
66       AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
67       if test "$apu_have_pgsql" != "1"; then
68         AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
69       fi
70       if test "$apu_have_pgsql" != "0"; then
71         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [$pgsql_CPPFLAGS])
72       fi
73     fi
74   ], [
75     AC_PATH_PROG([PGSQL_CONFIG],[pg_config])
76     if test "x$PGSQL_CONFIG" != 'x'; then
77       pgsql_CPPFLAGS="-I`$PGSQL_CONFIG --includedir`"
78       pgsql_LDFLAGS="-L`$PGSQL_CONFIG --libdir` `$PGSQL_CONFIG --libs`"
80       APR_ADDTO(CPPFLAGS, [$pgsql_CPPFLAGS])
81       APR_ADDTO(LDFLAGS, [$pgsql_LDFLAGS])
82     fi
84     AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
85     if test "$apu_have_pgsql" = "0"; then
86       AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
87     fi
88     if test "$apu_have_pgsql" != "0" && test "x$PGSQL_CONFIG" != 'x'; then
89       APR_ADDTO(APRUTIL_PRIV_INCLUDES, [$pgsql_CPPFLAGS])
90     fi
91   ])
92   AC_SUBST(apu_have_pgsql)
93   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
94   dnl we know the library is there.
95   if test "$apu_have_pgsql" = "1"; then
96     LDADD_dbd_pgsql="$pgsql_LDFLAGS -lpq"
97   fi
98   AC_SUBST(LDADD_dbd_pgsql)
100   LIBS="$old_libs"
101   CPPFLAGS="$old_cppflags"
102   LDFLAGS="$old_ldflags"
105 AC_DEFUN([APU_CHECK_DBD_MYSQL], [
106   apu_have_mysql=0
108   old_libs="$LIBS"
109   old_cppflags="$CPPFLAGS"
110   old_ldflags="$LDFLAGS"
112   AC_ARG_WITH([mysql], APR_HELP_STRING([--with-mysql=DIR], [enable MySQL DBD driver]),
113   [
114     if test "$withval" = "yes"; then
115       AC_PATH_PROG([MYSQL_CONFIG],[mysql_config])
116       if test "x$MYSQL_CONFIG" != 'x'; then
117         mysql_CPPFLAGS="`$MYSQL_CONFIG --include`"
118         mysql_LDFLAGS="`$MYSQL_CONFIG --libs_r`"
120         APR_ADDTO(CPPFLAGS, [$mysql_CPPFLAGS])
121         APR_ADDTO(LDFLAGS, [$mysql_LDFLAGS])
122       fi
124       AC_CHECK_HEADERS(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
125       if test "$apu_have_mysql" = "0"; then
126         AC_CHECK_HEADERS(mysql/mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
127       fi
128       if test "$apu_have_mysql" != "0" && test "x$MYSQL_CONFIG" != 'x'; then
129         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [$mysql_CPPFLAGS])
130       fi
131     elif test "$withval" = "no"; then
132       :
133     else
134       AC_PATH_PROG([MYSQL_CONFIG],[mysql_config],,[$withval/bin])
135       if test "x$MYSQL_CONFIG" != 'x'; then
136         mysql_CPPFLAGS="`$MYSQL_CONFIG --include`"
137         mysql_LDFLAGS="`$MYSQL_CONFIG --libs_r`"
138       else
139         mysql_CPPFLAGS="-I$withval/include"
140         mysql_LDFLAGS="-L$withval/lib "
141       fi
143       APR_ADDTO(CPPFLAGS, [$mysql_CPPFLAGS])
144       APR_ADDTO(LDFLAGS, [$mysql_LDFLAGS])
146       AC_MSG_NOTICE(checking for mysql in $withval)
147       AC_CHECK_HEADERS(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
149       if test "$apu_have_mysql" != "1"; then
150         AC_CHECK_HEADERS(mysql/mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
151       fi
152       if test "$apu_have_mysql" != "0"; then
153         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [$mysql_CPPFLAGS])
154       fi
155     fi
156   ])
158   AC_SUBST(apu_have_mysql)
160   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
161   dnl we know the library is there.
162   if test "$apu_have_mysql" = "1"; then
163     LDADD_dbd_mysql=$mysql_LDFLAGS
164   fi
165   AC_SUBST(LDADD_dbd_mysql)
167   LIBS="$old_libs"
168   CPPFLAGS="$old_cppflags"
169   LDFLAGS="$old_ldflags"
172 AC_DEFUN([APU_CHECK_DBD_SQLITE3], [
173   apu_have_sqlite3=0
175   old_libs="$LIBS"
176   old_cppflags="$CPPFLAGS"
177   old_ldflags="$LDFLAGS"
179   AC_ARG_WITH([sqlite3], APR_HELP_STRING([--with-sqlite3=DIR], [enable sqlite3 DBD driver]),
180   [
181     if test "$withval" = "yes"; then
182       AC_CHECK_HEADERS(sqlite3.h, AC_CHECK_LIB(sqlite3, sqlite3_open, [apu_have_sqlite3=1]))
183     elif test "$withval" = "no"; then
184       :
185     else
186       sqlite3_CPPFLAGS="-I$withval/include"
187       sqlite3_LDFLAGS="-L$withval/lib "
189       APR_ADDTO(CPPFLAGS, [$sqlite3_CPPFLAGS])
190       APR_ADDTO(LDFLAGS, [$sqlite3_LDFLAGS])
192       AC_MSG_NOTICE(checking for sqlite3 in $withval)
193       AC_CHECK_HEADERS(sqlite3.h, AC_CHECK_LIB(sqlite3, sqlite3_open, [apu_have_sqlite3=1]))
194       if test "$apu_have_sqlite3" != "0"; then
195         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$withval/include])
196       fi
197     fi
198   ], [
199     AC_CHECK_HEADERS(sqlite3.h, AC_CHECK_LIB(sqlite3, sqlite3_open, [apu_have_sqlite3=1]))
200   ])
202   AC_SUBST(apu_have_sqlite3)
204   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
205   dnl we know the library is there.
206   if test "$apu_have_sqlite3" = "1"; then
207     LDADD_dbd_sqlite3="$sqlite3_LDFLAGS -lsqlite3"
208   fi
209   AC_SUBST(LDADD_dbd_sqlite3)
211   LIBS="$old_libs"
212   CPPFLAGS="$old_cppflags"
213   LDFLAGS="$old_ldflags"
216 AC_DEFUN([APU_CHECK_DBD_SQLITE2], [
217   apu_have_sqlite2=0
219   old_libs="$LIBS"
220   old_cppflags="$CPPFLAGS"
221   old_ldflags="$LDFLAGS"
223   AC_ARG_WITH([sqlite2], APR_HELP_STRING([--with-sqlite2=DIR], [enable sqlite2 DBD driver]),
224   [
225     if test "$withval" = "yes"; then
226       AC_CHECK_HEADERS(sqlite.h, AC_CHECK_LIB(sqlite, sqlite_open, [apu_have_sqlite2=1]))
227     elif test "$withval" = "no"; then
228       :
229     else
230       sqlite2_CPPFLAGS="-I$withval/include"
231       sqlite2_LDFLAGS="-L$withval/lib "
233       APR_ADDTO(CPPFLAGS, [$sqlite2_CPPFLAGS])
234       APR_ADDTO(LDFLAGS, [$sqlite2_LDFLAGS])
236       AC_MSG_NOTICE(checking for sqlite2 in $withval)
237       AC_CHECK_HEADERS(sqlite.h, AC_CHECK_LIB(sqlite, sqlite_open, [apu_have_sqlite2=1]))
238       if test "$apu_have_sqlite2" != "0"; then
239         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$withval/include])
240       fi
241     fi
242   ], [
243     AC_CHECK_HEADERS(sqlite.h, AC_CHECK_LIB(sqlite, sqlite_open, [apu_have_sqlite2=1]))
244   ])
246   AC_SUBST(apu_have_sqlite2)
248   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
249   dnl we know the library is there.
250   if test "$apu_have_sqlite2" = "1"; then
251     LDADD_dbd_sqlite2="$sqlite2_LDFLAGS -lsqlite"
252   fi
253   AC_SUBST(LDADD_dbd_sqlite2)
255   LIBS="$old_libs"
256   CPPFLAGS="$old_cppflags"
257   LDFLAGS="$old_ldflags"
260 AC_DEFUN([APU_CHECK_DBD_ORACLE], [
261   apu_have_oracle=0
263   old_libs="$LIBS"
264   old_cppflags="$CPPFLAGS"
265   old_ldflags="$LDFLAGS"
267   AC_ARG_WITH([oracle-include],
268     APR_HELP_STRING([--with-oracle-include=DIR], [path to Oracle include files]))
269   AC_ARG_WITH([oracle], 
270     APR_HELP_STRING([--with-oracle=DIR], [enable Oracle DBD driver; giving ORACLE_HOME as DIR]),
271   [
272     if test "$withval" = "yes"; then
273       if test -n "$with_oracle_include"; then
274         oracle_CPPFLAGS="$CPPFLAGS -I$with_oracle_include"
275         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$with_oracle_include])
276       fi
278       APR_ADDTO(CPPFLAGS, [$oracle_CPPFLAGS])
280       AC_CHECK_HEADERS(oci.h, AC_CHECK_LIB(clntsh, OCIEnvCreate, [apu_have_oracle=1],[
281         unset ac_cv_lib_clntsh_OCIEnvCreate
282         AC_CHECK_LIB(clntsh, OCIEnvCreate, [
283           apu_have_oracle=1
284           LDADD_dbd_oracle="-lnnz10"
285         ],,[-lnnz10])
286       ]))
287     elif test "$withval" = "no"; then
288       :
289     else
290       if test -n "$with_oracle_include"; then
291         oracle_CPPFLAGS="$CPPFLAGS -I$with_oracle_include"
292         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$with_oracle_include])
293       else
294         oracle_CPPFLAGS="-I$withval/rdbms/demo -I$withval/rdbms/public"
295       fi
296       oracle_LDFLAGS="-L$withval/lib "
298       APR_ADDTO(CPPFLAGS, [$oracle_CPPFLAGS])
299       APR_ADDTO(LDFLAGS, [$oracle_LDFLAGS])
301       AC_MSG_NOTICE(checking for oracle in $withval)
302       AC_CHECK_HEADERS(oci.h, AC_CHECK_LIB(clntsh, OCIEnvCreate, [apu_have_oracle=1],[
303         unset ac_cv_lib_clntsh_OCIEnvCreate
304         AC_CHECK_LIB(clntsh, OCIEnvCreate, [
305           apu_have_oracle=1
306           LDADD_dbd_oracle="-lnnz10"
307         ],,[-lnnz10])
308       ]))
309       if test "$apu_have_oracle" != "0"; then
310         LDADD_dbd_oracle="-R$withval/lib"
311         if test -z "$with_oracle_include"; then
312           APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$withval/rdbms/demo])
313           APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$withval/rdbms/public])
314         fi
315       fi
316     fi
317   ])
319   AC_SUBST(apu_have_oracle)
321   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
322   dnl we know the library is there.
323   if test "$apu_have_oracle" = "1"; then
324     LDADD_dbd_oracle="$oracle_LDFLAGS $LDADD_dbd_oracle -lclntsh"
325   fi
326   AC_SUBST(LDADD_dbd_oracle)
328   LIBS="$old_libs"
329   CPPFLAGS="$old_cppflags"
330   LDFLAGS="$old_ldflags"
334 AC_DEFUN([APU_CHECK_DBD_FREETDS], [
335   apu_have_freetds=0
337   old_libs="$LIBS"
338   old_cppflags="$CPPFLAGS"
339   old_ldflags="$LDFLAGS"
341   AC_ARG_WITH([freetds], 
342     APR_HELP_STRING([--with-freetds=DIR], [specify FreeTDS location]),
343   [
344     if test "$withval" = "yes"; then
345       AC_CHECK_HEADERS(sybdb.h, AC_CHECK_LIB(sybdb, tdsdbopen, [apu_have_freetds=1]))
346     elif test "$withval" = "no"; then
347       :
348     else
349       sybdb_CPPFLAGS="-I$withval/include"
350       sybdb_LDFLAGS="-L$withval/lib "
352       APR_ADDTO(CPPFLAGS, [$sybdb_CPPFLAGS])
353       APR_ADDTO(LDFLAGS, [$sybdb_LDFLAGS])
355       AC_MSG_NOTICE(checking for freetds in $withval)
356       AC_CHECK_HEADERS(sybdb.h, AC_CHECK_LIB(sybdb, tdsdbopen, [apu_have_freetds=1]))
357       if test "$apu_have_freetds" != "0"; then
358         APR_ADDTO(APRUTIL_PRIV_INCLUDES, [-I$withval/include])
359       fi
360     fi
361   ], [
362     AC_CHECK_HEADERS(sybdb.h, AC_CHECK_LIB(sybdb, tdsdbopen, [apu_have_freetds=1]))
363   ])
365   AC_SUBST(apu_have_freetds)
367   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
368   dnl we know the library is there.
369   if test "$apu_have_freetds" = "1"; then
370     LDADD_dbd_freetds="$sybdb_LDFLAGS -lsybdb"
371     dnl Erm, I needed pcreposix, but I think that dependency has gone
372     dnl from the current code
373     dnl LDADD_dbd_freetds="$LDADD_dbd_freetds -lsybdb -lpcreposix"
374   fi
375   AC_SUBST(LDADD_dbd_freetds)
377   LIBS="$old_libs"
378   CPPFLAGS="$old_cppflags"
379   LDFLAGS="$old_ldflags"
383 AC_DEFUN([APU_CHECK_DBD_DSO], [
385   AC_ARG_ENABLE([dbd-dso], 
386      APR_HELP_STRING([--disable-dbd-dso], [disable DSO build of DBD drivers]))
388   if test "$enable_dbd_dso" = "no"; then
389      # Statically link the DBD drivers:
391      objs=
392      test $apu_have_oracle = 1 && objs="$objs dbd/apr_dbd_oracle.lo"
393      test $apu_have_pgsql = 1 && objs="$objs dbd/apr_dbd_pgsql.lo"
394      test $apu_have_mysql = 1 && objs="$objs dbd/apr_dbd_mysql.lo"
395      test $apu_have_sqlite2 = 1 && objs="$objs dbd/apr_dbd_sqlite2.lo"
396      test $apu_have_sqlite3 = 1 && objs="$objs dbd/apr_dbd_sqlite3.lo"
397      test $apu_have_freetds = 1 && objs="$objs dbd/apr_dbd_freetds.lo"
398      EXTRA_OBJECTS="$EXTRA_OBJECTS $objs"
400      # Use libtool *.la for mysql if available
401      if test $apu_have_mysql = 1; then
402        for flag in $LDADD_dbd_mysql
403        do
404          dir=`echo $flag | grep "^-L" | sed s:-L::`
405          if test "x$dir" != 'x'; then
406            if test -f "$dir/libmysqlclient_r.la"; then
407              LDADD_dbd_mysql=$dir/libmysqlclient_r.la
408              break
409            fi
410          fi
411        done
412      fi
414      APRUTIL_LIBS="$APRUTIL_LIBS $LDADD_dbd_pgsql $LDADD_dbd_sqlite2 $LDADD_dbd_sqlite3 $LDADD_dbd_oracle $LDADD_dbd_mysql $LDADD_dbd_freetds"
415      APRUTIL_EXPORT_LIBS="$APRUTIL_EXPORT_LIBS $LDADD_dbd_pgsql $LDADD_dbd_sqlite2 $LDADD_dbd_sqlite3 $LDADD_dbd_oracle $LDADD_dbd_mysql $LDADD_dbd_freetds"
416   else
417      AC_DEFINE([APU_DSO_BUILD], 1, [Define if DBD drivers are built as DSOs])
418      
419      dsos=
420      test $apu_have_oracle = 1 && dsos="$dsos dbd/apr_dbd_oracle.la"
421      test $apu_have_pgsql = 1 && dsos="$dsos dbd/apr_dbd_pgsql.la"
422      test $apu_have_mysql = 1 && dsos="$dsos dbd/apr_dbd_mysql.la"
423      test $apu_have_sqlite2 = 1 && dsos="$dsos dbd/apr_dbd_sqlite2.la"
424      test $apu_have_sqlite3 = 1 && dsos="$dsos dbd/apr_dbd_sqlite3.la"
425      test $apu_have_freetds = 1 && dsos="$dsos dbd/apr_dbd_freetds.la"
427      APU_MODULES="$APU_MODULES $dsos"
428   fi