#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-bin

VERSION=1.0
ARCH=${ARCH:-i486}
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

echo "+===========+"
echo "| rpm2targz |"
echo "+===========+"
cd $TMP
mkdir -p $PKG/usr/bin
cc -o $PKG/usr/bin/rpmoffset $CWD/rpmoffset.c
cat $CWD/rpm2targz > $PKG/usr/bin/rpm2targz
chmod 755 $PKG/usr/bin/{rpmoffset,rpm2targz}
( cd $PKG/usr/bin ; ln -sf rpm2targz rpm2tgz )
mkdir -p $PKG/usr/doc/rpm2targz
cp -a $CWD/rpm2targz.README $PKG/usr/doc/rpm2targz/rpm2targz.README
chmod 644 $PKG/usr/doc/rpm2targz/rpm2targz.README
( 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
)

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/rpm2tgz-$VERSION-$ARCH-$BUILD.tgz