#!/bin/sh
# Set initial variables:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-groff
VERSION=1.19.2
ARCH=alpha
BUILD=2
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG/usr
( cd $TMP
rm -rf groff-$VERSION
tar xjf $CWD/groff-$VERSION.tar.bz2
cd groff-$VERSION
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
zcat $CWD/groff.docdir.diff.gz | patch -p1 --verbose || exit
./configure \
 --prefix=/usr \
 $TARGET
make || exit
make install prefix=$PKG/usr
( cd $PKG
 find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
 find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
# If you want all this stuff, it's in the source tarball:
rm -rf $PKG/usr/doc/groff-$VERSION/*.ps $PKG/usr/doc/groff-$VERSION/examples $PKG/usr/doc/groff-$VERSION/html
gzip -9 $PKG/usr/man/man?/*
rm -f $PKG/usr/info/dir
gzip -9 $PKG/usr/info/*
# fix permissions
chown -R root:bin $PKG/usr/bin
# Do not use color ANSI output by default for man pages.
# A silly "innovation" if ever there was one, sure to break
# a ton of existing scripts otherwise...
zcat $CWD/groff.man.mdoc.local.gz >> $PKG/usr/share/groff/site-tmac/man.local
zcat $CWD/groff.man.mdoc.local.gz >> $PKG/usr/share/groff/site-tmac/mdoc.local
( cd $PKG
  ( cd usr/bin ; ln -sf eqn geqn )
  ( cd usr/bin ; ln -sf indxbib gindxbib )
  ( cd usr/bin ; ln -sf pic gpic )
  ( cd usr/bin ; ln -sf refer grefer )
  ( cd usr/bin ; ln -sf soelim gsoelim )
  ( cd usr/bin ; ln -sf soelim zsoelim )
  ( cd usr/bin ; ln -sf tbl gtbl )
  ( cd usr/bin ; ln -sf troff gtroff )
  ( cd usr/bin ; ln -sf lookbib glookbib )
  ( cd usr/bin ; ln -sf nroff gnroff )
  ( cd usr/bin ; ln -sf neqn gneqn )
  ( cd usr/bin ; ln -sf gxditview xditview )
)
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/groff-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/groff.build.log
