#! /bin/sh -

#######################################################################
#                                                                     #
#                              OCamlGen                               #
#                                                                     #
#                       OCaml module Generator                        #
#                                                                     #
#               EPI Pomdapi, INRIA Paris - Rocquencourt               #
#                                                                     #
#  Copyright 1997-2014 INRIA.                                         #
#  Institut National de Recherche en Informatique et en Automatique.  #
#  All rights reserved. This file is distributed only by permission.  #
#                                                                     #
#  Pierre Weis <Pierre.Weis@inria.fr>                                 #
#                                                                     #
#######################################################################

# $Id: configure_user,v 1.9 2014/01/31 09:51:51 fclement Exp $

DEBUG_MODE=false

SCRIPT=`basename $0`

if test "$0" != "./$SCRIPT"; then
    echo "$SCRIPT: error: only launch this script using \"./$SCRIPT\"." 1>&2
    exit 155
fi

debug () {
    if ${DEBUG_MODE:?}; then
        echo "$SCRIPT: $1." 1>&2
    fi
}

debug "Script started"

MKDIR="mkdir -p"

# Use an absolute path or die! As we may act after ``cd'' commands...
PROJECT_ROOT_DIR="${PWD:?}"
PROJECT_CONFIG_DIR="$PROJECT_ROOT_DIR/config"
PROJECT_SUMMARIES_DIR="$PROJECT_CONFIG_DIR/summaries"

$MKDIR "$PROJECT_SUMMARIES_DIR"

# First source specific configuration profile if present.
PROFILE="$PROJECT_CONFIG_DIR/specific_configure.profile"
LOG="$PROJECT_SUMMARIES_DIR/specific_configure_profile.summary"
if test -f "$PROFILE"; then
    debug "Launching specific profile"
    . "$PROFILE" 1> "$LOG"
fi

# Then source generic configuration profile.
PROFILE="$PROJECT_ROOT_DIR/pph/user/scripts/configure.profile"
LOG="$PROJECT_SUMMARIES_DIR/configure_profile.summary"
debug "Launching generic profile"
. "$PROFILE" 1> "$LOG"

# Configuration checkpoint.
$TOUCH "${USER_CONFIGURE_CHECKPOINT:?}"

debug "Script done"

exit 0
