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

View File

@ -48,6 +48,12 @@ checkEnv()
# 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()
{
if [ -d "$1" ]
@ -58,6 +64,19 @@ expandPath()
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()
{
expandPath $WM_PROJECT_DIR
@ -71,22 +90,32 @@ findTarget()
then
echo "$Script error: could not find Make directory" 1>&2
exit 1
elif [ -d "$1/Make" ]; then
elif [ -d "$1/Make" ]
then
dir=$1
else
findTarget "$1/.."
fi
}
# Change to 'MakeDir'
# - 'MakeDir' for its input
#
# Sets:
# - dir
#
# Side-effect variables:
# - sets exPath
# - unsets targetType
cdSource()
{
if [ ! -d $MakeDir ]
then
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 .
targetType=
if [ "$dir" ]
then
@ -97,13 +126,30 @@ cdSource()
fi
fi
[ -r $MakeDir/files ] || {
echo "$Script error: file '$MakeDir/files' does not exist in $PWD" 1>&2
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()
{
expandPath $WM_PROJECT_DIR
@ -127,7 +173,18 @@ findObjectDir()
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()
{
sourceFile=${depFile%.dep}

View File

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

View File

@ -26,46 +26,29 @@
# wcleanLnIncludeAll
#
# Usage
# wcleanLnIncludeAll [dir1] .. [dirN]
# wcleanLnIncludeAll [dir1 [..dirN]]
#
# Description
# 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 ]
then
# Add the CWD to the arguments
# Default is to search the CWD
set -- .
elif [ "$1" = "-h" -o "$1" = "-help" ]
then
echo "Usage: $Script [dir1] .. [dirN]"
echo
echo " Delete all the lnInclude directories in the tree"
echo
exec 1>&2
cat<<USAGE
Usage: ${0##*/} [dir1 [..dirN]]
* Remove all lnInclude directories found in the tree
USAGE
exit 1
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
#------------------------------------------------------------------------------
@ -81,12 +64,6 @@ do
fi
done
#------------------------------------------------------------------------------
# Cleanup local variables and functions
#------------------------------------------------------------------------------
unset Script MakeDir
exit 0 # clean exit
#------------------------------------------------------------------------------

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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