#!/bin/bash
# Usage:
# ./build_gcm [path]
# where 'path' is an optional argument to this script specifying
# the full path to where the 'fcm' command is to be found

job=1
dirname="" #path to where the fcm command will be found
if (( $# >= 1 )) ; then
  dirname=$1
  # check that "dirname" exists and is a directory
  if [[ ! -d $dirname ]] ; then
    echo "$0 error : $dirname is not a directory" >&2
    exit 1
  fi
  # add a trailing "/" to $dirname
  dirname=${dirname}"/"
  shift;
fi

if [[ -f '.lock' && $force_compile == false ]]
then
    echo "WARNING: you are probably already compiling the model somewhere else."
    echo "Wait until the first compilation is finished before launching this one."
    echo "If you are sure that you are not compiling elsewhere,"
    echo "run makelmdz_fcm with option -force_compile"
    exit 1
fi

echo "compiling..." > '.lock'

# run "fcm build" command
${dirname}fcm build $*

build_command_status=$?

# cleanup
\rm -f '.lock' 

exit $build_command_status

