#!/bin/sh
# Build/install Tk the way AlphaSlack's binary package is made:
CWD=`pwd`
TMP=/tmp
PKG=$TMP/package-tk
VERSION=8.4.7
ARCH=alpha
BUILD=1
TARGET=$ARCH-alphaslack-linux

cd $TMP
tar xzf $CWD/tk$VERSION-src.tar.gz
( cd tk$VERSION
chown -R root.root .
find . -perm 664 -exec chmod 644 {} \;
mkdir -p $PKG/usr/doc/tk$VERSION
cp -a README changes license.terms $PKG/usr/doc/tk$VERSION
cd unix
./configure --prefix=/usr --disable-shared $TARGET
make
mkdir -p $PKG/usr/lib/tk8.4 $PKG/usr/include $PKG/usr/bin $PKG/usr/man/man{1,3,n}
cat libtk8.4.a > $PKG/usr/lib/libtk8.4.a ; chmod 555 $PKG/usr/lib/libtk8.4.a
make distclean
./configure --prefix=/usr --enable-shared $TARGET
zcat $CWD/tk-Makefile.diff.gz | patch -p1 --verbose
make
# 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 |' > $TMP/mkgzLinks.sh
cat wish > $PKG/usr/bin/wish8.4 ; chown root.bin $PKG/usr/bin/wish8.4 ; chmod 755 $PKG/usr/bin/wish8.4
cat ../generic/tk.h > $PKG/usr/include/tk.h
cat ../generic/tkDecls.h > $PKG/usr/include/tkDecls.h
cat ../generic/tkPlatDecls.h > $PKG/usr/include/tkPlatDecls.h
cat libtk8.4.so > $PKG/usr/lib/libtk8.4.so ; chmod 555 $PKG/usr/lib/libtk8.4.so
cat libtkstub8.4.a > $PKG/usr/lib/libtkstub8.4.a
cat tkConfig.sh > $PKG/usr/lib/tkConfig.sh
cp -a ../library/* $PKG/usr/lib/tk8.4
cat ../generic/prolog.ps > $PKG/usr/lib/tk8.4/prolog.ps
cat tkAppInit.c > $PKG/usr/lib/tk8.4/tkAppInit.c
cat ../doc/wish.1 > $PKG/usr/man/man1/wish.1
cp ../doc/*.3 $PKG/usr/man/man3
cp ../doc/*.n $PKG/usr/man/mann
gzip -9 $PKG/usr/man/man{1,3,n}/*
cat $CWD/pkgIndex.tcl > $PKG/usr/lib/tk8.4/pkgIndex.tcl
( cd $PKG
( cd usr/bin ; ln -sf wish8.4 wish )
( cd usr/lib ; ln -sf libtk8.4.a libtk.a ; ln -sf libtk8.4.so libtk.so ; ln -sf libtkstub8.4.a libtkstub.a )
( cd usr/lib/tk8.4/demos ; chmod 755 widget timer tcolor square rolodex rmt ixset hello browse )
( cd usr/man/man3 ; sh $TMP/mkgzLinks.sh . )
)
rm -rf $TMP/mkgzLinks.sh
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cd $PKG
makepkg -l y -c n $TMP/tk-$VERSION-$ARCH-$BUILD.tgz
) 2>&1 | tee $TMP/tk.build.log
