#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-pilot-link
VERSION=0.12.5
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf pilot-link-$VERSION
tar xjf $CWD/pilot-link-$VERSION.tar.bz2
cd pilot-link-$VERSION
chown -R root.root .
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --infodir=/usr/info \
 --localstatedir=/var/lib \
 --enable-threads \
 --enable-libusb \
 --with-tcl=/usr/lib \
 --with-python \
 --with-perl \
 --enable-conduits \
 --build=$TARGET

# --with-perl
# generates unusable perl-modules and install they to the wrong dir.

make || exit 1
make install DESTDIR=$PKG
chown -R root.bin $PKG/usr/bin
( 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
)
strip -g $PKG/usr/lib/*.a 2> /dev/null
mkdir -p $PKG/usr/doc/pilot-link-$VERSION
cp -a AUTHORS COPYING COPYING.LIB NEWS README doc/TODO $PKG/usr/doc/pilot-link-$VERSION
chmod 644 $PKG/usr/doc/pilot-link-$VERSION/*
#mv $PKG/PDA::Pilot.3 $PKG/usr/doc/pilot-link-$VERSION
#mv $PKG/{PDA,auto} $PKG/usr/share/pilot-link
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat << EOF > $PKG/install/doinst.sh
if [ ! -r dev/pilot ]; then # pick a default
  ( cd dev ; ln -sf ttyS0 pilot )
fi
EOF
cd $PKG
makepkg -l y -c n $TMP/pilot-link-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/pilot-link.build.log
