#!/bin/bash

package=hugin
version=-2012.0.0

progname=$0

source ../cascade-make/lib/cascade-lib.bash GEXT_HUGIN ../.. $*

prefix=$GEXTHUGIN_INSTALLED

# Whether force_config is set for this package depends on CMake test
# to see if 'release' directory has been created or no
if [ $auto_config = "1" ] ; then
  if [ ! -d $package$version/release ]; then
    force_config=1
  fi
fi

opt_run_untar $force_untar $auto_untar $package $version .tar.bz2

if [ $force_config = "1" ] ; then
  echo "[pushd $package$version]"
  ( cd $package$version ; \
    if [ ! -d release ] ; then \
      echo "Creating 'release' directory" ; \
      mkdir release ; \
    fi ; \
    cd release ; \
    LDFLAGS="$LDFLAGS -lgfortran -lutil" CFLAGS="$CFLAGS -lutil" cmake \
          -D CMAKE_INSTALL_PREFIX=$prefix \
          -D ENABLE_LAPACK=YES \
          -D BUILD_HSI:BOOL=OFF \
          ..;
   )
  if [ $? != 0 ] ; then
      echo "      Error encountered running *configure* stage of $progname"
      exit 1
  fi
  echo "[popd]"
else
  if [ $auto_config = "1" ] ; then
    echo "Found top-level for ${progname%.*} => no need to run configure/initialize CMake"
  fi
fi

opt_run_cmake $compile $package $version "release"
opt_run_cmake $install $package $version "release" "install"
opt_run_cmake $clean $package $version "release" "clean"
opt_run_cmake $distclean $package $version "release" "distclean"

opt_run_tarclean $tarclean $package $version

