Commit 53767fc8 authored by Andrew Heather's avatar Andrew Heather
Browse files

Merge branch 'feature-flexible-install-paths' into 'develop'

Feature flexible install paths

See merge request !366
parents 0f27a540 934d0bd7
......@@ -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
......
......@@ -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"
......
......@@ -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
......
......@@ -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
......
......@@ -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"
......
#!/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
#------------------------------------------------------------------------------
......
#!/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
......
# ----------------------------------------------------------------------------
# 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
# ---------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# 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
# ---------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# 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
# ---------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# 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
# ---------------------------------------------------------------------------
......@@ -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
......
#----------------------------------*-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
#------------------------------------------------------------------------------
#----------------------------------*-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
#------------------------------------------------------------------------------
......@@ -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 | \