makeMGridGen 4.57 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 22 23 24 25 26 27 28 29 30 31 32
#
# Script
#     makeMGridGen
#
# Description
#     Build script for MGridGen (serial)
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
# Run from ThirdParty directory only
wmakeCheckPwd "$WM_THIRD_PARTY_DIR" || {
    echo "Error: Current directory is not \$WM_THIRD_PARTY_DIR"
    echo "    The environment variables are inconsistent with the installation."
    echo "    Check the OpenFOAM entries in your dot-files and source them."
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------

# mgridgen version from OpenFOAM etc/config.sh file:
33
_foamConfig mgridgen
mark's avatar
mark committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

mgridgenPACKAGE=${MGRIDGEN_VERSION:-mgridgen-none}

#------------------------------------------------------------------------------
usage() {
    exec 1>&2
    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
    cat<<USAGE

usage: ${0##*/} [OPTION] [mgridgen-VERSION]
options:
  -gcc              Force gcc/g++ instead of the values from \$WM_CC, \$WM_CXX
  -help

* Build MGridGen
      $mgridgenPACKAGE

USAGE
    exit 1
}

#------------------------------------------------------------------------------
56
exportCompiler          # Compiler info for CMake/configure
mark's avatar
mark committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
    -h | -help)
        usage
        ;;
    -gcc)
        useGcc  # Use gcc/g++
        ;;
    mgridgen-[1-9]* | MGridGen-[1-9]* | parmgridgen-[1-9]* | ParMGridGen-[1-9]*)
        mgridgenPACKAGE="${1%%/}"
        ;;
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$mgridgenPACKAGE" ] || die "The mgridgen-VERSION was not specified"

Mark Olesen's avatar
Mark Olesen committed
80
# Nothing to build
mark's avatar
mark committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
if _foamIsNone "$mgridgenPACKAGE"
then
    echo "Using mgridgen-none (skip ThirdParty build of MGridGen)"
    exit 0
elif _foamIsSystem "$mgridgenPACKAGE"
then
    echo "Using mgridgen-system"
    exit 0
fi

#------------------------------------------------------------------------------
#
# Build MGridGen

#   MGRIDGEN_SOURCE_DIR : location of the original sources
#   MGRIDGEN_ARCH_PATH  : installation directory

MGRIDGEN_SOURCE_DIR=$WM_THIRD_PARTY_DIR/$mgridgenPACKAGE
MGRIDGEN_ARCH_PATH=$installBASE$WM_PRECISION_OPTION$WM_LABEL_OPTION/$mgridgenPACKAGE

: ${FOAM_MPI:=dummy}

echo
echo ========================================
echo "Build mgridgen library $mgridgenPACKAGE"
echo

#
# Manual installation
#
install()
{
113
    echo "Install into $MGRIDGEN_ARCH_PATH"
mark's avatar
mark committed
114

115 116 117
    local bindir=$MGRIDGEN_ARCH_PATH/bin
    local incdir=$MGRIDGEN_ARCH_PATH/include
    local libdir=$MGRIDGEN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH
mark's avatar
mark committed
118

119 120 121 122
    for dir in $MGRIDGEN_ARCH_PATH $bindir $incdir $libdir
    do
        mkdir -m 0755 -p $dir
    done
mark's avatar
mark committed
123

124 125 126
    cp -vf mgridgen.h   $incdir
    cp -vf libmgrid.a   $libdir
    cp -vf mgridgen     $bindir
mark's avatar
mark committed
127

128 129
    chmod -R 0644 $incdir/* $libdir/*
    chmod -R 0755 $bindir/*
mark's avatar
mark committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
}


# Needs future adjustment
# - for shared library
# - for mpi-specific library locations
if [ -f $MGRIDGEN_ARCH_PATH/include/mgridgen.h \
  -a -r $MGRIDGEN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH/libmgrid.a ]
then
    echo "    MGridGen header in $MGRIDGEN_ARCH_PATH/include"
    echo "    MGridGen libs   in $MGRIDGEN_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH" # static
    echo
else
(
    cd $MGRIDGEN_SOURCE_DIR || exit 1
    [ -e Makefile ] && make realclean 2>/dev/null

    # Remove any existing build folder and recreate
    rm -rf $MGRIDGEN_ARCH_PATH

    serial="${CC:-$WM_CC}"   # CC (serial compiler)   default=cc
    # parallel=$(whichMpicc)   # PARCC (parallel compiler) default=mpicc
    # PARCC=$parallel
    # PARLD=$parallel
    # PARLIBS="-L../.. -lparmgrid -lmgrid -lm"

    make \
        COPTIONS="-fPIC"  \
        LDOPTIONS="-fPIC" \
        CC=$serial \
        LD=$serial \
        LIBDIR="-L../.." \
        LIBS="-L../.. -lmgrid -lm" \
        make=make \
        serial \
    && install \
    && echo "Built: $mgridgenPACKAGE"
) || {
    echo "Error building: $mgridgenPACKAGE"
}
fi

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