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