#!/bin/sh
# Heavily based on the Slackware 12.0 SlackBuild
# http://www.theorie.physik.uni-goettingen.de/~ostreich/transcode/
# Packager Vincenzi Loris - slacky@slacky.it

CWD=`pwd`
TMP=${TMP:-/tmp/tgz}
PKG=$TMP/package
NAME=transcode
VERSION=`date +%Y%m%d`
CHOST=i486
ARCH=${ARCH:-i486}
BUILD=1sl

rm -rf $PKG
mkdir -p $PKG

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
fi

cd $TMP
cvs -z3 -d :pserver:cvs@cvs.exit1.org:/cvstc co -r transcode_1_1 transcode
cd $NAME
autoreconf -i -f
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure --prefix=/usr \
--mandir=/usr/man \
--with-ffmpeg-libs-includes=/usr/include/ffmpeg \
--with-ffmpeg-libs-libs=/usr/lib \
--with-libquicktime-prefix=/usr \
--with-libquicktime-includes=/usr/include/lqt \
--with-libquicktime-libs=/usr/lib \
--with-libfame-prefix=/usr \
--with-libfame-includes=/usr/include \
--with-libfame-libs=/usr/lib \
--with-lzo-prefix=/usr \
--with-lzo-includes=/usr/include/lzo \
--with-lzo-libs=/usr/lib \
--enable-freetype2 \
--enable-libdv \
--enable-avifile \
--enable-libmpeg3 \
--enable-theora \
--enable-v4l \
--enable-xvid \
--enable-alsa \
--enable-x264 \
--enable-faac \
--enable-ogg \
--enable-vorbis \
--enable-libquicktime \
--enable-a52-default-decoder \
--enable-a52 \
--enable-mjpegtools \
--enable-libfame \
--enable-libxml2 \
--enable-imagemagick \
--enable-sdl \
--enable-gtk \
--enable-lzo \
--program-prefix= \
--program-suffix= \
--build=$CHOST-slackware-linux
read
make
make install DESTDIR=$PKG
mv -f $PKG/usr/share/doc $PKG/usr/
rm -rf $PKG/usr/share
mv -f $PKG/usr/doc/$NAME $PKG/usr/doc/$NAME-$VERSION
cp -a AUTHORS ChangeLog COPYING INSTALL README TODO $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
find $PKG/usr/man -type f -exec gzip -9 {} \;
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
requiredbuilder -v -y -s $CWD $PKG
makepkg -l y -c n $CWD/$NAME-$VERSION-$ARCH-$BUILD.tgz

if [ "$1" = "--cleanup" ]; then
 rm -rf $TMP
fi
