#! /bin/sh

cd `dirname $0`
cd src

clear
cat <<@

Welcome to the compilation of WIMS (WWW Interactive Mathematics Server)!

This utility guides you interactively through the choice of compilation
options, then launches the compilation automatically.

If you want to compile WIMS with default options, just press [Enter].

If you want to personalize the compilation options, or if the default options
lead to compilation failures, type 'y' and press [Enter].

If you don't want to compile, press Ctrl-C to abort.

@
read -p "Interactive options (y/n)? [n] " ans

options=
 if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
 cat <<@

--------------------------------------------------------------------------

   WIMS compile options (the letter in the bracket is the default)

1. WIMS will build its own library, libwims. It can be compiled with
   either static or dynamic libwims. However, compiling with dynamic libwims
   is not recommended.
@
 read -p "   -- Compile with dynamic libwims (not recommended)? (y/n) [n] " ans
 if [ "$ans" = "y" ] || [ "$ans" = "Y" ]; then
  options="$options --with-dynamic"
 else
  options="$options --without-dynamic"
 fi
 cat <<@

2. This package includes an independent program, 'units-filter',
   which is used in physics/chemistry exercises for unit recognition.
   Its compilation requires flex.
@
 read -p "   -- Compile units-filter (y/n)? [y] " ans
 if [ "$ans" = "n" ] || [ "$ans" = "N" ]; then
  options="$options --without-units"
 else
  options="$options --with-units"
 fi
 cat <<@

3. This package includes an independent program, 'chemeq',
   which is used in physics/chemistry exercises for checking balancing
   conditions in chemical equations.
   Its compilation requires GNU C++ compiler and flex, and is known to
   present some compatibility problems. Say 'n' if you have trouble with it.
@
 read -p "   -- Compile chemeq (y/n)? [y] " ans
 if [ "$ans" = "n" ] || [ "$ans" = "N" ]; then
  options="$options --without-chemeq"
 else
  options="$options --with-chemeq"
 fi
 cat <<@

-----------------------------------------------------------------------

   Options: $options

@
 read -p "   Now press [Enter] to start compilation, or Ctrl-C to abort. " ans
fi

./configure $options || exit
if [ ! -f Makefile ]; then exit; fi
make clean || exit
make all || exit
cd ..
bin/mkindex
cat <<@

WIMS is successfully compiled and installed.
Now please su to root, and execute the script bin/wrapuid.

@

