#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-cryptsetup
VERSION=${VERSION:-1.1.0}
ARCH=${ARCH:-alpha}
BUILD=${BUILD:-1}
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf cryptsetup-$VERSION
tar xf $CWD/cryptsetup-$VERSION.tar.bz2
chown -R root:root *
chmod -R u+w,go+r-w,a-s *
cd cryptsetup-$VERSION
./configure \
 --prefix=/usr \
 --localstatedir=/var \
 --sysconfdir=/etc \
 --datadir=/usr/share \
 --mandir=/usr/man \
 --localedir=/usr/share/locale \
 --build=$TARGET 
make || exit
make DESTDIR=$PKG install

# Move the cryptsetup binary to $PKG/sbin:
mkdir -p $PKG/sbin
( cd $PKG/usr/sbin
 mv cryptsetup ../../sbin
 ln -sf ../../sbin/cryptsetup .
)
# Documentation
mkdir -p $PKG/usr/doc/cryptsetup-$VERSION
cp -a AUTHORS COPYING ChangeLog TODO $PKG/usr/doc/cryptsetup-$VERSION
chmod -R a-w $PKG/usr/doc/cryptsetup-$VERSION/*

# Compress the man page(s)
find $PKG/usr/man -type f -name "*.?" -exec gzip -9f {} \; || true

# Strip binaries
( cd $PKG
find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)
# Add a package description
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
# Build the package:
cd $PKG
makepkg -l y -c n $TMP/cryptsetup-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/cryptsetup.build.log
