# This is a semi-automatic script for building the binary packages.
# It is designed to be run on Cygwin,
# but it should run fine on Linux and other GNU environments.

set -x

ARCHIVES_DIR="/cygdrive/i/Compilations GNU/Sources GCC/zoo"
BUILD_DIR=$HOME/compil
INSTALL_DIR=/usr
PACKAGENAME=zoo
VERSION=-2-10-1
VERSIONPATCH=
VERSIONBIN=-bin-mintv4e
VERSIONBUILD=-`date +%Y%m%d`

cd $BUILD_DIR
tar jxvf "$ARCHIVES_DIR/$PACKAGENAME$VERSION.tar.bz2"
#mv $PACKAGENAME$VERSION $PACKAGENAME$VERSION$VERSIONPATCH
#tar jxvf "$ARCHIVES_DIR/$PACKAGENAME$VERSION.tar.bz2"
#cd $PACKAGENAME$VERSION$VERSIONPATCH
#bzcat "$ARCHIVES_DIR/$PACKAGENAME$VERSION$VERSIONPATCH.patch.bz2" |patch -p1
#cd ..

cd $PACKAGENAME$VERSION$VERSIONPATCH/v*

sed -i 's:#include "zooio.h"::g' addfname.c machine.c basename.c comment.c misc2.c options.c zoofilt.c zoo.c zoopack.c
sed -i 's:#include "zoo.h":#include "zoo.h"\n#include "zooio.h":g' addfname.c machine.c basename.c comment.c misc2.c options.c zoofilt.c zoo.c zoopack.c
sed -i 's:#include <sys/time.h>:#include <time.h>\n#include <sys/time.h>:g' bsd.c
sed -i 's:#include "zooio.h":#include "zoo.h"\n#include "zooio.h":g' prterror.c
sed -i 's:#include "errors.i":#include "zoo.h"\n#include "zooio.h"\n#include "errors.i":g' zoofilt.c
sed -i 's:#include "zooio.h"::g' fiz.c
sed -i 's:#include "zoofns.h"::g' fiz.c
sed -i 's:#include "zoo.h":#include "zoo.h"\n#include "zooio.h"\n#include "zoofns.h":g' fiz.c
sed -i 's:extern VOIDPTR memmove();:/*extern VOIDPTR memmove();*/:g' ar.h
make CC="m68k-atari-mint-gcc -mcpu=5475" CFLAGS="-O2 -fomit-frame-pointer -s -c -D__linux" LDFLAGS=-s zoo fiz

install -d binary-package$INSTALL_DIR/bin
install zoo fiz binary-package$INSTALL_DIR/bin
install -d binary-package$INSTALL_DIR/share/man/man1
install zoo.1 fiz.1 binary-package$INSTALL_DIR/share/man/man1
cd binary-package
gzip -9 ${INSTALL_DIR#/}/share/man/*/*

tar --owner=0 --group=0 -jcvf $PACKAGENAME$VERSION$VERSIONPATCH$VERSIONBIN$VERSIONBUILD.tar.bz2 ${INSTALL_DIR#/}
