#!/bin/bash -x

# emacs.build
# Compile & install the Emacs package for Slackware
# Based on the Slackware build script,
# modified by Stuart Winter <stuart@armedslack.org> for ARMedslack
# 26-Jun-2004
# If only I could make a clean SlackBuild for this filth *sigh*

VERSION=$1 # the version of emacs

# Extract source:
cd $SLACKTRACKSCRATCHDIR
tar jxvvf $CWD/emacs-$PKGVER.tar.bz2
tar jxvvf $CWD/leim-$VERSION.tar.bz2
cd emacs-$VERSION
slackhousekeeping

# Install docs:
mkdir -p /usr/doc/$PACKAGE-$VERSION
cp -a BUGS FTP INSTALL README \
      /usr/doc/$PACKAGE-$VERSION
( cd /usr/doc/$PACKAGE-$VERSION && ln -sf /usr/share/$PACKAGE/$VERSION/etc . )

# Build a version of emacs that is not linked to the X11 libraries:
CFLAGS="$SLKCFLAGS" \
LDFLAGS=-s \
./configure \
   $ARCH-slackware-linux \
   --prefix=/usr \
   --with-x=no \
   --with-pop || failconfig
make || failmake
make install || failinstall
# Break the hard link 'emacs' - we only want the version number at this stage
# anyway. This wouldn't be a problem if we were building the X version next:
( cd /usr/bin
  mv -f emacs-$VERSION emacs-$VERSION-no-x11 
  rm -f emacs )

# Build the full X11 emacs:
CFLAGS="$SLKCFLAGS" \
LDFLAGS=-s \
./configure \
    $ARCH-slackware-linux \
    --prefix=/usr \
    --with-x11 \
    --with-x-toolkit \
    --with-pop || failconfig
make || failmake
make install || failinstall
( cd /usr/bin
  rm -vvf emacs
  mv -vvf emacs-$VERSION emacs-$VERSION-with-x11
  ln -vvsf emacs-$VERSION-with-x11 emacs )

# This avoids a collision with Exuberant Ctags...
mv /usr/bin/ctags /usr/bin/ctags-emacs
mv /usr/man/man1/ctags.1 /usr/man/man1/ctags-emacs.1

# Install the package description for the main emacs- package (the one with X support)
rm -rf /install
mkdir /install
sed 's?i486?'"$PORTARCH"'?g' $CWD/slack-desc.emacs > /install/slack-desc
chmod 644 /install/*
# This will attempt to handle the Exuberant Ctags situation gracefully...
install -m644 $CWD/doinst.sh-emacs /install/doinst.sh

# The rest of the packages are built using postbuild.sh
