#!/bin/sh
#
#   Make OpenAMQ source packages
#
#   Modified 2005/06/03 - mato@imatix.com
#
#   Creates OpenAMQ source package including all dependent products.
#
PRODUCTS="base foreign base2 gsl4 openamq"

for PRODUCT in $PRODUCTS; do
    echo "Preparing $PRODUCT sources..."
    cd $HOME/products/$PRODUCT
    rm -f *.tar.gz *.zip
    boom configure
    boom clean distsrc
    eval ${PRODUCT}_version=`boom version`
done

echo "Tagging CVS for $openamq_version..."
cvs commit -m "$openamq_version"
cvs -Q tag -RF `echo $openamq_version | sed 's/\./_/'`

echo "Building $openamq_version full package ($PRODUCTS)..."
rm -rf $openamq_version
mkdir  $openamq_version
cd     $openamq_version

cat<<END>build.sh
#!/bin/sh
#   Build and install OpenAMQ and framework products
#   Set the IBASE variable to the installation directory

if [ -z "$\IBASE" ]; then
    echo "The IBASE environment variable is not defined."
    echo "Set this to desired installation directory, e.g. $\HOME/ibase."
    echo "Then, add $\\\IBASE/bin to your PATH for best results."
    exit 1
fi
END

cat<<END>build.bat
@echo off
:-  Build and install OpenAMQ and framework products
:-  Set the IBASE variable to the installation directory

if "%IBASE%"=="" (
    echo The IBASE environment variable is not defined.
    echo Set this to desired installation directory, e.g. c:\ibase.
    echo Then, add ^%IBASE^%/bin to your PATH for best results.
    goto exit
)
END

for PRODUCT in $PRODUCTS; do
    eval ARCHIVE="\$${PRODUCT}_version"
    tar -xzf $HOME/products/$PRODUCT/$ARCHIVE-src.tar.gz

    echo "cd $ARCHIVE"               >>build.sh
    echo "sh ./boomake build install">>build.sh
    echo "cd .."                     >>build.sh

    echo "cd $ARCHIVE"           >>build.bat
    echo "boomake build install" >>build.bat
    echo "cd .."                 >>build.bat
done

cat<<END>>build.sh
echo "Finished building and installing OpenAMQ."
echo "The OpenAMQ server has been installed into $\IBASE/openamq/servers"
echo "and you can run the server from this directory or copy it elsewhere."
echo "OpenAMQ clients have been installed into $\IBASE/openamq/clients."
END

cat<<END>>build.bat
echo Finished building and installing OpenAMQ.
echo The OpenAMQ server has been installed into %IBASE%\\openamq\\servers
echo and you can run the server from this directory or copy it elsewhere.
echo OpenAMQ clients have been installed into %IBASE%\\openamq\\clients.
:exit
END

cd ..
echo "Building $openamq_version packages..."
rm *.zip *.tar.gz
pax -w $openamq_version | gzip -c > $openamq_version.tar.gz
zip -lqrm $openamq_version.zip $openamq_version

echo cd pub>response
echo bin>>response
echo put $openamq_version.zip>>response
echo put $openamq_version.tar.gz>>response
echo quit>>response
ftp openamq.org < response
rm response
echo "    Unix sources: http://openamq.org/pub/${openamq_version}.tar.gz"
echo "    Win32 sources: http://openamq.org/pub/${openamq_version}.zip"
echo "    Win32 binaries: http://openamq.org/pub/${openamq_version}-win32.zip"
