cc_args=('-O2' '-Wall' '-Wextra')
if [ "$OS" == "Windows_NT" ] ; then
  cc_args_x=('-Wl,--stack=256000000')
elif [ "`uname -o`" == 'GNU/Linux' ] ; then
  ulimit -s unlimited
fi

function compile_cpp
{
  echo "Compile $1 to $2"
  if ! [ -e $2 ] || [[ `stat --format=%z $2` < `stat --format=%z $1` ]] ; then
    echo "  Compile flags: ${cc_args[@]}, ${cc_args_x[@]}"
    g++ --std=gnu++0x -Wno-unused-result "${cc_args[@]}" "${cc_args_x[@]}" $1 -o $2 || die "compile: FAILED"
  else
    echo "  Executable is newer than source; nothing to do."
  fi
}

function die
{
  echo $*
  exit
}
