#!/bin/sh
cd ${0%/*} || exit 1                         # Run from this directory
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
. $WM_PROJECT_DIR/wmake/scripts/have_kahip
. $WM_PROJECT_DIR/wmake/scripts/have_metis
. $WM_PROJECT_DIR/wmake/scripts/have_scotch

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

: ${FOAM_EXT_LIBBIN:=/usr/lib$WM_COMPILER_LIB_ARCH}  # Extra safety?
export FOAM_EXT_LIBBIN

#
# Define how to create an mpi-versioned library of $targetType
# compile into qualified directory
# use sentinel file(s) to handle version changes
#
wmakeMpiLib()
{
    local decompName="$1"
    local objectsDir
    shift
    for libName
    do
    (
        WM_OPTIONS="$WM_OPTIONS$WM_MPLIB"
        objectsDir="$WM_PROJECT_DIR/build/$WM_OPTIONS/src/parallel/decompose/$libName"
        whichmpi="$objectsDir/using:$FOAM_MPI"
        whichdecomp="$objectsDir/using:$decompName"
        [ -e "$whichmpi" -a -e "$whichdecomp" ] || wclean $libName
        echo "wmake $targetType $libName"
        wmake $targetType $libName
        mkdir -p "$objectsDir"
        touch "$whichdecomp" "$whichmpi"
    )
    done
}

wmakeLnInclude -u decompositionMethods

if have_scotch
then
    wmake $targetType scotchDecomp
    if [ -d "$FOAM_LIBBIN/$FOAM_MPI" ]
    then
        wmakeMpiLib "$SCOTCH_VERSION" ptscotchDecomp
    fi
fi

if have_metis
then
    wmake $targetType metisDecomp
fi

if have_kahip
then
    wmake $targetType kahipDecomp
fi

wmake $targetType decompositionMethods
wmake $targetType decompose


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