#!/bin/sh
# Build CMake 2.4.8 LZM module

# Contributor: Alexander Markov <apsheronets@gmail.com>
# CMake  is an extensible, open-source system that manages the build process in an operating system and in a compiler-independent manner.
# http://www.cmake.org/

pkgname=cmake
pkgver=2.4.8
pkgrel=1
arch=i486
startdir=`pwd`

# Make temporary directories
mkdir src/
mkdir pkg/

# Download sources
wget -c "http://www.cmake.org/files/v2.4/$pkgname-$pkgver.tar.gz"

# Extract sources
tar -xf ${pkgname}-${pkgver}.tar.gz -C src/

# Build
cd ${startdir}/src/${pkgname}-${pkgver}/
./bootstrap --prefix=/usr
make || exit
make DESTDIR=${startdir}/pkg/ install
# Uncomment it if license will be needed
#install -Dm644 ${startdir}/src/${pkgname}-${pkgver}/Copyright.txt ${startdir}/pkg/usr/share/licenses/${pkgname}/Copyright.txt
cd ${startdir}/

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

# Clean
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/
