1# $Id: configure.ac,v 1.519 2013/03/22 01:49:15 dtucker Exp $
2#
3# Copyright (c) 1999-2004 Damien Miller
4#
5# Permission to use, copy, modify, and distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17AC_PREREQ(2.69)
18
19dnl AC_INIT([OpenSMTPD-extras], m4_esyscmd(date +%Y%m%d%H%M%S | sed -e 's/^\(.*\)$/5.7-\1/' | tr -d '\n'), [bugs@opensmtpd.org], [opensmtpd-extras], [https://github.com/OpenSMTPD/OpenSMTPD-extras])
20AC_INIT([OpenSMTPD-extras], [5.7.2], [bugs@opensmtpd.org], [opensmtpd-extras], [https://github.com/OpenSMTPD/OpenSMTPD-extras])
21
22AC_LANG([C])
23AC_CONFIG_MACRO_DIR([m4])
24
25AC_CONFIG_HEADER([config.h])
26AC_PROG_CC
27AC_CANONICAL_HOST
28AC_C_BIGENDIAN
29
30# Checks for programs.
31AC_PROG_CPP
32AC_PROG_INSTALL
33AC_PROG_LIBTOOL
34AC_PATH_PROG([AR], [ar])
35AC_PATH_PROG([CAT], [cat])
36AC_PATH_PROG([SED], [sed])
37AC_PATH_PROG([TEST_MINUS_S_SH], [bash])
38AC_PATH_PROG([TEST_MINUS_S_SH], [ksh])
39AC_PATH_PROG([TEST_MINUS_S_SH], [sh])
40AC_PATH_PROG([SH], [sh])
41AC_PATH_PROG([GROFF], [groff])
42AC_PATH_PROG([NROFF], [nroff])
43AC_PATH_PROG([MANDOC], [mandoc])
44
45AM_INIT_AUTOMAKE([subdir-objects no-dependencies])
46
47LT_INIT
48
49#here we should test for variables set by libtool detection
50if test "x$with_pic" != "xno" ; then
51	CFLAGS="$CFLAGS ${pic_flag}"
52fi
53
54
55#from here everything comes from portable openssh configure.ac script
56
57#l50
58dnl select manpage formatter
59if test "x$MANDOC" != "x" ; then
60	MANFMT="$MANDOC"
61elif test "x$NROFF" != "x" ; then
62	MANFMT="$NROFF -mandoc"
63elif test "x$GROFF" != "x" ; then
64	MANFMT="$GROFF -mandoc -Tascii"
65else
66	AC_MSG_WARN([no manpage formatted found])
67	MANFMT="false"
68fi
69AC_SUBST([MANFMT])
70#l61
71
72#l78
73if test -z "$AR" ; then
74	AC_MSG_ERROR([*** 'ar' missing, please install or fix your \$PATH ***])
75fi
76#l80
77
78#l101
79if test -z "$LD" ; then
80	LD=$CC
81fi
82AC_SUBST([LD])
83
84AC_C_INLINE
85
86AC_CHECK_DECL([LLONG_MAX], [have_llong_max=1], , [#include <limits.h>])
87#l108
88
89#l150 (without _FORTIFY_SOURCE=2)
90if test "$GCC" = "yes" || test "$GCC" = "egcs"; then
91	OSSH_CHECK_CFLAG_COMPILE([-Qunused-arguments])
92	OSSH_CHECK_CFLAG_COMPILE([-Wunknown-warning-option])
93	OSSH_CHECK_CFLAG_COMPILE([-Wall])
94	OSSH_CHECK_CFLAG_COMPILE([-Wpointer-arith])
95	OSSH_CHECK_CFLAG_COMPILE([-Wuninitialized])
96	OSSH_CHECK_CFLAG_COMPILE([-Wsign-compare])
97	OSSH_CHECK_CFLAG_COMPILE([-Wformat-security])
98	OSSH_CHECK_CFLAG_COMPILE([-Wsizeof-pointer-memaccess])
99	OSSH_CHECK_CFLAG_COMPILE([-Wpointer-sign], [-Wno-pointer-sign])
100	OSSH_CHECK_CFLAG_COMPILE([-Wunused-result], [-Wno-unused-result])
101	OSSH_CHECK_CFLAG_COMPILE([-fno-strict-aliasing])
102#	OSSH_CHECK_CFLAG_COMPILE([-D_FORTIFY_SOURCE=2])
103	AC_MSG_CHECKING([gcc version])
104	GCC_VER=`$CC -v 2>&1 | $AWK '/gcc version /{print $3}'`
105	AC_MSG_RESULT([$GCC_VER])
106
107	AC_MSG_CHECKING([if $CC accepts -fno-builtin-memset])
108	saved_CFLAGS="$CFLAGS"
109	CFLAGS="$CFLAGS -fno-builtin-memset"
110	AC_LINK_IFELSE([AC_LANG_PROGRAM([[ #include <string.h> ]],
111			[[ char b[10]; memset(b, 0, sizeof(b)); ]])],
112		[ AC_MSG_RESULT([yes]) ],
113		[ AC_MSG_RESULT([no])
114		  CFLAGS="$saved_CFLAGS" ]
115	)
116
117	# -fstack-protector-all doesn't always work for some GCC versions
118	# and/or platforms, so we test if we can.  If it's not supported
119	# on a given platform gcc will emit a warning so we use -Werror.
120	if test "x$use_stack_protector" = "x1"; then
121	    for t in -fstack-protector-strong -fstack-protector-all \
122		    -fstack-protector; do
123		AC_MSG_CHECKING([if $CC supports $t])
124		saved_CFLAGS="$CFLAGS"
125		saved_LDFLAGS="$LDFLAGS"
126		CFLAGS="$CFLAGS $t -Werror"
127		LDFLAGS="$LDFLAGS $t -Werror"
128		AC_LINK_IFELSE(
129			[AC_LANG_PROGRAM([[ #include <stdio.h> ]],
130			[[
131	char x[256];
132	snprintf(x, sizeof(x), "XXX");
133			 ]])],
134		    [ AC_MSG_RESULT([yes])
135		      CFLAGS="$saved_CFLAGS $t"
136		      LDFLAGS="$saved_LDFLAGS $t"
137		      AC_MSG_CHECKING([if $t works])
138		      AC_RUN_IFELSE(
139			[AC_LANG_PROGRAM([[ #include <stdio.h> ]],
140			[[
141	char x[256];
142	snprintf(x, sizeof(x), "XXX");
143			]])],
144			[ AC_MSG_RESULT([yes])
145			  break ],
146			[ AC_MSG_RESULT([no]) ],
147			[ AC_MSG_WARN([cross compiling: cannot test])
148			  break ]
149		      )
150		    ],
151		    [ AC_MSG_RESULT([no]) ]
152		)
153		CFLAGS="$saved_CFLAGS"
154		LDFLAGS="$saved_LDFLAGS"
155	    done
156	fi
157
158	if test -z "$have_llong_max"; then
159		# retry LLONG_MAX with -std=gnu99, needed on some Linuxes
160		unset ac_cv_have_decl_LLONG_MAX
161		saved_CFLAGS="$CFLAGS"
162		CFLAGS="$CFLAGS -std=gnu99"
163		AC_CHECK_DECL([LLONG_MAX],
164		    [have_llong_max=1],
165		    [CFLAGS="$saved_CFLAGS"],
166		    [#include <limits.h>]
167		)
168	fi
169fi
170
171AC_MSG_CHECKING([if compiler allows __attribute__ on return types])
172AC_COMPILE_IFELSE(
173    [AC_LANG_PROGRAM([[
174#include <stdlib.h>
175__attribute__((__unused__)) static void foo(void){return;}]],
176    [[ exit(0); ]])],
177    [ AC_MSG_RESULT([yes]) ],
178    [ AC_MSG_RESULT([no])
179      AC_DEFINE(NO_ATTRIBUTE_ON_RETURN_TYPE, 1,
180	 [compiler does not accept __attribute__ on return types]) ]
181)
182
183AC_ARG_WITH([rpath],
184	[  --without-rpath         Disable auto-added -R linker paths],
185	[
186		if test "x$withval" = "xno" ; then
187			need_dash_r=""
188		fi
189		if test "x$withval" = "xyes" ; then
190			need_dash_r=1
191		fi
192	]
193)
194
195# Allow user to specify flags
196AC_ARG_WITH([cflags],
197	[  --with-cflags           Specify additional flags to pass to compiler],
198	[
199		if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
200		    test "x${withval}" != "xyes"; then
201			CFLAGS="$CFLAGS $withval"
202		fi
203	]
204)
205AC_ARG_WITH([cppflags],
206	[  --with-cppflags         Specify additional flags to pass to preprocessor] ,
207	[
208		if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
209		    test "x${withval}" != "xyes"; then
210			CPPFLAGS="$CPPFLAGS $withval"
211		fi
212	]
213)
214AC_ARG_WITH([ldflags],
215	[  --with-ldflags          Specify additional flags to pass to linker],
216	[
217		if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
218		    test "x${withval}" != "xyes"; then
219			LDFLAGS="$LDFLAGS $withval"
220		fi
221	]
222)
223AC_ARG_WITH([libs],
224	[  --with-libs             Specify additional libraries to link with],
225	[
226		if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
227		    test "x${withval}" != "xyes"; then
228			LIBS="$LIBS $withval"
229		fi
230	]
231)
232AC_ARG_WITH([Werror],
233	[  --with-Werror           Build main code with -Werror],
234	[
235		if test -n "$withval"  &&  test "x$withval" != "xno"; then
236			werror_flags="-Werror"
237			if test "x${withval}" != "xyes"; then
238				werror_flags="$withval"
239			fi
240		fi
241	]
242)
243#l325
244
245AC_CHECK_HEADERS([ \
246	arpa/inet.h \
247	ctype.h \
248	dirent.h \
249	fcntl.h \
250	grp.h \
251	inttypes.h \
252	limits.h \
253	mach/mach_time.h \
254	ndir.h \
255	netdb.h \
256	netinet/in.h \
257	pam/pam_appl.h \
258	paths.h \
259	security/pam_appl.h \
260	stdint.h \
261	stdlib.h \
262	string.h \
263	strings.h \
264	sys/dir.h \
265	sys/ndir.h \
266	sys/param.h \
267	sys/pstat.h \
268	sys/socket.h \
269	sys/time.h \
270	sys/un.h \
271	syslog.h \
272	time.h \
273	ucred.h \
274	unistd.h
275])
276
277#l432 (customized)
278# Check for some target-specific stuff
279	case "$host" in
280*-*-darwin*)
281	use_pie=auto
282	AC_MSG_CHECKING([if we have working getaddrinfo])
283	AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include <mach-o/dyld.h>
284main() { if (NSVersionOfRunTimeLibrary("System") >= (60 << 16))
285		exit(0);
286	else
287		exit(1);
288}
289			]])],
290	[AC_MSG_RESULT([working])],
291	[AC_MSG_RESULT([buggy])
292	],
293	[AC_MSG_RESULT([assume it is working])])
294	;;
295*-*-dragonfly*)
296	SMTPDLIBS="$SMTPDLIBS -lcrypt"
297	;;
298*-*-linux* | *-gnu* | *-k*bsd*-gnu* )
299	use_pie=auto
300	CFLAGS="$CFLAGS -D_BSD_SOURCE"
301	;;
302*-*-netbsd*)
303	if test "x$withval" != "xno" ; then
304		need_dash_r=1
305	fi
306	;;
307*-*-openbsd*)
308	use_pie=auto
309	asr_in_libc=1
310	;;
311esac
312AM_CONDITIONAL([NO_LIBASR], [test x$asr_in_libc = x1])
313
314AC_MSG_CHECKING([compiler and flags for sanity])
315AC_RUN_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h> ]], [[ exit(0); ]])],
316	[	AC_MSG_RESULT([yes]) ],
317	[
318		AC_MSG_RESULT([no])
319		AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***])
320	],
321	[	AC_MSG_WARN([cross compiling: not checking compiler sanity]) ]
322)
323
324dnl Checks for header files.
325# Checks for libraries.
326AC_CHECK_FUNC([setsockopt], , [AC_CHECK_LIB([socket], [setsockopt])])
327
328#l1525
329AC_ARG_WITH([pie],
330    [  --with-pie             Build Position Independent Executables if possible], [
331	if test "x$withval" = "xno"; then
332		use_pie=no
333	fi
334	if test "x$withval" = "xyes"; then
335		use_pie=yes
336	fi
337    ]
338)
339if test "x$use_pie" = "x"; then
340	use_pie=no
341fi
342if test "x$use_pie" = "xauto"; then
343	# Automatic PIE requires gcc >= 4.x
344	AC_MSG_CHECKING([for gcc >= 4.x])
345	AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
346#if !defined(__GNUC__) || __GNUC__ < 4
347#error gcc is too old
348#endif
349]])],
350	[ AC_MSG_RESULT([yes]) ],
351	[ AC_MSG_RESULT([no])
352	  use_pie=no ]
353)
354fi
355if test "x$use_pie" != "xno"; then
356	SAVED_CFLAGS="$CFLAGS"
357	SAVED_LDFLAGS="$LDFLAGS"
358	OSSH_CHECK_CFLAG_COMPILE([-fPIE])
359	OSSH_CHECK_LDFLAG_LINK([-pie])
360	# We use both -fPIE and -pie or neither.
361	AC_MSG_CHECKING([whether both -fPIE and -pie are supported])
362	if echo "x $CFLAGS"  | grep ' -fPIE' >/dev/null 2>&1 && \
363	   echo "x $LDFLAGS" | grep ' -pie'  >/dev/null 2>&1 ; then
364		AC_MSG_RESULT([yes])
365	else
366		AC_MSG_RESULT([no])
367		CFLAGS="$SAVED_CFLAGS"
368		LDFLAGS="$SAVED_LDFLAGS"
369	fi
370fi
371#l1570
372
373# Checks for library functions.
374AC_FUNC_FORK
375AC_FUNC_FSEEKO
376AC_FUNC_MALLOC
377AC_FUNC_REALLOC
378
379AC_CHECK_FUNCS([ \
380	arc4random \
381	arc4random_uniform \
382	asprintf \
383	closefrom \
384	dirfd \
385	freeaddrinfo \
386	getaddrinfo \
387	getline \
388	gethostname \
389	getnameinfo \
390	getopt \
391	memmove \
392	memchr \
393	memset \
394	regcomp \
395	socketpair \
396	strdup \
397	strerror \
398	strncasecmp \
399	strpbrk \
400	strrchr \
401	strtol \
402	strtoumax \
403	strtoull \
404	strlcat \
405	strlcpy \
406	strtonum \
407	sysconf \
408	time \
409	tzset \
410	vasprintf \
411	vsnprintf
412])
413
414#l1723
415AC_CHECK_DECL([strsep],
416	[AC_CHECK_FUNCS([strsep])],
417	[],
418	[
419#ifdef HAVE_STRING_H
420# include <string.h>
421#endif
422	])
423#l1730
424
425#l1747
426AC_CHECK_DECLS([O_NONBLOCK], , ,
427	[
428#include <sys/types.h>
429#ifdef HAVE_SYS_STAT_H
430# include <sys/stat.h>
431#endif
432#ifdef HAVE_FCNTL_H
433# include <fcntl.h>
434#endif
435	])
436
437AC_CHECK_DECLS([writev], , , [
438#include <sys/types.h>
439#include <sys/uio.h>
440#include <unistd.h>
441	])
442
443#l1873
444# Check for broken snprintf
445if test "x$ac_cv_func_snprintf" = "xyes" ; then
446	AC_MSG_CHECKING([whether snprintf correctly terminates long strings])
447	AC_RUN_IFELSE(
448		[AC_LANG_PROGRAM([[ #include <stdio.h> ]],
449		[[
450	char b[5];
451	snprintf(b,5,"123456789");
452	exit(b[4]!='\0');
453		]])],
454		[AC_MSG_RESULT([yes])],
455		[
456			AC_MSG_RESULT([no])
457			AC_DEFINE([BROKEN_SNPRINTF], [1],
458				[Define if your snprintf is busted])
459			AC_MSG_WARN([****** Your snprintf() function is broken, complain to your vendor])
460		],
461		[ AC_MSG_WARN([cross compiling: Assuming working snprintf()]) ]
462	)
463fi
464
465# If we don't have a working asprintf, then we strongly depend on vsnprintf
466# returning the right thing on overflow: the number of characters it tried to
467# create (as per SUSv3)
468if test "x$ac_cv_func_asprintf" != "xyes" && \
469   test "x$ac_cv_func_vsnprintf" = "xyes" ; then
470	AC_MSG_CHECKING([whether vsnprintf returns correct values on overflow])
471	AC_RUN_IFELSE(
472		[AC_LANG_PROGRAM([[
473#include <sys/types.h>
474#include <stdio.h>
475#include <stdarg.h>
476
477int x_snprintf(char *str,size_t count,const char *fmt,...)
478{
479	size_t ret; va_list ap;
480	va_start(ap, fmt); ret = vsnprintf(str, count, fmt, ap); va_end(ap);
481	return ret;
482}
483		]], [[
484	char x[1];
485	exit(x_snprintf(x, 1, "%s %d", "hello", 12345) == 11 ? 0 : 1);
486		]])],
487		[AC_MSG_RESULT([yes])],
488		[
489			AC_MSG_RESULT([no])
490			AC_DEFINE([BROKEN_SNPRINTF], [1],
491				[Define if your snprintf is busted])
492			AC_MSG_WARN([****** Your vsnprintf() function is broken, complain to your vendor])
493		],
494		[ AC_MSG_WARN([cross compiling: Assuming working vsnprintf()]) ]
495	)
496fi
497
498# On systems where [v]snprintf is broken, but is declared in stdio,
499# check that the fmt argument is const char * or just char *.
500# This is only useful for when BROKEN_SNPRINTF
501AC_MSG_CHECKING([whether snprintf can declare const char *fmt])
502AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
503#include <stdio.h>
504int snprintf(char *a, size_t b, const char *c, ...) { return 0; }
505		]], [[
506	snprintf(0, 0, 0);
507		]])],
508   [AC_MSG_RESULT([yes])
509    AC_DEFINE([SNPRINTF_CONST], [const],
510              [Define as const if snprintf() can declare const char *fmt])],
511   [AC_MSG_RESULT([no])
512    AC_DEFINE([SNPRINTF_CONST], [/* not const */])])
513
514dnl see whether mkstemp() requires XXXXXX
515AC_MSG_CHECKING([for (overly) strict mkstemp])
516AC_RUN_IFELSE(
517	[AC_LANG_PROGRAM([[
518#include <stdlib.h>
519	]], [[
520	char template[]="conftest.mkstemp-test";
521	if (mkstemp(template) == -1)
522		exit(1);
523	unlink(template);
524	exit(0);
525	]])],
526	[
527		AC_MSG_RESULT([no])
528	],
529	[
530		AC_MSG_RESULT([yes])
531		AC_DEFINE([HAVE_STRICT_MKSTEMP], [1], [Silly mkstemp()])
532	],
533	[
534		AC_MSG_RESULT([yes])
535		AC_DEFINE([HAVE_STRICT_MKSTEMP])
536	]
537)
538#l1982
539
540#l2174 (customized, bu adding -lssl to LIBS)
541# Search for OpenSSL
542saved_CPPFLAGS="$CPPFLAGS"
543saved_LDFLAGS="$LDFLAGS"
544AC_ARG_WITH([libssl],
545	[  --with-libssl=PATH     Specify path to libssl installation ],
546	[
547		if test "x$withval" != "xno" ; then
548			case "$withval" in
549				# Relative paths
550				./*|../*)	withval="`pwd`/$withval"
551			esac
552			if test -d "$withval/lib"; then
553				if test -n "${need_dash_r}"; then
554					LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
555				else
556					LDFLAGS="-L${withval}/lib ${LDFLAGS}"
557				fi
558			elif test -d "$withval/lib64"; then
559				if test -n "${need_dash_r}"; then
560					LDFLAGS="-L${withval}/lib64 -R${withval}/lib64 ${LDFLAGS}"
561				else
562					LDFLAGS="-L${withval}/lib64 ${LDFLAGS}"
563				fi
564			else
565				if test -n "${need_dash_r}"; then
566					LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
567				else
568					LDFLAGS="-L${withval} ${LDFLAGS}"
569				fi
570			fi
571			if test -d "$withval/include"; then
572				CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
573			else
574				CPPFLAGS="-I${withval} ${CPPFLAGS}"
575			fi
576		fi
577	]
578)
579## XXX chl -lssl manually added
580LIBS="-lcrypto -lssl $LIBS"
581AC_TRY_LINK_FUNC([RAND_add], [AC_DEFINE([HAVE_OPENSSL], [1],
582	[Define if your ssl headers are included
583	with #include <openssl/header.h>])],
584	[
585		dnl Check default openssl install dir
586		if test -n "${need_dash_r}"; then
587			LDFLAGS="-L/usr/local/ssl/lib -R/usr/local/ssl/lib ${saved_LDFLAGS}"
588		else
589			LDFLAGS="-L/usr/local/ssl/lib ${saved_LDFLAGS}"
590		fi
591		CPPFLAGS="-I/usr/local/ssl/include ${saved_CPPFLAGS}"
592		AC_CHECK_HEADER([openssl/opensslv.h], ,
593		    [AC_MSG_ERROR([*** OpenSSL headers missing - please install first or check config.log ***])])
594		AC_TRY_LINK_FUNC([RAND_add], [AC_DEFINE([HAVE_OPENSSL])],
595			[
596				AC_MSG_ERROR([*** Can't find recent OpenSSL libcrypto (see config.log for details) ***])
597			]
598		)
599	]
600)
601
602# XXX make --without-openssl work
603AC_DEFINE_UNQUOTED([WITH_OPENSSL], [1], [use libcrypto for cryptography])
604
605AC_MSG_CHECKING([if programs using OpenSSL functions will link])
606AC_LINK_IFELSE(
607	[AC_LANG_PROGRAM([[ #include <openssl/evp.h> ]],
608	[[ SSLeay_add_all_algorithms(); ]])],
609	[
610		AC_MSG_RESULT([yes])
611	],
612	[
613		AC_MSG_RESULT([no])
614		saved_LIBS="$LIBS"
615		LIBS="$LIBS -ldl"
616		AC_MSG_CHECKING([if programs using OpenSSL need -ldl])
617		AC_LINK_IFELSE(
618			[AC_LANG_PROGRAM([[ #include <openssl/evp.h> ]],
619			[[ SSLeay_add_all_algorithms(); ]])],
620			[
621				AC_MSG_RESULT([yes])
622			],
623			[
624				AC_MSG_RESULT([no])
625				LIBS="$saved_LIBS"
626			]
627		)
628	]
629)
630
631
632SMTPD_USER=_smtpd
633AC_ARG_WITH([user-smtpd],
634	[  --with-user-smtpd=user Specify non-privileged user for privilege separation (default=_smtpd)],
635	[
636		if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
637		    test "x${withval}" != "xyes"; then
638			SMTPD_USER=$withval
639		fi
640	]
641)
642AC_DEFINE_UNQUOTED([SMTPD_USER], ["$SMTPD_USER"],
643	[non-privileged user for privilege separation])
644AC_SUBST([SMTPD_USER])
645
646# Checks for typedefs, structures, and compiler characteristics.
647AC_TYPE_MODE_T
648AC_TYPE_OFF_T
649AC_TYPE_PID_T
650AC_TYPE_SIZE_T
651AC_TYPE_SSIZE_T
652AC_TYPE_UID_T
653AC_TYPE_UINT8_T
654AC_TYPE_UINT16_T
655AC_TYPE_UINT32_T
656AC_TYPE_UINT64_T
657
658AC_CHECK_TYPES([long long, unsigned long long])
659
660AC_CHECK_SIZEOF([short int], [2])
661AC_CHECK_SIZEOF([int], [4])
662AC_CHECK_SIZEOF([long int], [4])
663AC_CHECK_SIZEOF([long long int], [8])
664
665# Sanity check long long for some platforms (AIX)
666if test "x$ac_cv_sizeof_long_long_int" = "x4" ; then
667	ac_cv_sizeof_long_long_int=0
668fi
669
670# compute LLONG_MIN and LLONG_MAX if we don't know them.
671if test -z "$have_llong_max"; then
672	AC_MSG_CHECKING([for max value of long long])
673	AC_RUN_IFELSE(
674		[AC_LANG_PROGRAM([[
675#include <stdio.h>
676/* Why is this so damn hard? */
677#ifdef __GNUC__
678# undef __GNUC__
679#endif
680#define __USE_ISOC99
681#include <limits.h>
682#define DATA "conftest.llminmax"
683#define my_abs(a) ((a) < 0 ? ((a) * -1) : (a))
684
685/*
686 * printf in libc on some platforms (eg old Tru64) does not understand %lld so
687 * we do this the hard way.
688 */
689static int
690fprint_ll(FILE *f, long long n)
691{
692	unsigned int i;
693	int l[sizeof(long long) * 8];
694
695	if (n < 0)
696		if (fprintf(f, "-") < 0)
697			return -1;
698	for (i = 0; n != 0; i++) {
699		l[i] = my_abs(n % 10);
700		n /= 10;
701	}
702	do {
703		if (fprintf(f, "%d", l[--i]) < 0)
704			return -1;
705	} while (i != 0);
706	if (fprintf(f, " ") < 0)
707		return -1;
708	return 0;
709}
710		]], [[
711	FILE *f;
712	long long i, llmin, llmax = 0;
713
714	if((f = fopen(DATA,"w")) == NULL)
715		exit(1);
716
717#if defined(LLONG_MIN) && defined(LLONG_MAX)
718	fprintf(stderr, "Using system header for LLONG_MIN and LLONG_MAX\n");
719	llmin = LLONG_MIN;
720	llmax = LLONG_MAX;
721#else
722	fprintf(stderr, "Calculating  LLONG_MIN and LLONG_MAX\n");
723	/* This will work on one's complement and two's complement */
724	for (i = 1; i > llmax; i <<= 1, i++)
725		llmax = i;
726	llmin = llmax + 1LL;	/* wrap */
727#endif
728
729	/* Sanity check */
730	if (llmin + 1 < llmin || llmin - 1 < llmin || llmax + 1 > llmax
731	    || llmax - 1 > llmax || llmin == llmax || llmin == 0
732	    || llmax == 0 || llmax < LONG_MAX || llmin > LONG_MIN) {
733		fprintf(f, "unknown unknown\n");
734		exit(2);
735	}
736
737	if (fprint_ll(f, llmin) < 0)
738		exit(3);
739	if (fprint_ll(f, llmax) < 0)
740		exit(4);
741	if (fclose(f) < 0)
742		exit(5);
743	exit(0);
744		]])],
745		[
746			llong_min=`$AWK '{print $1}' conftest.llminmax`
747			llong_max=`$AWK '{print $2}' conftest.llminmax`
748
749			AC_MSG_RESULT([$llong_max])
750			AC_DEFINE_UNQUOTED([LLONG_MAX], [${llong_max}LL],
751			    [max value of long long calculated by configure])
752			AC_MSG_CHECKING([for min value of long long])
753			AC_MSG_RESULT([$llong_min])
754			AC_DEFINE_UNQUOTED([LLONG_MIN], [${llong_min}LL],
755			    [min value of long long calculated by configure])
756		],
757		[
758			AC_MSG_RESULT([not found])
759		],
760		[
761			AC_MSG_WARN([cross compiling: not checking])
762		]
763	)
764fi
765
766
767# More checks for data types
768TYPE_SOCKLEN_T
769
770
771AC_CACHE_CHECK([for struct sockaddr_storage], ac_cv_have_struct_sockaddr_storage, [
772	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
773#include <sys/types.h>
774#include <sys/socket.h>
775		]], [[ struct sockaddr_storage s; ]])],
776	[ ac_cv_have_struct_sockaddr_storage="yes" ],
777	[ ac_cv_have_struct_sockaddr_storage="no"
778	])
779])
780if test "x$ac_cv_have_struct_sockaddr_storage" = "xyes" ; then
781	AC_DEFINE([HAVE_STRUCT_SOCKADDR_STORAGE], [1],
782		[define if you have struct sockaddr_storage data type])
783fi
784
785AC_CACHE_CHECK([for struct sockaddr_in6], ac_cv_have_struct_sockaddr_in6, [
786	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
787#include <sys/types.h>
788#include <netinet/in.h>
789		]], [[ struct sockaddr_in6 s; s.sin6_family = 0; ]])],
790	[ ac_cv_have_struct_sockaddr_in6="yes" ],
791	[ ac_cv_have_struct_sockaddr_in6="no"
792	])
793])
794if test "x$ac_cv_have_struct_sockaddr_in6" = "xyes" ; then
795	AC_DEFINE([HAVE_STRUCT_SOCKADDR_IN6], [1],
796		[define if you have struct sockaddr_in6 data type])
797fi
798
799AC_CACHE_CHECK([for struct in6_addr], ac_cv_have_struct_in6_addr, [
800	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
801#include <sys/types.h>
802#include <netinet/in.h>
803		]], [[ struct in6_addr s; s.s6_addr[0] = 0; ]])],
804	[ ac_cv_have_struct_in6_addr="yes" ],
805	[ ac_cv_have_struct_in6_addr="no"
806	])
807])
808if test "x$ac_cv_have_struct_in6_addr" = "xyes" ; then
809	AC_DEFINE([HAVE_STRUCT_IN6_ADDR], [1],
810		[define if you have struct in6_addr data type])
811
812dnl Now check for sin6_scope_id
813	AC_CHECK_MEMBERS([struct sockaddr_in6.sin6_scope_id], , ,
814		[
815#ifdef HAVE_SYS_TYPES_H
816#include <sys/types.h>
817#endif
818#include <netinet/in.h>
819		])
820fi
821
822AC_CACHE_CHECK([for struct addrinfo], ac_cv_have_struct_addrinfo, [
823	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
824#include <sys/types.h>
825#include <sys/socket.h>
826#include <netdb.h>
827		]], [[ struct addrinfo s; s.ai_flags = AI_PASSIVE; ]])],
828	[ ac_cv_have_struct_addrinfo="yes" ],
829	[ ac_cv_have_struct_addrinfo="no"
830	])
831])
832if test "x$ac_cv_have_struct_addrinfo" = "xyes" ; then
833	AC_DEFINE([HAVE_STRUCT_ADDRINFO], [1],
834		[define if you have struct addrinfo data type])
835fi
836
837AC_CACHE_CHECK([for struct timeval], ac_cv_have_struct_timeval, [
838	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ #include <sys/time.h> ]],
839	[[ struct timeval tv; tv.tv_sec = 1;]])],
840	[ ac_cv_have_struct_timeval="yes" ],
841	[ ac_cv_have_struct_timeval="no"
842	])
843])
844if test "x$ac_cv_have_struct_timeval" = "xyes" ; then
845	AC_DEFINE([HAVE_STRUCT_TIMEVAL], [1], [define if you have struct timeval])
846	have_struct_timeval=1
847fi
848
849#l3561
850AC_CHECK_MEMBERS([struct passwd.pw_gecos], [], [], [[
851#include <sys/types.h>
852#include <pwd.h>
853]])
854
855AC_CACHE_CHECK([for ss_family field in struct sockaddr_storage],
856		ac_cv_have_ss_family_in_struct_ss, [
857	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
858#include <sys/types.h>
859#include <sys/socket.h>
860		]], [[ struct sockaddr_storage s; s.ss_family = 1; ]])],
861	[ ac_cv_have_ss_family_in_struct_ss="yes" ],
862	[ ac_cv_have_ss_family_in_struct_ss="no" ])
863])
864if test "x$ac_cv_have_ss_family_in_struct_ss" = "xyes" ; then
865	AC_DEFINE([HAVE_SS_FAMILY_IN_SS], [1], [Fields in struct sockaddr_storage])
866fi
867
868AC_CACHE_CHECK([for __ss_family field in struct sockaddr_storage],
869		ac_cv_have___ss_family_in_struct_ss, [
870	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
871#include <sys/types.h>
872#include <sys/socket.h>
873		]], [[ struct sockaddr_storage s; s.__ss_family = 1; ]])],
874	[ ac_cv_have___ss_family_in_struct_ss="yes" ],
875	[ ac_cv_have___ss_family_in_struct_ss="no"
876	])
877])
878if test "x$ac_cv_have___ss_family_in_struct_ss" = "xyes" ; then
879	AC_DEFINE([HAVE___SS_FAMILY_IN_SS], [1],
880		[Fields in struct sockaddr_storage])
881fi
882
883dnl make sure we're using the real structure members and not defines
884AC_CACHE_CHECK([for msg_control field in struct msghdr],
885		ac_cv_have_control_in_msghdr, [
886	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
887#include <sys/types.h>
888#include <sys/socket.h>
889#include <sys/uio.h>
890		]], [[
891#ifdef msg_control
892#error "msg_control is a macro"
893exit(1);
894#endif
895struct msghdr m;
896m.msg_control = 0;
897exit(0);
898		]])],
899		[ ac_cv_have_control_in_msghdr="yes" ],
900		[ ac_cv_have_control_in_msghdr="no" ]
901	)
902])
903if test "x$ac_cv_have_control_in_msghdr" = "xyes" ; then
904	AC_DEFINE([HAVE_CONTROL_IN_MSGHDR], [1],
905		[Define if your system uses ancillary data style
906		file descriptor passing])
907fi
908
909AC_CACHE_CHECK([if libc defines __progname], ac_cv_libc_defines___progname, [
910	AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],
911		[[ extern char *__progname; printf("%s", __progname); ]])],
912	[ ac_cv_libc_defines___progname="yes" ],
913	[ ac_cv_libc_defines___progname="no"
914	])
915])
916if test "x$ac_cv_libc_defines___progname" = "xyes" ; then
917	AC_DEFINE([HAVE___PROGNAME], [1], [Define if libc defines __progname])
918fi
919
920#l4010
921# Looking for programs, paths and files
922
923PRIVSEP_PATH=/var/empty
924AC_ARG_WITH([path-empty],
925	[  --with-path-empty=PATH  Specify path to empty directory (default=/var/empty)],
926	[
927		if test -n "$withval"  &&  test "x$withval" != "xno"  &&  \
928		    test "x${withval}" != "xyes"; then
929			PRIVSEP_PATH=$withval
930		fi
931	]
932)
933AC_SUBST([PRIVSEP_PATH])
934#l4022
935
936#l4045
937STRIP_OPT=-s
938AC_ARG_ENABLE([strip],
939	[  --disable-strip         Disable calling strip(1) on install],
940	[
941		if test "x$enableval" = "xno" ; then
942			STRIP_OPT=
943		fi
944	]
945)
946AC_SUBST([STRIP_OPT])
947#l4054
948
949#l4176 (customized s/ssh.1/smtpd/smtpd.8/)
950# Options from here on. Some of these are preset by platform above
951AC_ARG_WITH([mantype],
952	[  --with-mantype=man|cat|doc  Set man page type],
953	[
954		case "$withval" in
955		man|cat|doc)
956			MANTYPE=$withval
957			;;
958		*)
959			AC_MSG_ERROR([invalid man type: $withval])
960			;;
961		esac
962	]
963)
964if test -z "$MANTYPE"; then
965	TestPath="/usr/bin${PATH_SEPARATOR}/usr/ucb"
966	AC_PATH_PROGS([NROFF], [nroff awf], [/bin/false], [$TestPath])
967	if ${NROFF} -mdoc ${srcdir}/smtpd/smtpd.8 >/dev/null 2>&1; then
968		MANTYPE=doc
969	elif ${NROFF} -man ${srcdir}/smtpd/smtpd.8 >/dev/null 2>&1; then
970		MANTYPE=man
971	else
972		MANTYPE=cat
973	fi
974fi
975AC_SUBST([MANTYPE])
976if test "$MANTYPE" = "doc"; then
977	mansubdir=man;
978else
979	mansubdir=$MANTYPE;
980fi
981AC_SUBST([mansubdir])
982#l4207
983
984case "$host" in
985*-*-openbsd*)
986	pkglibexecdir="$libexecdir/smtpd"
987	;;
988*)
989	pkglibexecdir="$libexecdir/opensmtpd"
990	;;
991esac
992AC_SUBST([pkglibexecdir])
993
994
995#
996# individual modules
997#
998
999HAVE_FILTER_MONKEY=no
1000AC_ARG_WITH([filter-monkey],
1001	[  --with-filter-monkey	Enable filter monkey],
1002	[
1003		if test "x$withval" != "xno" ; then
1004			AC_DEFINE([HAVE_FILTER_MONKEY], [1],
1005				[Define if you have filter monkey])
1006			HAVE_FILTER_MONKEY=yes
1007		fi
1008	]
1009)
1010AM_CONDITIONAL([HAVE_FILTER_MONKEY], [test $HAVE_FILTER_MONKEY = yes])
1011
1012HAVE_FILTER_STUB=no
1013AC_ARG_WITH([filter-stub],
1014	[  --with-filter-stub	Enable filter stub],
1015	[
1016		if test "x$withval" != "xno" ; then
1017			AC_DEFINE([HAVE_FILTER_STUB], [1],
1018				[Define if you have filter stub])
1019			HAVE_FILTER_STUB=yes
1020		fi
1021	]
1022)
1023AM_CONDITIONAL([HAVE_FILTER_STUB], [test $HAVE_FILTER_STUB = yes])
1024
1025HAVE_FILTER_TRACE=no
1026AC_ARG_WITH([filter-trace],
1027	[  --with-filter-trace	Enable filter trace],
1028	[
1029		if test "x$withval" != "xno" ; then
1030			AC_DEFINE([HAVE_FILTER_TRACE], [1],
1031				[Define if you have filter trace])
1032			HAVE_FILTER_TRACE=yes
1033		fi
1034	]
1035)
1036AM_CONDITIONAL([HAVE_FILTER_TRACE], [test $HAVE_FILTER_TRACE = yes])
1037
1038HAVE_FILTER_VOID=no
1039AC_ARG_WITH([filter-void],
1040	[  --with-filter-void	Enable filter void],
1041	[
1042		if test "x$withval" != "xno" ; then
1043			AC_DEFINE([HAVE_FILTER_VOID], [1],
1044				[Define if you have filter void])
1045			HAVE_FILTER_VOID=yes
1046		fi
1047	]
1048)
1049AM_CONDITIONAL([HAVE_FILTER_VOID], [test $HAVE_FILTER_VOID = yes])
1050
1051
1052#
1053# QUEUES
1054#
1055HAVE_QUEUE_NULL=no
1056AC_ARG_WITH([queue-null],
1057	[  --with-queue-null	Enable queue null],
1058	[
1059		if test "x$withval" != "xno" ; then
1060			AC_DEFINE([HAVE_QUEUE_NULL], [1],
1061				[Define if you have queue null])
1062			HAVE_QUEUE_NULL=yes
1063		fi
1064	]
1065)
1066AM_CONDITIONAL([HAVE_QUEUE_NULL], [test $HAVE_QUEUE_NULL = yes])
1067
1068HAVE_QUEUE_PYTHON=no
1069AC_ARG_WITH([queue-python],
1070	[  --with-queue-python	Enable queue python],
1071	[
1072		if test "x$withval" != "xno" ; then
1073			AC_DEFINE([HAVE_QUEUE_PYTHON], [1],
1074				[Define if you have queue python])
1075			HAVE_QUEUE_PYTHON=yes
1076			need_python=yes
1077		fi
1078	]
1079)
1080AM_CONDITIONAL([HAVE_QUEUE_PYTHON], [test $HAVE_QUEUE_PYTHON = yes])
1081
1082HAVE_QUEUE_RAM=no
1083AC_ARG_WITH([queue-ram],
1084	[  --with-queue-ram	Enable queue ram],
1085	[
1086		if test "x$withval" != "xno" ; then
1087			AC_DEFINE([HAVE_QUEUE_RAM], [1],
1088				[Define if you have queue ram])
1089			HAVE_QUEUE_RAM=yes
1090		fi
1091	]
1092)
1093AM_CONDITIONAL([HAVE_QUEUE_RAM], [test $HAVE_QUEUE_RAM = yes])
1094
1095HAVE_QUEUE_STUB=no
1096AC_ARG_WITH([queue-stub],
1097	[  --with-queue-stub	Enable queue stub],
1098	[
1099		if test "x$withval" != "xno" ; then
1100			AC_DEFINE([HAVE_QUEUE_STUB], [1],
1101				[Define if you have queue stub])
1102			HAVE_QUEUE_STUB=yes
1103		fi
1104	]
1105)
1106AM_CONDITIONAL([HAVE_QUEUE_STUB], [test $HAVE_QUEUE_STUB = yes])
1107
1108
1109
1110#
1111# TABLES
1112#
1113
1114# Whether to enable *experimental* LDAP support
1115HAVE_TABLE_LDAP=no
1116AC_ARG_WITH([table-ldap],
1117	[  --with-table-ldap	Enable table LDAP],
1118	[
1119		if test "x$withval" != "xno" ; then
1120			AC_DEFINE([HAVE_TABLE_LDAP], [1],
1121				[Define if you have experimental LDAP support])
1122			HAVE_TABLE_LDAP=yes
1123		fi
1124	]
1125)
1126AM_CONDITIONAL([HAVE_TABLE_LDAP], [test $HAVE_TABLE_LDAP = yes])
1127
1128# Whether to enable *experimental* MySQL support
1129HAVE_TABLE_MYSQL=no
1130AC_ARG_WITH([table-mysql],
1131	[  --with-table-mysql	Enable table MySQL],
1132	[
1133		if test "x$withval" != "xno" ; then
1134			AC_DEFINE([HAVE_TABLE_MYSQL], [1],
1135				[Define if you have experimental MySQL support])
1136			HAVE_TABLE_MYSQL=yes
1137			AC_PATH_PROG([MYSQL_CONFIG], [mysql_config], , $PATH)
1138			if test "x$MYSQL_CONFIG" = "x"; then
1139				AC_MSG_RESULT([mysql_config not found, proceeding with default settings])
1140			else
1141				AC_MSG_CHECKING([for MySQL lib path])
1142				MYSQL_LIBS=`"$MYSQL_CONFIG" --libs | sed -n 's#.*-L\(\"/[^\"]*\"\).*#\1#p;s#.*-L\(/[^[:space:]]*\).*#\1#p;'`
1143				if test "x$MYSQL_LIBS" = "x"; then
1144					AC_MSG_RESULT([not found, proceeding with default settings])
1145				else
1146					AC_MSG_RESULT([found $MYSQL_LIBS])
1147					LDFLAGS="-L${MYSQL_LIBS} ${LDFLAGS}"
1148				fi
1149			fi
1150		fi
1151	]
1152)
1153AM_CONDITIONAL([HAVE_TABLE_MYSQL], [test $HAVE_TABLE_MYSQL = yes])
1154
1155# Whether to enable *experimental* PostgreSQL support
1156HAVE_TABLE_POSTGRES=no
1157AC_ARG_WITH([table-postgres],
1158	[  --with-table-postgres	Enable table PostgreSQL],
1159	[
1160		if test "x$withval" != "xno" ; then
1161			AC_DEFINE([HAVE_TABLE_POSTGRES], [1],
1162				[Define if you have experimental PostgreSQL support])
1163			HAVE_TABLE_POSTGRES=yes
1164		fi
1165	]
1166)
1167AM_CONDITIONAL([HAVE_TABLE_POSTGRES], [test $HAVE_TABLE_POSTGRES = yes])
1168
1169
1170# Whether to enable *experimental* Redis support
1171HAVE_TABLE_REDIS=no
1172AC_ARG_WITH([table-redis],
1173	[  --with-table-redis	Enable table Redis],
1174	[
1175		if test "x$withval" != "xno" ; then
1176			AC_DEFINE([HAVE_TABLE_REDIS], [1],
1177				[Define if you have experimental Redis support])
1178			HAVE_TABLE_REDIS=yes
1179			need_redis=yes
1180		fi
1181	]
1182)
1183AM_CONDITIONAL([HAVE_TABLE_REDIS], [test $HAVE_TABLE_REDIS = yes])
1184
1185# Whether to enable *experimental* Redis support
1186HAVE_TABLE_SOCKETMAP=no
1187AC_ARG_WITH([table-socketmap],
1188	[  --with-table-socketmap	Enable table socketmap],
1189	[
1190		if test "x$withval" != "xno" ; then
1191			AC_DEFINE([HAVE_TABLE_SOCKETMAP], [1],
1192				[Define if you have experimental socketmap support])
1193		HAVE_TABLE_SOCKETMAP=yes
1194		fi
1195	]
1196)
1197AM_CONDITIONAL([HAVE_TABLE_SOCKETMAP], [test $HAVE_TABLE_SOCKETMAP = yes])
1198
1199# Whether to enable table_passwd
1200HAVE_TABLE_PASSWD=no
1201AC_ARG_WITH([table-passwd],
1202	[  --with-table-passwd	Enable table passwd],
1203	[
1204		if test "x$withval" != "xno" ; then
1205			AC_DEFINE([HAVE_TABLE_PASSWD], [1],
1206				[Define if you want to enable table passwd])
1207			HAVE_TABLE_PASSWD=yes
1208		fi
1209	]
1210)
1211AM_CONDITIONAL([HAVE_TABLE_PASSWD], [test $HAVE_TABLE_PASSWD = yes])
1212
1213# Whether to enable table_python
1214HAVE_TABLE_PYTHON=no
1215AC_ARG_WITH([table-python],
1216	[  --with-table-python	Enable table python],
1217	[
1218		if test "x$withval" != "xno" ; then
1219			AC_DEFINE([HAVE_TABLE_PYTHON], [1],
1220				[Define if you want to enable table python])
1221			HAVE_TABLE_PYTHON=yes
1222			need_python=yes
1223		fi
1224	]
1225)
1226AM_CONDITIONAL([HAVE_TABLE_PYTHON], [test $HAVE_TABLE_PYTHON = yes])
1227
1228HAVE_TABLE_SQLITE=no
1229AC_ARG_WITH([table-sqlite],
1230	[  --with-table-sqlite	Enable table SQLite],
1231	[
1232		if test "x$withval" != "xno" ; then
1233			AC_DEFINE([HAVE_TABLE_SQLITE], [1],
1234				[Define if you have SQLite support])
1235			HAVE_TABLE_SQLITE=yes
1236		fi
1237	]
1238)
1239AM_CONDITIONAL([HAVE_TABLE_SQLITE], [test $HAVE_TABLE_SQLITE = yes])
1240
1241HAVE_TABLE_STUB=no
1242AC_ARG_WITH([table-stub],
1243	[  --with-table-stub	Enable table stub],
1244	[
1245		if test "x$withval" != "xno" ; then
1246			AC_DEFINE([HAVE_TABLE_STUB], [1],
1247				[Define if you have stub support])
1248			HAVE_TABLE_STUB=yes
1249		fi
1250	]
1251)
1252AM_CONDITIONAL([HAVE_TABLE_STUB], [test $HAVE_TABLE_STUB = yes])
1253
1254
1255#
1256# TOOLS
1257#
1258HAVE_TOOL_STATS=no
1259AC_ARG_WITH([tool-stats],
1260	[  --with-tool-stats	Enable tool stats],
1261	[
1262		if test "x$withval" != "xno" ; then
1263			AC_DEFINE([HAVE_TOOL_STATS], [1],
1264				[Define if you have stats support])
1265			HAVE_TOOL_STATS=yes
1266		fi
1267	]
1268)
1269AM_CONDITIONAL([HAVE_TOOL_STATS], [test $HAVE_TOOL_STATS = yes])
1270
1271
1272#
1273# SCHEDULERS
1274#
1275HAVE_SCHEDULER_RAM=no
1276AC_ARG_WITH([scheduler-ram],
1277	[  --with-scheduler-ram	Enable scheduler ram],
1278	[
1279		if test "x$withval" != "xno" ; then
1280			AC_DEFINE([HAVE_SCHEDULER_RAM], [1],
1281				[Define if you have scheduler ram])
1282			HAVE_SCHEDULER_RAM=yes
1283		fi
1284	]
1285)
1286AM_CONDITIONAL([HAVE_SCHEDULER_RAM], [test $HAVE_SCHEDULER_RAM = yes])
1287
1288HAVE_SCHEDULER_STUB=no
1289AC_ARG_WITH([scheduler-stub],
1290	[  --with-scheduler-stub	Enable scheduler stub],
1291	[
1292		if test "x$withval" != "xno" ; then
1293			AC_DEFINE([HAVE_SCHEDULER_STUB], [1],
1294				[Define if you have scheduler stub])
1295			HAVE_SCHEDULER_STUB=yes
1296		fi
1297	]
1298)
1299AM_CONDITIONAL([HAVE_SCHEDULER_STUB], [test $HAVE_SCHEDULER_STUB = yes])
1300
1301HAVE_SCHEDULER_PYTHON=no
1302AC_ARG_WITH([scheduler-python],
1303	[  --with-scheduler-python	Enable scheduler python],
1304	[
1305		if test "x$withval" != "xno" ; then
1306			AC_DEFINE([HAVE_SCHEDULER_PYTHON], [1],
1307				[Define if you have scheduler python])
1308			HAVE_SCHEDULER_PYTHON=yes
1309			need_python=yes
1310		fi
1311	]
1312)
1313AM_CONDITIONAL([HAVE_SCHEDULER_PYTHON], [test $HAVE_SCHEDULER_PYTHON = yes])
1314
1315
1316AC_ARG_WITH([python],
1317	[  --with-python=PATH    Specify prefix of python installation ],
1318	[
1319		if test "x$withval" != "xno" ; then
1320			python_prefix="${withval}"
1321		fi
1322	]
1323)
1324AC_ARG_WITH([python-type],
1325	[  --with-python-type=PATH  Specify the type of python used ],
1326	[
1327		if test "x$withval" != "xno" ; then
1328			python_type="${withval}"
1329		fi
1330	]
1331)
1332
1333AC_ARG_WITH([perl],
1334	[  --with-perl=PATH      Specify prefix of perl installation ],
1335	[
1336		if test "x$withval" != "xno" ; then
1337			perl_prefix="${withval}"
1338		fi
1339	]
1340)
1341
1342AC_ARG_WITH([lua],
1343	[  --with-lua=PATH       Specify prefix of lua installation ],
1344	[
1345		if test "x$withval" != "xno" ; then
1346			lua_prefix="${withval}"
1347		fi
1348	]
1349
1350)
1351AC_ARG_WITH([lua-type],
1352	[  --with-lua-type=PATH  Specify the type of lua used (automatic if unspecified, otherwise luajit, lua, or another version) ],
1353	[
1354		if test "x$withval" != "xno" ; then
1355			lua_type="${withval}"
1356		fi
1357	]
1358)
1359
1360#
1361# check for python
1362#
1363PYTHON_CPPFLAGS=
1364PYTHON_LDFLAGS=
1365if test x"${need_python}" = x"yes"; then
1366   PYTHON_CONFIG=
1367   if test x"${python_type}" = x""; then
1368	python_type="python"
1369   fi
1370   for path in /usr/local/bin /usr/bin; do
1371	if test -f ${path}/${python_type}-config; then
1372		PYTHON_CONFIG=${path}/${python_type}-config
1373		break
1374	fi
1375   done
1376
1377   # if python provided --with-python, override
1378   if test x"${with_python}" != x""; then
1379      PYTHON_CONFIG="${python_prefix}/bin/${python_type}-config"
1380   fi
1381
1382   if ! test -f $PYTHON_CONFIG; then
1383      AC_MSG_ERROR([*** $PYTHON_CONFIG could not be found, please install or use --with-python ***])
1384   fi
1385
1386   PYTHON_CPPFLAGS="`$PYTHON_CONFIG --includes`"
1387   PYTHON_LDFLAGS="-L`$PYTHON_CONFIG --prefix`/lib `$PYTHON_CONFIG --libs`"
1388fi
1389AC_SUBST([PYTHON_CPPFLAGS])
1390AC_SUBST([PYTHON_LDFLAGS])
1391
1392#
1393# check for perl
1394#
1395PERL_CPPFLAGS=
1396PERL_LDFLAGS=
1397if test x"${need_perl}" = x"yes"; then
1398   PERL_CONFIG=
1399   for path in /usr/local/bin /usr/bin; do
1400	if test -f ${path}/perl; then
1401		PERL_CONFIG=${path}/perl
1402		break
1403	fi
1404   done
1405
1406   # if perl provided --with-perl, override
1407   if test x"${with_perl}" != x""; then
1408      PERL_CONFIG="${perl_prefix}/bin/perl"
1409   fi
1410
1411   if ! test -f $PERL_CONFIG; then
1412      AC_MSG_ERROR([*** $PERL_CONFIG could not be found, please install or use --with-perl ***])
1413   fi
1414
1415   PERL_CPPFLAGS="`perl -MExtUtils::Embed -e ccopts`"
1416   PERL_LDFLAGS="`perl -MExtUtils::Embed -e ldopts`"
1417fi
1418AC_SUBST([PERL_CPPFLAGS])
1419AC_SUBST([PERL_LDFLAGS])
1420
1421#
1422# check for lua
1423#
1424LUA_CPPFLAGS=
1425LUA_LDFLAGS=
1426if test x"${need_lua}" = x"yes"; then
1427   LUA_CONFIG=
1428   for path in /usr/local/bin /usr/bin; do
1429	if test -f ${path}/pkg-config; then
1430		LUA_CONFIG=${path}/pkg-config
1431		break
1432	fi
1433   done
1434
1435   # if lua provided --with-lua, override
1436   if test x"${with_lua}" != x""; then
1437      LUA_CONFIG="${lua_prefix}/bin/pkg-config"
1438   fi
1439
1440   if ! test -f $LUA_CONFIG; then
1441     if test x"${lua_type}" = x""; then
1442       for i in luajit lua lua5.2 lua-5.2 lua5.1 lua-5.1; do
1443         if test -d ${lua_prefix:-/usr/local}/include/${i}*; then
1444	   lua_type=$i
1445	   break
1446	 fi
1447       done
1448     fi
1449     LUA_CPPFLAGS="-I${lua_prefix:-/usr/local}/include/${lua_type}"
1450     LUA_LDFLAGS="-L${lua_prefix:-/usr/local}/lib -l${lua_type} -lm"
1451   else
1452     if test x"${lua_type}" = x""; then
1453       for i in luajit lua lua5.2 lua-5.2 lua5.1 lua-5.1; do
1454         if $LUA_CONFIG --exists $i 2>/dev/null; then
1455	   lua_type=$i
1456	   break
1457	 fi
1458       done
1459     fi
1460     LUA_CPPFLAGS="`$LUA_CONFIG --cflags $lua_type`"
1461     LUA_LDFLAGS="`$LUA_CONFIG --libs $lua_type`"
1462   fi
1463fi
1464AC_SUBST([LUA_CPPFLAGS])
1465AC_SUBST([LUA_LDFLAGS])
1466
1467#
1468# check for hiredis
1469#
1470REDIS_CPPFLAGS=
1471REDIS_LDFLAGS=
1472if test x"${need_redis}" = x"yes"; then
1473   REDIS_CONFIG=
1474   for path in /usr/local/bin /usr/bin; do
1475	if test -f ${path}/pkg-config; then
1476		REDIS_CONFIG=${path}/pkg-config
1477		break
1478	fi
1479   done
1480
1481   # if redis provided --with-redis, override
1482   if test x"${with_hiredis}" != x""; then
1483      REDIS_CONFIG="${redis_prefix}/bin/pkg-config"
1484   fi
1485
1486   if ! test -f $REDIS_CONFIG; then
1487      AC_MSG_ERROR([*** $REDIS_CONFIG could not be found, please install or use --with-redis ***])
1488   fi
1489
1490   REDIS_CPPFLAGS="`$REDIS_CONFIG --cflags hiredis`"
1491   REDIS_LDFLAGS="`$REDIS_CONFIG --libs hiredis`"
1492fi
1493AC_SUBST([REDIS_CPPFLAGS])
1494AC_SUBST([REDIS_LDFLAGS])
1495
1496##chl (based on OpenSSL checks, see above)
1497# Search for libevent
1498saved_CPPFLAGS="$CPPFLAGS"
1499saved_LDFLAGS="$LDFLAGS"
1500AC_ARG_WITH([libevent],
1501	[  --with-libevent=PATH     Specify path to libevent installation ],
1502	[
1503		if test "x$withval" != "xno" ; then
1504			case "$withval" in
1505				# Relative paths
1506				./*|../*)	withval="`pwd`/$withval"
1507			esac
1508			if test -d "$withval/lib"; then
1509				if test -n "${need_dash_r}"; then
1510					LDFLAGS="-L${withval}/lib -R${withval}/lib ${LDFLAGS}"
1511				else
1512					LDFLAGS="-L${withval}/lib ${LDFLAGS}"
1513				fi
1514			elif test -d "$withval/lib64"; then
1515				if test -n "${need_dash_r}"; then
1516					LDFLAGS="-L${withval}/lib64 -R${withval}/lib64 ${LDFLAGS}"
1517				else
1518					LDFLAGS="-L${withval}/lib64 ${LDFLAGS}"
1519				fi
1520			else
1521				if test -n "${need_dash_r}"; then
1522					LDFLAGS="-L${withval} -R${withval} ${LDFLAGS}"
1523				else
1524					LDFLAGS="-L${withval} ${LDFLAGS}"
1525				fi
1526			fi
1527			if test -d "$withval/include"; then
1528				CPPFLAGS="-I${withval}/include ${CPPFLAGS}"
1529			else
1530				CPPFLAGS="-I${withval} ${CPPFLAGS}"
1531			fi
1532			need_libevent_autodetect=no
1533		fi
1534	]
1535)
1536
1537if test x"${need_libevent_autodetect}" != x"no"; then
1538   for path in /usr/local /usr; do
1539       if test -f "${path}/include/event.h"; then
1540       	  CPPFLAGS="-I${path}/include ${CPPFLAGS}"
1541	  LDFLAGS="-L${path}/lib ${LDFLAGS}"
1542       fi
1543   done
1544fi
1545
1546LIBS="-levent $LIBS"
1547
1548AC_MSG_CHECKING([if programs using libevent functions will link])
1549AC_LINK_IFELSE(
1550	[AC_LANG_PROGRAM([[
1551	#include <event.h>
1552	]], [[
1553	event_base_new();
1554	]])],
1555	[
1556		AC_MSG_RESULT([yes])
1557	],
1558	[
1559		AC_MSG_RESULT([no])
1560	]
1561)
1562
1563LIBS="$LIBS ${SMTPDLIBS}"
1564##end of chl
1565
1566
1567AC_CONFIG_FILES([Makefile
1568		openbsd-compat/Makefile
1569
1570		extras/Makefile
1571
1572		extras/queues/Makefile
1573		extras/queues/queue-null/Makefile
1574		extras/queues/queue-python/Makefile
1575		extras/queues/queue-ram/Makefile
1576		extras/queues/queue-stub/Makefile
1577
1578		extras/schedulers/Makefile
1579		extras/schedulers/scheduler-python/Makefile
1580		extras/schedulers/scheduler-ram/Makefile
1581		extras/schedulers/scheduler-stub/Makefile
1582
1583		extras/tables/Makefile
1584		extras/tables/table-passwd/Makefile
1585		extras/tables/table-ldap/Makefile
1586		extras/tables/table-mysql/Makefile
1587		extras/tables/table-postgres/Makefile
1588		extras/tables/table-python/Makefile
1589		extras/tables/table-redis/Makefile
1590		extras/tables/table-socketmap/Makefile
1591		extras/tables/table-sqlite/Makefile
1592		extras/tables/table-stub/Makefile
1593		])
1594
1595#l4761
1596AC_OUTPUT
1597
1598
1599# Print summary of options
1600
1601# Someone please show me a better way :)
1602A=`eval echo ${prefix}` ; A=`eval echo ${A}`
1603B=`eval echo ${bindir}` ; B=`eval echo ${B}`
1604C=`eval echo ${sbindir}` ; C=`eval echo ${C}`
1605D=`eval echo ${sysconfdir}` ; D=`eval echo ${D}`
1606E=`eval echo ${mandir}/${mansubdir}X` ; E=`eval echo ${E}`
1607F=`eval echo ${PRIVSEP_PATH}` ; F=`eval echo ${F}`
1608
1609echo ""
1610echo "OpenSMTPD-extras have been configured with the following options:"
1611echo "                     User binaries: $B"
1612echo "                   System binaries: $C"
1613echo "               Configuration files: $D"
1614echo "                      Manual pages: $E"
1615echo "  Privilege separation chroot path: $F"
1616echo "                Package libexecdir: ${pkglibexecdir}"
1617echo "                    Manpage format: $MANTYPE"
1618echo ""
1619
1620echo "              Host: ${host}"
1621echo "          Compiler: ${CC}"
1622echo "    Compiler flags: ${CFLAGS}"
1623echo "Preprocessor flags: ${CPPFLAGS}"
1624echo "      Linker flags: ${LDFLAGS}"
1625echo "         Libraries: ${LIBS}"
1626echo ""
1627
1628if test x"${need_python}" = x"yes"; then
1629echo "Built with Python support:"
1630echo "          CPPFLAGS: ${PYTHON_CPPFLAGS}"
1631echo "           LDFLAGS: ${PYTHON_LDFLAGS}"
1632echo ""
1633fi
1634
1635if test x"${need_perl}" = x"yes"; then
1636echo "Built with Perl support:"
1637echo "          CPPFLAGS: ${PERL_CPPFLAGS}"
1638echo "           LDFLAGS: ${PERL_LDFLAGS}"
1639echo ""
1640fi
1641
1642if test x"${need_lua}" = x"yes"; then
1643echo "Built with Lua support:"
1644echo "          CPPFLAGS: ${LUA_CPPFLAGS}"
1645echo "           LDFLAGS: ${LUA_LDFLAGS}"
1646echo ""
1647fi
1648
1649if test x"${need_redis}" = x"yes"; then
1650echo "Built with redis support:"
1651echo "          CPPFLAGS: ${REDIS_CPPFLAGS}"
1652echo "           LDFLAGS: ${REDIS_LDFLAGS}"
1653echo ""
1654fi
1655