1# Copyright (C) 2005  Internet Systems Consortium, Inc. ("ISC")
2#
3# Permission to use, copy, modify, and distribute this software for any
4# purpose with or without fee is hereby granted, provided that the above
5# copyright notice and this permission notice appear in all copies.
6#
7# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
8# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
10# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
12# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13# PERFORMANCE OF THIS SOFTWARE.
14
15#
16# Shorthand.  Note quoting: DLZ_DRIVER_DIR expanded in Makefile, not here.
17#
18dlzdir='${DLZ_DRIVER_DIR}'
19
20#
21# Private autoconf macro to simplify configuring drivers:
22#
23#   DLZ_ADD_DRIVER(DEFINE, DRIVER, INCLUDES, LIBS)
24#
25# where:
26#   DEFINE is FOO (to define -DDLZ_FOO)
27#   DRIVER is dlz_foo_driver (sources without the .c)
28#   INCLUDES is any necessary include definitions
29#   LIBS is any necessary library definitions
30#
31AC_DEFUN(DLZ_ADD_DRIVER, [
32	CONTRIB_DLZ="$CONTRIB_DLZ -DDLZ_$1"
33	for i in $2
34	do
35		DLZ_DRIVER_SRCS="$DLZ_DRIVER_SRCS $dlzdir/$i.c"
36		DLZ_DRIVER_OBJS="$DLZ_DRIVER_OBJS $i.$O"
37	done
38	if test -n "$3"
39	then
40		DLZ_DRIVER_INCLUDES="$DLZ_DRIVER_INCLUDES $3"
41	fi
42	if test -n "$4"
43	then
44		DLZ_DRIVER_LIBS="$DLZ_DRIVER_LIBS $4"
45	fi
46])
47
48#
49# Check for the various DLZ drivers
50#
51
52#
53# Was --with-dlz-postgres specified?
54#
55
56AC_MSG_CHECKING(for Postgres DLZ driver)
57AC_ARG_WITH(dlz_postgres,
58[  --with-dlz-postgres[=PATH]   Build with Postgres DLZ driver [yes|no|path].
59			       (Required to use Postgres with DLZ)],
60    use_dlz_postgres="$withval", use_dlz_postgres="no")
61
62if test "$use_dlz_postgres" != "no"
63then
64	if test "$use_dlz_postgres" != "yes"
65        then
66                AC_PATH_PROGS(PG_CONFIG, pg_config, [not found], $use_dlz_postgres/bin)
67	else
68                AC_PATH_PROGS(PG_CONFIG, pg_config, [not found])
69	fi
70
71	if test "$PG_CONFIG" != "not found"
72	then
73		use_dlz_postgres=`$PG_CONFIG --includedir`
74		use_dlz_postgres_lib=`$PG_CONFIG --libdir`
75	else
76		pgprefix="$use_dlz_postgres"
77		use_dlz_postgres="$pgprefix/include"
78		use_dlz_postgres_lib="$pgprefix/lib"
79	fi
80fi
81
82if test "$use_dlz_postgres" = "yes/include"
83then
84	# User did not specify path and Postgres didn't say - guess it
85	pgdirs="/usr /usr/local /usr/local/pgsql /usr/pkg"
86	for d in $pgdirs
87	do
88		if test -f $d/include/libpq-fe.h
89		then
90			use_dlz_postgres=$d/include
91			use_dlz_postgres_lib=$d/lib
92			break
93		fi
94	done
95fi
96
97if test "$use_dlz_postgres" = "yes/include"
98then
99	# Still no joy, give up
100
101	AC_MSG_RESULT(not found)
102	AC_MSG_ERROR(
103[No pg_config and PostgreSQL was not found in any of $pgdirs; use --with-dlz-postgres=/path or put pg_config in your path])
104fi
105
106case "$use_dlz_postgres" in
107	no)
108		AC_MSG_RESULT(no)
109		;;
110	*)
111		DLZ_ADD_DRIVER(POSTGRES, dlz_postgres_driver,
112				[-I$use_dlz_postgres],
113				[-L$use_dlz_postgres_lib -lpq])
114
115		AC_MSG_RESULT(
116[using PostgreSQL from $use_dlz_postgres_lib and $use_dlz_postgres])
117		;;
118esac
119
120
121#
122# Was --with-dlz-mysql specified?
123#
124
125AC_MSG_CHECKING(for MySQL DLZ driver)
126AC_ARG_WITH(dlz_mysql,
127[  --with-dlz-mysql[=PATH]   Build with MySQL DLZ driver [yes|no|path].
128			       (Required to use MySQL with DLZ)],
129    use_dlz_mysql="$withval", use_dlz_mysql="no")
130
131mysql_include=""
132mysql_lib=""
133if test "$use_dlz_mysql" = "yes"
134then
135	# User did not specify a path - guess it
136	mysqldirs="/usr /usr/local /usr/local/mysql /usr/pkg"
137	for d in $mysqldirs
138	do
139		if test -f $d/include/mysql/mysql.h
140		then
141			use_dlz_mysql=$d
142			mysql_include=$d/include/mysql
143			if test -d $d/lib/mysql
144			then
145				mysql_lib=$d/lib/mysql
146			else
147				mysql_lib=$d/lib
148			fi
149			break
150		elif test -f $d/include/mysql.h
151		then
152			use_dlz_mysql=$d
153			mysql_include=$d/include
154			if test -d $d/lib/mysql
155			then
156				mysql_lib=$d/lib/mysql
157			else
158				mysql_lib=$d/lib
159			fi
160			break
161		fi
162	done
163elif test "$use_dlz_mysql" != "no"
164then
165	d=$use_dlz_mysql
166	if test -f $d/include/mysql/mysql.h
167	then
168		mysql_include=$d/include/mysql
169		if test -d $d/lib/mysql
170		then
171			mysql_lib=$d/lib/mysql
172		else
173			mysql_lib=$d/lib
174		fi
175	elif test -f $d/include/mysql.h
176	then
177		mysql_include=$d/include
178		if test -d $d/lib/mysql
179		then
180			mysql_lib=$d/lib/mysql
181		else
182			mysql_lib=$d/lib
183		fi
184	fi
185fi
186
187if test "$use_dlz_mysql" = "yes"
188then
189	AC_MSG_RESULT(not found)
190	AC_MSG_ERROR(
191[MySQL was not found in any of $mysqldirs; use --with-dlz-mysql=/path])
192fi
193
194case "$use_dlz_mysql" in
195	no)
196		AC_MSG_RESULT(no)
197		;;
198	*)
199		DLZ_ADD_DRIVER(MYSQL, dlz_mysql_driver,
200				[-I${mysql_include}],
201				[-L${mysql_lib} -lmysqlclient -lz -lcrypt -lm])
202
203		AC_MSG_RESULT(
204[using mysql from ${mysql_lib} and ${mysql_include}])
205		;;
206esac
207
208
209#
210# Was --with-dlz-bdb specified?
211#
212
213AC_MSG_CHECKING(for Berkeley DB DLZ driver...)
214AC_ARG_WITH(dlz_bdb,
215[  --with-dlz-bdb[=PATH]   Build with Berkeley DB DLZ driver [yes|no|path].
216			       (Required to use Berkeley DB with DLZ)],
217    use_dlz_bdb="$withval", use_dlz_bdb="no")
218
219case "$use_dlz_bdb" in
220	no)
221		AC_MSG_RESULT(no)
222		;;
223	*)
224		if test "$use_dlz_bdb" = "yes"
225		then
226			# User did not specify a path - guess directories
227			bdbdirs="/usr/local /usr/pkg /usr"
228		elif test -d "$use_dlz_bdb"
229		then
230			# User specified directory and it exists
231			bdbdirs="$use_dlz_bdb"
232		else
233			AC_MSG_RESULT(not found)
234			AC_MSG_ERROR([path $use_dlz_bdb does not exist])
235			bdbdirs=""
236		fi
237
238		# Use path we were given or guessed.  This is insanely
239		# complicated because we have to search for a bunch of
240		# platform-specific variations and have to check
241		# separately for include and library directories.
242
243		# Set both to yes, so we can check them later
244		dlz_bdb_inc="yes"
245		dlz_bdb_libs="yes"
246
247                AC_MSG_RESULT( )
248		for dd in $bdbdirs
249		do
250			# Skip nonexistant directories
251			if test ! -d "$dd"
252			then
253				continue
254			fi
255
256			# Check other locations for includes.
257			# Order is important (sigh).
258
259			bdb_incdirs="/db53 /db51 /db48 /db47 /db46 /db45 /db44 /db43 /db42 /db41 /db4 /db"
260			# include a blank element first
261			for d in "" $bdb_incdirs
262			do
263				if test -f "$dd/include${d}/db.h"
264				then
265					dlz_bdb_inc="-I$dd/include${d}"
266					break
267				fi
268			done
269
270			# Give up on this directory if we couldn't
271			# find the include subdir
272
273			if test "$dlz_bdb_inc" = "yes"
274			then
275				continue
276			fi
277
278			# Look for libname other than libdb.so.
279			# Order is important (sigh).
280
281			bdb_libnames="db53 db-5.3 db51 db-5.1 db48 db-4.8 db47 db-4.7 db46 db-4.6 db45 db-4.5 db44 db-4.4 db43 db-4.3 db42 db-4.2 db41 db-4.1 db"
282			for d in $bdb_libnames
283			do
284				if test "$dd" = "/usr"
285				then
286					AC_CHECK_LIB($d, db_create, dlz_bdb_libs="-l${d}")
287					if test $dlz_bdb_libs != "yes"
288					then
289						break
290					fi
291				elif test -f "$dd/lib/lib${d}.so"
292				then
293					dlz_bdb_libs="-L${dd}/lib -l${d}"
294					break
295				fi
296			done
297
298			# If we found both incdir and lib, we're done
299			if test "$dlz_bdb_libs" != "yes"
300			then
301				break
302			fi
303
304			# Otherwise, we're starting over
305
306			dlz_bdb_inc="yes"
307			dlz_bdb_libs="yes"
308		done
309
310		# Done searching, now make sure we got everything.
311
312		if test "$dlz_bdb_inc" = "yes"
313		then
314			AC_MSG_ERROR([could not find Berkeley DB include directory])
315		fi
316
317		if test "$dlz_bdb_libs" = "yes"
318		then
319			AC_MSG_RESULT(not found)
320			AC_MSG_ERROR([could not find Berkeley DB library])
321		fi
322
323		DLZ_ADD_DRIVER(BDB, dlz_bdb_driver dlz_bdbhpt_driver,
324			       [$dlz_bdb_inc], [$dlz_bdb_libs])
325
326		AC_MSG_RESULT([using Berkeley DB: $dlz_bdb_inc $dlz_bdb_libs])
327
328		AC_CONFIG_FILES([contrib/dlz/bin/dlzbdb/Makefile])
329		;;
330esac
331
332
333#
334# Was --with-dlz-filesystem specified?
335#
336
337AC_MSG_CHECKING(for file system DLZ driver)
338AC_ARG_WITH(dlz_filesystem,
339[  --with-dlz-filesystem[=PATH]   Build with filesystem DLZ driver [yes|no].
340			       (Required to use file system driver with DLZ)],
341    use_dlz_filesystem="$withval", use_dlz_filesystem="no")
342
343case "$use_dlz_filesystem" in
344	no)
345		AC_MSG_RESULT(no)
346		;;
347	*)
348		DLZ_ADD_DRIVER(FILESYSTEM, dlz_filesystem_driver)
349		DLZ_SYSTEM_TEST=filesystem
350		AC_MSG_RESULT(yes)
351		;;
352esac
353
354
355#
356# Was --with-dlz-ldap specified?
357#
358
359AC_MSG_CHECKING(for LDAP DLZ driver)
360AC_ARG_WITH(dlz_ldap,
361[  --with-dlz-ldap[=PATH]   Build with LDAP DLZ driver [yes|no|path].
362			       (Required to use LDAP with DLZ)],
363    use_dlz_ldap="$withval", use_dlz_ldap="no")
364
365if test "$use_dlz_ldap" = "yes"
366then
367	# User did not specify a path - guess it
368	ldapdirs="/usr /usr/local /usr/pkg"
369	for d in $ldapdirs
370	do
371		if test -f $d/include/ldap.h
372		then
373			use_dlz_ldap=$d
374			break
375		fi
376	done
377fi
378
379if test "$use_dlz_ldap" = "yes"
380then
381	AC_MSG_RESULT(not found)
382	AC_MSG_ERROR(
383[LDAP headers were not found in any of $ldapdirs; use --with-dlz-ldap=/path])
384fi
385
386case "$use_dlz_ldap" in
387	no)
388		AC_MSG_RESULT(no)
389		;;
390	*)
391		DLZ_ADD_DRIVER(LDAP, dlz_ldap_driver,
392				[-I$use_dlz_ldap/include],
393				[-L$use_dlz_ldap/lib -lldap -llber])
394
395		AC_MSG_RESULT(
396[using LDAP from $use_dlz_ldap/lib and $use_dlz_ldap/include])
397		;;
398esac
399
400
401#
402# Was --with-dlz-odbc specified?
403#
404
405AC_MSG_CHECKING(for ODBC DLZ driver)
406AC_ARG_WITH(dlz_odbc,
407[  --with-dlz-odbc[=PATH]   Build with ODBC DLZ driver [yes|no|path].
408			       (Required to use ODBC with DLZ)],
409    use_dlz_odbc="$withval", use_dlz_odbc="no")
410
411if test "$use_dlz_odbc" = "yes"
412then
413	# User did not specify a path - guess it
414	libodbc_found=no
415	sql_h_found=no
416	AC_CHECK_HEADER(sql.h, sql_h_found=yes)
417	AC_CHECK_LIB(odbc, SQLConnect, libodbc_found=yes)
418
419	if test $libodbc_found = "yes" -o $sql_h_found = "yes"
420	then
421		use_dlz_odbc=system
422		dlz_odbc_include=""
423		dlz_odbc_libs="-lodbc"
424	else
425		odbcdirs="/usr /usr/local /usr/pkg"
426		for d in $odbcdirs
427		do
428			if test -f $d/include/sql.h -a -f $d/lib/libodbc.a
429			then
430				use_dlz_odbc=$d
431				dlz_odbc_include="-I$use_dlz_odbc/include"
432				dlz_odbc_libs="-L$use_dlz_odbc/lib -lodbc"
433				break
434			fi
435		done
436	fi
437fi
438
439case "$use_dlz_odbc" in
440	no)
441		AC_MSG_RESULT(no)
442		;;
443	yes)
444		AC_MSG_RESULT(not found)
445		AC_MSG_ERROR(
446[ODBC headers were not found in any of $odbcdirs; use --with-dlz-odbc=/path])
447		;;
448	*)
449		DLZ_ADD_DRIVER(ODBC, dlz_odbc_driver,
450				[$dlz_odbc_include],
451				[$dlz_odbc_libs])
452
453		AC_MSG_RESULT([using ODBC from $use_dlz_odbc])
454		;;
455esac
456
457
458#
459# Was --with-dlz-stub specified?
460#
461
462AC_MSG_CHECKING(for stub DLZ driver)
463AC_ARG_WITH(dlz_stub,
464[  --with-dlz-stub[=PATH]   Build with stub DLZ driver [yes|no].
465			       (Required to use stub driver with DLZ)],
466    use_dlz_stub="$withval", use_dlz_stub="no")
467
468case "$use_dlz_stub" in
469	no)
470		AC_MSG_RESULT(no)
471		;;
472	*)
473
474		DLZ_ADD_DRIVER(STUB, dlz_stub_driver)
475
476		AC_MSG_RESULT(yes)
477		;;
478esac
479
480# Add any additional DLZ drivers here.
481
482#
483# Finally, some generic stuff that applies to all drivers, assuming
484# we're compiling contrib DLZ drivers at all.
485#
486if test -n "$CONTRIB_DLZ"
487then
488	CONTRIB_DLZ="-DCONTRIB_DLZ $CONTRIB_DLZ"
489
490	#
491	# Where to find DLZ driver header files.
492	#
493	DLZ_DRIVER_INCLUDES="-I$dlzdir/include $DLZ_DRIVER_INCLUDES"
494
495	#
496	# Initialization and shutdown wrappers, helper functions.
497	#
498	DLZ_DRIVER_SRCS="$dlzdir/dlz_drivers.c $dlzdir/sdlz_helper.c $DLZ_DRIVER_SRCS"
499	DLZ_DRIVER_OBJS="dlz_drivers.$O sdlz_helper.$O $DLZ_DRIVER_OBJS"
500fi
501