set -e
echo -n "Searching C++ compiler ... "
if [ `which g++` ]
then
  echo yes
else
  echo no
  exit
fi

okay=yes
echo "Searching libraries:"
for LIB in SDL SDL_gfx SDL_ttf
do
  message=yes
  echo -n "library $LIB ... "
  if [ `ls -d /Development/lib/lib$LIB.so` ]
  then
    echo $message
  else
    okay=no
  fi
done

if [ $okay = no ]; then echo "Some libraries are missing, exit."; exit; fi

echo -n "Searching font files ... "
FONTDIR=/usr/share/fonts

if test $# -gt 1; then
  if test $1 = "--fontdir"; then
    shift
    FONTDIR="$1"
  else
    echo "unexpected option $1"
    exit
  fi
fi
FONTPATH=`find $FONTDIR -name FreeSans.ttf`
FONTPATH_BOLD=`find $FONTDIR -name FreeSansBold.ttf`
FONTPATH_MONO=`find $FONTDIR -name FreeMono.ttf`

if [ -z "$FONTPATH" ] || [ -z "$FONTPATH_BOLD" ] || [ -z "$FONTPATH_MONO" ]
then
  okay=no
else
  echo okay
fi

if [ $okay = no ]; then echo "TrueType font-spec not found, exit."; exit; fi

echo "const char* FONTPATH=\"$FONTPATH\";" > config.h
echo "const char* FONTPATH_BOLD=\"$FONTPATH_BOLD\";" >> config.h
echo "const char* FONTPATH_MONO=\"$FONTPATH_MONO\";" >> config.h
echo "Created: config.h. Now you can run 'make'"
 
