#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-groff
SRC=/devel/manpagesrc
INFO=/devel/info-pages/usr/info
TEX=/devel/texinfo-docs

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/_groff.tar.gz

# Function to handle manpage source:
man2gz () { # $1 is source page name, $2 is target name for preformatted
            # output (full path && name) and $3 is the same, but for the
            # source.
  mkdir -p `dirname $2`
  groff -s -p -t -e -Tascii -mandoc $1 | gzip -9c > $2
  if [ ! "$3" = "" ]; then
    mkdir -p `dirname $3`
    cat $1 > $3 
  fi 
}

echo "+============+"
echo "| groff-1.09 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/groff-1.09.tar.gz
cd groff-1.09
zcat $CWD/groff-1.09.diff.gz | patch
./configure --prefix=/usr
make CFLAGS=-O2 LDFLAGS=-s
strip addftinfo/addftinfo eqn/eqn indxbib/indxbib lookbib/lookbib \
pic/pic refer/refer grodvi/grodvi groff/groff grotty/grotty soelim/soelim \
tbl/tbl troff/troff lkbib/lkbib pfbtops/pfbtops psbb/psbb tfmtodit/tfmtodit \
grops/grops
cat addftinfo/addftinfo > $PKG/usr/bin/addftinfo
cat eqn/eqn > $PKG/usr/bin/geqn
cat indxbib/indxbib > $PKG/usr/bin/gindxbib
cat lookbib/lookbib > $PKG/usr/bin/glookbib
cat pic/pic > $PKG/usr/bin/gpic
cat refer/refer > $PKG/usr/bin/grefer
cat grodvi/grodvi > $PKG/usr/bin/grodvi
cat groff/groff > $PKG/usr/bin/groff
cat grotty/grotty > $PKG/usr/bin/grotty
cat soelim/soelim > $PKG/usr/bin/gsoelim
cat tbl/tbl > $PKG/usr/bin/gtbl
cat troff/troff > $PKG/usr/bin/gtroff
cat lkbib/lkbib > $PKG/usr/bin/lkbib
cat pfbtops/pfbtops > $PKG/usr/bin/pfbtops
cat psbb/psbb > $PKG/usr/bin/psbb
cat tfmtodit/tfmtodit > $PKG/usr/bin/tfmtodit
cat grops/grops > $PKG/usr/bin/grops
cd xditview
zcat $CWD/gxditview.diff.gz | patch
xmkmf
make
strip gxditview
cat gxditview > $PKG/usr/X11R6/bin/gxditview

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

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