#!/bin/sh

DOS=no

while [ "$1" != "" ]; do
	case "$1" in
	-dos)	DOS=yes; shift;;
	*)	break;;
	esac
done

if [ "$1" = "" -o "$1" = "" ]; then
	echo "Usage: makedist [-dos] binary archive"
	exit 1
fi

binary=$1
archive=$2

mkdir sketchy-bin
mkdir sketchy-bin/doc
mkdir sketchy-bin/doc/library
mkdir sketchy-bin/lib
mkdir sketchy-bin/src

cp LICENSE sketchy-bin
cp sketchy.image sketchy-bin

cp doc/index.html sketchy-bin/doc
cp doc/ndx2.html sketchy-bin/doc
cp doc/sk*.html sketchy-bin/doc
cp doc/sketchy.css sketchy-bin/doc
cp doc/toc2-x.html sketchy-bin/doc
cp doc/toc2.html sketchy-bin/doc

cp doc/library/* sketchy-bin/doc/library
cp lib/* sketchy-bin/lib
cp src/* sketchy-bin/src

if [ $DOS = yes ]; then
	cp $binary sketchy-bin
	cp dist/README.W9X sketchy-bin
	cp dist/sketchy.bat sketchy-bin
	for file in \
		sketchy-bin/LICENSE \
		sketchy-bin/README.W9X \
		sketchy-bin/lib/* \
		sketchy-bin/src/*
	do
		sed -i "" -e "s/$/
/" $file
	done
else
	mv $binary sketchy-bin
	cp dist/README.Unix sketchy-bin
	cp doc/sketchy.7 sketchy-bin/doc
	cp dist/sk.sh sketchy-bin/sk
	cp dist/install sketchy-bin
fi

mv sketchy-bin sketchy

if [ $DOS = yes ]; then
	zip -q9r $archive.zip sketchy
	cat ~/bin/unzipsfx-gcc.exe $archive.zip >$archive.exe
	rm $archive.zip
else
	tar cf $archive sketchy
	gzip -f9 $archive
fi

rm -rf sketchy

