#!/bin/sh
# Heavily based on the Slackware 12.1 SlackBuild
# http://easytag.sourceforge.net/
# Packagers Street41 (street41@gmail.com) alias MOgWai46
# Requirements: id3lib, mpeg4ip, speex, xvidcore
# http://www.slacky.it

CWD=`pwd`

# Packages Information:
VERSION=2.1.6
NAME=easytag
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1af}

PKG=/tmp/package-$NAME
rm -rf $PKG
mkdir -p $PKG

cd /tmp
rm -rf $NAME-$VERSION
tar xjvf $CWD/$NAME-$VERSION.tar.bz2
cd $NAME-$VERSION
chown -R root:root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
CFLAGS="-O2 -march=i486 -mtune=i686" \
CXXFLAGS="-O2 -march=i486 -mtune=i686" \
  ./configure \
  --prefix=/usr \
  --mandir=/usr/man \
  --program-prefix= \
  --program-suffix= \
  --build=$ARCH-slackware-linux
make -j3
make install DESTDIR=$PKG
mkdir -p $PKG/usr/doc/$NAME-$VERSION
cp -a ABOUT-NLS COPYING INSTALL README THANKS TODO \
  $PKG/usr/doc/$NAME-$VERSION

gzip -9 $PKG/usr/man/*/*
( 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
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 $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz
