From bdbdd25bac8e7c68a7b01273eb207c854ef803fa Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@Germany>
Date: Fri, 7 Aug 2009 20:24:11 +0200
Subject: [PATCH] Allwmake and {applications,src}/Allwmake use
 wmake/wmakeCheckPwd

- solves problems that can occur when checking $PWD and links are involved
---
 Allwmake                                |  5 ++---
 applications/Allwmake                   |  5 ++---
 src/Allwmake                            |  5 ++---
 bin/foamCheckPwd => wmake/wmakeCheckPwd | 15 ++++++++++-----
 4 files changed, 16 insertions(+), 14 deletions(-)
 rename bin/foamCheckPwd => wmake/wmakeCheckPwd (88%)

diff --git a/Allwmake b/Allwmake
index 2e570c89a53..36d7658f196 100755
--- a/Allwmake
+++ b/Allwmake
@@ -1,13 +1,12 @@
 #!/bin/sh
 cd ${0%/*} || exit 1    # run from this directory
 
-if [ "$PWD" != "$WM_PROJECT_DIR" ]
-then
+wmakeCheckPwd "$WM_PROJECT_DIR" || {
     echo "Error: Current directory is not \$WM_PROJECT_DIR"
     echo "    The environment variables are inconsistent with the installation."
     echo "    Check the OpenFOAM entries in your dot-files and source them."
     exit 1
-fi
+}
 
 # wmake is required for subsequent targets
 ( cd wmake/src && make )
diff --git a/applications/Allwmake b/applications/Allwmake
index ddb5b116fc0..48e66941d30 100755
--- a/applications/Allwmake
+++ b/applications/Allwmake
@@ -1,13 +1,12 @@
 #!/bin/sh
 cd ${0%/*} || exit 1    # run from this directory
 
-if [ "$PWD" != "$WM_PROJECT_DIR/applications" ]
-then
+wmakeCheckPwd "$WM_PROJECT_DIR/applications" || {
     echo "Error: Current directory is not \$WM_PROJECT_DIR/applications"
     echo "    The environment variables are inconsistent with the installation."
     echo "    Check the OpenFOAM entries in your dot-files and source them."
     exit 1
-fi
+}
 
 set -x
 
diff --git a/src/Allwmake b/src/Allwmake
index 1fcbb76d333..ebef2d8d0d1 100755
--- a/src/Allwmake
+++ b/src/Allwmake
@@ -1,13 +1,12 @@
 #!/bin/sh
 cd ${0%/*} || exit 1    # run from this directory
 
-if [ "$PWD" != "$WM_PROJECT_DIR/src" ]
-then
+wmakeCheckPwd "$WM_PROJECT_DIR/src" || {
     echo "Error: Current directory is not \$WM_PROJECT_DIR/src"
     echo "    The environment variables are inconsistent with the installation."
     echo "    Check the OpenFOAM entries in your dot-files and source them."
     exit 1
-fi
+}
 
 set -x
 
diff --git a/bin/foamCheckPwd b/wmake/wmakeCheckPwd
similarity index 88%
rename from bin/foamCheckPwd
rename to wmake/wmakeCheckPwd
index 1da6f1a84da..48266543faa 100755
--- a/bin/foamCheckPwd
+++ b/wmake/wmakeCheckPwd
@@ -24,7 +24,7 @@
 #     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 #
 # Script
-#     foamCheckPwd
+#     wmakeCheckPwd
 #
 # Description
 #     Check that the current working directory is equal to a particular
@@ -80,19 +80,24 @@ done
 dirName="$1"
 
 
-# trival checks first
+# trivial checks first
 [ "$PWD" = "$dirName" ] && exit 0
-[ -d "$dirName" ] || exit 1
+
+[ -d "$dirName" ] || {
+    [ "$quietOpt" = true ] || echo "Error: Directory does not exist $dirName"
+    exit 1
+}
 
 
 # use /bin/pwd to get the absolute path (could be linked)
 thisDir=$(/bin/pwd)
-dirName=$(cd $dirName 2>/dev/null && /bin/pwd)
+target=$(cd $dirName 2>/dev/null && /bin/pwd)
 
 # okay
-[ "$thisDir" = "$dirName" ] && exit 0
+[ "$thisDir" = "$target" ] && exit 0
 
 # some other error
+[ "$quietOpt" = true ] || echo "Error: Current directory is not $dirName"
 exit 1
 
 #------------------------------------------------------------------------------
-- 
GitLab