circleci: Detect core count
[ghc.git] / .circleci / prepare-system.sh
1 #!/usr/bin/env bash
2 # vim: sw=2 et
3 set -euo pipefail
4
5 fail() {
6 echo "ERROR: $*" >&2
7 exit 1
8 }
9
10 echo 'BUILD_SPHINX_HTML = NO' > mk/validate.mk
11 echo 'BUILD_SPHINX_PDF = NO' >> mk/validate.mk
12 hackage_index_state="@1522046735"
13
14 cat > mk/build.mk <<EOF
15 V=1
16 HADDOCK_DOCS=YES
17 LATEX_DOCS=YES
18 HSCOLOUR_SRCS=YES
19 BUILD_DOCBOOK_HTML=YES
20 BeConservative=YES
21 EOF
22
23 case "$(uname)" in
24 Linux)
25 if [[ -n ${TARGET:-} ]]; then
26 if [[ $TARGET = FreeBSD ]]; then
27 # cross-compiling to FreeBSD
28 add-apt-repository -y ppa:hvr/ghc
29 apt-get update -qq
30 apt-get install -qy ghc-8.0.2 cabal-install-1.24 alex happy \
31 ncurses-dev git make automake autoconf gcc perl \
32 python3 texinfo xz-utils lbzip2 patch
33 cabal update
34 cabal install --reinstall hscolour --index-state=$hackage_index_state
35 ln -s $HOME/.cabal/bin/HsColour /usr/local/bin/HsColour
36
37 echo 'HADDOCK_DOCS = NO' >> mk/build.mk
38 echo 'WERROR=' >> mk/build.mk
39 # https://circleci.com/docs/2.0/env-vars/#interpolating-environment-variables-to-set-other-environment-variables
40 echo 'export PATH=/opt/ghc/bin:$PATH' >> $BASH_ENV
41 else
42 fail "TARGET=$target not supported"
43 fi
44 else
45 cabal update
46 cabal install --reinstall hscolour
47 sudo ln -s /home/ghc/.cabal/bin/HsColour /usr/local/bin/HsColour || true
48 fi
49 ;;
50 Darwin)
51 if [[ -n ${TARGET:-} ]]; then
52 fail "uname=$(uname) not supported for cross-compilation"
53 fi
54 # It looks like we already have python2 here and just installing python3
55 # does not work.
56 brew upgrade python
57 brew install ghc cabal-install ncurses gmp
58 cabal update
59 cabal install --reinstall alex happy haddock hscolour --index-state=$hackage_index_state
60 # put them on the $PATH, don't fail if already installed
61 ln -s $HOME/.cabal/bin/alex /usr/local/bin/alex || true
62 ln -s $HOME/.cabal/bin/happy /usr/local/bin/happy || true
63 ln -s $HOME/.cabal/bin/HsColour /usr/local/bin/HsColour || true
64 ;;
65 *)
66 fail "uname=$(uname) not supported"
67 esac