STYLE: make wmake scripts look more POSIX-like

- also add some comments about the side-effects
This commit is contained in:
Mark Olesen
2017-02-10 11:38:12 +01:00
committed by mark
parent 6343e1e3b3
commit 46ecad8f7a
16 changed files with 276 additions and 339 deletions

View File

@ -28,8 +28,8 @@
# Description # Description
# Updates the header of application files. # Updates the header of application files.
# By default, writes current version in the header. # By default, writes current version in the header.
# Alternatively version can be specified with -v option. # The version can alternatively be specified with the -v option.
# Also removes consecutive blank lines from file. # Also removes consecutive blank lines from the file.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
usage() { usage() {
@ -66,7 +66,7 @@ do
shift 2 shift 2
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
@ -118,7 +118,7 @@ FoamFileAttribute()
tmpFile=FoamFile.tmp$$ tmpFile=FoamFile.tmp$$
for caseFile for caseFile
do do
if grep FoamFile $caseFile >/dev/null 2>&1 if grep -q FoamFile $caseFile 2>/dev/null
then then
echo "Updating case file: $caseFile" echo "Updating case file: $caseFile"
sed -n '/FoamFile/,/}/p' $caseFile > $tmpFile sed -n '/FoamFile/,/}/p' $caseFile > $tmpFile
@ -137,7 +137,7 @@ do
[ -s $tmpFile ] && cat $tmpFile >| $caseFile [ -s $tmpFile ] && cat $tmpFile >| $caseFile
rm -f $tmpFile 2>/dev/null rm -f $tmpFile 2>/dev/null
else else
echo " Invalid case file: $caseFile" 1>&2 echo "Invalid case file: $caseFile" 1>&2
fi fi
done done

View File

@ -48,6 +48,12 @@ checkEnv()
# Search up directories tree for the Make sub-directory # Search up directories tree for the Make sub-directory
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Return the absolute path for a directory or a file's parent directory
# expandPath dirName
# expandPath fileName
#
# Sets:
# - exPath
expandPath() expandPath()
{ {
if [ -d "$1" ] if [ -d "$1" ]
@ -58,6 +64,19 @@ expandPath()
fi fi
} }
# Find the target directory
# findTarget dirName
# findTarget fileName
#
# Sets:
# - dir
#
# Side-effect variables:
# - sets exPath
# - sets wmpdir
#
# Global variables used:
# - WM_PROJECT_DIR, HOME
findTarget() findTarget()
{ {
expandPath $WM_PROJECT_DIR expandPath $WM_PROJECT_DIR
@ -65,28 +84,38 @@ findTarget()
expandPath $1 expandPath $1
if [ "$exPath" = "$wmpdir" \ if [ "$exPath" = "$wmpdir" \
-o "$exPath" = "$HOME" \ -o "$exPath" = "$HOME" \
-o "$exPath" = "/" \ -o "$exPath" = "/" \
] ]
then then
echo "$Script error: could not find Make directory" 1>&2 echo "$Script error: could not find Make directory" 1>&2
exit 1 exit 1
elif [ -d "$1/Make" ]; then elif [ -d "$1/Make" ]
then
dir=$1 dir=$1
else else
findTarget "$1/.." findTarget "$1/.."
fi fi
} }
# Change to 'MakeDir'
# - 'MakeDir' for its input
#
# Sets:
# - dir
#
# Side-effect variables:
# - sets exPath
# - unsets targetType
cdSource() cdSource()
{ {
if [ ! -d $MakeDir ] if [ ! -d $MakeDir ]
then then
echo "$Script: '$MakeDir' directory does not exist in $PWD" 1>&2 echo "$Script: '$MakeDir' directory does not exist in $PWD" 1>&2
echo " Searching up directories tree for Make directory" echo " Searching up directories tree for Make directory" 1>&2
unset targetType
findTarget . findTarget .
targetType=
if [ "$dir" ] if [ "$dir" ]
then then
@ -97,13 +126,30 @@ cdSource()
fi fi
fi fi
[ -r $MakeDir/files ] || { [ -r $MakeDir/files ] || {
echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2 echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2
exit 1 exit 1
} }
} }
# Find the object directory
# findObjectDir dirName
# findObjectDir fileName
#
# Sets:
# - dir
# - path
# - appDir
# - objectsDir
#
# Side-effect variables:
# - sets exPath
# - sets wmpdir
# - set platformPath
#
# Global variables used:
# - WM_PROJECT_DIR, WM_OPTIONS
findObjectDir() findObjectDir()
{ {
expandPath $WM_PROJECT_DIR expandPath $WM_PROJECT_DIR
@ -127,7 +173,18 @@ findObjectDir()
fi fi
} }
if [ -n "$BASH_VERSION" ]; then
# depToSource
# - uses 'depFile' for its input
#
# Sets:
# - sourceFile
#
# Global variables used:
# - WM_OPTIONS
# - WM_MPLIB
if [ -n "$BASH_VERSION" ]
then
depToSource() depToSource()
{ {
sourceFile=${depFile%.dep} sourceFile=${depFile%.dep}

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -34,7 +34,7 @@
# lnInclude directories generated for libraries. # lnInclude directories generated for libraries.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script=${0##*/} # Note: need 'Script' for some functions in wmakeFunctions
# Source the wmake functions # Source the wmake functions
. ${0%/*}/scripts/wmakeFunctions . ${0%/*}/scripts/wmakeFunctions
@ -82,7 +82,7 @@ do
shift shift
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
@ -117,7 +117,7 @@ then
# Specified alternative name for the Make sub-directory: # Specified alternative name for the Make sub-directory:
[ $# -ge 3 ] && MakeDir=$3 [ $# -ge 3 ] && MakeDir=$3
if [ "$dir" ] if [ -n "$dir" ]
then then
cd $dir 2>/dev/null || { cd $dir 2>/dev/null || {
echo "$Script error: could not change to directory '$dir'" 1>&2 echo "$Script error: could not change to directory '$dir'" 1>&2
@ -126,8 +126,7 @@ then
fi fi
# Print command # Print command
[ -z "$targetType" ] || targetSpace=" " echo "$Script $targetType${targetType:+ }${dir:-.}"
echo "$Script $targetType$targetSpace${dir:-.}"
fi fi
@ -147,7 +146,6 @@ fi
if [ "$targetType" = empty ] if [ "$targetType" = empty ]
then then
# First pass: clean up empty source code directories # First pass: clean up empty source code directories
echo "Removing empty directories..." echo "Removing empty directories..."
# Get sub-directories avoiding particular directories # Get sub-directories avoiding particular directories
@ -259,8 +257,8 @@ then
objectsDir=$MakeDir/$WM_OPTIONS objectsDir=$MakeDir/$WM_OPTIONS
if [ $(echo $PWD | grep "$WM_PROJECT_DIR") ] if [ $(echo $PWD | grep "$WM_PROJECT_DIR") ]
then then
platformPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS} buildPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}
objectsDir=$platformPath$(echo $PWD | sed s%$WM_PROJECT_DIR%% ) objectsDir=$buildPath$(echo $PWD | sed s%$WM_PROJECT_DIR%%)
fi fi
rm -rf $objectsDir 2>/dev/null rm -rf $objectsDir 2>/dev/null
fi fi
@ -270,17 +268,8 @@ fi
# Remove the lnInclude directory if present # Remove the lnInclude directory if present
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
if [ -d lnInclude ] [ -d lnInclude ] && rm -rf lnInclude 2>/dev/null
then
rm -rf lnInclude 2>/dev/null
fi
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage MakeDir
exit 0 # clean exit
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -26,46 +26,29 @@
# wcleanLnIncludeAll # wcleanLnIncludeAll
# #
# Usage # Usage
# wcleanLnIncludeAll [dir1] .. [dirN] # wcleanLnIncludeAll [dir1 [..dirN]]
# #
# Description # Description
# Delete all the lnInclude directories in the tree. # Delete all the lnInclude directories in the tree.
# #
##------------------------------------------------------------------------------
Script=${0##*/}
# Source the wmake functions
. ${0%/*}/scripts/wmakeFunctions
#------------------------------------------------------------------------------
# Parse arguments and options
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Default to the CWD
if [ "$#" -eq 0 ] if [ "$#" -eq 0 ]
then then
# Add the CWD to the arguments # Default is to search the CWD
set -- . set -- .
elif [ "$1" = "-h" -o "$1" = "-help" ] elif [ "$1" = "-h" -o "$1" = "-help" ]
then then
echo "Usage: $Script [dir1] .. [dirN]" exec 1>&2
echo cat<<USAGE
echo " Delete all the lnInclude directories in the tree" Usage: ${0##*/} [dir1 [..dirN]]
echo
* Remove all lnInclude directories found in the tree
USAGE
exit 1 exit 1
fi fi
#------------------------------------------------------------------------------
# Search up the directory tree for the Make sub-directory,
# check the existance of the 'files' file and clean there if present
#------------------------------------------------------------------------------
# Need to add an option or special logic to control cdSource
# MakeDir=Make
# cdSource
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Search for all lnInclude directories and delete them # Search for all lnInclude directories and delete them
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
@ -81,12 +64,6 @@ do
fi fi
done done
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script MakeDir
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -71,7 +71,8 @@ USAGE
} }
# Print help message # Print help message
if [ "$1" = "-h" -o "$1" = "-help" ]; then if [ "$1" = "-h" -o "$1" = "-help" ]
then
usage usage
fi fi
@ -79,15 +80,11 @@ fi
[ "$PWD" = "$WM_PROJECT_DIR" ] || \ [ "$PWD" = "$WM_PROJECT_DIR" ] || \
usage "Not in the project top-level directory " $WM_PROJECT_DIR usage "Not in the project top-level directory " $WM_PROJECT_DIR
# Get the platforms from the arguments # Get the platforms from the arguments or '-current'
platforms="$@" platforms="${@:--current}"
# If no arguments are provided select the current platform if [ "$platforms" = "-all" ]
if [ "$#" -lt 1 ]; then then
platforms="-current"
fi
if [ "$platforms" = "-all" ]; then
echo "Removing all platforms/sub-directories" echo "Removing all platforms/sub-directories"
rm -rf platforms/* rm -rf platforms/*
@ -116,12 +113,6 @@ else
done done
fi fi
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script platforms
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -74,18 +74,23 @@ do
esac esac
done done
if [ $# -eq 0 ]
then
echo "$Script: no source file specified" 1>&2
exit 1
fi
# Check environment variables # Check environment variables
checkEnv checkEnv
sourceFile=$1
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Check <file> is is the current directory, # Check <file> is in the current directory,
# otherwise search tree for first occurrance # otherwise search tree for first occurrance
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
sourceFile=$1 if [ ! -e "$sourceFile" ]
if [ ! -e $1 ]
then then
sourceFile=$(find . -name $sourceFile -print -quit) sourceFile=$(find . -name $sourceFile -print -quit)
if [ -z "$sourceFile" ] if [ -z "$sourceFile" ]
@ -95,24 +100,14 @@ then
fi fi
fi fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Search up directories tree for the Make sub-directory containing dep files # Search up directories tree for the Make sub-directory containing dep files
# and echo path for the dep file corresponding to the specified source file # and echo path for the dep file corresponding to the specified source file
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
findObjectDir $sourceFile findObjectDir $sourceFile
echo "$objectsDir/${sourceFile##*/}.dep"
fileName=${1##*/} exit 0 # clean exit
echo $objectsDir/$fileName.dep
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -53,7 +53,7 @@
# wclean, wcleanPlatform, wcleanLnIncludeAll # wclean, wcleanPlatform, wcleanLnIncludeAll
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script=${0##*/} # Note: need 'Script' for some functions in wmakeFunctions
# Source the wmake functions # Source the wmake functions
. ${0%/*}/scripts/wmakeFunctions . ${0%/*}/scripts/wmakeFunctions
@ -127,8 +127,7 @@ useAllCores()
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Default to compiling the local target only # Default to compiling the local target only
all= unset all update
update=
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -141,10 +140,10 @@ do
export WM_QUIET=1 export WM_QUIET=1
;; ;;
-a | -all | all) -a | -all | all)
all="all" all=all
;; ;;
-q | -queue | queue) -q | -queue | queue)
all="queue" all=queue
;; ;;
# Parallel compilation on all cores of local machine # Parallel compilation on all cores of local machine
-j) -j)
@ -154,13 +153,13 @@ do
echo "Compiling enabled on $WM_NCOMPPROCS cores" echo "Compiling enabled on $WM_NCOMPPROCS cores"
;; ;;
# Parallel compilation on specified number of cores # Parallel compilation on specified number of cores
-j*) -j[1-9]*)
export WM_NCOMPPROCS=${1#-j} export WM_NCOMPPROCS=${1#-j}
echo "Compiling enabled on $WM_NCOMPPROCS cores" echo "Compiling enabled on $WM_NCOMPPROCS cores"
;; ;;
# Non-stop compilation, ignoring errors # Non-stop compilation, ignoring errors
-k | -non-stop) -k | -non-stop)
export WM_CONTINUE_ON_ERROR=1 export WM_CONTINUE_ON_ERROR=true
;; ;;
# Disable scheduled parallel compilation # Disable scheduled parallel compilation
-no-scheduler) -no-scheduler)
@ -173,15 +172,15 @@ do
# - remove empty directories, along with deprecated object directories # - remove empty directories, along with deprecated object directories
# and respective binaries. # and respective binaries.
-update) -update)
update="true" update=true
[ -z "$all" ] && all="all" : ${all:=all} # implies 'all', unless previous set to 'queue' etc.
;; ;;
--) --)
shift shift
break break
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
@ -200,10 +199,10 @@ checkEnv
# When compiling anything but a standalone exe WM_PROJECT and WM_PROJECT_DIR # When compiling anything but a standalone exe WM_PROJECT and WM_PROJECT_DIR
# must be set # must be set
[ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || { [ "$1" = exe -o \( "$WM_PROJECT" -a "$WM_PROJECT_DIR" \) ] || {
echo "$Script error:" 1>&2 exec 1>&2
echo " environment variable \$WM_PROJECT or " \ echo "$Script error:"
"\$WM_PROJECT_DIR not set" 1>&2 echo " environment variable \$WM_PROJECT or \$WM_PROJECT_DIR not set"
echo " while building project library" 1>&2 echo " while building project library"
exit 1 exit 1
} }
@ -219,11 +218,11 @@ then
[ $? -eq 0 ] || unset WM_NCOMPPROCS [ $? -eq 0 ] || unset WM_NCOMPPROCS
fi fi
if [ "$WM_NCOMPPROCS" ] if [ -n "$WM_NCOMPPROCS" ]
then then
parOpt="-j $WM_NCOMPPROCS" parOpt="-j $WM_NCOMPPROCS"
if [ "$WM_NCOMPPROCS" -gt 1 -a ! "$MAKEFLAGS" ] if [ "$WM_NCOMPPROCS" -gt 1 -a -z "$MAKEFLAGS" ]
then then
lockDir=$HOME/.$WM_PROJECT/.wmake lockDir=$HOME/.$WM_PROJECT/.wmake
@ -265,7 +264,7 @@ then
# Specified alternative name for the Make sub-directory: # Specified alternative name for the Make sub-directory:
[ $# -ge 3 ] && MakeDir=$3 [ $# -ge 3 ] && MakeDir=$3
if [ "$dir" ] if [ -n "$dir" ]
then then
cd $dir 2>/dev/null || { cd $dir 2>/dev/null || {
echo "$Script error: could not change to directory '$dir'" 1>&2 echo "$Script error: could not change to directory '$dir'" 1>&2
@ -274,16 +273,15 @@ then
fi fi
# Print command # Print command
[ -z "$targetType" ] || targetSpace=" " echo "$Script $targetType${targetType:+ }${dir:-.}"
echo "$Script $targetType$targetSpace${dir:-.}"
fi fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Recurse the source tree to compile "all" targets # Recurse the source tree to update all
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
if [ -n "$update" ] if [ "$update" = true ]
then then
wrmdep -update wrmdep -update
wrmdep -old wrmdep -old
@ -297,40 +295,37 @@ fi
# Recurse the source tree to compile "all" targets # Recurse the source tree to compile "all" targets
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
if [ "$all" = "all" ] if [ "$all" = all ]
then then
if [ -e Allwmake ] if [ -e Allwmake ]
then then
./Allwmake -fromWmake $targetType ./Allwmake -fromWmake $targetType
exit $? exit $?
fi
# Find all the sub-directories containing a 'Make' directory
# (xargs is just used to flatten the list)
FOAM_APPS=$(
for d in *
do [ -d "$d" -a "$d" != Optional -a "$d" != Make ] && echo "$d"
done | xargs)
if [ -n "$FOAM_APPS" ]
then
# Compile all applications in sub-directories
$make ${WM_CONTINUE_ON_ERROR:+-k} \
-f $WM_DIR/makefiles/apps \
TARGET="$targetType" FOAM_APPS="$FOAM_APPS"
makeExitCode=$?
else else
# Have to keep track of the main exit code for the call to "make" makeExitCode=0 # For fall-through
makeExitCode=0 fi
# Find all the sub-directories containing a 'Make' directory # Exit if current directory does not contains a 'Make' directory or
FOAM_APPS=$(\ # an error was previously encountered
for d in *; \ if [ ! -d "$MakeDir" -o $makeExitCode -ne 0 ]
do [ -d "$d" -a "$d" != Optional -a "$d" != Make ] \ then
&& echo "$d"; \ exit $makeExitCode
done | xargs \
)
if [ ! "$FOAM_APPS" = "" ]
then
# Compile all applications in sub-directories
$make ${WM_CONTINUE_ON_ERROR:+-k} \
-f $WM_DIR/makefiles/apps \
TARGET="$targetType" FOAM_APPS="$FOAM_APPS"
makeExitCode=$?
fi
# If the current directory contains a 'Make' directory continue
# otherwise exit, or always exit in case of error
if [ ! -d $MakeDir -o $makeExitCode -ne 0 ]
then
exit $makeExitCode
fi
# Clean up tracking variable
unset makeExitCode
fi fi
fi fi
@ -339,9 +334,9 @@ fi
# Recurse the source tree to compile "all" targets using wmakeQueue # Recurse the source tree to compile "all" targets using wmakeQueue
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
if [ "$all" = "queue" ] if [ "$all" = queue ]
then then
[ -n "$update" ] || wmakeLnIncludeAll $parOpt [ "$update" = true ] || wmakeLnIncludeAll $parOpt
( (
export WM_COLLECT_DIR=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}/${PWD////_} export WM_COLLECT_DIR=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}/${PWD////_}
@ -369,20 +364,18 @@ cdSource
# Transform no option to "libso" if that looks appropriate or remove it # Transform no option to "libso" if that looks appropriate or remove it
# so that the call to make builds the application # so that the call to make builds the application
if [ "$targetType" = "" ] if [ -z "$targetType" ]
then then
unset targetType if grep -qe '^ *LIB *=' "$MakeDir/files" 2>/dev/null
if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1
then then
targetType=libso targetType=libso
fi fi
elif grep -e '^ *EXE *=' "$MakeDir/files" >/dev/null 2>&1 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
lib*) lib*)
unset targetType unset targetType
break
;; ;;
esac esac
fi fi
@ -396,8 +389,8 @@ fi
objectsDir=$MakeDir/$WM_OPTIONS objectsDir=$MakeDir/$WM_OPTIONS
if [ $(echo $PWD | grep "$WM_PROJECT_DIR") ] if [ $(echo $PWD | grep "$WM_PROJECT_DIR") ]
then then
platformPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS} buildPath=$WM_PROJECT_DIR/platforms/${WM_OPTIONS}
objectsDir=$platformPath$(echo $PWD | sed s%$WM_PROJECT_DIR%% ) objectsDir=$buildPath$(echo $PWD | sed s%$WM_PROJECT_DIR%%)
fi fi
( (
@ -429,16 +422,15 @@ fi
# Make the dependency files # Make the dependency files
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# For libraries create lnInclude ... # 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)
# ... but only if 'LIB' is declared in 'Make/files' if grep -qe '^ *LIB *=' "$MakeDir/files" 2>/dev/null
if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1 then
then $make -s -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \
$make -s -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \ OBJECTS_DIR=$objectsDir lnInclude
OBJECTS_DIR=$objectsDir lnInclude fi
fi ;;
;;
esac esac
@ -453,12 +445,7 @@ then
OBJECTS_DIR=$objectsDir updatedep OBJECTS_DIR=$objectsDir updatedep
makeExitCode=$? makeExitCode=$?
if [ $makeExitCode -ne 0 ] [ $makeExitCode -eq 0 ] || exit $makeExitCode
then
exit $makeExitCode
fi
unset makeExitCode
fi fi
@ -469,12 +456,6 @@ fi
exec $make -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \ exec $make -f $WM_DIR/makefiles/general MAKE_DIR=$MakeDir \
OBJECTS_DIR=$objectsDir $targetType OBJECTS_DIR=$objectsDir $targetType
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage useAllCores update expandPath findTarget
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -89,7 +89,7 @@ dirName="$1"
# Simple check against $PWD # Simple check against $PWD
[ "$PWD" = "$dirName" ] && exit 0 [ "$PWD" = "$dirName" ] && exit 0
# Check existance of <dir> # Check existence of <dir>
[ -d "$dirName" ] || { [ -d "$dirName" ] || {
[ "$quietOpt" = true ] || { [ "$quietOpt" = true ] || {
echo "$Script error: Directory does not exist $dirName" echo "$Script error: Directory does not exist $dirName"
@ -108,14 +108,7 @@ target=$(cd $dirName 2>/dev/null && /bin/pwd)
[ "$quietOpt" = true ] || { [ "$quietOpt" = true ] || {
echo "$Script error: Current directory is not $dirName" echo "$Script error: Current directory is not $dirName"
} }
exit 1 exit 1
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -68,8 +68,8 @@ USAGE
exit 1 exit 1
} }
# Set true to clean-up file if interupted # Set true to clean-up file if interrupted
cleanup= unset cleanup
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -78,7 +78,7 @@ do
usage usage
;; ;;
-kill | -clean) -kill | -clean)
cleanup="true" cleanup=true
shift shift
;; ;;
-*) -*)
@ -110,7 +110,7 @@ makefile="$WM_COLLECT_DIR.Makefile"
# Clean-up files and exit # Clean-up files and exit
if [ -n "$cleanup" ] if [ "$cleanup" = true ]
then then
rm -rf $WM_COLLECT_DIR rm -rf $WM_COLLECT_DIR
rm -f $makefile rm -f $makefile
@ -142,31 +142,23 @@ then
echo -e "\t$E cd $PWD && \\" >> $file echo -e "\t$E cd $PWD && \\" >> $file
echo -e "\t${@:1:($#-1)} $object" >> $file echo -e "\t${@:1:($#-1)} $object" >> $file
echo >> $file echo >> $file
else elif [ -d $WM_COLLECT_DIR ]
if [ -d $WM_COLLECT_DIR ] then
then # Collect all the makefiles into a single makefiles for this build
# Collect all the makefiles into a single makefiles for this build (cd $WM_COLLECT_DIR && ls -1rt | xargs cat > $makefile)
(cd $WM_COLLECT_DIR && ls -1rt | xargs cat > $makefile)
# Add a build rule for all of the targets # Add a build rule for all of the targets
echo 'all: $(OBJECTS)' >> $makefile echo 'all: $(OBJECTS)' >> $makefile
# Clear out all of the target makefiles # Clear out all of the target makefiles
rm -rf $WM_COLLECT_DIR rm -rf $WM_COLLECT_DIR
# Run make on the collected makefile # Run make on the collected makefile
make -j $WM_NCOMPPROCS -f $makefile all make -j $WM_NCOMPPROCS -f $makefile all
rm -f $makefile rm -f $makefile
fi
fi fi
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -60,7 +60,7 @@ do
usage usage
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
@ -102,11 +102,6 @@ fi
} }
#------------------------------------------------------------------------------ exit 0 # clean exit
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -91,7 +91,7 @@ do
shift shift
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
@ -167,12 +167,6 @@ find .. $findOpt \
\) \ \) \
-exec ln $lnOpt {} . \; -exec ln $lnOpt {} . \;
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -62,12 +62,12 @@ findName=lnInclude
nCores=0 nCores=0
# Default 'wmakeLnInclude' option # Default 'wmakeLnInclude' option
wmLnOpt= unset wmLnOpt
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
case "$1" in case "$1" in
-h | -help) # Provide immediate help -h | -help)
usage usage
;; ;;
-u | -update) -u | -update)
@ -75,16 +75,16 @@ do
;; ;;
# Parallel execution on WM_NCOMPPROCS cores # Parallel execution on WM_NCOMPPROCS cores
-j) -j)
nCores=$WM_NCOMPPROCS nCores=${WM_NCOMPPROCS:-0}
test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \ test $# -ge 2 && expr $2 + 1 > /dev/null 2>&1 \
&& shift && nCores=$1 && shift && nCores=$1
;; ;;
# Parallel compilation on specified number of cores # Parallel compilation on specified number of cores
-j*) -j[1-9]*)
nCores=${1#-j} nCores=${1#-j}
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
@ -93,9 +93,6 @@ do
shift shift
done done
FAIL=0
if [ "$nCores" -gt 0 ] if [ "$nCores" -gt 0 ]
then then
echo "$Script: starting wmakeLnInclude processes on $nCores cores" echo "$Script: starting wmakeLnInclude processes on $nCores cores"
@ -122,7 +119,7 @@ do
topDir=${MakeDir%/Make} # trim /Make from the end topDir=${MakeDir%/Make} # trim /Make from the end
if [ -d "$topDir" ] if [ -d "$topDir" ]
then then
if grep -e '^ *LIB *=' "$MakeDir/files" >/dev/null 2>&1 if grep -qe '^ *LIB *=' "$MakeDir/files" 2>/dev/null
then then
# If running in parallel start wmakeLnInclude on nCores # If running in parallel start wmakeLnInclude on nCores
# and more as the cores become free # and more as the cores become free
@ -159,12 +156,6 @@ then
sleep 2 sleep 2
fi fi
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -237,12 +237,6 @@ then
setterm -foreground default setterm -foreground default
fi fi
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -252,12 +252,6 @@ do
sleep 1 sleep 1
done done
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2015-2016 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -25,21 +25,21 @@
# Script wrmdep # Script wrmdep
# #
# Usage # Usage
# wrmdep [-a | -all | all] [file] # wrmdep [-a | -all | all] [file1 [..fileN]]
# wrmdep [-o | -old] [dir1 .. dirN] # wrmdep [-o | -old] [[dir1 [..dirN]]
# wrmdep -update # wrmdep -update
# #
# Description # Description
# This is a catch-all script for pruning .dep files, depending on the # This is a catch-all script for pruning .dep files, depending on the
# provided arguments. # provided arguments.
# #
# [-a | -all | all] [file]: # [-a | -all | all] [file1 [.. fileN]]:
# Remove all .dep files from the object directory tree corresponding to the # Remove all .dep files from the object directory tree corresponding to the
# current source derectory or remove only the .dep files referring to the # current source directory or remove only the .dep files referring to the
# optionally specified [file]. With the -a/-all/all option the .dep files # optionally specified file(s). With the -a/-all/all option the .dep files
# are removed for all platforms rather than just the current platform. # are removed for all platforms rather than just the current platform.
# #
# [-o | -old] [dir1 .. dirN]: # [-o | -old] [dir1 [.. dirN]]:
# Remove *.dep files that are without a corresponding .C or .L source file. # Remove *.dep files that are without a corresponding .C or .L source file.
# This occurs when a directory has been moved. # This occurs when a directory has been moved.
# - prints the questionable directory and *.dep file # - prints the questionable directory and *.dep file
@ -48,10 +48,11 @@
# Search all the "src" and "application" directories of the project for # Search all the "src" and "application" directories of the project for
# broken symbolic links for source code files and then remove all .dep # broken symbolic links for source code files and then remove all .dep
# files that relate to files that no longer exist. # files that relate to files that no longer exist.
# Must be executed in the project top-level directory: $WM_PROJECT_DIR. # Must be executed in the project top-level directory:
# $WM_PROJECT_DIR.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script=${0##*/} # Note: need 'Script' for some functions in wmakeFunctions
# Source the wmake functions # Source the wmake functions
. ${0%/*}/scripts/wmakeFunctions . ${0%/*}/scripts/wmakeFunctions
@ -62,26 +63,27 @@ usage() {
cat<<USAGE cat<<USAGE
Usage: Usage:
$Script [-a | -all | all] [file] $Script [-a | -all | all] [file1 [..fileN]]
Remove all .dep files or remove .dep files referring to <file> Remove all .dep files or remove .dep files referring to <file>
With the -a/-all/all option the .dep files are removed for all With the -a/-all/all option the .dep files are removed for all
platform rather than just the current platform. platforms rather than just the current platform ($WM_OPTIONS).
$Script [-o | -old] [dir1 .. dirN] $Script [-o | -old] [dir1 [..dirN]]
Remove *.dep files that are without a corresponding .C or .L file. Remove *.dep files that are without a corresponding .C or .L file.
This occurs when a directory has been moved. This occurs when a directory has been moved.
- prints the questionable directory and *.dep file - prints the questionable directory and *.dep file
Note: to remove empty directories, run: wclean empty Note: to remove empty directories, run: wclean empty
$Script -update $Script -update
Search all the "src" and "application" directories of the project for Search all the "src" and "application" directories of the project for
broken symbolic links for source code files and then remove all .dep broken symbolic links for source code files and then remove all .dep
files that relate to files that no longer exist. files that relate to files that no longer exist.
Must be executed in the project top-level directory: $WM_PROJECT_DIR Must be executed in the project top-level directory:
$WM_PROJECT_DIR
USAGE USAGE
exit 1 exit 1
@ -93,10 +95,10 @@ USAGE
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Default is for removing all .dep files in the current directory # Default is for removing all .dep files in the current directory
rmdepMode="files" rmdepMode=files
# Default to processing only the current platform # Default to processing only the current platform
all= unset all
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -105,27 +107,28 @@ do
-h | -help) -h | -help)
usage usage
;; ;;
# Non-stop compilation, ignoring errors # All platforms
-a | -all | all) -a | -all | all)
all="all" all=all
shift shift
;; ;;
-o | -old) -o | -old)
rmdepMode="oldFolders" rmdepMode=oldFolders
shift shift
;; ;;
-update) -update)
rmdepMode="updateMode" rmdepMode=updateMode
shift shift
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
;; ;;
esac esac
done done
#------------------------------------------------------------------------------
# Check environment variables # Check environment variables
checkEnv checkEnv
@ -141,7 +144,7 @@ files)
findObjectDir . findObjectDir .
# With the -a/-all option replace the current platform with a wildcard # With the -a/-all option replace the current platform with a wildcard
if [ "$all" = "all" ] if [ "$all" = all ]
then then
objectsDir=$(echo $objectsDir | sed s%$WM_OPTIONS%*% ) objectsDir=$(echo $objectsDir | sed s%$WM_OPTIONS%*% )
fi fi
@ -151,19 +154,21 @@ files)
echo "removing all .dep files ..." echo "removing all .dep files ..."
find $objectsDir -name '*.dep' -print | xargs -t rm 2>/dev/null find $objectsDir -name '*.dep' -print | xargs -t rm 2>/dev/null
else else
echo "removing .dep files referring to $1 ..." echo "removing .o files corresponding to"
find $objectsDir -name '*.dep' -exec grep -q "$1" '{}' \; \ echo " $@ ..."
-exec rm '{}' \; -print for file
do
find $objectsDir -name '*.dep' -exec grep -q "$file" '{}' \; \
-exec rm '{}' \; -print
done
fi fi
;; ;;
oldFolders) oldFolders)
# Default is the current directory # Default is the current directory
[ "$#" -gt 0 ] || set -- . [ "$#" -gt 0 ] || set -- .
echo "Removing dep files that refer to sources files that no longer exist..." echo "Removing dep files that refer to source files that no longer exist..."
for checkDir for checkDir
do do
@ -182,21 +187,19 @@ oldFolders)
depToSource $depFile depToSource $depFile
# Check C++ or Flex source file exists # Check C++ or Flex source file exists
if [ ! -r "$sourceFile" ]; if [ ! -r "$sourceFile" ]
then then
echo " rm $depFile" echo " rm $depFile"
rm -f $depFile 2>/dev/null rm -f $depFile 2>/dev/null
fi fi
done done
done done
;; ;;
updateMode) updateMode)
if [ "$PWD" != "$WM_PROJECT_DIR" ] if [ "$PWD" != "$WM_PROJECT_DIR" ]
then then
echo "Cannot 'update', not in the project top-level directory" echo "Cannot 'update', not in the project top-level directory" 1>&2
exit 1 exit 1
fi fi
@ -206,30 +209,19 @@ updateMode)
for filePathAndName in $fileNameList for filePathAndName in $fileNameList
do do
fileName=$(basename $filePathAndName) fileName=$(basename $filePathAndName)
echo " 'src': $fileName" for subdir in src applications
cd src do
$Script -a $fileName echo " '$subdir': $fileName"
(cd $subdir && $Script -a $fileName)
echo " 'applications': $fileName" done
cd ../applications
$Script -a $fileName
cd ..
# Just in case, remove the symbolic link as the last step # Just in case, remove the symbolic link as the last step
unlink $filePathAndName unlink $filePathAndName
done done
;; ;;
esac esac
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage rmdepMode all
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------

View File

@ -4,7 +4,7 @@
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration | # \\ / O peration |
# \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation # \\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
# \\/ M anipulation | # \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# License # License
# This file is part of OpenFOAM. # This file is part of OpenFOAM.
@ -26,7 +26,7 @@
# wrmo # wrmo
# #
# Usage # Usage
# wrmo [-a | -all | all] [file] # wrmo [-a | -all | all] [file1 [... fileN]]
# #
# Description # Description
# Remove all .o files from the object directory tree corresponding to the # Remove all .o files from the object directory tree corresponding to the
@ -35,7 +35,7 @@
# are removed for all platforms rather than just the current platform. # are removed for all platforms rather than just the current platform.
# #
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
Script=${0##*/} Script=${0##*/} # Note: need 'Script' for some functions in wmakeFunctions
# Source the wmake functions # Source the wmake functions
. ${0%/*}/scripts/wmakeFunctions . ${0%/*}/scripts/wmakeFunctions
@ -44,7 +44,11 @@ usage() {
exec 1>&2 exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE cat<<USAGE
Usage: $Script [file] Usage: $Script [OPTION] [file1 [... fileN]]
options:
-a | -all All platforms (current: $WM_OPTIONS)
-h | -help Print the usage
Remove all .o files or remove .o file corresponding to <file> Remove all .o files or remove .o file corresponding to <file>
@ -58,7 +62,7 @@ USAGE
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------
# Default to processing only the current platform # Default to processing only the current platform
all= unset all
while [ "$#" -gt 0 ] while [ "$#" -gt 0 ]
do do
@ -66,17 +70,17 @@ do
-h | -help) -h | -help)
usage usage
;; ;;
# Non-stop compilation, ignoring errors # All platforms
-a | -all | all) -a | -all | all)
all="all" all=all
shift shift
;; ;;
-*) -*)
usage "unknown option: '$*'" usage "unknown option: '$1'"
;; ;;
*) *)
break break
;; ;;
esac esac
done done
@ -91,7 +95,7 @@ checkEnv
findObjectDir . findObjectDir .
# With the -a/-all option replace the current platform with a wildcard # With the -a/-all option replace the current platform with a wildcard
if [ "$all" = "all" ] if [ "$all" = all ]
then then
objectsDir=$(echo $objectsDir | sed s%$WM_OPTIONS%*% ) objectsDir=$(echo $objectsDir | sed s%$WM_OPTIONS%*% )
fi fi
@ -101,16 +105,14 @@ then
echo "removing all .o files ..." echo "removing all .o files ..."
find $objectsDir -name '*.o' -print | xargs -t rm 2>/dev/null find $objectsDir -name '*.o' -print | xargs -t rm 2>/dev/null
else else
echo "removing .o files corresponding to $1 ..." echo "removing .o files corresponding to"
rm $objectsDir/${1%%.*}.o echo " $@ ..."
for file
do
rm $objectsDir/${file%%.*}.o
done
fi fi
exit 0 # clean exit
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script usage
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------