- Use the OPENFOAM define (eg, 1806, 1812), which normally corresponds to a major release, to define an API level. This remains consistent within a release cycle and means that it is possible to manage several sub-versions and continue to have a consistent lookup. The current API value is updated automatically during the build and cached as meta data for later use, even when the wmake/ directory is missing or OpenFOAM has not yet be initialized. The version information reported on program start or with -help usage adjusted to reflect this. The build tag from git now also carries the date as being more meaningful to trace than a hash value. - Update etc/bashrc and etc/cshrc to obtain the project directory directly instead of via its prefix directory. The value obtained corresponds to an absolute path, from which the prefix directory can be obtained. The combination of these changes removes the reliance on any particular directory naming convention. For example, With an 1812 version (API level): WM_PROJECT_VERSION=myVersion installed as /some/path/somewhere/openfoam-mySandbox This makes the -prefix, -foamInstall, -projectVersion, -version values of foamEtcFiles, and similar entries for foamConfigurePaths superfluous. WM_PROJECT_INST_DIR is no longer required or used ENH: improve handling and discovery of ThirdParty - improve the flexibility and reusability of ThirdParty packs to cover various standard use cases: 1. Unpacking initial release tar files with two parallel directories - OpenFOAM-v1812/ - ThirdParty-v1812/ 2. With an adjusted OpenFOAM directory name, for whatever reason - OpenFOAM-v1812-myCustom/ - openfoam-1812-other-info/ 3. Operating with/without ThirdParty directory To handle these use cases, the following discovery is used. Note PROJECT = the OpenFOAM directory `$WM_PROJECT_DIR` PREFIX = the parent directory VERSION = `$WM_PROJECT_VERSION` API = `$WM_PROJECT_API`, as per `foamEtcFiles -show-api` 0. PROJECT/ThirdParty - for single-directory installations 1. PREFIX/ThirdParty-VERSION - this corresponds to the traditional approach 2. PREFIX/ThirdParty-vAPI - allows for an updated value of VERSION (eg, v1812-myCustom) without requiring a renamed ThirdParty. The API value would still be '1812' and the original ThirdParty-v1812/ would be found. 3. PREFIX/ThirdParty-API - this is the same as the previous example, but using an unadorned API value. This also makes sense if the chosen version name also uses the unadorned API value in its naming (eg, 1812-patch190131, 1812.19W03) 4. PREFIX/ThirdParty-common - permits maximum reuse for various versions, but only for experienced user who are aware of potential version incompatibilities Directory existence is checked as is the presence of an Allwmake file or a platforms/ directory. This reduces the potential of false positive matches and limits the selection to directories that are either with sources (has the Allwmake file), or pre-compiled binaries (has the platforms/ directory). If none of the explored directories are found to be suitable, it reverts to using a PROJECT/ThirdParty dummy location since this is within the project source tree and can be trusted to have no negative side-effects. ENH: add csh support to foamConfigurePaths - this removes the previously experienced inconsistence in config file contents. REMOVED: foamExec - was previously used when switching versions and before the bashrc/cshrc discovery logic was added. It is now obsolete.
235 lines
6.9 KiB
Bash
235 lines
6.9 KiB
Bash
#----------------------------------*-sh-*--------------------------------------
|
|
# ========= |
|
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
# \\ / O peration |
|
|
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
|
# \\/ M anipulation | Copyright (C) 2017-2018 OpenCFD Ltd.
|
|
#------------------------------------------------------------------------------
|
|
# License
|
|
# This file is part of OpenFOAM, licensed under GNU General Public License
|
|
# <http://www.gnu.org/licenses/>.
|
|
#
|
|
# File
|
|
# etc/config.sh/functions
|
|
# - sourced by OpenFOAM-*/etc/bashrc
|
|
#
|
|
# Description
|
|
# Shell functions and variables used when sourcing the OpenFOAM environment
|
|
#
|
|
# Some functionality mirrored by bin/tools/lib-dir
|
|
#
|
|
#------------------------------------------------------------------------------
|
|
|
|
if [ -z "$WM_SHELL_FUNCTIONS" ]
|
|
then
|
|
# Not previously loaded/defined - define now
|
|
|
|
# Temporary environment variable to track loading/unloading of functions
|
|
WM_SHELL_FUNCTIONS=loaded
|
|
|
|
# Cleaning environment variables
|
|
foamClean="$WM_PROJECT_DIR/bin/foamCleanPath"
|
|
|
|
# Cleaning environment variables
|
|
unset -f _foamClean 2>/dev/null
|
|
_foamClean()
|
|
{
|
|
foamVar_name="$1"
|
|
shift
|
|
eval "$($foamClean -sh-env=$foamVar_name $@)"
|
|
unset "foamVar_name"
|
|
}
|
|
|
|
# Echo values to stderr when FOAM_VERBOSE is on, no-op otherwise
|
|
unset -f _foamEcho 2>/dev/null
|
|
if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ]
|
|
then
|
|
_foamEcho() { echo "$@" 1>&2; }
|
|
else
|
|
_foamEcho() { true; }
|
|
fi
|
|
|
|
# Source an etc file, possibly with some verbosity
|
|
# - use eval to avoid intermediate variables (ksh doesn't have 'local')
|
|
unset -f _foamEtc 2>/dev/null
|
|
if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ]
|
|
then
|
|
_foamEtc()
|
|
{
|
|
eval "$($WM_PROJECT_DIR/bin/foamEtcFile -sh-verbose ${FOAM_CONFIG_NOUSER:+-mode=o} $@)";
|
|
}
|
|
else
|
|
_foamEtc()
|
|
{
|
|
eval "$($WM_PROJECT_DIR/bin/foamEtcFile -sh ${FOAM_CONFIG_NOUSER:+-mode=o} $@)";
|
|
}
|
|
fi
|
|
|
|
# Prepend PATH
|
|
unset -f _foamAddPath 2>/dev/null
|
|
_foamAddPath()
|
|
{
|
|
[ -n "$1" ] && export PATH="$1:$PATH"
|
|
}
|
|
|
|
# Prepend MANPATH
|
|
unset -f _foamAddMan 2>/dev/null
|
|
_foamAddMan()
|
|
{
|
|
[ -n "$1" ] && export MANPATH="$1:$MANPATH"
|
|
}
|
|
|
|
# Prepend LD_LIBRARY_PATH
|
|
unset -f _foamAddLib 2>/dev/null
|
|
_foamAddLib()
|
|
{
|
|
[ -n "$1" ] && export LD_LIBRARY_PATH="$1:$LD_LIBRARY_PATH"
|
|
}
|
|
|
|
# Prepend to LD_LIBRARY_PATH with additional checking
|
|
# $1 = base directory for 'lib' or 'lib64'
|
|
# $2 = fallback libname ('lib' or 'lib64')
|
|
#
|
|
# 0) Skip entirely if directory ends in "-none" or "-system".
|
|
# These special cases (disabled, system directories) should not require
|
|
# adjustment of LD_LIBRARY_PATH
|
|
# 1) Check for dir/lib64 and dir/lib
|
|
# 2) Use fallback if the previous failed
|
|
#
|
|
# Return 0 on success
|
|
unset -f _foamAddLibAuto 2>/dev/null
|
|
_foamAddLibAuto()
|
|
{
|
|
# Note ksh does not have 'local' thus these ugly variable names
|
|
foamVar_prefix="$1"
|
|
foamVar_end="${1##*-}"
|
|
|
|
# Do not add (none) or a system directory
|
|
if [ -z "$foamVar_prefix" -o "$foamVar_end" = none -o "$foamVar_end" = system ]
|
|
then
|
|
unset foamVar_prefix foamVar_end
|
|
return 1
|
|
elif [ -d "$foamVar_prefix" ]
|
|
then
|
|
for foamVar_end in lib$WM_COMPILER_LIB_ARCH lib
|
|
do
|
|
if [ -d "$foamVar_prefix/$foamVar_end" ]
|
|
then
|
|
export LD_LIBRARY_PATH="$foamVar_prefix/$foamVar_end:$LD_LIBRARY_PATH"
|
|
unset foamVar_prefix foamVar_end
|
|
return 0
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Use fallback. Add without checking existence of the directory
|
|
foamVar_end=$2
|
|
if [ -n "$foamVar_end" ]
|
|
then
|
|
case "$foamVar_end" in
|
|
/*) # An absolute path
|
|
export LD_LIBRARY_PATH="$foamVar_end:$LD_LIBRARY_PATH"
|
|
;;
|
|
(*) # Relative to prefix
|
|
export LD_LIBRARY_PATH="$foamVar_prefix/$foamVar_end:$LD_LIBRARY_PATH"
|
|
;;
|
|
esac
|
|
unset foamVar_prefix foamVar_end
|
|
return 0
|
|
fi
|
|
|
|
unset foamVar_prefix foamVar_end
|
|
return 1 # Nothing set
|
|
}
|
|
|
|
|
|
# Special treatment for Darwin
|
|
# - DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH
|
|
if [ "$(uname -s 2>/dev/null)" = Darwin ]
|
|
then
|
|
unset -f _foamAddLib _foamAddLibAuto 2>/dev/null
|
|
|
|
# Prepend DYLD_LIBRARY_PATH
|
|
_foamAddLib()
|
|
{
|
|
[ -n "$1" ] && export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
|
|
}
|
|
|
|
# Prepend to DYLD_LIBRARY_PATH with additional checking
|
|
# - use lib-dir script instead of rewriting
|
|
_foamAddLibAuto()
|
|
{
|
|
eval "$($WM_PROJECT_DIR/bin/tools/lib-dir -sh $@)";
|
|
}
|
|
fi
|
|
|
|
|
|
# Evaluate command-line parameters
|
|
unset -f _foamEval 2>/dev/null
|
|
_foamEval()
|
|
{
|
|
for i
|
|
do
|
|
case "$i" in
|
|
-*)
|
|
# Stray option (not meant for us here) -> get out
|
|
break
|
|
;;
|
|
*=)
|
|
# name= -> unset name
|
|
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
|
|
&& echo "unset ${1%=}" 1>&2
|
|
eval "unset ${1%=}"
|
|
;;
|
|
*=*)
|
|
# name=value -> export name=value
|
|
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
|
|
&& echo "export $i" 1>&2
|
|
eval "export $i"
|
|
;;
|
|
*)
|
|
# Filename: source it
|
|
if [ -f "$i" ]
|
|
then
|
|
[ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] \
|
|
&& echo "Using: $i" 1>&2
|
|
. "$i"
|
|
else
|
|
_foamEtc -silent "$i"
|
|
fi
|
|
;;
|
|
esac
|
|
done
|
|
}
|
|
|
|
|
|
#--------------------------------------------------------------------------
|
|
# Avoid any ThirdParty settings that may have 'leaked' into the environment
|
|
|
|
unset MPI_ARCH_PATH
|
|
unset ADIOS_ARCH_PATH
|
|
unset ADIOS1_ARCH_PATH
|
|
unset ADIOS2_ARCH_PATH
|
|
unset BOOST_ARCH_PATH
|
|
unset CCMIO_ARCH_PATH
|
|
unset CGAL_ARCH_PATH
|
|
unset FFTW_ARCH_PATH
|
|
unset GPERFTOOLS_ARCH_PATH
|
|
unset GMP_ARCH_PATH
|
|
unset MPFR_ARCH_PATH
|
|
unset MESA_ARCH_PATH
|
|
unset METIS_ARCH_PATH
|
|
unset SCOTCH_ARCH_PATH
|
|
|
|
else
|
|
# Was previously loaded/defined - now unset
|
|
|
|
unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null
|
|
unset -f _foamClean _foamEcho _foamEtc _foamEval 2>/dev/null
|
|
unset foamClean
|
|
unset WM_SHELL_FUNCTIONS
|
|
|
|
fi
|
|
|
|
#------------------------------------------------------------------------------
|