openfoam/etc/config.sh/functions
Mark Olesen b970ba0901 ENH: minor improvements to environment
- handle sourcing bashrc with a relative path (issue #383)
- handle sourcing from bash and zsh.
  Still need manual intervention when sourcing dash, sh, or ksh.
- replace grep in etc/cshrc with sed only
- logical instead of physical path for WM_PROJECT_DIR (issue #431).
  Doesn't seem to be possible for csh/tcsh.

  * Continue using physical locations when comparing directories,
    but not for the top-level FOAM_INST_DIR, WM_PROJECT_DIR.

- relocate WM_CC, WM_CXX overrides from etc/config.*/compiler
  to etc/config.*/settings to ensure that they are left untouched
  when etc/config.sh/compiler is sourced while making third-party
  packages (eg, gcc, llvm, CGAL).

- provide fallback FOAM_TUTORIALS setting in RunFunctions

STYLE: remove "~OpenFOAM" fallback as being too rare, non-obvious
2017-03-20 08:57:12 +01:00

114 lines
3.4 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 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM.
#
# OpenFOAM is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
#
# File
# etc/config.sh/functions
#
# Description
# Initialization script functions for the bashrc environment
# Sourced from OpenFOAM-<VERSION>/etc/config.sh/bashrc
#
#------------------------------------------------------------------------------
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
# Prefix to PATH
_foamAddPath()
{
[ $# -gt 0 ] && export PATH=$1:$PATH
}
# Prefix to LD_LIBRARY_PATH
_foamAddLib()
{
[ $# -gt 0 ] && export LD_LIBRARY_PATH=$1:$LD_LIBRARY_PATH
}
# Prefix to MANPATH
_foamAddMan()
{
[ $# -gt 0 ] && export MANPATH=$1:$MANPATH
}
# Source an etc file, possibly with some verbosity
_foamEtc()
{
local file
if [ $# -gt 0 ] && file=$($WM_PROJECT_DIR/bin/foamEtcFile "$@")
then
[ "$FOAM_VERBOSE" -a "$PS1" ] && echo "Using: $file" 1>&2
. $file
fi
}
# Evaluate command-line parameters
_foamEval()
{
while [ $# -gt 0 ]
do
case "$1" in
-*)
# Stray option (not meant for us here) -> get out
break
;;
*=)
# name= -> unset name
[ "$FOAM_VERBOSE" -a "$PS1" ] && echo "unset ${1%=}" 1>&2
eval "unset ${1%=}"
;;
*=*)
# name=value -> export name=value
[ "$FOAM_VERBOSE" -a "$PS1" ] && echo "export $1" 1>&2
eval "export $1"
;;
*)
# Filename: source it
if [ -f "$1" ]
then
[ "$FOAM_VERBOSE" -a "$PS1" ] && echo "Using: $1" 1>&2
. "$1"
else
_foamEtc -silent "$1"
fi
;;
esac
shift
done
}
else
# Was previously loaded/defined - now unset
unset WM_SHELL_FUNCTIONS
unset -f _foamAddPath _foamAddLib _foamAddMan
unset -f _foamEtc _foamEval
fi
#------------------------------------------------------------------------------