if test -e ./AMDiS ; then
  echo "there is already an AMDiS directory. I will abort. "
  exit 1
fi

ERROR=""
DOWNLOAD="OK"
svn --username studentiwr co https://gforge.zih.tu-dresden.de/svn/amdis/trunk amdis
if test $? -ne 0 ; then
  DOWNLOAD="NOT OK"
  ERROR="DOWNLOAD"
fi
if test "$1" ; then
  prefix="$1"
else
  prefix=$(pwd)/amdis_installed
fi
echo "prefix: ${prefix}"
if test ! -d ${prefix} ; then
  mkdir --parents ${prefix}
fi
if test ! -d amdis_build ; then
  mkdir amdis_build
fi
cd amdis_build
CONFIGURING="OK"
cmake -DCMAKE_INSTALL_PREFIX=${prefix} ../AMDiS 
if test $? -ne 0; then
  CONFIGURING="NOT OK"
  ERROR="${ERROR} CONFIGURE"
fi
COMPILE="OK"
make
if test $? -ne 0; then
  COMPILE="NOT OK"
  ERROR="${ERROR} COMPILE"
fi
INSTALLING="OK"
make install
if test $? -ne 0; then
  INSTALLING="NOT OK"
  ERROR="${ERROR} INSTALL"
fi
if test -z "${ERROR}"; then
  echo "amdis was successfully downloaded, configured and installed to ${prefix}"
  echo "you can use this installation in cmake with the AMDiS_DIR ${prefix}/share/amdis"
else
  echo "something went wrong: "
  echo "download:  ${DOWNLOAD}"
  echo "configure: ${CONFIGURING}"
  echo "compile:   ${COMPILE}"
  echo "install:   ${INSTALLING}"
fi