makeKAHIP 4.97 KB
Newer Older
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.
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/>.
12 13 14 15 16 17 18 19 20 21
#
# Script
#     makeKAHIP
#
# Description
#     Build the KaHIP library (int32 only).
#
# ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
#------------------------------------------------------------------------------
22 23 24
# Dynamic library endings (default is .so)
[ "$(uname -s)" = Darwin ] && SO=dylib || SO=so

25 26 27 28 29 30 31 32
# Short-circuit test for an installation
if [ "$1" = "-test" ]
then
    [ "$#" -eq 2 ] || { echo "${0##*/} -test : needs 1 argument"; exit 1; }
    dir="$2" # <- KAHIP_ARCH_PATH
    if [ -d "$dir/include" ]
    then
        for lib in \
33
            $FOAM_EXT_LIBBIN/libkahip.$SO \
34
            $dir/lib/libkahip.a \
35
            $dir/lib/libkahip.$SO \
36
            $dir/lib$WM_COMPILER_LIB_ARCH/libkahip.a \
37
            $dir/lib$WM_COMPILER_LIB_ARCH/libkahip.$SO \
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
            ;
        do
            if [ -r "$lib" ]
            then
                echo "    kahip include: $dir/include"
                echo "    kahip library: ${lib%/*}"
                exit 0
            fi
        done
    fi
    exit 2
fi
#------------------------------------------------------------------------------
# Run from third-party directory only
cd ${0%/*} && wmakeCheckPwd "$WM_THIRD_PARTY_DIR" 2>/dev/null || {
    echo "Error (${0##*/}) : not located in \$WM_THIRD_PARTY_DIR"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
[ -n "$FOAM_EXT_LIBBIN" ] || {
    echo "Error (${0##*/}) : \$FOAM_EXT_LIBBIN not set"
    echo "    Check your OpenFOAM environment and installation"
    exit 1
}
. etc/tools/ThirdPartyFunctions
#------------------------------------------------------------------------------
64
_foamConfig kahip
65 66 67 68 69 70 71 72 73 74 75 76 77

kahipPACKAGE=${KAHIP_VERSION:-kahip-system}
targetType=libso

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

Usage: ${0##*/} [OPTION] [lib|libso] [kahip-VERSION]
options:
78
  -gcc          Force gcc/g++ instead of using \$WM_CC, \$WM_CXX
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  -help

* Compile KaHIP
      $kahipPACKAGE

USAGE
    exit 1
}
#------------------------------------------------------------------------------

# Parse options
while [ "$#" -gt 0 ]
do
    case "$1" in
    '') ;;      # Ignore empty
    -h | -help) usage   ;;
    -gcc)       useGcc  ;;

    lib|libso)
        targetType="$1"
        ;;

101
    kahip-[1-9]* | kahip-git | KaHIP_* |  KaHIP-[1-9]*)
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        kahipPACKAGE="${1%%/}"
        unset KAHIP_ARCH_PATH  # Avoid inconsistency
        ;;
    *)
        die "unknown option/argument: '$1'"
        ;;
    esac
    shift
done

[ -n "$kahipPACKAGE" ] || die "The kahip-VERSION was not specified"

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

125 126
requireWMakeToolchain

127 128 129 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
#------------------------------------------------------------------------------
#
# Build KaHIP
#
#   KAHIP_ARCH_PATH  : installation directory
#   KAHIP_SOURCE_DIR : location of the original sources

KAHIP_SOURCE_DIR=$sourceBASE/$kahipPACKAGE
KAHIP_ARCH_PATH=$installBASE/$kahipPACKAGE

[ -d "$KAHIP_SOURCE_DIR" ] || {
    echo "Missing sources: '$kahipPACKAGE'"
    exit 1
}

#
# Manual installation
#
install()
{
    # Ensure a clean build next time
    wclean

    local bindir=$KAHIP_ARCH_PATH/bin
    local incdir=$KAHIP_ARCH_PATH/include
    local libdir=$KAHIP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH

    mkdir -m 0755 -p $incdir

    /bin/cp -pv \
        $KAHIP_SOURCE_DIR/interface/kaHIP_interface.h \
        $incdir
}

echo "Starting build: $kahipPACKAGE ($targetType)"
echo
(
    cd $KAHIP_SOURCE_DIR/lib || exit 1
    export GIT_DIR=$KAHIP_SOURCE_DIR/.git # Mask seeing our own git-repo

    rm -rf $KAHIP_ARCH_PATH
168
    rm -f $FOAM_EXT_LIBBIN/libkahip.$SO
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198

    libdir=$KAHIP_ARCH_PATH/lib$WM_COMPILER_LIB_ARCH

    cpMakeFiles kahip 2>/dev/null

    if [ -e ../interface -a ! -e interface ]
    then
        ln -s ../interface interface
    fi

    # Place static libraries in sub-directory:
    if [ "$targetType" = lib ]
    then
        mkdir -m 0755 -p $libdir 2>/dev/null
        export FOAM_EXT_LIBBIN=$libdir
    fi

    # Location of lib sources for wmake
    export KAHIP_LIB_SRC=$PWD

    wmake -j $WM_NCOMPPROCS -s $targetType \
    && echo "Built: kahip" \
    && install
) || {
    echo "Error building: kahip"
    exit 1
}


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