From 10f5e8080328ce7307f4f352a563311cd482e326 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 11 Feb 2011 09:21:08 +0100
Subject: [PATCH] ENH: add -make option to touchdep, toucho

- restricts selection to Make/$WM_OPTIONS* subdirectories, which is
  useful when multiple compilers are in use
---
 bin/touchdep | 70 +++++++++++++++++++++++++++++++++++++++++++---------
 bin/toucho   | 67 ++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 113 insertions(+), 24 deletions(-)

diff --git a/bin/touchdep b/bin/touchdep
index cfc8cebc20b..48c19081ca1 100755
--- a/bin/touchdep
+++ b/bin/touchdep
@@ -3,7 +3,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
+#   \\  /    A nd           | Copyright (C) 2004-2011 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #-------------------------------------------------------------------------------
 # License
@@ -28,25 +28,71 @@
 # Description
 #     touch all .dep files
 #------------------------------------------------------------------------------
+usage() {
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
 
-# default is pwd
-if [ "$#" -eq 0 ]
-then
-    set -- .
-elif [ "$1" = "-h" -o "$1" = "-help" ]
-then
-    echo "Usage: ${0##*/} [dir1] .. [dirN]"
-    echo "    touch all .dep files"
+Usage: ${0##*/} [OPTION] [dir1] .. [dirN]
+options:
+  -make         limit selection to 'Make/\$WM_OPTIONS*' (Make/$WM_OPTIONS*)
+  -help         print the usage
+
+Find and touch all .dep files in the specified directories.
+Uses the cwd by default if no directories are specified.
+
+Current value of WM_OPTIONS=$WM_OPTIONS
+
+
+NOTE The '-make' is a future feature.
+This is currently no separation of .dep files by platforms.
+
+USAGE
     exit 1
-fi
+}
+
+
+unset restrictOpt
+
+# parse options
+while [ "$#" -gt 0 ]
+do
+    case "$1" in
+    -h | -help)
+        usage
+        ;;
+    -m | -make)
+        [ -n "$WM_OPTIONS" ] || usage "Error: -make option only valid when \$WM_OPTIONS is set"
+        restrictOpt=true
+        shift
+        ;;
+    -*)
+        usage "unknown option: '$*'"
+        ;;
+    *)
+        break
+        ;;
+    esac
+done
+
 
+# no directories specified: default is pwd
+[ "$#" -gt 0 ] || set -- .
 
 for i
 do
     if [ -d "$i" ]
     then
-        echo "touching all .dep files: $i"
-        find $i -name '*.dep' -print | xargs -t touch
+        if [ "$restrictOpt" = true ]
+        then
+            echo "touching all .dep files under Make/$WM_OPTIONS* : $i"
+            find -depth -name Make -type d -print | \
+                xargs -i find '{}' -depth -name "$WM_OPTIONS*" -type d -print | \
+                xargs -i find '{}' -name '*.dep' -type f -print | \
+                xargs -t touch
+        else
+            echo "touching all .dep files: $i"
+            find $i -name '*.dep' -type f -print | xargs -t touch
+        fi
     else
         echo "no directory: $i"
     fi
diff --git a/bin/toucho b/bin/toucho
index aa14d49d2de..71093cc49cd 100755
--- a/bin/toucho
+++ b/bin/toucho
@@ -3,7 +3,7 @@
 # =========                 |
 # \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
 #  \\    /   O peration     |
-#   \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
+#   \\  /    A nd           | Copyright (C) 2004-2011 OpenCFD Ltd.
 #    \\/     M anipulation  |
 #-------------------------------------------------------------------------------
 # License
@@ -28,27 +28,70 @@
 # Description
 #     touch all .o files
 #------------------------------------------------------------------------------
+usage() {
+    while [ "$#" -ge 1 ]; do echo "$1"; shift; done
+    cat<<USAGE
 
-# default is pwd
-if [ "$#" -eq 0 ]
-then
-    set -- .
-elif [ "$1" = "-h" -o "$1" = "-help" ]
-then
-    echo "Usage: ${0##*/} [dir1] .. [dirN]"
-    echo "    touch all .o files"
+Usage: ${0##*/} [OPTION] [dir1] .. [dirN]
+options:
+  -make         limit selection to 'Make/\$WM_OPTIONS*'
+  -help         print the usage
+
+Find and touch all .o files in the specified directories.
+Uses the cwd by default if no directories are specified.
+
+Current value of WM_OPTIONS=$WM_OPTIONS
+
+USAGE
     exit 1
-fi
+}
+
+
+unset restrictOpt
+
+# parse options
+while [ "$#" -gt 0 ]
+do
+    case "$1" in
+    -h | -help)
+        usage
+        ;;
+    -m | -make)
+        [ -n "$WM_OPTIONS" ] || usage "Error: -make option only valid when \$WM_OPTIONS is set"
+        restrictOpt=true
+        shift
+        ;;
+    -*)
+        usage "unknown option: '$*'"
+        ;;
+    *)
+        break
+        ;;
+    esac
+done
 
 
+# no directories specified: default is pwd
+[ "$#" -gt 0 ] || set -- .
+
 for i
 do
     if [ -d "$i" ]
     then
-        echo "touching all .o files: $i"
-        find $i -name '*.o' -print | xargs -t touch
+        if [ "$restrictOpt" = true ]
+        then
+            echo "touching all .o files under Make/$WM_OPTIONS* : $i"
+            find -depth -name Make -type d -print | \
+                xargs -i find '{}' -depth -name "$WM_OPTIONS*" -type d -print | \
+                xargs -i find '{}' -name '*.o' -type f -print | \
+                xargs -t touch
+        else
+            echo "touching all .o files: $i"
+            find $i -name '*.o' -type f -print | xargs -t touch
+        fi
     else
         echo "no directory: $i"
     fi
 done
+
 #------------------------------------------------------------------------------
-- 
GitLab