#!/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.7 |"
echo "+=============+"
cd $TMP
tar xzvf $CWD/texinfo-3.7.tar.gz
cd texinfo-3.7
cp -a COPYING INTRODUCTION NEWS README $PKG/usr/doc/texinfo
chown root.root $PKG/usr/doc/texinfo/*
chmod 644 $PKG/usr/doc/texinfo/*
./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/*.el emacs/*.elc ; do
  cp -a $file $PKG/usr/share/emacs/site-lisp
done
chown root.root $PKG/usr/share/emacs/site-lisp/*
chmod 644 $PKG/usr/share/emacs/site-lisp/*
for file in texinfo texinfo-* ; do
  gzip -9c $file > $PKG/usr/info/$file.gz
done
cp -a texinfo.tex $PKG/usr/lib/teTeX/texmf/tex/texinfo
chown root.root $PKG/usr/lib/teTeX/texmf/tex/texinfo/texinfo.tex

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

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