#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-ccache

VERSION=2.4
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf ccache-$VERSION
tar xzvf $CWD/ccache-$VERSION.tar.gz
cd ccache-$VERSION
chown -R root:root .
./configure --prefix=/usr
make
make install DESTDIR=$PKG
gzip -9 $PKG/usr/man/man1/*.1
mkdir -p $PKG/usr/doc/ccache-$VERSION
cp -a \
  web/index.html README \
  $PKG/usr/doc/ccache-$VERSION
# Strip binaries:
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/ccache-$VERSION-$ARCH-$BUILD.tgz

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