#!/bin/sh

[ -z $PREPKG ] && exit 1

PACKAGE=icmake
VERSION=7.11
FILES=$(cd $(dirname $0) ; pwd)

# I'm too lazy to generate a standalone patch for this:
sed -i 's,/usr/share/man/man1,/usr/man/man1,' def/destinations

mkdir -p $PREPKG/{install,usr/{bin,doc/$PACKAGE-$VERSION,{lib,share}/$PACKAGE,man/man1}}/

chown -R root:root .
sh bootstrap.sh &> bootstrap.sh.output || exit 1

# ugh, what a mess. time to install everything by hand
cp -p bin/icm[a-z]* $PREPKG/usr/bin/
cp -p bin/icm-* $PREPKG/usr/lib/$PACKAGE/
cp -a doc/README.icmbuild doc/icmake.doc templates/ CHANGES \
  $PREPKG/usr/doc/$PACKAGE-$VERSION/
cp -p doc/*.1 $PREPKG/usr/man/man1/
gzip -r9 $PREPKG/usr/man/
ln -s icmake.1.gz $PREPKG/usr/man/man1/icmun.1.gz
cp -a usr/share/$PACKAGE/* $PREPKG/usr/share/$PACKAGE/

cp $FILES/slack-desc $PREPKG/install/

find $PREPKG -exec file {} \; \
  | awk -F : '/ ELF / {print $1}' \
  | xargs strip -p --strip-unneeded
