ENH: robustness improvements for wmakeFunctions

- relocated module-prefix handling to wmakeFunctions
This commit is contained in:
Mark Olesen 2020-11-26 09:06:34 +01:00
parent a50047bbcc
commit 9c86b5d722
4 changed files with 80 additions and 72 deletions

View File

@ -389,7 +389,7 @@ esac
# Final # Final
# Ensure MPI_ARCH_PATH is marked for export # Ensure MPI_ARCH_PATH is marked for export
[ -n "$MPI_ARCH_PATH" ] && export MPI_ARCH_PATH [ -n "$MPI_ARCH_PATH" ] && export MPI_ARCH_PATH
# A real (non-dummy) MPI # A real (non-dummy) MPI

View File

@ -86,7 +86,7 @@ USAGE
# Parse the arguments and options # Parse the arguments and options
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
unset optDebug optLog optNonRecursive optPrefix optQueue unset optDebug optLog optNonRecursive optQueue
unset optWmakeFrontend unset optWmakeFrontend
for arg in "$@" for arg in "$@"
@ -112,27 +112,21 @@ do
;; ;;
-module-prefix=* | -prefix=* | --prefix=*) -module-prefix=* | -prefix=* | --prefix=*)
optPrefix="${arg#*=}" # As per setModulePrefix (wmakeFunctions)
case "$optPrefix" in export FOAM_MODULE_PREFIX="${arg#*=}"
case "$FOAM_MODULE_PREFIX" in
# Prefix: user # Prefix: user
(u | user) (u | user) FOAM_MODULE_PREFIX="${FOAM_USER_LIBBIN%/*}" ;;
export FOAM_MODULE_PREFIX="${FOAM_USER_LIBBIN%/*}"
;;
# Prefix: group # Prefix: group
(g | group) (g | group) FOAM_MODULE_PREFIX="${FOAM_SITE_LIBBIN%/*}" ;;
export FOAM_MODULE_PREFIX="${FOAM_SITE_LIBBIN%/*}"
;;
# Prefix: openfoam (other) # Prefix: openfoam (other)
(o | openfoam) (o | openfoam) FOAM_MODULE_PREFIX="${FOAM_LIBBIN%/*}" ;;
export FOAM_MODULE_PREFIX="${FOAM_LIBBIN%/*}"
;;
# Prefix: custom (absolute or relative) # Prefix: directory (absolute or relative)
(*) (*)
export FOAM_MODULE_PREFIX="$optPrefix" : "${FOAM_MODULE_PREFIX:=/usr/local}" # Fallback (autoconf-like)
: "${FOAM_MODULE_PREFIX:=/usr/local}" # Default (autoconf)
# Require absolute path # Require absolute path
[ "${FOAM_MODULE_PREFIX#/}" != "${FOAM_MODULE_PREFIX}" ] || \ [ "${FOAM_MODULE_PREFIX#/}" != "${FOAM_MODULE_PREFIX}" ] || \
@ -140,8 +134,9 @@ do
;; ;;
esac esac
# Avoid potential conflicts
unset FOAM_MODULE_APPBIN FOAM_MODULE_LIBBIN unset FOAM_MODULE_APPBIN FOAM_MODULE_LIBBIN
echo "Module prefix = $FOAM_MODULE_PREFIX" 1>&2 echo "Module prefix = ${FOAM_MODULE_PREFIX:-[]}" 1>&2
continue # Handled argument continue # Handled argument
;; ;;
@ -228,7 +223,7 @@ fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
unset optWmakeFrontend unset optWmakeFrontend
unset optNonRecursive optDebug optLog optPrefix optQueue unset optNonRecursive optDebug optLog optQueue
unset -f usage unset -f usage

View File

@ -26,11 +26,11 @@ MakeDir=Make
: "${Script:=wmakeFunctions}" : "${Script:=wmakeFunctions}"
# Environment defaults # Environment defaults
if [ -z "$WM_DIR" ] if [ -z "$WM_DIR" ] && [ -n "$WM_PROJECT_DIR" ]
then then
WM_DIR="$WM_PROJECT_DIR/wmake" WM_DIR="$WM_PROJECT_DIR/wmake"
export WM_DIR
fi fi
[ -n "$WM_DIR" ] && export WM_DIR
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -40,21 +40,55 @@ checkEnv()
{ {
local check failed local check failed
# Default for WM_DIR already provided above # Possibly redundant check for WM_DIR
for check in WM_PROJECT_DIR WM_DIR WM_OPTIONS
for check in WM_PROJECT_DIR WM_OPTIONS
do do
eval test -n "\$$check" || failed="$failed $check" eval test -n "\$$check" || failed="$failed $check"
done done
[ -z "$failed" ] || { if [ -n "$failed" ]
echo "$Script error: Environment variable(s) not set" 1>&2 then
echo "$Script error: OpenFOAM environment variable(s) not set" 1>&2
echo " $failed" 1>&2 echo " $failed" 1>&2
exit 1 exit 1
} fi
} }
# Set FOAM_MODULE_PREFIX according to
# - absolute/relative path
# - predefined type (u,user | g,group | o,openfoam)
setModulePrefix()
{
export FOAM_MODULE_PREFIX="$1"
case "$FOAM_MODULE_PREFIX" in
# Prefix: user
(u | user) FOAM_MODULE_PREFIX="${FOAM_USER_LIBBIN%/*}" ;;
# Prefix: group
(g | group) FOAM_MODULE_PREFIX="${FOAM_SITE_LIBBIN%/*}" ;;
# Prefix: openfoam (other)
(o | openfoam) FOAM_MODULE_PREFIX="${FOAM_LIBBIN%/*}" ;;
# Prefix: directory (absolute or relative)
(*)
: "${FOAM_MODULE_PREFIX:=/usr/local}" # Fallback (autoconf-like)
# Require absolute path
[ "${FOAM_MODULE_PREFIX#/}" != "${FOAM_MODULE_PREFIX}" ] || \
FOAM_MODULE_PREFIX="${PWD}/${FOAM_MODULE_PREFIX}"
;;
esac
# Avoid potential conflicts
unset FOAM_MODULE_APPBIN FOAM_MODULE_LIBBIN
echo "Module prefix = ${FOAM_MODULE_PREFIX:-[]}" 1>&2
}
#------------------------------------------------------------------------------
# Return the absolute (physical) path for a directory or # Return the absolute (physical) path for a directory or
# for a file's parent directory # for a file's parent directory
# expandPath dirName # expandPath dirName

View File

@ -179,7 +179,15 @@ die()
make="make" make="make"
# Print compiler/system information (serial only) # Print compiler/system information (serial only)
printInfo() { make --no-print-directory -f "$WM_DIR"/makefiles/info "$@"; } printInfo() {
if [ -f "$WM_DIR"/makefiles/info ]
then
make --no-print-directory -f "$WM_DIR"/makefiles/info "$@"
else
echo "OpenFOAM environment not set?" 1>&2
return 1
fi
}
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -245,36 +253,7 @@ do
;; ;;
-module-prefix=*) -module-prefix=*)
optPrefix="${1#*=}" setModulePrefix "${1#*=}"
case "$optPrefix" in
# Prefix: user
(u | user)
export FOAM_MODULE_PREFIX="${FOAM_USER_LIBBIN%/*}"
;;
# Prefix: group
(g | group)
export FOAM_MODULE_PREFIX="${FOAM_SITE_LIBBIN%/*}"
;;
# Prefix: openfoam (other)
(o | openfoam)
export FOAM_MODULE_PREFIX="${FOAM_LIBBIN%/*}"
;;
# Prefix: custom (absolute or relative)
(*)
export FOAM_MODULE_PREFIX="$optPrefix"
: "${FOAM_MODULE_PREFIX:=/usr/local}" # Default (autoconf)
# Require absolute path
[ "${FOAM_MODULE_PREFIX#/}" != "${FOAM_MODULE_PREFIX}" ] || \
FOAM_MODULE_PREFIX="${PWD}/${FOAM_MODULE_PREFIX}"
;;
esac
unset FOAM_MODULE_APPBIN FOAM_MODULE_LIBBIN
echo "Module prefix = $FOAM_MODULE_PREFIX" 1>&2
;; ;;
-show-api | -show-ext-so | \ -show-api | -show-ext-so | \
@ -461,7 +440,7 @@ else
echo "$Script error: could not change to directory '$dir'" 1>&2 echo "$Script error: could not change to directory '$dir'" 1>&2
exit 1 exit 1
} }
elif [ -f "$MakeDir/files" ] elif [ -f "$MakeDir"/files ]
then then
dir="(${PWD##*/})" # Implicit directory information dir="(${PWD##*/})" # Implicit directory information
fi fi
@ -552,7 +531,7 @@ then
then then
# Compile all applications in sub-directories # Compile all applications in sub-directories
$make ${WM_CONTINUE_ON_ERROR:+-k} \ $make ${WM_CONTINUE_ON_ERROR:+-k} \
-f $WM_DIR/makefiles/apps \ -f "$WM_DIR"/makefiles/apps \
TARGET="$targetType" FOAM_APPS="$FOAM_APPS" TARGET="$targetType" FOAM_APPS="$FOAM_APPS"
exitCode=$? exitCode=$?
fi fi
@ -600,11 +579,11 @@ cdSource
# so that the call to make builds the application # so that the call to make builds the application
if [ -z "$targetType" ] if [ -z "$targetType" ]
then then
if grep -qe '^ *LIB *=' "$MakeDir/files" 2>/dev/null if grep -qe '^ *LIB *=' "$MakeDir"/files 2>/dev/null
then then
targetType=libso targetType=libso
fi fi
elif grep -qe '^ *EXE *=' "$MakeDir/files" 2>/dev/null elif grep -qe '^ *EXE *=' "$MakeDir"/files 2>/dev/null
then then
# Application. Remove any nonsense targetType # Application. Remove any nonsense targetType
case "$targetType" in case "$targetType" in
@ -644,11 +623,11 @@ fi
# Pre-build the $WM_OPTIONS/options file # Pre-build the $WM_OPTIONS/options file
# which is included when building the $WM_OPTIONS/files file # which is included when building the $WM_OPTIONS/files file
$make -s -f $WM_DIR/makefiles/files \ $make -s -f "$WM_DIR"/makefiles/files \
MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" "$objectsDir"/options MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" "$objectsDir"/options
$make -s -f $WM_DIR/makefiles/files \ $make -s -f "$WM_DIR"/makefiles/files \
MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir"
) )
@ -656,7 +635,7 @@ fi
# Check the $objectsDir/sourceFiles file was created successfully # Check the $objectsDir/sourceFiles file was created successfully
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
[ -r $objectsDir/sourceFiles ] || { [ -r "$objectsDir"/sourceFiles ] || {
echo "$Script error: file '$objectsDir/sourceFiles'" \ echo "$Script error: file '$objectsDir/sourceFiles'" \
"could not be created in $PWD" 1>&2 "could not be created in $PWD" 1>&2
exit 1 exit 1
@ -670,10 +649,10 @@ fi
# For libraries create lnInclude, but only if 'LIB' is declared in 'Make/files' # For libraries create lnInclude, but only if 'LIB' is declared in 'Make/files'
case "$targetType" in case "$targetType" in
(lib | libo | libso | dep) (lib | libo | libso | dep)
if grep -qe '^ *LIB *=' "$MakeDir/files" 2>/dev/null if grep -qe '^ *LIB *=' "$MakeDir"/files 2>/dev/null
then then
$make -s -f $WM_DIR/makefiles/general \ $make -s -f "$WM_DIR"/makefiles/general \
MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir lnInclude MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" lnInclude
fi fi
;; ;;
esac esac
@ -686,8 +665,8 @@ esac
if [ -n "$WM_UPDATE_DEPENDENCIES" ] if [ -n "$WM_UPDATE_DEPENDENCIES" ]
then then
$make -f $WM_DIR/makefiles/general \ $make -f "$WM_DIR"/makefiles/general \
MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir updatedep MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" updatedep
exitCode="$?" exitCode="$?"
[ "$exitCode" -eq 0 ] || exit "$exitCode" [ "$exitCode" -eq 0 ] || exit "$exitCode"
@ -698,8 +677,8 @@ fi
# Make the dependency files or object files and link # Make the dependency files or object files and link
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
exec $make -f $WM_DIR/makefiles/general \ exec $make -f "$WM_DIR"/makefiles/general \
MAKE_DIR=$MakeDir OBJECTS_DIR=$objectsDir $targetType MAKE_DIR="$MakeDir" OBJECTS_DIR="$objectsDir" $targetType
exit 0 # clean exit exit 0 # clean exit