#!/bin/sh

[ -z $PREPKG ] && exit 1

PACKAGE=sylpheed
VERSION=3.7.0
FILES=$(cd $(dirname $0) ; pwd)

mkdir -p \
  $PREPKG/{install,usr/{doc/$PACKAGE-$VERSION,share/icons/hicolor/{48x48,64x64,128x128}/apps}}/

tar xf $FILES/$PACKAGE-$VERSION.tar.xz || exit 1

chmod -R \
  g-w .
chown -R \
  root:root .
cd $PACKAGE-$VERSION/
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --enable-gpgme \
  --enable-ldap \
  --enable-ssl \
  --build=i586-slackware-linux &> configure.output || exit 1
make $MAKEJOBS &> make.output || exit 1
make DESTDIR=$PREPKG install &> make_install.output || exit 1

cp -p \
  ABOUT-NLS AUTHORS COPYING* ChangeLog* LICENSE NEWS* PLUGIN* README* TODO* \
  $PREPKG/usr/doc/$PACKAGE-$VERSION/
cp -p \
  $PACKAGE.png \
  $PREPKG/usr/share/icons/hicolor/48x48/apps/$PACKAGE.png
cp -p \
  $PACKAGE-64x64.png \
  $PREPKG/usr/share/icons/hicolor/64x64/apps/$PACKAGE.png
cp -p \
  $PACKAGE-128x128.png \
  $PREPKG/usr/share/icons/hicolor/128x128/apps/$PACKAGE.png

cp \
  $FILES/{doinst.sh,slack-desc} \
  $PREPKG/install/

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