dnl configure.in  -  Used to produce a configuration script for netboot
dnl                  programs. Process this file with autoconf to create
dnl                  a configure script.
dnl
dnl Copyright (C) 1996-2007 Gero Kuhlmann
dnl
dnl $Id: configure.ac,v 1.49 2007/02/01 12:09:23 gkminix Exp $
dnl
dnl
dnl ===========================================================================
dnl
dnl Include version information into M4 script. Note that this will only
dnl define M4 macros which substitute to the netboot version. It does
dnl not actually read the version file when the configure script is run.
dnl All version information within the netboot package is derived from
dnl these version macros. It is therefore necessary to re-build the configure
dnl script every time the version information has changed.
dnl
m4_include(nbversion.m4)
m4_if(m4_eval(NB_PATCHLEVEL > 0), 0,
	[m4_define([NB_NBVERSION], [NB_VER_MAJOR.NB_VER_MINOR])],
	[m4_define([NB_NBVERSION], [NB_VER_MAJOR.NB_VER_MINOR.NB_PATCHLEVEL])])
m4_define([NB_COPYRIGHT], [1995-NB_YEAR G. Kuhlmann])


dnl
dnl Now start the autoconfig game
dnl
AC_REVISION($Revision: 1.49 $)
AC_INIT([netboot], [NB_NBVERSION], [netboot@gkminix.han.de])
AC_PREREQ(2.6)
AC_CONFIG_SRCDIR(version)
AC_CONFIG_AUX_DIR(misc)
AC_CONFIG_LIBOBJ_DIR(nblib)
AC_COPYRIGHT([Copyright (C) NB_COPYRIGHT])


dnl
dnl Define all the files which should be generated by this configure script
dnl
AC_CONFIG_HEADERS(include/config.h)
AC_CONFIG_FILES(make.config include/version.h)


dnl
dnl If libdir or datadir are the same as the default, the user didn't
dnl set them explicitly, so set our own default.
dnl
if test "$libdir" = '${exec_prefix}/lib'; then
	nblibdir='${exec_prefix}/lib/netboot'
else
	nblibdir="$libdir"
fi
AC_SUBST(nblibdir)
if test "$datadir" = '${prefix}/share'; then
	nbdatadir='${prefix}/share/netboot'
else
	if test "$datadir" = '${datarootdir}'; then
		nbdatadir='${datarootdir}/netboot'
	else
		nbdatadir="$datadir"
	fi
fi
AC_SUBST(nbdatadir)


dnl
dnl Process any host information from the command line and determine on what
dnl kind of CPU the utility programs are going to run.
dnl
AC_CANONICAL_HOST
case "$host_cpu" in
changequote(, )dnl
	i[3456]86)	HOSTCPU=i386 ;;
changequote([, ])dnl
	x86_64)		HOSTCPU=i386 ;;
	*)		HOSTCPU="$host_cpu" ;;
esac


dnl
dnl Set a common name for the netboot configuration file
dnl
AC_ARG_ENABLE(config-file,
	AC_HELP_STRING([--enable-config-file],
			[name of netboot config file (default=netboot.config)]),
	[case "$enableval" in
		"yes" | "no" )
			AC_MSG_ERROR(enable-config-file option must specify a file name)
			;;
		"")
			CONFIGFILE="netboot.config"
			;;
		*)
			CONFIGFILE="$enableval"
			;;
	 esac
	],
	[CONFIGFILE="netboot.config"])
AC_SUBST(CONFIGFILE)


dnl
dnl Set version information
dnl
AC_SUBST([VER_MAJOR],	'[NB_VER_MAJOR]')
AC_SUBST([VER_MINOR],	'[NB_VER_MINOR]')
AC_SUBST([NBVERSION],	'[NB_NBVERSION]')
AC_SUBST([COPYRIGHT],	'[NB_COPYRIGHT]')


dnl
dnl ===========================================================================
dnl
dnl Check for C compiler and its options
dnl
tempflags="$CFLAGS"
test "${CFLAGS+set}" = set || CFLAGS="-O"
AC_PROG_CC
if test -z "$tempflags"; then
	AC_CHECK_CC_OPT(-O2, ac_cc_opt_o)
	if test -z "$ac_cc_opt_o"; then
		$as_unset ac_cc_opt_o
		AC_CHECK_CC_OPT(-O, ac_cc_opt_o)
	fi
	CFLAGS="$ac_cc_opt_o"
	AC_PROG_CC_WARNINGS
fi
AC_ISC_POSIX
AC_C_PROTOTYPES
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE


dnl
dnl We need to know some parameters of the system which is going to
dnl execute the mknbi programs so cross-compiling is not possible
dnl
if test "X$cross_compiling" = "Xyes"; then
	AC_MSG_ERROR([can't configure for cross compilation])
fi


dnl
dnl ===========================================================================
dnl
dnl Check for EBCDIC character set
dnl We are unable to compile any target files on non-ASCII systems
dnl
CF_EBCDIC
if test "X$cf_cv_ebcdic" = "Xyes"; then
	with_gnu_cc86="no"
	with_gnu_as86="no"
	with_gnu_ld86="no"
fi


dnl
dnl Check for subdirectories to build makefiles in
dnl
TOOLSUBDIRS="makerom mknbi-dos mknbi-linux mknbi-mgl"
CONFSUBDIRS="makerom"
AC_ARG_ENABLE(bootrom,
	AC_HELP_STRING([--enable-bootrom],
			[enable compiling the bootrom (default=disabled)]),
	[if test "X$enableval" = "Xyes"; then
		if test "X$cf_cv_ebcdic" = "Xyes"; then
			AC_MSG_WARN([Unable to compile bootrom on non-ASCII systems])
		else
			CONFSUBDIRS="$CONFSUBDIRS bootrom"
		fi
	 fi]
	)
AC_ARG_ENABLE(mknbi-dos,
	AC_HELP_STRING([--disable-mknbi-dos],
			[disable compiling mknbi-dos (default=enabled)]),
	[if test "X$enableval" = "Xyes"; then CONFSUBDIRS="$CONFSUBDIRS mknbi-dos"; fi],
	[CONFSUBDIRS="$CONFSUBDIRS mknbi-dos"])
AC_ARG_ENABLE(mknbi-linux,
	AC_HELP_STRING([--disable-mknbi-linux],
			[disable compiling mknbi-linux (default=enabled)]),
	[if test "X$enableval" = "Xyes"; then CONFSUBDIRS="$CONFSUBDIRS mknbi-linux"; fi],
	[CONFSUBDIRS="$CONFSUBDIRS mknbi-linux"])
AC_ARG_ENABLE(mknbi-mgl,
	AC_HELP_STRING([--disable-mknbi-mgl],
			[disable compiling mknbi-mgl (default=enabled)]),
	[if test "X$enableval" = "Xyes"; then CONFSUBDIRS="$CONFSUBDIRS mknbi-mgl"; fi],
	[CONFSUBDIRS="$CONFSUBDIRS mknbi-mgl"])
AC_SUBST(CONFSUBDIRS)
AC_SUBST(TOOLSUBDIRS)


dnl
dnl ===========================================================================
dnl
dnl check for required programs
dnl
am_aux_dir=`cd $ac_aux_dir && pwd`
test "X${MISSING+set}" = "Xset" || MISSING="\${SHELL} $am_aux_dir/missing"
if eval "$MISSING --run true"; then
	ac_missing="$MISSING --run "
else
	ac_missing=":"
	AC_MSG_WARN(['missing' script is too old or not available])
fi
AC_PROG_EGREP
AC_PROG_INSTALL
AC_PROG_AWK
AC_PROG_CPP
AC_CHECK_PROGS(AR, ar, :)
AC_CHECK_PROGS(YACC, 'bison -y' byacc yacc, [$ac_missing yacc])
AC_PROG_LEX
if test "x$LEX" = "x:"; then
	# In case lex or flex are missing, we use the precompiled flex source
	if test "X$cf_cv_ebcdic" = "Xyes"; then
		AC_MSG_ERROR([lex or flex required for non-ASCII systems])
	fi
	LEX="$ac_missing flex"
	LEXLIB=""
	ac_cv_prog_lex_root="lex.yy"
	LEX_OUTPUT_ROOT="$ac_cv_prog_lex_root"
	if test "X$ac_cv_prog_lex_yytext_pointer" != "Xyes"; then
		ac_cv_prog_lex_yytext_pointer=yes
		AC_DEFINE(YYTEXT_POINTER, 1)
	fi
fi


dnl
dnl Initialize libtool. We always build static libraries.
dnl
tagnames=""
AC_ENABLE_STATIC(yes)
AC_ENABLE_SHARED(yes)
AC_LIBTOOL_DLOPEN
AC_PROG_LIBTOOL
AC_SUBST(LIBTOOL_DEPS)
AC_LIB_PREFIX


dnl
dnl ===========================================================================
dnl
dnl check for i386 GNU C compiler (either generic or cross-compiler) for
dnl building 16-bit programs
dnl
AH_TEMPLATE(HAVE_USED_ATTRIBUTE,
	[Define if GNU i386 supports the "used" function attribute])
AH_TEMPLATE(HAVE_ALWAYS_INLINE_ATTRIBUTE,
	[Define if GNU i386 supports the "always_inline" function attribute])
AC_ARG_VAR(GCC86, [GNU C compiler command for i386 target])
AC_ARG_VAR(CPP86, [GNU C pre-processor command for i386 target])
AC_ARG_WITH(gnu-cc86,
	AC_HELP_STRING([--with-gnu-cc86],
				[specify path of i386 GNU C compiler]),
	[case "$withval" in
		"yes" )
			AC_MSG_ERROR(with-gnu-cc86 option must specify a file name)
			;;
		"no" )
			GCC86="none"
			;;
		*)
			GCC86="$withval"
			;;
	 esac
	])

# determine if we have to look for an i386 C cross compiler
case $HOSTCPU in
	i386)
		AC_MSG_CHECKING(for GNU C compiler)
		CCNAMES="gnu-cc"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}gcc"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}gcc3*"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}cc"
		CCPATH="$PATH"
		;;
	*)
		AC_MSG_CHECKING(for i386 GNU C compiler)
changequote(, )dnl
		CCNAMES="i[3456]86-*-cc"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}i[3456]86-*-gcc"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}gnu-cc"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}gcc"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}gcc3*"
		CCNAMES="${CCNAMES}${PATH_SEPARATOR}cc"
		CCPATH="/usr/i[3456]86-*/bin"
		CCPATH="${CCPATH}${PATH_SEPARATOR}/usr/local/i[3456]86-*/bin"
		CCPATH="${CCPATH}${PATH_SEPARATOR}${PATH}"
changequote([, ])dnl
		;;
esac

# search for all files which look like a suitable compiler
if test -z "$GCC86"; then
	CCFILES=""
	NB_PATH_WALK([$CCPATH], [
changequote(, )dnl
		ac_files=`echo "$ac_dir/$CCNAMES" | \
				sed -e "s,[$PATH_SEPARATOR], $ac_dir/,g"`
changequote([, ])dnl
		for ac_prog in $ac_files
		do
			for ac_exec_ext in '' $ac_executable_extensions
			do
				if test -x "$ac_prog$ac_exec_ext"; then
					CCFILES="$CCFILES $ac_prog$ac_exec_ext"
				fi
			done
		done
	])
else
	# the user is always right
	if test "$GCC86" != "none"; then
changequote(, )dnl
		CCFILES=`echo "$GCC86" | sed -e "s,[$PATH_SEPARATOR], ,g"`
changequote([, ])dnl
	else
		CCFILES=""
	fi
fi

# check each file if it supports the i386 target
GCC86="none"
GCC86_AS=""
GCC86_LD=""
for ac_prog in $CCFILES
do
	# check each compiler if it is GNU and supports a i386 target
	cc86_help_string="`$ac_prog --help 2>&1 </dev/null`"
	if (echo "$cc86_help_string" | $EGREP '(gcc|GCC)' >/dev/null); then
		# determine target and version of compiler
changequote(, )dnl
		cc86_version=`$ac_prog -dumpversion 2>&1 | \
				sed -n -e '1s/^\([0-9]\{1,\}\)\..*$/\1/p'`
		cc86_target=`$ac_prog -dumpmachine 2>&1`
		if test -z "$cc86_target"; then
			cc86_target=`uname -m`"-"
		fi
		cc86_target=`echo "$cc86_target" | \
				sed -n -e '1s/^i[3456]86-.*$/i386/p'`
changequote([, ])dnl
		test "${cc86_version+set}" = set || cc86_version="0"
		test "${cc86_target+set}" = set || cc86_target="none"

		# we need at least version 3 and a i386 target
		if test "$cc86_version" -ge 3 && \
		   test "$cc86_target" = "i386" && \
		   test "$GCC86" = "none"; then
			# determine assembler and linker used by compiler
changequote(, )dnl
			cc86_as=`$ac_prog -print-prog-name=as 2>&1 | sed -e '
					:begin
					s/\/[^/]\{1,\}\/\.\.\//\//
					t begin
					q'`
			cc86_ld=`$ac_prog -print-prog-name=ld 2>&1 | sed -e '
					:begin
					s/\/[^/]\{1,\}\/\.\.\//\//
					t begin
					q'`
changequote([, ])dnl
			if test -x "$cc86_as"; then
				GCC86_AS="$cc86_as"
			else
				NB_PATH_WALK([$PATH], [
					if test -x "$ac_dir/$cc86_as"; then
						GCC86_AS="$ac_dir/$cc86_as"
						break
					fi
				])
			fi
			if test -x "$cc86_ld"; then
				GCC86_LD="$cc86_ld"
			else
				NB_PATH_WALK([$PATH], [
					if test -x "$ac_dir/$cc86_ld"; then
						GCC86_LD="$ac_dir/$cc86_ld"
						break
					fi
				])
			fi
			if test -n "$GCC86_AS" && test -n "$GCC86_LD"; then
				GCC86="$ac_prog"
				break
			fi
		fi
	fi
done
if test "${GCC86-none}" = "none"; then
	GCC86="none"
	CPP86="none"
	GCC86_TARGET_FLAGS=""
	AC_MSG_RESULT(no)
else
	if test "${CPP86-none}" = "none"; then
		CPP86="$GCC86 -E"
	fi
	# Newer versions of GCC support the "used" function attribute
	NB_CHECK_COMP([GCC86 -c -Werror -x c], [
__attribute__((used)) void demo()
{
  static int a = 1;
}

int main()
{
  return 0;
}
	], [
		AC_DEFINE(HAVE_USED_ATTRIBUTE)
	])
	# Newer versions of GCC support the "always_inline" function attribute
	NB_CHECK_COMP([GCC86 -c -Werror -x c], [
__attribute__((always_inline)) static inline int demo()
{
  return 0;
}

int main()
{
  return(demo());
}
	], [
		AC_DEFINE(HAVE_ALWAYS_INLINE_ATTRIBUTE)
		GCC86_TARGET_FLAGS="-finline-functions"
	], [
		GCC86_TARGET_FLAGS="-finline-limit=10000"
	])
	# The so called hardened GNU toolchain produces code to protect for
	# stack manipulation and position-independent executables. Both
	# concepts are not only unnecessary for the boot loader code, but can
	# also break everything. We therefore have to detect this situation
	# and disable any such features.
	NB_CHECK_COMP([GCC86 -c -x c -fno-pie], [void f(){}], [
		GCC86_TARGET_FLAGS="$GCC86_TARGET_FLAGS -fno-pie"
	])
	NB_CHECK_COMP([GCC86 -c -x c -fno-stack-protector], [void f(){}], [
		GCC86_TARGET_FLAGS="$GCC86_TARGET_FLAGS -fno-stack-protector"
	])
	NB_CHECK_COMP([GCC86 -c -x c -fno-stack-protector-all], [void f(){}], [
		GCC86_TARGET_FLAGS="$GCC86_TARGET_FLAGS -fno-stack-protector-all"
	])
	AC_MSG_RESULT($GCC86)
fi
AC_SUBST(GCC86_TARGET_FLAGS)


dnl
dnl ===========================================================================
dnl
dnl check for i386 GNU assembler (either generic or cross-assembler) for
dnl building 16-bit programs
dnl
AH_TEMPLATE(GAS_NEED_DATA32,
	[Define if GNU i386 assembler needs data32 prefix for movzx/movsx])
AH_TEMPLATE(GAS_NEED_FLAT,
	[Define if GNU i386 assembler needs flat prefix for immediate values])
AH_TEMPLATE(HAVE_ARCH_I386,
	[Define if GNU i386 assembler supports .arch pseudo-opcode])
AC_ARG_VAR(GAS86, [GNU C assembler command for i386 target])
AC_ARG_WITH(gnu-as86,
	AC_HELP_STRING([--with-gnu-as86],
				[specify path of i386 GNU assembler]),
	[case "$withval" in
		"yes" )
			AC_MSG_ERROR(with-gnu-as86 option must specify a file name)
			;;
		"no" )
			GAS86="none"
			;;
		*)
			GAS86="$withval"
			;;
	 esac
	])

# determine if we have to look for an i386 cross assembler
case $HOSTCPU in
	i386)
		AC_MSG_CHECKING(for GNU assembler)
		ASNAMES="gnu-as"
		ASNAMES="${ASNAMES}${PATH_SEPARATOR}gas"
		ASNAMES="${ASNAMES}${PATH_SEPARATOR}as"
		ASPATH="$PATH"
		;;
	*)
		AC_MSG_CHECKING(for i386 GNU assembler)
changequote(, )dnl
		ASNAMES="i[3456]86-*-as"
		ASNAMES="${ASNAMES}${PATH_SEPARATOR}i[3456]86-*-gas"
		ASNAMES="${ASNAMES}${PATH_SEPARATOR}gnu-as"
		ASNAMES="${ASNAMES}${PATH_SEPARATOR}gas"
		ASNAMES="${ASNAMES}${PATH_SEPARATOR}as"
		ASPATH="/usr/i[3456]86-*/bin"
		ASPATH="${ASPATH}${PATH_SEPARATOR}/usr/local/i[3456]86-*/bin"
		ASPATH="${ASPATH}${PATH_SEPARATOR}${PATH}"
changequote([, ])dnl
		;;
esac

# search for all files which look like a suitable assembler
if test -z "$GAS86"; then
	ASFILES="$GCC86_AS"
	NB_PATH_WALK([$ASPATH], [
changequote(, )dnl
		ac_files=`echo "$ac_dir/$ASNAMES" | \
					sed -e "s,[$PATH_SEPARATOR], $ac_dir/,g"`
changequote([, ])dnl
		for ac_prog in $ac_files
		do
			for ac_exec_ext in '' $ac_executable_extensions
			do
				if test -x "$ac_prog$ac_exec_ext"; then
					ASFILES="$ASFILES $ac_prog$ac_exec_ext"
				fi
			done
		done
	])
else
	# the user is always right
	if test "$GAS86" != "none"; then
changequote(, )dnl
		ASFILES=`echo "$GAS86" | sed -e "s,[$PATH_SEPARATOR], ,g"`
changequote([, ])dnl
	else
		ASFILES=""
	fi
fi

# check each file if it supports the i386 target
GAS86="none"
GAS86TARGET=""
GAS86EMUL=""
for ac_prog in $ASFILES
do
	# check each assembler if it is GNU and supports a i386 target
	as_version_string="`$ac_prog --version 2>&1 </dev/null`"
	if (echo "$as_version_string" | $EGREP '(GNU|with BFD)' >/dev/null); then
		# determine target of assembler
changequote(, )dnl
		as_target=`echo "$as_version_string" | \
				sed -n -e '/target of/!d
				           s/[ 	][ 	]*/ /g
					   s/.*target of *\`//
					   s/'\''.*$//
					   p'`
		as_target_cpu=`echo "$as_target" | \
				sed -n -e 's/^\([^-]\{1,\}\)-.*$/\1/p'`
		as_target_man=`echo "$as_target" | \
				sed -n -e 's/^[^-]\{1,\}-\([^-]\{1,\}\).*$/\1/p'`
		as_target_os=`echo "$as_target" | \
				sed -n -e 's/^[^-]\{1,\}-[^-]\{1,\}-\([^-]\{1,\}\).*$/\1/p'`
changequote([, ])dnl
		case "$as_target_cpu" in
			i386 | i486 | i586 | i686)
				as_target_cpu="i386"
				as_target_flags=""
				;;
			x86_64)
				as_target_cpu="i386"
				as_target_flags="--32"
				;;
			*)
				as_target_flags=""
				;;
		esac
		if test -z "$as_target_os"; then
			as_target_os="$as_target_man"
			as_target_man="unknown"
		fi
		as_target="${as_target_cpu}-${as_target_man}-${as_target_os}"
		echo "$as_me: program $ac_prog supports target $as_target" >&AS_MESSAGE_LOG_FD

		# this list has been taken from GNU binutils source code
		# note: do NOT change the order of entries in here!
		case "$as_target" in
			i386-*-beospe*)
				as_target_obj="pei-i386"
				as_target_emul="i386beos"
				;;
			i386-*-beos*)
				as_target_obj="elf32-i386"
				as_target_emul="elf_i386"
				;;
			i386-*-winnt* | \
			i386-*-pe | \
			i386-*-cygwin* | \
			i386-*-mingw32*)
				as_target_obj="pei-i386"
				as_target_emul="i386pe"
				;;
			i386-*-interix*)
				as_target_obj="pei-i386"
				as_target_emul="i386pe"
				;;
			i386-*-bsd* | \
			i386-*-freebsdaout* | \
			i386-*-freebsd[12].* | \
			i386-*-freebsd[12])
				as_target_obj="a.out-i386-bsd"
				as_target_emul="i386bsd"
				;;
			i386-*-netbsd* | \
			i386-*-openbsd*)
				as_target_obj="a.out-i386-netbsd"
				as_target_emul="i386nbsd"
				;;
			i386-obrien-freebsd*)
				as_target_obj="elf32-i386"
				as_target_emul="elf_i386"
				;;
			i386-*-freebsd* | \
			i386-*-linux-gnu* | \
			i386-*-sysv[45]* | \
			i386-*-solaris*)
				as_target_obj="elf32-i386"
				as_target_emul="elf_i386"
				;;
			i386-*-linux*aout* | \
			i386-*-linux*oldld)
				as_target_obj="a.out-i386-linux"
				as_target_emul="i386linux"
				;;
			i386-*-lynxos*)
				as_target_obj="coff-i386-lynx"
				as_target_emul="i386lynx"
				;;
			i386-*-aix* | \
			i386-*-linux*coff* | \
			i386-*-sysv* | \
			i386-*-sco3.2* | \
			i386-*-isc*)
				as_target_obj="coff-i386"
				as_target_emul="i386coff"
				;;
			i386-*-rtemself* | \
			i386-*-linux | \
			i386-*-elf* | \
			i386-*-gnu*)
				as_target_obj="elf32-i386"
				as_target_emul="elf_i386"
				;;
			i386-*-msdosdjgpp* | \
			i386-*-go32* | \
			i386-go32-rtems*)
				as_target_obj="coff-go32"
				as_target_emul="i386go32"
				;;
			i386-*-rtems* | \
			i386-*-coff)
				as_target_obj="coff-i386"
				as_target_emul="i386coff"
				;;
			i386-*-msdos)
				as_target_obj="a.out-i386"
				as_target_emul="i386msdos"
				;;
			i386-*-mach*)
				as_target_obj="a.out-mach3"
				as_target_emul="i386mach"
				;;
			i386-*-moss*)
				as_target_obj="elf32-i386"
				as_target_emul="i386moss"
				;;
			i386-*-vxworks* | \
			i386-*-aout)
				as_target_obj="a.out-i386"
				as_target_emul="i386aout"
				;;
			i386-*-chaos)
				as_target_obj="elf32-i386"
				as_target_emul="elf_i386"
				;;
			*)
				as_target_obj=""
				as_target_emul=""
				;;
		esac
		if test -n "$as_target_obj" && test -n "$as_target_emul"; then
			NB_CHECK_COMP([ac_prog $as_target_flags], [
.intel_syntax noprefix
.code16
.text
_start:	mov	ax,0
	mov	es,ax
	mov	ebx,[dat1]
	mov	si,offset dat1
	ret
.data
dat1:	.long	0x123
			], [
				if test "$GAS86" = "none"; then
					GAS86="$ac_prog"
					GAS86TARGET="$as_target_obj"
					GAS86EMUL="$as_target_emul"
					GAS86_TARGET_FLAGS="$as_target_flags"
				else
					# prefer elf over a.out over coff
					# over pei
					case "$GAS86TARGET/$as_target_obj" in
						a.out-*/elf32-* | \
						coff-*/elf32-* | \
						pei-*/elf32-* | \
						coff-*/a.out-* | \
						pei-*/a.out-* | \
						pei-*/coff-*)
						  GAS86="$ac_prog"
						  GAS86TARGET="$as_target_obj"
						  GAS86EMUL="$as_target_emul"
						  GAS86_TARGET_FLAGS="$as_target_flags"
						  ;;
					esac
				fi
			])
		fi
	fi
done
if test "${GAS86-none}" = "none" ; then
	GAS86="none"
	GAS86_TARGET_FLAGS=""
	AC_MSG_RESULT(no)
else
	# Some versions of GAS have problems with movzx/movsx as they
	# need a data32 prefix
	NB_CHECK_COMP([GAS86 $GAS86_TARGET_FLAGS], [
.intel_syntax noprefix
.code16
.text
_start:	mov	ax,0
 data32	movzx	ebx,ax
	ret
	], [
		AC_DEFINE(GAS_NEED_DATA32)
	])

	# New versions of GAS correctly interpret immediate equates so they
	# dont need the "flat" construct. Actually, they complain about the
	# use of "flat" in such cases, so we can use this behaviour to deter-
	# mine whether we have a "new" GAS.
	NB_CHECK_COMP([GAS86 $GAS86_TARGET_FLAGS], [
.intel_syntax noprefix
.code16
.text
.equ	t,2
_start:	mov	ax,flat t
	ret
	], [
		AC_DEFINE(GAS_NEED_FLAT)
	])

	# Some versions of GAS have problems with .arch pseudo-opcode
	NB_CHECK_COMP([GAS86 $GAS86_TARGET_FLAGS], [
.intel_syntax noprefix
.arch i386
.code16
.text
_start:	mov	ax,0
	ret
	], [
		AC_DEFINE(HAVE_ARCH_I386)
	])

	# We need a target format which supports arbitrary segment
	# names.
	case "$GAS86TARGET" in
		elf32-* | coff-* | pei-*)
			AC_MSG_RESULT($GAS86)
			;;
		*)
			GAS86="none"
			GAS86_TARGET_FLAGS=""
			AC_MSG_RESULT(no)
			;;
	esac
fi
AC_SUBST(GAS86_TARGET_FLAGS)


dnl
dnl ===========================================================================
dnl
dnl check for i386 GNU linker to produce 16-bit i386 programs
dnl
AC_ARG_VAR(GLD86, [GNU C linker command for i386 target])
AC_ARG_WITH(gnu-ld86,
	AC_HELP_STRING([--with-gnu-ld86],
				[specify path of i386 GNU linker]),
	[case "$withval" in
		"yes" )
			AC_MSG_ERROR(with-gnu-ld86 option must specify a file name)
			;;
		"no" )
			GLD86="none"
			;;
		*)
			GLD86="$withval"
			;;
	 esac
	])

# determine if we have to look for an i386 cross linker
case $HOSTCPU in
	i386)
		AC_MSG_CHECKING(for GNU linker)
		LDNAMES="gnu-ld"
		LDNAMES="${LDNAMES}${PATH_SEPARATOR}gld"
		LDNAMES="${LDNAMES}${PATH_SEPARATOR}ld"
		LDPATH="$PATH"
		;;
	*)
		AC_MSG_CHECKING(for GNU linker supporting i386)
changequote(, )dnl
		LDNAMES="i[3456]86-*-ld"
		LDNAMES="${LDNAMES}${PATH_SEPARATOR}i[3456]86-*-gld"
		LDNAMES="${LDNAMES}${PATH_SEPARATOR}gnu-ld"
		LDNAMES="${LDNAMES}${PATH_SEPARATOR}gld"
		LDNAMES="${LDNAMES}${PATH_SEPARATOR}ld"
		LDPATH="/usr/i[3456]86-*/bin"
		LDPATH="${LDPATH}${PATH_SEPARATOR}/usr/local/i[3456]86-*/bin"
		LDPATH="${LDPATH}${PATH_SEPARATOR}${PATH}"
changequote([, ])dnl
		;;
esac

# search for all files which look like a suitable linker
if test -z "$GLD86"; then
	LDFILES="$GCC86_LD"
	NB_PATH_WALK([$LDPATH], [
changequote(, )dnl
		ac_files=`echo "$ac_dir/$LDNAMES" | \
					sed -e "s,[$PATH_SEPARATOR], $ac_dir/,g"`
changequote([, ])dnl
		for ac_prog in $ac_files
		do
			for ac_exec_ext in '' $ac_executable_extensions
			do
				if test -x "$ac_prog$ac_exec_ext"; then
					LDFILES="$LDFILES $ac_prog$ac_exec_ext"
				fi
			done
		done
	])
else
	# the user is always right
	if test "$GLD86" != "none"; then
changequote(, )dnl
		LDFILES=`echo "$GLD86" | sed -e "s,[$PATH_SEPARATOR], ,g"`
changequote([, ])dnl
	else
		LDFILES=""
	fi
fi

# check each file if it supports the i386 target
GLD86="none"
GNUELF="nognu"
FIRST_EMUL=""
for ac_prog in $LDFILES
do
	# check each linker if it is GNU and supports a i386 target
	ld_version_string="`$ac_prog -v 2>&1`"
	if (echo "$ld_version_string" | $EGREP '(GNU|with BFD)' >/dev/null); then
		# determine linker emulations and targets
		ld_help_string="`$ac_prog --help 2>&1`"
changequote(, )dnl
		ld_emul=`echo "$ld_help_string" | \
				sed -n -e '/supported emulations:/!d
				           s/[ 	][ 	]*/ /g
					   s/.*supported emulations: *//
					   p'`
		ld_targets=`echo "$ld_help_string" | \
				sed -n -e '/supported targets:/!d
				           s/[ 	][ 	]*/ /g
					   s/.*supported targets: *//
					   p'`
changequote([, ])dnl
		# check that linker supports emulation required for assembler
		ld_has_emul="no"
		for i in $ld_emul
		do
			# strip trailing text off of certain emulation names
			case "$i" in
				elf_i386*)
					cur_emul="elf_i386"
					;;
				i386pe*)
					cur_emul="i386pe"
					;;
				*)
					cur_emul="$i"
					;;
			esac
			# check if linker supports required emulation
			if test -z "$FIRST_EMUL"; then
				FIRST_EMUL="$cur_emul"
			fi
			if test "$cur_emul" = "$GAS86EMUL"; then
				ld_has_emul="yes"
				break
			fi
		done
		# check that linker supports input and output targets
		ld_has_binary_target="no"
		ld_has_input_target="no"
		ld_has_elf_target="no"
		for i in $ld_targets
		do
			test "$i" = "$GAS86TARGET" && ld_has_input_target="yes"
			test "$i" = "binary" && ld_has_binary_target="yes"
			test "$i" = "elf32-i386" && ld_has_elf_target="yes"
		done
		if test "$ld_has_elf_target"; then
			GNUELF="gnu"
		fi
		if test "$ld_has_emul" = "yes" && \
		   test "$ld_has_binary_target" = "yes" && \
		   test "$ld_has_input_target" = "yes"; then
			GLD86="$ac_prog"
			break
		fi
	fi
done
if test "${GLD86-none}" = "none" ; then
	GLD86="none"
	GLD86_TARGET_FLAGS=""
	AC_MSG_RESULT(no)
else
	if test "$FIRST_EMUL" = "$GAS86EMUL"; then
		# native linker
		GLD86_TARGET_FLAGS=""
	else
		# cross linker
		GLD86_TARGET_FLAGS="-m $GAS86EMUL -b $GAS86TARGET"
	fi
	AC_MSG_RESULT($GLD86)
fi
AC_SUBST(GLD86_TARGET_FLAGS)


dnl
dnl ===========================================================================
dnl
dnl check for some other GNU programs required for building 16 bit programs
dnl also check if we have to recreate the target system library
dnl
if test "$GCC86" = "none" || \
   test "$GAS86" = "none" || \
   test "$GLD86" = "none"; then
	GNU16BIT="nognu"
	GNUELF="nognu"
	AC_MSG_WARN([Can't compile i86 modules, using default])
else
	GNU16BIT="gnu"
fi
if test "$GNU16BIT" = "gnu"; then
	CONFSUBDIRS="i386 $CONFSUBDIRS"
fi
AC_SUBST(GNU16BIT)
AC_SUBST(GNUELF)


dnl
dnl ===========================================================================
dnl
dnl Save what we found so far
dnl
AC_CACHE_SAVE


dnl
dnl ===========================================================================
dnl
dnl always set _GNU_SOURCE so that we can detect GNU extensions if
dnl available
dnl
AC_DEFINE(_GNU_SOURCE, 1, [Always include GNU extensions if available])


dnl
dnl ===========================================================================
dnl
dnl check for header files
dnl
AC_HEADER_STDC
AC_HEADER_STAT
AC_HEADER_TIME
AC_HEADER_DIRENT
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS([getopt.h malloc.h netdb.h assert.h limits.h paths.h pwd.h \
	locale.h langinfo.h \
	sys/time.h sys/param.h sys/bitypes.h sys/file.h \
	sys/select.h sys/poll.h \
	netinet/in.h arpa/inet.h],
	[], [], [AC_INCLUDES_DEFAULT()])


dnl
dnl ===========================================================================
dnl
dnl see if errno must be declared even when we include errno.h
dnl note that errno.h is standard, and according to the autoconf
dnl documentation there is no need to check for errno.h
dnl
AH_TEMPLATE(NEED_DECLARATION_ERRNO,
	[Define if errno must be declared even when <errno.h> is included])
AC_CACHE_CHECK([whether errno must be declared], ac_cv_declare_errno, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <errno.h>], [
				int x = errno
			])], ac_cv_declare_errno=no,
			    ac_cv_declare_errno=yes,
			    ac_cv_declare_errno=no)
])
if test $ac_cv_declare_errno = yes; then
	AC_DEFINE(NEED_DECLARATION_ERRNO)
fi


dnl
dnl ===========================================================================
dnl
dnl check for structures and types
dnl
AC_STRUCT_TM
AC_TYPE_SIGNAL
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_TYPE_UID_T
AC_TYPE_MODE_T

AH_TEMPLATE(HAVE_INTPTR_T,
		[Define to 1 if intptr_t defined by <stdint.h> or <unistd.h>])
if test $ac_cv_header_stdint_h = yes; then
	AC_CHECK_TYPE(intptr_t, [AC_DEFINE(HAVE_INTPTR_T)], )
else
	if test $ac_cv_header_unistd_h = yes; then
		AC_CHECK_TYPE(intptr_t, [AC_DEFINE(HAVE_INTPTR_T)], )
	fi
fi


dnl
dnl ===========================================================================
dnl
dnl check for misc. library functions
dnl
AC_REPLACE_FUNCS([strncmp strstr strspn strcspn strtol \
			memset memcmp vfprintf vsprintf vasprintf])
AC_CHECK_FUNCS([bzero bcopy index rindex memcpy memmove strchr strrchr])

if test $ac_cv_func_memcpy = no && test $ac_cv_func_bcopy = no; then
	AC_LIBOBJ(memcpy)
fi
if test $ac_cv_func_memmove = no && test $ac_cv_func_bcopy = no; then
	AC_LIBOBJ(memmove)
fi
if test $ac_cv_func_strchr = no && test $ac_cv_func_index = no; then
	AC_LIBOBJ(strchr)
fi
if test $ac_cv_func_strrchr = no && test $ac_cv_func_rindex = no; then
	AC_LIBOBJ(strrchr)
fi

AC_CHECK_FUNCS([atexit on_exit], [break])
AC_CHECK_FUNCS([getcwd getwd], [break])
AC_CHECK_FUNCS([waitpid wait3], [break])
AC_CHECK_FUNCS([raise gsignal], [break])
AC_CHECK_FUNCS([select poll], [break])
AC_CHECK_FUNCS([mkdir mkstemp getenv gettimeofday flock setlocale nl_langinfo])
AC_CHECK_FUNC(getopt_long, , [
	AC_LIBOBJ(getopt)
	AC_LIBOBJ(getopt1)
])


dnl
dnl ===========================================================================
dnl
dnl check for network support routines
dnl
if test "X$ISC" = "Xyes"; then
	LIBS="$LIBS -lnsl_s -linet"
else
	AC_CHECK_FUNC(gethostbyname)
	if test $ac_cv_func_gethostbyname = no; then
		AC_CHECK_LIB(nsl, gethostbyname, [LIBS="$LIBS -lnsl"])
	fi
	AC_CHECK_FUNC(inet_ntoa)
	if test $ac_cv_func_inet_ntoa = no; then
		AC_CHECK_LIB(socket, inet_ntoa, [LIBS="-lsocket $LIBS"])
	fi
	AC_CHECK_FUNC(inet_addr)
	if test $ac_cv_func_inet_addr = no; then
		AC_CHECK_LIB(socket, inet_addr, [LIBS="-lsocket $LIBS"])
	fi
fi
AC_SUBST(LIBS)


dnl
dnl ===========================================================================
dnl
dnl check for Berkeley DB support
dnl
AH_TEMPLATE(HAVE_BDB,
	[Define if you have the Berkeley DB library, version 4 or newer])
AH_TEMPLATE(DB_HEADER,
	[Specify file to include for Berkeley DB library])
AC_ARG_WITH(berkeley-db,
		AC_HELP_STRING([--with-berkeley-db],
			[use Berkeley DB support (default=yes)]),
		[ac_cv_use_bdb="$withval"], [ac_cv_use_bdb="yes"])

BDBLIB=""
if test "$ac_cv_use_bdb" != "no"; then
	AX_BERKELEY_DB([4.0.0], [ac_cv_have_bdb=yes], [ac_cv_have_bdb=no])
fi
if test "X$ac_cv_have_bdb" = "Xyes"; then
	AC_LIBOBJ(dbbdb)
	AC_DEFINE(HAVE_BDB)
	BDBLIB="$DB_LIBS"
fi
AC_SUBST(BDBLIB)


dnl
dnl ===========================================================================
dnl
dnl check for unixODBC library support
dnl
AH_TEMPLATE(HAVE_ODBC,
	[Define if you have the unixODBC library])
AC_ARG_WITH(odbc,
		AC_HELP_STRING([--with-odbc],
			[use unixODBC support (default=yes)]),
		[ac_cv_use_odbc="$withval"], [ac_cv_use_odbc="yes"])

ODBC_FLAGS=""
ODBC_PATH="$includedir/odbc:$oldincludedir/odbc:/usr/local/include/odbc:/opt/odbc/include"
ODBCLIB="-lodbc"
if test "$ac_cv_use_odbc" != "no"; then
	if test "$ac_cv_use_odbc" != "yes"; then
		ODBC_FLAGS="-I $ac_cv_use_odbc"
	else
		NB_PATH_WALK([$ODBC_PATH], [
			if test -f "$ac_dir/sql.h"; then
				ODBC_FLAGS="-I $ac_dir"
				break
			fi
		])
	fi
	OLD_CPPFLAGS="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS $ODBC_FLAGS"
	AC_CACHE_CHECK([for unixODBC support], ac_cv_have_odbc, [
		ac_cv_have_odbc=no
		AC_COMPILE_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT()
@%:@include <sql.h>
@%:@if !defined(ODBCVER) || ODBCVER < 0x0300
@%:@error
@%:@endif])],[
			OLD_LIBS="$LIBS"
			LIBS="$ODBCLIB $OLD_LIBS"
			AC_LINK_IFELSE([AC_LANG_CALL([], [SQLConnect])],
					[ac_cv_have_odbc=yes])
			if test "X$ac_cv_have_odbc" != "Xyes"; then
				ODBCLIB="-lunixodbc"
				LIBS="$ODBCLIB $OLD_LIBS"
				AC_LINK_IFELSE([AC_LANG_CALL([], [SQLConnect])],
						[ac_cv_have_odbc=yes])
			fi
			LIBS="$OLD_LIBS"
		])
	])
	CPPFLAGS="$OLD_CPPFLAGS"
fi
if test "X$ac_cv_have_odbc" = "Xyes"; then
	AC_LIBOBJ(dbodbc)
	AC_DEFINE(HAVE_ODBC)
else
	ODBC_FLAGS=""
	ODBCLIB=""
fi
AC_SUBST(ODBCLIB)
AC_SUBST(ODBC_FLAGS)


dnl
dnl ===========================================================================
dnl
dnl check for LZO compression library support
dnl
AH_TEMPLATE(HAVE_LZO,
	[Define if you have the LZO compression library])
AH_TEMPLATE(USE_LZO_VERSION,
	[Define version of LZO library to use])
AC_ARG_WITH(lzo,
		AC_HELP_STRING([--with-lzo],
			[use LZO compression support (default=yes)]),
		[ac_cv_use_lzo="$withval"], [ac_cv_use_lzo="yes"])

LZO_FLAGS=""
LZO_PATH="$includedir/lzo:$oldincludedir/lzo:/usr/local/include/lzo:/opt/lzo/include"
LZOLIB=""
if test "$ac_cv_use_lzo" != "no"; then
	if test "$ac_cv_use_lzo" != "yes"; then
		LZO_FLAGS="-I $ac_cv_use_lzo"
	else
		NB_PATH_WALK([$LZO_PATH], [
			if test -f "$ac_dir/lzoconf.h"; then
				LZO_FLAGS="-I $ac_dir"
				break
			fi
		])
	fi
	OLD_CPPFLAGS="$CPPFLAGS"
	CPPFLAGS="$CPPFLAGS $LZO_FLAGS"
	AC_CACHE_CHECK([for LZO compression support], ac_cv_have_lzo, [
		ac_cv_have_lzo=no
		AC_COMPILE_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT()
@%:@include <lzoconf.h>
@%:@if !defined(LZO_VERSION) || LZO_VERSION < 0x1000
@%:@error
@%:@endif])],[
			AC_COMPILE_IFELSE([AC_LANG_SOURCE([AC_INCLUDES_DEFAULT()
@%:@include <lzoconf.h>
@%:@if !defined(LZO_VERSION) || LZO_VERSION < 0x2000
@%:@error
@%:@endif])],[ac_cv_lzo_version=2],[ac_cv_lzo_version=1])
		],[ac_cv_lzo_version=0])
		OLD_LIBS="$LIBS"
		if test "X$ac_cv_lzo_version" = "X2"; then
			LZOLIB="-llzo2"
			LIBS="$LZOLIB $OLD_LIBS"
			AC_LINK_IFELSE([AC_LANG_CALL([], [lzo_version])],
					[ac_cv_have_lzo=yes],[ac_cv_lzo_version=1])
		fi
		if test "X$ac_cv_lzo_version" = "X1"; then
			LZOLIB="-llzo"
			LIBS="$LZOLIB $OLD_LIBS"
			AC_LINK_IFELSE([AC_LANG_CALL([], [lzo_version])],
					[ac_cv_have_lzo=yes],[ac_cv_lzo_version=0])
		fi
		LIBS="$OLD_LIBS"
	])
	CPPFLAGS="$OLD_CPPFLAGS"
fi
if test "X$ac_cv_have_lzo" = "Xyes"; then
	AC_DEFINE(HAVE_LZO)
	AC_DEFINE_UNQUOTED(USE_LZO_VERSION, [$ac_cv_lzo_version])
else
	LZO_FLAGS=""
	LZOLIB=""
fi
AC_SUBST(LZOLIB)
AC_SUBST(LZO_FLAGS)


dnl
dnl ===========================================================================
dnl
dnl check for compiler characteristics
dnl
AH_TEMPLATE(USE_PACKED,
	[Define if compiler supports __attribute__((packed))])
AH_TEMPLATE(USE_PRAGMA_PACK,
	[Define if compiler supports pragma pack(1)])
AH_TEMPLATE(USE_PRAGMA_ALIGN,
	[Define if compiler supports pragma options align=packed])
AC_CACHE_CHECK([for packed attribute], ac_cv_use_packed, [
	AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
		struct test_struct {
			int i1 __attribute__((packed));
		} t1;
	]])], ac_cv_use_packed=yes,
	      ac_cv_use_packed=no,
	      ac_cv_use_packed=no)
])
if test "$ac_cv_use_packed" = yes; then
	AC_DEFINE(USE_PACKED)
else
	AC_CACHE_CHECK([for pack pragma], ac_cv_use_pragma_pack, [
		AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#pragma pack(1)
			struct {
				char c[3];
				int  i;
			} s;
#pragma pack()
		]],[[
			char *cp1, *cp2;
			cp1 = (char *)(&s.i);
			cp2 = (char *)(&s) + 3;
			exit(cp1 != cp2);
		]])], ac_cv_use_pragma_pack=yes,
		      ac_cv_use_pragma_pack=no,
		      ac_cv_use_pragma_pack=no)
	])
	if test "$ac_cv_use_pragma_pack" = yes; then
		AC_DEFINE(USE_PRAGMA_PACK)
	else
		AC_CACHE_CHECK([for align pragma], ac_cv_use_pragma_align, [
			AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#pragma options align=packed
				struct {
					char c[3];
					int  i;
				} s;
#pragma options align=reset
			]],[[
				char *cp1, *cp2;
				cp1 = (char *)(&s.i);
				cp2 = (char *)(&s) + 3;
				exit(cp1 != cp2);
			]])], ac_cv_use_pragma_align=yes,
			      ac_cv_use_pragma_align=no,
			      ac_cv_use_pragma_align=no)
		])
		if test "$ac_cv_use_pragma_align" = yes; then
			AC_DEFINE(USE_PRAGMA_ALIGN)
		else
			AC_MSG_WARN([Can't find out how to pack structures, programs might not run properly])
			AC_DEFINE(USE_PRAGMA_PACK)
		fi
	fi
fi
AH_TEMPLATE(USE_U_INT,
	[Define if system has u_int8_t, u_int16_t and u_int32_t defined])
AH_TEMPLATE(USE__UXX,
	[Define if system has __u8, __u16 and __u32 defined])
AH_TEMPLATE(U8_TYPE,
	[Set to the type your C compiler uses for 8 bit variables,
	 for example 'unsigned char'. If defined, this will override
	 the type definitiones found in standard header files.])
AH_TEMPLATE(U16_TYPE,
	[Set to the type your C compiler uses for 16 bit variables,
	 for example 'unsigned short'. If defined, this will override
	 the type definitiones found in standard header files.])
AH_TEMPLATE(U32_TYPE,
	[Set to the type your C compiler uses for 32 bit variables,
	 for example 'unsigned long'. If defined, this will override
	 the type definitiones found in standard header files.])
AC_CACHE_CHECK([for definition of __uxx in types.h], ac_cv_use__uxx, [
	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#else
# ifdef HAVE_STDINT_H
#  include <stdint.h>
# endif
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_BITYPES_H
# include <sys/bitypes.h>
#endif]], [[ __u8 u1; __u16 u2; __u32 u3; ]]
		)], ac_cv_use__uxx=yes,
		    ac_cv_use__uxx=no,
		    ac_cv_use__uxx=no)
])
if test "$ac_cv_use__uxx" = yes; then
	AC_DEFINE(USE__UXX)
else
	AC_CACHE_CHECK([for definition of u_intxx_t in types.h], ac_cv_use_u_int, [
		AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#else
# ifdef HAVE_STDINT_H
#  include <stdint.h>
# endif
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_BITYPES_H
# include <sys/bitypes.h>
#endif]], [[ u_int8_t u1; u_int16_t u2; u_int32_t u3; ]]
		)], ac_cv_use_u_int=yes,
		    ac_cv_use_u_int=no,
		    ac_cv_use_u_int=no)
	])
	if test "$ac_cv_use_u_int" = yes; then
		AC_DEFINE(USE_U_INT)
	fi
fi
AC_CHECK_SIZEOF(int *)
AC_CHECK_SIZEOF(unsigned short)
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_SIZEOF(unsigned int)
AC_DEFINE_UNQUOTED(SIZEOF_UNSIGNED, $ac_cv_sizeof_unsigned_int,
					[Same value as SIZEOF_UNSIGNED_INT])


dnl
dnl ===========================================================================
dnl
dnl check for system characteristics
dnl
AH_TEMPLATE(USE_COPY,
	[Define if system cannot access misaligned data and has to use memcpy])
AC_CACHE_CHECK([whether system allows accessing misaligned data], ac_cv_allow_misalign, [
	# Avoid optimizations
	OLD_CFLAGS="$CFLAGS"
	CFLAGS=""
	AC_RUN_IFELSE([AC_LANG_PROGRAM([[
#ifdef USE_PACKED
# define PACKED __attribute__((packed))
#else
# define PACKED
#endif
#ifdef USE_PRAGMA_PACK
# pragma pack(1)
#endif
#ifdef USE_PRAGMA_ALIGN
# pragma options align=packed
#endif
		struct us {
			int  a;
			char c[3];
			int  i;
		} PACKED;
#ifdef USE_PRAGMA_PACK
# pragma pack()
#endif
#ifdef USE_PRAGMA_ALIGN
# pragma options align=reset
#endif
		static struct us s;
		static int ret = 0, *ip;

		static void docheck(i)
		int i;
		{
		  if (i != 1) ret++;
		}
	]],[[
		s.i = 1;
		docheck(s.i);
		ip = (int *)&(s.c[1]);
		*ip = 1;
		docheck(*ip);
		exit(ret);
	]])], ac_cv_allow_misalign=yes,
	      ac_cv_allow_misalign=no,
	      ac_cv_allow_misalign=yes)
	CFLAGS="$OLD_CFLAGS"
])
if test "$ac_cv_allow_misalign" = no; then
	AC_DEFINE(USE_COPY)
fi
AC_C_BIGENDIAN


dnl
dnl ===========================================================================
dnl
dnl now generate everything
dnl
AC_OUTPUT

