#!/bin/sh
# Build VIM 7.1.285 LZM module

# Contributor: Alexander Markov <apsheronets@gmail.com>
# Vim is an almost compatible version of the UNIX editor vi.  Many new
# features have been added:  multi level undo, command line history, 
# filename completion, block operations, and more.
#
# Vim's development is led by Bram Moolenaar.
#
# This package also contains the Exuberant Ctags program
# written by Darren Hiebert.
# http://www.vim.org/


pkgname=vim
pkgver=7.1.285
pkgrel=1
arch=i486
startdir=`pwd`

slackmirror='ftp://ftp.belnet.be/packages/slackware'

# Make temporary directory
mkdir pkg/

# Download slackware's package
wget -c "${slackmirror}/slackware-12.1/slackware/ap/vim-7.1.285-i486-1.tgz"

# Extract packages and sources
tar -xf vim-7.1.285-i486-1.tgz -C pkg/ || exit
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/
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/)'
rm -r ${startdir}/pkg/
