#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-oprofile
VERSION=0.8.1
ARCH=alpha
BUILD=1

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf oprofile-$VERSION
tar xjf $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?/*
rm -rf $PKG/usr/share/oprofile/{i386,ia64,arm,x86-64}
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n ../oprofile-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/oprofile.build.log
