#!/bin/sh -x

# This is a driver script to build a pure binary, trivially installable
# .tar.gz distribution file.

# Log all output to PID based file

PKG=procps
 
exec < /dev/null > ../distlog-$$ 2>&1


# Verify that there is no RCS updating to be done

# LIST=`find -name \*,v|sed 's/RCS\/\(.*\),v/\1/g'`
for i in $LIST
do
    if ! rcsdiff $i > /dev/null 2>&1 ; then
	echo NOTE: $i out of sync
	errors=1
    fi
done

# Compile the package

if [ $# -gt 0 ]			# if given any arguments
    then make distclean		# clear everything out first
fi

if ! make
    then echo $PKG mkdist: compile/link error -- cannot continue > /dev/tty
         exit 2
fi

# Strip the binaries for minimal dist size (otherwise stripped with install)

file `find -perm +100 -type f` | grep ELF | sed 's/:.*//' | xargs strip


# Build the installer script

if [ -r mkinstall -a -x mkinstall ]
    then ./mkinstall
    else echo $PKG mkdist:  -- cannot continue > /dev/tty
         exit 3
fi


# Generate the tar exclude file

cat > /tmp/tarX-$$ <<- EOF
	*.[oa]
	*.bak
	*~
	.back
	RCS
	*,v
	.log-*
EOF

GZIP=-9
FILE=`pwd`
FILE=`basename $FILE`

cd ..
rm -f $FILE || :
tar -cvvzf $FILE.tgz -X /tmp/tarX-$$ $FILE

rm -f /tmp/tarX-$$

exit 0
