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