#!/bin/sh
CWD=`pwd` 
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-librep

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

cd $TMP
tar xzvf $CWD/librep-0.13.6.tar.gz
cd librep-0.13.6
CFLAGS=-O2 ./configure --prefix=/opt/gnome \
                       --sysconfdir=/etc/opt/gnome \
                       --with-gnu-ld \
                       --with-readline \
                       sparc-slackware-linux
make
make DESTDIR=$PKG install
mkdir -p $PKG/usr/doc/librep-0.13.6
cp -a AUTHORS BUGS COPYING ChangeLog HACKING INSTALL NEWS README \
   THANKS TODO TREE $PKG/usr/doc/librep-0.13.6
chown -R root.root $PKG/usr/doc/librep-0.13.6
find $PKG/usr/doc/librep-0.13.6 -type f -exec chmod 644 {} \;
find $PKG/usr/doc/librep-0.13.6 -type d -exec chmod 755 {} \;
rm $PKG/opt/gnome/info/dir
gzip -9 $PKG/opt/gnome/info/*

# Build the package:
cd $PKG
echo "y
n" | makepkg $TMP/librep.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
 if [ "`filesize $file`" = "20" ]; then
  echo "WARNING: possible empty gzipped file $file"
 fi
done

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