#!/bin/sh
CWD=`pwd`
PKG=/tmp/package-oprofile

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

rm -rf $PKG
mkdir -p $PKG
cd /tmp
rm -rf oprofile-$VERSION
tar xjvf $CWD/oprofile-$VERSION.tar.bz2
cd oprofile-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
./configure \
  --prefix=/usr
make
make install DESTDIR=$PKG
# This seems misplaced, and isn't referenced by any binaries or other files.
# I'm tempted to think it shouldn't have been installed, but will just move it:
if [ -r $PKG/usr/share/mangled-name ]; then
  mv $PKG/usr/share/mangled-name $PKG/usr/share/oprofile/mangled-name
fi
( cd $PKG/usr/bin
  strip *
  chown -R root.bin .
)
mv $PKG/usr/share/doc $PKG/usr
mv $PKG/usr/doc/oprofile $PKG/usr/doc/oprofile-$VERSION
cp -a \
  COPYING README TODO \
  $PKG/usr/doc/oprofile-$VERSION
gzip -9 $PKG/usr/man/man?/*

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
makepkg -l y -c n ../oprofile-$VERSION-$ARCH-$BUILD.tgz

