#!/bin/sh
# Ported from Slackware .build

# Set initial variables:
PKGNAM=gtk+
VERSION=${VERSION:-1.2.10}
BUILD=${BUILD:-5}

. /etc/pkghelpers
pkghelpers_env

rm -rf $PKG
mkdir -p $PKG

cd /tmp
rm -rf ${PKGNAM}-${VERSION}
tar xzvf $CWD/${PKGNAM}-$VERSION.tar.gz
cd $PKGNAM-$VERSION

# Make sure ownerships and permissions are sane:
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 {} \;

# Configure:
if [ ! -r configure ]; then
  sh autogen.sh
fi
CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib$LIBSUFFIX \
  --sysconfdir=/etc \
  --with-glib-prefix=/usr \
  --enable-shared \
  --host=$ARCH-$DISTRO-linux-gnu \
  --build=$ARCH-$DISTRO-linux-gnu \
  --target=$ARCH-$DISTRO-linux-gnu \
  $ARCH-$DISTRO-linux

# Build and install:
make -j12 CFLAGS="$SLKCFLAGS" || exit 1
make CFLAGS="$SLKCFLAGS" install DESTDIR=$PKG || exit 1

# Install documentation:
mkdir -p $PKG/usr/doc/$PKGNAM-$VERSION
cp -a \
  ABOUT-NLS AUTHORS COPYING HACKING INSTALL NEWS README README.cvs-commits TODO \
  $PKG/usr/doc/$PKGNAM-$VERSION

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
pkghelpers_fixup
pkghelpers_makepkg