dnl Process this file with autoconf to produce a configure script.
dnl
AC_INIT(ncftp/main.c)
AC_PREREQ(2.13)
AC_CONFIG_HEADER(config.h)
wi_ARG_DISABLE_CCDV
AC_ARG_WITH(curses,[  --without-curses        do not try to find and use the curses library],nc_cv_curses=$withval,nc_cv_curses=yes)
wi_ARG_ENABLE_DEBUG
AC_ARG_WITH(ncurses,[  --without-ncurses       do not try to find and use the ncurses library],nc_cv_ncurses=$withval,nc_cv_ncurses=yes)
wi_ARG_DISABLE_PRECOMP
dnl AC_ARG_WITH(readline,[  --without-readline      do not try to find and use the readline library],nc_cv_readline=$withval,nc_cv_readline=yes)
wi_ARG_WITH_SOCKS5
wi_ARG_ENABLE_SSP
wi_ARG_DISABLE_MACOSX_UNIVERSAL



dnl ---------------------------------------------------------------------------
dnl Environment and compiler settings.
dnl ---------------------------------------------------------------------------
dnl
wi_ENV_VAR_MESSAGES
wi_OS_VAR

case "$os" in
	linux)
		OS="linux-$arch-$libc"
		;;
esac

if test -f sh/install-sh ; then chmod 755 sh/*.sh sh/config.* sh/install-sh ; fi
AC_CONFIG_AUX_DIR([sh])
AC_PROG_CC
wi_CC_PRECOMP
wi_REQUEST_NO_Y2K_WARNINGS
wi_CFLAGS_LFS_OR_LFS64
wi_CFLAGS_REENTRANT
wi_MACOSX_UNIVERSAL_CFLAGS
wi_SFLAG
AC_OBJEXT
AC_EXEEXT
wi_DEFINE_UNAME
wi_EXTRA_SYSV_SUNOS_DIRS	dnl	For better curses library on SunOS 4

dnl Try to use PATH rather than hardcode the installation path, if possible.
if test "${prefix-NONE}" != "NONE" && test "$prefix" != "/usr/local" && test "$prefix" != "/usr"; then
	AC_DEFINE_UNQUOTED(PREFIX_BINDIR, "$prefix/bin")
fi



dnl ---------------------------------------------------------------------------
dnl Checks for header files.
dnl ---------------------------------------------------------------------------
dnl
AC_HEADER_STDC
dnl Readline headers #ifdefs for string.h, sio needs strings.h for AIX
AC_CHECK_HEADERS(arpa/nameser.h gnu/libc-version.h locale.h net/errno.h nserve.h resolv.h sgtty.h string.h strings.h sys/id.h sys/ioctl.h syslog.h sys/socket.h sys/time.h sys/types.h sys/utsname.h sys/systeminfo.h termio.h termios.h time.h utime.h unistd.h gnu/libc-version.h)
AC_TIME_WITH_SYS_TIME
dnl	# sio
wi_UNIX_DOMAIN_SOCKETS
SIO_OBJS_U=''
SIO_SOBJS_U=''
if test "$wi_cv_unix_domain_sockets" = yes ; then
	SIO_OBJS_U='$(OBJS_U) '
	SIO_SOBJS_U='$(SOBJS_U) '
fi
AC_SUBST(SIO_OBJS_U)
AC_SUBST(SIO_SOBJS_U)
dnl	# sio



dnl ---------------------------------------------------------------------------
dnl Checks for libraries.
dnl ---------------------------------------------------------------------------
dnl
wi_NET_LIBS
wi_LIB_SOCKS5

LIBCURSES=''
if test "$nc_cv_curses" = yes ; then
	wi_LIB_CURSES
fi
dnl if test "$nc_cv_readline" = yes ; then
dnl 	wi_LIB_READLINE
dnl fi

dnl
dnl DNSSEC
dnl
# Check whether user wants DNSSEC local validation support
AC_ARG_WITH(dnssec-local-validation,
        [  --with-dnssec-local-validation Enable local DNSSEC validation using libval (no)], want_dnssec=$withval, want_dnssec=no)
if ! test "x-$want_dnssec" = "x-no" ; then
    AC_CHECK_HEADERS(validator/validator.h)
    if test "$ac_cv_header_validator_validator_h" != yes; then
        AC_MSG_ERROR(Can't find validator.h)
    fi
    AC_CHECK_LIB(ssl, SHA1_Init,,AC_MSG_ERROR([Can't find SSL library]))
    AC_CHECK_LIB(sres, query_send,,AC_MSG_ERROR([Can't find libsres]))
    AC_CHECK_LIB(val, p_val_status,
                 LIBS="$LIBS -lval"
                 have_val_res_query=yes,
                 [ AC_CHECK_LIB(pthread, pthread_rwlock_init)
		   AC_CHECK_LIB(val-threads, p_val_status,
                   have_val_res_query=yes
                   LIBS="-lval-threads $LIBS"
                   LIBVAL_SUFFIX="-threads",
                   AC_MSG_ERROR(Can't find libval or libval-threads))
                 ])
    AC_DEFINE(DNSSEC_LOCAL_VALIDATION, 1,
              [Define if you want local DNSSEC validation support])
fi



dnl ---------------------------------------------------------------------------
dnl Checks for typedefs, structures, and compiler characteristics.
dnl ---------------------------------------------------------------------------
dnl
AC_C_CONST
AC_TYPE_SIZE_T
AC_TYPE_OFF_T
AC_TYPE_MODE_T
AC_TYPE_PID_T
AC_TYPE_UID_T
wi_VOID_MAIN_RETURN_TYPE
wi_USE_LONG_LONG
wi_STRUCT_TIMEVAL_FIELD_TYPES
wi_UNISTD_FUNC_PARAM_TYPES
wi_FUNC_SELECT_ARGTYPES
wi_STRUCT_STAT64
wi_TYPE_SIG_ATOMIC_T
wi_GETOPT
wi__RES_DEFDNAME	dnl				# sio
wi_STRUCT_CMSGHDR	dnl				# sio
wi_MSGHDR_CONTROL	dnl				# sio
wi_MSGHDR_ACCRIGHTS	dnl				# sio
wi_HEADER_SYS_SELECT_H	dnl				# sio



dnl ---------------------------------------------------------------------------
dnl Checks for library functions.
dnl ---------------------------------------------------------------------------
dnl
wi_FUNC_GETCWD
AC_CHECK_FUNCS(fstat64 getdomainname gethostname getpass getpassphrase gnu_get_libc_release gnu_get_libc_version inet_aton inet_ntop llseek lseek64 lstat64 memmove mktime open64 pathconf readlink res_init setlocale setpgid setpgrp setsid setvbuf sigaction sigsetjmp stat64 strcasecmp strcoll strdup strerror strncoll strstr strtoq symlink sysconf sysctl sysinfo syslog tcgetattr uname waitpid)
AC_CHECK_FUNCS(gethostbyaddr_r gethostbyname_r gethostbyname2_r getlogin_r getpwnam_r _posix_getpwnam_r getpwuid_r _posix_getpwuid_r getservbyname_r getservbyport_r gmtime_r localtime_r readdir_r)
wi_SNPRINTF
wi_FUNC_SIGSETJMP
wi_FUNC_SETPGRP
wi_FUNC_SETVBUF
AC_FUNC_ALLOCA	dnl Only needed for Linux, and for one function in Sio.
wi_CURSES_FEATURES
if test "x$LIBCURSES" = "x" ; then
	VIS_DPROGS="# ../bin/ncftpbookmarks${EXEEXT}"
else
	VIS_DPROGS="../bin/ncftpbookmarks${EXEEXT}"
fi



dnl ---------------------------------------------------------------------------
dnl Checks for system characteristics.
dnl ---------------------------------------------------------------------------
dnl
AC_SYS_LONG_FILE_NAMES
AC_PROG_MAKE_SET
wi_PROG_TAR
wi_CREATE_TAR_FILES
wi_PROG_RANLIB
wi_PROG_AR
AC_PROG_INSTALL
wi_PROG_CCDV
wi_MANDIR
wi_SUBST_LONGEST_INT_HEADER([libncftp/ncftp.h])
wi_SUBST_STAT_HEADER([libncftp/ncftp.h])
wi_REMOVE_UNKNOWN_PREPROCESSING_DIRECTIVES_FROM_FILE([libncftp/ncftp.h])
LIBSET='$(LIB)'
Z30='#'
case "$HOME" in
	*lcompile*)
		;;
	*)
		if test -x /usr/local/bin/incrementor ; then
			Z30='	-@/usr/local/bin/incrementor -b -f version.c -f version.o'
		fi
		;;
esac
wi_RESOLVE_PATH([$srcdir], MAINDIR)
wi_RESOLVE_PATH([$MAINDIR/libncftp/ncftp.h], [libncftp_h])
wi_DIRNAME(libncftp_h)
wi_RESOLVE_PATH([$MAINDIR/sio/sio.h], [sio_h])
wi_DIRNAME(sio_h)
wi_RESOLVE_PATH([$MAINDIR/Strn/Strn.h], [strn_h])
wi_DIRNAME(strn_h)
CPPFLAGS="-I${MAINDIR} -I${libncftp_h} -I${sio_h} -I${strn_h} $CPPFLAGS"
LDFLAGS="-L${libncftp_h} -L${sio_h} -L${strn_h} $LDFLAGS"
wi_BEAUTIFY_ENVIRONMENT_VARIABLES



dnl ---------------------------------------------------------------------------
dnl Extra steps to work with precompiled headers.
dnl ---------------------------------------------------------------------------
dnl
LIBNCFTP_PRECOMP="libncftp/pch.mk.none"
SIO_PRECOMP="sio/pch.mk.none"
if test "${wi_cv_cc_precomp}_${wi_cv_cc_precomp_type}" = "yes_gcc_gch_files" ; then
	LIBNCFTP_PRECOMP="libncftp/pch.mk.gcc-gch"
	SIO_PRECOMP="sio/pch.mk.gcc-gch"
elif test "${wi_cv_cc_precomp}_${SYS}" = "yes_macosx" ; then
	LIBNCFTP_PRECOMP="libncftp/pch.mk.$SYS"
	SIO_PRECOMP="sio/pch.mk.$SYS"
fi
AC_SUBST_FILE(LIBNCFTP_PRECOMP)
AC_SUBST_FILE(SIO_PRECOMP)



dnl ---------------------------------------------------------------------------
dnl Version lookups for Makefile variables.
dnl ---------------------------------------------------------------------------
dnl
changequote(<<, >>)dnl
LIBNCFTP_VERSION=`sed -n '/kLibraryVersion/{
	s/^[^0-9]*//
	s/\ .*$//
	p
	q
}' libncftp/ncftp.h`

NCFTP_VERSION=`sed -n '/gVersion\[\]/{
	s/^[^0-9]*//
	s/\/.*$//
	p
	q
}' ncftp/version.c`

SIO_VERSION=`sed -n '/kSioVersion/{
	s/^[^0-9]*//
	s/\ .*$//
	p
	q
}' sio/sio.h`

STRN_VERSION=`sed -n '/gStrnLibVersion\[\]/{
	s/^[^0-9]*//
	s/\".*$//
	p
	q
}' Strn/Strncpy.c`

Z00="unknown_id"
Z31=''
if [ -x /sbin/md5 ] ; then
	Z00=`hostname | tr '[A-Z]' '[a-z]' | /sbin/md5`
elif [ -x /usr/bin/md5sum ] ; then
	Z00=`hostname -f | tr '[A-Z]' '[a-z]' | /usr/bin/md5sum | cut -d ' ' -f1`
fi

case "$Z00" in
	'e85dfd19937dece65225d717f4cd5f22'|'816c501837158512dc4f606d58f4993b'|'9aa70fa2084f59bab13fe52bdfff65f4')
		Z31='	scp -p "$(STGZFILE)" build@Src:src/ncftp/current/ ; mv ncftp-*-src.* /ztmp/'
		;;
	
esac
changequote([, ])dnl

dnl ---------------------------------------------------------------------------
dnl Create Makefiles and config.h files.
dnl ---------------------------------------------------------------------------
dnl
wi_SUMMARIZE_COMPILER_FLAGS
AC_SUBST(CC)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LIBS)
AC_SUBST(SFLAG)
AC_SUBST(DEFS)
AC_SUBST(MAKE)
AC_SUBST(Z30)
AC_SUBST(Z31)
AC_SUBST(LIBSET)
AC_SUBST(MAINDIR)
AC_SUBST(NCFTP_VERSION)
AC_SUBST(LIBNCFTP_VERSION)
AC_SUBST(SIO_VERSION)
AC_SUBST(STRN_VERSION)
AC_SUBST(VIS_DPROGS)
AC_SUBST(SIZEOF_OFF_T)
AC_SUBST(SIZEOF_ST_SIZE)
AC_OUTPUT_COMMANDS([/bin/rm -f ./ncftp/readln.o])
AC_OUTPUT([Makefile Makefile.bin ncftp/Makefile libncftp/Makefile Strn/Makefile sio/Makefile sh_util/Makefile vis/Makefile])
