#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-texinfo
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/_texinfo.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 "| texinfo-3.6 |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/texinfo-3.6.tar.gz
cd texinfo-3.6
./configure --prefix=/usr
make CFLAGS=-O2 LDFLAGS=-s
cat makeinfo/makeinfo > $PKG/usr/bin/makeinfo
gzip -9c makeinfo/makeinfo.info > $PKG/usr/info/makeinfo.info.gz
cat info/info > $PKG/usr/bin/info
gzip -9c info/info.info > $PKG/usr/info/info.info.gz
gzip -9c info/info-stnd.info > $PKG/usr/info/info-stnd.info.gz
gzip -9c info/info.1 > $PKG/usr/man/man1/info.1.gz
cat util/texindex > $PKG/usr/bin/texindex
cat util/texi2dvi > $PKG/usr/bin/texi2dvi
for file in emacs/info.elc emacs/makeinfo.elc emacs/texinfo.elc \
emacs/texnfo-upd.elc emacs/texnfo-tex.elc emacs/texinfmt.elc \
emacs/informat.elc emacs/detexinfo.elc; do 
  cp $file $PKG/usr/share/emacs/site-lisp
done
for file in texinfo texinfo-* ; do
  gzip -9c $file > $PKG/usr/info/$file.gz
done
cp texinfo.tex $PKG/usr/lib/texinfo

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

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