Fix readlink for os x.
[ghc.git] / build.sh
1 #!/usr/bin/env bash
2
3 # readlink on os x, doesn't support -f, to prevent the
4 # need of installing coreutils (e.g. through brew, just
5 # for readlink, we use the follownig substitute.
6 #
7 # source: http://stackoverflow.com/a/1116890
8 function rl {
9 TARGET_FILE=$1
10
11 cd "$(dirname "$TARGET_FILE")"
12 TARGET_FILE=$(basename "$TARGET_FILE")
13
14 # Iterate down a (possible) chain of symlinks
15 while [ -L "$TARGET_FILE" ]
16 do
17 TARGET_FILE=$(readlink "$TARGET_FILE")
18 cd "$(dirname "$TARGET_FILE")"
19 TARGET_FILE=$(basename "$TARGET_FILE")
20 done
21
22 # Compute the canonicalized name by finding the physical path
23 # for the directory we're in and appending the target file.
24 PHYS_DIR=`pwd -P`
25 RESULT=$PHYS_DIR/$TARGET_FILE
26 echo $RESULT
27 }
28
29 set -euo pipefail
30
31 root="$(dirname "$(rl "$0")")"
32
33 mkdir -p "$root/.shake"
34
35 ghc \
36 "$root/src/Main.hs" \
37 -Wall \
38 -i"$root/src" \
39 -rtsopts \
40 -with-rtsopts=-I0 \
41 -outputdir="$root/.shake" \
42 -j -O \
43 -o "$root/.shake/build"
44
45 "$root/.shake/build" \
46 --lint \
47 --directory "$root/.." \
48 --colour \
49 "$@"