From fa8c33168e13ef9178258636ae93ad40b7f00e48 Mon Sep 17 00:00:00 2001 From: Panagiotis Velissariou Date: Thu, 13 May 2021 12:41:15 -0500 Subject: [PATCH] Updated build.sh file --- build.sh | 215 +----- scripts/build-v1.0.sh | 214 ++++++ scripts/build-v1.1.sh | 227 +++++++ scripts/functions_build | 617 ++++++++++++++++++ .../functions_build-v1.0 | 0 scripts/functions_build.del | 617 ++++++++++++++++++ 6 files changed, 1676 insertions(+), 214 deletions(-) mode change 100755 => 120000 build.sh create mode 100644 scripts/build-v1.0.sh create mode 100644 scripts/build-v1.1.sh create mode 100644 scripts/functions_build rename functions_build => scripts/functions_build-v1.0 (100%) create mode 100644 scripts/functions_build.del diff --git a/build.sh b/build.sh deleted file mode 100755 index ba6f6cb4..00000000 --- a/build.sh +++ /dev/null @@ -1,214 +0,0 @@ -#!/bin/bash - -########################################################################### -### Author: Panagiotis Velissariou -### -### Version - 1.0 Fri Dec 04 2020 -########################################################################### - - -###==================== -# Make sure that the current working directory is in the PATH -[[ ! :$PATH: == *:".":* ]] && export PATH="${PATH}:." - - -# Get the directory where the script is located -scrNAME="${BASH_SOURCE[0]}" -if [[ $(uname -s) == Darwin ]]; then -# readonly scrDIR="$(cd "$(dirname "$(greadlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)" - readonly scrDIR="$(cd "$(dirname "$(grealpath -s "${scrNAME}" )" )" && pwd -P)" -else -# readonly scrDIR="$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)" - readonly scrDIR="$(cd "$(dirname "$(realpath -s "${scrNAME}")" )" && pwd -P)" -fi - -funcs="$( find ${scrDIR} -type f -name "functions_build" | head -n 1 )" -if [ -f "${funcs}" ]; then - source "${funcs}" -else - echo " ### ERROR :: in ${scrNAME}" - echo " Cannot load the required file: ${funcs}" - echo " Exiting now ..." - echo - exit 1 -fi - -unset funcs -###==================== - - -######### -# Call ParseArgs to get the user input. -ParseArgs "${@}" - - -########## -# Set the variables for this script -CLEAN=${MY_CLEAN:-0} - -[ -n "${MY_COMPILER:+1}" ] && COMPILER="$( toLOWER "${MY_COMPILER}" )" - -[ -n "${MY_COMPONENT:+1}" ] && COMPONENT="$( toUPPER "${MY_COMPONENT}" )" - -[ -n "${MY_OS:+1}" ] && OS="$( toLOWER "${MY_OS}" )" - -[ "${MY_PARMAKE:0}" -gt 1 ] && PARMAKE=${MY_PARMAKE} - -[ -n "${MY_PLATFORM:+1}" ] && PLATFORM="$( toLOWER "${MY_PLATFORM}" )" - -[ -n "${MY_VERBOSE:+1}" ] && VERBOSE="$( toLOWER "${MY_VERBOSE}" )" - -modFILE="envmodules${COMPILER:+_${COMPILER}}${PLATFORM:+.${PLATFORM}}" - -# Customize the NEMS.x filename to include the component names -if [ -n "${COMPONENT:+1}" ]; then - compFNAME="$( strTrim "$( toLOWER "${COMPONENT}" )" )" - compFNAME="$( echo "${compFNAME}" | sed 's/ /_/g' )" -fi - -# Export some environment variables for NEMS -export NEMS_COMPILER=${COMPILER} -########## - - -########## -# Get the project directories and perform a basic check on them -readonly nemsDIR="${NEMS_DIR:-${scrDIR}/NEMS}" -if [ ! -f "${nemsDIR}/NEMSAppBuilder" ]; then - echo "The project directory \"${nemsDIR}\" does not appear to contain NEMSAppBuilder." - echo "Is this the correct NEMS directory?" - echo "You might need to set the environment variable NEMS_DIR before running this script." - echo "Exiting ..." - exit 1 -fi - -readonly modDIR="${NEMSMODS_DIR:-${scrDIR}/modulefiles}" -if [ ! -f "${modDIR}/${modFILE}" ]; then - echo "The modulefiles directory \"${modDIR}\" does not appear to contain module: ${modFILE}." - echo "Is this the correct modulefiles directory?" - echo "You might need to set the environment variable NEMSMODS_DIR before running this script." - echo "Exiting ..." - exit 1 -fi -########## - - -########## -# If the user requested to clean the build folder, do the cleaning end exit -if [ ${CLEAN:-0} -ge 1 ]; then - echo "User requested to only clean the project. Cleaning ..." - - pushd ${nemsDIR} >/dev/null 2>&1 - [ ${CLEAN:-0} -eq 1 ] && compileNems clean - [ ${CLEAN:-0} -eq 2 ] && compileNems distclean - popd >/dev/null 2>&1 - - exit 0 -fi -########## - - -########## -# Source the environment module -source ${modDIR}/${modFILE} - -component_ww3="$( echo "${COMPONENT}" | sed 's/ /:/g' )" -if [[ :${component_ww3}: == *:"WW3":* ]]; then - export WW3_CONFOPT="${COMPILER}" - export WW3_COMP="${COMPILER}" - export WWATCH3_NETCDF=NC4 -fi -########## - - -########## -# Get a final user response for the variables -echo -echo "The following variables are defined:" -echo " CLEAN = ${CLEAN}" -echo " COMPILER = ${COMPILER:-Undefined, Supported values are: [${MY_COMPILING_SYTEMS}]}" -echo " NEMS_COMPILER = ${NEMS_COMPILER}" -if [[ :${component_ww3}: == *:"WW3":* ]]; then - echo " WW3_CONFOPT = ${WW3_CONFOPT}" - echo " WW3_COMP = ${WW3_COMP}" - echo " WWATCH3_NETCDF = ${WWATCH3_NETCDF}" -fi -echo " COMPONENTS = ${COMPONENT:-Undefined, Supported values are: [${MY_COMPONENT_LIST}]}" -echo " OS = ${OS}" -echo " PLATFORM = ${PLATFORM}" -echo " VERBOSE = ${VERBOSE}" -echo -echo " HDF5HOME = ${HDF5HOME}" -echo " NETCDFHOME = ${NETCDFHOME}" -echo " NETCDF_INCDIR = ${NETCDF_INCDIR}" -echo " NETCDF_LIBDIR = ${NETCDF_LIBDIR}" -echo -echo " ESMFMKFILE = ${ESMFMKFILE}" -echo - -module list - -echo_response= -while [ -z "${echo_response}" ] ; do - echo -n "Are these values correct? [y/n]: " - read echo_response - echo_response="$( getYesNo "${echo_response}" )" -done - -if [ "${echo_response:-no}" = "no" ]; then - echo - echo "User responded: ${echo_response}" - echo "Exiting now ..." - echo - exit 1 -fi - -unset echo_response -########## - - -############################################################ -### START THE CALCULATIONS -############################################################ - -########## -# Compile the project -compileERR=0 -pushd ${nemsDIR} >/dev/null 2>&1 - case ${CLEAN:-0} in - -1 ) - compileNems clean - compileERR=$? - ;; - -2 ) - compileNems distclean - compileERR=$? - ;; - -3 ) - compileNems noclean - compileERR=$? - ;; - * ) - compileNems clean - compileERR=$? - ;; - esac - - if [ ${compileERR} -eq 0 ]; then - compileNems build - compileERR=$? - fi - - if [ ${compileERR} -eq 0 ]; then - if [ -f exe/NEMS.x ]; then - cp -p exe/NEMS.x exe/NEMS${compFNAME:+-${compFNAME}}.x - fi - fi -popd >/dev/null 2>&1 - -########## -# Install all data, executables, libraries in a common directory -[ ${compileERR:-0} -eq 0 ] && installNems -########## - -exit 0 diff --git a/build.sh b/build.sh new file mode 120000 index 00000000..7def0452 --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +scripts/build-v1.1.sh \ No newline at end of file diff --git a/scripts/build-v1.0.sh b/scripts/build-v1.0.sh new file mode 100644 index 00000000..ba6f6cb4 --- /dev/null +++ b/scripts/build-v1.0.sh @@ -0,0 +1,214 @@ +#!/bin/bash + +########################################################################### +### Author: Panagiotis Velissariou +### +### Version - 1.0 Fri Dec 04 2020 +########################################################################### + + +###==================== +# Make sure that the current working directory is in the PATH +[[ ! :$PATH: == *:".":* ]] && export PATH="${PATH}:." + + +# Get the directory where the script is located +scrNAME="${BASH_SOURCE[0]}" +if [[ $(uname -s) == Darwin ]]; then +# readonly scrDIR="$(cd "$(dirname "$(greadlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)" + readonly scrDIR="$(cd "$(dirname "$(grealpath -s "${scrNAME}" )" )" && pwd -P)" +else +# readonly scrDIR="$(cd "$(dirname "$(readlink -f -n "${BASH_SOURCE[0]}" )" )" && pwd -P)" + readonly scrDIR="$(cd "$(dirname "$(realpath -s "${scrNAME}")" )" && pwd -P)" +fi + +funcs="$( find ${scrDIR} -type f -name "functions_build" | head -n 1 )" +if [ -f "${funcs}" ]; then + source "${funcs}" +else + echo " ### ERROR :: in ${scrNAME}" + echo " Cannot load the required file: ${funcs}" + echo " Exiting now ..." + echo + exit 1 +fi + +unset funcs +###==================== + + +######### +# Call ParseArgs to get the user input. +ParseArgs "${@}" + + +########## +# Set the variables for this script +CLEAN=${MY_CLEAN:-0} + +[ -n "${MY_COMPILER:+1}" ] && COMPILER="$( toLOWER "${MY_COMPILER}" )" + +[ -n "${MY_COMPONENT:+1}" ] && COMPONENT="$( toUPPER "${MY_COMPONENT}" )" + +[ -n "${MY_OS:+1}" ] && OS="$( toLOWER "${MY_OS}" )" + +[ "${MY_PARMAKE:0}" -gt 1 ] && PARMAKE=${MY_PARMAKE} + +[ -n "${MY_PLATFORM:+1}" ] && PLATFORM="$( toLOWER "${MY_PLATFORM}" )" + +[ -n "${MY_VERBOSE:+1}" ] && VERBOSE="$( toLOWER "${MY_VERBOSE}" )" + +modFILE="envmodules${COMPILER:+_${COMPILER}}${PLATFORM:+.${PLATFORM}}" + +# Customize the NEMS.x filename to include the component names +if [ -n "${COMPONENT:+1}" ]; then + compFNAME="$( strTrim "$( toLOWER "${COMPONENT}" )" )" + compFNAME="$( echo "${compFNAME}" | sed 's/ /_/g' )" +fi + +# Export some environment variables for NEMS +export NEMS_COMPILER=${COMPILER} +########## + + +########## +# Get the project directories and perform a basic check on them +readonly nemsDIR="${NEMS_DIR:-${scrDIR}/NEMS}" +if [ ! -f "${nemsDIR}/NEMSAppBuilder" ]; then + echo "The project directory \"${nemsDIR}\" does not appear to contain NEMSAppBuilder." + echo "Is this the correct NEMS directory?" + echo "You might need to set the environment variable NEMS_DIR before running this script." + echo "Exiting ..." + exit 1 +fi + +readonly modDIR="${NEMSMODS_DIR:-${scrDIR}/modulefiles}" +if [ ! -f "${modDIR}/${modFILE}" ]; then + echo "The modulefiles directory \"${modDIR}\" does not appear to contain module: ${modFILE}." + echo "Is this the correct modulefiles directory?" + echo "You might need to set the environment variable NEMSMODS_DIR before running this script." + echo "Exiting ..." + exit 1 +fi +########## + + +########## +# If the user requested to clean the build folder, do the cleaning end exit +if [ ${CLEAN:-0} -ge 1 ]; then + echo "User requested to only clean the project. Cleaning ..." + + pushd ${nemsDIR} >/dev/null 2>&1 + [ ${CLEAN:-0} -eq 1 ] && compileNems clean + [ ${CLEAN:-0} -eq 2 ] && compileNems distclean + popd >/dev/null 2>&1 + + exit 0 +fi +########## + + +########## +# Source the environment module +source ${modDIR}/${modFILE} + +component_ww3="$( echo "${COMPONENT}" | sed 's/ /:/g' )" +if [[ :${component_ww3}: == *:"WW3":* ]]; then + export WW3_CONFOPT="${COMPILER}" + export WW3_COMP="${COMPILER}" + export WWATCH3_NETCDF=NC4 +fi +########## + + +########## +# Get a final user response for the variables +echo +echo "The following variables are defined:" +echo " CLEAN = ${CLEAN}" +echo " COMPILER = ${COMPILER:-Undefined, Supported values are: [${MY_COMPILING_SYTEMS}]}" +echo " NEMS_COMPILER = ${NEMS_COMPILER}" +if [[ :${component_ww3}: == *:"WW3":* ]]; then + echo " WW3_CONFOPT = ${WW3_CONFOPT}" + echo " WW3_COMP = ${WW3_COMP}" + echo " WWATCH3_NETCDF = ${WWATCH3_NETCDF}" +fi +echo " COMPONENTS = ${COMPONENT:-Undefined, Supported values are: [${MY_COMPONENT_LIST}]}" +echo " OS = ${OS}" +echo " PLATFORM = ${PLATFORM}" +echo " VERBOSE = ${VERBOSE}" +echo +echo " HDF5HOME = ${HDF5HOME}" +echo " NETCDFHOME = ${NETCDFHOME}" +echo " NETCDF_INCDIR = ${NETCDF_INCDIR}" +echo " NETCDF_LIBDIR = ${NETCDF_LIBDIR}" +echo +echo " ESMFMKFILE = ${ESMFMKFILE}" +echo + +module list + +echo_response= +while [ -z "${echo_response}" ] ; do + echo -n "Are these values correct? [y/n]: " + read echo_response + echo_response="$( getYesNo "${echo_response}" )" +done + +if [ "${echo_response:-no}" = "no" ]; then + echo + echo "User responded: ${echo_response}" + echo "Exiting now ..." + echo + exit 1 +fi + +unset echo_response +########## + + +############################################################ +### START THE CALCULATIONS +############################################################ + +########## +# Compile the project +compileERR=0 +pushd ${nemsDIR} >/dev/null 2>&1 + case ${CLEAN:-0} in + -1 ) + compileNems clean + compileERR=$? + ;; + -2 ) + compileNems distclean + compileERR=$? + ;; + -3 ) + compileNems noclean + compileERR=$? + ;; + * ) + compileNems clean + compileERR=$? + ;; + esac + + if [ ${compileERR} -eq 0 ]; then + compileNems build + compileERR=$? + fi + + if [ ${compileERR} -eq 0 ]; then + if [ -f exe/NEMS.x ]; then + cp -p exe/NEMS.x exe/NEMS${compFNAME:+-${compFNAME}}.x + fi + fi +popd >/dev/null 2>&1 + +########## +# Install all data, executables, libraries in a common directory +[ ${compileERR:-0} -eq 0 ] && installNems +########## + +exit 0 diff --git a/scripts/build-v1.1.sh b/scripts/build-v1.1.sh new file mode 100644 index 00000000..30f8880e --- /dev/null +++ b/scripts/build-v1.1.sh @@ -0,0 +1,227 @@ +#!/bin/bash + +########################################################################### +### Author: Panagiotis Velissariou +### +### Version - 1.1 +### +### 1.1 Wed Apr 14 2021 +### 1.0 Fri Dec 04 2020 +########################################################################### + + +###==================== +# Make sure that the current working directory is in the PATH +[[ ! :$PATH: == *:".":* ]] && export PATH="${PATH}:." + + +# Get the directory where the script is located +if [[ $(uname -s) == Darwin ]]; then + readonly scrNAME="$( grealpath -s "${BASH_SOURCE[0]}" )" + readonly scrDIR="$(cd "$(dirname "${scrNAME}" )" && pwd -P)" +else + readonly scrNAME="$( realpath -s "${BASH_SOURCE[0]}" )" + readonly scrDIR="$(cd "$(dirname "$(realpath -s "${BASH_SOURCE[0]}")" )" && pwd -P)" +fi + +funcs="$( find ${scrDIR} -type f -name "functions_build" | head -n 1 )" +if [ -f "${funcs}" ]; then + source "${funcs}" +else + echo " ### ERROR :: in ${scrNAME}" + echo " Cannot load the required file: ${funcs}" + echo " Exiting now ..." + echo + exit 1 +fi + +unset funcs +###==================== + + +######### +# Call ParseArgs to get the user input. +ParseArgs "${@}" + + +########## +# Set the variables for this script +CLEAN=${MY_CLEAN:-0} + +[ -n "${MY_COMPILER:+1}" ] && COMPILER="$( toLOWER "${MY_COMPILER}" )" + +[ -n "${MY_COMPONENT:+1}" ] && COMPONENT="$( toUPPER "${MY_COMPONENT}" )" + + +[ -n "${MY_OS:+1}" ] && OS="$( toLOWER "${MY_OS}" )" +if [ -n "${MY_PLATFORM:+1}" ]; then + PLATFORM="$( toLOWER "${MY_PLATFORM}" )" +else + PLATFORM="${OS}" +fi +export NEMS_PLATFORM=${PLATFORM} +export MACHINE_ID=${PLATFORM} + + +[ "${MY_PARMAKE:0}" -gt 1 ] && PARMAKE=${MY_PARMAKE} + +[ -n "${MY_VERBOSE:+1}" ] && VERBOSE="$( toLOWER "${MY_VERBOSE}" )" + +modFILE="envmodules${COMPILER:+_${COMPILER}}${PLATFORM:+.${PLATFORM}}" + +# Customize the NEMS.x filename to include the component names +if [ -n "${COMPONENT:+1}" ]; then + compFNAME="$( strTrim "$( toLOWER "${COMPONENT}" )" )" + compFNAME="$( echo "${compFNAME}" | sed 's/ /_/g' )" +fi + +# Export some environment variables for NEMS +export NEMS_COMPILER=${COMPILER} +########## + + +########## +# Get the project directories and perform a basic check on them +readonly nemsDIR="${NEMS_DIR:-${scrDIR}/NEMS}" +if [ ! -f "${nemsDIR}/NEMSAppBuilder" ]; then + echo "The project directory \"${nemsDIR}\" does not appear to contain NEMSAppBuilder." + echo "Is this the correct NEMS directory?" + echo "You might need to set the environment variable NEMS_DIR before running this script." + echo "Exiting ..." + exit 1 +fi + +readonly modDIR="${NEMSMODS_DIR:-${scrDIR}/modulefiles}" +if [ ! -f "${modDIR}/${modFILE}" ]; then + echo + echo "The modulefiles directory \"${modDIR}\" does not appear to contain the module file: ${modFILE}." + echo "Is this the correct \"modulefiles\" directory?" + echo "You might need to set the environment variable \"NEMSMODS_DIR\" to point to a custom modulefiles directory before running this script." + echo "Exiting ..." + echo + exit 1 +fi +########## + + +########## +# If the user requested to clean the build folder, do the cleaning end exit +if [ ${CLEAN:-0} -ge 1 ]; then + echo "User requested to only clean the project. Cleaning ..." + + pushd ${nemsDIR} >/dev/null 2>&1 + [ ${CLEAN:-0} -eq 1 ] && compileNems clean + [ ${CLEAN:-0} -eq 2 ] && compileNems distclean + popd >/dev/null 2>&1 + + exit 0 +fi +########## + + +########## +# Source the environment module +source ${modDIR}/${modFILE} + +component_ww3="$( echo "${COMPONENT}" | sed 's/ /:/g' )" +if [[ :${component_ww3}: == *:"WW3":* ]]; then + export WW3_CONFOPT="${COMPILER}" + export WW3_COMP="${COMPILER}" + export WWATCH3_NETCDF=NC4 +fi +########## + + +########## +# Get a final user response for the variables +echo +echo "The following variables are defined:" +echo " CLEAN = ${CLEAN}" +echo " COMPILER = ${COMPILER:-Undefined, Supported values are: [${MY_COMPILING_SYTEMS}]}" +echo " NEMS_COMPILER = ${NEMS_COMPILER}" +echo " MODULES FILE = ${modFILE}" +if [[ :${component_ww3}: == *:"WW3":* ]]; then + echo " WW3_CONFOPT = ${WW3_CONFOPT}" + echo " WW3_COMP = ${WW3_COMP}" + echo " WWATCH3_NETCDF = ${WWATCH3_NETCDF}" +fi +echo " COMPONENTS = ${COMPONENT:-Undefined, Supported values are: [${MY_COMPONENT_LIST}]}" +echo " OS = ${OS}" +echo " PLATFORM = ${PLATFORM}" +echo " VERBOSE = ${VERBOSE}" +echo +echo " HDF5HOME = ${HDF5HOME}" +echo " NETCDFHOME = ${NETCDFHOME}" +echo " NETCDF_INCDIR = ${NETCDF_INCDIR}" +echo " NETCDF_LIBDIR = ${NETCDF_LIBDIR}" +echo +echo " ESMFMKFILE = ${ESMFMKFILE}" +echo + +module list + + +echo_response= +while [ -z "${echo_response}" ] ; do + echo -n "Are these values correct? [y/n]: " + read echo_response + echo_response="$( getYesNo "${echo_response}" )" +done + +if [ "${echo_response:-no}" = "no" ]; then + echo + echo "User responded: ${echo_response}" + echo "Exiting now ..." + echo + exit 1 +fi + +unset echo_response +########## + + +############################################################ +### START THE CALCULATIONS +############################################################ + +########## +# Compile the project +compileERR=0 +pushd ${nemsDIR} >/dev/null 2>&1 + case ${CLEAN:-0} in + -1 ) + compileNems clean + compileERR=$? + ;; + -2 ) + compileNems distclean + compileERR=$? + ;; + -3 ) + compileNems noclean + compileERR=$? + ;; + * ) + compileNems clean + compileERR=$? + ;; + esac + + if [ ${compileERR} -eq 0 ]; then + compileNems build + compileERR=$? + fi + + if [ ${compileERR} -eq 0 ]; then + if [ -f exe/NEMS.x ]; then + cp -p exe/NEMS.x exe/NEMS${compFNAME:+-${compFNAME}}.x + fi + fi +popd >/dev/null 2>&1 + +########## +# Install all data, executables, libraries in a common directory +[ ${compileERR:-0} -eq 0 ] && installNems +########## + +exit 0 diff --git a/scripts/functions_build b/scripts/functions_build new file mode 100644 index 00000000..ebb69270 --- /dev/null +++ b/scripts/functions_build @@ -0,0 +1,617 @@ +#!/bin/bash-*-Shell-script-functions*- + +########################################################################### +### Author: Panagiotis Velissariou +### +### Version - 1.0 Fri Dec 04 2020 +########################################################################### + +set +u + +MY_COMPILING_SYTEMS="gnu, intel, pgi" + +MY_ATM_MODS="ATMESH WRF HWRF PAHM" +MY_OCN_MODS="ADCIRC SCHISM FVCOM ROMS" +MY_HYD_MODS="NWM" +MY_WAV_MODS="WW3DATA WW3" + +MY_COMPONENT_LIST="${MY_ATM_MODS} ${MY_OCN_MODS} ${MY_HYD_MODS} ${MY_WAV_MODS} " + +################################################## +### MODELLING SYSTEM BUILD FUNCTIONS +################################################## + +###======================================== +### ParseArgs() +### Usage: ParseArgs args +### Parameters: args = the script options +### Returns: 0 +### Echoes: NONE +### +### Gets the supplied options to the script. +###======================================== +ParseArgs() +{ + local nm_func=$( basename ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} ) + + local opt_all opt_opt opt_arg opt_chk + + local t_VAR + local ans0 ans ival intN + local all_evars + + all_evars="MY_CLEAN MY_COMPILER MY_COMPONENT MY_OS MY_PARMAKE MY_PLATFORM MY_VERBOSE" + + for ival in ${all_evars}; do unset __${ival}; done + + + __MY_CLEAN=0 + __MY_COMPILER=intel + __MY_COMPONENT="ADCIRC WW3DATA ATMESH" + __MY_OS= + __MY_PARMAKE=1 + __MY_PLATFORM= + __MY_VERBOSE= + + + # ----- + # Process the function options + opt_all=( c clean compiler component j os plat v verbose h help ) + opt_all=":$( echo "${opt_all[@]/#/-} ${opt_all[@]/#/--}" | sed 's/ /:/g' ):" + + unset __OPTION_LIST + while test $# -gt 0; do + case "${1}" in + -[^-]*=* | --[^-]*=* ) + opt_opt="$( toLOWER "$( echo "${1}" | sed 's/=.*//' )" )" + len=$(( ${#opt_opt} + 1 )) + opt_arg="$( strTrim "$( echo "${1:${len}}" )" 2 )" + [ "$( echo "${opt_all}" | egrep -o ":${opt_arg}:" )" ] && \ + opt_arg= + ;; + -[^-]* | --[^-]* ) + opt_opt="$( toLOWER "${1}" )" + opt_chk="$( toLOWER "$( echo "${2}" | sed 's/=.*//' )" )" + if [ "$( echo "${opt_all}" | egrep -o ":${opt_chk}:" )" ]; then + opt_arg= + else + opt_arg="$( strTrim "$( echo "${2}" )" )" + fi + ;; + *) + opt_opt= + opt_arg= + ;; + esac + + case "${opt_opt}" in + -c | --c | -clean | --clean ) + checkFuncOpt "--clean" + if [ $? -eq 0 ]; then + __MY_CLEAN=1 + if [ "X${opt_arg}" != "X" ]; then + if `isInteger "${opt_arg}"` ; then + __MY_CLEAN=$( echo "${opt_arg}" ) + [ ${opt_arg} -le -3 ] && __MY_CLEAN=-3 + [ ${opt_arg} -ge 2 ] && __MY_CLEAN=2 + else + __MY_CLEAN=0 + [ "$( getYesNo "${opt_arg}" )" = "yes" ] && __MY_CLEAN=1 + fi + fi + fi + ;; + -compiler | --compiler ) + checkFuncOpt "--compiler" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_COMPILER="$( echo "${opt_arg}" | sed 's/[[:space:]]//g' )" + fi + fi + ;; + -component | --component ) + checkFuncOpt "--component" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_COMPONENT="$( strTrim "${opt_arg}" )" + fi + fi + ;; + -j | --j ) + checkFuncOpt "--j" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_PARMAKE=1 + t_VAR="$( getPosInteger "${opt_arg}" )" + [ ! -z "${t_VAR}" ] && __MY_PARMAKE=${t_VAR} + fi + fi + ;; + -os | --os ) + checkFuncOpt "--os" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_OS="$( echo "${opt_arg}" | sed 's/[[:space:]]//g' )" + fi + fi + ;; + -plat | --plat ) + checkFuncOpt "--plat" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_PLATFORM="$( echo "${opt_arg}" | sed 's/[[:space:]]//g' )" + fi + fi + ;; + -v | --v | -verbose | --verbose ) + checkFuncOpt "--verbose" + if [ $? -eq 0 ]; then + __MY_VERBOSE=b + if [ "X${opt_arg}" != "X" ]; then + __MY_VERBOSE="$( echo "$( strTrim "${opt_arg}" 2 )" | sed 's/[[:space:]]/,/g' )" + fi + fi + ;; + -h | -help | --h | --help ) + UsageBuild ${nm_func} + ;; + *) ;; # DEFAULT + esac + shift + opt_opt= + opt_arg= + done + unset __OPTION_LIST + # ----- + + if [ -z "${__MY_OS}" ]; then + case "$(uname -s)" in + Darwin ) __MY_OS="macosx" ;; + Linux ) __MY_OS="linux" ;; + *) __MY_OS="UNDEFINED";; # DEFAULT + esac + fi + + # Export the values of all __* variables. + for ival in ${all_evars} + do + ans0="$( eval "echo \${$(echo ${ival}):-}" )" + ans="$( eval "echo \${$(echo __${ival}):-}" )" + ans=${ans:-${ans0:-}} + + eval "${ival}=\${ans}" + export ${ival} + + unset __${ival} + done + + return 0 +} + +UsageBuild() +{ + local nm="$( basename ${0} )" + + echo + echo "Usage: \"${nm}\" [{-|--}option1{=|space}[option_value1]] [{-|--}option2{=|space}[option_value2]] ..." + echo + + echo " -h|-help|--h|--help" + echo " Show this help screen." + echo + #--- + echo " -c|--c|-clean|--clean [=|space] \"0|1|yes|no\" (OPTIONAL)." + echo " Only clean the already compiled CMake build system." + echo " Default: 0|no." + echo + #--- + echo " -compiler|--compiler [=|space] \"compiling_system\" (OPTIONAL)." + echo " The compiling system to use (${MY_COMPILING_SYTEMS})." + echo " Default: intel." + echo + #--- + echo " -component|--component [=|space] \"component_list\" (OPTIONAL)." + echo " The component(s) to use (${MY_COMPONENT_LIST})." + echo " Default: \"ADCIRC WW3DATA ATMESH\"." + echo + #--- + echo " -j|--j [=|space] \"N\" (OPTIONAL)." + echo " Define the number of make jobs to run simultaneously." + echo " Default: 1." + echo + #--- + echo " -os|--os [=|space] \"OS string\" (OPTIONAL)." + echo " The name of the Operating system." + echo " Supported OSes: linux macosx." + echo " Default: current OS." + echo + #--- + echo " -plat|--plat [=|space] \"platform\" (OPTIONAL)." + echo " The name of the compute HPC platform to consider." + echo " Selecting a platform, environment modules specific to that platform are loaded" + echo " and corresponding environment variables are set." + echo " Supported platforms: cheyenne gaea hera jet orion stampede wcoss." + echo " Default: none." + echo + #--- + echo " -v|--v|-verbose|--verbose [=|space] \"a,b,v,i,j,m,n\" (any combination, OPTIONAL)." + echo " Enable verbosity in the make files during compilation." + echo " a (all) : all types of debugging output are enabled" + echo " n (none) : disable all debugging currently enabled" + echo " b (basic) : basic debugging and whether the build was successful or not" + echo " v (verbose) : a level above basic" + echo " i (implicit) : prints messages describing the implicit rule searches for each target" + echo " j (jobs) : prints messages giving details on the invocation of specific sub-commands" + echo " m (makefile) : enables messages while rebuilding makefiles" + echo " Default:none." + echo + #--- + + exit 0 +} + +###======================================== +### checkFuncOpt() +### Usage: checkFuncOpt opt_name +### Parameters: +### opt_name: The name of the option to a function +### +### Returns : Exits on error +### +### Exports : __OPTION_LIST +### +### Echoes : NONE +### +### checkFuncOpt: Checks if an option to a function is already supplied. +###======================================== +checkFuncOpt() { + local opt_inp opt_list + + [ $# -eq 0 ] && return -1 + + opt_inp="$( strTrim "${1}" 2 )" + opt_inp="$( echo "${opt_inp}" | sed 's/^[-]*//' )" + + opt_list="$( strTrim "${__OPTION_LIST}" 2 )" + [ -n ${opt_list:+1} ] && \ + opt_list=":$( echo "${opt_list}" | sed 's/ /:/g' ):" + + [ "$( echo "${opt_list}" | egrep -o ":${opt_inp}:" )" ] && return 1 + + __OPTION_LIST="${__OPTION_LIST} ${opt_inp}" + export __OPTION_LIST + + return 0 +} + +###======================================== +### isInteger() +### Usage: isInteger var +### Parameters: var +### Returns: 1 if var is not an integer (0 is an integer as well) +### 0 in any other case +### Echoes: NONE +###======================================== +isInteger() +{ + local -i retval=1 + + [ $# -eq 0 ] && return ${retval} + + if [ "${1:-UNDEF}" -eq "${1}" ] 2>/dev/null + then + retval=0 + fi + + return ${retval} +} + +###======================================== +### getInteger() +### Usage: getInteger int +### Parameters: int (int >=0 or, int < 0) +### Returns: 1 if var is not an integer +### 0 in any other case +### Echoes: int, if it is a valid integer (including 0), +### in any other case echoes an empty string +###======================================== +getInteger() +{ + local -i retval=0 + local echoval= minus= + + # strip spaces, '+' signs and '-' signs + # if the first character of the string is '-', set the minus variable + echoval="$( echo "${1}" | sed 's/[[:space:]+]//g' )" + [ "X$( echo "${echoval:0:1}" )" = "X-" ] && minus="-" + echoval="${minus}$( echo "${echoval}" | sed 's/[[:space:]-]//g' )" + + if isInteger ${echoval}; then + echoval="$(echo "scale=0; ${echoval} + 0" | bc -ql 2>/dev/null)" + retval=$? + echoval="${echoval:-0}" + else + echoval= + retval=1 + fi + + echo -n ${echoval} + + return ${retval} +} + +###======================================== +### getPosInteger() +### Usage: getPosInteger posint +### Parameters: posint (posint >= 0) +### Returns: 1 if var is not a positive integer +### 0 in any other case +### Echoes: posint if it is a valid positive integer +### (including 0), in any other case echoes an +### empty string +###======================================== +getPosInteger() +{ + local -i retval=0 + local echoval= + + echoval=$( getInteger "${1}" ) + retval=$? + + if [ ${retval} -ne 0 ] ; then + echoval= + retval=1 + else + if [ ${echoval} -lt 0 ]; then + echoval= + retval=1 + fi + fi + + echo -n ${echoval} + + return ${retval} +} + +###======================================== +### getYesNo() +### Usage: getYesNo value +### Parameters: +### value : The input value (the value of a parameter) +### The value of a bash parameter that is checked +### against TRUE/FALSE. If the value is one of: +### ">=1|y|yes|yea|yeah|yep" +### then the value of parameter is TRUE (answer = yes). +### If the value is one of: +### "<=0|n|no|not|nop|nope" +### then the value of parameter is FALSE (answer = no). +### If the value is empty then the value of parameter +### is FALSE (answer = no) +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : A "yes" or "no" answer. +### +### getYesNo: Checks if a parameter is assigned a TRUE/FALSE value. +###======================================== +getYesNo() +{ + local param answer + + param="$( echo "${1}" | tr '[:upper:]' '[:lower:]' )" + + if [ "${param}" -eq "${param}" ] 2>/dev/null + then + [ ${param} -le 0 ] && param=0 + [ ${param} -gt 0 ] && param=1 + fi + + case "${param}" in + 1|y|yes|yea|yeah|yep) answer="yes" ;; + 0|n|no|not|nop|nope) answer="no" ;; + *) answer="" ;; # DEFAULT + esac + + echo -n "${answer}" +} + +###======================================== +### toUPPER() +### Usage: toUPPER string +### Parameters: +### string : The string in to convert +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : The input string converted to an all upper case string +### +### toUPPER: Converts a string to an all upper case string +###======================================== +function toUPPER() +{ + echo "${1}" | tr '[:lower:]' '[:upper:]' +} + +###======================================== +### toLOWER() +### Usage: toLOWER string +### Parameters: +### string : The string in to convert +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : The input string converted to an all lower case string +### +### toLOWER: Converts a string to an all lower case string +###======================================== +function toLOWER() +{ + echo "${1}" | tr '[:upper:]' '[:lower:]' +} + +###======================================== +### strESC() +### Usage: strESC string +### Parameters: +### string : The input string +### The input string on which this function is applied +### to escape special characters used in bash/sed ... +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : The modified string with its special characters escaped +### +### strESC: Escapes special characters in a string: "'()/[]*. +###======================================== +strESC() +{ + echo -n "$( echo "${*}" | sed -e "s/[\"\'\(\)\/\*\!]/\\\&/g;s/\[/\\\&/g;s/\]/\\\&/g" )" +} + +strESC1() +{ + echo -n "$( echo "${*}" | sed -e "s/[\&\/\*\!]/\\\&/g;s/\[/\\\&/g;s/\]/\\\&/g" )" +} + +###======================================== +### strTrim() +### Usage: strTrim s1 flag +### Parameters: +### s1 : The input string +### flag : Integer +### A value that controls the action of strTrim. +### If flag is zero or not present, trailing blanks are removed. +### Leading blanks are removed if it is equal to 1. +### Both are removed if it is equal to 2. +### In any other case, trailing blanks are removed. +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : s1 with all leading and/or trailing +### white spaces removed. +### +### strTrim: Removes all leading and/or trailing white spaces +### from the input string +###======================================== +function strTrim () +{ + local trimFLG="${2:-0}" + local out_str= + + case ${trimFLG} in + 0) out_str="$(echo "${1}" | sed 's/[[:space:]]*$//')" ;; + 1) out_str="$(echo "${1}" | sed 's/^[[:space:]]*//')" ;; + 2) out_str="$(echo "${1}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" ;; + *) out_str="$(echo "${1}" | sed 's/[[:space:]]*$//')" ;; + esac + + echo -n ${out_str} +} + +compileNems() { + local cmp_type cmp_make cmp_comp cmp_mjob + local err=0 + + [ $# -eq 0 ] && return ${err} + + cmp_type="$( toLOWER "${1}" )" + cmp_make=GNUmakefile + cmp_comp="${COMPONENT:+COMPONENTS=\"${COMPONENT}\"}" + cmp_mjob="${PARMAKE:+-j ${PARMAKE}}" + cmp_verb="${VERBOSE:+--debug=${VERBOSE}}" + + case "${cmp_type}" in + "clean"|"distclean" ) + if [ -f "${cmp_make}" ]; then + echo + echo "compileNems :: Cleaning: make -f ${cmp_make} ${cmp_type} ${cmp_comp}" + eval "make ${cmp_verb} -f ${cmp_make} ${cmp_type} ${cmp_comp}" + err=$? + + if [ "${cmp_type}" == "distclean" ]; then + rm -f NEMS/exe/NEMS-*.x + fi + else + echo "compileNems :: Cleaning: no makefile found: makefile = ${cmp_make}" + err=1 + fi + ;; + "build"|"compile" ) + if [ -f "${cmp_make}" ]; then + echo + echo "compileNems :: Compiling: make ${cmp_mjob} -f ${cmp_make} ${cmp_type} ${cmp_comp}" + eval "make ${cmp_verb} ${cmp_mjob} -f ${cmp_make} ${cmp_type} ${cmp_comp}" + err=$? + else + echo "compileNems :: Compiling: no makefile found: makefile = ${cmp_make}" + err=1 + fi + ;; + * ) err=0 ;; # Do nothing + esac + + return ${err} +} + +installNems() { + local cmp_comp icmp + local instdir + local CPBIN="/bin/cp -fpv" + local RMBIN="/bin/rm -fv" + + instdir="ALLBIN_INSTALL" + + cmp_comp="${COMPONENT}" + + [ ! -d "${instdir}" ] && mkdir -p ${instdir} + + for icmp in ${cmp_comp} + do + indir="${icmp}_INSTALL" + + if [ -d ${indir} ]; then + echo + echo " --- Installing from: ${indir} to ${instdir} ---" + ${CPBIN} ${indir}/* ${instdir}/ + fi + + ###### Extra ADCIRC files + if [ "${icmp}" == "ADCIRC" ]; then + echo + echo " --- Installing from: ${icmp} to ${instdir} ---" + for iprog in adcprep + do + prog="$( find ${icmp} -type f -name ${iprog} | head -1 )" + if [ -n "${prog:+1}" ]; then + ${CPBIN} ${prog} ${instdir}/ + fi + done + fi + ###### + done + + ###### Install the NEMS/exe/NEMS* files + echo + echo " --- Installing from: NEMS/exe to ${instdir} ---" + for iprog in NEMS/exe/NEMS-*.x + do + if [ -f "${iprog}" ]; then + ${CPBIN} ${iprog} ${instdir}/ + fi + done + + ###### Remove un-needed files from instdir + echo + echo " --- Removing files that are not needed from: ${instdir} ---" + ${RMBIN} ${instdir}/*.mk ${instdir}/*.mod +} diff --git a/functions_build b/scripts/functions_build-v1.0 similarity index 100% rename from functions_build rename to scripts/functions_build-v1.0 diff --git a/scripts/functions_build.del b/scripts/functions_build.del new file mode 100644 index 00000000..ebb69270 --- /dev/null +++ b/scripts/functions_build.del @@ -0,0 +1,617 @@ +#!/bin/bash-*-Shell-script-functions*- + +########################################################################### +### Author: Panagiotis Velissariou +### +### Version - 1.0 Fri Dec 04 2020 +########################################################################### + +set +u + +MY_COMPILING_SYTEMS="gnu, intel, pgi" + +MY_ATM_MODS="ATMESH WRF HWRF PAHM" +MY_OCN_MODS="ADCIRC SCHISM FVCOM ROMS" +MY_HYD_MODS="NWM" +MY_WAV_MODS="WW3DATA WW3" + +MY_COMPONENT_LIST="${MY_ATM_MODS} ${MY_OCN_MODS} ${MY_HYD_MODS} ${MY_WAV_MODS} " + +################################################## +### MODELLING SYSTEM BUILD FUNCTIONS +################################################## + +###======================================== +### ParseArgs() +### Usage: ParseArgs args +### Parameters: args = the script options +### Returns: 0 +### Echoes: NONE +### +### Gets the supplied options to the script. +###======================================== +ParseArgs() +{ + local nm_func=$( basename ${BASH_SOURCE[${#BASH_SOURCE[@]}-1]} ) + + local opt_all opt_opt opt_arg opt_chk + + local t_VAR + local ans0 ans ival intN + local all_evars + + all_evars="MY_CLEAN MY_COMPILER MY_COMPONENT MY_OS MY_PARMAKE MY_PLATFORM MY_VERBOSE" + + for ival in ${all_evars}; do unset __${ival}; done + + + __MY_CLEAN=0 + __MY_COMPILER=intel + __MY_COMPONENT="ADCIRC WW3DATA ATMESH" + __MY_OS= + __MY_PARMAKE=1 + __MY_PLATFORM= + __MY_VERBOSE= + + + # ----- + # Process the function options + opt_all=( c clean compiler component j os plat v verbose h help ) + opt_all=":$( echo "${opt_all[@]/#/-} ${opt_all[@]/#/--}" | sed 's/ /:/g' ):" + + unset __OPTION_LIST + while test $# -gt 0; do + case "${1}" in + -[^-]*=* | --[^-]*=* ) + opt_opt="$( toLOWER "$( echo "${1}" | sed 's/=.*//' )" )" + len=$(( ${#opt_opt} + 1 )) + opt_arg="$( strTrim "$( echo "${1:${len}}" )" 2 )" + [ "$( echo "${opt_all}" | egrep -o ":${opt_arg}:" )" ] && \ + opt_arg= + ;; + -[^-]* | --[^-]* ) + opt_opt="$( toLOWER "${1}" )" + opt_chk="$( toLOWER "$( echo "${2}" | sed 's/=.*//' )" )" + if [ "$( echo "${opt_all}" | egrep -o ":${opt_chk}:" )" ]; then + opt_arg= + else + opt_arg="$( strTrim "$( echo "${2}" )" )" + fi + ;; + *) + opt_opt= + opt_arg= + ;; + esac + + case "${opt_opt}" in + -c | --c | -clean | --clean ) + checkFuncOpt "--clean" + if [ $? -eq 0 ]; then + __MY_CLEAN=1 + if [ "X${opt_arg}" != "X" ]; then + if `isInteger "${opt_arg}"` ; then + __MY_CLEAN=$( echo "${opt_arg}" ) + [ ${opt_arg} -le -3 ] && __MY_CLEAN=-3 + [ ${opt_arg} -ge 2 ] && __MY_CLEAN=2 + else + __MY_CLEAN=0 + [ "$( getYesNo "${opt_arg}" )" = "yes" ] && __MY_CLEAN=1 + fi + fi + fi + ;; + -compiler | --compiler ) + checkFuncOpt "--compiler" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_COMPILER="$( echo "${opt_arg}" | sed 's/[[:space:]]//g' )" + fi + fi + ;; + -component | --component ) + checkFuncOpt "--component" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_COMPONENT="$( strTrim "${opt_arg}" )" + fi + fi + ;; + -j | --j ) + checkFuncOpt "--j" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_PARMAKE=1 + t_VAR="$( getPosInteger "${opt_arg}" )" + [ ! -z "${t_VAR}" ] && __MY_PARMAKE=${t_VAR} + fi + fi + ;; + -os | --os ) + checkFuncOpt "--os" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_OS="$( echo "${opt_arg}" | sed 's/[[:space:]]//g' )" + fi + fi + ;; + -plat | --plat ) + checkFuncOpt "--plat" + if [ $? -eq 0 ]; then + if [ "X${opt_arg}" != "X" ]; then + __MY_PLATFORM="$( echo "${opt_arg}" | sed 's/[[:space:]]//g' )" + fi + fi + ;; + -v | --v | -verbose | --verbose ) + checkFuncOpt "--verbose" + if [ $? -eq 0 ]; then + __MY_VERBOSE=b + if [ "X${opt_arg}" != "X" ]; then + __MY_VERBOSE="$( echo "$( strTrim "${opt_arg}" 2 )" | sed 's/[[:space:]]/,/g' )" + fi + fi + ;; + -h | -help | --h | --help ) + UsageBuild ${nm_func} + ;; + *) ;; # DEFAULT + esac + shift + opt_opt= + opt_arg= + done + unset __OPTION_LIST + # ----- + + if [ -z "${__MY_OS}" ]; then + case "$(uname -s)" in + Darwin ) __MY_OS="macosx" ;; + Linux ) __MY_OS="linux" ;; + *) __MY_OS="UNDEFINED";; # DEFAULT + esac + fi + + # Export the values of all __* variables. + for ival in ${all_evars} + do + ans0="$( eval "echo \${$(echo ${ival}):-}" )" + ans="$( eval "echo \${$(echo __${ival}):-}" )" + ans=${ans:-${ans0:-}} + + eval "${ival}=\${ans}" + export ${ival} + + unset __${ival} + done + + return 0 +} + +UsageBuild() +{ + local nm="$( basename ${0} )" + + echo + echo "Usage: \"${nm}\" [{-|--}option1{=|space}[option_value1]] [{-|--}option2{=|space}[option_value2]] ..." + echo + + echo " -h|-help|--h|--help" + echo " Show this help screen." + echo + #--- + echo " -c|--c|-clean|--clean [=|space] \"0|1|yes|no\" (OPTIONAL)." + echo " Only clean the already compiled CMake build system." + echo " Default: 0|no." + echo + #--- + echo " -compiler|--compiler [=|space] \"compiling_system\" (OPTIONAL)." + echo " The compiling system to use (${MY_COMPILING_SYTEMS})." + echo " Default: intel." + echo + #--- + echo " -component|--component [=|space] \"component_list\" (OPTIONAL)." + echo " The component(s) to use (${MY_COMPONENT_LIST})." + echo " Default: \"ADCIRC WW3DATA ATMESH\"." + echo + #--- + echo " -j|--j [=|space] \"N\" (OPTIONAL)." + echo " Define the number of make jobs to run simultaneously." + echo " Default: 1." + echo + #--- + echo " -os|--os [=|space] \"OS string\" (OPTIONAL)." + echo " The name of the Operating system." + echo " Supported OSes: linux macosx." + echo " Default: current OS." + echo + #--- + echo " -plat|--plat [=|space] \"platform\" (OPTIONAL)." + echo " The name of the compute HPC platform to consider." + echo " Selecting a platform, environment modules specific to that platform are loaded" + echo " and corresponding environment variables are set." + echo " Supported platforms: cheyenne gaea hera jet orion stampede wcoss." + echo " Default: none." + echo + #--- + echo " -v|--v|-verbose|--verbose [=|space] \"a,b,v,i,j,m,n\" (any combination, OPTIONAL)." + echo " Enable verbosity in the make files during compilation." + echo " a (all) : all types of debugging output are enabled" + echo " n (none) : disable all debugging currently enabled" + echo " b (basic) : basic debugging and whether the build was successful or not" + echo " v (verbose) : a level above basic" + echo " i (implicit) : prints messages describing the implicit rule searches for each target" + echo " j (jobs) : prints messages giving details on the invocation of specific sub-commands" + echo " m (makefile) : enables messages while rebuilding makefiles" + echo " Default:none." + echo + #--- + + exit 0 +} + +###======================================== +### checkFuncOpt() +### Usage: checkFuncOpt opt_name +### Parameters: +### opt_name: The name of the option to a function +### +### Returns : Exits on error +### +### Exports : __OPTION_LIST +### +### Echoes : NONE +### +### checkFuncOpt: Checks if an option to a function is already supplied. +###======================================== +checkFuncOpt() { + local opt_inp opt_list + + [ $# -eq 0 ] && return -1 + + opt_inp="$( strTrim "${1}" 2 )" + opt_inp="$( echo "${opt_inp}" | sed 's/^[-]*//' )" + + opt_list="$( strTrim "${__OPTION_LIST}" 2 )" + [ -n ${opt_list:+1} ] && \ + opt_list=":$( echo "${opt_list}" | sed 's/ /:/g' ):" + + [ "$( echo "${opt_list}" | egrep -o ":${opt_inp}:" )" ] && return 1 + + __OPTION_LIST="${__OPTION_LIST} ${opt_inp}" + export __OPTION_LIST + + return 0 +} + +###======================================== +### isInteger() +### Usage: isInteger var +### Parameters: var +### Returns: 1 if var is not an integer (0 is an integer as well) +### 0 in any other case +### Echoes: NONE +###======================================== +isInteger() +{ + local -i retval=1 + + [ $# -eq 0 ] && return ${retval} + + if [ "${1:-UNDEF}" -eq "${1}" ] 2>/dev/null + then + retval=0 + fi + + return ${retval} +} + +###======================================== +### getInteger() +### Usage: getInteger int +### Parameters: int (int >=0 or, int < 0) +### Returns: 1 if var is not an integer +### 0 in any other case +### Echoes: int, if it is a valid integer (including 0), +### in any other case echoes an empty string +###======================================== +getInteger() +{ + local -i retval=0 + local echoval= minus= + + # strip spaces, '+' signs and '-' signs + # if the first character of the string is '-', set the minus variable + echoval="$( echo "${1}" | sed 's/[[:space:]+]//g' )" + [ "X$( echo "${echoval:0:1}" )" = "X-" ] && minus="-" + echoval="${minus}$( echo "${echoval}" | sed 's/[[:space:]-]//g' )" + + if isInteger ${echoval}; then + echoval="$(echo "scale=0; ${echoval} + 0" | bc -ql 2>/dev/null)" + retval=$? + echoval="${echoval:-0}" + else + echoval= + retval=1 + fi + + echo -n ${echoval} + + return ${retval} +} + +###======================================== +### getPosInteger() +### Usage: getPosInteger posint +### Parameters: posint (posint >= 0) +### Returns: 1 if var is not a positive integer +### 0 in any other case +### Echoes: posint if it is a valid positive integer +### (including 0), in any other case echoes an +### empty string +###======================================== +getPosInteger() +{ + local -i retval=0 + local echoval= + + echoval=$( getInteger "${1}" ) + retval=$? + + if [ ${retval} -ne 0 ] ; then + echoval= + retval=1 + else + if [ ${echoval} -lt 0 ]; then + echoval= + retval=1 + fi + fi + + echo -n ${echoval} + + return ${retval} +} + +###======================================== +### getYesNo() +### Usage: getYesNo value +### Parameters: +### value : The input value (the value of a parameter) +### The value of a bash parameter that is checked +### against TRUE/FALSE. If the value is one of: +### ">=1|y|yes|yea|yeah|yep" +### then the value of parameter is TRUE (answer = yes). +### If the value is one of: +### "<=0|n|no|not|nop|nope" +### then the value of parameter is FALSE (answer = no). +### If the value is empty then the value of parameter +### is FALSE (answer = no) +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : A "yes" or "no" answer. +### +### getYesNo: Checks if a parameter is assigned a TRUE/FALSE value. +###======================================== +getYesNo() +{ + local param answer + + param="$( echo "${1}" | tr '[:upper:]' '[:lower:]' )" + + if [ "${param}" -eq "${param}" ] 2>/dev/null + then + [ ${param} -le 0 ] && param=0 + [ ${param} -gt 0 ] && param=1 + fi + + case "${param}" in + 1|y|yes|yea|yeah|yep) answer="yes" ;; + 0|n|no|not|nop|nope) answer="no" ;; + *) answer="" ;; # DEFAULT + esac + + echo -n "${answer}" +} + +###======================================== +### toUPPER() +### Usage: toUPPER string +### Parameters: +### string : The string in to convert +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : The input string converted to an all upper case string +### +### toUPPER: Converts a string to an all upper case string +###======================================== +function toUPPER() +{ + echo "${1}" | tr '[:lower:]' '[:upper:]' +} + +###======================================== +### toLOWER() +### Usage: toLOWER string +### Parameters: +### string : The string in to convert +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : The input string converted to an all lower case string +### +### toLOWER: Converts a string to an all lower case string +###======================================== +function toLOWER() +{ + echo "${1}" | tr '[:upper:]' '[:lower:]' +} + +###======================================== +### strESC() +### Usage: strESC string +### Parameters: +### string : The input string +### The input string on which this function is applied +### to escape special characters used in bash/sed ... +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : The modified string with its special characters escaped +### +### strESC: Escapes special characters in a string: "'()/[]*. +###======================================== +strESC() +{ + echo -n "$( echo "${*}" | sed -e "s/[\"\'\(\)\/\*\!]/\\\&/g;s/\[/\\\&/g;s/\]/\\\&/g" )" +} + +strESC1() +{ + echo -n "$( echo "${*}" | sed -e "s/[\&\/\*\!]/\\\&/g;s/\[/\\\&/g;s/\]/\\\&/g" )" +} + +###======================================== +### strTrim() +### Usage: strTrim s1 flag +### Parameters: +### s1 : The input string +### flag : Integer +### A value that controls the action of strTrim. +### If flag is zero or not present, trailing blanks are removed. +### Leading blanks are removed if it is equal to 1. +### Both are removed if it is equal to 2. +### In any other case, trailing blanks are removed. +### +### Returns : NONE +### +### Exports : NONE +### +### Echoes : s1 with all leading and/or trailing +### white spaces removed. +### +### strTrim: Removes all leading and/or trailing white spaces +### from the input string +###======================================== +function strTrim () +{ + local trimFLG="${2:-0}" + local out_str= + + case ${trimFLG} in + 0) out_str="$(echo "${1}" | sed 's/[[:space:]]*$//')" ;; + 1) out_str="$(echo "${1}" | sed 's/^[[:space:]]*//')" ;; + 2) out_str="$(echo "${1}" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')" ;; + *) out_str="$(echo "${1}" | sed 's/[[:space:]]*$//')" ;; + esac + + echo -n ${out_str} +} + +compileNems() { + local cmp_type cmp_make cmp_comp cmp_mjob + local err=0 + + [ $# -eq 0 ] && return ${err} + + cmp_type="$( toLOWER "${1}" )" + cmp_make=GNUmakefile + cmp_comp="${COMPONENT:+COMPONENTS=\"${COMPONENT}\"}" + cmp_mjob="${PARMAKE:+-j ${PARMAKE}}" + cmp_verb="${VERBOSE:+--debug=${VERBOSE}}" + + case "${cmp_type}" in + "clean"|"distclean" ) + if [ -f "${cmp_make}" ]; then + echo + echo "compileNems :: Cleaning: make -f ${cmp_make} ${cmp_type} ${cmp_comp}" + eval "make ${cmp_verb} -f ${cmp_make} ${cmp_type} ${cmp_comp}" + err=$? + + if [ "${cmp_type}" == "distclean" ]; then + rm -f NEMS/exe/NEMS-*.x + fi + else + echo "compileNems :: Cleaning: no makefile found: makefile = ${cmp_make}" + err=1 + fi + ;; + "build"|"compile" ) + if [ -f "${cmp_make}" ]; then + echo + echo "compileNems :: Compiling: make ${cmp_mjob} -f ${cmp_make} ${cmp_type} ${cmp_comp}" + eval "make ${cmp_verb} ${cmp_mjob} -f ${cmp_make} ${cmp_type} ${cmp_comp}" + err=$? + else + echo "compileNems :: Compiling: no makefile found: makefile = ${cmp_make}" + err=1 + fi + ;; + * ) err=0 ;; # Do nothing + esac + + return ${err} +} + +installNems() { + local cmp_comp icmp + local instdir + local CPBIN="/bin/cp -fpv" + local RMBIN="/bin/rm -fv" + + instdir="ALLBIN_INSTALL" + + cmp_comp="${COMPONENT}" + + [ ! -d "${instdir}" ] && mkdir -p ${instdir} + + for icmp in ${cmp_comp} + do + indir="${icmp}_INSTALL" + + if [ -d ${indir} ]; then + echo + echo " --- Installing from: ${indir} to ${instdir} ---" + ${CPBIN} ${indir}/* ${instdir}/ + fi + + ###### Extra ADCIRC files + if [ "${icmp}" == "ADCIRC" ]; then + echo + echo " --- Installing from: ${icmp} to ${instdir} ---" + for iprog in adcprep + do + prog="$( find ${icmp} -type f -name ${iprog} | head -1 )" + if [ -n "${prog:+1}" ]; then + ${CPBIN} ${prog} ${instdir}/ + fi + done + fi + ###### + done + + ###### Install the NEMS/exe/NEMS* files + echo + echo " --- Installing from: NEMS/exe to ${instdir} ---" + for iprog in NEMS/exe/NEMS-*.x + do + if [ -f "${iprog}" ]; then + ${CPBIN} ${iprog} ${instdir}/ + fi + done + + ###### Remove un-needed files from instdir + echo + echo " --- Removing files that are not needed from: ${instdir} ---" + ${RMBIN} ${instdir}/*.mk ${instdir}/*.mod +}