#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-bzip2
SRC=/devel/manpagesrc
INFO=$PKG/usr/info
TEX=/devel/texinfo-docs

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_bzip2.tar.gz

echo "+==============+"
echo "| bzip2-0.9.0b |"
echo "+==============+"
cd $TMP
tar xzvf $CWD/bzip2-0.9.0b.tar.gz
cd bzip2-0.9.0b
make
strip bzip2 bzip2recover
cat bzip2 > $PKG/bin/bzip2
cat bzip2recover > $PKG/bin/bzip2recover
cat bzip2.1 | gzip -9c > $PKG/usr/man/man1/bzip2.1.gz
echo '.so man1/bzip2.1' | gzip -9c > $PKG/usr/man/man1/bzip2recover.1.gz
cp -a LICENSE README bzip2.txt manual_*.html $PKG/usr/doc/bzip2
chown root.root $PKG/usr/doc/bzip2/*
chmod 644 $PKG/usr/doc/bzip2/*

# Build the package:
cd $PKG
tar czvf $TMP/bzip2.tgz .

# Warn of zero-length files:
for file in `find . -type f -print` ; do
 if [ "`filesize $file`" = "0" ]; then
  echo "WARNING: zero length file $file"
 fi
done

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/bzip2-0.9.0b
  rm -rf $PKG
fi