makeMPICH 4.94 KB
Newer Older
mark's avatar
mark committed
1 2 3 4 5
#!/bin/sh
#------------------------------------------------------------------------------
# =========                 |
# \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
#  \\    /   O peration     |
6
#   \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
mark's avatar
mark committed
7 8 9
#    \\/     M anipulation  |
#------------------------------------------------------------------------------
# License
Mark Olesen's avatar
Mark Olesen committed
10 11
#     This file is part of OpenFOAM, licensed under GNU General Public License
#     <http://www.gnu.org/licenses/>.
mark's avatar
mark committed
12 13 14 15 16 17 18 19 20 21
#
# Script
#     makeMPICH
#
# Description
#     Build script for mpich - legacy (unmaintained) build code!
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
22 23 24
# Dynamic library endings (default is .so)
[ "$(uname -s)" = Darwin ] && SO=dylib || SO=so

mark's avatar
mark committed
25 26 27 28 29
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
    [ "$#" -eq 2 ] || { echo "${0##*/} -test : needs 1 argument"; exit 1; }
    dir="$2" # <- MPI_ARCH_PATH
30
    if [ -r "$dir/lib$WM_COMPILER_LIB_ARCH/libmpich.$SO" ]
mark's avatar
mark committed
31
    then
mark's avatar
mark committed
32
        echo "Have mpich shared library (${dir##*/})"
mark's avatar
mark committed
33
        exit 0
mark's avatar
mark committed
34
    elif [ -r "$dir/lib$WM_COMPILER_LIB_ARCH/libmpich.a" ]
mark's avatar
mark committed
35
    then
mark's avatar
mark committed
36
        echo "Have mpich static library (${dir##*/})"
mark's avatar
mark committed
37 38 39 40 41 42 43 44
        exit 0
    else
        echo "No mpich libraries found: ${dir:-not-specified}"
        exit 2
    fi
fi
#------------------------------------------------------------------------------
# Run from third-party directory only
45
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
mark's avatar
mark committed
46 47 48 49 50
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
51 52 53 54 55
# Transition
# ~~~~~~~~~~
_foamAddLib()  { true; }
_foamAddMan()  { true; }
_foamAddPath() { true; }
mark's avatar
mark committed
56 57
#------------------------------------------------------------------------------

58 59 60
WM_MPLIB=MPICH                                  # Ensure we get the correct MPI

# mpich version from OpenFOAM etc/config.sh file:
61
_foamConfig mpi
mark's avatar
mark committed
62 63

mpiPACKAGE=${FOAM_MPI:-mpich-system}
64

mark's avatar
mark committed
65 66 67 68 69 70
#------------------------------------------------------------------------------
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

Mark Olesen's avatar
Mark Olesen committed
71
usage: ${0##*/} [OPTION] [mpich-VERSION] [-- configure-options]
mark's avatar
mark committed
72 73 74 75 76 77 78 79 80 81 82
options:
  -gcc              force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
  -help

* build mpich with
      ${mpiPACKAGE:-'unspecified mpich version'}

USAGE
    exit 1
}
#------------------------------------------------------------------------------
83
exportCompiler          # Compiler info for CMake/configure
mark's avatar
mark committed
84 85 86 87 88

# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
89
    '') ;;      # Ignore empty
Mark Olesen's avatar
Mark Olesen committed
90
    --) break;; # Extra configure options (leave on $@ for later detection)
91 92 93
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;

mark's avatar
mark committed
94 95 96
    mpich*)
        mpiPACKAGE="${1%%/}"
        ;;
Mark Olesen's avatar
Mark Olesen committed
97

mark's avatar
mark committed
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$mpiPACKAGE" ] || die "The mpich-VERSION was not specified"

# Nothing to build
if _foamIsNone "$mpiPACKAGE"
then
    echo "Using mpich-none (skip ThirdParty build of mpich)"
    exit 0
elif _foamIsSystem "$mpiPACKAGE"
then
    echo "Using mpich-system (skip ThirdParty build of mpich)"
    exit 0
fi

#------------------------------------------------------------------------------
#
120
# Build mpich
mark's avatar
mark committed
121 122 123 124 125 126 127
#
#   MPI_SOURCE_DIR : location of the original sources
#   MPI_ARCH_PATH  : installation directory

MPI_SOURCE_DIR=$sourceBASE/$mpiPACKAGE
MPI_ARCH_PATH=$installBASE/$mpiPACKAGE

128
if [ -r "$MPI_ARCH_PATH/lib_ARCH/libmpi.$SO" ]
mark's avatar
mark committed
129 130 131 132 133 134 135 136 137 138
then
    echo "Already has shared library"
elif [ -r "$MPI_ARCH_PATH/lib/libmpi.a" ]
then
    echo "Already has static library"
else
    echo "Starting build: $WM_MPLIB ($mpiPACKAGE)"
    echo

    (
Mark Olesen's avatar
Mark Olesen committed
139
        # Configuration options:
mark's avatar
mark committed
140
        unset configOpt
Mark Olesen's avatar
Mark Olesen committed
141 142 143 144 145 146 147 148 149

        # Additional configure options
        if [ "$1" = "--" ]
        then
            shift
            configOpt="$configOpt $@"
        fi

        # End of configuration options
mark's avatar
mark committed
150
        # ----------------------------
mark's avatar
mark committed
151

mark's avatar
mark committed
152
        cd $MPI_SOURCE_DIR || exit 1
153
        export GIT_DIR=$PWD/.git # Mask seeing our own git-repo
mark's avatar
mark committed
154
        [ -e Makefile ] && make distclean 2>/dev/null
mark's avatar
mark committed
155

mark's avatar
mark committed
156
        rm -rf $MPI_ARCH_PATH
mark's avatar
mark committed
157 158 159
        rm -rf $buildDIR
        mkdir -p $buildDIR
        cd $buildDIR
mark's avatar
mark committed
160

mark's avatar
mark committed
161 162
        set -x
        $MPI_SOURCE_DIR/configure \
mark's avatar
mark committed
163
            --prefix=$MPI_ARCH_PATH \
mark's avatar
mark committed
164 165 166 167 168 169 170 171 172 173 174 175 176
            --disable-fortran --disable-g \
            --libdir=$MPI_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH \
            --enable-shared --disable-static \
            $configOpt \
        && set +x \
        && make -j $WM_NCOMPPROCS \
        && make install \
        && echo "Built: $mpiPACKAGE" \
        && pkgconfigAdjust $MPI_ARCH_PATH
    ) || {
        echo "Error building: $mpiPACKAGE"
        exit 1
    }
mark's avatar
mark committed
177 178 179
fi

#------------------------------------------------------------------------------