#!/usr/local/bin/bash

if [ $# != 2 ]
then
	echo "usage: make_binary_dist <fileroot> <os>"
	echo "example: make_binary_dist linkbin Linux-2.X-ix86"
	echo "example: make_binary_dist linkbin SunOS-5.5.1-sun4"
	exit 1
fi

echo $1

if [ ! -f CHANGELOG ]
then
	echo "error: couldn't find CHANGELOG -- is this a link root directory?"
	exit 1
fi

if [ ! -f src/Link ]
then
	echo "error: executable src/Link doesn't exist"
	exit 1
fi

mkdir -p /tmp/link_bindir/STk
mkdir -p /tmp/link_bindir/stklos
mkdir -p /tmp/link_bindir/$2

cp $STK_LIBRARY/STk/* /tmp/link_bindir/STk
cp $STK_LIBRARY/$2/hash.so /tmp/link_bindir/$2/.
cp -R $STK_LOAD_PATH/* /tmp/link_bindir/stklos
cp src/Link /tmp/link_bindir/Link
cp CHANGELOG /tmp/link_bindir/CHANGELOG
cp COPYRIGHTS /tmp/link_bindir/COPYRIGHTS
cp GUI_QUICKREF /tmp/link_bindir/GUI_QUICKREF
cp $STK_LIBRARY/prolog.ps /tmp/link_bindir/.
cp bin/binary.readme /tmp/link_bindir/README
cp bin/binary.makefile /tmp/link_bindir/Makefile

pushd /tmp
tar cf $1.tar link_bindir
gzip $1.tar
popd
mv /tmp/$1.tar.gz .

rm -rf /tmp/link_bindir
