build-cabal 1.33 KB
Newer Older
1 2 3
#!/usr/bin/env bash

CABAL=cabal
4
CABFLAGS="--disable-documentation --disable-profiling --disable-library-profiling $CABFLAGS"
5

Andrey Mokhov's avatar
Andrey Mokhov committed
6 7
# It is currently more robust to pass Cabal an absolute path to the project file.
PROJ="$PWD/hadrian/cabal.project"
8

Andrey Mokhov's avatar
Andrey Mokhov committed
9
set -euo pipefail
10

Andrey Mokhov's avatar
Andrey Mokhov committed
11 12 13 14
if ! [ -f "$PROJ" ]; then
    echo "Current working directory must be GHC's top-level folder"
    exit 2
fi
15 16 17 18 19 20 21 22 23

if ! type "$CABAL" > /dev/null; then
    echo "Please make sure 'cabal' is in your PATH"
    exit 2
fi

CABVERSTR=$("$CABAL" --numeric-version)
CABVER=( ${CABVERSTR//./ } )

24
build_failed() {
25
    ( ghc --info | grep -s '("Support SMP","YES")' > /dev/null ) \
26 27 28 29 30 31 32 33 34 35 36
      || cat <<EOF
Your compiler does not support the threaded runtime system.
Please disable the \`threaded\` Cabal flag in project.cabal.local
by running:

    echo -e "package hadrian\n  flags: -threaded" >> project.cabal.local

EOF
    exit 1
}

Andrey Mokhov's avatar
Andrey Mokhov committed
37 38 39
if [ "${CABVER[0]}" -gt 2 -o "${CABVER[0]}" -eq 2 -a "${CABVER[1]}" -ge 2 ];
then
    "$CABAL" --project-file="$PROJ" new-build $CABFLAGS -j exe:hadrian
40 41
    # use new-exec instead of new-run to make sure that the build-tools (alex & happy) are in PATH
    "$CABAL" --project-file="$PROJ" new-exec  $CABFLAGS    hadrian -- \
Andrey Mokhov's avatar
Andrey Mokhov committed
42
        --directory "$PWD" \
43 44
        "$@" \
        || build_failed
45
else
Andrey Mokhov's avatar
Andrey Mokhov committed
46 47
    echo "Cabal version is too old; you need at least cabal-install 2.2"
    exit 2
48
fi