#!/bin/sh
# Build unison 2.27.57 LZM module

# Contributor: Alexander Markov <apsheronets@gmail.com>
# File-synchronization tool, console version. It is used for synchronizing files between two directories, either on one computer, or between a computer and another storage device (e.g. another computer, or a removable disc). It runs on Unix-like operating systems (including Linux, Mac OS X, and Solaris), as well as on Windows.
# http://www.cis.upenn.edu/~bcpierce/unison

# Ocaml is needed to build.

pkgname=unison
pkgver=2.27.57
pkgrel=2
arch=i486
startdir=`pwd`

# Make temporary directories
mkdir src/
mkdir pkg/

# Download sources
wget -c "http://www.cis.upenn.edu/~bcpierce/unison/download/releases/stable/${pkgname}-${pkgver}.tar.gz"

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

# Build
cd ${startdir}/src/${pkgname}-${pkgver}/
CFLAGS="-O3 -march=i486 -mtune=i686"
make clean
make UISTYLE=text DEBUGGING=false THREADS=true || exit
install -Dm755 unison ${startdir}/pkg/usr/bin/unison
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/
