# Build/install Tk the way Slackware's binary package is made:
CWD=`pwd`

VERSION=8.4.6
# Don't forget the "8.4" symlinks down there...
ARCH=${ARCH:-sparc}
BUILD=${BUILD:-0}

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

PKG=/tmp/package-tk
rm -rf /tmp/tk$VERSION
rm -rf $PKG

cd /tmp
tar xzvf $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 /usr/doc/tk$VERSION
cp -a README license.terms /usr/doc/tk$VERSION
cd unix

CFLAGS="$SLKCFLAGS" \
  ./configure --prefix=/usr --disable-shared
make install

make clean
CFLAGS="$SLKCFLAGS" \
  ./configure --prefix=/usr --enable-shared
make install INSTALL_ROOT=$PKG

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

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

cd $PKG/usr/man
for dir in *; do cd $dir; gzip *; cd ..; done

cd $PKG
makepkg -l y -c n ../tk-$VERSION-$ARCH-$BUILD.tgz
