ENH: support FOAM_MODULE_PREFIX to guide location of module builds (#1721)

- When compiling additional modules or user code, we need more control
  for the installation locations beyond the usual FOAM_USER_LIBBIN,
  FOAM_SITE_LIBBIN, FOAM_LIBBIN, and wish to have these values be
  modifiable without editing files.

- provide wmake rules for handling standard defaults:
    * GENERAL_RULES/module-path-user
    * GENERAL_RULES/module-path-group
    * GENERAL_RULES/module-path-project
  which are incorporated as follows:

  Make/options:
      include $(GENERAL_RULES)/module-path-user

  Make/files:
      LIB = $(FOAM_MODULE_LIBBIN)/libMyLibrary

  By default these would compile into FOAM_USER_{APPBIN,LIBBIN} but
  could be adjusted at compilation time. For example,

```
wmake -module-prefix=/path/my-install-location
```
Or
```
./Allwmake -module-prefix=/path/my-install-location
./Allwmake -prefix=/path/my-install-location
```
Or
```
FOAM_MODULE_PREFIX=/path/my-install-location ./Allwmake
```

ENH: add -no-recursion option for AllwmakeParseArguments

- more descriptive naming than the -fromWmake option (still supported)

- remove wmake/scripts/wmake.{cmake,wmake}-args since the -prefix
  handling and -no-recursion is now directly handled by AllwmakeParseArguments
This commit is contained in:
Mark Olesen 2020-06-08 13:51:26 +02:00
parent 0f27a540be
commit 934d0bd743
15 changed files with 241 additions and 227 deletions

View File

@ -73,7 +73,12 @@ echo
applications/Allwmake $targetType $*
# Additional components/modules
if [ -d "$WM_PROJECT_DIR/modules" ]
if [ "$FOAM_MODULE_PREFIX" = false ]
then
echo "========================================"
echo "OpenFOAM modules disabled (prefix=false)"
echo
elif [ -d "$WM_PROJECT_DIR/modules" ]
then
echo "========================================"
echo "Compile OpenFOAM modules"
@ -83,6 +88,10 @@ then
set +e
export WM_CONTINUE_ON_ERROR=true
# Default build into OpenFOAM project locations
: "${FOAM_MODULE_PREFIX:=${FOAM_LIBBIN%/*}}"
export FOAM_MODULE_PREFIX
(cd "$WM_PROJECT_DIR/modules" 2>/dev/null && wmake -all)
fi

View File

@ -153,7 +153,8 @@ unset FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS
# Capture values of old directories to be cleaned from PATH, LD_LIBRARY_PATH
foamOldDirs="$WM_PROJECT_DIR $WM_THIRD_PARTY_DIR \
$HOME/$WM_PROJECT/$USER $FOAM_USER_APPBIN $FOAM_USER_LIBBIN \
$WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN"
$WM_PROJECT_SITE $FOAM_SITE_APPBIN $FOAM_SITE_LIBBIN \
$FOAM_MODULE_APPBIN $FOAM_MODULE_LIBBIN"
# [WM_PROJECT_DIR] - Location of this OpenFOAM version
export WM_PROJECT_DIR="$projectDir"

View File

@ -89,6 +89,9 @@ unsetenv FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS
unsetenv FOAM_EXT_LIBBIN
unsetenv FOAM_JOB_DIR
unsetenv FOAM_LIBBIN
unsetenv FOAM_MODULE_APPBIN
unsetenv FOAM_MODULE_LIBBIN
unsetenv FOAM_MODULE_PREFIX
unsetenv FOAM_MPI
unsetenv FOAM_RUN
unsetenv FOAM_SETTINGS

View File

@ -76,6 +76,9 @@ unset FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS
unset FOAM_EXT_LIBBIN
unset FOAM_JOB_DIR
unset FOAM_LIBBIN
unset FOAM_MODULE_APPBIN
unset FOAM_MODULE_LIBBIN
unset FOAM_MODULE_PREFIX
unset FOAM_MPI
unset FOAM_RUN
unset FOAM_SETTINGS

View File

@ -169,6 +169,12 @@ endif
if ( $?FOAM_SITE_LIBBIN ) then
set foamOldDirs="$foamOldDirs $FOAM_SITE_LIBBIN"
endif
if ( $?FOAM_MODULE_APPBIN ) then
set foamOldDirs="$foamOldDirs $FOAM_MODULE_APPBIN"
endif
if ( $?FOAM_MODULE_LIBBIN ) then
set foamOldDirs="$foamOldDirs $FOAM_MODULE_LIBBIN"
endif
# [WM_PROJECT_DIR] - Location of this OpenFOAM version
setenv WM_PROJECT_DIR "$projectDir"

View File

@ -1,7 +1,6 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
# No AllwmakeParseArguments [infinite loop via Allwmake]
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmake.wmake-args
. ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments -no-recursion
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
#------------------------------------------------------------------------------

View File

@ -1,7 +1,6 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
# No AllwmakeParseArguments [infinite loop via Allwmake]
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmake.wmake-args
. ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments -no-recursion
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
. ${WM_PROJECT_DIR:?}/wmake/scripts/have_scotch

View File

@ -0,0 +1,21 @@
# ----------------------------------------------------------------------------
# Set defaults for FOAM_MODULE_APPBIN, FOAM_MODULE_LIBBIN
# based on group locations
#
# FOAM_MODULE_APPBIN ?= FOAM_SITE_APPBIN
# FOAM_MODULE_LIBBIN ?= FOAM_SITE_LIBBIN
#
# See: GENERAL_RULES/module-path-prefix
# ----------------------------------------------------------------------------
include $(GENERAL_RULES)/module-path-prefix
ifeq (,$(strip $(FOAM_MODULE_APPBIN)))
FOAM_MODULE_APPBIN = $(FOAM_SITE_APPBIN)
endif
ifeq (,$(strip $(FOAM_MODULE_LIBBIN)))
FOAM_MODULE_LIBBIN = $(FOAM_SITE_LIBBIN)
endif
# ---------------------------------------------------------------------------

View File

@ -0,0 +1,50 @@
# ----------------------------------------------------------------------------
# Set defaults for FOAM_MODULE_APPBIN, FOAM_MODULE_LIBBIN
# based on FOAM_MODULE_PREFIX
#
# FOAM_MODULE_APPBIN ?= FOAM_MODULE_PREFIX/bin
# FOAM_MODULE_LIBBIN ?= FOAM_MODULE_PREFIX/iib
#
# ----------------------------------------------------------------------------
# When compiling additional modules or user code, we need flexibility for
# the installation locations. The project directories may be read-only etc.
#
# For this purpose, introduce three additional make variables:
#
# - FOAM_MODULE_PREFIX - default is unset
# - FOAM_MODULE_APPBIN - default is $(FOAM_MODULE_PREFIX)/bin
# - FOAM_MODULE_LIBBIN - default is $(FOAM_MODULE_PREFIX)/lib
#
# The developer may have an intended default location for a particular module.
#
# For default location 'user':
# Make/options: include $(GENERAL_RULES)/module-path-user
# Make/files: LIB = $(FOAM_MODULE_LIBBIN)/libXYZ
#
# For default location 'group':
# Make/options: include $(GENERAL_RULES)/module-path-group
# Make/files: LIB = $(FOAM_MODULE_LIBBIN)/libXYZ
#
# For default location 'project' (openfoam):
# Make/options: include $(GENERAL_RULES)/module-path-project
# Make/files: LIB = $(FOAM_MODULE_LIBBIN)/libXYZ
#
#
# The module-path-{user,group,project} rules should include module-path-prefix
# first.
#
# ----------------------------------------------------------------------------
ifeq (,$(strip $(FOAM_MODULE_APPBIN)))
ifneq (,$(strip $(FOAM_MODULE_PREFIX)))
FOAM_MODULE_APPBIN = $(strip $(FOAM_MODULE_PREFIX))/bin
endif
endif
ifeq (,$(strip $(FOAM_MODULE_LIBBIN)))
ifneq (,$(strip $(FOAM_MODULE_PREFIX)))
FOAM_MODULE_LIBBIN = $(strip $(FOAM_MODULE_PREFIX))/lib
endif
endif
# ---------------------------------------------------------------------------

View File

@ -0,0 +1,21 @@
# ----------------------------------------------------------------------------
# Set defaults for FOAM_MODULE_APPBIN, FOAM_MODULE_LIBBIN
# based on project locations
#
# FOAM_MODULE_APPBIN ?= FOAM_APPBIN
# FOAM_MODULE_LIBBIN ?= FOAM_LIBBIN
#
# See: GENERAL_RULES/module-path-prefix
# ----------------------------------------------------------------------------
include $(GENERAL_RULES)/module-path-prefix
ifeq (,$(strip $(FOAM_MODULE_APPBIN)))
FOAM_MODULE_APPBIN = $(FOAM_APPBIN)
endif
ifeq (,$(strip $(FOAM_MODULE_LIBBIN)))
FOAM_MODULE_LIBBIN = $(FOAM_LIBBIN)
endif
# ---------------------------------------------------------------------------

View File

@ -0,0 +1,21 @@
# ----------------------------------------------------------------------------
# Set defaults for FOAM_MODULE_APPBIN, FOAM_MODULE_LIBBIN
# based on user locations
#
# FOAM_MODULE_APPBIN ?= FOAM_USER_APPBIN
# FOAM_MODULE_LIBBIN ?= FOAM_USER_LIBBIN
#
# See: GENERAL_RULES/module-path-prefix
# ----------------------------------------------------------------------------
include $(GENERAL_RULES)/module-path-prefix
ifeq (,$(strip $(FOAM_MODULE_APPBIN)))
FOAM_MODULE_APPBIN = $(FOAM_USER_APPBIN)
endif
ifeq (,$(strip $(FOAM_MODULE_LIBBIN)))
FOAM_MODULE_LIBBIN = $(FOAM_USER_LIBBIN)
endif
# ---------------------------------------------------------------------------

View File

@ -28,9 +28,15 @@
# Parsed options (wmake)
# -debug
# -q | -queue
# -module-prefix=...
# Exports FOAM_MODULE_PREFIX value.
# Unsets FOAM_MODULE_APPBIN, FOAM_MODULE_LIBBIN.
# Handles (user|group|openfoam) or (u|g|o) as per foamEtcFile,
# or absolute/relative paths
#
# Parsed options (special)
# -l | -log | -log=FILE
# -prefix=... same as -module-prefix=...
#
#------------------------------------------------------------------------------
# Check environment
@ -54,11 +60,15 @@ Executing ${0##*/} is equivalent to
wmake -all [OPTIONS]
With these additional options:
-l | -log | -log=name
With additional options:
-l | -log Tee output to log.\$WM_OPTIONS
-log=NAME Tee output to given filename
-prefix=... Identical to wmake -module-prefix
-no-recursion Prevent recursive call (do NOT call 'wmake -all')
-fromWmake Same as -no-recursion
See
wmake -help (or wmake -help-full)
wmake -help (or wmake -help-full)
USAGE
exit 0 # clean exit
@ -69,7 +79,7 @@ USAGE
# Parse the arguments and options
#------------------------------------------------------------------------------
unset fromWmake optDebug optLog optQueue
unset optDebug optLog optNonRecursive optPrefix optQueue
for arg in "$@"
do
@ -80,19 +90,58 @@ do
-h | -help*)
usage
;;
-fromWmake)
# If called from wmake (to avoid recursion)
fromWmake=true
-no-recurs* | -fromWmake)
# Avoid recursion (eg, if called from wmake)
optNonRecursive=true
continue # Handled argument
;;
-prefix=* | -module-prefix=*)
optPrefix="${arg#*=}"
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
continue # Handled argument
;;
-k | -keep-going | -non-stop)
# Keep going, ignoring errors
export WM_CONTINUE_ON_ERROR=true
continue # Permanently remove arg
;;
-l | -log)
optLog="log.${WM_OPTIONS:-build}"
continue # Permanently remove arg
;;
-log=*)
optLog="${arg##*=}"
if [ -d "$optLog" ]
@ -104,17 +153,20 @@ do
fi
continue # Permanently remove arg
;;
-debug)
optDebug="-debug"
continue # Permanently remove arg
;;
-q | -queue)
optQueue="-queue"
continue # Permanently remove arg
;;
lib | libo | libso | dep | objects)
# Target type
targetType=$arg
targetType="$arg"
;;
esac
@ -127,7 +179,7 @@ done
# Execute wmake -all if not called from wmake
#------------------------------------------------------------------------------
if [ -z "$fromWmake" ]
if [ -z "$optNonRecursive" ]
then
if [ -z "$optLog" ]
then
@ -140,7 +192,7 @@ then
# Need to cleanup after the tee
rc=$? # Error code from tee (not wmake), but not entirely important
echo "Done logging to '$optLog'" 1>&2
exit $rc
exit "$rc"
fi
fi
@ -159,7 +211,7 @@ fi
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset fromWmake optDebug optLog optQueue
unset optNonRecursive optDebug optLog optPrefix optQueue
unset -f usage

View File

@ -1,120 +0,0 @@
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# File
# wmake/scripts/wmake.cmake-args
#
# Description
# Special-purpose argument parser (eg, for Allwmake scripts)
# that handles -prefix=... and some other simpler tasks
#
# Usage
# # Parse the arguments by sourcing this script
# . ${WM_PROJECT_DIR:?}/wmake/scripts/wmake.cmake-args
#
# Options
# -prefix=...
# Exports CMAKE_INSTALL_PREFIX value.
# Handles u(ser), g(roup), o(ther) short-cuts (see foamEtcFile),
# absolute or relative paths
#
# -j | -jN | -j N
# Compile using all or specified N cores/hyperthreads
#
#------------------------------------------------------------------------------
# NB: nArgs to track the current processing position to avoid wraparound
# when checking for optional parameters (eg, the -j processing)
nArgs="$#"
for arg in "$@"
do
shift; nArgs="$((nArgs - 1))" # Drop argument
case "$arg" in
# Install prefix: user
-prefix=u | -prefix=user)
export CMAKE_INSTALL_PREFIX="${FOAM_USER_LIBBIN%/*}"
echo "Install prefix = user ($CMAKE_INSTALL_PREFIX)" 1>&2
continue # Handled argument
;;
# Install prefix: group
-prefix=g | -prefix=group)
export CMAKE_INSTALL_PREFIX="${FOAM_SITE_LIBBIN%/*}"
echo "Install prefix = group ($CMAKE_INSTALL_PREFIX)" 1>&2
continue # Handled argument
;;
# Install prefix: other/openfoam
-prefix=o | -prefix=other | -prefix=openfoam)
export CMAKE_INSTALL_PREFIX="${FOAM_LIBBIN%/*}"
echo "Install prefix = openfoam ($CMAKE_INSTALL_PREFIX)" 1>&2
continue # Handled argument
;;
# Install prefix: custom
-prefix=*)
export CMAKE_INSTALL_PREFIX="${arg#*=}"
: "${CMAKE_INSTALL_PREFIX:=/usr/local}" # Default as per autoconf
# Require as absolute path
[ "${CMAKE_INSTALL_PREFIX#/}" != "${CMAKE_INSTALL_PREFIX}" ] || \
CMAKE_INSTALL_PREFIX="${PWD}/${CMAKE_INSTALL_PREFIX}"
echo "Install prefix = $CMAKE_INSTALL_PREFIX" 1>&2
continue # Handled argument
;;
# Parallel compilation (all or specified number of cores)
-j)
export WM_NCOMPPROCS=0
if [ "$nArgs" -gt 0 ]
then
case "$1" in
[0-9]*)
if WM_NCOMPPROCS="$(expr 0 + "$1" 2>/dev/null)"
then
shift; nArgs="$((nArgs - 1))" # Drop argument
fi
;;
esac
fi
if [ "${WM_NCOMPPROCS:=0}" -le 0 ]
then
WM_NCOMPPROCS=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || \
WM_NCOMPPROCS=1
fi
echo "Compiling enabled on $WM_NCOMPPROCS cores" 1>&2
continue # Handled argument
;;
# Parallel compilation (specified number of cores)
-j[0-9]*)
export WM_NCOMPPROCS="${arg#-j}"
if [ "${WM_NCOMPPROCS:=0}" -le 0 ]
then
WM_NCOMPPROCS=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || \
WM_NCOMPPROCS=1
fi
echo "Compiling enabled on $WM_NCOMPPROCS cores" 1>&2
continue # Handled argument
;;
esac
set -- "$@" "$arg" # Reinsert unhandled argument
done
#------------------------------------------------------------------------------

View File

@ -1,90 +0,0 @@
#----------------------------------*-sh-*--------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# File
# wmake/scripts/wmake.wmake-args
#
# Description
# Reduced argument parser (eg, for scripts using wmake)
# that handles some common parameters
#
# Usage
# # Parse the arguments by sourcing this script
# . ${WM_PROJECT_DIR:?}/wmake/scripts/wmake.wmake-args
#
# Options
# -s | -silent | -quiet
# Exports WM_QUIET=true
#
# -j | -jN | -j N
# Compile using all or specified N cores/hyperthreads
#
#------------------------------------------------------------------------------
# NB: nArgs to track the current processing position to avoid wraparound
# when checking for optional parameters (eg, the -j processing)
nArgs="$#"
for arg in "$@"
do
shift; nArgs="$((nArgs - 1))" # Drop argument
case "$arg" in
# Silent operation
-s | -silent | -quiet)
export WM_QUIET=true
continue # Handled argument
;;
# Parallel compilation (all or specified number of cores)
-j)
export WM_NCOMPPROCS=0
if [ "$nArgs" -gt 0 ]
then
case "$1" in
[0-9]*)
if WM_NCOMPPROCS="$(expr 0 + "$1" 2>/dev/null)"
then
shift; nArgs="$((nArgs - 1))" # Drop argument
fi
;;
esac
fi
if [ "${WM_NCOMPPROCS:=0}" -le 0 ]
then
WM_NCOMPPROCS=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || \
WM_NCOMPPROCS=1
fi
echo "Compiling enabled on $WM_NCOMPPROCS cores" 1>&2
continue # Handled argument
;;
# Parallel compilation (specified number of cores)
-j[0-9]*)
export WM_NCOMPPROCS="${arg#-j}"
if [ "${WM_NCOMPPROCS:=0}" -le 0 ]
then
WM_NCOMPPROCS=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || \
WM_NCOMPPROCS=1
fi
echo "Compiling enabled on $WM_NCOMPPROCS cores" 1>&2
continue # Handled argument
;;
esac
set -- "$@" "$arg" # Reinsert unhandled argument
done
#------------------------------------------------------------------------------

View File

@ -51,6 +51,7 @@
#
# Environment
# FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS
# FOAM_MODULE_PREFIX
#
# See also
# wmakeLnInclude, wmakeLnIncludeAll, wmakeCollect, wdep, wrmdep, wrmo,
@ -81,6 +82,9 @@ if [ -n "$1" ]
then
cat<<HELP_FULL
-debug Define c++DBUG='-DFULLDEBUG -g -O0' as override
-module-prefix=PATH Specify FOAM_MODULE_PREFIX as absolute/relative path
-module-prefix=TYPE Specify FOAM_MODULE_PREFIX as predefined type
(u,user | g,group | o,openfoam)
-no-scheduler Disable scheduled parallel compilation
-show-api Print api value (from Make rules)
-show-ext-so Print shared library extension (with '.' separator)
@ -140,6 +144,7 @@ Special targets:
Environment
FOAM_EXTRA_CFLAGS FOAM_EXTRA_CXXFLAGS FOAM_EXTRA_LDFLAGS
FOAM_MODULE_PREFIX
HELP_TAIL_FULL
else
@ -226,6 +231,40 @@ do
-debug)
optDebug="-DFULLDEBUG -g -O0"
;;
-module-prefix=*)
optPrefix="${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-compile-c | -show-c | -show-cflags | -show-cflags-arch | \
-show-compile-cxx | -show-cxx | -show-cxxflags | -show-cxxflags-arch )