#!/bin/sh

PKGNAM=flac
VERSION=1.2.1
BUILD=${BUILD:-2}

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf flac-$VERSION
tar xjvf $CWD/flac-$VERSION.tar.bz2
cd flac-$VERSION
zcat $CWD/flac.man.diff.gz | patch -p1 --verbose --backup --suffix=.orig

pkghelpers_permissions

# We disable assembly optimizations to ensure compatibility with older
# hardware, but you're welcome to comment this out and give it a try.
# I've heard it gives a noticable speedup.
if [ "$ARCH" != "x86_64" ]; then
  DISABLE_ASM_OPTIMIZATIONS=""
else
  DISABLE_ASM_OPTIMIZATIONS=${DISABLE_ASM_OPTIMIZATIONS:-"--disable-asm-optimizations"}
fi

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
	--libdir=/usr/lib$LIBSUFFIX \
  --mandir=/usr/man \
  $DISABLE_ASM_OPTIMIZATIONS \
  --build=$ARCH-$DISTRO-linux
sed -i "s,usr/lib/,usr/lib$LIBSUFFIX/,g" Makefile
make -j4 || exit 1
make install DESTDIR=$PKG
# Adjust docs to traditional Slackware location:
mv $PKG/usr/share/doc $PKG/usr
rm $PKG/usr/doc/flac-$VERSION/FLAC.tag
mv $PKG/usr/doc/flac-$VERSION/html/* $PKG/usr/doc/flac-$VERSION
rmdir $PKG/usr/doc/flac-$VERSION/html
# we're not putting 3MB of API docs in the binary package...
( cd $PKG/usr/doc/flac-$VERSION/api && rm -r * )
cat << EOF > $PKG/usr/doc/flac-$VERSION/api/README
Full HTML based API documentation may be found in the FLAC
source package.  It is not included in the binary package due
to size.
EOF
# Add a few more docs:
cp -a \
  AUTHORS COPYING* README \
  $PKG/usr/doc/flac-$VERSION
mkdir $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
pkghelpers_fixup
pkghelpers_makepkg