#!/bin/sh
# Script for building GNOKII package
# Written by Pawe Kot <pkot@linuxnews.pl>

# Set initial variables:
CWD=`pwd`
if [ "${TMP}" = "" ]; then
  TMP=/tmp
fi
PKG=${TMP}/package-xgnokii

NAME=gnokii
VERSION=0.6.12
ARCH=${ARCH:-i486}
BUILD=1

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

cd $TMP
rm -rf ${NAME}-${VERSION}
tar xzvf ${CWD}/${NAME}-${VERSION}.tar.gz
chown -R root.root ${NAME}-${VERSION}
cd ${NAME}-${VERSION}
./configure \
  --prefix=/usr \
  --sysconfdir=/etc \
  --program-prefix="" \
  --program-suffix="" \
  --enable-security \
  --with-x \
  --with-xgnokiidir=/usr/X11R6 \
  ${ARCH}-slackware-linux
make
# File permissions will be set by doinst.sh
make install-strip DESTDIR=${PKG}
make install-docs DESTDIR=${PKG}

gzip -9 ${PKG}/usr/man/man?/*
# Default config
mkdir -P ${PKG}/etc
cp Docs/sample/gnokiirc ${PKG}/etc/gnokiirc.new
mkdir -p ${PKG}/install
cat ${CWD}/slack-desc-xgnokii > ${PKG}/install/slack-desc
cat ${CWD}/doinst-xgnokii.sh > ${PKG}/install/doinst.sh

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

# Clean up the extra stuff:
if [ "$1" = "--cleanup" ]; then
  rm -rf ${TMP}/${NAME}-${VERSION}
  rm -rf ${PKG}
fi
