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

rm -rf $PKG
mkdir -p $PKG
( cd $TMP
rm -rf tk$VERSION
tar xjf $CWD/tk$VERSION-src.tar.bz2
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-64bit \
 --enable-threads \
 --disable-shared \
 --enable-man-symlinks \
 --enable-man-compression=gzip || exit
make || exit
make install DESTDIR=$PKG || exit
make clean

./configure \
 --prefix=/usr \
 --enable-64bit \
 --enable-threads \
 --enable-shared \
 --enable-man-symlinks \
 --enable-man-compression=gzip || exit
make || exit
make install DESTDIR=$PKG || exit

( cd $PKG/usr/bin
  rm -f wish
  ln -sf wish8.4 wish )
( cd $PKG/usr/lib
  rm -f libtk.a libtk.so libtkstub.a
  ln -sf libtk8.4.a libtk.a
  ln -sf libtk8.4.so libtk.so
  ln -sf libtkstub8.4.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
