#!/bin/sh

# Slackware build script for Chromium B.S.U.
# Written by Erik Hanson  erik@slackbuilds.org

PRGNAM=chromium
VERSION=0.9.12
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

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

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP 
rm -rf $PRGNAM-$VERSION
tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2 || exit 1
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

# Patch the hell out of this old dog, courtesy debian.
for patch in $CWD/patches/* ; do patch -p1 < $patch || exit 1 ; done

CFLAGS="$SLKCFLAGS" \
./configure --disable-setup || exit 1

make || exit 1

# Manual installation
mkdir -p $PKG/usr/{games,share/{games/chromium,pixmaps,applications},man/man6}
/usr/bin/ginstall -s -m 755 bin/chromium $PKG/usr/games
/usr/bin/ginstall -m 644 $CWD/chromium.xpm $PKG/usr/share/pixmaps
/usr/bin/ginstall -m 644 $CWD/chromium.6.gz $PKG/usr/man/man6
cp -a data/fonts data/png data/wav $PKG/usr/share/games/chromium/

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION/html $PKG/install
cp -a AUTHORS CHANGES INSTALL LICENSE README README.vorbis \
  $PKG/usr/doc/$PRGNAM-$VERSION
cp -a data/doc/* $PKG/usr/doc/$PRGNAM-$VERSION/html
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild
cat $CWD/chromium.desktop > $PKG/usr/share/applications/chromium.desktop
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz