#!/bin/sh
# Set initial variables:
PATH=$PATH:/usr/X11R6/bin
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-afterstep

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi

# Explode the package framework:
cd $PKG
explodepkg $CWD/_afterstep.tar.gz

echo "+===============+"
echo "| AfterStep-1.0 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/AfterStep-1.0.tar.gz
cd AfterStep-1.0
# build program
zcat $CWD/configure.h.diff.gz | patch -p0
./MakeMakefiles
make all
# remove debugging symbols
strip afterstep/afterstep
for modname in Animate Audio Auto Banner Pager Wharf asclock
do
   strip modules/$modname/$modname
done
# write binaries to package
cat afterstep/afterstep > $PKG/usr/X11R6/bin/afterstep
cat modules/asclock/asclock > $PKG/usr/X11R6/bin/asclock
for modname in Animate Audio Auto Banner Pager Wharf
do
   cat modules/$modname/$modname > $PKG/usr/X11R6/lib/X11/afterstep/$modname
done
# copy icon and background files to necessary locations
cp icons/*.xpm $PKG/usr/X11R6/include/X11/pixmaps
cp backgrounds/* $PKG/usr/X11R6/lib/X11/afterstep/backgrounds
# do the man pages
cat afterstep/afterstep.man | gzip -9c > $PKG/usr/X11R6/man/man1/afterstep.1.gz
for manname in Animate Audio Auto Banner Pager Wharf asclock
do
   cat modules/$manname/$manname.man | gzip -9c > \
      $PKG/usr/X11R6/man/man1/$manname.1.gz
done
# write out default configuration file
cat sample.steprc > $PKG/usr/X11R6/lib/X11/afterstep/system.steprc
# copy docs to the doc directory
cp CHANGES $PKG/usr/doc/AfterStep-1.0
cp CREDITS $PKG/usr/doc/AfterStep-1.0
cp FAQ $PKG/usr/doc/AfterStep-1.0
cp INSTALL $PKG/usr/doc/AfterStep-1.0
cp README $PKG/usr/doc/AfterStep-1.0
cp README.8bit $PKG/usr/doc/AfterStep-1.0

# Build the package:
cd $PKG
tar czvf $TMP/afterstep.tgz .

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/AfterStep-1.0
  rm -rf $PKG
fi
