xref: /openbsd/usr.sbin/nsd/configure.ac (revision a6445c1d)
1dnl
2dnl Some global settings
3dnl
4
5sinclude(acx_nlnetlabs.m4)
6
7AC_INIT(NSD,4.1.0,nsd-bugs@nlnetlabs.nl)
8AC_CONFIG_HEADER([config.h])
9
10CFLAGS="$CFLAGS"
11AC_AIX
12if test "$ac_cv_header_minix_config_h" = "yes"; then
13	AC_DEFINE(_NETBSD_SOURCE,1, [Enable for compile on Minix])
14fi
15
16dnl
17dnl By default set $sysconfdir to /etc and $localstatedir to /var
18dnl
19case "$prefix" in
20	NONE)
21		case "$sysconfdir" in
22			'${prefix}/etc')
23				sysconfdir=/etc
24			;;
25                esac
26		case "$localstatedir" in
27			'${prefix}/var')
28				localstatedir=/var
29			;;
30		esac
31	;;
32esac
33
34#
35# Determine configuration directory
36#
37configdir=$sysconfdir/nsd
38AC_ARG_WITH([configdir],
39	AC_HELP_STRING([--with-configdir=dir], [NSD configuration directory]),
40	[configdir=$withval])
41AC_DEFINE_UNQUOTED(CONFIGDIR, ["`eval echo $configdir`"], [NSD config dir])
42AC_SUBST(configdir)
43
44#
45# Determine configuration file
46nsd_conf_file=${configdir}/nsd.conf
47AC_ARG_WITH([nsd_conf_file],
48	AC_HELP_STRING([--with-nsd_conf_file=path], [Pathname to the NSD configuration file]),
49	[nsd_conf_file=$withval])
50AC_SUBST(nsd_conf_file)
51# the eval is to evaluate shell expansion twice, once
52# for $nsd_conf_file and once for the ${prefix} within it.
53AC_DEFINE_UNQUOTED(CONFIGFILE, ["`eval echo $nsd_conf_file`"], [Pathname to the NSD configuration file])
54
55#
56# Default logfile
57#
58logfile=${localstatedir}/log/nsd.log
59AC_ARG_WITH([logfile],
60	AC_HELP_STRING([--with-logfile=path], [Pathname to the default log file]),
61	[logfile=$withval])
62AC_SUBST(logfile)
63
64#
65# Database directory
66#
67dbdir=${localstatedir}/db/nsd
68
69#
70# Determine the pidfile location. Check if /var/run exists, if so set pidfile
71# to /var/run/nsd.pid by default
72#
73if test -d ${localstatedir}/run; then
74	pidfile=${localstatedir}/run/nsd.pid
75else
76	pidfile=${dbdir}/nsd.pid
77fi
78AC_ARG_WITH([pidfile],
79	AC_HELP_STRING([--with-pidfile=path], [Pathname to the NSD pidfile]),
80	[pidfile=$withval])
81AC_SUBST(pidfile)
82AC_DEFINE_UNQUOTED(PIDFILE, ["`eval echo $pidfile`"], [Pathname to the NSD pidfile])
83
84#
85# Determine location of nsd.db
86#
87dbfile=${dbdir}/nsd.db
88AC_ARG_WITH([dbfile],
89	AC_HELP_STRING([--with-dbfile=path], [Pathname to the NSD database]),
90	[dbfile=$withval])
91AC_SUBST(dbfile)
92AC_DEFINE_UNQUOTED(DBFILE, ["`eval echo $dbfile`"], [Pathname to the NSD database])
93
94dbdir=`dirname $dbfile`
95AC_SUBST(dbdir)
96
97piddir=`dirname $pidfile`
98AC_SUBST(piddir)
99
100#
101# Determine the default directory for the zone files
102#
103zonesdir=$configdir
104AC_ARG_WITH([zonesdir],
105	AC_HELP_STRING([--with-zonesdir=dir], [NSD default location for zone files]),
106	[zonesdir=$withval])
107AC_SUBST(zonesdir)
108AC_DEFINE_UNQUOTED(ZONESDIR, ["`eval echo $zonesdir`"], [NSD default location for zone files. Empty string or NULL to disable.])
109
110# default xfrd file location.
111xfrdfile=${dbdir}/xfrd.state
112AC_ARG_WITH([xfrdfile], AC_HELP_STRING([--with-xfrdfile=path],
113	[Pathname to the NSD xfrd zone timer state file]), [xfrdfile=$withval])
114AC_DEFINE_UNQUOTED(XFRDFILE, ["`eval echo $xfrdfile`"], [Pathname to the NSD xfrd zone timer state file.])
115AC_SUBST(xfrdfile)
116
117# default zonelist file location.
118zonelistfile=${dbdir}/zone.list
119AC_ARG_WITH([zonelistfile], AC_HELP_STRING([--with-zonelistfile=path],
120	[Pathname to the NSD zone list file]), [zonelistfile=$withval])
121AC_DEFINE_UNQUOTED(ZONELISTFILE, ["`eval echo $zonelistfile`"], [Pathname to the NSD zone list file.])
122AC_SUBST(zonelistfile)
123
124# default xfr dir location.
125xfrdir="/tmp"
126AC_ARG_WITH([xfrdir], AC_HELP_STRING([--with-xfrdir=path],
127	[Pathname to where the NSD transfer dir is created]), [xfrdir=$withval])
128AC_DEFINE_UNQUOTED(XFRDIR, ["`eval echo $xfrdir`"], [Pathname to where the NSD transfer dir is created.])
129AC_SUBST(xfrdir)
130
131# nsd sbin location. tmpinstantiate execprefix with defaults if not yet done.
132if test "x${exec_prefix}" = "xNONE"; then
133	if test "x${prefix}" = "xNONE"; then exec_prefix="$ac_default_prefix"
134	else exec_prefix="${prefix}"; fi
135	nsd_start_path="`eval echo $sbindir`/nsd"
136	exec_prefix="NONE"
137else
138	nsd_start_path="`eval echo $sbindir`/nsd"
139fi
140AC_DEFINE_UNQUOTED(NSD_START_PATH, ["$nsd_start_path"], [Pathname to start nsd from nsd-control])
141
142#
143# Determine default chroot directory
144#
145AC_ARG_WITH([chroot],
146	AC_HELP_STRING([--with-chroot=dir], [NSD default chroot directory]),
147	[
148		chrootdir=$withval
149		AC_DEFINE_UNQUOTED(CHROOTDIR, ["`eval echo $chrootdir`"], [NSD default chroot directory])
150	])
151AC_SUBST(chrootdir)
152
153#
154# Determine the user name to drop privileges to
155#
156user=nsd
157AC_ARG_WITH([user],
158	AC_HELP_STRING([--with-user=username], [User name or ID to answer the queries with]),
159	[user=$withval])
160AC_SUBST(user)
161AC_DEFINE_UNQUOTED(USER, ["$user"], [the user name to drop privileges to])
162
163# Checks for programs.
164AC_PROG_AWK
165AC_PROG_CC
166AC_PROG_LN_S
167AC_PROG_INSTALL
168AC_PROG_LEX
169AC_PROG_YACC
170
171AC_DEFUN([AC_CHECK_FORMAT_ATTRIBUTE],
172[AC_REQUIRE([AC_PROG_CC])
173AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "format" attribute)
174AC_CACHE_VAL(ac_cv_c_format_attribute,
175[ac_cv_c_format_attribute=no
176AC_TRY_COMPILE(
177[#include <stdio.h>
178void f (char *format, ...) __attribute__ ((format (printf, 1, 2)));
179void (*pf) (char *format, ...) __attribute__ ((format (printf, 1, 2)));
180], [
181   f ("%s", "str");
182],
183[ac_cv_c_format_attribute="yes"],
184[ac_cv_c_format_attribute="no"])
185])
186
187AC_MSG_RESULT($ac_cv_c_format_attribute)
188if test $ac_cv_c_format_attribute = yes; then
189  AC_DEFINE(HAVE_ATTR_FORMAT, 1, [Whether the C compiler accepts the "format" attribute])
190fi
191])dnl
192
193AC_DEFUN([AC_CHECK_UNUSED_ATTRIBUTE],
194[AC_REQUIRE([AC_PROG_CC])
195AC_MSG_CHECKING(whether the C compiler (${CC-cc}) accepts the "unused" attribute)
196AC_CACHE_VAL(ac_cv_c_unused_attribute,
197[ac_cv_c_unused_attribute=no
198AC_TRY_COMPILE(
199[#include <stdio.h>
200void f (char *u __attribute__((unused)));
201], [
202   f ("x");
203],
204[ac_cv_c_unused_attribute="yes"],
205[ac_cv_c_unused_attribute="no"])
206])
207
208AC_MSG_RESULT($ac_cv_c_unused_attribute)
209if test $ac_cv_c_unused_attribute = yes; then
210  AC_DEFINE(HAVE_ATTR_UNUSED, 1, [Whether the C compiler accepts the "unused" attribute])
211fi
212])dnl
213
214AC_DEFUN([CHECK_COMPILER_FLAG],
215[
216AC_REQUIRE([AC_PROG_CC])
217AC_MSG_CHECKING(whether $CC supports -$1)
218cache=`echo $1 | sed 'y%.=/+-%___p_%'`
219AC_CACHE_VAL(cv_prog_cc_flag_$cache,
220[
221echo 'void f(){}' >conftest.c
222if test -z "`$CC -$1 -c conftest.c 2>&1`"; then
223eval "cv_prog_cc_flag_$cache=yes"
224else
225eval "cv_prog_cc_flag_$cache=no"
226fi
227rm -f conftest*
228])
229if eval "test \"`echo '$cv_prog_cc_flag_'$cache`\" = yes"; then
230AC_MSG_RESULT(yes)
231:
232$2
233else
234AC_MSG_RESULT(no)
235:
236$3
237fi
238])
239
240AC_DEFUN([AC_CHECK_CTIME_R],
241[AC_REQUIRE([AC_PROG_CC])
242AC_MSG_CHECKING(whether ctime_r works with two arguments)
243AC_CACHE_VAL(ac_cv_c_ctime_c,
244[ac_cv_c_ctime_c=no
245AC_TRY_COMPILE(
246[#include <time.h>
247void testing (void) { time_t clock; char current_time[40]; ctime_r(&clock, current_time); }],
248[
249        testing();
250],
251[ac_cv_c_ctime_c="yes"],
252[ac_cv_c_ctime_c="no"])
253])
254
255AC_MSG_RESULT($ac_cv_c_ctime_c)
256if test $ac_cv_c_ctime_c = no; then
257        CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
258fi
259])dnl
260
261# Checks for typedefs, structures, and compiler characteristics.
262# allow user to override the -g -O2 flags.
263if test "x$CFLAGS" = "x" ; then
264	ACX_CHECK_COMPILER_FLAG(g, [CFLAGS="$CFLAGS -g"])
265	# we do not use O3 because it causes miscompilations.
266	ACX_CHECK_COMPILER_FLAG(O2, [CFLAGS="$CFLAGS -O2"])
267	ACX_CHECK_FLTO
268fi
269AC_C_CONST
270AC_C_INLINE
271AC_TYPE_UID_T
272AC_TYPE_PID_T
273AC_TYPE_SIZE_T
274AC_TYPE_OFF_T
275
276AC_CHECK_FORMAT_ATTRIBUTE
277AC_CHECK_UNUSED_ATTRIBUTE
278ACX_CHECK_MEMCMP_SIGNED
279AC_CHECK_CTIME_R
280
281# Checks for libraries.
282
283# Check for SSL, original taken from
284# http://www.gnu.org/software/ac-archive/htmldoc/check_ssl.html and
285# modified for NSD.
286AC_DEFUN([CHECK_SSL], [
287    AC_ARG_WITH(ssl, AC_HELP_STRING([--with-ssl=pathname],
288                [enable SSL (will check /usr/local/ssl
289                /usr/lib/ssl /usr/ssl /usr/pkg /usr/sfw /usr/local /usr)]),[
290        ],[
291            withval="yes"
292        ])
293    if test x_$withval != x_no; then
294        AC_MSG_CHECKING(for SSL)
295        if test x_$withval = x_ -o x_$withval = x_yes; then
296            withval="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/sfw /usr/local /usr"
297        fi
298        for dir in $withval; do
299            ssldir="$dir"
300            if test -f "$dir/include/openssl/ssl.h"; then
301                found_ssl="yes";
302                AC_DEFINE_UNQUOTED([HAVE_SSL], [], [Define if you have the SSL libraries installed.])
303                if test x_$ssldir != x_/usr; then
304                    CPPFLAGS="$CPPFLAGS -I$ssldir/include";
305                fi
306                break;
307            fi
308        done
309        if test x_$found_ssl != x_yes; then
310            AC_MSG_ERROR(Cannot find the SSL libraries in $withval)
311        else
312            AC_MSG_RESULT(found in $ssldir)
313            HAVE_SSL=yes
314            if test x_$ssldir != x_/usr; then
315                LDFLAGS="$LDFLAGS -L$ssldir/lib";
316            fi
317	    if test x_$ssldir = x_/usr/sfw; then
318		LDFLAGS="$LDFLAGS -R$ssldir/lib";
319	    fi
320            AC_CHECK_LIB(crypto, HMAC_CTX_init,, [
321                    AC_MSG_ERROR([OpenSSL found in $ssldir, but version 0.9.7 or higher is required])
322                ])
323		AC_CHECK_FUNCS([EVP_sha1 EVP_sha256])
324        fi
325        AC_SUBST(HAVE_SSL)
326    fi
327])dnl
328
329# check for libevent
330AC_ARG_WITH(libevent, AC_HELP_STRING([--with-libevent=pathname],
331    [use libevent (will check /usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr  or you can specify an explicit path), useful when the zone count is high.]),
332    [ ],[ withval="yes" ])
333if test x_$withval = x_yes -o x_$withval != x_no; then
334        AC_MSG_CHECKING(for libevent)
335        if test x_$withval = x_ -o x_$withval = x_yes; then
336            withval="/usr/local /opt/local /usr/lib /usr/pkg /usr/sfw /usr"
337        fi
338        for dir in $withval; do
339            thedir="$dir"
340            if test -f "$dir/include/event.h" -o -f "$dir/include/event2/event.h"; then
341                found_libevent="yes"
342		dnl assume /usr is in default path.
343		if test "$thedir" != "/usr"; then
344                    CPPFLAGS="$CPPFLAGS -I$thedir/include"
345		fi
346                break;
347            fi
348        done
349        if test x_$found_libevent != x_yes; then
350		if test -f "$dir/event.h" -a \( -f "$dir/libevent.la" -o -f "$dir/libev.la" \) ; then
351			# libevent source directory
352            		AC_MSG_RESULT(found in $thedir)
353                	CPPFLAGS="$CPPFLAGS -I$thedir -I$thedir/include"
354			# remove evdns from linking
355			ev_files_o=`ls $thedir/*.o | grep -v evdns\.o | grep -v bufferevent_openssl\.o`
356			cp $ev_files_o .
357			LDFLAGS="$ev_files_o $LDFLAGS -lm"
358		else
359            		AC_MSG_ERROR([Cannot find the libevent library.
360You can restart ./configure --with-libevent=no to use a builtin alternative.])
361		fi
362        else
363            AC_MSG_RESULT(found in $thedir)
364	    dnl if event2 exists and no event lib in dir itself, use subdir
365	    if test ! -f $thedir/lib/libevent.a -a ! -f $thedir/lib/libevent.so -a -d "$thedir/lib/event2"; then
366		LDFLAGS="$LDFLAGS -L$thedir/lib/event2"
367		ACX_RUNTIME_PATH_ADD([$thedir/lib/event2])
368	    else
369		    dnl assume /usr is in default path, do not add "".
370		    if test "$thedir" != "/usr" -a "$thedir" != ""; then
371			LDFLAGS="$LDFLAGS -L$thedir/lib"
372			ACX_RUNTIME_PATH_ADD([$thedir/lib])
373		    fi
374	    fi
375        fi
376	# check for library used by libevent after 1.3c
377	AC_SEARCH_LIBS([clock_gettime], [rt])
378
379	# is the event.h header libev or libevent?
380	AC_CHECK_HEADERS([event.h],,, [AC_INCLUDES_DEFAULT])
381	AC_CHECK_DECL(EV_VERSION_MAJOR, [
382		AC_SEARCH_LIBS(event_set, [ev])
383	],[
384		AC_SEARCH_LIBS(event_set, [event])
385	],[AC_INCLUDES_DEFAULT
386#include <event.h>
387	])
388	AC_CHECK_FUNCS([event_base_free]) # only in libevent 1.2 and later
389	AC_CHECK_FUNCS([event_base_once]) # only in libevent 1.4.1 and later
390	AC_CHECK_FUNCS([event_base_new]) # only in libevent 1.4.1 and later
391	AC_CHECK_FUNCS([event_base_get_method]) # only in libevent 1.4.3 and later
392	AC_CHECK_FUNCS([ev_loop]) # only in libev. (tested on 3.51)
393	AC_CHECK_FUNCS([ev_default_loop]) # only in libev. (tested on 4.00)
394else
395	AC_DEFINE(USE_MINI_EVENT, 1, [Define if you want to use internal select based events])
396fi
397
398# Checks for header files.
399AC_HEADER_STDC
400AC_HEADER_SYS_WAIT
401AC_CHECK_HEADERS([time.h arpa/inet.h signal.h string.h strings.h fcntl.h limits.h netinet/in.h stddef.h sys/param.h sys/socket.h syslog.h unistd.h sys/select.h stdarg.h stdint.h netdb.h sys/bitypes.h tcpd.h glob.h grp.h endian.h])
402
403AC_DEFUN([CHECK_VALIST_DEF],
404[
405AC_REQUIRE([AC_PROG_CC])
406AC_MSG_CHECKING(for double definition of struct va_list)
407AC_CACHE_VAL(ac_cv_c_va_list_def,
408[
409cat >conftest.c <<EOF
410#include <stdio.h>
411#include <stdarg.h>
412int foo(void);
413EOF
414if test -z "`$CC -Werror -D_XOPEN_SOURCE=600 -c conftest.c 2>&1`"; then
415eval "ac_cv_c_va_list_def=no"
416else
417eval "ac_cv_c_va_list_def=yes"
418fi
419rm -f conftest*
420])
421if test $ac_cv_c_va_list_def = yes; then
422AC_MSG_RESULT(yes)
423:
424AC_DEFINE_UNQUOTED([HAVE_VA_LIST_DOUBLE_DEF], [], [Define this if you have double va_list definitions.])
425else
426AC_MSG_RESULT(no)
427:
428
429fi
430])
431
432CHECK_VALIST_DEF
433
434AC_DEFUN([AC_CHECK_STRPTIME],
435[AC_REQUIRE([AC_PROG_CC])
436AC_MSG_CHECKING(whether strptime needs defines)
437AC_CACHE_VAL(ac_cv_c_strptime_needs_defs,
438[
439cat >conftest.c <<EOF
440#include <time.h>
441int testing (void) { struct tm t; const char *timestr="201201"; return strptime(timestr, "%Y%m", &t) != 0; }
442EOF
443if test -z "`$CC -Wall -Werror -c conftest.c 2>&1`"; then
444eval "ac_cv_c_strptime_needs_defs=no"
445else
446eval "ac_cv_c_strptime_needs_defs=yes"
447fi
448rm -f conftest*
449])
450
451AC_MSG_RESULT($ac_cv_c_strptime_needs_defs)
452if test $ac_cv_c_strptime_needs_defs = yes; then
453AC_DEFINE_UNQUOTED([STRPTIME_NEEDS_DEFINES], 1, [strptime is available from time.h with some defines.])
454fi
455])dnl
456
457AC_CHECK_STRPTIME
458
459# check wether strptime also works
460AC_DEFUN([AC_CHECK_STRPTIME_WORKS],
461[AC_REQUIRE([AC_PROG_CC])
462AC_MSG_CHECKING(whether strptime works)
463if test c${cross_compiling} = cno; then
464AC_RUN_IFELSE([AC_LANG_SOURCE([[
465#define _XOPEN_SOURCE 600
466#include <time.h>
467int main(void) { struct tm tm; char *res;
468res = strptime("20070207111842", "%Y%m%d%H%M%S", &tm);
469if (!res) return 1; return 0; }
470]])] , [eval "ac_cv_c_strptime_works=yes"], [eval "ac_cv_c_strptime_works=no"])
471else
472eval "ac_cv_c_strptime_works=maybe"
473fi
474AC_MSG_RESULT($ac_cv_c_strptime_works)
475if test $ac_cv_c_strptime_works = no; then
476AC_LIBOBJ(strptime)
477else
478AC_DEFINE_UNQUOTED([STRPTIME_WORKS], 1, [use default strptime.])
479fi
480])dnl
481
482AC_SEARCH_LIBS(inet_pton, [nsl])
483AC_SEARCH_LIBS(socket, [socket])
484
485AC_CHECK_STRPTIME_WORKS
486ACX_CHECK_NONBLOCKING_BROKEN
487ACX_MKDIR_ONE_ARG
488
489# set -I. and -Isrcdir
490if test -n "$CPPFLAGS"; then
491	CPPFLAGS="$CPPFLAGS -I."
492else
493	CPPFLAGS="-I."
494fi
495if test "$srcdir" != "."; then
496	CPPFLAGS="$CPPFLAGS -I$srcdir"
497	if test -f $srcdir/config.h; then
498		AC_ERROR([$srcdir/config.h is in the way, please remove it])
499	fi
500fi
501
502dnl LIBGTOP_CHECK_TYPE
503dnl Stolen from Gnome's anjuta
504dnl Improved version of AC_CHECK_TYPE which takes into account
505dnl that we need to #include some other header files on some
506dnl systems to get some types.
507
508dnl AC_LIBGTOP_CHECK_TYPE(TYPE, DEFAULT)
509AC_DEFUN([AC_LIBGTOP_CHECK_TYPE],
510[AC_REQUIRE([AC_HEADER_STDC])dnl
511AC_MSG_CHECKING(for $1)
512AC_CACHE_VAL(ac_cv_type_$1,
513[AC_EGREP_CPP(dnl
514changequote(<<,>>)dnl
515<<(^|[^a-zA-Z_0-9])$1[^a-zA-Z_0-9]>>dnl
516changequote([,]), [
517#include <sys/types.h>
518#if STDC_HEADERS
519#include <stdlib.h>
520#include <stddef.h>
521#endif
522
523#ifdef HAVE_STDINT_H
524#include <stdint.h>
525#endif
526
527#ifdef HAVE_SYS_SOCKET_H
528#include <sys/socket.h>
529#endif
530
531#ifdef HAVE_ARPA_INET_H
532#include <arpa/inet.h>
533#endif
534
535#ifdef HAVE_SIGNAL_H
536#include <signal.h>
537#endif
538
539/* For Tru64 */
540#ifdef HAVE_SYS_BITYPES_H
541#include <sys/bitypes.h>
542#endif
543], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
544AC_MSG_RESULT($ac_cv_type_$1)
545if test $ac_cv_type_$1 = no; then
546  AC_DEFINE($1, $2, Define "$1" to "$2" if "$1" is missing)
547fi
548])
549
550AC_LIBGTOP_CHECK_TYPE(int8_t, char)
551AC_LIBGTOP_CHECK_TYPE(int16_t, short)
552AC_LIBGTOP_CHECK_TYPE(int32_t, int)
553AC_LIBGTOP_CHECK_TYPE(int64_t, long long)
554AC_LIBGTOP_CHECK_TYPE(uint8_t, unsigned char)
555AC_LIBGTOP_CHECK_TYPE(uint16_t, unsigned short)
556AC_LIBGTOP_CHECK_TYPE(uint32_t, unsigned int)
557AC_LIBGTOP_CHECK_TYPE(uint64_t, unsigned long long)
558AC_LIBGTOP_CHECK_TYPE(socklen_t, int)
559AC_LIBGTOP_CHECK_TYPE(sig_atomic_t, int)
560AC_LIBGTOP_CHECK_TYPE(ssize_t, int)
561AC_LIBGTOP_CHECK_TYPE(suseconds_t, time_t)
562
563AC_CHECK_TYPE(in_addr_t, [], [AC_DEFINE([in_addr_t], [uint32_t], [in_addr_t])], [
564#if HAVE_SYS_TYPES_H
565# include <sys/types.h>
566#endif
567#if HAVE_NETINET_IN_H
568# include <netinet/in.h>
569#endif])
570ACX_CHECK_SS_FAMILY
571
572# Checks for library functions.
573AC_FUNC_CHOWN
574AC_FUNC_FORK
575AC_FUNC_MALLOC
576AC_TYPE_SIGNAL
577AC_FUNC_FSEEKO
578AC_SYS_LARGEFILE
579AC_CHECK_SIZEOF(void*)
580AC_CHECK_SIZEOF(off_t)
581AC_CHECK_FUNCS([arc4random arc4random_uniform])
582AC_CHECK_FUNCS([tzset alarm chroot dup2 endpwent gethostname memset memcpy pwrite socket strcasecmp strchr strdup strerror strncasecmp strtol writev getaddrinfo getnameinfo freeaddrinfo gai_strerror sigaction sigprocmask strptime strftime localtime_r setusercontext glob initgroups setresuid setreuid setresgid setregid getpwnam mmap])
583
584AC_ARG_ENABLE(recvmmsg, AC_HELP_STRING([--enable-recvmmsg], [Enable recvmmsg and sendmmsg compilation, faster but some kernel versions may have implementation problems]))
585case "$enable_recvmmsg" in
586        yes)
587		AC_CHECK_FUNC([recvmmsg], [
588AC_RUN_IFELSE([AC_LANG_SOURCE([[
589#include <sys/socket.h>
590#include <errno.h>
591int main(void)
592{
593	int s = socket(AF_INET, SOCK_DGRAM, 0);
594	int r = recvmmsg(s, 0, 0, 0, 0) == -1 && errno == ENOSYS;
595	close(s);
596	return r;
597}
598]])], [
599AC_DEFINE([HAVE_RECVMMSG], [1], [Define if recvmmsg is implemented])], [
600], [
601AC_DEFINE([HAVE_RECVMMSG], [1], [Define if recvmmsg exists])]
602)])
603		AC_CHECK_FUNC([sendmmsg], [
604AC_RUN_IFELSE([AC_LANG_SOURCE([[
605#include <sys/socket.h>
606#include <errno.h>
607int main(void)
608{
609	int s = socket(AF_INET, SOCK_DGRAM, 0);
610	int r = sendmmsg(s, 0, 0, 0) == -1 && errno == ENOSYS;
611	close(s);
612	return r;
613}
614]])], [
615AC_DEFINE([HAVE_SENDMMSG], [1], [Define if sendmmsg is implemented])], [
616], [
617AC_DEFINE([HAVE_SENDMMSG], [1], [Define if sendmmsg exists])]
618)])
619
620		;;
621        no|*)
622                ;;
623esac
624
625# check if setreuid en setregid fail, on MacOSX10.4(darwin8).
626if echo $build_os | grep darwin8 > /dev/null; then
627	AC_DEFINE(DARWIN_BROKEN_SETREUID, 1, [Define this if on macOSX10.4-darwin8 and setreuid and setregid do not work])
628fi
629
630#
631# Checking for missing functions we can replace
632#
633AC_REPLACE_FUNCS(basename)
634AC_REPLACE_FUNCS(inet_aton)
635AC_REPLACE_FUNCS(inet_pton)
636AC_REPLACE_FUNCS(inet_ntop)
637AC_REPLACE_FUNCS(snprintf)
638AC_REPLACE_FUNCS(strlcat)
639AC_REPLACE_FUNCS(strlcpy)
640AC_REPLACE_FUNCS(strptime)
641AC_REPLACE_FUNCS(b64_pton)
642AC_REPLACE_FUNCS(b64_ntop)
643AC_REPLACE_FUNCS(pselect)
644AC_REPLACE_FUNCS(memmove)
645
646AC_MSG_CHECKING(for pselect prototype in sys/select.h)
647AC_EGREP_HEADER([[^a-zA-Z_]*pselect[^a-zA-Z_]], sys/select.h, AC_DEFINE(HAVE_PSELECT_PROTO, 1,
648	[if sys/select.h provides pselect prototype]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
649
650AC_MSG_CHECKING(for ctime_r prototype in time.h)
651AC_EGREP_HEADER([[^a-zA-Z_]*ctime_r[^a-zA-Z_]], time.h, AC_DEFINE(HAVE_CTIME_R_PROTO, 1,
652	[if time.h provides ctime_r prototype]) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
653
654AC_CHECK_TYPE([struct timespec], AC_DEFINE(HAVE_STRUCT_TIMESPEC, 1, [If time.h has a struct timespec (for pselect).]), [], [
655AC_INCLUDES_DEFAULT
656#ifdef HAVE_SIGNAL_H
657#include <signal.h>
658#endif
659#ifdef HAVE_TIME_H
660#include <time.h>
661#endif
662])
663
664dnl
665dnl Some random defines's
666dnl
667AC_DEFINE_UNQUOTED([IDENTITY], ["unidentified server"], [Define to the default nsd identity.])
668AC_DEFINE_UNQUOTED([VERSION], [PACKAGE_STRING], [Define to the NSD version to answer version.server query.])
669AC_DEFINE_UNQUOTED([TCP_BACKLOG], [256], [Define to the backlog to be used with listen.])
670AC_DEFINE_UNQUOTED([TCP_PORT], ["53"], [Define to the default tcp port.])
671AC_DEFINE_UNQUOTED([TCP_MAX_MESSAGE_LEN], [65535], [Define to the default maximum message length.])
672AC_DEFINE_UNQUOTED([UDP_PORT], ["53"], [Define to the default udp port.])
673AC_DEFINE_UNQUOTED([UDP_MAX_MESSAGE_LEN], [512], [Define to the default maximum udp message length.])
674AC_DEFINE_UNQUOTED([EDNS_MAX_MESSAGE_LEN], [4096], [Define to the default maximum message length with EDNS.])
675AC_DEFINE_UNQUOTED([MAXSYSLOGMSGLEN], [512], [Define to the maximum message length to pass to syslog.])
676AC_DEFINE_UNQUOTED([NSD_CONTROL_PORT], [8952], [Define to the default nsd-control port.])
677AC_DEFINE_UNQUOTED([NSD_CONTROL_VERSION], [1], [Define to nsd-control proto version.])
678
679dnl
680dnl Determine the syslog facility to use
681dnl
682facility=LOG_DAEMON
683AC_ARG_WITH([facility],
684        AC_HELP_STRING([--with-facility=name], [Syslog default facility (LOG_DAEMON)]),
685        [facility=$withval])
686AC_DEFINE_UNQUOTED([FACILITY], $facility, [Define to the default facility for syslog.])
687
688dnl
689dnl Determine the maximum number of ip-addresses that are allowed
690dnl
691max_ips=16
692AC_ARG_WITH([max_ips],
693	AC_HELP_STRING([--with-max-ips=number], [Limit on the number of ip-addresses that may be specified]),
694	[max_ips=$withval])
695AC_DEFINE_UNQUOTED([MAX_INTERFACES], $max_ips, [Define to the maximum ip-addresses to serve.])
696
697dnl
698dnl Determine the default tcp timeout
699dnl
700tcp_timeout=120
701AC_ARG_WITH([tcp_timeout],
702	AC_HELP_STRING([--with-tcp-timeout=number], [Limit the default tcp timeout]),
703	[tcp_timeout=$withval])
704AC_DEFINE_UNQUOTED([TCP_TIMEOUT], $tcp_timeout, [Define to the default tcp timeout.])
705
706dnl
707dnl Features
708dnl
709AC_ARG_ENABLE(root-server, AC_HELP_STRING([--enable-root-server], [Configure NSD as a root server]))
710case "$enable_root_server" in
711        yes)
712		AC_DEFINE_UNQUOTED([ROOT_SERVER], [], [Define this to configure as a root server.])
713		;;
714        no|*)
715                ;;
716esac
717
718AC_ARG_ENABLE(ipv6, AC_HELP_STRING([--disable-ipv6], [Disables IPv6 support]))
719case "$enable_ipv6" in
720        no)
721                ;;
722        yes|*)
723		AC_DEFINE_UNQUOTED([INET6], [], [Define this to enable IPv6 support.])
724		;;
725esac
726
727AC_ARG_ENABLE(bind8-stats, AC_HELP_STRING([--enable-bind8-stats], [Enables BIND8 like NSTATS & XSTATS]))
728
729case "$enable_bind8_stats" in
730	yes|'')
731		AC_DEFINE_UNQUOTED([BIND8_STATS], [], [Define this to enable BIND8 like NSTATS & XSTATS.])
732		;;
733	no|*)
734		;;
735esac
736
737AC_ARG_ENABLE(checking, AC_HELP_STRING([--enable-checking], [Enable internal runtime checks]))
738case "$enable_checking" in
739        yes)
740		CHECK_COMPILER_FLAG(W, [ CFLAGS="$CFLAGS -W" ])
741		CHECK_COMPILER_FLAG(Wall, [ CFLAGS="$CFLAGS -Wall" ])
742		CHECK_COMPILER_FLAG(Wextra, [ CFLAGS="$CFLAGS -Wextra" ])
743		CHECK_COMPILER_FLAG(Wdeclaration-after-statement, [ CFLAGS="$CFLAGS -Wdeclaration-after-statement" ])
744		;;
745        no|*)
746                AC_DEFINE([NDEBUG], [], [Undefine this to enable internal runtime checks.])
747                ;;
748esac
749
750AC_ARG_ENABLE(ratelimit, AC_HELP_STRING([--enable-ratelimit], [Enable rate limiting]))
751case "$enable_ratelimit" in
752	yes)
753		AC_DEFINE_UNQUOTED([RATELIMIT], [], [Define this to enable rate limiting.])
754		dnl causes awk to not match the exclusion start marker.
755		ratelimit="xx"
756		;;
757	no|*)
758		ratelimit=""
759		;;
760esac
761AC_SUBST(ratelimit)
762
763# we need SSL for TSIG (and maybe also for NSEC3).
764CHECK_SSL
765if test x$HAVE_SSL = x"yes"; then
766	ACX_LIB_SSL
767	SSL_LIBS="-lssl"
768	AC_SUBST(SSL_LIBS)
769	AC_CHECK_HEADERS([openssl/ssl.h],,, [AC_INCLUDES_DEFAULT])
770	AC_CHECK_HEADERS([openssl/err.h],,, [AC_INCLUDES_DEFAULT])
771	AC_CHECK_HEADERS([openssl/rand.h],,, [AC_INCLUDES_DEFAULT])
772else
773	AC_MSG_WARN([No SSL, therefore remote-control is disabled])
774fi
775
776AC_ARG_ENABLE(nsec3, AC_HELP_STRING([--disable-nsec3], [Disable NSEC3 support]))
777case "$enable_nsec3" in
778        no)
779		;;
780        yes)
781		AC_DEFINE_UNQUOTED([NSEC3], [], [Define this to enable NSEC3 support.])
782		;;
783		*)
784		if test x$HAVE_SSL = x"yes"; then
785			AC_DEFINE_UNQUOTED([NSEC3], [], [Define this to enable NSEC3 support.])
786		else
787			AC_MSG_WARN([No SSL, therefore NSEC3 is disabled])
788		fi
789                ;;
790esac
791
792AC_ARG_ENABLE(minimal-responses, AC_HELP_STRING([--disable-minimal-responses], [Disable response minimization. More truncation.]))
793case "$enable_minimal_responses" in
794        no)
795		;;
796        yes|*)
797		AC_DEFINE_UNQUOTED([MINIMAL_RESPONSES], [], [Define this to enable response minimalization to reduce truncation.])
798                ;;
799esac
800
801AC_ARG_ENABLE(mmap, AC_HELP_STRING([--enable-mmap], [Use mmap instead of malloc. Experimental.]))
802case "$enable_mmap" in
803        yes)
804		AC_CHECK_HEADERS([sys/mman.h])
805		AC_LIBGTOP_CHECK_TYPE(uintptr_t, void*)
806		AC_CHECK_FUNCS([mmap munmap])
807		AC_DEFINE_UNQUOTED([USE_MMAP_ALLOC], [], [Define this to enable mmap instead of malloc. Experimental.])
808		;;
809        no|*)
810                ;;
811esac
812
813AH_BOTTOM([
814/* define before includes as it specifies what standard to use. */
815#if (defined(HAVE_PSELECT) && !defined (HAVE_PSELECT_PROTO)) \
816	|| !defined (HAVE_CTIME_R_PROTO) \
817	|| defined (STRPTIME_NEEDS_DEFINES)
818#  ifndef _XOPEN_SOURCE
819#    define _XOPEN_SOURCE 600
820#  endif
821#  ifndef _POSIX_C_SOURCE
822#    define _POSIX_C_SOURCE 200112
823#  endif
824#  ifndef _BSD_SOURCE
825#    define _BSD_SOURCE 1
826#  endif
827#  ifndef __EXTENSIONS__
828#    define __EXTENSIONS__ 1
829#  endif
830#  ifndef _STDC_C99
831#    define _STDC_C99 1
832#  endif
833#  ifndef _ALL_SOURCE
834#    define _ALL_SOURCE 1
835#  endif
836#endif
837])
838
839AH_BOTTOM([
840#ifdef HAVE_VA_LIST_DOUBLE_DEF
841/* workaround double va_list definition on some platforms */
842#  ifndef _VA_LIST_DEFINED
843#    define _VA_LIST_DEFINED
844#  endif
845#endif
846])
847
848AH_BOTTOM([
849#include <sys/types.h>
850#if STDC_HEADERS
851#include <stdlib.h>
852#include <stddef.h>
853#endif
854
855#ifdef HAVE_TIME_H
856#include <time.h>
857#endif
858
859#ifdef HAVE_STDINT_H
860#include <stdint.h>
861#endif
862
863#ifdef HAVE_SYS_SOCKET_H
864#include <sys/socket.h>
865#endif
866
867#ifdef HAVE_NETINET_IN_H
868#include <netinet/in.h>
869#endif
870
871#ifdef HAVE_ARPA_INET_H
872#include <arpa/inet.h>
873#endif
874
875/* For Tru64 */
876#ifdef HAVE_SYS_BITYPES_H
877#include <sys/bitypes.h>
878#endif
879])
880
881AH_BOTTOM([
882#ifdef HAVE_ATTR_FORMAT
883#define ATTR_FORMAT(archetype, string_index, first_to_check) \
884    __attribute__ ((format (archetype, string_index, first_to_check)))
885#else /* !HAVE_ATTR_FORMAT */
886#define ATTR_FORMAT(archetype, string_index, first_to_check) /* empty */
887#endif /* !HAVE_ATTR_FORMAT */
888#if defined(__cplusplus)
889#define ATTR_UNUSED(x)
890#elif defined(HAVE_ATTR_UNUSED)
891#define ATTR_UNUSED(x)  x __attribute__((unused))
892#else /* !HAVE_ATTR_UNUSED */
893#define ATTR_UNUSED(x)  x
894#endif /* !HAVE_ATTR_UNUSED */
895])
896
897AH_BOTTOM([
898#ifndef IPV6_MIN_MTU
899#define IPV6_MIN_MTU 1280
900#endif /* IPV6_MIN_MTU */
901
902#ifndef AF_INET6
903#define AF_INET6	28
904#endif /* AF_INET6 */
905])
906
907if test $ac_cv_func_getaddrinfo = no; then
908AC_LIBOBJ([fake-rfc2553])
909fi
910
911AH_BOTTOM([
912/* maximum nesting of included files */
913#define MAXINCLUDES 10
914])
915
916AH_BOTTOM([
917#ifndef HAVE_B64_NTOP
918int b64_ntop(uint8_t const *src, size_t srclength,
919	     char *target, size_t targsize);
920#endif /* !HAVE_B64_NTOP */
921#ifndef HAVE_B64_PTON
922int b64_pton(char const *src, uint8_t *target, size_t targsize);
923#endif /* !HAVE_B64_PTON */
924#ifndef HAVE_FSEEKO
925#define fseeko fseek
926#define ftello ftell
927#endif /* HAVE_FSEEKO */
928#ifndef HAVE_SNPRINTF
929#include <stdarg.h>
930int snprintf (char *str, size_t count, const char *fmt, ...);
931int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
932#endif /* HAVE_SNPRINTF */
933#ifndef HAVE_INET_PTON
934int inet_pton(int af, const char* src, void* dst);
935#endif /* HAVE_INET_PTON */
936#ifndef HAVE_INET_NTOP
937const char *inet_ntop(int af, const void *src, char *dst, size_t size);
938#endif
939#ifndef HAVE_INET_ATON
940int inet_aton(const char *cp, struct in_addr *addr);
941#endif
942#ifndef HAVE_MEMMOVE
943void *memmove(void *dest, const void *src, size_t n);
944#endif
945#ifndef HAVE_STRLCAT
946size_t strlcat(char *dst, const char *src, size_t siz);
947#endif
948#ifndef HAVE_STRLCPY
949size_t strlcpy(char *dst, const char *src, size_t siz);
950#endif
951#ifndef HAVE_GETADDRINFO
952#include "compat/fake-rfc2553.h"
953#endif
954#ifndef HAVE_STRPTIME
955#define HAVE_STRPTIME 1
956char *strptime(const char *s, const char *format, struct tm *tm);
957#endif
958#ifndef STRPTIME_WORKS
959#define STRPTIME_WORKS 1
960char *nsd_strptime(const char *s, const char *format, struct tm *tm);
961#define strptime(a,b,c) nsd_strptime((a),(b),(c))
962#endif
963])
964AH_BOTTOM(
965AHX_MEMCMP_BROKEN(nsd)
966AHX_CONFIG_MAXHOSTNAMELEN
967)
968AH_BOTTOM([
969
970/* provide timespec def if not available */
971#ifndef CONFIG_DEFINES
972#define CONFIG_DEFINES
973#ifndef HAVE_STRUCT_TIMESPEC
974#ifndef __timespec_defined
975#define __timespec_defined 1
976	struct timespec {
977		long    tv_sec;         /* seconds */
978		long    tv_nsec;        /* nanoseconds */
979	};
980#endif /* !__timespec_defined */
981#endif /* !HAVE_STRUCT_TIMESPEC */
982#endif /* !CONFIG_DEFINES */
983])
984
985# big fat warning
986if test "$enable_checking" = "yes"; then
987        echo "************************************************"
988        echo "* You have activated \"--enable-checking\"       *"
989        echo "*                                              *"
990        echo "* This will instruct NSD to be stricter        *"
991        echo "* when validating its input. This could lead   *"
992        echo "* to a reduced service level.                  *"
993        echo "*                                              *"
994        echo "************************************************"
995fi
996
997AC_CONFIG_FILES([Makefile])
998AC_OUTPUT
999