changeset 18406:194041c3fdab

improve path resolving in mx.sh so that it can be run from outside the repo root
author Andreas Woess <andreas.woess@jku.at>
date Fri, 14 Nov 2014 13:49:12 +0100
parents 4a1b4400bb1f
children f439fdb137a3
files mxtool/mx
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mxtool/mx	Tue Nov 18 11:03:39 2014 +0100
+++ b/mxtool/mx	Fri Nov 14 13:49:12 2014 +0100
@@ -28,9 +28,13 @@
 dir=`/bin/pwd`
 
 # Resolve location of this script so that mx.py can be found in the same directory
-source="${BASH_SOURCE[0]}"
-while [ -h "$source" ] ; do source="$(readlink "$source")"; done
-dir="$( cd -P "$( dirname "$source" )" && pwd )"
+source="${BASH_SOURCE[${#BASH_SOURCE[@]} - 1]}"
+while [ -h "$source" ]; do
+  dir="$(cd -P "$(dirname "$source")" && pwd)"
+  source="$(readlink "$source")"
+  [[ $source != /* ]] && source="$dir/$source"
+done
+dir="$(cd -P "$(dirname "$source")" && pwd)"
 
 if [ ! -f "$dir/mx.py" ]; then
     echo "Cannot find mx.py in $dir"