#!/bin/sh

SOFTWARE=faad2
VERSION=2.0
ARCH=i486
BUILD=1slackles

# FAAD2 is compiled with GCC 3.3.4. I didn't
# check why it doesn't compile with 3.4.3.
export CFLAGS="-O2 -march=i486 -mcpu=i686"
export CXXFLAGS="$CFLAGS"

PKG="/tmp/package-$SOFTWARE"
CWD=`pwd`
TMP=/tmp
umask 0022

cd "$TMP"
rm -rf "$PKG" "$SOFTWARE"
tar xzvf "$CWD/$SOFTWARE-$VERSION.tar.gz"
cd "$SOFTWARE"
autoreconf -vif
./configure \
  --prefix=/usr \
  --with-xmms \
  --with-drm \
  --with-mp4v2 \
  || exit 1

# If you have never seen an ugly hack, look at this: ;-)
sed -i 605,608d Makefile

make || exit 1
make DESTDIR="$PKG" install
( cd "$PKG"
  find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
  find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
  gzip -9 "$PKG"/usr/man/*/*
)
mkdir -p "$PKG/install" "$PKG/usr/doc/$SOFTWARE-$VERSION"
cp -v AUTHORS CHANGELOG ChangeLog COPYING LICENSE README* TODO USAGE "$PKG/usr/doc/$SOFTWARE-$VERSION"
cp -v "$CWD/slack-desc" "$PKG/install"

cd "$PKG"
makepkg -c n -l y /tmp/$SOFTWARE-$VERSION-i486-1slackles.tgz
