#!/bin/sh
# Build/install Tk the way Slackware's binary package is made:

. /etc/pkghelpers

PKGNAM=tk
VERSION=8.4.15
# See also version number 8.4 in the symlinks below...)
BUILD=2

pkghelpers_env

cd $TMP
rm -rf tk$VERSION
tar xjvf $CWD/tk$VERSION-src.tar.bz2 || exit 1
cd tk$VERSION || exit 1

if [ "x$LIBSUFFIX" = "x64" ]; then
  zcat $CWD/libdir.diff.gz | patch -p1 --verbose || exit 1
fi

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
make clean

if [ "x$LIBSUFFIX" = "x64" ]; then
	EXTRACONF="--enable-64bit"
else
	EXTRACONF=""
fi

CFLAGS="$SLKCFLAGS -I/usr/include/tcl-private/generic" \
./configure \
  --prefix=/usr \
  --libdir=/usr/lib$LIBSUFFIX \
  --enable-shared \
  --enable-man-symlinks \
  --enable-man-compression=gzip \
	$EXTRACONF
make -j10 || exit 1
make install DESTDIR=$PKG

# Some sources require Tk's private headers, which might not be the
# best thing but we'll include them where we've seen other teams
# doing the same thing:
mkdir -p $PKG/usr/include/tk-private/{generic,unix}
cp -a ../generic/*.h $PKG/usr/include/tk-private/generic
cp -a ../unix/*.h $PKG/usr/include/tk-private/unix
( cd $PKG/usr/include/tk-private/generic
  rm -f tk.h tkDecls.h tkPlatDecls.h
  ln -sf ../../tk.h .
  ln -sf ../../tkDecls.h .
  ln -sf ../../tkPlatDecls.h
)

( cd $PKG/usr/bin
  rm -f wish
  ln -sf wish8.4 wish
)
( cd $PKG/usr/lib$LIBSUFFIX
  rm -f libtk.so
  ln -sf libtk8.4.so libtk.so
)

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

cd $PKG
pkghelpers_fixup
pkghelpers_makepkg