#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-bridge-utils

VERSION=1.2
ARCH=${ARCH:-i486}
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

cd $TMP
rm -rf bridge-utils-$VERSION
tar xzf $CWD/bridge-utils-$VERSION.tar.gz || exit 1
cd bridge-utils-$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 {} \;

# This is bad form, but what can you do...
autoconf

./configure \
  --prefix=/usr \
  --mandir=/usr/man

make || exit 1
make install DESTDIR=$PKG
mkdir -p $PKG/sbin
mv $PKG/usr/sbin/brctl $PKG/sbin/brctl
( cd $PKG/usr/sbin ; ln -sf ../../sbin/brctl brctl )
strip --strip-unneeded $PKG/sbin/brctl
rmdir $PKG/usr/sbin
strip -g $PKG/usr/lib/libbridge.a
gzip -9 $PKG/usr/man/man8/*.8

mkdir -p $PKG/usr/doc/bridge-utils-$VERSION
cp -a \
  AUTHORS COPYING ChangeLog README THANKS TODO  \
  doc \
  $PKG/usr/doc/bridge-utils-$VERSION
( cd $PKG/usr/doc/bridge-utils-$VERSION/doc
  rm -f Makefile Makefile.in RPM-GPG-KEY brctl.8
)

# Finish up the package:
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/bridge-utils-$VERSION-$ARCH-$BUILD.tgz