diff --git a/wmake/scripts/cmakeFunctions b/wmake/scripts/cmakeFunctions index 1b560cd6ad..d1793eec0c 100644 --- a/wmake/scripts/cmakeFunctions +++ b/wmake/scripts/cmakeFunctions @@ -81,7 +81,7 @@ cmakeVersioned() mkdir -p "$objectsDir" \ && ( cd "$objectsDir" && call_cmake "$@" "$sourceDir" && \ - make "-j${WM_NCOMPPROCS:-1}" ) \ + make ) \ && storeDependency "$sentinel" "$depend" $@ } @@ -108,7 +108,7 @@ cmakeVersionedInstall() mkdir -p "$objectsDir" \ && ( cd "$objectsDir" && call_cmake "$@" "$sourceDir" && \ - make "-j${WM_NCOMPPROCS:-1}" install ) \ + make install ) \ && storeDependency "$sentinel" "$depend" $@ } diff --git a/wmake/scripts/wcleanObjects b/wmake/scripts/wcleanObjects index b04efe7e3d..d417b78ec7 100755 --- a/wmake/scripts/wcleanObjects +++ b/wmake/scripts/wcleanObjects @@ -61,7 +61,7 @@ options: -curr | -current Use \$WM_OPTIONS ($WM_OPTIONS) -comp | -compiler Use \$WM_ARCH\$WM_COMPILER* ($WM_ARCH$WM_COMPILER) -compiler=NAME Use \$WM_ARCH* ($WM_ARCH*) - -h | -help Print the usage + -help Print the usage Deletes specified $targetDir object file directories from project top-level: Project: $WM_PROJECT_DIR diff --git a/wmake/scripts/wmake.wmake-args b/wmake/scripts/wmake.wmake-args new file mode 100644 index 0000000000..87d4495026 --- /dev/null +++ b/wmake/scripts/wmake.wmake-args @@ -0,0 +1,90 @@ +#----------------------------------*-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 + +#------------------------------------------------------------------------------ diff --git a/wmake/wclean b/wmake/wclean index 78d16533b1..53712bfadd 100755 --- a/wmake/wclean +++ b/wmake/wclean @@ -52,7 +52,7 @@ Usage: $Script [OPTION] [dir] options: -a | -all All subdirectories, uses Allwclean, Allclean if they exist -s | -silent Silent mode (ignored - for compatibility with wmake) - -h | -help Display short help and exit + -help Display short help and exit -help-full Display full help and exit subcommands (wclean subcommand -help for more information): @@ -136,7 +136,7 @@ do -a | -all | all) targetType=all ;; - -s | -silent) # Ignored - for compatibility with wmake + -s | -silent | -quiet) export WM_QUIET=true ;; -*) diff --git a/wmake/wmake b/wmake/wmake index 83425b95e7..b411cf8ab2 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -100,7 +100,7 @@ fi cat<&2 + echo + echo "Error encountered:" + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + echo + echo "See '${0##*/} -help' for usage" + echo exit 1 } @@ -61,35 +76,53 @@ USAGE # Parse arguments and options #------------------------------------------------------------------------------ -findName=lnInclude +# Parallel operation requested nCores=0 -# Default 'wmakeLnInclude' option -unset wmLnOpt +unset optForce optUpdate while [ "$#" -gt 0 ] do case "$1" in -h | -help*) - usage + printHelp + ;; + -f | -force) + optForce=true ;; -u | -update) - wmLnOpt="-update" + optUpdate=true + ;; + -s | -silent | -quiet) + export WM_QUIET=true ;; # Parallel execution on WM_NCOMPPROCS cores -j) - nCores=${WM_NCOMPPROCS:-0} - test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \ - && shift && nCores=$1 + nJobs=0 + case "$2" in + [0-9]*) + if nJobs="$(expr 0 + "$2" 2>/dev/null)" + then + shift + fi + ;; + esac - [ "$nCores" = 0 ] && nCores=1 + if [ "${nJobs:=0}" -gt 0 ] + then + nCores="$nJobs" + else + nCores="${WM_NCOMPPROCS:-1}" + [ "$nCores" -gt 0 ] || nCores=1 + fi ;; + # Parallel compilation on specified number of cores -j[1-9]*) - nCores=${1#-j} + nCores="${1#-j}" ;; -*) - usage "unknown option: '$1'" + die "unknown option: '$1'" ;; *) break @@ -98,6 +131,7 @@ do shift done + # Default search is from CWD, with special handling of the top-level # project directory: {applications,src} directories if [ "$#" -eq 0 ] @@ -112,14 +146,14 @@ fi if [ "$nCores" -gt 0 ] then - echo "$Script: starting wmakeLnInclude processes on $nCores cores" + echo "${0##*/}: starting wmakeLnInclude processes on $nCores cores" else - echo "$Script: running wmakeLnInclude" + echo "${0##*/}: running wmakeLnInclude" fi for checkDir do - if [ -d $checkDir ] + if [ -d "$checkDir" ] then echo " searching $checkDir for 'Make' directories" else @@ -127,7 +161,7 @@ do continue fi - find $checkDir -depth -name Make -type d -print | while read MakeDir + find "$checkDir" -depth -name Make -type d -print | while read MakeDir do topDir=${MakeDir%/Make} # trim /Make from the end if [ -d "$topDir" ] @@ -145,9 +179,9 @@ do wait -n joblist=($(jobs -p)) done - wmakeLnInclude $wmLnOpt $topDir & + wmakeLnInclude ${optForce:+-force} ${optUpdate:+-update} $topDir & else - wmakeLnInclude $wmLnOpt $topDir + wmakeLnInclude ${optForce:+-force} ${optUpdate:+-update} $topDir fi elif [ -d "$topDir/lnInclude" ] then @@ -160,7 +194,7 @@ done if [ "$nCores" -gt 0 ] then - # Wait for all of the wmakeLnInclude jobs to finish + # Wait for wmakeLnInclude jobs to finish wait # Synchronize the file system to ensure that all of the links exist