#!/bin/sh
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-libusb
VERSION=1.0.6
VER=0.1.3
ARCH=alpha
BUILD=3
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf libusb-$VERSION
tar xf $CWD/libusb-$VERSION.tar.bz2
cd libusb-$VERSION
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
./configure \
 --prefix=/usr \
 --docdir=/usr/doc/libusb-$VERSION \
 --disable-static \
 --build=$TARGET
make || exit 1
make install DESTDIR=$PKG

mkdir -p $PKG/usr/doc/libusb-$VERSION
cp -a AUTHORS COPYING INSTALL NEWS PORTING README THANKS TODO $PKG/usr/doc/libusb-$VERSION
# If there's a ChangeLog, installing at least part of the recent history
# is useful, but don't let it get totally out of control:
if [ -r ChangeLog ]; then
    DOCSDIR=$(echo $PKG/usr/doc/libusb-$VERSION)
    cat ChangeLog | head -n 1000 > $DOCSDIR/ChangeLog
    touch -r ChangeLog $DOCSDIR/ChangeLog
fi

cd $TMP
rm -rf libusb-compat-$VER
tar xf $CWD/libusb-compat-$VER.tar.bz2
cd libusb-compat-$VER
chown -R root.root .
find . -perm 777 -exec chmod 755 {} \;
find . -perm 664 -exec chmod 644 {} \;
./configure \
 --prefix=/usr \
 --docdir=/usr/doc/libusb-compat-$VER \
 --disable-static \
 --build=$TARGET
make || exit 1
make install DESTDIR=$PKG

mkdir -p $PKG/usr/doc/libusb-compat-$VER
cp -a AUTHORS COPYING INSTALL LICENSE NEWS README $PKG/usr/doc/libusb-compat-$VER
# If there's a ChangeLog, installing at least part of the recent history
# is useful, but don't let it get totally out of control:
if [ -r ChangeLog ]; then
    DOCSDIR=$(echo $PKG/usr/doc/libusb-compat-$VER)
    cat ChangeLog | head -n 1000 > $DOCSDIR/ChangeLog
    touch -r ChangeLog $DOCSDIR/ChangeLog
fi

( 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
cd $PKG
makepkg -l y -c n $TMP/libusb-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/libusb.build.log
