#!/bin/sh
#
# This file was generated by confgen.
# Do not edit.
#

PREFIX='/usr'
#EXECPREFIX='$PREFIX'
INSTALLROOT=''
BINMODE='755'
#DAEMONMODE='$BINMODE'
MANMODE='644'

while [ x$1 != x ]; do case $1 in

	--help)
	cat <<EOF
Usage: configure [options]
    --help                Show this message
    --debug               Enable debugging
    --prefix=path         Prefix for location of files [/usr]
    --exec-prefix=path    Location for arch-depedent files [prefix]
    --installroot=root    Top of filesystem tree to install in [/]
    --binmode=mode        Mode for binaries [755]
    --daemonmode=mode     Mode for daemon binaries [same as binmode]
    --manmode=mode        Mode for manual pages [644]
EOF
	exit 0;;
	--verbose) ;;
	--quiet) ;;

	--debug) DEBUG=1;;
	--prefix=*) PREFIX=`echo $1 | sed 's/--prefix=//'` ;;
	--exec-prefix=*) EXECPREFIX=`echo $1 | sed 's/--exec-prefix=//'` ;;
	--installroot=*) INSTALLROOT=`echo $1 | sed 's/--installroot=//'` ;;
	--binmode=*) BINMODE=`echo $1 | sed 's/--binmode=//'` ;;
	--daemonmode=*) DAEMONMODE=`echo $1 | sed 's/--daemonmode=//'` ;;
	--manmode=*) MANMODE=`echo $1 | sed 's/--manmode=//'` ;;
	*) echo "Unrecognized option: $1"; exit 1;;
esac 
shift
done

if [ x$EXECPREFIX = x ]; then 
	EXECPREFIX="$PREFIX"
fi

if [ x$DAEMONMODE = x ]; then 
	DAEMONMODE="$BINMODE"
fi

########################################################################

BINDIR="$EXECPREFIX/bin"
SBINDIR="$EXECPREFIX/sbin"
MANDIR="$PREFIX/man"

echo "Directories: $ROOTBINDIR $BINDIR $SBINDIR $MANDIR"
if [ x$INSTALLROOT != x ]; then
	echo "Installing in chroot tree rooted at $INSTALLROOT"
fi


########################################################################

CC=gcc
CFLAGS=
WARNINGS=
LDFLAGS=
LIBS=


echo -n "Checking for gcc..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "nope. Using cc."
	CC=cc
else
	echo "found"
fi


rm -f __conftest __conftest.c
echo -n "Checking that $CC works..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main(int argc, char *argv[]) {
    printf("Hello from %s\n", argv[0]);
    return argc;
}
EOF
$CC $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "nope, doesn't run."
	echo "Sorry."
	exit 1
fi
TEMP=`./__conftest 1 2 3`
if [ $? != 4 ]; then
	echo "nope, doesn't work."
	echo "Sorry."
	exit 1
fi
if [ "x$TEMP" != "xHello from ./__conftest" ]; then
	echo "nope, doesn't work."
	echo "Sorry."
	exit 1
fi
echo 'ok'


rm -f __conftest __conftest.c
########################################################################

echo -n "Checking if $CC accepts -Wall..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wall $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wall"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -W..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -W $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -W"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wpointer-arith..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wpointer-arith $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wpointer-arith"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wbad-function-cast..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wbad-function-cast $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wbad-function-cast"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wcast-qual..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wcast-qual $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wcast-qual"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wstrict-prototypes..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wstrict-prototypes $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wstrict-prototypes"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wmissing-prototypes..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wmissing-prototypes $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wmissing-prototypes"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wmissing-declarations..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wmissing-declarations $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wmissing-declarations"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wnested-externs..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wnested-externs $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wnested-externs"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Winline..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Winline $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Winline"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -Wcast-align..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -Wcast-align $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	WARNINGS="${WARNINGS} -Wcast-align"
fi


rm -f __conftest __conftest.c
########################################################################

echo -n "Checking if $CC accepts -pipe..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -pipe $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	CFLAGS="${CFLAGS} -pipe"
fi


rm -f __conftest __conftest.c
if [ x$DEBUG != x ]; then
echo -n "Checking if $CC accepts -g..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -g $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	CFLAGS="${CFLAGS} -g"
fi


rm -f __conftest __conftest.c
else
echo -n "Checking if $CC accepts -O2..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -O2 $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	CFLAGS="${CFLAGS} -O2"
fi


rm -f __conftest __conftest.c
echo -n "Checking if $CC accepts -s..."
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    printf("Hello\n");
    return 0;
}
EOF
$CC -s $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "no"
else
	echo "yes"
	LDFLAGS="${LDFLAGS} -s"
fi


rm -f __conftest __conftest.c
fi
########################################################################

NEED_BSD_SIGNAL=1
echo -n "Checking for BSD signal semantics..."
cat <<EOF >__conftest.c
#include <unistd.h>
#include <signal.h>
int count=0;
handle() { count++; }
int main() {
    int pid=getpid();
    signal(SIGINT, handle);
    kill(pid,SIGINT);
    kill(pid,SIGINT);
    kill(pid,SIGINT);
    if (count!=3) return 1;
    return 0;
}
EOF
$CC $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "nope"
	TEMP=0
else
	TEMP=1
fi
if [ $TEMP = 1 ]; then
  ./__conftest
  if [ $? != 0 ]; then
     TEMP=0; echo 'nope'
  else
     TEMP=1; echo 'got it'
fi;fi


rm -f __conftest __conftest.c
if [ $TEMP = 0 ]; then
echo -n "Checking if -D__USE_BSD_SIGNAL helps..."
cat <<EOF >__conftest.c
#include <unistd.h>
#include <signal.h>
int count=0;
handle() { count++; }
int main() {
    int pid=getpid();
    signal(SIGINT, handle);
    kill(pid,SIGINT);
    kill(pid,SIGINT);
    kill(pid,SIGINT);
    if (count!=3) return 1;
    return 0;
}
EOF
$CC -D__USE_BSD_SIGNAL $CFLAGS $WARNINGS $LIBS __conftest.c -o __conftest >/dev/null 2>&1
if [ $? != 0 ]; then
	echo "nope"
	TEMP=0
else
	TEMP=1
fi
if [ $TEMP = 1 ]; then
  ./__conftest
  if [ $? != 0 ]; then
     TEMP=0; echo 'nope'
  else
     TEMP=1; echo 'got it'
fi;fi


rm -f __conftest __conftest.c
if [ $TEMP = 0 ]; then
  echo 'Sorry.'
  exit 1
else
  CFLAGS="${CFLAGS} -D__USE_BSD_SIGNAL"
fi;fi


########################################################################

CFLAGS="${CFLAGS} "'$(WARNINGS)'
echo 'Generating MCONFIG...'
mv -f MCONFIG MCONFIG.old
echo -n '# Generated by configure on ' >MCONFIG
date >> MCONFIG
echo '#' >>MCONFIG
echo >>MCONFIG

echo "# Directory for user binaries" >>MCONFIG
echo "BINDIR=$BINDIR" >>MCONFIG
echo >>MCONFIG
echo "# Directory for man page tree" >>MCONFIG
echo "MANDIR=$MANDIR" >>MCONFIG
echo >>MCONFIG
echo "# Directory for system binaries" >>MCONFIG
echo "SBINDIR=$SBINDIR" >>MCONFIG
echo >>MCONFIG
echo "# Install into chroot area found here" >>MCONFIG
echo "INSTALLROOT=$INSTALLROOT" >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo "# Mode for user binaries" >>MCONFIG
echo "BINMODE=$BINMODE" >>MCONFIG
echo >>MCONFIG
echo "# Mode for daemon binaries" >>MCONFIG
echo "DAEMONMODE=$DAEMONMODE" >>MCONFIG
echo >>MCONFIG
echo "# Mode for manual pages" >>MCONFIG
echo "MANMODE=$MANMODE" >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo "# Compiler to use" >>MCONFIG
echo "CC=$CC" >>MCONFIG
echo >>MCONFIG
echo "# Compiler warnings" >>MCONFIG
echo "WARNINGS=$WARNINGS" >>MCONFIG
echo >>MCONFIG
echo "# Compiler flags to use" >>MCONFIG
echo "CFLAGS=$CFLAGS" >>MCONFIG
echo >>MCONFIG
echo "# Link-time flags to use" >>MCONFIG
echo "LDFLAGS=$LDFLAGS" >>MCONFIG
echo >>MCONFIG
echo "# Additional link libraries" >>MCONFIG
echo "LIBS=$LIBS" >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo >>MCONFIG
echo "# Tell confgen we need BSD signal semantics" >>MCONFIG
echo "NEED_BSD_SIGNAL=$NEED_BSD_SIGNAL" >>MCONFIG
echo >>MCONFIG


