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

rm -rf $PKG
mkdir -p $PKG/usr
( cd $TMP
rm -rf gtk+-$VERSION
tar xjf $CWD/gtk+-$VERSION.tar.bz2
cd gtk+-$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 {} \;                                                                                                                                            
zcat $CWD/gtk.pnglz.diff.gz | patch -p1 --verbose || exit 1
./configure \
 --prefix=/usr \
 --sysconfdir=/etc \
 --mandir=/usr/man \
 --with-xinput=yes \
 --build=$TARGET || exit 1
make || exit 1
make install DESTDIR=$PKG || exit 1
# I'm spamming your root partition
make install
mkdir -p $PKG/etc/gtk-2.0
cp -a /etc/gtk-2.0/* $PKG/etc/gtk-2.0
chown -R root.bin $PKG/usr/bin
( cd $PKG
 find . | xargs file | grep "executable" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
 find . | xargs file | grep "shared object" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded
)
gzip -9 $PKG/usr/man/man?/*.?
mkdir -p $PKG/usr/doc/gtk+-$VERSION
cp -a AUTHORS COPYING ChangeLog NEWS README $PKG/usr/doc/gtk+-$VERSION
# I'm almost inclined to think this stuff is obsolete, but I don't know for sure.
# I do know that leaving it in doesn't hurt (aside from a few wasted bytes, but
# probably less than the comments here waste ;-)
mkdir -p $PKG/etc/profile.d
cp -a $CWD/profile.d/* $PKG/etc/profile.d
chmod 755 $PKG/etc/profile.d/*
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $TMP/package-gtk+
makepkg -l y -c n $TMP/gtk+2-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/gtk+2.build.log
