Skip to content
Snippets Groups Projects
foamConfigurePaths 6.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • #!/bin/sh
    #---------------------------------*- sh -*-------------------------------------
    # =========                 |
    # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    #  \\    /   O peration     |
    
    #   \\  /    A nd           | Copyright (C) 2011-2013 OpenFOAM Foundation
    
    #    \\/     M anipulation  |
    #------------------------------------------------------------------------------
    # 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/>.
    #
    # Script
    #     foamConfigurePaths
    #
    # Description
    #     hardcode installation directory
    #
    #------------------------------------------------------------------------------
    usage() {
    
        while [ "$#" -ge 1 ]; do echo "$1"; shift; done
        cat<<USAGE
    
    usage: ${0##*/}
    
      --foamInstall dir         specify installation directory (e.g. /opt)
    
    andy's avatar
    andy committed
      --projectName name        specify project name (e.g. openfoam220)
      --projectVersion ver      specify project version (e.g. 2.2.0)
      --archOption arch         specify architecture option (only 32 or 64 applicable)
      --paraviewInstall dir     specify ParaView_DIR (e.g. /opt/paraviewopenfoam3120)
      --paraviewVersion ver     specify ParaView_VERSION (e.g. 3.12.0)
    
      --scotchArchPath dir      specify SCOTCH_ARCH_PATH (e.g. /opt/OpenFOAM-scotch-6.0.0/)
      --scotchVersion ver       specify SCOTCH_VERSION (e.g. 6.0.0)
    
    
    * hardcode paths to installation
    
    USAGE
        exit 1
    }
    
    
    
    andy's avatar
    andy committed
    # Function to do replacement on file. Checks if any replacement has been done.
    # _inlineSed <file> <regexp> <replacement> <msg>
    
    andy's avatar
    andy committed
        file="$1"
    
        [ -f "$file" ] || {
            echo "Missing file: $file"
    
    andy's avatar
    andy committed
        regexp="$2"
        replacement="$3"
        msg="$4"
    
    andy's avatar
    andy committed
        cmd='/^[^#]/s@'"$regexp"'@'"$replacement"'@'
    
        grep -q "$regexp" "$file" && sed -i -e "$cmd" "$file" || \
            (echo "Failed: $msg in $file" && exit 1)
    
        echo "Okay: $msg in $file"
    
    [ -f etc/bashrc ] || usage "Please run from top-level directory of installation"
    
    unset foamInstall projectName projectVersion archOption
    unset paraviewInstall scotchArchPath
    
    
    # parse options
    while [ "$#" -gt 0 ]
    do
        case "$1" in
    
        -foamInstall | --foamInstall)
    
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
    
            foamInstall="$2"
    
            # replace foamInstall=...
    
            _inlineSed \
                etc/bashrc \
    
    andy's avatar
    andy committed
                'foamInstall=.*' \
                'foamInstall='"$foamInstall" \
    
                "Replacing foamInstall setting by '$foamInstall'"
    
       -projectName | --projectName)
    
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
    
            projectName="$2"
    
            # replace WM_PROJECT_DIR=...
    
    andy's avatar
    andy committed
                'WM_PROJECT_DIR=.*' \
                'WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/'"$projectName" \
    
                "Replacing WM_PROJECT_DIR setting by $projectName"
            shift 2
            ;;
       --projectVersion)
    
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
            projectVersion="$2"
            # replace WM_PROJECT_VERSION=...
            echo "Replacing WM_PROJECT_VERSION setting by $projectVersion"
    
    andy's avatar
    andy committed
            _inlineSed \
                etc/bashrc \
                'WM_PROJECT_VERSION=.*' \
                'WM_PROJECT_VERSION='"$projectVersion" \
                "Replacing WM_PROJECT_VERSION setting by $projectVersion"
    
    
        -archOption | --archOption)
    
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
    
            archOption="$2"
    
            current_archOption=`grep WM_ARCH_OPTION= etc/bashrc | sed "s/export WM_ARCH_OPTION=//"`
            if [ "$archOption" != "$current_archOption" ]
            then
                # replace WM_ARCH_OPTION=...
                _inlineSed \
                    etc/bashrc \
    
    andy's avatar
    andy committed
                    'WM_ARCH_OPTION=.*' \
                    'WM_ARCH_OPTION='"$archOption" \
                    "Replacing WM_ARCH_OPTION setting by '$archOption'"
    
            else
                echo "WM_ARCH_OPTION already set to $archOption"
            fi
    
        -paraviewInstall | --paraviewInstall)
    
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
    
            paraviewInstall="$2"
    
            # replace ParaView_DIR=...
    
                etc/config.sh/paraview \
    
    andy's avatar
    andy committed
                'ParaView_DIR=.*' \
                'ParaView_DIR='"$paraviewInstall" \
    
                "Replacing ParaView_DIR setting by '$paraviewInstall'"
    
        -paraviewVersion | --paraviewVersion)
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
            paraviewVersion="$2"
            # replace ParaView_VERSION=...
            _inlineSed \
    
                etc/config.sh/paraview \
    
    andy's avatar
    andy committed
                'ParaView_VERSION=.*' \
                'ParaView_VERSION='"$paraviewVersion" \
                "Replacing ParaView_VERSION setting by '$paraviewVersion'"
    
        -scotchVersion | --scotchVersion)
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
            scotchVersion="$2"
            _inlineSed \
    
                etc/config.sh/scotch \
    
                'SCOTCH_VERSION=.*' \
                'SCOTCH_VERSION='"$scotchVersion" \
                "Replacing SCOTCH_VERSION setting by '$scotchVersion'"
            shift 2
            ;;
        -scotchArchPath | --scotchArchPath)
            [ "$#" -ge 2 ] || usage "'$1' option requires an argument"
            scotchArchPath="$2"
            _inlineSed \
    
                etc/config.sh/scotch \
    
                'SCOTCH_ARCH_PATH=.*' \
                'SCOTCH_ARCH_PATH='"$scotchArchPath" \
                "Replacing SCOTCH_ARCH_PATH setting by '$scotchArchPath'"
            shift 2
            ;;
    
        *)
            usage "unknown option/argument: '$*'"
            ;;
        esac
    done
    
    
    [ -n "$foamInstall" -o -n "$projectName" -o -n "$projectVersion" -o -n "$archOption" \
    -o -n "$paraviewInstall" -o -n "$paraviewVersion" \
    -o -n "$scotchVersion" -o -n "$scotchArchPath" \
    ] || usage "Please specify at least one configure option"
    
    #echo "Replacing WM_PROJECT setting by '$projectName'"
    
    #sed -i -e 's@WM_PROJECT=.*@WM_PROJECT='"$projectName@" etc/bashrc
    
    
    # Set WM_MPLIB=SYSTEMOPENMPI always
    
    andy's avatar
    andy committed
        'export WM_MPLIB=.*' \
        'export WM_MPLIB=SYSTEMOPENMPI' \
    
        "Replacing WM_MPLIB setting by 'SYSTEMOPENMPI'"
    
    ## set foamCompiler=system always
    #_inlineSed \
    #    etc/bashrc \
    
    andy's avatar
    andy committed
    #    'foamCompiler=.*' \
    #    'foamCompiler=system' \
    
    #    "Replacing foamCompiler setting by 'system'"
    
    
    #------------------------------------------------------------------------------