# 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:-i486}
BUILD=${BUILD:-1}

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"
fi

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

( cd /usr/bin
  rm -f wish
  ln -sf wish8.4 wish )
( cd /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 /install
cat $CWD/slack-desc > /install/slack-desc

# Make a script to produce symlinks to gzipped man pages (used when packing later):
cat mkLinks | perl -pi -e 's|\.3|foo3foo3|' | perl -pi -e 's|\.3|foo3foo3|' | \
  perl -pi -e 's|foo3foo3|.3.gz|' | perl -pi -e 's|foo3foo3|.3.gz|' | \
  perl -pi -e 's|\.n|foonfoon|' | perl -pi -e 's|\.n|foonfoon|' | \
  perl -pi -e 's|foonfoon|.n.gz|' | perl -pi -e 's|foonfoon|.n.gz|' | \
  perl -pi -e 's|ln |ln -sf |' > $CWD/mkgzLinks.sh

# Briefly, to use the above generated script, you go into say /usr/man/man3/
# of the extracted package and do this:
# mkdir tmp
# cp *.* tmp
# mv tmp/* .
# rm -r tmp
# gzip -9 *
# sh /path/to/mkgzLinks.sh .