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

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf xfsprogs-$VERSION
tar xf $CWD/xfsprogs-$VERSION.tar.gz
cd xfsprogs-$VERSION
chown -R root:root .
find . -perm 666 -exec chmod 644 {} \;
find . -perm 664 -exec chmod 644 {} \;
find . -perm 600 -exec chmod 644 {} \;
find . -perm 444 -exec chmod 644 {} \;
find . -perm 400 -exec chmod 644 {} \;
find . -perm 440 -exec chmod 644 {} \;
find . -perm 777 -exec chmod 755 {} \;
find . -perm 775 -exec chmod 755 {} \;
find . -perm 511 -exec chmod 755 {} \;
find . -perm 711 -exec chmod 755 {} \;
find . -perm 555 -exec chmod 755 {} \;
# Make sure you have the same version of autoconf as the
# developers did...  ;-)
autoconf
./configure \
 --prefix=/usr \
 --mandir=/usr/man \
 --datadir=/usr/share \
 --libdir=/lib \
 --libexecdir=/usr/lib \
 --sbindir=/sbin \
 --bindir=/usr/sbin \
 --enable-shared=yes \
 --enable-gettext=yes \
 --build=$TARGET

make || exit 1
make install DIST_ROOT=$PKG || exit 1
make install-dev DIST_ROOT=$PKG || exit 1
mv $PKG/usr/share/doc $PKG/usr
mv $PKG/usr/doc/xfsprogs $PKG/usr/doc/xfsprogs-$VERSION
# It would be nice to keep the same timestamps that the files have in the source:
cp -a README doc/COPYING doc/CREDITS $PKG/usr/doc/xfsprogs-$VERSION
rm -f $PKG/usr/doc/xfsprogs-$VERSION/CHANGES.gz
# The install location for many binaries changed with the update to 3.1.1,
# but it seems like the wrong place to put most of this stuff:
mkdir -p $PKG/usr/sbin
mv $PKG/sbin/xfs_* $PKG/usr/sbin
mv $PKG/usr/sbin/xfs_repair $PKG/sbin
# Remove bogus files:
rm -f $PKG/lib/*.so $PKG/lib/*.la $PKG/usr/lib/*.la
# Make /usr/lib/libhandle.so a symlink to /lib/libhandle.so.1:
if [ -f $PKG/lib/libhandle.so.1 ]; then
  mkdir -p $PKG/usr/lib
  ( cd $PKG/usr/lib ; rm -f libhandle.so ; ln -sf /lib/libhandle.so.1 libhandle.so )
  ( cd $PKG/lib ; mv *.a $PKG/usr/lib )
else
  exit 1
  # and fix your script!  ;-)
fi
# Fix shared library perms:
chmod 755 $PKG/lib/*
# Strip libraries:
( 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
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/xfsprogs-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/xfsprogs.build.log
