#!/bin/sh

echo
echo "*** configuring dstumbler v0.4 ***"
echo "*** by h1kari - (c) 2001 Dachb0den Labs ***"
echo

echo -n "checking for host os... "

if (test $1); then
  hostos=$1
else
  hostos=`(uname -sr) 2>/dev/null`
fi

# set compilation options based on the os
case $hostos in
  "NetBSD"*)
    hostos="netbsd"; echo $hostos
    cflags="-Wall -I/usr/local/include -I/usr/pkg/include"
    ldflags="-L/usr/pkg/lib -lncurses"
    curses="ncurses"
    cursesincl="/usr/pkg/include/ncurses.h" ;;
  "OpenBSD"*)
    hostos="openbsd"; echo $hostos
    cflags="-Wall -I/usr/local/include"
    ldflags="-lcurses"
    curses="curses"
    cursesincl="/usr/include/curses.h" ;;
  "FreeBSD"*)
    hostos="freebsd"; echo $hostos
    cflags="-Wall -I/usr/local/include"
    ldflags="-L/usr/local/lib -lncurses"
    curses="ncurses"
    cursesincl="/usr/include/ncurses.h" ;;
  *)
    hostos="unsupported"; echo $hostos;
    echo
    echo "** unable to determine host os **"
    echo "the configuration script was either unable to determine your os, or "
    echo "your current os isn't supported. if your system is supported, try "
    echo "specifying it when running ./configure <os>."
    echo
    exit 2 ;;
esac

# check for curses on the system before configuring
echo -n "checking for $curses... "
if ! (test -f $cursesincl); then
  echo "no"
  echo
  echo "** unable to find $curses **"
  echo "the configuration script was unable to determine that $curses is "
  echo "installed on your system. if you do not have it installed, please "
  echo "make sure it's installed before you try configuring again."
  exit 2
else
  echo "yes"
fi


# notify user of all configuration options
echo
echo "$hostos system configured with the following compilation options:"
echo "  CFLAGS=$cflags"
echo "  LDFLAGS=$ldflags"

# replace CFLAGS and LDFLAGS in config file with os dependant values
sed -e "s%@cflags@%$cflags%" -e "s%@ldflags@%$ldflags%" Makefile.in >Makefile

echo
echo "at this time you can make any last minute changes to the Makefile if "
echo "needed. once you are satisfied, run make to compile dstumbler."
echo

exit 0
