#!/bin/sh

# run the build with ntsec on if possible...
pkg=perl_debug
ver=5.8.5
release=-2
dir=`pwd`
shortver=`echo ${ver}${release} | sed 's/-.*//'`
buildperl=buildperl

## checkout builddir
rm -rf ${dir}/${buildperl}
mkdir -p -m 777 ${dir}/${buildperl}

## unpack
rm -rf ${pkg}-${ver}
tar jxf perl-${ver}.tar.bz2
mv perl-${ver}/ ${pkg}-${ver}/
mkdir -p /usr/share/doc/${pkg}-${ver}${release}
/bin/install -c -m 644 ${pkg}-${ver}/Artistic ${pkg}-${ver}/Copying ${pkg}-${ver}/README /usr/share/doc/${pkg}-${ver}${release}

## patch to get debug versions of the binaries & dll's
(cd ${pkg}-${ver} ; patch -p1<../hints.cygwin.sh.debug.patch)
## db_file patch
(cd ${pkg}-${ver} ; patch -p1<../db_file-1.810.patch)

## configure perl
cd ${dir}/${buildperl}

cp ${dir}/Policy.sh ${dir}/${buildperl}

sh ${dir}/${pkg}-${ver}/Configure -de	\
		-Dmksymlinks	\
		-Duse64bitint	\
		-Dusethreads	\
		-Doptimize='-g -O2'	\
		-Dman3ext='3pm'	\
		2>&1 | tee ${dir}/log.configure

# Implied by usethreads
#		-Dusemultiplicity	\
#		-Uusemymalloc	\

## build perl
make 2>&1 | tee ${dir}/log.make

cp /usr/bin/cygcrypt-0.dll .

## make the tests
make test 2>&1 | tee ${dir}/log.test
(cd t;./perl harness) 2>&1 | tee ${dir}/log.harness

export PERLIO=perlio
## make the tests
make test 2>&1 | tee ${dir}/log.test.perlio
echo 'PERLIO=perlio' >> ${dir}/log.test.perlio
(cd t;./perl harness) 2>&1 | tee ${dir}/log.harness.perlio
echo 'PERLIO=perlio' >> ${dir}/log.harness.perlio

rm -f cygcrypt-0.dll

# export PERLIO=raw
# ## make the tests
# make test 2>&1 | tee ${dir}/log.test.raw
# echo 'PERLIO=perlio' >> ${dir}/log.test.raw
# (cd t;./perl harness) 2>&1 | tee ${dir}/log.harness.raw
# echo 'PERLIO=raw' >> ${dir}/log.harness.raw
# 
# export PERLIO=crlf
# ## make the tests
# make test 2>&1 | tee ${dir}/log.test.crlf
# echo 'PERLIO=perlio' >> ${dir}/log.test.crlf
# (cd t;./perl harness) 2>&1 | tee ${dir}/log.harness.crlf
# echo 'PERLIO=crlf' >> ${dir}/log.harness.crlf

## install
make install 2>&1 | tee ${dir}/log.install

cd ${dir}
for i in \
         Compress-Zlib-1.33	\
         IO-Zlib-1.01	\
         Archive-Tar-1.10	\
         MD5-2.03	\
         Term-ReadLine-Perl-1.0203 \
         Net-Telnet-3.03	\
         TermReadKey-2.21	\
         XML-Parser-2.34;	\
do (tar xzf ${i}.tar.gz &&	\
    (cd ${i} &&	\
    perl Makefile.PL &&	\
    make &&	\
    make install UNINST=1));	\
done
