#!/bin/sh
# Build subversion 1.4.6 module

# Contributor: Alexander Markov <apsheronets@gmail.com>

# Subversion is a version control system which allows you to keep old
# versions of files and directories (usually source code), and keep a
# log of who, when, and why changes occurred, similar to other such
# systems like CVS, RCS or SCCS.  Subversion keeps all the information
# to permit extracting previous versions of those files at any time.
# For more information about the Subversion project, visit:
#   http://subversion.tigris.org

pkgname=subversion
pkgver=1.4.6
pkgrel=2
arch=i486
startdir=`pwd`

# Make temporary directories
mkdir pkg/
mkdir src/

# Download slackware's packages
wget -c "ftp://ftp.belnet.be/packages/slackware/slackware-12.1/slackware/d/${pkgname}-${pkgver}-i486-1.tgz"
wget -c "ftp://ftp.belnet.be/packages/slackware/slackware-12.1/slackware/l/apr-util-1.2.12-i486-1.tgz"
wget -c "ftp://ftp.belnet.be/packages/slackware/slackware-12.1/slackware/l/apr-1.2.12-i486-1.tgz"
wget -c "ftp://ftp.belnet.be/packages/slackware/slackware-12.1/slackware/l/neon-0.26.4-i486-1.tgz"

# Extract packages
tar -xf ${pkgname}-${pkgver}-i486-1.tgz -C pkg/
cd ${startdir}/pkg/ && sh install/doinst.sh && cd ${startdir}
tar -xf apr-1.2.12-i486-1.tgz -C pkg/
cd ${startdir}/pkg/ && sh install/doinst.sh && cd ${startdir}
tar -xf apr-util-1.2.12-i486-1.tgz -C pkg/
cd ${startdir}/pkg/ && sh install/doinst.sh && cd ${startdir}
tar -xf neon-0.26.4-i486-1.tgz -C pkg/
cd ${startdir}/pkg/ && sh install/doinst.sh && cd ${startdir}

# Copy slaxbuild
mkdir -p ${startdir}/pkg/usr/src/slaxbuilds/
cp $0 ${startdir}/pkg/usr/src/slaxbuilds/

# Clean
rm -r ${startdir}/pkg/install/
rm -r ${startdir}/pkg/usr/doc/
find ${startdir}/pkg/ -type d | xargs chmod -v 755;
find ${startdir}/pkg/usr/man/ -type l -name "*.gz" | xargs -r gunzip -f
find ${startdir}/pkg/usr/man/ ! -type l -name "*.gz" | xargs -r gunzip
find ${startdir}/pkg/ | xargs file | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded

# Make module
dir2lzm ${startdir}/pkg/ ${startdir}/${pkgname}-${pkgver}-${arch}-${pkgrel}.lzm && echo || exit

echo 'Remove temporary files (pkg/ and src/)'
rm -r ${startdir}/pkg/ ${startdir}/src/
