Correct detection of various databases (PostgreSQL, MySQL, SQLite2/3, Oracle).
[apr-util.git] / build / dbd.m4
blob964698f2728da63152fa7f974ca6fcbb44f63b10
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   AC_ARG_WITH([pgsql], [
28   --with-pgsql=DIR          specify PostgreSQL location
29   ], [
30     apu_have_pgsql=0
31     if test "$withval" = "yes"; then
32       AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
33       if test "$apu_have_pgsql" == "0"; then
34         AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
35       fi
36     elif test "$withval" = "no"; then
37       apu_have_pgsql=0
38     else
39       old_cppflags="$CPPFLAGS"
40       old_ldflags="$LDFLAGS"
42       pgsql_CPPFLAGS="-I$withval/include"
43       pgsql_LDFLAGS="-L$withval/lib "
45       APR_ADDTO(CPPFLAGS, [$pgsql_CPPFLAGS])
46       APR_ADDTO(LDFLAGS, [$pgsql_LDFLAGS])
48       AC_MSG_NOTICE(checking for pgsql in $withval)
49       AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
50       if test "$apu_have_pgsql" != "0"; then
51         APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
52         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
53       fi
54       if test "$apu_have_pgsql" != "1"; then
55         AC_CHECK_HEADERS(postgresql/libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
56         if test "$apu_have_pgsql" != "0"; then
57           APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include/postgresql])
58           APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
59         fi
60       fi
62       CPPFLAGS="$old_cppflags"
63       LDFLAGS="$old_ldflags"
64     fi
65   ], [
66     apu_have_pgsql=0
67     AC_CHECK_HEADERS(libpq-fe.h, AC_CHECK_LIB(pq, PQsendQueryPrepared, [apu_have_pgsql=1]))
68   ])
69   AC_SUBST(apu_have_pgsql)
70   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
71   dnl we know the library is there.
72   if test "$apu_have_pgsql" = "1"; then
73     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lpq])
74     APR_ADDTO(APRUTIL_LIBS,[-lpq])
75   fi
77 dnl
78 AC_DEFUN([APU_CHECK_DBD_MYSQL], [
79   apu_have_mysql=0
81   AC_ARG_WITH([mysql], [
82   --with-mysql=DIR          **** SEE INSTALL.MySQL ****
83   ], [
84     apu_have_mysql=0
85     if test "$withval" = "yes"; then
86       old_cppflags="$CPPFLAGS"
87       old_ldflags="$LDFLAGS"
89       AC_PATH_PROG([MYSQL_CONFIG],[mysql_config])
90       if test "x$MYSQL_CONFIG" != 'x'; then
91         mysql_CPPFLAGS="`$MYSQL_CONFIG --include`"
92         mysql_LDFLAGS="`$MYSQL_CONFIG --libs_r`"
94         APR_ADDTO(CPPFLAGS, [$mysql_CPPFLAGS])
95         APR_ADDTO(LDFLAGS, [$mysql_LDFLAGS])
96       fi
98       AC_CHECK_HEADERS(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
99       if test "$apu_have_mysql" == "0"; then
100         AC_CHECK_HEADERS(mysql/mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
101       else
102         if test "x$MYSQL_CONFIG" != 'x'; then
103           APR_ADDTO(APRUTIL_INCLUDES, [$mysql_CPPFLAGS])
104           APR_ADDTO(APRUTIL_LDFLAGS, [$mysql_LDFLAGS])
105         fi
106       fi
108       CPPFLAGS="$old_cppflags"
109       LDFLAGS="$old_ldflags"
110     elif test "$withval" = "no"; then
111       apu_have_mysql=0
112     else
113       old_cppflags="$CPPFLAGS"
114       old_ldflags="$LDFLAGS"
116       AC_PATH_PROG([MYSQL_CONFIG],[mysql_config],,[$withval/bin])
117       if test "x$MYSQL_CONFIG" != 'x'; then
118         mysql_CPPFLAGS="`$MYSQL_CONFIG --include`"
119         mysql_LDFLAGS="`$MYSQL_CONFIG --libs_r`"
120       else
121         mysql_CPPFLAGS="-I$withval/include"
122         mysql_LDFLAGS="-L$withval/lib "
123       fi
125       APR_ADDTO(CPPFLAGS, [$mysql_CPPFLAGS])
126       APR_ADDTO(LDFLAGS, [$mysql_LDFLAGS])
128       AC_MSG_NOTICE(checking for mysql in $withval)
129       AC_CHECK_HEADERS(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
130       if test "$apu_have_mysql" != "0"; then
131         APR_ADDTO(APRUTIL_INCLUDES, [$mysql_CPPFLAGS])
132         APR_ADDTO(APRUTIL_LDFLAGS, [$mysql_LDFLAGS])
133       fi
135       if test "$apu_have_mysql" != "1"; then
136         AC_CHECK_HEADERS(mysql/mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
137         if test "$apu_have_mysql" != "0"; then
138           APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include/mysql])
139           APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
140         fi
141       fi
143       CPPFLAGS="$old_cppflags"
144       LDFLAGS="$old_ldflags"
145     fi
146   ], [
147     apu_have_mysql=0
149     old_cppflags="$CPPFLAGS"
150     old_ldflags="$LDFLAGS"
152     AC_PATH_PROG([MYSQL_CONFIG],[mysql_config])
153     if test "x$MYSQL_CONFIG" != 'x'; then
154       mysql_CPPFLAGS="`$MYSQL_CONFIG --include`"
155       mysql_LDFLAGS="`$MYSQL_CONFIG --libs_r`"
157       APR_ADDTO(CPPFLAGS, [$mysql_CPPFLAGS])
158       APR_ADDTO(LDFLAGS, [$mysql_LDFLAGS])
159     fi
161     AC_CHECK_HEADERS(mysql.h, AC_CHECK_LIB(mysqlclient_r, mysql_init, [apu_have_mysql=1]))
163     if test "$apu_have_mysql" != "0"; then
164       if test "x$MYSQL_CONFIG" != 'x'; then
165         APR_ADDTO(APRUTIL_INCLUDES, [$mysql_CPPFLAGS])
166         APR_ADDTO(APRUTIL_LDFLAGS, [$mysql_LDFLAGS])
167       fi
168     fi
170     CPPFLAGS="$old_cppflags"
171     LDFLAGS="$old_ldflags"
172   ])
174   AC_SUBST(apu_have_mysql)
176   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
177   dnl we know the library is there.
178   if test "$apu_have_mysql" = "1"; then
179     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lmysqlclient_r])
180     APR_ADDTO(APRUTIL_LIBS,[-lmysqlclient_r])
181   fi
184 AC_DEFUN([APU_CHECK_DBD_SQLITE3], [
185   apu_have_sqlite3=0
187   AC_ARG_WITH([sqlite3], [
188   --with-sqlite3=DIR         
189   ], [
190     apu_have_sqlite3=0
191     if test "$withval" = "yes"; then
192       AC_CHECK_HEADERS(sqlite3.h, AC_CHECK_LIB(sqlite3, sqlite3_open, [apu_have_sqlite3=1]))
193     elif test "$withval" = "no"; then
194       apu_have_sqlite3=0
195     else
196       old_cppflags="$CPPFLAGS"
197       old_ldflags="$LDFLAGS"
199       sqlite3_CPPFLAGS="-I$withval/include"
200       sqlite3_LDFLAGS="-L$withval/lib "
202       APR_ADDTO(CPPFLAGS, [$sqlite3_CPPFLAGS])
203       APR_ADDTO(LDFLAGS, [$sqlite3_LDFLAGS])
205       AC_MSG_NOTICE(checking for sqlite3 in $withval)
206       AC_CHECK_HEADERS(sqlite3.h, AC_CHECK_LIB(sqlite3, sqlite3_open, [apu_have_sqlite3=1]))
207       if test "$apu_have_sqlite3" != "0"; then
208         APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
209         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
210       fi
212       CPPFLAGS="$old_cppflags"
213       LDFLAGS="$old_ldflags"
214     fi
215   ], [
216     apu_have_sqlite3=0
217     AC_CHECK_HEADERS(sqlite3.h, AC_CHECK_LIB(sqlite3, sqlite3_open, [apu_have_sqlite3=1]))
218   ])
220   AC_SUBST(apu_have_sqlite3)
222   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
223   dnl we know the library is there.
224   if test "$apu_have_sqlite3" = "1"; then
225     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lsqlite3])
226     APR_ADDTO(APRUTIL_LIBS,[-lsqlite3])
227   fi
230 AC_DEFUN([APU_CHECK_DBD_SQLITE2], [
231   apu_have_sqlite2=0
233   AC_ARG_WITH([sqlite2], [
234   --with-sqlite2=DIR         
235   ], [
236     apu_have_sqlite2=0
237     if test "$withval" = "yes"; then
238       AC_CHECK_HEADERS(sqlite.h, AC_CHECK_LIB(sqlite, sqlite_open, [apu_have_sqlite2=1]))
239     elif test "$withval" = "no"; then
240       apu_have_sqlite2=0
241     else
242       old_cppflags="$CPPFLAGS"
243       old_ldflags="$LDFLAGS"
245       sqlite2_CPPFLAGS="-I$withval/include"
246       sqlite2_LDFLAGS="-L$withval/lib "
248       APR_ADDTO(CPPFLAGS, [$sqlite2_CPPFLAGS])
249       APR_ADDTO(LDFLAGS, [$sqlite2_LDFLAGS])
251       AC_MSG_NOTICE(checking for sqlite2 in $withval)
252       AC_CHECK_HEADERS(sqlite.h, AC_CHECK_LIB(sqlite, sqlite_open, [apu_have_sqlite2=1]))
253       if test "$apu_have_sqlite2" != "0"; then
254         APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
255         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/include])
256       fi
258       CPPFLAGS="$old_cppflags"
259       LDFLAGS="$old_ldflags"
260     fi
261   ], [
262     apu_have_sqlite2=0
263     AC_CHECK_HEADERS(sqlite.h, AC_CHECK_LIB(sqlite, sqlite_open, [apu_have_sqlite2=1]))
264   ])
266   AC_SUBST(apu_have_sqlite2)
268   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
269   dnl we know the library is there.
270   if test "$apu_have_sqlite2" = "1"; then
271     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lsqlite])
272     APR_ADDTO(APRUTIL_LIBS,[-lsqlite])
273   fi
276 AC_DEFUN([APU_CHECK_DBD_ORACLE], [
277   apu_have_oracle=0
279   AC_ARG_WITH([oracle], [
280   --with-oracle=DIR         specify ORACLE_HOME location
281   ], [
282     apu_have_oracle=0
283     if test "$withval" = "yes"; then
284       AC_CHECK_HEADERS(oci.h, AC_CHECK_LIB(clntsh, OCIEnvCreate, [apu_have_oracle=1]))
285     elif test "$withval" = "no"; then
286       apu_have_oracle=0
287     else
288       old_cppflags="$CPPFLAGS"
289       old_ldflags="$LDFLAGS"
291       oracle_CPPFLAGS="-I$withval/rdbms/demo -I$withval/rdbms/public"
292       oracle_LDFLAGS="-L$withval/lib "
294       APR_ADDTO(CPPFLAGS, [$oracle_CPPFLAGS])
295       APR_ADDTO(LDFLAGS, [$oracle_LDFLAGS])
297       AC_MSG_NOTICE(checking for oracle in $withval)
298       AC_CHECK_HEADERS(oci.h, AC_CHECK_LIB(clntsh, OCIEnvCreate, [apu_have_oracle=1]))
299       if test "$apu_have_oracle" != "0"; then
300         APR_ADDTO(APRUTIL_LDFLAGS, [-L$withval/lib])
301         APR_ADDTO(APRUTIL_LDFLAGS, [-R$withval/lib])
302         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/rdbms/demo])
303         APR_ADDTO(APRUTIL_INCLUDES, [-I$withval/rdbms/public])
304       fi
306       CPPFLAGS="$old_cppflags"
307       LDFLAGS="$old_ldflags"
308     fi
309   ], [
310     apu_have_oracle=0
311     AC_CHECK_HEADERS(oci.h, AC_CHECK_LIB(clntsh, OCIEnvCreate, [apu_have_oracle=1]))
312   ])
314   AC_SUBST(apu_have_oracle)
316   dnl Since we have already done the AC_CHECK_LIB tests, if we have it, 
317   dnl we know the library is there.
318   if test "$apu_have_oracle" = "1"; then
319     APR_ADDTO(APRUTIL_EXPORT_LIBS,[-lclntsh])
320     APR_ADDTO(APRUTIL_LIBS,[-lclntsh])
321   fi