#!/bin/bash

WORKDIR=`pwd`

echo "This script will download and build all DUNE core modules."
echo
echo "The installation directory is: $WORKDIR"
echo "Third party libraries have to be downloaded manually."
echo "Please take a look at this script for parameters and options."
echo
read -p "Install DUNE core modules to $WORKDIR? (Y/N) " YN
if [ "$YN" != "Y" ] ;then
  exit 1
fi

# this script downloads the necessary set of DUNE core modules
# NOTE: third party libraries need to be downloaded manually and
# added to the config.opts file

#change appropriately, i.e. 2.4 or empty (which refers to master)
DUNEVERSION=2.4

# your favorite compiler optimization flags
FLAGS="-O3 -DNDEBUG"
MAKE_FLAGS="-j4"

# dune modules needed to build the DUNE core modules
DUNEMODULES="dune-common dune-geometry dune-grid dune-istl dune-localfunctions"

if ! test -f config.opts ; then
echo "MAKE_FLAGS=\"$MAKE_FLAGS\"
CMAKE_FLAGS=\"-DCMAKE_CXX_FLAGS=\\\"$FLAGS\\\" \\
             -DENABLE_HEADERCHECK=ON\"" > config.opts
fi

DUNEBRANCH=
if [ "$DUNEVERSION" != "" ] ; then
  DUNEBRANCH="-b releases/$DUNEVERSION"
fi

ALUGRIDBRANCH="-b papers/main"
# get all dune modules necessary
for MOD in $DUNEMODULES ; do
  GIT="$MOD"".git"
  git clone $DUNEBRANCH https://gitlab.dune-project.org/core/$GIT
done

# build all DUNE modules in the correct order
./dune-common/bin/dunecontrol --opts=config.opts all
