#!/bin/sh
# Heavily based on the Slackware 13.0 SlackBuild
# http://www.kernel.org/pub/linux/utils/kernel/cpufreq/cpufrequtils.html

# Upgraded by Leonardo Totaro - elleti.brain)(vision
# ( brainvision AT slacky DOT it )
# http://www.slacky.eu

CWD=`pwd`
if ["$TMP" = ""]; then
 TMP=/tmp
fi
PKG=$TMP/package-cpufrequtils
NAME=cpufrequtils
VERSION=007
ARCH=${ARCH:-i686}
BUILD=1pg

if [ -d $TMP/$NAME-$VERSION ];then
 rm -r $TMP/$NAME-$VERSION
fi
mkdir -p $TMP
if [ -d $PKG ]; then
 rm -r $PKG
fi
mkdir -p $PKG

cd $TMP
tar xjvf $CWD/$NAME-$VERSION.tar.bz2

cd $NAME-$VERSION

chown -R root:root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 666 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;

make
make install DESTDIR=$PKG 
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a \
AUTHORS COPYING README \
 $PKG/usr/doc/$NAME-$VERSION

( 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/*/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/slack-desc > $PKG/usr/doc/$NAME-$VERSION/slack-desc
cat $CWD/$NAME.SlackBuild > $PKG/usr/doc/$NAME-$VERSION/$NAME.SlackBuild
cd $PKG
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n ../$NAME-$VERSION-$ARCH-$BUILD.txz
mv $TMP/$NAME-$VERSION-$ARCH-$BUILD.txz $CWD

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP/$NAME-$VERSION
 rm -rf $PKG
fi
