#!/bin/bash

#!/bin/sh

# source shflags from current directory
. ./shflags

# define a 'prefix' command-line string flag
DEFINE_string 'prefix' '/usr/local/tol32' 'location to install' 'p'
DEFINE_string 'withtcl' '/usr/lib/tcl8.4' 'location of tclConfig.sh' 't'

# parse the command-line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"

# dump configuration
echo "prefix=${FLAGS_prefix}"
echo "withtcl=${FLAGS_withtcl}"

pushd ../tol
./bjam-gcc-release --prefix=${FLAGS_prefix}
./sudo_install --prefix=${FLAGS_prefix}
popd

pushd ../toltcl/release
./default_config.sh --with-tcl=${FLAGS_withtcl} --with-tol=${FLAGS_prefix}
make
sudo make install
popd

pushd ../tolsh
./build.sh
sudo cp Linux/tolsh3.2 ${FLAGS_prefix}/bin/tolsh
popd

# first execution of TOL under current user is to create tolcore.oza
${FLAGS_prefix}/bin/tolsh -c "Real 1"
# this execution is to download last version of default packages
sudo ${FLAGS_prefix}/bin/tolsh -c "TolPackage::Client::DefaultFetch(?)"
