#!/bin/sh
# Portable System Interface Copyright (c) 1997-1998 Tycho Softworks.
# $Id: dist 1.4 Sat, 19 Sep 1998 20:16:33 -0400 dyfet $

if test ! -f config.pkg ; then
	echo "dist: config.pkg missing!"
fi

# defaults!

config="config.pkg config Makefile.in `echo *.spec` `echo sdk/bin/*`"
exclude="*.so *.do *.o *.a config.cc config.install _config.h config.cache config *.tar.gz *~ .* core Makefile .backup"
exclude_exe="true"
exclude_files=".EXCLUDE"

. ./config.pkg

root=`pwd`

if test -z "$VERSION" ; then
	version='unknown'
else
	version=$VERSION
fi

if test -z "$PACKAGE" ; then
	package=`basename $root`
else
	package=$PACKAGE
fi

dist=$package'-'$version
cd ..

if test ! $dist = $root ; then
	rm -f $dist
	ln -s $root $dist
fi

xlist=$dist/.EXCLUDE
echo -n >$xlist
for file in $exclude_files ; do
	echo $dist/$file >>$xlist
done

flist=""
include=$DOCUMENTS
examine="sdk "$DISTRIBUTE

for cfg in $include $config ; do
	if test -f "$dist/$cfg" ; then
		flist=$flist' '$dist/$cfg
	fi
done

for dir in $examine ; do
	flist=$flist' '$dist/$dir
	if test $exclude_exe = "true" ; then
		find $dist/$dir -perm +1 -type f -follow -print >>$xlist
	fi
	for deny in $exclude ; do
		find $dist/$dir -follow -name $deny -print >>$xlist
	done
done

target=$dist/$dist.tar.gz
tar -X $xlist -cvhzf $target $flist


if [ ! $dist = $root ] ; then
	rm $dist
fi


