#!/bin/sh
#
# This file is created by Kenneth 'Redhead' Nielsen <kn@redhead.dk>
# Do NOT edit it, or you can edit it, but then I wouldn't waugh for it's liabillety.
#
# This is _NOT_ a script created by autoconf or automake, it is hand made, and 
# I've put _many_ hours of work into it, in order to achieve possitive results 
# on all kinds of systems.
#
#
#
# $Id: configure,v 1.6 2003/07/28 17:47:51 redhead Exp $ 
#
#
# $Log: configure,v $
# Revision 1.6  2003/07/28 17:47:51  redhead
# Wanted to add a loging feature to configure.. Just trying to see if it
# works out.
#
#

QUIET=
LOG=
DOC="yes"
BOXES="yes"
FORCE_BOX="no"
IDIOT=

PREFIX=/usr/share/sigit
BINDIR=/usr/bin
ETCDIR=/etc
MANDIR=/usr/share/man
LOCATE_BOXES=
INSTALLROOT=''

BINMODE='555'
MANMODE='644'

INSTALL=
POD2MAN=
CC="$CC"
YACC=
LEXER=
AR=
CFLAGS="$CFLAGS"
DFLAGS=
PRELINK=
LINKFLAGS=
INCFLAGS=

ANSI_COMPILED=

host=NONE
target=NONE
build=NONE
nonopt=NONE

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

	--help)
	cat <<EOF
Usage: configure [options]
    --help                 Show this message
    --quiet                Sshh.. Be vewy vewy quiet, I'm hunting wabbits 
    --log                  Extra logging written to config.log
    --ansi-c               If you want the code compiled to conform with ANSI C
                            WARNING: be prepared for several warnings
    --idiot                Only use this flag, if you want the code to be 
                           extremly uptimized.
                            WARNING: use with caution, it might produce a non 
                                     functioning program. 
    --host=HOST            What host system type ie: i586-linux [guessed]
    --target=TARGET        What target system type ie: i586-linux [guessed]
    --build=BUILD          What build system type ie: i586-linux [guessed]
    --prefix=path          Prefix for location of files [$PREFIX]
    --bin-dir=path         Location for executable files [$BINDIR]
    --man-dir=path         Location for man archive [$MANDIR]
    --etc-dir=path         Location for common configuration [$ETCDIR]
    --install-root=root    Top of filesystem tree to install in [/]
    --bin-mode=mode        Mode for binaries [$BINMODE]
    --man-mode=mode        Mode for manual pages [$MANMODE]
    --with-boxes           If you want support for boxing feature [default]
                             (requires boxes installed)
    --with-boxes=/path     To enable and specify location of boxes 
    --force-boxes          If you're not sure the location of boxes is correct
                           the configure script will avoid searching for it, or
                           even try looking if the --with-boxes=/path should be wrong.
                              (Use with caution)
    --without-boxes        If you don't want support for boxing feature
    --with-c-compiler=CC   Program for compiling C source [guessed]
    --with-yacc=YACC       Program for creating parser usualy bison [guessed]
    --with-lexer=LEXER     Program for creating lexer usualy flex [guessed]
    --with-archive=AR      Program for creating archives usualy ar [guessed]
    --with-pod2man=pod     Program for making .pod files to man pages [guessed]
    --with-pthread=/where  Location of your libpthread.so, usualy in /usr/lib/ [guessed]
EOF
	exit 0;;
	--verbose) ;;
	--quiet) 
	    QUIET="yes"
	    LOG="yes" 
	    ;;
	--log) LOG="yes" ;;
	--ansi-c) ANSI_COMPILED="yes" ;;
	--idiot) IDIOT="yes" ;;
	--host=*) host=`echo $1 | sed 's/^[^=]*=//'` ;;
	--target=*) target=`echo $1 | sed 's/^[^=]*=//'` ;;
	--build=*) build=`echo $1 | sed 's/^[^=]*=//'` ;;
	--prefix=*) PREFIX=`echo $1 | sed 's/^[^=]*=//'` ;;
	--bin-dir=*) BINDIR=`echo $1 | sed 's/^[^=]*=//'` ;;
	--man-dir=*) MANDIR=`echo $1 | sed 's/^[^=]*=//'` ;;
	--etc-dir=*) ETCDIR=`echo $1 | sed 's/^[^=]*=//'` ;;
	--install-root=*) INSTALLROOT=`echo $1 | sed 's/^[^=]*=//'` ;;
	--bin-mode=*) BINMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
	--man-mode=*) MANMODE=`echo $1 | sed 's/^[^=]*=//'` ;;
	--with-c-compiler=*) CC=`echo $1 | sed 's/^[^=]*=//'` ;;
	--without-boxes) BOXES="no" ;;
	--with-boxes) BOXES="yes" ;;
	--with-boxes=*) 
	    LOCATE_BOXES=`echo $1 | sed 's/^[^=]*=//'` 
	    BOXES="yes" 
	    ;;
	--without-boxes) BOXES="no" ;;
	--force-boxes) FORCE_BOX="yes" ;;
	--with-yacc=*) YACC=`echo $1 | sed 's/^[^=]*=//'` ;;
	--with-lexer=*) LEXER=`echo $1 | sed 's/^[^=]*=//'` ;;
	--with-lexer=*) AR=`echo $1 | sed 's/^[^=]*=//'` ;;
	--with-pod2man=*) POD2MAN=`echo $1 | sed 's/^[^=]*=//'` ;;
	--with-pthread=*) PRELINK=`echo $1 | sed 's/^[^=]*=//'` ;;
	*) echo "Unrecognized option: $1"; exit 1;;
esac 
shift
done

# Check how echo works in this /bin/sh
case `echo -n` in
    -n)   echo_front=''      echo_end='\c'    ;;      # SysV echo
    *)    echo_front=-n      echo_end=''      ;;      # BSD echo
esac

WARNINGS='-Wall -Wpointer-arith -Wbad-function-cast -Wcast-qual -Wstrict-prototypes -Wnested-externs -Winline'

if [ "$QUIET" = "yes" ]; then
# File descriptor usage:
# 0 standard input
# 1 file creation
# 2 errors and warnings
# 3 some systems may open it to /dev/tty
# 4 used on the Kubota Titan
# 6 checking for... messages and results
# 5 compiler messages saved in config.log
    exec 6>/dev/null
else
    exec 6>&1
fi

if [ "$LOG" = "yes" ]; then
    exec 5>./config.log
    echo "Logfile for debugging: ./config.log" 1>&6
fi

if [ "$PREFIX" = "/usr/share/sigit" ]; then
    echo "Using default PREFIX setting... ok" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "Using default PREFIX setting at: $PREFIX" 1>&5
    fi
else
    echo "PREFIX setting is beeing changed... ok" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "PREFIX setting is beeing changed to... $PREFIX/sigit.data" 1>&5
    fi
    DFLAGS="$DFLAGS -D__DATA__FILE__=\\\"$PREFIX/sigit.data\\\""
fi


if [ "$ETCDIR" = "/etc" ]; then
    echo "Using default ETC setting... ok" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "Using default ETC setting at: $ETCDIR" 1>&5
    fi
else
    echo "ETC setting is beeing changed... ok" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "ETC setting is beeing changed to... $ETCDIR/sigit.rc" 1>&5
    fi
    DFLAGS="$DFLAGS -D__CONF__FILE__=\\\"$ETCDIR/sigit.rc\\\""
fi

if [ x"$INSTALLROOT" != x ]; then
    echo "Installing in chroot tree rooted at: $INSTALLROOT" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "Installing in chroot tree rooted at: $INSTALLROOT" 1>&5
    fi
fi

echo "Directories: $PREFIX $BINDIR $MANDIR $ETCDIR" 1>&6
if [ "$LOG" = "yes" ]; then
    echo "Directories: $PREFIX $BINDIR $MANDIR $ETCDIR" 1>&5
fi


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

# Do some error checking and defaulting for the host and target type.
# The inputs are:
#    configure --host=HOST --target=TARGET --build=BUILD 
#
# The rules are:
# 1. You are not allowed to specify --host, --target, and nonopt at the
#    same time.
# 2. Host defaults to nonopt.
# 3. If nonopt is not specified, then host defaults to the current host,
#    as determined by config.guess.
# 4. Target and build default to nonopt.
# 5. If nonopt is not specified, then target and build default to host.

# The aliases save the names the user supplied, while $host etc.
# will get canonicalized.


echo $echo_front "Checking host system type... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking host system type... $echo_end" 1>&5
fi

host_alias=$host
case "$host_alias" in
NONE)
  case $nonopt in
  NONE)
    if host_alias=`${CONFIG_SHELL-/bin/sh} scripts/config.guess`; then :
    else { 
	    echo "Failed" 1>&6
	    echo "error: can not guess host type, you must specify one" 1>&6 
	    if [ "$LOG" = "yes" ]; then
		echo "Failed" 1>&5
		echo "error: can not guess host type, you must specify one" 1>&5 
	    fi
	    exit 1; 
	}
    fi ;;
  *) host_alias=$nonopt ;;
  esac ;;
esac

host=`${CONFIG_SHELL-/bin/sh} scripts/config.sub $host_alias`
host_cpu=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
host_vendor=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
host_os=`echo $host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
echo "$host" 1>&6
if [ "$LOG" = "yes" ]; then
    echo "$host" 1>&5
fi

echo $echo_front "Checking target system type... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
   echo $echo_front "Checking target system type... $echo_end" 1>&5
fi

target_alias=$target

case "$target_alias" in
NONE)
  case $nonopt in
  NONE) target_alias=$host_alias ;;
  *) target_alias=$nonopt ;;
  esac ;;
esac

target=`${CONFIG_SHELL-/bin/sh} scripts/config.sub $target_alias`
target_cpu=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
target_vendor=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
target_os=`echo $target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
echo "$target" 1>&6
if [ "$LOG" = "yes" ]; then
    echo "$target" 1>&5
fi

echo $echo_front "Checking build system type... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking build system type... $echo_end" 1>&5
fi

build_alias=$build
case "$build_alias" in
NONE)
  case $nonopt in
  NONE) build_alias=$host_alias ;;
  *) build_alias=$nonopt ;;
  esac ;;
esac

build=`${CONFIG_SHELL-/bin/sh} scripts/config.sub $build_alias`
build_cpu=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
build_vendor=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
build_os=`echo $build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
echo "$build" 1>&6
if [ "$LOG" = "yes" ]; then
    echo "$build" 1>&5
fi


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

cat << EOF > __conftest.c
    int main() { int class=0; return class; }
EOF

if [ x"$CC" = x ]; then
    echo $echo_front "Looking for a C compiler... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Looking for a C compiler... $echo_end" 1>&5
    fi

    for TRY in gcc egcs g++ CC c++ cc; do
       (
           $TRY __conftest.c -o __conftest || exit 1;
           ./__conftest || exit 1;
       ) >/dev/null 2>&1 || continue;
       CC=$TRY
       break;
    done
    if [ x"'$CC'" = x ]; then
        echo "failed" 1>&6
        echo "Cannot find a C compiler. Run configure with --with-c-compiler." 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "failed" 1>&5
	    echo "Cannot find a C compiler. Run configure with --with-c-compiler." 1>&5
	fi
        rm -f __conftest*
        exit
    fi
    echo "$CC" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "$CC" 1>&5
    fi
fi


#################################################
######## INSTALL TESTER #########################
# Find a good install program.  We prefer a C program (faster),
# so one script is as good as another.  But avoid the broken or
# incompatible versions:
# SysV /etc/install, /usr/sbin/install
# SunOS /usr/etc/install
# IRIX /sbin/install
# AIX /bin/install
# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
# AFS /usr/afsws/bin/install, which mishandles nonexistent args
# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
# ./scripts/install.sh slow painfull, not supported on all systems
echo $echo_front "Looking for a BSD compatible install... $echo_end"  1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Looking for a BSD compatible install... $echo_end"  1>&5
fi
if test -z "$INSTALL"; then
    if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
	echo "(cached) $ac_c"  1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "(cached) $ac_c"  1>&5
	fi
    else
	IFS="${IFS=         }"; ac_save_IFS="$IFS"; IFS=":"
	for ac_dir in $PATH; do
    # Account for people who put trailing slashes in PATH elements.
	    case "$ac_dir/" in
		/|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) 
		    ;;
		*)
      # OSF1 and SCO ODT 3.0 have their own names for install.
      # Don't use installbsd from OSF since it installs stuff as root
      # by default.
		    for ac_prog in ginstall scoinst install; do
			if test -f $ac_dir/$ac_prog; then
			    if test $ac_prog = install &&
				grep dspmsg $ac_dir/$ac_prog >/dev/null 2>&1; then
            # AIX install.  It has an incompatible calling convention.
				:
			    else
				ac_cv_path_install="$ac_dir/$ac_prog -c"
				break 2
			    fi
			fi
		    done
		    ;;
	    esac
	done
	IFS="$ac_save_IFS"
	
    fi
    if test "${ac_cv_path_install+set}" = set; then
	INSTALL="$ac_cv_path_install"
    else
    # As a last resort, use the slow shell script.  We don't cache a
    # path for INSTALL within a source directory, because that will
    # break other packages using the cache if that directory is
    # removed, or if the path is relative.
	INSTALL="$PWD/scripts/install.sh"
    fi
fi
echo "$INSTALL"  1>&6
if [ "$LOG" = "yes" ]; then
    echo "$INSTALL"  1>&5
fi

######## pod2man TESTER #########################
# Find a good pod2man program.  We prefer a C program (faster),
# so one script is as good as another.  

if [ "$DOC" = "yes" ]; then
    if [ x"$POD2MAN" = x ]; then
	echo $echo_front "Looking for a pod2man program... $echo_end"  1>&6
	if [ "$LOG" = "yes" ]; then
	    echo $echo_front "Looking for a pod2man program... $echo_end"  1>&5
	fi
	if test -z "$POD2MAN"; then
	    if eval "test \"`echo '$''{'pod_cv_path_install'+set}'`\" = set"; then
		echo "(cached) $pod_c"  1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "(cached) $pod_c"  1>&5
		fi
	    else
		IFS="${IFS=         }"; pod_save_IFS="$IFS"; IFS=":"
		for pod_dir in $PATH; do
    # Account for people who put trailing slashes in PATH elements.
		    case "$pod_dir/" in
			/|./|.//|/etc/*|/usr/sbin/*|/usr/etc/*|/sbin/*|/usr/afsws/bin/*|/usr/ucb/*) 
			    ;;
			*)
			    for pod_prog in pod2man; do
				if test -f $pod_dir/$pod_prog; then
				    pod_cv_path_install="$pod_dir/$pod_prog"
				    break 2
				fi
			    done
			    ;;
		    esac
		done		
		IFS="$pod_save_IFS"
	    fi	    
	    if test "${pod_cv_path_install+set}" = set; then
		POD2MAN="$pod_cv_path_install"
	    else
		# ARGH, theres no pod2man found. Damned...
		echo ":WARNING:" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "Failed"  1>&5
		fi
		echo "" 1>&6
		echo ",-----------------------------------------------------------------." 1>&6
		echo "| The pod2man program is needed in order to create documentation. |" 1>&6
		echo "| Since there wasn't found any pod2man program on your system the |" 1>&6
		echo "| documentation won't be created.                                 |" 1>&6
		echo "|                                                                 |" 1>&6
		echo "| Should you be interrested in having the documentation created,  |" 1>&6
		echo "| please specify the pod2man program to use by running:           |" 1>&6
		echo "|       ./configure --with-pod2man=/location/of/pod2man           |" 1>&6
		echo "'-----------------------------------------------------------------'" 1>&6
		echo "" 1>&6
		DOC="no"
	    fi
	fi
	echo "$POD2MAN" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "$POD2MAN" 1>&5
	fi
    fi
fi
###################################################

if [ x"$YACC" = x ]; then
#  Looking for a yacc on the system.
    echo $echo_front "Looking for a compiler compiler... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Looking for a compiler compiler... $echo_end" 1>&5
    fi
    YACC=/usr/bin/bison
    echo "$YACC" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "$YACC" 1>&5
    fi  
fi
if [ x"$LEXER" = x ]; then
#  Looking for a lexer on the system.
    echo $echo_front "Looking for a lexical analyzer... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Looking for a lexical analyzer... $echo_end" 1>&5
    fi
    LEXER=/usr/bin/flex
    echo "$LEXER" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "$LEXER" 1>&5
    fi  
fi
if [ x"$AR" = x ]; then
#  Looking for a yacc on the system.
    echo $echo_front "Looking for a archive creator... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Looking for a archive creator ... $echo_end" 1>&5
    fi
    AR=/usr/bin/ar
    echo "$AR" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "$AR" 1>&5
    fi  
fi

# Find our boxes for support.
# Locate boxes, if they just want it, and havn't given a location
# If they give a location, trust it blindly, else alert that something's wrong.

if [ x"$BOXES" = x"yes" ]; then
    echo $echo_front "Looking for boxes... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Looking for boxes... $echo_end" 1>&5
    fi
    if [ x"$LOCATE_BOXES" = x ]; then
	# Locate it yourself, look in the varius /bin /usr/bin /usr/local/bin /sbin /usr/sbin /usr/local/sbin
	for location in /bin /usr/bin /usr/local/bin /sbin /usr/sbin /usr/local/sbin; do
	    if [ -x $location/boxes ]; then
		LOCATE_BOXES=$location/boxes
		break;
	    fi
	done
    fi
    if [ x$FORCE_BOX = x"no" ]; then
	if [ x$LOCATE_BOXES != x ]; then
	    if [ -x $LOCATE_BOXES/boxes ]; then
		echo "$LOCATE_BOXES/boxes" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "$LOCATE_BOXES/boxes" 1>&5
		fi
		LOCATE_BOXES=$LOCATE_BOXES/boxes
	    elif [ -x $LOCATE_BOXES ]; then
		echo "$LOCATE_BOXES" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "$LOCATE_BOXES" 1>&5
		fi
	    else
		echo ":ERROR:" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "Failed" 1>&5
		fi
		echo "" 1>&6
		echo "#################################################################" 1>&6
		echo " Couldn't locate boxes in the given [$LOCATE_BOXES]" 1>&6
		echo " Assuming that there is no working boxes, could this be due to   " 1>&6
		echo " the execution bit not beeing set on boxes ??                    " 1>&6
		echo " For now I will not compile with boxes support, if you wish to   " 1>&6
		echo " maintain boxes support and don't care about this warning, please" 1>&6
		echo " configure it with --force-boxes and the --with-boxes=/path/boxes" 1>&6
		echo " in order to don't pay attention to any working boxes." 1>&6
		echo "#################################################################" 1>&6
		echo "" 1>&6
		BOXES="no"
	    fi
	else
        # Danger no boxes location found.. We will alert here.
	    echo ":WARNING:" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "Failed"  1>&5
	    fi
	    echo "" 1>&6
	    echo ",-----------------------------------------------------------------." 1>&6
	    echo "| Could not locate any boxes program in any of the varius places: |" 1>&6
	    echo "|  /bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin   |" 1>&6
	    echo "|                                                                 |" 1>&6
	    echo "| Should you be interrested in having boxes support, please give  |" 1>&6
	    echo "| the location of the boxes program along with the --with-boxes   |" 1>&6
	    echo "| ie:         ./configure --with-boxes=/my/bin/boxes              |" 1>&6
	    echo "|         For now I asume you didn't want boxes support.          |" 1>&6
	    echo "'-----------------------------------------------------------------'" 1>&6
	    echo "" 1>&6
	    BOXES="no"
	fi
    else
	# screw everything lets enable boxes anyway.
	if [ x$LOCATE_BOXES != x ]; then
	    if [ -x $LOCATE_BOXES/boxes ]; then
		LOCATE_BOXES=$LOCATE_BOXES/boxes
	    fi
	fi
	echo ":WARNING:" 1>&6
	echo "" 1>&6
	echo "################################################################" 1>&6
	echo "  Boxes is assumed working as [$LOCATE_BOXES]" 1>&6
	echo "    This is beeing compiled in without any further checking.  " 1>&6
	echo "  Sorry, if the program will stop working, but hey you wanted it" 1>&6
	echo "  this way, so deal with it." 1>&6
	echo "################################################################" 1>&6
	echo "" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "Using boxes with no reference"  1>&5
	fi
    fi
fi


######################################################
echo $echo_front "Looking for a Linux /proc filesystem... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo "Looking for a Linux /proc filesystem... " 1>&5
    echo "More specificaly if theres a /proc/uptime file." 1>&5
fi

if [ -f /proc/uptime ]; then
    DFLAGS="$DFLAGS -DI__HAVE__PROC"
    echo "/proc/uptime" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "/proc/uptime"  1>&5
    fi
else
    echo "non found" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "non found"  1>&5
    fi
fi


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

echo $echo_front "Looking for a Linux /dev filesystem... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo "Looking for a Linux /dev filesystem... " 1>&5
    echo "More specificaly if theres a /dev/random file." 1>&5
fi

if [ -c /dev/random ]; then
    DFLAGS="$DFLAGS -DI__HAVE__DEV"
    echo "/dev/random" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "/dev/random"  1>&5
    fi
else
    echo "non found" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "non found"  1>&5
    fi
fi


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

echo $echo_front "Checking if $CC compiler works... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking if $CC compiler works... $echo_end" 1>&5
fi
if (
	$CC __conftest.c -o __conftest || exit 1
	./__conftest || exit 1
    ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    echo "no" 1>&6
    echo "Compiler \"$CC\" does not exist or cannot compile C; try another." 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "no" 1>&5
	echo "Compiler \"$CC\" does not exist or cannot compile C; try another." 1>&5
    fi

    rm -f __conftest*
    exit
fi

# if we use this test, then it gotta be a lunatic.

if [ x"$IDIOT" != x ]; then
    CFLAGS="-O4 -fforce-mem -fforce-addr -finline-functions -fkeep-inline-functions -ffast-math -fstrength-reduce -fthread-jumps -fcse-follow-jumps -fcse-skip-blocks -frerun-cse-after-loop -frerun-loop-opt -fexpensive-optimizations -fschedule-insns2 -fcaller-saves -funroll-loops -fmove-all-movables -fomit-frame-pointer"
    echo $echo_front "Checking if $CC accepts gcc warnings... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "Checking if $CC accepts gcc warnings... " 1>&5
	echo "Warning flags beeing tested are: $WARNINGS" 1>&5
    fi
    if (
		$CC $WARNINGS __conftest.c -o __conftest || exit 1
	) >/dev/null 2>&1; then
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
	CC_WARNINGS=1
    else
	echo "no" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	fi
    fi
    echo $echo_front "Checking if $CC accepts idiotic optimization flags... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "Checking if $CC accepts idiotic optimization flags... " 1>&5
	echo "Flags beeing tested: $CFLAGS" 1>&5
    fi
    if (
		$CC $CFLAGS __conftest.c -o __conftest || exit 1
	) >/dev/null 2>&1; then
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
    else
	echo "no" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	fi
    fi
    echo $echo_front "Checking if $CC accepts -march=$target_cpu... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Checking if $CC accepts -march=$target_cpu... $echo_end" 1>&5
    fi
    if (
	    $CC -march=$target_cpu __conftest.c -o __conftest || exit 1
	) >/dev/null 2>&1; then
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
	CFLAGS="$CFLAGS -march=$target_cpu"
    else
	echo "no" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	fi
    fi
fi 

# test for the ordinary flags.

if [ x"$CFLAGS" = x ]; then
    echo $echo_front "Checking if $CC accepts gcc warnings... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "Checking if $CC accepts gcc warnings... " 1>&5
	echo "Warning flags beeing tested are: $WARNINGS" 1>&5
    fi
    if (
		$CC $WARNINGS __conftest.c -o __conftest || exit 1
	) >/dev/null 2>&1; then
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
	CC_WARNINGS=1
    else
	echo "no" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	fi
    fi
    
    echo $echo_front "Checking if $CC accepts -O3... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Checking if $CC accepts -O3... $echo_end" 1>&5
    fi
    if (
	    $CC -O3 __conftest.c -o __conftest
	) >/dev/null 2>&1; then
	    echo "yes" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "yes" 1>&5
	    fi
	    CFLAGS="$CFLAGS -O3"
    else
	echo "no" 1>&6
	echo $echo_front "Checking if $CC accepts -O... $echo_end" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	    echo $echo_front "Checking if $CC accepts -O... $echo_end" 1>&5
	fi
	if (
		$CC -O __conftest.c -o __conftest
	    ) >/dev/null 2>&1; then
	    echo "yes" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "yes" 1>&5
	    fi
	    CFLAGS="$CFLAGS -O"
	else
	    echo "no" 1>&6
	    echo $echo_front "Checking if $CC accepts -g... $echo_end" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "no" 1>&5
		echo $echo_front "Checking if $CC accepts -g... $echo_end" 1>&5
	    fi
	    if (
		    $CC -g __conftest.c -o __conftest
		    ) >/dev/null 2>&1; then
		echo "yes" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "yes" 1>&5
		fi
		CFLAGS="$CFLAGS -g"
	    else
		echo "no" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "no" 1>&5
		fi
	    fi
	fi
    fi
    echo $echo_front "Checking if $CC accepts -march=$target_cpu... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Checking if $CC accepts -march=$target_cpu... $echo_end" 1>&5
    fi
    if (
		$CC -march=$target_cpu __conftest.c -o __conftest || exit 1
	) >/dev/null 2>&1; then
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
	CFLAGS="$CFLAGS -march=$target_cpu"
    else
	echo "no" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	fi
    fi
fi
rm -f __conftest*

#################### Test if the parsed $CFLAGS is in -ansi expectancy #######

echo $echo_front "Checking if -ansi flag is in \$CFLAGS... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking if -ansi flag is in \$CFLAGS... $echo_end" 1>&5
fi
IBBI=`echo "$CFLAGS" | grep -- -ansi`
RETVAL="$?"
if [ "$RETVAL" -eq 0 ]; then
    ANSI_COMPILED="yes"
    DFLAGS="$DFLAGS -D__ANSI__COMPILED__ -D__NO__ALLOCA__USED__=malloc"
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    if [ x"$ANSI_COMPILED" != x ]; then
	DFLAGS="$DFLAGS -D__ANSI__COMPILED__ -D__NO__ALLOCA__USED__=malloc"
	CFLAGS="$CFLAGS -ansi"
    fi
    echo "no" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "no" 1>&5
    fi
fi

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

echo $echo_front "Checking if build environment is sane... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking if build environment is sane... $echo_end" 1>&5
fi

# Just in case
sleep 1
echo timestamp > __conftestfile
# Do `set' in a subshell so we don't clobber the current shell's
# arguments.  Must try -L first in case configure is actually a
# symlink; some systems play weird games with the mod time of symlinks
# (eg FreeBSD returns the mod time of the symlink's containing
# directory).
if (
	set X `ls -Lt configure __conftestfile 2> /dev/null`
	if test "$*" = "X"; then
      # -L didn't work.
	    set X `ls -t configure __conftestfile`
	fi
	if test "$*" != "X configure __conftestfile" \
	    && test "$*" != "X __conftestfile configure"; then
	    
      # If neither matched, then we have a broken ls.  This can happen
      # if, for instance, CONFIG_SHELL is bash and it inherits a
      # broken ls alias from the environment.  This has actually
      # happened.  Such a system could not be considered "sane".
	    {
		echo "no" 1>&6
		echo "ls -t appears to fail.  Make sure there is not a broken alias in your environment" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "no" 1>&5
		    echo "ls -t appears to fail.  Make sure there is not a broken alias in your environment" 1>&5
		fi
		rm -f __conftest*
		exit 1; 
	    }
	fi	
	test "$2" = __conftestfile
    )
    then
   # Ok.
    :
else
   {
       echo "no" 1>&6
       echo "newly created file is older than distributed files! Check your system clock" 1>&6
       if [ "$LOG" = "yes" ]; then
	   echo "no" 1>&5
	   echo "newly created file is older than distributed files! Check your system clock" 1>&5
       fi
       rm -f __conftest*
       exit 1; 
   }
fi
rm -f __conftest*
echo "yes" 1>&6

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

echo $echo_front "Checking if ${MAKE-make} sets \${MAKE}... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking if ${MAKE-make} sets \${MAKE}... $echo_end" 1>&5
fi

set dummy ${MAKE-make}; ac_make=`echo "$2" | sed 'y%./+-%__p_%'`
if eval "test \"`echo '$''{'ac_cv_prog_make_${ac_make}_set'+set}'`\" = set"; then
    echo "(cached) $ac_c" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "(cache) $ac_c" 1>&5
    fi
else
    cat > __conftestmake <<\EOF
all:
	@echo 'ac_maketemp="${MAKE}"'
EOF
    
# GNU make sometimes prints "make[1]: Entering...", which would confuse us.
    eval `${MAKE-make} -f __conftestmake 2>/dev/null | grep temp=`
    if test -n "$ac_maketemp"; then
	eval ac_cv_prog_make_${ac_make}_set=yes
    else
	eval ac_cv_prog_make_${ac_make}_set=no
    fi
    rm -f __conftest*
fi
if eval "test \"`echo '$ac_cv_prog_make_'${ac_make}_set`\" = yes"; then
    echo "yes" 1>&6
  if [ "$LOG" = "yes" ]; then
      echo "yes" 1>&5
  fi
  SET_MAKE=
else
  echo "no" 1>&6
  if [ "$LOG" = "yes" ]; then
      echo "no" 1>&5
  fi
  SET_MAKE="MAKE=${MAKE-make}"
fi
rm -f __conftest*

##################################################
    
echo $echo_front "Checking for BSD signal semantics... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for BSD signal semantics... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
int count=0;
void handle(int foo) { count++; }
int main() {
    int pid=getpid();
    signal(SIGINT, handle);
    kill(pid,SIGINT);
    if (count == 0) return 1;
    return 0;
}

EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
      ./__conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    if (
          $CC -D__USE_BSD_SIGNAL __conftest.c  -o __conftest || exit 1
          ./__conftest || exit 1
       ) >/dev/null 2>&1; then
        echo "-D__USE_BSD_SIGNAL" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "-D__USE_BSD_SIGNAL" 1>&5
	fi
        DFLAGS="$DFLAGS -D__USE_BSD_SIGNAL"
    else
        echo "no" 1>&6
	echo "This package needs BSD signal semantics to run." 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	    echo "This package needs BSD signal semantics to run." 1>&5
	fi
        rm -f __conftest*
	exit 
    fi
fi
rm -f __conftest*

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

echo $echo_front "Checking for GNU getopt support... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for GNU getopt support... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <getopt.h>
int main (int argc, char **argv) {
           int c;
           int digit_optind = 0;

           static struct option long_options[] = {
                   {"add", 1, 0, 0},
                   {"append", 0, 0, 0},
                   {"delete", 1, 0, 0},
                   {"verbose", 0, 0, 0},
                   {"create", 1, 0, 'c'},
                   {"file", 1, 0, 0},
                   {0, 0, 0, 0}
           };

           while (1) {
               int this_option_optind = optind ? optind : 1;
               int option_index = 0;
               c = getopt_long (argc, argv, "ab",
                        long_options, &option_index);
               if (c == -1)
                   break;

               switch (c) {
               case 0:
                   break;
               case 'a':
                   break;

               case 'b':
                   break;

               default:
                   break;

              }
           }

         return 0;
 }

EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
      ./__conftest || exit 1
   ) >/dev/null 2>&1; then
        DFLAGS="$DFLAGS -DI__HAVE__GETOPT_LONG"
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    if (
	    $CC -D_GNU_SOURCE __conftest.c  -o __conftest || exit 1
	    ./__conftest || exit 1
	) >/dev/null 2>&1; then
	echo "-D_GNU_SOURCE" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "-D_GNU_SOURCE" 1>&5
	fi
	DFLAGS="$DFLAGS -D_GNU_SOURCE -DI__HAVE__GETOPT_LONG"
    else
	echo "no" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "no" 1>&5
	fi
    fi
fi
rm -f __conftest*

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

echo $echo_front "Checking for POSIX threads... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for POSIX threads... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
//#include <unistd.h>
#include <pthread.h>
int count=0;
void *handle() { count++;}
int main() {
  pthread_t thread;
  pthread_create(&thread, NULL, handle, NULL);
  return 0;
}
EOF

if [ x"$PRELINK" = x ]; then
    if (
	    $CC -lpthread __conftest.c  -o __conftest || exit 1
	    ./__conftest || exit 1
	) >/dev/null 2>&1; then
	LINKFLAGS="$LINKFLAGS -lpthread"
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
    else
	if (
		$CC -D_REENTRANT -lpthread __conftest.c  -o __conftest || exit 1
		./__conftest || exit 1
	    ) >/dev/null 2>&1; then
	    echo "-D_REENTRANT" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "-D_REENTRANT" 1>&5
	    fi
	    DFLAGS="$DFLAGS -D_REENTRANT"
	    LINKFLAGS="$LINKFLAGS -lpthread"
	else
	    if (
		    $CC -D_REENTRANT -D_THREAD_SAFE -lpthreads __conftest.c  -o __conftest || exit 1
		    ./__conftest || exit 1
		) >/dev/null 2>&1; then
		echo "-D_REENTRANT -D_THREAD_SAFE" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "-D_REENTRANT -D_THREAD_SAFE" 1>&5
		fi
		DFLAGS="$DFLAGS -D_REENTRANT -D_THREAD_SAFE"
		LINKFLAGS="$LINKFLAGS -lpthreads"
	    else
		if (
			$CC -D_GNU_SOURCE -lpthread __conftest.c  -o __conftest || exit 1		    
			./__conftest || exit 1
		    ) >/dev/null 2>&1; then
		    echo "-D_GNU_SOURCE" 1>&6
		    if [ "$LOG" = "yes" ]; then
			echo "-D_GNU_SOURCE" 1>&5
		    fi
		    DFLAGS="$DFLAGS -D_GNU_SOURCE"
		    LINKFLAGS="$LINKFLAGS -lpthread"
		else
		    if (
			    $CC -D_GNU_SOURCE -D_REENTRANT -lpthread __conftest.c  -o __conftest || exit 1
			    ./__conftest || exit 1
			) >/dev/null 2>&1; then
			echo "-D_REENTRANT" 1>&6
			if [ "$LOG" = "yes" ]; then
			    echo "-D_REENTRANT" 1>&5
			fi
			DFLAGS="$DFLAGS -D_REENTRANT -D_GNU_SOURCE"
			LINKFLAGS="$LINKFLAGS -lpthread"
		    else    
			if (
				$CC -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -lpthreads __conftest.c  -o __conftest || exit 1
				./__conftest || exit 1
			    ) >/dev/null 2>&1; then
			    echo "-D_REENTRANT -D_THREAD_SAFE" 1>&6
			    if [ "$LOG" = "yes" ]; then
				echo "-D_REENTRANT -D_THREAD_SAFE" 1>&5
			    fi
			    DFLAGS="$DFLAGS -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE"
			    LINKFLAGS="$LINKFLAGS -lpthreads"
			else	    
			    if (
				    $CC -D_GNU_SOURCE -lpthread -L/usr/local/lib/pth __conftest.c  -o __conftest || exit 1		    
				    ./__conftest || exit 1
				) >/dev/null 2>&1; then
				echo "-L/usr/local/lib/pth" 1>&6
				if [ "$LOG" = "yes" ]; then
				    echo "-L/usr/local/lib/pth" 1>&5
				fi
				DFLAGS="$DFLAGS -D_GNU_SOURCE"
				LINKFLAGS="$LINKFLAGS -lpthread -L/usr/local/lib/pth"
			    else
				if (
					$CC -D_GNU_SOURCE -D_REENTRANT -lpthread -L/usr/local/lib/pth __conftest.c  -o __conftest || exit 1
					./__conftest || exit 1
				    ) >/dev/null 2>&1; then
				    echo "-L/usr/local/lib/pth" 1>&6
				    if [ "$LOG" = "yes" ]; then
					echo "-L/usr/local/lib/pth" 1>&5
				    fi
				    DFLAGS="$DFLAGS -D_REENTRANT -D_GNU_SOURCE"
				    LINKFLAGS="$LINKFLAGS -lpthread -L/usr/local/lib/pth"
				else    
				    if (
					    $CC -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -lpthreads -L/usr/local/lib/pth __conftest.c  -o __conftest || exit 1
					    ./__conftest || exit 1
					) >/dev/null 2>&1; then
					echo "-L/usr/local/lib/pth" 1>&6
					if [ "$LOG" = "yes" ]; then
					    echo "-L/usr/local/lib/pth" 1>&5
					fi
					DFLAGS="$DFLAGS -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE"
					LINKFLAGS="$LINKFLAGS -lpthreads -L/usr/local/lib/pth"
				    else    
					echo "FAILURE" 1>&6
					echo "" 1>&6
					echo ",---------------------------------------------------------------." 1>&6
					echo "| This program needs pthread in order to run, if you havn't got |" 1>&6
					echo "| pthread installed, it can _NOT_ compile. Should it be located |" 1>&6
					echo "| else where than the locations allready tried, please tell the |" 1>&6
					echo "| configure script where to find it ie:                         |" 1>&6
					echo "|                                                               |" 1>&6
					echo "| ./configure --with-pthread=/dir/of/libpthread.so              |" 1>&6
					echo "'------------------------------------------------------------ --'" 1>&6
					echo "" 1>&6
				    fi
				    rm -f __conftest*
				    exit
				fi		    
			    fi
			fi
		    fi
		fi
	    fi
	fi
    fi
else
    if (
	    $CC -lpthread -L$PRELINK __conftest.c  -o __conftest || exit 1
	    ./__conftest || exit 1
	) >/dev/null 2>&1; then
	LINKFLAGS="$LINKFLAGS -lpthread -L$PRELINK"
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
    else
	if (
		$CC -D_REENTRANT -lpthread  -L$PRELINK __conftest.c  -o __conftest || exit 1
		./__conftest || exit 1
	    ) >/dev/null 2>&1; then
	    echo "-D_REENTRANT" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "-D_REENTRANT" 1>&5
	    fi
	    DFLAGS="$DFLAGS -D_REENTRANT"
	    LINKFLAGS="$LINKFLAGS -lpthread -L$PRELINK"
	else
	    if (
		    $CC -D_REENTRANT -D_THREAD_SAFE -lpthreads -L$PRELINK __conftest.c  -o __conftest || exit 1
		    ./__conftest || exit 1
		) >/dev/null 2>&1; then
		echo "-D_REENTRANT -D_THREAD_SAFE" 1>&6
		if [ "$LOG" = "yes" ]; then
		    echo "-D_REENTRANT -D_THREAD_SAFE" 1>&5
		fi
		DFLAGS="$DFLAGS -D_REENTRANT -D_THREAD_SAFE"
		LINKFLAGS="$LINKFLAGS -lpthreads -L$PRELINK"
	    else
		if (
			$CC -D_GNU_SOURCE -lpthread -L$PRELINK __conftest.c  -o __conftest || exit 1		    
			./__conftest || exit 1
		    ) >/dev/null 2>&1; then
		    echo "-D_GNU_SOURCE" 1>&6
		    if [ "$LOG" = "yes" ]; then
			echo "-D_GNU_SOURCE" 1>&5
		    fi
		    DFLAGS="$DFLAGS -D_GNU_SOURCE"
		    LINKFLAGS="$LINKFLAGS -lpthread -L$PRELINK"
		else
		    if (
			    $CC -D_GNU_SOURCE -D_REENTRANT -lpthread -L$PRELINK __conftest.c  -o __conftest || exit 1
			    ./__conftest || exit 1
			) >/dev/null 2>&1; then
			echo "-D_REENTRANT" 1>&6
			if [ "$LOG" = "yes" ]; then
			    echo "-D_REENTRANT" 1>&5
			fi
			DFLAGS="$DFLAGS -D_REENTRANT -D_GNU_SOURCE"
			LINKFLAGS="$LINKFLAGS -lpthread -L$PRELINK"
		    else    
			if (
				$CC -D_GNU_SOURCE -D_REENTRANT -D_THREAD_SAFE -lpthreads -L$PRELINK __conftest.c  -o __conftest || exit 1
				./__conftest || exit 1
			    ) >/dev/null 2>&1; then
			    echo "-D_REENTRANT -D_THREAD_SAFE" 1>&6
			    if [ "$LOG" = "yes" ]; then
				echo "-D_REENTRANT -D_THREAD_SAFE" 1>&5
			    fi
			    DFLAGS="$DFLAGS -D_REENTRANT -D_THREAD_SAFE -D_GNU_SOURCE"
			    LINKFLAGS="$LINKFLAGS -lpthreads -L$PRELINK"
			else    
			    echo "FAILURE" 1>&6
			    echo "" 1>&6
			    echo ",-------------------------------------------------------------." 1>&6
			    echo "| The test wasn't able to prove, that your given location of  |" 1>&6
			    echo "| libpthread.so is valid for compiling the program, are you   |" 1>&6
			    echo "| sure the argument to --with-pthread is the directory, not   |" 1>&6
			    echo "| actual libpthread.so file. If your libpthread is located in |" 1>&6
			    echo "| /usr/lib/pthreads, then the configure command should be:    |" 1>&6
			    echo "|                                                             |" 1>&6
			    echo "| ./configure --with-pthread=/usr/lib/pthreads                |" 1>&6
			    echo "'-------------------------------------------------------------'" 1>&6
			    echo "" 1>&6

			fi
			rm -f __conftest*
			exit
		    fi		    
		fi
	    fi
	fi
    fi
fi
rm -f __conftest*

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

echo $echo_front "Checking for zlib support... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for zlib support... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <zlib.h>
int counter;
void handler(){counter++;}
int main(){
  gzFile fil =  gzopen("", "rb");
  return 0;
}

EOF
if (
      $CC -lz __conftest.c  -o __conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
    LINKFLAGS="$LINKFLAGS -lz"
else
    if (
          $CC -D_GNU_SOURCE -lz __conftest.c  -o __conftest || exit 1
          ./__conftest || exit 1
       ) >/dev/null 2>&1; then
        echo "-D_GNU_SOURCE" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "-D_GNU_SOURCE" 1>&5
	fi
        DFLAGS="$DFLAGS -D_GNU_SOURCE"
        LINKFLAGS="$LINKFLAGS -lz"
    else
	if (
		$CC -D_GNU_SOURCE -lz -lm __conftest.c  -o __conftest || exit 1
		./__conftest || exit 1
	    ) >/dev/null 2>&1; then
	    echo "-lm" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "-lm" 1>&5
	    fi
	    DFLAGS="$DFLAGS -D_GNU_SOURCE"
	    LINKFLAGS="$LINKFLAGS -lz -lm"
	else
	    echo "no" 1>&6
	    echo "This package needs zlib support to run." 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "no" 1>&5
		echo "This package needs zlib support to run." 1>&5
	    fi
	    rm -f __conftest*
	    exit
	fi
    fi
fi
rm -f __conftest*


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

echo $echo_front "Checking for snprintf declaration... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for snprintf declaration... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <stdio.h>
int main() {
    void *x = (void *)snprintf;
    printf("%lx", (long)x);
    return 0;
}

EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    if (
          $CC -D_GNU_SOURCE __conftest.c  -o __conftest || exit 1
          ./__conftest || exit 1
       ) >/dev/null 2>&1; then
        echo "-D_GNU_SOURCE" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "-D_GNU_SOURCE" 1>&5
	fi
	DFLAGS="$DFLAGS -D_GNU_SOURCE"
    else
	DFLAGS="$DFLAGS -DMANUAL__DEFINE__SNPRINTF"
        echo "manual" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "manual" 1>&5
	fi
    fi
fi
rm -f __conftest*

echo $echo_front "Checking for snprintf implementation... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for snprintf implementation... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <stdio.h>
#include <string.h>
#ifdef DECLARE_SNPRINTF
#ifdef __cplusplus
extern "C"
#endif /*__cplusplus*/
int snprintf(char *, int, const char *, ...);
#endif /*DECLARE_SNPRINTF*/
int main() {
    char buf[32];
    snprintf(buf, 8, "%s", "1234567890");
    if (strlen(buf)!=7) return 1;
    return 0;
}

EOF
if (
      $CC __conftest.c $LIBBSD -o __conftest || exit 1
      ./__conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
    DFLAGS="$DFLAGS -DI__HAVE__SNPRINTF"
else
    if (
          $CC __conftest.c -lsnprintf $LIBBSD -o __conftest || exit 1
          ./__conftest || exit 1
       ) >/dev/null 2>&1; then
        echo "-lsnprintf" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "-lsnprintf" 1>&5
	fi
	DFLAGS="$DFLAGS -DI__HAVE__SNPRINTF"
        LINKFLAGS="$LINKFLAGS -lsnprintf"
    else
        if (
              $CC __conftest.c -ldb $LIBBSD -o __conftest || exit 1
              ./__conftest || exit 1
           ) >/dev/null 2>&1; then
            echo "-ldb" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "-ldb" 1>&5
	    fi
	    DFLAGS="$DFLAGS -DI__HAVE__SNPRINTF"
            LINKFLAGS="$LINKFLAGS -ldb"
        else
            echo "missing" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "missing" 1>&5
	    fi
        fi
    fi
fi
rm -f __conftest*



### Check uname() function on machine
echo $echo_front "Checking for uname declaration... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for uname declaration... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <sys/utsname.h>
int main() {
    void *x = (void *)uname;
    printf("%lx", (long)x);
    return 0;
}

EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
fi
rm -f __conftest*


echo $echo_front "Checking for uname implementation... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for uname implementation... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <sys/utsname.h>
int main() {
    struct utsname unamebuf;
    return (uname(&unamebuf));
}

EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    DFLAGS="$DFLAGS -DI__HAVE__UNAME"
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    echo "no" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "no" 1>&5
    fi
fi
rm -f __conftest*


### Check strncpy() function on machine
echo $echo_front "Checking for strncpy declaration... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for strncpy declaration... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <stdio.h>
#include <string.h>
int main() {
    void *x = (void *)strncpy;
    printf("%lx", (long)x);
    return 0;
}

EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
fi
rm -f __conftest*


echo $echo_front "Checking for strncpy implementation... $echo_end" 1>&6
if [ "$LOG" = "yes" ]; then
    echo $echo_front "Checking for strncpy implementation... $echo_end" 1>&5
fi
cat <<EOF >__conftest.c
#include <string.h>
int main(){
        char *src="src";
        char dest[4];
        strncpy(dest, src, 4);
        return(!(strlen(src)==strlen(dest)));
}
EOF
if (
      $CC __conftest.c  -o __conftest || exit 1
   ) >/dev/null 2>&1; then
    echo "yes" 1>&6
    DFLAGS="$DFLAGS -DI__HAVE__STRNCPY"
    if [ "$LOG" = "yes" ]; then
	echo "yes" 1>&5
    fi
else
    echo "no" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo "no" 1>&5
    fi
fi
rm -f __conftest*

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

if [ x"$ANSI_COMPILED" = x ]; then
    echo $echo_front "Checking for alloca implementation... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Checking for alloca implementation... $echo_end" 1>&5
    fi
    
    cat <<EOF >__conftest.c
#include <stdlib.h>
int main() {
    char* buf = alloca(5*sizeof(char));
    return 0;
}
EOF
    if (
	    $CC __conftest.c $LIBBSD -o __conftest || exit 1
	./__conftest || exit 1
	) >/dev/null 2>&1; then
	echo "yes" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "yes" 1>&5
	fi
    else
	rm -f __conftest*
	cat <<EOF >__conftest.c
#include <alloca.h>
int main() {
    char* buf = alloca(5*sizeof(char));
    return 0;
}
EOF
	if (
		$CC __conftest.c $LIBBSD -o __conftest || exit 1
		./__conftest || exit 1
	    ) >/dev/null 2>&1; then
	    echo "yes" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "yes" 1>&5
	    fi
	    DFLAGS="$DFLAGS -DSYSTEM_V_ALLOCA"
	else
	    echo "missing" 1>&6
	    echo "# Warning: using malloc instead, you might experience trouble compiling the program. #" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "missing" 1>&5
		echo "# Warning: using malloc instead, you might experience trouble compiling the program. #" 1>&5
	    fi
	    DFLAGS="$DFLAGS -D__NO__ALLOCA__USED__=malloc"
	fi
    fi
    rm -f __conftest*
fi    
##################################################
# check version of boxes.
if [ x"$BOXES" = x"yes" ]; then
    echo $echo_front "Checking for version of boxes... $echo_end" 1>&6
    if [ "$LOG" = "yes" ]; then
	echo $echo_front "Checking for version of boxes... $echo_end" 1>&5
    fi
    if [ x"$FORCE_BOX" = x"no" ]; then
	BOX_VERSION=`$LOCATE_BOXES -v | sed -e 's/ /\\\\ /g' -e 's/(/\\\\\(/g' -e 's/)/\\\\\)/g'`
	INT_VER=`$LOCATE_BOXES -v`
	if [ x"$BOX_VERSION" = x ]; then
	    echo ":ERROR:" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "Failed" 1>&5
	    fi
	    echo "" 1>&6
	    echo "##################################################################" 1>&6
	    echo "#         Couldn't determain a valid version of boxes.           #" 1>&6
	    echo "# Assuming that there is no working boxes, could this be due to  #" 1>&6
	    echo "# the execution bit not beeing set on boxes ??                   #" 1>&6
	    echo "# For now I will not compile with boxes support, if you wish to  #" 1>&6
	    echo "# maintain boxes support, please make sure it is located where   #" 1>&6
	    echo "# the --with-boxes flag indicates, and that it has the execution #" 1>&6
	    echo "# bit set.                                                       #" 1>&6
	    echo "##################################################################" 1>&6
	    echo "" 1>&6	
	    BOXES="no"
	else
	    DFLAGS="$DFLAGS -DBOXING_SUPPORT -DLOCATE_BOXES=\\\"$LOCATE_BOXES\\\" -DBOXES_VERSION=\\\"$BOX_VERSION\\\""
	    echo "$INT_VER" 1>&6
	    if [ "$LOG" = "yes" ]; then
		echo "$INT_VER" 1>&5
	    fi
	fi
    else
	# Since we're running with no security here, just make something up.
	BOX_VERSION="boxes\ \(No\ verified\ version\)"
	INT_VER="No verified version"
	DFLAGS="$DFLAGS -DBOXING_SUPPORT -DLOCATE_BOXES=\\\"$LOCATE_BOXES\\\" -DBOXES_VERSION=\\\"$BOX_VERSION\\\""
	echo "$INT_VER" 1>&6
	if [ "$LOG" = "yes" ]; then
	    echo "$INT_VER" 1>&5
	fi	
    fi    
fi


## libbsd should go last in case it's broken
if [ "x$LIBBSD" != x ]; then
    LIBS="$LIBS $LIBBSD"
fi

echo $echo_front "Generating Makefile.guess... $echo_end" 1>&6
(
    echo "#"
    echo "# Makefile.guess"
    echo $echo_front "# Generated by Sigit configure on $echo_end"
    date
    echo "#"
    echo

    echo "$SET_MAKE"
    echo "DOC=$DOC"
    echo "BINMODE=$BINMODE"
    echo "MANMODE=$MANMODE"
    echo "PREFIX=$PREFIX"
    echo "BINDIR=$BINDIR"
    echo "MANDIR=$MANDIR"
    echo "ETCDIR=$ETCDIR"
    echo "INSTALLROOT=$INSTALLROOT"
    echo "INSTALL=$INSTALL"
    echo "POD2MAN=$POD2MAN"
    echo "CC=$CC"
    echo "YACC=$YACC"
    echo "LEX=$LEXER"
    echo "AR=$AR"
    if [ x$CC_WARNINGS != x ]; then
        CFLAGS="$CFLAGS $WARNINGS"
    fi

    echo "CFLAGS=$CFLAGS" | sed 's/= */=/'
    echo "DFLAGS=$DFLAGS" | sed 's/= */=/'
    echo "LINKFLAGS=$LINKFLAGS" | sed 's/= */=/'
    echo "INCFLAGS=$INCFLAGS" | sed  's/= */=/'
    echo "LIBS=$LIBS" | sed 's/= */=/'

) > Makefile.guess

echo "done" 1>&6

echo $echo_front "Generating Makefile... $echo_end" 1>&6
(
    echo "#"
    echo "# Makefile"
    echo $echo_front "# Generated by Sigit configure on $echo_end"
    date
    echo "#"
    echo
    echo "include Makefile.guess"
    echo 
    echo "SUB=src doc scripts data"
    echo 
    cat Makefile.in
) > Makefile

echo "done" 1>&6



