#!/bin/sh
# yconfigure version 5.8.3
# (C) 1997-2004 Daniel Spangberg
# This file tries to find the OS type and writes a makefile to Makefile.machine
# from automatic tests and a file called Makefilebody.
# If you are having problems trying to run this on ULTRIX try:
# /bin/sh5 /the-path/yconfigure in the directory with the Makefilebody file.
# If you have special requirements such as other compilers than the default ones:
# (examples are for sh, bash and ksh. "export VAR=x" corresponds to
# "setenv VAR x" in csh/tcsh)
# try something similar to this:
# (If you need this a tip is to put the appropriate commands in your
# ~/.bashrc or ~/.cshrc)
# Change C compiler:
# export YCC=/usr/bin/gcc
# Change Fortran compiler:
# export YF77=/usr/bin/g77
# Change Fortran C preprocessor:
# export YFCPP=/usr/bin/gcc -E
# Change libraries to link:
# export YLIBS=-lsocket -lncurses -lm -L$HOME/mylib -lmylib
# Change Fortran specific libraries to link (note the -lm. it may be important!):
# export YFLIBS=-lg2c -lm
# Change flags to pass to C compiler:
# export YCFLAGS=-O6 -march=pentiumpro
# Change flags to pass to Fortran compiler:
# export YF77FLAGS=-O2 -mcpu=r8000
# Do not use MPI even if found:
# export NOMPI=1
# Change way to call MPI compiler (example is for IBM SP2):
# export MPICC=mpcc
# Work around bug in MPICH mpicc script that strips off quotation marks:
# export MPICHBUG=1
# Do not use SYSV IPC even if found:
# export NOIPC=1
# Do not use BSD Sockets even if found:
# export NOBSDSOCK=1
# Define whatever you like:
# export YDEFINES="-DUSE_X11 -I/usr/X11/include"
# Skip most automatic detection (you need to specify all options yourself):
# export NOAUTO=1
# HELPLINES should be the number of lines above this one!
# HELPLINES2 should be one less than HELPLINES
HELPLINES=41
HELPLINES2=40
THISFILE=$0

if [ "$1" = "-h" ]; then
    head -$HELPLINES $THISFILE |tail -$HELPLINES2 |tr -d '#'
    exit 0
fi

#         1         2         3         4         5         6         7         8
#123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
echo Running yconfigure...
echo If you are having problems please look at the header of the yconfigure script:
echo `pwd`/$THISFILE
if [ -r Makefilebody ]; then
echo '# Generated automatically by yconfigure' >Makefile.machine
# Initialize variables:
YMACHOPTS="$YCFLAGS"
YF77MACHOPTS="$YF77FLAGS"
EXTRADEFINES=
DEBUGOPT=
DEFINES=
GLLIBS=
XLIBS=
FLIBS=
LIBS=
MACHINEOPTS=
F77MACHINEOPTS=
F77WARNINGS=
EXTRAOBJS=
WARNINGS=
INCLUDEDIRS=
LIBDIRS=
TAROPTS=
COMPRESSOPTS=
STUPIDW32=
F90=
F90LIBS=
F90MACHINEOPTS=
LIB64=
CASEINSENSITIVE=

# Automatically check for MPICH / LAM
if [ "x $MPICC" = "x " ]; then
    MPICC=mpicc
fi
# Unfortunately; the mpicc script in MPICH strips off the quotation marks
# to avoid it type
# export MPICHBUG=1
# or
# setenv MPICHBUG 1
# before doing make.
if [ "x $MPICHBUG" = "x " ]; then
    MPICHBUG=0
fi
# Unfortunately this doesn't work with all shells (or versions of test?)
TESTEXECUTE=-x

#user library directory
UNAME=`uname`
UNAMEM=`uname -m |sed 's/i.86/i386/' |sed 's/IP../MIPS/'`
UNAME=$UNAME.$UNAMEM
USERLIB="$CYGPREFIX$HOME/lib/$UNAME"

# useful parse functions
parse_first() {
    echo $1
}

parse_rest() {
    if [ $# = 0 ]; then
	echo
    else
	shift
	echo $*
    fi
}

fatal_error_help() {
    echo Type ./yconfigure -h to show help
}

ypreferred() {
    UNAME="$OSNAME"
    UNAMEM=`uname -m |sed 's/i.86/i386/' |sed 's/IP../MIPS/'`
    RESULT=`cat Makefilebody |sed 's/ypreferred/YPREFERRED/'|grep "#" |grep "YPREFERRED($UNAME-" |grep $1| head -1`
    if [ -n "$RESULT" ]; then
	RESULT=`echo $RESULT |cut -d")" -f2`
	RESULT2=`cat Makefilebody |sed 's/ypreferred/YPREFERRED/'|grep "#" |grep "YPREFERRED($UNAME-$UNAMEM)" |grep $1`
	if [ -n "$RESULT2" ]; then
	    RESULT=`echo $RESULT2 |cut -d")" -f2`
	fi
	echo $RESULT
    fi
}

echo Determining operating system... |tr -d '\012'
MYOS=`uname`

case "$MYOS" in
    Linux)
	echo Linux |tr -d '\012'
	OSNAME=Linux
	MTYPE=`uname -m |sed 's/i.86/i386/'`
	if [ $MTYPE = i386 ]; then
		echo _i386
		OSFULLNAME=Linux_i386
	elif [ $MTYPE = x86_64 ]; then
		echo _x86_64
                LIB64="64"
		OSFULLNAME=Linux_x86_64
	elif [ $MTYPE = sparc ]; then
		echo _sparc
		OSFULLNAME=Linux_sparc
	elif [ $MTYPE = alpha ]; then
		echo _alpha
		OSFULLNAME=Linux_alpha
	else
		echo _$MTYPE
		OSFULLNAME=Linux_$MTYPE
		echo Unknown machine type $MTYPE. Please check results carefully.
	fi
	MACHINEOPTS="$MACHINEOPTS -O6"
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	if [ "x $USEOPENGL" = "x yes" ]; then
	    DEFINES="$DEFINES -DUSEOPENGL"
	    GLLIBS="$GLLIBS -lGL"
	fi
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lgfortran -lm"
	LIBS="$LIBS -lm"
	CC=gcc
	F77MACHINEOPTS="$F77MACHINEOPTS $MACHINEOPTS"
	F77=gfortran
	F77WARNINGS="$F77WARNINGS -Wall"
	WARNINGS="$WARNINGS -Wall"
	FCPP="gcc -E"
	LIBDIRS="$LIBDIRS -L/usr/X11/lib$LIB64 -L/usr/X11R6/lib$LIB64"
	PICOPTS="-fPIC"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=mksharedlib.linux
	
# Portland group fortran 90 compiler
	F90=pgf90
	F90FLAGS="-Minform=inform -fast -pc 64 -tp px"
	F90CPP="gcc -x c -ansi -E"
	;;
    Darwin)
	echo Darwin
	OSNAME=Darwin
	MTYPE=`uname -m |sed 's/i.86/i386/'`
	OSFULLNAME=Darwin_$MTYPE
	CC=/sw/bin/gcc
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lgfortran -lm"
	LIBS="$LIBS -lm"
	F77=/sw/bin/gfortran
	FCPP="/sw/bin/gfortran -E"
	LIBDIRS="$LIBDIRS -L/usr/X11/lib"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=echo
	;;
    FreeBSD)
	echo FreeBSD
	OSNAME=FreeBSD
	OSFULLNAME=FreeBSD
	MACHINEOPTS="-O6"
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	if [ "x $USEOPENGL" = "x yes" ]; then
	    DEFINES="$DEFINES -DUSEOPENGL"
	    GLLIBS="$GLLIBS -lGL"
	fi
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lgfortran -lm"
	LIBS="$LIBS -lm"
	CC=cc
	F77MACHINEOPTS="$F77MACHINEOPTS $MACHINEOPTS"
	F77=f77
	F77WARNINGS="$F77WARNINGS"
	WARNINGS="$WARNINGS"
	FCPP="cpp -P -traditional"
	LIBDIRS="$LIBDIRS -L/usr/X11/lib -L/usr/X11R6/lib"
        INCLUDEDIRS="$INCLUDEDIRS -I/usr/X11R6/include"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=echo
        DEFINES="-I/usr/X11R6/include -L/usr/X11R6/lib $DEFINES"

  ;;
  CYGWIN*)
	if [ -n "$MINGW" ]; then
	    echo MinGW |tr -d '\012' 
	    OSNAME=MinGW
	    MTYPE=`uname -m |sed 's/i.86/i386/'`
	    if [ $MTYPE = i386 ]; then
		echo _i386
		OSFULLNAME=MinGW_i386
	    else
		echo _$MTYPE
		OSFULLNAME=MinGW_$MTYPE
		echo Unknown machine type $MTYPE. Please check results carefully.
	    fi
	    if [ -z "$CYGPREFIX" ]; then
		echo "I need You to set the CYGPREFIX environment variable!"
		exit 1
	    fi
	else
	    echo Cygwin |tr -d '\012' 
	    OSNAME=Cygwin
	    MTYPE=`uname -m |sed 's/i.86/i386/'`
	    if [ $MTYPE = i386 ]; then
		echo _i386
		OSFULLNAME=Cygwin_i386
	    else
		echo _$MTYPE
		OSFULLNAME=Cygwin_$MTYPE
		echo Unknown machine type $MTYPE. Please check results carefully.
	    fi
	fi
	MACHINEOPTS="$MACHINEOPTS -O6"
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	if [ "x $USEOPENGL" = "x yes" ]; then
	    DEFINES="$DEFINES -DUSEOPENGL"
	    GLLIBS="$GLLIBS -lGL"
	fi
        INCLUDEDIRS="$INCLUDEDIRS -I/usr/X11R6/include"
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lgfortran -lm"
	LIBS="$LIBS -lm"
	CC=gcc
	F77MACHINEOPTS="$F77MACHINEOPTS $MACHINEOPTS"
	F77=gfortran
	F77WARNINGS="$F77WARNINGS"
	WARNINGS="$WARNINGS"
	FCPP="gcc -E"
	LIBDIRS="$LIBDIRS -L/usr/X11R6/lib"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
        SHAREDCOMMAND=echo
 ;;
 ULTRIX)
	echo DEC_MIPS_ULTRIX
	OSNAME=ULTRIX
	OSFULLNAME=DEC_MIPS_ULTRIX
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lUfor -lfor -lutil -li -lots -lm"
	LIBS="$LIBS -lm"
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	CC=cc
	MACHINEOPTS="$MACHINEOPTS -std1 -O2"
	F77=f77
	F77MACHINEOPTS="$F77MACHINEOPTS -O4"
	FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=echo
        TESTEXECUTE=-r
 ;;
 OSF1)
	echo DEC_Alpha_OSF1
	OSNAME=OSF1
	OSFULLNAME=DEC_Alpha_OSF1
	CC=c89
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1 -D_OSF_SOURCE"
	if [ "x $USEOPENGL" = "x yes" ]; then
	    INCLUDEDIRS="$INCLUDEDIRS -I/usr/include/GL"
	    DEFINES="$DEFINES -DUSEOPENGL"
	    GLLIBS="$GLLIBS -lGL"
	fi
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lUfor -lfor -lFutil -lm -lots"
	LIBS="$LIBS -lm"
	MACHINEOPTS="$MACHINEOPTS -O4"
	F77=f77
	F77MACHINEOPTS="$F77MACHINEOPTS -O4"
	FCPP="/lib/cpp -lang-c -traditional -P -DLANGUAGE_FORTRAN"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=echo

 ;;
 IRIX*)
	echo SGI_IRIX |tr -d '\012'

        OSVERSION=`(uname -r |grep "4." |wc -l)`
	if [ $OSVERSION = 1 ]; then
	    IRIXVERSION=10
	    echo _4
	else
	    OSVERSION=`(uname -r |grep "6." |wc -l)`
	    if [ $OSVERSION = 1 ]; then
		IRIXVERSION=6
		echo _6
	    else
		IRIXVERSION=unknown
		echo _unknown
		echo Unknown OS version. Please check results carefully.
	    fi
	fi
	OSNAME=IRIX
	OSFULLNAME="SGI_IRIX_"$IRIXVERSION
	XLIBS="$XLIBS -lXext -lX11"
        LIBS="$LIBS -lm"
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	if [ $IRIXVERSION = 6 ]; then
		FLIBS="$FLIBS -lftn -lm"
		MACHINEOPTS="$MACHINEOPTS -O2"
		F77MACHINEOPTS="$F77MACHINEOPTS -O2"
 	elif [ $IRIXVERSION = 4 ]; then
		FLIBS="$FLIBS -lF77 -lm -lU77 -lI77 -lisam -lmpc"
	else
		FLIBS="$FLIBS -lftn -lm"
		MACHINEOPTS="$MACHINEOPTS -O2"
		F77MACHINEOPTS="$F77MACHINEOPTS -O2"
	fi
	CC=cc
	F77=f77
	FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
	F90=f90
	F90FLAGS="-O2"
	F90CPP="/lib/cpp -P" 
	TAR=tar
	TAROPTS=cf
	COMPRESS=compress
	SHAREDCOMMAND=echo
 ;;
 HP-UX)
	echo HP_PA_UX |tr -d '\012'
        OSVERSION=`(uname -r |grep ".10." |wc -l)`
	if [ $OSVERSION = 1 ]; then
	    HPOSVERSION=10
	    echo _10
	else
	    OSVERSION=`(uname -r |grep ".09." |wc -l)`
	    if [ $OSVERSION = 1 ]; then
		HPOSVERSION=9
		echo _9
	    else
		echo _unknown
		HPOSVERSION=unknown
		echo Unknown OS version. Please check results carefully.
	    fi
	fi
        OSNAME=HPUX
	OSFULLNAME="HP_PA_UX_"$HPOSVERSION
	CC=c89
	if [ $HPOSVERSION = 9 ]; then
	    LIBDIRS="$LIBDIRS -L/usr/lib/X11R5"
	    DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1 -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_POSIX_SOURCE"
	elif [ $HPOSVERSION = 10 ]; then
	    INCLUDEDIRS="$INCLUDEDIRS -I/usr/include/X11R5"
	    DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1 -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_XOPEN_SOURCE_EXTENDED"
	else
	    LIBDIRS="$LIBDIRS -L/usr/lib/X11R5"
	    INCLUDEDIRS="$INCLUDEDIRS -I/usr/include/X11R5"
	    DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1 -D_INCLUDE_POSIX_SOURCE -D_INCLUDE_HPUX_SOURCE -D_INCLUDE_XOPEN_SOURCE -D_INCLUDE_XOPEN_SOURCE_EXTENDED"
	fi
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lcl -lisamstub -lm"
	LIBS="$LIBS -lm"
	MACHINEOPTS="$MACHINEOPTS +O3"
	F77=f77
	F77MACHINEOPTS="$F77MACHINEOPTS +ppu +O3"
	FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=echo
 ;;
 AIX)
	echo IBM_AIX
	OSNAME=AIX
	OSFULLNAME=IBM_AIX
	CC=xlc
	MACHINEOPTS="$MACHINEOPTS -O3"
	F77=xlf
	F77MACHINEOPTS="$F77MACHINEOPTS -O3 -qextname"
	DEFINES="$DEFINES -DFLOAT_SQRT -D_POSIX_SOURCE -DFSTRINGPASS1 -D_ALL_SOURCE=1"
	FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -lxlf -lm"
	LIBS="$LIBS -lm"
	TAR=tar
	TAROPTS=cf
	COMPRESS=compress
	SHAREDCOMMAND=echo

 ;;
 SunOS)
	echo Solaris |tr -d '\012'
	OSNAME=Solaris
	MTYPE=`uname -m`
	CC=cc
	case "$MTYPE" in
    	  i86pc)
		echo _x86
		OSFULLNAME=Solaris_x86
		MACHINEOPTS="$MACHINEOPTS -m486 -O6"
		F77MACHINEOPTS="$F77MACHINEOPTS -O -Nx400"
		FLIBS="$FLIBS -lf2c -lm"
	  ;;
          sun*)
		echo _sun
		OSFULLNAME=Solaris_sun
		MACHINEOPTS="$MACHINEOPTS -O"
		F77MACHINEOPTS="$F77MACHINEOPTS -O -Nx400"
		FLIBS="$FLIBS -lM77 -lF77 -lsunmath -lm"
	  ;;
        esac

	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	XLIBS="$XLIBS -lXext -lX11"

	LIBS="$LIBS -lm"

	F77=f77
	WARNINGS="$WARNINGS"
	FCPP="/usr/ccs/lib/cpp -P -DLANGUAGE_FORTRAN"
	LIBDIRS="$LIBDIRS -L/usr/X11/lib"
	TAR=tar
	TAROPTS=cf
	COMPRESS=gzip
	COMPRESSOPTS="-f9"
	SHAREDCOMMAND=echo
 ;;
 unicos)
	echo Unicos
	OSNAME=Unicos
	OSFULLNAME=Unicos
	CC=cc
	MACHINEOPTS="$MACHINEOPTS -O3"
	F77=f77
	F77MACHINEOPTS="$F77MACHINEOPTS -O3"
	DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
	FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
	XLIBS="$XLIBS -lXext -lX11"
	FLIBS="$FLIBS -ldont_know"
	LIBS="$LIBS -lm"
	TAR=tar
	TAROPTS=cf
	COMPRESS=compress
	SHAREDCOMMAND=echo
 ;;
 *)
	MYOSV=`uname -v`
	case "$MYOSV" in
		unicosmk)
			echo Cray_Unicos/mk
			OSNAME=Unicos_mk
			OSFULLNAME=Cray_Unicos_mk
			MPICC="cc -Xm"
			CC=cc
			MACHINEOPTS="$MACHINEOPTS -O2"
			F77=f77
			F77MACHINEOPTS="$F77MACHINEOPTS -O2"
			DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
			FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
			XLIBS="$XLIBS -lXext -lX11"
			FLIBS="$FLIBS -ldont_know"
			LIBS="$LIBS -lm"
			TAR=tar
			TAROPTS=cf
			COMPRESS=compress
			SHAREDCOMMAND=echo
		;;
		*)
			echo Unknown Operating system $MYOS
			echo Unknown OS. Please check results carefully.
			OSNAME=Unknown
			OSFULLNAME=Unknown_unknown
			CC=cc
			DEFINES="$DEFINES -DFLOAT_SQRT -DFSTRINGPASS1"
			XLIBS="$XLIBS -lXext -lX11"
			FLIBS="$FLIBS -lgfortran -lm"
			LIBS="$LIBS -lm"
			F77=gfortran
			FCPP="/lib/cpp -P -DLANGUAGE_FORTRAN"
			LIBDIRS="$LIBDIRS -L/usr/X11/lib"
			TAR=tar
			TAROPTS=cf
			COMPRESS=compress
			COMPRESSOPTS=
			SHAREDCOMMAND=echo
	 ;;
	esac
 ;;
esac

OSSTRING="$OSFULLNAME"

# End of OS specific configuration

# Check case insensitive filesystem

touch testcase.f
if [ -r testcase.F ]; then
    CASEINSENSITIVE=or
    echo The filesystem is case insensitive
else
    echo The filesystem is case sensitive
fi
rm testcase.f


# Check the preferred compilers

MC="`ypreferred CC`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YCC" = "x " ]; then
    echo "Using preset C compiler: "|tr -d '\012'
else
    CC="$YCC"
    echo "Using user C compiler: "|tr -d '\012'
fi
echo $CC

MC="`ypreferred F77`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YF77" = "x " ]; then
    echo "Using preset Fortran compiler: "|tr -d '\012'
else
    F77="$YF77"
    echo "Using user Fortran compiler: "|tr -d '\012'
fi
echo $F77

MC="`ypreferred F90`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YF90" = "x " ]; then
    echo "Using preset Fortran 90 compiler: "|tr -d '\012'
else
    F90="$YF90"
    echo "Using user Fortran 90 compiler: "|tr -d '\012'
fi
echo $F90

MC="`ypreferred F90CPP`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YF90CPP" = "x " ]; then
    echo "Using preset C-preprocessor for Fortran 90: "|tr -d '\012'
else
    F90CPP="$YF90CPP"
    echo "Using user C-preprocessor for Fortran 90: "|tr -d '\012'
fi
echo $F90CPP

if [ "x $YF90LIBS" = "x " ]; then
    echo "Using preset Fortran 90 libs: "|tr -d '\012'
else
    F90LIBS="$YF90LIBS"
    echo "Using user Fortran 90 libs: "|tr -d '\012'
fi
echo $F90LIBS


MC="`ypreferred FCPP`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YFCPP" = "x " ]; then
    echo "Using preset C-preprocessor for Fortran: "|tr -d '\012'
else
    FCPP="$YFCPP"
    echo "Using user C-preprocessor for Fortran: "|tr -d '\012'
fi
echo $FCPP

MC="`ypreferred LIBS`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YLIBS" = "x " ]; then
    echo "Using preset C libs: "|tr -d '\012'
else
    LIBS="$YLIBS"
    echo "Using user C libs: "|tr -d '\012'
fi
echo $LIBS

MC="`ypreferred FLIBS`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YFLIBS" = "x " ]; then
    echo "Using preset Fortran libs: "|tr -d '\012'
else
    FLIBS="$YFLIBS"
    echo "Using user Fortran libs: "|tr -d '\012'
fi
echo $FLIBS

MC="`ypreferred MACHINEOPTS`"
if [ -n "$MC" ]; then
    eval $MC
fi

MC="`ypreferred EXTRAOBJS`"
if [ -n "$MC" ]; then
    eval $MC
fi

# Check whether user wants other optimization options
if [ "x $YMACHOPTS" = "x " ]; then
    echo "Using preset options for C: "|tr -d '\012'
else
    MACHINEOPTS="$YMACHOPTS"
    echo "Using user options for C: "|tr -d '\012'
fi
echo $MACHINEOPTS

MC="`ypreferred F77MACHINEOPTS`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YF77MACHOPTS" = "x " ]; then
    echo "Using preset options for Fortran: "|tr -d '\012'
else
    F77MACHINEOPTS="$YF77MACHOPTS"
    echo "Using user options for Fortran: "|tr -d '\012'
fi
echo $F77MACHINEOPTS

MC="`ypreferred F90FLAGS`"
if [ -n "$MC" ]; then
    eval $MC
fi

if [ "x $YF90FLAGS" = "x " ]; then
    echo "Using preset flags for Fortran 90: "|tr -d '\012'
else
    F90FLAGS="$YF90FLAGS"
    echo "Using user flags for Fortran 90: "|tr -d '\012'
fi
echo $F90FLAGS


if [ "x $NOAUTO" = "x " ]; then

# General tests
# Compile home directory
ODIR=`pwd`
cd ..
MYHOME=`pwd`
echo "MYHOME="$MYHOME >> $ODIR/Makefile.machine
cd $ODIR

DEFINES="$DEFINES $YDEFINES"

# Check what's needed:
C_COMPILER=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " C_COMPILER"| wc -l`
if [ $C_COMPILER = 1 ]; then
	C_COMPILER_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " C_COMPILER"| grep " REQUIRED" |wc -l`
fi

if [ $C_COMPILER = 1 ]; then
    echo Checking that the C compiler works... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for the C compiler */' >testdir/testtemp.c
    echo '#include <stdio.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'printf("Hello World!*n");' |tr '*' '\\' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -o hello >/dev/null 2>&1; then
	if [ $TESTEXECUTE ./hello ]; then
	    if ./hello >/dev/null 2>&1; then
		echo Yes
	    else
		echo No
		echo Fatal: Simple C code fails to execute.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: C compiler cannot generate executable code.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: C compiler cannot generate code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $C_COMPILER_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

LINK_STATIC=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LINK_STATIC"| wc -l`
if [ $LINK_STATIC = 1 ]; then
    case "$OSFULLNAME" in
	Linux*)
	LIBS="-static $LIBS"
      ;;
    esac
fi


THOROUGH_ARCH_CHECKS=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " THOROUGH_ARCH_CHECKS"| wc -l`
if [ $THOROUGH_ARCH_CHECKS = 1 ]; then
    case "$OSFULLNAME" in
	Linux*)
	    if [ $OSFULLNAME = Linux_i386 ]; then
		echo "Determining architecture..." |tr -d '\012'
		# Check our architecture by parsing /proc/cpuinfo
		CPU_VENDOR_INTEL=`grep "^vendor_id" /proc/cpuinfo |grep "\<GenuineIntel\>" |wc -l`
		CPU_VENDOR_AMD=`grep "^vendor_id" /proc/cpuinfo |grep "\<AuthenticAMD\>" |wc -l`
		CPU_FAMILY=`grep "^cpu family" /proc/cpuinfo |cut -f2 -d':'`
		CPU_VENDOR="Unknown"
		if [ $CPU_VENDOR_INTEL = 1 ]; then
		    echo "Intel " |tr -d '\012'
		    CPU_VENDOR="Intel"
		    if [ $CPU_FAMILY = 3 ]; then
			echo "i386 " |tr -d '\012'
			ARCH_TRIES="-m386"
			ARCH_NAMES="386"
		    elif [ $CPU_FAMILY = 4 ]; then
			echo "i486 " |tr -d '\012'
			ARCH_TRIES="-m486"
			ARCH_NAMES="486"
		    elif [ $CPU_FAMILY = 5 ]; then
			echo "Pentium or Pentium MMX " |tr -d '\012'
			ARCH_TRIES="-march=pentium -mpentium -m486"
			ARCH_NAMES="pentium pentium 486"
		    else
			# This is at least a pentiumpro
			echo "Pentium Pro / Pentium II / Pentium III or higher" |tr -d '\012'
			ARCH_TRIES="-march=pentiumpro -mpentiumpro -m486"
			ARCH_NAMES="pentiumpro pentiumpro 486"
		    fi
		elif [ $CPU_VENDOR_AMD = 1 ]; then
		    echo "AMD " |tr -d '\012'
		    CPU_VENDOR="AMD"
		    if [ $CPU_FAMILY = 3 ]; then
			echo "i386" |tr -d '\012'
			ARCH_TRIES="-m386 "
			ARCH_NAMES="386"
		    elif [ $CPU_FAMILY = 4 ]; then
			echo "i486" |tr -d '\012'
			ARCH_TRIES="-m486 "
			ARCH_NAMES="486"
		    elif [ $CPU_FAMILY = 5 ]; then
			# Should really check if k5 or k6...
			echo "k5 or k6 " |tr -d '\012'
			ARCH_TRIES="-march=k6 -march=pentium -mpentium -m486"
			ARCH_NAMES="k6 pentium pentium 486"
		    else
			# This is at least an athlon (k7)
			echo "Athlon, Duron or higher " |tr -d '\012'
# Be compatible for now...
#			ARCH_TRIES="-march=athlon -march=pentiumpro -mpentiumpro -m486"
#			ARCH_NAMES="athlon pentiumpro pentiumpro 486"
			ARCH_TRIES="-march=pentiumpro -mpentiumpro -m486"
			ARCH_NAMES="pentiumpro pentiumpro 486"
		    fi
		else
		    echo "Unknown (Using default architecture)" |tr -d '\012'
		    ARCH_TRIES=""
		    ARCH_NAMES=""
		fi

		if [ "x $COMPATIBLE" = "x yes" ]; then
		    if [ -n "$ARCH_TRIES" ]; then
			echo ", compatibility mode" |tr -d '\012'
			ARCH_TRIES="-m486"
			ARCH_NAMES="486"
		    fi
		fi

		if [ -n "$ARCH_TRIES" ] ; then
		    LEFT_ARCH="$ARCH_TRIES"
		    LEFT_ARCH_NAMES="$ARCH_NAMES"
		    while [ -n "$LEFT_ARCH" ]; do
			THIS_ARCH=`parse_first $LEFT_ARCH`
			LEFT_ARCH=`parse_rest $LEFT_ARCH`
			THIS_ARCH_NAME=`parse_first $LEFT_ARCH_NAMES`
			LEFT_ARCH_NAMES=`parse_rest $LEFT_ARCH_NAMES`
			mkdir testdir
			echo '/* A test program for the C compiler */' >testdir/testtemp.c
			echo '#include <stdio.h>' >>testdir/testtemp.c
			echo 'int main(){' >>testdir/testtemp.c
			echo 'printf("Hello World!*n");' |tr '*' '\\' >>testdir/testtemp.c
			echo 'return 0;}' >>testdir/testtemp.c
			cd testdir
			MYEXITCODE=0
			if $CC $THIS_ARCH $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -o hello >/dev/null 2>&1; then
			    if [ $TESTEXECUTE ./hello ]; then
				if ./hello >/dev/null 2>&1; then
				    # Things are ok here
				    LEFT_ARCH=""
				    MACHINEOPTS="$MACHINEOPTS $THIS_ARCH"
				    OSFULLNAME="Linux_$THIS_ARCH_NAME"
				else
				    MYEXITCODE=1
				fi
			    else
				MYEXITCODE=1
			    fi
		        else
			    MYEXITCODE=1
			fi
			cd ..
			rm -rf testdir
		   done
		else
		    OSFULLNAME="Linux_x86_unknown"
		fi

		# If possible, align stack using a hack...
		MACHINEOPTS="$MACHINEOPTS -DUSE_X86_ALIGN_HACK"
		echo ", x86 align hack " |tr -d '\012'

		echo
	    fi
      ;;
    esac
fi

F90_COMPILER=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F90_COMPILER"| wc -l`
if [ $F90_COMPILER = 1 ]; then
	F90_COMPILER_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F90_COMPILER"| grep " REQUIRED" |wc -l`
fi

if [ $F90_COMPILER = 1 ]; then
    echo Checking that the Fortran 90 compiler works... |tr -d '\012'
    mkdir testdir
    echo '!A test program for the Fortran 90 compiler' >testdir/testtemp.f90
    echo 'program hello' >>testdir/testtemp.f90
    echo 'integer :: A' >>testdir/testtemp.f90
    echo 'write(*,*) '"'"'Hello World!'"'" >>testdir/testtemp.f90
    echo 'stop' >>testdir/testtemp.f90
    echo 'end' >>testdir/testtemp.f90
    cd testdir
    MYEXITCODE=0
    if $F90 $F90FLAGS testtemp.f90 -o hello >/dev/null 2>&1; then
	if [ $TESTEXECUTE ./hello ]; then
	    if ./hello >/dev/null 2>&1; then
		echo Yes
	    else
		echo No
		echo Fatal: Simple Fortran 90 code fails to execute.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: Fortran 90 compiler cannot generate executable code.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: Fortran 90 compiler cannot generate code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $F90_COMPILER_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi


F90_CPP=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F90_CPP"| wc -l`
if [ $F90_CPP = 1 ]; then
	F90_CPP_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F90_CPP"| grep " REQUIRED" |wc -l`
fi

if [ $F90_CPP = 1 ]; then
    echo Checking that the C preprocessor can preprocess Fortran 90 code... |tr -d '\012'
    mkdir testdir
    echo '!A test program for the C preprocessor and the Fortran 90 compiler' >testdir/testtemp.f90
    echo '#define TESTDEFINE 42' >>testdir/testtemp.f90
    echo 'program hello' >>testdir/testtemp.f90
    echo 'character*5 a,b' >>testdir/testtemp.f90
    echo 'character*10 c' >>testdir/testtemp.f90
    echo 'write(*,*) '"'"'Hello World!'"'"',TESTDEFINE' >>testdir/testtemp.f90
    echo 'a='"'"'hello'"'" >>testdir/testtemp.f90
    echo 'b='"'"'world'"'" >>testdir/testtemp.f90
# Important that C preprocessor doesn't strip off c++ comments.
# They are concatenations in FORTRAN.
    echo 'c=a// &' >>testdir/testtemp.f90
    echo 'b' >>testdir/testtemp.f90
    echo 'stop' >>testdir/testtemp.f90
    echo 'end' >>testdir/testtemp.f90
    cd testdir
    MYEXITCODE=0
    if $F90CPP testtemp.f90 >ftemp.f90 2>/dev/null; then
#       echo $F90 $F90FLAGS ftemp.f90 -o hello 
#exit 1
	if $F90 $F90FLAGS ftemp.f90 -o hello >/dev/null 2>&1; then
	    if [ $TESTEXECUTE ./hello ]; then
		if ./hello >/dev/null 2>&1; then
		    echo Yes
		else
		    echo No
		    echo Fatal: Preprocessed Fortran 90 code fails to execute.
		    MYEXITCODE=1
		fi
	    else
		echo No
		echo Fatal: Fortran 90 compiler cannot generate executable code from preprocessed code.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: C preprocessor processes Fortran 90 code badly.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: C preprocessor cannot preprocess Fortran 90 code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $F90_CPP_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

F90_C_LINK=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F90_C_LINK"| wc -l`
if [ $F90_C_LINK = 1 ]; then
	F90_C_LINK_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F90_C_LINK"| grep " REQUIRED" |wc -l`
fi

if [ $F90_C_LINK = 1 ]; then
    echo Checking that C and Fortran 90 code can be linked together... |tr -d '\012'
    mkdir testdir
    echo '/* The test part for the C compiler */' >testdir/testtemp.c
    echo '#include <stdio.h>' >>testdir/testtemp.c
    echo 'extern void hellof_();' >>testdir/testtemp.c
    echo 'void helloc_(){' >>testdir/testtemp.c
    echo 'printf("Helloc");' >>testdir/testtemp.c
    echo 'hellof_();' >>testdir/testtemp.c
    echo 'return;}' >>testdir/testtemp.c
    echo '!The test part for the Fortran 90 compiler' >testdir/ftemp.f90
    echo 'subroutine hellof' >>testdir/ftemp.f90
    echo 'write(*,*) '"'"'Hello Worldfortransub!'"'" >>testdir/ftemp.f90
    echo 'return' >>testdir/ftemp.f90
    echo 'end' >>testdir/ftemp.f90
    echo 'program hello' >>testdir/ftemp.f90
    echo 'write(*,*) '"'"'Hello Worldfortranprogram!'"'" >>testdir/ftemp.f90
    echo 'call helloc' >>testdir/ftemp.f90
    echo 'stop' >>testdir/ftemp.f90
    echo 'end' >>testdir/ftemp.f90
    cd testdir
    MYEXITCODE=0
    $CC -c $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c >/dev/null 2>&1
    $F90 -c $F90FLAGS ftemp.f90 >/dev/null 2>&1
    if $F90 $F90FLAGS ftemp.o testtemp.o  -o hello >/dev/null 2>&1; then
	if [ $TESTEXECUTE ./hello ]; then
	    if ./hello >/dev/null 2>&1; then
		echo Yes
	    else
		echo No
		echo Fatal: C and Fortran 90 code linked together fails to execute.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: F90 compiler cannot create executable code from C and Fortran 90 code.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: F90 compiler cannot create code from C and Fortran 90 code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $F90_C_LINK_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

F77_COMPILER=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F77_COMPILER"| wc -l`
if [ $F77_COMPILER = 1 ]; then
	F77_COMPILER_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F77_COMPILER"| grep " REQUIRED" |wc -l`
fi

if [ $F77_COMPILER = 1 ]; then
    echo Checking that the FORTRAN compiler works... |tr -d '\012'
    mkdir testdir
    echo 'c     A test program for the FORTRAN compiler' >testdir/testtemp.f
    echo '      program hello' >>testdir/testtemp.f
    echo '      write(*,*) '"'"'Hello World!'"'" >>testdir/testtemp.f
    echo '      stop' >>testdir/testtemp.f
    echo '      end' >>testdir/testtemp.f
    cd testdir
    MYEXITCODE=0
    if $F77 $F77MACHINEOPTS testtemp.f -o hello >/dev/null 2>&1; then
	if [ $TESTEXECUTE ./hello ]; then
	    if ./hello >/dev/null 2>&1; then
		echo Yes
	    else
		echo No
		echo Fatal: Simple FORTRAN code fails to execute.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: FORTRAN compiler cannot generate executable code.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: FORTRAN compiler cannot generate code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $F77_COMPILER_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

F77_CPP=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F77_CPP"| wc -l`
if [ $F77_CPP = 1 ]; then
	F77_CPP_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F77_CPP"| grep " REQUIRED" |wc -l`
fi

if [ $F77_CPP = 1 ]; then
    echo Checking that the C preprocessor can preprocess FORTRAN code... |tr -d '\012'
    mkdir testdir
    echo 'c     A test program for the C preprocessor and FORTRAN compiler' >testdir/testtemp.F
    echo '#define TESTDEFINE 42' >>testdir/testtemp.F
    echo '      program hello' >>testdir/testtemp.F
    echo '      character*5 a,b' >>testdir/testtemp.F
    echo '      character*10 c' >>testdir/testtemp.F
    echo '      write(*,*) '"'"'Hello World!'"'"',TESTDEFINE' >>testdir/testtemp.F
    echo '      a='"'"'hello'"'" >>testdir/testtemp.F
    echo '      b='"'"'world'"'" >>testdir/testtemp.F
# Important that C preprocessor doesn't strip off c++ comments.
# They are concatenations in FORTRAN.
    echo '      c=a//' >>testdir/testtemp.F
    echo '     xb' >>testdir/testtemp.F
    echo '      stop' >>testdir/testtemp.F
    echo '      end' >>testdir/testtemp.F
    cd testdir
    MYEXITCODE=0
    if $FCPP testtemp.F >ftemp.f 2>/dev/null; then
	if $F77 $F77MACHINEOPTS ftemp.f -o hello >/dev/null 2>&1; then
	    if [ $TESTEXECUTE ./hello ]; then
		if ./hello >/dev/null 2>&1; then
		    echo Yes
		else
		    echo No
		    echo Fatal: Preprocessed FORTRAN code fails to execute.
		    MYEXITCODE=1
		fi
	    else
		echo No
		echo Fatal: FORTRAN compiler cannot generate executable code from preprocessed code.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: C preprocessor processes FORTRAN code badly.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: C preprocessor cannot preprocess FORTRAN code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $F77_CPP_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

F77_C_LINK=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F77_C_LINK"| wc -l`
if [ $F77_C_LINK = 1 ]; then
	F77_C_LINK_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " F77_C_LINK"| grep " REQUIRED" |wc -l`
fi

if [ $F77_C_LINK = 1 ]; then
    echo Checking that C and FORTRAN code can be linked together... |tr -d '\012'
    mkdir testdir
    echo '/* The test part for the C compiler */' >testdir/testtemp.c
    echo 'void hello_();'>>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'hello_();' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    echo 'c     The test part for the FORTRAN compiler' >testdir/ftemp.f
    echo '      subroutine hello' >>testdir/ftemp.f
    echo '      write(*,*) '"'"'Hello World!'"'" >>testdir/ftemp.f
    echo '      return' >>testdir/ftemp.f
    echo '      end' >>testdir/ftemp.f
    cd testdir
    MYEXITCODE=0
    $CC -c $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c >/dev/null 2>&1
    $F77 -c $F77MACHINEOPTS ftemp.f >/dev/null 2>&1
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES ftemp.o testtemp.o $FLIBS -o hello >/dev/null 2>&1; then
	if [ $TESTEXECUTE ./hello ]; then
	    if ./hello >/dev/null 2>&1; then
		echo Yes
	    else
		echo No
		echo Fatal: C and FORTRAN code linked together fails to execute.
		MYEXITCODE=1
	    fi
	else
	    echo No
	    echo Fatal: C compiler cannot create executable code from C and FORTRAN code.
	    MYEXITCODE=1
	fi
    else
	echo No
	echo Fatal: C compiler cannot create code from C and FORTRAN code.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $F77_C_LINK_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
    
    if [ $MYEXITCODE = 0 ]; then
	echo Testing how FORTRAN compiler assigns function names at link level... |tr -d '\012'
	mkdir testdir
	echo '/* The test part for the C compiler */' >testdir/testtemp.c
	echo 'void hello_a_long_one_();'>>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'hello_a_long_one_();' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	echo 'c     The test part for the FORTRAN compiler' >testdir/ftemp.f
	echo '      subroutine hello_a_long_one' >>testdir/ftemp.f
	echo '      write(*,*) '"'"'Hello World!'"'" >>testdir/ftemp.f
	echo '      return' >>testdir/ftemp.f
	echo '      end' >>testdir/ftemp.f
	cd testdir
	MYEXITCODE=0
	$CC -c $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c >/dev/null 2>&1
	$F77 -c $F77MACHINEOPTS ftemp.f >/dev/null 2>&1
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES ftemp.o testtemp.o $FLIBS -o hello >/dev/null 2>&1; then
	    if [ $TESTEXECUTE ./hello ]; then
		if ./hello >/dev/null 2>&1; then
		    echo One underscore to long function names
		else
		    MYEXITCODE=1
		fi
	    else
		MYEXITCODE=1
	    fi
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    mkdir testdir
	    echo '/* The test part for the C compiler */' >testdir/testtemp.c
	    echo 'void hello_a_long_one__();'>>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'hello_a_long_one__();' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    echo 'c     The test part for the FORTRAN compiler' >testdir/ftemp.f
	    echo '      subroutine hello_a_long_one' >>testdir/ftemp.f
	    echo '      write(*,*) '"'"'Hello World!'"'" >>testdir/ftemp.f
	    echo '      return' >>testdir/ftemp.f
	    echo '      end' >>testdir/ftemp.f
	    cd testdir
	    MYEXITCODE=0
	    $CC -c $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c >/dev/null 2>&1
	    $F77 -c $F77MACHINEOPTS ftemp.f >/dev/null 2>&1
	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES ftemp.o testtemp.o $FLIBS -o hello >/dev/null 2>&1; then
		if [ $TESTEXECUTE ./hello ]; then
		    if ./hello >/dev/null 2>&1; then
			echo 'Two underscores to long function names (f77 style)'
			DEFINES="$DEFINES -DUSCORE2"
		    else
			MYEXITCODE=1
		    fi
		else
		    MYEXITCODE=1
		fi
	    else
		MYEXITCODE=1
	    fi
	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		if [ $F77_C_LINK_REQUIRED = 1 ]; then
		    echo
		    echo Fatal: Unknown number of underscores added to long function names.
		    rm -rf Makefile.machine
		    fatal_error_help
		    exit 1
		fi
	    fi
	fi
    fi
fi

# Check what's needed:
TYPE_SIZES=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " TYPE_SIZES"| wc -l`

if [ $TYPE_SIZES = 1 ]; then
    echo Checking type sizes...
    mkdir testdir
    echo '/* A test program for type sizes */' >testdir/testtemp.c
    echo '#include <stdio.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'printf("%d %d %d %d %d %dSn",sizeof(short),sizeof(int),sizeof(long),sizeof(void*),sizeof(float),sizeof(double));' |tr 'S' '\\' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -o hello >/dev/null 2>&1; then
	if [ $TESTEXECUTE ./hello ]; then
	    if ./hello >sizes.out 2>&1; then
		MYDATA=`cat sizes.out`
		MYTYPE=`parse_first $MYDATA`
                MYDATA=`parse_rest $MYDATA`
		EXTRADEFINES="$EXTRADEFINES -DSIZEOF_SHORT=$MYTYPE"
		echo "sizeof(short)=$MYTYPE"
		MYTYPE=`parse_first $MYDATA`
                MYDATA=`parse_rest $MYDATA`
		EXTRADEFINES="$EXTRADEFINES -DSIZEOF_INT=$MYTYPE"
		echo "sizeof(int)=$MYTYPE"
		MYTYPE=`parse_first $MYDATA`
                MYDATA=`parse_rest $MYDATA`
		EXTRADEFINES="$EXTRADEFINES -DSIZEOF_LONG=$MYTYPE"
		echo "sizeof(long)=$MYTYPE"
		MYTYPE=`parse_first $MYDATA`
                MYDATA=`parse_rest $MYDATA`
		EXTRADEFINES="$EXTRADEFINES -DSIZEOF_POINTER=$MYTYPE"
		echo 'sizeof(void*)'"=$MYTYPE"
		MYTYPE=`parse_first $MYDATA`
                MYDATA=`parse_rest $MYDATA`
		EXTRADEFINES="$EXTRADEFINES -DSIZEOF_FLOAT=$MYTYPE"
		echo "sizeof(float)=$MYTYPE"
		MYTYPE=`parse_first $MYDATA`
                MYDATA=`parse_rest $MYDATA`
		EXTRADEFINES="$EXTRADEFINES -DSIZEOF_DOUBLE=$MYTYPE"
		echo "sizeof(double)=$MYTYPE"
	    else
		echo Fatal: Cannot determine type sizes.
		MYEXITCODE=1
	    fi
	else
	    echo Fatal: Cannot determine type sizes.
	    MYEXITCODE=1
	fi
    else
	echo Fatal: Cannot determine type sizes.
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	rm -rf Makefile.machine
	fatal_error_help
	exit 1
    fi
fi

USLEEP=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " USLEEP"| wc -l`
if [ $USLEEP = 1 ]; then
	USLEEP_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " USLEEP"| grep " REQUIRED" |wc -l`
fi

if [ $USLEEP = 1 ]; then
    echo Testing for usleep... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for usleep */' >testdir/testtemp.c
    echo '#include <unistd.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'usleep(1);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	echo Yes
    else
	echo No
	EXTRADEFINES="$EXTRADEFINES -DNEED_OWN_USLEEP"
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $USLEEP_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

PYTHON=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PYTHON"| wc -l`
if [ $PYTHON = 1 ]; then
	PYTHON_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PYTHON"| grep " REQUIRED" |wc -l`
fi

if [ $PYTHON = 1 ]; then
    echo Checking for Python... |tr -d '\012'
    if [ -x "`which python`" ]; then
	echo Yes
	echo Extracting Python prefix dir...|tr -d '\012'

        # We really need python 2.0 or up. However on Redhat Linux systems this is named
        # python2 not python. Horrible!
        PYTHONEXE=python
        PTEST="`which python2 2>/dev/null`"
        if [ -x "$PTEST" ]; then
          PYTHONEXE=python2
        fi

	PYTHONDIR="`echo 'import os ; import sys ; print os.path.normpath(sys.prefix)' |$PYTHONEXE`"

	echo $PYTHONDIR

	echo Extracting Python version...|tr -d '\012'
	PVER=`echo "import sys; print sys.version[:3]" |$PYTHONEXE`
	echo $PVER


	if [ -n "$MINGW" ]; then
	    PYTHONDIR=`echo $PYTHONDIR |tr '\\\\' '/'`
	    PYTHONINCLUDE=`echo $PYTHONDIR/include`
	    PYTHONLIBDIR=`echo $PYTHONDIR/libs`
	else
	    PYTHONINCLUDE=`echo $PYTHONDIR/include/python$PVER`
	    PYTHONLIBDIR=`echo $PYTHONDIR/lib$LIB64/python$PVER`
	fi

	echo Assuming Python include directory: "$PYTHONINCLUDE"
	echo Assuming Python library directory: "$PYTHONLIBDIR"

	if [ -r "$PYTHONINCLUDE" ]; then
	    if [ -r "$PYTHONLIBDIR" ]; then

		if [ -n "$MINGW" ]; then
		    PYTHONLIB="`echo $PYTHONLIBDIR/libpython$PVER.a`"
		else
		    PYTHONLIB="`echo $PYTHONLIBDIR/config/libpython$PVER.a`"
		fi

		echo Assuming Python header file: "$PYTHONINCLUDE/Python.h"
		if [ -r "$PYTHONINCLUDE/Python.h" ]; then

		    echo Assuming Python library: "$PYTHONLIB"
		    if [ -r "$PYTHONLIB" ]; then
			
			echo Python C tests...|tr -d '\012'
			mkdir testdir
			echo '/* A test program for python */' >testdir/testtemp.c
			echo '#include <Python.h>' >>testdir/testtemp.c
			echo 'static PyObject *xx(PyObject *self, PyObject *args){' >>testdir/testtemp.c
			echo 'char *c;' >>testdir/testtemp.c
			echo 'PyArg_ParseTuple(args, "s", &c);' >>testdir/testtemp.c
			echo 'return NULL; }' >>testdir/testtemp.c
			echo 'static PyMethodDef p[]= {{"xx",xx,METH_VARARGS}};' >>testdir/testtemp.c
			echo 'DL_EXPORT(void) initxx(){Py_InitModule("xx",p);}' >>testdir/testtemp.c
			cd testdir
			MYEXITCODE=0
			if $CC -c $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES -I$PYTHONINCLUDE testtemp.c $PYTHONLIB $LIBS >/dev/null 2>&1; then
			    echo Yes
			    EXTRADEFINES="$EXTRADEFINES -DUSE_PYTHON"
			    INCLUDEDIRS="$INCLUDEDIRS -I$PYTHONINCLUDE"
			    LIBS="$PYTHONLIB $LIBS"
			    
    # Extract more information from python installation...
			    echo Extracting Python mod libraries...|tr -d '\012'
			    PLIBS="`echo 'import distutils.sysconfig ; print distutils.sysconfig.get_config_var("MODLIBS")' |$PYTHONEXE`"
			    if [ "x$PLIBS" = "xNone" ]; then
				PLIBS=""
			    fi
			    echo $PLIBS
			    LIBS="$LIBS $PLIBS"
			    
			    echo Extracting Python libraries...|tr -d '\012'
			    PLIBS="`echo 'import distutils.sysconfig ; print distutils.sysconfig.get_config_var("LIBS")' |$PYTHONEXE`"
			    if [ "x$PLIBS" = "xNone" ]; then
				PLIBS=""
			    fi
			    echo $PLIBS
			    LIBS="$LIBS $PLIBS"
			    
			    echo Extracting Python options...|tr -d '\012'
			    PLIBS="`echo 'import distutils.sysconfig ; print distutils.sysconfig.get_config_var("LINKFORSHARED")' |$PYTHONEXE`"
			    if [ "x$PLIBS" = "xNone" ]; then
				PLIBS=""
			    fi
			    echo $PLIBS
			    LIBS="$LIBS $PLIBS"
			else
			    echo No
			    MYEXITCODE=1
			fi
			cd ..
			rm -rf testdir
		    else
			echo Cannot read Python library "$PYTHONLIB"
			MYEXITCODE=1
		    fi
		else
		    echo Cannot read Python include file "$PYTHONINCLUDE/Python.h"
		    MYEXITCODE=1
		fi
	    else
		echo Python library directory "$PYTHONINCLUDE" problems
		MYEXITCODE=1
	    fi
	else
	    echo Python include directory "$PYTHONINCLUDE" problems
	    MYEXITCODE=1
	fi
    else
	echo No
	MYEXITCODE=1
    fi
    if [ $MYEXITCODE = 1 ]; then
	if [ $PYTHON_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

POSIX_DIRENT=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " POSIX_DIRENT"| wc -l`
if [ $POSIX_DIRENT = 1 ]; then
	POSIX_DIRENT_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " POSIX_DIRENT"| grep " REQUIRED" |wc -l`
fi

if [ $POSIX_DIRENT = 1 ]; then
    echo Testing for working POSIX directory management... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for posix directory management */' >testdir/testtemp.c
    echo '#include <unistd.h>' >>testdir/testtemp.c
    echo '#include <sys/types.h>' >>testdir/testtemp.c
    echo '#include <sys/stat.h>' >>testdir/testtemp.c
    echo '#include <dirent.h>' >>testdir/testtemp.c
    echo '#include <errno.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'DIR *mydir;' >>testdir/testtemp.c
    echo 'struct dirent *mydirent;' >>testdir/testtemp.c
    echo 'struct stat buf;' >>testdir/testtemp.c
    echo 'char *cdir,*cbuf;' >>testdir/testtemp.c
    echo 'mydir=opendir("");' >>testdir/testtemp.c
    echo 'mydirent=readdir(mydir);' >>testdir/testtemp.c
    echo 'stat(mydirent->d_name,&buf);' >>testdir/testtemp.c
    echo 'if (S_ISDIR(buf.st_mode))' >>testdir/testtemp.c
    echo 'rewinddir(mydir);' >>testdir/testtemp.c
    echo 'closedir(mydir);' >>testdir/testtemp.c
    echo 'cdir=getcwd(cbuf,1);' >>testdir/testtemp.c
    echo 'if (errno==ERANGE)' >>testdir/testtemp.c
    echo 'return 1;' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	echo Yes
    else
	echo No
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	if [ $POSIX_DIRENT_REQUIRED = 1 ]; then
	    echo Fatal: POSIX directory management does not work.
	    rm -rf Makefile.machine
	    exit 1
	fi
    fi
fi

X11_LIB=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " X11_LIB"| wc -l`
if [ $X11_LIB = 1 ]; then
	X11_LIB_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " X11_LIB"| grep " REQUIRED" |wc -l`
fi

if [ $X11_LIB = 1 ]; then
    echo Checking that X include files are there... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for the X include files */' >testdir/testtemp.c
    echo '#include <X11/Xlib.h>' >>testdir/testtemp.c
    echo '#include <X11/Xutil.h>' >>testdir/testtemp.c
    echo '#include <X11/X.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $XLIBS $LIBS >/dev/null 2>&1; then
	echo Yes
        DEFINES="$DEFINES -DUSE_X11"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
    # Had to copy X include files to this directory for some OS:s.
	INCLUDEDIRS="$INCLUDEDIRS -I"$HOME"/X11/include"
	mkdir testdir
	echo '/* A test program for the X include files */' >testdir/testtemp.c
	echo '#include <X11/Xlib.h>' >>testdir/testtemp.c
	echo '#include <X11/Xutil.h>' >>testdir/testtemp.c
	echo '#include <X11/X.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $XLIBS $LIBS >/dev/null 2>&1; then
	    echo Yes, in "$HOME"/X11/include.
	    DEFINES="$DEFINES -DUSE_X11"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    if [ $X11_LIB_REQUIRED = 1 ]; then
		echo Sorry, but the X include files are missing on your system,
		echo or they are in a non-standard directory. Add the non-standard
		echo directory to the configure file '(this one!)' or install them in
		echo "$HOME"/X11/include.
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    fi

    if [ $MYEXITCODE = 0 ]; then

	X11_DOUBLE=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " X11_DOUBLE"| wc -l`
	if [ $X11_DOUBLE = 1 ]; then
		X11_DOUBLE_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " X11_DOUBLE"| grep " REQUIRED" |wc -l`
	fi

	if [ $X11_DOUBLE = 1 ]; then
	    echo Testing for double buffer extension... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for the double buffer extension */' >testdir/testtemp.c
	    echo '#include <X11/Xlib.h>' >>testdir/testtemp.c
	    echo '#include <X11/Xutil.h>' >>testdir/testtemp.c
	    echo '#include <X11/X.h>' >>testdir/testtemp.c
	    echo '#include <X11/extensions/Xdbe.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'int maj,min,status; Display *display;' >>testdir/testtemp.c
	    echo 'status=XdbeQueryExtension(display,&maj,&min);' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0	    
	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $XLIBS $LIBS >/dev/null 2>&1; then
		echo Yes
		DEFINES="$DEFINES -DDOUBLEBUFFER"
	    else
		echo No
		MYEXITCODE=1
	    fi
	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		if [ $X11_DOUBLE_REQUIRED = 1 ]; then
		    rm -rf Makefile.machine
		    fatal_error_help
		    exit 1
		fi
	    fi
	fi	    

	X11_MULTI=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " X11_MULTI"| wc -l`
	if [ $X11_MULTI = 1 ]; then
		X11_MULTI_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " X11_MULTI"| grep " REQUIRED" |wc -l`
	fi

	if [ $X11_MULTI = 1 ]; then
	    echo Testing for multi buffer extension... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for the multi buffer extension */' >testdir/testtemp.c
	    echo '#include <X11/Xlib.h>' >>testdir/testtemp.c
	    echo '#include <X11/Xutil.h>' >>testdir/testtemp.c
	    echo '#include <X11/X.h>' >>testdir/testtemp.c
	    echo '#include <X11/extensions/multibuf.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'int eventbase,errorbase,status; Display *display;' >>testdir/testtemp.c
	    echo 'status=XmbufQueryExtension(display,&eventbase,&errorbase);' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0	    
	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $XLIBS $LIBS >/dev/null 2>&1; then
		echo Yes
		DEFINES="$DEFINES -DMULTIBUFFER"
	    else
		echo No
		MYEXITCODE=1
	    fi
	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		if [ $X11_MULTI_REQUIRED = 1 ]; then
		    rm -rf Makefile.machine
		    fatal_error_help
		    exit 1
		fi
	    fi
	fi	    


	XCO=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " XCO"| wc -l`
	if [ $XCO = 1 ]; then
		XCO_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " XCO"| grep " REQUIRED" |wc -l`
	fi
	    
	if [ $XCO = 1 ]; then
	    LIBDIRS="$LIBDIRS -L`pwd`/../Xco"
	    INCLUDEDIRS="$INCLUDEDIRS -I`pwd`/../Xco"
	    echo Checking for Xco... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for Xco */' >testdir/testtemp.c
	    echo '#include <X11/Xlib.h>' >>testdir/testtemp.c
	    echo '#include <Xco.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'XcoInit();' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0
	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c -lXco $XLIBS $LIBS >/dev/null 2>&1; then
		echo Yes
		DEFINES="$DEFINES -DUSE_XCO"
		XLIBS="-lXco $XLIBS"
	    else
		MYEXITCODE=1
	    fi
	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		mkdir testdir
		echo '/* A test program for Xco */' >testdir/testtemp.c
		echo '#include <X11/Xlib.h>' >>testdir/testtemp.c
		echo '#include <Xco.h>' >>testdir/testtemp.c
		echo 'int main(){' >>testdir/testtemp.c
		echo 'XcoInit();' >>testdir/testtemp.c
		echo 'return 0;}' >>testdir/testtemp.c
		cd testdir
		MYEXITCODE=0
		if $CC $MACHINEOPTS -I$USERLIB -L$USERLIB $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c -lXco $XLIBS $LIBS >/dev/null 2>&1; then
		    echo Yes, in "$USERLIB".
		    DEFINES="$DEFINES -DUSE_XCO"
		    XLIBS="-lXco $XLIBS"
		    LIBDIRS="$LIBDIRS -L$USERLIB"
		    INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
		else
		    MYEXITCODE=1
		fi
		cd ..
		rm -rf testdir
		if [ $MYEXITCODE = 1 ]; then
		    echo No
		    if [ $XCO_REQUIRED = 1 ]; then
			rm -rf Makefile.machine
			fatal_error_help
			exit 1
		    fi
		fi
	    fi
	fi
    fi
fi

Y4VM=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " Y4VM"| wc -l`
if [ $Y4VM = 1 ]; then
	Y4VM_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " Y4VM"| grep " REQUIRED" |wc -l`
fi

if [ $Y4VM = 1 ]; then
    LIBDIRS="$LIBDIRS -L`pwd`/../y4vm"
    INCLUDEDIRS="$INCLUDEDIRS -I`pwd`/../y4vm"
    echo Checking for Y4vm... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for y4vm */' >testdir/testtemp.c
    echo '#include <y4vm.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'vm_init();' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -ly4vm -lm>/dev/null 2>&1; then
	echo Yes
        DEFINES="$DEFINES -DUSE_Y4VM"
        LIBS="$LIBS -ly4vm -lm"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	mkdir testdir
	echo '/* A test program for y4vm */' >testdir/testtemp.c
	echo '#include <y4vm.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'vm_init();' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS -I$USERLIB -L$USERLIB $DEFINES $EXTRADEFINES testtemp.c $LIBS -ly4vm -lm >/dev/null 2>&1; then
	    echo Yes, in $USERLIB
	    DEFINES="$DEFINES -DUSE_Y4VM"
	    LIBS="$LIBS -ly4vm -lm"
	    LIBDIRS="$LIBDIRS -L$USERLIB"
	    INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $Y4VM_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    fi
fi

Y4_VERSION2=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " Y4_VERSION2"| wc -l`
if [ $Y4_VERSION2 = 1 ]; then
	Y4_VERSION2_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " Y4_VERSION2"| grep " REQUIRED" |wc -l`
fi

if [ $Y4_VERSION2 = 1 ]; then
    echo Checking for Y4vm2... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for y4vm2 */' >testdir/testtemp.c
    echo '#include <stdio.h>' >>testdir/testtemp.c
    echo '#include <stdlib.h>' >>testdir/testtemp.c
    echo '#include <y4vm2.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'y4vm_t *t=create_y4vm();' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -ly4vm2 -lm>/dev/null 2>&1; then
	echo Yes
        DEFINES="$DEFINES -DUSE_Y4VM2"
        LIBS="$LIBS -ly4vm2 -lm"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	mkdir testdir
	echo '/* A test program for y4vm2 */' >testdir/testtemp.c
	echo '#include <stdio.h>' >>testdir/testtemp.c
	echo '#include <stdlib.h>' >>testdir/testtemp.c
	echo '#include <y4vm2.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'y4vm_t *t=create_y4vm();' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS -I$USERLIB -L$USERLIB $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -ly4vm2 -lm >/dev/null 2>&1; then
	    echo Yes, in "$USERLIB".
	    DEFINES="$DEFINES -DUSE_Y4VM2"
	    LIBS="$LIBS -ly4vm2 -lm"
	    LIBDIRS="$LIBDIRS -L$USERLIB"
	    INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $Y4_VERSION2_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    fi
fi

LIBFIXPOINT=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LIBFIXPOINT"| wc -l`
if [ $LIBFIXPOINT = 1 ]; then
	LIBFIXPOINT_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LIBFIXPOINT"| grep " REQUIRED" |wc -l`
fi

if [ $LIBFIXPOINT = 1 ]; then
    echo Checking for libfixpoint... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for libfixpoint */' >testdir/testtemp.c
    echo '#include <fixpoint/fixpoint.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'fix_t f=dtofix16(1.,0.,2.);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -lfixpoint>/dev/null 2>&1; then
	echo Yes
        DEFINES="$DEFINES -DUSE_LIBFIXPOINT"
        LIBS="$LIBS -lfixpoint"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	mkdir testdir
	echo '/* A test program for libfixpoint */' >testdir/testtemp.c
	echo '#include <fixpoint/fixpoint.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'fix_t f=dtofix16(1.,0.,2.);' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS -I$USERLIB -L$USERLIB $DEFINES $EXTRADEFINES testtemp.c $LIBS -lfixpoint >/dev/null 2>&1; then
	    echo Yes, in $USERLIB
	    DEFINES="$DEFINES -DUSE_LIBFIXPOINT"
	    LIBS="$LIBS -lfixpoint"
	    LIBDIRS="$LIBDIRS -L$USERLIB"
	    INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $LIBFIXPOINT_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    fi
fi

LIBDUMP=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LIBDUMP"| wc -l`
if [ $LIBDUMP = 1 ]; then
	LIBDUMP_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LIBDUMP"| grep " REQUIRED" |wc -l`
fi

if [ $LIBDUMP = 1 ]; then
    echo Checking for libdump... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for libdump */' >testdir/testtemp.c
    echo '#include <libdump/libdump.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'DmpOpenWrite("hello",1,1,0.1);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -ldump>/dev/null 2>&1; then
	echo Yes
        DEFINES="$DEFINES -DUSE_LIBDUMP"
        LIBS="$LIBS -ldump"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	mkdir testdir
	echo '/* A test program for libdump */' >testdir/testtemp.c
	echo '#include <libdump/libdump.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'DmpOpenWrite("hello",1,1,0.1);' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS -I$USERLIB -L$USERLIB $DEFINES $EXTRADEFINES testtemp.c $LIBS -ldump >/dev/null 2>&1; then
	    echo Yes, in $USERLIB
	    DEFINES="$DEFINES -DUSE_LIBDUMP"
	    LIBS="$LIBS -ldump"
	    LIBDIRS="$LIBDIRS -L$USERLIB"
	    INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $LIBDUMP_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    fi
fi

LIBDMPNG=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LIBDMPNG"| wc -l`
if [ $LIBDMPNG = 1 ]; then
	LIBDMPNG_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " LIBDMPNG"| grep " REQUIRED" |wc -l`
fi

if [ $LIBDMPNG = 1 ]; then
    echo Checking for libdmpng... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for libdmpng */' >testdir/testtemp.c
    echo '#include <libdmpng/dmpng.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'DmpngOpenWrite("hello",1,1,0.1);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c -ldmpng $LIBS >/dev/null 2>&1; then
	echo Yes
        DEFINES="$DEFINES -DUSE_LIBDMPNG"
        LIBS="-ldmpng $LIBS"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	mkdir testdir
	echo '/* A test program for libdmpng */' >testdir/testtemp.c
	echo '#include <libdmpng/dmpng.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'DmpngOpenWrite("hello",1,1,0.1);' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS -I$USERLIB -L$USERLIB $DEFINES $EXTRADEFINES testtemp.c -ldmpng $LIBS >/dev/null 2>&1; then
	    echo Yes, in $USERLIB
	    DEFINES="$DEFINES -DUSE_LIBDMPNG"
	    LIBS="-ldmpng $LIBS"
	    LIBDIRS="$LIBDIRS -L$USERLIB"
	    INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $LIBDMPNG_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    fi
fi

READLINE=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " READLINE"| wc -l`
if [ $READLINE = 1 ]; then
	READLINE_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " READLINE"| grep " REQUIRED" |wc -l`
fi

if [ $READLINE = 1 ]; then
    echo Checking for GNU readline... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for readline */' >testdir/testtemp.c
    echo '#include <stdio.h>' >>testdir/testtemp.c
    echo '#include <readline/readline.h>' >>testdir/testtemp.c
    echo '#include <readline/history.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'readline("");' >>testdir/testtemp.c
    echo 'add_history("");' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0

    LIBTEST=1
    LIBLIST="-ltermcap -lcurses -lncurses"
    MORELIBS=""
    while [ "$LIBTEST" = "1" ]; do
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -lreadline $MORELIBS >/dev/null 2>&1; then
	    echo Yes |tr -d '\012'
	    DEFINES="$DEFINES -DUSE_READLINE"
	    LIBS="$LIBS -lreadline $MORELIBS"
	    if [ -n "$MORELIBS" ]; then
		echo ", together with $MORELIBS" 
	    else
		echo
	    fi
	    LIBTEST=0
	else
	    if [ -z "$LIBLIST" ]; then
		LIBTEST=0
		MYEXITCODE=1
	    else
		MORELIBS="`parse_first $LIBLIST`"
		LIBLIST="`parse_rest $LIBLIST`"
	    fi
	fi
    done
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	mkdir testdir
	echo '/* A test program for readline */' >testdir/testtemp.c
	echo '#include <stdio.h>' >>testdir/testtemp.c
	echo '#include <readline/readline.h>' >>testdir/testtemp.c
	echo '#include <readline/history.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'readline("");' >>testdir/testtemp.c
	echo 'add_history("");' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c

	cd testdir
	MYEXITCODE=0

	LIBTEST=1
	LIBLIST="-ltermcap -lcurses -lncurses"
	MORELIBS=""
	while [ "$LIBTEST" = "1" ]; do
	    if $CC $MACHINEOPTS -I$USERLIB -L$USERLIB $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -lreadline $MORELIBS >/dev/null 2>&1; then
		echo Yes, in "$USERLIB"|tr -d '\012'
		DEFINES="$DEFINES -DUSE_READLINE"
		LIBS="$LIBS -lreadline $MORELIBS"
		LIBDIRS="$LIBDIRS -L$USERLIB"
		INCLUDEDIRS="$INCLUDEDIRS -I$USERLIB"
		if [ -n "$MORELIBS" ]; then
		    echo ", together with $MORELIBS" 
		else
		    echo
		fi
		LIBTEST=0
	    else
		if [ -z "$LIBLIST" ]; then
		    LIBTEST=0
		    MYEXITCODE=1
		else
		    MORELIBS="`parse_first $LIBLIST`"
		    LIBLIST="`parse_rest $LIBLIST`"
		fi
	    fi
	done
        cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $READLINE_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi

    fi
fi

MPI=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " MPI"| wc -l`
if [ $MPI = 1 ]; then
	MPI_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " MPI"| grep " REQUIRED" |wc -l`
fi

if [ $MPI = 1 ]; then
    if [ "x $NOMPI" = "x " ]; then
	echo Looking for MPI... |tr -d '\012'
	mkdir testdir
	echo '/* A test program for the C compiler */' >testdir/testtemp.c
	echo '#include <stdio.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'printf("Hello World!*n");' |tr '*' '\\' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0	    	
	if $MPICC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -o hello >/dev/null 2>&1; then
	    echo Yes
	    CC="$MPICC"
	    DEFINES="$DEFINES -DUSE_MPI"
	else
	    echo No
	    MPICHBUG=0
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    if [ $MPI_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
    else
	MPICHBUG=0
    fi
else
    MPICHBUG=0
fi

IPC=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " IPC"| wc -l`
if [ $IPC = 1 ]; then
	IPC_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " IPC"| grep " REQUIRED" |wc -l`
fi

if [ $IPC = 1 ]; then
    if [ "x $NOIPC" = "x " ]; then
	echo Looking for SYSV IPC... |tr -d '\012'
	mkdir testdir
	echo '/* A test program for IPC */' >testdir/testtemp.c
	echo '#include <stdlib.h>' >>testdir/testtemp.c
	echo '#include <sys/types.h>' >>testdir/testtemp.c
	echo '#include <sys/ipc.h>' >>testdir/testtemp.c
	echo '#include <sys/shm.h>' >>testdir/testtemp.c
	echo '#include <sys/sem.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
  	echo 'struct sembuf myop;' >>testdir/testtemp.c
	echo 'int id=shmget(IPC_PRIVATE,1,0660|IPC_CREAT);' >>testdir/testtemp.c
	echo 'char *buf=shmat(id,0,0);' >>testdir/testtemp.c
	echo 'id=semget(IPC_PRIVATE,1,0660|IPC_CREAT);' >>testdir/testtemp.c
  	echo 'semop(id,&myop,1);' >>testdir/testtemp.c
  	echo 'shmctl (id,IPC_RMID,NULL);' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	    echo Yes
	    DEFINES="$DEFINES -DUSE_IPC"
	else
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $IPC_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	fi
	if [ $MYEXITCODE = 0 ]; then
	    echo Checking that system defines union semun... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for semun */' >testdir/testtemp.c
            echo '#ifndef _XOPEN_SOURCE' >>testdir/testtemp.c
            echo '#define _XOPEN_SOURCE' >>testdir/testtemp.c
            echo '#endif' >>testdir/testtemp.c
	    echo '#include <sys/types.h>' >>testdir/testtemp.c
	    echo '#include <sys/ipc.h>' >>testdir/testtemp.c
	    echo '#include <sys/shm.h>' >>testdir/testtemp.c
	    echo '#include <sys/sem.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'int id;' >>testdir/testtemp.c
	    echo 'union semun semopts;' >>testdir/testtemp.c
	    echo 'semctl(id,1,SETVAL,semopts);' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0
	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
		echo Yes
	    else
		echo No
		DEFINES="$DEFINES -DNEED_OWN_SEMUN_DEF"
		MYEXITCODE=1
	    fi
	    cd ..
	    rm -rf testdir
	fi
    fi
fi

BSDSOCK=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " BSDSOCK"| wc -l`
if [ $BSDSOCK = 1 ]; then
	BSDSOCK_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " BSDSOCK"| grep " REQUIRED" |wc -l`
fi

if [ $BSDSOCK = 1 ]; then
    if [ "x $NOBSDSOCK" = "x " ]; then
	echo Looking for BSD Sockets... |tr -d '\012'
	mkdir testdir
	echo '/* A test program for BSDSOCK */' >testdir/testtemp.c
	echo '#include <stdio.h>' >>testdir/testtemp.c
	echo '#include <string.h>' >>testdir/testtemp.c
	echo '#include <ctype.h>' >>testdir/testtemp.c
	echo '#include <stdlib.h>' >>testdir/testtemp.c
	echo '#include <unistd.h>' >>testdir/testtemp.c
	echo '#include <sys/types.h>' >>testdir/testtemp.c
	echo '#include <sys/socket.h>' >>testdir/testtemp.c
	echo '#include <netdb.h>' >>testdir/testtemp.c
	echo '#include <netinet/in.h>' >>testdir/testtemp.c
	echo '#include <arpa/inet.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'char *h;' >>testdir/testtemp.c
	echo 'struct sockaddr_in serv_addr;' >>testdir/testtemp.c
	echo 'int on=1;' >>testdir/testtemp.c
	echo 'gethostname(h,1);' >>testdir/testtemp.c
	echo 'gethostbyname(h);' >>testdir/testtemp.c
	echo 'ntohl(1);' >>testdir/testtemp.c
	echo 'socket(PF_INET,SOCK_STREAM,0);' >>testdir/testtemp.c
	echo 'setsockopt(on,SOL_SOCKET,SO_REUSEADDR,(char*)&on,sizeof(on));' >>testdir/testtemp.c
	echo 'serv_addr.sin_family=PF_INET;' >>testdir/testtemp.c
	echo 'serv_addr.sin_port=htons(1);' >>testdir/testtemp.c
	echo 'serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);' >>testdir/testtemp.c
	echo 'bind(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
        echo 'listen(on,1);' >>testdir/testtemp.c
	echo 'connect(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
	echo 'setsockopt(on,SOL_SOCKET,SO_KEEPALIVE,(char*) &on,sizeof(on));' >>testdir/testtemp.c
	echo 'accept(on,(struct sockaddr*) &serv_addr,&on);' >>testdir/testtemp.c
	echo 'inet_ntoa(serv_addr.sin_addr);' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0

	LIBTEST=1
	LIBLIST="-lsocket -lnsl"
	MORELIBS=""
	while [ "$LIBTEST" = "1" ]; do
	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS $MORELIBS >/dev/null 2>&1; then
		echo Yes |tr -d '\012'
		DEFINES="$DEFINES -DUSE_BSDSOCK"
		LIBS="$LIBS $MORELIBS"
		if [ -n "$MORELIBS" ]; then
		    echo ", in $MORELIBS" 
		else
		    echo
		fi
		LIBTEST=0
	    else
		if [ -z "$LIBLIST" ]; then
		    LIBTEST=0
		    MYEXITCODE=1
		else
		    MORELIBS="$MORELIBS `parse_first $LIBLIST`"
		    LIBLIST="`parse_rest $LIBLIST`"
		fi
	    fi
	done

	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then
	    echo No
	    if [ $BSDSOCK_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	else
	    echo Looking for TCP_NODELAY... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for BSDSOCK/TCP_NODELAY */' >testdir/testtemp.c
	    echo '#include <stdio.h>' >>testdir/testtemp.c
	    echo '#include <string.h>' >>testdir/testtemp.c
	    echo '#include <ctype.h>' >>testdir/testtemp.c
	    echo '#include <stdlib.h>' >>testdir/testtemp.c
	    echo '#include <unistd.h>' >>testdir/testtemp.c
	    echo '#include <sys/types.h>' >>testdir/testtemp.c
	    echo '#include <sys/socket.h>' >>testdir/testtemp.c
	    echo '#include <netdb.h>' >>testdir/testtemp.c
	    echo '#include <netinet/in.h>' >>testdir/testtemp.c
	    echo '#include <arpa/inet.h>' >>testdir/testtemp.c
	    echo '#include <netinet/tcp.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'char *h;' >>testdir/testtemp.c
	    echo 'struct sockaddr_in serv_addr;' >>testdir/testtemp.c
	    echo 'int on=1;' >>testdir/testtemp.c
	    echo 'struct protoent *proto;' >>testdir/testtemp.c
	    echo 'gethostname(h,1);' >>testdir/testtemp.c
	    echo 'gethostbyname(h);' >>testdir/testtemp.c
	    echo 'ntohl(1);' >>testdir/testtemp.c
	    echo 'socket(PF_INET,SOCK_STREAM,0);' >>testdir/testtemp.c
	    echo 'setsockopt(on,SOL_SOCKET,SO_REUSEADDR,(char*)&on,sizeof(on));' >>testdir/testtemp.c
	    echo 'serv_addr.sin_family=PF_INET;' >>testdir/testtemp.c
	    echo 'serv_addr.sin_port=htons(1);' >>testdir/testtemp.c
	    echo 'serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);' >>testdir/testtemp.c
	    echo 'bind(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
	    echo 'listen(on,1);' >>testdir/testtemp.c
	    echo 'connect(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
	    echo 'setsockopt(on,SOL_SOCKET,SO_KEEPALIVE,(char*) &on,sizeof(on));' >>testdir/testtemp.c
	    echo 'accept(on,(struct sockaddr*) &serv_addr,&on);' >>testdir/testtemp.c
	    echo 'inet_ntoa(serv_addr.sin_addr);' >>testdir/testtemp.c
	    echo 'proto=getprotobyname("tcp");' >>testdir/testtemp.c
	    echo 'setsockopt(on,proto->p_proto,TCP_NODELAY,(char*)&on,sizeof(on));' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0

	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS $MORELIBS >/dev/null 2>&1; then
		echo "Yes, we can attempt to disable Nagle algorithm!"
		DEFINES="$DEFINES -DUSE_TCP_NODELAY"
	    else
		MYEXITCODE=1
	    fi

	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		echo No
	    fi


	    echo Checking if system defines socklen_t... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for BSDSOCK/socklen_t */' >testdir/testtemp.c
	    echo '#include <stdio.h>' >>testdir/testtemp.c
	    echo '#include <string.h>' >>testdir/testtemp.c
	    echo '#include <ctype.h>' >>testdir/testtemp.c
	    echo '#include <stdlib.h>' >>testdir/testtemp.c
	    echo '#include <unistd.h>' >>testdir/testtemp.c
	    echo '#include <sys/types.h>' >>testdir/testtemp.c
	    echo '#include <sys/socket.h>' >>testdir/testtemp.c
	    echo '#include <netdb.h>' >>testdir/testtemp.c
	    echo '#include <netinet/in.h>' >>testdir/testtemp.c
	    echo '#include <arpa/inet.h>' >>testdir/testtemp.c
	    echo '#include <netinet/tcp.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'struct sockaddr_in caddr;' >>testdir/testtemp.c
	    echo 'socklen_t caddrlen=sizeof(caddr);' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0

	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS $MORELIBS >/dev/null 2>&1; then
		echo "Yes"
		DEFINES="$DEFINES -DHAS_SOCKLEN_T"
	    else
		MYEXITCODE=1
	    fi

	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		echo No
	    fi

	fi
    fi
fi

WINSOCK=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " WINSOCK"| wc -l`
if [ $WINSOCK = 1 ]; then
	WINSOCK_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " WINSOCK"| grep " REQUIRED" |wc -l`
fi

if [ $WINSOCK = 1 ]; then
    if [ "x $NOWINSOCK" = "x " ]; then
	echo Looking for WINSOCK... |tr -d '\012'
	mkdir testdir
	echo '/* A test program for WINSOCK */' >testdir/testtemp.c
	echo '#include <stdio.h>' >>testdir/testtemp.c
	echo '#include <string.h>' >>testdir/testtemp.c
	echo '#include <ctype.h>' >>testdir/testtemp.c
	echo '#include <stdlib.h>' >>testdir/testtemp.c
	echo '#include <winsock.h>' >>testdir/testtemp.c
	echo 'int main(){' >>testdir/testtemp.c
	echo 'char *h;' >>testdir/testtemp.c
	echo 'struct sockaddr_in serv_addr;' >>testdir/testtemp.c
	echo 'int on=1;' >>testdir/testtemp.c
	echo 'gethostname(h,1);' >>testdir/testtemp.c
	echo 'gethostbyname(h);' >>testdir/testtemp.c
	echo 'ntohl(1);' >>testdir/testtemp.c
	echo 'socket(PF_INET,SOCK_STREAM,0);' >>testdir/testtemp.c
	echo 'setsockopt(on,SOL_SOCKET,SO_REUSEADDR,(char*)&on,sizeof(on));' >>testdir/testtemp.c
	echo 'serv_addr.sin_family=PF_INET;' >>testdir/testtemp.c
	echo 'serv_addr.sin_port=htons(1);' >>testdir/testtemp.c
	echo 'serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);' >>testdir/testtemp.c
	echo 'bind(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
        echo 'listen(on,1);' >>testdir/testtemp.c
	echo 'connect(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
	echo 'setsockopt(on,SOL_SOCKET,SO_KEEPALIVE,(char*) &on,sizeof(on));' >>testdir/testtemp.c
	echo 'accept(on,(struct sockaddr*) &serv_addr,&on);' >>testdir/testtemp.c
	echo 'inet_ntoa(serv_addr.sin_addr);' >>testdir/testtemp.c
	echo 'return 0;}' >>testdir/testtemp.c
	cd testdir
	MYEXITCODE=0
	if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS -lwsock32 >/dev/null 2>&1; then
	    echo Yes
	    DEFINES="$DEFINES -DUSE_WINSOCK"
	    LIBS="$LIBS -lwsock32"
	else
	    echo No
	    MYEXITCODE=1
	fi
	cd ..
	rm -rf testdir
	if [ $MYEXITCODE = 1 ]; then

	    if [ $WINSOCK_REQUIRED = 1 ]; then
		rm -rf Makefile.machine
		fatal_error_help
		exit 1
	    fi
	else
	    echo Looking for TCP_NODELAY... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for WINSOCK/TCP_NODELAY */' >testdir/testtemp.c
	    echo '#include <stdio.h>' >>testdir/testtemp.c
	    echo '#include <string.h>' >>testdir/testtemp.c
	    echo '#include <ctype.h>' >>testdir/testtemp.c
	    echo '#include <stdlib.h>' >>testdir/testtemp.c
	    echo '#include <winsock.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'char *h;' >>testdir/testtemp.c
	    echo 'struct sockaddr_in serv_addr;' >>testdir/testtemp.c
	    echo 'int on=1;' >>testdir/testtemp.c
	    echo 'struct protoent *proto;' >>testdir/testtemp.c
	    echo 'gethostname(h,1);' >>testdir/testtemp.c
	    echo 'gethostbyname(h);' >>testdir/testtemp.c
	    echo 'ntohl(1);' >>testdir/testtemp.c
	    echo 'socket(PF_INET,SOCK_STREAM,0);' >>testdir/testtemp.c
	    echo 'setsockopt(on,SOL_SOCKET,SO_REUSEADDR,(char*)&on,sizeof(on));' >>testdir/testtemp.c
	    echo 'serv_addr.sin_family=PF_INET;' >>testdir/testtemp.c
	    echo 'serv_addr.sin_port=htons(1);' >>testdir/testtemp.c
	    echo 'serv_addr.sin_addr.s_addr=htonl(INADDR_ANY);' >>testdir/testtemp.c
	    echo 'bind(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
	    echo 'listen(on,1);' >>testdir/testtemp.c
	    echo 'connect(on,(struct sockaddr*) &serv_addr,sizeof(serv_addr));' >>testdir/testtemp.c
	    echo 'setsockopt(on,SOL_SOCKET,SO_KEEPALIVE,(char*) &on,sizeof(on));' >>testdir/testtemp.c
	    echo 'accept(on,(struct sockaddr*) &serv_addr,&on);' >>testdir/testtemp.c
	    echo 'inet_ntoa(serv_addr.sin_addr);' >>testdir/testtemp.c
	    echo 'proto=getprotobyname("tcp");' >>testdir/testtemp.c
	    echo 'setsockopt(on,proto->p_proto,TCP_NODELAY,(char*)&on,sizeof(on));' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0

	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS $MORELIBS >/dev/null 2>&1; then
		echo "Yes, we can attempt to disable Nagle algorithm!"
		DEFINES="$DEFINES -DUSE_TCP_NODELAY"
	    else
		MYEXITCODE=1
	    fi

	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		echo No
	    fi


	    echo Checking if system defines socklen_t... |tr -d '\012'
	    mkdir testdir
	    echo '/* A test program for WINSOCK/socklen_t */' >testdir/testtemp.c
	    echo '#include <stdio.h>' >>testdir/testtemp.c
	    echo '#include <string.h>' >>testdir/testtemp.c
	    echo '#include <ctype.h>' >>testdir/testtemp.c
	    echo '#include <stdlib.h>' >>testdir/testtemp.c
	    echo '#include <winsock.h>' >>testdir/testtemp.c
	    echo 'int main(){' >>testdir/testtemp.c
	    echo 'struct sockaddr_in caddr;' >>testdir/testtemp.c
	    echo 'socklen_t caddrlen=sizeof(caddr);' >>testdir/testtemp.c
	    echo 'return 0;}' >>testdir/testtemp.c
	    cd testdir
	    MYEXITCODE=0

	    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS $MORELIBS >/dev/null 2>&1; then
		echo "Yes"
		DEFINES="$DEFINES -DHAS_SOCKLEN_T"
	    else
		MYEXITCODE=1
	    fi

	    cd ..
	    rm -rf testdir
	    if [ $MYEXITCODE = 1 ]; then
		echo No
	    fi

	fi
    fi
fi

ISNANINF=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " ISNANINF"| wc -l`
if [ $ISNANINF = 1 ]; then
	ISNANINF_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " ISNANINF"| grep " REQUIRED" |wc -l`
fi
if [ $ISNANINF = 1 ]; then
    echo Checking for isnan/isinf... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for isnan/isinf */' >testdir/testtemp.c
              
    echo '#include <math.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'double x;' >>testdir/testtemp.c
    echo 'isnan(x);' >>testdir/testtemp.c
    echo 'isinf(x);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	echo Yes
	DEFINES="$DEFINES -DHAS_ISNANINF"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	echo No
	if [ $ISNANINF_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

CLOCK_GETTIME=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " CLOCK_GETTIME"| wc -l`
if [ $CLOCK_GETTIME = 1 ]; then
	CLOCK_GETTIME_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " CLOCK_GETTIME"| grep " REQUIRED" |wc -l`
fi
if [ $CLOCK_GETTIME = 1 ]; then
    echo Checking for clock_gettime... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for clock_gettime */' >testdir/testtemp.c
              
    echo '#include <time.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'struct timespec tv;' >>testdir/testtemp.c
    echo 'clock_gettime(CLOCK_REALTIME,&tv);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	echo Yes
	DEFINES="$DEFINES -DUSE_CLOCK_GETTIME"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	echo No
	if [ $CLOCK_GETTIME_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

GETTIMEOFDAY=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " GETTIMEOFDAY"| wc -l`
if [ $GETTIMEOFDAY = 1 ]; then
	GETTIMEOFDAY_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " GETTIMEOFDAY"| grep " REQUIRED" |wc -l`
fi
if [ $GETTIMEOFDAY = 1 ]; then
    echo Checking for gettimeofday... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for gettimeofday */' >testdir/testtemp.c
              
    echo '#include <stdlib.h>' >>testdir/testtemp.c
    echo '#include <sys/time.h>' >>testdir/testtemp.c
    echo '#include <unistd.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'struct timeval tv;' >>testdir/testtemp.c
    echo 'gettimeofday(&tv,NULL);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	echo Yes
	DEFINES="$DEFINES -DUSE_GETTIMEOFDAY"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	echo No
	if [ $GETTIMEOFDAY_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi

FTIME=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " FTIME"| wc -l`
if [ $FTIME = 1 ]; then
	FTIME_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " FTIME"| grep " REQUIRED" |wc -l`
fi
if [ $FTIME = 1 ]; then
    echo Checking for ftime... |tr -d '\012'
    mkdir testdir
    echo '/* A test program for ftime */' >testdir/testtemp.c
              
    echo '#include <sys/timeb.h>' >>testdir/testtemp.c
    echo 'int main(){' >>testdir/testtemp.c
    echo 'struct timeb tp;' >>testdir/testtemp.c
    echo 'ftime(&tp);' >>testdir/testtemp.c
    echo 'return 0;}' >>testdir/testtemp.c
    cd testdir
    MYEXITCODE=0
    if $CC $MACHINEOPTS $INCLUDEDIRS $LIBDIRS $DEFINES $EXTRADEFINES testtemp.c $LIBS >/dev/null 2>&1; then
	echo Yes
	DEFINES="$DEFINES -DUSE_FTIME"
    else
	MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
	echo No
	if [ $FTIME_REQUIRED = 1 ]; then
	    rm -rf Makefile.machine
	    fatal_error_help
	    exit 1
	fi
    fi
fi


PORT3=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PORT3"| wc -l`
PORT3F77=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PORT3_F77"| wc -l`
PORT3F90=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PORT3_F90"| wc -l`
if [ $PORT3F90 = 1 ]; then
    PORT3=0
    if [ $PORT3F77 = 1 ]; then
	PORT3=1
    fi
fi

if [ $PORT3 = 1 ]; then
        PORT3_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PORT3"| grep " REQUIRED" |wc -l`
fi
 
if [ $PORT3 = 1 ]; then
    echo "Looking for port library (for FORTRAN77)..." |tr -d '\012'
    mkdir testdir
    echo 'C A test program for port' >testdir/testtemp.f
    echo '      program porttest' >>testdir/testtemp.f
    echo '      external myfun' >>testdir/testtemp.f
    echo '      call smnf(i,x, myfun,0.1)' >>testdir/testtemp.f
    echo '      stop' >>testdir/testtemp.f
    echo '      end' >>testdir/testtemp.f
    echo '      subroutine myfun(i,x,j,f)' >>testdir/testtemp.f
    echo '      return' >>testdir/testtemp.f
    echo '      end' >>testdir/testtemp.f
    cd testdir
    MYEXITCODE=0
    if $F77 $F77MACHINEOPTS testtemp.f $LIBDIRS -lport $LIBS >/dev/null 2>&1; then
        echo Yes
        LIBS="-lport $LIBS"
    else
        echo No
        MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
        if [ $PORT3_REQUIRED = 1 ]; then
            rm -rf Makefile.machine
            fatal_error_help
            exit 1
        fi
    fi
fi

PORT3F90=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PORT3_F90"| wc -l`
if [ $PORT3F90 = 1 ]; then
        PORT3F90_REQUIRED=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " PORT3_F90"| grep " REQUIRED" |wc -l`
fi
 
if [ $PORT3F90 = 1 ]; then
    echo "Looking for port library (for Fortran 90)..." |tr -d '\012'
    mkdir testdir
    echo '!A test program for port' >testdir/testtemp.f90
    echo 'program porttest' >>testdir/testtemp.f90
    echo 'external myfun' >>testdir/testtemp.f90
    echo 'call smnf(i,x, myfun,0.1)' >>testdir/testtemp.f90
    echo 'stop' >>testdir/testtemp.f90
    echo 'end' >>testdir/testtemp.f90
    echo 'subroutine myfun(i,x,j,f)' >>testdir/testtemp.f90
    echo 'return' >>testdir/testtemp.f90
    echo 'end' >>testdir/testtemp.f90
    cd testdir
    MYEXITCODE=0
    if $F90 $F90FLAGS testtemp.f90 $LIBDIRS -lport90 $LIBS >/dev/null 2>&1; then
        echo Yes
        LIBS="-lport90 $LIBS"
    else
        echo No
        MYEXITCODE=1
    fi
    cd ..
    rm -rf testdir
    if [ $MYEXITCODE = 1 ]; then
        if [ $PORT3F90_REQUIRED = 1 ]; then
            rm -rf Makefile.machine
            fatal_error_help
            exit 1
        fi
    fi
fi

GENERATE_PIC=`cat Makefilebody |tr '[a-z]' '[A-Z]' |grep "#" |grep "YUSE" |grep " GENERATE_PIC"| wc -l`
if [ $GENERATE_PIC = 1 ]; then
    MACHINEOPTS="$MACHINEOPTS $PICOPTS"
fi

else
    echo Disabled automatic detection...
fi

# Emit configuration
echo CASEINSENSITIVE="$CASEINSENSITIVE" >>Makefile.machine
echo CC="$CC" >>Makefile.machine
echo F77="$F77" >>Makefile.machine
echo EXTRADEFINES="$EXTRADEFINES" >>Makefile.machine
echo OSNAME="$OSNAME" >>Makefile.machine
echo OSFULLNAME="$OSFULLNAME" >>Makefile.machine
echo MACHINEOPTS="$MACHINEOPTS" >>Makefile.machine
echo DEBUGOPT="$DEBUGOPT" >>Makefile.machine
echo DEFINES="$DEFINES" >>Makefile.machine
echo GLLIBS="$GLLIBS" >>Makefile.machine
echo XLIBS="$XLIBS" >>Makefile.machine
echo FLIBS="$FLIBS" >>Makefile.machine
echo LIBS="$LIBS" >>Makefile.machine
echo F77MACHINEOPTS="$F77MACHINEOPTS" >>Makefile.machine
echo EXTRAOBJS="$EXTRAOBJS" >>Makefile.machine
echo F77WARNINGS="$F77WARNINGS" >>Makefile.machine
echo WARNINGS="$WARNINGS" >>Makefile.machine
echo FCPP="$STUPIDW32_SHELL $STUPIDW32_QUOTE $FCPP" >>Makefile.machine
echo INCLUDEDIRS="$INCLUDEDIRS" >>Makefile.machine
echo LIBDIRS="$LIBDIRS" >>Makefile.machine
echo TAR="$TAR" >>Makefile.machine
echo TAROPTS="$TAROPTS" >>Makefile.machine
echo COMPRESS="$COMPRESS" >>Makefile.machine
echo COMPRESSOPTS="$COMPRESSOPTS" >>Makefile.machine
echo SHAREDCOMMAND="$SHAREDCOMMAND" >>Makefile.machine
cat programversion.h >>Makefile.machine
echo COMPILEINFO='"'"$OSFULLNAME - Compiled `date` by `whoami` on `hostname`"'"' >>Makefile.machine
echo OSSTRING='"'"$OSSTRING"'"' >>Makefile.machine
if [ $MPICHBUG = 1 ]; then
    echo COMMONDEFINES='-DPROGRAMVERSION='"'\\\""'$(PROGRAMVERSION)'"\\\"'" '-DCOMPILEINFO='"'\\\""'$(COMPILEINFO)'"\\\"'" '-DOSSTRING='"'\\\""'$(OSSTRING)'"\\\"'" >>Makefile.machine
else
    echo COMMONDEFINES='-DPROGRAMVERSION='"'"'$(PROGRAMVERSION)'"'" '-DCOMPILEINFO='"'"'$(COMPILEINFO)'"'" '-DOSSTRING='"'"'$(OSSTRING)'"'" >>Makefile.machine
fi
echo CCOPTS='$(MACHINEOPTS) $(COMMONDEFINES) $(DEFINES) $(EXTRADEFINES)' >>Makefile.machine
echo FCPPOPTS='$(COMMONDEFINES) $(DEFINES) $(EXTRADEFINES)' >>Makefile.machine
echo F77OPTS='$(F77MACHINEOPTS)' >>Makefile.machine
echo F90="$F90" >>Makefile.machine
echo F90CPP="$F90CPP" >>Makefile.machine
echo F90FLAGS="$F90FLAGS" >>Makefile.machine
echo F90LIBS="$F90LIBS" >>Makefile.machine
cat Makefilebody >>Makefile.machine
else
    echo Cannot find Makefilebody.
    echo This is not the way to compile this program. Read the files README and INSTALL.
    exit 1
fi



