#!/bin/sh

[ -z $PREPKG ] && exit 1

PACKAGE=xchat
VERSION=1.8.11
FILES=$(cd $(dirname $0) ; pwd)

# patrick's sanity patch
PATCHES="
$PACKAGE-1.8.9.stopforcing-g.diff.gz
"

for PATCH in $PATCHES ; do
  zcat $FILES/patches/$PATCH | patch -p0 &> $PATCH.output
done

# official patch
PATCHES="
xc1811fixststint.diff
"

for PATCH in $PATCHES ; do
  cat $FILES/patches/$PATCH | patch -p1 &> $PATCH.output
done

mkdir -p \
  $PREPKG/{install,usr/{doc/$PACKAGE-$VERSION,share/applications}}/

chown -R \
  root:root .
CFLAGS="-O2 -march=i486 -mtune=i686" \
  ./configure \
  --prefix=/usr \
  --disable-mmx \
  --build=i486-slackware-linux &> configure.output || exit 1
make $MAKEJOBS &> make.output || exit 1
make DESTDIR=$PREPKG install &> make_install.output || exit 1

cp -a \
  scripts-perl/ AUTHORS COPYING ChangeLog README doc/${PACKAGE}* \
  $PREPKG/usr/doc/$PACKAGE-$VERSION/
cp -p \
  $PACKAGE.desktop \
  $PREPKG/usr/share/applications/

rm -rf \
  $PREPKG/usr/{doc/$PACKAGE-$VERSION/scripts-perl/CVS,etc}/

cp \
  $FILES/slack-desc \
  $PREPKG/install/

find $PREPKG -exec file {} \; \
  | awk -F : '/ ELF / {print $1}' \
  | xargs strip -p --strip-unneeded
