dnl
dnl autoconf input file to generate MCONFIG
dnl

AC_PREREQ(2.52)
AC_REVISION([$Id: configure.in,v 1.25 2001/11/12 23:40:51 hpa Exp $])
AC_INIT(MCONFIG.in)
AC_PREFIX_DEFAULT(/usr)

AC_ISC_POSIX
AC_AIX
AC_MINIX
AC_PROG_CC
AC_C_CONST
AC_C_INLINE

AC_SYS_LARGEFILE

PA_ADD_CFLAGS(-W)
PA_ADD_CFLAGS(-Wall)
PA_ADD_CFLAGS(-Wpointer-arith)
PA_ADD_CFLAGS(-Wbad-function-cast)
PA_ADD_CFLAGS(-Wcast-equal)
PA_ADD_CFLAGS(-Wstrict-prototypes)
PA_ADD_CFLAGS(-Wmissing-prototypes)
PA_ADD_CFLAGS(-Wmissing-declarations)
PA_ADD_CFLAGS(-Wnested-externs)
PA_ADD_CFLAGS(-Winline)
PA_ADD_CFLAGS(-Wwrite-strings)
PA_ADD_CFLAGS(-Wundef)
PA_ADD_CFLAGS(-Wshadow)
PA_ADD_CFLAGS(-Wsign-compare)
PA_ADD_CFLAGS(-pipe)

AC_HEADER_STDC
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_HEADERS(libgen.h)
AC_CHECK_HEADERS(memory.h)
AC_CHECK_HEADERS(stddef.h)
AC_CHECK_HEADERS(stdint.h)
AC_CHECK_HEADERS(stdlib.h)
AC_CHECK_HEADERS(string.h)
AC_CHECK_HEADERS(strings.h)
AC_CHECK_HEADERS(sysexits.h)
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(sys/filio.h)
AC_CHECK_HEADERS(sys/stat.h)
AC_CHECK_HEADERS(sys/types.h)
dnl This is needed on some versions of FreeBSD...
AC_CHECK_HEADERS(machine/param.h)

AC_CHECK_TYPES(intmax_t)
AC_CHECK_TYPES(long long)
AC_CHECK_TYPES(uint16_t)
AC_CHECK_TYPES(uint32_t)
AC_CHECK_TYPES(u_short)
AC_CHECK_TYPES(u_long)
AC_TYPE_PID_T

AC_SEARCH_LIBS(socket, socket, , [AC_MSG_ERROR(socket library not found)])
AC_SEARCH_LIBS(gethostbyname, [nsl resolv], , [AC_MSG_ERROR(gethostbyname not found)])
AC_SEARCH_LIBS(inet_aton, [nsl resolv], , [AC_MSG_ERROR(inet_aton not found)])
AC_SEARCH_LIBS(herror, [nsl resolv], , [AC_MSG_ERROR(herror not found)])

AC_CHECK_FUNCS(setsid)
AC_CHECK_FUNCS(recvmsg)
AC_CHECK_FUNCS(setreuid)
AC_CHECK_FUNCS(setregid)
dnl Solaris 8 has [u]intmax_t but not strtoumax().  How utterly braindamaged.
AC_CHECK_FUNCS(strtoumax)
AC_CHECK_FUNCS(strtoull)

PA_MSGHDR_MSG_CONTROL
PA_STRUCT_IN_PKTINFO


AH_TEMPLATE([HAVE_IPPORT_TFTP_DEFINITION],
[Define if netinet/in.h defines IPPORT_TFTP.])
PA_HEADER_DEFINES(netinet/in.h, int, IPPORT_TFTP)

PA_WITH_BOOL(tcpwrappers, 1,
[  --without-tcpwrappers   disable tcpwrapper permissions checking],
[
	AC_SEARCH_LIBS(yp_get_default_domain, [nsl resolv])
	PA_HAVE_TCPWRAPPERS
],:)

AH_TEMPLATE([WITH_REGEX],
[Define if we are compiling with regex filename remapping.])

PA_WITH_BOOL(remap, 1,
[  --without-remap         disable regex-based filename remapping],
[
	AC_CHECK_HEADER(regex.h,
	[
		AC_SEARCH_LIBS(regcomp, [regex rx],
		[
			AC_DEFINE(WITH_REGEX)
			TFTPDOBJS="remap.o $TFTPDOBJS"
		])
	])
],:)

AH_TEMPLATE([WITH_READLINE],
[Define if we are compiling with readline command-line editing.])

PA_WITH_BOOL(readline, 1,
[  --without-readline      disable the use of readline command-line editing],
[
	USE_READLINE=true
	AC_CHECK_HEADER(readline/readline.h, [], [USE_READLINE=false])
	AC_CHECK_HEADER(readline/history.h, [], [USE_READLINE=false])
	if $USE_READLINE
	then
		AC_SEARCH_LIBS(readline, [readline history],
		[
			AC_DEFINE(WITH_READLINE)
		])
	fi
],:)

AH_TEMPLATE([HAVE_SIGSETJMP],
[Define if we have sigsetjmp, siglongjmp and sigjmp_buf.])
PA_SIGSETJMP([AC_DEFINE(HAVE_SIGSETJMP)])

LIBXTRA=false
AC_SEARCH_LIBS(xmalloc, iberty, , LIBXTRA=true LIBOBJS="$LIBOBJS xmalloc.o")
AC_SEARCH_LIBS(xstrdup, iberty, , LIBXTRA=true LIBOBJS="$LIBOBJS xstrdup.o")
AC_SEARCH_LIBS(bsd_signal, bsd, , LIBXTRA=true LIBOBJS="$LIBOBJS bsdsignal.o")
if $LIBXTRA; then
	LIBS="../lib/libxtra.a $LIBS"
fi

AC_SUBST(LIBOBJS)
AC_SUBST(TFTPDOBJS)

AC_PROG_RANLIB
AC_PROG_INSTALL

AC_CONFIG_HEADER(acconfig.h)
AC_OUTPUT(MCONFIG)
