#!/bin/sh

VERSION=1.7
ARCH=${ARCH:-noarch}
BUILD=${BUILD:-1tukaani}

set -e
PKG=/tmp/package-tcllib
rm -rf "$PKG"

CWD=`pwd`

cd /tmp
rm -rf "tcllib-$VERSION"
tar xvf $CWD/tcllib-$VERSION.tar.*
cd tcllib-$VERSION

tclsh installer.tcl -no-wait -no-gui -no-html -nroff -examples -pkgs -apps \
  -pkg-path $PKG/usr/lib/tcllib$VERSION \
  -app-path $PKG/usr/bin \
  -nroff-path $PKG/usr/man/mann \
  -example-path $PKG/usr/doc/tcllib-$VERSION/examples

gzip -9 $PKG/usr/man/*/*
# This conflicts with `blt' but because tcllib has two version of `graph'
# and the older is named `graph1.n.gz' this (v2.0) can be `graph2.n.gz':
( cd $PKG/usr/man/mann
  mv graph.n.gz graph2.n.gz
)

mkdir -p $PKG/usr/doc/tcllib-$VERSION
cp -a \
  ChangeLog \
  DESCRIPTION.txt \
  license.terms \
  PACKAGES \
  PACKAGES.LAST \
  README* \
  STATUS \
  $PKG/usr/doc/tcllib-$VERSION

# installer.tcl doesn't copy these:
cp -a examples/README examples/oreilly-oscon2001/ $PKG/usr/doc/tcllib-$VERSION/examples
cp -a devdoc $PKG/usr/doc/tcllib-$VERSION

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

cd "$PKG"
makepkg -c y -l y ../tcllib-$VERSION-$ARCH-$BUILD.tlz
