Fix warnings (#547)
[hadrian.git] / build.sh
1 #!/usr/bin/env bash
2
3 set -euo pipefail
4
5 # readlink on os x, doesn't support -f, to prevent the
6 # need of installing coreutils (e.g. through brew, just
7 # for readlink, we use the follownig substitute.
8 #
9 # source: http://stackoverflow.com/a/1116890
10 function rl {
11 TARGET_FILE="$1"
12
13 cd "$(dirname "$TARGET_FILE")"
14 TARGET_FILE="$(basename "$TARGET_FILE")"
15
16 # Iterate down a (possible) chain of symlinks
17 while [ -L "$TARGET_FILE" ]
18 do
19 TARGET_FILE="$(readlink "$TARGET_FILE")"
20 cd "$(dirname "$TARGET_FILE")"
21 TARGET_FILE="$(basename "$TARGET_FILE")"
22 done
23
24 # Compute the canonicalized name by finding the physical path
25 # for the directory we're in and appending the target file.
26 PHYS_DIR="$(pwd -P)"
27 RESULT="$PHYS_DIR/$TARGET_FILE"
28 echo "$RESULT"
29 }
30
31 root="$(dirname "$(rl "$0")")"
32
33 # By default on Linux/MacOS we build Hadrian using Cabal
34 (. "$root/build.cabal.sh" "$@")