#!/bin/sh
#
# -----------------------------------------------------------------------------
#
# Slackware SlackBuild script 
# ===========================
# By:        Eric Hameleers <alien@sox.homeip.net>
# For:       tv-fonts
# URL:       http://linux.bytesex.org/xawtv/tvfonts.html
# Needs:     
# Changelog:
# 1.1-1:   02/Aug/2005 by Eric Hameleers <alien@sox.homeip.net>
#            * Initial build.
# 
# Run 'sh SlackBuild --cleanup' to build a Slackware package.
# The package (.tgz) plus descriptive .txt file are created in /tmp .
# Install using 'installpkg'. 
#
# -----------------------------------------------------------------------------

# --- INIT ---
# Set initial variables:
CWD=`pwd`
if [ "$TMP" = "" ]; then
  TMP=/tmp
fi

PRGNAM=tv-fonts
VERSION=1.1
ARCH=${ARCH:-noarch}
BUILD=1

PKG=$TMP/package-$PRGNAM

if [ ! -d $TMP/tmp-$PRGNAM ]; then
  mkdir -p $TMP/tmp-$PRGNAM # location to build the source
fi
if [ ! -d $PKG ]; then
  mkdir -p $PKG # place for the package to be built
fi


# --- PACKAGE BUILDING ---

echo "++"
echo "|| $PRGNAM-$VERSION"
echo "++"

rm -rf $PKG/*

cd $TMP/tmp-$PRGNAM


# --- TARBALL EXTRACTION,PATCH,MODIFY ---

echo "Extracting the program tarball for $PRGNAM..."
tar -xjvf $CWD/${PRGNAM}-${VERSION}.tar.bz2

cd ${PRGNAM}-${VERSION}

chown -R root.root *
find . -perm 777 -exec chmod 755 {} \;


# --- BUILDING ---

echo Building ...

make 2>&1 | tee $CWD/make-${PRGNAM}.log

#
# Install all the needed stuff to the package dir
#
mkdir -p $PKG/usr/X11R6/lib/X11/fonts/tv
cp -a *.pcf.gz $PKG/usr/X11R6/lib/X11/fonts/tv/

# We'll use the encodings on the system, so hopefully they are the right ones...
( cd $PKG/usr/X11R6/lib/X11/fonts/tv/
  mkfontdir -e /usr/X11R6/lib/X11/fonts/encodings -e /usr/X11R6/lib/X11/fonts/encodings/large .
)


# --- OWNERSHIP, RIGHTS ---

chmod -R o-w $PKG


# --- PACKAGE DESCRIPTION ---

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
if [ -f $CWD/doinst.sh ]; then
  cat $CWD/doinst.sh > $PKG/install/doinst.sh
fi


# --- BUILDING ---

# Build the package:
cd $PKG
makepkg --linkadd y --chown n $TMP/${PRGNAM}-${VERSION}-${ARCH}-${BUILD}.tgz \
  2>&1 | tee $CWD/makepkg-${PRGNAM}.log
(cd $TMP && md5sum ${PRGNAM}-${VERSION}-${ARCH}-${BUILD}.tgz > ${PRGNAM}-${VERSION}-${ARCH}-${BUILD}.tgz.md5)
cat $CWD/slack-desc | grep "^${PRGNAM}" > $TMP/${PRGNAM}-${VERSION}-${ARCH}-${BUILD}.txt


# --- CLEANUP ---

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