#!/bin/sh
# Build/install Tk the way AlphaSlack's binary package is made:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-tk
VERSION=8.5.4
# See also version number 8.5 in the symlinks below...)
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf tk$VERSION
tar xzf $CWD/tk$VERSION-src.tar.gz
cd tk$VERSION
chown -R root.root .
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 {} \;
mkdir -p $PKG/usr/doc/tk$VERSION
cp -a README license.terms $PKG/usr/doc/tk$VERSION
cd unix
./configure \
 --prefix=/usr \
 --enable-threads \
 --enable-shared \
 --enable-man-symlinks \
 --enable-man-compression=gzip \
 --build=$TARGET || exit 1
make -j2 || exit 1
make install DESTDIR=$PKG || exit 1

( cd $PKG/usr/bin
 rm -f wish
 ln -sf wish8.5 wish )
( cd $PKG/usr/lib
 rm -rf libtk.so libtkstub.a
 ln -sf libtk8.5.so libtk.so
 ln -sf libtkstub8.5.a libtkstub.a )

chown -R root:bin $PKG/usr/bin

( 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
)

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n ../tk-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/tk.build.log
