#!/bin/sh

if [ -f config.mk ]; then
  . ./config.mk
else
  . ./.config.mk
  if [ -f /etc/redhat-release ]; then MODDIR=REDHAT; fi
fi
INCMK=config.mk

# flush out INCMK file
echo -n > $INCMK
echo -e "\nWe'll automatically configure for modules versions and the wireless"
echo -e "extensions from your running kernel.  If you don't like this, you'll"
echo -e "need to force otherwise in the Makefile."
echo -e "\nWhen you execute \"make install\", the driver modules will be copied here."
echo -e "The default of \"REDHAT\" will use redhat default locations."
echo -ne "  Module location? [$MODDIR]: "
read MODDIRNEW
if [ ! -z $MODDIRNEW ]; then
	MODDIR=$MODDIRNEW
fi
echo MODDIR=$MODDIR >> $INCMK

if [ "fooREDHAT" = "foo$MODDIR" ]; then
	BINDIR=/usr/local/bin
	echo BINDIR=$BINDIR >> $INCMK
	echo -e "\nExecutables will be put in /usr/local/bin"
else
  echo -e "\nThe utility you will use to set run-time parameters goes in this"
  echo "subdirectory.  Put it where you put your executables."
  echo -ne "  Executables? [$BINDIR]: "
  read BINDIRNEW
  if [ ! -z $BINDIRNEW ]; then
	BINDIR=$BINDIRNEW
  fi
  echo BINDIR=$BINDIR >> $INCMK
fi

if [ "fooREDHAT" = "foo$MODDIR" ]; then
	MANDIR=/usr/local/man
	echo MANDIR=$MANDIR >> $INCMK
	echo -e "\nMan pages will be put in /usr/local/man"
else
  echo -e "\nThe man pages go in this subdirectory."
  echo -ne "  Man pages? [$MANDIR]: "
  read MANDIRNEW
  if [ ! -z $MANDIRNEW ]; then
	MANDIR=$MANDIRNEW
  fi
  echo MANDIR=$MANDIR >> $INCMK
fi

if [ "fooREDHAT" = "foo$MODDIR" ]; then
	LINUXH=/usr/include
	echo LINUXH=$LINUXH >> $INCMK
	echo -e "\nLinux header files are in /usr/include"
else
  echo -e "\nYour GCC header files should have a subdirectory called"
  echo "linux.  Note the GCC header-file location here."
  echo -ne "  System header files? [$LINUXH]: "
  read LINUXHNEW
  if [ ! -z $LINUXHNEW ]; then
	LINUXH=$LINUXHNEW
  fi
  echo LINUXH=$LINUXH >> $INCMK
fi

if [ "fooREDHAT" = "foo$MODDIR" ]; then
  if [ -r /proc/bus/pccard ]; then
	PCCARD=y
  	echo -e "\nPC Card support compiled in."
  else
	PCCARD=n
  	echo -e "\nNo PC Card support compiled in."
  fi
  echo PCCARD=$PCCARD >> $INCMK
  if [ $PCCARD = y -o $PCCARD = Y ]; then
	echo -e "\nPCMCIA header files are in $(echo $PCCARDH)."
  fi
  echo PCCARDH=$(echo $PCCARDH) >> $INCMK
else
  echo -e "\nWill this driver be used to drive a PC Card (PCMCIA)?  If so"
  echo "choose yes.  If you don't have PCMCIA on your system, it's"
  echo "best to say no."
  echo -ne "  PC Card support? [$PCCARD]: "
  read PCCARDNEW
  if [ ! -z $PCCARDNEW ]; then
	PCCARD=$PCCARDNEW
  fi
  echo PCCARD=$PCCARD >> ${INCMK}

  if [ $PCCARD = y -o $PCCARD = Y ]; then
	echo -e "\nWe need to know where you keep your PCMCIA header files.  Under"
	echo "this directory, there should be a directory called \"pcmcia\"."
	echo -ne "  pcmcia header files? [$(echo $PCCARDH)]: "
	read PCCARDHNEW
  fi
  if [ ! -z $PCCARDHNEW ]; then
	PCCARDH=$PCCARDHNEW
  fi
  echo PCCARDH=$(echo $PCCARDH) >> $INCMK
fi

echo -e "\nThis is the default CardType.  CardType tells the driver what type"
echo "of Proxim card you are using.  See README for more details."
echo -ne "  CardType default [$CARDTYPEVAL]: "
read CARDTYPEVALNEW
if [ ! -z $CARDTYPEVALNEW ]; then
	CARDTYPEVAL=$CARDTYPEVALNEW
fi
echo CARDTYPEVAL=$CARDTYPEVAL >> $INCMK

echo -e "\nDo you want to read the rest of your configuration from the" 
echo "running kernel (as opposed to reading from /usr/src/linux/.config)?"
echo -ne "  Read from running kernel [$RUNNING]: "
read RUNNINGNEW
if [ ! -z $RUNNINGNEW ]; then
	RUNNING=$RUNNINGNEW
fi
echo RUNNING=$RUNNING >> $INCMK
if [ $RUNNING = "n" -o $RUNNING = "N" ]; then
	. /usr/src/linux/.config
  	echo CONFIG_NET_RADIO=$CONFIG_NET_RADIO >> $INCMK
  	echo CONFIG_PCI=$CONFIG_PCI >> $INCMK
  	echo MODVERSIONS=$CONFIG_MODVERSIONS >> $INCMK
else
  CONFIG_NET_RADIO=n
  if [ -r /proc/net/wireless ]; then 
	CONFIG_NET_RADIO=y
  fi
  echo CONFIG_NET_RADIO=$CONFIG_NET_RADIO >> $INCMK

  CONFIG_PCI=n
  if /sbin/ksyms -a | grep pcibios >/dev/null; then
	CONFIG_PCI=y
  fi
  echo CONFIG_PCI=$CONFIG_PCI >> $INCMK

  MODVERSIONS=n
  if /sbin/ksyms -a | grep printk_R >/dev/null; then
  	MODVERSIONS=y
  fi
  echo MODVERSIONS=$MODVERSIONS >> $INCMK
fi

BUFFERNEW=y
if [ ! -z $BUFFERNEW ]; then
	BUFFER=$BUFFERNEW
fi
echo BUFFER=$BUFFER >> $INCMK

#echo -e "\nThere used to be a bug when using buffering so I had made it"
#echo "optional.  I think it's fixed so just say yes."
#echo -ne "  Put buffering in the driver? [${BUFFER}]: "
#read BUFFER

echo -e "\nDONE!"
echo -e "\nDo 'make modules modules_install' on this driver. Check the"
echo -e "README* files for configuration information.\n"
