configure.ac revision 255838
1122394Sharti#                                               -*- Autoconf -*-
2150920Sharti# Process this file with autoconf to produce a configure script.
3150920ShartiAC_PREREQ(2.56)
4150920Shartisinclude(acx_nlnetlabs.m4)
5122394Shartisinclude(acx_pthread.m4)
6122394Shartisinclude(acx_python.m4)
7122394Shartisinclude(ac_pkg_swig.m4)
8122394Sharti
9208483SuqsAC_INIT(unbound, 1.4.20, unbound-bugs@nlnetlabs.nl, unbound)
10133211Sharti
11133211ShartiLIBUNBOUND_CURRENT=3
12133211ShartiLIBUNBOUND_REVISION=5
13133211ShartiLIBUNBOUND_AGE=1
14133211Sharti# 1.0.0 had 0:12:0
15133211Sharti# 1.0.1 had 0:13:0
16122394Sharti# 1.0.2 had 0:14:0
17122394Sharti# 1.1.0 had 0:15:0
18122394Sharti# 1.1.1 had 0:16:0
19133211Sharti# 1.2.0 had 0:17:0
20133211Sharti# 1.2.1 had 0:18:0
21133211Sharti# 1.3.0 had 1:0:0   # ub_cancel and -export-symbols.
22133211Sharti# 1.3.1 had 1:1:0
23133211Sharti# 1.3.2 had 1:2:0
24133211Sharti# 1.3.3 had 1:3:0
25133211Sharti# 1.3.4 had 1:4:0
26133211Sharti# 1.4.0-snapshots had 1:5:0
27133211Sharti# 1.4.0 had 1:5:0 (not 2:0:0)   # ub_result.why_bogus
28133211Sharti# 1.4.1 had 2:1:0
29133211Sharti# 1.4.2 had 2:2:0
30133211Sharti# 1.4.3 had 2:3:0
31122394Sharti# 1.4.4 had 2:4:0
32156066Sharti# 1.4.5 had 2:5:0
33122394Sharti# 1.4.6 had 2:6:0
34216294Ssyrinx# 1.4.7 had 2:7:0
35156066Sharti# 1.4.8 had 2:8:0
36122394Sharti# 1.4.9 had 2:9:0
37122394Sharti# 1.4.10 had 2:10:0
38150920Sharti# 1.4.11 had 2:11:0
39150920Sharti# 1.4.12 had 2:12:0
40122394Sharti# 1.4.13 had 2:13:0
41122394Sharti# and 1.4.13p1 and 1.4.13.p2
42122394Sharti# 1.4.14 had 2:14:0
43122394Sharti# 1.4.15 had 3:0:1 # adds ub_version()
44122394Sharti# 1.4.16 had 3:1:1
45216294Ssyrinx# 1.4.17 had 3:2:1
46122394Sharti# 1.4.18 had 3:3:1
47122394Sharti# 1.4.19 had 3:4:1
48122394Sharti# 1.4.20 had 4:0:2 # adds libunbound.ttl
49122394Sharti
50122394Sharti#   Current  -- the number of the binary API that we're implementing
51122394Sharti#   Revision -- which iteration of the implementation of the binary
52122394Sharti#               API are we supplying?
53211401Suqs#   Age      -- How many previous binary API versions do we also
54142810Sharti#               support?
55150920Sharti#
56150920Sharti# If we release a new version that does not change the binary API,
57122394Sharti# increment Revision.
58122394Sharti#
59122394Sharti# If we release a new version that changes the binary API, but does
60122394Sharti# not break programs compiled against the old binary API, increment
61122394Sharti# Current and Age.  Set Revision to 0, since this is the first
62122394Sharti# implementation of the new API.
63211401Suqs#
64211401Suqs# Otherwise, we're changing the binary API and breaking bakward
65122394Sharti# compatibility with old binaries.  Increment Current.  Set Age to 0,
66211401Suqs# since we're backward compatible with no previous APIs.  Set Revision
67122394Sharti# to 0 too.
68122394ShartiAC_SUBST(LIBUNBOUND_CURRENT)
69122394ShartiAC_SUBST(LIBUNBOUND_REVISION)
70122394ShartiAC_SUBST(LIBUNBOUND_AGE)
71122394Sharti
72216294SsyrinxCFLAGS="$CFLAGS"
73216294SsyrinxAC_AIX
74216294Ssyrinx
75122394Shartidnl
76216294Ssyrinxdnl By default set prefix to /usr/local
77122394Shartidnl
78211401Suqscase "$prefix" in
79122394Sharti        NONE)
80211401Suqs		prefix="/usr/local"
81122394Sharti        ;;
82211401Suqsesac
83122394Sharti
84211401Suqs# are we on MinGW?
85150920Shartiif uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
86216294Ssyrinxelse 
87150920Sharti	if echo $target | grep mingw32 >/dev/null; then on_mingw="yes"
88216294Ssyrinx	else on_mingw="no"; fi
89216294Ssyrinxfi
90216294Ssyrinx
91122394Sharti#
92211401Suqs# Determine configuration file
93211401Suqs# the eval is to evaluate shell expansion twice
94150920Shartiif test $on_mingw = "no"; then
95122394Sharti  ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
96142810Shartielse
97122394Sharti  ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
98211401Suqsfi
99122394ShartiAC_ARG_WITH([conf_file],
100211401Suqs        AC_HELP_STRING([--with-conf-file=path], 
101122394Sharti	[Pathname to the Unbound configuration file]),
102122394Sharti	[ub_conf_file="$withval"])
103122394ShartiAC_SUBST(ub_conf_file)
104122394ShartiACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
105122394ShartiAC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
106122394Sharti
107122394Sharti# Determine run, chroot directory and pidfile locations
108122394ShartiAC_ARG_WITH(run-dir, 
109150920Sharti    AC_HELP_STRING([--with-run-dir=path], 
110150920Sharti    [set default directory to chdir to (by default dir part of cfg file)]), 
111122394Sharti    UNBOUND_RUN_DIR="$withval", 
112122394Shartiif test $on_mingw = no; then
113122394Sharti    UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
114122394Shartielse
115122394Sharti    UNBOUND_RUN_DIR=""
116122394Shartifi
117122394Sharti)
118122394ShartiAC_SUBST(UNBOUND_RUN_DIR)
119122394ShartiACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
120122394ShartiAC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
121122394Sharti
122122394ShartiAC_ARG_WITH(chroot-dir, 
123150920Sharti    AC_HELP_STRING([--with-chroot-dir=path], 
124150920Sharti    [set default directory to chroot to (by default same as run-dir)]), 
125122394Sharti    UNBOUND_CHROOT_DIR="$withval", 
126122394Shartiif test $on_mingw = no; then
127122394Sharti    UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
128122394Shartielse
129150920Sharti    UNBOUND_CHROOT_DIR=""
130150920Shartifi
131150920Sharti)
132122394ShartiAC_SUBST(UNBOUND_CHROOT_DIR)
133150920ShartiACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
134150920ShartiAC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
135122394Sharti
136122394ShartiAC_ARG_WITH(share-dir,
137150920Sharti    AC_HELP_STRING([--with-share-dir=path],
138122394Sharti    [set default directory with shared data (by default same as share/unbound)]),
139122394Sharti    UNBOUND_SHARE_DIR="$withval",
140122394Sharti    UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
141122394ShartiAC_SUBST(UNBOUND_SHARE_DIR)
142122394ShartiAC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
143122394Sharti
144122394ShartiAC_ARG_WITH(pidfile, 
145122394Sharti    AC_HELP_STRING([--with-pidfile=filename], 
146122394Sharti    [set default pathname to unbound pidfile (default run-dir/unbound.pid)]), 
147122394Sharti    UNBOUND_PIDFILE="$withval", 
148122394Shartiif test $on_mingw = no; then
149122394Sharti    UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
150122394Shartielse
151122394Sharti    UNBOUND_PIDFILE=""
152150920Shartifi
153150920Sharti)
154122394ShartiAC_SUBST(UNBOUND_PIDFILE)
155122394ShartiACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
156122394ShartiAC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
157122394Sharti
158122394ShartiAC_ARG_WITH(rootkey-file, 
159122394Sharti    AC_HELP_STRING([--with-rootkey-file=filename], 
160150920Sharti    [set default pathname to root key file (default run-dir/root.key). This file is read and written.]), 
161150920Sharti    UNBOUND_ROOTKEY_FILE="$withval", 
162122394Shartiif test $on_mingw = no; then
163122394Sharti    UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
164122394Shartielse
165150920Sharti    UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
166150920Shartifi
167122394Sharti)
168122394ShartiAC_SUBST(UNBOUND_ROOTKEY_FILE)
169150920ShartiACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
170150920ShartiAC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
171122394Sharti
172122394ShartiAC_ARG_WITH(rootcert-file, 
173122394Sharti    AC_HELP_STRING([--with-rootcert-file=filename], 
174122394Sharti    [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.]), 
175122394Sharti    UNBOUND_ROOTCERT_FILE="$withval", 
176122394Shartiif test $on_mingw = no; then
177122394Sharti    UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
178122394Shartielse
179150920Sharti    UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
180150920Shartifi
181122394Sharti)
182150920ShartiAC_SUBST(UNBOUND_ROOTCERT_FILE)
183150920ShartiACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
184122394ShartiAC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
185122394Sharti
186122394ShartiAC_ARG_WITH(username, 
187122394Sharti    AC_HELP_STRING([--with-username=user], 
188122394Sharti    [set default user that unbound changes to (default user is unbound)]), 
189122394Sharti    UNBOUND_USERNAME="$withval", 
190122394Sharti    UNBOUND_USERNAME="unbound")
191122394ShartiAC_SUBST(UNBOUND_USERNAME)
192122394ShartiAC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
193122394Sharti
194150920ShartiAC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
195150920ShartiACX_RSRC_VERSION(wnvs)
196122394ShartiAC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
197122394Sharti
198122394Sharti# Checks for typedefs, structures, and compiler characteristics.
199122394ShartiAC_C_CONST
200122394ShartiAC_LANG_C
201122394Sharti# allow user to override the -g -O2 flags.
202122394Shartiif test "x$CFLAGS" = "x" ; then
203150920ShartiACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
204150920ShartiACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
205150920Shartifi
206150920ShartiAC_PROG_CC
207150920ShartiACX_DEPFLAG
208142810ShartiACX_DETERMINE_EXT_FLAGS_UNBOUND
209150920Sharti
210150920Sharti# debug mode flags warnings
211150920ShartiAC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
212150920ShartiAC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
213150920Shartiif test "$enable_debug" = "yes"; then debug_enabled="$enable_debug"; 
214150920Shartielse debug_enabled="$enable_checking"; fi
215150920ShartiAC_SUBST(debug_enabled)
216150920Sharticase "$debug_enabled" in
217122394Sharti        yes)
218150920Sharti		ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
219150920Sharti		ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
220122394Sharti		ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
221122394Sharti		ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
222122394Sharti		AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
223211401Suqs		;;
224122394Sharti	no|*)
225122394Sharti		# nothing to do.
226122394Sharti		;;
227122394Shartiesac
228122394ShartiACX_CHECK_FLTO
229122394Sharti
230122394ShartiAC_C_INLINE
231122394ShartiACX_CHECK_FORMAT_ATTRIBUTE
232122394ShartiACX_CHECK_UNUSED_ATTRIBUTE
233122394Sharti
234122394Shartiif test "$srcdir" != "."; then
235122394Sharti	CPPFLAGS="$CPPFLAGS -I$srcdir"
236150920Shartifi
237150920Sharti
238122394ShartiAC_DEFUN([ACX_YYLEX_DESTROY], [
239122394Sharti	AC_MSG_CHECKING([for yylex_destroy])
240122394Sharti	if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
241122394Sharti		AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
242122394Sharti		AC_MSG_RESULT(yes)
243122394Sharti	else AC_MSG_RESULT(no); fi
244122394Sharti])
245122394Sharti
246150920ShartiAC_PROG_LEX
247150920ShartiACX_YYLEX_DESTROY
248122394ShartiAC_PROG_YACC
249122394ShartiAC_CHECK_PROG(doxygen, doxygen, doxygen)
250122394ShartiAC_CHECK_TOOL(STRIP, strip)
251122394ShartiACX_LIBTOOL_C_ONLY
252122394Sharti
253122394Sharti# Checks for header files.
254122394ShartiAC_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])
255216294Ssyrinx
256216294Ssyrinx# check for types.  
257122394Sharti# Using own tests for int64* because autoconf builtin only give 32bit.
258122394ShartiAC_CHECK_TYPE(int8_t, signed char)
259122394ShartiAC_CHECK_TYPE(int16_t, short)
260211401SuqsAC_CHECK_TYPE(int32_t, int)
261128237ShartiAC_CHECK_TYPE(int64_t, long long)
262128237ShartiAC_CHECK_TYPE(uint8_t, unsigned char)
263128237ShartiAC_CHECK_TYPE(uint16_t, unsigned short)
264211401SuqsAC_CHECK_TYPE(uint32_t, unsigned int)
265156066ShartiAC_CHECK_TYPE(uint64_t, unsigned long long)
266211401SuqsAC_TYPE_SIZE_T
267156066ShartiAC_CHECK_TYPE(ssize_t, int)
268156066ShartiAC_TYPE_UID_T
269122394ShartiAC_TYPE_PID_T
270122394ShartiAC_TYPE_OFF_T
271156066ShartiACX_TYPE_U_CHAR
272156066ShartiACX_TYPE_RLIM_T
273122394ShartiACX_TYPE_SOCKLEN_T
274122394ShartiACX_TYPE_IN_ADDR_T
275122394ShartiACX_TYPE_IN_PORT_T
276122394ShartiACX_CHECK_MEMCMP_SIGNED
277122394Sharti
278208483Suqs# add option to disable the evil rpath
279122394ShartiACX_ARG_RPATH
280122394ShartiAC_SUBST(RUNTIME_PATH)
281
282# check to see if libraries are needed for these functions.
283AC_SEARCH_LIBS([inet_pton], [nsl])
284AC_SEARCH_LIBS([socket], [socket])
285
286# check wether strptime also works
287AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
288[AC_REQUIRE([AC_PROG_CC])
289AC_MSG_CHECKING(whether strptime works)
290if test c${cross_compiling} = cno; then
291AC_RUN_IFELSE([AC_LANG_SOURCE([[
292#define _XOPEN_SOURCE
293#include <time.h>
294int main(void) { struct tm tm; char *res;
295res = 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);
296if (!res) return 2;
297res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
298if (!res) return 1; return 0; }
299]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
300else
301eval "ac_cv_c_strptime_works=maybe"
302fi
303AC_MSG_RESULT($ac_cv_c_strptime_works)
304if test $ac_cv_c_strptime_works = no; then
305AC_LIBOBJ(strptime)
306else
307AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
308fi
309])dnl
310
311# check some functions of the OS before linking libs (while still runnable).
312AC_FUNC_CHOWN
313AC_FUNC_FORK
314AC_TYPE_SIGNAL
315AC_FUNC_FSEEKO
316ACX_SYS_LARGEFILE
317ACX_CHECK_NONBLOCKING_BROKEN
318ACX_MKDIR_ONE_ARG
319AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
320
321# set memory allocation checking if requested
322AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
323	[ enable to memory allocation statistics, for debug purposes ]), 
324	, )
325AC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
326	[ enable for lightweight alloc assertions, for debug purposes ]), 
327	, )
328AC_ARG_ENABLE(alloc-nonregional, AC_HELP_STRING([--enable-alloc-nonregional],
329	[ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]), 
330	, )
331if test x_$enable_alloc_nonregional = x_yes; then
332	AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
333fi
334if test x_$enable_alloc_checks = x_yes; then
335	AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
336else
337	if test x_$enable_alloc_lite = x_yes; then
338		AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
339	else
340		ACX_FUNC_MALLOC([unbound])
341	fi
342fi
343
344# check windows threads (we use them, not pthreads, on windows).
345if test "$on_mingw" = "yes"; then
346# check windows threads
347	AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
348	AC_MSG_CHECKING([for CreateThread])
349	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
350#ifdef HAVE_WINDOWS_H
351#include <windows.h>
352#endif
353], [
354	HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
355])],
356	AC_MSG_RESULT(yes)
357	AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
358,	
359	AC_MSG_RESULT(no)
360)
361
362else
363# not on mingw, check thread libraries.
364
365# check for thread library.
366# check this first, so that the pthread lib does not get linked in via
367# libssl or libpython, and thus distorts the tests, and we end up using
368# the non-threadsafe C libraries.
369AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], 
370 [use pthreads library, or --without-pthreads to disable threading support.]), 
371 [ ],[ withval="yes" ])
372ub_have_pthreads=no
373if test x_$withval != x_no; then
374	ACX_PTHREAD([
375		AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
376		LIBS="$PTHREAD_LIBS $LIBS"
377		CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
378		CC="$PTHREAD_CC"
379		ub_have_pthreads=yes
380		AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
381		])
382fi
383
384# check solaris thread library 
385AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], 
386	[use solaris native thread library.]), [ ],[ withval="no" ])
387ub_have_sol_threads=no
388if test x_$withval != x_no; then
389	if test x_$ub_have_pthreads != x_no; then
390	    AC_WARN([Have pthreads already, ignoring --with-solaris-threads])
391	else
392	AC_SEARCH_LIBS(thr_create, [thread],
393	[
394    		AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
395
396		ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
397			[CFLAGS="$CFLAGS -D_REENTRANT"])
398		ub_have_sol_threads=yes
399	] , [ 
400		AC_ERROR([no solaris threads found.]) 
401	])
402	fi
403fi
404
405fi # end of non-mingw check of thread libraries
406
407# Check for PyUnbound
408AC_ARG_WITH(pyunbound,
409   AC_HELP_STRING([--with-pyunbound],
410   [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
411   [], [ withval="no" ])
412
413ub_test_python=no
414ub_with_pyunbound=no
415if test x_$withval != x_no; then
416   ub_with_pyunbound=yes
417   ub_test_python=yes
418fi
419
420# Check for Python module
421AC_ARG_WITH(pythonmodule,
422   AC_HELP_STRING([--with-pythonmodule],
423   [build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
424   [], [ withval="no" ])
425
426ub_with_pythonmod=no
427if test x_$withval != x_no; then
428   ub_with_pythonmod=yes
429   ub_test_python=yes
430fi
431
432# Check for Python & SWIG only on PyUnbound or PyModule
433if test x_$ub_test_python != x_no; then
434
435   # Check for Python
436   ub_have_python=no
437   ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
438   AC_PYTHON_DEVEL
439   if test ! -z "$PYTHON_VERSION"; then
440	if test `$PYTHON -c "print '$PYTHON_VERSION' >= '2.4.0'"` = "False"; then
441		AC_ERROR([Python version >= 2.4.0 is required])
442	fi
443
444      # Have Python
445      AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
446      LIBS="$PYTHON_LDFLAGS $LIBS"
447      CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
448      ub_have_python=yes
449
450      # Check for SWIG
451      ub_have_swig=no
452      AC_PROG_SWIG
453      AC_MSG_CHECKING(SWIG)
454      if test ! -x "$SWIG"; then
455         AC_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
456      else
457         AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
458         AC_SUBST(swig, "$SWIG")
459         AC_MSG_RESULT(present)
460
461         # If have Python & SWIG
462         # Declare PythonMod
463         if test x_$ub_with_pythonmod != x_no; then
464            AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
465            WITH_PYTHONMODULE=yes
466            AC_SUBST(WITH_PYTHONMODULE)
467	    PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
468	    AC_SUBST(PYTHONMOD_OBJ)
469	    PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
470	    AC_SUBST(PYTHONMOD_HEADER)
471	    PYTHONMOD_INSTALL=pythonmod-install
472	    AC_SUBST(PYTHONMOD_INSTALL)
473	    PYTHONMOD_UNINSTALL=pythonmod-uninstall
474	    AC_SUBST(PYTHONMOD_UNINSTALL)
475         fi
476
477         # Declare PyUnbound
478         if test x_$ub_with_pyunbound != x_no; then
479            AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
480            WITH_PYUNBOUND=yes
481            AC_SUBST(WITH_PYUNBOUND)
482	    PYUNBOUND_OBJ="libunbound_wrap.lo"
483	    AC_SUBST(PYUNBOUND_OBJ)
484	    PYUNBOUND_TARGET="_unbound.la"
485	    AC_SUBST(PYUNBOUND_TARGET)
486	    PYUNBOUND_INSTALL=pyunbound-install
487	    AC_SUBST(PYUNBOUND_INSTALL)
488	    PYUNBOUND_UNINSTALL=pyunbound-uninstall
489	    AC_SUBST(PYUNBOUND_UNINSTALL)
490         fi
491      fi
492   else
493      AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
494      ub_with_pyunbound=no
495      ub_with_pythonmod=no
496   fi
497fi
498
499if test "`uname`" = "NetBSD"; then
500	NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
501	AC_SUBST(NETBSD_LINTFLAGS)
502fi
503CONFIG_DATE=`date +%Y%m%d`
504AC_SUBST(CONFIG_DATE)
505
506# Checks for libraries.
507
508# libnss
509USE_NSS="no"
510AC_ARG_WITH([nss], AC_HELP_STRING([--with-nss=path],
511	[use libnss instead of openssl, installed at path.]),
512	[
513	USE_NSS="yes"
514	AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
515	if test "$withval" != "" -a "$withval" != "yes"; then
516		CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
517		LDFLAGS="$LDFLAGS -L$withval/lib"
518		ACX_RUNTIME_PATH_ADD([$withval/lib])
519		CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
520	else
521		CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
522		CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
523	fi
524        LIBS="$LIBS -lnss3 -lnspr4"
525	]
526)
527
528# openssl
529if test $USE_NSS = "no"; then
530ACX_WITH_SSL
531ACX_LIB_SSL
532AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
533AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
534AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode])
535AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free], [], [], [
536AC_INCLUDES_DEFAULT
537#ifdef HAVE_OPENSSL_ERR_H
538#include <openssl/err.h>
539#endif
540
541#ifdef HAVE_OPENSSL_RAND_H
542#include <openssl/rand.h>
543#endif
544
545#ifdef HAVE_OPENSSL_CONF_H
546#include <openssl/conf.h>
547#endif
548
549#ifdef HAVE_OPENSSL_ENGINE_H
550#include <openssl/engine.h>
551#endif
552#include <openssl/ssl.h>
553#include <openssl/evp.h>
554])
555fi
556
557
558AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
559case "$enable_sha2" in
560	no)
561	;;
562	yes|*)
563	AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
564	;;
565esac
566
567# check wether gost also works
568AC_DEFUN([AC_CHECK_GOST_WORKS],
569[AC_REQUIRE([AC_PROG_CC])
570AC_MSG_CHECKING([if GOST works])
571if test c${cross_compiling} = cno; then
572BAKCFLAGS="$CFLAGS"
573if test -n "$ssldir"; then
574	CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
575fi
576AC_RUN_IFELSE([AC_LANG_SOURCE([[
577#include <string.h>
578#include <openssl/ssl.h>
579#include <openssl/evp.h>
580#include <openssl/engine.h>
581#include <openssl/conf.h>
582/* routine to load gost from ldns */
583int load_gost_id(void)
584{
585	static int gost_id = 0;
586	const EVP_PKEY_ASN1_METHOD* meth;
587	ENGINE* e;
588
589	if(gost_id) return gost_id;
590
591	/* see if configuration loaded gost implementation from other engine*/
592	meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
593	if(meth) {
594		EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
595		return gost_id;
596	}
597
598	/* see if engine can be loaded already */
599	e = ENGINE_by_id("gost");
600	if(!e) {
601		/* load it ourself, in case statically linked */
602		ENGINE_load_builtin_engines();
603		ENGINE_load_dynamic();
604		e = ENGINE_by_id("gost");
605	}
606	if(!e) {
607		/* no gost engine in openssl */
608		return 0;
609	}
610	if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
611		ENGINE_finish(e);
612		ENGINE_free(e);
613		return 0;
614	}
615
616	meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
617	if(!meth) {
618		/* algo not found */
619		ENGINE_finish(e);
620		ENGINE_free(e);
621		return 0;
622	}
623	EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
624	return gost_id;
625}
626int main(void) { 
627	EVP_MD_CTX* ctx;
628	const EVP_MD* md;
629	unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
630	const char* str = "Hello world";
631	const unsigned char check[] = {
632		0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
633		0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
634		0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
635		0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
636	};
637	OPENSSL_config(NULL);
638	(void)load_gost_id();
639	md = EVP_get_digestbyname("md_gost94");
640	if(!md) return 1;
641	memset(digest, 0, sizeof(digest));
642	ctx = EVP_MD_CTX_create();
643	if(!ctx) return 2;
644	if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
645	if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
646	if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
647	/* uncomment to see the hash calculated.
648		{int i;
649		for(i=0; i<32; i++)
650			printf(" %2.2x", (int)digest[i]);
651		printf("\n");}
652	*/
653	if(memcmp(digest, check, sizeof(check)) != 0)
654		return 6;
655	return 0;
656}
657]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
658CFLAGS="$BAKCFLAGS"
659else
660eval "ac_cv_c_gost_works=maybe"
661fi
662AC_MSG_RESULT($ac_cv_c_gost_works)
663])dnl
664
665AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
666use_gost="no"
667if test $USE_NSS = "no"; then
668case "$enable_gost" in
669	no)
670	;;
671	*)
672	AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
673	AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
674	AC_CHECK_GOST_WORKS
675	if test "$ac_cv_c_gost_works" != no; then
676		use_gost="yes"
677		AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
678	fi
679	;;
680esac
681fi dnl !USE_NSS
682
683AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
684use_ecdsa="no"
685case "$enable_ecdsa" in
686    no)
687      ;;
688    *)
689      if test $USE_NSS = "no"; then
690	      AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
691	      AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
692	      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
693#include <openssl/evp.h>
694	      ])
695	      # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
696	      AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
697	      if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
698		AC_MSG_RESULT([no])
699		AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
700	      else
701		AC_MSG_RESULT([yes])
702	      fi
703      fi
704      # we now know we have ECDSA and the required curves.
705      AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
706      use_ecdsa="yes"
707      ;;
708esac
709
710# check for libevent
711AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
712    [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.]),
713    [ ],[ withval="no" ])
714if test x_$withval = x_yes -o x_$withval != x_no; then
715        AC_MSG_CHECKING(for libevent)
716        if test x_$withval = x_ -o x_$withval = x_yes; then
717            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
718        fi
719        for dir in $withval; do
720            thedir="$dir"
721            if test -f "$dir/include/event.h"; then
722                found_libevent="yes"
723		dnl assume /usr is in default path.
724		if test "$thedir" != "/usr"; then
725                    CPPFLAGS="$CPPFLAGS -I$thedir/include"
726		fi
727                break;
728            fi
729        done
730        if test x_$found_libevent != x_yes; then
731		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
732			# libevent source directory
733            		AC_MSG_RESULT(found in $thedir)
734                	CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
735			BAK_LDFLAGS_SET="1"
736			BAK_LDFLAGS="$LDFLAGS"
737			# remove evdns from linking
738			mkdir build >/dev/null 2>&1
739			mkdir build/libevent >/dev/null 2>&1
740			mkdir build/libevent/.libs >/dev/null 2>&1
741			ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
742			ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
743			ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
744			cp $ev_files_o build/libevent
745			cp $ev_files_lo build/libevent
746			cp $ev_files_libso build/libevent/.libs
747            		LATE_LDFLAGS="build/libevent/*.lo -lm"
748			LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
749		else
750            		AC_MSG_ERROR([Cannot find the libevent library in $withval
751You can restart ./configure --with-libevent=no to use a builtin alternative.
752Please note that this alternative is not as capable as libevent when using
753large outgoing port ranges.  ])
754		fi
755        else
756            AC_MSG_RESULT(found in $thedir)
757	    dnl assume /usr is in default path, do not add "".
758	    if test "$thedir" != "/usr" -a "$thedir" != ""; then
759                LDFLAGS="$LDFLAGS -L$thedir/lib"
760		ACX_RUNTIME_PATH_ADD([$thedir/lib])
761	    fi
762        fi
763	# check for library used by libevent after 1.3c
764	AC_SEARCH_LIBS([clock_gettime], [rt])
765
766	# is the event.h header libev or libevent?
767	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
768	AC_CHECK_DECL(EV_VERSION_MAJOR, [
769		AC_SEARCH_LIBS(event_set, [ev])
770	],[
771		AC_SEARCH_LIBS(event_set, [event])
772	],[AC_INCLUDES_DEFAULT
773#include <event.h>
774	])
775	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
776	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
777	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
778	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
779	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
780	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
781	if test -n "$BAK_LDFLAGS_SET"; then
782		LDFLAGS="$BAK_LDFLAGS"
783	fi
784else
785	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
786fi
787
788# check for libexpat
789AC_ARG_WITH(libexpat, AC_HELP_STRING([--with-libexpat=path],
790    [specify explicit path for libexpat.]),
791    [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
792AC_MSG_CHECKING(for libexpat)
793found_libexpat="no"
794for dir in $withval ; do
795            if test -f "$dir/include/expat.h"; then
796		found_libexpat="yes"
797		dnl assume /usr is in default path.
798		if test "$dir" != "/usr"; then
799                    CPPFLAGS="$CPPFLAGS -I$dir/include"
800		    LDFLAGS="$LDFLAGS -L$dir/lib"
801		fi
802            	AC_MSG_RESULT(found in $dir)
803                break;
804            fi
805done
806if test x_$found_libexpat != x_yes; then
807	AC_ERROR([Could not find libexpat, expat.h])
808fi
809AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
810
811# set static linking if requested
812AC_SUBST(staticexe)
813staticexe=""
814AC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
815	[ enable to compile executables statically against event, ldns libs, for debug purposes ]), 
816	, )
817if test x_$enable_static_exe = x_yes; then
818	staticexe="-static"
819	if test "$on_mingw" = yes; then
820		staticexe="-all-static"
821		# for static crosscompile, include gdi32 and zlib here.
822		if test "`uname`" = "Linux"; then
823			LIBS="$LIBS -lgdi32 -lz"
824		fi
825	fi
826fi
827
828# set lock checking if requested
829AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
830	[ enable to check lock and unlock calls, for debug purposes ]), 
831	, )
832if test x_$enable_lock_checks = x_yes; then
833	AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
834	CHECKLOCK_OBJ="checklocks.lo"
835	AC_SUBST(CHECKLOCK_OBJ)
836fi
837
838ACX_CHECK_GETADDRINFO_WITH_INCLUDES
839if test "$USE_WINSOCK" = 1; then
840	AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
841	AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
842#include <windows.h>
843	])
844	AC_CHECK_TOOL(WINDRES, windres)
845	LIBS="$LIBS -liphlpapi"
846	WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
847	AC_SUBST(WINAPPS)
848	WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
849	AC_SUBST(WIN_DAEMON_SRC)
850	WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
851	AC_SUBST(WIN_DAEMON_OBJ)
852	WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
853	AC_SUBST(WIN_DAEMON_OBJ_LINK)
854	WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
855	AC_SUBST(WIN_HOST_OBJ_LINK)
856	WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
857	AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
858	WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
859	AC_SUBST(WIN_CONTROL_OBJ_LINK)
860	WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
861	AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
862fi
863if test $ac_cv_func_getaddrinfo = no; then
864	AC_LIBOBJ([fake-rfc2553])
865fi
866# check after getaddrinfo for its libraries
867ACX_FUNC_IOCTLSOCKET
868
869# see if daemon(3) exists, and if it is deprecated.
870AC_CHECK_FUNCS([daemon])
871if test $ac_cv_func_daemon = yes; then
872	ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
873#include <stdlib.h>
874])
875fi
876
877AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
878AC_INCLUDES_DEFAULT
879#if HAVE_SYS_PARAM_H
880#include <sys/param.h>
881#endif
882
883#ifdef HAVE_SYS_SOCKET_H
884#include <sys/socket.h>
885#endif
886
887#ifdef HAVE_SYS_UIO_H
888#include <sys/uio.h>
889#endif
890
891#ifdef HAVE_NETINET_IN_H
892#include <netinet/in.h>
893#endif
894
895#ifdef HAVE_ARPA_INET_H
896#include <arpa/inet.h>
897#endif
898
899#ifdef HAVE_WINSOCK2_H
900#include <winsock2.h>
901#endif
902
903#ifdef HAVE_WS2TCPIP_H
904#include <ws2tcpip.h>
905#endif
906])
907AC_SEARCH_LIBS([setusercontext], [util])
908AC_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])
909AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
910AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
911
912# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
913if echo $build_os | grep darwin8 > /dev/null; then
914	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
915fi
916AC_REPLACE_FUNCS(inet_aton)
917AC_REPLACE_FUNCS(inet_pton)
918AC_REPLACE_FUNCS(inet_ntop)
919AC_REPLACE_FUNCS(snprintf)
920AC_REPLACE_FUNCS(strlcpy)
921AC_REPLACE_FUNCS(memmove)
922AC_REPLACE_FUNCS(gmtime_r)
923LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
924AC_SUBST(LIBOBJ_WITHOUT_CTIME)
925AC_REPLACE_FUNCS(ctime_r)
926
927AC_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]))
928case "$enable_allsymbols" in
929	yes)
930	COMMON_OBJ_ALL_SYMBOLS=""
931	UBSYMS=""
932	EXTRALINK="-L. -L.libs -lunbound"
933	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])
934	;;
935	no|*)
936	COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
937	UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
938	EXTRALINK=""
939	;;
940esac
941AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
942AC_SUBST(EXTRALINK)
943AC_SUBST(UBSYMS)
944if test x_$enable_lock_checks = x_yes; then
945	UBSYMS="-export-symbols clubsyms.def"
946	cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
947	echo lock_protect >> clubsyms.def
948	echo lock_unprotect >> clubsyms.def
949	echo lock_get_mem >> clubsyms.def
950	echo checklock_start >> clubsyms.def
951	echo checklock_stop >> clubsyms.def
952	echo checklock_lock >> clubsyms.def
953	echo checklock_unlock >> clubsyms.def
954	echo checklock_init >> clubsyms.def
955	echo checklock_thrcreate >> clubsyms.def
956	echo checklock_thrjoin >> clubsyms.def
957fi
958
959AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
960# on openBSD, the implicit rule make $< work.
961# on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
962# gmake works.
963cat >conftest.make <<EOF
964all:	conftest.lo
965
966conftest.lo foo.lo bla.lo:
967	if test -f "\$<"; then touch \$@; fi
968
969.SUFFIXES: .lo
970.c.lo:
971	if test -f "\$<"; then touch \$@; fi
972
973conftest.lo:        conftest.dir/conftest.c
974EOF
975mkdir conftest.dir
976touch conftest.dir/conftest.c
977rm -f conftest.lo conftest.c
978${MAKE:-make} -f conftest.make >/dev/null
979rm -f conftest.make conftest.c conftest.dir/conftest.c
980rm -rf conftest.dir
981if test ! -f conftest.lo; then
982	AC_MSG_RESULT(no)
983	SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
984	SOURCEFILE='`cat .source`'
985else
986	AC_MSG_RESULT(yes)
987	SOURCEDETERMINE=':'
988	SOURCEFILE='$<'
989fi
990rm -f conftest.lo
991AC_SUBST(SOURCEDETERMINE)
992AC_SUBST(SOURCEFILE)
993
994# see if we want to build the library or everything
995ALLTARGET="alltargets"
996AC_ARG_WITH(libunbound-only, AC_HELP_STRING([--with-libunbound-only],
997	[do not build daemon and tool programs]),
998	[
999	if test "$withval" = "yes"; then
1000		ALLTARGET="lib"
1001	fi
1002])
1003AC_SUBST(ALLTARGET)
1004
1005# check this after all other compilation checks, since the linking of the lib
1006# may break checks after this.
1007AC_ARG_WITH(ldns, AC_HELP_STRING([--with-ldns=PATH], 
1008	[specify prefix of path of ldns library to use]), 
1009	[
1010	if test "$withval" != "yes"; then
1011		if test "$withval" != "/usr" -a "$withval" != ""; then
1012			CPPFLAGS="-I$withval/include $CPPFLAGS"
1013			LDFLAGS="-L$withval/lib $LDFLAGS"
1014			ACX_RUNTIME_PATH_ADD([$withval/lib])
1015		fi
1016		ldnsdir="$withval"
1017		AC_SUBST(ldnsdir)
1018	fi
1019])
1020
1021# check if ldns is good enough
1022AC_CHECK_LIB(ldns, ldns_rr_new,,[
1023	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])
1024])
1025AC_CHECK_FUNC(ldns_buffer_copy)
1026if test $USE_NSS = "no"; then
1027    AC_CHECK_FUNC(ldns_key_buf2rsa_raw)
1028else
1029    dnl ignore test
1030    ac_cv_func_ldns_key_buf2rsa_raw="yes"
1031fi
1032AC_CHECK_FUNC(ldns_get_random)
1033AC_CHECK_FUNC(ldns_b32_ntop_extended_hex)
1034if test x$use_gost = xyes -a x$USE_NSS = xno; then
1035    AC_CHECK_FUNC(ldns_key_EVP_load_gost_id)
1036    AC_CHECK_FUNCS([ldns_key_EVP_unload_gost])
1037else
1038    dnl ignore test
1039    ac_cv_func_ldns_key_EVP_load_gost_id="yes"
1040fi
1041if test x$use_ecdsa = xyes; then
1042    AC_CHECK_DECL([LDNS_ECDSAP384SHA384], [], [], [
1043AC_INCLUDES_DEFAULT
1044#ifdef HAVE_SYS_SOCKET_H
1045#  include <sys/socket.h>
1046#endif
1047#ifdef HAVE_WS2TCPIP_H
1048#  include <ws2tcpip.h>
1049#endif
1050#include <ldns/ldns.h>
1051    ])
1052else
1053    ac_cv_have_decl_LDNS_ECDSAP384SHA384="yes"
1054fi
1055AC_CHECK_HEADERS([ldns/ldns.h],,[
1056	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])
1057	], [AC_INCLUDES_DEFAULT
1058#ifdef HAVE_SYS_SOCKET_H
1059#include <sys/socket.h>
1060#endif
1061
1062#ifdef HAVE_NETINET_IN_H
1063#include <netinet/in.h>
1064#endif
1065
1066#ifdef HAVE_ARPA_INET_H
1067#include <arpa/inet.h>
1068#endif
1069
1070#ifdef HAVE_WINSOCK2_H
1071#include <winsock2.h>
1072#endif
1073
1074#ifdef HAVE_WS2TCPIP_H
1075#include <ws2tcpip.h>
1076#endif
1077])
1078if test $ac_cv_func_ldns_buffer_copy = yes \
1079    -a $ac_cv_func_ldns_key_buf2rsa_raw = yes \
1080    -a $ac_cv_func_ldns_get_random = yes \
1081    -a $ac_cv_header_ldns_ldns_h = yes \
1082    -a $ac_cv_func_ldns_b32_ntop_extended_hex = yes \
1083    -a $ac_cv_func_ldns_key_EVP_load_gost_id = yes \
1084    -a $ac_cv_have_decl_LDNS_ECDSAP384SHA384 = yes; then
1085    dnl ldns was found
1086    :
1087else
1088    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])
1089fi
1090
1091ACX_STRIP_EXT_FLAGS
1092LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1093
1094AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1095
1096AH_BOTTOM(
1097dnl this must be first AH_CONFIG, to define the flags before any includes.
1098AHX_CONFIG_EXT_FLAGS
1099
1100dnl includes
1101[
1102#ifndef UNBOUND_DEBUG
1103#  define NDEBUG
1104#endif
1105
1106#include <stdio.h>
1107#include <string.h>
1108#include <unistd.h>
1109#include <assert.h>
1110
1111#if STDC_HEADERS
1112#include <stdlib.h>
1113#include <stddef.h>
1114#endif
1115
1116#ifdef HAVE_STDINT_H
1117#include <stdint.h>
1118#endif
1119
1120#include <errno.h>
1121
1122#if HAVE_SYS_PARAM_H
1123#include <sys/param.h>
1124#endif
1125
1126#ifdef HAVE_SYS_SOCKET_H
1127#include <sys/socket.h>
1128#endif
1129
1130#ifdef HAVE_SYS_UIO_H
1131#include <sys/uio.h>
1132#endif
1133
1134#ifdef HAVE_NETINET_IN_H
1135#include <netinet/in.h>
1136#endif
1137
1138#ifdef HAVE_ARPA_INET_H
1139#include <arpa/inet.h>
1140#endif
1141
1142#ifdef HAVE_WINSOCK2_H
1143#include <winsock2.h>
1144#endif
1145
1146#ifdef HAVE_WS2TCPIP_H
1147#include <ws2tcpip.h>
1148#endif
1149]
1150
1151AHX_CONFIG_FORMAT_ATTRIBUTE
1152AHX_CONFIG_UNUSED_ATTRIBUTE
1153AHX_CONFIG_FSEEKO
1154AHX_CONFIG_MAXHOSTNAMELEN
1155AHX_CONFIG_SNPRINTF(unbound)
1156AHX_CONFIG_INET_PTON(unbound)
1157AHX_CONFIG_INET_NTOP(unbound)
1158AHX_CONFIG_INET_ATON(unbound)
1159AHX_CONFIG_MEMMOVE(unbound)
1160AHX_CONFIG_STRLCPY(unbound)
1161AHX_CONFIG_GMTIME_R(unbound)
1162AHX_CONFIG_W32_SLEEP
1163AHX_CONFIG_W32_USLEEP
1164AHX_CONFIG_W32_RANDOM
1165AHX_CONFIG_W32_SRANDOM
1166AHX_CONFIG_W32_FD_SET_T
1167AHX_CONFIG_IPV6_MIN_MTU
1168AHX_MEMCMP_BROKEN(unbound)
1169
1170[
1171#ifndef HAVE_CTIME_R
1172#define ctime_r unbound_ctime_r
1173char *ctime_r(const time_t *timep, char *buf);
1174#endif
1175
1176#if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1177#define strptime unbound_strptime
1178struct tm;
1179char *strptime(const char *s, const char *format, struct tm *tm);
1180#endif
1181
1182#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))
1183   /* using version of libevent that is not threadsafe. */
1184#  define LIBEVENT_SIGNAL_PROBLEM 1
1185#endif
1186
1187#ifndef CHECKED_INET6
1188#  define CHECKED_INET6
1189#  ifdef AF_INET6
1190#    define INET6
1191#  else
1192#    define AF_INET6        28
1193#  endif
1194#endif /* CHECKED_INET6 */
1195
1196/* maximum nesting of included files */
1197#define MAXINCLUDES 10
1198#ifndef HAVE_GETADDRINFO
1199struct sockaddr_storage;
1200#include "compat/fake-rfc2553.h"
1201#endif
1202
1203#ifdef UNBOUND_ALLOC_STATS
1204#  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
1205#  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
1206#  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
1207#  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
1208void *unbound_stat_malloc(size_t size);
1209void *unbound_stat_calloc(size_t nmemb, size_t size);
1210void unbound_stat_free(void *ptr);
1211void *unbound_stat_realloc(void *ptr, size_t size);
1212void *unbound_stat_malloc_log(size_t size, const char* file, int line,
1213	const char* func);
1214void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1215	int line, const char* func);
1216void unbound_stat_free_log(void *ptr, const char* file, int line,
1217	const char* func);
1218void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
1219	int line, const char* func);
1220#elif defined(UNBOUND_ALLOC_LITE)
1221#  include "util/alloc.h"
1222#endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
1223
1224/** default port for DNS traffic. */
1225#define UNBOUND_DNS_PORT 53
1226/** default port for unbound control traffic, registered port with IANA,
1227    ub-dns-control  8953/tcp    unbound dns nameserver control */
1228#define UNBOUND_CONTROL_PORT 8953
1229/** the version of unbound-control that this software implements */
1230#define UNBOUND_CONTROL_VERSION 1
1231
1232])
1233
1234AC_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 smallapp/unbound-control-setup.sh])
1235AC_CONFIG_HEADER([config.h])
1236AC_OUTPUT
1237