#!/bin/sh
# Build rxvt-unicode for Slackware (by arossato@istitutocolli.org)

TMP=/tmp
CWD=`pwd`
PKG=$TMP/package-rxvt-unicode
rm -rf $PKG
mkdir -p $PKG

VERSION=8.2
ARCH=${ARCH:-i486}
BUILD=1ar

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

cd $TMP
rm -rf rxvt-unicode-$VERSION
tar xjvf $CWD/rxvt-unicode-$VERSION.tar.bz2
cd rxvt-unicode-$VERSION
chown -R root:root .
CFLAGS="$SLKCFLAGS" \
./configure \
--prefix=/usr \
--enable-languages \
--enable-xpm-background \
--enable-transparency \
--enable-rxvt-scroll \
--enable-next-scroll \
--enable-xterm-scroll \
--enable-plain-scroll \
--enable-xim \
--enable-frills \
--enable-keepscrolling \
--enable-mousewheel \
--enable-slipwheeling \
--disable-perl \
--enable-font-styles \
--enable-xft \
--enable-fading \
--enable-tinting \
--enable-iso14755 \
--enable-selectionscrolling \
--enable-slipwheeling \
--enable-smart-resize \
--enable-text-blink \
--enable-pointer-blank \
--enable-utmp \
--enable-wtmp \
--enable-lastlog \
$ARCH-slackware-linux
make
make install DESTDIR=$PKG
( 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
)
gzip -9 $PKG/usr/man/man1/*
requiredbuilder -y $PKG

mkdir -p $PKG/usr/doc/rxvt-unicode-$VERSION
cp -a \
  COPYING Changes INSTALL MANIFEST README.FAQ README.configure \
  $PKG/usr/doc/rxvt-unicode-$VERSION
cp -a \
  doc/embed doc/embed-tk doc/podtbl doc/pty-fd doc/rxvt-tabbed \
  $PKG/usr/doc/rxvt-unicode-$VERSION
mv doc/etc $PKG/usr/doc/rxvt-unicode-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
makepkg -l y -c n $TMP/rxvt-unicode-$VERSION-$ARCH-$BUILD.tgz
