#! /bin/sh


rm -f config.cache

if [ ! -f configure ]; then
    echo "ERROR: unable to find 'configure'"
    echo "execute this program at kinoko/src directory"
    exit
fi


export CXX
export CPPFLAGS
export CXXFLAGS
export MAKE
export KINOKO_ROOT


KINOKO_ROOT=`cd ..; pwd`
echo "KINOKO_ROOT: $KINOKO_ROOT"


if [ -z $1 ]; then
    SYSTEM="OTHER";
else
    SYSTEM=$1;
fi

if [ -z $2 ]; then
    CXXFLAGS="$CXXFLAGS";
else
    CXXFLAGS="$CXXFLAGS $2";
fi


if [ $SYSTEM = "LINUX" ]; then
    CXX="g++";
    CPPFLAGS="";
    CXXFLAGS="$CXXFLAGS -Wall";
    ./configure --with-root

elif [ $SYSTEM = "LINUX-FULL" ]; then
    CXX="g++";
    CPPFLAGS="";
    CXXFLAGS="$CXXFLAGS -Wall";
    ./configure --with-PostgreSQL --with-MySQL --with-SQLite --with-gemini --with-root

elif [ $SYSTEM = "LINUX-MIN" ]; then
    CXX="g++";
    CPPFLAGS="";
    CXXFLAGS="$CXXFLAGS";
    ./configure --without-readline --without-zlib

elif [ $SYSTEM = "SOLARIS" ]; then
    CXX="CC";
    CPPFLAGS="-I/opt/stl"; 
    CXXFLAGS="$CXXFLAGS -instances=static -xwe -xildoff";
    ./configure

elif [ $SYSTEM = "SOLARIS-FORCE" ]; then
    CXX="CC";
    CPPFLAGS="-I/opt/stl"; 
    CXXFLAGS="$CXXFLAGS -instances=static -xwe -xildoff";
    ./configure --with-frcvme="/opt/FRCvme" --with-kekcamlib="/opt/CAMAC"

elif [ $SYSTEM = "AIX" ]; then
    CXX="xlC";
    CPPFLAGS="";
    CXXFLAGS="$CXXFLAGS -Wl,-bbigtoc -qstaticinline";
    MAKE="gmake";
    ./configure

elif [ $SYSTEM = "AIX64" ]; then
    CXX="xlC";
    CPPFLAGS="";
    CXXFLAGS="$CXXFLAGS -q64 -Wl,-bbigtoc";
    MAKE="gmake";
    ./configure

elif [ $SYSTEM = "AIX-GCC" ]; then
    CXX="g++";
    CPPFLAGS="";
    CXXFLAGS="$CXXFLAGS";
    MAKE="gmake";
    ./configure

else
    CXXFLAGS="$CXXFLAGS";
    ./configure 
fi
