Skip to content

Commit

Permalink
Build flexibility. (#836)
Browse files Browse the repository at this point in the history
Flexibility to call the "build_all.sh" script from anywhere, thereby relaxing 
the need to "cd" into the cloned ufs_utils directory. 

Option to specify a build directory (the default is retained as ./build).

Option to reuse a previously created build directory (the default is to create a 
new "./build" directory with every execution of "build_all.sh" as was before).

Option to provide an installation prefix (the default is retained as the current directory).
  • Loading branch information
aerorahul authored Jul 17, 2023
1 parent 8b7e4a1 commit 9d1622b
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions build_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,72 @@

set -eux

# Get the root of the cloned ufs-utils directory
if [[ $(uname -s) == Darwin ]]; then
readonly DIR_ROOT=$(cd "$(dirname "$(greadlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
else
readonly DIR_ROOT=$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)
fi

# User Options
target=${target:-"NULL"}
compiler=${compiler:-"intel"}
PW_CSP=${PW_CSP:-} # TODO: This is an implementation from EPIC and consistent with the UFS WM build system.
export MOD_PATH

if [[ "$target" == "linux.*" || "$target" == "macosx.*" ]]; then
unset -f module
set +x
source ./modulefiles/build.$target > /dev/null
set -x
unset -f module
set +x
source "${DIR_ROOT}/modulefiles/build.${target}" > /dev/null
set -x
else
set +x
source ./sorc/machine-setup.sh
if [[ "${target}" == "noaacloud" ]]; then
#TODO: This will need to be revisited once the EPIC supported-stacks come online.
#TODO: This is a hack due to how the spack-stack module files are generated; there may be a better way to do this.
source /contrib/global-workflow/spack-stack/envs/spack_2021.0.3.env
else
module use ./modulefiles
fi
module load build.$target.$compiler > /dev/null
module list
set +x
source "${DIR_ROOT}/sorc/machine-setup.sh"
if [[ "${target}" == "noaacloud" ]]; then
#TODO: This will need to be revisited once the EPIC supported-stacks come online.
#TODO: This is a hack due to how the spack-stack module files are generated; there may be a better way to do this.
source /contrib/global-workflow/spack-stack/envs/spack_2021.0.3.env
else
module use "${DIR_ROOT}/modulefiles"
fi
module load "build.$target.$compiler" > /dev/null
module list
set -x
fi

# Ensure the submodules have been initialized.

if [[ ! -d ./ccpp-physics/physics ]]; then
if [[ ! -d "${DIR_ROOT}/ccpp-physics/physics" ]]; then
cd "${DIR_ROOT}"
git submodule init
git submodule update
fi

# Collect BUILD Options
CMAKE_FLAGS+=" -DCMAKE_BUILD_TYPE=${BUILD_TYPE:-Release}"

# Install options; destination for built executables, libraries, CMake Package config
CMAKE_FLAGS+=" -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX:-${DIR_ROOT}} -DCMAKE_INSTALL_BINDIR=${INSTALL_BINDIR:-exec}"

# Testing options
# The unit test data download is part of the build system. Not all machines can
# access the EMC ftp site, so turn off the build (-DBUILD_TESTING=OFF) of the units tests accordingly.
# Those with access to the EMC ftp site are: Orion and Hera.

CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=../ -DCMAKE_INSTALL_BINDIR=exec -DBUILD_TESTING=OFF"
CMAKE_FLAGS+=" -DBUILD_TESTING=${BUILD_TESTING:-OFF}"

# Allow users of this script to provide CMake options e.g. -DGFS=ON|OFF to build GFS specific utilities only
CMAKE_OPTS=${CMAKE_OPTS:-}

rm -fr ./build
mkdir ./build && cd ./build
# Re-use or create a new BUILD_DIR (Default: create new BUILD_DIR)
BUILD_DIR=${BUILD_DIR:-"${DIR_ROOT}/build"}
[[ ${BUILD_CLEAN:-"YES"} =~ [yYtT] ]] && rm -rf "$BUILD_DIR"
mkdir -p "${BUILD_DIR}" && cd "${BUILD_DIR}"

cmake .. ${CMAKE_FLAGS} ${CMAKE_OPTS}
cmake ${CMAKE_FLAGS} ${CMAKE_OPTS} "${DIR_ROOT}"

make -j ${BUILD_JOBS:-8} VERBOSE=${BUILD_VERBOSE:-}
make -j "${BUILD_JOBS:-8}" VERBOSE="${BUILD_VERBOSE:-}"
make install

#ctest
#ctest -I 4,5

exit
exit 0

0 comments on commit 9d1622b

Please sign in to comment.