#!/bin/sh
# Build this against 2.6.x kernel source and headers...

VERSION=2.6.9-ss040831
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-0}

PKG=/tmp/package-iproute2
rm -rf $PKG
mkdir -p $PKG
mkdir -p $PKG/usr/man/man8
CWD=`pwd`
cd /tmp
rm -rf iproute2-2.6.9
tar xzvf $CWD/iproute2-$VERSION.tar.gz
cd iproute2-2.6.9
zcat $CWD/iproute2.dbpath.diff.gz | patch -p1 --verbose
zcat $CWD/patches-splack/iproute2-2.6.9-free_error-2.patch.gz \
 | patch -p1 --verbose

chown -R root.root .
find . -perm 775 -exec chmod 755 {} \;
find . -perm 444 -exec chmod 644 {} \;

make
make install DESTDIR=$PKG

for file in $PKG/etc/iproute2/* ; do
  mv $file ${file}.new
done
( 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
)
chown -R root:bin $PKG/usr/sbin
mv $PKG/usr/sbin $PKG
( cd $PKG/usr/man/man8
  gzip -9 *.?
  rm *.?
  ln -sf tc-pbfifo.8.gz tc-bfifo.8.gz
  ln -sf tc-pbfifo.8.gz tc-pfifo.8.gz
)
mv $PKG/usr/doc/iproute2 $PKG/usr/doc/iproute2-$VERSION
cp -a RE* \
  $PKG/usr/doc/iproute2-$VERSION
mkdir -p $PKG/var/lib/arpd
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $PKG
makepkg -l y -c n /tmp/iproute2-$(echo $VERSION | tr - _)-$ARCH-$BUILD.tgz

