#!/bin/sh

VERSION=$1

# Extract source. Normally I'd extract it into slacktrack's dir but
# config.sh from Slackware has it in /tmp.
#cd $SLACKTRACKSCRATCHDIR
cd /tmp
rm -rf elm*
tar zxvvf $CWD/elm$VERSION.tar.gz
cd elm$VERSION
slackhousekeeping

rm -rf /var/lib/elm
mkdir -p /var/lib/elm

# Copy the default config:
cp $CWD/config.sh .

# Configure our CFLAGS.  At this point I'll just mention why I'm bothering
# to do this since none of the other ports do.
# If I choose to build this inside Scratchbox then it'll build binaries that do not
# work properly on the RiscPC.  SB's gcc doesn't honour the gcc specs file so I have
# to set the cflags manually.  I usually always build natively now, but I've got
# into the habit of doing this.
sed -i "s?^optimize=.*?optimize='$ARCH_CFLAGS'?" config.sh

# Configure:
I_STDARG=1 ./Configure

# Build:
make CCFLAGS=-DI_STDARG || failmake
make install

# Install docs:
mkdir -p /usr/doc/$PACKAGE-$VERSION
cp -a BUGS NOTICE Overview README doc/*.guid* doc/Elm.cover \
      /usr/doc/$PACKAGE-$VERSION

# Install man pages:
cd doc
install -m644 *.1 /usr/man/man1

# Replace hard links with symlinks:
( cd /usr/bin 
  rm -rf frm ; ln -sf nfrm frm 
  rm -rf newmail ; ln -sf wnewmail newmail )

# Install package description:
cd /
slackdesc
