Move Hadrian executable to /hadrian.
[ghc.git] / build.sh
index f09c30c..f7d06c2 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -2,21 +2,50 @@
 
 set -euo pipefail
 
-root="$(dirname "$0")"
+# 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"
 
-mkdir -p "$root/.shake"
+    cd "$(dirname "$TARGET_FILE")"
+    TARGET_FILE="$(basename "$TARGET_FILE")"
 
-ghc                           \
-    "$root/src/Main.hs"       \
-    -Wall                     \
-    -i"$root/src"             \
-    -rtsopts                  \
-    -with-rtsopts=-I0         \
-    -outputdir="$root/.shake" \
-    -j -O                      \
-    -o "$root/.shake/build"
+    # 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
 
-"$root/.shake/build"       \
+    # 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"
+}
+
+root="$(dirname "$(rl "$0")")"
+
+mkdir -p "$root/../_build/hadrian"
+
+ghc                                      \
+    "$root/src/Main.hs"                  \
+    -Wall                                \
+    -fno-warn-name-shadowing             \
+    -XRecordWildCards                    \
+    -i"$root/src"                        \
+    -rtsopts                             \
+    -with-rtsopts=-I0                    \
+    -threaded                            \
+    -outputdir="$root/../_build/hadrian" \
+    -j -O                                \
+    -o "$root/hadrian"
+
+"$root/hadrian"            \
     --lint                 \
     --directory "$root/.." \
     --colour               \