.bat file tidy up plus shake-0.16 compatibility (#392)
[ghc.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 if type cabal > /dev/null 2>&1; then
34 CABVERSTR=$(cabal --numeric-version)
35 CABVER=( ${CABVERSTR//./ } )
36 if [ "${CABVER[0]}" -eq 1 -a "${CABVER[1]}" -ge 24 ]; then
37 echo "** Cabal 1.24 or later detected. Please consider using the 'build.cabal.sh' script **"
38 echo ""
39 fi
40 fi
41
42 mkdir -p "$root/bin"
43
44 ghc \
45 "$root/src/Main.hs" \
46 -Wall \
47 -fno-warn-name-shadowing \
48 -XRecordWildCards \
49 -i"$root/src" \
50 -i"$root/../libraries/Cabal/Cabal" \
51 -rtsopts \
52 -with-rtsopts=-I0 \
53 -threaded \
54 -outputdir="$root/bin" \
55 -j -O \
56 -o "$root/bin/hadrian"
57
58 "$root/bin/hadrian" \
59 --lint \
60 --directory "$root/.." \
61 "$@"