#!/bin/sh

# script to setup library and auto generated files.

function setversion() {
    eval `sed -n 's/^\([A-Z]*\)=\([p0-9].*\)$/\1=\2/p' Variables.make`
    NEWVER=$MAJVER.$MINVER.$PATCHLEVEL
    echo
    echo "Current  version ("`pwd`") is $NEWVER"
    echo
}

MAKE=${MAKE:-make}
PREFIX=${PREFIX:-.}
NEEDFLOWERVER=1.1.2

echo using PREFIX=$PREFIX
echo I need Flower version $NEEDFLOWERVER

flowertar=flower-$NEEDFLOWERVER
here=`pwd`
cd ..

if [ -x flower ]
then
    echo Found flowerdir
else

    if [ ! -d $flowertar ]
    then
	echo "can't find $flowertar"
	exit 1;
    fi
    rm flower
    ln -s $flowertar flower
fi

echo Compiling Library
{
    cd flower;
    setversion
    if [ $NEWVER != $NEEDFLOWERVER ]; then
	echo "You seem to be having an incorrect version of the Flower library"
    else
	echo "You got the correct Flower version."
    fi
    $MAKE
}

cd $here

echo '#define LIBDIR "'$PREFIX'/"'> hdr/config.hh
touch Site.make
$MAKE -f Initial.make

echo "The sources are ready for compiling. "
echo "To make sure that you don't have any stale dependencies: do"
echo "		make clean"
