openfoam/etc/config.sh/functions
Mark Olesen b4d38ab468 ENH: improve handling of ThirdParty packages
- generalize some of the library extensions (.so vs .dylib).
  Provide as wmake 'sysFunctions'

- added note about unsupported/incomplete system support

- centralize detection of ThirdParty packages into wmake/ subdirectory
  by providing a series of scripts in the spirit of GNU autoconfig.
  For example,

      have_boost, have_readline, have_scotch, ...

  Each of the `have_<package>` scripts will generally provide the
  following type of functions:

      have_<package>          # detection
      no_<package>            # reset
      echo_<package>          # echoing

  and the following type of variables:

      HAVE_<package>          # unset or 'true'
      <package>_ARCH_PATH     # root for <package>
      <package>_INC_DIR       # include directory for <package>
      <package>_LIB_DIR       # library directory for <package>

  This simplifies the calling scripts:

      if have_metis
      then
          wmake metisDecomp
      fi

  As well as reducing clutter in the corresponding Make/options:

      EXE_INC = \
          -I$(METIS_INC_DIR) \
          -I../decompositionMethods/lnInclude

      LIB_LIBS = \
          -L$(METIS_LIB_DIR) -lmetis

  Any additional modifications (platform-specific or for an external build
  system) can now be made centrally.
2018-04-24 14:51:19 +02:00

210 lines
6.2 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 is shadowed in 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
_foamClean()
{
local var=$1
shift
eval $($WM_PROJECT_DIR/bin/foamCleanPath -sh-env=$var "$@")
}
# Prepend PATH
_foamAddPath()
{
[ -n "$1" ] && export PATH=$1:$PATH
}
# Prepend MANPATH
_foamAddMan()
{
[ -n "$1" ] && export MANPATH=$1:$MANPATH
}
# Prepend LD_LIBRARY_PATH
_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
_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
# Source an etc file, possibly with some verbosity
# - use eval to avoid intermediate variables (ksh doesn't have 'local')
if [ "$FOAM_VERBOSE" -a "$PS1" ]
then
_foamEtc(){ eval "$($WM_PROJECT_DIR/bin/foamEtcFile -sh-verbose $@)"; }
else
_foamEtc(){ eval "$($WM_PROJECT_DIR/bin/foamEtcFile -sh $@)"; }
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
}
#--------------------------------------------------------------------------
# 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 _foamEtc _foamEval 2>/dev/null
unset foamClean
unset WM_SHELL_FUNCTIONS
fi
#------------------------------------------------------------------------------