]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - configure.ac
import unbound 1.4.21
[FreeBSD/FreeBSD.git] / configure.ac
1 #                                               -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3 AC_PREREQ(2.56)
4 sinclude(acx_nlnetlabs.m4)
5 sinclude(ax_pthread.m4)
6 sinclude(acx_python.m4)
7 sinclude(ac_pkg_swig.m4)
8
9 # must be numbers. ac_defun because of later processing
10 m4_define([VERSION_MAJOR],[1])
11 m4_define([VERSION_MINOR],[4])
12 m4_define([VERSION_MICRO],[21])
13 AC_INIT(unbound, m4_defn([VERSION_MAJOR]).m4_defn([VERSION_MINOR]).m4_defn([VERSION_MICRO]), unbound-bugs@nlnetlabs.nl, unbound)
14 AC_SUBST(UNBOUND_VERSION_MAJOR, [VERSION_MAJOR])
15 AC_SUBST(UNBOUND_VERSION_MINOR, [VERSION_MINOR])
16 AC_SUBST(UNBOUND_VERSION_MICRO, [VERSION_MICRO])
17
18 LIBUNBOUND_CURRENT=4
19 LIBUNBOUND_REVISION=1
20 LIBUNBOUND_AGE=2
21 # 1.0.0 had 0:12:0
22 # 1.0.1 had 0:13:0
23 # 1.0.2 had 0:14:0
24 # 1.1.0 had 0:15:0
25 # 1.1.1 had 0:16:0
26 # 1.2.0 had 0:17:0
27 # 1.2.1 had 0:18:0
28 # 1.3.0 had 1:0:0   # ub_cancel and -export-symbols.
29 # 1.3.1 had 1:1:0
30 # 1.3.2 had 1:2:0
31 # 1.3.3 had 1:3:0
32 # 1.3.4 had 1:4:0
33 # 1.4.0-snapshots had 1:5:0
34 # 1.4.0 had 1:5:0 (not 2:0:0)   # ub_result.why_bogus
35 # 1.4.1 had 2:1:0
36 # 1.4.2 had 2:2:0
37 # 1.4.3 had 2:3:0
38 # 1.4.4 had 2:4:0
39 # 1.4.5 had 2:5:0
40 # 1.4.6 had 2:6:0
41 # 1.4.7 had 2:7:0
42 # 1.4.8 had 2:8:0
43 # 1.4.9 had 2:9:0
44 # 1.4.10 had 2:10:0
45 # 1.4.11 had 2:11:0
46 # 1.4.12 had 2:12:0
47 # 1.4.13 had 2:13:0
48 # and 1.4.13p1 and 1.4.13.p2
49 # 1.4.14 had 2:14:0
50 # 1.4.15 had 3:0:1 # adds ub_version()
51 # 1.4.16 had 3:1:1
52 # 1.4.17 had 3:2:1
53 # 1.4.18 had 3:3:1
54 # 1.4.19 had 3:4:1
55 # 1.4.20 had 4:0:2 # adds libunbound.ttl # but shipped 3:5:1
56 # 1.4.21 had 4:1:2
57
58 #   Current  -- the number of the binary API that we're implementing
59 #   Revision -- which iteration of the implementation of the binary
60 #               API are we supplying?
61 #   Age      -- How many previous binary API versions do we also
62 #               support?
63 #
64 # If we release a new version that does not change the binary API,
65 # increment Revision.
66 #
67 # If we release a new version that changes the binary API, but does
68 # not break programs compiled against the old binary API, increment
69 # Current and Age.  Set Revision to 0, since this is the first
70 # implementation of the new API.
71 #
72 # Otherwise, we're changing the binary API and breaking bakward
73 # compatibility with old binaries.  Increment Current.  Set Age to 0,
74 # since we're backward compatible with no previous APIs.  Set Revision
75 # to 0 too.
76 AC_SUBST(LIBUNBOUND_CURRENT)
77 AC_SUBST(LIBUNBOUND_REVISION)
78 AC_SUBST(LIBUNBOUND_AGE)
79
80 pretty_cmdline() {
81         cmdline=""
82         while test -n "$1"; do
83                 cmdline="$cmdline '"`echo $1 | sed -e 's/\\\\/\\\\\\\\/g' | sed -e 's/"/\\\\"/g' `"'"
84                 shift
85         done
86 }
87 pretty_cmdline $@
88 AC_DEFINE_UNQUOTED(CONFIGURE_BUILD_WITH, ["$cmdline"], [configure flags])
89 AC_CANONICAL_TARGET
90 AC_DEFINE_UNQUOTED(CONFIGURE_TARGET, ["$target"], [configure target system])
91 AC_DEFINE_UNQUOTED(CONFIGURE_DATE, ["`date`"], [configure date])
92
93 CFLAGS="$CFLAGS"
94 AC_AIX
95
96 dnl
97 dnl By default set prefix to /usr/local
98 dnl
99 case "$prefix" in
100         NONE)
101                 prefix="/usr/local"
102         ;;
103 esac
104
105 # are we on MinGW?
106 if uname -s 2>&1 | grep MINGW32 >/dev/null; then on_mingw="yes"
107 else 
108         if echo $target | grep mingw32 >/dev/null; then on_mingw="yes"
109         else on_mingw="no"; fi
110 fi
111
112 #
113 # Determine configuration file
114 # the eval is to evaluate shell expansion twice
115 if test $on_mingw = "no"; then
116   ub_conf_file=`eval echo "${sysconfdir}/unbound/unbound.conf"`
117 else
118   ub_conf_file="C:\\Program Files\\Unbound\\service.conf"
119 fi
120 AC_ARG_WITH([conf_file],
121         AC_HELP_STRING([--with-conf-file=path], 
122         [Pathname to the Unbound configuration file]),
123         [ub_conf_file="$withval"])
124 AC_SUBST(ub_conf_file)
125 ACX_ESCAPE_BACKSLASH($ub_conf_file, hdr_config)
126 AC_DEFINE_UNQUOTED(CONFIGFILE, ["$hdr_config"], [Pathname to the Unbound configuration file])
127
128 # Determine run, chroot directory and pidfile locations
129 AC_ARG_WITH(run-dir, 
130     AC_HELP_STRING([--with-run-dir=path], 
131     [set default directory to chdir to (by default dir part of cfg file)]), 
132     UNBOUND_RUN_DIR="$withval", 
133 if test $on_mingw = no; then
134     UNBOUND_RUN_DIR=`dirname "$ub_conf_file"`
135 else
136     UNBOUND_RUN_DIR=""
137 fi
138 )
139 AC_SUBST(UNBOUND_RUN_DIR)
140 ACX_ESCAPE_BACKSLASH($UNBOUND_RUN_DIR, hdr_run)
141 AC_DEFINE_UNQUOTED(RUN_DIR, ["$hdr_run"], [Directory to chdir to])
142
143 AC_ARG_WITH(chroot-dir, 
144     AC_HELP_STRING([--with-chroot-dir=path], 
145     [set default directory to chroot to (by default same as run-dir)]), 
146     UNBOUND_CHROOT_DIR="$withval", 
147 if test $on_mingw = no; then
148     UNBOUND_CHROOT_DIR="$UNBOUND_RUN_DIR"
149 else
150     UNBOUND_CHROOT_DIR=""
151 fi
152 )
153 AC_SUBST(UNBOUND_CHROOT_DIR)
154 ACX_ESCAPE_BACKSLASH($UNBOUND_CHROOT_DIR, hdr_chroot)
155 AC_DEFINE_UNQUOTED(CHROOT_DIR, ["$hdr_chroot"], [Directory to chroot to])
156
157 AC_ARG_WITH(share-dir,
158     AC_HELP_STRING([--with-share-dir=path],
159     [set default directory with shared data (by default same as share/unbound)]),
160     UNBOUND_SHARE_DIR="$withval",
161     UNBOUND_SHARE_DIR="$UNBOUND_RUN_DIR")
162 AC_SUBST(UNBOUND_SHARE_DIR)
163 AC_DEFINE_UNQUOTED(SHARE_DIR, ["$UNBOUND_SHARE_DIR"], [Shared data])
164
165 AC_ARG_WITH(pidfile, 
166     AC_HELP_STRING([--with-pidfile=filename], 
167     [set default pathname to unbound pidfile (default run-dir/unbound.pid)]), 
168     UNBOUND_PIDFILE="$withval", 
169 if test $on_mingw = no; then
170     UNBOUND_PIDFILE="$UNBOUND_RUN_DIR/unbound.pid"
171 else
172     UNBOUND_PIDFILE=""
173 fi
174 )
175 AC_SUBST(UNBOUND_PIDFILE)
176 ACX_ESCAPE_BACKSLASH($UNBOUND_PIDFILE, hdr_pid)
177 AC_DEFINE_UNQUOTED(PIDFILE, ["$hdr_pid"], [default pidfile location])
178
179 AC_ARG_WITH(rootkey-file, 
180     AC_HELP_STRING([--with-rootkey-file=filename], 
181     [set default pathname to root key file (default run-dir/root.key). This file is read and written.]), 
182     UNBOUND_ROOTKEY_FILE="$withval", 
183 if test $on_mingw = no; then
184     UNBOUND_ROOTKEY_FILE="$UNBOUND_RUN_DIR/root.key"
185 else
186     UNBOUND_ROOTKEY_FILE="C:\\Program Files\\Unbound\\root.key"
187 fi
188 )
189 AC_SUBST(UNBOUND_ROOTKEY_FILE)
190 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTKEY_FILE, hdr_rkey)
191 AC_DEFINE_UNQUOTED(ROOT_ANCHOR_FILE, ["$hdr_rkey"], [default rootkey location])
192
193 AC_ARG_WITH(rootcert-file, 
194     AC_HELP_STRING([--with-rootcert-file=filename], 
195     [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.]), 
196     UNBOUND_ROOTCERT_FILE="$withval", 
197 if test $on_mingw = no; then
198     UNBOUND_ROOTCERT_FILE="$UNBOUND_RUN_DIR/icannbundle.pem"
199 else
200     UNBOUND_ROOTCERT_FILE="C:\\Program Files\\Unbound\\icannbundle.pem"
201 fi
202 )
203 AC_SUBST(UNBOUND_ROOTCERT_FILE)
204 ACX_ESCAPE_BACKSLASH($UNBOUND_ROOTCERT_FILE, hdr_rpem)
205 AC_DEFINE_UNQUOTED(ROOT_CERT_FILE, ["$hdr_rpem"], [default rootcert location])
206
207 AC_ARG_WITH(username, 
208     AC_HELP_STRING([--with-username=user], 
209     [set default user that unbound changes to (default user is unbound)]), 
210     UNBOUND_USERNAME="$withval", 
211     UNBOUND_USERNAME="unbound")
212 AC_SUBST(UNBOUND_USERNAME)
213 AC_DEFINE_UNQUOTED(UB_USERNAME, ["$UNBOUND_USERNAME"], [default username])
214
215 AC_DEFINE(WINVER, 0x0502, [the version of the windows API enabled])
216 ACX_RSRC_VERSION(wnvs)
217 AC_DEFINE_UNQUOTED(RSRC_PACKAGE_VERSION, [$wnvs], [version number for resource files])
218
219 # Checks for typedefs, structures, and compiler characteristics.
220 AC_C_CONST
221 AC_LANG_C
222 # allow user to override the -g -O2 flags.
223 if test "x$CFLAGS" = "x" ; then
224 ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
225 ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
226 fi
227 AC_PROG_CC
228 ACX_DEPFLAG
229 ACX_DETERMINE_EXT_FLAGS_UNBOUND
230
231 # debug mode flags warnings
232 AC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable warnings, asserts, makefile-dependencies]))
233 AC_ARG_ENABLE(debug, AC_HELP_STRING([--enable-debug], [same as enable-checking]))
234 if test "$enable_debug" = "yes"; then debug_enabled="$enable_debug"; 
235 else debug_enabled="$enable_checking"; fi
236 AC_SUBST(debug_enabled)
237 case "$debug_enabled" in
238         yes)
239                 ACX_CHECK_COMPILER_FLAG(W, [CFLAGS="$CFLAGS -W"])
240                 ACX_CHECK_COMPILER_FLAG(Wall, [CFLAGS="$CFLAGS -Wall"])
241                 ACX_CHECK_COMPILER_FLAG(Wextra, [CFLAGS="$CFLAGS -Wextra"])
242                 ACX_CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [CFLAGS="$CFLAGS -Wdeclaration-after-statement"])
243                 AC_DEFINE([UNBOUND_DEBUG], [], [define this to enable debug checks.])
244                 ;;
245         no|*)
246                 # nothing to do.
247                 ;;
248 esac
249 ACX_CHECK_FLTO
250
251 AC_C_INLINE
252 ACX_CHECK_FORMAT_ATTRIBUTE
253 ACX_CHECK_UNUSED_ATTRIBUTE
254
255 if test "$srcdir" != "."; then
256         CPPFLAGS="$CPPFLAGS -I$srcdir"
257 fi
258
259 AC_DEFUN([ACX_YYLEX_DESTROY], [
260         AC_MSG_CHECKING([for yylex_destroy])
261         if echo %% | $LEX -t 2>&1 | grep yylex_destroy >/dev/null 2>&1; then
262                 AC_DEFINE(LEX_HAS_YYLEX_DESTROY, 1, [if lex has yylex_destroy])
263                 AC_MSG_RESULT(yes)
264         else AC_MSG_RESULT(no); fi
265 ])
266
267 AC_PROG_LEX
268 ACX_YYLEX_DESTROY
269 AC_PROG_YACC
270 AC_CHECK_PROG(doxygen, doxygen, doxygen)
271 AC_CHECK_TOOL(STRIP, strip)
272 ACX_LIBTOOL_C_ONLY
273
274 # Checks for header files.
275 AC_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])
276
277 # check for types.  
278 # Using own tests for int64* because autoconf builtin only give 32bit.
279 AC_CHECK_TYPE(int8_t, signed char)
280 AC_CHECK_TYPE(int16_t, short)
281 AC_CHECK_TYPE(int32_t, int)
282 AC_CHECK_TYPE(int64_t, long long)
283 AC_CHECK_TYPE(uint8_t, unsigned char)
284 AC_CHECK_TYPE(uint16_t, unsigned short)
285 AC_CHECK_TYPE(uint32_t, unsigned int)
286 AC_CHECK_TYPE(uint64_t, unsigned long long)
287 AC_TYPE_SIZE_T
288 AC_CHECK_TYPE(ssize_t, int)
289 AC_TYPE_UID_T
290 AC_TYPE_PID_T
291 AC_TYPE_OFF_T
292 ACX_TYPE_U_CHAR
293 ACX_TYPE_RLIM_T
294 ACX_TYPE_SOCKLEN_T
295 ACX_TYPE_IN_ADDR_T
296 ACX_TYPE_IN_PORT_T
297 ACX_CHECK_MEMCMP_SIGNED
298
299 # add option to disable the evil rpath
300 ACX_ARG_RPATH
301 AC_SUBST(RUNTIME_PATH)
302
303 # check to see if libraries are needed for these functions.
304 AC_SEARCH_LIBS([inet_pton], [nsl])
305 AC_SEARCH_LIBS([socket], [socket])
306
307 # check wether strptime also works
308 AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
309 [AC_REQUIRE([AC_PROG_CC])
310 AC_MSG_CHECKING(whether strptime works)
311 if test c${cross_compiling} = cno; then
312 AC_RUN_IFELSE([AC_LANG_SOURCE([[
313 #define _XOPEN_SOURCE
314 #include <time.h>
315 int main(void) { struct tm tm; char *res;
316 res = 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);
317 if (!res) return 2;
318 res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
319 if (!res) return 1; return 0; }
320 ]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
321 else
322 eval "ac_cv_c_strptime_works=maybe"
323 fi
324 AC_MSG_RESULT($ac_cv_c_strptime_works)
325 if test $ac_cv_c_strptime_works = no; then
326 AC_LIBOBJ(strptime)
327 else
328 AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
329 fi
330 ])dnl
331
332 # check some functions of the OS before linking libs (while still runnable).
333 AC_FUNC_CHOWN
334 AC_FUNC_FORK
335 AC_TYPE_SIGNAL
336 AC_FUNC_FSEEKO
337 ACX_SYS_LARGEFILE
338 ACX_CHECK_NONBLOCKING_BROKEN
339 ACX_MKDIR_ONE_ARG
340 AC_CHECK_FUNCS([strptime],[AC_CHECK_STRPTIME_WORKS],[AC_LIBOBJ([strptime])])
341
342 # set memory allocation checking if requested
343 AC_ARG_ENABLE(alloc-checks, AC_HELP_STRING([--enable-alloc-checks],
344         [ enable to memory allocation statistics, for debug purposes ]), 
345         , )
346 AC_ARG_ENABLE(alloc-lite, AC_HELP_STRING([--enable-alloc-lite],
347         [ enable for lightweight alloc assertions, for debug purposes ]), 
348         , )
349 AC_ARG_ENABLE(alloc-nonregional, AC_HELP_STRING([--enable-alloc-nonregional],
350         [ enable nonregional allocs, slow but exposes regional allocations to other memory purifiers, for debug purposes ]), 
351         , )
352 if test x_$enable_alloc_nonregional = x_yes; then
353         AC_DEFINE(UNBOUND_ALLOC_NONREGIONAL, 1, [use malloc not regions, for debug use])
354 fi
355 if test x_$enable_alloc_checks = x_yes; then
356         AC_DEFINE(UNBOUND_ALLOC_STATS, 1, [use statistics for allocs and frees, for debug use])
357 else
358         if test x_$enable_alloc_lite = x_yes; then
359                 AC_DEFINE(UNBOUND_ALLOC_LITE, 1, [use to enable lightweight alloc assertions, for debug use])
360         else
361                 ACX_FUNC_MALLOC([unbound])
362         fi
363 fi
364
365 # check windows threads (we use them, not pthreads, on windows).
366 if test "$on_mingw" = "yes"; then
367 # check windows threads
368         AC_CHECK_HEADERS([windows.h],,, [AC_INCLUDES_DEFAULT])
369         AC_MSG_CHECKING([for CreateThread])
370         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
371 #ifdef HAVE_WINDOWS_H
372 #include <windows.h>
373 #endif
374 ], [
375         HANDLE t = CreateThread(NULL, 0, NULL, NULL, 0, NULL);
376 ])],
377         AC_MSG_RESULT(yes)
378         AC_DEFINE(HAVE_WINDOWS_THREADS, 1, [Using Windows threads])
379 ,       
380         AC_MSG_RESULT(no)
381 )
382
383 else
384 # not on mingw, check thread libraries.
385
386 # check for thread library.
387 # check this first, so that the pthread lib does not get linked in via
388 # libssl or libpython, and thus distorts the tests, and we end up using
389 # the non-threadsafe C libraries.
390 AC_ARG_WITH(pthreads, AC_HELP_STRING([--with-pthreads], 
391  [use pthreads library, or --without-pthreads to disable threading support.]), 
392  [ ],[ withval="yes" ])
393 ub_have_pthreads=no
394 if test x_$withval != x_no; then
395         AX_PTHREAD([
396                 AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.])
397                 LIBS="$PTHREAD_LIBS $LIBS"
398                 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
399                 CC="$PTHREAD_CC"
400                 ub_have_pthreads=yes
401                 AC_CHECK_TYPES([pthread_spinlock_t, pthread_rwlock_t],,,[#include <pthread.h>])
402                 ])
403 fi
404
405 # check solaris thread library 
406 AC_ARG_WITH(solaris-threads, AC_HELP_STRING([--with-solaris-threads], 
407         [use solaris native thread library.]), [ ],[ withval="no" ])
408 ub_have_sol_threads=no
409 if test x_$withval != x_no; then
410         if test x_$ub_have_pthreads != x_no; then
411             AC_WARN([Have pthreads already, ignoring --with-solaris-threads])
412         else
413         AC_SEARCH_LIBS(thr_create, [thread],
414         [
415                 AC_DEFINE(HAVE_SOLARIS_THREADS, 1, [Using Solaris threads])
416
417                 ACX_CHECK_COMPILER_FLAG(mt, [CFLAGS="$CFLAGS -mt"],
418                         [CFLAGS="$CFLAGS -D_REENTRANT"])
419                 ub_have_sol_threads=yes
420         ] , [ 
421                 AC_ERROR([no solaris threads found.]) 
422         ])
423         fi
424 fi
425
426 fi # end of non-mingw check of thread libraries
427
428 # Check for PyUnbound
429 AC_ARG_WITH(pyunbound,
430    AC_HELP_STRING([--with-pyunbound],
431    [build PyUnbound, or --without-pyunbound to skip it. (default=no)]),
432    [], [ withval="no" ])
433
434 ub_test_python=no
435 ub_with_pyunbound=no
436 if test x_$withval != x_no; then
437    ub_with_pyunbound=yes
438    ub_test_python=yes
439 fi
440
441 # Check for Python module
442 AC_ARG_WITH(pythonmodule,
443    AC_HELP_STRING([--with-pythonmodule],
444    [build Python module, or --without-pythonmodule to disable script engine. (default=no)]),
445    [], [ withval="no" ])
446
447 ub_with_pythonmod=no
448 if test x_$withval != x_no; then
449    ub_with_pythonmod=yes
450    ub_test_python=yes
451 fi
452
453 # Check for Python & SWIG only on PyUnbound or PyModule
454 if test x_$ub_test_python != x_no; then
455
456    # Check for Python
457    ub_have_python=no
458    ac_save_LIBS="$LIBS" dnl otherwise AC_PYTHON_DEVEL thrashes $LIBS
459    AC_PYTHON_DEVEL
460    if test ! -z "$PYTHON_VERSION"; then
461         if test `$PYTHON -c "print '$PYTHON_VERSION' >= '2.4.0'"` = "False"; then
462                 AC_ERROR([Python version >= 2.4.0 is required])
463         fi
464
465       # Have Python
466       AC_DEFINE(HAVE_PYTHON,1,[Define if you have Python libraries and header files.])
467       LIBS="$PYTHON_LDFLAGS $LIBS"
468       CPPFLAGS="$CPPFLAGS $PYTHON_CPPFLAGS"
469       ub_have_python=yes
470
471       # Check for SWIG
472       ub_have_swig=no
473       AC_PROG_SWIG
474       AC_MSG_CHECKING(SWIG)
475       if test ! -x "$SWIG"; then
476          AC_ERROR([failed to find swig tool, install it, or do not build Python module and PyUnbound])
477       else
478          AC_DEFINE(HAVE_SWIG, 1, [Define if you have Swig libraries and header files.])
479          AC_SUBST(swig, "$SWIG")
480          AC_MSG_RESULT(present)
481
482          # If have Python & SWIG
483          # Declare PythonMod
484          if test x_$ub_with_pythonmod != x_no; then
485             AC_DEFINE(WITH_PYTHONMODULE, 1, [Define if you want Python module.])
486             WITH_PYTHONMODULE=yes
487             AC_SUBST(WITH_PYTHONMODULE)
488             PYTHONMOD_OBJ="pythonmod.lo pythonmod_utils.lo"
489             AC_SUBST(PYTHONMOD_OBJ)
490             PYTHONMOD_HEADER='$(srcdir)/pythonmod/pythonmod.h'
491             AC_SUBST(PYTHONMOD_HEADER)
492             PYTHONMOD_INSTALL=pythonmod-install
493             AC_SUBST(PYTHONMOD_INSTALL)
494             PYTHONMOD_UNINSTALL=pythonmod-uninstall
495             AC_SUBST(PYTHONMOD_UNINSTALL)
496          fi
497
498          # Declare PyUnbound
499          if test x_$ub_with_pyunbound != x_no; then
500             AC_DEFINE(WITH_PYUNBOUND, 1, [Define if you want PyUnbound.])
501             WITH_PYUNBOUND=yes
502             AC_SUBST(WITH_PYUNBOUND)
503             PYUNBOUND_OBJ="libunbound_wrap.lo"
504             AC_SUBST(PYUNBOUND_OBJ)
505             PYUNBOUND_TARGET="_unbound.la"
506             AC_SUBST(PYUNBOUND_TARGET)
507             PYUNBOUND_INSTALL=pyunbound-install
508             AC_SUBST(PYUNBOUND_INSTALL)
509             PYUNBOUND_UNINSTALL=pyunbound-uninstall
510             AC_SUBST(PYUNBOUND_UNINSTALL)
511          fi
512       fi
513    else
514       AC_MSG_RESULT([*** Python libraries not found, won't build PythonMod or PyUnbound ***])
515       ub_with_pyunbound=no
516       ub_with_pythonmod=no
517    fi
518 fi
519
520 if test "`uname`" = "NetBSD"; then
521         NETBSD_LINTFLAGS='"-D__RENAME(x)=" -D_NETINET_IN_H_'
522         AC_SUBST(NETBSD_LINTFLAGS)
523 fi
524 CONFIG_DATE=`date +%Y%m%d`
525 AC_SUBST(CONFIG_DATE)
526
527 # Checks for libraries.
528
529 # libnss
530 USE_NSS="no"
531 AC_ARG_WITH([nss], AC_HELP_STRING([--with-nss=path],
532         [use libnss instead of openssl, installed at path.]),
533         [
534         USE_NSS="yes"
535         AC_DEFINE(HAVE_NSS, 1, [Use libnss for crypto])
536         if test "$withval" != "" -a "$withval" != "yes"; then
537                 CPPFLAGS="$CPPFLAGS -I$withval/include/nss3"
538                 LDFLAGS="$LDFLAGS -L$withval/lib"
539                 ACX_RUNTIME_PATH_ADD([$withval/lib])
540                 CPPFLAGS="-I$withval/include/nspr4 $CPPFLAGS"
541         else
542                 CPPFLAGS="$CPPFLAGS -I/usr/include/nss3"
543                 CPPFLAGS="-I/usr/include/nspr4 $CPPFLAGS"
544         fi
545         LIBS="$LIBS -lnss3 -lnspr4"
546         ]
547 )
548
549 # openssl
550 if test $USE_NSS = "no"; then
551 ACX_WITH_SSL
552 ACX_LIB_SSL
553 AC_CHECK_HEADERS([openssl/conf.h],,, [AC_INCLUDES_DEFAULT])
554 AC_CHECK_HEADERS([openssl/engine.h],,, [AC_INCLUDES_DEFAULT])
555 AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode])
556 AC_CHECK_DECLS([SSL_COMP_get_compression_methods,sk_SSL_COMP_pop_free], [], [], [
557 AC_INCLUDES_DEFAULT
558 #ifdef HAVE_OPENSSL_ERR_H
559 #include <openssl/err.h>
560 #endif
561
562 #ifdef HAVE_OPENSSL_RAND_H
563 #include <openssl/rand.h>
564 #endif
565
566 #ifdef HAVE_OPENSSL_CONF_H
567 #include <openssl/conf.h>
568 #endif
569
570 #ifdef HAVE_OPENSSL_ENGINE_H
571 #include <openssl/engine.h>
572 #endif
573 #include <openssl/ssl.h>
574 #include <openssl/evp.h>
575 ])
576 fi
577
578
579 AC_ARG_ENABLE(sha2, AC_HELP_STRING([--disable-sha2], [Disable SHA256 and SHA512 RRSIG support]))
580 case "$enable_sha2" in
581         no)
582         ;;
583         yes|*)
584         AC_DEFINE([USE_SHA2], [1], [Define this to enable SHA256 and SHA512 support.])
585         ;;
586 esac
587
588 # check wether gost also works
589 AC_DEFUN([AC_CHECK_GOST_WORKS],
590 [AC_REQUIRE([AC_PROG_CC])
591 AC_MSG_CHECKING([if GOST works])
592 if test c${cross_compiling} = cno; then
593 BAKCFLAGS="$CFLAGS"
594 if test -n "$ssldir"; then
595         CFLAGS="$CFLAGS -Wl,-rpath,$ssldir/lib"
596 fi
597 AC_RUN_IFELSE([AC_LANG_SOURCE([[
598 #include <string.h>
599 #include <openssl/ssl.h>
600 #include <openssl/evp.h>
601 #include <openssl/engine.h>
602 #include <openssl/conf.h>
603 /* routine to load gost from ldns */
604 int load_gost_id(void)
605 {
606         static int gost_id = 0;
607         const EVP_PKEY_ASN1_METHOD* meth;
608         ENGINE* e;
609
610         if(gost_id) return gost_id;
611
612         /* see if configuration loaded gost implementation from other engine*/
613         meth = EVP_PKEY_asn1_find_str(NULL, "gost2001", -1);
614         if(meth) {
615                 EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
616                 return gost_id;
617         }
618
619         /* see if engine can be loaded already */
620         e = ENGINE_by_id("gost");
621         if(!e) {
622                 /* load it ourself, in case statically linked */
623                 ENGINE_load_builtin_engines();
624                 ENGINE_load_dynamic();
625                 e = ENGINE_by_id("gost");
626         }
627         if(!e) {
628                 /* no gost engine in openssl */
629                 return 0;
630         }
631         if(!ENGINE_set_default(e, ENGINE_METHOD_ALL)) {
632                 ENGINE_finish(e);
633                 ENGINE_free(e);
634                 return 0;
635         }
636
637         meth = EVP_PKEY_asn1_find_str(&e, "gost2001", -1);
638         if(!meth) {
639                 /* algo not found */
640                 ENGINE_finish(e);
641                 ENGINE_free(e);
642                 return 0;
643         }
644         EVP_PKEY_asn1_get0_info(&gost_id, NULL, NULL, NULL, NULL, meth);
645         return gost_id;
646 }
647 int main(void) { 
648         EVP_MD_CTX* ctx;
649         const EVP_MD* md;
650         unsigned char digest[64]; /* its a 256-bit digest, so uses 32 bytes */
651         const char* str = "Hello world";
652         const unsigned char check[] = {
653                 0x40 , 0xed , 0xf8 , 0x56 , 0x5a , 0xc5 , 0x36 , 0xe1 ,
654                 0x33 , 0x7c , 0x7e , 0x87 , 0x62 , 0x1c , 0x42 , 0xe0 ,
655                 0x17 , 0x1b , 0x5e , 0xce , 0xa8 , 0x46 , 0x65 , 0x4d ,
656                 0x8d , 0x3e , 0x22 , 0x9b , 0xe1 , 0x30 , 0x19 , 0x9d
657         };
658         OPENSSL_config(NULL);
659         (void)load_gost_id();
660         md = EVP_get_digestbyname("md_gost94");
661         if(!md) return 1;
662         memset(digest, 0, sizeof(digest));
663         ctx = EVP_MD_CTX_create();
664         if(!ctx) return 2;
665         if(!EVP_DigestInit_ex(ctx, md, NULL)) return 3;
666         if(!EVP_DigestUpdate(ctx, str, 10)) return 4;
667         if(!EVP_DigestFinal_ex(ctx, digest, NULL)) return 5;
668         /* uncomment to see the hash calculated.
669                 {int i;
670                 for(i=0; i<32; i++)
671                         printf(" %2.2x", (int)digest[i]);
672                 printf("\n");}
673         */
674         if(memcmp(digest, check, sizeof(check)) != 0)
675                 return 6;
676         return 0;
677 }
678 ]])] , [eval "ac_cv_c_gost_works=yes"], [eval "ac_cv_c_gost_works=no"])
679 CFLAGS="$BAKCFLAGS"
680 else
681 eval "ac_cv_c_gost_works=maybe"
682 fi
683 AC_MSG_RESULT($ac_cv_c_gost_works)
684 ])dnl
685
686 AC_ARG_ENABLE(gost, AC_HELP_STRING([--disable-gost], [Disable GOST support]))
687 use_gost="no"
688 if test $USE_NSS = "no"; then
689 case "$enable_gost" in
690         no)
691         ;;
692         *)
693         AC_CHECK_FUNC(EVP_PKEY_set_type_str, [:],[AC_MSG_ERROR([OpenSSL 1.0.0 is needed for GOST support])])
694         AC_CHECK_FUNC(EC_KEY_new, [], [AC_MSG_ERROR([OpenSSL does not support ECC, needed for GOST support])])
695         AC_CHECK_GOST_WORKS
696         if test "$ac_cv_c_gost_works" != no; then
697                 use_gost="yes"
698                 AC_DEFINE([USE_GOST], [1], [Define this to enable GOST support.])
699         fi
700         ;;
701 esac
702 fi dnl !USE_NSS
703
704 AC_ARG_ENABLE(ecdsa, AC_HELP_STRING([--disable-ecdsa], [Disable ECDSA support]))
705 use_ecdsa="no"
706 case "$enable_ecdsa" in
707     no)
708       ;;
709     *)
710       if test $USE_NSS = "no"; then
711               AC_CHECK_FUNC(ECDSA_sign, [], [AC_MSG_ERROR([OpenSSL does not support ECDSA: please upgrade or rerun with --disable-ecdsa])])
712               AC_CHECK_FUNC(SHA384_Init, [], [AC_MSG_ERROR([OpenSSL does not support SHA384: please upgrade or rerun with --disable-ecdsa])])
713               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
714 #include <openssl/evp.h>
715               ])
716               # see if OPENSSL 1.0.0 or later (has EVP MD and Verify independency)
717               AC_MSG_CHECKING([if openssl supports SHA2 and ECDSA with EVP])
718               if grep OPENSSL_VERSION_NUMBER $ssldir/include/openssl/opensslv.h | grep 0x0 >/dev/null; then
719                 AC_MSG_RESULT([no])
720                 AC_DEFINE_UNQUOTED([USE_ECDSA_EVP_WORKAROUND], [1], [Define this to enable an EVP workaround for older openssl])
721               else
722                 AC_MSG_RESULT([yes])
723               fi
724       fi
725       # we now know we have ECDSA and the required curves.
726       AC_DEFINE_UNQUOTED([USE_ECDSA], [1], [Define this to enable ECDSA support.])
727       use_ecdsa="yes"
728       ;;
729 esac
730
731 # check for libevent
732 AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
733     [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.]),
734     [ ],[ withval="no" ])
735 if test x_$withval = x_yes -o x_$withval != x_no; then
736         AC_MSG_CHECKING(for libevent)
737         if test x_$withval = x_ -o x_$withval = x_yes; then
738             withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
739         fi
740         for dir in $withval; do
741             thedir="$dir"
742             if test -f "$dir/include/event.h"; then
743                 found_libevent="yes"
744                 dnl assume /usr is in default path.
745                 if test "$thedir" != "/usr"; then
746                     CPPFLAGS="$CPPFLAGS -I$thedir/include"
747                 fi
748                 break;
749             fi
750         done
751         if test x_$found_libevent != x_yes; then
752                 if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
753                         # libevent source directory
754                         AC_MSG_RESULT(found in $thedir)
755                         CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
756                         BAK_LDFLAGS_SET="1"
757                         BAK_LDFLAGS="$LDFLAGS"
758                         # remove evdns from linking
759                         mkdir build >/dev/null 2>&1
760                         mkdir build/libevent >/dev/null 2>&1
761                         mkdir build/libevent/.libs >/dev/null 2>&1
762                         ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
763                         ev_files_lo=`ls $thedir/*.lo | grep -v evdns\.lo | grep -v bufferevent_openssl\.lo`
764                         ev_files_libso=`ls $thedir/.libs/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
765                         cp $ev_files_o build/libevent
766                         cp $ev_files_lo build/libevent
767                         cp $ev_files_libso build/libevent/.libs
768                         LATE_LDFLAGS="build/libevent/*.lo -lm"
769                         LDFLAGS="build/libevent/*.o $LDFLAGS -lm"
770                 else
771                         AC_MSG_ERROR([Cannot find the libevent library in $withval
772 You can restart ./configure --with-libevent=no to use a builtin alternative.
773 Please note that this alternative is not as capable as libevent when using
774 large outgoing port ranges.  ])
775                 fi
776         else
777             AC_MSG_RESULT(found in $thedir)
778             dnl assume /usr is in default path, do not add "".
779             if test "$thedir" != "/usr" -a "$thedir" != ""; then
780                 LDFLAGS="$LDFLAGS -L$thedir/lib"
781                 ACX_RUNTIME_PATH_ADD([$thedir/lib])
782             fi
783         fi
784         # check for library used by libevent after 1.3c
785         AC_SEARCH_LIBS([clock_gettime], [rt])
786
787         # is the event.h header libev or libevent?
788         AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
789         AC_CHECK_DECL(EV_VERSION_MAJOR, [
790                 AC_SEARCH_LIBS(event_set, [ev])
791         ],[
792                 AC_SEARCH_LIBS(event_set, [event])
793         ],[AC_INCLUDES_DEFAULT
794 #include <event.h>
795         ])
796         AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
797         AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
798         AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
799         AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
800         AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
801         AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
802         if test -n "$BAK_LDFLAGS_SET"; then
803                 LDFLAGS="$BAK_LDFLAGS"
804         fi
805 else
806         AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
807 fi
808
809 # check for libexpat
810 AC_ARG_WITH(libexpat, AC_HELP_STRING([--with-libexpat=path],
811     [specify explicit path for libexpat.]),
812     [ ],[ withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr" ])
813 AC_MSG_CHECKING(for libexpat)
814 found_libexpat="no"
815 for dir in $withval ; do
816             if test -f "$dir/include/expat.h"; then
817                 found_libexpat="yes"
818                 dnl assume /usr is in default path.
819                 if test "$dir" != "/usr"; then
820                     CPPFLAGS="$CPPFLAGS -I$dir/include"
821                     LDFLAGS="$LDFLAGS -L$dir/lib"
822                 fi
823                 AC_MSG_RESULT(found in $dir)
824                 break;
825             fi
826 done
827 if test x_$found_libexpat != x_yes; then
828         AC_ERROR([Could not find libexpat, expat.h])
829 fi
830 AC_CHECK_HEADERS([expat.h],,, [AC_INCLUDES_DEFAULT])
831
832 # set static linking if requested
833 AC_SUBST(staticexe)
834 staticexe=""
835 AC_ARG_ENABLE(static-exe, AC_HELP_STRING([--enable-static-exe],
836         [ enable to compile executables statically against event, ldns libs, for debug purposes ]), 
837         , )
838 if test x_$enable_static_exe = x_yes; then
839         staticexe="-static"
840         if test "$on_mingw" = yes; then
841                 staticexe="-all-static"
842                 # for static crosscompile, include gdi32 and zlib here.
843                 if test "`uname`" = "Linux"; then
844                         LIBS="$LIBS -lgdi32 -lz"
845                 fi
846         fi
847 fi
848
849 # set lock checking if requested
850 AC_ARG_ENABLE(lock_checks, AC_HELP_STRING([--enable-lock-checks],
851         [ enable to check lock and unlock calls, for debug purposes ]), 
852         , )
853 if test x_$enable_lock_checks = x_yes; then
854         AC_DEFINE(ENABLE_LOCK_CHECKS, 1, [Define if you want to use debug lock checking (slow).])
855         CHECKLOCK_OBJ="checklocks.lo"
856         AC_SUBST(CHECKLOCK_OBJ)
857 fi
858
859 ACX_CHECK_GETADDRINFO_WITH_INCLUDES
860 if test "$USE_WINSOCK" = 1; then
861         AC_DEFINE(UB_ON_WINDOWS, 1, [Use win32 resources and API])
862         AC_CHECK_HEADERS([iphlpapi.h],,, [AC_INCLUDES_DEFAULT
863 #include <windows.h>
864         ])
865         AC_CHECK_TOOL(WINDRES, windres)
866         LIBS="$LIBS -liphlpapi"
867         WINAPPS="unbound-service-install.exe unbound-service-remove.exe anchor-update.exe"
868         AC_SUBST(WINAPPS)
869         WIN_DAEMON_SRC="winrc/win_svc.c winrc/w_inst.c"
870         AC_SUBST(WIN_DAEMON_SRC)
871         WIN_DAEMON_OBJ="win_svc.lo w_inst.lo"
872         AC_SUBST(WIN_DAEMON_OBJ)
873         WIN_DAEMON_OBJ_LINK="rsrc_unbound.o"
874         AC_SUBST(WIN_DAEMON_OBJ_LINK)
875         WIN_HOST_OBJ_LINK="rsrc_unbound_host.o"
876         AC_SUBST(WIN_HOST_OBJ_LINK)
877         WIN_UBANCHOR_OBJ_LINK="rsrc_unbound_anchor.o log.lo locks.lo"
878         AC_SUBST(WIN_UBANCHOR_OBJ_LINK)
879         WIN_CONTROL_OBJ_LINK="rsrc_unbound_control.o"
880         AC_SUBST(WIN_CONTROL_OBJ_LINK)
881         WIN_CHECKCONF_OBJ_LINK="rsrc_unbound_checkconf.o"
882         AC_SUBST(WIN_CHECKCONF_OBJ_LINK)
883 fi
884 if test $ac_cv_func_getaddrinfo = no; then
885         AC_LIBOBJ([fake-rfc2553])
886 fi
887 # check after getaddrinfo for its libraries
888 ACX_FUNC_IOCTLSOCKET
889
890 # see if daemon(3) exists, and if it is deprecated.
891 AC_CHECK_FUNCS([daemon])
892 if test $ac_cv_func_daemon = yes; then
893         ACX_FUNC_DEPRECATED([daemon], [(void)daemon(0, 0);], [
894 #include <stdlib.h>
895 ])
896 fi
897
898 AC_CHECK_MEMBERS([struct in_pktinfo.ipi_spec_dst],,,[
899 AC_INCLUDES_DEFAULT
900 #if HAVE_SYS_PARAM_H
901 #include <sys/param.h>
902 #endif
903
904 #ifdef HAVE_SYS_SOCKET_H
905 #include <sys/socket.h>
906 #endif
907
908 #ifdef HAVE_SYS_UIO_H
909 #include <sys/uio.h>
910 #endif
911
912 #ifdef HAVE_NETINET_IN_H
913 #include <netinet/in.h>
914 #endif
915
916 #ifdef HAVE_ARPA_INET_H
917 #include <arpa/inet.h>
918 #endif
919
920 #ifdef HAVE_WINSOCK2_H
921 #include <winsock2.h>
922 #endif
923
924 #ifdef HAVE_WS2TCPIP_H
925 #include <ws2tcpip.h>
926 #endif
927 ])
928 AC_SEARCH_LIBS([setusercontext], [util])
929 AC_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])
930 AC_CHECK_FUNCS([setresuid],,[AC_CHECK_FUNCS([setreuid])])
931 AC_CHECK_FUNCS([setresgid],,[AC_CHECK_FUNCS([setregid])])
932
933 # check if setreuid en setregid fail, on MacOSX10.4(darwin8).
934 if echo $build_os | grep darwin8 > /dev/null; then
935         AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
936 fi
937 AC_REPLACE_FUNCS(inet_aton)
938 AC_REPLACE_FUNCS(inet_pton)
939 AC_REPLACE_FUNCS(inet_ntop)
940 AC_REPLACE_FUNCS(snprintf)
941 AC_REPLACE_FUNCS(strlcpy)
942 AC_REPLACE_FUNCS(memmove)
943 AC_REPLACE_FUNCS(gmtime_r)
944 LIBOBJ_WITHOUT_CTIME="$LIBOBJS"
945 AC_SUBST(LIBOBJ_WITHOUT_CTIME)
946 AC_REPLACE_FUNCS(ctime_r)
947
948 AC_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]))
949 case "$enable_allsymbols" in
950         yes)
951         COMMON_OBJ_ALL_SYMBOLS=""
952         UBSYMS=""
953         EXTRALINK="-L. -L.libs -lunbound"
954         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])
955         ;;
956         no|*)
957         COMMON_OBJ_ALL_SYMBOLS='$(COMMON_OBJ)'
958         UBSYMS='-export-symbols $(srcdir)/libunbound/ubsyms.def'
959         EXTRALINK=""
960         ;;
961 esac
962 AC_SUBST(COMMON_OBJ_ALL_SYMBOLS)
963 AC_SUBST(EXTRALINK)
964 AC_SUBST(UBSYMS)
965 if test x_$enable_lock_checks = x_yes; then
966         UBSYMS="-export-symbols clubsyms.def"
967         cp ${srcdir}/libunbound/ubsyms.def clubsyms.def
968         echo lock_protect >> clubsyms.def
969         echo lock_unprotect >> clubsyms.def
970         echo lock_get_mem >> clubsyms.def
971         echo checklock_start >> clubsyms.def
972         echo checklock_stop >> clubsyms.def
973         echo checklock_lock >> clubsyms.def
974         echo checklock_unlock >> clubsyms.def
975         echo checklock_init >> clubsyms.def
976         echo checklock_thrcreate >> clubsyms.def
977         echo checklock_thrjoin >> clubsyms.def
978 fi
979
980 AC_MSG_CHECKING([if ${MAKE:-make} supports $< with implicit rule in scope])
981 # on openBSD, the implicit rule make $< work.
982 # on Solaris, it does not work ($? is changed sources, $^ lists dependencies).
983 # gmake works.
984 cat >conftest.make <<EOF
985 all:    conftest.lo
986
987 conftest.lo foo.lo bla.lo:
988         if test -f "\$<"; then touch \$@; fi
989
990 .SUFFIXES: .lo
991 .c.lo:
992         if test -f "\$<"; then touch \$@; fi
993
994 conftest.lo:        conftest.dir/conftest.c
995 EOF
996 mkdir conftest.dir
997 touch conftest.dir/conftest.c
998 rm -f conftest.lo conftest.c
999 ${MAKE:-make} -f conftest.make >/dev/null
1000 rm -f conftest.make conftest.c conftest.dir/conftest.c
1001 rm -rf conftest.dir
1002 if test ! -f conftest.lo; then
1003         AC_MSG_RESULT(no)
1004         SOURCEDETERMINE='echo "$^" | awk "-F " "{print \$$1;}" > .source'
1005         SOURCEFILE='`cat .source`'
1006 else
1007         AC_MSG_RESULT(yes)
1008         SOURCEDETERMINE=':'
1009         SOURCEFILE='$<'
1010 fi
1011 rm -f conftest.lo
1012 AC_SUBST(SOURCEDETERMINE)
1013 AC_SUBST(SOURCEFILE)
1014
1015 # see if we want to build the library or everything
1016 ALLTARGET="alltargets"
1017 AC_ARG_WITH(libunbound-only, AC_HELP_STRING([--with-libunbound-only],
1018         [do not build daemon and tool programs]),
1019         [
1020         if test "$withval" = "yes"; then
1021                 ALLTARGET="lib"
1022         fi
1023 ])
1024 AC_SUBST(ALLTARGET)
1025
1026 # check this after all other compilation checks, since the linking of the lib
1027 # may break checks after this.
1028 AC_ARG_WITH(ldns, AC_HELP_STRING([--with-ldns=PATH], 
1029         [specify prefix of path of ldns library to use]), 
1030         [
1031         if test "$withval" != "yes"; then
1032                 if test "$withval" != "/usr" -a "$withval" != ""; then
1033                         CPPFLAGS="-I$withval/include $CPPFLAGS"
1034                         LDFLAGS="-L$withval/lib $LDFLAGS"
1035                         ACX_RUNTIME_PATH_ADD([$withval/lib])
1036                 fi
1037                 ldnsdir="$withval"
1038                 AC_SUBST(ldnsdir)
1039         fi
1040 ])
1041
1042 # check if ldns is good enough
1043 AC_CHECK_LIB(ldns, ldns_rr_new,,[
1044         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])
1045 ])
1046 AC_CHECK_FUNC(ldns_buffer_copy)
1047 if test $USE_NSS = "no"; then
1048     AC_CHECK_FUNC(ldns_key_buf2rsa_raw)
1049 else
1050     dnl ignore test
1051     ac_cv_func_ldns_key_buf2rsa_raw="yes"
1052 fi
1053 AC_CHECK_FUNC(ldns_get_random)
1054 AC_CHECK_FUNC(ldns_b32_ntop_extended_hex)
1055 if test x$use_gost = xyes -a x$USE_NSS = xno; then
1056     AC_CHECK_FUNC(ldns_key_EVP_load_gost_id)
1057     AC_CHECK_FUNCS([ldns_key_EVP_unload_gost])
1058 else
1059     dnl ignore test
1060     ac_cv_func_ldns_key_EVP_load_gost_id="yes"
1061 fi
1062 if test x$use_ecdsa = xyes; then
1063     AC_CHECK_DECL([LDNS_ECDSAP384SHA384], [], [], [
1064 AC_INCLUDES_DEFAULT
1065 #ifdef HAVE_SYS_SOCKET_H
1066 #  include <sys/socket.h>
1067 #endif
1068 #ifdef HAVE_WS2TCPIP_H
1069 #  include <ws2tcpip.h>
1070 #endif
1071 #include <ldns/ldns.h>
1072     ])
1073 else
1074     ac_cv_have_decl_LDNS_ECDSAP384SHA384="yes"
1075 fi
1076 AC_CHECK_HEADERS([ldns/ldns.h],,[
1077         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])
1078         ], [AC_INCLUDES_DEFAULT
1079 #ifdef HAVE_SYS_SOCKET_H
1080 #include <sys/socket.h>
1081 #endif
1082
1083 #ifdef HAVE_NETINET_IN_H
1084 #include <netinet/in.h>
1085 #endif
1086
1087 #ifdef HAVE_ARPA_INET_H
1088 #include <arpa/inet.h>
1089 #endif
1090
1091 #ifdef HAVE_WINSOCK2_H
1092 #include <winsock2.h>
1093 #endif
1094
1095 #ifdef HAVE_WS2TCPIP_H
1096 #include <ws2tcpip.h>
1097 #endif
1098 ])
1099 if test $ac_cv_func_ldns_buffer_copy = yes \
1100     -a $ac_cv_func_ldns_key_buf2rsa_raw = yes \
1101     -a $ac_cv_func_ldns_get_random = yes \
1102     -a $ac_cv_header_ldns_ldns_h = yes \
1103     -a $ac_cv_func_ldns_b32_ntop_extended_hex = yes \
1104     -a $ac_cv_func_ldns_key_EVP_load_gost_id = yes \
1105     -a $ac_cv_have_decl_LDNS_ECDSAP384SHA384 = yes; then
1106     dnl ldns was found
1107     :
1108 else
1109     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])
1110 fi
1111
1112 ACX_STRIP_EXT_FLAGS
1113 LDFLAGS="$LATE_LDFLAGS $LDFLAGS"
1114
1115 AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [10240], [Define to the maximum message length to pass to syslog.])
1116
1117 AH_BOTTOM(
1118 dnl this must be first AH_CONFIG, to define the flags before any includes.
1119 AHX_CONFIG_EXT_FLAGS
1120
1121 dnl includes
1122 [
1123 #ifndef UNBOUND_DEBUG
1124 #  define NDEBUG
1125 #endif
1126
1127 #include <stdio.h>
1128 #include <string.h>
1129 #include <unistd.h>
1130 #include <assert.h>
1131
1132 #if STDC_HEADERS
1133 #include <stdlib.h>
1134 #include <stddef.h>
1135 #endif
1136
1137 #ifdef HAVE_STDINT_H
1138 #include <stdint.h>
1139 #endif
1140
1141 #include <errno.h>
1142
1143 #if HAVE_SYS_PARAM_H
1144 #include <sys/param.h>
1145 #endif
1146
1147 #ifdef HAVE_SYS_SOCKET_H
1148 #include <sys/socket.h>
1149 #endif
1150
1151 #ifdef HAVE_SYS_UIO_H
1152 #include <sys/uio.h>
1153 #endif
1154
1155 #ifdef HAVE_NETINET_IN_H
1156 #include <netinet/in.h>
1157 #endif
1158
1159 #ifdef HAVE_ARPA_INET_H
1160 #include <arpa/inet.h>
1161 #endif
1162
1163 #ifdef HAVE_WINSOCK2_H
1164 #include <winsock2.h>
1165 #endif
1166
1167 #ifdef HAVE_WS2TCPIP_H
1168 #include <ws2tcpip.h>
1169 #endif
1170 ]
1171
1172 AHX_CONFIG_FORMAT_ATTRIBUTE
1173 AHX_CONFIG_UNUSED_ATTRIBUTE
1174 AHX_CONFIG_FSEEKO
1175 AHX_CONFIG_MAXHOSTNAMELEN
1176 AHX_CONFIG_SNPRINTF(unbound)
1177 AHX_CONFIG_INET_PTON(unbound)
1178 AHX_CONFIG_INET_NTOP(unbound)
1179 AHX_CONFIG_INET_ATON(unbound)
1180 AHX_CONFIG_MEMMOVE(unbound)
1181 AHX_CONFIG_STRLCPY(unbound)
1182 AHX_CONFIG_GMTIME_R(unbound)
1183 AHX_CONFIG_W32_SLEEP
1184 AHX_CONFIG_W32_USLEEP
1185 AHX_CONFIG_W32_RANDOM
1186 AHX_CONFIG_W32_SRANDOM
1187 AHX_CONFIG_W32_FD_SET_T
1188 AHX_CONFIG_IPV6_MIN_MTU
1189 AHX_MEMCMP_BROKEN(unbound)
1190
1191 [
1192 #ifndef HAVE_CTIME_R
1193 #define ctime_r unbound_ctime_r
1194 char *ctime_r(const time_t *timep, char *buf);
1195 #endif
1196
1197 #if !defined(HAVE_STRPTIME) || !defined(STRPTIME_WORKS)
1198 #define strptime unbound_strptime
1199 struct tm;
1200 char *strptime(const char *s, const char *format, struct tm *tm);
1201 #endif
1202
1203 #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))
1204    /* using version of libevent that is not threadsafe. */
1205 #  define LIBEVENT_SIGNAL_PROBLEM 1
1206 #endif
1207
1208 #ifndef CHECKED_INET6
1209 #  define CHECKED_INET6
1210 #  ifdef AF_INET6
1211 #    define INET6
1212 #  else
1213 #    define AF_INET6        28
1214 #  endif
1215 #endif /* CHECKED_INET6 */
1216
1217 #ifndef HAVE_GETADDRINFO
1218 struct sockaddr_storage;
1219 #include "compat/fake-rfc2553.h"
1220 #endif
1221
1222 #ifdef UNBOUND_ALLOC_STATS
1223 #  define malloc(s) unbound_stat_malloc_log(s, __FILE__, __LINE__, __func__)
1224 #  define calloc(n,s) unbound_stat_calloc_log(n, s, __FILE__, __LINE__, __func__)
1225 #  define free(p) unbound_stat_free_log(p, __FILE__, __LINE__, __func__)
1226 #  define realloc(p,s) unbound_stat_realloc_log(p, s, __FILE__, __LINE__, __func__)
1227 void *unbound_stat_malloc(size_t size);
1228 void *unbound_stat_calloc(size_t nmemb, size_t size);
1229 void unbound_stat_free(void *ptr);
1230 void *unbound_stat_realloc(void *ptr, size_t size);
1231 void *unbound_stat_malloc_log(size_t size, const char* file, int line,
1232         const char* func);
1233 void *unbound_stat_calloc_log(size_t nmemb, size_t size, const char* file,
1234         int line, const char* func);
1235 void unbound_stat_free_log(void *ptr, const char* file, int line,
1236         const char* func);
1237 void *unbound_stat_realloc_log(void *ptr, size_t size, const char* file,
1238         int line, const char* func);
1239 #elif defined(UNBOUND_ALLOC_LITE)
1240 #  include "util/alloc.h"
1241 #endif /* UNBOUND_ALLOC_LITE and UNBOUND_ALLOC_STATS */
1242
1243 /** default port for DNS traffic. */
1244 #define UNBOUND_DNS_PORT 53
1245 /** default port for unbound control traffic, registered port with IANA,
1246     ub-dns-control  8953/tcp    unbound dns nameserver control */
1247 #define UNBOUND_CONTROL_PORT 8953
1248 /** the version of unbound-control that this software implements */
1249 #define UNBOUND_CONTROL_VERSION 1
1250
1251 ])
1252
1253 AC_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])
1254 AC_CONFIG_HEADER([config.h])
1255 AC_OUTPUT