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