#!/bin/sh

if [ $# -gt 0 ]
then
    if [ $1 = "-help" -o $1 = "--help" ]
    then
        echo 'Recognized configure options:'
        echo ''
        echo 'Installation options:'
        echo '--include-prefix=/some/path      - path to install SOCI header files'
        echo '--lib-prefix=/some/path          - path to install SOCI libraries'
        echo ''
        echo 'MySQL options:'
        echo '--mysql-include=/some/path       - directory containing mysql.h'
        echo '--mysql-lib=/some/path           - directory containing libmysqlclient.[a|so]'
        echo ''
        echo 'Oracle options (if ORACLE_HOME variable is not set):'
        echo '--oracle-include=/some/path      - directory containing oci.h'
        echo '--oracle-lib=/some/path          - directory containing libclntsh.[a|so]'
        echo ''
        echo 'PostgreSQL options:'
        echo '--postgresql-include=/some/path  - directory containing libpq/libpq-fs.h'
        echo '--postgresql-lib=/some/path      - directory containing libpq.[a|so]'
        echo ''
        echo 'Test programs compilation options (not needed for library build):'
        echo '--boost-include=/some/path       - root include directory of Boost'
        echo '--boost-lib=/some/path           - root lib directory of Boost'
        echo ''
        exit
    fi
fi

mkdir -p build/unix/local
path="build/unix/local/parameters"
rm -f $path
touch $path
for param in $*
do
        echo $param >> $path
done

printf 'Trying to find the Tcl interpreter... '
tcl_found=0

for path in "/usr/bin/tclsh" \
            "/usr/local/bin/tclsh8.5" \
            "/usr/local/bin/tclsh8.4" \
            "/usr/local/bin/tclsh8.3"; do
    if [ -x $path ]
    then
        echo $path > build/unix/local/tcl
        echo $path
        tcl_found=1
        break
    fi
done

if [ $tcl_found -eq 0 ]
then
        echo 'NOT found.'
        echo 'Is the Tcl installed?'
        exit
fi

echo ''
cd build/unix; `cat local/tcl` parse-parameters.tcl

echo ''
echo 'Configure done.'
echo 'Yes, it was short.'
echo ''
echo 'You can now run make.'
