#!/bin/bash

# postbuild.sh
# Create the other Emacs packages from the stuff that altertrack
# has found (after the 'make install' from emacs.build).
#
# The contents of these packages have been deduced by studying the .tgz
# binary packages found in Slackware v10.0.
#
# by Stuart Winter <stuart@armedslack.org> for ARMedslack
# 26-Jun-2004

# Get the emacs version from the trackbuild script:
VERSION=$1

# At this stage I'd think about considering the output from the find-el-orphans.sh
# script included in source/e.  However, all of the files it emits *are* already installed
# and as such will make it into the package.  Am I missing something?
# I'm guessing that in days gone, the user contributed stuff in that script *was* excluded
# from 'make install', but I can't see any evidence of that with my build of emacs-21.3.
# The only thing I could think of using the script's output for would be to copy the
# missing .elc files from the source (some are there, some aren't) into the package;
# but Slackware's packages don't have these files so mine won't either.

# Make the framework directories for the other packages.
# We'll build them inside slacktrack's temporary directory to save
# me having to tidy it up afterwards:
( cd $SLACKTRACKSCRATCHDIR
  mkdir -p pkg-emacs-info/{install,usr}
  mkdir -p pkg-emacs-leim/{install,usr/share/emacs/$VERSION}
  mkdir -p pkg-emacs-lisp/{install,usr/{share/emacs/$VERSION,libexec/emacs/$VERSION/$PORTARCH-slackware-linux}}
  mkdir -p pkg-emacs-misc/{install,usr/share/emacs/$VERSION}
  mkdir -p pkg-emacs-nox/{install,usr/{share/emacs/$VERSION/etc,bin}}
)

# Set the Slackware policies over the entire package (this is done again in
# altertrack but *after* -this script- has finished, therefore the additional
# packages I create here won't get the policy treatment if I don't do it now):
# After altertrack has determined the differences between the filesystem's contents 
# before and after the build, it copies them into $SLACKTRACKFAKEROOT; this is now
# where the entire contents of our package reside:
cd $SLACKTRACKFAKEROOT
slackstripall   # strip all .a archives and all ELFs
slackgzpages -i # compress man & info pages and delete usr/info/dir
slackslack      # chown -R root:root, chmod -R og-w, set root:bin ownerships, slack644docs )
chmod -R a-s .  # Tsk.
chmod -R a-t .  # The 't' bit on files has no meaning in modern Unix

#
# Build the emacs-info package:
#
mv usr/info \
   $SLACKTRACKSCRATCHDIR/pkg-emacs-info/usr
install -m644 $CWD/slack-desc.emacs-info \
              $SLACKTRACKSCRATCHDIR/pkg-emacs-info/install/slack-desc
( cd $SLACKTRACKSCRATCHDIR/pkg-emacs-info
  makepkg -l y -c n $PKGSTORE/$PKGSERIES/emacs-info-$PKGVER-noarch-$BUILD.tgz )

#
# Build the emacs-leim package:
#
mv usr/share/emacs/$VERSION/leim \
   $SLACKTRACKSCRATCHDIR/pkg-emacs-leim/usr/share/emacs/$VERSION
install -m644 $CWD/slack-desc.emacs-leim \
              $SLACKTRACKSCRATCHDIR/pkg-emacs-leim/install/slack-desc
( cd $SLACKTRACKSCRATCHDIR/pkg-emacs-leim
  makepkg -l y -c n $PKGSTORE/$PKGSERIES/emacs-leim-$VERSION-noarch-$BUILD.tgz )

#
# Build the emacs-lisp package:
#
cp -a usr/share/emacs/{site-lisp,$VERSION/{lisp,site-lisp}} \
      $SLACKTRACKSCRATCHDIR/pkg-emacs-lisp/usr/share/emacs
install -m644 $CWD/slack-desc.emacs-lisp \
              $SLACKTRACKSCRATCHDIR/pkg-emacs-lisp/install/slack-desc
#
# I have had a customer report (and I have confirmed) that emacs isn't fully functional
# (and complains) without them.  
# In Slackware 8.1 these fns-*.el files are in: emacs-lisp-21.2-i386-1.tgz
# but in Slackware 9.1 & 10 they are *not* in emacs-lisp-21.3-noarch-1.tgz
# Infact, the only place they *are* in is emacs-21.3-i486-1.tgz
# Obviously if you want the emacs-nox package you don't also want to install
# the whopping great big emacs with X package - if indeed you even want to install
# emacs at *all* ;-)
#
# PORTARCH=arm, i486, sparc, powerpc and so on.
cp -a usr/libexec/emacs/$VERSION/*-slackware-linux/fns-*.el \
      $SLACKTRACKSCRATCHDIR/pkg-emacs-lisp/usr/libexec/emacs/$VERSION/$PORTARCH-slackware-linux
( cd $SLACKTRACKSCRATCHDIR/pkg-emacs-lisp
  makepkg -l y -c n $PKGSTORE/$PKGSERIES/emacs-lisp-$PKGVER-noarch-$BUILD.tgz )

#
# Build the emacs-misc package:
#
mv usr/share/emacs/$VERSION/etc \
   $SLACKTRACKSCRATCHDIR/pkg-emacs-misc/usr/share/emacs/$VERSION
# and move this document back into the main package:
mkdir -p usr/share/emacs/$VERSION/etc
mv -f $SLACKTRACKSCRATCHDIR/pkg-emacs-misc/usr/share/emacs/$VERSION/etc/DOC-* \
      usr/share/emacs/$VERSION/etc
install -m644 $CWD/slack-desc.emacs-misc \
              ${SLACKTRACKSCRATCHDIR}/pkg-emacs-misc/install/slack-desc
( cd $SLACKTRACKSCRATCHDIR/pkg-emacs-misc
  makepkg -l y -c n $PKGSTORE/$PKGSERIES/emacs-misc-$PKGVER-noarch-$BUILD.tgz )

#
# Build the emacs-nox package:
#
mv -f usr/bin/emacs-$VERSION-no-x11 \
      $SLACKTRACKSCRATCHDIR/pkg-emacs-nox/usr/bin/
cp -a usr/share/emacs/$VERSION/etc/DOC-* \
      $SLACKTRACKSCRATCHDIR/pkg-emacs-nox/usr/share/emacs/$VERSION/etc/
install -m644 $CWD/slack-desc.emacs-nox \
              $SLACKTRACKSCRATCHDIR/pkg-emacs-nox/install/slack-desc
( cd $SLACKTRACKSCRATCHDIR/pkg-emacs-nox
  makepkg -l y -c n $PKGSTORE/$PKGSERIES/emacs-nox-$PKGVER-$ARCH-$BUILD.tgz )

#
# And *finally* we leave slacktrack/altertrack to build what's left of the
# original contents into the main 7Mbytes emacs-$PKGVER-$ARCH-$BUILD.tgz
# package (the one that contains support for X).
# (i.e. everything else compiled & installed by emacs.build)
# 
