#!/bin/bash
# make_panomatic.sh is a script that generates a DEB Pan-o-matic package
# from source. Aimed at Ubuntu 8.04 x86_64. Use at your own risk.

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..."
# TODO: Check the list - not all are probably needed.
sudo aptitude -y install build-essential autoconf automake libtool \
  libc6-dev libgcc1 cmake g++ checkinstall \
  libboost-dev boost-build \
  libboost-thread-dev libboost-graph-dev 

LOG="$HOME/panomatic.log"
if [ -f $LOG ]; then rm $LOG; touch $LOG; fi

mkdir -p $HOME/src
cd $HOME/src
VER="0.9.4"
wget -N -r "http://aorlinsk2.free.fr/panomatic/download.php?d=7&v=$VER"
tar -xvjf panomatic-$VER-src.tar.bz2
cd $HOME/src/panomatic-$VER

# These optimisations are for Intel Core 2 Duo only!!
cat /proc/cpuinfo | grep -q "2 Duo CPU"
if [ $? = 0 ]; then
    export CPPFLAGS="-O3 -ffast-math -mtune=nocona -mfpmath=sse -msse3" 
else
    export CPPFLAGS="-O3" 
fi
# Or set manually if cross-compiling
#export CPPFLAGS="-O3 -ffast-math -mtune=nocona -mfpmath=sse -msse3" 

./reconf
./configure --prefix=/usr/local | tee -a "$LOG"
make clean
make | tee -a "$LOG"

cat > description-pak <<'EOF'
Pan-o-matic is a tool that automates the creation of control points in Hugin.
EOF

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

echo "*** Going to create deb package with checkinstall..."
sudo checkinstall \
  --pkgname "panomatic" \
  --pkgversion "$VER" \
  --pkglicense "GPL" \
  --pkggroup "Applications/Graphics" \
  --maintainer "Milan Knizek at volny dot cz" \
  --requires \
    "libboost-thread1.34.1, libc6, \
    libgcc1, libstdc++6" \
  --docdir "/usr/local/share/doc" \
  -D --install=no --default --pakdir $HOME --backup=no | tee -a "$LOG"

echo "Script $0 completed successfully."


