: /bin/sh
set +x

####
## This script gets some directory locations to use in the Makefile
####

help ( ) {
echo "configure commands available:"
echo ""
echo "--help			displays this page"
echo "--prefix=PREFIX		use PREFIX as install directory"
echo "--with-tk			build and install TK"
exit 0
}

build_tk=no
ap_base=""

if [ $# != "0" ]
then
  for i in $@
  do
    case $i in
    --help)	help ;;
    --prefix*) ap_base=`echo $i | sed -e 's/^[^=]*=//g'` ;install_apache=yes ;;
    --with-tk) build_tk=yes ;;
    *)		echo "Invalid command option $i" ; help ; exit 1 ;;
    esac
  done

fi

if [ "$ap_base" = "" ]
then
  ap_base=/usr/local/apache

  echo "Configuration of NeoWebScript."

  cat << EOF
Where would you like NeoWebScript on your system? [$ap_base]
EOF

  read ans
  if [ "$ans" = "" ]
  then
    if [ "$ap_base" = "" ]
    then
      echo "I am sorry, but I must insist that you let us know where to install NeoWebScript."
      exit 1
    fi
  else
    ap_base=$ans
  fi

  # Look for Apache, and warn the user if it is there
  install_apache=yes
  if [ -d $ap_base ]
  then
    cat << EOF
The directory $ap_base exists already.  Do you want to
[O]verwrite, [A]bort Apache install but install everything else, or [Q]uit?
[O/A/Q] 
EOF

  read ans
  if [ "$ans" = "A" -o "$ans" = "a" ]
  then
    install_apache=no
  elif [ "$ans" = "Q" -o "$ans" = "q" ]
  then
    exit 1
  fi
  
fi

fi

if [ $install_apache = "yes" ]
then
    (
    cd apache_1.3.6
    ./configure --prefix=${ap_base} --enable-rule=SHARED_CORE --enable-module=so
    )
fi

(
cd neotcl8.1.1-lite
if [ "$build_tk" = "yes" ]
then
  ./configure --prefix=${ap_base} --enable-shared --enable-gcc --disable-make
else
  ./configure --prefix=${ap_base} --enable-shared --enable-gcc --disable-make \
	--without-tk --enable-tk=NO
fi
)

(
cd modules
./configure --enable-shared --prefix=${ap_base}
)

(
cd tools
./configure --prefix=${ap_base}
)

####
## Write this info into the final Makefile
####
cat > Makefile << EOF
##
## Locations to install NeoWebScript
## Constructed from configure script
##

PREFIX=$ap_base
INSTALL_APACHE=$install_apache


EOF

cat < Makefile.in >> Makefile

cat << EOF
You may now do a "make"

Thank you!
EOF

