#!/bin/sh
# by: volkerdi@slackware.com
# Set initial variables:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-gpm
VERSION=1.19.6
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

mkdir -p $PKG
( cd $PKG
explodepkg $CWD/_gpm.tar.gz
cd $TMP
tar xjf $CWD/gpm-$VERSION.tar.bz2
cd gpm-$VERSION
zcat $CWD/gpm_$VERSION-10.diff.gz | patch -p1
# This adds #include <time.h> in addition to #include <sys/time.h> per
# recent glibc requirements.
zcat $CWD/gpm-1.19.6.time.diff.gz | patch -p1
zcat $CWD/gcc3.4.patch.gz | patch -p0
find . -perm 600 -exec chmod 644 {} \;
find . -perm 700 -exec chmod 755 {} \;
# Nico says the proper way to compile for gpm/ncurses support is:
#   compile ncurses without gpm
#   compile gpm --with-curses
#   compile ncurses --with-gpm
# BTW, I did try gpm-1.20.0, but it produces spurious output on stderr
# totally breaking dialog.  Even after patching that, I noticed more
# quirks using it for a couple of days than I've seen with 1.19.6 with
# all of the patches we apply.  I think it's best to wait until these
# issues are ironed out before upgrading gpm.
./configure --prefix=/usr --with-curses --sysconfdir=/etc $TARGET
# There are bugs in the docs, so -i work around them :)
make
( cd src
  strip disable-paste gpm mev gpm-root libgpm.so.1.18.0
  cat disable-paste > $PKG/usr/bin/disable-paste
  cat gpm > $PKG/usr/sbin/gpm
  cat mev > $PKG/usr/bin/mev
  cat gpm-root > $PKG/usr/bin/gpm-root
  cat headers/gpm.h > $PKG/usr/include/gpm.h
  cat libgpm.a > $PKG/usr/lib/libgpm.a
  cat libgpm.so.1.18.0 > $PKG/lib/libgpm.so.1.18.0
)
( cd conf
  cat gpm-root.conf > $PKG/etc/gpm-root.conf
  cat gpm-syn.conf > $PKG/etc/gpm-syn.conf
  cat gpm-twiddler.conf > $PKG/etc/gpm-twiddler.conf
)
( cd contrib/emacs
  cat t-mouse.el > $PKG/usr/share/emacs/site-lisp/t-mouse.el
)
( cd doc
  cp *.8 $PKG/usr/man/man8
  cp *.1 $PKG/usr/man/man1
)
# This is no longer there, but no big deal.  Emacs'll use the .el.
#cat t-mouse.elc > $PKG/usr/share/emacs/site-lisp/t-mouse.elc
mkdir -p $PKG/usr/doc/gpm-$VERSION
cp -a BUGS COPYING ChangeLog Changes MANIFEST README TODO $PKG/usr/doc/gpm-$VERSION
chown -R root.root $PKG/usr/doc/gpm-$VERSION
chmod 644 $PKG/usr/doc/gpm-$VERSION/*
gzip -9 $PKG/usr/man/man{1,8}/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
echo "n" | makepkg $TMP/gpm-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/gpm.build.log
