#!/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

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

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"
    exit
  fi
  # add a trailing "/" to $dirname
  dirname=${dirname}"/"
  shift;
fi

# run "fcm build" command
echo "Running <${dirname}fcm build " "$@" ">"
"${dirname}fcm" build "$@"

build_command_status=$?

# cleanup
rm -f '.lock'

exit $build_command_status

