diff --git a/bin/foamCleanPath b/bin/foamCleanPath index 1fcfcb196d..03d75bad59 100755 --- a/bin/foamCleanPath +++ b/bin/foamCleanPath @@ -7,7 +7,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2017-2020 OpenCFD Ltd. +# Copyright (C) 2017-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -43,22 +43,31 @@ # eval "$(foamCleanPath -sh=PATH "$PATH" dir1:dir2)" # eval "$(foamCleanPath -sh=PATH -env=PATH dir1:dir2)" # eval "$(foamCleanPath -sh-env=PATH dir1:dir2)" +# eval "$(foamCleanPath -sh-path dir1:dir2)" # # - Similarly for c-shell -# eval `foamCleanPath -csh-env=PATH dir1:dir2` +# eval `foamCleanPath -csh-path dir1:dir2` +# +# For library paths, it is suggested to use -sh-lib, or -csh-lib. +# The will use DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH on Darwin. # #------------------------------------------------------------------------------ printHelp() { cat</dev/null)" in + (Darwin) name='DYLD_LIBRARY_PATH';; + (*) name='LD_LIBRARY_PATH';; + esac ;; - esac + esac + optEnvName="$name" # Use for input evaluation + ;; - # Shell-specific output prefix ("setenv ENVNAME xyz" or "ENVNAME=xyz") - case "$1" in - -csh*) - shellOutput="setenv $name " - ;; - *) - shellOutput="$name=" + -csh-path | -sh-path) + shellFlavour="$1" + name='PATH' + optEnvName="$name" # Use for input evaluation + shellOutput="$name" # Use for output + ;; + + -csh-lib | -sh-lib) + shellFlavour="$1" + case "$(uname -s 2>/dev/null)" in + (Darwin) name='DYLD_LIBRARY_PATH';; + (*) name='LD_LIBRARY_PATH';; + esac + optEnvName="$name" # Use for input evaluation + shellOutput="$name" # Use for output + ;; + + -csh=* | -sh=* | -csh-env=* | -sh-env=*) + shellFlavour="$1" + name="${1#*=}" + [ -n "$name" ] || die "Option '$1' missing an ENVNAME" + # Accept aliases + case "$name" in + (-path) name='PATH';; + (-lib) + case "$(uname -s 2>/dev/null)" in + (Darwin) name='DYLD_LIBRARY_PATH';; + (*) name='LD_LIBRARY_PATH';; + esac ;; esac + shellOutput="$name" # Use for output + # Use for input evaluation + case "$1" in (*-env=*) optEnvName="$name";; esac ;; -debug) @@ -149,6 +183,17 @@ do shift done +# Set the output prefix +# c-shell: setenv ENVNAME ... +# POSIX : ENVNAME=... +if [ -n "$shellOutput" ] +then + case "$shellFlavour" in + (-csh*) shellOutput="setenv ${shellOutput} " ;; + (*) shellOutput="${shellOutput}=" ;; + esac +fi + # Basic checks if [ -n "$optEnvName" ] diff --git a/bin/tools/foamCreateModuleInclude b/bin/tools/foamCreateModuleInclude index 73214c253b..610c50130f 100755 --- a/bin/tools/foamCreateModuleInclude +++ b/bin/tools/foamCreateModuleInclude @@ -7,7 +7,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2016-2017 CINECA -# Copyright (C) 2017-2020 OpenCFD Ltd. +# Copyright (C) 2017-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -327,14 +327,14 @@ fi foamClean="$WM_PROJECT_DIR/bin/foamCleanPath" if [ -x "$foamClean" ] then - eval $("$foamClean" -sh-env=PATH "$foamOldDirs") + eval $("$foamClean" -sh-path "$foamOldDirs") + eval $("$foamClean" -sh-lib "$foamOldDirs") eval $("$foamClean" -sh-env=MANPATH "$foamOldDirs") - eval $("$foamClean" -sh-env=LD_LIBRARY_PATH "$foamOldDirs") # May not have/need any third party at all if [ -n "$FOAM_EXT_LIBBIN" ] && [ ! -d "$FOAM_EXT_LIBBIN" ] then - eval $("$foamClean" -sh-env=LD_LIBRARY_PATH "$FOAM_EXT_LIBBIN") + eval $("$foamClean" -sh-lib "$FOAM_EXT_LIBBIN") unset FOAM_EXT_LIBBIN fi fi diff --git a/etc/config.csh/functions b/etc/config.csh/functions index c7cec4f07b..71bc08f76c 100644 --- a/etc/config.csh/functions +++ b/etc/config.csh/functions @@ -19,18 +19,34 @@ # # Some functionality implemented via bin/tools/lib-dir # +# Defined Variables +# foamClean : path to bin/foamCleanPath +# _foam_uname_s : cache value for `uname -s` +# +# Defined Functions (Aliases) +# _foamClean : eval call to foamCleanPath for specific shell +# _foamEcho : silent/non-silent echo +# _foamEtc : resolve etc files (silent or verbose) +# _foamAddPath : prepend to MANPATH +# _foamAddMan : prepend to MANPATH +# _foamAddLib : prepend to [DY]LD_LIBRARY_PATH +# _foamAddLibAuto: call to lib-dir for lib64/lib resolved name +# #------------------------------------------------------------------------------ # Cleaning environment variables alias _foamClean 'eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=\!*`' +# Cache value for `uname -s` +set _foam_uname_s=`uname -s` + # Prepend PATH, MANPATH, LD_LIBRARY_PATH alias _foamAddPath 'setenv PATH \!*\:${PATH}' alias _foamAddMan 'setenv MANPATH \!*\:${MANPATH}' # Special treatment for Darwin # - DYLD_LIBRARY_PATH instead of LD_LIBRARY_PATH -if (`uname -s` == "Darwin") then +if ("${_foam_uname_s}" == "Darwin") then alias _foamAddLib 'setenv DYLD_LIBRARY_PATH \!*\:${DYLD_LIBRARY_PATH}' else alias _foamAddLib 'setenv LD_LIBRARY_PATH \!*\:${LD_LIBRARY_PATH}' diff --git a/etc/config.csh/paraview b/etc/config.csh/paraview index b14625ff1f..861275b176 100644 --- a/etc/config.csh/paraview +++ b/etc/config.csh/paraview @@ -66,8 +66,8 @@ if (! $?WM_COMPILER_LIB_ARCH ) setenv WM_COMPILER_LIB_ARCH set archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER" # Clean path and library path -eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=PATH "$ParaView_DIR $archDir/ParaView- $archDir/qt-"` -eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-env=LD_LIBRARY_PATH "$ParaView_DIR $archDir/ParaView- $archDir/qt-"` +eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-path "$ParaView_DIR $archDir/ParaView- $archDir/qt-"` +eval `$WM_PROJECT_DIR/bin/foamCleanPath -csh-lib "$ParaView_DIR $archDir/ParaView- $archDir/qt-"` # Evaluate command-line parameters for ParaView while ( $#argv > 0 ) @@ -156,6 +156,7 @@ default: if ( -r "$ParaView_DIR" ) then setenv PATH "${ParaView_DIR}/bin:${PATH}" set pvLibDir="unknown" + set pv_libdirs="" # QT libraries as required, and Qt5_DIR for the root directory. # Another possibility: "qtpaths --qt-version" @@ -168,7 +169,7 @@ default: endsw foreach libDir ("lib$WM_COMPILER_LIB_ARCH" "lib") if ( -d "${qtDir}/${libDir}" ) then - setenv LD_LIBRARY_PATH "${qtDir}/${libDir}:${LD_LIBRARY_PATH}" + set pv_libdirs="${qtDir}/${libDir}:${pv_libdirs}" break endif end @@ -186,7 +187,7 @@ default: set libDir="$pvLibDir" # Needs lib/paraview-X.X (not lib) breaksw endsw - setenv LD_LIBRARY_PATH "${ParaView_DIR}/${libDir}:${LD_LIBRARY_PATH}" + set pv_libdirs="${ParaView_DIR}/${libDir}:${pv_libdirs}" break endif set pvLibDir="unknown" @@ -200,6 +201,19 @@ default: set pv_plugin_dir="${pv_plugin_dir} (missing)" # For message endif + + # Any extra library directories + if ( -n "$pv_libdirs" != "" ) then + switch "WM_ARCH" in + case darwin*: + setenv DYLD_LIBRARY_PATH "${pv_libdirs}:$DYLD_LIBRARY_PATH" + breaksw + default: + setenv LD_LIBRARY_PATH "${pv_libdirs}:$LD_LIBRARY_PATH" + breaksw + endsw + endif + if ($?FOAM_VERBOSE && $?prompt) then echo "Using paraview" echo " ParaView_DIR : $ParaView_DIR" @@ -225,6 +239,6 @@ endif unsetenv ParaView_VERSION ParaView_QT unset archDir libDir -unset pv_api pv_plugin_dir pvLibDir pvPython qtDir +unset pv_api pv_plugin_dir pv_libdirs pvLibDir pvPython qtDir #------------------------------------------------------------------------------ diff --git a/etc/config.csh/setup b/etc/config.csh/setup index 52b5476bb6..4b0a9a18ea 100644 --- a/etc/config.csh/setup +++ b/etc/config.csh/setup @@ -145,16 +145,19 @@ if ( $?FOAM_CONFIG_ETC ) then endif -# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH) +# Clean standard environment variables (PATH, MANPATH, [DY]LD_LIBRARY_PATH) # - avoid local variables shadowing setenv variables unset PATH MANPATH LD_LIBRARY_PATH DYLD_LIBRARY_PATH if (! $?MANPATH ) setenv MANPATH if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH +if ("${_foam_uname_s}" == "Darwin" ) then + if (! $?DYLD_LIBRARY_PATH ) setenv DYLD_LIBRARY_PATH +endif _foamClean PATH "$foamOldDirs" _foamClean MANPATH "$foamOldDirs" -_foamClean LD_LIBRARY_PATH "$foamOldDirs" +_foamClean -lib "$foamOldDirs" #------------------------------------------------------------------------------ @@ -207,9 +210,9 @@ endif # Remove duplicates from environment paths -_foamClean PATH -_foamClean MANPATH -_foamClean LD_LIBRARY_PATH +_foamClean PATH "$foamOldDirs" +_foamClean MANPATH "$foamOldDirs" +_foamClean -lib # Add trailing ':' for system manpages if ( $?MANPATH ) then @@ -239,6 +242,6 @@ unalias _foamAddLib unalias _foamAddLibAuto # Variables (done as final statement for a clean exit code) -unset cleaned foamOldDirs _foamFoundDir _foamPrefixDir +unset cleaned foamOldDirs _foam_uname_s _foamFoundDir _foamPrefixDir #------------------------------------------------------------------------------ diff --git a/etc/config.csh/unset b/etc/config.csh/unset index 47f4b496c3..b9a611ddc1 100644 --- a/etc/config.csh/unset +++ b/etc/config.csh/unset @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2016-2020 OpenCFD Ltd. +# Copyright (C) 2016-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -153,19 +153,26 @@ unsetenv SCOTCH_ARCH_PATH # PATH, LD_LIBRARY_PATH, MANPATH if ( $?foamClean ) then - eval `$foamClean -csh-env=PATH "$foamOldDirs"` - - if ($?LD_LIBRARY_PATH) then - eval `$foamClean -csh-env=LD_LIBRARY_PATH "$foamOldDirs"` - if ("${LD_LIBRARY_PATH}" == "") unsetenv LD_LIBRARY_PATH - endif - if ($?MANPATH) then eval `$foamClean -csh-env=MANPATH "$foamOldDirs"` - if ("${MANPATH}" == "") unsetenv MANPATH endif + if ($?LD_LIBRARY_PATH) then + eval `$foamClean -csh-env=LD_LIBRARY_PATH "$foamOldDirs"` + endif + if ($?DYLD_LIBRARY_PATH) then + eval `$foamClean -csh-env=DYLD_LIBRARY_PATH "$foamOldDirs"` + endif +endif +if ($?MANPATH) then + if ("${MANPATH}" == "") unsetenv MANPATH +endif +if ($?LD_LIBRARY_PATH) then + if ("${LD_LIBRARY_PATH}" == "") unsetenv LD_LIBRARY_PATH +endif +if ($?DYLD_LIBRARY_PATH) then + if ("${DYLD_LIBRARY_PATH}" == "") unsetenv DYLD_LIBRARY_PATH endif diff --git a/etc/config.sh/functions b/etc/config.sh/functions index 1c9ee25bff..105ca2d4c5 100644 --- a/etc/config.sh/functions +++ b/etc/config.sh/functions @@ -20,6 +20,20 @@ # # Some functionality mirrored by bin/tools/lib-dir # +# Defined Variables +# WM_SHELL_FUNCTIONS : tracking variable +# foamClean : path to bin/foamCleanPath +# _foam_uname_s : cache value for `uname -s` +# +# Defined Functions +# _foamClean : eval call to foamCleanPath for specific shell +# _foamEcho : silent/non-silent echo +# _foamEtc : resolve etc files (silent or verbose) +# _foamAddPath : prepend to MANPATH +# _foamAddMan : prepend to MANPATH +# _foamAddLib : prepend to [DY]LD_LIBRARY_PATH +# _foamAddLibAuto: prepend to lib64/lib resolved name +# #------------------------------------------------------------------------------ if [ -z "$WM_SHELL_FUNCTIONS" ] @@ -32,6 +46,9 @@ then # Cleaning environment variables foamClean="$WM_PROJECT_DIR/bin/foamCleanPath" + # Cache value for `uname -s` + _foam_uname_s="$(uname -s 2>/dev/null)" + # Cleaning environment variables unset -f _foamClean 2>/dev/null _foamClean() @@ -70,12 +87,25 @@ then case "$1" in (/?*) export MANPATH="$1:$MANPATH" ;; esac } - # Prepend LD_LIBRARY_PATH + # Prepend LD_LIBRARY_PATH (DYLD_LIBRARY_PATH for Darwin) unset -f _foamAddLib 2>/dev/null - _foamAddLib() - { - case "$1" in (/?*) export LD_LIBRARY_PATH="$1:$LD_LIBRARY_PATH" ;; esac - } + if [ "${_foam_uname_s}" = Darwin ] + then + _foamAddLib() + { + case "$1" in (/?*) + export DYLD_LIBRARY_PATH="${1}${DYLD_LIBRARY_PATH:+:}${DYLD_LIBRARY_PATH}" ;; + esac + } + else + _foamAddLib() + { + case "$1" in (/?*) + export LD_LIBRARY_PATH="${1}${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}" ;; + esac + } + fi + # Prepend to LD_LIBRARY_PATH with additional checking # $1 = base directory for 'lib' or 'lib64' @@ -106,7 +136,7 @@ then do if [ -d "$foamVar_prefix/$foamVar_end" ] then - export LD_LIBRARY_PATH="$foamVar_prefix/$foamVar_end:$LD_LIBRARY_PATH" + _foamAddLib "$foamVar_prefix/$foamVar_end" unset foamVar_prefix foamVar_end return 0 fi @@ -119,10 +149,10 @@ then then case "$foamVar_end" in (/*) # Absolute path - export LD_LIBRARY_PATH="$foamVar_end:$LD_LIBRARY_PATH" + _foamAddLib "foamVar_end" ;; (*) # Relative to prefix - export LD_LIBRARY_PATH="$foamVar_prefix/$foamVar_end:$LD_LIBRARY_PATH" + _foamAddLib "$foamVar_prefix/$foamVar_end" ;; esac unset foamVar_prefix foamVar_end @@ -134,27 +164,6 @@ then } - # 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() - { - case "$1" in (/?*) export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH" ;; esac - } - - # 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 - - #-------------------------------------------------------------------------- # Avoid any ThirdParty settings that may have 'leaked' into the environment @@ -180,6 +189,7 @@ else unset -f _foamAddPath _foamAddMan _foamAddLib _foamAddLibAuto 2>/dev/null unset -f _foamClean _foamEcho _foamEtc 2>/dev/null unset foamClean + unset _foam_uname_s unset WM_SHELL_FUNCTIONS fi diff --git a/etc/config.sh/paraview b/etc/config.sh/paraview index ca2e235b78..f7feadb4f9 100644 --- a/etc/config.sh/paraview +++ b/etc/config.sh/paraview @@ -69,11 +69,11 @@ archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER" # Clean path and library path eval \ - "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=PATH \ + "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-path \ $ParaView_DIR $archDir/ParaView- $archDir/qt-)" eval \ - "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=LD_LIBRARY_PATH \ + "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-lib \ $ParaView_DIR $archDir/ParaView- $archDir/qt-)" # Evaluate command-line parameters for ParaView @@ -131,6 +131,7 @@ case "$ParaView_VERSION" in if [ -r "$ParaView_DIR" ] then export PATH="$ParaView_DIR/bin:$PATH" + unset pv_libdirs # QT libraries as required, and Qt5_DIR for the root directory. # Another possibility: "qtpaths --qt-version" @@ -146,7 +147,7 @@ case "$ParaView_VERSION" in do if [ -d "$qtDir/$libDir" ] then - export LD_LIBRARY_PATH="$qtDir/$libDir:$LD_LIBRARY_PATH" + pv_libdirs="$qtDir/$libDir" break fi done @@ -165,7 +166,7 @@ case "$ParaView_VERSION" in libDir="$pvLibDir" # Needs lib/paraview-X.X (not lib) ;; esac - export LD_LIBRARY_PATH="$ParaView_DIR/$libDir:$LD_LIBRARY_PATH" + pv_libdirs="$ParaView_DIR/$libDir:${pv_libdirs}" break fi unset pvLibDir @@ -180,6 +181,16 @@ case "$ParaView_VERSION" in pv_plugin_dir="${pv_plugin_dir} (missing)" # For message fi + # Any extra library directories + if [ -n "$pv_libdirs" ] + then + case "$WM_ARCH" in + (darwin*) + export DYLD_LIBRARY_PATH="${pv_libdirs}:$DYLD_LIBRARY_PATH" ;; + (*) export LD_LIBRARY_PATH="${pv_libdirs}:$LD_LIBRARY_PATH" ;; + esac + fi + if [ -n "$FOAM_VERBOSE" ] && [ -n "$PS1" ] then echo "Using paraview" 1>&2 @@ -208,6 +219,6 @@ then fi unset archDir libDir -unset pv_api pv_plugin_dir pvLibDir pvPython qtDir +unset pv_api pv_plugin_dir pv_libdirs pvLibDir pvPython qtDir #------------------------------------------------------------------------------ diff --git a/etc/config.sh/paraview-system b/etc/config.sh/paraview-system index 3f1b569f0a..56b29377ea 100644 --- a/etc/config.sh/paraview-system +++ b/etc/config.sh/paraview-system @@ -5,7 +5,7 @@ # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------ -# Copyright (C) 2019-2020 OpenCFD Ltd. +# Copyright (C) 2019-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -27,11 +27,11 @@ archDir="$WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER" # Clean path and library path eval \ - "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=PATH \ + "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-path \ $ParaView_DIR $archDir/ParaView-)" eval \ - "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=LD_LIBRARY_PATH \ + "$($WM_PROJECT_DIR/bin/foamCleanPath -sh-lib \ $ParaView_DIR $archDir/ParaView-)" #------------------------------------------------------------------------------ diff --git a/etc/config.sh/setup b/etc/config.sh/setup index fb0a1f5e59..0d912ce6b7 100644 --- a/etc/config.sh/setup +++ b/etc/config.sh/setup @@ -186,7 +186,7 @@ fi export PATH MANPATH LD_LIBRARY_PATH _foamClean PATH "$foamOldDirs" _foamClean MANPATH "$foamOldDirs" -_foamClean LD_LIBRARY_PATH "$foamOldDirs" +_foamClean -lib "$foamOldDirs" #------------------------------------------------------------------------------ # Base setup (OpenFOAM compilation), MPI and third-party packages @@ -244,7 +244,7 @@ export PATH MANPATH LD_LIBRARY_PATH _foamClean PATH _foamClean MANPATH -_foamClean LD_LIBRARY_PATH +_foamClean -lib # Add trailing ':' for system manpages if [ -n "$MANPATH" ] diff --git a/etc/config.sh/unset b/etc/config.sh/unset index 699f705235..ec50b9753a 100644 --- a/etc/config.sh/unset +++ b/etc/config.sh/unset @@ -6,7 +6,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2016-2020 OpenCFD Ltd. +# Copyright (C) 2016-2021 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. @@ -154,12 +154,14 @@ unset SCOTCH_ARCH_PATH if [ -n "$foamClean" ] then eval "$($foamClean -sh-env=PATH $foamOldDirs)" - eval "$($foamClean -sh-env=LD_LIBRARY_PATH $foamOldDirs)" eval "$($foamClean -sh-env=MANPATH $foamOldDirs)" + eval "$($foamClean -sh-env=LD_LIBRARY_PATH $foamOldDirs)" + eval "$($foamClean -sh-env=DYLD_LIBRARY_PATH $foamOldDirs)" fi -[ -n "$LD_LIBRARY_PATH" ] || unset LD_LIBRARY_PATH [ -n "$MANPATH" ] || unset MANPATH +[ -n "$LD_LIBRARY_PATH" ] || unset LD_LIBRARY_PATH +[ -n "$DYLD_LIBRARY_PATH" ] || unset DYLD_LIBRARY_PATH #------------------------------------------------------------------------------ # Cleanup aliases and functions