# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           gpg_verify 1.0
PortGroup           legacysupport 1.1

name                ghc
version             9.14.1
revision            3
categories          lang haskell
maintainers         {ieee.org:s.t.smith @essandess} openmaintainer
license             BSD

description         The Glorious Glasgow Haskell Compilation System
long_description    The Glasgow Haskell Compiler is a robust, \
                    fully-featured, optimising compiler and \
                    interactive environment for Haskell 98, GHC \
                    compiles Haskell to either native code or C.  It \
                    implements numerous experimental language \
                    extensions to Haskell 98, for example: \
                    concurrency, a foreign language interface, \
                    multi-parameter type classes, scoped type \
                    variables, existential and universal \
                    quantification, unboxed types, exceptions, weak \
                    pointers, and so on.  GHC comes with a \
                    generational garbage collector, and a space and \
                    time profiler.

homepage            https://haskell.org/${name}

# https://gitlab.haskell.org/ghc/ghc/-/wikis/building/hadrian
# https://www.haskell.org/ghc/blog/20220805-make-to-hadrian.html

use_xz              yes
master_sites        https://downloads.haskell.org/~${name}/${version}

platform arm {
    set ghc_build_arch  aarch64
}
platform i386 {
    set ghc_build_arch  x86_64
}
platform powerpc {
    set ghc_build_arch  ppc
}

if {${os.arch} ni [list arm i386]} {
    known_fail      yes
    pre-fetch {
        ui_error "GHC is only available on macOS \
            with [join ${supported_archs} " or "] architectures."
        error {unsupported platform}
    }
}

set ghc_version     ${version}
set ghc_distname    ${distname}-${ghc_build_arch}-apple-darwin

set exedir          ${prefix}/lib/${distname}
set docdir          ${prefix}/share/doc/${distname}
set mandir          ${prefix}/share/man/man1

set livecheck_url   https://gitlab.haskell.org/ghc/ghc/-/wikis/GHC%20Status#all-released-ghc-versions
set livecheck_regex {\[download]\[dl([0-9.]+)]}

# set build_arch by hand on arm64/x86_64 systems to get x86_64/arm64 checksums
# sudo port -d checksum ghc-prebuilt os.arch=arm build_arch=arm64
# sudo port -d checksum ghc-prebuilt os.arch=i386 build_arch=x86_64
# run `port clean --all ghc-prebuilt` afterwards
if {${build_arch} eq {arm64}} {
    checksums       ${ghc_distname}${extract.suffix} \
                    rmd160  76564a5fa684f2eefacac5c79d2ca05d24090068 \
                    sha256  841591f152085be605616682779341847d24fd56bd6d22ca61bb37ee32b50681 \
                    size    313330900
} elseif {${build_arch} eq {x86_64}} {
    checksums       ${ghc_distname}${extract.suffix} \
                    rmd160  6fd1284c44b67b3fb3dcb9daaf6861a6906bd01f \
                    sha256  404b2ceacb2b2092a2f1d9e8f551a72d0bf34d897c0c7baf3e79ffec837a0b72 \
                    size    317523092
}
set ghc_source_checksums [list \
                    ${distname}-src${extract.suffix} \
                    rmd160  10c3aab5742c510af38de83d2825db39d62c5654 \
                    sha256  2a83779c9af86554a3289f2787a38d6aa83d00d136aa9f920361dd693c101e77 \
                    size    33970212 \
                    ]
set ghc_testsuite_checksums [list \
                    ${distname}-testsuite${extract.suffix} \
                    rmd160  fd28ae79adb89044bf502b7bf29cff949ca23a7c \
                    sha256  84aefc21f0f7ddf3d1324ebac76bfb9dcb0766c14a703304c2508c6789a645ed \
                    size    8154160 \
                    ]

# Has issues if enabled
configure.ccache    no

# gpg --list-packets ${distfiles}/${distname}-src${extract.suffix}.sig
# https://keys.openpgp.org/vks/v1/by-fingerprint/88B57FCF7DB53B4DB3BFA4B1588764FBE22D19C4
# https://pgp.mit.edu/pks/lookup?op=get&search=0x88B57FCF7DB53B4DB3BFA4B1588764FBE22D19C4
set gpg_keyid       588764FBE22D19C4

# relative paths to ${prefix}
set ghc_libdir ${prefix}/lib/${name}-${version}

# LlvmMaxVersion=20 from ./configure.ac; must be less than actual llvm version
set ghc_llvm_version    19

set libiconv_path       ""

# common commands for subport `ghc-prebuilt` and port `ghc +prebuilt` variant
# Note: subport `ghc-prebuilt` is necessary to bootstrap Haskell build tools,
# including port `ghc`, and (nearly equivalent) port `ghc +prebuilt` is
# simply a fallback option when `ghc` cannot be compiled
proc ghc_prebuilt_commands {} {
    global          supported_archs \
                    distfiles ghc_distname extract.suffix \
                    gpg_verify.use_gpg_verification \
                    ghc_distname extract.suffix \
                    checksums ghc_distname extract.suffix \
                    gpg_verify.verify_gpg_signature \
                    filespath gpg_keyid \
                    post-checksum \
                    distpath \
                    depends_build \
                    depends_lib \
                    ghc_llvm_version \
                    extract.only extract.rename \
                    compiler.c_standard \
                    compiler.blacklist \
                    distname name ghc_version \
                    configure.env \
                    prefix \
                    build \
                    post-destroot \
                    libiconv_path \
                    exedir docdir mandir \
                    destroot \
                    fs-traverse \
                    ghc_build_arch

    supported_archs arm64 x86_64

    distfiles       ${ghc_distname}${extract.suffix}

    gpg_verify.use_gpg_verification \
                    yes

    if {[option gpg_verify.use_gpg_verification]} {
        distfiles-append \
                    ${ghc_distname}${extract.suffix}.sig
        checksums-append \
                    ${ghc_distname}${extract.suffix}.sig \
                    size    438

        post-checksum {
            gpg_verify.verify_gpg_signature \
                    ${filespath}/keyid-${gpg_keyid}.txt \
                    ${distpath}/${ghc_distname}${extract.suffix}.sig \
                    ${distpath}/${ghc_distname}${extract.suffix}
        }
    }

    depends_build-append \
                    port:file

    depends_lib-append \
                    port:cctools \
                    port:ld64 \
                    port:libiconv \
                    port:llvm-${ghc_llvm_version}

    extract.only    ${ghc_distname}${extract.suffix}
    extract.rename  yes

    # Build requires C11
    compiler.c_standard 2011
    # On OSX 10.{8,9} with clang 503, 600
    #   :info:build dtrace: failed to open td=gnu11/usr/bin/clang -std=gnu11 -E ...
    compiler.blacklist-append {clang < 700}

    distname        ${name}-${ghc_version}

    configure.env-append \
                    "LD=${prefix}/bin/ld" \
                    "LLC=${prefix}/bin/llc-mp-${ghc_llvm_version}" \
                    "OPT=${prefix}/bin/opt-mp-${ghc_llvm_version}"

    build           {}

    post-destroot {
        set exedir  ${prefix}/lib/${distname}
        set docdir  ${prefix}/share/doc/${distname}
        set mandir  ${prefix}/share/man/man1

        # The upstream Darwin bindist is built against the SDK iconv, whose
        # entry points are iconv*. MacPorts libiconv exports libiconv*, and
        # ${prefix}/lib may appear before the SDK library path in downstream
        # GHC links. Rewrite ghc-internal's iconv references so the prebuilt
        # compiler is consistent with its MacPorts libiconv dependency.
        foreach archive [glob -nocomplain \
                ${destroot}${exedir}/lib/*/ghc-internal-*/libHSghc-internal*.a] {
            set iconv_object {}
            foreach archive_member [split [exec ar -t ${archive}] \n] {
                if {[regexp {^iconv(\.p)?_o$|^iconv\.o$} ${archive_member}]} {
                    set iconv_object ${archive_member}
                    break
                }
            }
            if {${iconv_object} eq {}} {
                ui_debug "No iconv object found in ${archive}"
                continue
            }

            set rewrite_dir ${workpath}/[file tail ${archive}]-iconv-rewrite
            delete -force ${rewrite_dir}
            xinstall -d ${rewrite_dir}

            system -W ${rewrite_dir} \
                    "ar -x ${archive} ${iconv_object}"
            system -W ${rewrite_dir} \
                    "${prefix}/bin/llvm-objcopy-mp-${ghc_llvm_version} \
                    --redefine-sym _iconv=_libiconv \
                    --redefine-sym _iconv_open=_libiconv_open \
                    --redefine-sym _iconv_close=_libiconv_close \
                    ${iconv_object} iconv.rewritten.o"
            move -force ${rewrite_dir}/iconv.rewritten.o ${rewrite_dir}/${iconv_object}
            system -W ${rewrite_dir} \
                    "ar -r ${archive} ${iconv_object}"
            system \
                    "ranlib ${archive}"
        }

        foreach dylib [glob -nocomplain \
                ${destroot}${exedir}/lib/*/libHSghc-internal*.dylib] {
            system \
                    "${prefix}/bin/llvm-objcopy-mp-${ghc_llvm_version} \
                    --redefine-sym _iconv=_libiconv \
                    --redefine-sym _iconv_open=_libiconv_open \
                    --redefine-sym _iconv_close=_libiconv_close \
                    ${dylib} ${dylib}.rewritten"
            move -force ${dylib}.rewritten ${dylib}
            system \
                    "install_name_tool -change /usr/lib/libiconv.2.dylib \
                    ${prefix}/lib/libiconv.2.dylib ${dylib}"
        }

        foreach conf [glob -nocomplain \
                ${destroot}${exedir}/lib/package.conf.d/ghc-internal-*.conf*] {
            set conf_fd [open ${conf} r]
            set conf_contents [read ${conf_fd}]
            close ${conf_fd}

            if {[string first "    ${prefix}/lib" ${conf_contents}] == -1} {
                set conf_lines [split ${conf_contents} \n]
                set conf_contents {}
                foreach line ${conf_lines} {
                    lappend conf_contents ${line}
                    if {${line} in [list "library-dirs:" "library-dirs-static:"]} {
                        set append_libdir_after_indented_line yes
                    } elseif {[info exists append_libdir_after_indented_line]} {
                        if {[string match "    *" ${line}]} {
                            lappend conf_contents "    ${prefix}/lib"
                            unset append_libdir_after_indented_line
                        }
                    } elseif {[string match "dynamic-library-dirs:*" ${line}]} {
                        lappend conf_contents "    ${prefix}/lib"
                    }
                }
                set conf_contents [join ${conf_contents} \n]
                set conf_fd [open ${conf} w]
                puts -nonewline ${conf_fd} ${conf_contents}
                close ${conf_fd}
            }
        }
        system \
                "${destroot}${exedir}/bin/ghc-pkg --global-package-db \
                ${destroot}${exedir}/lib/package.conf.d recache"

        delete -force \
            ${destroot}${docdir}/archives

        fs-traverse d ${destroot}${prefix}/share {
            if { [file isdirectory ${d}]
                && [string match ${ghc_build_arch}-*-${distname}-* \
                    [file tail ${d}]] } {
                if { [file exists ${d}] } {
                    file delete -force {*}[glob -directory ${d} *]
                }
            }
        }
    }
}

if {${name} eq ${subport}} {
    variant prebuilt \
        description {Install prebuilt binaries. Note: variant `ghc +prebuilt`
            is used as a fallback when `ghc` cannot be compiled, whereas
            port `ghc-prebuilt` is necessary to bootstrap Haskell build tools,
            including port `ghc`.} {}

    if { ![variant_isset "prebuilt"] } {
        PortGroup   haskell_cabal 1.0

        haskell_cabal.use_prebuilt  yes

        haskell_cabal.env \
                    "CABAL_CONFIG=${haskell_cabal.cabal_root}/config" \
                    "GHC=${haskell_cabal.cabal_root}/bin/ghc" \
                    "LD=${prefix}/bin/ld" \
                    "LLC=${prefix}/bin/llc-mp-${ghc_llvm_version}" \
                    "OPT=${prefix}/bin/opt-mp-${ghc_llvm_version}" \
                    "PATH=${workpath}/bin:${haskell_cabal.cabal_root}/bin:$env(PATH)"

        distfiles       [lindex ${ghc_source_checksums} 0] \
                        [lindex ${ghc_testsuite_checksums} 0]
        checksums       {*}${ghc_source_checksums} \
                        {*}${ghc_testsuite_checksums}
        extract.only    [lindex ${ghc_source_checksums} 0] \
                        [lindex ${ghc_testsuite_checksums} 0]

        gpg_verify.use_gpg_verification \
                        yes

        if {[option gpg_verify.use_gpg_verification]} {
            distfiles-append \
                        ${distname}-testsuite${extract.suffix}.sig
            checksums-append \
                        ${distname}-testsuite${extract.suffix}.sig \
                size    438

            post-checksum {
                gpg_verify.verify_gpg_signature \
                    ${filespath}/keyid-${gpg_keyid}.txt \
                    ${distpath}/${distname}-testsuite${extract.suffix}.sig \
                    ${distpath}/${distname}-testsuite${extract.suffix}
            }
        }

        # Build requires C11
        compiler.c_standard 2011
        # On OSX 10.{8,9} with clang 503, 600
        #   :info:build dtrace: failed to open td=gnu11/usr/bin/clang -std=gnu11 -E ...
        compiler.blacklist-append {clang < 700}
        # * Missing (or bad) C libraries: m, dl, ffi
        compiler.blacklist-append {clang >= 1700.3}

        # use these to specify python versions, python3 required
        # use ${prefix}/var/macports/sources/rsync.macports.org/macports/release/tarballs/ports/_resources/port1.0/group/python-1.0.tcl
        set python3_version 314
        set python3_branch  [string index ${python3_version} 0].[string range ${python3_version} 1 end]
        set python3_prefix  ${frameworks_dir}/Python.framework/Versions/${python3_branch}
        set python3_bin     ${python3_prefix}/bin/python${python3_branch}

        depends_build-append \
                    port:alex \
                    port:autoconf \
                    port:automake \
                    port:bash \
                    port:bzip2 \
                    port:file \
                    port:gzip \
                    port:hadrian \
                    port:happy \
                    port:hscolour \
                    port:python${python3_version} \
                    port:py${python3_version}-sphinx \
                    port:texlive-fonts-extra \
                    port:texlive-fonts-recommended \
                    port:texlive-latex-extra \
                    port:texlive-xetex \
                    port:xz

        depends_lib-append  \
                    port:cctools \
                    port:gmp \
                    port:ld64 \
                    port:libffi \
                    port:libiconv \
                    port:llvm-${ghc_llvm_version} \
                    port:ncurses
        
        # build depends upon these x86_64 binaries
        depends_skip_archcheck-append \
                    alex \
                    hadrian \
                    happy \
                    hscolour

        post-extract {
            xinstall -d ${workpath}/bin
            ln -s   ${python3_bin} \
                    ${workpath}/bin/python3
            ln -s   ${prefix}/bin/sphinx-build-${python3_branch} \
                    ${workpath}/bin/sphinx-build
            # avoid this cabal/sed error in macOS 10 and earlier:
            # checking for version of sphinx-build... sed: illegal option -- r
            ln -s   ${prefix}/bin/gsed \
                    ${workpath}/bin/sed
        }

        post-patch {
            if { ![file exists ${worksrcpath}/boot] } {
                xinstall \
                    ${worksrcpath}/boot.source \
                    ${worksrcpath}/boot
            }

            # fix DejaVu texlive fonts names, e.g. "\setmonofont{DejaVu Sans Mono}"
            foreach f [list \
                        ${worksrcpath}/libraries/Cabal/doc/conf.py \
                        ${worksrcpath}/docs/users_guide/conf.py \
                    ] {
                reinplace -E \
                    "s|(\{DejaVu\[\[:alnum:]_]*)\[\[:space:]]+|\\1|g" ${f}
                reinplace -E \
                    "s|(\{DejaVu\[\[:alnum:]_]*)\[\[:space:]]+|\\1|g" ${f}
                reinplace -E \
                    "s|\{(DejaVu\[\[:alnum:]_]*)\}|\{\\1.ttf\}|g" ${f}
            }
        }

        # Please remove after this issue is resolved
        # https://gitlab.haskell.org/ghc/ghc/-/issues/26810
        # diff -NaurdwB -I '^#[[:space:]]*' ./ghc-orig ./ghc-new | sed -E -e 's/\.\/ghc-(orig|new)/\./g' > patch-layout_html.diff
        patchfiles-append \
                    patch-layout_html.diff

        use_configure   yes
        use_autoconf    yes

        configure.cmd   ./configure
        configure.pre_args \
                        --prefix=${prefix}
        configure.args

        pre-configure {
            system -W ${worksrcpath} \
                    "env ${haskell_cabal.env} ./boot"
        }

        # https://gitlab.haskell.org/ghc/ghc/-/issues/22118
        configure.pre_args-append \
                    --with-ffi-includes=${prefix}/include \
                    --with-ffi-libraries=${prefix}/lib \
                    --with-gmp-includes=${prefix}/include \
                    --with-gmp-libraries=${prefix}/lib \
                    --with-iconv-includes=${prefix}/include \
                    --with-iconv-libraries=${prefix}/lib \
                    --with-system-libffi

        build.cmd       hadrian
        build.target    reloc-binary-dist-dir
        build.pre_args
        build.post_args -VVVVV [haskell_cabal.build_getjobsarg]

        # libHSbase shipped with GHC links against system libiconv,
        # which provides the 'iconv' symbol, but not the 'libiconv'
        # symbol. Because the compilation process statically links
        # libHSbase.a, we must add these flags to ghc linking.
        # See: ./hadrian/doc/user-settings.md
        # If ghc-prebuilt links against SDK libiconv symbols:
        #    -L${configure.sdkroot}/usr/lib
        # otherwise: -L${prefix}/lib
        build.post_args-append \
                    "\"stage0.*.ghc.link.opts += -L${prefix}/lib\"" \
                    "\"stage1.*.ghc.link.opts += -L${prefix}/lib\"" \
                    "\"stage2.*.ghc.link.opts += -L${prefix}/lib\"" \
                    "\"stage3.*.ghc.link.opts += -L${prefix}/lib\""

        # Note: these post_args link.opts must appear *after* the preceding stage specific ones
        build.post_args-append \
                    "\"*.*.ghc.link.opts += -v\""

        post-build {
            system -W ${build.dir} \
                [join [list "env GHC='${worksrcpath}/_build/stage1/bin/ghc' ${build.cmd} docs" {*}${build.post_args}]]
        }

        destroot.cmd    ${build.cmd}
        destroot.target install
        destroot.pre_args \
                        --prefix=${destroot}${prefix}
        destroot.post_args \
                        {*}${build.post_args}

        pre-destroot {
            # mk/install_script.sh isn't automatically created by hadrian
            set bindist_mkdir [glob ${worksrcpath}/_build/bindist/${distname}-*/mk]
            if {![file exists ${bindist_mkdir}/install_script.sh]} {
                xinstall -W ${worksrcpath} mk/install_script.sh ${bindist_mkdir}
            }
        }

        # documentation
        post-destroot {
            xinstall -W ${filespath} -m 0644 ./ghci.conf ${destroot}${prefix}/etc

            delete  ${destroot}${prefix}/share/share/doc/${distname}/archives

            xinstall -d ${destroot}${prefix}/share/man/man1
            if {[file exists ${worksrcpath}/_build/manpage/${name}.1]} {
                xinstall -m 0644 \
                    ${worksrcpath}/_build/manpage/${name}.1 \
                    ${destroot}${prefix}/share/man/man1
            }
        }

        post-destroot {
            # delete any destroot path appearing in text files
            fs-traverse f ${destroot}${prefix} {
                if {[file isfile ${f}] && [file type ${f}] eq {file}} {
                    if {[string match "text/*" [lindex [exec file --mime-type ${f}] end]]} {
                        reinplace -q "s|${destroot}||g" ${f}
                    }
                }
            }
        }

        haskell_cabal.bindirs-append \
                    ${destroot}${prefix}/lib/${subport}-${version}/bin \
                    ${destroot}${prefix}/lib/${subport}-${version}/lib/bin

        test.cmd        ${build.cmd}
        test.target     test
        test.pre_args
        test.post_args  {*}${build.post_args}
        test.run        yes

        post-activate {
            system  "${prefix}/bin/ghc-pkg recache"
        }
    } else { # variant_isset "prebuilt"
        ghc_prebuilt_commands
    }

    notes "The GHC User Manual is available at:

    file://${prefix}/share/doc/${distname}/html/index.html
    ${prefix}/share/doc/${distname}/users_guide.pdf

Copy/edit ${prefix}/etc/ghci.conf to your directory ~/.ghc
for a user-specific startup configuration.

Note: variant `ghc +prebuilt` is used as a fallback when `ghc`
cannot be compiled, whereas port `ghc-prebuilt` is necessary to bootstrap
Haskell build tools, including port `ghc`."

    livecheck.url   ${livecheck_url}
    livecheck.type  regex
    livecheck.regex ${livecheck_regex}
}

subport ghc-prebuilt {
    revision        1

    ghc_prebuilt_commands

    # rename installed files to *-prebuilt
    post-destroot {
        foreach f [glob ${destroot}${prefix}/bin/*] {
            if {[file isfile ${f}] && [file type ${f}] eq {file}
                && [string match "text/*" [lindex [exec file --mime-type ${f}] end]]} {
                reinplace -E -q \
                    "s|^(exeprog=\".+)(\")\$|\\1-prebuilt\\2|" \
                    ${f}
                foreach d [list ${exedir} ${docdir}] {
                    reinplace -E -q "s|(${d})|\\1-prebuilt|g" ${f}
                }
                move ${f} ${f}-prebuilt
            } elseif {[file type ${f}] eq {link}} {
                set flink [file readlink ${f}]
                ln -s ${flink}-prebuilt ${f}-prebuilt
                delete ${f}
            }
        }
        foreach d [list ${destroot}${exedir} ${destroot}${docdir}] {
            move    ${d} ${d}-prebuilt
        }
        move ${destroot}${mandir}/${name}.1 ${destroot}${mandir}/${name}-prebuilt.1
    }

    notes "Note: port `ghc-prebuilt` is necessary to bootstrap Haskell
build tools, including port `ghc`, whereas port variant `ghc +prebuilt`
is used as a fallback when `ghc` cannot be compiled."

    livecheck.url   ${livecheck_url}
    livecheck.type  regex
    livecheck.regex ${livecheck_regex}
}

subport hadrian {
    # `hadrian --version` uses the shake version, not the hadrian.cabal version
    # See: https://hackage.haskell.org/package/shake
    version         0.19.8
    # please revbump when updating the ghc version
    revision        3

    description     Hadrian is the build system for the Glasgow Haskell Compiler
    long_description \
                    {*}${description}. Hadrian is more scalable, faster, \
                    and spectacularly more maintainable than its Make-based \
                    predecessor.

    homepage        https://gitlab.haskell.org/${name}/${name}/-/tree/master/${subport}

    distname        ${name}-${ghc_version}
    distfiles       [lindex ${ghc_source_checksums} 0]
    checksums       {*}${ghc_source_checksums}
    extract.only    [lindex ${ghc_source_checksums} 0]
if {[exists extract.rename]} {
    extract.rename  yes
}
    set worksrcpath ${workpath}/${worksrcdir}/${subport}

    variant stack \
        description {Use stack to build.} {}

    if { [variant_isset "stack"] } {
        PortGroup   haskell_stack 1.0

        post-extract {
            # Fix for cabal data-files hardcoded path in binary
            # See:
            # https://github.com/commercialhaskell/stack/issues/848
            # https://github.com/commercialhaskell/stack/issues/4857
            # https://github.com/haskell/cabal/issues/462
            # https://github.com/haskell/cabal/issues/3586
            xinstall -m 0644 -W ${worksrcpath} \
                    ${filespath}/Paths_${subport}.hs ./src/Paths_${subport}.hs

            reinplace "s|@PREFIX@|${prefix}|g" \
                    ${worksrcpath}/src/Paths_${subport}.hs
            reinplace "s|@NAME@|${subport}|g" \
                    ${worksrcpath}/src/Paths_${subport}.hs
            reinplace -E \
                    "s|(Version\[\[:space:\]\]+)\\\[\[\[:digit:\]\]+(,\[\[:digit:\]\]+){1,4}\\\]|\\1\[[join [split ${version} .] ,]\]|" \
                    ${worksrcpath}/src/Paths_${subport}.hs
        }
    } else {
        PortGroup   haskell_cabal 1.0

        variant haskell_cabal_use_prebuilt \
            description {Use prebuilt cabal and ghc. This is a necessary\
                default variant because hadrian is used to bootstrap ghc\
                and ghc is used to bootstrap cabal.} {
            haskell_cabal.use_prebuilt  yes
        }
        default_variants-append \
                    +haskell_cabal_use_prebuilt

        build.target-append \
                    --project-file=cabal.project \
                    --allow-newer
        build.post_args-append \
                    --bindir=${prefix}/bin \
                    --datadir=${prefix}/share/${subport}
    }

    # `hadrian --version` uses the shake version, not the hadrian.cabal version
    livecheck.url   https://hackage.haskell.org/package/shake
    livecheck.type  regex
    livecheck.regex {</a>, <strong>([0-9.]+)</strong>}
}
