#!/bin/sh
#
# Do not edit!
# This file was generated from configure.in by BSDBuild 3.2.
#
# To regenerate this file, get the latest BSDBuild release from
# http://hypertriton.com/bsdbuild/, and use the command:
#
#     $ cat configure.in | mkconfigure > configure
#
# Copyright (c) 2001-2015 Hypertriton, Inc. <http://hypertriton.com/>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
PACKAGE="Untitled"
VERSION=""
RELEASE=""

optarg=
for arg
do
	case "$arg" in
	-*=*)
	    optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'`
	    ;;
	*)
	    optarg=
	    ;;
	esac

	case "$arg" in
	--build=*)
	    build_arg=$optarg
	    ;;
	--host=*)
	    host_arg=$optarg
	    ;;
	--target=*)
	    target=$optarg
	    ;;
	--emul-os=*)
	    PROJ_TARGET=$optarg
	    ;;
	--byte-order=*)
	    byte_order=$optarg
	    ;;
	--prefix=*)
	    prefix=$optarg
	    ;;
	--exec-prefix=*)
	    exec_prefix=$optarg
	    ;;
	--sysconfdir=*)
	    sysconfdir=$optarg
	    ;;
	--bindir=*)
	    bindir=$optarg
	    ;;
	--libdir=*)
	    libdir=$optarg
	    ;;
	--moduledir=*)
	    moduledir=$optarg
	    ;;
	--libexecdir=*)
	    libexecdir=$optarg
	    ;;
	--datadir=*)
	    datadir=$optarg
	    ;;
	--statedir=* | --localstatedir=*)
	    statedir=$optarg
	    ;;
	--localedir=*)
	    localedir=$optarg
	    ;;
	--mandir=*)
	    mandir=$optarg
	    ;;
	--infodir=* | --datarootdir=* | --docdir=* | --htmldir=* | --dvidir=* | --pdfdir=* | --psdir=* | --sharedstatedir=* | --sbindir=*)
	    ;;
	--enable-*)
	    option=`echo $arg | sed -e 's/--enable-//' -e 's/=.*//'`
	    option=`echo $option | sed 's/-/_/g'`
	    case "$arg" in
	        *=*)
	            eval "enable_${option}='$optarg'"
	            eval "prefix_${option}='$optarg'"
		    ;;
		*)
	            eval "enable_${option}=yes"
		    ;;
	    esac
	    ;;
	--disable-*)
	    option=`echo $arg | sed -e 's/--disable-//'`;
	    option=`echo $option | sed 's/-/_/g'`
	    eval "enable_${option}=no"
	    ;;
	--with-*)
	    option=`echo $arg | sed -e 's/--with-//' -e 's/=.*//'`
	    option=`echo $option | sed 's/-/_/g'`
	    case "$arg" in
	        *=*)
	            eval "with_${option}='$optarg'"
	            eval "prefix_${option}='$optarg'"
		    ;;
		*)
	            eval "with_${option}=yes"
		    ;;
	    esac
	    ;;
	--without-*)
	    option=`echo $arg | sed -e 's/--without-//'`;
	    option=`echo $option | sed 's/-/_/g'`
	    eval "with_${option}=no"
	    ;;
	--x-includes=*)
	    with_x_includes=$optarg
	    ;;
	--x-libraries=*)
	    with_x_libraries=$optarg
	    ;;
	--help)
	    show_help=yes
	    ;;
	--version)
	    show_version=yes
	    ;;
	--srcdir=*)
	    srcdir=$optarg
	    ;;
	--testdir=*)
	    testdir=$optarg
	    ;;
	--cache=*)
	    cache=$optarg
	    ;;
	--includes=*)
	    includes=$optarg
	    ;;
	--cache-file=*)
	    ;;
	--config-cache | -C)
	    ;;
	*)
	    echo "invalid argument: $arg"
	    echo "try ./configure --help"
	    exit 1
	    ;;
	esac
done
if [ -e "/bin/echo" ]; then
    /bin/echo -n ""
    if [ $? = 0 ]; then
    	ECHO_N="/bin/echo -n"
    else
    	ECHO_N="echo -n"
    fi
else
    ECHO_N="echo -n"
fi
PERL=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -x "${path}/perl" ]; then
		PERL="${path}/perl"
		break
	fi
done
PKGCONFIG=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -x "${path}/pkg-config" ]; then
		PKGCONFIG="${path}/pkg-config"
		break
	fi
done
if [ "${prefix}" != "" ]; then
    PREFIX="$prefix"
else
    PREFIX="/usr/local"
fi
if [ "${exec_prefix}" != "" ]; then
    EXEC_PREFIX="$exec_prefix"
else
    EXEC_PREFIX="${PREFIX}"
fi
if [ "${srcdir}" != "" ]; then
	if [ "${PERL}" = "" ]; then
		echo "*"
		echo "* Separate build (--srcdir) requires perl, but there is"
		echo "* no perl interpreter to be found in your PATH."
		echo "*"
		exit 1
	fi
	SRC=${srcdir}
else
	SRC=`pwd`
fi
BLD=`pwd`
SRCDIR="${SRC}"
BLDDIR="${BLD}"

if [ "${testdir}" != "" ]; then
	echo "Configure tests will be executed in ${testdir}"
	if [ ! -e "${testdir}" ]; then
		echo "Creating ${testdir}"
		mkdir ${testdir}
	fi
else
	testdir="."
fi
if [ "${includes}" = "" ]; then
	includes="yes"
fi
case "${includes}" in
yes|no)
	;;
link)
	if [ "${with_proj_generation}" ]; then
		echo "Cannot use --includes=link with --with-proj-generation!"
		exit 1
	fi
	;;
*)
	echo "Usage: --includes [yes|no|link]"
	exit 1
	;;
esac
if [ "${srcdir}" = "" ]; then
	cat << EOT > configure.dep.pl
#!/usr/bin/env perl
# Public domain.
# Scan Makefiles for "include .depend" and generate empty ".depend" files,
# such that make can be run prior to an initial "make depend".
#

my %V = ();

sub MakefileIncludesDepend (\$\$)
{
	my \$path = shift;
	my \$cwd = shift;

	if (!open(MF, \$path)) {
		return (0);
	}
	my @lines = ();
	foreach \$_ (<MF>) {
		chop;

		if (/^(.+)\\\\\$/) {			# Expansion
			\$line .= \$1;
		} else {				# New line
			if (\$line) {
				push @lines, \$line . \$_;
				\$line = '';
			} else {
				push @lines, \$_;
			}
		}
	}
	foreach \$_ (@lines) {
		if (/^\\s*#/) { next; }
		if (/^\\t/) { next; }
		s/\\\$\\{(\\w+)\\}/\$V{\$1}/g;
		if (/^\\s*(\\w+)\\s*=\\s*"(.+)"\$/ ||
		    /^\\s*(\\w+)\\s*=\\s*(.+)\$/) {
			\$V{\$1} = \$2;
		} elsif (/^\\s*(\\w+)\\s*\\+=\\s*"(.+)"\$/ ||
		         /^\\s*(\\w+)\\s*\\+=\\s*(.+)\$/) {
			if (exists(\$V{\$1}) && \$V{\$1} ne '') {
				\$V{\$1} .= ' '.\$2;
			} else {
				\$V{\$1} = \$2;
			}
		}
		if (/^\\s*include\\s+(.+)\$/) {
			if (\$1 eq '.depend' ||
			    MakefileIncludesDepend(\$cwd.'/'.\$1, \$cwd)) {
				return (1);
			}
		}
	}
	close(MF);
	return (0);
}

sub Scan (\$)
{
	my \$dir = shift;

	unless (opendir(CWD, \$dir)) {
		print STDERR "\$dir: opendir: \$!; ignoring\\n";
		return;
	}
	%V = ();
	if (-e \$dir.'/Makefile' &&
	    MakefileIncludesDepend("\$dir/Makefile", \$dir)) {
		if (open(OUT, ">\$dir/.depend")) {
			close(OUT);
		} else {
			print STDERR "\$dir/.depend: \$!; ignoring\\n";
		}
	}
	foreach my \$ent (readdir(CWD)) {
		my \$file = \$dir.'/'.\$ent;

		if (\$ent =~ /^\\./) {
			next;
		}
		if (-d \$file) {
			Scan(\$file);
			next;
		}
	}
	closedir(CWD);
}
if (@ARGV < 1) {
	print STDERR "Usage: gen-dotdepend.pl [directory]\\n";
	exit(1);
}
Scan(\$ARGV[0]);
EOT
	if [ "${PERL}" != "" ]; then
		${PERL} configure.dep.pl .
		rm -f configure.dep.pl
	else
		echo "*"
		echo "* Warning: No perl was found. Perl is required for automatic"
		echo "* generation of .depend files. You may need to create empty"
		echo "* .depend files where it is required."
		echo "*"
	fi
fi
if [ "${show_help}" = "yes" ]; then
echo "This configure script was generated by BSDBuild 3.2."
echo "<http://bsdbuild.hypertriton.com/>"
echo ""
echo "Usage: ./configure [options]"
echo ""
echo "Standard build options:"
echo "    --bindir=DIR              Executables for common users [PREFIX/bin]"
echo "    --build=STRING            Host environment for build [auto-detect]"
echo "    --byte-order=STRING       Byte order for build (LE|BE) [auto-detect]"
echo "    --cache=DIR               Cache ./configure results in directory [none]"
echo "    --datadir=DIR|NONE        Data files for program use [PREFIX/share]"
echo "    --enable-nls              Multi-language support [no]"
echo "    --exec-prefix=DIR         Machine-dependent installation base [PREFIX]"
echo "    --host=STRING             Cross-compile for target environment [BUILD]"
echo "    --includes=STRING         Preprocess C headers (yes|no|link) [yes]"
echo "    --libdir=DIR              System libraries [PREFIX/lib]"
echo "    --libexecdir=DIR          Executables for program use [PREFIX/libexec]"
echo "    --localedir=DIR           Multi-language support locales [DATADIR/locale]"
echo "    --mandir=DIR              Manual page documentation [PREFIX/man]"
echo "    --moduledir=DIR|NONE      Dynamically loaded modules [PREFIX/lib]"
echo "    --prefix=DIR              Installation base [/usr/local]"
echo "    --srcdir=DIR              Source directory for concurrent build [.]"
echo "    --statedir=DIR|NONE       Modifiable single-machine data [PREFIX/var]"
echo "    --sysconfdir=DIR|NONE     System configuration files [PREFIX/etc]"
echo "    --testdir=DIR             Execute all tests in this directory [.]"
echo "    --with-bundles            Generate application/library bundles [yes]"
echo "    --with-catman             Install cat files for manual pages [auto-detect]"
echo "    --with-ctags              Generate ctags(1) tag files [no]"
echo "    --with-docs               Generate printable documentation [no]"
echo "    --with-gettext            Use gettext for multi-language [auto-detect]"
echo "    --with-libtool            Specify path to libtool [bundled]"
echo "    --with-manlinks           Add manual entries for every function [no]"
echo "    --with-manpages           Generate Unix manual pages [yes]"
echo ""
echo "Global Agar options:"
echo "    --enable-<library>          Build libraries (gui|vg|math|dev|au) [all]"
echo "    --enable-debug              General debugging [no]"
echo "    --enable-legacy             Deprecated interfaces [yes]"
echo "    --enable-threads            Thread safety [check]"
echo "    --enable-warnings           Suggested compiler warnings [no]"
echo "    --with-pthreads[=PREFIX]    POSIX Threads support [check]"
echo ""
echo "Options specific to CORE library:"
echo "    --enable-debug-core         Expensive AG_Object debugging [no]"
echo "    --enable-network            Network interface [check]"
echo "    --with-db4[=PREFIX]         AG_Db: Berkeley DB backend [check]"
echo "    --with-mysql[=PREFIX]       AG_Db: MySQL backend [no]"
echo "    --with-iconv[=PREFIX]       Character set conversion [check]"
echo ""
echo "Options specific to MATH library:"
echo "    --with-<mode>-fp            Precision (single|double|quad) [double]"
echo "    --with-altivec              AltiVec-optimized routines [check]"
echo "    --with-altivec-inline       Inline Altivec-optimized routines [no]"
echo "    --with-sse                  SSE-optimized routines [check]"
echo "    --with-sse-inline           Inline SSE-optimized routines [no]"
echo "    --without-sse[234]          Disable SSE2/SSE3 [check]"
echo ""
echo "Options specific to AU library:"
echo "    --with-sndfile[=PREFIX]     Enable sndfile support [check]"
echo "    --with-portaudio[=PREFIX]   Enable portaudio driver [check]"
echo ""
echo "Options specific to GUI library:"
echo "    --enable-debug-gui          Expensive GUI debugging [no]"
echo "    --with-freetype[=PREFIX]    Enable FreeType support [check]"
echo "    --with-fontconfig[=PREFIX]  Enable Fontconfig support [check]"
echo "    --with-gl[=PREFIX]          OpenGL rendering support [check]"
echo "    --with-jpeg[=PREFIX]        Built-in JPEG image support [check]"
echo "    --with-png[=PREFIX]         Built-in PNG image support [check]"
echo "    --with-x[=PREFIX]           Build with X windows support [check]"
echo "    --with-xinerama[=PREFIX]    Build with Xinerama support [check]"
echo "    --with-glx[=PREFIX]         Enable accelerated X driver [check]"
echo "    --with-sdl[=PREFIX]         Enable SDL 1.2 driver [check]"
echo "    --with-wgl                  Enable MS Windows driver [check]"
echo "    --with-cocoa                Enable MacOS X Cocoa driver [check]"
echo "    --with-uim[=PREFIX]         Enable UIM input method [no]"
exit 1
fi;
if [ "${show_version}" = "yes" ]; then
echo "BSDBuild 3.2"
exit 0
fi;
if [ "${srcdir}" != "" ]; then
	build_guessed=`sh ${srcdir}/mk/config.guess`
else
	build_guessed=`sh mk/config.guess`
fi
if [ $? != 0 ]; then
	echo "mk/config.guess failed"
	exit 1
fi
if [ "${build_arg}" != "" ]; then
	build="${build_arg}"
else
	build="${build_guessed}"
fi
if [ "${host_arg}" != "" ]; then
	host="${host_arg}"
else
	host="${build}"
fi
if [ "${host}" != "${build_guessed}" ]; then
	CROSS_COMPILING="yes"
else
	CROSS_COMPILING="no"
fi
if [ "${with_bundles}" != "no" ]; then
	case "${host}" in
	arm-apple-darwin*)
		PROG_BUNDLE="iOS"
		;;
	*-*-darwin*)
		PROG_BUNDLE="OSX"
		;;
	esac
fi
echo "BSDBuild 3.2 (http://bsdbuild.hypertriton.com)"

echo "#!/bin/sh" > config.status
echo "# Generated by configure script (BSDBuild 3.2)." >> config.status
echo "Generated by configure script (BSDBuild 3.2)." > config.log

if [ -e "Makefile.config" ]; then
	echo "* Overwriting existing Makefile.config"
fi
echo "# Generated by configure script (BSDBuild 3.2)." > Makefile.config
echo "" >> Makefile.config
echo "BUILD=${build}" >> Makefile.config
echo "HOST=${host}" >> Makefile.config
echo "CROSS_COMPILING=${CROSS_COMPILING}" >> Makefile.config
echo "SRCDIR=${SRC}" >> Makefile.config
echo "BLDDIR=${BLD}" >> Makefile.config

$ECHO_N "./configure" >> config.log
$ECHO_N "./configure" >> config.status
for arg
do
	$ECHO_N " $arg" >> config.log
	$ECHO_N " $arg" >> config.status
done
echo "" >> config.log
echo "" >> config.status
if [ -e "$BLD/include/agar/config" ]; then
	echo "* Overwriting $BLD/include/agar/config directory"
	rm -fR "$BLD/include/agar/config"
fi
mkdir -p "$BLD/include/agar/config"
if [ $? != 0 ]; then
	echo "Could not create $BLD/include/agar/config directory."
	exit 1
fi
cat << EOT > conftest.1
.\" COMMENT
.Dd 
.Dd NOVEMBER 23, 2009
.Dt TEST 1
.Os
.ds vT Test
.ds oS Test 1.0
.Sh NAME
.Nm test
.Nd Test document
.Sh DESCRIPTION
EOT

HAVE_MANDOC="no"
MANDOC=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -x "${path}/mandoc" ]; then
		cat conftest.1 | ${path}/mandoc -Tascii >/dev/null
		if [ "$?" = "0" ]; then
			HAVE_MANDOC="yes"
			MANDOC="${path}/mandoc"
			break;
		fi
	elif [ -x "${path}/nroff" ]; then
		cat conftest.1 | ${path}/nroff -Tmandoc >/dev/null
		if [ "$?" = "0" ]; then
			HAVE_MANDOC="yes"
			MANDOC="${path}/nroff -Tmandoc"
			break;
		fi
	fi
done
rm -f conftest.1

if [ "${HAVE_MANDOC}" = "no" ]; then
	if [ "${with_manpages}" = "yes" ]; then
		echo "*"
		echo "* --with-manpages was requested, but either the"
		echo "* nroff(1)/mandoc(1) utility or the mdoc(7) macro"
		echo "* package were not found."
		echo "*"
		exit 1
	fi
	echo "HAVE_MANDOC=no" >> Makefile.config
	echo "NOMAN=yes" >> Makefile.config
	echo "NOMANLINKS=yes" >> Makefile.config
else
	echo "HAVE_MANDOC=yes" >> Makefile.config
	echo "MANDOC=${MANDOC}" >> Makefile.config
	if [ "${with_catman}" = "no" ]; then
		echo "NOCATMAN=yes" >> Makefile.config
	else
		if [ "${with_catman}" = "yes" ]; then
			echo "NOCATMAN=no" >> Makefile.config
		else
			case "${host}" in
			*-*-freebsd*)
				echo "NOCATMAN=yes" >> Makefile.config
				;;
			*)
				echo "NOCATMAN=no" >> Makefile.config
				;;
			esac
		fi
	fi
	if [ "${with_manpages}" = "no" ]; then
		echo "NOMAN=yes" >> Makefile.config
		echo "NOMANLINKS=yes" >> Makefile.config
	else
		if [ "${with_manlinks}" != "yes" ]; then
			echo "NOMANLINKS=yes" >> Makefile.config
		fi
	fi
fi
if [ "${with_docs}" = "no" ]; then
	echo "NODOC=yes" >> Makefile.config
fi
if [ "${enable_nls}" = "yes" ]; then
ENABLE_NLS="yes"
echo "#ifndef ENABLE_NLS" > $BLD/include/agar/config/enable_nls.h
echo "#define ENABLE_NLS \"$ENABLE_NLS\"" >> $BLD/include/agar/config/enable_nls.h
echo "#endif" >> $BLD/include/agar/config/enable_nls.h
echo "hdefs[\"ENABLE_NLS\"] = \"$ENABLE_NLS\"" >>configure.lua
msgfmt=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -x "${path}/msgfmt" ]; then
		msgfmt=${path}/msgfmt
		break
	fi
done
if [ "${msgfmt}" != "" ]; then
	HAVE_GETTEXT="yes"
else
	HAVE_GETTEXT="no"
fi
echo "#ifndef ENABLE_NLS" > $BLD/include/agar/config/enable_nls.h
echo "#define ENABLE_NLS \"$ENABLE_NLS\"" >> $BLD/include/agar/config/enable_nls.h
echo "#endif" >> $BLD/include/agar/config/enable_nls.h
echo "hdefs[\"ENABLE_NLS\"] = \"$ENABLE_NLS\"" >>configure.lua
else
ENABLE_NLS="no"
HAVE_GETTEXT="no"
echo "#undef ENABLE_NLS" >$BLD/include/agar/config/enable_nls.h
echo "hdefs[\"ENABLE_NLS\"] = nil" >>configure.lua
fi;
CTAGS=""
if [ "${with_ctags}" = "yes" ]; then
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -x "${path}/ectags" ]; then
			CTAGS="${path}/ectags"
			break
		fi
	done
	if [ "${CTAGS}" = "" ]; then
		for path in `echo $PATH | sed 's/:/ /g'`; do
			if [ -x "${path}/ctags" ]; then
				CTAGS="${path}/ctags"
				break
			fi
		done
	fi
fi
echo "CTAGS=${CTAGS}" >> Makefile.config
if [ "${prefix_libtool}" != "" -a "${prefix_libtool}" != "bundled" ]; then
	LIBTOOL_BUNDLED="no"
	LIBTOOL="${prefix_libtool}"
else
	LIBTOOL_BUNDLED="yes"
	LIBTOOL=\${TOP}/mk/libtool/libtool
fi
echo "LIBTOOL_BUNDLED=${LIBTOOL_BUNDLED}" >> Makefile.config
echo "LIBTOOL=${LIBTOOL}" >> Makefile.config
echo "PREFIX?=${PREFIX}" >> Makefile.config
echo "#ifndef PREFIX" > $BLD/include/agar/config/prefix.h
echo "#define PREFIX \"$PREFIX\"" >> $BLD/include/agar/config/prefix.h
echo "#endif" >> $BLD/include/agar/config/prefix.h
echo "hdefs[\"PREFIX\"] = \"$PREFIX\"" >>configure.lua
if [ "${bindir}" != "" ]; then
	BINDIR="${bindir}"
	BINDIR_SPECIFIED="yes"
else
	BINDIR="${PREFIX}/bin"
fi
echo "#ifndef BINDIR" > $BLD/include/agar/config/bindir.h
echo "#define BINDIR \"$BINDIR\"" >> $BLD/include/agar/config/bindir.h
echo "#endif" >> $BLD/include/agar/config/bindir.h
echo "hdefs[\"BINDIR\"] = \"$BINDIR\"" >>configure.lua
if [ "${libdir}" != "" ]; then
	LIBDIR="${libdir}"
	LIBDIR_SPECIFIED="yes"
else
	LIBDIR="${PREFIX}/lib"
fi
echo "#ifndef LIBDIR" > $BLD/include/agar/config/libdir.h
echo "#define LIBDIR \"$LIBDIR\"" >> $BLD/include/agar/config/libdir.h
echo "#endif" >> $BLD/include/agar/config/libdir.h
echo "hdefs[\"LIBDIR\"] = \"$LIBDIR\"" >>configure.lua
if [ "${moduledir}" != "" ]; then
	MODULEDIR="${moduledir}"
	MODULEDIR_SPECIFIED="yes"
else
	MODULEDIR="${PREFIX}/lib"
fi
echo "#ifndef MODULEDIR" > $BLD/include/agar/config/moduledir.h
echo "#define MODULEDIR \"$MODULEDIR\"" >> $BLD/include/agar/config/moduledir.h
echo "#endif" >> $BLD/include/agar/config/moduledir.h
echo "hdefs[\"MODULEDIR\"] = \"$MODULEDIR\"" >>configure.lua
if [ "${libexecdir}" != "" ]; then
	LIBEXECDIR="${libexecdir}"
	LIBEXECDIR_SPECIFIED="yes"
else
	LIBEXECDIR="${PREFIX}/libexec"
fi
echo "#ifndef LIBEXECDIR" > $BLD/include/agar/config/libexecdir.h
echo "#define LIBEXECDIR \"$LIBEXECDIR\"" >> $BLD/include/agar/config/libexecdir.h
echo "#endif" >> $BLD/include/agar/config/libexecdir.h
echo "hdefs[\"LIBEXECDIR\"] = \"$LIBEXECDIR\"" >>configure.lua
if [ "${datadir}" != "" ]; then
	DATADIR="${datadir}"
	DATADIR_SPECIFIED="yes"
else
	DATADIR="${PREFIX}/share"
fi
echo "#ifndef DATADIR" > $BLD/include/agar/config/datadir.h
echo "#define DATADIR \"$DATADIR\"" >> $BLD/include/agar/config/datadir.h
echo "#endif" >> $BLD/include/agar/config/datadir.h
echo "hdefs[\"DATADIR\"] = \"$DATADIR\"" >>configure.lua
if [ "${statedir}" != "" ]; then
	STATEDIR="${statedir}"
	STATEDIR_SPECIFIED="yes"
else
	STATEDIR="${PREFIX}/var"
fi
echo "#ifndef STATEDIR" > $BLD/include/agar/config/statedir.h
echo "#define STATEDIR \"$STATEDIR\"" >> $BLD/include/agar/config/statedir.h
echo "#endif" >> $BLD/include/agar/config/statedir.h
echo "hdefs[\"STATEDIR\"] = \"$STATEDIR\"" >>configure.lua
if [ "${sysconfdir}" != "" ]; then
	SYSCONFDIR="${sysconfdir}"
	SYSCONFDIR_SPECIFIED="yes"
else
	SYSCONFDIR="${PREFIX}/etc"
fi
echo "#ifndef SYSCONFDIR" > $BLD/include/agar/config/sysconfdir.h
echo "#define SYSCONFDIR \"$SYSCONFDIR\"" >> $BLD/include/agar/config/sysconfdir.h
echo "#endif" >> $BLD/include/agar/config/sysconfdir.h
echo "hdefs[\"SYSCONFDIR\"] = \"$SYSCONFDIR\"" >>configure.lua
if [ "${localedir}" != "" ]; then
	LOCALEDIR="${localedir}"
	LOCALEDIR_SPECIFIED="yes"
else
	LOCALEDIR="${DATADIR}/locale"
fi
echo "#ifndef LOCALEDIR" > $BLD/include/agar/config/localedir.h
echo "#define LOCALEDIR \"$LOCALEDIR\"" >> $BLD/include/agar/config/localedir.h
echo "#endif" >> $BLD/include/agar/config/localedir.h
echo "hdefs[\"LOCALEDIR\"] = \"$LOCALEDIR\"" >>configure.lua
if [ "${mandir}" != "" ]; then
	MANDIR="${mandir}"
	MANDIR_SPECIFIED="yes"
else
	MANDIR="${PREFIX}/man"
fi
echo "#ifndef MANDIR" > $BLD/include/agar/config/mandir.h
echo "#define MANDIR \"$MANDIR\"" >> $BLD/include/agar/config/mandir.h
echo "#endif" >> $BLD/include/agar/config/mandir.h
echo "hdefs[\"MANDIR\"] = \"$MANDIR\"" >>configure.lua
PACKAGE="Agar"
echo "#ifndef PACKAGE" > $BLD/include/agar/config/package.h
echo "#define PACKAGE \"$PACKAGE\"" >> $BLD/include/agar/config/package.h
echo "#endif" >> $BLD/include/agar/config/package.h
echo "hdefs[\"PACKAGE\"] = \"$PACKAGE\"" >>configure.lua
VERSION="1.5.0"
echo "#ifndef VERSION" > $BLD/include/agar/config/version.h
echo "#define VERSION \"$VERSION\"" >> $BLD/include/agar/config/version.h
echo "#endif" >> $BLD/include/agar/config/version.h
echo "hdefs[\"VERSION\"] = \"$VERSION\"" >>configure.lua
RELEASE="A Mild Breeze upon the Brow of the Dead"
echo "#ifndef RELEASE" > $BLD/include/agar/config/release.h
echo "#define RELEASE \"$RELEASE\"" >> $BLD/include/agar/config/release.h
echo "#endif" >> $BLD/include/agar/config/release.h
echo "hdefs[\"RELEASE\"] = \"$RELEASE\"" >>configure.lua
if [ "${DATADIR_SPECIFIED}" != "yes" ]; then
DATADIR="${PREFIX}/share/agar"
echo "#ifndef DATADIR" > $BLD/include/agar/config/datadir.h
echo "#define DATADIR \"$DATADIR\"" >> $BLD/include/agar/config/datadir.h
echo "#endif" >> $BLD/include/agar/config/datadir.h
echo "hdefs[\"DATADIR\"] = \"$DATADIR\"" >>configure.lua
fi;
if [ "${LOCALEDIR_SPECIFIED}" != "yes" ]; then
LOCALEDIR="${DATADIR}/locale"
echo "#ifndef LOCALEDIR" > $BLD/include/agar/config/localedir.h
echo "#define LOCALEDIR \"$LOCALEDIR\"" >> $BLD/include/agar/config/localedir.h
echo "#endif" >> $BLD/include/agar/config/localedir.h
echo "hdefs[\"LOCALEDIR\"] = \"$LOCALEDIR\"" >>configure.lua
fi;
if [ "${TTFDIR_SPECIFIED}" != "yes" ]; then
TTFDIR="${DATADIR}/fonts"
echo "#ifndef TTFDIR" > $BLD/include/agar/config/ttfdir.h
echo "#define TTFDIR \"$TTFDIR\"" >> $BLD/include/agar/config/ttfdir.h
echo "#endif" >> $BLD/include/agar/config/ttfdir.h
echo "hdefs[\"TTFDIR\"] = \"$TTFDIR\"" >>configure.lua
fi;
if [ "${INCLDIR_SPECIFIED}" != "yes" ]; then
INCLDIR="${PREFIX}/include/agar"
echo "#ifndef INCLDIR" > $BLD/include/agar/config/incldir.h
echo "#define INCLDIR \"$INCLDIR\"" >> $BLD/include/agar/config/incldir.h
echo "#endif" >> $BLD/include/agar/config/incldir.h
echo "hdefs[\"INCLDIR\"] = \"$INCLDIR\"" >>configure.lua
fi;
if [ "${DATADIR}" = "NONE" ]
 then
LOCALEDIR="NONE"
echo "#ifndef LOCALEDIR" > $BLD/include/agar/config/localedir.h
echo "#define LOCALEDIR \"$LOCALEDIR\"" >> $BLD/include/agar/config/localedir.h
echo "#endif" >> $BLD/include/agar/config/localedir.h
echo "hdefs[\"LOCALEDIR\"] = \"$LOCALEDIR\"" >>configure.lua
LOCALEDIR="NONE"
TTFDIR="NONE"
echo "#ifndef TTFDIR" > $BLD/include/agar/config/ttfdir.h
echo "#define TTFDIR \"$TTFDIR\"" >> $BLD/include/agar/config/ttfdir.h
echo "#endif" >> $BLD/include/agar/config/ttfdir.h
echo "hdefs[\"TTFDIR\"] = \"$TTFDIR\"" >>configure.lua
TTFDIR="NONE"
fi
$ECHO_N "checking for a C compiler..."
$ECHO_N "checking for a C compiler..." >> config.log
if [ "$CROSS_COMPILING" = "yes" ]; then
	CROSSPFX="${host}-"
else
	CROSSPFX=""
fi
if [ "$CC" = "" ]; then
	for i in `echo $PATH |sed 's/:/ /g'`; do
		if [ -x "${i}/${CROSSPFX}cc" ]; then
			if [ -f "${i}/${CROSSPFX}cc" ]; then
				CC="${i}/${CROSSPFX}cc"
				break
			fi
		elif [ -x "${i}/${CROSSPFX}gcc" ]; then
			if [ -f "${i}/${CROSSPFX}gcc" ]; then
				CC="${i}/${CROSSPFX}gcc"
				break
			fi
		fi
	done
	if [ "$CC" = "" ]; then
		echo "*"
		echo "* Cannot find ${CROSSPFX}cc or ${CROSSPFX}gcc in default PATH."
		echo "* You may need to set the CC environment variable."
		echo "*"
		echo "Cannot find ${CROSSPFX}cc or ${CROSSPFX}gcc in PATH." >> config.log
		HAVE_CC="no"
		echo "no"
	else
		HAVE_CC="yes"
		echo "yes, ${CC}"
		echo "yes, ${CC}" >> config.log
	fi
else
	HAVE_CC="yes"
	echo "using ${CC}"
fi

if [ "${HAVE_CC}" = "yes" ]; then
	$ECHO_N "checking whether the C compiler works..."
	$ECHO_N "checking whether the C compiler works..." >> config.log
	cat << 'EOT' > conftest.c
int main(int argc, char *argv[]) { return (0); }
EOT
	$CC -o conftest conftest.c 2>>config.log
	if [ $? != 0 ]; then
	    echo "no"
	    echo "no (test failed to compile)" >> config.log
		HAVE_CC="no"
	else
		HAVE_CC="yes"
	fi

	if [ "${HAVE_CC}" = "yes" ]; then
		if [ "${EXECSUFFIX}" = "" ]; then
			EXECSUFFIX=""
			for OUTFILE in conftest.exe conftest conftest.*; do
				if [ -f $OUTFILE ]; then
					case $OUTFILE in
					*.c | *.cc | *.m | *.o | *.obj | *.bb | *.bbg | *.d | *.pdb | *.tds | *.xcoff | *.dSYM | *.xSYM )
						;;
					*.* )
						EXECSUFFIX=`expr "$OUTFILE" : '[^.]*\(\..*\)'`
						break ;;
					* )
						break ;;
					esac;
			    fi
			done
			if [ "$EXECSUFFIX" != "" ]; then
				echo "yes (it outputs $EXECSUFFIX files)"
				echo "yes (it outputs $EXECSUFFIX files)" >> config.log
			else
				echo "yes"
				echo "yes" >> config.log
			fi
echo "#ifndef EXECSUFFIX" > $BLD/include/agar/config/execsuffix.h
echo "#define EXECSUFFIX \"$EXECSUFFIX\"" >> $BLD/include/agar/config/execsuffix.h
echo "#endif" >> $BLD/include/agar/config/execsuffix.h
echo "hdefs[\"EXECSUFFIX\"] = \"$EXECSUFFIX\"" >>configure.lua
		else
			echo "yes"
			echo "yes" >> config.log
		fi
	fi
	rm -f conftest.c conftest$EXECSUFFIX
	TEST_CFLAGS=""
fi
if [ "${HAVE_CC}" = "yes" ]; then
$ECHO_N "cc: checking for compiler warning options..."
$ECHO_N "cc: checking for compiler warning options..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int main(int argc, char *argv[]) { return (0); }

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CC_WARNINGS="yes"
echo "#ifndef HAVE_CC_WARNINGS" > $BLD/include/agar/config/have_cc_warnings.h
echo "#define HAVE_CC_WARNINGS \"$HAVE_CC_WARNINGS\"" >> $BLD/include/agar/config/have_cc_warnings.h
echo "#endif" >> $BLD/include/agar/config/have_cc_warnings.h
echo "hdefs[\"HAVE_CC_WARNINGS\"] = \"$HAVE_CC_WARNINGS\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CC_WARNINGS="no"
echo "#undef HAVE_CC_WARNINGS" >$BLD/include/agar/config/have_cc_warnings.h
echo "hdefs[\"HAVE_CC_WARNINGS\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_CC_WARNINGS}" = "yes" ]; then
TEST_CFLAGS="-Wall -Werror"
fi;
$ECHO_N "cc: checking for long double..."
$ECHO_N "cc: checking for long double..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
int
main(int argc, char *argv[])
{
	long double ld = 0.1;

	printf("%Lf", ld);
	return (ld == 1.0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_LONG_DOUBLE="yes"
echo "#ifndef HAVE_LONG_DOUBLE" > $BLD/include/agar/config/have_long_double.h
echo "#define HAVE_LONG_DOUBLE \"$HAVE_LONG_DOUBLE\"" >> $BLD/include/agar/config/have_long_double.h
echo "#endif" >> $BLD/include/agar/config/have_long_double.h
echo "hdefs[\"HAVE_LONG_DOUBLE\"] = \"$HAVE_LONG_DOUBLE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_LONG_DOUBLE="no"
echo "#undef HAVE_LONG_DOUBLE" >$BLD/include/agar/config/have_long_double.h
echo "hdefs[\"HAVE_LONG_DOUBLE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "cc: checking for long long..."
$ECHO_N "cc: checking for long long..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int
main(int argc, char *argv[])
{
	long long ll = -1;
	unsigned long long ull = 1;

	return (ll != -1 || ull != 1);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_LONG_LONG="yes"
echo "#ifndef HAVE_LONG_LONG" > $BLD/include/agar/config/have_long_long.h
echo "#define HAVE_LONG_LONG \"$HAVE_LONG_LONG\"" >> $BLD/include/agar/config/have_long_long.h
echo "#endif" >> $BLD/include/agar/config/have_long_long.h
echo "hdefs[\"HAVE_LONG_LONG\"] = \"$HAVE_LONG_LONG\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_LONG_LONG="no"
echo "#undef HAVE_LONG_LONG" >$BLD/include/agar/config/have_long_long.h
echo "hdefs[\"HAVE_LONG_LONG\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "cc: checking for cygwin environment..."
$ECHO_N "cc: checking for cygwin environment..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/stat.h>
#include <windows.h>

int
main(int argc, char *argv[]) {
	struct stat sb;
	DWORD rv;
	rv = GetFileAttributes("foo");
	stat("foo", &sb);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -mcygwin -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -mcygwin -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CYGWIN="yes"
echo "#ifndef HAVE_CYGWIN" > $BLD/include/agar/config/have_cygwin.h
echo "#define HAVE_CYGWIN \"$HAVE_CYGWIN\"" >> $BLD/include/agar/config/have_cygwin.h
echo "#endif" >> $BLD/include/agar/config/have_cygwin.h
echo "hdefs[\"HAVE_CYGWIN\"] = \"$HAVE_CYGWIN\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CYGWIN="no"
echo "#undef HAVE_CYGWIN" >$BLD/include/agar/config/have_cygwin.h
echo "hdefs[\"HAVE_CYGWIN\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "cc: checking for -mwindows option..."
$ECHO_N "cc: checking for -mwindows option..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <windows.h>
int
main(int argc, char *argv[]) {
	return GetFileAttributes("foo") ? 0 : 1;
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -mwindows -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -mwindows -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CC_MWINDOWS="yes"
echo "#ifndef HAVE_CC_MWINDOWS" > $BLD/include/agar/config/have_cc_mwindows.h
echo "#define HAVE_CC_MWINDOWS \"$HAVE_CC_MWINDOWS\"" >> $BLD/include/agar/config/have_cc_mwindows.h
echo "#endif" >> $BLD/include/agar/config/have_cc_mwindows.h
echo "hdefs[\"HAVE_CC_MWINDOWS\"] = \"$HAVE_CC_MWINDOWS\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CC_MWINDOWS="no"
echo "#undef HAVE_CC_MWINDOWS" >$BLD/include/agar/config/have_cc_mwindows.h
echo "hdefs[\"HAVE_CC_MWINDOWS\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
if [ "${HAVE_CC_MWINDOWS}" = "yes" ]; then
PROG_GUI_FLAGS="-mwindows"
else
PROG_GUI_FLAGS=""
fi;
$ECHO_N "cc: checking for -mconsole option..."
$ECHO_N "cc: checking for -mconsole option..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <windows.h>
int
main(int argc, char *argv[]) {
	return GetFileAttributes("foo") ? 0 : 1;
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -mconsole -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -mconsole -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CC_MCONSOLE="yes"
echo "#ifndef HAVE_CC_MCONSOLE" > $BLD/include/agar/config/have_cc_mconsole.h
echo "#define HAVE_CC_MCONSOLE \"$HAVE_CC_MCONSOLE\"" >> $BLD/include/agar/config/have_cc_mconsole.h
echo "#endif" >> $BLD/include/agar/config/have_cc_mconsole.h
echo "hdefs[\"HAVE_CC_MCONSOLE\"] = \"$HAVE_CC_MCONSOLE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CC_MCONSOLE="no"
echo "#undef HAVE_CC_MCONSOLE" >$BLD/include/agar/config/have_cc_mconsole.h
echo "hdefs[\"HAVE_CC_MCONSOLE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
if [ "${HAVE_CC_MCONSOLE}" = "yes" ]; then
PROG_CLI_FLAGS="-mconsole"
else
PROG_CLI_FLAGS=""
fi;
case "${host}" in
*-*-cygwin* | *-*-mingw32*)
$ECHO_N "cc: checking for linker -no-undefined option..."
$ECHO_N "cc: checking for linker -no-undefined option..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int main(int argc, char *argv[]) { return (0); }

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -Wl,--no-undefined -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -Wl,--no-undefined -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_LD_NO_UNDEFINED="yes"
echo "#ifndef HAVE_LD_NO_UNDEFINED" > $BLD/include/agar/config/have_ld_no_undefined.h
echo "#define HAVE_LD_NO_UNDEFINED \"$HAVE_LD_NO_UNDEFINED\"" >> $BLD/include/agar/config/have_ld_no_undefined.h
echo "#endif" >> $BLD/include/agar/config/have_ld_no_undefined.h
echo "hdefs[\"HAVE_LD_NO_UNDEFINED\"] = \"$HAVE_LD_NO_UNDEFINED\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_LD_NO_UNDEFINED="no"
echo "#undef HAVE_LD_NO_UNDEFINED" >$BLD/include/agar/config/have_ld_no_undefined.h
echo "hdefs[\"HAVE_LD_NO_UNDEFINED\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
if [ "${HAVE_LD_NO_UNDEFINED}" = "yes" ]; then
LIBTOOLOPTS_SHARED="${LIBTOOLOPTS_SHARED} -no-undefined -Wl,--no-undefined"
fi;
$ECHO_N "cc: checking for linker -static-libgcc option..."
$ECHO_N "cc: checking for linker -static-libgcc option..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int main(int argc, char *argv[]) { return (0); }

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -static-libgcc -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -static-libgcc -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_LD_STATIC_LIBGCC="yes"
echo "#ifndef HAVE_LD_STATIC_LIBGCC" > $BLD/include/agar/config/have_ld_static_libgcc.h
echo "#define HAVE_LD_STATIC_LIBGCC \"$HAVE_LD_STATIC_LIBGCC\"" >> $BLD/include/agar/config/have_ld_static_libgcc.h
echo "#endif" >> $BLD/include/agar/config/have_ld_static_libgcc.h
echo "hdefs[\"HAVE_LD_STATIC_LIBGCC\"] = \"$HAVE_LD_STATIC_LIBGCC\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_LD_STATIC_LIBGCC="no"
echo "#undef HAVE_LD_STATIC_LIBGCC" >$BLD/include/agar/config/have_ld_static_libgcc.h
echo "hdefs[\"HAVE_LD_STATIC_LIBGCC\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
if [ "${HAVE_LD_STATIC_LIBGCC}" = "yes" ]; then
LIBTOOLOPTS_SHARED="${LIBTOOLOPTS_SHARED} -XCClinker -static-libgcc"
fi;
;;
esac
fi;
if [ "${HAVE_CC}" != "yes" ]; then
echo "* "
echo "* " >> config.log
echo "* This software requires cc installed on your system."
echo "* This software requires cc installed on your system." >> config.log
echo "* "
echo "* " >> config.log
echo "configure failed!"
exit 1
fi;
$ECHO_N "checking for aligned attribute..."
$ECHO_N "checking for aligned attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int main(int argc, char *argv[])
{
	struct s1 { int x,y,z; } __attribute__ ((aligned(16)));
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ALIGNED_ATTRIBUTE="yes"
echo "#ifndef HAVE_ALIGNED_ATTRIBUTE" > $BLD/include/agar/config/have_aligned_attribute.h
echo "#define HAVE_ALIGNED_ATTRIBUTE \"$HAVE_ALIGNED_ATTRIBUTE\"" >> $BLD/include/agar/config/have_aligned_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_aligned_attribute.h
echo "hdefs[\"HAVE_ALIGNED_ATTRIBUTE\"] = \"$HAVE_ALIGNED_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ALIGNED_ATTRIBUTE="no"
echo "#undef HAVE_ALIGNED_ATTRIBUTE" >$BLD/include/agar/config/have_aligned_attribute.h
echo "hdefs[\"HAVE_ALIGNED_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for __bounded__ attribute..."
$ECHO_N "checking for __bounded__ attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
void foostring(char *, int) __attribute__ ((__bounded__(__string__,1,2)));
void foostring(char *a, int c) { }
void foobuffer(void *, int) __attribute__ ((__bounded__(__buffer__,1,2)));
void foobuffer(void *a, int c) { }
int main(void)
{
	char buf[32];
	foostring(buf, sizeof(buf));
	foobuffer(buf, sizeof(buf));
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_BOUNDED_ATTRIBUTE="yes"
echo "#ifndef HAVE_BOUNDED_ATTRIBUTE" > $BLD/include/agar/config/have_bounded_attribute.h
echo "#define HAVE_BOUNDED_ATTRIBUTE \"$HAVE_BOUNDED_ATTRIBUTE\"" >> $BLD/include/agar/config/have_bounded_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_bounded_attribute.h
echo "hdefs[\"HAVE_BOUNDED_ATTRIBUTE\"] = \"$HAVE_BOUNDED_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_BOUNDED_ATTRIBUTE="no"
echo "#undef HAVE_BOUNDED_ATTRIBUTE" >$BLD/include/agar/config/have_bounded_attribute.h
echo "hdefs[\"HAVE_BOUNDED_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for const attribute..."
$ECHO_N "checking for const attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int foo(int) __attribute__ ((const));
int foo(int x) { return (x*x); }
int main(int argc, char *argv[])
{
	int x = foo(1);
	return (x);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CONST_ATTRIBUTE="yes"
echo "#ifndef HAVE_CONST_ATTRIBUTE" > $BLD/include/agar/config/have_const_attribute.h
echo "#define HAVE_CONST_ATTRIBUTE \"$HAVE_CONST_ATTRIBUTE\"" >> $BLD/include/agar/config/have_const_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_const_attribute.h
echo "hdefs[\"HAVE_CONST_ATTRIBUTE\"] = \"$HAVE_CONST_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CONST_ATTRIBUTE="no"
echo "#undef HAVE_CONST_ATTRIBUTE" >$BLD/include/agar/config/have_const_attribute.h
echo "hdefs[\"HAVE_CONST_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for deprecated attribute..."
$ECHO_N "checking for deprecated attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
void foo(void) __attribute__ ((deprecated));
void foo(void) { }

int main(int argc, char *argv[])
{
/*	foo(); */
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_DEPRECATED_ATTRIBUTE="yes"
echo "#ifndef HAVE_DEPRECATED_ATTRIBUTE" > $BLD/include/agar/config/have_deprecated_attribute.h
echo "#define HAVE_DEPRECATED_ATTRIBUTE \"$HAVE_DEPRECATED_ATTRIBUTE\"" >> $BLD/include/agar/config/have_deprecated_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_deprecated_attribute.h
echo "hdefs[\"HAVE_DEPRECATED_ATTRIBUTE\"] = \"$HAVE_DEPRECATED_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_DEPRECATED_ATTRIBUTE="no"
echo "#undef HAVE_DEPRECATED_ATTRIBUTE" >$BLD/include/agar/config/have_deprecated_attribute.h
echo "hdefs[\"HAVE_DEPRECATED_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for __format__ attribute..."
$ECHO_N "checking for __format__ attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdarg.h>
void foo1(char *, ...)
     __attribute__((__format__ (printf, 1, 2)));
void foo2(char *, ...)
     __attribute__((__format__ (__printf__, 1, 2)))
     __attribute__((__nonnull__ (1)));
void foo1(char *a, ...) {}
void foo2(char *a, ...) {}
int main(int argc, char *argv[])
{
	foo1("foo %s", "bar");
	foo2("foo %d", 1);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_FORMAT_ATTRIBUTE="yes"
echo "#ifndef HAVE_FORMAT_ATTRIBUTE" > $BLD/include/agar/config/have_format_attribute.h
echo "#define HAVE_FORMAT_ATTRIBUTE \"$HAVE_FORMAT_ATTRIBUTE\"" >> $BLD/include/agar/config/have_format_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_format_attribute.h
echo "hdefs[\"HAVE_FORMAT_ATTRIBUTE\"] = \"$HAVE_FORMAT_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_FORMAT_ATTRIBUTE="no"
echo "#undef HAVE_FORMAT_ATTRIBUTE" >$BLD/include/agar/config/have_format_attribute.h
echo "hdefs[\"HAVE_FORMAT_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for __nonnull__ attribute..."
$ECHO_N "checking for __nonnull__ attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
void foo(char *) __attribute__((__nonnull__ (1)));
void foo(char *a) { }
int main(int argc, char *argv[])
{
	foo("foo");
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_NONNULL_ATTRIBUTE="yes"
echo "#ifndef HAVE_NONNULL_ATTRIBUTE" > $BLD/include/agar/config/have_nonnull_attribute.h
echo "#define HAVE_NONNULL_ATTRIBUTE \"$HAVE_NONNULL_ATTRIBUTE\"" >> $BLD/include/agar/config/have_nonnull_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_nonnull_attribute.h
echo "hdefs[\"HAVE_NONNULL_ATTRIBUTE\"] = \"$HAVE_NONNULL_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_NONNULL_ATTRIBUTE="no"
echo "#undef HAVE_NONNULL_ATTRIBUTE" >$BLD/include/agar/config/have_nonnull_attribute.h
echo "hdefs[\"HAVE_NONNULL_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for noreturn attribute..."
$ECHO_N "checking for noreturn attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <unistd.h>
#include <stdlib.h>
void foo(void) __attribute__ ((noreturn));
void foo(void) { _exit(0); }
int main(int argc, char *argv[])
{
	foo();
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_NORETURN_ATTRIBUTE="yes"
echo "#ifndef HAVE_NORETURN_ATTRIBUTE" > $BLD/include/agar/config/have_noreturn_attribute.h
echo "#define HAVE_NORETURN_ATTRIBUTE \"$HAVE_NORETURN_ATTRIBUTE\"" >> $BLD/include/agar/config/have_noreturn_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_noreturn_attribute.h
echo "hdefs[\"HAVE_NORETURN_ATTRIBUTE\"] = \"$HAVE_NORETURN_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_NORETURN_ATTRIBUTE="no"
echo "#undef HAVE_NORETURN_ATTRIBUTE" >$BLD/include/agar/config/have_noreturn_attribute.h
echo "hdefs[\"HAVE_NORETURN_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for packed attribute..."
$ECHO_N "checking for packed attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int main(int argc, char *argv[])
{
	struct s1 { char c; int x,y,z; } __attribute__ ((packed));
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PACKED_ATTRIBUTE="yes"
echo "#ifndef HAVE_PACKED_ATTRIBUTE" > $BLD/include/agar/config/have_packed_attribute.h
echo "#define HAVE_PACKED_ATTRIBUTE \"$HAVE_PACKED_ATTRIBUTE\"" >> $BLD/include/agar/config/have_packed_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_packed_attribute.h
echo "hdefs[\"HAVE_PACKED_ATTRIBUTE\"] = \"$HAVE_PACKED_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PACKED_ATTRIBUTE="no"
echo "#undef HAVE_PACKED_ATTRIBUTE" >$BLD/include/agar/config/have_packed_attribute.h
echo "hdefs[\"HAVE_PACKED_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for pure attribute..."
$ECHO_N "checking for pure attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int foo(int) __attribute__ ((pure));
int foo(int x) { return (x*x); }
int main(int argc, char *argv[])
{
	int x = foo(1);
	return (x);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PURE_ATTRIBUTE="yes"
echo "#ifndef HAVE_PURE_ATTRIBUTE" > $BLD/include/agar/config/have_pure_attribute.h
echo "#define HAVE_PURE_ATTRIBUTE \"$HAVE_PURE_ATTRIBUTE\"" >> $BLD/include/agar/config/have_pure_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_pure_attribute.h
echo "hdefs[\"HAVE_PURE_ATTRIBUTE\"] = \"$HAVE_PURE_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PURE_ATTRIBUTE="no"
echo "#undef HAVE_PURE_ATTRIBUTE" >$BLD/include/agar/config/have_pure_attribute.h
echo "hdefs[\"HAVE_PURE_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for warn_unused_result attribute..."
$ECHO_N "checking for warn_unused_result attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int foo(void) __attribute__ ((warn_unused_result));
int foo(void) { return (1); }
int main(int argc, char *argv[])
{
	int rv = foo();
	return (rv);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_WARN_UNUSED_RESULT_ATTRIBUTE="yes"
echo "#ifndef HAVE_WARN_UNUSED_RESULT_ATTRIBUTE" > $BLD/include/agar/config/have_warn_unused_result_attribute.h
echo "#define HAVE_WARN_UNUSED_RESULT_ATTRIBUTE \"$HAVE_WARN_UNUSED_RESULT_ATTRIBUTE\"" >> $BLD/include/agar/config/have_warn_unused_result_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_warn_unused_result_attribute.h
echo "hdefs[\"HAVE_WARN_UNUSED_RESULT_ATTRIBUTE\"] = \"$HAVE_WARN_UNUSED_RESULT_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_WARN_UNUSED_RESULT_ATTRIBUTE="no"
echo "#undef HAVE_WARN_UNUSED_RESULT_ATTRIBUTE" >$BLD/include/agar/config/have_warn_unused_result_attribute.h
echo "hdefs[\"HAVE_WARN_UNUSED_RESULT_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for unused variable attribute..."
$ECHO_N "checking for unused variable attribute..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
int main(int argc, char *argv[])
{
	int __attribute__ ((unused)) variable;
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_UNUSED_VARIABLE_ATTRIBUTE="yes"
echo "#ifndef HAVE_UNUSED_VARIABLE_ATTRIBUTE" > $BLD/include/agar/config/have_unused_variable_attribute.h
echo "#define HAVE_UNUSED_VARIABLE_ATTRIBUTE \"$HAVE_UNUSED_VARIABLE_ATTRIBUTE\"" >> $BLD/include/agar/config/have_unused_variable_attribute.h
echo "#endif" >> $BLD/include/agar/config/have_unused_variable_attribute.h
echo "hdefs[\"HAVE_UNUSED_VARIABLE_ATTRIBUTE\"] = \"$HAVE_UNUSED_VARIABLE_ATTRIBUTE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_UNUSED_VARIABLE_ATTRIBUTE="no"
echo "#undef HAVE_UNUSED_VARIABLE_ATTRIBUTE" >$BLD/include/agar/config/have_unused_variable_attribute.h
echo "hdefs[\"HAVE_UNUSED_VARIABLE_ATTRIBUTE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for an Objective-C compiler..."
$ECHO_N "checking for an Objective-C compiler..." >> config.log
if [ "$CROSS_COMPILING" = "yes" ]; then
	CROSSPFX="${host}-"
else
	CROSSPFX=""
fi
if [ "$OBJC" = "" ]; then
	if [ "$CC" != "" ]; then
		OBJC="$CC"
		HAVE_OBJC="yes"
		echo "using CC (${OBJC})"
	else
		for i in `echo $PATH |sed 's/:/ /g'`; do
			if [ -x "${i}/${CROSSPFX}cc" ]; then
				if [ -f "${i}/${CROSSPFX}cc" ]; then
					OBJC="${i}/${CROSSPFX}cc"
					break
				fi
			elif [ -x "${i}/${CROSSPFX}gcc" ]; then
				if [ -f "${i}/${CROSSPFX}gcc" ]; then
					OBJC="${i}/${CROSSPFX}gcc"
					break
				fi
			fi
		done
		if [ "$OBJC" = "" ]; then
		    echo "*"
		    echo "* Cannot find ${CROSSPFX}objc or ${CROSSPFX}gcc in default PATH."
		    echo "* You may need to set the OBJC environment variable."
		    echo "*"
		    echo "Cannot find ${CROSSPFX}objc or ${CROSSPFX}gcc in PATH." >> config.log
			HAVE_OBJC="no"
			echo "no"
		else
			HAVE_OBJC="yes"
			echo "yes, ${OBJC}"
			echo "yes, ${OBJC}" >> config.log
		fi
	fi
else
	HAVE_OBJC="yes"
	echo "using ${OBJC}"
fi

if [ "${HAVE_OBJC}" = "yes" ]; then
	$ECHO_N "checking whether the Objective-C compiler works..."
	$ECHO_N "checking whether the Objective-C compiler works..." >> config.log
	cat << 'EOT' > conftest.m
#import <stdio.h>
int main(int argc, char *argv[]) { return (0); }
EOT
	$OBJC -x objective-c -o conftest conftest.m 2>>config.log
	if [ $? != 0 ]; then
	    echo "no"
	    echo "no (test failed to compile)" >> config.log
		HAVE_OBJC="no"
	else
		HAVE_OBJC="yes"
	fi
	
	if [ "${HAVE_OBJC}" = "yes" ]; then
		if [ "${EXECSUFFIX}" = "" ]; then
			EXECSUFFIX=""
			for OUTFILE in conftest.exe conftest conftest.*; do
				if [ -f $OUTFILE ]; then
					case $OUTFILE in
					*.c | *.cc | *.m | *.o | *.obj | *.bb | *.bbg | *.d | *.pdb | *.tds | *.xcoff | *.dSYM | *.xSYM )
						;;
					*.* )
						EXECSUFFIX=`expr "$OUTFILE" : '[^.]*\(\..*\)'`
						break ;;
					* )
						break ;;
					esac;
			    fi
			done
			if [ "$EXECSUFFIX" != "" ]; then
				echo "yes (it outputs $EXECSUFFIX files)"
				echo "yes (it outputs $EXECSUFFIX files)" >> config.log
			else
				echo "yes"
				echo "yes" >> config.log
			fi
echo "#ifndef EXECSUFFIX" > $BLD/include/agar/config/execsuffix.h
echo "#define EXECSUFFIX \"$EXECSUFFIX\"" >> $BLD/include/agar/config/execsuffix.h
echo "#endif" >> $BLD/include/agar/config/execsuffix.h
echo "hdefs[\"EXECSUFFIX\"] = \"$EXECSUFFIX\"" >>configure.lua
		else
			echo "yes"
			echo "yes" >> config.log
		fi
	fi
	rm -f conftest.m conftest$EXECSUFFIX
	TEST_OBJCFLAGS=""
fi
if [ "${HAVE_OBJC}" = "yes" ]; then
$ECHO_N "objc: checking for compiler warning options..."
$ECHO_N "objc: checking for compiler warning options..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.m
int main(int argc, char *argv[]) { return (0); }

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -x objective-c -o $testdir/conftest conftest.m " >>config.log
$CC $CFLAGS $TEST_CFLAGS -Wall -Werror -x objective-c -o $testdir/conftest conftest.m  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_OBJC_WARNINGS="yes"
echo "#ifndef HAVE_OBJC_WARNINGS" > $BLD/include/agar/config/have_objc_warnings.h
echo "#define HAVE_OBJC_WARNINGS \"$HAVE_OBJC_WARNINGS\"" >> $BLD/include/agar/config/have_objc_warnings.h
echo "#endif" >> $BLD/include/agar/config/have_objc_warnings.h
echo "hdefs[\"HAVE_OBJC_WARNINGS\"] = \"$HAVE_OBJC_WARNINGS\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_OBJC_WARNINGS="no"
echo "#undef HAVE_OBJC_WARNINGS" >$BLD/include/agar/config/have_objc_warnings.h
echo "hdefs[\"HAVE_OBJC_WARNINGS\"] = nil" >>configure.lua
fi;
rm -f conftest.m $testdir/conftest$EXECSUFFIX
if [ "${HAVE_OBJC_WARNINGS}" = "yes" ]; then
TEST_OBJCFLAGS="-Wall -Werror"
fi;
rm -f conftest.m $testdir/conftest$EXECSUFFIX
fi;
$ECHO_N "checking for <sys/types.h>..."
$ECHO_N "checking for <sys/types.h>..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
int main(int argc, char *argv[]) {
	size_t len = 1;
	len++;
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_SYS_TYPES_H="yes"
echo "#ifndef _MK_HAVE_SYS_TYPES_H" > $BLD/include/agar/config/_mk_have_sys_types_h.h
echo "#define _MK_HAVE_SYS_TYPES_H \"$_MK_HAVE_SYS_TYPES_H\"" >> $BLD/include/agar/config/_mk_have_sys_types_h.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_sys_types_h.h
echo "hdefs[\"_MK_HAVE_SYS_TYPES_H\"] = \"$_MK_HAVE_SYS_TYPES_H\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_SYS_TYPES_H="no"
echo "#undef _MK_HAVE_SYS_TYPES_H" >$BLD/include/agar/config/_mk_have_sys_types_h.h
echo "hdefs[\"_MK_HAVE_SYS_TYPES_H\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${_MK_HAVE_SYS_TYPES_H}" = "yes" ]; then
$ECHO_N "checking for int64_t type..."
$ECHO_N "checking for int64_t type..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
	int64_t i64 = 0;
	u_int64_t u64 = 0;
	printf("%lld %llu", (long long)i64, (unsigned long long)u64);
	return (i64 != 0 || u64 != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_INT64_T="yes"
echo "#ifndef HAVE_INT64_T" > $BLD/include/agar/config/have_int64_t.h
echo "#define HAVE_INT64_T \"$HAVE_INT64_T\"" >> $BLD/include/agar/config/have_int64_t.h
echo "#endif" >> $BLD/include/agar/config/have_int64_t.h
echo "hdefs[\"HAVE_INT64_T\"] = \"$HAVE_INT64_T\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_INT64_T="no"
echo "#undef HAVE_INT64_T" >$BLD/include/agar/config/have_int64_t.h
echo "hdefs[\"HAVE_INT64_T\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for __int64 type..."
$ECHO_N "checking for __int64 type..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
	__int64 i64 = 0;
	printf("%lld", (long long)i64);
	return (i64 != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE___INT64="yes"
echo "#ifndef HAVE___INT64" > $BLD/include/agar/config/have___int64.h
echo "#define HAVE___INT64 \"$HAVE___INT64\"" >> $BLD/include/agar/config/have___int64.h
echo "#endif" >> $BLD/include/agar/config/have___int64.h
echo "hdefs[\"HAVE___INT64\"] = \"$HAVE___INT64\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE___INT64="no"
echo "#undef HAVE___INT64" >$BLD/include/agar/config/have___int64.h
echo "hdefs[\"HAVE___INT64\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_INT64_T}" = "yes" ]; then
HAVE_64BIT="yes"
echo "#ifndef HAVE_64BIT" > $BLD/include/agar/config/have_64bit.h
echo "#define HAVE_64BIT \"$HAVE_64BIT\"" >> $BLD/include/agar/config/have_64bit.h
echo "#endif" >> $BLD/include/agar/config/have_64bit.h
echo "hdefs[\"HAVE_64BIT\"] = \"$HAVE_64BIT\"" >>configure.lua
else
if [ "${HAVE___INT64}" = "yes" ]; then
HAVE_64BIT="yes"
echo "#ifndef HAVE_64BIT" > $BLD/include/agar/config/have_64bit.h
echo "#define HAVE_64BIT \"$HAVE_64BIT\"" >> $BLD/include/agar/config/have_64bit.h
echo "#endif" >> $BLD/include/agar/config/have_64bit.h
echo "hdefs[\"HAVE_64BIT\"] = \"$HAVE_64BIT\"" >>configure.lua
else
echo "#undef HAVE_64BIT" >$BLD/include/agar/config/have_64bit.h
echo "hdefs[\"HAVE_64BIT\"] = nil" >>configure.lua
fi;
fi;
else
echo "#undef HAVE_64BIT" >$BLD/include/agar/config/have_64bit.h
echo "hdefs[\"HAVE_64BIT\"] = nil" >>configure.lua
fi;
$ECHO_N "checking for <stdlib.h>..."
$ECHO_N "checking for <stdlib.h>..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdlib.h>
int main(int argc, char *argv[]) {
	void *foo = malloc(1);
	free(foo);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_STDLIB_H="yes"
echo "#ifndef _MK_HAVE_STDLIB_H" > $BLD/include/agar/config/_mk_have_stdlib_h.h
echo "#define _MK_HAVE_STDLIB_H \"$_MK_HAVE_STDLIB_H\"" >> $BLD/include/agar/config/_mk_have_stdlib_h.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_stdlib_h.h
echo "hdefs[\"_MK_HAVE_STDLIB_H\"] = \"$_MK_HAVE_STDLIB_H\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_STDLIB_H="no"
echo "#undef _MK_HAVE_STDLIB_H" >$BLD/include/agar/config/_mk_have_stdlib_h.h
echo "hdefs[\"_MK_HAVE_STDLIB_H\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for <unistd.h>..."
$ECHO_N "checking for <unistd.h>..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char *argv[]) {
	uid_t uid = getuid();
	pid_t pid = getpid();
	return (pid == 0 || uid == 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_UNISTD_H="yes"
echo "#ifndef _MK_HAVE_UNISTD_H" > $BLD/include/agar/config/_mk_have_unistd_h.h
echo "#define _MK_HAVE_UNISTD_H \"$_MK_HAVE_UNISTD_H\"" >> $BLD/include/agar/config/_mk_have_unistd_h.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_unistd_h.h
echo "hdefs[\"_MK_HAVE_UNISTD_H\"] = \"$_MK_HAVE_UNISTD_H\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_UNISTD_H="no"
echo "#undef _MK_HAVE_UNISTD_H" >$BLD/include/agar/config/_mk_have_unistd_h.h
echo "hdefs[\"_MK_HAVE_UNISTD_H\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for compatible <limits.h>..."
$ECHO_N "checking for compatible <limits.h>..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <limits.h>

int main(int argc, char *argv[]) {
	int i = INT_MIN;
	unsigned u = 0;
	long l = LONG_MIN;
	unsigned long ul = 0;
	i = INT_MAX;
	u = UINT_MAX;
	l = LONG_MAX;
	ul = ULONG_MAX;
	return (i != INT_MAX || u != UINT_MAX || l != LONG_MAX || ul != LONG_MAX);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_LIMITS_H="yes"
echo "#ifndef _MK_HAVE_LIMITS_H" > $BLD/include/agar/config/_mk_have_limits_h.h
echo "#define _MK_HAVE_LIMITS_H \"$_MK_HAVE_LIMITS_H\"" >> $BLD/include/agar/config/_mk_have_limits_h.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_limits_h.h
echo "hdefs[\"_MK_HAVE_LIMITS_H\"] = \"$_MK_HAVE_LIMITS_H\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_LIMITS_H="no"
echo "#undef _MK_HAVE_LIMITS_H" >$BLD/include/agar/config/_mk_have_limits_h.h
echo "hdefs[\"_MK_HAVE_LIMITS_H\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for compatible <float.h>..."
$ECHO_N "checking for compatible <float.h>..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <float.h>

int main(int argc, char *argv[]) {
	float flt = 0.0f;
	double dbl = 0.0;

	flt += FLT_EPSILON;
	dbl += DBL_EPSILON;
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_FLOAT_H="yes"
echo "#ifndef _MK_HAVE_FLOAT_H" > $BLD/include/agar/config/_mk_have_float_h.h
echo "#define _MK_HAVE_FLOAT_H \"$_MK_HAVE_FLOAT_H\"" >> $BLD/include/agar/config/_mk_have_float_h.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_float_h.h
echo "hdefs[\"_MK_HAVE_FLOAT_H\"] = \"$_MK_HAVE_FLOAT_H\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_FLOAT_H="no"
echo "#undef _MK_HAVE_FLOAT_H" >$BLD/include/agar/config/_mk_have_float_h.h
echo "hdefs[\"_MK_HAVE_FLOAT_H\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the C math library..."
$ECHO_N "checking for the C math library..." >> config.log
if [ "" != "" ]; then
MATH_CFLAGS="-I"
MATH_LIBS="-L -lm"
else
MATH_CFLAGS=""
MATH_LIBS="-lm"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <math.h>

int
main(int argc, char *argv[])
{
	double d = 1.0;
	d = fabs(d);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${MATH_CFLAGS} -o $testdir/conftest conftest.c ${MATH_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${MATH_CFLAGS} -o $testdir/conftest conftest.c ${MATH_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_MATH="yes"
echo "#ifndef HAVE_MATH" > $BLD/include/agar/config/have_math.h
echo "#define HAVE_MATH \"$HAVE_MATH\"" >> $BLD/include/agar/config/have_math.h
echo "#endif" >> $BLD/include/agar/config/have_math.h
echo "hdefs[\"HAVE_MATH\"] = \"$HAVE_MATH\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_MATH="no"
echo "#undef HAVE_MATH" >$BLD/include/agar/config/have_math.h
echo "hdefs[\"HAVE_MATH\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_MATH}" = "yes" ]; then
echo "#ifndef MATH_CFLAGS" > $BLD/include/agar/config/math_cflags.h
echo "#define MATH_CFLAGS \"$MATH_CFLAGS\"" >> $BLD/include/agar/config/math_cflags.h
echo "#endif" >> $BLD/include/agar/config/math_cflags.h
echo "hdefs[\"MATH_CFLAGS\"] = \"$MATH_CFLAGS\"" >>configure.lua
echo "#ifndef MATH_LIBS" > $BLD/include/agar/config/math_libs.h
echo "#define MATH_LIBS \"$MATH_LIBS\"" >> $BLD/include/agar/config/math_libs.h
echo "#endif" >> $BLD/include/agar/config/math_libs.h
echo "hdefs[\"MATH_LIBS\"] = \"$MATH_LIBS\"" >>configure.lua
else
echo "#undef MATH_CFLAGS" >$BLD/include/agar/config/math_cflags.h
echo "hdefs[\"MATH_CFLAGS\"] = nil" >>configure.lua
MATH_CFLAGS=""
echo "#undef MATH_LIBS" >$BLD/include/agar/config/math_libs.h
echo "hdefs[\"MATH_LIBS\"] = nil" >>configure.lua
MATH_LIBS=""
fi;
$ECHO_N "checking for the C math library (C99)..."
$ECHO_N "checking for the C math library (C99)..." >> config.log
if [ "" != "" ]; then
MATH_C99_CFLAGS="-I"
MATH_C99_LIBS="-L -lm"
else
MATH_C99_CFLAGS=""
MATH_C99_LIBS="-lm"
fi;
case "${host}" in
*-pc-mingw32*)
echo "skipping (libmingwex linker errors)"
echo "skipping (libmingwex linker errors)" >> config.log
HAVE_MATH_C99="no"
echo "#undef HAVE_MATH_C99" >$BLD/include/agar/config/have_math_c99.h
echo "hdefs[\"HAVE_MATH_C99\"] = nil" >>configure.lua
;;
*)
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <math.h>

int
main(int argc, char *argv[])
{
	float f = 1.0;
	double d = 1.0;

	d = fabs(d);
	f = sqrtf(fabsf(f));
	return (f > d) ? 0 : 1;
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${MATH_C99_CFLAGS} -o $testdir/conftest conftest.c ${MATH_C99_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${MATH_C99_CFLAGS} -o $testdir/conftest conftest.c ${MATH_C99_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_MATH_C99="yes"
echo "#ifndef HAVE_MATH_C99" > $BLD/include/agar/config/have_math_c99.h
echo "#define HAVE_MATH_C99 \"$HAVE_MATH_C99\"" >> $BLD/include/agar/config/have_math_c99.h
echo "#endif" >> $BLD/include/agar/config/have_math_c99.h
echo "hdefs[\"HAVE_MATH_C99\"] = \"$HAVE_MATH_C99\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_MATH_C99="no"
echo "#undef HAVE_MATH_C99" >$BLD/include/agar/config/have_math_c99.h
echo "hdefs[\"HAVE_MATH_C99\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
;;
esac
if [ "${HAVE_MATH_C99}" = "yes" ]; then
echo "#ifndef MATH_C99_CFLAGS" > $BLD/include/agar/config/math_c99_cflags.h
echo "#define MATH_C99_CFLAGS \"$MATH_C99_CFLAGS\"" >> $BLD/include/agar/config/math_c99_cflags.h
echo "#endif" >> $BLD/include/agar/config/math_c99_cflags.h
echo "hdefs[\"MATH_C99_CFLAGS\"] = \"$MATH_C99_CFLAGS\"" >>configure.lua
echo "#ifndef MATH_C99_LIBS" > $BLD/include/agar/config/math_c99_libs.h
echo "#define MATH_C99_LIBS \"$MATH_C99_LIBS\"" >> $BLD/include/agar/config/math_c99_libs.h
echo "#endif" >> $BLD/include/agar/config/math_c99_libs.h
echo "hdefs[\"MATH_C99_LIBS\"] = \"$MATH_C99_LIBS\"" >>configure.lua
else
echo "#undef MATH_C99_CFLAGS" >$BLD/include/agar/config/math_c99_cflags.h
echo "hdefs[\"MATH_C99_CFLAGS\"] = nil" >>configure.lua
MATH_C99_CFLAGS=""
echo "#undef MATH_C99_LIBS" >$BLD/include/agar/config/math_c99_libs.h
echo "hdefs[\"MATH_C99_LIBS\"] = nil" >>configure.lua
MATH_C99_LIBS=""
fi;
$ECHO_N "checking for a getpwuid() function..."
$ECHO_N "checking for a getpwuid() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <sys/types.h>
#include <pwd.h>

int
main(int argc, char *argv[])
{
	struct passwd *pwd;
	uid_t uid = 0;

	pwd = getpwuid(uid);
	return (pwd != NULL && pwd->pw_dir != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETPWUID="yes"
echo "#ifndef HAVE_GETPWUID" > $BLD/include/agar/config/have_getpwuid.h
echo "#define HAVE_GETPWUID \"$HAVE_GETPWUID\"" >> $BLD/include/agar/config/have_getpwuid.h
echo "#endif" >> $BLD/include/agar/config/have_getpwuid.h
echo "hdefs[\"HAVE_GETPWUID\"] = \"$HAVE_GETPWUID\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETPWUID="no"
echo "#undef HAVE_GETPWUID" >$BLD/include/agar/config/have_getpwuid.h
echo "hdefs[\"HAVE_GETPWUID\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the getpwnam_r() interface..."
$ECHO_N "checking for the getpwnam_r() interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

int
main(int argc, char *argv[])
{
	struct passwd pw, *res;
	char *buf;
	size_t bufSize;
	int rv;

	bufSize = sysconf(_SC_GETPW_R_SIZE_MAX);
	if (bufSize == -1) { bufSize = 16384; }
	if ((buf = malloc(bufSize)) == NULL) { return (1); }

	rv = getpwnam_r("foo", &pw, buf, bufSize, &res);
	if (res == NULL) {
		return (rv == 0);
	}
	return (pw.pw_dir != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETPWNAM_R="yes"
echo "#ifndef HAVE_GETPWNAM_R" > $BLD/include/agar/config/have_getpwnam_r.h
echo "#define HAVE_GETPWNAM_R \"$HAVE_GETPWNAM_R\"" >> $BLD/include/agar/config/have_getpwnam_r.h
echo "#endif" >> $BLD/include/agar/config/have_getpwnam_r.h
echo "hdefs[\"HAVE_GETPWNAM_R\"] = \"$HAVE_GETPWNAM_R\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETPWNAM_R="no"
echo "#undef HAVE_GETPWNAM_R" >$BLD/include/agar/config/have_getpwnam_r.h
echo "hdefs[\"HAVE_GETPWNAM_R\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for a getenv() function..."
$ECHO_N "checking for a getenv() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdlib.h>
int
main(int argc, char *argv[])
{
	(void)getenv("PATH");
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETENV="yes"
echo "#ifndef HAVE_GETENV" > $BLD/include/agar/config/have_getenv.h
echo "#define HAVE_GETENV \"$HAVE_GETENV\"" >> $BLD/include/agar/config/have_getenv.h
echo "#endif" >> $BLD/include/agar/config/have_getenv.h
echo "hdefs[\"HAVE_GETENV\"] = \"$HAVE_GETENV\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETENV="no"
echo "#undef HAVE_GETENV" >$BLD/include/agar/config/have_getenv.h
echo "hdefs[\"HAVE_GETENV\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for a getuid() function..."
$ECHO_N "checking for a getuid() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
	uid_t uid = getuid();
	return (uid != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETUID="yes"
echo "#ifndef HAVE_GETUID" > $BLD/include/agar/config/have_getuid.h
echo "#define HAVE_GETUID \"$HAVE_GETUID\"" >> $BLD/include/agar/config/have_getuid.h
echo "#endif" >> $BLD/include/agar/config/have_getuid.h
echo "hdefs[\"HAVE_GETUID\"] = \"$HAVE_GETUID\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETUID="no"
echo "#undef HAVE_GETUID" >$BLD/include/agar/config/have_getuid.h
echo "hdefs[\"HAVE_GETUID\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for a strsep() function..."
$ECHO_N "checking for a strsep() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
int
main(int argc, char *argv[])
{
	char foo[32], *pFoo = &foo[0];
	char *s;

	foo[0] = '\0';
	s = strsep(&pFoo, " ");
	return (s != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_STRSEP="yes"
echo "#ifndef HAVE_STRSEP" > $BLD/include/agar/config/have_strsep.h
echo "#define HAVE_STRSEP \"$HAVE_STRSEP\"" >> $BLD/include/agar/config/have_strsep.h
echo "#endif" >> $BLD/include/agar/config/have_strsep.h
echo "hdefs[\"HAVE_STRSEP\"] = \"$HAVE_STRSEP\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_STRSEP="no"
echo "#undef HAVE_STRSEP" >$BLD/include/agar/config/have_strsep.h
echo "hdefs[\"HAVE_STRSEP\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for an asprintf() function..."
$ECHO_N "checking for an asprintf() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>

int
main(int argc, char *argv[])
{
	char *buf;
	if (asprintf(&buf, "foo %s", "bar") == 0) {
	    return (0);
	}
	return (1);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -D_GNU_SOURCE -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -D_GNU_SOURCE -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ASPRINTF="yes"
echo "#ifndef HAVE_ASPRINTF" > $BLD/include/agar/config/have_asprintf.h
echo "#define HAVE_ASPRINTF \"$HAVE_ASPRINTF\"" >> $BLD/include/agar/config/have_asprintf.h
echo "#endif" >> $BLD/include/agar/config/have_asprintf.h
echo "hdefs[\"HAVE_ASPRINTF\"] = \"$HAVE_ASPRINTF\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ASPRINTF="no"
echo "#undef HAVE_ASPRINTF" >$BLD/include/agar/config/have_asprintf.h
echo "hdefs[\"HAVE_ASPRINTF\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for the snprintf() function..."
$ECHO_N "checking for the snprintf() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>

int
main(int argc, char *argv[])
{
	char buf[16];
	(void)snprintf(buf, sizeof(buf), "foo");
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SNPRINTF="yes"
echo "#ifndef HAVE_SNPRINTF" > $BLD/include/agar/config/have_snprintf.h
echo "#define HAVE_SNPRINTF \"$HAVE_SNPRINTF\"" >> $BLD/include/agar/config/have_snprintf.h
echo "#endif" >> $BLD/include/agar/config/have_snprintf.h
echo "hdefs[\"HAVE_SNPRINTF\"] = \"$HAVE_SNPRINTF\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SNPRINTF="no"
echo "#undef HAVE_SNPRINTF" >$BLD/include/agar/config/have_snprintf.h
echo "hdefs[\"HAVE_SNPRINTF\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the vsnprintf() function..."
$ECHO_N "checking for the vsnprintf() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <stdarg.h>

static void
testfmt(const char *fmt, ...)
{
	char buf[16];
	va_list ap;
	va_start(ap, fmt);
	(void)vsnprintf(buf, sizeof(buf), fmt, ap);
	va_end(ap);
}
int
main(int argc, char *argv[])
{
	testfmt("foo", 1, 2, 3);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_VSNPRINTF="yes"
echo "#ifndef HAVE_VSNPRINTF" > $BLD/include/agar/config/have_vsnprintf.h
echo "#define HAVE_VSNPRINTF \"$HAVE_VSNPRINTF\"" >> $BLD/include/agar/config/have_vsnprintf.h
echo "#endif" >> $BLD/include/agar/config/have_vsnprintf.h
echo "hdefs[\"HAVE_VSNPRINTF\"] = \"$HAVE_VSNPRINTF\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_VSNPRINTF="no"
echo "#undef HAVE_VSNPRINTF" >$BLD/include/agar/config/have_vsnprintf.h
echo "hdefs[\"HAVE_VSNPRINTF\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for a vasprintf() function..."
$ECHO_N "checking for a vasprintf() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <stdarg.h>

int
testprintf(const char *fmt, ...)
{
	va_list args;
	char *buf;

	va_start(args, fmt);
	if (vasprintf(&buf, "%s", args) == -1) {
		return (-1);
	}
	va_end(args);
	return (0);
}
int
main(int argc, char *argv[])
{
	return (testprintf("foo %s", "bar"));
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -D_GNU_SOURCE -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -D_GNU_SOURCE -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_VASPRINTF="yes"
echo "#ifndef HAVE_VASPRINTF" > $BLD/include/agar/config/have_vasprintf.h
echo "#define HAVE_VASPRINTF \"$HAVE_VASPRINTF\"" >> $BLD/include/agar/config/have_vasprintf.h
echo "#endif" >> $BLD/include/agar/config/have_vasprintf.h
echo "hdefs[\"HAVE_VASPRINTF\"] = \"$HAVE_VASPRINTF\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_VASPRINTF="no"
echo "#undef HAVE_VASPRINTF" >$BLD/include/agar/config/have_vasprintf.h
echo "hdefs[\"HAVE_VASPRINTF\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
$ECHO_N "checking for ANSI-style signal() facilities..."
$ECHO_N "checking for ANSI-style signal() facilities..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <signal.h>

void
sighandler(int sig)
{
}

int
main(int argc, char *argv[])
{
	signal(SIGTERM, sighandler);
	signal(SIGILL, sighandler);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_SIGNAL="yes"
echo "#ifndef _MK_HAVE_SIGNAL" > $BLD/include/agar/config/_mk_have_signal.h
echo "#define _MK_HAVE_SIGNAL \"$_MK_HAVE_SIGNAL\"" >> $BLD/include/agar/config/_mk_have_signal.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_signal.h
echo "hdefs[\"_MK_HAVE_SIGNAL\"] = \"$_MK_HAVE_SIGNAL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_SIGNAL="no"
echo "#undef _MK_HAVE_SIGNAL" >$BLD/include/agar/config/_mk_have_signal.h
echo "hdefs[\"_MK_HAVE_SIGNAL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for setjmp() and longjmp()..."
$ECHO_N "checking for setjmp() and longjmp()..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <setjmp.h>

jmp_buf jmpbuf;

int
main(int argc, char *argv[])
{
	longjmp(jmpbuf, 1);
	setjmp(jmpbuf);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_SETJMP="yes"
echo "#ifndef _MK_HAVE_SETJMP" > $BLD/include/agar/config/_mk_have_setjmp.h
echo "#define _MK_HAVE_SETJMP \"$_MK_HAVE_SETJMP\"" >> $BLD/include/agar/config/_mk_have_setjmp.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_setjmp.h
echo "hdefs[\"_MK_HAVE_SETJMP\"] = \"$_MK_HAVE_SETJMP\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_SETJMP="no"
echo "#undef _MK_HAVE_SETJMP" >$BLD/include/agar/config/_mk_have_setjmp.h
echo "hdefs[\"_MK_HAVE_SETJMP\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for a strtoll() function..."
$ECHO_N "checking for a strtoll() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdlib.h>

int
main(int argc, char *argv[])
{
	long long int lli;
	char *ep = NULL;
	char *foo = "1234";

	lli = strtoll(foo, &ep, 10);
	return (lli != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_STRTOLL="yes"
echo "#ifndef _MK_HAVE_STRTOLL" > $BLD/include/agar/config/_mk_have_strtoll.h
echo "#define _MK_HAVE_STRTOLL \"$_MK_HAVE_STRTOLL\"" >> $BLD/include/agar/config/_mk_have_strtoll.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_strtoll.h
echo "hdefs[\"_MK_HAVE_STRTOLL\"] = \"$_MK_HAVE_STRTOLL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_STRTOLL="no"
echo "#undef _MK_HAVE_STRTOLL" >$BLD/include/agar/config/_mk_have_strtoll.h
echo "hdefs[\"_MK_HAVE_STRTOLL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for a strtold() function..."
$ECHO_N "checking for a strtold() function..." >> config.log
if [ "${HAVE_LONG_DOUBLE}" = "yes" ]; then
if [ "${HAVE_CYGWIN}" = "no" ]; then
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifndef __NetBSD__
# define _XOPEN_SOURCE 600
#endif
#include <stdlib.h>
int
main(int argc, char *argv[])
{
	long double ld;
	char *ep = NULL;
	char *foo = "1234";

	ld = strtold(foo, &ep);
	return (ld != 1234.0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
_MK_HAVE_STRTOLD="yes"
echo "#ifndef _MK_HAVE_STRTOLD" > $BLD/include/agar/config/_mk_have_strtold.h
echo "#define _MK_HAVE_STRTOLD \"$_MK_HAVE_STRTOLD\"" >> $BLD/include/agar/config/_mk_have_strtold.h
echo "#endif" >> $BLD/include/agar/config/_mk_have_strtold.h
echo "hdefs[\"_MK_HAVE_STRTOLD\"] = \"$_MK_HAVE_STRTOLD\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
_MK_HAVE_STRTOLD="no"
echo "#undef _MK_HAVE_STRTOLD" >$BLD/include/agar/config/_mk_have_strtold.h
echo "hdefs[\"_MK_HAVE_STRTOLD\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
else
_MK_HAVE_STRTOLD="no"
echo "#undef _MK_HAVE_STRTOLD" >$BLD/include/agar/config/_mk_have_strtold.h
echo "hdefs[\"_MK_HAVE_STRTOLD\"] = nil" >>configure.lua
echo "not checking (cygwin issues)"
echo "not checking (cygwin issues)" >> config.log
fi;
else
_MK_HAVE_STRTOLD="no"
echo "#undef _MK_HAVE_STRTOLD" >$BLD/include/agar/config/_mk_have_strtold.h
echo "hdefs[\"_MK_HAVE_STRTOLD\"] = nil" >>configure.lua
echo "skipping (no long double)"
echo "skipping (no long double)" >> config.log
fi;
$ECHO_N "checking for byte order..."
$ECHO_N "checking for byte order..." >> config.log
if [ "${byte_order}" != "" ]; then
if [ "${byte_order}" = "LE" ]; then
_MK_BYTE_ORDER="LE"
else
if [ "${byte_order}" = "BE" ]; then
_MK_BYTE_ORDER="BE"
else
echo "Usage: --byte-order=[LE|BE]"
exit 1
fi;
fi;
else
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/param.h>
int
main(int argc, char *argv[])
{
#if BYTE_ORDER == BIG_ENDIAN
	static volatile char *bo = "BiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiANBiGEnDiAN";
#else
	static volatile char *bo = "LiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiANLiTTLeEnDiAN";
#endif
	int c = 0;
	volatile char *p = bo;
	while (*p != '\0') { c *= (int)*p; }
	return (c>123?c:456);
}

EOT
echo "$CC $CFLAGS  -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS  -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "Failed to compile test program for byte order ($?)"
	echo "Failed to compile test program for byte order ($?)" >> config.log
	exit 1
fi
rm -f conftest.c

_MK_BYTE_ORDER=""
_MK_BYTE_ORDER_LESTRING="LiTTLeEnD"
_MK_BYTE_ORDER_BESTRING="BiGEnDiAN"
od -tc $testdir/conftest$EXECSUFFIX | sed 's/ //g' > $testdir/conftest.dump

if grep "$_MK_BYTE_ORDER_LESTRING" $testdir/conftest.dump >/dev/null; then
	_MK_BYTE_ORDER="LE"
	if grep "$_MK_BYTE_ORDER_BESTRING" $testdir/conftest.dump >/dev/null; then
		echo "*"
		echo "* Unable to auto-determine host byte order. Please re-run ./configure"
		echo "* with --byte-order=LE or --byte-order=BE."
		echo "*"
		exit 1
	fi
else
	if grep "$_MK_BYTE_ORDER_BESTRING" $testdir/conftest.dump >/dev/null; then
		_MK_BYTE_ORDER="BE"
		if grep "$_MK_BYTE_ORDER_LESTRING" $testdir/conftest.dump >/dev/null; then
			echo "*"
			echo "* Unable to auto-determine host byte order. Please re-run ./configure"
			echo "* with --byte-order=LE or --byte-order=BE."
			echo "*"
			exit 1
		fi
	fi
fi
rm -f conftest.c $testdir/conftest $testdir/conftest.dump
fi;
if [ "$_MK_BYTE_ORDER" = "LE" ]; then
echo "little-endian"
echo "little-endian" >> config.log
_MK_LITTLE_ENDIAN="yes"
echo "#ifndef _MK_LITTLE_ENDIAN" > $BLD/include/agar/config/_mk_little_endian.h
echo "#define _MK_LITTLE_ENDIAN \"$_MK_LITTLE_ENDIAN\"" >> $BLD/include/agar/config/_mk_little_endian.h
echo "#endif" >> $BLD/include/agar/config/_mk_little_endian.h
echo "hdefs[\"_MK_LITTLE_ENDIAN\"] = \"$_MK_LITTLE_ENDIAN\"" >>configure.lua
echo "#undef _MK_BIG_ENDIAN" >$BLD/include/agar/config/_mk_big_endian.h
echo "hdefs[\"_MK_BIG_ENDIAN\"] = nil" >>configure.lua
else
echo "big-endian"
echo "big-endian" >> config.log
_MK_BIG_ENDIAN="yes"
echo "#ifndef _MK_BIG_ENDIAN" > $BLD/include/agar/config/_mk_big_endian.h
echo "#define _MK_BIG_ENDIAN \"$_MK_BIG_ENDIAN\"" >> $BLD/include/agar/config/_mk_big_endian.h
echo "#endif" >> $BLD/include/agar/config/_mk_big_endian.h
echo "hdefs[\"_MK_BIG_ENDIAN\"] = \"$_MK_BIG_ENDIAN\"" >>configure.lua
echo "#undef _MK_LITTLE_ENDIAN" >$BLD/include/agar/config/_mk_little_endian.h
echo "hdefs[\"_MK_LITTLE_ENDIAN\"] = nil" >>configure.lua
fi;
$ECHO_N "checking for dlopen() interface..."
$ECHO_N "checking for dlopen() interface..." >> config.log
DSO_CFLAGS=""
DSO_LIBS=""
TEST_CFLAGS_ORIG="${TEST_CFLAGS}"
TEST_HEADERS="Yes"
echo > conftest.c
echo "#include <dlfcn.h>" >> conftest.c
echo "int main (int argc, char *argv[]) { return (0); }" >> conftest.c
MK_COMPILE_STATUS="OK"
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
HAVE_DLFCN_H="yes"
echo "#ifndef HAVE_DLFCN_H" > $BLD/include/agar/config/have_dlfcn_h.h
echo "#define HAVE_DLFCN_H \"$HAVE_DLFCN_H\"" >> $BLD/include/agar/config/have_dlfcn_h.h
echo "#endif" >> $BLD/include/agar/config/have_dlfcn_h.h
echo "hdefs[\"HAVE_DLFCN_H\"] = \"$HAVE_DLFCN_H\"" >>configure.lua
if [ "${TEST_HEADERS}" = "Yes" ]; then
TEST_CFLAGS="${TEST_CFLAGS} -DHAVE_DLFCN_H"
fi;
else
HAVE_DLFCN_H="no"
echo "#undef HAVE_DLFCN_H" >$BLD/include/agar/config/have_dlfcn_h.h
echo "hdefs[\"HAVE_DLFCN_H\"] = nil" >>configure.lua
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif

int
main(int argc, char *argv[])
{
	void *handle;
	char *error;
	handle = dlopen("foo.so", 0);
	error = dlerror();
	(void)dlsym(handle, "foo");
	return (error != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_DLOPEN="yes"
echo "#ifndef HAVE_DLOPEN" > $BLD/include/agar/config/have_dlopen.h
echo "#define HAVE_DLOPEN \"$HAVE_DLOPEN\"" >> $BLD/include/agar/config/have_dlopen.h
echo "#endif" >> $BLD/include/agar/config/have_dlopen.h
echo "hdefs[\"HAVE_DLOPEN\"] = \"$HAVE_DLOPEN\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_DLOPEN="no"
echo "#undef HAVE_DLOPEN" >$BLD/include/agar/config/have_dlopen.h
echo "hdefs[\"HAVE_DLOPEN\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_DLOPEN}" = "no" ]; then
$ECHO_N "checking for dlopen() in -ldl..."
$ECHO_N "checking for dlopen() in -ldl..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#ifdef HAVE_DLFCN_H
#include <dlfcn.h>
#endif

int
main(int argc, char *argv[])
{
	void *handle;
	char *error;
	handle = dlopen("foo.so", 0);
	error = dlerror();
	(void)dlsym(handle, "foo");
	return (error != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -ldl -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -ldl -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_DLOPEN="yes"
echo "#ifndef HAVE_DLOPEN" > $BLD/include/agar/config/have_dlopen.h
echo "#define HAVE_DLOPEN \"$HAVE_DLOPEN\"" >> $BLD/include/agar/config/have_dlopen.h
echo "#endif" >> $BLD/include/agar/config/have_dlopen.h
echo "hdefs[\"HAVE_DLOPEN\"] = \"$HAVE_DLOPEN\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_DLOPEN="no"
echo "#undef HAVE_DLOPEN" >$BLD/include/agar/config/have_dlopen.h
echo "hdefs[\"HAVE_DLOPEN\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
if [ "${HAVE_DLOPEN}" = "yes" ]; then
DSO_CFLAGS=""
DSO_LIBS="-ldl"
echo "#ifndef DSO_CFLAGS" > $BLD/include/agar/config/dso_cflags.h
echo "#define DSO_CFLAGS \"$DSO_CFLAGS\"" >> $BLD/include/agar/config/dso_cflags.h
echo "#endif" >> $BLD/include/agar/config/dso_cflags.h
echo "hdefs[\"DSO_CFLAGS\"] = \"$DSO_CFLAGS\"" >>configure.lua
echo "#ifndef DSO_LIBS" > $BLD/include/agar/config/dso_libs.h
echo "#define DSO_LIBS \"$DSO_LIBS\"" >> $BLD/include/agar/config/dso_libs.h
echo "#endif" >> $BLD/include/agar/config/dso_libs.h
echo "hdefs[\"DSO_LIBS\"] = \"$DSO_LIBS\"" >>configure.lua
fi;
fi;
TEST_CFLAGS="${TEST_CFLAGS_ORIG}"
TEST_HEADERS=""
$ECHO_N "checking for dyld interface..."
$ECHO_N "checking for dyld interface..." >> config.log
TEST_CFLAGS_ORIG="${TEST_CFLAGS}"
TEST_HEADERS="Yes"
echo > conftest.c
echo "#include <mach-o/dyld.h>" >> conftest.c
echo "int main (int argc, char *argv[]) { return (0); }" >> conftest.c
MK_COMPILE_STATUS="OK"
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
HAVE_MACH_O_DYLD_H="yes"
echo "#ifndef HAVE_MACH_O_DYLD_H" > $BLD/include/agar/config/have_mach_o_dyld_h.h
echo "#define HAVE_MACH_O_DYLD_H \"$HAVE_MACH_O_DYLD_H\"" >> $BLD/include/agar/config/have_mach_o_dyld_h.h
echo "#endif" >> $BLD/include/agar/config/have_mach_o_dyld_h.h
echo "hdefs[\"HAVE_MACH_O_DYLD_H\"] = \"$HAVE_MACH_O_DYLD_H\"" >>configure.lua
if [ "${TEST_HEADERS}" = "Yes" ]; then
TEST_CFLAGS="${TEST_CFLAGS} -DHAVE_MACH_O_DYLD_H"
fi;
else
HAVE_MACH_O_DYLD_H="no"
echo "#undef HAVE_MACH_O_DYLD_H" >$BLD/include/agar/config/have_mach_o_dyld_h.h
echo "hdefs[\"HAVE_MACH_O_DYLD_H\"] = nil" >>configure.lua
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef HAVE_MACH_O_DYLD_H
#include <mach-o/dyld.h>
#endif
int
main(int argc, char *argv[])
{
	NSObjectFileImage img;
	NSObjectFileImageReturnCode rv;

	rv = NSCreateObjectFileImageFromFile("foo", &img);
	return (rv == NSObjectFileImageSuccess);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_DYLD="yes"
echo "#ifndef HAVE_DYLD" > $BLD/include/agar/config/have_dyld.h
echo "#define HAVE_DYLD \"$HAVE_DYLD\"" >> $BLD/include/agar/config/have_dyld.h
echo "#endif" >> $BLD/include/agar/config/have_dyld.h
echo "hdefs[\"HAVE_DYLD\"] = \"$HAVE_DYLD\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_DYLD="no"
echo "#undef HAVE_DYLD" >$BLD/include/agar/config/have_dyld.h
echo "hdefs[\"HAVE_DYLD\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_DYLD}" = "yes" ]; then
echo "checking for NSLINKMODULE_OPTION_RETURN_ON_ERROR"
echo "checking for NSLINKMODULE_OPTION_RETURN_ON_ERROR" >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef HAVE_MACH_O_DYLD_H
#include <mach-o/dyld.h>
#endif
int
main(int argc, char *argv[])
{
	NSObjectFileImage img;
	NSObjectFileImageReturnCode rv;
	void *handle;

	rv = NSCreateObjectFileImageFromFile("foo", &img);
	handle = (void *)NSLinkModule(img, "foo",
	    NSLINKMODULE_OPTION_RETURN_ON_ERROR|
		NSLINKMODULE_OPTION_NONE);
	if (handle == NULL) {
		NSLinkEditErrors errs;
		int n;
		const char *f, *s = NULL;
		NSLinkEditError(&errs, &n, &f, &s);
	}
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_DYLD_RETURN_ON_ERROR="yes"
echo "#ifndef HAVE_DYLD_RETURN_ON_ERROR" > $BLD/include/agar/config/have_dyld_return_on_error.h
echo "#define HAVE_DYLD_RETURN_ON_ERROR \"$HAVE_DYLD_RETURN_ON_ERROR\"" >> $BLD/include/agar/config/have_dyld_return_on_error.h
echo "#endif" >> $BLD/include/agar/config/have_dyld_return_on_error.h
echo "hdefs[\"HAVE_DYLD_RETURN_ON_ERROR\"] = \"$HAVE_DYLD_RETURN_ON_ERROR\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_DYLD_RETURN_ON_ERROR="no"
echo "#undef HAVE_DYLD_RETURN_ON_ERROR" >$BLD/include/agar/config/have_dyld_return_on_error.h
echo "hdefs[\"HAVE_DYLD_RETURN_ON_ERROR\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
else
HAVE_DYLD_RETURN_ON_ERROR="no"
echo "#undef HAVE_DYLD_RETURN_ON_ERROR" >$BLD/include/agar/config/have_dyld_return_on_error.h
echo "hdefs[\"HAVE_DYLD_RETURN_ON_ERROR\"] = nil" >>configure.lua
fi;
TEST_CFLAGS="${TEST_CFLAGS_ORIG}"
TEST_HEADERS=""
$ECHO_N "checking for shl_load() interface..."
$ECHO_N "checking for shl_load() interface..." >> config.log
TEST_CFLAGS_ORIG="${TEST_CFLAGS}"
TEST_HEADERS="Yes"
echo > conftest.c
echo "#include <dl.h>" >> conftest.c
echo "int main (int argc, char *argv[]) { return (0); }" >> conftest.c
MK_COMPILE_STATUS="OK"
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
HAVE_DL_H="yes"
echo "#ifndef HAVE_DL_H" > $BLD/include/agar/config/have_dl_h.h
echo "#define HAVE_DL_H \"$HAVE_DL_H\"" >> $BLD/include/agar/config/have_dl_h.h
echo "#endif" >> $BLD/include/agar/config/have_dl_h.h
echo "hdefs[\"HAVE_DL_H\"] = \"$HAVE_DL_H\"" >>configure.lua
if [ "${TEST_HEADERS}" = "Yes" ]; then
TEST_CFLAGS="${TEST_CFLAGS} -DHAVE_DL_H"
fi;
else
HAVE_DL_H="no"
echo "#undef HAVE_DL_H" >$BLD/include/agar/config/have_dl_h.h
echo "hdefs[\"HAVE_DL_H\"] = nil" >>configure.lua
fi;
if [ "" != "" ]; then
SHL_LOAD_LIBS="-L -ldld"
else
SHL_LOAD_LIBS="-ldld"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#ifdef HAVE_DL_H
#include <dl.h>
#endif

int
main(int argc, char *argv[])
{
	void *handle;
	void **p;

	handle = shl_load("foo.so", BIND_IMMEDIATE, 0);
	(void)shl_findsym((shl_t *)&handle, "foo", TYPE_PROCEDURE, p);
	(void)shl_findsym((shl_t *)&handle, "foo", TYPE_DATA, p);
	shl_unload((shl_t)handle);
	return (handle != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${SHL_LOAD_LIBS} -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${SHL_LOAD_LIBS} -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SHL_LOAD="yes"
echo "#ifndef HAVE_SHL_LOAD" > $BLD/include/agar/config/have_shl_load.h
echo "#define HAVE_SHL_LOAD \"$HAVE_SHL_LOAD\"" >> $BLD/include/agar/config/have_shl_load.h
echo "#endif" >> $BLD/include/agar/config/have_shl_load.h
echo "hdefs[\"HAVE_SHL_LOAD\"] = \"$HAVE_SHL_LOAD\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SHL_LOAD="no"
echo "#undef HAVE_SHL_LOAD" >$BLD/include/agar/config/have_shl_load.h
echo "hdefs[\"HAVE_SHL_LOAD\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest
if [ "${HAVE_SHL_LOAD}" = "yes" ]; then
DSO_LIBS="$DSO_LIBS $SHL_LOAD_LIBS"
echo "#ifndef HAVE_SHL_LOAD" > $BLD/include/agar/config/have_shl_load.h
echo "#define HAVE_SHL_LOAD \"$HAVE_SHL_LOAD\"" >> $BLD/include/agar/config/have_shl_load.h
echo "#endif" >> $BLD/include/agar/config/have_shl_load.h
echo "hdefs[\"HAVE_SHL_LOAD\"] = \"$HAVE_SHL_LOAD\"" >>configure.lua
echo "#ifndef DSO_LIBS" > $BLD/include/agar/config/dso_libs.h
echo "#define DSO_LIBS \"$DSO_LIBS\"" >> $BLD/include/agar/config/dso_libs.h
echo "#endif" >> $BLD/include/agar/config/dso_libs.h
echo "hdefs[\"DSO_LIBS\"] = \"$DSO_LIBS\"" >>configure.lua
else
echo "#undef HAVE_SHL_LOAD" >$BLD/include/agar/config/have_shl_load.h
echo "hdefs[\"HAVE_SHL_LOAD\"] = nil" >>configure.lua
fi;
TEST_CFLAGS="${TEST_CFLAGS_ORIG}"
TEST_HEADERS=""
$ECHO_N "checking for the gettimeofday() function..."
$ECHO_N "checking for the gettimeofday() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/time.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
	struct timeval tv;
	int rv = gettimeofday(&tv, NULL);
	return (rv);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETTIMEOFDAY="yes"
echo "#ifndef HAVE_GETTIMEOFDAY" > $BLD/include/agar/config/have_gettimeofday.h
echo "#define HAVE_GETTIMEOFDAY \"$HAVE_GETTIMEOFDAY\"" >> $BLD/include/agar/config/have_gettimeofday.h
echo "#endif" >> $BLD/include/agar/config/have_gettimeofday.h
echo "hdefs[\"HAVE_GETTIMEOFDAY\"] = \"$HAVE_GETTIMEOFDAY\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETTIMEOFDAY="no"
echo "#undef HAVE_GETTIMEOFDAY" >$BLD/include/agar/config/have_gettimeofday.h
echo "hdefs[\"HAVE_GETTIMEOFDAY\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the select() interface..."
$ECHO_N "checking for the select() interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/time.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

int
main(int argc, char *argv[])
{
	struct timeval tv;
	int rv;

	tv.tv_sec = 1;
	tv.tv_usec = 1;
	rv = select(0, NULL, NULL, NULL, &tv);
	return (rv == -1 && errno != EINTR);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SELECT="yes"
echo "#ifndef HAVE_SELECT" > $BLD/include/agar/config/have_select.h
echo "#define HAVE_SELECT \"$HAVE_SELECT\"" >> $BLD/include/agar/config/have_select.h
echo "#endif" >> $BLD/include/agar/config/have_select.h
echo "hdefs[\"HAVE_SELECT\"] = \"$HAVE_SELECT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SELECT="no"
echo "#undef HAVE_SELECT" >$BLD/include/agar/config/have_select.h
echo "hdefs[\"HAVE_SELECT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the glob() function..."
$ECHO_N "checking for the glob() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <glob.h>
#include <stdio.h>

int
main(int argc, char *argv[])
{
	glob_t gl;
	int rv, i;
	char *s = NULL;

	rv = glob("~/foo", GLOB_TILDE, NULL, &gl);
	for (i = 0; i < gl.gl_pathc; i++) { s = gl.gl_pathv[i]; }
	return (rv != 0 && s != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GLOB="yes"
echo "#ifndef HAVE_GLOB" > $BLD/include/agar/config/have_glob.h
echo "#define HAVE_GLOB \"$HAVE_GLOB\"" >> $BLD/include/agar/config/have_glob.h
echo "#endif" >> $BLD/include/agar/config/have_glob.h
echo "hdefs[\"HAVE_GLOB\"] = \"$HAVE_GLOB\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GLOB="no"
echo "#undef HAVE_GLOB" >$BLD/include/agar/config/have_glob.h
echo "hdefs[\"HAVE_GLOB\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the getopt() function..."
$ECHO_N "checking for the getopt() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <getopt.h>

int
main(int argc, char *argv[])
{
	int c, x = 0;
	while ((c = getopt(argc, argv, "foo")) != -1) {
		extern char *optarg;
		extern int optind, opterr, optopt;
		if (optarg != NULL) { x = 1; }
		if (optind > 0) { x = 2; }
		if (opterr > 0) { x = 3; }
		if (optopt > 0) { x = 4; }
	}
	return (x != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETOPT="yes"
echo "#ifndef HAVE_GETOPT" > $BLD/include/agar/config/have_getopt.h
echo "#define HAVE_GETOPT \"$HAVE_GETOPT\"" >> $BLD/include/agar/config/have_getopt.h
echo "#endif" >> $BLD/include/agar/config/have_getopt.h
echo "hdefs[\"HAVE_GETOPT\"] = \"$HAVE_GETOPT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETOPT="no"
echo "#undef HAVE_GETOPT" >$BLD/include/agar/config/have_getopt.h
echo "hdefs[\"HAVE_GETOPT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the execvp() function..."
$ECHO_N "checking for the execvp() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <unistd.h>

int
main(int argc, char *argv[])
{
	char *args[3];
	int rv;

	args[0] = "foo";
	args[2] = NULL;

	rv = execvp(args[0], args);
	return (rv);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_EXECVP="yes"
echo "#ifndef HAVE_EXECVP" > $BLD/include/agar/config/have_execvp.h
echo "#define HAVE_EXECVP \"$HAVE_EXECVP\"" >> $BLD/include/agar/config/have_execvp.h
echo "#endif" >> $BLD/include/agar/config/have_execvp.h
echo "hdefs[\"HAVE_EXECVP\"] = \"$HAVE_EXECVP\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_EXECVP="no"
echo "#undef HAVE_EXECVP" >$BLD/include/agar/config/have_execvp.h
echo "hdefs[\"HAVE_EXECVP\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for clock_gettime() interface (w/o -lrt)..."
$ECHO_N "checking for clock_gettime() interface (w/o -lrt)..." >> config.log
CLOCK_CFLAGS=""
CLOCK_LIBS=""
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <time.h>
int
main(int argc, char *argv[])
{
	struct timespec ts;
	clock_gettime(CLOCK_REALTIME, &ts);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CLOCK_CFLAGS} -o $testdir/conftest conftest.c ${CLOCK_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CLOCK_CFLAGS} -o $testdir/conftest conftest.c ${CLOCK_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CLOCK_GETTIME="yes"
echo "#ifndef HAVE_CLOCK_GETTIME" > $BLD/include/agar/config/have_clock_gettime.h
echo "#define HAVE_CLOCK_GETTIME \"$HAVE_CLOCK_GETTIME\"" >> $BLD/include/agar/config/have_clock_gettime.h
echo "#endif" >> $BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = \"$HAVE_CLOCK_GETTIME\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CLOCK_GETTIME="no"
echo "#undef HAVE_CLOCK_GETTIME" >$BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_CLOCK_GETTIME}" = "yes" ]; then
echo "#ifndef HAVE_CLOCK_GETTIME" > $BLD/include/agar/config/have_clock_gettime.h
echo "#define HAVE_CLOCK_GETTIME \"$HAVE_CLOCK_GETTIME\"" >> $BLD/include/agar/config/have_clock_gettime.h
echo "#endif" >> $BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = \"$HAVE_CLOCK_GETTIME\"" >>configure.lua
echo "#ifndef CLOCK_CFLAGS" > $BLD/include/agar/config/clock_cflags.h
echo "#define CLOCK_CFLAGS \"$CLOCK_CFLAGS\"" >> $BLD/include/agar/config/clock_cflags.h
echo "#endif" >> $BLD/include/agar/config/clock_cflags.h
echo "hdefs[\"CLOCK_CFLAGS\"] = \"$CLOCK_CFLAGS\"" >>configure.lua
echo "#ifndef CLOCK_LIBS" > $BLD/include/agar/config/clock_libs.h
echo "#define CLOCK_LIBS \"$CLOCK_LIBS\"" >> $BLD/include/agar/config/clock_libs.h
echo "#endif" >> $BLD/include/agar/config/clock_libs.h
echo "hdefs[\"CLOCK_LIBS\"] = \"$CLOCK_LIBS\"" >>configure.lua
else
$ECHO_N "checking for clock_gettime() interface (with -lrt)..."
$ECHO_N "checking for clock_gettime() interface (with -lrt)..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <time.h>
int
main(int argc, char *argv[])
{
	struct timespec ts;
	clock_gettime(CLOCK_REALTIME, &ts);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CLOCK_CFLAGS} -o $testdir/conftest conftest.c -lrt" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CLOCK_CFLAGS} -o $testdir/conftest conftest.c -lrt 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CLOCK_GETTIME="yes"
echo "#ifndef HAVE_CLOCK_GETTIME" > $BLD/include/agar/config/have_clock_gettime.h
echo "#define HAVE_CLOCK_GETTIME \"$HAVE_CLOCK_GETTIME\"" >> $BLD/include/agar/config/have_clock_gettime.h
echo "#endif" >> $BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = \"$HAVE_CLOCK_GETTIME\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CLOCK_GETTIME="no"
echo "#undef HAVE_CLOCK_GETTIME" >$BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_CLOCK_GETTIME}" = "yes" ]; then
CLOCK_LIBS="-lrt"
echo "#ifndef HAVE_CLOCK_GETTIME" > $BLD/include/agar/config/have_clock_gettime.h
echo "#define HAVE_CLOCK_GETTIME \"$HAVE_CLOCK_GETTIME\"" >> $BLD/include/agar/config/have_clock_gettime.h
echo "#endif" >> $BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = \"$HAVE_CLOCK_GETTIME\"" >>configure.lua
echo "#ifndef CLOCK_CFLAGS" > $BLD/include/agar/config/clock_cflags.h
echo "#define CLOCK_CFLAGS \"$CLOCK_CFLAGS\"" >> $BLD/include/agar/config/clock_cflags.h
echo "#endif" >> $BLD/include/agar/config/clock_cflags.h
echo "hdefs[\"CLOCK_CFLAGS\"] = \"$CLOCK_CFLAGS\"" >>configure.lua
echo "#ifndef CLOCK_LIBS" > $BLD/include/agar/config/clock_libs.h
echo "#define CLOCK_LIBS \"$CLOCK_LIBS\"" >> $BLD/include/agar/config/clock_libs.h
echo "#endif" >> $BLD/include/agar/config/clock_libs.h
echo "hdefs[\"CLOCK_LIBS\"] = \"$CLOCK_LIBS\"" >>configure.lua
else
echo "#undef HAVE_CLOCK_GETTIME" >$BLD/include/agar/config/have_clock_gettime.h
echo "hdefs[\"HAVE_CLOCK_GETTIME\"] = nil" >>configure.lua
fi;
fi;
$ECHO_N "checking for winmm time interface..."
$ECHO_N "checking for winmm time interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef _XBOX
#include <xtl.h>
#else
#include <windows.h>
#include <mmsystem.h>
#endif

int
main(int argc, char *argv[])
{
	DWORD t0;
#ifndef _XBOX
	timeBeginPeriod(1);
#endif
	t0 = timeGetTime();
	Sleep(1);
	return (t0 != 0) ? 0 : 1;
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c -lwinmm" >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c -lwinmm 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CLOCK_WIN32="yes"
echo "#ifndef HAVE_CLOCK_WIN32" > $BLD/include/agar/config/have_clock_win32.h
echo "#define HAVE_CLOCK_WIN32 \"$HAVE_CLOCK_WIN32\"" >> $BLD/include/agar/config/have_clock_win32.h
echo "#endif" >> $BLD/include/agar/config/have_clock_win32.h
echo "hdefs[\"HAVE_CLOCK_WIN32\"] = \"$HAVE_CLOCK_WIN32\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CLOCK_WIN32="no"
echo "#undef HAVE_CLOCK_WIN32" >$BLD/include/agar/config/have_clock_win32.h
echo "hdefs[\"HAVE_CLOCK_WIN32\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_CLOCK_WIN32}" = "yes" ]; then
CLOCK_CFLAGS=""
CLOCK_LIBS="-lwinmm"
echo "#ifndef HAVE_CLOCK_WIN32" > $BLD/include/agar/config/have_clock_win32.h
echo "#define HAVE_CLOCK_WIN32 \"$HAVE_CLOCK_WIN32\"" >> $BLD/include/agar/config/have_clock_win32.h
echo "#endif" >> $BLD/include/agar/config/have_clock_win32.h
echo "hdefs[\"HAVE_CLOCK_WIN32\"] = \"$HAVE_CLOCK_WIN32\"" >>configure.lua
echo "#ifndef CLOCK_CFLAGS" > $BLD/include/agar/config/clock_cflags.h
echo "#define CLOCK_CFLAGS \"$CLOCK_CFLAGS\"" >> $BLD/include/agar/config/clock_cflags.h
echo "#endif" >> $BLD/include/agar/config/clock_cflags.h
echo "hdefs[\"CLOCK_CFLAGS\"] = \"$CLOCK_CFLAGS\"" >>configure.lua
echo "#ifndef CLOCK_LIBS" > $BLD/include/agar/config/clock_libs.h
echo "#define CLOCK_LIBS \"$CLOCK_LIBS\"" >> $BLD/include/agar/config/clock_libs.h
echo "#endif" >> $BLD/include/agar/config/clock_libs.h
echo "hdefs[\"CLOCK_LIBS\"] = \"$CLOCK_LIBS\"" >>configure.lua
else
echo "#undef HAVE_CLOCK_WIN32" >$BLD/include/agar/config/have_clock_win32.h
echo "hdefs[\"HAVE_CLOCK_WIN32\"] = nil" >>configure.lua
fi;
$ECHO_N "checking for the nanosleep() function..."
$ECHO_N "checking for the nanosleep() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <time.h>

int
main(int argc, char *argv[])
{
	struct timespec rqtp, rmtp;
	int rv;

	rqtp.tv_sec = 1;
	rqtp.tv_nsec = 1000000;
	rv = nanosleep(&rqtp, &rmtp);
	return (rv == -1);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_NANOSLEEP="yes"
echo "#ifndef HAVE_NANOSLEEP" > $BLD/include/agar/config/have_nanosleep.h
echo "#define HAVE_NANOSLEEP \"$HAVE_NANOSLEEP\"" >> $BLD/include/agar/config/have_nanosleep.h
echo "#endif" >> $BLD/include/agar/config/have_nanosleep.h
echo "hdefs[\"HAVE_NANOSLEEP\"] = \"$HAVE_NANOSLEEP\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_NANOSLEEP="no"
echo "#undef HAVE_NANOSLEEP" >$BLD/include/agar/config/have_nanosleep.h
echo "hdefs[\"HAVE_NANOSLEEP\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the kqueue() mechanism..."
$ECHO_N "checking for the kqueue() mechanism..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/event.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>

int
main(int argc, char *argv[])
{
	struct kevent kev, chg;
	int kq, fd = -1, nev;

	if ((kq = kqueue()) == -1) { return (1); }
#if defined(__NetBSD__)
	EV_SET(&kev, (uintptr_t)fd, EVFILT_READ, EV_ADD|EV_ENABLE|EV_ONESHOT, 0, 0, (intptr_t)NULL);
	EV_SET(&kev, (uintptr_t)1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 0, (intptr_t)NULL);
#else
	EV_SET(&kev, fd, EVFILT_READ, EV_ADD|EV_ENABLE|EV_ONESHOT, 0, 0, NULL);
	EV_SET(&kev, 1, EVFILT_TIMER, EV_ADD|EV_ENABLE, 0, 0, NULL);
#endif
	nev = kevent(kq, &kev, 1, &chg, 1, NULL);
	return (chg.flags & EV_ERROR);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_KQUEUE="yes"
echo "#ifndef HAVE_KQUEUE" > $BLD/include/agar/config/have_kqueue.h
echo "#define HAVE_KQUEUE \"$HAVE_KQUEUE\"" >> $BLD/include/agar/config/have_kqueue.h
echo "#endif" >> $BLD/include/agar/config/have_kqueue.h
echo "hdefs[\"HAVE_KQUEUE\"] = \"$HAVE_KQUEUE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_KQUEUE="no"
echo "#undef HAVE_KQUEUE" >$BLD/include/agar/config/have_kqueue.h
echo "hdefs[\"HAVE_KQUEUE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the Linux timerfd interface..."
$ECHO_N "checking for the Linux timerfd interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/timerfd.h>

int
main(int argc, char *argv[])
{
	struct itimerspec its;
	int fd;

	if ((fd = timerfd_create(CLOCK_MONOTONIC, TFD_TIMER_ABSTIME)) != -1) {
		its.it_interval.tv_sec = 0;
		its.it_interval.tv_nsec = 0L;
		its.it_value.tv_sec = 0;
		its.it_value.tv_nsec = 0L;
		return (timerfd_settime(fd, 0, &its, NULL) == -1);
	}
	return (1);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_TIMERFD="yes"
echo "#ifndef HAVE_TIMERFD" > $BLD/include/agar/config/have_timerfd.h
echo "#define HAVE_TIMERFD \"$HAVE_TIMERFD\"" >> $BLD/include/agar/config/have_timerfd.h
echo "#endif" >> $BLD/include/agar/config/have_timerfd.h
echo "hdefs[\"HAVE_TIMERFD\"] = \"$HAVE_TIMERFD\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_TIMERFD="no"
echo "#undef HAVE_TIMERFD" >$BLD/include/agar/config/have_timerfd.h
echo "hdefs[\"HAVE_TIMERFD\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the Windows CSIDL system..."
$ECHO_N "checking for the Windows CSIDL system..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <shlobj.h>

int
main(int argc, char *argv[])
{
	WCHAR path[MAX_PATH];

	if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PROFILE, NULL, 0, path))) {
		return (0);
	} else {
		return (1);
	}
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS  -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_CSIDL="yes"
echo "#ifndef HAVE_CSIDL" > $BLD/include/agar/config/have_csidl.h
echo "#define HAVE_CSIDL \"$HAVE_CSIDL\"" >> $BLD/include/agar/config/have_csidl.h
echo "#endif" >> $BLD/include/agar/config/have_csidl.h
echo "hdefs[\"HAVE_CSIDL\"] = \"$HAVE_CSIDL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_CSIDL="no"
echo "#undef HAVE_CSIDL" >$BLD/include/agar/config/have_csidl.h
echo "hdefs[\"HAVE_CSIDL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the Xbox XDK..."
$ECHO_N "checking for the Xbox XDK..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <xtl.h>
#ifndef _XBOX
# error undefined
#endif
int
main(int argc, char *argv[])
{
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_XBOX="yes"
echo "#ifndef HAVE_XBOX" > $BLD/include/agar/config/have_xbox.h
echo "#define HAVE_XBOX \"$HAVE_XBOX\"" >> $BLD/include/agar/config/have_xbox.h
echo "#endif" >> $BLD/include/agar/config/have_xbox.h
echo "hdefs[\"HAVE_XBOX\"] = \"$HAVE_XBOX\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_XBOX="no"
echo "#undef HAVE_XBOX" >$BLD/include/agar/config/have_xbox.h
echo "hdefs[\"HAVE_XBOX\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
CFLAGS="$CFLAGS -D_AGAR_INTERNAL"
CXXFLAGS="$CXXFLAGS -D_AGAR_INTERNAL"
CFLAGS="$CFLAGS -D_BSD_SOURCE"
CXXFLAGS="$CXXFLAGS -D_BSD_SOURCE"
if [ "${enable_warnings}" = "yes" ]
 then
CFLAGS="$CFLAGS -Wall"
CXXFLAGS="$CXXFLAGS -Wall"
CFLAGS="$CFLAGS -Werror"
CXXFLAGS="$CXXFLAGS -Werror"
CFLAGS="$CFLAGS -Wmissing-prototypes"
CXXFLAGS="$CXXFLAGS -Wmissing-prototypes"
CFLAGS="$CFLAGS -Wno-switch"
CXXFLAGS="$CXXFLAGS -Wno-switch"
WNO_UNINITIALIZED="-Wno-uninitialized"
else
WNO_UNINITIALIZED=""
fi
if [ "${enable_debug}" = "yes" ]
 then
AG_DEBUG="yes"
echo "#ifndef AG_DEBUG" > $BLD/include/agar/config/ag_debug.h
echo "#define AG_DEBUG \"$AG_DEBUG\"" >> $BLD/include/agar/config/ag_debug.h
echo "#endif" >> $BLD/include/agar/config/ag_debug.h
echo "hdefs[\"AG_DEBUG\"] = \"$AG_DEBUG\"" >>configure.lua
CFLAGS="${CFLAGS} -g"
else
echo "#undef AG_DEBUG" >$BLD/include/agar/config/ag_debug.h
echo "hdefs[\"AG_DEBUG\"] = nil" >>configure.lua
fi
if [ "${enable_debug_core}" = "yes" ]
 then
AG_DEBUG_CORE="yes"
echo "#ifndef AG_DEBUG_CORE" > $BLD/include/agar/config/ag_debug_core.h
echo "#define AG_DEBUG_CORE \"$AG_DEBUG_CORE\"" >> $BLD/include/agar/config/ag_debug_core.h
echo "#endif" >> $BLD/include/agar/config/ag_debug_core.h
echo "hdefs[\"AG_DEBUG_CORE\"] = \"$AG_DEBUG_CORE\"" >>configure.lua
else
echo "#undef AG_DEBUG_CORE" >$BLD/include/agar/config/ag_debug_core.h
echo "hdefs[\"AG_DEBUG_CORE\"] = nil" >>configure.lua
fi
if [ "${enable_debug_gui}" = "yes" ]
 then
AG_DEBUG_GUI="yes"
echo "#ifndef AG_DEBUG_GUI" > $BLD/include/agar/config/ag_debug_gui.h
echo "#define AG_DEBUG_GUI \"$AG_DEBUG_GUI\"" >> $BLD/include/agar/config/ag_debug_gui.h
echo "#endif" >> $BLD/include/agar/config/ag_debug_gui.h
echo "hdefs[\"AG_DEBUG_GUI\"] = \"$AG_DEBUG_GUI\"" >>configure.lua
else
echo "#undef AG_DEBUG_GUI" >$BLD/include/agar/config/ag_debug_gui.h
echo "hdefs[\"AG_DEBUG_GUI\"] = nil" >>configure.lua
fi
if [ "${enable_legacy}" != "no" ]
 then
AG_LEGACY="yes"
echo "#ifndef AG_LEGACY" > $BLD/include/agar/config/ag_legacy.h
echo "#define AG_LEGACY \"$AG_LEGACY\"" >> $BLD/include/agar/config/ag_legacy.h
echo "#endif" >> $BLD/include/agar/config/ag_legacy.h
echo "hdefs[\"AG_LEGACY\"] = \"$AG_LEGACY\"" >>configure.lua
else
echo "#undef AG_LEGACY" >$BLD/include/agar/config/ag_legacy.h
echo "hdefs[\"AG_LEGACY\"] = nil" >>configure.lua
fi
if [ "${enable_gui}" != "no" ]
 then
ENABLE_GUI="yes"
echo "#ifndef ENABLE_GUI" > $BLD/include/agar/config/enable_gui.h
echo "#define ENABLE_GUI \"$ENABLE_GUI\"" >> $BLD/include/agar/config/enable_gui.h
echo "#endif" >> $BLD/include/agar/config/enable_gui.h
echo "hdefs[\"ENABLE_GUI\"] = \"$ENABLE_GUI\"" >>configure.lua
SUBDIR_gui="gui"
	if [ "${with_sdl}" != "no" ]
 then
$ECHO_N "checking for SDL..."
$ECHO_N "checking for SDL..." >> config.log
if [ "${prefix_sdl}" != "" ]; then
MK_EXEC_FOUND="No"

if [ "${prefix_sdl}" != "" ]; then
	if [ -e "${prefix_sdl}/bin/sdl-config" ]; then
		SDL_PREFIX=`${prefix_sdl}/bin/sdl-config --prefix`
		MK_EXEC_FOUND="Yes"
	fi
else
	SDL_PREFIX=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/sdl-config" ]; then
			SDL_PREFIX=`${path}/sdl-config --prefix`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_sdl}" != "" ]; then
	if [ -e "${prefix_sdl}/bin/sdl-config" ]; then
		SDL_VERSION=`${prefix_sdl}/bin/sdl-config --version`
		MK_EXEC_FOUND="Yes"
	fi
else
	SDL_VERSION=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/sdl-config" ]; then
			SDL_VERSION=`${path}/sdl-config --version`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_sdl}" != "" ]; then
	if [ -e "${prefix_sdl}/bin/sdl-config" ]; then
		SDL_CFLAGS=`${prefix_sdl}/bin/sdl-config --cflags`
		MK_EXEC_FOUND="Yes"
	fi
else
	SDL_CFLAGS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/sdl-config" ]; then
			SDL_CFLAGS=`${path}/sdl-config --cflags`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_sdl}" != "" ]; then
	if [ -e "${prefix_sdl}/bin/sdl-config" ]; then
		SDL_LIBS=`${prefix_sdl}/bin/sdl-config --libs`
		MK_EXEC_FOUND="Yes"
	fi
else
	SDL_LIBS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/sdl-config" ]; then
			SDL_LIBS=`${path}/sdl-config --libs`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
else
case "${host}" in
*-*-darwin*)
MK_EXEC_FOUND="No"
SDL_VERSION=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_VERSION=`${path}/sdl-config --version`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_VERSION" > ${cache}/exec-SDL_VERSION
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_VERSION
fi
if [ "${SDL_VERSION}" != "" ]; then
MK_EXEC_FOUND="No"
SDL_PREFIX=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_PREFIX=`${path}/sdl-config --prefix`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_PREFIX" > ${cache}/exec-SDL_PREFIX
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_PREFIX
fi
MK_EXEC_FOUND="No"
SDL_CFLAGS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_CFLAGS=`${path}/sdl-config --cflags`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_CFLAGS" > ${cache}/exec-SDL_CFLAGS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_CFLAGS
fi
MK_EXEC_FOUND="No"
SDL_LIBS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_LIBS=`${path}/sdl-config --libs`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_LIBS" > ${cache}/exec-SDL_LIBS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_LIBS
fi
else
$ECHO_N "framework..."
$ECHO_N "framework..." >> config.log
SDL_VERSION="1.2.15"
SDL_CFLAGS="-D_USE_SDL_FRAMEWORK"
SDL_LIBS="-framework SDL"
fi;
;;
*-*-freebsd*)
MK_EXEC_FOUND="No"
SDL_VERSION=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl11-config" ]; then
		SDL_VERSION=`${path}/sdl11-config --version`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_VERSION" > ${cache}/exec-SDL_VERSION
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_VERSION
fi
if [ "${SDL_VERSION}" != "" ]; then
MK_EXEC_FOUND="No"
SDL_PREFIX=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl11-config" ]; then
		SDL_PREFIX=`${path}/sdl11-config --prefix`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_PREFIX" > ${cache}/exec-SDL_PREFIX
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_PREFIX
fi
MK_EXEC_FOUND="No"
SDL_CFLAGS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl11-config" ]; then
		SDL_CFLAGS=`${path}/sdl11-config --cflags`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_CFLAGS" > ${cache}/exec-SDL_CFLAGS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_CFLAGS
fi
MK_EXEC_FOUND="No"
SDL_LIBS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl11-config" ]; then
		SDL_LIBS=`${path}/sdl11-config --libs`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_LIBS" > ${cache}/exec-SDL_LIBS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_LIBS
fi
else
MK_EXEC_FOUND="No"
SDL_PREFIX=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_PREFIX=`${path}/sdl-config --prefix`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_PREFIX" > ${cache}/exec-SDL_PREFIX
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_PREFIX
fi
MK_EXEC_FOUND="No"
SDL_VERSION=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_VERSION=`${path}/sdl-config --version`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_VERSION" > ${cache}/exec-SDL_VERSION
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_VERSION
fi
MK_EXEC_FOUND="No"
SDL_CFLAGS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_CFLAGS=`${path}/sdl-config --cflags`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_CFLAGS" > ${cache}/exec-SDL_CFLAGS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_CFLAGS
fi
MK_EXEC_FOUND="No"
SDL_LIBS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_LIBS=`${path}/sdl-config --libs`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_LIBS" > ${cache}/exec-SDL_LIBS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_LIBS
fi
fi;
;;
*)
MK_EXEC_FOUND="No"
SDL_PREFIX=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_PREFIX=`${path}/sdl-config --prefix`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_PREFIX" > ${cache}/exec-SDL_PREFIX
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_PREFIX
fi
MK_EXEC_FOUND="No"
SDL_VERSION=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_VERSION=`${path}/sdl-config --version`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_VERSION" > ${cache}/exec-SDL_VERSION
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_VERSION
fi
MK_EXEC_FOUND="No"
SDL_CFLAGS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_CFLAGS=`${path}/sdl-config --cflags`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_CFLAGS" > ${cache}/exec-SDL_CFLAGS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_CFLAGS
fi
MK_EXEC_FOUND="No"
SDL_LIBS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/sdl-config" ]; then
		SDL_LIBS=`${path}/sdl-config --libs`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$SDL_LIBS" > ${cache}/exec-SDL_LIBS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-SDL_LIBS
fi
;;
esac
fi;
if [ "${SDL_VERSION}" != "" ]; then
if [ "${prefix_sdl}" != "" ]; then
echo "yes ($SDL_VERSION in ${prefix_sdl})"
echo "yes ($SDL_VERSION in ${prefix_sdl})" >> config.log
else
echo "yes ($SDL_VERSION)"
echo "yes ($SDL_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$SDL_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$SDL_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$SDL_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 1 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 1 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 2 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 2 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 0 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 1.2.0 (found $SDL_VERSION); skipping."
echo "* Minimum required version is 1.2.0 (found $SDL_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_sdl}" != "" ]; then
echo "no (not in ${prefix_sdl})"
echo "no (not in ${prefix_sdl})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether SDL works..."
$ECHO_N "checking whether SDL works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef _USE_SDL_FRAMEWORK
# include <SDL/SDL.h>
# ifdef main
#  undef main
# endif
#else
# include <SDL.h>
#endif
int main(int argc, char *argv[]) {
	SDL_Surface *su;

	if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) != 0) {
		return (1);
	}
	su = SDL_CreateRGBSurface(0, 16, 16, 32, 0, 0, 0, 0);
	SDL_FreeSurface(su);
	SDL_Quit();
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SDL="yes"
echo "#ifndef HAVE_SDL" > $BLD/include/agar/config/have_sdl.h
echo "#define HAVE_SDL \"$HAVE_SDL\"" >> $BLD/include/agar/config/have_sdl.h
echo "#endif" >> $BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = \"$HAVE_SDL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SDL="no"
echo "#undef HAVE_SDL" >$BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_SDL}" = "yes" ]; then
case "${host}" in
*-*-cygwin* | *-*-mingw32*)
if [ -e  "${SDL_PREFIX}/include/SDL" ]; then
SDL_CFLAGS="-I${SDL_PREFIX}/include/SDL -D_GNU_SOURCE=1"
fi;
if [ -e  "${SDL_PREFIX}/lib/libSDL.dll.a" ]; then
SDL_LIBS="-L${SDL_PREFIX}/lib -lSDL.dll"
fi;
;;
esac
echo "#ifndef SDL_CFLAGS" > $BLD/include/agar/config/sdl_cflags.h
echo "#define SDL_CFLAGS \"$SDL_CFLAGS\"" >> $BLD/include/agar/config/sdl_cflags.h
echo "#endif" >> $BLD/include/agar/config/sdl_cflags.h
echo "hdefs[\"SDL_CFLAGS\"] = \"$SDL_CFLAGS\"" >>configure.lua
echo "#ifndef SDL_LIBS" > $BLD/include/agar/config/sdl_libs.h
echo "#define SDL_LIBS \"$SDL_LIBS\"" >> $BLD/include/agar/config/sdl_libs.h
echo "#endif" >> $BLD/include/agar/config/sdl_libs.h
echo "hdefs[\"SDL_LIBS\"] = \"$SDL_LIBS\"" >>configure.lua
else
$ECHO_N "checking whether SDL works (with X11 libs)..."
$ECHO_N "checking whether SDL works (with X11 libs)..." >> config.log
SDL_LIBS="${SDL_LIBS} -L/usr/X11R6/lib -lX11 -lXext -lXrandr -lXrender"
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef _USE_SDL_FRAMEWORK
# include <SDL/SDL.h>
# ifdef main
#  undef main
# endif
#else
# include <SDL.h>
#endif
int main(int argc, char *argv[]) {
	SDL_Surface *su;

	if (SDL_Init(SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) != 0) {
		return (1);
	}
	su = SDL_CreateRGBSurface(0, 16, 16, 32, 0, 0, 0, 0);
	SDL_FreeSurface(su);
	SDL_Quit();
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${SDL_CFLAGS} -o $testdir/conftest conftest.c ${SDL_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SDL="yes"
echo "#ifndef HAVE_SDL" > $BLD/include/agar/config/have_sdl.h
echo "#define HAVE_SDL \"$HAVE_SDL\"" >> $BLD/include/agar/config/have_sdl.h
echo "#endif" >> $BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = \"$HAVE_SDL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SDL="no"
echo "#undef HAVE_SDL" >$BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_SDL}" = "yes" ]; then
echo "#ifndef SDL_CFLAGS" > $BLD/include/agar/config/sdl_cflags.h
echo "#define SDL_CFLAGS \"$SDL_CFLAGS\"" >> $BLD/include/agar/config/sdl_cflags.h
echo "#endif" >> $BLD/include/agar/config/sdl_cflags.h
echo "hdefs[\"SDL_CFLAGS\"] = \"$SDL_CFLAGS\"" >>configure.lua
echo "#ifndef SDL_LIBS" > $BLD/include/agar/config/sdl_libs.h
echo "#define SDL_LIBS \"$SDL_LIBS\"" >> $BLD/include/agar/config/sdl_libs.h
echo "#endif" >> $BLD/include/agar/config/sdl_libs.h
echo "hdefs[\"SDL_LIBS\"] = \"$SDL_LIBS\"" >>configure.lua
else
echo "#undef SDL_CFLAGS" >$BLD/include/agar/config/sdl_cflags.h
echo "hdefs[\"SDL_CFLAGS\"] = nil" >>configure.lua
SDL_CFLAGS=""
echo "#undef SDL_LIBS" >$BLD/include/agar/config/sdl_libs.h
echo "hdefs[\"SDL_LIBS\"] = nil" >>configure.lua
SDL_LIBS=""
fi;
fi;
else
echo "#undef HAVE_SDL" >$BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = nil" >>configure.lua
echo "#undef SDL_CFLAGS" >$BLD/include/agar/config/sdl_cflags.h
echo "hdefs[\"SDL_CFLAGS\"] = nil" >>configure.lua
echo "#undef SDL_LIBS" >$BLD/include/agar/config/sdl_libs.h
echo "hdefs[\"SDL_LIBS\"] = nil" >>configure.lua
fi;
		if [ "${HAVE_SDL}" != "yes" ]
 then
			if [ "${with_sdl}" = "yes" ]
 then
				echo "*"
				echo "* --with-sdl was requested, but the SDL "
				echo "* library was not found."
				echo "*"
				exit 1
			else
echo "#undef HAVE_SDL" >$BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = nil" >>configure.lua
			fi
		fi
	else
echo "#undef HAVE_SDL" >$BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = nil" >>configure.lua
	fi
	if [ "${with_gl}" != "no" ]
 then
$ECHO_N "checking for OpenGL..."
$ECHO_N "checking for OpenGL..." >> config.log
GL_CFLAGS=""
GL_LIBS=""
GL_FOUND=""
if [ "${prefix_gl}" != "" ]; then
if [ -e  "${prefix_gl}/include" ]; then
GL_CFLAGS="-I${prefix_gl}/include"
GL_LIBS="${GL_LIBS} -L${prefix_gl}/lib"
GL_FOUND="yes"
fi;
else
case "${host}" in
*-*-darwin*)
$ECHO_N "framework..."
$ECHO_N "framework..." >> config.log
OPENGL_CFLAGS="-D_USE_OPENGL_FRAMEWORK"
OPENGL_LIBS="-framework OpenGL"
GL_FOUND="yes"
;;
*)
if [ -e  "/usr/include/X11/GL" ]; then
GL_CFLAGS="-I/usr/include/X11"
GL_FOUND="yes"
fi;
if [ -e  "/usr/include/X11R6/GL" ]; then
GL_CFLAGS="-I/usr/include/X11R6"
GL_FOUND="yes"
fi;
if [ -e  "/usr/include/X11R7/GL" ]; then
GL_CFLAGS="-I/usr/include/X11R7"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/X11/include/GL" ]; then
GL_CFLAGS="-I/usr/local/X11/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/X11R6/include/GL" ]; then
GL_CFLAGS="-I/usr/local/X11R6/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/X11R7/include/GL" ]; then
GL_CFLAGS="-I/usr/local/X11R7/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/include/X11/GL" ]; then
GL_CFLAGS="-I/usr/local/include/X11"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/include/X11R6/GL" ]; then
GL_CFLAGS="-I/usr/local/include/X11R6"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/include/X11R7/GL" ]; then
GL_CFLAGS="-I/usr/local/include/X11R7"
GL_FOUND="yes"
fi;
if [ -e  "/usr/X11/include/GL" ]; then
GL_CFLAGS="-I/usr/X11/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/X11R6/include/GL" ]; then
GL_CFLAGS="-I/usr/X11R6/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/X11R7/include/GL" ]; then
GL_CFLAGS="-I/usr/X11R7/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/include/GL" ]; then
GL_CFLAGS="-I/usr/local/include"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/X11/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/local/X11/lib"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/X11R6/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/local/X11R6/lib"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/X11R7/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/local/X11R7/lib"
GL_FOUND="yes"
fi;
if [ -e  "/usr/X11/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/X11/lib"
GL_FOUND="yes"
fi;
if [ -e  "/usr/X11R6/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/X11R6/lib"
GL_FOUND="yes"
fi;
if [ -e  "/usr/X11R7/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/X11R7/lib"
GL_FOUND="yes"
fi;
if [ -e  "/usr/local/lib" ]; then
GL_LIBS="${GL_LIBS} -L/usr/local/lib"
GL_FOUND="yes"
fi;
;;
esac
fi;
if [ "${GL_FOUND}" = "yes" ]; then
echo "yes"
echo "yes" >> config.log
case "${host}" in
*-*-darwin*)
;;
*-*-cygwin* | *-*-mingw32*)
$ECHO_N "checking whether -lopengl32 works..."
$ECHO_N "checking whether -lopengl32 works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef _USE_OPENGL_FRAMEWORK
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
#endif
int main(int argc, char *argv[]) {
	glFlush();
	glLoadIdentity();
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c -lopengl32" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c -lopengl32 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_LIBOPENGL32="yes"
echo "#ifndef HAVE_LIBOPENGL32" > $BLD/include/agar/config/have_libopengl32.h
echo "#define HAVE_LIBOPENGL32 \"$HAVE_LIBOPENGL32\"" >> $BLD/include/agar/config/have_libopengl32.h
echo "#endif" >> $BLD/include/agar/config/have_libopengl32.h
echo "hdefs[\"HAVE_LIBOPENGL32\"] = \"$HAVE_LIBOPENGL32\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_LIBOPENGL32="no"
echo "#undef HAVE_LIBOPENGL32" >$BLD/include/agar/config/have_libopengl32.h
echo "hdefs[\"HAVE_LIBOPENGL32\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_LIBOPENGL32}" = "yes" ]; then
OPENGL_LIBS="${GL_LIBS} -lopengl32"
else
OPENGL_LIBS="${GL_LIBS} -lGL"
fi;
;;
*)
OPENGL_CFLAGS="${GL_CFLAGS}"
OPENGL_LIBS="${GL_LIBS} -lGL"
;;
esac
$ECHO_N "checking whether OpenGL works..."
$ECHO_N "checking whether OpenGL works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef _USE_OPENGL_FRAMEWORK
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
#endif
int main(int argc, char *argv[]) {
	glFlush();
	glLoadIdentity();
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c ${OPENGL_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c ${OPENGL_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_OPENGL="yes"
echo "#ifndef HAVE_OPENGL" > $BLD/include/agar/config/have_opengl.h
echo "#define HAVE_OPENGL \"$HAVE_OPENGL\"" >> $BLD/include/agar/config/have_opengl.h
echo "#endif" >> $BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = \"$HAVE_OPENGL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_OPENGL="no"
echo "#undef HAVE_OPENGL" >$BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_OPENGL}" = "yes" ]; then
echo "#ifndef OPENGL_CFLAGS" > $BLD/include/agar/config/opengl_cflags.h
echo "#define OPENGL_CFLAGS \"$OPENGL_CFLAGS\"" >> $BLD/include/agar/config/opengl_cflags.h
echo "#endif" >> $BLD/include/agar/config/opengl_cflags.h
echo "hdefs[\"OPENGL_CFLAGS\"] = \"$OPENGL_CFLAGS\"" >>configure.lua
echo "#ifndef OPENGL_LIBS" > $BLD/include/agar/config/opengl_libs.h
echo "#define OPENGL_LIBS \"$OPENGL_LIBS\"" >> $BLD/include/agar/config/opengl_libs.h
echo "#endif" >> $BLD/include/agar/config/opengl_libs.h
echo "hdefs[\"OPENGL_LIBS\"] = \"$OPENGL_LIBS\"" >>configure.lua
else
$ECHO_N "checking whether -lGL requires -lm..."
$ECHO_N "checking whether -lGL requires -lm..." >> config.log
OPENGL_LIBS="${OPENGL_LIBS} -lm"
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#ifdef _USE_OPENGL_FRAMEWORK
# include <OpenGL/gl.h>
#else
# include <GL/gl.h>
#endif
int main(int argc, char *argv[]) {
	glFlush();
	glLoadIdentity();
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c ${OPENGL_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c ${OPENGL_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_OPENGL="yes"
echo "#ifndef HAVE_OPENGL" > $BLD/include/agar/config/have_opengl.h
echo "#define HAVE_OPENGL \"$HAVE_OPENGL\"" >> $BLD/include/agar/config/have_opengl.h
echo "#endif" >> $BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = \"$HAVE_OPENGL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_OPENGL="no"
echo "#undef HAVE_OPENGL" >$BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_OPENGL}" = "yes" ]; then
echo "#ifndef OPENGL_CFLAGS" > $BLD/include/agar/config/opengl_cflags.h
echo "#define OPENGL_CFLAGS \"$OPENGL_CFLAGS\"" >> $BLD/include/agar/config/opengl_cflags.h
echo "#endif" >> $BLD/include/agar/config/opengl_cflags.h
echo "hdefs[\"OPENGL_CFLAGS\"] = \"$OPENGL_CFLAGS\"" >>configure.lua
echo "#ifndef OPENGL_LIBS" > $BLD/include/agar/config/opengl_libs.h
echo "#define OPENGL_LIBS \"$OPENGL_LIBS\"" >> $BLD/include/agar/config/opengl_libs.h
echo "#endif" >> $BLD/include/agar/config/opengl_libs.h
echo "hdefs[\"OPENGL_LIBS\"] = \"$OPENGL_LIBS\"" >>configure.lua
else
echo "#undef OPENGL_CFLAGS" >$BLD/include/agar/config/opengl_cflags.h
echo "hdefs[\"OPENGL_CFLAGS\"] = nil" >>configure.lua
OPENGL_CFLAGS=""
echo "#undef OPENGL_LIBS" >$BLD/include/agar/config/opengl_libs.h
echo "hdefs[\"OPENGL_LIBS\"] = nil" >>configure.lua
OPENGL_LIBS=""
fi;
fi;
else
echo "no"
echo "no" >> config.log
fi;
		if [ "${HAVE_OPENGL}" = "yes" ]
 then
SDL_CFLAGS="$SDL_CFLAGS $OPENGL_CFLAGS"
		else
			if [ "${with_gl}" = "yes" ]
 then
				echo "*"
				echo "* --with-gl was requested, but no OpenGL"
				echo "* library was found."
				echo "*"
				exit 1
			else
echo "#undef HAVE_OPENGL" >$BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = nil" >>configure.lua
			fi
		fi
	else
echo "#undef HAVE_OPENGL" >$BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = nil" >>configure.lua
	fi
	
	if [ "${with_x}" != "no" ]
 then
$ECHO_N "checking for the X window system..."
$ECHO_N "checking for the X window system..." >> config.log
if [ "${PKGCONFIG}" != "" -a "`${PKGCONFIG} --variable=prefix x11 2>/dev/null`" != "" ]; then
if [ "${prefix_x}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix x11 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_x}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, x11 is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_x}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct x11 prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		X11_VERSION=`$PKGCONFIG x11 --modversion 2>/dev/null`
	fi
else
	X11_VERSION=`$PKGCONFIG x11 --modversion 2>/dev/null`
fi
if [ "${prefix_x}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix x11 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_x}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, x11 is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_x}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct x11 prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		X11_CFLAGS=`$PKGCONFIG x11 --cflags 2>/dev/null`
	fi
else
	X11_CFLAGS=`$PKGCONFIG x11 --cflags 2>/dev/null`
fi
if [ "${prefix_x}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix x11 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_x}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, x11 is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_x}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct x11 prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		X11_LIBS=`$PKGCONFIG x11 --libs 2>/dev/null`
	fi
else
	X11_LIBS=`$PKGCONFIG x11 --libs 2>/dev/null`
fi
else
X11_CFLAGS=""
X11_LIBS=""
if [ "${prefix_x}" != "" ]; then
if [ -e  "${prefix_x}/include/X11" ]; then
X11_CFLAGS="-I${prefix_x}/include"
fi;
if [ -e  "${prefix_x}/lib" ]; then
X11_LIBS="-L${prefix_x}/lib -lX11"
fi;
else
if [ "${with_x_libraries}" != "" ]; then
if [ -e  "${with_x_includes}/X11" ]; then
X11_CFLAGS="-I${with_x_includes}/X11"
else
X11_CFLAGS="-I${with_x_includes}"
fi;
X11_LIBS="-L${with_x_libraries} -lX11"
else
if [ -e  "/usr/local/include/X11" ]; then
X11_CFLAGS="-I/usr/local/include"
break
fi;
if [ -e  "/usr/include/X11" ]; then
X11_CFLAGS="-I/usr/include"
break
fi;
if [ -e  "/usr/include/X11/X11" ]; then
X11_CFLAGS="-I/usr/include/X11"
break
fi;
if [ -e  "/usr/include/X11R7/X11" ]; then
X11_CFLAGS="-I/usr/include/X11R7"
break
fi;
if [ -e  "/usr/include/X11R6/X11" ]; then
X11_CFLAGS="-I/usr/include/X11R6"
break
fi;
if [ -e  "/usr/include/X11R5/X11" ]; then
X11_CFLAGS="-I/usr/include/X11R5"
break
fi;
if [ -e  "/usr/include/X11R4/X11" ]; then
X11_CFLAGS="-I/usr/include/X11R4"
break
fi;
if [ -e  "/usr/local/X11/include/X11" ]; then
X11_CFLAGS="-I/usr/local/X11/include"
break
fi;
if [ -e  "/usr/local/X11R7/include/X11" ]; then
X11_CFLAGS="-I/usr/local/X11R7/include"
break
fi;
if [ -e  "/usr/local/X11R6/include/X11" ]; then
X11_CFLAGS="-I/usr/local/X11R6/include"
break
fi;
if [ -e  "/usr/local/X11R5/include/X11" ]; then
X11_CFLAGS="-I/usr/local/X11R5/include"
break
fi;
if [ -e  "/usr/local/X11R4/include/X11" ]; then
X11_CFLAGS="-I/usr/local/X11R4/include"
break
fi;
if [ -e  "/usr/local/include/X11/X11" ]; then
X11_CFLAGS="-I/usr/local/include/X11"
break
fi;
if [ -e  "/usr/local/include/X11R7/X11" ]; then
X11_CFLAGS="-I/usr/local/include/X11R7"
break
fi;
if [ -e  "/usr/local/include/X11R6/X11" ]; then
X11_CFLAGS="-I/usr/local/include/X11R6"
break
fi;
if [ -e  "/usr/local/include/X11R5/X11" ]; then
X11_CFLAGS="-I/usr/local/include/X11R5"
break
fi;
if [ -e  "/usr/local/include/X11R4/X11" ]; then
X11_CFLAGS="-I/usr/local/include/X11R4"
break
fi;
if [ -e  "/usr/X11/include/X11" ]; then
X11_CFLAGS="-I/usr/X11/include"
break
fi;
if [ -e  "/usr/X11R7/include/X11" ]; then
X11_CFLAGS="-I/usr/X11R7/include"
break
fi;
if [ -e  "/usr/X11R6/include/X11" ]; then
X11_CFLAGS="-I/usr/X11R6/include"
break
fi;
if [ -e  "/usr/X11R5/include/X11" ]; then
X11_CFLAGS="-I/usr/X11R5/include"
break
fi;
if [ -e  "/usr/X11R4/include/X11" ]; then
X11_CFLAGS="-I/usr/X11R4/include"
break
fi;
if [ -e  "/opt/X11/include/X11" ]; then
X11_CFLAGS="-I/opt/X11/include"
break
fi;
if [ -e  "/usr/local/lib/libX11.so" ]; then
X11_LIBS="-L/usr/local/lib -lX11"
break
fi;
if [ -e  "/usr/local/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/local/lib -lX11"
break
fi;
if [ -e  "/usr/lib/libX11.so" ]; then
X11_LIBS="-L/usr/lib -lX11"
break
fi;
if [ -e  "/usr/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11/lib/libX11.so" ]; then
X11_LIBS="-L/usr/local/X11/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/local/X11/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R7/lib/libX11.so" ]; then
X11_LIBS="-L/usr/local/X11R7/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R7/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/local/X11R7/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R6/lib/libX11.so" ]; then
X11_LIBS="-L/usr/local/X11R6/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R6/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/local/X11R6/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R5/lib/libX11.so" ]; then
X11_LIBS="-L/usr/local/X11R5/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R5/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/local/X11R5/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R4/lib/libX11.so" ]; then
X11_LIBS="-L/usr/local/X11R4/lib -lX11"
break
fi;
if [ -e  "/usr/local/X11R4/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/local/X11R4/lib -lX11"
break
fi;
if [ -e  "/usr/X11/lib/libX11.so" ]; then
X11_LIBS="-L/usr/X11/lib -lX11"
break
fi;
if [ -e  "/usr/X11/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/X11/lib -lX11"
break
fi;
if [ -e  "/usr/X11R7/lib/libX11.so" ]; then
X11_LIBS="-L/usr/X11R7/lib -lX11"
break
fi;
if [ -e  "/usr/X11R7/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/X11R7/lib -lX11"
break
fi;
if [ -e  "/usr/X11R6/lib/libX11.so" ]; then
X11_LIBS="-L/usr/X11R6/lib -lX11"
break
fi;
if [ -e  "/usr/X11R6/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/X11R6/lib -lX11"
break
fi;
if [ -e  "/usr/X11R5/lib/libX11.so" ]; then
X11_LIBS="-L/usr/X11R5/lib -lX11"
break
fi;
if [ -e  "/usr/X11R5/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/X11R5/lib -lX11"
break
fi;
if [ -e  "/usr/X11R4/lib/libX11.so" ]; then
X11_LIBS="-L/usr/X11R4/lib -lX11"
break
fi;
if [ -e  "/usr/X11R4/lib/libX11.so.*" ]; then
X11_LIBS="-L/usr/X11R4/lib -lX11"
break
fi;
if [ -e  "/opt/X11/lib/libX11.so" ]; then
X11_LIBS="-L/opt/X11/lib -lX11"
break
fi;
if [ -e  "/opt/X11/lib/libX11.so.*" ]; then
X11_LIBS="-L/opt/X11/lib -lX11"
break
fi;
fi;
fi;
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <X11/Xlib.h>
int main(int argc, char *argv[])
{
	Display *disp;
	disp = XOpenDisplay(NULL);
	XCloseDisplay(disp);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${X11_CFLAGS} -o $testdir/conftest conftest.c ${X11_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${X11_CFLAGS} -o $testdir/conftest conftest.c ${X11_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_X11="yes"
echo "#ifndef HAVE_X11" > $BLD/include/agar/config/have_x11.h
echo "#define HAVE_X11 \"$HAVE_X11\"" >> $BLD/include/agar/config/have_x11.h
echo "#endif" >> $BLD/include/agar/config/have_x11.h
echo "hdefs[\"HAVE_X11\"] = \"$HAVE_X11\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_X11="no"
echo "#undef HAVE_X11" >$BLD/include/agar/config/have_x11.h
echo "hdefs[\"HAVE_X11\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_X11}" = "yes" ]; then
echo "#ifndef X11_CFLAGS" > $BLD/include/agar/config/x11_cflags.h
echo "#define X11_CFLAGS \"$X11_CFLAGS\"" >> $BLD/include/agar/config/x11_cflags.h
echo "#endif" >> $BLD/include/agar/config/x11_cflags.h
echo "hdefs[\"X11_CFLAGS\"] = \"$X11_CFLAGS\"" >>configure.lua
echo "#ifndef X11_LIBS" > $BLD/include/agar/config/x11_libs.h
echo "#define X11_LIBS \"$X11_LIBS\"" >> $BLD/include/agar/config/x11_libs.h
echo "#endif" >> $BLD/include/agar/config/x11_libs.h
echo "hdefs[\"X11_LIBS\"] = \"$X11_LIBS\"" >>configure.lua
else
echo "#undef X11_CFLAGS" >$BLD/include/agar/config/x11_cflags.h
echo "hdefs[\"X11_CFLAGS\"] = nil" >>configure.lua
X11_CFLAGS=""
echo "#undef X11_LIBS" >$BLD/include/agar/config/x11_libs.h
echo "hdefs[\"X11_LIBS\"] = nil" >>configure.lua
X11_LIBS=""
fi;
if [ "${HAVE_X11}" = "yes" ]; then
$ECHO_N "checking for the XKB extension..."
$ECHO_N "checking for the XKB extension..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <X11/Xlib.h>
#include <X11/XKBlib.h>
int main(int argc, char *argv[])
{
	Display *disp;
	KeyCode kc = 0;
	KeySym ks;
	disp = XOpenDisplay(NULL);
	ks = XkbKeycodeToKeysym(disp, kc, 0, 0);
	XCloseDisplay(disp);
	return (ks != NoSymbol);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${X11_CFLAGS} -o $testdir/conftest conftest.c ${X11_LIBS} -lX11" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${X11_CFLAGS} -o $testdir/conftest conftest.c ${X11_LIBS} -lX11 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_XKB="yes"
echo "#ifndef HAVE_XKB" > $BLD/include/agar/config/have_xkb.h
echo "#define HAVE_XKB \"$HAVE_XKB\"" >> $BLD/include/agar/config/have_xkb.h
echo "#endif" >> $BLD/include/agar/config/have_xkb.h
echo "hdefs[\"HAVE_XKB\"] = \"$HAVE_XKB\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_XKB="no"
echo "#undef HAVE_XKB" >$BLD/include/agar/config/have_xkb.h
echo "hdefs[\"HAVE_XKB\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
else
echo "#undef HAVE_XKB" >$BLD/include/agar/config/have_xkb.h
echo "hdefs[\"HAVE_XKB\"] = nil" >>configure.lua
fi;
		if [ "${HAVE_X11}" != "yes" ]
 then
			if [ "${with_x}" = "yes" ]
 then
				echo "*"
				echo "* --with-x was requested, but Xlib "
				echo "* was not found."
				echo "*"
				exit 1
			else
echo "#undef HAVE_X11" >$BLD/include/agar/config/have_x11.h
echo "hdefs[\"HAVE_X11\"] = nil" >>configure.lua
			fi
		fi
		if [ "${with_xinerama}" != "no" ]
 then
$ECHO_N "checking for the Xinerama extension..."
$ECHO_N "checking for the Xinerama extension..." >> config.log
if [ "${PKGCONFIG}" != "" -a "`${PKGCONFIG} --variable=prefix xinerama 2>/dev/null`" != "" ]; then
if [ "${prefix_xinerama}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix xinerama 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_xinerama}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, xinerama is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_xinerama}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct xinerama prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		XINERAMA_VERSION=`$PKGCONFIG xinerama --modversion 2>/dev/null`
	fi
else
	XINERAMA_VERSION=`$PKGCONFIG xinerama --modversion 2>/dev/null`
fi
if [ "${prefix_xinerama}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix xinerama 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_xinerama}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, xinerama is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_xinerama}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct xinerama prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		XINERAMA_CFLAGS=`$PKGCONFIG xinerama --cflags 2>/dev/null`
	fi
else
	XINERAMA_CFLAGS=`$PKGCONFIG xinerama --cflags 2>/dev/null`
fi
if [ "${prefix_xinerama}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix xinerama 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_xinerama}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, xinerama is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_xinerama}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct xinerama prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		XINERAMA_LIBS=`$PKGCONFIG xinerama --libs 2>/dev/null`
	fi
else
	XINERAMA_LIBS=`$PKGCONFIG xinerama --libs 2>/dev/null`
fi
else
XINERAM_CFLAGS=""
XINERAMA_LIBS=""
if [ "${prefix_xinerama}" != "" ]; then
if [ -e  "${prefix_xinerama}/include/X11" ]; then
XINERAMA_CFLAGS="-I${prefix_xinerama}/include"
fi;
if [ -e  "${prefix_xinerama}/lib" ]; then
XINERAMA_LIBS="-L${prefix_xinerama}/lib"
fi;
else
if [ -e  "/usr/include/X11/X11" ]; then
XINERAMA_CFLAGS="-I/usr/include/X11"
fi;
if [ -e  "/usr/include/X11R6/X11" ]; then
XINERAMA_CFLAGS="-I/usr/include/X11R6"
fi;
if [ -e  "/usr/local/X11/include/X11" ]; then
XINERAMA_CFLAGS="-I/usr/local/X11/include"
fi;
if [ -e  "/usr/local/X11R6/include/X11" ]; then
XINERAMA_CFLAGS="-I/usr/local/X11R6/include"
fi;
if [ -e  "/usr/local/include/X11/X11" ]; then
XINERAMA_CFLAGS="-I/usr/local/include/X11"
fi;
if [ -e  "/usr/local/include/X11R6/X11" ]; then
XINERAMA_CFLAGS="-I/usr/local/include/X11R6"
fi;
if [ -e  "/usr/X11/include/X11" ]; then
XINERAMA_CFLAGS="-I/usr/X11/include"
fi;
if [ -e  "/usr/X11R6/include/X11" ]; then
XINERAMA_CFLAGS="-I/usr/X11R6/include"
fi;
if [ -e  "/usr/local/X11/lib" ]; then
XINERAMA_LIBS="${XINERAMA_LIBS} -L/usr/local/X11/lib"
fi;
if [ -e  "/usr/local/X11R6/lib" ]; then
XINERAMA_LIBS="${XINERAMA_LIBS} -L/usr/local/X11R6/lib"
fi;
if [ -e  "/usr/X11/lib" ]; then
XINERAMA_LIBS="${XINERAMA_LIBS} -L/usr/X11/lib"
fi;
if [ -e  "/usr/X11R6/lib" ]; then
XINERAMA_LIBS="${XINERAMA_LIBS} -L/usr/X11R6/lib"
fi;
fi;
XINERAMA_LIBS="${XINERAMA_LIBS} -lXinerama"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <X11/Xlib.h>
#include <X11/extensions/Xinerama.h>

int main(int argc, char *argv[])
{
	Display *disp;
	int event_base = 0, error_base = 0;
	int rv = 1;

	disp = XOpenDisplay(NULL);
	if (XineramaQueryExtension(disp, &event_base, &error_base)) {
		rv = 0;
	}
	XCloseDisplay(disp);
	return (rv);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${X11_CFLAGS} ${XINERAMA_CFLAGS} -o $testdir/conftest conftest.c ${X11_LIBS} ${XINERAMA_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${X11_CFLAGS} ${XINERAMA_CFLAGS} -o $testdir/conftest conftest.c ${X11_LIBS} ${XINERAMA_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_XINERAMA="yes"
echo "#ifndef HAVE_XINERAMA" > $BLD/include/agar/config/have_xinerama.h
echo "#define HAVE_XINERAMA \"$HAVE_XINERAMA\"" >> $BLD/include/agar/config/have_xinerama.h
echo "#endif" >> $BLD/include/agar/config/have_xinerama.h
echo "hdefs[\"HAVE_XINERAMA\"] = \"$HAVE_XINERAMA\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_XINERAMA="no"
echo "#undef HAVE_XINERAMA" >$BLD/include/agar/config/have_xinerama.h
echo "hdefs[\"HAVE_XINERAMA\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_XINERAMA}" = "yes" ]; then
echo "#ifndef XINERAMA_CFLAGS" > $BLD/include/agar/config/xinerama_cflags.h
echo "#define XINERAMA_CFLAGS \"$XINERAMA_CFLAGS\"" >> $BLD/include/agar/config/xinerama_cflags.h
echo "#endif" >> $BLD/include/agar/config/xinerama_cflags.h
echo "hdefs[\"XINERAMA_CFLAGS\"] = \"$XINERAMA_CFLAGS\"" >>configure.lua
echo "#ifndef XINERAMA_LIBS" > $BLD/include/agar/config/xinerama_libs.h
echo "#define XINERAMA_LIBS \"$XINERAMA_LIBS\"" >> $BLD/include/agar/config/xinerama_libs.h
echo "#endif" >> $BLD/include/agar/config/xinerama_libs.h
echo "hdefs[\"XINERAMA_LIBS\"] = \"$XINERAMA_LIBS\"" >>configure.lua
else
echo "#undef XINERAMA_CFLAGS" >$BLD/include/agar/config/xinerama_cflags.h
echo "hdefs[\"XINERAMA_CFLAGS\"] = nil" >>configure.lua
XINERAMA_CFLAGS=""
echo "#undef XINERAMA_LIBS" >$BLD/include/agar/config/xinerama_libs.h
echo "hdefs[\"XINERAMA_LIBS\"] = nil" >>configure.lua
XINERAMA_LIBS=""
fi;
			if [ "${HAVE_XINERAMA}" != "yes" ]
 then
				if [ "${with_xinerama}" = "yes" ]
 then
					echo "*"
					echo "* --with-xinerama was requested, but the "
					echo "* Xinerama extension was not found."
					echo "*"
					exit 1
				else
echo "#undef HAVE_XINERAMA" >$BLD/include/agar/config/have_xinerama.h
echo "hdefs[\"HAVE_XINERAMA\"] = nil" >>configure.lua
				fi
			fi
		else
echo "#undef HAVE_XINERAMA" >$BLD/include/agar/config/have_xinerama.h
echo "hdefs[\"HAVE_XINERAMA\"] = nil" >>configure.lua
		fi
	else
echo "#undef HAVE_X11" >$BLD/include/agar/config/have_x11.h
echo "hdefs[\"HAVE_X11\"] = nil" >>configure.lua
	fi
	
	if [ "${with_cocoa}" != "no" ]
 then
$ECHO_N "checking for the Cocoa framework..."
$ECHO_N "checking for the Cocoa framework..." >> config.log
COCOA_CFLAGS="-DTARGET_API_MAC_CARBON -DTARGET_API_MAC_OSX -force_cpusubtype_ALL -fpascal-strings"
COCOA_LIBS="-lobjc -Wl,-framework,Cocoa -Wl,-framework,OpenGL -Wl,-framework,IOKit"
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.m
#import <Cocoa/Cocoa.h>

int main(int argc, char *argv[]) { return (0); }

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${COCOA_CFLAGS} -x objective-c -o $testdir/conftest conftest.m ${COCOA_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${COCOA_CFLAGS} -x objective-c -o $testdir/conftest conftest.m ${COCOA_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_COCOA="yes"
echo "#ifndef HAVE_COCOA" > $BLD/include/agar/config/have_cocoa.h
echo "#define HAVE_COCOA \"$HAVE_COCOA\"" >> $BLD/include/agar/config/have_cocoa.h
echo "#endif" >> $BLD/include/agar/config/have_cocoa.h
echo "hdefs[\"HAVE_COCOA\"] = \"$HAVE_COCOA\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_COCOA="no"
echo "#undef HAVE_COCOA" >$BLD/include/agar/config/have_cocoa.h
echo "hdefs[\"HAVE_COCOA\"] = nil" >>configure.lua
fi;
rm -f conftest.m $testdir/conftest$EXECSUFFIX
if [ "${HAVE_COCOA}" = "yes" ]; then
echo "#ifndef COCOA_CFLAGS" > $BLD/include/agar/config/cocoa_cflags.h
echo "#define COCOA_CFLAGS \"$COCOA_CFLAGS\"" >> $BLD/include/agar/config/cocoa_cflags.h
echo "#endif" >> $BLD/include/agar/config/cocoa_cflags.h
echo "hdefs[\"COCOA_CFLAGS\"] = \"$COCOA_CFLAGS\"" >>configure.lua
echo "#ifndef COCOA_LIBS" > $BLD/include/agar/config/cocoa_libs.h
echo "#define COCOA_LIBS \"$COCOA_LIBS\"" >> $BLD/include/agar/config/cocoa_libs.h
echo "#endif" >> $BLD/include/agar/config/cocoa_libs.h
echo "hdefs[\"COCOA_LIBS\"] = \"$COCOA_LIBS\"" >>configure.lua
else
echo "#undef COCOA_CFLAGS" >$BLD/include/agar/config/cocoa_cflags.h
echo "hdefs[\"COCOA_CFLAGS\"] = nil" >>configure.lua
COCOA_CFLAGS=""
echo "#undef COCOA_LIBS" >$BLD/include/agar/config/cocoa_libs.h
echo "hdefs[\"COCOA_LIBS\"] = nil" >>configure.lua
COCOA_LIBS=""
fi;
		if [ "${HAVE_COCOA}" != "yes" ]
 then
			if [ "${with_cocoa}" = "yes" ]
 then
				echo "*"
				echo "* --with-cocoa was requested, but the "
				echo "* Cocoa framework was not found."
				echo "*"
				exit 1
			else
echo "#undef HAVE_COCOA" >$BLD/include/agar/config/have_cocoa.h
echo "hdefs[\"HAVE_COCOA\"] = nil" >>configure.lua
			fi
		fi
	else
echo "#undef HAVE_COCOA" >$BLD/include/agar/config/have_cocoa.h
echo "hdefs[\"HAVE_COCOA\"] = nil" >>configure.lua
	fi
	if [ "${HAVE_OPENGL}" = "yes" ]
 then
		if [ "${with_glx}" != "no" ]
 then
$ECHO_N "checking for the GLX interface..."
$ECHO_N "checking for the GLX interface..." >> config.log
GLX_CFLAGS="${OPENGL_CFLAGS} ${X11_CFLAGS}"
GLX_LIBS="${OPENGL_LIBS} ${X11_LIBS}"
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glx.h>
#else
#include <GL/gl.h>
#include <GL/glx.h>
#endif
int main(int argc, char *argv[]) {
	Display *d;
	XVisualInfo *xvi;
	int glxAttrs[] = { GLX_RGBA, GLX_RED_SIZE,1, GLX_DEPTH_SIZE,1, None };
	GLXContext glxCtx;
	int err, ev, s;

	d = XOpenDisplay(NULL);
	(void)glXQueryExtension(d, &err, &ev);
	s = DefaultScreen(d);
	if ((xvi = glXChooseVisual(d, s, glxAttrs)) == NULL) { return (1); }
	if ((glxCtx = glXCreateContext(d, xvi, 0, GL_FALSE)) == NULL) { return (1); }
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${GLX_CFLAGS} -o $testdir/conftest conftest.c ${GLX_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${GLX_CFLAGS} -o $testdir/conftest conftest.c ${GLX_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GLX="yes"
echo "#ifndef HAVE_GLX" > $BLD/include/agar/config/have_glx.h
echo "#define HAVE_GLX \"$HAVE_GLX\"" >> $BLD/include/agar/config/have_glx.h
echo "#endif" >> $BLD/include/agar/config/have_glx.h
echo "hdefs[\"HAVE_GLX\"] = \"$HAVE_GLX\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GLX="no"
echo "#undef HAVE_GLX" >$BLD/include/agar/config/have_glx.h
echo "hdefs[\"HAVE_GLX\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_GLX}" = "yes" ]; then
echo "#ifndef GLX_CFLAGS" > $BLD/include/agar/config/glx_cflags.h
echo "#define GLX_CFLAGS \"$GLX_CFLAGS\"" >> $BLD/include/agar/config/glx_cflags.h
echo "#endif" >> $BLD/include/agar/config/glx_cflags.h
echo "hdefs[\"GLX_CFLAGS\"] = \"$GLX_CFLAGS\"" >>configure.lua
echo "#ifndef GLX_LIBS" > $BLD/include/agar/config/glx_libs.h
echo "#define GLX_LIBS \"$GLX_LIBS\"" >> $BLD/include/agar/config/glx_libs.h
echo "#endif" >> $BLD/include/agar/config/glx_libs.h
echo "hdefs[\"GLX_LIBS\"] = \"$GLX_LIBS\"" >>configure.lua
else
echo "#undef GLX_CFLAGS" >$BLD/include/agar/config/glx_cflags.h
echo "hdefs[\"GLX_CFLAGS\"] = nil" >>configure.lua
GLX_CFLAGS=""
echo "#undef GLX_LIBS" >$BLD/include/agar/config/glx_libs.h
echo "hdefs[\"GLX_LIBS\"] = nil" >>configure.lua
GLX_LIBS=""
fi;
			if [ "${HAVE_GLX}" != "yes" ]
 then
				if [ "${with_glx}" = "yes" ]
 then
					echo "*"
					echo "* --with-glx was requested, but no"
					echo "* compatible GLX library was found."
					echo "*"
					exit 1
				else
echo "#undef HAVE_GLX" >$BLD/include/agar/config/have_glx.h
echo "hdefs[\"HAVE_GLX\"] = nil" >>configure.lua
				fi
			fi
		else
echo "#undef HAVE_GLX" >$BLD/include/agar/config/have_glx.h
echo "hdefs[\"HAVE_GLX\"] = nil" >>configure.lua
		fi
		
		if [ "${with_wgl}" != "no" ]
 then
$ECHO_N "checking for the WGL interface..."
$ECHO_N "checking for the WGL interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <windows.h>

int main(int argc, char *argv[]) {
	HWND hwnd;
	HDC hdc;
	HGLRC hglrc;

	hwnd = CreateWindowEx(0, "a", "a", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,
	    CW_USEDEFAULT, 0,0, NULL, NULL, GetModuleHandle(NULL), NULL);
	hdc = GetDC(hwnd);
	hglrc = wglCreateContext(hdc);
	SwapBuffers(hdc);
	wglDeleteContext(hglrc);
	ReleaseDC(hwnd, hdc);
	DestroyWindow(hwnd);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c ${OPENGL_LIBS} -lgdi32" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${OPENGL_CFLAGS} -o $testdir/conftest conftest.c ${OPENGL_LIBS} -lgdi32 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_WGL="yes"
echo "#ifndef HAVE_WGL" > $BLD/include/agar/config/have_wgl.h
echo "#define HAVE_WGL \"$HAVE_WGL\"" >> $BLD/include/agar/config/have_wgl.h
echo "#endif" >> $BLD/include/agar/config/have_wgl.h
echo "hdefs[\"HAVE_WGL\"] = \"$HAVE_WGL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_WGL="no"
echo "#undef HAVE_WGL" >$BLD/include/agar/config/have_wgl.h
echo "hdefs[\"HAVE_WGL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_WGL}" = "yes" ]; then
OPENGL_LIBS="${OPENGL_LIBS} -lgdi32"
echo "#ifndef OPENGL_LIBS" > $BLD/include/agar/config/opengl_libs.h
echo "#define OPENGL_LIBS \"$OPENGL_LIBS\"" >> $BLD/include/agar/config/opengl_libs.h
echo "#endif" >> $BLD/include/agar/config/opengl_libs.h
echo "hdefs[\"OPENGL_LIBS\"] = \"$OPENGL_LIBS\"" >>configure.lua
fi;
			if [ "${HAVE_WGL}" != "yes" ]
 then
				if [ "${with_wgl}" = "yes" ]
 then
					echo "*"
					echo "* --with-wgl was requested, but the"
					echo "* WGL test has failed."
					echo "*"
					exit 1
				else
echo "#undef HAVE_WGL" >$BLD/include/agar/config/have_wgl.h
echo "hdefs[\"HAVE_WGL\"] = nil" >>configure.lua
				fi
			fi
		else
echo "#undef HAVE_WGL" >$BLD/include/agar/config/have_wgl.h
echo "hdefs[\"HAVE_WGL\"] = nil" >>configure.lua
		fi
	else
echo "#undef HAVE_WGL" >$BLD/include/agar/config/have_wgl.h
echo "hdefs[\"HAVE_WGL\"] = nil" >>configure.lua
echo "#undef HAVE_GLX" >$BLD/include/agar/config/have_glx.h
echo "hdefs[\"HAVE_GLX\"] = nil" >>configure.lua
	fi
	
	if [ "${with_freetype}" != "no" ]
 then
$ECHO_N "checking for FreeType..."
$ECHO_N "checking for FreeType..." >> config.log
MK_EXEC_FOUND="No"

if [ "${prefix_freetype}" != "" ]; then
	if [ -e "${prefix_freetype}/bin/freetype-config" ]; then
		FREETYPE_VERSION=`${prefix_freetype}/bin/freetype-config --version`
		MK_EXEC_FOUND="Yes"
	fi
else
	FREETYPE_VERSION=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/freetype-config" ]; then
			FREETYPE_VERSION=`${path}/freetype-config --version`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_freetype}" != "" ]; then
	if [ -e "${prefix_freetype}/bin/freetype-config" ]; then
		FREETYPE_CFLAGS=`${prefix_freetype}/bin/freetype-config --cflags`
		MK_EXEC_FOUND="Yes"
	fi
else
	FREETYPE_CFLAGS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/freetype-config" ]; then
			FREETYPE_CFLAGS=`${path}/freetype-config --cflags`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_freetype}" != "" ]; then
	if [ -e "${prefix_freetype}/bin/freetype-config" ]; then
		FREETYPE_LIBS=`${prefix_freetype}/bin/freetype-config --libs`
		MK_EXEC_FOUND="Yes"
	fi
else
	FREETYPE_LIBS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/freetype-config" ]; then
			FREETYPE_LIBS=`${path}/freetype-config --libs`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
case "${host}" in
*-*-irix*)
if [ -e  "/usr/freeware/include" ]; then
FREETYPE_CFLAGS="${FREETYPE_CFLAGS} -I/usr/freeware/include"
fi;
;;
esac
if [ "${FREETYPE_VERSION}" != "" ]; then
if [ "${prefix_freetype}" != "" ]; then
echo "yes ($FREETYPE_VERSION in ${prefix_freetype})"
echo "yes ($FREETYPE_VERSION in ${prefix_freetype})" >> config.log
else
echo "yes ($FREETYPE_VERSION)"
echo "yes ($FREETYPE_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$FREETYPE_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$FREETYPE_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$FREETYPE_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 7 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 7 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 0 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 0 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 1 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 7.0.1 (found $FREETYPE_VERSION); skipping."
echo "* Minimum required version is 7.0.1 (found $FREETYPE_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_freetype}" != "" ]; then
echo "no (not in ${prefix_freetype})"
echo "no (not in ${prefix_freetype})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether FreeType works..."
$ECHO_N "checking whether FreeType works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
int
main(int argc, char *argv[])
{
	FT_Library library;
	FT_Face face;
	FT_Init_FreeType(&library);
	FT_New_Face(library, "foo", 0, &face);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${FREETYPE_CFLAGS} -o $testdir/conftest conftest.c ${FREETYPE_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${FREETYPE_CFLAGS} -o $testdir/conftest conftest.c ${FREETYPE_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_FREETYPE="yes"
echo "#ifndef HAVE_FREETYPE" > $BLD/include/agar/config/have_freetype.h
echo "#define HAVE_FREETYPE \"$HAVE_FREETYPE\"" >> $BLD/include/agar/config/have_freetype.h
echo "#endif" >> $BLD/include/agar/config/have_freetype.h
echo "hdefs[\"HAVE_FREETYPE\"] = \"$HAVE_FREETYPE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_FREETYPE="no"
echo "#undef HAVE_FREETYPE" >$BLD/include/agar/config/have_freetype.h
echo "hdefs[\"HAVE_FREETYPE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_FREETYPE}" = "yes" ]; then
echo "#ifndef FREETYPE_CFLAGS" > $BLD/include/agar/config/freetype_cflags.h
echo "#define FREETYPE_CFLAGS \"$FREETYPE_CFLAGS\"" >> $BLD/include/agar/config/freetype_cflags.h
echo "#endif" >> $BLD/include/agar/config/freetype_cflags.h
echo "hdefs[\"FREETYPE_CFLAGS\"] = \"$FREETYPE_CFLAGS\"" >>configure.lua
echo "#ifndef FREETYPE_LIBS" > $BLD/include/agar/config/freetype_libs.h
echo "#define FREETYPE_LIBS \"$FREETYPE_LIBS\"" >> $BLD/include/agar/config/freetype_libs.h
echo "#endif" >> $BLD/include/agar/config/freetype_libs.h
echo "hdefs[\"FREETYPE_LIBS\"] = \"$FREETYPE_LIBS\"" >>configure.lua
else
echo "#undef FREETYPE_CFLAGS" >$BLD/include/agar/config/freetype_cflags.h
echo "hdefs[\"FREETYPE_CFLAGS\"] = nil" >>configure.lua
FREETYPE_CFLAGS=""
echo "#undef FREETYPE_LIBS" >$BLD/include/agar/config/freetype_libs.h
echo "hdefs[\"FREETYPE_LIBS\"] = nil" >>configure.lua
FREETYPE_LIBS=""
fi;
else
echo "#undef HAVE_FREETYPE" >$BLD/include/agar/config/have_freetype.h
echo "hdefs[\"HAVE_FREETYPE\"] = nil" >>configure.lua
fi;
		if [ "${HAVE_FREETYPE}" != "yes" ]
 then
			echo "*"
			echo "* The FreeType library was not found, aborting!"
			echo "*"
			echo "* Agar needs FreeType to display vector fonts"
			echo "* (http://www.freetype.org/)."
			echo "*"
			echo "* If you really want to use Agar's built-in"
			echo "* monospace bitmap font engine (not recommended),"
			echo "* please use: ./configure --without-freetype"
			echo "*"
			exit 1
		fi
	else
echo "#undef HAVE_FREETYPE" >$BLD/include/agar/config/have_freetype.h
echo "hdefs[\"HAVE_FREETYPE\"] = nil" >>configure.lua
	fi
	
	if [ "${with_fontconfig}" != "no" ]
 then
$ECHO_N "checking for fontconfig..."
$ECHO_N "checking for fontconfig..." >> config.log
if [ "${prefix_fontconfig}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix fontconfig 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_fontconfig}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, fontconfig is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_fontconfig}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct fontconfig prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		FONTCONFIG_VERSION=`$PKGCONFIG fontconfig --modversion 2>/dev/null`
	fi
else
	FONTCONFIG_VERSION=`$PKGCONFIG fontconfig --modversion 2>/dev/null`
fi
if [ "${prefix_fontconfig}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix fontconfig 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_fontconfig}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, fontconfig is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_fontconfig}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct fontconfig prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		FONTCONFIG_CFLAGS=`$PKGCONFIG fontconfig --cflags 2>/dev/null`
	fi
else
	FONTCONFIG_CFLAGS=`$PKGCONFIG fontconfig --cflags 2>/dev/null`
fi
if [ "${prefix_fontconfig}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix fontconfig 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_fontconfig}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, fontconfig is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_fontconfig}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct fontconfig prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		FONTCONFIG_LIBS=`$PKGCONFIG fontconfig --libs 2>/dev/null`
	fi
else
	FONTCONFIG_LIBS=`$PKGCONFIG fontconfig --libs 2>/dev/null`
fi
if [ "${FONTCONFIG_VERSION}" != "" ]; then
if [ "${prefix_fontconfig}" != "" ]; then
echo "yes ($FONTCONFIG_VERSION in ${prefix_fontconfig})"
echo "yes ($FONTCONFIG_VERSION in ${prefix_fontconfig})" >> config.log
else
echo "yes ($FONTCONFIG_VERSION)"
echo "yes ($FONTCONFIG_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$FONTCONFIG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$FONTCONFIG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$FONTCONFIG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 2 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 2 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 6 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 6 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 0 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 2.6.0 (found $FONTCONFIG_VERSION); skipping."
echo "* Minimum required version is 2.6.0 (found $FONTCONFIG_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_fontconfig}" != "" ]; then
echo "no (not in ${prefix_fontconfig})"
echo "no (not in ${prefix_fontconfig})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether fontconfig works..."
$ECHO_N "checking whether fontconfig works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <string.h>
#include <fontconfig/fontconfig.h>

int
main(int argc, char *argv[])
{
	FcPattern *pattern, *fpat;
    FcResult result = FcResultMatch;
	const FcChar8 name[1] = { '\0' };
    FcChar8 *file;
    FcMatrix *mat = NULL;
    double size;
    int idx;
    if (!FcInit()) { return (1); }
    if ((pattern = FcNameParse(name)) == NULL) { return (1); }
    if (!FcConfigSubstitute(NULL, pattern, FcMatchPattern)) { return (1); }
    FcDefaultSubstitute(pattern);
    if ((fpat = FcFontMatch(NULL, pattern, &result)) == NULL) { return (1); }
    if (FcPatternGetString(fpat, FC_FILE, 0, &file) != FcResultMatch) { return (1); }
    if (FcPatternGetInteger(fpat, FC_INDEX, 0, &idx) != FcResultMatch) { return (1); }
    if (FcPatternGetDouble(fpat, FC_SIZE, 0, &size) != FcResultMatch) { return (1); }
    if (FcPatternGetMatrix(fpat, FC_MATRIX, 0, &mat) != FcResultMatch) { return (1); }
    return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${FONTCONFIG_CFLAGS} -o $testdir/conftest conftest.c ${FONTCONFIG_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${FONTCONFIG_CFLAGS} -o $testdir/conftest conftest.c ${FONTCONFIG_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_FONTCONFIG="yes"
echo "#ifndef HAVE_FONTCONFIG" > $BLD/include/agar/config/have_fontconfig.h
echo "#define HAVE_FONTCONFIG \"$HAVE_FONTCONFIG\"" >> $BLD/include/agar/config/have_fontconfig.h
echo "#endif" >> $BLD/include/agar/config/have_fontconfig.h
echo "hdefs[\"HAVE_FONTCONFIG\"] = \"$HAVE_FONTCONFIG\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_FONTCONFIG="no"
echo "#undef HAVE_FONTCONFIG" >$BLD/include/agar/config/have_fontconfig.h
echo "hdefs[\"HAVE_FONTCONFIG\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_FONTCONFIG}" = "yes" ]; then
echo "#ifndef FONTCONFIG_CFLAGS" > $BLD/include/agar/config/fontconfig_cflags.h
echo "#define FONTCONFIG_CFLAGS \"$FONTCONFIG_CFLAGS\"" >> $BLD/include/agar/config/fontconfig_cflags.h
echo "#endif" >> $BLD/include/agar/config/fontconfig_cflags.h
echo "hdefs[\"FONTCONFIG_CFLAGS\"] = \"$FONTCONFIG_CFLAGS\"" >>configure.lua
echo "#ifndef FONTCONFIG_LIBS" > $BLD/include/agar/config/fontconfig_libs.h
echo "#define FONTCONFIG_LIBS \"$FONTCONFIG_LIBS\"" >> $BLD/include/agar/config/fontconfig_libs.h
echo "#endif" >> $BLD/include/agar/config/fontconfig_libs.h
echo "hdefs[\"FONTCONFIG_LIBS\"] = \"$FONTCONFIG_LIBS\"" >>configure.lua
else
echo "#undef FONTCONFIG_CFLAGS" >$BLD/include/agar/config/fontconfig_cflags.h
echo "hdefs[\"FONTCONFIG_CFLAGS\"] = nil" >>configure.lua
FONTCONFIG_CFLAGS=""
echo "#undef FONTCONFIG_LIBS" >$BLD/include/agar/config/fontconfig_libs.h
echo "hdefs[\"FONTCONFIG_LIBS\"] = nil" >>configure.lua
FONTCONFIG_LIBS=""
fi;
else
echo "#undef HAVE_FONTCONFIG" >$BLD/include/agar/config/have_fontconfig.h
echo "hdefs[\"HAVE_FONTCONFIG\"] = nil" >>configure.lua
fi;
	else
echo "#undef HAVE_FONTCONFIG" >$BLD/include/agar/config/have_fontconfig.h
echo "hdefs[\"HAVE_FONTCONFIG\"] = nil" >>configure.lua
	fi
	
	if [ "${with_jpeg}" != "no" ]
 then
$ECHO_N "checking for libjpeg..."
$ECHO_N "checking for libjpeg..." >> config.log
JPEG_CFLAGS=""
if [ "${prefix_jpeg}" != "" ]; then
if [ -e  "${prefix_jpeg}/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I${prefix_jpeg}/include"
JPEG_LIBS="-L${prefix_jpeg}/lib -ljpeg"
fi;
else
if [ -e  "/usr/local/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I/usr/local/include"
JPEG_LIBS="-L/usr/local/lib -ljpeg"
fi;
if [ -e  "/usr/X11R6/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I/usr/X11R6/include"
JPEG_LIBS="-L/usr/X11R6/lib -ljpeg"
fi;
if [ -e  "/usr/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I/usr/include"
JPEG_LIBS="-L/usr/lib -ljpeg"
fi;
if [ -e  "/usr/pkg/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I/usr/pkg/include"
JPEG_LIBS="-L/usr/pkg/lib -ljpeg"
fi;
if [ -e  "/opt/local/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I/opt/local/include"
JPEG_LIBS="-L/opt/local/lib -ljpeg"
fi;
if [ -e  "/opt/include/jpeglib.h" ]; then
JPEG_CFLAGS="-I/opt/include"
JPEG_LIBS="-L/opt/lib -ljpeg"
fi;
fi;
if [ "${JPEG_LIBS}" != "" ]; then
echo "yes"
echo "yes" >> config.log
$ECHO_N "checking whether libjpeg works..."
$ECHO_N "checking whether libjpeg works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <jpeglib.h>

struct jpeg_error_mgr		jerr;
struct jpeg_compress_struct	jcomp;

int
main(int argc, char *argv[])
{
	jcomp.err = jpeg_std_error(&jerr);

	jpeg_create_compress(&jcomp);
	jcomp.image_width = 32;
	jcomp.image_height = 32;
	jcomp.input_components = 3;
	jcomp.in_color_space = JCS_RGB;

	jpeg_set_defaults(&jcomp);
	jpeg_set_quality(&jcomp, 75, TRUE);

	jpeg_destroy_compress(&jcomp);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${JPEG_CFLAGS} -o $testdir/conftest conftest.c ${JPEG_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${JPEG_CFLAGS} -o $testdir/conftest conftest.c ${JPEG_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_JPEG="yes"
echo "#ifndef HAVE_JPEG" > $BLD/include/agar/config/have_jpeg.h
echo "#define HAVE_JPEG \"$HAVE_JPEG\"" >> $BLD/include/agar/config/have_jpeg.h
echo "#endif" >> $BLD/include/agar/config/have_jpeg.h
echo "hdefs[\"HAVE_JPEG\"] = \"$HAVE_JPEG\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_JPEG="no"
echo "#undef HAVE_JPEG" >$BLD/include/agar/config/have_jpeg.h
echo "hdefs[\"HAVE_JPEG\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_JPEG}" = "yes" ]; then
echo "#ifndef JPEG_CFLAGS" > $BLD/include/agar/config/jpeg_cflags.h
echo "#define JPEG_CFLAGS \"$JPEG_CFLAGS\"" >> $BLD/include/agar/config/jpeg_cflags.h
echo "#endif" >> $BLD/include/agar/config/jpeg_cflags.h
echo "hdefs[\"JPEG_CFLAGS\"] = \"$JPEG_CFLAGS\"" >>configure.lua
echo "#ifndef JPEG_LIBS" > $BLD/include/agar/config/jpeg_libs.h
echo "#define JPEG_LIBS \"$JPEG_LIBS\"" >> $BLD/include/agar/config/jpeg_libs.h
echo "#endif" >> $BLD/include/agar/config/jpeg_libs.h
echo "hdefs[\"JPEG_LIBS\"] = \"$JPEG_LIBS\"" >>configure.lua
else
echo "#undef JPEG_CFLAGS" >$BLD/include/agar/config/jpeg_cflags.h
echo "hdefs[\"JPEG_CFLAGS\"] = nil" >>configure.lua
JPEG_CFLAGS=""
echo "#undef JPEG_LIBS" >$BLD/include/agar/config/jpeg_libs.h
echo "hdefs[\"JPEG_LIBS\"] = nil" >>configure.lua
JPEG_LIBS=""
fi;
else
echo "#undef HAVE_JPEG" >$BLD/include/agar/config/have_jpeg.h
echo "hdefs[\"HAVE_JPEG\"] = nil" >>configure.lua
echo "#undef JPEG_CFLAGS" >$BLD/include/agar/config/jpeg_cflags.h
echo "hdefs[\"JPEG_CFLAGS\"] = nil" >>configure.lua
echo "#undef JPEG_LIBS" >$BLD/include/agar/config/jpeg_libs.h
echo "hdefs[\"JPEG_LIBS\"] = nil" >>configure.lua
echo "no"
echo "no" >> config.log
fi;
		if [ "${HAVE_JPEG}" != "yes" ]
 then
			if [ "${with_jpeg}" = "yes" ]
 then
				echo "*"
				echo "* --with-jpeg was requested, but libjpeg"
				echo "* was not found."
				echo "*"
				exit 1
			else
echo "#undef HAVE_JPEG" >$BLD/include/agar/config/have_jpeg.h
echo "hdefs[\"HAVE_JPEG\"] = nil" >>configure.lua
			fi
		fi
	else
echo "#undef HAVE_JPEG" >$BLD/include/agar/config/have_jpeg.h
echo "hdefs[\"HAVE_JPEG\"] = nil" >>configure.lua
	fi
	
	if [ "${with_png}" != "no" ]
 then
$ECHO_N "checking for libpng..."
$ECHO_N "checking for libpng..." >> config.log
MK_EXEC_FOUND="No"

if [ "${prefix_png}" != "" ]; then
	if [ -e "${prefix_png}/bin/libpng-config" ]; then
		PNG_VERSION=`${prefix_png}/bin/libpng-config --version`
		MK_EXEC_FOUND="Yes"
	fi
else
	PNG_VERSION=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/libpng-config" ]; then
			PNG_VERSION=`${path}/libpng-config --version`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_png}" != "" ]; then
	if [ -e "${prefix_png}/bin/libpng-config" ]; then
		PNG_CFLAGS=`${prefix_png}/bin/libpng-config --cflags`
		MK_EXEC_FOUND="Yes"
	fi
else
	PNG_CFLAGS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/libpng-config" ]; then
			PNG_CFLAGS=`${path}/libpng-config --cflags`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_png}" != "" ]; then
	if [ -e "${prefix_png}/bin/libpng-config" ]; then
		PNG_LOPTS=`${prefix_png}/bin/libpng-config --L_opts`
		MK_EXEC_FOUND="Yes"
	fi
else
	PNG_LOPTS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/libpng-config" ]; then
			PNG_LOPTS=`${path}/libpng-config --L_opts`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
MK_EXEC_FOUND="No"

if [ "${prefix_png}" != "" ]; then
	if [ -e "${prefix_png}/bin/libpng-config" ]; then
		PNG_LIBS=`${prefix_png}/bin/libpng-config --libs`
		MK_EXEC_FOUND="Yes"
	fi
else
	PNG_LIBS=""
	for path in `echo $PATH | sed 's/:/ /g'`; do
		if [ -e "${path}/libpng-config" ]; then
			PNG_LIBS=`${path}/libpng-config --libs`
			MK_EXEC_FOUND="Yes"
			break
		fi
	done
fi
PNG_LIBS="${PNG_LOPTS} ${PNG_LIBS}"
if [ "${PNG_VERSION}" != "" ]; then
if [ "${prefix_png}" != "" ]; then
echo "yes ($PNG_VERSION in ${prefix_png})"
echo "yes ($PNG_VERSION in ${prefix_png})" >> config.log
else
echo "yes ($PNG_VERSION)"
echo "yes ($PNG_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$PNG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$PNG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$PNG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 1 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 1 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 2 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 2 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 49 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 1.2.49 (found $PNG_VERSION); skipping."
echo "* Minimum required version is 1.2.49 (found $PNG_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_png}" != "" ]; then
echo "no (not in ${prefix_png})"
echo "no (not in ${prefix_png})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether libpng works..."
$ECHO_N "checking whether libpng works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <png.h>

int main(int argc, char *argv[])
{
	char foo[4];

	if (png_sig_cmp((png_bytep)foo, 0, 3)) {
		return (1);
	}
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PNG_CFLAGS} -o $testdir/conftest conftest.c ${PNG_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PNG_CFLAGS} -o $testdir/conftest conftest.c ${PNG_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PNG="yes"
echo "#ifndef HAVE_PNG" > $BLD/include/agar/config/have_png.h
echo "#define HAVE_PNG \"$HAVE_PNG\"" >> $BLD/include/agar/config/have_png.h
echo "#endif" >> $BLD/include/agar/config/have_png.h
echo "hdefs[\"HAVE_PNG\"] = \"$HAVE_PNG\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PNG="no"
echo "#undef HAVE_PNG" >$BLD/include/agar/config/have_png.h
echo "hdefs[\"HAVE_PNG\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PNG}" = "yes" ]; then
echo "#ifndef PNG_CFLAGS" > $BLD/include/agar/config/png_cflags.h
echo "#define PNG_CFLAGS \"$PNG_CFLAGS\"" >> $BLD/include/agar/config/png_cflags.h
echo "#endif" >> $BLD/include/agar/config/png_cflags.h
echo "hdefs[\"PNG_CFLAGS\"] = \"$PNG_CFLAGS\"" >>configure.lua
echo "#ifndef PNG_LIBS" > $BLD/include/agar/config/png_libs.h
echo "#define PNG_LIBS \"$PNG_LIBS\"" >> $BLD/include/agar/config/png_libs.h
echo "#endif" >> $BLD/include/agar/config/png_libs.h
echo "hdefs[\"PNG_LIBS\"] = \"$PNG_LIBS\"" >>configure.lua
else
echo "#undef PNG_CFLAGS" >$BLD/include/agar/config/png_cflags.h
echo "hdefs[\"PNG_CFLAGS\"] = nil" >>configure.lua
PNG_CFLAGS=""
echo "#undef PNG_LIBS" >$BLD/include/agar/config/png_libs.h
echo "hdefs[\"PNG_LIBS\"] = nil" >>configure.lua
PNG_LIBS=""
fi;
MK_VERSION_MAJOR=`echo "$PNG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$PNG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$PNG_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 1 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 1 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 4 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 4 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 0 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "yes" ]; then
HAVE_LIBPNG14="yes"
echo "#ifndef HAVE_LIBPNG14" > $BLD/include/agar/config/have_libpng14.h
echo "#define HAVE_LIBPNG14 \"$HAVE_LIBPNG14\"" >> $BLD/include/agar/config/have_libpng14.h
echo "#endif" >> $BLD/include/agar/config/have_libpng14.h
echo "hdefs[\"HAVE_LIBPNG14\"] = \"$HAVE_LIBPNG14\"" >>configure.lua
else
echo "#undef HAVE_LIBPNG14" >$BLD/include/agar/config/have_libpng14.h
echo "hdefs[\"HAVE_LIBPNG14\"] = nil" >>configure.lua
fi;
else
echo "#undef HAVE_PNG" >$BLD/include/agar/config/have_png.h
echo "hdefs[\"HAVE_PNG\"] = nil" >>configure.lua
echo "#undef PNG_CFLAGS" >$BLD/include/agar/config/png_cflags.h
echo "hdefs[\"PNG_CFLAGS\"] = nil" >>configure.lua
echo "#undef PNG_LIBS" >$BLD/include/agar/config/png_libs.h
echo "hdefs[\"PNG_LIBS\"] = nil" >>configure.lua
echo "#undef HAVE_LIBPNG14" >$BLD/include/agar/config/have_libpng14.h
echo "hdefs[\"HAVE_LIBPNG14\"] = nil" >>configure.lua
fi;
		if [ "${HAVE_PNG}" != "yes" ]
 then
			if [ "${with_png}" = "yes" ]
 then
				echo "*"
				echo "* --with-png was requested, but libpng"
				echo "* was not found."
				echo "*"
				exit 1
			else
echo "#undef HAVE_PNG" >$BLD/include/agar/config/have_png.h
echo "hdefs[\"HAVE_PNG\"] = nil" >>configure.lua
echo "#undef HAVE_LIBPNG14" >$BLD/include/agar/config/have_libpng14.h
echo "hdefs[\"HAVE_LIBPNG14\"] = nil" >>configure.lua
			fi
		fi
	else
echo "#undef HAVE_PNG" >$BLD/include/agar/config/have_png.h
echo "hdefs[\"HAVE_PNG\"] = nil" >>configure.lua
echo "#undef HAVE_LIBPNG14" >$BLD/include/agar/config/have_libpng14.h
echo "hdefs[\"HAVE_LIBPNG14\"] = nil" >>configure.lua
	fi
else
echo "#undef ENABLE_GUI" >$BLD/include/agar/config/enable_gui.h
echo "hdefs[\"ENABLE_GUI\"] = nil" >>configure.lua
SUBDIR_gui=""
echo "#undef HAVE_SDL" >$BLD/include/agar/config/have_sdl.h
echo "hdefs[\"HAVE_SDL\"] = nil" >>configure.lua
echo "#undef HAVE_X11" >$BLD/include/agar/config/have_x11.h
echo "hdefs[\"HAVE_X11\"] = nil" >>configure.lua
echo "#undef HAVE_COCOA" >$BLD/include/agar/config/have_cocoa.h
echo "hdefs[\"HAVE_COCOA\"] = nil" >>configure.lua
echo "#undef HAVE_OPENGL" >$BLD/include/agar/config/have_opengl.h
echo "hdefs[\"HAVE_OPENGL\"] = nil" >>configure.lua
echo "#undef HAVE_GLX" >$BLD/include/agar/config/have_glx.h
echo "hdefs[\"HAVE_GLX\"] = nil" >>configure.lua
echo "#undef HAVE_WGL" >$BLD/include/agar/config/have_wgl.h
echo "hdefs[\"HAVE_WGL\"] = nil" >>configure.lua
echo "#undef HAVE_FREETYPE" >$BLD/include/agar/config/have_freetype.h
echo "hdefs[\"HAVE_FREETYPE\"] = nil" >>configure.lua
echo "#undef HAVE_FONTCONFIG" >$BLD/include/agar/config/have_fontconfig.h
echo "hdefs[\"HAVE_FONTCONFIG\"] = nil" >>configure.lua
echo "#undef HAVE_JPEG" >$BLD/include/agar/config/have_jpeg.h
echo "hdefs[\"HAVE_JPEG\"] = nil" >>configure.lua
echo "#undef HAVE_PNG" >$BLD/include/agar/config/have_png.h
echo "hdefs[\"HAVE_PNG\"] = nil" >>configure.lua
echo "#undef HAVE_LIBPNG14" >$BLD/include/agar/config/have_libpng14.h
echo "hdefs[\"HAVE_LIBPNG14\"] = nil" >>configure.lua
fi
if [ "${enable_network}" != "no" ]
 then
$ECHO_N "checking for the getaddrinfo() function..."
$ECHO_N "checking for the getaddrinfo() function..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

int
main(int argc, char *argv[])
{
	struct addrinfo hints, *res0;
	const char *s;
	int rv;

	hints.ai_family = PF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_flags = AI_PASSIVE;
	rv = getaddrinfo("hostname", "port", &hints, &res0);
	s = gai_strerror(rv);
	freeaddrinfo(res0);
	return (s != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETADDRINFO="yes"
echo "#ifndef HAVE_GETADDRINFO" > $BLD/include/agar/config/have_getaddrinfo.h
echo "#define HAVE_GETADDRINFO \"$HAVE_GETADDRINFO\"" >> $BLD/include/agar/config/have_getaddrinfo.h
echo "#endif" >> $BLD/include/agar/config/have_getaddrinfo.h
echo "hdefs[\"HAVE_GETADDRINFO\"] = \"$HAVE_GETADDRINFO\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETADDRINFO="no"
echo "#undef HAVE_GETADDRINFO" >$BLD/include/agar/config/have_getaddrinfo.h
echo "hdefs[\"HAVE_GETADDRINFO\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the SIOCGIFCONF interface..."
$ECHO_N "checking for the SIOCGIFCONF interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <unistd.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <netdb.h>
int
main(int argc, char *argv[])
{
	char buf[4096];
	struct ifconf conf;
	struct ifreq *ifr;
	int sock;
	if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
		return (1);
	}
	conf.ifc_len = sizeof(buf);
	conf.ifc_buf = (caddr_t)buf;
	if (ioctl(sock, SIOCGIFCONF, &conf) < 0) {
		return (1);
	}
#if !defined(_SIZEOF_ADDR_IFREQ)
#define _SIZEOF_ADDR_IFREQ sizeof
#endif
	for (ifr = (struct ifreq *)buf;
	     (char *)ifr < &buf[conf.ifc_len];
	     ifr = (struct ifreq *)((char *)ifr + _SIZEOF_ADDR_IFREQ(*ifr))) {
		if (ifr->ifr_addr.sa_family == AF_INET)
			return (1);
	}
	close(sock);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SIOCGIFCONF="yes"
echo "#ifndef HAVE_SIOCGIFCONF" > $BLD/include/agar/config/have_siocgifconf.h
echo "#define HAVE_SIOCGIFCONF \"$HAVE_SIOCGIFCONF\"" >> $BLD/include/agar/config/have_siocgifconf.h
echo "#endif" >> $BLD/include/agar/config/have_siocgifconf.h
echo "hdefs[\"HAVE_SIOCGIFCONF\"] = \"$HAVE_SIOCGIFCONF\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SIOCGIFCONF="no"
echo "#undef HAVE_SIOCGIFCONF" >$BLD/include/agar/config/have_siocgifconf.h
echo "hdefs[\"HAVE_SIOCGIFCONF\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for the setsockopt() interface..."
$ECHO_N "checking for the setsockopt() interface..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, rv;
	struct timeval tv;
	socklen_t tvLen = sizeof(tv);
	tv.tv_sec = 1; tv.tv_usec = 0;
	rv = setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, tvLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SETSOCKOPT="yes"
echo "#ifndef HAVE_SETSOCKOPT" > $BLD/include/agar/config/have_setsockopt.h
echo "#define HAVE_SETSOCKOPT \"$HAVE_SETSOCKOPT\"" >> $BLD/include/agar/config/have_setsockopt.h
echo "#endif" >> $BLD/include/agar/config/have_setsockopt.h
echo "hdefs[\"HAVE_SETSOCKOPT\"] = \"$HAVE_SETSOCKOPT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SETSOCKOPT="no"
echo "#undef HAVE_SETSOCKOPT" >$BLD/include/agar/config/have_setsockopt.h
echo "hdefs[\"HAVE_SETSOCKOPT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_SETSOCKOPT}" = "yes" ]; then
$ECHO_N "checking for SO_OOBINLINE..."
$ECHO_N "checking for SO_OOBINLINE..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, val = 1, rv;
	socklen_t valLen = sizeof(val);
	rv = setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &val, valLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SO_OOBINLINE="yes"
echo "#ifndef HAVE_SO_OOBINLINE" > $BLD/include/agar/config/have_so_oobinline.h
echo "#define HAVE_SO_OOBINLINE \"$HAVE_SO_OOBINLINE\"" >> $BLD/include/agar/config/have_so_oobinline.h
echo "#endif" >> $BLD/include/agar/config/have_so_oobinline.h
echo "hdefs[\"HAVE_SO_OOBINLINE\"] = \"$HAVE_SO_OOBINLINE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SO_OOBINLINE="no"
echo "#undef HAVE_SO_OOBINLINE" >$BLD/include/agar/config/have_so_oobinline.h
echo "hdefs[\"HAVE_SO_OOBINLINE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for SO_REUSEPORT..."
$ECHO_N "checking for SO_REUSEPORT..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, val = 1, rv;
	socklen_t valLen = sizeof(val);
	rv = setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &val, valLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SO_REUSEPORT="yes"
echo "#ifndef HAVE_SO_REUSEPORT" > $BLD/include/agar/config/have_so_reuseport.h
echo "#define HAVE_SO_REUSEPORT \"$HAVE_SO_REUSEPORT\"" >> $BLD/include/agar/config/have_so_reuseport.h
echo "#endif" >> $BLD/include/agar/config/have_so_reuseport.h
echo "hdefs[\"HAVE_SO_REUSEPORT\"] = \"$HAVE_SO_REUSEPORT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SO_REUSEPORT="no"
echo "#undef HAVE_SO_REUSEPORT" >$BLD/include/agar/config/have_so_reuseport.h
echo "hdefs[\"HAVE_SO_REUSEPORT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for SO_TIMESTAMP..."
$ECHO_N "checking for SO_TIMESTAMP..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, val = 1, rv;
	socklen_t valLen = sizeof(val);
	rv = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMP, &val, valLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SO_TIMESTAMP="yes"
echo "#ifndef HAVE_SO_TIMESTAMP" > $BLD/include/agar/config/have_so_timestamp.h
echo "#define HAVE_SO_TIMESTAMP \"$HAVE_SO_TIMESTAMP\"" >> $BLD/include/agar/config/have_so_timestamp.h
echo "#endif" >> $BLD/include/agar/config/have_so_timestamp.h
echo "hdefs[\"HAVE_SO_TIMESTAMP\"] = \"$HAVE_SO_TIMESTAMP\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SO_TIMESTAMP="no"
echo "#undef HAVE_SO_TIMESTAMP" >$BLD/include/agar/config/have_so_timestamp.h
echo "hdefs[\"HAVE_SO_TIMESTAMP\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for SO_NOSIGPIPE..."
$ECHO_N "checking for SO_NOSIGPIPE..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, val = 1, rv;
	socklen_t valLen = sizeof(val);
	rv = setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, &val, valLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SO_NOSIGPIPE="yes"
echo "#ifndef HAVE_SO_NOSIGPIPE" > $BLD/include/agar/config/have_so_nosigpipe.h
echo "#define HAVE_SO_NOSIGPIPE \"$HAVE_SO_NOSIGPIPE\"" >> $BLD/include/agar/config/have_so_nosigpipe.h
echo "#endif" >> $BLD/include/agar/config/have_so_nosigpipe.h
echo "hdefs[\"HAVE_SO_NOSIGPIPE\"] = \"$HAVE_SO_NOSIGPIPE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SO_NOSIGPIPE="no"
echo "#undef HAVE_SO_NOSIGPIPE" >$BLD/include/agar/config/have_so_nosigpipe.h
echo "hdefs[\"HAVE_SO_NOSIGPIPE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for SO_LINGER..."
$ECHO_N "checking for SO_LINGER..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, rv;
	struct linger ling;
	socklen_t lingLen = sizeof(ling);
	ling.l_onoff = 1; ling.l_linger = 1;
	rv = setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, lingLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SO_LINGER="yes"
echo "#ifndef HAVE_SO_LINGER" > $BLD/include/agar/config/have_so_linger.h
echo "#define HAVE_SO_LINGER \"$HAVE_SO_LINGER\"" >> $BLD/include/agar/config/have_so_linger.h
echo "#endif" >> $BLD/include/agar/config/have_so_linger.h
echo "hdefs[\"HAVE_SO_LINGER\"] = \"$HAVE_SO_LINGER\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SO_LINGER="no"
echo "#undef HAVE_SO_LINGER" >$BLD/include/agar/config/have_so_linger.h
echo "hdefs[\"HAVE_SO_LINGER\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
$ECHO_N "checking for SO_ACCEPTFILTER..."
$ECHO_N "checking for SO_ACCEPTFILTER..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
	int fd = 0, rv;
	struct accept_filter_arg afa;
	socklen_t afaLen = sizeof(afa);
	afa.af_name[0] = '\0';
	afa.af_arg[0] = '\0';
	rv = setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, afaLen);
	return (rv != 0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c" >>config.log
$CC $CFLAGS $TEST_CFLAGS -o $testdir/conftest conftest.c 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SO_ACCEPTFILTER="yes"
echo "#ifndef HAVE_SO_ACCEPTFILTER" > $BLD/include/agar/config/have_so_acceptfilter.h
echo "#define HAVE_SO_ACCEPTFILTER \"$HAVE_SO_ACCEPTFILTER\"" >> $BLD/include/agar/config/have_so_acceptfilter.h
echo "#endif" >> $BLD/include/agar/config/have_so_acceptfilter.h
echo "hdefs[\"HAVE_SO_ACCEPTFILTER\"] = \"$HAVE_SO_ACCEPTFILTER\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SO_ACCEPTFILTER="no"
echo "#undef HAVE_SO_ACCEPTFILTER" >$BLD/include/agar/config/have_so_acceptfilter.h
echo "hdefs[\"HAVE_SO_ACCEPTFILTER\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
fi;
$ECHO_N "checking for the WinSock interface..."
$ECHO_N "checking for the WinSock interface..." >> config.log
echo "no"
echo "no" >> config.log
HAVE_WINSOCK1="no"
HAVE_WINSOCK2="no"
echo "#undef HAVE_WINSOCK1" >$BLD/include/agar/config/have_winsock1.h
echo "hdefs[\"HAVE_WINSOCK1\"] = nil" >>configure.lua
echo "#undef HAVE_WINSOCK2" >$BLD/include/agar/config/have_winsock2.h
echo "hdefs[\"HAVE_WINSOCK2\"] = nil" >>configure.lua
HAVE_NETWORK="yes"
AG_NETWORK="yes"
echo "#ifndef AG_NETWORK" > $BLD/include/agar/config/ag_network.h
echo "#define AG_NETWORK \"$AG_NETWORK\"" >> $BLD/include/agar/config/ag_network.h
echo "#endif" >> $BLD/include/agar/config/ag_network.h
echo "hdefs[\"AG_NETWORK\"] = \"$AG_NETWORK\"" >>configure.lua
else
HAVE_NETWORK="no"
echo "#undef AG_NETWORK" >$BLD/include/agar/config/ag_network.h
echo "hdefs[\"AG_NETWORK\"] = nil" >>configure.lua
echo "#undef HAVE_GETADDRINFO" >$BLD/include/agar/config/have_getaddrinfo.h
echo "hdefs[\"HAVE_GETADDRINFO\"] = nil" >>configure.lua
echo "#undef HAVE_SETSOCKOPT" >$BLD/include/agar/config/have_setsockopt.h
echo "hdefs[\"HAVE_SETSOCKOPT\"] = nil" >>configure.lua
echo "#undef HAVE_SO_OOBINLINE" >$BLD/include/agar/config/have_so_oobinline.h
echo "hdefs[\"HAVE_SO_OOBINLINE\"] = nil" >>configure.lua
echo "#undef HAVE_SO_REUSEPORT" >$BLD/include/agar/config/have_so_reuseport.h
echo "hdefs[\"HAVE_SO_REUSEPORT\"] = nil" >>configure.lua
echo "#undef HAVE_SO_TIMESTAMP" >$BLD/include/agar/config/have_so_timestamp.h
echo "hdefs[\"HAVE_SO_TIMESTAMP\"] = nil" >>configure.lua
echo "#undef HAVE_SO_NOSIGPIPE" >$BLD/include/agar/config/have_so_nosigpipe.h
echo "hdefs[\"HAVE_SO_NOSIGPIPE\"] = nil" >>configure.lua
echo "#undef HAVE_SO_LINGER" >$BLD/include/agar/config/have_so_linger.h
echo "hdefs[\"HAVE_SO_LINGER\"] = nil" >>configure.lua
echo "#undef HAVE_SO_ACCEPTFILTER" >$BLD/include/agar/config/have_so_acceptfilter.h
echo "hdefs[\"HAVE_SO_ACCEPTFILTER\"] = nil" >>configure.lua
echo "#undef HAVE_WINSOCK1" >$BLD/include/agar/config/have_winsock1.h
echo "hdefs[\"HAVE_WINSOCK1\"] = nil" >>configure.lua
echo "#undef HAVE_WINSOCK2" >$BLD/include/agar/config/have_winsock2.h
echo "hdefs[\"HAVE_WINSOCK2\"] = nil" >>configure.lua
echo "#undef HAVE_SIOCGIFCONF" >$BLD/include/agar/config/have_siocgifconf.h
echo "hdefs[\"HAVE_SIOCGIFCONF\"] = nil" >>configure.lua
fi
	
if [ "${with_db4}" != "no" ]
 then
$ECHO_N "checking for Berkeley DB 4.x..."
$ECHO_N "checking for Berkeley DB 4.x..." >> config.log
DB4_CFLAGS=""
DB4_LIBS=""
DB4_VERSION=""

for path in ${prefix_db4} /usr /usr/local /opt; do
	if [ -e "${path}/include/db4.8" ]; then
		DB4_CFLAGS="-I${path}/include/db4.8 -I${path}/include"
		DB4_VERSION="4.8"
	elif [ -e "${path}/include/db4.7" ]; then
		DB4_CFLAGS="-I${path}/include/db4.7 -I${path}/include"
		DB4_VERSION="4.7"
	elif [ -e "${path}/include/db4.6" ]; then
		DB4_CFLAGS="-I${path}/include/db4.6 -I${path}/include"
		DB4_VERSION="4.6"
	elif [ -e "${path}/include/db4.5" ]; then
		DB4_CFLAGS="-I${path}/include/db4.5 -I${path}/include"
		DB4_VERSION="4.5"
	elif [ -e "${path}/include/db4.4" ]; then
		DB4_CFLAGS="-I${path}/include/db4.4 -I${path}/include"
		DB4_VERSION="4.4"
	elif [ -e "${path}/include/db4.3" ]; then
		DB4_CFLAGS="-I${path}/include/db4.3 -I${path}/include"
		DB4_VERSION="4.3"
	elif [ -e "${path}/include/db4.2" ]; then
		DB4_CFLAGS="-I${path}/include/db4.2 -I${path}/include"
		DB4_VERSION="4.2"
	elif [ -e "${path}/include/db47" ]; then
		DB4_CFLAGS="-I${path}/include/db47 -I${path}/include"
		DB4_VERSION="4.7"
	elif [ -e "${path}/include/db46" ]; then
		DB4_CFLAGS="-I${path}/include/db46 -I${path}/include"
		DB4_VERSION="4.6"
	elif [ -e "${path}/include/db45" ]; then
		DB4_CFLAGS="-I${path}/include/db45 -I${path}/include"
		DB4_VERSION="4.5"
	elif [ -e "${path}/include/db44" ]; then
		DB4_CFLAGS="-I${path}/include/db44 -I${path}/include"
		DB4_VERSION="4.4"
	elif [ -e "${path}/include/db43" ]; then
		DB4_CFLAGS="-I${path}/include/db43 -I${path}/include"
		DB4_VERSION="4.3"
	elif [ -e "${path}/include/db42" ]; then
		DB4_CFLAGS="-I${path}/include/db42 -I${path}/include"
		DB4_VERSION="4.2"
	elif [ -e "${path}/include/db4" ]; then
		DB4_CFLAGS="-I${path}/include/db4 -I${path}/include"
		DB4_VERSION="4"
	fi
	case "${DB4_VERSION}" in
	4)
		if [ -e "${path}/lib/db4" ]; then
			DB4_LIBS="-L${path}/lib/db4 -ldb"
		fi
		;;
	4.2)
		if [ -e "${path}/lib/db42" ]; then
			DB4_LIBS="-L${path}/lib/db42 -ldb"
		elif [ -e "${path}/lib/libdb-4.2.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.2"
		fi
		;;
	4.3)
		if [ -e "${path}/lib/db43" ]; then
			DB4_LIBS="-L${path}/lib/db43 -ldb"
		elif [ -e "${path}/lib/libdb-4.3.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.3"
		fi
		;;
	4.4)
		if [ -e "${path}/lib/db44" ]; then
			DB4_LIBS="-L${path}/lib/db44 -ldb"
		elif [ -e "${path}/lib/libdb-4.4.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.4"
		fi
		;;
	4.5)
		if [ -e "${path}/lib/db45" ]; then
			DB4_LIBS="-L${path}/lib/db45 -ldb"
		elif [ -e "${path}/lib/libdb-4.5.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.5"
		fi
		;;
	4.6)
		if [ -e "${path}/lib/db46" ]; then
			DB4_LIBS="-L${path}/lib/db46 -ldb"
		elif [ -e "${path}/lib/libdb-4.6.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.6"
		fi
		;;
	4.7)
		if [ -e "${path}/lib/db47" ]; then
			DB4_LIBS="-L${path}/lib/db47 -ldb"
		elif [ -e "${path}/lib/libdb-4.7.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.7"
		fi
		;;
	4.8)
		if [ -e "${path}/lib/db48" ]; then
			DB4_LIBS="-L${path}/lib/db48 -ldb"
		elif [ -e "${path}/lib/libdb-4.8.so" ]; then
			DB4_LIBS="-L${path}/lib -ldb-4.8"
		fi
		;;
	*)
		;;
	esac
done
if [ "${DB4_VERSION}" != "" ]; then
if [ "${prefix_db4}" != "" ]; then
echo "yes ($DB4_VERSION in ${prefix_db4})"
echo "yes ($DB4_VERSION in ${prefix_db4})" >> config.log
else
echo "yes ($DB4_VERSION)"
echo "yes ($DB4_VERSION)" >> config.log
fi;
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 0 (found $DB4_VERSION); skipping."
echo "* Minimum required version is 0 (found $DB4_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_db4}" != "" ]; then
echo "no (not in ${prefix_db4})"
echo "no (not in ${prefix_db4})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether DB4 works..."
$ECHO_N "checking whether DB4 works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <db.h>
#if DB_VERSION_MAJOR != 4
#error version
#endif
int main(int argc, char *argv[]) {
	DB *db;
	db_create(&db, NULL, 0);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${DB4_CFLAGS} -o $testdir/conftest conftest.c ${DB4_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${DB4_CFLAGS} -o $testdir/conftest conftest.c ${DB4_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_DB4="yes"
echo "#ifndef HAVE_DB4" > $BLD/include/agar/config/have_db4.h
echo "#define HAVE_DB4 \"$HAVE_DB4\"" >> $BLD/include/agar/config/have_db4.h
echo "#endif" >> $BLD/include/agar/config/have_db4.h
echo "hdefs[\"HAVE_DB4\"] = \"$HAVE_DB4\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_DB4="no"
echo "#undef HAVE_DB4" >$BLD/include/agar/config/have_db4.h
echo "hdefs[\"HAVE_DB4\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_DB4}" = "yes" ]; then
echo "#ifndef DB4_CFLAGS" > $BLD/include/agar/config/db4_cflags.h
echo "#define DB4_CFLAGS \"$DB4_CFLAGS\"" >> $BLD/include/agar/config/db4_cflags.h
echo "#endif" >> $BLD/include/agar/config/db4_cflags.h
echo "hdefs[\"DB4_CFLAGS\"] = \"$DB4_CFLAGS\"" >>configure.lua
echo "#ifndef DB4_LIBS" > $BLD/include/agar/config/db4_libs.h
echo "#define DB4_LIBS \"$DB4_LIBS\"" >> $BLD/include/agar/config/db4_libs.h
echo "#endif" >> $BLD/include/agar/config/db4_libs.h
echo "hdefs[\"DB4_LIBS\"] = \"$DB4_LIBS\"" >>configure.lua
else
echo "#undef DB4_CFLAGS" >$BLD/include/agar/config/db4_cflags.h
echo "hdefs[\"DB4_CFLAGS\"] = nil" >>configure.lua
DB4_CFLAGS=""
echo "#undef DB4_LIBS" >$BLD/include/agar/config/db4_libs.h
echo "hdefs[\"DB4_LIBS\"] = nil" >>configure.lua
DB4_LIBS=""
fi;
else
echo "#undef HAVE_DB4" >$BLD/include/agar/config/have_db4.h
echo "hdefs[\"HAVE_DB4\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_DB4}" != "yes" ]
 then
		if [ "${with_db4}" = "yes" ]
 then
			echo "*"
			echo "* --with-db4 was requested, but Berkeley DB"
			echo "* was not found."
			echo "*"
			exit 1
		else
echo "#undef HAVE_DB4" >$BLD/include/agar/config/have_db4.h
echo "hdefs[\"HAVE_DB4\"] = nil" >>configure.lua
		fi
	fi
else
echo "#undef HAVE_DB4" >$BLD/include/agar/config/have_db4.h
echo "hdefs[\"HAVE_DB4\"] = nil" >>configure.lua
fi
if [ "${with_mysql}" = "yes" ]
 then
$ECHO_N "checking for MySQL..."
$ECHO_N "checking for MySQL..." >> config.log
MK_EXEC_FOUND="No"
MK_CACHED="No"
MK_EXEC_UNIQUE="No"
MK_EXEC_FOUND_PATH=""
MYSQL_VERSION=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/mysql_config" ]; then
		if [ "$MK_EXEC_FOUND" = "Yes" ]; then
			echo "yes."
			echo "* Warning: Multiple 'mysql_config' exist in PATH (using $MK_EXEC_FOUND_PATH)"
			echo "* Warning: Multiple 'mysql_config' exist in PATH (using $MK_EXEC_FOUND_PATH)" >> config.log
			break
		fi
		MYSQL_VERSION=`${path}/mysql_config --version`
		MK_EXEC_FOUND="Yes"
		MK_EXEC_FOUND_PATH="${path}/mysql_config"
	fi
done
if [ "${MYSQL_VERSION}" != "" ]; then
if [ "${prefix_mysql}" != "" ]; then
echo "yes ($MYSQL_VERSION in ${prefix_mysql})"
echo "yes ($MYSQL_VERSION in ${prefix_mysql})" >> config.log
else
echo "yes ($MYSQL_VERSION)"
echo "yes ($MYSQL_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$MYSQL_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$MYSQL_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$MYSQL_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 5 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 5 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 5 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 5 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 8 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 5.5.8 (found $MYSQL_VERSION); skipping."
echo "* Minimum required version is 5.5.8 (found $MYSQL_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_mysql}" != "" ]; then
echo "no (not in ${prefix_mysql})"
echo "no (not in ${prefix_mysql})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether MySQL works..."
$ECHO_N "checking whether MySQL works..." >> config.log
MK_EXEC_FOUND="No"
MYSQL_CFLAGS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/mysql_config" ]; then
		MYSQL_CFLAGS=`${path}/mysql_config --cflags`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$MYSQL_CFLAGS" > ${cache}/exec-MYSQL_CFLAGS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-MYSQL_CFLAGS
fi
MK_EXEC_FOUND="No"
MYSQL_LIBS=""
for path in `echo $PATH | sed 's/:/ /g'`; do
	if [ -e "${path}/mysql_config" ]; then
		MYSQL_LIBS=`${path}/mysql_config --libs`
		MK_EXEC_FOUND="Yes"
		break
	fi
done
if [ "${cache}" != "" ]; then
	echo "$MYSQL_LIBS" > ${cache}/exec-MYSQL_LIBS
	echo $MK_EXEC_FOUND > ${cache}/exec-found-MYSQL_LIBS
fi
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <mysql.h>
#include <string.h>

int
main(int argc, char *argv[])
{
	MYSQL *my = mysql_init(NULL);
	if (my != NULL) { mysql_close(my); }
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${MYSQL_CFLAGS} -o $testdir/conftest conftest.c ${MYSQL_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${MYSQL_CFLAGS} -o $testdir/conftest conftest.c ${MYSQL_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_MYSQL="yes"
echo "#ifndef HAVE_MYSQL" > $BLD/include/agar/config/have_mysql.h
echo "#define HAVE_MYSQL \"$HAVE_MYSQL\"" >> $BLD/include/agar/config/have_mysql.h
echo "#endif" >> $BLD/include/agar/config/have_mysql.h
echo "hdefs[\"HAVE_MYSQL\"] = \"$HAVE_MYSQL\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_MYSQL="no"
echo "#undef HAVE_MYSQL" >$BLD/include/agar/config/have_mysql.h
echo "hdefs[\"HAVE_MYSQL\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_MYSQL}" = "yes" ]; then
echo "#ifndef MYSQL_CFLAGS" > $BLD/include/agar/config/mysql_cflags.h
echo "#define MYSQL_CFLAGS \"$MYSQL_CFLAGS\"" >> $BLD/include/agar/config/mysql_cflags.h
echo "#endif" >> $BLD/include/agar/config/mysql_cflags.h
echo "hdefs[\"MYSQL_CFLAGS\"] = \"$MYSQL_CFLAGS\"" >>configure.lua
echo "#ifndef MYSQL_LIBS" > $BLD/include/agar/config/mysql_libs.h
echo "#define MYSQL_LIBS \"$MYSQL_LIBS\"" >> $BLD/include/agar/config/mysql_libs.h
echo "#endif" >> $BLD/include/agar/config/mysql_libs.h
echo "hdefs[\"MYSQL_LIBS\"] = \"$MYSQL_LIBS\"" >>configure.lua
else
echo "#undef MYSQL_CFLAGS" >$BLD/include/agar/config/mysql_cflags.h
echo "hdefs[\"MYSQL_CFLAGS\"] = nil" >>configure.lua
MYSQL_CFLAGS=""
echo "#undef MYSQL_LIBS" >$BLD/include/agar/config/mysql_libs.h
echo "hdefs[\"MYSQL_LIBS\"] = nil" >>configure.lua
MYSQL_LIBS=""
fi;
else
echo "#undef MYSQL_CFLAGS" >$BLD/include/agar/config/mysql_cflags.h
echo "hdefs[\"MYSQL_CFLAGS\"] = nil" >>configure.lua
echo "#undef MYSQL_LIBS" >$BLD/include/agar/config/mysql_libs.h
echo "hdefs[\"MYSQL_LIBS\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_MYSQL}" != "yes" ]
 then
		if [ "${with_mysql}" = "yes" ]
 then
			echo "*"
			echo "* --with-mysql was requested, but libmysqlclient"
			echo "* was not found."
			echo "*"
			exit 1
		else
echo "#undef HAVE_MYSQL" >$BLD/include/agar/config/have_mysql.h
echo "hdefs[\"HAVE_MYSQL\"] = nil" >>configure.lua
		fi
	fi
else
echo "#undef HAVE_MYSQL" >$BLD/include/agar/config/have_mysql.h
echo "hdefs[\"HAVE_MYSQL\"] = nil" >>configure.lua
fi
if [ "${enable_threads}" != "no" ]
 then
$ECHO_N "checking for POSIX threads..."
$ECHO_N "checking for POSIX threads..." >> config.log
if [ "${prefix_pthreads}" != "" ]; then
PTHREADS_CFLAGS="-I${prefix_pthreads}/include"
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthread"
else
PTHREADS_CFLAGS=""
PTHREADS_LIBS="-lpthread"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>

static void *start_routine(void *arg)
{
	return (NULL);
}
int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_t thread;
	pthread_mutex_init(&mutex, NULL);
	pthread_mutex_lock(&mutex);
	pthread_mutex_unlock(&mutex);
	pthread_mutex_destroy(&mutex);
	pthread_create(&thread, NULL, start_routine, NULL);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREADS="yes"
echo "#ifndef HAVE_PTHREADS" > $BLD/include/agar/config/have_pthreads.h
echo "#define HAVE_PTHREADS \"$HAVE_PTHREADS\"" >> $BLD/include/agar/config/have_pthreads.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = \"$HAVE_PTHREADS\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREADS="no"
echo "#undef HAVE_PTHREADS" >$BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREADS}" = "yes" ]; then
CFLAGS="${CFLAGS} ${PTHREADS_CFLAGS}"
echo "#ifndef PTHREADS_CFLAGS" > $BLD/include/agar/config/pthreads_cflags.h
echo "#define PTHREADS_CFLAGS \"$PTHREADS_CFLAGS\"" >> $BLD/include/agar/config/pthreads_cflags.h
echo "#endif" >> $BLD/include/agar/config/pthreads_cflags.h
echo "hdefs[\"PTHREADS_CFLAGS\"] = \"$PTHREADS_CFLAGS\"" >>configure.lua
echo "#ifndef PTHREADS_LIBS" > $BLD/include/agar/config/pthreads_libs.h
echo "#define PTHREADS_LIBS \"$PTHREADS_LIBS\"" >> $BLD/include/agar/config/pthreads_libs.h
echo "#endif" >> $BLD/include/agar/config/pthreads_libs.h
echo "hdefs[\"PTHREADS_LIBS\"] = \"$PTHREADS_LIBS\"" >>configure.lua
else
$ECHO_N "checking for -pthread..."
$ECHO_N "checking for -pthread..." >> config.log
PTHREADS_LIBS="-pthread"
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>

static void *start_routine(void *arg)
{
	return (NULL);
}
int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_t thread;
	pthread_mutex_init(&mutex, NULL);
	pthread_mutex_lock(&mutex);
	pthread_mutex_unlock(&mutex);
	pthread_mutex_destroy(&mutex);
	pthread_create(&thread, NULL, start_routine, NULL);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREADS="yes"
echo "#ifndef HAVE_PTHREADS" > $BLD/include/agar/config/have_pthreads.h
echo "#define HAVE_PTHREADS \"$HAVE_PTHREADS\"" >> $BLD/include/agar/config/have_pthreads.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = \"$HAVE_PTHREADS\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREADS="no"
echo "#undef HAVE_PTHREADS" >$BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREADS}" = "yes" ]; then
CFLAGS="${CFLAGS} ${PTHREADS_CFLAGS}"
echo "#ifndef PTHREADS_CFLAGS" > $BLD/include/agar/config/pthreads_cflags.h
echo "#define PTHREADS_CFLAGS \"$PTHREADS_CFLAGS\"" >> $BLD/include/agar/config/pthreads_cflags.h
echo "#endif" >> $BLD/include/agar/config/pthreads_cflags.h
echo "hdefs[\"PTHREADS_CFLAGS\"] = \"$PTHREADS_CFLAGS\"" >>configure.lua
echo "#ifndef PTHREADS_LIBS" > $BLD/include/agar/config/pthreads_libs.h
echo "#define PTHREADS_LIBS \"$PTHREADS_LIBS\"" >> $BLD/include/agar/config/pthreads_libs.h
echo "#endif" >> $BLD/include/agar/config/pthreads_libs.h
echo "hdefs[\"PTHREADS_LIBS\"] = \"$PTHREADS_LIBS\"" >>configure.lua
else
PTHREADS_CFLAGS=""
PTHREADS_LIBS=""
$ECHO_N "checking for -pthread (common paths)..."
$ECHO_N "checking for -pthread (common paths)..." >> config.log
if [ -e  "${prefix_pthreads}/lib/pthread.h" ]; then
PTHREADS_CFLAGS="-I${prefix_pthreads}/lib"
fi;
if [ -e  "/usr/include/pthreads/pthread.h" ]; then
PTHREADS_CFLAGS="-I/usr/include/pthreads"
fi;
if [ -e  "/usr/local/include/pthread.h" ]; then
PTHREADS_CFLAGS="-I/usr/local/include"
fi;
if [ -e  "/usr/local/include/pthreads/pthread.h" ]; then
PTHREADS_CFLAGS="-I/usr/local/include/pthreads"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthread.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthread"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC1.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGC1"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC1d.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGC1d"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE1.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE1"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE1d.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE1d"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC2.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGC2"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC2d.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGC2d"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE2.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE2"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE2d.a" ]; then
PTHREADS_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE2d"
fi;
if [ -e  "/usr/local/lib/libpthread.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthread"
fi;
if [ -e  "/usr/local/lib/libpthreadGC1.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGC1"
fi;
if [ -e  "/usr/local/lib/libpthreadGC1d.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGC1d"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE1.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGCE1"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE1d.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGCE1d"
fi;
if [ -e  "/usr/local/lib/libpthreadGC2.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGC2"
fi;
if [ -e  "/usr/local/lib/libpthreadGC2d.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGC2d"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE2.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGCE2"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE2d.a" ]; then
PTHREADS_LIBS="-L/usr/local/lib -lpthreadGCE2d"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>

static void *start_routine(void *arg)
{
	return (NULL);
}
int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_t thread;
	pthread_mutex_init(&mutex, NULL);
	pthread_mutex_lock(&mutex);
	pthread_mutex_unlock(&mutex);
	pthread_mutex_destroy(&mutex);
	pthread_create(&thread, NULL, start_routine, NULL);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREADS="yes"
echo "#ifndef HAVE_PTHREADS" > $BLD/include/agar/config/have_pthreads.h
echo "#define HAVE_PTHREADS \"$HAVE_PTHREADS\"" >> $BLD/include/agar/config/have_pthreads.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = \"$HAVE_PTHREADS\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREADS="no"
echo "#undef HAVE_PTHREADS" >$BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREADS}" = "yes" ]; then
CFLAGS="${CFLAGS} ${PTHREADS_CFLAGS}"
echo "#ifndef PTHREADS_CFLAGS" > $BLD/include/agar/config/pthreads_cflags.h
echo "#define PTHREADS_CFLAGS \"$PTHREADS_CFLAGS\"" >> $BLD/include/agar/config/pthreads_cflags.h
echo "#endif" >> $BLD/include/agar/config/pthreads_cflags.h
echo "hdefs[\"PTHREADS_CFLAGS\"] = \"$PTHREADS_CFLAGS\"" >>configure.lua
echo "#ifndef PTHREADS_LIBS" > $BLD/include/agar/config/pthreads_libs.h
echo "#define PTHREADS_LIBS \"$PTHREADS_LIBS\"" >> $BLD/include/agar/config/pthreads_libs.h
echo "#endif" >> $BLD/include/agar/config/pthreads_libs.h
echo "hdefs[\"PTHREADS_LIBS\"] = \"$PTHREADS_LIBS\"" >>configure.lua
fi;
fi;
fi;
$ECHO_N "checking for the X/Open Threads Extension..."
$ECHO_N "checking for the X/Open Threads Extension..." >> config.log
case "${host}" in
*-*-freebsd* | *-*-dragonfly*)
PTHREADS_XOPEN_CFLAGS=""
;;
*)
PTHREADS_XOPEN_CFLAGS="-U_XOPEN_SOURCE -D_XOPEN_SOURCE=600"
;;
esac
if [ "${prefix_pthreads}" != "" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthread"
else
PTHREADS_XOPEN_LIBS="-lpthread"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>

int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_mutexattr_t mutexattr;
	pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&mutex, &mutexattr);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_XOPEN_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_XOPEN_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_XOPEN_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_XOPEN_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREADS_XOPEN="yes"
echo "#ifndef HAVE_PTHREADS_XOPEN" > $BLD/include/agar/config/have_pthreads_xopen.h
echo "#define HAVE_PTHREADS_XOPEN \"$HAVE_PTHREADS_XOPEN\"" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = \"$HAVE_PTHREADS_XOPEN\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREADS_XOPEN="no"
echo "#undef HAVE_PTHREADS_XOPEN" >$BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREADS_XOPEN}" = "yes" ]; then
echo "#ifndef HAVE_PTHREADS_XOPEN" > $BLD/include/agar/config/have_pthreads_xopen.h
echo "#define HAVE_PTHREADS_XOPEN \"$HAVE_PTHREADS_XOPEN\"" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = \"$HAVE_PTHREADS_XOPEN\"" >>configure.lua
echo "#ifndef PTHREADS_XOPEN_CFLAGS" > $BLD/include/agar/config/pthreads_xopen_cflags.h
echo "#define PTHREADS_XOPEN_CFLAGS \"$PTHREADS_XOPEN_CFLAGS\"" >> $BLD/include/agar/config/pthreads_xopen_cflags.h
echo "#endif" >> $BLD/include/agar/config/pthreads_xopen_cflags.h
echo "hdefs[\"PTHREADS_XOPEN_CFLAGS\"] = \"$PTHREADS_XOPEN_CFLAGS\"" >>configure.lua
echo "#ifndef PTHREADS_XOPEN_LIBS" > $BLD/include/agar/config/pthreads_xopen_libs.h
echo "#define PTHREADS_XOPEN_LIBS \"$PTHREADS_XOPEN_LIBS\"" >> $BLD/include/agar/config/pthreads_xopen_libs.h
echo "#endif" >> $BLD/include/agar/config/pthreads_xopen_libs.h
echo "hdefs[\"PTHREADS_XOPEN_LIBS\"] = \"$PTHREADS_XOPEN_LIBS\"" >>configure.lua
else
PTHREADS_XOPEN_LIBS=""
$ECHO_N "checking for the X/Open Threads Extension (common paths)..."
$ECHO_N "checking for the X/Open Threads Extension (common paths)..." >> config.log
if [ -e  "${prefix_pthreads}/lib/libpthread.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthread"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC1.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGC1"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC1d.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGC1d"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE1.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE1"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE1d.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE1d"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC2.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGC2"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGC2d.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGC2d"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE2.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE2"
fi;
if [ -e  "${prefix_pthreads}/lib/libpthreadGCE2d.a" ]; then
PTHREADS_XOPEN_LIBS="-L${prefix_pthreads}/lib -lpthreadGCE2d"
fi;
if [ -e  "/usr/local/lib/libpthread.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthread"
fi;
if [ -e  "/usr/local/lib/libpthreadGC1.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGC1"
fi;
if [ -e  "/usr/local/lib/libpthreadGC1d.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGC1d"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE1.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGCE1"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE1d.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGCE1d"
fi;
if [ -e  "/usr/local/lib/libpthreadGC2.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGC2"
fi;
if [ -e  "/usr/local/lib/libpthreadGC2d.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGC2d"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE2.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGCE2"
fi;
if [ -e  "/usr/local/lib/libpthreadGCE2d.a" ]; then
PTHREADS_XOPEN_LIBS="-L/usr/local/lib -lpthreadGCE2d"
fi;
if [ -e  "${prefix_pthreads}/lib/pthread.h" ]; then
PTHREADS_CFLAGS="-I${prefix_pthreads}/lib"
fi;
if [ -e  "/usr/include/pthreads/pthread.h" ]; then
PTHREADS_CFLAGS="-I/usr/include/pthreads"
fi;
if [ -e  "/usr/local/include/pthread.h" ]; then
PTHREADS_CFLAGS="-I/usr/local/include"
fi;
if [ -e  "/usr/local/include/pthreads/pthread.h" ]; then
PTHREADS_CFLAGS="-I/usr/local/include/pthreads"
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>

int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_mutexattr_t mutexattr;
	pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&mutex, &mutexattr);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_XOPEN_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_XOPEN_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_XOPEN_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_XOPEN_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREADS_XOPEN="yes"
echo "#ifndef HAVE_PTHREADS_XOPEN" > $BLD/include/agar/config/have_pthreads_xopen.h
echo "#define HAVE_PTHREADS_XOPEN \"$HAVE_PTHREADS_XOPEN\"" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = \"$HAVE_PTHREADS_XOPEN\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREADS_XOPEN="no"
echo "#undef HAVE_PTHREADS_XOPEN" >$BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREADS_XOPEN}" = "yes" ]; then
echo "#ifndef HAVE_PTHREADS_XOPEN" > $BLD/include/agar/config/have_pthreads_xopen.h
echo "#define HAVE_PTHREADS_XOPEN \"$HAVE_PTHREADS_XOPEN\"" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "#endif" >> $BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = \"$HAVE_PTHREADS_XOPEN\"" >>configure.lua
echo "#ifndef PTHREADS_XOPEN_CFLAGS" > $BLD/include/agar/config/pthreads_xopen_cflags.h
echo "#define PTHREADS_XOPEN_CFLAGS \"$PTHREADS_XOPEN_CFLAGS\"" >> $BLD/include/agar/config/pthreads_xopen_cflags.h
echo "#endif" >> $BLD/include/agar/config/pthreads_xopen_cflags.h
echo "hdefs[\"PTHREADS_XOPEN_CFLAGS\"] = \"$PTHREADS_XOPEN_CFLAGS\"" >>configure.lua
echo "#ifndef PTHREADS_XOPEN_LIBS" > $BLD/include/agar/config/pthreads_xopen_libs.h
echo "#define PTHREADS_XOPEN_LIBS \"$PTHREADS_XOPEN_LIBS\"" >> $BLD/include/agar/config/pthreads_xopen_libs.h
echo "#endif" >> $BLD/include/agar/config/pthreads_xopen_libs.h
echo "hdefs[\"PTHREADS_XOPEN_LIBS\"] = \"$PTHREADS_XOPEN_LIBS\"" >>configure.lua
else
echo "#undef HAVE_PTHREADS_XOPEN" >$BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = nil" >>configure.lua
fi;
fi;
$ECHO_N "checking for PTHREAD_MUTEX_RECURSIVE..."
$ECHO_N "checking for PTHREAD_MUTEX_RECURSIVE..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>
int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_mutexattr_t mutexattr;
	pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE);
	pthread_mutex_init(&mutex, &mutexattr);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREAD_MUTEX_RECURSIVE="yes"
echo "#ifndef HAVE_PTHREAD_MUTEX_RECURSIVE" > $BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "#define HAVE_PTHREAD_MUTEX_RECURSIVE \"$HAVE_PTHREAD_MUTEX_RECURSIVE\"" >> $BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "#endif" >> $BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE\"] = \"$HAVE_PTHREAD_MUTEX_RECURSIVE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREAD_MUTEX_RECURSIVE="no"
echo "#undef HAVE_PTHREAD_MUTEX_RECURSIVE" >$BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREAD_MUTEX_RECURSIVE}" = "yes" ]; then
echo "#ifndef HAVE_PTHREAD_MUTEX_RECURSIVE" > $BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "#define HAVE_PTHREAD_MUTEX_RECURSIVE \"$HAVE_PTHREAD_MUTEX_RECURSIVE\"" >> $BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "#endif" >> $BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE\"] = \"$HAVE_PTHREAD_MUTEX_RECURSIVE\"" >>configure.lua
else
echo "#undef HAVE_PTHREAD_MUTEX_RECURSIVE" >$BLD/include/agar/config/have_pthread_mutex_recursive.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE\"] = nil" >>configure.lua
fi;
$ECHO_N "checking for PTHREAD_MUTEX_RECURSIVE_NP..."
$ECHO_N "checking for PTHREAD_MUTEX_RECURSIVE_NP..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <pthread.h>
#include <signal.h>
int main(int argc, char *argv[])
{
	pthread_mutex_t mutex;
	pthread_mutexattr_t mutexattr;
	pthread_mutexattr_settype(&mutexattr, PTHREAD_MUTEX_RECURSIVE_NP);
	pthread_mutex_init(&mutex, &mutexattr);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PTHREADS_CFLAGS} -o $testdir/conftest conftest.c ${PTHREADS_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PTHREAD_MUTEX_RECURSIVE_NP="yes"
echo "#ifndef HAVE_PTHREAD_MUTEX_RECURSIVE_NP" > $BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "#define HAVE_PTHREAD_MUTEX_RECURSIVE_NP \"$HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"" >> $BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "#endif" >> $BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"] = \"$HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PTHREAD_MUTEX_RECURSIVE_NP="no"
echo "#undef HAVE_PTHREAD_MUTEX_RECURSIVE_NP" >$BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PTHREAD_MUTEX_RECURSIVE_NP}" = "yes" ]; then
echo "#ifndef HAVE_PTHREAD_MUTEX_RECURSIVE_NP" > $BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "#define HAVE_PTHREAD_MUTEX_RECURSIVE_NP \"$HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"" >> $BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "#endif" >> $BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"] = \"$HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"" >>configure.lua
else
echo "#undef HAVE_PTHREAD_MUTEX_RECURSIVE_NP" >$BLD/include/agar/config/have_pthread_mutex_recursive_np.h
echo "hdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_PTHREADS}" = "yes" ]
	then
AG_THREADS="yes"
echo "#ifndef AG_THREADS" > $BLD/include/agar/config/ag_threads.h
echo "#define AG_THREADS \"$AG_THREADS\"" >> $BLD/include/agar/config/ag_threads.h
echo "#endif" >> $BLD/include/agar/config/ag_threads.h
echo "hdefs[\"AG_THREADS\"] = \"$AG_THREADS\"" >>configure.lua
		if [ "${HAVE_PTHREADS_XOPEN}" = "no" ]
 then
		if [ "${HAVE_PTHREAD_MUTEX_RECURSIVE}" = "no" ]
 then
		if [ "${HAVE_PTHREAD_MUTEX_RECURSIVE_NP}" = "no" ]
 then
echo "#undef AG_THREADS" >$BLD/include/agar/config/ag_threads.h
echo "hdefs[\"AG_THREADS\"] = nil" >>configure.lua
			if [ "${enable_threads}" = "yes" ]
 then
				echo "*"
				echo "* --enable-threads was given, but your"
				echo "* pthreads library seems to lack support"
				echo "* for recursive mutexes."
				echo "*"
				exit 1
			fi
		fi
		fi
		fi
	else
echo "#undef AG_THREADS" >$BLD/include/agar/config/ag_threads.h
echo "hdefs[\"AG_THREADS\"] = nil" >>configure.lua
		if [ "${enable_threads}" = "yes" ]
 then
			echo "*"
			echo "* --enable-threads was given, but no pthreads"
			echo "* library was found on your system."
			echo "*"
			exit 1
		fi
	fi
else
echo "#undef AG_THREADS" >$BLD/include/agar/config/ag_threads.h
echo "hdefs[\"AG_THREADS\"] = nil" >>configure.lua
echo "#undef HAVE_PTHREADS" >$BLD/include/agar/config/have_pthreads.h
echo "hdefs[\"HAVE_PTHREADS\"] = nil" >>configure.lua
echo "#undef HAVE_PTHREADS_XOPEN" >$BLD/include/agar/config/have_pthreads_xopen.h
echo "hdefs[\"HAVE_PTHREADS_XOPEN\"] = nil" >>configure.lua
	if [ "${enable_warnings}" = "yes" ]
 then
CFLAGS="$CFLAGS -Wno-unused"
CXXFLAGS="$CXXFLAGS -Wno-unused"
	fi
fi
if [ "${with_uim}" = "yes" ]
 then
$ECHO_N "checking for uim framework..."
$ECHO_N "checking for uim framework..." >> config.log
if [ "${prefix_uim}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix uim 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_uim}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, uim is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_uim}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct uim prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		UIM_VERSION=`$PKGCONFIG uim --modversion 2>/dev/null`
	fi
else
	UIM_VERSION=`$PKGCONFIG uim --modversion 2>/dev/null`
fi
if [ "${prefix_uim}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix uim 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_uim}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, uim is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_uim}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct uim prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		UIM_CFLAGS=`$PKGCONFIG uim --cflags 2>/dev/null`
	fi
else
	UIM_CFLAGS=`$PKGCONFIG uim --cflags 2>/dev/null`
fi
if [ "${prefix_uim}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix uim 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_uim}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, uim is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_uim}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct uim prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		UIM_LIBS=`$PKGCONFIG uim --libs 2>/dev/null`
	fi
else
	UIM_LIBS=`$PKGCONFIG uim --libs 2>/dev/null`
fi
if [ "${UIM_VERSION}" != "" ]; then
if [ "${prefix_uim}" != "" ]; then
echo "yes ($UIM_VERSION in ${prefix_uim})"
echo "yes ($UIM_VERSION in ${prefix_uim})" >> config.log
else
echo "yes ($UIM_VERSION)"
echo "yes ($UIM_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$UIM_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$UIM_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$UIM_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 1 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 1 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 8 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 8 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 0 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 1.8.0 (found $UIM_VERSION); skipping."
echo "* Minimum required version is 1.8.0 (found $UIM_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_uim}" != "" ]; then
echo "no (not in ${prefix_uim})"
echo "no (not in ${prefix_uim})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether uim works..."
$ECHO_N "checking whether uim works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <uim.h>
#include <uim-util.h>

int main(int argc, char *argv[]) {
	uim_context uimCtx;
	const char *s;
	int i;

	uimCtx = uim_create_context(NULL, "UTF-8", NULL, NULL, uim_iconv, NULL);
	for (i = 0; i < uim_get_nr_im(uimCtx); i++) {
		s = uim_get_im_name(uimCtx, i);
		if (s == NULL) { return (1); }
	}
	uim_release_context(uimCtx);

	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${UIM_CFLAGS} -o $testdir/conftest conftest.c ${UIM_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${UIM_CFLAGS} -o $testdir/conftest conftest.c ${UIM_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_UIM="yes"
echo "#ifndef HAVE_UIM" > $BLD/include/agar/config/have_uim.h
echo "#define HAVE_UIM \"$HAVE_UIM\"" >> $BLD/include/agar/config/have_uim.h
echo "#endif" >> $BLD/include/agar/config/have_uim.h
echo "hdefs[\"HAVE_UIM\"] = \"$HAVE_UIM\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_UIM="no"
echo "#undef HAVE_UIM" >$BLD/include/agar/config/have_uim.h
echo "hdefs[\"HAVE_UIM\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_UIM}" = "yes" ]; then
echo "#ifndef UIM_CFLAGS" > $BLD/include/agar/config/uim_cflags.h
echo "#define UIM_CFLAGS \"$UIM_CFLAGS\"" >> $BLD/include/agar/config/uim_cflags.h
echo "#endif" >> $BLD/include/agar/config/uim_cflags.h
echo "hdefs[\"UIM_CFLAGS\"] = \"$UIM_CFLAGS\"" >>configure.lua
echo "#ifndef UIM_LIBS" > $BLD/include/agar/config/uim_libs.h
echo "#define UIM_LIBS \"$UIM_LIBS\"" >> $BLD/include/agar/config/uim_libs.h
echo "#endif" >> $BLD/include/agar/config/uim_libs.h
echo "hdefs[\"UIM_LIBS\"] = \"$UIM_LIBS\"" >>configure.lua
else
echo "#undef UIM_CFLAGS" >$BLD/include/agar/config/uim_cflags.h
echo "hdefs[\"UIM_CFLAGS\"] = nil" >>configure.lua
UIM_CFLAGS=""
echo "#undef UIM_LIBS" >$BLD/include/agar/config/uim_libs.h
echo "hdefs[\"UIM_LIBS\"] = nil" >>configure.lua
UIM_LIBS=""
fi;
else
echo "#undef HAVE_UIM" >$BLD/include/agar/config/have_uim.h
echo "hdefs[\"HAVE_UIM\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_UIM}" != "yes" ]
 then
		if [ "${with_uim}" = "yes" ]
 then
			echo "*"
			echo "* --with-uim was requested, but the uim "
			echo "* framework is not installed."
			echo "*"
			exit 1
		else
echo "#undef HAVE_UIM" >$BLD/include/agar/config/have_uim.h
echo "hdefs[\"HAVE_UIM\"] = nil" >>configure.lua
		fi
	fi
else
echo "#undef HAVE_UIM" >$BLD/include/agar/config/have_uim.h
echo "hdefs[\"HAVE_UIM\"] = nil" >>configure.lua
fi
	
if [ "${enable_nls}" = "yes" ]
 then
$ECHO_N "checking for iconv() in libc..."
$ECHO_N "checking for iconv() in libc..." >> config.log
ICONV_CFLAGS=""
ICONV_LIBS=""
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int main(int argc, char *argv[])
{
	char *inbuf = "foo";
	size_t inlen = strlen(inbuf), rv;
	char *outbuf = malloc(3);
	size_t outbuflen = 3;
	iconv_t cd;

	cd = iconv_open("ISO-8859-1", "UTF-8");
	rv = iconv(cd, &inbuf, &inlen, &outbuf, &outbuflen);
	iconv_close(cd);
	return ((rv == (size_t)-1));
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ICONV="yes"
echo "#ifndef HAVE_ICONV" > $BLD/include/agar/config/have_iconv.h
echo "#define HAVE_ICONV \"$HAVE_ICONV\"" >> $BLD/include/agar/config/have_iconv.h
echo "#endif" >> $BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = \"$HAVE_ICONV\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ICONV="no"
echo "#undef HAVE_ICONV" >$BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_ICONV}" = "no" ]; then
$ECHO_N "checking for iconv() in -liconv..."
$ECHO_N "checking for iconv() in -liconv..." >> config.log
if [ "${prefix_iconv}" != "" ]; then
if [ -e  "${prefix_iconv}/include/iconv.h" ]; then
ICONV_CFLAGS="-I${prefix_iconv}/include"
ICONV_LIBS="-L${prefix_iconv}/lib -liconv"
fi;
else
if [ -e  "/usr/include/iconv.h" ]; then
ICONV_CFLAGS="-I/usr/include"
ICONV_LIBS="-L/usr/lib -liconv"
fi;
if [ -e  "/usr/local/include/iconv.h" ]; then
ICONV_CFLAGS="-I/usr/local/include"
ICONV_LIBS="-L/usr/local/lib -liconv"
fi;
if [ -e  "/opt/include/iconv.h" ]; then
ICONV_CFLAGS="-I/opt/include"
ICONV_LIBS="-L/opt/lib -liconv"
fi;
if [ -e  "/opt/local/include/iconv.h" ]; then
ICONV_CFLAGS="-I/opt/local/include"
ICONV_LIBS="-L/opt/local/lib -liconv"
fi;
if [ -e  "/usr/pkg/include/iconv.h" ]; then
ICONV_CFLAGS="-I/usr/pkg/include"
ICONV_LIBS="-L/usr/pkg/lib -liconv"
fi;
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int main(int argc, char *argv[])
{
	char *inbuf = "foo";
	size_t inlen = strlen(inbuf), rv;
	char *outbuf = malloc(3);
	size_t outbuflen = 3;
	iconv_t cd;

	cd = iconv_open("ISO-8859-1", "UTF-8");
	rv = iconv(cd, &inbuf, &inlen, &outbuf, &outbuflen);
	iconv_close(cd);
	return ((rv == (size_t)-1));
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ICONV="yes"
echo "#ifndef HAVE_ICONV" > $BLD/include/agar/config/have_iconv.h
echo "#define HAVE_ICONV \"$HAVE_ICONV\"" >> $BLD/include/agar/config/have_iconv.h
echo "#endif" >> $BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = \"$HAVE_ICONV\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ICONV="no"
echo "#undef HAVE_ICONV" >$BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_ICONV}" = "no" ]; then
$ECHO_N "checking for iconv() in -liconv (const)..."
$ECHO_N "checking for iconv() in -liconv (const)..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int main(int argc, char *argv[])
{
	const char *inbuf = "foo";
	size_t inlen = strlen(inbuf), rv;
	char *outbuf = malloc(3);
	size_t outbuflen = 3;
	iconv_t cd;

	cd = iconv_open("ISO-8859-1", "UTF-8");
	rv = iconv(cd, &inbuf, &inlen, &outbuf, &outbuflen);
	iconv_close(cd);
	return ((rv == (size_t)-1));
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ICONV="yes"
echo "#ifndef HAVE_ICONV" > $BLD/include/agar/config/have_iconv.h
echo "#define HAVE_ICONV \"$HAVE_ICONV\"" >> $BLD/include/agar/config/have_iconv.h
echo "#endif" >> $BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = \"$HAVE_ICONV\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ICONV="no"
echo "#undef HAVE_ICONV" >$BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
fi;
else
$ECHO_N "checking for iconv() with const..."
$ECHO_N "checking for iconv() with const..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int main(int argc, char *argv[])
{
	const char *inbuf = "foo";
	size_t inlen = strlen(inbuf), rv;
	char *outbuf = malloc(3);
	size_t outbuflen = 3;
	iconv_t cd;

	cd = iconv_open("ISO-8859-1", "UTF-8");
	rv = iconv(cd, &inbuf, &inlen, &outbuf, &outbuflen);
	iconv_close(cd);
	return ((rv == (size_t)-1));
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wno-cast-qual -o $testdir/conftest conftest.c ${ICONV_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ICONV="yes"
echo "#ifndef HAVE_ICONV" > $BLD/include/agar/config/have_iconv.h
echo "#define HAVE_ICONV \"$HAVE_ICONV\"" >> $BLD/include/agar/config/have_iconv.h
echo "#endif" >> $BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = \"$HAVE_ICONV\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ICONV="no"
echo "#undef HAVE_ICONV" >$BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
fi;
echo "#ifndef ICONV_CFLAGS" > $BLD/include/agar/config/iconv_cflags.h
echo "#define ICONV_CFLAGS \"$ICONV_CFLAGS\"" >> $BLD/include/agar/config/iconv_cflags.h
echo "#endif" >> $BLD/include/agar/config/iconv_cflags.h
echo "hdefs[\"ICONV_CFLAGS\"] = \"$ICONV_CFLAGS\"" >>configure.lua
echo "#ifndef ICONV_LIBS" > $BLD/include/agar/config/iconv_libs.h
echo "#define ICONV_LIBS \"$ICONV_LIBS\"" >> $BLD/include/agar/config/iconv_libs.h
echo "#endif" >> $BLD/include/agar/config/iconv_libs.h
echo "hdefs[\"ICONV_LIBS\"] = \"$ICONV_LIBS\"" >>configure.lua
if [ "${HAVE_ICONV}" = "yes" ]; then
$ECHO_N "checking whether iconv() is const-correct..."
$ECHO_N "checking whether iconv() is const-correct..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <iconv.h>

int main(int argc, char *argv[])
{
	const char *inbuf = "foo";
	size_t inlen = strlen(inbuf), rv;
	char *outbuf = malloc(3);
	size_t outbuflen = 3;
	iconv_t cd;

	cd = iconv_open("ISO-8859-1", "UTF-8");
	rv = iconv(cd, &inbuf, &inlen, &outbuf, &outbuflen);
	iconv_close(cd);
	return ((rv == (size_t)-1));
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wcast-qual -Werror -o $testdir/conftest conftest.c ${ICONV_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${ICONV_CFLAGS} -Wcast-qual -Werror -o $testdir/conftest conftest.c ${ICONV_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ICONV_CONST="yes"
echo "#ifndef HAVE_ICONV_CONST" > $BLD/include/agar/config/have_iconv_const.h
echo "#define HAVE_ICONV_CONST \"$HAVE_ICONV_CONST\"" >> $BLD/include/agar/config/have_iconv_const.h
echo "#endif" >> $BLD/include/agar/config/have_iconv_const.h
echo "hdefs[\"HAVE_ICONV_CONST\"] = \"$HAVE_ICONV_CONST\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ICONV_CONST="no"
echo "#undef HAVE_ICONV_CONST" >$BLD/include/agar/config/have_iconv_const.h
echo "hdefs[\"HAVE_ICONV_CONST\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
else
echo "#undef HAVE_ICONV_CONST" >$BLD/include/agar/config/have_iconv_const.h
echo "hdefs[\"HAVE_ICONV_CONST\"] = nil" >>configure.lua
fi;
$ECHO_N "checking for a gettext library in libc..."
$ECHO_N "checking for a gettext library in libc..." >> config.log
GETTEXT_CFLAGS=""
GETTEXT_LIBS=""
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <libintl.h>
int main(int argc, char *argv[])
{
	char *s;
	bindtextdomain("foo", "/foo");
	textdomain("foo");
	s = gettext("string");
	s = dgettext("foo","string");
	return (s != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${GETTEXT_CFLAGS} -o $testdir/conftest conftest.c ${GETTEXT_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${GETTEXT_CFLAGS} -o $testdir/conftest conftest.c ${GETTEXT_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETTEXT="yes"
echo "#ifndef HAVE_GETTEXT" > $BLD/include/agar/config/have_gettext.h
echo "#define HAVE_GETTEXT \"$HAVE_GETTEXT\"" >> $BLD/include/agar/config/have_gettext.h
echo "#endif" >> $BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = \"$HAVE_GETTEXT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETTEXT="no"
echo "#undef HAVE_GETTEXT" >$BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_GETTEXT}" = "no" ]; then
$ECHO_N "checking for a gettext library in -lintl..."
$ECHO_N "checking for a gettext library in -lintl..." >> config.log
if [ "${prefix_gettext}" != "" ]; then
if [ -e  "${prefix_gettext}/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I${prefix_gettext}/include"
GETTEXT_LIBS="-L${prefix_gettext}/lib -lintl"
fi;
else
if [ -e  "${prefix_gettext}/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I${prefix_gettext}/include"
GETTEXT_LIBS="-L${prefix_gettext}/lib -lintl"
fi;
if [ -e  "/usr/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I/usr/include"
GETTEXT_LIBS="-L/usr/lib -lintl"
fi;
if [ -e  "/usr/local/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I/usr/local/include"
GETTEXT_LIBS="-L/usr/local/lib -lintl"
fi;
if [ -e  "/opt/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I/opt/include"
GETTEXT_LIBS="-L/opt/lib -lintl"
fi;
if [ -e  "/opt/local/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I/opt/local/include"
GETTEXT_LIBS="-L/opt/local/lib -lintl"
fi;
if [ -e  "/usr/pkg/include/libintl.h" ]; then
GETTEXT_CFLAGS="-I/usr/pkg/include"
GETTEXT_LIBS="-L/usr/pkg/lib -lintl"
fi;
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <libintl.h>
int main(int argc, char *argv[])
{
	char *s;
	bindtextdomain("foo", "/foo");
	textdomain("foo");
	s = gettext("string");
	s = dgettext("foo","string");
	return (s != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${GETTEXT_CFLAGS} -o $testdir/conftest conftest.c ${GETTEXT_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${GETTEXT_CFLAGS} -o $testdir/conftest conftest.c ${GETTEXT_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETTEXT="yes"
echo "#ifndef HAVE_GETTEXT" > $BLD/include/agar/config/have_gettext.h
echo "#define HAVE_GETTEXT \"$HAVE_GETTEXT\"" >> $BLD/include/agar/config/have_gettext.h
echo "#endif" >> $BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = \"$HAVE_GETTEXT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETTEXT="no"
echo "#undef HAVE_GETTEXT" >$BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_GETTEXT}" = "yes" ]; then
echo "#ifndef GETTEXT_CFLAGS" > $BLD/include/agar/config/gettext_cflags.h
echo "#define GETTEXT_CFLAGS \"$GETTEXT_CFLAGS\"" >> $BLD/include/agar/config/gettext_cflags.h
echo "#endif" >> $BLD/include/agar/config/gettext_cflags.h
echo "hdefs[\"GETTEXT_CFLAGS\"] = \"$GETTEXT_CFLAGS\"" >>configure.lua
echo "#ifndef GETTEXT_LIBS" > $BLD/include/agar/config/gettext_libs.h
echo "#define GETTEXT_LIBS \"$GETTEXT_LIBS\"" >> $BLD/include/agar/config/gettext_libs.h
echo "#endif" >> $BLD/include/agar/config/gettext_libs.h
echo "hdefs[\"GETTEXT_LIBS\"] = \"$GETTEXT_LIBS\"" >>configure.lua
else
$ECHO_N "checking whether -lintl requires -liconv..."
$ECHO_N "checking whether -lintl requires -liconv..." >> config.log
if [ "${prefix_gettext}" != "" ]; then
if [ -e  "${prefix_gettext}/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I${prefix_gettext}/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L${prefix_gettext}/lib -liconv"
fi;
else
if [ -e  "${prefix_gettext}/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I${prefix_gettext}/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L${prefix_gettext}/lib -liconv"
fi;
if [ -e  "/usr/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I/usr/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L/usr/lib -liconv"
fi;
if [ -e  "/usr/local/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I/usr/local/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L/usr/local/lib -liconv"
fi;
if [ -e  "/opt/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I/opt/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L/opt/lib -liconv"
fi;
if [ -e  "/opt/local/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I/opt/local/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L/opt/local/lib -liconv"
fi;
if [ -e  "/usr/pkg/include/iconv.h" ]; then
GETTEXT_CFLAGS="${GETTEXT_CFLAGS} -I/usr/pkg/include"
GETTEXT_LIBS="${GETTEXT_LIBS} -L/usr/pkg/lib -liconv"
fi;
fi;
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <libintl.h>
int main(int argc, char *argv[])
{
	char *s;
	bindtextdomain("foo", "/foo");
	textdomain("foo");
	s = gettext("string");
	s = dgettext("foo","string");
	return (s != NULL);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${GETTEXT_CFLAGS} -o $testdir/conftest conftest.c ${GETTEXT_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${GETTEXT_CFLAGS} -o $testdir/conftest conftest.c ${GETTEXT_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_GETTEXT="yes"
echo "#ifndef HAVE_GETTEXT" > $BLD/include/agar/config/have_gettext.h
echo "#define HAVE_GETTEXT \"$HAVE_GETTEXT\"" >> $BLD/include/agar/config/have_gettext.h
echo "#endif" >> $BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = \"$HAVE_GETTEXT\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_GETTEXT="no"
echo "#undef HAVE_GETTEXT" >$BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_GETTEXT}" = "yes" ]; then
echo "#ifndef GETTEXT_CFLAGS" > $BLD/include/agar/config/gettext_cflags.h
echo "#define GETTEXT_CFLAGS \"$GETTEXT_CFLAGS\"" >> $BLD/include/agar/config/gettext_cflags.h
echo "#endif" >> $BLD/include/agar/config/gettext_cflags.h
echo "hdefs[\"GETTEXT_CFLAGS\"] = \"$GETTEXT_CFLAGS\"" >>configure.lua
echo "#ifndef GETTEXT_LIBS" > $BLD/include/agar/config/gettext_libs.h
echo "#define GETTEXT_LIBS \"$GETTEXT_LIBS\"" >> $BLD/include/agar/config/gettext_libs.h
echo "#endif" >> $BLD/include/agar/config/gettext_libs.h
echo "hdefs[\"GETTEXT_LIBS\"] = \"$GETTEXT_LIBS\"" >>configure.lua
else
echo "#undef GETTEXT_CFLAGS" >$BLD/include/agar/config/gettext_cflags.h
echo "hdefs[\"GETTEXT_CFLAGS\"] = nil" >>configure.lua
GETTEXT_CFLAGS=""
echo "#undef GETTEXT_LIBS" >$BLD/include/agar/config/gettext_libs.h
echo "hdefs[\"GETTEXT_LIBS\"] = nil" >>configure.lua
GETTEXT_LIBS=""
fi;
fi;
else
echo "#undef GETTEXT_CFLAGS" >$BLD/include/agar/config/gettext_cflags.h
echo "hdefs[\"GETTEXT_CFLAGS\"] = nil" >>configure.lua
echo "#undef GETTEXT_LIBS" >$BLD/include/agar/config/gettext_libs.h
echo "hdefs[\"GETTEXT_LIBS\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_GETTEXT}" != "yes" ]
 then
		echo "*"
		echo "* --enable-nls was given but gettext was not found."
		echo "*"
		exit 1
	fi
else
echo "#undef HAVE_ICONV" >$BLD/include/agar/config/have_iconv.h
echo "hdefs[\"HAVE_ICONV\"] = nil" >>configure.lua
echo "#undef HAVE_GETTEXT" >$BLD/include/agar/config/have_gettext.h
echo "hdefs[\"HAVE_GETTEXT\"] = nil" >>configure.lua
fi
if [ "${enable_math}" != "no" ]
 then
ENABLE_MATH="yes"
echo "#ifndef ENABLE_MATH" > $BLD/include/agar/config/enable_math.h
echo "#define ENABLE_MATH \"$ENABLE_MATH\"" >> $BLD/include/agar/config/enable_math.h
echo "#endif" >> $BLD/include/agar/config/enable_math.h
echo "hdefs[\"ENABLE_MATH\"] = \"$ENABLE_MATH\"" >>configure.lua
SUBDIR_math="math"
else
echo "#undef ENABLE_MATH" >$BLD/include/agar/config/enable_math.h
echo "hdefs[\"ENABLE_MATH\"] = nil" >>configure.lua
SUBDIR_math=""
fi
if [ "${with_altivec}" != "no" ]
 then
$ECHO_N "checking for AltiVec (with <altivec.h>)..."
$ECHO_N "checking for AltiVec (with <altivec.h>)..." >> config.log
case "$host" in
powerpc-*-darwin*)
	ALTIVEC_CFLAGS="-faltivec -maltivec"
	ALTIVEC_CHECK_CFLAGS="-D_DARWIN_C_SOURCE"
	echo "ALTIVEC_CHECK_CFLAGS=${ALTIVEC_CHECK_CFLAGS}" >> Makefile.config
	;;
*)
	ALTIVEC_CFLAGS="-mabi=altivec -maltivec"
	ALTIVEC_CHECK_CFLAGS=""
	echo "ALTIVEC_CHECK_CFLAGS=" >> Makefile.config
	;;
esac
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <altivec.h>
float a[4] = { 1,2,3,4 };
float b[4] = { 5,6,7,8 };
float c[4];

int
main(int argc, char *argv[])
{
	vector float *va = (vector float *)a;
	vector float *vb = (vector float *)b;
	vector float *vc = (vector float *)c;

	*vc = vec_add(*va, *vb);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${ALTIVEC_CFLAGS} -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${ALTIVEC_CFLAGS} -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ALTIVEC="yes"
echo "#ifndef HAVE_ALTIVEC" > $BLD/include/agar/config/have_altivec.h
echo "#define HAVE_ALTIVEC \"$HAVE_ALTIVEC\"" >> $BLD/include/agar/config/have_altivec.h
echo "#endif" >> $BLD/include/agar/config/have_altivec.h
echo "hdefs[\"HAVE_ALTIVEC\"] = \"$HAVE_ALTIVEC\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ALTIVEC="no"
echo "#undef HAVE_ALTIVEC" >$BLD/include/agar/config/have_altivec.h
echo "hdefs[\"HAVE_ALTIVEC\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_ALTIVEC}" = "yes" ]; then
HAVE_ALTIVEC_H=""
echo "#ifndef ALTIVEC_CFLAGS" > $BLD/include/agar/config/altivec_cflags.h
echo "#define ALTIVEC_CFLAGS \"$ALTIVEC_CFLAGS\"" >> $BLD/include/agar/config/altivec_cflags.h
echo "#endif" >> $BLD/include/agar/config/altivec_cflags.h
echo "hdefs[\"ALTIVEC_CFLAGS\"] = \"$ALTIVEC_CFLAGS\"" >>configure.lua
echo "#ifndef HAVE_ALTIVEC_H" > $BLD/include/agar/config/have_altivec_h.h
echo "#define HAVE_ALTIVEC_H \"$HAVE_ALTIVEC_H\"" >> $BLD/include/agar/config/have_altivec_h.h
echo "#endif" >> $BLD/include/agar/config/have_altivec_h.h
echo "hdefs[\"HAVE_ALTIVEC_H\"] = \"$HAVE_ALTIVEC_H\"" >>configure.lua
else
$ECHO_N "checking for AltiVec (without <altivec.h>)..."
$ECHO_N "checking for AltiVec (without <altivec.h>)..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
float a[4] = { 1,2,3,4 };
float b[4] = { 5,6,7,8 };
float c[4];

int
main(int argc, char *argv[])
{
	vector float *va = (vector float *)a;
	vector float *vb = (vector float *)b;
	vector float *vc = (vector float *)c;

	*vc = vec_add(*va, *vb);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${ALTIVEC_CFLAGS} -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${ALTIVEC_CFLAGS} -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_ALTIVEC="yes"
echo "#ifndef HAVE_ALTIVEC" > $BLD/include/agar/config/have_altivec.h
echo "#define HAVE_ALTIVEC \"$HAVE_ALTIVEC\"" >> $BLD/include/agar/config/have_altivec.h
echo "#endif" >> $BLD/include/agar/config/have_altivec.h
echo "hdefs[\"HAVE_ALTIVEC\"] = \"$HAVE_ALTIVEC\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_ALTIVEC="no"
echo "#undef HAVE_ALTIVEC" >$BLD/include/agar/config/have_altivec.h
echo "hdefs[\"HAVE_ALTIVEC\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_ALTIVEC}" = "yes" ]; then
echo "#ifndef ALTIVEC_CFLAGS" > $BLD/include/agar/config/altivec_cflags.h
echo "#define ALTIVEC_CFLAGS \"$ALTIVEC_CFLAGS\"" >> $BLD/include/agar/config/altivec_cflags.h
echo "#endif" >> $BLD/include/agar/config/altivec_cflags.h
echo "hdefs[\"ALTIVEC_CFLAGS\"] = \"$ALTIVEC_CFLAGS\"" >>configure.lua
else
echo "#undef ALTIVEC_CFLAGS" >$BLD/include/agar/config/altivec_cflags.h
echo "hdefs[\"ALTIVEC_CFLAGS\"] = nil" >>configure.lua
ALTIVEC_CFLAGS=""
fi;
echo "#undef HAVE_ALTIVEC_H" >$BLD/include/agar/config/have_altivec_h.h
echo "hdefs[\"HAVE_ALTIVEC_H\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_ALTIVEC}" != "yes" ]
 then
		if [ "${with_altivec}" = "yes" ]
 then
			echo "*"
			echo "* --with-altivec was requested, but "
			echo "* AltiVec is not supported by compiler"
			echo "*"
			exit 1
		else
echo "#undef HAVE_ALTIVEC" >$BLD/include/agar/config/have_altivec.h
echo "hdefs[\"HAVE_ALTIVEC\"] = nil" >>configure.lua
echo "#undef HAVE_ALTIVEC_H" >$BLD/include/agar/config/have_altivec_h.h
echo "hdefs[\"HAVE_ALTIVEC_H\"] = nil" >>configure.lua
echo "#undef INLINE_ALTIVEC" >$BLD/include/agar/config/inline_altivec.h
echo "hdefs[\"INLINE_ALTIVEC\"] = nil" >>configure.lua
		fi
	else
		if [ "${with_altivec_inline}" = "yes" ]
 then
INLINE_ALTIVEC="yes"
echo "#ifndef INLINE_ALTIVEC" > $BLD/include/agar/config/inline_altivec.h
echo "#define INLINE_ALTIVEC \"$INLINE_ALTIVEC\"" >> $BLD/include/agar/config/inline_altivec.h
echo "#endif" >> $BLD/include/agar/config/inline_altivec.h
echo "hdefs[\"INLINE_ALTIVEC\"] = \"$INLINE_ALTIVEC\"" >>configure.lua
		else
echo "#undef INLINE_ALTIVEC" >$BLD/include/agar/config/inline_altivec.h
echo "hdefs[\"INLINE_ALTIVEC\"] = nil" >>configure.lua
		fi
	fi
else
echo "#undef HAVE_ALTIVEC" >$BLD/include/agar/config/have_altivec.h
echo "hdefs[\"HAVE_ALTIVEC\"] = nil" >>configure.lua
echo "#undef HAVE_ALTIVEC_H" >$BLD/include/agar/config/have_altivec_h.h
echo "hdefs[\"HAVE_ALTIVEC_H\"] = nil" >>configure.lua
echo "#undef INLINE_ALTIVEC" >$BLD/include/agar/config/inline_altivec.h
echo "hdefs[\"INLINE_ALTIVEC\"] = nil" >>configure.lua
fi
if [ "${with_sse}" != "no" ]
 then
$ECHO_N "checking for SSE extensions..."
$ECHO_N "checking for SSE extensions..." >> config.log
SSE_CFLAGS="-msse"
MK_COMPILE_STATUS="OK"
MK_RUN_STATUS="OK"
cat << EOT > conftest.c
#include <xmmintrin.h>
#include <stdio.h>

#define MAXERR 1e-4

typedef union vec {
	float v[4];
	__m128 m128;
	struct { float x, y, z, pad; };
} MyVector __attribute__ ((aligned(16)));

int
main(int argc, char *argv[])
{
	MyVector a;
	__m128 v;

	a.x = 1.0f;
	a.y = 2.0f;
	a.z = 3.0f;
	v = _mm_set1_ps(1.0f);
	a.m128 = _mm_mul_ps(a.m128, v);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${SSE_CFLAGS} -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${SSE_CFLAGS} -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
(cd $testdir && ./conftest$EXECSUFFIX) >> config.log
if [ "$?" = "0" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SSE="yes"
echo "#ifndef HAVE_SSE" > $BLD/include/agar/config/have_sse.h
echo "#define HAVE_SSE \"$HAVE_SSE\"" >> $BLD/include/agar/config/have_sse.h
echo "#endif" >> $BLD/include/agar/config/have_sse.h
echo "hdefs[\"HAVE_SSE\"] = \"$HAVE_SSE\"" >>configure.lua
else
echo "no (test program failed)"
echo "no (test program failed)" >> config.log
MK_RUN_STATUS="FAIL(\$?)"
HAVE_SSE="no"
echo "#undef HAVE_SSE" >$BLD/include/agar/config/have_sse.h
echo "hdefs[\"HAVE_SSE\"] = nil" >>configure.lua
fi;
else
echo "no (compilation failed)"
echo "no (compilation failed)" >> config.log
MK_RUN_STATUS="FAIL(\$?)"
HAVE_SSE="no"
echo "#undef HAVE_SSE" >$BLD/include/agar/config/have_sse.h
echo "hdefs[\"HAVE_SSE\"] = nil" >>configure.lua
fi;
if [ "${HAVE_SSE}" = "yes" ]; then
echo "#ifndef SSE_CFLAGS" > $BLD/include/agar/config/sse_cflags.h
echo "#define SSE_CFLAGS \"$SSE_CFLAGS\"" >> $BLD/include/agar/config/sse_cflags.h
echo "#endif" >> $BLD/include/agar/config/sse_cflags.h
echo "hdefs[\"SSE_CFLAGS\"] = \"$SSE_CFLAGS\"" >>configure.lua
else
echo "#undef SSE_CFLAGS" >$BLD/include/agar/config/sse_cflags.h
echo "hdefs[\"SSE_CFLAGS\"] = nil" >>configure.lua
SSE_CFLAGS=""
fi;
$ECHO_N "checking for SSE2 extensions..."
$ECHO_N "checking for SSE2 extensions..." >> config.log
SSE2_CFLAGS="-msse2"
MK_COMPILE_STATUS="OK"
MK_RUN_STATUS="OK"
cat << EOT > conftest.c
#include <emmintrin.h>

int
main(int argc, char *argv[])
{
	double a[4] __attribute__ ((aligned(16)));
	double b[4] __attribute__ ((aligned(16)));
	double rv;
	__m128d vec1, vec2;
	a[0] = 1.0f; a[1] = 2.0f; a[2] = 3.0f; a[3] = 4.0f;
	b[0] = 1.0f; b[1] = 2.0f; b[2] = 3.0f; b[3] = 4.0f;
	vec1 = _mm_load_pd(a);
	vec2 = _mm_load_pd(b);
	vec1 = _mm_xor_pd(vec1, vec2);
	_mm_store_sd(&rv, vec1);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${SSE2_CFLAGS} -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${SSE2_CFLAGS} -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
(cd $testdir && ./conftest$EXECSUFFIX) >> config.log
if [ "$?" = "0" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SSE2="yes"
echo "#ifndef HAVE_SSE2" > $BLD/include/agar/config/have_sse2.h
echo "#define HAVE_SSE2 \"$HAVE_SSE2\"" >> $BLD/include/agar/config/have_sse2.h
echo "#endif" >> $BLD/include/agar/config/have_sse2.h
echo "hdefs[\"HAVE_SSE2\"] = \"$HAVE_SSE2\"" >>configure.lua
else
echo "no (test program failed)"
echo "no (test program failed)" >> config.log
MK_RUN_STATUS="FAIL(\$?)"
HAVE_SSE2="no"
echo "#undef HAVE_SSE2" >$BLD/include/agar/config/have_sse2.h
echo "hdefs[\"HAVE_SSE2\"] = nil" >>configure.lua
fi;
else
echo "no (compilation failed)"
echo "no (compilation failed)" >> config.log
MK_RUN_STATUS="FAIL(\$?)"
HAVE_SSE2="no"
echo "#undef HAVE_SSE2" >$BLD/include/agar/config/have_sse2.h
echo "hdefs[\"HAVE_SSE2\"] = nil" >>configure.lua
fi;
if [ "${HAVE_SSE2}" = "yes" ]; then
echo "#ifndef SSE2_CFLAGS" > $BLD/include/agar/config/sse2_cflags.h
echo "#define SSE2_CFLAGS \"$SSE2_CFLAGS\"" >> $BLD/include/agar/config/sse2_cflags.h
echo "#endif" >> $BLD/include/agar/config/sse2_cflags.h
echo "hdefs[\"SSE2_CFLAGS\"] = \"$SSE2_CFLAGS\"" >>configure.lua
else
echo "#undef SSE2_CFLAGS" >$BLD/include/agar/config/sse2_cflags.h
echo "hdefs[\"SSE2_CFLAGS\"] = nil" >>configure.lua
SSE2_CFLAGS=""
fi;
$ECHO_N "checking for SSE3 extensions..."
$ECHO_N "checking for SSE3 extensions..." >> config.log
SSE3_CFLAGS="-msse3"
MK_COMPILE_STATUS="OK"
MK_RUN_STATUS="OK"
cat << EOT > conftest.c
#include <pmmintrin.h>

int
main(int argc, char *argv[])
{
	float a[4] __attribute__ ((aligned(16)));
	float b[4] __attribute__ ((aligned(16)));
	__m128 vec1, vec2;
	float rv;
	a[0] = 1.0f; a[1] = 2.0f; a[2] = 3.0f; a[3] = 4.0f;
	b[0] = 1.0f; b[1] = 2.0f; b[2] = 3.0f; b[3] = 4.0f;
	vec1 = _mm_load_ps(a);
	vec2 = _mm_load_ps(b);
	vec1 = _mm_mul_ps(vec1, vec2);
	vec1 = _mm_hadd_ps(vec1, vec1);
	vec1 = _mm_hadd_ps(vec1, vec1);
	_mm_store_ss(&rv, vec1);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${SSE3_CFLAGS} -o $testdir/conftest conftest.c " >>config.log
$CC $CFLAGS $TEST_CFLAGS ${CFLAGS} ${SSE3_CFLAGS} -o $testdir/conftest conftest.c  2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
(cd $testdir && ./conftest$EXECSUFFIX) >> config.log
if [ "$?" = "0" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SSE3="yes"
echo "#ifndef HAVE_SSE3" > $BLD/include/agar/config/have_sse3.h
echo "#define HAVE_SSE3 \"$HAVE_SSE3\"" >> $BLD/include/agar/config/have_sse3.h
echo "#endif" >> $BLD/include/agar/config/have_sse3.h
echo "hdefs[\"HAVE_SSE3\"] = \"$HAVE_SSE3\"" >>configure.lua
else
echo "no (test program failed)"
echo "no (test program failed)" >> config.log
MK_RUN_STATUS="FAIL(\$?)"
HAVE_SSE3="no"
echo "#undef HAVE_SSE3" >$BLD/include/agar/config/have_sse3.h
echo "hdefs[\"HAVE_SSE3\"] = nil" >>configure.lua
fi;
else
echo "no (compilation failed)"
echo "no (compilation failed)" >> config.log
MK_RUN_STATUS="FAIL(\$?)"
HAVE_SSE3="no"
echo "#undef HAVE_SSE3" >$BLD/include/agar/config/have_sse3.h
echo "hdefs[\"HAVE_SSE3\"] = nil" >>configure.lua
fi;
if [ "${HAVE_SSE3}" = "yes" ]; then
echo "#ifndef SSE3_CFLAGS" > $BLD/include/agar/config/sse3_cflags.h
echo "#define SSE3_CFLAGS \"$SSE3_CFLAGS\"" >> $BLD/include/agar/config/sse3_cflags.h
echo "#endif" >> $BLD/include/agar/config/sse3_cflags.h
echo "hdefs[\"SSE3_CFLAGS\"] = \"$SSE3_CFLAGS\"" >>configure.lua
else
echo "#undef SSE3_CFLAGS" >$BLD/include/agar/config/sse3_cflags.h
echo "hdefs[\"SSE3_CFLAGS\"] = nil" >>configure.lua
SSE3_CFLAGS=""
fi;
	if [ "${HAVE_SSE}" != "yes" ]
 then
		if [ "${with_sse}" = "yes" ]
 then
			echo "*"
			echo "* --with-sse was requested, but SSE "
			echo "* intrinsics not supported by compiler"
			echo "*"
			exit 1
		else
echo "#undef HAVE_SSE" >$BLD/include/agar/config/have_sse.h
echo "hdefs[\"HAVE_SSE\"] = nil" >>configure.lua
echo "#undef INLINE_SSE" >$BLD/include/agar/config/inline_sse.h
echo "hdefs[\"INLINE_SSE\"] = nil" >>configure.lua
		fi
	else
		if [ "${with_sse_inline}" = "yes" ]
 then
INLINE_SSE="yes"
echo "#ifndef INLINE_SSE" > $BLD/include/agar/config/inline_sse.h
echo "#define INLINE_SSE \"$INLINE_SSE\"" >> $BLD/include/agar/config/inline_sse.h
echo "#endif" >> $BLD/include/agar/config/inline_sse.h
echo "hdefs[\"INLINE_SSE\"] = \"$INLINE_SSE\"" >>configure.lua
		else
echo "#undef INLINE_SSE" >$BLD/include/agar/config/inline_sse.h
echo "hdefs[\"INLINE_SSE\"] = nil" >>configure.lua
		fi
		if [ "${with_sse2}" = "no" ]
 then
echo "#undef HAVE_SSE2" >$BLD/include/agar/config/have_sse2.h
echo "hdefs[\"HAVE_SSE2\"] = nil" >>configure.lua
		fi
		if [ "${with_sse3}" = "no" ]
 then
echo "#undef HAVE_SSE3" >$BLD/include/agar/config/have_sse3.h
echo "hdefs[\"HAVE_SSE3\"] = nil" >>configure.lua
		fi
	fi
else
echo "#undef HAVE_SSE" >$BLD/include/agar/config/have_sse.h
echo "hdefs[\"HAVE_SSE\"] = nil" >>configure.lua
echo "#undef HAVE_SSE2" >$BLD/include/agar/config/have_sse2.h
echo "hdefs[\"HAVE_SSE2\"] = nil" >>configure.lua
echo "#undef HAVE_SSE3" >$BLD/include/agar/config/have_sse3.h
echo "hdefs[\"HAVE_SSE3\"] = nil" >>configure.lua
echo "#undef INLINE_SSE" >$BLD/include/agar/config/inline_sse.h
echo "hdefs[\"INLINE_SSE\"] = nil" >>configure.lua
fi
if [ "${with_single_fp}" = "yes" ]
 then
	if [ "${HAVE_MATH_C99}" != "yes" ]
 then
		echo "*"
		echo "* --with-single-fp was requested, but your compiler does"
		echo "* not support the C99 math routines (sinf(), etc)."
		echo "*"
		exit 1
	fi
SINGLE_PRECISION="yes"
echo "#ifndef SINGLE_PRECISION" > $BLD/include/agar/config/single_precision.h
echo "#define SINGLE_PRECISION \"$SINGLE_PRECISION\"" >> $BLD/include/agar/config/single_precision.h
echo "#endif" >> $BLD/include/agar/config/single_precision.h
echo "hdefs[\"SINGLE_PRECISION\"] = \"$SINGLE_PRECISION\"" >>configure.lua
else
echo "#undef SINGLE_PRECISION" >$BLD/include/agar/config/single_precision.h
echo "hdefs[\"SINGLE_PRECISION\"] = nil" >>configure.lua
fi
if [ "${with_double_fp}" != "no" ]
 then
DOUBLE_PRECISION="yes"
echo "#ifndef DOUBLE_PRECISION" > $BLD/include/agar/config/double_precision.h
echo "#define DOUBLE_PRECISION \"$DOUBLE_PRECISION\"" >> $BLD/include/agar/config/double_precision.h
echo "#endif" >> $BLD/include/agar/config/double_precision.h
echo "hdefs[\"DOUBLE_PRECISION\"] = \"$DOUBLE_PRECISION\"" >>configure.lua
else
echo "#undef DOUBLE_PRECISION" >$BLD/include/agar/config/double_precision.h
echo "hdefs[\"DOUBLE_PRECISION\"] = nil" >>configure.lua
fi
if [ "${with_quad_fp}" = "yes" ]
 then
	if [ "${HAVE_LONG_DOUBLE}" != "yes" ]
 then
		echo "*"
		echo "* --with-quad-fp was requested, but your compiler"
		echo "* does not support the C99 long double type."
		echo "*"
		exit 1
	fi
	if [ "${HAVE_MATH_C99}" != "yes" ]
 then
		echo "*"
		echo "* --with-quad-fp was requested, but the C99 math"
		echo "* routines (sinl(), etc.) are not available."
		echo "*"
		exit 1
	fi
QUAD_PRECISION="yes"
echo "#ifndef QUAD_PRECISION" > $BLD/include/agar/config/quad_precision.h
echo "#define QUAD_PRECISION \"$QUAD_PRECISION\"" >> $BLD/include/agar/config/quad_precision.h
echo "#endif" >> $BLD/include/agar/config/quad_precision.h
echo "hdefs[\"QUAD_PRECISION\"] = \"$QUAD_PRECISION\"" >>configure.lua
else
echo "#undef QUAD_PRECISION" >$BLD/include/agar/config/quad_precision.h
echo "hdefs[\"QUAD_PRECISION\"] = nil" >>configure.lua
fi
if [ "${enable_vg}" != "no" -a "${enable_gui}" != "no" ]
 then
ENABLE_VG="yes"
echo "#ifndef ENABLE_VG" > $BLD/include/agar/config/enable_vg.h
echo "#define ENABLE_VG \"$ENABLE_VG\"" >> $BLD/include/agar/config/enable_vg.h
echo "#endif" >> $BLD/include/agar/config/enable_vg.h
echo "hdefs[\"ENABLE_VG\"] = \"$ENABLE_VG\"" >>configure.lua
SUBDIR_vg="vg"
else
echo "#undef ENABLE_VG" >$BLD/include/agar/config/enable_vg.h
echo "hdefs[\"ENABLE_VG\"] = nil" >>configure.lua
SUBDIR_vg=""
fi
if [ "${enable_dev}" != "no" -a "${enable_gui}" != "no" ]
 then
ENABLE_DEV="yes"
echo "#ifndef ENABLE_DEV" > $BLD/include/agar/config/enable_dev.h
echo "#define ENABLE_DEV \"$ENABLE_DEV\"" >> $BLD/include/agar/config/enable_dev.h
echo "#endif" >> $BLD/include/agar/config/enable_dev.h
echo "hdefs[\"ENABLE_DEV\"] = \"$ENABLE_DEV\"" >>configure.lua
SUBDIR_dev="dev"
else
echo "#undef ENABLE_DEV" >$BLD/include/agar/config/enable_dev.h
echo "hdefs[\"ENABLE_DEV\"] = nil" >>configure.lua
SUBDIR_dev=""
fi
if [ "${enable_au}" != "no" -a "${enable_audio}" != "no" ]
 then
$ECHO_N "checking for libsndfile..."
$ECHO_N "checking for libsndfile..." >> config.log
if [ "${prefix_sndfile}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix sndfile 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_sndfile}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, sndfile is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_sndfile}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct sndfile prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		SNDFILE_VERSION=`$PKGCONFIG sndfile --modversion 2>/dev/null`
	fi
else
	SNDFILE_VERSION=`$PKGCONFIG sndfile --modversion 2>/dev/null`
fi
if [ "${prefix_sndfile}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix sndfile 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_sndfile}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, sndfile is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_sndfile}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct sndfile prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		SNDFILE_CFLAGS=`$PKGCONFIG sndfile --cflags 2>/dev/null`
	fi
else
	SNDFILE_CFLAGS=`$PKGCONFIG sndfile --cflags 2>/dev/null`
fi
if [ "${prefix_sndfile}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix sndfile 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_sndfile}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, sndfile is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_sndfile}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct sndfile prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		SNDFILE_LIBS=`$PKGCONFIG sndfile --libs 2>/dev/null`
	fi
else
	SNDFILE_LIBS=`$PKGCONFIG sndfile --libs 2>/dev/null`
fi
if [ "${SNDFILE_VERSION}" != "" ]; then
if [ "${prefix_sndfile}" != "" ]; then
echo "yes ($SNDFILE_VERSION in ${prefix_sndfile})"
echo "yes ($SNDFILE_VERSION in ${prefix_sndfile})" >> config.log
else
echo "yes ($SNDFILE_VERSION)"
echo "yes ($SNDFILE_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$SNDFILE_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$SNDFILE_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_MICRO=`echo "$SNDFILE_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\3/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 1 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 1 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -gt 0 ]; then
			MK_VERSION_OK="yes";
		elif [ $MK_VERSION_MINOR -eq 0 ]; then
			if [ "$MK_VERSION_MICRO" = "" ]; then
				MK_VERSION_OK="yes"
			else
				if [ $MK_VERSION_MICRO -ge 21 ]; then
					MK_VERSION_OK="yes"
				fi
			fi
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 1.0.21 (found $SNDFILE_VERSION); skipping."
echo "* Minimum required version is 1.0.21 (found $SNDFILE_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_sndfile}" != "" ]; then
echo "no (not in ${prefix_sndfile})"
echo "no (not in ${prefix_sndfile})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether libsndfile works..."
$ECHO_N "checking whether libsndfile works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <sndfile.h>

int main(int argc, char *argv[]) {
	SNDFILE *sf;
	SF_INFO sfi;

	sfi.format = 0;
	sf = sf_open("foo", 0, &sfi);
	sf_close(sf);
	return (0);
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${SNDFILE_CFLAGS} -o $testdir/conftest conftest.c ${SNDFILE_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${SNDFILE_CFLAGS} -o $testdir/conftest conftest.c ${SNDFILE_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_SNDFILE="yes"
echo "#ifndef HAVE_SNDFILE" > $BLD/include/agar/config/have_sndfile.h
echo "#define HAVE_SNDFILE \"$HAVE_SNDFILE\"" >> $BLD/include/agar/config/have_sndfile.h
echo "#endif" >> $BLD/include/agar/config/have_sndfile.h
echo "hdefs[\"HAVE_SNDFILE\"] = \"$HAVE_SNDFILE\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_SNDFILE="no"
echo "#undef HAVE_SNDFILE" >$BLD/include/agar/config/have_sndfile.h
echo "hdefs[\"HAVE_SNDFILE\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_SNDFILE}" = "yes" ]; then
echo "#ifndef SNDFILE_CFLAGS" > $BLD/include/agar/config/sndfile_cflags.h
echo "#define SNDFILE_CFLAGS \"$SNDFILE_CFLAGS\"" >> $BLD/include/agar/config/sndfile_cflags.h
echo "#endif" >> $BLD/include/agar/config/sndfile_cflags.h
echo "hdefs[\"SNDFILE_CFLAGS\"] = \"$SNDFILE_CFLAGS\"" >>configure.lua
echo "#ifndef SNDFILE_LIBS" > $BLD/include/agar/config/sndfile_libs.h
echo "#define SNDFILE_LIBS \"$SNDFILE_LIBS\"" >> $BLD/include/agar/config/sndfile_libs.h
echo "#endif" >> $BLD/include/agar/config/sndfile_libs.h
echo "hdefs[\"SNDFILE_LIBS\"] = \"$SNDFILE_LIBS\"" >>configure.lua
else
echo "#undef SNDFILE_CFLAGS" >$BLD/include/agar/config/sndfile_cflags.h
echo "hdefs[\"SNDFILE_CFLAGS\"] = nil" >>configure.lua
SNDFILE_CFLAGS=""
echo "#undef SNDFILE_LIBS" >$BLD/include/agar/config/sndfile_libs.h
echo "hdefs[\"SNDFILE_LIBS\"] = nil" >>configure.lua
SNDFILE_LIBS=""
fi;
else
echo "#undef HAVE_SNDFILE" >$BLD/include/agar/config/have_sndfile.h
echo "hdefs[\"HAVE_SNDFILE\"] = nil" >>configure.lua
fi;
	if [ "${HAVE_SNDFILE}" = "yes" ]
 then
ENABLE_AU="yes"
echo "#ifndef ENABLE_AU" > $BLD/include/agar/config/enable_au.h
echo "#define ENABLE_AU \"$ENABLE_AU\"" >> $BLD/include/agar/config/enable_au.h
echo "#endif" >> $BLD/include/agar/config/enable_au.h
echo "hdefs[\"ENABLE_AU\"] = \"$ENABLE_AU\"" >>configure.lua
SUBDIR_au="au"
$ECHO_N "checking for PortAudio2..."
$ECHO_N "checking for PortAudio2..." >> config.log
PORTAUDIO_VERSION=""
if [ "${PKGCONFIG}" != "" -a "`${PKGCONFIG} --variable=prefix portaudio-2.0 2>/dev/null`" != "" ]; then
if [ "${prefix_portaudio}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix portaudio-2.0 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_portaudio}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, portaudio-2.0 is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_portaudio}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct portaudio-2.0 prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		PORTAUDIO_VERSION=`$PKGCONFIG portaudio-2.0 --modversion 2>/dev/null`
	fi
else
	PORTAUDIO_VERSION=`$PKGCONFIG portaudio-2.0 --modversion 2>/dev/null`
fi
if [ "${prefix_portaudio}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix portaudio-2.0 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_portaudio}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, portaudio-2.0 is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_portaudio}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct portaudio-2.0 prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		PORTAUDIO_CFLAGS=`$PKGCONFIG portaudio-2.0 --cflags 2>/dev/null`
	fi
else
	PORTAUDIO_CFLAGS=`$PKGCONFIG portaudio-2.0 --cflags 2>/dev/null`
fi
if [ "${prefix_portaudio}" != "" ]; then
	MK_EXEC_PKGPREFIX=`$PKGCONFIG --variable=prefix portaudio-2.0 2>/dev/null`
	if [ "$MK_EXEC_PKGPREFIX" != "${prefix_portaudio}" ]; then
		echo " "
		echo "* "
		echo "* ERROR: According to pkg-config, portaudio-2.0 is installed in prefix: "
		echo "* $MK_EXEC_PKGPREFIX, but the prefix (${prefix_portaudio}) was specified."
		echo "* "
		echo "* Please re-run ./configure again with the correct portaudio-2.0 prefix"
		echo "* (or specify no prefix at all to enable auto-detection)."
		echo "* "
		exit 1
	else
		PORTAUDIO_LIBS=`$PKGCONFIG portaudio-2.0 --libs 2>/dev/null`
	fi
else
	PORTAUDIO_LIBS=`$PKGCONFIG portaudio-2.0 --libs 2>/dev/null`
fi
if [ "${PORTAUDIO_VERSION}" != "" ]; then
PORTAUDIO_VERSION="${PORTAUDIO_VERSION}.0"
fi;
if [ -e  "/usr/local/include/portaudio2/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/usr/local/include/portaudio2 ${PORTAUDIO_CFLAGS}"
fi;
if [ -e  "/usr/include/portaudio2/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/usr/include/portaudio2 ${PORTAUDIO_CFLAGS}"
fi;
if [ -e  "/opt/local/include/portaudio2/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/opt/local/include/portaudio2 ${PORTAUDIO_CFLAGS}"
fi;
if [ -e  "/opt/include/portaudio2/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/opt/include/portaudio2 ${PORTAUDIO_CFLAGS}"
fi;
if [ -e  "/usr/pkg/include/portaudio2/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/usr/pkg/include/portaudio2 ${PORTAUDIO_CFLAGS}"
fi;
else
PORTAUDIO_CFLAGS=""
PORTAUDIO_LIBS=""
if [ "${prefix_portaudio}" != "" ]; then
if [ -e  "${prefix_portaudio}/include/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I${prefix_portaudio}/include ${PTHREADS_CFLAGS}"
PORTAUDIO_LIBS="-L${prefix_portaudio}/lib -lportaudio ${PTHREADS_LIBS}"
PORTAUDIO_VERSION="18.0"
fi;
else
if [ -e  "/usr/local/include/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/usr/local/include ${PTHREADS_CFLAGS}"
PORTAUDIO_LIBS="-L/usr/local/lib -lportaudio ${PTHREADS_LIBS}"
PORTAUDIO_VERSION="18.0"
fi;
if [ -e  "/usr/include/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/usr/include ${PTHREADS_CFLAGS}"
PORTAUDIO_LIBS="-L/usr/lib -lportaudio ${PTHREADS_LIBS}"
PORTAUDIO_VERSION="18.0"
fi;
if [ -e  "/opt/local/include/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/opt/local/include ${PTHREADS_CFLAGS}"
PORTAUDIO_LIBS="-L/opt/local/lib -lportaudio ${PTHREADS_LIBS}"
PORTAUDIO_VERSION="18.0"
fi;
if [ -e  "/opt/include/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/opt/include ${PTHREADS_CFLAGS}"
PORTAUDIO_LIBS="-L/opt/lib -lportaudio ${PTHREADS_LIBS}"
PORTAUDIO_VERSION="18.0"
fi;
if [ -e  "/usr/pkg/include/portaudio.h" ]; then
PORTAUDIO_CFLAGS="-I/usr/pkg/include ${PTHREADS_CFLAGS}"
PORTAUDIO_LIBS="-L/usr/pkg/lib -lportaudio ${PTHREADS_LIBS}"
PORTAUDIO_VERSION="18.0"
fi;
fi;
fi;
if [ "${PORTAUDIO_VERSION}" != "" ]; then
if [ "${prefix_portaudio}" != "" ]; then
echo "yes ($PORTAUDIO_VERSION in ${prefix_portaudio})"
echo "yes ($PORTAUDIO_VERSION in ${prefix_portaudio})" >> config.log
else
echo "yes ($PORTAUDIO_VERSION)"
echo "yes ($PORTAUDIO_VERSION)" >> config.log
fi;
MK_VERSION_MAJOR=`echo "$PORTAUDIO_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\1/'`;
MK_VERSION_MINOR=`echo "$PORTAUDIO_VERSION" |sed 's/\([0-9]*\).\([0-9]*\).\([0-9]*\).*/\2/'`;
MK_VERSION_OK="no"
if [ $MK_VERSION_MAJOR -gt 19 ]; then
	MK_VERSION_OK="yes";
elif [ $MK_VERSION_MAJOR -eq 19 ]; then
	if [ "$MK_VERSION_MINOR" = "" ]; then
		MK_VERSION_OK="yes"
	else
		if [ $MK_VERSION_MINOR -ge 0 ]; then
			MK_VERSION_OK="yes"
		fi
	fi
fi
if [ "${MK_VERSION_OK}" = "no" ]; then
echo "*"
echo "*" >> config.log
echo "* Minimum required version is 19.0 (found $PORTAUDIO_VERSION); skipping."
echo "* Minimum required version is 19.0 (found $PORTAUDIO_VERSION); skipping." >> config.log
echo "*"
echo "*" >> config.log
fi;
else
if [ "${prefix_portaudio}" != "" ]; then
echo "no (not in ${prefix_portaudio})"
echo "no (not in ${prefix_portaudio})" >> config.log
else
echo "no"
echo "no" >> config.log
fi;
MK_VERSION_OK="no"
fi;
if [ "${MK_VERSION_OK}" = "yes" ]; then
$ECHO_N "checking whether PortAudio2 works..."
$ECHO_N "checking whether PortAudio2 works..." >> config.log
MK_COMPILE_STATUS="OK"
cat << EOT > conftest.c
#include <stdio.h>
#include <portaudio.h>

int
main(int argc, char *argv[])
{
	int rv;

	if ((rv = Pa_Initialize()) != paNoError) {
		if (Pa_IsFormatSupported(NULL, NULL, 48000.0) != 0) {
			return (0);
		} else {
			return (rv);
		}
	} else {
		Pa_Terminate();
		return (0);
	}
}

EOT
echo "$CC $CFLAGS $TEST_CFLAGS ${PORTAUDIO_CFLAGS} -o $testdir/conftest conftest.c ${PORTAUDIO_LIBS}" >>config.log
$CC $CFLAGS $TEST_CFLAGS ${PORTAUDIO_CFLAGS} -o $testdir/conftest conftest.c ${PORTAUDIO_LIBS} 2>>config.log
if [ $? != 0 ]; then
	echo "-> failed ($?)" >> config.log
	MK_COMPILE_STATUS="FAIL($?)"
fi
if [ "${MK_COMPILE_STATUS}" = "OK" ]; then
echo "yes"
echo "yes" >> config.log
HAVE_PORTAUDIO="yes"
echo "#ifndef HAVE_PORTAUDIO" > $BLD/include/agar/config/have_portaudio.h
echo "#define HAVE_PORTAUDIO \"$HAVE_PORTAUDIO\"" >> $BLD/include/agar/config/have_portaudio.h
echo "#endif" >> $BLD/include/agar/config/have_portaudio.h
echo "hdefs[\"HAVE_PORTAUDIO\"] = \"$HAVE_PORTAUDIO\"" >>configure.lua
else
echo "no"
echo "no" >> config.log
HAVE_PORTAUDIO="no"
echo "#undef HAVE_PORTAUDIO" >$BLD/include/agar/config/have_portaudio.h
echo "hdefs[\"HAVE_PORTAUDIO\"] = nil" >>configure.lua
fi;
rm -f conftest.c $testdir/conftest$EXECSUFFIX
if [ "${HAVE_PORTAUDIO}" = "yes" ]; then
echo "#ifndef PORTAUDIO_CFLAGS" > $BLD/include/agar/config/portaudio_cflags.h
echo "#define PORTAUDIO_CFLAGS \"$PORTAUDIO_CFLAGS\"" >> $BLD/include/agar/config/portaudio_cflags.h
echo "#endif" >> $BLD/include/agar/config/portaudio_cflags.h
echo "hdefs[\"PORTAUDIO_CFLAGS\"] = \"$PORTAUDIO_CFLAGS\"" >>configure.lua
echo "#ifndef PORTAUDIO_LIBS" > $BLD/include/agar/config/portaudio_libs.h
echo "#define PORTAUDIO_LIBS \"$PORTAUDIO_LIBS\"" >> $BLD/include/agar/config/portaudio_libs.h
echo "#endif" >> $BLD/include/agar/config/portaudio_libs.h
echo "hdefs[\"PORTAUDIO_LIBS\"] = \"$PORTAUDIO_LIBS\"" >>configure.lua
else
echo "#undef PORTAUDIO_CFLAGS" >$BLD/include/agar/config/portaudio_cflags.h
echo "hdefs[\"PORTAUDIO_CFLAGS\"] = nil" >>configure.lua
PORTAUDIO_CFLAGS=""
echo "#undef PORTAUDIO_LIBS" >$BLD/include/agar/config/portaudio_libs.h
echo "hdefs[\"PORTAUDIO_LIBS\"] = nil" >>configure.lua
PORTAUDIO_LIBS=""
fi;
else
echo "#undef HAVE_PORTAUDIO" >$BLD/include/agar/config/have_portaudio.h
echo "hdefs[\"HAVE_PORTAUDIO\"] = nil" >>configure.lua
echo "#undef PORTAUDIO_CFLAGS" >$BLD/include/agar/config/portaudio_cflags.h
echo "hdefs[\"PORTAUDIO_CFLAGS\"] = nil" >>configure.lua
echo "#undef PORTAUDIO_LIBS" >$BLD/include/agar/config/portaudio_libs.h
echo "hdefs[\"PORTAUDIO_LIBS\"] = nil" >>configure.lua
fi;
	else
		if [ "${enable_au}" = "yes" -o "${enable_audio}" = "yes" ]
 then
			echo "*"
			echo "* --enable-au was requested, but the sndfile library"
			echo "* (required) is not installed."
			echo "*"
			exit 1
		fi
echo "#undef ENABLE_AU" >$BLD/include/agar/config/enable_au.h
echo "hdefs[\"ENABLE_AU\"] = nil" >>configure.lua
SUBDIR_au=""
echo "#undef HAVE_SNDFILE" >$BLD/include/agar/config/have_sndfile.h
echo "hdefs[\"HAVE_SNDFILE\"] = nil" >>configure.lua
echo "#undef HAVE_PORTAUDIO" >$BLD/include/agar/config/have_portaudio.h
echo "hdefs[\"HAVE_PORTAUDIO\"] = nil" >>configure.lua
	fi
else
echo "#undef ENABLE_AU" >$BLD/include/agar/config/enable_au.h
echo "hdefs[\"ENABLE_AU\"] = nil" >>configure.lua
SUBDIR_au=""
echo "#undef HAVE_SNDFILE" >$BLD/include/agar/config/have_sndfile.h
echo "hdefs[\"HAVE_SNDFILE\"] = nil" >>configure.lua
echo "#undef HAVE_PORTAUDIO" >$BLD/include/agar/config/have_portaudio.h
echo "hdefs[\"HAVE_PORTAUDIO\"] = nil" >>configure.lua
fi
SRCS_CORE=""
if [ "${HAVE_SNPRINTF}" != "yes" ]
 then
SRCS_CORE="${SRCS_CORE} snprintf.c"
fi
if [ "${HAVE_CLOCK_WIN32}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} time_win32.c"
fi
if [ "${HAVE_CLOCK_GETTIME}" = "yes" ]
 then
	if [ "${HAVE_NANOSLEEP}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} time_posix.c"
	fi
	if [ "${HAVE_PTHREADS}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} time_renderer.c"
	fi
fi
if [ "${HAVE_GETTIMEOFDAY}" = "yes" ]
 then
	if [ "${HAVE_SELECT}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} time_gettimeofday.c"
	fi
fi
if [ "${HAVE_DB4}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} db_bdb.c"
fi
if [ "${HAVE_MYSQL}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} db_mysql.c"
fi
if [ "${HAVE_NETWORK}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} net.c net_dummy.c"
	if [ "${HAVE_WINSOCK1}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} net_winsock1.c"
	fi
	if [ "${HAVE_WINSOCK2}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} net_winsock2.c"
	fi
	if [ "${HAVE_GETADDRINFO}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} net_bsd.c"
	fi
fi
if [ "${HAVE_GETPWUID}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} user_posix.c"
fi
if [ "${HAVE_XBOX}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} user_xbox.c xbox.c"
fi
if [ "${HAVE_CSIDL}" = "yes" ]
 then
SRCS_CORE="${SRCS_CORE} user_win32.c"
fi
SRCS_GUI=""
if [ "${HAVE_SDL}" = "yes" ]
 then
SRCS_GUI="${SRCS_GUI} drv_sdl_common.c drv_sdlfb.c"
	if [ "${HAVE_OPENGL}" = "yes" ]
 then
SRCS_GUI="${SRCS_GUI} drv_sdlgl.c"
	fi
fi
if [ "${HAVE_OPENGL}" = "yes" ]
 then
SRCS_GUI="${SRCS_GUI} drv_gl_common.c"
	if [ "${HAVE_GLX}" = "yes" ]
 then
SRCS_GUI="${SRCS_GUI} drv_glx.c"
	fi
	if [ "${HAVE_WGL}" = "yes" ]
 then
SRCS_GUI="${SRCS_GUI} drv_wgl.c"
	fi
fi
if [ "${HAVE_COCOA}" = "yes" ]
 then
SRCS_GUI="${SRCS_GUI} drv_cocoa.m"
fi
SRCS_AU=""
if [ "${AG_THREADS}" = "yes" ]
 then
	if [ "${HAVE_SNDFILE}" = "yes" ]
 then
SRCS_AU="${SRCS_AU} au_dev_file.c"
	fi
	if [ "${HAVE_PORTAUDIO}" = "yes" ]
 then
SRCS_AU="${SRCS_AU} au_dev_pa.c"
	fi
fi
if [ ! -e "$BLD/include/agar" ]; then
	mkdir -p "$BLD/include/agar"
fi
if [ "${includes}" = "link" ]; then
	$ECHO_N "* Linking C include files..."
	if [ "${SRCDIR}" != "${BLDDIR}" ]; then
		(cd ${SRCDIR} && ${PERL} mk/gen-includelinks.pl "${SRCDIR}" "$BLD/include/agar" 1>>${BLDDIR}/config.log 2>&1)
	else
		${PERL} mk/gen-includelinks.pl "${SRCDIR}" "$BLD/include/agar" 1>>config.log 2>&1
	fi
	if [ $? != 0 ]; then
		echo "${PERL} mk/gen-includelinks.pl failed"
		exit 1
	fi
	echo "done"
else
	if [ "${PERL}" = "" ]; then
		echo "*"
		echo "* The --includes=yes option requires perl, but no perl"
		echo "* interpreter was found. If perl is unavailable, please"
		echo "* please rerun configure with --includes=link instead."
		echo "*"
		exit 1
	fi
	$ECHO_N "* Preprocessing C include files..."
	if [ "${SRCDIR}" != "${BLDDIR}" ]; then
		(cd ${SRCDIR} && ${PERL} mk/gen-includes.pl "$BLD/include/agar" 1>>${BLDDIR}/config.log 2>&1)
	else
		${PERL} mk/gen-includes.pl "$BLD/include/agar" 1>>config.log 2>&1
	fi
	if [ $? != 0 ]; then
		echo "${PERL} mk/gen-includes.pl failed"
		exit 1
	fi
	echo "done"
fi
CFLAGS="$CFLAGS -I$BLD/include"
CXXFLAGS="$CXXFLAGS -I$BLD/include"
config_script_out="agar-config"
config_script_cflags="-I${INCLDIR} ${SDL_CFLAGS} ${FREETYPE_CFLAGS} ${FONTCONFIG_CFLAGS} ${OPENGL_CFLAGS} ${X11_CFLAGS} ${GLX_CFLAGS} ${XINERAMA_CFLAGS} ${COCOA_CFLAGS} ${MATH_CFLAGS} ${PNG_CFLAGS} ${PTHREADS_CFLAGS} ${DB4_CFLAGS} ${MYSQL_CFLAGS} ${GETTEXT_CFLAGS} ${DSO_CFLAGS} ${CLOCK_CFLAGS} ${UIM_CFLAGS} ${ICONV_CFLAGS}"
config_script_libs="-L${LIBDIR} -lag_gui -lag_core ${SDL_LIBS} ${FREETYPE_LIBS} ${FONTCONFIG_LIBS} ${OPENGL_LIBS} ${X11_LIBS} ${XINERAMA_LIBS} ${COCOA_LIBS} ${MATH_LIBS} ${JPEG_LIBS} ${PNG_LIBS} ${PTHREADS_LIBS} ${DB4_LIBS} ${MYSQL_LIBS} ${GETTEXT_LIBS} ${DSO_LIBS} ${CLOCK_LIBS} ${UIM_LIBS} ${ICONV_LIBS}"
# Avoid breakage with existing trees compiled before BSDBuild 2.8.
if [ -d "$config_script_out" ]; then
	echo "rm -fR $config_script_out"
	rm -fR $config_script_out
fi
if [ "${SRC}" != "" ]; then
	if [ -d "${SRC}/$config_script_out" ]; then
		echo "rm -fR ${SRC}/$config_script_out"
		rm -fR ${SRC}/$config_script_out
	fi
fi
cat << EOT > $config_script_out
#!/bin/sh
# Generated for ${PACKAGE} by BSDBuild 3.2.
# <http://bsdbuild.hypertriton.com>

prefix="${PREFIX}"
exec_prefix="${EXEC_PREFIX}"
exec_prefix_set="no"
libdir="${LIBDIR}"

usage="\
Usage: $config_script_out [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"

if test \$# -eq 0; then
	echo "\${usage}" 1>&2
	exit 1
fi

while test \$# -gt 0; do
	case "\$1" in
	-*=*)
		optarg=\`echo "\$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'\`
		;;
	*)
		optarg=
		;;
	esac

	case \$1 in
	--prefix=*)
		prefix=\$optarg
		if test \$exec_prefix_set = no ; then
			exec_prefix=\$optarg
		fi
		;;
	--prefix)
		echo "\$prefix"
		;;
	--exec-prefix=*)
		exec_prefix=\$optarg
		exec_prefix_set=yes
		;;
	--exec-prefix)
		echo "\$exec_prefix"
		;;
	--version)
		echo "${VERSION}"
		;;
	--cflags)
		echo "$config_script_cflags"
		;;
	--libs | --static-libs)
		echo "$config_script_libs"
		;;
	*)
		echo "\${usage}" 1>&2
		exit 1
		;;
	esac
	shift
done
EOT
config_script_out="agar-core-config"
config_script_cflags="-I${INCLDIR} ${MATH_CFLAGS} ${GETTEXT_CFLAGS} ${DSO_CFLAGS} ${CLOCK_CFLAGS} ${ICONV_CFLAGS}"
config_script_libs="-L${LIBDIR} -lag_core ${MATH_LIBS} ${PTHREADS_LIBS} ${DB4_LIBS} ${MYSQL_LIBS} ${GETTEXT_LIBS} ${DSO_LIBS} ${CLOCK_LIBS} ${ICONV_LIBS}"
# Avoid breakage with existing trees compiled before BSDBuild 2.8.
if [ -d "$config_script_out" ]; then
	echo "rm -fR $config_script_out"
	rm -fR $config_script_out
fi
if [ "${SRC}" != "" ]; then
	if [ -d "${SRC}/$config_script_out" ]; then
		echo "rm -fR ${SRC}/$config_script_out"
		rm -fR ${SRC}/$config_script_out
	fi
fi
cat << EOT > $config_script_out
#!/bin/sh
# Generated for ${PACKAGE} by BSDBuild 3.2.
# <http://bsdbuild.hypertriton.com>

prefix="${PREFIX}"
exec_prefix="${EXEC_PREFIX}"
exec_prefix_set="no"
libdir="${LIBDIR}"

usage="\
Usage: $config_script_out [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"

if test \$# -eq 0; then
	echo "\${usage}" 1>&2
	exit 1
fi

while test \$# -gt 0; do
	case "\$1" in
	-*=*)
		optarg=\`echo "\$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'\`
		;;
	*)
		optarg=
		;;
	esac

	case \$1 in
	--prefix=*)
		prefix=\$optarg
		if test \$exec_prefix_set = no ; then
			exec_prefix=\$optarg
		fi
		;;
	--prefix)
		echo "\$prefix"
		;;
	--exec-prefix=*)
		exec_prefix=\$optarg
		exec_prefix_set=yes
		;;
	--exec-prefix)
		echo "\$exec_prefix"
		;;
	--version)
		echo "${VERSION}"
		;;
	--cflags)
		echo "$config_script_cflags"
		;;
	--libs | --static-libs)
		echo "$config_script_libs"
		;;
	*)
		echo "\${usage}" 1>&2
		exit 1
		;;
	esac
	shift
done
EOT
config_script_out="agar-dev-config"
config_script_cflags="-I${INCLDIR}"
config_script_libs="-L${LIBDIR} -lag_dev"
# Avoid breakage with existing trees compiled before BSDBuild 2.8.
if [ -d "$config_script_out" ]; then
	echo "rm -fR $config_script_out"
	rm -fR $config_script_out
fi
if [ "${SRC}" != "" ]; then
	if [ -d "${SRC}/$config_script_out" ]; then
		echo "rm -fR ${SRC}/$config_script_out"
		rm -fR ${SRC}/$config_script_out
	fi
fi
cat << EOT > $config_script_out
#!/bin/sh
# Generated for ${PACKAGE} by BSDBuild 3.2.
# <http://bsdbuild.hypertriton.com>

prefix="${PREFIX}"
exec_prefix="${EXEC_PREFIX}"
exec_prefix_set="no"
libdir="${LIBDIR}"

usage="\
Usage: $config_script_out [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"

if test \$# -eq 0; then
	echo "\${usage}" 1>&2
	exit 1
fi

while test \$# -gt 0; do
	case "\$1" in
	-*=*)
		optarg=\`echo "\$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'\`
		;;
	*)
		optarg=
		;;
	esac

	case \$1 in
	--prefix=*)
		prefix=\$optarg
		if test \$exec_prefix_set = no ; then
			exec_prefix=\$optarg
		fi
		;;
	--prefix)
		echo "\$prefix"
		;;
	--exec-prefix=*)
		exec_prefix=\$optarg
		exec_prefix_set=yes
		;;
	--exec-prefix)
		echo "\$exec_prefix"
		;;
	--version)
		echo "${VERSION}"
		;;
	--cflags)
		echo "$config_script_cflags"
		;;
	--libs | --static-libs)
		echo "$config_script_libs"
		;;
	*)
		echo "\${usage}" 1>&2
		exit 1
		;;
	esac
	shift
done
EOT
config_script_out="agar-math-config"
config_script_cflags="-I${INCLDIR} ${MATH_CFLAGS} ${ALTIVEC_CFLAGS} ${SSE_CFLAGS} ${SSE2_CFLAGS} ${SSE3_CFLAGS} ${MATH_CFLAGS}"
config_script_libs="-L${LIBDIR} -lag_math ${MATH_LIBS}"
# Avoid breakage with existing trees compiled before BSDBuild 2.8.
if [ -d "$config_script_out" ]; then
	echo "rm -fR $config_script_out"
	rm -fR $config_script_out
fi
if [ "${SRC}" != "" ]; then
	if [ -d "${SRC}/$config_script_out" ]; then
		echo "rm -fR ${SRC}/$config_script_out"
		rm -fR ${SRC}/$config_script_out
	fi
fi
cat << EOT > $config_script_out
#!/bin/sh
# Generated for ${PACKAGE} by BSDBuild 3.2.
# <http://bsdbuild.hypertriton.com>

prefix="${PREFIX}"
exec_prefix="${EXEC_PREFIX}"
exec_prefix_set="no"
libdir="${LIBDIR}"

usage="\
Usage: $config_script_out [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"

if test \$# -eq 0; then
	echo "\${usage}" 1>&2
	exit 1
fi

while test \$# -gt 0; do
	case "\$1" in
	-*=*)
		optarg=\`echo "\$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'\`
		;;
	*)
		optarg=
		;;
	esac

	case \$1 in
	--prefix=*)
		prefix=\$optarg
		if test \$exec_prefix_set = no ; then
			exec_prefix=\$optarg
		fi
		;;
	--prefix)
		echo "\$prefix"
		;;
	--exec-prefix=*)
		exec_prefix=\$optarg
		exec_prefix_set=yes
		;;
	--exec-prefix)
		echo "\$exec_prefix"
		;;
	--version)
		echo "${VERSION}"
		;;
	--cflags)
		echo "$config_script_cflags"
		;;
	--libs | --static-libs)
		echo "$config_script_libs"
		;;
	*)
		echo "\${usage}" 1>&2
		exit 1
		;;
	esac
	shift
done
EOT
config_script_out="agar-vg-config"
config_script_cflags="-I${INCLDIR}"
config_script_libs="-L${LIBDIR} -lag_vg"
# Avoid breakage with existing trees compiled before BSDBuild 2.8.
if [ -d "$config_script_out" ]; then
	echo "rm -fR $config_script_out"
	rm -fR $config_script_out
fi
if [ "${SRC}" != "" ]; then
	if [ -d "${SRC}/$config_script_out" ]; then
		echo "rm -fR ${SRC}/$config_script_out"
		rm -fR ${SRC}/$config_script_out
	fi
fi
cat << EOT > $config_script_out
#!/bin/sh
# Generated for ${PACKAGE} by BSDBuild 3.2.
# <http://bsdbuild.hypertriton.com>

prefix="${PREFIX}"
exec_prefix="${EXEC_PREFIX}"
exec_prefix_set="no"
libdir="${LIBDIR}"

usage="\
Usage: $config_script_out [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"

if test \$# -eq 0; then
	echo "\${usage}" 1>&2
	exit 1
fi

while test \$# -gt 0; do
	case "\$1" in
	-*=*)
		optarg=\`echo "\$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'\`
		;;
	*)
		optarg=
		;;
	esac

	case \$1 in
	--prefix=*)
		prefix=\$optarg
		if test \$exec_prefix_set = no ; then
			exec_prefix=\$optarg
		fi
		;;
	--prefix)
		echo "\$prefix"
		;;
	--exec-prefix=*)
		exec_prefix=\$optarg
		exec_prefix_set=yes
		;;
	--exec-prefix)
		echo "\$exec_prefix"
		;;
	--version)
		echo "${VERSION}"
		;;
	--cflags)
		echo "$config_script_cflags"
		;;
	--libs | --static-libs)
		echo "$config_script_libs"
		;;
	*)
		echo "\${usage}" 1>&2
		exit 1
		;;
	esac
	shift
done
EOT
config_script_out="agar-au-config"
config_script_cflags="-I${INCLDIR} ${PORTAUDIO_CFLAGS} ${SNDFILE_CFLAGS}"
config_script_libs="-L${LIBDIR} -lag_au ${PORTAUDIO_LIBS} ${SNDFILE_LIBS}"
# Avoid breakage with existing trees compiled before BSDBuild 2.8.
if [ -d "$config_script_out" ]; then
	echo "rm -fR $config_script_out"
	rm -fR $config_script_out
fi
if [ "${SRC}" != "" ]; then
	if [ -d "${SRC}/$config_script_out" ]; then
		echo "rm -fR ${SRC}/$config_script_out"
		rm -fR ${SRC}/$config_script_out
	fi
fi
cat << EOT > $config_script_out
#!/bin/sh
# Generated for ${PACKAGE} by BSDBuild 3.2.
# <http://bsdbuild.hypertriton.com>

prefix="${PREFIX}"
exec_prefix="${EXEC_PREFIX}"
exec_prefix_set="no"
libdir="${LIBDIR}"

usage="\
Usage: $config_script_out [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs]"

if test \$# -eq 0; then
	echo "\${usage}" 1>&2
	exit 1
fi

while test \$# -gt 0; do
	case "\$1" in
	-*=*)
		optarg=\`echo "\$1" | LC_ALL="C" sed 's/[-_a-zA-Z0-9]*=//'\`
		;;
	*)
		optarg=
		;;
	esac

	case \$1 in
	--prefix=*)
		prefix=\$optarg
		if test \$exec_prefix_set = no ; then
			exec_prefix=\$optarg
		fi
		;;
	--prefix)
		echo "\$prefix"
		;;
	--exec-prefix=*)
		exec_prefix=\$optarg
		exec_prefix_set=yes
		;;
	--exec-prefix)
		echo "\$exec_prefix"
		;;
	--version)
		echo "${VERSION}"
		;;
	--cflags)
		echo "$config_script_cflags"
		;;
	--libs | --static-libs)
		echo "$config_script_libs"
		;;
	*)
		echo "\${usage}" 1>&2
		exit 1
		;;
	esac
	shift
done
EOT
echo "OBJC=$OBJC" >>Makefile.config
echo "mdefs[\"OBJC\"] = \"$OBJC\"" >>configure.lua
echo "HAVE_SDL=$HAVE_SDL" >>Makefile.config
echo "mdefs[\"HAVE_SDL\"] = \"$HAVE_SDL\"" >>configure.lua
echo "GETTEXT_LIBS=$GETTEXT_LIBS" >>Makefile.config
echo "mdefs[\"GETTEXT_LIBS\"] = \"$GETTEXT_LIBS\"" >>configure.lua
echo "PORTAUDIO_LIBS=$PORTAUDIO_LIBS" >>Makefile.config
echo "mdefs[\"PORTAUDIO_LIBS\"] = \"$PORTAUDIO_LIBS\"" >>configure.lua
echo "GLX_CFLAGS=$GLX_CFLAGS" >>Makefile.config
echo "mdefs[\"GLX_CFLAGS\"] = \"$GLX_CFLAGS\"" >>configure.lua
echo "SRCS_AU=$SRCS_AU" >>Makefile.config
echo "mdefs[\"SRCS_AU\"] = \"$SRCS_AU\"" >>configure.lua
echo "_MK_HAVE_FLOAT_H=$_MK_HAVE_FLOAT_H" >>Makefile.config
echo "mdefs[\"_MK_HAVE_FLOAT_H\"] = \"$_MK_HAVE_FLOAT_H\"" >>configure.lua
echo "SUBDIR_dev=$SUBDIR_dev" >>Makefile.config
echo "mdefs[\"SUBDIR_dev\"] = \"$SUBDIR_dev\"" >>configure.lua
echo "HAVE_COCOA=$HAVE_COCOA" >>Makefile.config
echo "mdefs[\"HAVE_COCOA\"] = \"$HAVE_COCOA\"" >>configure.lua
echo "SSE3_CFLAGS=$SSE3_CFLAGS" >>Makefile.config
echo "mdefs[\"SSE3_CFLAGS\"] = \"$SSE3_CFLAGS\"" >>configure.lua
echo "HAVE_UNUSED_VARIABLE_ATTRIBUTE=$HAVE_UNUSED_VARIABLE_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_UNUSED_VARIABLE_ATTRIBUTE\"] = \"$HAVE_UNUSED_VARIABLE_ATTRIBUTE\"" >>configure.lua
echo "GLX_LIBS=$GLX_LIBS" >>Makefile.config
echo "mdefs[\"GLX_LIBS\"] = \"$GLX_LIBS\"" >>configure.lua
echo "HAVE_MATH=$HAVE_MATH" >>Makefile.config
echo "mdefs[\"HAVE_MATH\"] = \"$HAVE_MATH\"" >>configure.lua
echo "MATH_C99_LIBS=$MATH_C99_LIBS" >>Makefile.config
echo "mdefs[\"MATH_C99_LIBS\"] = \"$MATH_C99_LIBS\"" >>configure.lua
echo "HAVE_VASPRINTF=$HAVE_VASPRINTF" >>Makefile.config
echo "mdefs[\"HAVE_VASPRINTF\"] = \"$HAVE_VASPRINTF\"" >>configure.lua
echo "SSE_CFLAGS=$SSE_CFLAGS" >>Makefile.config
echo "mdefs[\"SSE_CFLAGS\"] = \"$SSE_CFLAGS\"" >>configure.lua
echo "LOCALEDIR=$LOCALEDIR" >>Makefile.config
echo "mdefs[\"LOCALEDIR\"] = \"$LOCALEDIR\"" >>configure.lua
echo "DB4_LIBS=$DB4_LIBS" >>Makefile.config
echo "mdefs[\"DB4_LIBS\"] = \"$DB4_LIBS\"" >>configure.lua
echo "HAVE_WARN_UNUSED_RESULT_ATTRIBUTE=$HAVE_WARN_UNUSED_RESULT_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_WARN_UNUSED_RESULT_ATTRIBUTE\"] = \"$HAVE_WARN_UNUSED_RESULT_ATTRIBUTE\"" >>configure.lua
echo "HAVE_NONNULL_ATTRIBUTE=$HAVE_NONNULL_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_NONNULL_ATTRIBUTE\"] = \"$HAVE_NONNULL_ATTRIBUTE\"" >>configure.lua
echo "HAVE_LIBPNG14=$HAVE_LIBPNG14" >>Makefile.config
echo "mdefs[\"HAVE_LIBPNG14\"] = \"$HAVE_LIBPNG14\"" >>configure.lua
echo "PROG_CLI_FLAGS=$PROG_CLI_FLAGS" >>Makefile.config
echo "mdefs[\"PROG_CLI_FLAGS\"] = \"$PROG_CLI_FLAGS\"" >>configure.lua
echo "HAVE_FREETYPE=$HAVE_FREETYPE" >>Makefile.config
echo "mdefs[\"HAVE_FREETYPE\"] = \"$HAVE_FREETYPE\"" >>configure.lua
echo "LIBTOOLOPTS_SHARED=$LIBTOOLOPTS_SHARED" >>Makefile.config
echo "mdefs[\"LIBTOOLOPTS_SHARED\"] = \"$LIBTOOLOPTS_SHARED\"" >>configure.lua
echo "HAVE_CC_MWINDOWS=$HAVE_CC_MWINDOWS" >>Makefile.config
echo "mdefs[\"HAVE_CC_MWINDOWS\"] = \"$HAVE_CC_MWINDOWS\"" >>configure.lua
echo "HAVE_PTHREADS=$HAVE_PTHREADS" >>Makefile.config
echo "mdefs[\"HAVE_PTHREADS\"] = \"$HAVE_PTHREADS\"" >>configure.lua
echo "LIBEXECDIR=$LIBEXECDIR" >>Makefile.config
echo "mdefs[\"LIBEXECDIR\"] = \"$LIBEXECDIR\"" >>configure.lua
echo "SRCS_CORE=$SRCS_CORE" >>Makefile.config
echo "mdefs[\"SRCS_CORE\"] = \"$SRCS_CORE\"" >>configure.lua
echo "SUBDIR_gui=$SUBDIR_gui" >>Makefile.config
echo "mdefs[\"SUBDIR_gui\"] = \"$SUBDIR_gui\"" >>configure.lua
echo "HAVE_NETWORK=$HAVE_NETWORK" >>Makefile.config
echo "mdefs[\"HAVE_NETWORK\"] = \"$HAVE_NETWORK\"" >>configure.lua
echo "HAVE_CC_WARNINGS=$HAVE_CC_WARNINGS" >>Makefile.config
echo "mdefs[\"HAVE_CC_WARNINGS\"] = \"$HAVE_CC_WARNINGS\"" >>configure.lua
echo "CLOCK_LIBS=$CLOCK_LIBS" >>Makefile.config
echo "mdefs[\"CLOCK_LIBS\"] = \"$CLOCK_LIBS\"" >>configure.lua
echo "PROG_BUNDLE=$PROG_BUNDLE" >>Makefile.config
echo "mdefs[\"PROG_BUNDLE\"] = \"$PROG_BUNDLE\"" >>configure.lua
echo "HAVE_XKB=$HAVE_XKB" >>Makefile.config
echo "mdefs[\"HAVE_XKB\"] = \"$HAVE_XKB\"" >>configure.lua
echo "PACKAGE=$PACKAGE" >>Makefile.config
echo "mdefs[\"PACKAGE\"] = \"$PACKAGE\"" >>configure.lua
echo "HAVE_JPEG=$HAVE_JPEG" >>Makefile.config
echo "mdefs[\"HAVE_JPEG\"] = \"$HAVE_JPEG\"" >>configure.lua
echo "XINERAMA_CFLAGS=$XINERAMA_CFLAGS" >>Makefile.config
echo "mdefs[\"XINERAMA_CFLAGS\"] = \"$XINERAMA_CFLAGS\"" >>configure.lua
echo "HAVE_LD_STATIC_LIBGCC=$HAVE_LD_STATIC_LIBGCC" >>Makefile.config
echo "mdefs[\"HAVE_LD_STATIC_LIBGCC\"] = \"$HAVE_LD_STATIC_LIBGCC\"" >>configure.lua
echo "HAVE_UIM=$HAVE_UIM" >>Makefile.config
echo "mdefs[\"HAVE_UIM\"] = \"$HAVE_UIM\"" >>configure.lua
echo "CC=$CC" >>Makefile.config
echo "mdefs[\"CC\"] = \"$CC\"" >>configure.lua
echo "HAVE_ICONV_CONST=$HAVE_ICONV_CONST" >>Makefile.config
echo "mdefs[\"HAVE_ICONV_CONST\"] = \"$HAVE_ICONV_CONST\"" >>configure.lua
echo "MYSQL_LIBS=$MYSQL_LIBS" >>Makefile.config
echo "mdefs[\"MYSQL_LIBS\"] = \"$MYSQL_LIBS\"" >>configure.lua
echo "MANDIR=$MANDIR" >>Makefile.config
echo "mdefs[\"MANDIR\"] = \"$MANDIR\"" >>configure.lua
echo "X11_LIBS=$X11_LIBS" >>Makefile.config
echo "mdefs[\"X11_LIBS\"] = \"$X11_LIBS\"" >>configure.lua
echo "UIM_CFLAGS=$UIM_CFLAGS" >>Makefile.config
echo "mdefs[\"UIM_CFLAGS\"] = \"$UIM_CFLAGS\"" >>configure.lua
echo "HAVE_CSIDL=$HAVE_CSIDL" >>Makefile.config
echo "mdefs[\"HAVE_CSIDL\"] = \"$HAVE_CSIDL\"" >>configure.lua
echo "LIBDIR=$LIBDIR" >>Makefile.config
echo "mdefs[\"LIBDIR\"] = \"$LIBDIR\"" >>configure.lua
echo "HAVE_PORTAUDIO=$HAVE_PORTAUDIO" >>Makefile.config
echo "mdefs[\"HAVE_PORTAUDIO\"] = \"$HAVE_PORTAUDIO\"" >>configure.lua
echo "HAVE_ASPRINTF=$HAVE_ASPRINTF" >>Makefile.config
echo "mdefs[\"HAVE_ASPRINTF\"] = \"$HAVE_ASPRINTF\"" >>configure.lua
echo "ICONV_CFLAGS=$ICONV_CFLAGS" >>Makefile.config
echo "mdefs[\"ICONV_CFLAGS\"] = \"$ICONV_CFLAGS\"" >>configure.lua
echo "HAVE_OPENGL=$HAVE_OPENGL" >>Makefile.config
echo "mdefs[\"HAVE_OPENGL\"] = \"$HAVE_OPENGL\"" >>configure.lua
echo "ICONV_LIBS=$ICONV_LIBS" >>Makefile.config
echo "mdefs[\"ICONV_LIBS\"] = \"$ICONV_LIBS\"" >>configure.lua
echo "HAVE_SSE2=$HAVE_SSE2" >>Makefile.config
echo "mdefs[\"HAVE_SSE2\"] = \"$HAVE_SSE2\"" >>configure.lua
echo "COCOA_CFLAGS=$COCOA_CFLAGS" >>Makefile.config
echo "mdefs[\"COCOA_CFLAGS\"] = \"$COCOA_CFLAGS\"" >>configure.lua
echo "PORTAUDIO_CFLAGS=$PORTAUDIO_CFLAGS" >>Makefile.config
echo "mdefs[\"PORTAUDIO_CFLAGS\"] = \"$PORTAUDIO_CFLAGS\"" >>configure.lua
echo "HAVE_PTHREADS_XOPEN=$HAVE_PTHREADS_XOPEN" >>Makefile.config
echo "mdefs[\"HAVE_PTHREADS_XOPEN\"] = \"$HAVE_PTHREADS_XOPEN\"" >>configure.lua
echo "HAVE_CONST_ATTRIBUTE=$HAVE_CONST_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_CONST_ATTRIBUTE\"] = \"$HAVE_CONST_ATTRIBUTE\"" >>configure.lua
echo "DATADIR=$DATADIR" >>Makefile.config
echo "mdefs[\"DATADIR\"] = \"$DATADIR\"" >>configure.lua
echo "HAVE_OBJC_WARNINGS=$HAVE_OBJC_WARNINGS" >>Makefile.config
echo "mdefs[\"HAVE_OBJC_WARNINGS\"] = \"$HAVE_OBJC_WARNINGS\"" >>configure.lua
echo "SYSCONFDIR=$SYSCONFDIR" >>Makefile.config
echo "mdefs[\"SYSCONFDIR\"] = \"$SYSCONFDIR\"" >>configure.lua
echo "MATH_CFLAGS=$MATH_CFLAGS" >>Makefile.config
echo "mdefs[\"MATH_CFLAGS\"] = \"$MATH_CFLAGS\"" >>configure.lua
echo "CXXFLAGS=$CXXFLAGS" >>Makefile.config
echo "mdefs[\"CXXFLAGS\"] = \"$CXXFLAGS\"" >>configure.lua
echo "SDL_LIBS=$SDL_LIBS" >>Makefile.config
echo "mdefs[\"SDL_LIBS\"] = \"$SDL_LIBS\"" >>configure.lua
echo "HAVE_WGL=$HAVE_WGL" >>Makefile.config
echo "mdefs[\"HAVE_WGL\"] = \"$HAVE_WGL\"" >>configure.lua
echo "HAVE_LIBOPENGL32=$HAVE_LIBOPENGL32" >>Makefile.config
echo "mdefs[\"HAVE_LIBOPENGL32\"] = \"$HAVE_LIBOPENGL32\"" >>configure.lua
echo "MATH_LIBS=$MATH_LIBS" >>Makefile.config
echo "mdefs[\"MATH_LIBS\"] = \"$MATH_LIBS\"" >>configure.lua
echo "SUBDIR_au=$SUBDIR_au" >>Makefile.config
echo "mdefs[\"SUBDIR_au\"] = \"$SUBDIR_au\"" >>configure.lua
echo "UIM_LIBS=$UIM_LIBS" >>Makefile.config
echo "mdefs[\"UIM_LIBS\"] = \"$UIM_LIBS\"" >>configure.lua
echo "TTFDIR=$TTFDIR" >>Makefile.config
echo "mdefs[\"TTFDIR\"] = \"$TTFDIR\"" >>configure.lua
echo "HAVE_ALTIVEC=$HAVE_ALTIVEC" >>Makefile.config
echo "mdefs[\"HAVE_ALTIVEC\"] = \"$HAVE_ALTIVEC\"" >>configure.lua
echo "ENABLE_NLS=$ENABLE_NLS" >>Makefile.config
echo "mdefs[\"ENABLE_NLS\"] = \"$ENABLE_NLS\"" >>configure.lua
echo "X11_CFLAGS=$X11_CFLAGS" >>Makefile.config
echo "mdefs[\"X11_CFLAGS\"] = \"$X11_CFLAGS\"" >>configure.lua
echo "SNDFILE_LIBS=$SNDFILE_LIBS" >>Makefile.config
echo "mdefs[\"SNDFILE_LIBS\"] = \"$SNDFILE_LIBS\"" >>configure.lua
echo "DSO_LIBS=$DSO_LIBS" >>Makefile.config
echo "mdefs[\"DSO_LIBS\"] = \"$DSO_LIBS\"" >>configure.lua
echo "HAVE_DEPRECATED_ATTRIBUTE=$HAVE_DEPRECATED_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_DEPRECATED_ATTRIBUTE\"] = \"$HAVE_DEPRECATED_ATTRIBUTE\"" >>configure.lua
echo "SDL_CFLAGS=$SDL_CFLAGS" >>Makefile.config
echo "mdefs[\"SDL_CFLAGS\"] = \"$SDL_CFLAGS\"" >>configure.lua
echo "GETTEXT_CFLAGS=$GETTEXT_CFLAGS" >>Makefile.config
echo "mdefs[\"GETTEXT_CFLAGS\"] = \"$GETTEXT_CFLAGS\"" >>configure.lua
echo "HAVE_SSE=$HAVE_SSE" >>Makefile.config
echo "mdefs[\"HAVE_SSE\"] = \"$HAVE_SSE\"" >>configure.lua
echo "HAVE_CC_MCONSOLE=$HAVE_CC_MCONSOLE" >>Makefile.config
echo "mdefs[\"HAVE_CC_MCONSOLE\"] = \"$HAVE_CC_MCONSOLE\"" >>configure.lua
echo "_MK_HAVE_UNISTD_H=$_MK_HAVE_UNISTD_H" >>Makefile.config
echo "mdefs[\"_MK_HAVE_UNISTD_H\"] = \"$_MK_HAVE_UNISTD_H\"" >>configure.lua
echo "ALTIVEC_CFLAGS=$ALTIVEC_CFLAGS" >>Makefile.config
echo "mdefs[\"ALTIVEC_CFLAGS\"] = \"$ALTIVEC_CFLAGS\"" >>configure.lua
echo "HAVE_X11=$HAVE_X11" >>Makefile.config
echo "mdefs[\"HAVE_X11\"] = \"$HAVE_X11\"" >>configure.lua
echo "HAVE_PNG=$HAVE_PNG" >>Makefile.config
echo "mdefs[\"HAVE_PNG\"] = \"$HAVE_PNG\"" >>configure.lua
echo "HAVE_SHL_LOAD=$HAVE_SHL_LOAD" >>Makefile.config
echo "mdefs[\"HAVE_SHL_LOAD\"] = \"$HAVE_SHL_LOAD\"" >>configure.lua
echo "FONTCONFIG_LIBS=$FONTCONFIG_LIBS" >>Makefile.config
echo "mdefs[\"FONTCONFIG_LIBS\"] = \"$FONTCONFIG_LIBS\"" >>configure.lua
echo "HAVE_SNDFILE=$HAVE_SNDFILE" >>Makefile.config
echo "mdefs[\"HAVE_SNDFILE\"] = \"$HAVE_SNDFILE\"" >>configure.lua
echo "OPENGL_CFLAGS=$OPENGL_CFLAGS" >>Makefile.config
echo "mdefs[\"OPENGL_CFLAGS\"] = \"$OPENGL_CFLAGS\"" >>configure.lua
echo "HAVE_DB4=$HAVE_DB4" >>Makefile.config
echo "mdefs[\"HAVE_DB4\"] = \"$HAVE_DB4\"" >>configure.lua
echo "PTHREADS_XOPEN_CFLAGS=$PTHREADS_XOPEN_CFLAGS" >>Makefile.config
echo "mdefs[\"PTHREADS_XOPEN_CFLAGS\"] = \"$PTHREADS_XOPEN_CFLAGS\"" >>configure.lua
echo "HAVE_DLOPEN=$HAVE_DLOPEN" >>Makefile.config
echo "mdefs[\"HAVE_DLOPEN\"] = \"$HAVE_DLOPEN\"" >>configure.lua
echo "FREETYPE_LIBS=$FREETYPE_LIBS" >>Makefile.config
echo "mdefs[\"FREETYPE_LIBS\"] = \"$FREETYPE_LIBS\"" >>configure.lua
echo "HAVE_PTHREAD_MUTEX_RECURSIVE_NP=$HAVE_PTHREAD_MUTEX_RECURSIVE_NP" >>Makefile.config
echo "mdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"] = \"$HAVE_PTHREAD_MUTEX_RECURSIVE_NP\"" >>configure.lua
echo "HAVE_ALIGNED_ATTRIBUTE=$HAVE_ALIGNED_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_ALIGNED_ATTRIBUTE\"] = \"$HAVE_ALIGNED_ATTRIBUTE\"" >>configure.lua
echo "PTHREADS_LIBS=$PTHREADS_LIBS" >>Makefile.config
echo "mdefs[\"PTHREADS_LIBS\"] = \"$PTHREADS_LIBS\"" >>configure.lua
echo "RELEASE=$RELEASE" >>Makefile.config
echo "mdefs[\"RELEASE\"] = \"$RELEASE\"" >>configure.lua
echo "HAVE_CLOCK_WIN32=$HAVE_CLOCK_WIN32" >>Makefile.config
echo "mdefs[\"HAVE_CLOCK_WIN32\"] = \"$HAVE_CLOCK_WIN32\"" >>configure.lua
echo "PROG_GUI_FLAGS=$PROG_GUI_FLAGS" >>Makefile.config
echo "mdefs[\"PROG_GUI_FLAGS\"] = \"$PROG_GUI_FLAGS\"" >>configure.lua
echo "CFLAGS=$CFLAGS" >>Makefile.config
echo "mdefs[\"CFLAGS\"] = \"$CFLAGS\"" >>configure.lua
echo "JPEG_LIBS=$JPEG_LIBS" >>Makefile.config
echo "mdefs[\"JPEG_LIBS\"] = \"$JPEG_LIBS\"" >>configure.lua
echo "HAVE_MYSQL=$HAVE_MYSQL" >>Makefile.config
echo "mdefs[\"HAVE_MYSQL\"] = \"$HAVE_MYSQL\"" >>configure.lua
echo "SUBDIR_math=$SUBDIR_math" >>Makefile.config
echo "mdefs[\"SUBDIR_math\"] = \"$SUBDIR_math\"" >>configure.lua
echo "HAVE_LD_NO_UNDEFINED=$HAVE_LD_NO_UNDEFINED" >>Makefile.config
echo "mdefs[\"HAVE_LD_NO_UNDEFINED\"] = \"$HAVE_LD_NO_UNDEFINED\"" >>configure.lua
echo "OBJCFLAGS=$OBJCFLAGS" >>Makefile.config
echo "mdefs[\"OBJCFLAGS\"] = \"$OBJCFLAGS\"" >>configure.lua
echo "HAVE_XINERAMA=$HAVE_XINERAMA" >>Makefile.config
echo "mdefs[\"HAVE_XINERAMA\"] = \"$HAVE_XINERAMA\"" >>configure.lua
echo "FREETYPE_CFLAGS=$FREETYPE_CFLAGS" >>Makefile.config
echo "mdefs[\"FREETYPE_CFLAGS\"] = \"$FREETYPE_CFLAGS\"" >>configure.lua
echo "HAVE_INT64_T=$HAVE_INT64_T" >>Makefile.config
echo "mdefs[\"HAVE_INT64_T\"] = \"$HAVE_INT64_T\"" >>configure.lua
echo "DSO_CFLAGS=$DSO_CFLAGS" >>Makefile.config
echo "mdefs[\"DSO_CFLAGS\"] = \"$DSO_CFLAGS\"" >>configure.lua
echo "FONTCONFIG_CFLAGS=$FONTCONFIG_CFLAGS" >>Makefile.config
echo "mdefs[\"FONTCONFIG_CFLAGS\"] = \"$FONTCONFIG_CFLAGS\"" >>configure.lua
echo "PTHREADS_XOPEN_LIBS=$PTHREADS_XOPEN_LIBS" >>Makefile.config
echo "mdefs[\"PTHREADS_XOPEN_LIBS\"] = \"$PTHREADS_XOPEN_LIBS\"" >>configure.lua
echo "HAVE_MATH_C99=$HAVE_MATH_C99" >>Makefile.config
echo "mdefs[\"HAVE_MATH_C99\"] = \"$HAVE_MATH_C99\"" >>configure.lua
echo "HAVE_PACKED_ATTRIBUTE=$HAVE_PACKED_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_PACKED_ATTRIBUTE\"] = \"$HAVE_PACKED_ATTRIBUTE\"" >>configure.lua
echo "PNG_CFLAGS=$PNG_CFLAGS" >>Makefile.config
echo "mdefs[\"PNG_CFLAGS\"] = \"$PNG_CFLAGS\"" >>configure.lua
echo "MODULEDIR=$MODULEDIR" >>Makefile.config
echo "mdefs[\"MODULEDIR\"] = \"$MODULEDIR\"" >>configure.lua
echo "INCLDIR=$INCLDIR" >>Makefile.config
echo "mdefs[\"INCLDIR\"] = \"$INCLDIR\"" >>configure.lua
echo "HAVE_BOUNDED_ATTRIBUTE=$HAVE_BOUNDED_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_BOUNDED_ATTRIBUTE\"] = \"$HAVE_BOUNDED_ATTRIBUTE\"" >>configure.lua
echo "HAVE_GETTEXT=$HAVE_GETTEXT" >>Makefile.config
echo "mdefs[\"HAVE_GETTEXT\"] = \"$HAVE_GETTEXT\"" >>configure.lua
echo "CLOCK_CFLAGS=$CLOCK_CFLAGS" >>Makefile.config
echo "mdefs[\"CLOCK_CFLAGS\"] = \"$CLOCK_CFLAGS\"" >>configure.lua
echo "OPENGL_LIBS=$OPENGL_LIBS" >>Makefile.config
echo "mdefs[\"OPENGL_LIBS\"] = \"$OPENGL_LIBS\"" >>configure.lua
echo "VERSION=$VERSION" >>Makefile.config
echo "mdefs[\"VERSION\"] = \"$VERSION\"" >>configure.lua
echo "HAVE_PURE_ATTRIBUTE=$HAVE_PURE_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_PURE_ATTRIBUTE\"] = \"$HAVE_PURE_ATTRIBUTE\"" >>configure.lua
echo "SNDFILE_CFLAGS=$SNDFILE_CFLAGS" >>Makefile.config
echo "mdefs[\"SNDFILE_CFLAGS\"] = \"$SNDFILE_CFLAGS\"" >>configure.lua
echo "STATEDIR=$STATEDIR" >>Makefile.config
echo "mdefs[\"STATEDIR\"] = \"$STATEDIR\"" >>configure.lua
echo "HAVE_CLOCK_GETTIME=$HAVE_CLOCK_GETTIME" >>Makefile.config
echo "mdefs[\"HAVE_CLOCK_GETTIME\"] = \"$HAVE_CLOCK_GETTIME\"" >>configure.lua
echo "HAVE_FONTCONFIG=$HAVE_FONTCONFIG" >>Makefile.config
echo "mdefs[\"HAVE_FONTCONFIG\"] = \"$HAVE_FONTCONFIG\"" >>configure.lua
echo "JPEG_CFLAGS=$JPEG_CFLAGS" >>Makefile.config
echo "mdefs[\"JPEG_CFLAGS\"] = \"$JPEG_CFLAGS\"" >>configure.lua
echo "HAVE_SSE3=$HAVE_SSE3" >>Makefile.config
echo "mdefs[\"HAVE_SSE3\"] = \"$HAVE_SSE3\"" >>configure.lua
echo "WNO_UNINITIALIZED=$WNO_UNINITIALIZED" >>Makefile.config
echo "mdefs[\"WNO_UNINITIALIZED\"] = \"$WNO_UNINITIALIZED\"" >>configure.lua
echo "HAVE_NORETURN_ATTRIBUTE=$HAVE_NORETURN_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_NORETURN_ATTRIBUTE\"] = \"$HAVE_NORETURN_ATTRIBUTE\"" >>configure.lua
echo "_MK_HAVE_LIMITS_H=$_MK_HAVE_LIMITS_H" >>Makefile.config
echo "mdefs[\"_MK_HAVE_LIMITS_H\"] = \"$_MK_HAVE_LIMITS_H\"" >>configure.lua
echo "EXECSUFFIX=$EXECSUFFIX" >>Makefile.config
echo "mdefs[\"EXECSUFFIX\"] = \"$EXECSUFFIX\"" >>configure.lua
echo "HAVE_GLX=$HAVE_GLX" >>Makefile.config
echo "mdefs[\"HAVE_GLX\"] = \"$HAVE_GLX\"" >>configure.lua
echo "BINDIR=$BINDIR" >>Makefile.config
echo "mdefs[\"BINDIR\"] = \"$BINDIR\"" >>configure.lua
echo "PNG_LIBS=$PNG_LIBS" >>Makefile.config
echo "mdefs[\"PNG_LIBS\"] = \"$PNG_LIBS\"" >>configure.lua
echo "_MK_HAVE_STDLIB_H=$_MK_HAVE_STDLIB_H" >>Makefile.config
echo "mdefs[\"_MK_HAVE_STDLIB_H\"] = \"$_MK_HAVE_STDLIB_H\"" >>configure.lua
echo "DB4_CFLAGS=$DB4_CFLAGS" >>Makefile.config
echo "mdefs[\"DB4_CFLAGS\"] = \"$DB4_CFLAGS\"" >>configure.lua
echo "HAVE_PTHREAD_MUTEX_RECURSIVE=$HAVE_PTHREAD_MUTEX_RECURSIVE" >>Makefile.config
echo "mdefs[\"HAVE_PTHREAD_MUTEX_RECURSIVE\"] = \"$HAVE_PTHREAD_MUTEX_RECURSIVE\"" >>configure.lua
echo "HAVE_FORMAT_ATTRIBUTE=$HAVE_FORMAT_ATTRIBUTE" >>Makefile.config
echo "mdefs[\"HAVE_FORMAT_ATTRIBUTE\"] = \"$HAVE_FORMAT_ATTRIBUTE\"" >>configure.lua
echo "SUBDIR_vg=$SUBDIR_vg" >>Makefile.config
echo "mdefs[\"SUBDIR_vg\"] = \"$SUBDIR_vg\"" >>configure.lua
echo "XINERAMA_LIBS=$XINERAMA_LIBS" >>Makefile.config
echo "mdefs[\"XINERAMA_LIBS\"] = \"$XINERAMA_LIBS\"" >>configure.lua
echo "MATH_C99_CFLAGS=$MATH_C99_CFLAGS" >>Makefile.config
echo "mdefs[\"MATH_C99_CFLAGS\"] = \"$MATH_C99_CFLAGS\"" >>configure.lua
echo "HAVE_ICONV=$HAVE_ICONV" >>Makefile.config
echo "mdefs[\"HAVE_ICONV\"] = \"$HAVE_ICONV\"" >>configure.lua
echo "SSE2_CFLAGS=$SSE2_CFLAGS" >>Makefile.config
echo "mdefs[\"SSE2_CFLAGS\"] = \"$SSE2_CFLAGS\"" >>configure.lua
echo "_MK_HAVE_SYS_TYPES_H=$_MK_HAVE_SYS_TYPES_H" >>Makefile.config
echo "mdefs[\"_MK_HAVE_SYS_TYPES_H\"] = \"$_MK_HAVE_SYS_TYPES_H\"" >>configure.lua
echo "SRCS_GUI=$SRCS_GUI" >>Makefile.config
echo "mdefs[\"SRCS_GUI\"] = \"$SRCS_GUI\"" >>configure.lua
echo "HAVE_CYGWIN=$HAVE_CYGWIN" >>Makefile.config
echo "mdefs[\"HAVE_CYGWIN\"] = \"$HAVE_CYGWIN\"" >>configure.lua
echo "HAVE___INT64=$HAVE___INT64" >>Makefile.config
echo "mdefs[\"HAVE___INT64\"] = \"$HAVE___INT64\"" >>configure.lua
echo "MYSQL_CFLAGS=$MYSQL_CFLAGS" >>Makefile.config
echo "mdefs[\"MYSQL_CFLAGS\"] = \"$MYSQL_CFLAGS\"" >>configure.lua
echo "PTHREADS_CFLAGS=$PTHREADS_CFLAGS" >>Makefile.config
echo "mdefs[\"PTHREADS_CFLAGS\"] = \"$PTHREADS_CFLAGS\"" >>configure.lua
echo "COCOA_LIBS=$COCOA_LIBS" >>Makefile.config
echo "mdefs[\"COCOA_LIBS\"] = \"$COCOA_LIBS\"" >>configure.lua
if [ "${srcdir}" != "" ]; then
	$ECHO_N "* Source is in ${srcdir}. Generating Makefiles..."
	${PERL} ${SRC}/mk/mkconcurrent.pl ${SRC}
	if [ $? != 0 ]; then
		exit 1;
	fi
	echo "done"
fi
echo "*"
echo "* Configuration successful. Use \"make depend all\" to compile,"
echo "* and \"make install\" to install this software under $PREFIX."
echo "*"
