#!/bin/bash

#  Authors     [Robert Meolic (meolic@uni-mb.si)]
#  Revision    [$Revision: 51 $]
#  Date        [$Date: 2013-04-03 17:57:12 +0200 (sre, 03 apr 2013) $]
#
#  Copyright   [This file is part of Biddy.
#               Copyright (C) 2006, 2013 UM-FERI
#               UM-FERI, Smetanova ulica 17, SI-2000 Maribor, Slovenia
#
#               Biddy is free software; you can redistribute it and/or modify
#               it under the terms of the GNU General Public License as
#               published by the Free Software Foundation; either version 2
#               of the License, or (at your option) any later version.
#
#               Biddy is distributed in the hope that it will be useful,
#               but WITHOUT ANY WARRANTY; without even the implied warranty of
#               MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#               GNU General Public License for more details.
#
#               You should have received a copy of the GNU General Public
#               License along with this program; if not, write to the Free
#               Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
#               Boston, MA 02110-1301 USA.]

# use CFLAGS="-m64" to produce 64-bit files on 32-bit system

NAME="biddy"
VERSION=`sed "s|\.|-|g" VERSION`
OS=`uname | sed "s/_.*//;s/[0-9]//g"`
CFLAGS=""

rm -f "$NAME-bin-$VERSION-$OS.zip"
rm -f "$NAME-$VERSION-$OS.zip"

rm -fr "./$NAME-$VERSION"

make "CFLAGS = $CFLAGS" "BINDIR = ../biddy/$NAME-$VERSION"
make clean "BINDIR = ../biddy/$NAME-$VERSION"

cp COPYING "./$NAME-$VERSION/"
cp CHANGES "./$NAME-$VERSION/"
cp biddy.h "./$NAME-$VERSION/"

echo "Creating $NAME-bin-$VERSION-$OS.zip ..."
zip -y -o "$NAME-bin-$VERSION-$OS.zip" "./$NAME-$VERSION"/* -x "./$NAME-$VERSION"/biddy.h -x "./$NAME-$VERSION"/libbiddy.a -x "./$NAME-$VERSION"/*.so
if [ -e "./$NAME-$VERSION"/libbiddy.so ] && [ ! -L "./$NAME-$VERSION"/libbiddy.so ] ; then
  zip -y -o "$NAME-bin-$VERSION-$OS.zip" "./$NAME-$VERSION"/libbiddy.so
fi

echo "Creating $NAME-$VERSION-$OS.zip ..."
zip -y -o "$NAME-$VERSION-$OS.zip" "./$NAME-$VERSION"/*

rm -fr "./$NAME-$VERSION"

echo ""
echo "*******************"
echo "PACKAGES COMPLETED!"
echo "*******************"
echo ""
