#!/bin/sh

# Slackware build script for ECI and Adobe ICC Profiles
# Written by klaatu at klaatu@hackerpublicradio.org
# with a buncha corrections by thrice`

PRGNAM=iccprofiles
VERSION=${VERSION:-2011}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}

# icc profiles are arch independent
ARCH=noarch

# get ready for some
# really bad naming schemes cuz color profile
# people and artists have no clue about logic or consistency

ADBNAM=Adobe\ ICC\ Profiles\ \(end-user\)
ECINAM=ECI_Offset_2009
RGBNAM=eciRGB_v2_profile

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

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION

if [ "${ADOBE}" != "no" ]; then
	unzip $CWD/Adobe*.zip

	# install Adobe profiles, without those ugly spaces
	install -d $PKG/usr/share/color/icc/${ADBNAM// /_}-${VERSION}/
	install -m644 "${ADBNAM}"/CMYK\ Profiles/*.icc \
	  $PKG/usr/share/color/icc/${ADBNAM// /_}-${VERSION}/
	install -m644 "${ADBNAM}"/RGB\ Profiles/*.icc \
	  $PKG/usr/share/color/icc/${ADBNAM// /_}-${VERSION}/

	# Add adobe docs
	mkdir -p $PKG/usr/doc/${PRGNAM}-${VERSION}/${ADBNAM// /_}
	install -m644 "${ADBNAM}"/*.pdf \
	  $PKG/usr/doc/${PRGNAM}-${VERSION}/${ADBNAM// /_}/
fi

if [ "$ECI" != "no" ]; then
	unzip $CWD/eci_offset*.zip
	unzip $CWD/ecirgb*.zip

	# Install ECI_Offset profiles
	install -d $PKG/usr/share/color/icc/${ECINAM}-${VERSION}/
	install -m644 ${ECINAM}/*.icc \
	  $PKG/usr/share/color/icc/${ECINAM}-${VERSION}/

	# Add ECI_Offset docs
	mkdir -p $PKG/usr/doc/${PRGNAM}-${VERSION}/${ECINAM}/
	install -m644 ${ECINAM}/*.pdf \
          $PKG/usr/doc/${PRGNAM}-${VERSION}/${ECINAM}/

	# Install eciRGB profiles
        install -d $PKG/usr/share/color/icc/${RGBNAM}-${VERSION}/
	install -m644 ${RGBNAM}/*.icc \
          $PKG/usr/share/color/icc/${RGBNAM}-${VERSION}/

	# Add RGB docs
	mkdir -p $PKG/usr/doc/${PRGNAM}-${VERSION}/${RGBNAM}/
	install -m644 ${RGBNAM}/*.rtf \
	  $PKG/usr/doc/${PRGNAM}-${VERSION}/${RGBNAM}/
fi

mkdir -p $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

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