Fix readlink for os x.
authorMoritz Angermann <moritz.angermann@gmail.com>
Tue, 5 Jan 2016 12:43:29 +0000 (20:43 +0800)
committerMoritz Angermann <moritz.angermann@gmail.com>
Tue, 5 Jan 2016 12:43:29 +0000 (20:43 +0800)
This should fix #104.

build.sh

index 82cbb93..de9b9d7 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,8 +1,34 @@
 #!/usr/bin/env bash
 
+# readlink on os x, doesn't support -f, to prevent the
+# need of installing coreutils (e.g. through brew, just
+# for readlink, we use the follownig substitute.
+#
+# source: http://stackoverflow.com/a/1116890
+function rl {
+    TARGET_FILE=$1
+
+    cd "$(dirname "$TARGET_FILE")"
+    TARGET_FILE=$(basename "$TARGET_FILE")
+
+    # Iterate down a (possible) chain of symlinks
+    while [ -L "$TARGET_FILE" ]
+    do
+        TARGET_FILE=$(readlink "$TARGET_FILE")
+        cd "$(dirname "$TARGET_FILE")"
+        TARGET_FILE=$(basename "$TARGET_FILE")
+    done
+
+    # Compute the canonicalized name by finding the physical path 
+    # for the directory we're in and appending the target file.
+    PHYS_DIR=`pwd -P`
+    RESULT=$PHYS_DIR/$TARGET_FILE
+    echo $RESULT
+}
+
 set -euo pipefail
 
-root="$(dirname "$(readlink -f "$0")")"
+root="$(dirname "$(rl "$0")")"
 
 mkdir -p "$root/.shake"