From 6b819790b4afe1a4ad86bae89662d1a82796e645 Mon Sep 17 00:00:00 2001
From: Henry <Henry>
Date: Sun, 11 Jan 2015 17:16:15 +0000
Subject: [PATCH] wdep: If source file is not in the current directory search
 tree for first occurrence

---
 bin/foamPackBin                    |  2 +-
 wmake/{ => scripts}/wmakeFunctions |  0
 wmake/wdep                         | 27 ++++++++++++++++-----------
 wmake/wrmdep                       |  4 ++--
 wmake/wrmdepold                    |  4 ++--
 wmake/wrmo                         |  4 ++--
 6 files changed, 23 insertions(+), 18 deletions(-)
 rename wmake/{ => scripts}/wmakeFunctions (100%)

diff --git a/bin/foamPackBin b/bin/foamPackBin
index 23c8ecbe28b..be338c2de68 100755
--- a/bin/foamPackBin
+++ b/bin/foamPackBin
@@ -133,7 +133,7 @@ fi
 
 #------------------------------------------------------------------------------
 
-# get list of directories
+# Get list of directories
 dirList=$( $listBinDirs $packDir $archOptions )
 if [ $? -eq 0 -a -n "$dirList" ]
 then
diff --git a/wmake/wmakeFunctions b/wmake/scripts/wmakeFunctions
similarity index 100%
rename from wmake/wmakeFunctions
rename to wmake/scripts/wmakeFunctions
diff --git a/wmake/wdep b/wmake/wdep
index a6f24064446..a89f81138f1 100755
--- a/wmake/wdep
+++ b/wmake/wdep
@@ -27,17 +27,15 @@
 #     cat `wdep <file>`
 #
 # Description
-#     Find the dep-file corresponding to <file> and print the path.
-#
-#     Note: wdep MUST be run from the directory containing <file>.
-#     If it proves useful an option could be added to search the local
-#     source-tree for <file> if it is not in the current directory.
+#     Find the .dep file corresponding to <file> and print the path.
+#     If <file> is not in the current directory the tree is searched for
+#     the first occurrence.
 #
 #------------------------------------------------------------------------------
 Script=${0##*/}
 
-# Source the wdep functions
-. ${0%/*}/wmakeFunctions
+# Source the wmake functions
+. ${0%/*}/scripts/wmakeFunctions
 
 usage() {
     exec 1>&2
@@ -78,13 +76,20 @@ checkEnv
 
 
 #------------------------------------------------------------------------------
-# Check <file> is is the current directory
+# Check <file> is is the current directory,
+# otherwise search tree for first occurrance
 #------------------------------------------------------------------------------
 
+sourceFile=$1
+
 if [ ! -e $1 ]
 then
-    echo "$Script error: source file $1 is not in the current directory" 1>&2
-    exit 1
+    sourceFile=$(find . -name $sourceFile -print -quit)
+    if [ -z "$sourceFile" ]
+    then
+        echo "$Script: cannot find source file $1" 1>&2
+        exit 1
+    fi
 fi
 
 
@@ -93,7 +98,7 @@ fi
 # and echo path for the dep file corresponding to the specified source file
 #------------------------------------------------------------------------------
 
-findObjectDir $1
+findObjectDir $sourceFile
 
 fileName=${1##*/}
 
diff --git a/wmake/wrmdep b/wmake/wrmdep
index 905c6958f7c..32c14546c0e 100755
--- a/wmake/wrmdep
+++ b/wmake/wrmdep
@@ -34,8 +34,8 @@
 #------------------------------------------------------------------------------
 Script=${0##*/}
 
-# Source the wmakeFunctions
-. ${0%/*}/wmakeFunctions
+# Source the wmake functions
+. ${0%/*}/scripts/wmakeFunctions
 
 usage() {
     exec 1>&2
diff --git a/wmake/wrmdepold b/wmake/wrmdepold
index 1e16b4220dd..61cdc92bc08 100755
--- a/wmake/wrmdepold
+++ b/wmake/wrmdepold
@@ -35,8 +35,8 @@
 #------------------------------------------------------------------------------
 Script=${0##*/}
 
-# Source the wdep functions
-. ${0%/*}/wmakeFunctions
+# Source the wmake functions
+. ${0%/*}/scripts/wmakeFunctions
 
 usage() {
     exec 1>&2
diff --git a/wmake/wrmo b/wmake/wrmo
index 177587aef57..1fb5cc40881 100755
--- a/wmake/wrmo
+++ b/wmake/wrmo
@@ -34,8 +34,8 @@
 #------------------------------------------------------------------------------
 Script=${0##*/}
 
-# Source the wmakeFunctions
-. ${0%/*}/wmakeFunctions
+# Source the wmake functions
+. ${0%/*}/scripts/wmakeFunctions
 
 usage() {
     exec 1>&2
-- 
GitLab