#!/bin/sh #---------------------------------*- sh -*------------------------------------- # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation # \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. #------------------------------------------------------------------------------ # 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 . # # Script # foamConfigurePaths # # Description # Adjust hardcoded installation paths and versions # #------------------------------------------------------------------------------ usage() { exec 1>&2 while [ "$#" -ge 1 ]; do echo "$1"; shift; done cat<&2 echo echo "Error: see '${0##*/} -help' for usage" while [ "$#" -ge 1 ]; do echo " $1"; shift; done echo exit 1 } # Function to do replacement on file. Checks if any replacement has been done. # _inlineSed _inlineSed() { local file="$1" local regexp="$2" local replacement="$3" local msg="$4" local cmd='/^[^#]/s@'"$regexp"'@'"$replacement"'@' [ -f "$file" ] || { echo "Missing file: $file" exit 2 # Fatal } grep -q "$regexp" "$file" && sed -i -e "$cmd" "$file" || { \ echo "Failed: $msg in $file" return 1 } echo "Okay: $msg in $file" return 0 } # Standard type of replacements. # replace .. # looks for KEYWORD=.* replace() { local file="$1" shift local key local val while [ "$#" -ge 2 ] do key=$1 val=$2 shift 2 _inlineSed \ $file \ "$key=.*" \ "$key=$val" \ "Replacing $key setting by '$val'" done } [ -f etc/bashrc ] || usage "Please run from top-level directory of installation" #------------------------------------------------------------------------------ unset adjusted # Parse options while [ "$#" -gt 0 ] do case "$1" in -h | -help | --help) usage ;; -foamInstall | --foamInstall) # Replace FOAM_INST_DIR=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" foamInstDir="$2" _inlineSed \ etc/bashrc \ '\(.*BASH_SOURCE.*\)' \ '##\1' \ "Removing default FOAM_INST_DIR setting" _inlineSed \ etc/bashrc \ '^ *FOAM_INST_DIR=.*' \ 'FOAM_INST_DIR='"$foamInstDir" \ "Setting FOAM_INST_DIR to '$foamInstDir'" adjusted=true shift ;; -projectName | --projectName) # Replace WM_PROJECT_DIR=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" projectName="$2" _inlineSed \ etc/bashrc \ 'WM_PROJECT_DIR=.*' \ 'WM_PROJECT_DIR=$WM_PROJECT_INST_DIR/'"$projectName" \ "Replacing WM_PROJECT_DIR setting by $projectName" adjusted=true shift ;; -projectVersion | --projectVersion) # Replace WM_PROJECT_VERSION=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/bashrc WM_PROJECT_VERSION "$2" adjusted=true shift ;; -archOption | --archOption) # Replace WM_ARCH_OPTION=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" archOption="$2" current="$(sed -ne '/^[^#]/s/^.* WM_ARCH_OPTION=//p' etc/bashrc)" if [ "$archOption" = "$current" ] then echo "WM_ARCH_OPTION already set to $archOption" else replace etc/bashrc WM_ARCH_OPTION "$2" fi adjusted=true shift ;; -label) # Replace WM_LABEL_SIZE=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/bashrc WM_LABEL_SIZE "$2" adjusted=true shift ;; -system) # Replace WM_COMPILER_TYPE=... and WM_COMPILER=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/bashrc WM_COMPILER_TYPE system WM_COMPILER "$2" adjusted=true shift ;; -third[Pp]arty) # Replace WM_COMPILER_TYPE=... and WM_COMPILER=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/bashrc WM_COMPILER_TYPE ThirdParty WM_COMPILER "$2" adjusted=true shift ;; -boost) # Replace boost_version=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/CGAL boost_version "$2" adjusted=true shift ;; -boostArchPath) # Replace BOOST_ARCH_PATH=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/CGAL BOOST_ARCH_PATH "$2" adjusted=true shift ;; -cgal) # Replace cgal_version=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/CGAL cgal_version "$2" adjusted=true shift ;; -cgalArchPath) # Replace CGAL_ARCH_PATH=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/CGAL CGAL_ARCH_PATH "$2" adjusted=true shift ;; -fftw) # Replace fftw_version=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/FFTW fftw_version "$2" adjusted=true shift ;; -fftwArchPath) # Replace FFTW_ARCH_PATH=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/FFTW FFTW_ARCH_PATH "$2" adjusted=true shift ;; -clang) # Replace clang_version=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/compiler clang_version "$2" adjusted=true shift ;; -cmake) # Replace cmake_version=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/paraview cmake_version "$2" adjusted=true shift ;; -paraview | -paraviewVersion | --paraviewVersion) # Replace ParaView_VERSION=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/paraview ParaView_VERSION "$2" adjusted=true shift ;; -paraviewInstall | --paraviewInstall) # Replace ParaView_DIR=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/paraview ParaView_DIR "$2" adjusted=true shift ;; -metis) # Replace METIS_VERSION=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/metis METIS_VERSION "$2" adjusted=true shift ;; -metisArchPath) # Replace METIS_ARCH_PATH=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/metis METIS_ARCH_PATH "$2" adjusted=true shift ;; -scotch | -scotchVersion | --scotchVersion) # Replace SCOTCH_VERSION=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/scotch SCOTCH_VERSION "$2" adjusted=true shift ;; -scotchArchPath | --scotchArchPath) # Replace SCOTCH_ARCH_PATH=... [ "$#" -ge 2 ] || die "'$1' option requires an argument" replace etc/config.sh/scotch SCOTCH_ARCH_PATH "$2" adjusted=true shift ;; *) die "unknown option/argument: '$1'" ;; esac shift done [ -n "$adjusted" ] || die "Please specify at least one configure option" # Set WM_MPLIB=SYSTEMOPENMPI always replace etc/bashrc WM_MPLIB SYSTEMOPENMPI ## Set WM_COMPILER_TYPE=system always # replace etc/bashrc WM_COMPILER_TYPE system #------------------------------------------------------------------------------