configure.ac revision 238106
1238106Sdes#                                               -*- Autoconf -*-
2238106Sdes# Process this file with autoconf to produce a configure script.
3238106SdesAC_PREREQ(2.56)
4238106Sdessinclude(acx_nlnetlabs.m4)
5238106Sdessinclude(acx_pthread.m4)
6238106Sdessinclude(acx_python.m4)
7238106Sdessinclude(ac_pkg_swig.m4)
8238106Sdes
9238106SdesAC_INIT(unbound, 1.4.17, unbound-bugs@nlnetlabs.nl, unbound)
10238106Sdes
11238106SdesLIBUNBOUND_CURRENT=3
12238106SdesLIBUNBOUND_REVISION=1
13238106SdesLIBUNBOUND_AGE=1
14238106Sdes# 1.0.0 had 0:12:0
15238106Sdes# 1.0.1 had 0:13:0
16238106Sdes# 1.0.2 had 0:14:0
17238106Sdes# 1.1.0 had 0:15:0
18238106Sdes# 1.1.1 had 0:16:0
19238106Sdes# 1.2.0 had 0:17:0
20238106Sdes# 1.2.1 had 0:18:0
21238106Sdes# 1.3.0 had 1:0:0   # ub_cancel and -export-symbols.
22238106Sdes# 1.3.1 had 1:1:0
23238106Sdes# 1.3.2 had 1:2:0
24238106Sdes# 1.3.3 had 1:3:0
25238106Sdes# 1.3.4 had 1:4:0
26238106Sdes# 1.4.0-snapshots had 1:5:0
27238106Sdes# 1.4.0 had 1:5:0 (not 2:0:0)   # ub_result.why_bogus
28238106Sdes# 1.4.1 had 2:1:0
29238106Sdes# 1.4.2 had 2:2:0
30238106Sdes# 1.4.3 had 2:3:0
31238106Sdes# 1.4.4 had 2:4:0
32238106Sdes# 1.4.5 had 2:5:0
33238106Sdes# 1.4.6 had 2:6:0
34238106Sdes# 1.4.7 had 2:7:0
35238106Sdes# 1.4.8 had 2:8:0
36238106Sdes# 1.4.9 had 2:9:0
37238106Sdes# 1.4.10 had 2:10:0
38238106Sdes# 1.4.11 had 2:11:0
39238106Sdes# 1.4.12 had 2:12:0
40238106Sdes# 1.4.13 had 2:13:0
41238106Sdes# and 1.4.13p1 and 1.4.13.p2
42238106Sdes# 1.4.14 had 2:14:0
43238106Sdes# 1.4.15 had 3:0:1 # adds ub_version()
44238106Sdes# 1.4.16 had 3:1:1
45238106Sdes# 1.4.17 had 3:2:1
46238106Sdes
47238106Sdes#   Current  -- the number of the binary API that we're implementing
48238106Sdes#   Revision -- which iteration of the implementation of the binary
49238106Sdes#               API are we supplying?
50238106Sdes#   Age      -- How many previous binary API versions do we also
51238106Sdes#               support?
52238106Sdes#
53238106Sdes# If we release a new version that does not change the binary API,
54238106Sdes# increment Revision.
55238106Sdes#
56238106Sdes# If we release a new version that changes the binary API, but does
57238106Sdes# not break programs compiled against the old binary API, increment
58238106Sdes# Current and Age.  Set Revision to 0, since this is the first
59238106Sdes# implementation of the new API.
60238106Sdes#
61238106Sdes# Otherwise, we're changing the binary API and breaking bakward
62238106Sdes# compatibility with old binaries.  Increment Current.  Set Age to 0,
63238106Sdes# since we're backward compatible with no previous APIs.  Set Revision
64238106Sdes# to 0 too.
65238106SdesAC_SUBST(LIBUNBOUND_CURRENT)
66238106SdesAC_SUBST(LIBUNBOUND_REVISION)
67238106SdesAC_SUBST(LIBUNBOUND_AGE)
68238106Sdes
69238106Sdespretty_cmdline() {
70238106Sdes	cmdline=""
71238106Sdes	while test -n "$1"; do
72238106Sdes		cmdline="$cmdline '"`echo $1 | sed -e 's/\\\\/\\\\\\\\/g' | sed -e 's/"/\\\\"/g' `"'"
73238106Sdes		shift
74238106Sdes	done
75238106Sdes}
76238106Sdespretty_cmdline $@
77238106SdesAC_DEFINE_UNQUOTED(CONFIGURE_BUILD_WITH, ["$cmdline"], [configure flags])
78238106SdesAC_CANONICAL_TARGET
79238106SdesAC_DEFINE_UNQUOTED(CONFIGURE_TARGET, ["$target"], [configure target system])
80238106SdesAC_DEFINE_UNQUOTED(CONFIGURE_DATE, ["`date`"], [configure date])
81238106Sdes
82238106SdesCFLAGS="$CFLAGS"
83238106SdesAC_AIX
84238106Sdes
85238106Sdesdnl
86238106Sdesdnl By default set prefix to /usr/local
87238106Sdesdnl
88238106Sdescase "$prefix" in
89238106Sdes        NONE)
90238106Sdes		prefix="/usr/local"
91238106Sdes        ;;
92238106Sdesesac
93238106Sdes
94238106Sdes# are we on MinGW?
95238106Sdesif uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
96238106Sdeselse 
97238106Sdes	if echo $target | grep mingw32 >/dev/null; then on_mingw="yes"
98238106Sdes	else on_mingw="no"; fi
99238106Sdesfi
100238106Sdes
101238106Sdes#
102238106Sdes# Determine configuration file
103238106Sdes# the eval is to evaluate shell expansion twice
104238106Sdesif test $on_mingw = "no"; then
105238106Sdes  ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
106238106Sdeselse
107238106Sdes  ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
108238106Sdesfi
109238106SdesAC_ARG_WITH([conf_file],
110238106Sdes        AC_HELP_STRING([--with-conf-file=path], 
111238106Sdes	[Pathname to the Unbound configuration file]),
112238106Sdes	[ub_conf_file="$withval"])
113238106SdesAC_SUBST(ub_conf_file)
114238106SdesACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
115238106SdesAC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
116238106Sdes
117238106Sdes# Determine run, chroot directory and pidfile locations
118238106SdesAC_ARG_WITH(run-dir, 
119238106Sdes    AC_HELP_STRING([--with-run-dir=path], 
120238106Sdes    [set default directory to chdir to (by default dir part of cfg file)]), 
121238106Sdes    UNBOUND_RUN_DIR="$withval", 
122238106Sdesif test $on_mingw = no; then
123238106Sdes    UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
124238106Sdeselse
125238106Sdes    UNBOUND_RUN_DIR=""
126238106Sdesfi
127238106Sdes)
128238106SdesAC_SUBST(UNBOUND_RUN_DIR)
129238106SdesACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
130238106SdesAC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
131238106Sdes
132238106SdesAC_ARG_WITH(chroot-dir, 
133238106Sdes    AC_HELP_STRING([--with-chroot-dir=path], 
134238106Sdes    [set default directory to chroot to (by default same as run-dir)]), 
135238106Sdes    UNBOUND_CHROOT_DIR="$withval", 
136238106Sdesif test $on_mingw = no; then
137238106Sdes    UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
138238106Sdeselse
139238106Sdes    UNBOUND_CHROOT_DIR=""
140238106Sdesfi
141238106Sdes)
142238106SdesAC_SUBST(UNBOUND_CHROOT_DIR)
143238106SdesACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
144238106SdesAC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
145238106Sdes
146238106SdesAC_ARG_WITH(share-dir,
147238106Sdes    AC_HELP_STRING([--with-share-dir=path],
148238106Sdes    [set default directory with shared data (by default same as share/unbound)]),
149238106Sdes    UNBOUND_SHARE_DIR="$withval",
150238106Sdes    UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
151238106SdesAC_SUBST(UNBOUND_SHARE_DIR)
152238106SdesAC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
153238106Sdes
154238106SdesAC_ARG_WITH(pidfile, 
155238106Sdes    AC_HELP_STRING([--with-pidfile=filename], 
156238106Sdes    [set default pathname to unbound pidfile (default run-dir/unbound.pid)]), 
157238106Sdes    UNBOUND_PIDFILE="$withval", 
158238106Sdesif test $on_mingw = no; then
159238106Sdes    UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
160238106Sdeselse
161238106Sdes    UNBOUND_PIDFILE=""
162238106Sdesfi
163238106Sdes)
164238106SdesAC_SUBST(UNBOUND_PIDFILE)
165238106SdesACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
166238106SdesAC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
167238106Sdes
168238106SdesAC_ARG_WITH(rootkey-file, 
169238106Sdes    AC_HELP_STRING([--with-rootkey-file=filename], 
170238106Sdes    [set default pathname to root key file (default run-dir/root.key). This file is read and written.]), 
171238106Sdes    UNBOUND_ROOTKEY_FILE="$withval", 
172238106Sdesif test $on_mingw = no; then
173238106Sdes    UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
174238106Sdeselse
175238106Sdes    UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
176238106Sdesfi
177238106Sdes)
178238106SdesAC_SUBST(UNBOUND_ROOTKEY_FILE)
179238106SdesACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
180238106SdesAC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
181238106Sdes
182238106SdesAC_ARG_WITH(rootcert-file, 
183238106Sdes    AC_HELP_STRING([--with-rootcert-file=filename], 
184238106Sdes    [set default pathname to root update certificate file (default run-dir/icannbundle.pem).  This file need not exist if you are content with the builtin.]), 
185238106Sdes    UNBOUND_ROOTCERT_FILE="$withval", 
186238106Sdesif test $on_mingw = no; then
187238106Sdes    UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
188238106Sdeselse
189238106Sdes    UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
190238106Sdesfi
191238106Sdes)
192238106SdesAC_SUBST(UNBOUND_ROOTCERT_FILE)
193238106SdesACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
194238106SdesAC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
195238106Sdes
196238106SdesAC_ARG_WITH(username, 
197238106Sdes    AC_HELP_STRING([--with-username=user], 
198238106Sdes    [set default user that unbound changes to (default user is unbound)]), 
199238106Sdes    UNBOUND_USERNAME="$withval", 
200238106Sdes    UNBOUND_USERNAME="unbound")
201238106SdesAC_SUBST(UNBOUND_USERNAME)
202238106SdesAC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
203238106Sdes
204238106SdesAC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
205238106SdesACX_RSRC_VERSION(wnvs)
206238106SdesAC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
207238106Sdes
208238106Sdes# Checks for typedefs, structures, and compiler characteristics.
209238106SdesAC_C_CONST
210238106SdesAC_LANG_C
211238106SdesACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
212238106SdesACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
213238106SdesAC_PROG_CC
214238106SdesACX_DEPFLAG
215238106SdesACX_DETERMINE_EXT_FLAGS_UNBOUND
216238106Sdes
217238106Sdes# debug mode flags warnings
218238106SdesAC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
219238106SdesAC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
220238106Sdesif test "$enable_debug" = "yes"; then debug_enabled="$enable_debug"; 
221238106Sdeselse debug_enabled="$enable_checking"; fi
222238106SdesAC_SUBST(debug_enabled)
223238106Sdescase "$debug_enabled" in
224238106Sdes        yes)
225238106Sdes		ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
226238106Sdes		ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
227238106Sdes		ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
228238106Sdes		ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
229238106Sdes		AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
230238106Sdes		;;
231238106Sdes	no|*)
232238106Sdes		# nothing to do.
233238106Sdes		;;
234238106Sdesesac
235238106SdesACX_CHECK_FLTO
236238106Sdes
237238106SdesAC_C_INLINE
238238106SdesACX_CHECK_FORMAT_ATTRIBUTE
239238106SdesACX_CHECK_UNUSED_ATTRIBUTE
240238106Sdes
241238106Sdesif test "$srcdir" != "."; then
242238106Sdes	CPPFLAGS="$CPPFLAGS -I$srcdir"
243238106Sdesfi
244238106Sdes
245238106SdesAC_DEFUN([ACX_YYLEX_DESTROY], [
246238106Sdes	AC_MSG_CHECKING([for yylex_destroy])
247238106Sdes	if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
248238106Sdes		AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
249238106Sdes		AC_MSG_RESULT(yes)
250238106Sdes	else AC_MSG_RESULT(no); fi
251238106Sdes])
252238106Sdes
253238106SdesAC_PROG_LEX
254238106SdesACX_YYLEX_DESTROY
255238106SdesAC_PROG_YACC
256238106SdesAC_CHECK_PROG(doxygen, doxygen, doxygen)
257238106SdesAC_CHECK_TOOL(STRIP, strip)
258238106SdesACX_LIBTOOL_C_ONLY
259238106Sdes
260238106Sdes# Checks for header files.
261238106SdesAC_CHECK_HEADERS([stdarg.h stdbool.h netinet/in.h sys/param.h sys/socket.h sys/uio.h sys/resource.h arpa/inet.h syslog.h netdb.h sys/wait.h pwd.h glob.h grp.h login_cap.h winsock2.h ws2tcpip.h],,, [AC_INCLUDES_DEFAULT])
262238106Sdes
263238106Sdes# check for types.  
264238106Sdes# Using own tests for int64* because autoconf builtin only give 32bit.
265238106SdesAC_CHECK_TYPE(int8_t, signed char)
266238106SdesAC_CHECK_TYPE(int16_t, short)
267238106SdesAC_CHECK_TYPE(int32_t, int)
268238106SdesAC_CHECK_TYPE(int64_t, long long)
269238106SdesAC_CHECK_TYPE(uint8_t, unsigned char)
270238106SdesAC_CHECK_TYPE(uint16_t, unsigned short)
271238106SdesAC_CHECK_TYPE(uint32_t, unsigned int)
272238106SdesAC_CHECK_TYPE(uint64_t, unsigned long long)
273238106SdesAC_TYPE_SIZE_T
274238106SdesAC_CHECK_TYPE(ssize_t, int)
275238106SdesAC_TYPE_UID_T
276238106SdesAC_TYPE_PID_T
277238106SdesAC_TYPE_OFF_T
278238106SdesACX_TYPE_U_CHAR
279238106SdesACX_TYPE_RLIM_T
280238106SdesACX_TYPE_SOCKLEN_T
281238106SdesACX_TYPE_IN_ADDR_T
282238106SdesACX_TYPE_IN_PORT_T
283238106SdesACX_CHECK_MEMCMP_SIGNED
284238106Sdes
285238106Sdes# add option to disable the evil rpath
286238106SdesACX_ARG_RPATH
287238106SdesAC_SUBST(RUNTIME_PATH)
288238106Sdes
289238106Sdes# check to see if libraries are needed for these functions.
290238106SdesAC_SEARCH_LIBS([inet_pton], [nsl])
291238106SdesAC_SEARCH_LIBS([socket], [socket])
292238106Sdes
293238106Sdes# check wether strptime also works
294238106SdesAC_DEFUN([AC_CHECK_STRPTIME_WORKS],
295238106Sdes[AC_REQUIRE([AC_PROG_CC])
296238106SdesAC_MSG_CHECKING(whether strptime works)
297238106Sdesif test c${cross_compiling} = cno; then
298238106SdesAC_RUN_IFELSE([AC_LANG_SOURCE([[
299238106Sdes#define _XOPEN_SOURCE
300238106Sdes#include <time.h>
301238106Sdesint main(void) { struct tm tm; char *res;
302238106Sdesres = strptime("2010-07-15T00:00:00+00:00", "%t%Y%t-%t%m%t-%t%d%tT%t%H%t:%t%M%t:%t%S%t", &tm);
303238106Sdesif (!res) return 2;
304238106Sdesres = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
305238106Sdesif (!res) return 1; return 0; }
306238106Sdes]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
307238106Sdeselse
308238106Sdeseval "ac_cv_c_strptime_works=maybe"
309238106Sdesfi
310238106SdesAC_MSG_RESULT($ac_cv_c_strptime_works)
311238106Sdesif test $ac_cv_c_strptime_works = no; then
312238106SdesAC_LIBOBJ(strptime)
313238106Sdeselse
314238106SdesAC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
315238106Sdesfi
316238106Sdes])dnl
317238106Sdes
318238106Sdes# check some functions of the OS before linking libs (while still runnable).
319238106SdesAC_FUNC_CHOWN
320238106SdesAC_FUNC_FORK
321238106SdesAC_TYPE_SIGNAL
322238106SdesAC_FUNC_FSEEKO
323238106SdesACX_SYS_LARGEFILE
324238106SdesACX_CHECK_NONBLOCKING_BROKEN
325238106SdesACX_MKDIR_ONE_ARG
326238106SdesAC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
327238106Sdes
328238106Sdes# set memory allocation checking if requested
329238106SdesAC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
330238106Sdes	[ enable to memory allocation statistics, for debug purposes ]), 
331238106Sdes	, )
332238106SdesAC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
333238106Sdes	[ enable for lightweight alloc assertions, for debug purposes ]), 
334238106Sdes	, )
335238106SdesAC_ARG_ENABLE(alloc-nonregional, AC_HELP_STRING([--enable-alloc-nonregional],
336238106Sdes	[ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]), 
337238106Sdes	, )
338238106Sdesif test x_$enable_alloc_nonregional = x_yes; then
339238106Sdes	AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
340238106Sdesfi
341238106Sdesif test x_$enable_alloc_checks = x_yes; then
342238106Sdes	AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
343238106Sdeselse
344238106Sdes	if test x_$enable_alloc_lite = x_yes; then
345238106Sdes		AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
346238106Sdes	else
347238106Sdes		ACX_FUNC_MALLOC([unbound])
348238106Sdes	fi
349238106Sdesfi
350238106Sdes
351238106Sdes# check windows threads (we use them, not pthreads, on windows).
352238106Sdesif test "$on_mingw" = "yes"; then
353238106Sdes# check windows threads
354238106Sdes	AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
355238106Sdes	AC_MSG_CHECKING([for CreateThread])
356238106Sdes	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
357238106Sdes#ifdef HAVE_WINDOWS_H
358238106Sdes#include <windows.h>
359238106Sdes#endif
360238106Sdes], [
361238106Sdes	HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
362238106Sdes])],
363238106Sdes	AC_MSG_RESULT(yes)
364238106Sdes	AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
365238106Sdes,	
366238106Sdes	AC_MSG_RESULT(no)
367238106Sdes)
368238106Sdes
369238106Sdeselse
370238106Sdes# not on mingw, check thread libraries.
371238106Sdes
372238106Sdes# check for thread library.
373238106Sdes# check this first, so that the pthread lib does not get linked in via
374238106Sdes# libssl or libpython, and thus distorts the tests, and we end up using
375238106Sdes# the non-threadsafe C libraries.
376238106SdesAC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], 
377238106Sdes [use pthreads library, or --without-pthreads to disable threading support.]), 
378238106Sdes [ ],[ withval="yes" ])
379238106Sdesub_have_pthreads=no
380238106Sdesif test x_$withval != x_no; then
381238106Sdes	ACX_PTHREAD([
382238106Sdes		AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
383238106Sdes		LIBS="$PTHREAD_LIBS $LIBS"
384238106Sdes		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
385238106Sdes		CC="$PTHREAD_CC"
386238106Sdes		ub_have_pthreads=yes
387238106Sdes		AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
388238106Sdes		])
389238106Sdesfi
390238106Sdes
391238106Sdes# check solaris thread library 
392238106SdesAC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], 
393238106Sdes	[use solaris native thread library.]), [ ],[ withval="no" ])
394238106Sdesub_have_sol_threads=no
395238106Sdesif test x_$withval != x_no; then
396238106Sdes	if test x_$ub_have_pthreads != x_no; then
397238106Sdes	    AC_WARN([Have pthreads already, ignoring --with-solaris-threads])
398238106Sdes	else
399238106Sdes	AC_SEARCH_LIBS(thr_create, [thread],
400238106Sdes	[
401238106Sdes    		AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
402238106Sdes
403238106Sdes		ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
404238106Sdes			[CFLAGS="$CFLAGS -D_REENTRANT"])
405238106Sdes		ub_have_sol_threads=yes
406238106Sdes	] , [ 
407238106Sdes		AC_ERROR([no solaris threads found.]) 
408238106Sdes	])
409238106Sdes	fi
410238106Sdesfi
411238106Sdes
412238106Sdesfi # end of non-mingw check of thread libraries
413238106Sdes
414238106Sdes# Check for PyUnbound
415238106SdesAC_ARG_WITH(pyunbound,
416238106Sdes   AC_HELP_STRING([--with-pyunbound],
417238106Sdes   [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
418238106Sdes   [], [ withval="no" ])
419238106Sdes
420238106Sdesub_test_python=no
421238106Sdesub_with_pyunbound=no
422238106Sdesif test x_$withval != x_no; then
423238106Sdes   ub_with_pyunbound=yes
424238106Sdes   ub_test_python=yes
425238106Sdesfi
426238106Sdes
427238106Sdes# Check for Python module
428238106SdesAC_ARG_WITH(pythonmodule,
429238106Sdes   AC_HELP_STRING([--with-pythonmodule],
430238106Sdes   [build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
431238106Sdes   [], [ withval="no" ])
432238106Sdes
433238106Sdesub_with_pythonmod=no
434238106Sdesif test x_$withval != x_no; then
435238106Sdes   ub_with_pythonmod=yes
436238106Sdes   ub_test_python=yes
437238106Sdesfi
438238106Sdes
439238106Sdes# Check for Python & SWIG only on PyUnbound or PyModule
440238106Sdesif test x_$ub_test_python != x_no; then
441238106Sdes
442238106Sdes   # Check for Python
443238106Sdes   ub_have_python=no
444238106Sdes   ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
445238106Sdes   AC_PYTHON_DEVEL
446238106Sdes   if test ! -z "$PYTHON_VERSION"; then
447238106Sdes	if test `$PYTHON -c "print '$PYTHON_VERSION' >= '2.4.0'"` = "False"; then
448238106Sdes		AC_ERROR([Python version >= 2.4.0 is required])
449238106Sdes	fi
450238106Sdes
451238106Sdes      # Have Python
452238106Sdes      AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
453238106Sdes      LIBS="$PYTHON_LDFLAGS $LIBS"
454238106Sdes      CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
455238106Sdes      ub_have_python=yes
456238106Sdes
457238106Sdes      # Check for SWIG
458238106Sdes      ub_have_swig=no
459238106Sdes      AC_PROG_SWIG
460238106Sdes      AC_MSG_CHECKING(SWIG)
461238106Sdes      if test ! -x "$SWIG"; then
462238106Sdes         AC_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
463238106Sdes      else
464238106Sdes         AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
465238106Sdes         AC_SUBST(swig, "$SWIG")
466238106Sdes         AC_MSG_RESULT(present)
467238106Sdes
468238106Sdes         # If have Python & SWIG
469238106Sdes         # Declare PythonMod
470238106Sdes         if test x_$ub_with_pythonmod != x_no; then
471238106Sdes            AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
472238106Sdes            WITH_PYTHONMODULE=yes
473238106Sdes            AC_SUBST(WITH_PYTHONMODULE)
474238106Sdes	    PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
475238106Sdes	    AC_SUBST(PYTHONMOD_OBJ)
476238106Sdes	    PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
477238106Sdes	    AC_SUBST(PYTHONMOD_HEADER)
478238106Sdes	    PYTHONMOD_INSTALL=pythonmod-install
479238106Sdes	    AC_SUBST(PYTHONMOD_INSTALL)
480238106Sdes	    PYTHONMOD_UNINSTALL=pythonmod-uninstall
481238106Sdes	    AC_SUBST(PYTHONMOD_UNINSTALL)
482238106Sdes         fi
483238106Sdes
484238106Sdes         # Declare PyUnbound
485238106Sdes         if test x_$ub_with_pyunbound != x_no; then
486238106Sdes            AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
487238106Sdes            WITH_PYUNBOUND=yes
488238106Sdes            AC_SUBST(WITH_PYUNBOUND)
489238106Sdes	    PYUNBOUND_OBJ="libunbound_wrap.lo"
490238106Sdes	    AC_SUBST(PYUNBOUND_OBJ)
491238106Sdes	    PYUNBOUND_TARGET="_unbound.la"
492238106Sdes	    AC_SUBST(PYUNBOUND_TARGET)
493238106Sdes	    PYUNBOUND_INSTALL=pyunbound-install
494238106Sdes	    AC_SUBST(PYUNBOUND_INSTALL)
495238106Sdes	    PYUNBOUND_UNINSTALL=pyunbound-uninstall
496238106Sdes	    AC_SUBST(PYUNBOUND_UNINSTALL)
497238106Sdes         fi
498238106Sdes      fi
499238106Sdes   else
500238106Sdes      AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
501238106Sdes      ub_with_pyunbound=no
502238106Sdes      ub_with_pythonmod=no
503238106Sdes   fi
504238106Sdesfi
505238106Sdes
506238106Sdesif test "`uname`" = "NetBSD"; then
507238106Sdes	NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
508238106Sdes	AC_SUBST(NETBSD_LINTFLAGS)
509238106Sdesfi
510238106SdesCONFIG_DATE=`date +%Y%m%d`
511238106SdesAC_SUBST(CONFIG_DATE)
512238106Sdes
513238106Sdes# Checks for libraries.
514238106SdesACX_WITH_SSL
515238106SdesACX_LIB_SSL
516238106SdesAC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
517238106SdesAC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
518238106SdesAC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512])
519238106SdesAC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free], [], [], [
520238106SdesAC_INCLUDES_DEFAULT
521238106Sdes#ifdef HAVE_OPENSSL_ERR_H
522238106Sdes#include <openssl/err.h>
523238106Sdes#endif
524238106Sdes
525238106Sdes#ifdef HAVE_OPENSSL_RAND_H
526238106Sdes#include <openssl/rand.h>
527238106Sdes#endif
528238106Sdes
529238106Sdes#ifdef HAVE_OPENSSL_CONF_H
530238106Sdes#include <openssl/conf.h>
531238106Sdes#endif
532238106Sdes
533238106Sdes#ifdef HAVE_OPENSSL_ENGINE_H
534238106Sdes#include <openssl/engine.h>
535238106Sdes#endif
536238106Sdes#include <openssl/ssl.h>
537238106Sdes#include <openssl/evp.h>
538238106Sdes])
539238106Sdes
540238106SdesAC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
541238106Sdescase "$enable_sha2" in
542238106Sdes	no)
543238106Sdes	;;
544238106Sdes	yes|*)
545238106Sdes	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
546238106Sdes	;;
547238106Sdesesac
548238106Sdes
549238106Sdes# check wether gost also works
550238106SdesAC_DEFUN([AC_CHECK_GOST_WORKS],
551238106Sdes[AC_REQUIRE([AC_PROG_CC])
552238106SdesAC_MSG_CHECKING([if GOST works])
553238106Sdesif test c${cross_compiling} = cno; then
554238106SdesBAKCFLAGS="$CFLAGS"
555238106Sdesif test -n "$ssldir"; then
556238106Sdes	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
557238106Sdesfi
558238106SdesAC_RUN_IFELSE([AC_LANG_SOURCE([[
559238106Sdes#include <string.h>
560238106Sdes#include <openssl/ssl.h>
561238106Sdes#include <openssl/evp.h>
562238106Sdes#include <openssl/engine.h>
563238106Sdes#include <openssl/conf.h>
564238106Sdes/* routine to load gost from ldns */
565238106Sdesint load_gost_id(void)
566238106Sdes{
567238106Sdes	static int gost_id = 0;
568238106Sdes	const EVP_PKEY_ASN1_METHOD* meth;
569238106Sdes	ENGINE* e;
570238106Sdes
571238106Sdes	if(gost_id) return gost_id;
572238106Sdes
573238106Sdes	/* see if configuration loaded gost implementation from other engine*/
574238106Sdes	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
575238106Sdes	if(meth) {
576238106Sdes		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
577238106Sdes		return gost_id;
578238106Sdes	}
579238106Sdes
580238106Sdes	/* see if engine can be loaded already */
581238106Sdes	e = ENGINE_by_id("gost");
582238106Sdes	if(!e) {
583238106Sdes		/* load it ourself, in case statically linked */
584238106Sdes		ENGINE_load_builtin_engines();
585238106Sdes		ENGINE_load_dynamic();
586238106Sdes		e = ENGINE_by_id("gost");
587238106Sdes	}
588238106Sdes	if(!e) {
589238106Sdes		/* no gost engine in openssl */
590238106Sdes		return 0;
591238106Sdes	}
592238106Sdes	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
593238106Sdes		ENGINE_finish(e);
594238106Sdes		ENGINE_free(e);
595238106Sdes		return 0;
596238106Sdes	}
597238106Sdes
598238106Sdes	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
599238106Sdes	if(!meth) {
600238106Sdes		/* algo not found */
601238106Sdes		ENGINE_finish(e);
602238106Sdes		ENGINE_free(e);
603238106Sdes		return 0;
604238106Sdes	}
605238106Sdes	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
606238106Sdes	return gost_id;
607238106Sdes}
608238106Sdesint main(void) { 
609238106Sdes	EVP_MD_CTX* ctx;
610238106Sdes	const EVP_MD* md;
611238106Sdes	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
612238106Sdes	const char* str = "Hello world";
613238106Sdes	const unsigned char check[] = {
614238106Sdes		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
615238106Sdes		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
616238106Sdes		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
617238106Sdes		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
618238106Sdes	};
619238106Sdes	OPENSSL_config(NULL);
620238106Sdes	(void)load_gost_id();
621238106Sdes	md = EVP_get_digestbyname("md_gost94");
622238106Sdes	if(!md) return 1;
623238106Sdes	memset(digest, 0, sizeof(digest));
624238106Sdes	ctx = EVP_MD_CTX_create();
625238106Sdes	if(!ctx) return 2;
626238106Sdes	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
627238106Sdes	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
628238106Sdes	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
629238106Sdes	/* uncomment to see the hash calculated.
630238106Sdes		{int i;
631238106Sdes		for(i=0; i<32; i++)
632238106Sdes			printf(" %2.2x", (int)digest[i]);
633238106Sdes		printf("\n");}
634238106Sdes	*/
635238106Sdes	if(memcmp(digest, check, sizeof(check)) != 0)
636238106Sdes		return 6;
637238106Sdes	return 0;
638238106Sdes}
639238106Sdes]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
640238106SdesCFLAGS="$BAKCFLAGS"
641238106Sdeselse
642238106Sdeseval "ac_cv_c_gost_works=maybe"
643238106Sdesfi
644238106SdesAC_MSG_RESULT($ac_cv_c_gost_works)
645238106Sdes])dnl
646238106Sdes
647238106SdesAC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
648238106Sdesuse_gost="no"
649238106Sdescase "$enable_gost" in
650238106Sdes	no)
651238106Sdes	;;
652238106Sdes	*)
653238106Sdes	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
654238106Sdes        AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
655238106Sdes	AC_CHECK_GOST_WORKS
656238106Sdes	if test $ac_cv_c_gost_works != no; then
657238106Sdes		use_gost="yes"
658238106Sdes		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
659238106Sdes	fi
660238106Sdes	;;
661238106Sdesesac
662238106Sdes
663238106SdesAC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
664238106Sdesuse_ecdsa="no"
665238106Sdescase "$enable_ecdsa" in
666238106Sdes    no)
667238106Sdes      ;;
668238106Sdes    *)
669238106Sdes      AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
670238106Sdes      AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
671238106Sdes      AC_CHECK_DECLS([NID_X9_62_prime256v1, NID_secp384r1], [], [AC_MSG_ERROR([OpenSSL does not support the ECDSA curves: please upgrade or rerun with --disable-ecdsa])], [AC_INCLUDES_DEFAULT
672238106Sdes#include <openssl/evp.h>
673238106Sdes      ])
674238106Sdes      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
675238106Sdes      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
676238106Sdes      if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
677238106Sdes	AC_MSG_RESULT([no])
678238106Sdes	AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
679238106Sdes      else
680238106Sdes	AC_MSG_RESULT([yes])
681238106Sdes      fi
682238106Sdes      # we now know we have ECDSA and the required curves.
683238106Sdes      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
684238106Sdes      use_ecdsa="yes"
685238106Sdes      ;;
686238106Sdesesac
687238106Sdes
688238106Sdes# check for libevent
689238106SdesAC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
690238106Sdes    [use libevent (will check /usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr  or you can specify an explicit path). Slower, but allows use of large outgoing port ranges.]),
691238106Sdes    [ ],[ withval="no" ])
692238106Sdesif test x_$withval = x_yes -o x_$withval != x_no; then
693238106Sdes        AC_MSG_CHECKING(for libevent)
694238106Sdes        if test x_$withval = x_ -o x_$withval = x_yes; then
695238106Sdes            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
696238106Sdes        fi
697238106Sdes        for dir in $withval; do
698238106Sdes            thedir="$dir"
699238106Sdes            if test -f "$dir/include/event.h"; then
700238106Sdes                found_libevent="yes"
701238106Sdes		dnl assume /usr is in default path.
702238106Sdes		if test "$thedir" != "/usr"; then
703238106Sdes                    CPPFLAGS="$CPPFLAGS -I$thedir/include"
704238106Sdes		fi
705238106Sdes                break;
706238106Sdes            fi
707238106Sdes        done
708238106Sdes        if test x_$found_libevent != x_yes; then
709238106Sdes		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
710238106Sdes			# libevent source directory
711238106Sdes            		AC_MSG_RESULT(found in $thedir)
712238106Sdes                	CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
713238106Sdes			BAK_LDFLAGS_SET="1"
714238106Sdes			BAK_LDFLAGS="$LDFLAGS"
715238106Sdes			# remove evdns from linking
716238106Sdes			mkdir build >/dev/null 2>&1
717238106Sdes			mkdir build/libevent >/dev/null 2>&1
718238106Sdes			mkdir build/libevent/.libs >/dev/null 2>&1
719238106Sdes			ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
720238106Sdes			ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
721238106Sdes			ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
722238106Sdes			cp $ev_files_o build/libevent
723238106Sdes			cp $ev_files_lo build/libevent
724238106Sdes			cp $ev_files_libso build/libevent/.libs
725238106Sdes            		LATE_LDFLAGS="build/libevent/*.lo -lm"
726238106Sdes			LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
727238106Sdes		else
728238106Sdes            		AC_MSG_ERROR([Cannot find the libevent library in $withval
729238106SdesYou can restart ./configure --with-libevent=no to use a builtin alternative.
730238106SdesPlease note that this alternative is not as capable as libevent when using
731238106Sdeslarge outgoing port ranges.  ])
732238106Sdes		fi
733238106Sdes        else
734238106Sdes            AC_MSG_RESULT(found in $thedir)
735238106Sdes	    dnl assume /usr is in default path, do not add "".
736238106Sdes	    if test "$thedir" != "/usr" -a "$thedir" != ""; then
737238106Sdes                LDFLAGS="$LDFLAGS -L$thedir/lib"
738238106Sdes		ACX_RUNTIME_PATH_ADD([$thedir/lib])
739238106Sdes	    fi
740238106Sdes        fi
741238106Sdes	# check for library used by libevent after 1.3c
742238106Sdes	AC_SEARCH_LIBS([clock_gettime], [rt])
743238106Sdes
744238106Sdes	# is the event.h header libev or libevent?
745238106Sdes	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
746238106Sdes	AC_CHECK_DECL(EV_VERSION_MAJOR, [
747238106Sdes		AC_SEARCH_LIBS(event_set, [ev])
748238106Sdes	],[
749238106Sdes		AC_SEARCH_LIBS(event_set, [event])
750238106Sdes	],[AC_INCLUDES_DEFAULT
751238106Sdes#include <event.h>
752238106Sdes	])
753238106Sdes	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
754238106Sdes	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
755238106Sdes	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
756238106Sdes	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
757238106Sdes	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
758238106Sdes	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
759238106Sdes	if test -n "$BAK_LDFLAGS_SET"; then
760238106Sdes		LDFLAGS="$BAK_LDFLAGS"
761238106Sdes	fi
762238106Sdeselse
763238106Sdes	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
764238106Sdesfi
765238106Sdes
766238106Sdes# check for libexpat
767238106SdesAC_ARG_WITH(libexpat, AC_HELP_STRING([--with-libexpat=path],
768238106Sdes    [specify explicit path for libexpat.]),
769238106Sdes    [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
770238106SdesAC_MSG_CHECKING(for libexpat)
771238106Sdesfound_libexpat="no"
772238106Sdesfor dir in $withval ; do
773238106Sdes            if test -f "$dir/include/expat.h"; then
774238106Sdes		found_libexpat="yes"
775238106Sdes		dnl assume /usr is in default path.
776238106Sdes		if test "$dir" != "/usr"; then
777238106Sdes                    CPPFLAGS="$CPPFLAGS -I$dir/include"
778238106Sdes		    LDFLAGS="$LDFLAGS -L$dir/lib"
779238106Sdes		fi
780238106Sdes            	AC_MSG_RESULT(found in $dir)
781238106Sdes                break;
782238106Sdes            fi
783238106Sdesdone
784238106Sdesif test x_$found_libexpat != x_yes; then
785238106Sdes	AC_ERROR([Could not find libexpat, expat.h])
786238106Sdesfi
787238106SdesAC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
788238106Sdes
789238106Sdes# set static linking if requested
790238106SdesAC_SUBST(staticexe)
791238106Sdesstaticexe=""
792238106SdesAC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
793238106Sdes	[ enable to compile executables statically against event, ldns libs, for debug purposes ]), 
794238106Sdes	, )
795238106Sdesif test x_$enable_static_exe = x_yes; then
796238106Sdes	staticexe="-static"
797238106Sdes	if test "$on_mingw" = yes; then
798238106Sdes		staticexe="-all-static"
799238106Sdes		# for static crosscompile, include gdi32 and zlib here.
800238106Sdes		if test "`uname`" = "Linux"; then
801238106Sdes			LIBS="$LIBS -lgdi32 -lz"
802238106Sdes		fi
803238106Sdes	fi
804238106Sdesfi
805238106Sdes
806238106Sdes# set lock checking if requested
807238106SdesAC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
808238106Sdes	[ enable to check lock and unlock calls, for debug purposes ]), 
809238106Sdes	, )
810238106Sdesif test x_$enable_lock_checks = x_yes; then
811238106Sdes	AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
812238106Sdes	CHECKLOCK_OBJ="checklocks.lo"
813238106Sdes	AC_SUBST(CHECKLOCK_OBJ)
814238106Sdesfi
815238106Sdes
816238106SdesACX_CHECK_GETADDRINFO_WITH_INCLUDES
817238106Sdesif test "$USE_WINSOCK" = 1; then
818238106Sdes	AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
819238106Sdes	AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
820238106Sdes#include <windows.h>
821238106Sdes	])
822238106Sdes	AC_CHECK_TOOL(WINDRES, windres)
823238106Sdes	LIBS="$LIBS -liphlpapi"
824238106Sdes	WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
825238106Sdes	AC_SUBST(WINAPPS)
826238106Sdes	WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
827238106Sdes	AC_SUBST(WIN_DAEMON_SRC)
828238106Sdes	WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
829238106Sdes	AC_SUBST(WIN_DAEMON_OBJ)
830238106Sdes	WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
831238106Sdes	AC_SUBST(WIN_DAEMON_OBJ_LINK)
832238106Sdes	WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
833238106Sdes	AC_SUBST(WIN_HOST_OBJ_LINK)
834238106Sdes	WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
835238106Sdes	AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
836238106Sdes	WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
837238106Sdes	AC_SUBST(WIN_CONTROL_OBJ_LINK)
838238106Sdes	WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
839238106Sdes	AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
840238106Sdesfi
841238106Sdesif test $ac_cv_func_getaddrinfo = no; then
842238106Sdes	AC_LIBOBJ([fake-rfc2553])
843238106Sdesfi
844238106Sdes# check after getaddrinfo for its libraries
845238106SdesACX_FUNC_IOCTLSOCKET
846238106Sdes
847238106Sdes# see if daemon(3) exists, and if it is deprecated.
848238106SdesAC_CHECK_FUNCS([daemon])
849238106Sdesif test $ac_cv_func_daemon = yes; then
850238106Sdes	ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
851238106Sdes#include <stdlib.h>
852238106Sdes])
853238106Sdesfi
854238106Sdes
855238106SdesAC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
856238106SdesAC_INCLUDES_DEFAULT
857238106Sdes#if HAVE_SYS_PARAM_H
858238106Sdes#include <sys/param.h>
859238106Sdes#endif
860238106Sdes
861238106Sdes#ifdef HAVE_SYS_SOCKET_H
862238106Sdes#include <sys/socket.h>
863238106Sdes#endif
864238106Sdes
865238106Sdes#ifdef HAVE_SYS_UIO_H
866238106Sdes#include <sys/uio.h>
867238106Sdes#endif
868238106Sdes
869238106Sdes#ifdef HAVE_NETINET_IN_H
870238106Sdes#include <netinet/in.h>
871238106Sdes#endif
872238106Sdes
873238106Sdes#ifdef HAVE_ARPA_INET_H
874238106Sdes#include <arpa/inet.h>
875238106Sdes#endif
876238106Sdes
877238106Sdes#ifdef HAVE_WINSOCK2_H
878238106Sdes#include <winsock2.h>
879238106Sdes#endif
880238106Sdes
881238106Sdes#ifdef HAVE_WS2TCPIP_H
882238106Sdes#include <ws2tcpip.h>
883238106Sdes#endif
884238106Sdes])
885238106SdesAC_SEARCH_LIBS([setusercontext], [util])
886238106SdesAC_CHECK_FUNCS([tzset sigprocmask fcntl getpwnam getrlimit setrlimit setsid sbrk chroot kill sleep usleep random srandom recvmsg sendmsg writev socketpair glob initgroups strftime localtime_r setusercontext _beginthreadex])
887238106SdesAC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
888238106SdesAC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
889238106Sdes
890238106Sdes# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
891238106Sdesif echo $build_os | grep darwin8 > /dev/null; then
892238106Sdes	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
893238106Sdesfi
894238106SdesAC_REPLACE_FUNCS(inet_aton)
895238106SdesAC_REPLACE_FUNCS(inet_pton)
896238106SdesAC_REPLACE_FUNCS(inet_ntop)
897238106SdesAC_REPLACE_FUNCS(snprintf)
898238106SdesAC_REPLACE_FUNCS(strlcpy)
899238106SdesAC_REPLACE_FUNCS(memmove)
900238106SdesAC_REPLACE_FUNCS(gmtime_r)
901238106SdesLIBOBJ_WITHOUT_CTIME="$LIBOBJS"
902238106SdesAC_SUBST(LIBOBJ_WITHOUT_CTIME)
903238106SdesAC_REPLACE_FUNCS(ctime_r)
904238106Sdes
905238106SdesAC_ARG_ENABLE(allsymbols, AC_HELP_STRING([--enable-allsymbols], [export all symbols from libunbound and link binaries to it, smaller install size but libunbound export table is polluted by internal symbols]))
906238106Sdescase "$enable_allsymbols" in
907238106Sdes	yes)
908238106Sdes	COMMON_OBJ_ALL_SYMBOLS=""
909238106Sdes	UBSYMS=""
910238106Sdes	EXTRALINK="-L. -L.libs -lunbound"
911238106Sdes	AC_DEFINE(EXPORT_ALL_SYMBOLS, 1, [Define this if you enabled-allsymbols from libunbound to link binaries to it for smaller install size, but the libunbound export table is polluted by internal symbols])
912238106Sdes	;;
913238106Sdes	no|*)
914238106Sdes	COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
915238106Sdes	UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
916238106Sdes	EXTRALINK=""
917238106Sdes	;;
918238106Sdesesac
919238106SdesAC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
920238106SdesAC_SUBST(EXTRALINK)
921238106SdesAC_SUBST(UBSYMS)
922238106Sdesif test x_$enable_lock_checks = x_yes; then
923238106Sdes	UBSYMS="-export-symbols clubsyms.def"
924238106Sdes	cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
925238106Sdes	echo lock_protect >> clubsyms.def
926238106Sdes	echo lock_unprotect >> clubsyms.def
927238106Sdes	echo lock_get_mem >> clubsyms.def
928238106Sdes	echo checklock_start >> clubsyms.def
929238106Sdes	echo checklock_stop >> clubsyms.def
930238106Sdes	echo checklock_lock >> clubsyms.def
931238106Sdes	echo checklock_unlock >> clubsyms.def
932238106Sdes	echo checklock_init >> clubsyms.def
933238106Sdes	echo checklock_thrcreate >> clubsyms.def
934238106Sdes	echo checklock_thrjoin >> clubsyms.def
935238106Sdesfi
936238106Sdes
937238106SdesAC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
938238106Sdes# on openBSD, the implicit rule make $< work.
939238106Sdes# on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
940238106Sdes# gmake works.
941238106Sdescat >conftest.make <<EOF
942238106Sdesall:	conftest.lo
943238106Sdes
944238106Sdesconftest.lo foo.lo bla.lo:
945238106Sdes	if test -f "\$<"; then touch \$@; fi
946238106Sdes
947238106Sdes.SUFFIXES: .lo
948238106Sdes.c.lo:
949238106Sdes	if test -f "\$<"; then touch \$@; fi
950238106Sdes
951238106Sdesconftest.lo:        conftest.dir/conftest.c
952238106SdesEOF
953238106Sdesmkdir conftest.dir
954238106Sdestouch conftest.dir/conftest.c
955238106Sdesrm -f conftest.lo conftest.c
956238106Sdes${MAKE:-make} -f conftest.make >/dev/null
957238106Sdesrm -f conftest.make conftest.c conftest.dir/conftest.c
958238106Sdesrm -rf conftest.dir
959238106Sdesif test ! -f conftest.lo; then
960238106Sdes	AC_MSG_RESULT(no)
961238106Sdes	SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
962238106Sdes	SOURCEFILE='`cat .source`'
963238106Sdeselse
964238106Sdes	AC_MSG_RESULT(yes)
965238106Sdes	SOURCEDETERMINE=':'
966238106Sdes	SOURCEFILE='$<'
967238106Sdesfi
968238106Sdesrm -f conftest.lo
969238106SdesAC_SUBST(SOURCEDETERMINE)
970238106SdesAC_SUBST(SOURCEFILE)
971238106Sdes
972238106Sdes# check this after all other compilation checks, since the linking of the lib
973238106Sdes# may break checks after this.
974238106SdesAC_ARG_WITH(ldns, AC_HELP_STRING([--with-ldns=PATH], 
975238106Sdes	[specify prefix of path of ldns library to use]), 
976238106Sdes	[
977238106Sdes	if test "$withval" != "yes"; then
978238106Sdes		if test "$withval" != "/usr" -a "$withval" != ""; then
979238106Sdes			CPPFLAGS="-I$withval/include $CPPFLAGS"
980238106Sdes			LDFLAGS="-L$withval/lib $LDFLAGS"
981238106Sdes			ACX_RUNTIME_PATH_ADD([$withval/lib])
982238106Sdes		fi
983238106Sdes		ldnsdir="$withval"
984238106Sdes		AC_SUBST(ldnsdir)
985238106Sdes	fi
986238106Sdes])
987238106Sdes
988238106Sdes# check if ldns is good enough
989238106SdesAC_CHECK_LIB(ldns, ldns_rr_new,,[
990238106Sdes	AC_MSG_ERROR([No ldns library found, install the ldns library into system lib dir or use --with-ldns=path to other location.  The --with-ldns can point to the make-dir of ldns.  Install the package ldns or download source http://www.nlnetlabs.nl/projects/ldns])
991238106Sdes])
992238106SdesAC_CHECK_FUNC(ldns_buffer_copy)
993238106SdesAC_CHECK_FUNC(ldns_key_buf2rsa_raw)
994238106SdesAC_CHECK_FUNC(ldns_get_random)
995238106SdesAC_CHECK_FUNC(ldns_b32_ntop_extended_hex)
996238106Sdesif test x$use_gost = xyes; then
997238106Sdes    AC_CHECK_FUNC(ldns_key_EVP_load_gost_id)
998238106Sdes    AC_CHECK_FUNCS([ldns_key_EVP_unload_gost])
999238106Sdeselse
1000238106Sdes    ac_cv_func_ldns_key_EVP_load_gost_id="yes"
1001238106Sdesfi
1002238106Sdesif test x$use_ecdsa = xyes; then
1003238106Sdes    AC_CHECK_DECL([LDNS_ECDSAP384SHA384], [], [], [
1004238106SdesAC_INCLUDES_DEFAULT
1005238106Sdes#ifdef HAVE_SYS_SOCKET_H
1006238106Sdes#  include <sys/socket.h>
1007238106Sdes#endif
1008238106Sdes#ifdef HAVE_WS2TCPIP_H
1009238106Sdes#  include <ws2tcpip.h>
1010238106Sdes#endif
1011238106Sdes#include <ldns/ldns.h>
1012238106Sdes    ])
1013238106Sdeselse
1014238106Sdes    ac_cv_have_decl_LDNS_ECDSAP384SHA384="yes"
1015238106Sdesfi
1016238106SdesAC_CHECK_HEADERS([ldns/ldns.h],,[
1017238106Sdes	AC_MSG_ERROR([No ldns include file found, install the ldns library development files.  Install package ldns-dev or ldns-devel or download source http://www.nlnetlabs.nl/projects/ldns])
1018238106Sdes	], [AC_INCLUDES_DEFAULT
1019238106Sdes#ifdef HAVE_SYS_SOCKET_H
1020238106Sdes#include <sys/socket.h>
1021238106Sdes#endif
1022238106Sdes
1023238106Sdes#ifdef HAVE_NETINET_IN_H
1024238106Sdes#include <netinet/in.h>
1025238106Sdes#endif
1026238106Sdes
1027238106Sdes#ifdef HAVE_ARPA_INET_H
1028238106Sdes#include <arpa/inet.h>
1029238106Sdes#endif
1030238106Sdes
1031238106Sdes#ifdef HAVE_WINSOCK2_H
1032238106Sdes#include <winsock2.h>
1033238106Sdes#endif
1034238106Sdes
1035238106Sdes#ifdef HAVE_WS2TCPIP_H
1036238106Sdes#include <ws2tcpip.h>
1037238106Sdes#endif
1038238106Sdes])
1039238106Sdesif test $ac_cv_func_ldns_buffer_copy = yes \
1040238106Sdes    -a $ac_cv_func_ldns_key_buf2rsa_raw = yes \
1041238106Sdes    -a $ac_cv_func_ldns_get_random = yes \
1042238106Sdes    -a $ac_cv_header_ldns_ldns_h = yes \
1043238106Sdes    -a $ac_cv_func_ldns_b32_ntop_extended_hex = yes \
1044238106Sdes    -a $ac_cv_func_ldns_key_EVP_load_gost_id = yes \
1045238106Sdes    -a $ac_cv_have_decl_LDNS_ECDSAP384SHA384 = yes; then
1046238106Sdes    dnl ldns was found
1047238106Sdes    :
1048238106Sdeselse
1049238106Sdes    AC_MSG_ERROR([ldns library is not recent, update the ldns library, install it into system lib dir or use --with-ldns=path to other location.  The --with-ldns can point to the make-dir of ldns.  Package libldns or download source http://www.nlnetlabs.nl/projects/ldns])
1050238106Sdesfi
1051238106Sdes
1052238106SdesACX_STRIP_EXT_FLAGS
1053238106SdesLDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1054238106Sdes
1055238106SdesAC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1056238106Sdes
1057238106SdesAH_BOTTOM(
1058238106Sdesdnl this must be first AH_CONFIG, to define the flags before any includes.
1059238106SdesAHX_CONFIG_EXT_FLAGS
1060238106Sdes
1061238106Sdesdnl includes
1062238106Sdes[
1063238106Sdes#ifndef UNBOUND_DEBUG
1064238106Sdes#  define NDEBUG
1065238106Sdes#endif
1066238106Sdes
1067238106Sdes#include <stdio.h>
1068238106Sdes#include <string.h>
1069238106Sdes#include <unistd.h>
1070238106Sdes#include <assert.h>
1071238106Sdes
1072238106Sdes#if STDC_HEADERS
1073238106Sdes#include <stdlib.h>
1074238106Sdes#include <stddef.h>
1075238106Sdes#endif
1076238106Sdes
1077238106Sdes#ifdef HAVE_STDINT_H
1078238106Sdes#include <stdint.h>
1079238106Sdes#endif
1080238106Sdes
1081238106Sdes#include <errno.h>
1082238106Sdes
1083238106Sdes#if HAVE_SYS_PARAM_H
1084238106Sdes#include <sys/param.h>
1085238106Sdes#endif
1086238106Sdes
1087238106Sdes#ifdef HAVE_SYS_SOCKET_H
1088238106Sdes#include <sys/socket.h>
1089238106Sdes#endif
1090238106Sdes
1091238106Sdes#ifdef HAVE_SYS_UIO_H
1092238106Sdes#include <sys/uio.h>
1093238106Sdes#endif
1094238106Sdes
1095238106Sdes#ifdef HAVE_NETINET_IN_H
1096238106Sdes#include <netinet/in.h>
1097238106Sdes#endif
1098238106Sdes
1099238106Sdes#ifdef HAVE_ARPA_INET_H
1100238106Sdes#include <arpa/inet.h>
1101238106Sdes#endif
1102238106Sdes
1103238106Sdes#ifdef HAVE_WINSOCK2_H
1104238106Sdes#include <winsock2.h>
1105238106Sdes#endif
1106238106Sdes
1107238106Sdes#ifdef HAVE_WS2TCPIP_H
1108238106Sdes#include <ws2tcpip.h>
1109238106Sdes#endif
1110238106Sdes]
1111238106Sdes
1112238106SdesAHX_CONFIG_FORMAT_ATTRIBUTE
1113238106SdesAHX_CONFIG_UNUSED_ATTRIBUTE
1114238106SdesAHX_CONFIG_FSEEKO
1115238106SdesAHX_CONFIG_MAXHOSTNAMELEN
1116238106SdesAHX_CONFIG_SNPRINTF(unbound)
1117238106SdesAHX_CONFIG_INET_PTON(unbound)
1118238106SdesAHX_CONFIG_INET_NTOP(unbound)
1119238106SdesAHX_CONFIG_INET_ATON(unbound)
1120238106SdesAHX_CONFIG_MEMMOVE(unbound)
1121238106SdesAHX_CONFIG_STRLCPY(unbound)
1122238106SdesAHX_CONFIG_GMTIME_R(unbound)
1123238106SdesAHX_CONFIG_W32_SLEEP
1124238106SdesAHX_CONFIG_W32_USLEEP
1125238106SdesAHX_CONFIG_W32_RANDOM
1126238106SdesAHX_CONFIG_W32_SRANDOM
1127238106SdesAHX_CONFIG_W32_FD_SET_T
1128238106SdesAHX_CONFIG_IPV6_MIN_MTU
1129238106SdesAHX_MEMCMP_BROKEN(unbound)
1130238106Sdes
1131238106Sdes[
1132238106Sdes#ifndef HAVE_CTIME_R
1133238106Sdes#define ctime_r unbound_ctime_r
1134238106Sdeschar *ctime_r(const time_t *timep, char *buf);
1135238106Sdes#endif
1136238106Sdes
1137238106Sdes#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1138238106Sdes#define strptime unbound_strptime
1139238106Sdesstruct tm;
1140238106Sdeschar *strptime(const char *s, const char *format, struct tm *tm);
1141238106Sdes#endif
1142238106Sdes
1143238106Sdes#if defined(HAVE_EVENT_H) && !defined(HAVE_EVENT_BASE_ONCE) && !(defined(HAVE_EV_LOOP) || defined(HAVE_EV_DEFAULT_LOOP)) && (defined(HAVE_PTHREAD) || defined(HAVE_SOLARIS_THREADS))
1144238106Sdes   /* using version of libevent that is not threadsafe. */
1145238106Sdes#  define LIBEVENT_SIGNAL_PROBLEM 1
1146238106Sdes#endif
1147238106Sdes
1148238106Sdes#ifndef CHECKED_INET6
1149238106Sdes#  define CHECKED_INET6
1150238106Sdes#  ifdef AF_INET6
1151238106Sdes#    define INET6
1152238106Sdes#  else
1153238106Sdes#    define AF_INET6        28
1154238106Sdes#  endif
1155238106Sdes#endif /* CHECKED_INET6 */
1156238106Sdes
1157238106Sdes/* maximum nesting of included files */
1158238106Sdes#define MAXINCLUDES 10
1159238106Sdes#ifndef HAVE_GETADDRINFO
1160238106Sdesstruct sockaddr_storage;
1161238106Sdes#include "compat/fake-rfc2553.h"
1162238106Sdes#endif
1163238106Sdes
1164238106Sdes#ifdef UNBOUND_ALLOC_STATS
1165238106Sdes#  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
1166238106Sdes#  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
1167238106Sdes#  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
1168238106Sdes#  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
1169238106Sdesvoid *unbound_stat_malloc(size_t size);
1170238106Sdesvoid *unbound_stat_calloc(size_t nmemb, size_t size);
1171238106Sdesvoid unbound_stat_free(void *ptr);
1172238106Sdesvoid *unbound_stat_realloc(void *ptr, size_t size);
1173238106Sdesvoid *unbound_stat_malloc_log(size_t size, const char* file, int line,
1174238106Sdes	const char* func);
1175238106Sdesvoid *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1176238106Sdes	int line, const char* func);
1177238106Sdesvoid unbound_stat_free_log(void *ptr, const char* file, int line,
1178238106Sdes	const char* func);
1179238106Sdesvoid *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
1180238106Sdes	int line, const char* func);
1181238106Sdes#elif defined(UNBOUND_ALLOC_LITE)
1182238106Sdes#  include "util/alloc.h"
1183238106Sdes#endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
1184238106Sdes
1185238106Sdes/** default port for DNS traffic. */
1186238106Sdes#define UNBOUND_DNS_PORT 53
1187238106Sdes/** default port for unbound control traffic, registered port with IANA,
1188238106Sdes    ub-dns-control  8953/tcp    unbound dns nameserver control */
1189238106Sdes#define UNBOUND_CONTROL_PORT 8953
1190238106Sdes/** the version of unbound-control that this software implements */
1191238106Sdes#define UNBOUND_CONTROL_VERSION 1
1192238106Sdes
1193238106Sdes])
1194238106Sdes
1195238106SdesAC_CONFIG_FILES([Makefile doc/example.conf doc/libunbound.3 doc/unbound.8 doc/unbound-anchor.8 doc/unbound-checkconf.8 doc/unbound.conf.5 doc/unbound-control.8])
1196238106SdesAC_CONFIG_HEADER([config.h])
1197238106SdesAC_OUTPUT
1198