#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-perl
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/_perl.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 "| perl-4.036 |"
echo "+============+"
cd $TMP
tar xzvf $CWD/perl-4.036.tar.gz
tar xzvf $CWD/perl-4.036-linux-kit.tar.gz
cd perl-4.036
patch <perl.udf
zcat $CWD/perl-4.036.diff.gz | patch -p1
zcat $CWD/perl-4.036.diff2.gz | patch
chmod 755 makedepend
make depend
make
make suidperl
cat perl > $PKG/usr/bin/perl4.036
cat suidperl > $PKG/usr/bin/sperl4.036
cat taintperl > $PKG/usr/bin/tperl4.036
man2gz h2ph.man $PKG/usr/man/preformat/cat1/h2ph.1.gz $SRC/usr/man/man1/h2ph.1
man2gz perl.man $PKG/usr/man/preformat/cat1/perl.1.gz $SRC/usr/man/man1/perl.1
cd x2p
cat a2p > $PKG/usr/bin/a2p
man2gz a2p.man $PKG/usr/man/preformat/cat1/a2p.1.gz $SRC/usr/man/man1/a2p.1
man2gz s2p.man $PKG/usr/man/preformat/cat1/s2p.1.gz $SRC/usr/man/man1/s2p.1

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

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