distributable: ~

versions:
  github: ghc/ghc/tags
  strip:
    - /^ghc-/
    - /-release$/

provides:
  - bin/ghc
  - bin/ghc-{{version.marketing}}
  - bin/ghc-{{version}}
  - bin/ghc-pkg
  - bin/ghc-pkg-{{version.marketing}}
  - bin/ghc-pkg-{{version}}
  - bin/ghci
  - bin/ghci-{{version.marketing}}
  - bin/ghci-{{version}}
  - bin/ghcup
  - bin/haddock
  - bin/haddock-{{version.marketing}}
  - bin/haddock-{{version}}
  - bin/hp2ps
  - bin/hp2ps-{{version.marketing}}
  - bin/hp2ps-{{version}}
  - bin/hpc
  - bin/hpc-{{version.marketing}}
  - bin/hpc-{{version}}
  - bin/hsc2hs
  - bin/hsc2hs-{{version.marketing}}
  - bin/hsc2hs-{{version}}
  - bin/runghc
  - bin/runghc-{{version.marketing}}
  - bin/runghc-{{version}}
  - bin/runhaskell
  - bin/runhaskell-{{version.marketing}}
  - bin/runhaskell-{{version}}

dependencies:
  gnu.org/gmp: 6
  invisible-island.net/ncurses: 6
  sourceware.org/libffi: 3
  linux:
    github.com/numactl/numactl: ^2
    gnu.org/gcc: '*'

warnings:
  - vendored

build:
  dependencies:
    curl.se: '*'
    linux:
      gnu.org/make: '*'
  script:
    # try to force PIC binaries
    - run: install -D $PROP {{prefix}}/.ghcup/config.yaml
      prop: |
        platform-override:
          arch: A_64
          platform:
            contents: Ubuntu
            tag: Linux
          version: '18.04'
      if: linux/x86-64

    - curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
    - PATH={{prefix}}/.ghcup/bin:$PATH
    - ghcup install ghc {{version}}
    - ghcup set ghc {{version}}
    - run: ln -s .ghcup/* .
      working-directory: ${{prefix}}
    - run: find . -type f -print0 | xargs -0 sed -i -e "s|$PKGX_DIR|\${PKGX_DIR:-\$HOME/.pkgx}|g" -e 's/\+brewing//g'
      working-directory: ${{prefix}}/ghc/{{version}}/bin
    - run: |
        sed -i.bak -e "s|$PKGX_DIR|\${PKGX_DIR:-\$HOME/.pkgx}|g" env
        rm env.bak
      working-directory: ${{prefix}}/.ghcup
    - run: find . -type f -name \*.conf -print0 | xargs -0 sed -i -e 's|{{prefix}}|${pkgroot}/../../../../..|g' -e 's/\+brewing//g'
      working-directory: ${{prefix}}/ghc/{{version}}/lib/ghc-{{version}}/package.conf.d
      if: <9.4
  env:
    BOOTSTRAP_HASKELL_NONINTERACTIVE: 1
    BOOTSTRAP_HASKELL_NO_UPGRADE: 1
    BOOTSTRAP_HASKELL_MINIMAL: 1
    GHCUP_INSTALL_BASE_PREFIX: ${{prefix}}
    GHCUP_SKIP_UPDATE_CHECK: 1

test:
  script:
    - ghc-pkg recache
    - ghc-pkg check
    - test "$(runghc $FIXTURE)" = "Hello World"
  fixture: main = putStrLn "Hello World"
