Skip to content
Snippets Groups Projects
foamConfigurePaths 18 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/sh
    
    #------------------------------------------------------------------------------
    
    # =========                 |
    # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    #  \\    /   O peration     |
    
    #   \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
    
    #    \\/     M anipulation  |
    #------------------------------------------------------------------------------
    #                           | Copyright (C) 2011-2016 OpenFOAM Foundation
    
    #------------------------------------------------------------------------------
    # License
    
    #     This file is part of OpenFOAM, licensed under GNU General Public License
    #     <http://www.gnu.org/licenses/>.
    
    #
    # Script
    #     foamConfigurePaths
    #
    # Description
    
    #     Adjust hardcoded installation versions and paths
    #     in etc/{bashrc,cshrc} and etc/config.{sh,csh}/
    
    #
    #------------------------------------------------------------------------------
    usage() {
    
        while [ "$#" -ge 1 ]; do echo "$1"; shift; done
        cat<<USAGE
    
    
    usage: ${0##*/} options
    
    Basic
    
      -project-path DIR   specify 'WM_PROJECT_DIR' (eg, /opt/openfoam1806-patch1)
      -version VER        specify project version (eg, v1806)
    
      -SP | -float32      single precision (WM_PRECISION_OPTION)
      -DP | -float64      double precision (WM_PRECISION_OPTION)
      -SPDP               mixed single/double precision
      -int32 | -int64     the 'WM_LABEL_SIZE'
    
      -system NAME        specify 'system' compiler to use (eg, Gcc, Icc,...)
      -third  NAME        specify 'ThirdParty' compiler to use (eg, Clang40,...)
      -gcc VER            specify 'gcc_version' for ThirdParty Gcc
      -clang VER          specify 'clang_version' for ThirdParty Clang
      gmp-VERSION         for ThirdParty gcc (gmp-system for system library)
      mpfr-VERSION        for ThirdParty gcc (mpfr-system for system library)
      mpc-VERSION         for ThirdParty gcc (mpc-system for system library)
    
      -mpi NAME           specify 'WM_MPLIB' type (eg, INTELMPI, etc)
      -openmpi VER        use ThirdParty openmpi, with version for 'FOAM_MPI'
      -openmpi-system     use system openmpi
      -openmpi-third      use ThirdParty openmpi (using default version)
    
      -boost VER          specify 'boost_version'
      -boost-path DIR     specify 'BOOST_ARCH_PATH'
      -cgal ver           specify 'cgal_version'
      -cgal-path DIR      specify 'CGAL_ARCH_PATH'
      -cmake VER          specify 'cmake_version'
      -fftw VER           specify 'fffw_version'
      -fftw-path DIR      specify 'FFTW_ARCH_PATH'
      -kahip VER          specify 'KAHIP_VERSION'
      -kahip-path DIR     specify 'KAHIP_ARCH_PATH'
      -metis ver          specify 'METIS_VERSION'
      -metis-path DIR     specify 'METIS_ARCH_PATH'
      -scotch VER         specify 'SCOTCH_VERSION' (eg, scotch_6.0.4)
    
      -scotch-path DIR    specify 'SCOTCH_ARCH_PATH' (eg, /opt/scotch_6.0.4)
    
      -paraview VER       specify 'ParaView_VERSION' (eg, 5.4.1)
    
      -paraview-qt VER    specify 'ParaView_QT' (eg, qt-system)
    
      -paraview-path DIR  specify 'ParaView_DIR' (eg, /opt/ParaView-5.4.1)
      -vtk  VER           specify 'vtk_version' (eg, VTK-7.1.0)
      -mesa VER           specify 'mesa_version' (eg, mesa-13.0.1)
    
      -foamInstall DIR    [obsolete]
      -projectName NAME   [obsolete]
      -sigfpe|-no-sigfpe  [obsolete - now under etc/controlDict]
    
      -archOption 32|64   [obsolete setting of 'WM_ARCH_OPTION' - edit manually]
    
    Adjusts hardcoded versions and installation paths (POSIX and C-shell).
    
      -version -foamVersion --projectVersion
    
      -archOption           --archOption
      -third                -ThirdParty
      -paraview             --paraviewVersion | -paraviewVersion
      -paraview-path        --paraviewInstall | -paraviewInstall
      -scotch               --scotchVersion | -scotchVersion
      -scotch-path          --scotchArchPath | -scotchArchPath
    
    # Report error and exit
    die()
    {
        exec 1>&2
        echo
    
        echo "Error encountered:"
    
        while [ "$#" -ge 1 ]; do echo "    $1"; shift; done
        echo
    
        echo "See '${0##*/} -help' for usage"
        echo
    
    # -----------------------------------------------------------------------------
    
    # Check that it appears to be an OpenFOAM installation
    [ -f etc/bashrc -a -d etc/config.sh ] || \
        usage "Please run from top-level directory of installation"
    
    
    # Check if argument matches the expected input. Respects case.
    # Uses sed for consistency with the replacement routines.
    #
    # _matches <arg> <matcher> [... <matcherN>]
    #
    _matches()
    {
        local input="$1"
        shift
        local result
        for regexp
        do
    
            result=$(echo "$input" | sed -ne "/^$regexp"'$/p')
    
            test -n "$result" && return 0  # successful match
        done
        return 1
    }
    
    
    
    andy's avatar
    andy committed
    # Function to do replacement on file. Checks if any replacement has been done.
    # _inlineSed <file> <regexp> <replacement> <msg>
    
        local file="$1"
        local regexp="$2"
        local replacement="$3"
        local msg="$4"
        local cmd='/^[^#]/s@'"$regexp"'@'"$replacement"'@'
    
    andy's avatar
    andy committed
    
        [ -f "$file" ] || {
            echo "Missing file: $file"
    
        grep -q "$regexp" "$file" && sed -i -e "$cmd" "$file" || { \
    
            echo "Failed: ${msg:-replacement} in $file"
    
        [ -n "$msg" ] && echo "    $msg  ($file)"
    
    
    # Standard <key> <val> type of replacements.
    # replace <file> <key1> <val1> .. <keyN> <valN>
    # looks for KEYWORD=.*
    replace()
    {
        local file="$1"
        shift
    
                "Replaced $key setting by '$val'"
    
    # Standard <key> <val> type of replacements.
    # replace <file> <key1> <val1> .. <keyN> <valN>
    # looks for "setenv KEYWORD value"
    # but avoids "setenv KEYWORD" without a value
    replaceCsh()
    {
        local file="$1"
        shift
    
        local key val
    
        while [ "$#" -ge 2 ]
        do
            key=$1
            val=$2
            shift 2
    
            _inlineSed \
                "$file"  \
                "setenv  *$key [^ #]*" \
                "setenv $key $val" \
                "Replaced $key setenv by '$val'"
        done
    }
    
    
    # Get the option's value (argument), or die on missing or empty argument
    
    # $1 option
    # $2 value
    getOptionValue()
    {
       [ -n "$2" ] || die "'$1' option requires an argument"
       echo "$2"
    }
    
    
    
    # Remove BASH_SOURCE and projectDir=... magic that looks like this:
    
    #     projectDir=$BASH_SOURCE
    #     [ -n "$projectDir" ] && projectDir= ...
    #     projectDir=...
    
    {
        local file="$1"
    
        [ -f "$file" ] || {
            echo "Missing file: $file"
            exit 2 # Fatal
        }
    
    
        echo "    Remove automatic projectDir setting ($file)"
    
            -e '/^ *#/!{/\(BASH_SOURCE\|projectDir=\)/s/^/##IGNORE## /}' \
            "$file"
    }
    
    
    # Remove set projectName=, set projectDir= magic that looks like this:
    # ----
    # set projectName="$WM_PROJECT"
    # set projectDir=`lsof +p $$ |& \
    
    #     sed -ne 'something /etc/cshrc something'`
    
    # ----
    removeCshMagic()
    {
        local file="$1"
    
        [ -f "$file" ] || {
            echo "Missing file: $file"
            exit 2 # Fatal
        }
    
        echo "    Remove automatic projectDir setting ($file)"
    
        sed -i \
            -e '/^ *#/!{\@\(projectName=\|projectDir=\|/etc/cshrc\)@s/^/##IGNORE## /}' \
    
    #------------------------------------------------------------------------------
    
    unset adjusted optMpi
    
    while [ "$#" -gt 0 ]
    do
        case "$1" in
    
        -h | -help* | --help*)
    
        '')
            # Discard empty arguments
            ;;
    
       -project-path)
            # Replace WM_PROJECT_DIR=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/bashrc  WM_PROJECT_DIR "\"$optionValue\""
            replaceCsh etc/cshrc   WM_PROJECT_DIR "\"$optionValue\""
    
            removeBashMagic etc/bashrc
            removeCshMagic  etc/cshrc
    
       -version | -foamVersion | --projectVersion)
    
            # Replace WM_PROJECT_VERSION=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/bashrc  WM_PROJECT_VERSION "$optionValue"
            replaceCsh etc/cshrc   WM_PROJECT_VERSION "$optionValue"
    
        -archOption | --archOption)
    
            optionValue=$(getOptionValue "$@")
    
            echo "Ignoring $1 option: no longer supported" 1>&2
    
        -SP | -float32)
            # Replace WM_PRECISION_OPTION=...
    
            replace    etc/bashrc  WM_PRECISION_OPTION "SP"
            replaceCsh etc/cshrc   WM_PRECISION_OPTION "SP"
    
            # Replace WM_PRECISION_OPTION=...
    
            replace    etc/bashrc  WM_PRECISION_OPTION "DP"
            replaceCsh etc/cshrc   WM_PRECISION_OPTION "DP"
    
        -SPDP)
            # Replace WM_PRECISION_OPTION=...
            replace    etc/bashrc  WM_PRECISION_OPTION "SPDP"
            replaceCsh etc/cshrc   WM_PRECISION_OPTION "SPDP"
            adjusted=true
            ;;
    
    
        -int32 | -int64)
            # Replace WM_LABEL_SIZE=...
            optionValue="${1#-int}"
    
            replace    etc/bashrc  WM_LABEL_SIZE "$optionValue"
            replaceCsh etc/cshrc   WM_LABEL_SIZE "$optionValue"
    
        -clang)
            # Replace clang_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/compiler   clang_version "$optionValue"
            replace etc/config.csh/compiler  clang_version "$optionValue"
    
        -gcc)
            # Replace gcc_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/compiler   gcc_version "$optionValue"
            replace etc/config.csh/compiler  gcc_version "$optionValue"
    
        -system)
            # Replace WM_COMPILER_TYPE=... and WM_COMPILER=...
    
            optionValue=$(getOptionValue "$@")
            replace etc/bashrc  \
                WM_COMPILER_TYPE system \
                WM_COMPILER "$optionValue"
    
            replaceCsh etc/cshrc \
                WM_COMPILER_TYPE system \
                WM_COMPILER "$optionValue"
    
        -third | -ThirdParty)
            # Replace WM_COMPILER_TYPE=... and WM_COMPILER=...
    
            optionValue=$(getOptionValue "$@")
            replace etc/bashrc  \
                WM_COMPILER_TYPE ThirdParty \
                WM_COMPILER "$optionValue"
    
            replaceCsh etc/cshrc  \
                WM_COMPILER_TYPE ThirdParty \
                WM_COMPILER "$optionValue"
    
        gmp-[4-9]* | gmp-system)
            # gcc-related package
    
            replace etc/config.sh/compiler   gmp_version "$1"
            replace etc/config.csh/compiler  gmp_version "$1"
    
        mpfr-[2-9]* | mpfr-system)
            # gcc-related package
    
            replace etc/config.sh/compiler   mpfr_version "$1"
            replace etc/config.csh/compiler  mpfr_version "$1"
    
        mpc-[0-9]* | mpc-system)
            # gcc-related package
    
            replace etc/config.sh/compiler   mpc_version "$1"
            replace etc/config.csh/compiler  mpc_version "$1"
    
        -mpi)
            # Explicitly set WM_MPLIB=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/bashrc  WM_MPLIB "$optionValue"
            replaceCsh etc/bashrc  WM_MPLIB "$optionValue"
    
            optMpi=system
            adjusted=true
            shift
            ;;
    
    
        -openmpi)
            # Replace FOAM_MPI=openmpi-<digits>.. and set to use third-party
            #  The edit is slightly fragile, but works
            expected="openmpi-[1-9][.0-9]*"
    
            optMpi=$(getOptionValue "$@")
    
            _matches "$optMpi" "$expected" || \
                die "'$1' has bad value: '$optMpi'"
    
    
            _inlineSed etc/config.sh/mpi \
                "FOAM_MPI=$expected" \
                "FOAM_MPI=$optMpi" \
                "Replaced 'FOAM_MPI=$expected' setting by 'FOAM_MPI=$optMpi'"
    
    
            _inlineSed etc/config.csh/mpi \
                "FOAM_MPI $expected" \
                "FOAM_MPI $optMpi" \
                "Replaced 'FOAM_MPI $expected' setting by 'FOAM_MPI $optMpi'"
    
            replace    etc/bashrc  WM_MPLIB OPENMPI
            replaceCsh etc/cshrc   WM_MPLIB OPENMPI
    
            adjusted=true
            shift
            ;;
    
        -openmpi-system)
            # Explicitly set WM_MPLIB=SYSTEMOPENMPI
    
            replace    etc/bashrc  WM_MPLIB SYSTEMOPENMPI
            replaceCsh etc/cshrc   WM_MPLIB SYSTEMOPENMPI
    
            optMpi=system
            adjusted=true
            ;;
    
        -openmpi-third)
            # Explicitly set WM_MPLIB=OPENMPI, using default setting for openmpi
    
            replace    etc/bashrc  WM_MPLIB OPENMPI
            replaceCsh etc/cshrc   WM_MPLIB OPENMPI
    
    
    ## Components ##
    
        -boost)
            # Replace boost_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/CGAL   boost_version "$optionValue"
            replace etc/config.csh/CGAL  boost_version "$optionValue"
    
        -boost-path)
            # Replace BOOST_ARCH_PATH=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/config.sh/CGAL   BOOST_ARCH_PATH "\"$optionValue\""
            replaceCsh etc/config.csh/CGAL  BOOST_ARCH_PATH "\"$optionValue\""
    
        -cgal)
            # Replace cgal_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/CGAL   cgal_version "$optionValue"
            replace etc/config.csh/CGAL  cgal_version "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -cgal-path)
            # Replace CGAL_ARCH_PATH=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/config.sh/CGAL   CGAL_ARCH_PATH "$optionValue"
            replaceCsh etc/config.csh/CGAL  CGAL_ARCH_PATH "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -fftw)
            # Replace fftw_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/FFTW   fftw_version "$optionValue"
            replace etc/config.csh/FFTW  fftw_version "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -fftw-path)
            # Replace FFTW_ARCH_PATH=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/config.sh/FFTW   FFTW_ARCH_PATH "\"$optionValue\""
            replaceCsh etc/config.csh/FFTW  FFTW_ARCH_PATH "\"$optionValue\""
    
            adjusted=true
            shift
            ;;
    
        -cmake)
            # Replace cmake_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/paraview   cmake_version "$optionValue"
            replace etc/config.csh/paraview  cmake_version "$optionValue"
    
        -kahip)
            # Replace KAHIP_VERSION=...
    
            optionValue=$(getOptionValue "$@")
            replace etc/config.sh/kahip  KAHIP_VERSION "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -kahip-path)
            # Replace KAHIP_ARCH_PATH=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/kahip  KAHIP_ARCH_PATH "\"$optionValue\""
    
        -metis)
            # Replace METIS_VERSION=...
    
            optionValue=$(getOptionValue "$@")
            replace etc/config.sh/metis  METIS_VERSION "$optionValue"
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/metis  METIS_ARCH_PATH "\"$optionValue\""
    
            adjusted=true
            shift
            ;;
    
        -scotch | -scotchVersion | --scotchVersion)
            # Replace SCOTCH_VERSION=...
    
            optionValue=$(getOptionValue "$@")
            replace etc/config.sh/scotch  SCOTCH_VERSION "$optionValue"
    
        -scotch-path | -scotchArchPath | --scotchArchPath)
    
            # Replace SCOTCH_ARCH_PATH=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/scotch  SCOTCH_ARCH_PATH "\"$optionValue\""
    
    
    ## Graphics ##
    
        -paraview | -paraviewVersion | --paraviewVersion)
            # Replace ParaView_VERSION=...
            expected="[5-9][.0-9]*"
    
            optionValue=$(getOptionValue "$@")
            _matches "$optionValue" "$expected" || \
                die "'$1' has bad value: '$optionValue'"
    
            replace etc/config.sh/paraview   ParaView_VERSION "$optionValue"
            replace etc/config.csh/paraview  ParaView_VERSION "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -paraview-qt)
            # Replace ParaView_QT=...
            optionValue=$(getOptionValue "$@")
            replace etc/config.sh/paraview   ParaView_QT "$optionValue"
            replace etc/config.csh/paraview  ParaView_QT "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -paraview-path | -paraviewInstall | --paraviewInstall)
            # Replace ParaView_DIR=...
    
            optionValue=$(getOptionValue "$@")
    
            replace    etc/config.sh/paraview   ParaView_DIR \""$optionValue\""
            replaceCsh etc/config.csh/paraview  ParaView_DIR \""$optionValue\""
    
        -vtk)
            # Replace vtk_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/vtk   vtk_version "$optionValue"
            replace etc/config.csh/vtk  vtk_version "$optionValue"
    
            adjusted=true
            shift
            ;;
    
        -mesa)
            # Replace mesa_version=...
    
            optionValue=$(getOptionValue "$@")
    
            replace etc/config.sh/vtk   mesa_version "$optionValue"
            replace etc/config.csh/vtk  mesa_version "$optionValue"
    
        -sigfpe | -no-sigfpe)
            echo "Enable/disable FOAM_SIGFPE now via controlDict" 1>&2
    
        -foamInstall | --foamInstall | -projectName | --projectName)
            # Removed for 1812
    
            optionValue=$(getOptionValue "$@")
    
            echo "Ignoring obsolete option $1" 1>&2
    
            die "unknown option/argument: '$1'"
    
    if [ "$adjusted" = false ]
    then
        echo "Nothing adjusted"
        exit 0
    elif [ -z "$adjusted" ]
    then
        die "Please specify at least one configure option"
    fi
    
    
    #------------------------------------------------------------------------------