#!/bin/sh

# Slackware build script for cups-pdf
# Written by Sebastien Ballet (phenixi@aliceadsl.fr)
# Modified by SlackBuilds.org

PRGNAM=cups-pdf
VERSION=${VERSION:-3.0beta1}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

if [ -z "$ARCH" ]; then
  case "$( uname -m )" in
    i?86) ARCH=i486 ;;
    arm*) ARCH=arm ;;
       *) ARCH=$( uname -m ) ;;
  esac
fi

CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

set -e

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
  LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2 -fPIC"
  LIBDIRSUFFIX="64"
else
  SLKCFLAGS="-O2"
  LIBDIRSUFFIX=""
fi

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar -xvf $CWD/$PRGNAM'_'$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

mkdir -p $PKG/usr/lib${LIBDIRSUFFIX}/cups/backend
gcc $SLCKFLAGS -s -lcups -o $PKG/usr/lib${LIBDIRSUFFIX}/cups/backend/cups-pdf src/cups-pdf.c

chmod 0700 $PKG/usr/lib${LIBDIRSUFFIX}/cups/backend/cups-pdf

mkdir -p $PKG/etc/cups
cat extra/cups-pdf.conf > $PKG/etc/cups/cups-pdf.conf.new

mkdir -p $PKG/usr/share/cups/model
cp -a extra/CUPS-PDF_opt.ppd $PKG/usr/share/cups/model/CUPS-PDF.ppd

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a COPYING ChangeLog README $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

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

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz}
