openfoam/wmake/scripts/have_kahip
Mark Olesen 6194548871 ENH: split off modules/list-modules script
STYLE: string quoting when echoing paths in wmake have_* scripts

STYLE: more consistency in foamRunTutorials, foamCleanTutorials options
2020-06-19 12:43:33 +02:00

166 lines
3.8 KiB
Bash

#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2018-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# have_kahip
#
# Description
# Detection/setup of KAHIP
#
# Requires
# config.sh/kahip
#
# Functions provided
# have_kahip, no_kahip, echo_kahip, query_kahip, search_kahip
#
# Variables set on success
# HAVE_KAHIP
# KAHIP_ARCH_PATH
# KAHIP_INC_DIR
# KAHIP_LIB_DIR
#
#------------------------------------------------------------------------------
. ${WM_PROJECT_DIR:?}/wmake/scripts/sysFunctions # General system functions
#------------------------------------------------------------------------------
# Reset
no_kahip()
{
unset HAVE_KAHIP KAHIP_ARCH_PATH KAHIP_INC_DIR KAHIP_LIB_DIR
unset KAHIP_VERSION
}
# Report
echo_kahip()
{
echo "kahip=${HAVE_KAHIP:-false}"
echo "root=\"$KAHIP_ARCH_PATH\""
echo "include=\"$KAHIP_INC_DIR\""
echo "library=\"$KAHIP_LIB_DIR\""
}
# Search
# $1 : prefix (*_ARCH_PATH, system, ...)
#
# On success, return 0 and export variables
# -> HAVE_KAHIP, KAHIP_ARCH_PATH, KAHIP_INC_DIR, KAHIP_LIB_DIR
search_kahip()
{
local warn="==> skip kahip"
local incName="kaHIP_interface.h"
local libName="libkahip"
local prefix="${1:-system}"
local header library
# ----------------------------------
if isNone "$prefix"
then
[ -n "$warn" ] && echo "$warn (disabled)"
return 1
elif hasAbsdir "$prefix"
then
header=$(findFirstFile "$prefix/include/$incName")
library=$(findExtLib "$libName")
elif isSystem "$prefix"
then
header=$(findSystemInclude -name="$incName")
prefix=$(sysPrefix "$header")
else
unset prefix
fi
# ----------------------------------
# Header
[ -n "$header" ] || {
[ -n "$warn" ] && echo "$warn (no header)"
return 2
}
# Library
[ -n "$library" ] \
|| library=$(findLibrary -prefix="$prefix" -name="$libName") \
|| {
[ -n "$warn" ] && echo "$warn (no library)"
return 2
}
# ----------------------------------
# kahip itself is 32-bit int, but our interface handles some
# 64-bit conversion (mesh size).
echo "kahip (label=32) - $prefix"
export HAVE_KAHIP=true
export KAHIP_ARCH_PATH="$prefix"
export KAHIP_INC_DIR="${header%/*}" # Basename
export KAHIP_LIB_DIR="${library%/*}" # Basename
}
# Output as per search_* function
have_kahip()
{
local warn="==> skip kahip"
local config="config.sh/kahip"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile "$config")"
then
. "$file"
else
[ -n "$warn" ] && echo "$warn (no $config)"
return 1
fi
search_kahip "$KAHIP_ARCH_PATH"
}
# Query settings
query_kahip()
{
local config="config.sh/kahip"
local file
if file="$("$WM_PROJECT_DIR"/bin/foamEtcFile -mode=o "$config")"
then
. "$file"
_process_query kahip "$KAHIP_ARCH_PATH"
else
echo "(no $config)" 1>&2
echo "kahip=unknown"
fi
}
#------------------------------------------------------------------------------
# Reset
no_kahip
# Test/query
case "$1" in
-test)
have_kahip
echo_kahip
;;
-query)
query_kahip
;;
esac
#------------------------------------------------------------------------------