#!/bin/sh

echo -n "checking os type... "
OS=`uname`
echo $OS

echo -n "checking stdint.h... "
if [ -f /usr/include/stdint.h ]
then
    DEFINES="$DEFINES -DHAVE_STDINT"
    echo "ok"
else
    echo "fail"

    echo -n "checking inttypes.h... "
    if [ -f /usr/include/inttypes.h ]
    then
	DEFINES="$DEFINES -DHAVE_INTTYPES"
	echo "ok"
    else
	echo "fail"
	echo "You need either stdint.h or inttypes.h to compile this"
	exit 1
    fi
fi

if [ "$OS"=="Linux" ]
then
    DEFINES="$DEFINES -DLINUX"
    echo -n "checking gmake... "
    gmake --version > /dev/null 2> /dev/null
    if [ $? -eq 0 ]
    then
	MAKE="gmake"
	echo "ok"
    else
	echo "fail"
	echo -n "checking make... "
	make --version > /dev/null 2> /dev/null
	if [ $? -eq 0 ]
	then
	    echo "ok"
	    MAKE="make"
	else
	    echo "fail"
	    echo "You need a GNU Make to compile this"
	    exit 1
	fi
    fi
else
    if [ "$OS"=="FreeBSD" ]
    then
	DEFINES="$DEFINES -DFREEBSD"
	echo -n "checking gmake... "
	gmake --version > /dev/null 2> /dev/null
	if [ $? -eq 0 ]
	then
	    echo "ok"
	    MAKE="gmake"
	else
	    echo "fail"
	    echo "You need a GNU Make to use this"
	    exit 1
	fi
    else
	echo "This version of software is only compatible with Linux and FreeBSD"
	exit 1
    fi
fi

echo "Configuration successfull. Details:"
echo -e "\tOS: $OS"
echo -e "\tGNU Make utility: $MAKE"
echo -e "\nType $MAKE and $MAKE install now"

rm -f make.conf
echo "OS = $OS" >> make.conf
echo "DEFINES = $DEFINES" >> make.conf