#!/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.10 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/groff-1.10.tar.gz
cd groff-1.10
./configure --prefix=/usr
make CFLAGS=-O2 CCFLAGS=-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 afmtodit/afmtodit > $PKG/usr/bin/afmtodit
cat eqn/eqn > $PKG/usr/bin/eqn
cat grodvi/grodvi > $PKG/usr/bin/grodvi
cat groff/groff > $PKG/usr/bin/groff
cat grog/grog > $PKG/usr/bin/grog
cat grolj4/grolj4 > $PKG/usr/bin/grolj4
cat grops/grops > $PKG/usr/bin/grops
cat grotty/grotty > $PKG/usr/bin/grotty
cat hpftodit/hpftodit > $PKG/usr/bin/hpftodit
cat indxbib/indxbib > $PKG/usr/bin/indxbib
cat lkbib/lkbib > $PKG/usr/bin/lkbib
cat lookbib/lookbib > $PKG/usr/bin/lookbib
cat eqn/neqn > $PKG/usr/bin/neqn
cat nroff/nroff > $PKG/usr/bin/nroff
cat pfbtops/pfbtops > $PKG/usr/bin/pfbtops
cat pic/pic > $PKG/usr/bin/pic
cat psbb/psbb > $PKG/usr/bin/psbb
cat refer/refer > $PKG/usr/bin/refer
cat soelim/soelim > $PKG/usr/bin/soelim
cat tbl/tbl > $PKG/usr/bin/tbl
cat tfmtodit/tfmtodit > $PKG/usr/bin/tfmtodit
cat troff/troff > $PKG/usr/bin/troff
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.10
  rm -rf $PKG
fi
