#!/bin/sh
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi
PKG=$TMP/package-pkgtools

# *** UPDATE THESE WITH EACH BUILD:
VERSION=10.0.0
DIALOG=0.9b-20031207
ARCH=${ARCH:-i486}
BUILD=1

if [ ! -d $TMP ]; then
  mkdir -p $TMP # location to build the source
fi
rm -rf $PKG
mkdir -p $PKG

# Explode the package framework:
cd $PKG
explodepkg $CWD/_pkgtools.tar.gz

cd $TMP
rm -rf dialog-$DIALOG
tar xzvf $CWD/dialog-$DIALOG.tar.gz
cd dialog-$DIALOG
find . -perm 444 -exec chmod 644 {} \;
chown -R root.root .
# Disable broken arrows in textbox widget:
zcat $CWD/dialog.textbox.noarrows.diff.gz | patch -p1
CFLAGS="-O" \
  ./configure \
  --prefix=/usr \
  --enable-nls
make
strip dialog
cat dialog > $PKG/bin/dialog
cat dialog.1 | gzip -9c > $PKG/usr/man/man1/dialog.1.gz
mkdir -p $PKG/etc
cat samples/slackware.rc > $PKG/etc/dialogrc
cd po
make
for file in *.gmo ; do
  mkdir -p $PKG/usr/share/locale/`basename $file .gmo`/LC_MESSAGES
  cat $file > $PKG/usr/share/locale/`basename $file .gmo`/LC_MESSAGES/dialog.mo
done
cd ..
# Install some docs:
PDOCS=$PKG/usr/doc/dialog-$DIALOG
mkdir -p $PDOCS
cp -a CHANGES COPYING README VERSION dialog.lsm $PDOCS

# This is in the tcpip package along with netconfig now:
#mkdir $TMP/ipmask
#cd $TMP/ipmask
#cc -s -O2 -o ipmask $CWD/ipmask.c
#cat ipmask > $PKG/bin/ipmask

cd $CWD
for page in explodepkg.8 installpkg.8 makepkg.8 upgradepkg.8 pkgtool.8 \
    removepkg.8 ; do
  cat $page | gzip -9c > $PKG/usr/man/man8/$page.gz
done
mkdir -p $PKG/usr/X11R6/man/man1
cat $CWD/xwmconfig.1 | gzip -9c > $PKG/usr/X11R6/man/man1/xwmconfig.1.gz

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

# Build the package:
cd $PKG
makepkg -l y -c n $TMP/pkgtools-$VERSION-$ARCH-$BUILD.tgz

echo
echo "HEY -- did you remember to update the version numbers in the setup scripts?"
echo

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf $TMP/dialog-$DIALOG
  rm -rf $TMP/ipmask
  rm -rf $PKG
fi