openfoam/etc/config.csh/setup
Mark Olesen 6c68c34e1a ENH: update handling of versioning and make control (issue #1010)
- 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.
2018-12-02 18:25:57 +01:00

188 lines
5.2 KiB
Bash

#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
# \\/ M anipulation |
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# File
# etc/config.csh/setup
# - sourced by OpenFOAM-*/etc/cshrc
#
# Description
# Finalize setup of OpenFOAM environment for C-shell (csh, tcsh)
#
# Environment
# FOAM_VERBOSE (set/unset)
# - add extra verbosity when sourcing files
# FOAM_CONFIG_NOUSER (set/unset)
# - suppress use of user/group configuration files
#
#------------------------------------------------------------------------------
# [WM_PROJECT_API] - The API level for the project
setenv WM_PROJECT_API `$WM_PROJECT_DIR/bin/foamEtcFile -show-api`
# The installation parent directory
set prefixDir="${WM_PROJECT_DIR:h}"
# Load shell "functions" (actually aliases)
source "$WM_PROJECT_DIR/etc/config.csh/functions"
# [WM_THIRD_PARTY_DIR] - Location of third-party software components
# \- This may be installed in a directory parallel to the OpenFOAM project
# directory, with the same version name or using the API value.
# It may also not be required at all, in which case a dummy "ThirdParty"
# directory inside of the OpenFOAM project directory.
#
# Note: only accept if the directory exists and contains a "Allwmake" file
setenv WM_THIRD_PARTY_DIR
set foundDir=''
_foamEcho "Locating ThirdParty directory"
foreach WM_THIRD_PARTY_DIR (\
"$WM_PROJECT_DIR/ThirdParty" \
"$prefixDir/ThirdParty-$WM_PROJECT_VERSION" \
"$prefixDir/ThirdParty-v$WM_PROJECT_API" \
"$prefixDir/ThirdParty-$WM_PROJECT_API" \
"$prefixDir/ThirdParty-common" \
)
_foamEcho "... $WM_THIRD_PARTY_DIR"
if ( -d "$WM_THIRD_PARTY_DIR" ) then
if ( -f "$WM_THIRD_PARTY_DIR/Allwmake" || -d "$WM_THIRD_PARTY_DIR/platforms" ) then
set foundDir=true
break
endif
endif
end
if ( "${%foundDir}" ) then
_foamEcho "Using $WM_THIRD_PARTY_DIR"
else
# Dummy fallback value
setenv WM_THIRD_PARTY_DIR "$WM_PROJECT_DIR/ThirdParty"
_foamEcho "Dummy $WM_THIRD_PARTY_DIR"
endif
# Done with ThirdParty discovery
# Overrides via <prefs.csh>
# 1. other (system) values
_foamEtc -mode=o prefs.csh
# 2. user or group values (unless disabled)
if (! $?FOAM_CONFIG_NOUSER ) then
_foamEtc -mode=ug prefs.csh
endif
# Capture and evaluate any command-line parameters
# These can be used to set/unset values, specify additional files etc.
setenv FOAM_SETTINGS "${*}"
while ( $#argv > 0 )
switch ($argv[1])
case -*:
# Stray option (not meant for us here) -> get out
break
breaksw
case *=:
# name= -> unsetenv name
_foamEcho "unsetenv $argv[1]:s/=//"
eval "unsetenv $argv[1]:s/=//"
breaksw
case *=*:
# name=value -> setenv name value
_foamEcho "setenv $argv[1]:s/=/ /"
eval "setenv $argv[1]:s/=/ /"
breaksw
default:
# Filename: source it
if ( -f "$argv[1]" ) then
_foamEcho "Using: $argv[1]"
source "$argv[1]"
else
_foamEtc -silent "$argv[1]"
endif
breaksw
endsw
shift
end
# Clean standard environment variables (PATH, MANPATH, LD_LIBRARY_PATH)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Prevent local variables from shadowing setenv variables
unset PATH MANPATH LD_LIBRARY_PATH LD_PRELOAD
if (! $?LD_LIBRARY_PATH ) setenv LD_LIBRARY_PATH
if (! $?MANPATH ) setenv MANPATH
_foamClean PATH "$foamOldDirs"
_foamClean MANPATH "$foamOldDirs"
_foamClean LD_LIBRARY_PATH "$foamOldDirs"
# Setup for OpenFOAM compilation etc
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config settings
# Setup for third-party packages
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamEtc -config mpi
_foamEtc -config paraview -- "$FOAM_SETTINGS" # Pass through for evaluation
_foamEtc -config vtk
_foamEtc -config ensight
## _foamEtc -config ADIOS
## _foamEtc -config ADIOS2
_foamEtc -config CGAL
_foamEtc -config FFTW
if ( -d "$WM_PROJECT_DIR/doc/man1" ) then
_foamAddMan "$WM_PROJECT_DIR/doc"
endif
# Interactive shell
if ($?prompt) then
_foamEtc -config aliases
_foamEtc -config tcsh_completion
endif
# Clean environment paths again. Only remove duplicates
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_foamClean PATH
_foamClean MANPATH
_foamClean LD_LIBRARY_PATH
# Add trailing ':' for system manpages
if ( $?MANPATH ) then
setenv MANPATH "${MANPATH}:"
endif
if ( $?LD_PRELOAD ) then
_foamClean LD_PRELOAD
endif
# Cleanup temporary information
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Unload shell "functions"
unalias _foamClean
unalias _foamEcho
unalias _foamEtc
unalias _foamAddPath
unalias _foamAddMan
unalias _foamAddLib
unalias _foamAddLibAuto
# Variables (done as final statement for a clean exit code)
unset cleaned foamOldDirs foundDir prefixDir
#------------------------------------------------------------------------------