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

VERSION=15.5
ARCH=i486
BUILD=2

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

cd $TMP
rm -rf cscope-$VERSION
tar xzvf $CWD/cscope-$VERSION.tar.gz
cd cscope-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 666 -exec chmod 644 {} \;
./configure --prefix=/usr
make
make install DESTDIR=$PKG
chown -R root.bin $PKG/usr/bin
( 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
)
gzip -9 $PKG/usr/man/man1/cscope.1
mkdir -p $PKG/usr/doc/cscope-$VERSION
cp -a \
  AUTHORS COPYING INSTALL NEWS README TODO \
  $PKG/usr/doc/cscope-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

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

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