#!/bin/sh

# metamail.build
# Build metamail for Slackware.
# Cleaned up by Stuart Winter for ARMedslack.

VERSION=$1

# Extract source:
cd $TMPBUILD
tar zxvvf $CWD/$PKGNAM-$VERSION.tar.gz
cd $PKGNAM-$VERSION
slackhousekeeping

# Apply diffs. I've used the newer Debian diff (the older one in Slackware 
# had automake errors) & removed the splitmail.c patch from metamail.fmtbuff.diff as it's no longer required.
zcat $PORTCWD/sources/metamail_*.diff.gz | patch -p1 --verbose || failpatch
#zcat $PORTCWD/patches/metamail.fmtbuf.diff.gz | patch -lp1

# De-debianize it:
sed -i 's|sensible-pager|more|g' bin/showexternal
sed -i 's|sensible-pager|more|g' bin/sun-message
sed -i 's|sensible-pager|more|g' src/metamail/mailto.c

# Configure:
ln -vsf /usr/share/libtool/config.sub /usr/share/libtool/config.guess config
chmod +x ./configure
./configure \
   --prefix=/usr || failconfig

# Build:
make $NUMJOBS || failmake
sed -i 's|/usr/lib/X11/fonts/misc|/usr/lib/metamail/fonts|g' bin/mailto-hebrew

# Install:
make install

# Docs:
mkdir -p /usr/doc/$PKGNAM-$VERSION
cp -a CREDITS README mailcap \
      /usr/doc/$PKGNAM-$VERSION

# Install man pages:
install -vpm644 man/*.1 /usr/man/man1
install -vpm644 man/*.5 /usr/man/man5

# Install fonts:
( cd fonts
  make
  mkdir -pm755 /usr/lib/metamail/fonts
  install -vpm644 *.pcf /usr/lib/metamail/fonts
  install -vpm644 fonts.alias fonts.dir \
                /usr/lib/metamail/fonts )

# These are obsolete, broken, and/or undocumented.
# Complain to volkerdi@slackware.com if you miss any of them...
for file in \
  mailserver rcvAppSingle richtoatk sndAppSingle sun-audio-file sun-message sun-to-mime sun2mime \
  rcvAppleSingle sndAppleSingle sun-message.csh \
  ; do
  rm -f /usr/bin/$file
  rm -f /usr/man/man1/$file.1
done
rm -f /usr/lib/libmetamail.a /usr/lib/libmetamail.la

# Install package description:
cd /
slackdesc
