#!/bin/sh
# make_autopano.sh is a script that generates a DEB autopano-sift-c package
# from SVN 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'

echo "*** Going to install dependencies from repository..."
sudo aptitude -y install \
  build-essential autoconf automake libtool flex bison libc6-dev \
  libgcc1 cmake g++ subversion checkinstall  libxml2-dev libgdiplus \
  libtiff4-dev libpng12-dev

LOG=$HOME/autopano.log
SVNDATE="20090817"
DBG=${1-Release}
PAKDBG=""
if [ "${DBG}" = "debug" ]; then DBG="Debug"; PAKDBG="dbg"; echo "Enabling Debug version" | tee -a $LOG; fi

mkdir -p $HOME/src
cd $HOME/src
svn co --revision {${SVNDATE}} https://hugin.svn.sourceforge.net/svnroot/hugin/autopano-sift-C/trunk/ autopano-sift-C | tee $LOG
REL=`cat $LOG | grep "Checked out revision" | sed 's/Checked out revision //' | sed 's/\.//'`
cd autopano-sift-C
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DCMAKE_BUILD_TYPE=$DBG . | tee -a $LOG
make clean | tee -a $LOG
make | tee -a $LOG

cat > description-pak <<'EOF'
This package provides an implementation of the SIFT algorithm and a set of
utilities to utilize the algorithm to match two or more images. As output, a
number of control points are created, which specify one and the same image
location in two images. The output is created as project file for the hugin
panorama stitching software, which is available at http://hugin.sf.net/
EOF

cat > postinstall-pak <<'EOF'
#!/bin/sh
set -e
ldconfig
EOF

echo "*** Going to create deb package with checkinstall..."
sudo checkinstall \
  --pkgname "autopano-sift-c" \
  --pkgversion "2.5.0beta$PAKDBG" \
  --pkgrelease "$REL" \
  --pkglicense "GPL 2" \
  --pkggroup "Applications/Graphics" \
  --maintainer "Milan Knizek at volny dot cz" \
  --requires \
    "libgdiplus, libglade2.0-cil, libglib2.0-cil, libgtk2.0-cil, \
    libmono-corlib1.0-cil, libmono-sharpzip0.84-cil, \
    libmono-system1.0-cil, mono-runtime" \
  --docdir "/usr/local/share/doc" \
  -D --install=no --default --pakdir $HOME --backup=no | tee -a "$LOG"

echo "Script $0 completed successfully."

