#!/bin/sh
# Build and install Perl on Slackware
# by:  David Cantrell <david@slackware.com>
# Currently maintained by <volkerdi@slackware.com>
#

CWD=`pwd`
TMP=/tmp/perl-sources/
ARCH=i386

PERL_VER=5.6.1
DBI_VER=1.25
DATASHOWTABLE_VER=3.3
GETOPT_MIXED_VER=1.008
MD5_VER=2.20
TERMREADKEY_VER=2.20
LIBNET_VER=1.12
VERSION=$PERL_VER

# Insert the slack-desc:
mkdir -p /install
cat $CWD/slack-desc > /install/slack-desc

# We remove the old Perl from the system before building
rm -rf /usr/lib/perl5

# And any old sources:
rm -rf $TMP
mkdir -p $TMP

# Extract the sources
cd $TMP
tar xvzf $CWD/perl-$VERSION.tar.gz
tar xvzf $CWD/DBI-$DBI_VER.tar.gz
tar xvzf $CWD/Data-ShowTable-$DATASHOWTABLE_VER.tar.gz
tar xvzf $CWD/Getopt-Mixed-$GETOPT_MIXED_VER.tar.gz
tar xvzf $CWD/Digest-MD5-$MD5_VER.tar.gz
tar xvzf $CWD/TermReadKey-$TERMREADKEY_VER.tar.gz
tar xvzf $CWD/libnet-$LIBNET_VER.tar.gz

chown -R root.root .
find . -perm 555 -exec chmod 755 {} \;
find . -perm 444 -exec chmod 644 {} \;

# It is often suggested that we add this to the ./Configure:
#            -Dusethreads \
# However, this option is considered experimental, and is not
# recommended for production systems.  As such, we can't add
# to our default perl build.  If you want the option anyway,
# just add it below and rebuild perl.

# Configure the perl source tree:
cd $TMP/perl-$VERSION

# Fix the no DB_File module problem:
zcat $CWD/perl-5.6.1.dbfile.diff.gz | patch -p1 -E --verbose

./Configure -de \
            -Dprefix=/usr \
            -Dcccdlflags='-fPIC' \
            -Dd_dosuid \
            -Darchname=i386-linux \
            -Dprivlib=/usr/lib/perl5 \
            -Darchlib=/usr/lib/perl5/i386-linux \
            -Dsitelib=/usr/lib/perl5/site_perl \
            -Dsitearch=/usr/lib/perl5/site_perl/i386-linux

# Build perl
make
make test

# Install perl
make install

# Symlinks
( cd /usr/bin
  ln -sf perl$VERSION perl
  ln -sf sperl$VERSION sperl
  ln -sf sperl$VERSION suidperl
  ln -sf c2ph pstruct )

# Install documentation
cd $TMP/perl-$VERSION
mkdir -p /usr/doc/perl-$VERSION
cp -a AUTHORS Artistic Copying INSTALL MAINTAIN MANIFEST README \
   README.Y2K README.threads Todo Todo-5.6 /usr/doc/perl-$VERSION

# Make and install the DBI module and docs
cd $TMP/DBI-$DBI_VER
perl ./Makefile.PL
make
make test
make install
mkdir -p /usr/doc/perl-$VERSION/DBI-$DBI_VER
cp -a MANIFEST README ToDo /usr/doc/perl-$VERSION/DBI-$DBI_VER

# Make and install Data-Showtable module and docs
cd $TMP/Data-ShowTable-$DATASHOWTABLE_VER
zcat $CWD/Data-ShowTable-$DATASHOWTABLE_VER.diff.gz | patch -p1 --verbose
perl ./Makefile.PL
make
make test
make install
mkdir -p /usr/doc/perl-$VERSION/Data-ShowTable-$DATASHOWTABLE_VER
cp -a Copyright GNU-LICENSE MANIFEST README *.html \
   /usr/doc/perl-$VERSION/Data-ShowTable-$DATASHOWTABLE_VER

# Make and install Getopt-Mixed module and docs
cd $TMP/Getopt-Mixed-$GETOPT_MIXED_VER
perl ./Makefile.PL
make
make test
make install
mkdir -p /usr/doc/perl-$VERSION/Getopt-Mixed-$GETOPT_MIXED_VER
cp -a MANIFEST README tstopt1 tstopt2 \
   /usr/doc/perl-$VERSION/Getopt-Mixed-$GETOPT_MIXED_VER

# Make and install libnet module and docs
cd $TMP/libnet-$LIBNET_VER
perl ./Makefile.PL
make
make test
make install
mkdir -p /usr/doc/perl-$VERSION/libnet-$LIBNET_VER
cp -a ChangeLog MANIFEST README* /usr/doc/perl-$VERSION/libnet-$LIBNET_VER

# Make and install TermReadKey module and docs
cd $TMP/TermReadKey-$TERMREADKEY_VER
perl ./Makefile.PL
make
make test
make install
mkdir -p /usr/doc/perl-$VERSION/TermReadKey-$TERMREADKEY_VER
cp -a MANIFEST README /usr/doc/perl-$VERSION/TermReadKey-$TERMREADKEY_VER

# Make and install MD5 module and docs
cd $TMP/Digest-MD5-$MD5_VER
perl ./Makefile.PL
make
make test
make install
mkdir -p /usr/doc/perl-$VERSION/MD5-$MD5_VER
cp -a Changes MANIFEST README /usr/doc/perl-$VERSION/MD5-$MD5_VER

