ENH: support build of scotch executables

- improve library checks to avoid unnecessary rebuild when
  cross-compiling
This commit is contained in:
Mark Olesen
2020-04-15 14:51:54 +02:00
parent a4ba6b72f5
commit 60d3922681

View File

@ -6,17 +6,16 @@
# \\ / A nd | www.openfoam.com # \\ / A nd | www.openfoam.com
# \\/ M anipulation | # \\/ M anipulation |
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Copyright (C) 2019 OpenCFD Ltd. # Copyright (C) 2019-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM, licensed under GNU General Public License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
# <http://www.gnu.org/licenses/>.
# #
# Script # Script
# makeSCOTCH # makeSCOTCH
# #
# Description # Description
# Build the SCOTCH and PTSCOTCH libraries # Build the SCOTCH and PTSCOTCH libraries, optionally build binaries
# #
# ---------------------------------------------- # ----------------------------------------------
# NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE # NO USER-CONFIGURABLE SETTINGS WITHIN THIS FILE
@ -53,18 +52,22 @@ usage()
Usage: ${0##*/} [OPTION] [libso] [scotch-VERSION] Usage: ${0##*/} [OPTION] [libso] [scotch-VERSION]
options: options:
-force Force compilation, even if include/library already exists
-gcc Force use of gcc/g++ -gcc Force use of gcc/g++
-bin Create scotch binaries as well (experimental)
-no-bin Suppress creation of scotch binaries (default)
-no-mpi Suppress build of pt-scotch -no-mpi Suppress build of pt-scotch
-help -help
* Compile SCOTCH * Compile SCOTCH
$kahipPACKAGE $scotchPACKAGE
USAGE USAGE
exit 1 exit 1
} }
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
unset optBinaries optForce
# Parse options # Parse options
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -73,9 +76,11 @@ do
-h | -help) usage ;; -h | -help) usage ;;
-gcc) useGcc ;; -gcc) useGcc ;;
-no-mpi) -force) optForce=true ;;
unset withMPI -bin) optBinaries=true ;;
;; -no-bin) unset optBinaries ;;
-no-mpi) unset withMPI ;;
scotch-[1-9]* | scotch-git | scotch_* | scotch-[1-9]*) scotch-[1-9]* | scotch-git | scotch_* | scotch-[1-9]*)
scotchPACKAGE="${1%%/}" scotchPACKAGE="${1%%/}"
unset SCOTCH_ARCH_PATH # Avoid inconsistency unset SCOTCH_ARCH_PATH # Avoid inconsistency
@ -90,11 +95,11 @@ done
[ -n "$scotchPACKAGE" ] || die "The scotch-VERSION was not specified" [ -n "$scotchPACKAGE" ] || die "The scotch-VERSION was not specified"
# Nothing to build # Nothing to build
if _foamIsNone $scotchPACKAGE if _foamIsNone "$scotchPACKAGE"
then then
echo "Using scotch-none (skip ThirdParty build of SCOTCH)" echo "Using scotch-none (skip ThirdParty build of SCOTCH)"
exit 0 exit 0
elif _foamIsSystem $scotchPACKAGE elif _foamIsSystem "$scotchPACKAGE"
then then
echo "Using scotch-system" echo "Using scotch-system"
exit 0 exit 0
@ -123,7 +128,7 @@ makefileInc="../../$scotchMakefile"
# SCOTCH_ARCH_PATH : installation directory # SCOTCH_ARCH_PATH : installation directory
# SCOTCH_SOURCE_DIR : location of the original sources # SCOTCH_SOURCE_DIR : location of the original sources
SCOTCH_SOURCE_DIR=$sourceBASE/$scotchPACKAGE SCOTCH_SOURCE_DIR="$sourceBASE/$scotchPACKAGE"
: "${SCOTCH_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$scotchPACKAGE}" : "${SCOTCH_ARCH_PATH:=$installBASE$WM_SIZE_OPTIONS/$scotchPACKAGE}"
[ -d "$SCOTCH_SOURCE_DIR/src" ] || { [ -d "$SCOTCH_SOURCE_DIR/src" ] || {
@ -137,12 +142,19 @@ echo ========================================
echo "scotch decomposition ($scotchPACKAGE)" echo "scotch decomposition ($scotchPACKAGE)"
echo " Makefile.inc : ${makefileInc##*/}" echo " Makefile.inc : ${makefileInc##*/}"
# (serial) scotch
prefixDIR="$SCOTCH_ARCH_PATH"
binDIR="$prefixDIR"/bin
incDIR="$prefixDIR"/include
libDIR="$FOAM_EXT_LIBBIN"
# Test installation. May or may not have libscotcherrexit.so # Test installation. May or may not have libscotcherrexit.so
if [ -f "$SCOTCH_ARCH_PATH/include/scotch.h" ] \ if [ -z "$optForce" ] \
&& [ -r "$FOAM_EXT_LIBBIN/libscotch$EXT_SO" ] && [ -f "$incDIR"/scotch.h ] \
&& haveLibso "$libDIR"/libscotch
then then
echo " scotch include: $SCOTCH_ARCH_PATH/include" echo " scotch include: $incDIR"
echo " scotch library: $FOAM_EXT_LIBBIN" echo " scotch library: $libDIR"
elif [ -d "$SCOTCH_SOURCE_DIR" ] elif [ -d "$SCOTCH_SOURCE_DIR" ]
then then
( (
@ -163,18 +175,14 @@ then
applyPatch "$scotchPACKAGE" .. # patch at parent-level applyPatch "$scotchPACKAGE" .. # patch at parent-level
prefixDIR=$SCOTCH_ARCH_PATH mkdir -p "$binDIR" 2>/dev/null
incDIR=$SCOTCH_ARCH_PATH/include mkdir -p "$incDIR" 2>/dev/null
libDIR=$FOAM_EXT_LIBBIN mkdir -p "$libDIR" 2>/dev/null
mkdir -p $prefixDIR 2>/dev/null
mkdir -p $incDIR 2>/dev/null
mkdir -p $libDIR 2>/dev/null
if [ -f "$makefileInc" ] if [ -f "$makefileInc" ]
then then
rm -f Makefile.inc rm -f Makefile.inc
ln -s $makefileInc Makefile.inc ln -s "$makefileInc" Makefile.inc
fi fi
[ -f Makefile.inc ] || { [ -f Makefile.inc ] || {
echo " Error: scotch needs an appropriate Makefile.inc" echo " Error: scotch needs an appropriate Makefile.inc"
@ -187,15 +195,24 @@ then
# Consistency for Intel-MPI and non-icc compilers # Consistency for Intel-MPI and non-icc compilers
[ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)" [ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)"
# The make targets
make_targets="libscotch"
if [ "$optBinaries" = true ]
then
make_targets="$make_targets scotch"
fi
make realclean 2>/dev/null # Extra safety make realclean 2>/dev/null # Extra safety
make -j $WM_NCOMPPROCS libscotch \ make -j $WM_NCOMPPROCS $make_targets \
&& make \ && make \
prefix=$prefixDIR \ prefix="$prefixDIR" \
includedir=$incDIR \ bindir="$binDIR" \
libdir=$libDIR \ libdir="$libDIR" \
includedir="$incDIR" \
install install
rmdir "$SCOTCH_ARCH_PATH/bin" 2> /dev/null || true # Superfluous bin? rmdir "$binDIR" 2>/dev/null || true # Remove empty bin/
rmdir "${binDIR%/*}" 2>/dev/null || true # ... and empty parent
make realclean 2>/dev/null || true # Failed cleanup is uncritical make realclean 2>/dev/null || true # Failed cleanup is uncritical
) || warnBuildIssues SCOTCH ) || warnBuildIssues SCOTCH
else else
@ -211,25 +228,32 @@ fi
exit 0 exit 0
} }
echo
echo ========================================
echo "pt-scotch decomposition ($scotchPACKAGE with $FOAM_MPI)"
# Build ptscotch if normal scotch was built (has include and library) # Build ptscotch if normal scotch was built (has include and library)
[ -f "$SCOTCH_ARCH_PATH/include/scotch.h" ] && \ # (reuse prefix/include/lib dirs set above)
[ -r "$FOAM_EXT_LIBBIN/libscotch$EXT_SO" ] || \ if [ -f "$incDIR"/scotch.h ] \
{ && haveLibso "$libDIR"/libscotch
# Report that the above tests failed and pass-through the failure
echo
echo " skipping - no <scotch.h> found"
exit 2
}
if [ -f "$SCOTCH_ARCH_PATH/include/$FOAM_MPI/ptscotch.h" ] && \
[ -r "$FOAM_EXT_LIBBIN/$FOAM_MPI/libptscotch$EXT_SO" ]
then then
echo " ptscotch include: $SCOTCH_ARCH_PATH/include/$FOAM_MPI" echo
echo " ptscotch library: $FOAM_EXT_LIBBIN/$FOAM_MPI" echo ========================================
echo "pt-scotch decomposition ($scotchPACKAGE with $FOAM_MPI)"
else
# Report that the above tests failed and pass-through the failure
echo "Skipping pt-scotch - no <scotch.h> found"
exit 2
fi
# (parallel) pt-scotch
prefixDIR="$SCOTCH_ARCH_PATH"
binDIR="$prefixDIR/bin/$FOAM_MPI"
incDIR="$prefixDIR/include/$FOAM_MPI"
libDIR="$FOAM_EXT_LIBBIN/$FOAM_MPI"
if [ -z "$optForce" ] \
&& [ -f "$incDIR"/ptscotch.h ] \
&& haveLibso "$libDIR"/libptscotch
then
echo " ptscotch include: $incDIR"
echo " ptscotch library: $libDIR"
else else
( (
# Older versions ok, but scotch-6.0.5a cannot build in parallel. # Older versions ok, but scotch-6.0.5a cannot build in parallel.
@ -246,18 +270,14 @@ else
export GIT_DIR="$SCOTCH_SOURCE_DIR/.git" # Mask seeing our own git-repo export GIT_DIR="$SCOTCH_SOURCE_DIR/.git" # Mask seeing our own git-repo
echo echo
prefixDIR=$SCOTCH_ARCH_PATH mkdir -p "$binDIR" 2>/dev/null
incDIR=$SCOTCH_ARCH_PATH/include/$FOAM_MPI mkdir -p "$incDIR" 2>/dev/null
libDIR=$FOAM_EXT_LIBBIN/$FOAM_MPI mkdir -p "$libDIR" 2>/dev/null
mkdir -p $prefixDIR 2>/dev/null
mkdir -p $incDIR 2>/dev/null
mkdir -p $libDIR 2>/dev/null
if [ -f "$makefileInc" ] if [ -f "$makefileInc" ]
then then
rm -f Makefile.inc rm -f Makefile.inc
ln -s $makefileInc Makefile.inc ln -s "$makefileInc" Makefile.inc
fi fi
[ -f Makefile.inc ] || { [ -f Makefile.inc ] || {
echo " Error: ptscotch needs an appropriate Makefile.inc" echo " Error: ptscotch needs an appropriate Makefile.inc"
@ -270,15 +290,24 @@ else
# Consistency for Intel-MPI and non-icc compilers # Consistency for Intel-MPI and non-icc compilers
[ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)" [ -n "$I_MPI_CC" ] || export I_MPI_CC="$(whichCC)"
# The make targets. No simple means of handling mpi-specific binaries
make_targets="libptscotch"
if [ "$optBinaries" = true ]
then
make_targets="$make_targets ptscotch"
fi
make realclean 2>/dev/null # Extra safety make realclean 2>/dev/null # Extra safety
make -j $WM_NCOMPPROCS libptscotch \ make -j $WM_NCOMPPROCS $make_targets \
&& make \ && make \
prefix=$prefixDIR \ prefix="$prefixDIR" \
includedir=$incDIR \ bindir="$binDIR" \
libdir=$libDIR \ libdir="$libDIR" \
includedir="$incDIR" \
install install
rmdir "$SCOTCH_ARCH_PATH/bin" 2> /dev/null || true # Superfluous bin? rmdir "$binDIR" 2>/dev/null || true # Remove empty bin/
rmdir "${binDIR%/*}" 2>/dev/null || true # ... and empty parent
make realclean 2>/dev/null || true # Failed cleanup is uncritical make realclean 2>/dev/null || true # Failed cleanup is uncritical
) || warnBuildIssues PTSCOTCH ) || warnBuildIssues PTSCOTCH
fi fi