#!/bin/bash
# This script needs to be run before the  cmake  command for CMake
# builds. It should be called from all cmake scripts. 
#
# This script auto-generates files that were autogerenated as part 
# of the autoconf system.

echo
echo "Automated copy of config.inc and glimmer_vers.F90 to build directory"
echo

mkdir -p fortran_autogen_srcs
pushd fortran_autogen_srcs

if [ $# -eq 1 ];
  then
    export CISM_SOURCE_DIR=$1 
  else
    export CISM_SOURCE_DIR=../../../
echo $1
fi
echo "Auto-copy script is using CISM source directory: "
echo $CISM_SOURCE_DIR

# Just a copy of a file without version info
# pushd ../libglimmer
echo "  --making copy of glimmer_vers.F90"
cp -p $CISM_SOURCE_DIR/libglimmer/glimmer_vers.F90.cmake.in glimmer_vers.F90

# Just a copy of a file with minimal info
popd
mkdir -p fortran_autocopy_includes
pushd fortran_autocopy_includes

echo "  --making copy of config.inc"
cp -p $CISM_SOURCE_DIR/utils/build/config.inc_generator/config.inc.cmake.in config.inc
popd
