#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-diff
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/_diff.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 -Tascii -mandoc $1 | gzip -9c > $2
  if [ ! "$3" = "" ]; then
    mkdir -p `dirname $3`
    cat $1 > $3 
  fi 
}

echo "+===============+"
echo "| diffutils-2.7 |"
echo "+===============+"
cd $TMP
tar xzvf $CWD/diffutils-2.7.tar.gz
cd diffutils-2.7
configure --prefix=/usr
make CFLAGS=-O2 LDFLAGS=-s
cat cmp > $PKG/usr/bin/cmp
cat diff > $PKG/usr/bin/diff
cat diff3 > $PKG/usr/bin/diff3
cat sdiff > $PKG/usr/bin/sdiff
for file in diff.info diff.info-1 diff.info-2 diff.info-3 diff.info-4 ; do
 cat $file | gzip -9c > $PKG/usr/info/$file.gz
done

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

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