CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-glib2
rm -rf $PKG
mkdir -p $PKG/usr

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

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
fi

cd $TMP
rm -rf glib-$VERSION
tar xjvf $CWD/glib-$VERSION.tar.bz2 || exit 1
cd glib-$VERSION
chown -R root:root .
find . -perm 664 -exec chmod 644 {} \;
CFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --mandir=/usr/man \
  --build=$ARCH-slackware-linux
make -j4 || exit 1
make install DESTDIR=$PKG

# Install profile scripts:
mkdir -p $PKG/etc/profile.d/
cp -a $CWD/libglib2.{csh,sh} $PKG/etc/profile.d/
chown root:root $PKG/etc/profile.d/*
chmod 755 $PKG/etc/profile.d/*
mv $PKG/etc/profile.d/libglib2.csh $PKG/etc/profile.d/libglib2.csh.new
mv $PKG/etc/profile.d/libglib2.sh $PKG/etc/profile.d/libglib2.sh.new

( 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
)
gzip -9 $PKG/usr/man/man?/*
mkdir -p $PKG/usr/doc/glib-$VERSION
cp -a \
  AUTHORS COPYING NEWS README \
  $PKG/usr/doc/glib-$VERSION
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
zcat $CWD/doinst.sh.gz > $PKG/install/doinst.sh

cd $TMP/package-glib2
makepkg -l y -c n ../glib2-$VERSION-$ARCH-$BUILD.tgz