#!/bin/sh
# make_iccexamin.sh is a script that generates a DEB ICC Examin package
# from GIT source. Aimed at Ubuntu 8.04

set -o errexit  # Exit when simple command fails.  Same as `set -e'
set -o nounset  # Trigger error when expanding unset variables.  Same as `set -u'

WHO="`whoami` <mail@home.net>"
PKGN="icc_examin"
PKGV="0.46"
PKGR="0"
#PKGF=${PKGN}-${PKGV}.tar.gz
TOP="${HOME}/src"
DEST="$HOME/tmp/${PKGN}"
ARCH="amd64" # or x86
DEB="iccexamin-${PKGV}-${PKGR}_${ARCH}.deb"

# Start from a green field
echo "*** Deleting previous code..."
sudo rm -rf ${TOP}/${PKGN} ${DEST}

echo "*** Going to install dependencies from repository..."
sudo apt-get install \
  build-essential git-core libfltk1.1-dev libpng12-dev \
  libtiff4-dev doxygen liblcms1-dev libx11-dev libxxf86vm-dev libxinerama-dev \
  gettext fakeroot oyranos libxpm-dev ftgl-dev libltdl3-dev

echo "*** Getting the source code..."
if [ -d ${TOP} ] ; then echo "src dir already exists."; else mkdir ${TOP}; fi
cd ${TOP}
# Download the current GIT source code. I do not know how to get a particular revision
git clone git://www.oyranos.org/git/${PKGN}

echo "*** Compiling..."
cd ${PKGN}
./configure --disable-verbose --prefix=/usr/local
make
make DESTDIR=${DEST} install 
mkdir -p -m 0777 ${DEST}/DEBIAN

# Basic description
echo "Package: iccexamin" > ${DEST}/DEBIAN/control
echo "Version: ${PKGV}-${PKGR}" >> ${DEST}/DEBIAN/control
echo "Section: Applications/Graphics" >> ${DEST}/DEBIAN/control
echo "Priority: optional" >> ${DEST}/DEBIAN/control
echo "Architecture: ${ARCH}" >> ${DEST}/DEBIAN/control
echo "Depends: oyranos, libfltk1.1, libpng12-0, libtiff4, liblcms1, libxpm4" >> ${DEST}/DEBIAN/control
echo "Replaces: cinepaint" >> ${DEST}/DEBIAN/control
echo "Maintainer: ${WHO}" >> ${DEST}/DEBIAN/control
echo "Description: ICC Examin is a colour management utility" >> ${DEST}/DEBIAN/control
echo " ICC Examin is a colour management utility" >> ${DEST}/DEBIAN/control

# Do some cleaning
find ${DEST} -type d | xargs chmod 755   # this is necessary on Debian Woody, don't ask me why

# Put it all together
fakeroot dpkg-deb --build ${DEST} ${HOME}/${DEB}

echo "Script $0 completed successfully."

