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

PortSystem                  1.0
PortGroup                   github 1.0
PortGroup                   legacysupport 1.1
PortGroup                   makefile 1.0

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

github.setup                augustss MicroHs 0.15.7.0 v
revision                    0
epoch                       1

categories                  lang haskell
maintainers                 {@barracuda156 macos-powerpc.org:barracuda}
license                     Apache-2

description                 extended subset of Haskell-2010
long_description            The language is an {*}${description}.

checksums                   rmd160  51faee34f416675942cea0a280cf4056a9349b65 \
                            sha256  2823b8aa19eb9cf4ddc1acd7cf197aebeb39054b8fdc70a8b288d18917e74020 \
                            size    1398751
github.tarball_from         archive

# If gmp variant is added, see: https://github.com/augustss/MicroHs/issues/351

patchfiles-append           patch-mhs.conf.diff

post-patch {
    reinplace "s|CCLIBS=|CCLIBS +=|" ${worksrcpath}/Makefile
    reinplace "s|@CC@|${configure.cc}|" ${worksrcpath}/mhs.conf.in
    if {${os.platform} eq "darwin" && ${os.major} < 16} {
        reinplace "s| @EXTRA_LIBS@| -L${prefix}/lib -lMacportsLegacySupport|" \
            ${worksrcpath}/mhs.conf.in
        reinplace "s| @EXTRA_CFLAGS@| -isystem${prefix}/include/LegacySupport -arch ${configure.build_arch}|" \
            ${worksrcpath}/mhs.conf.in
    } elseif {${os.platform} eq "darwin"} {
        reinplace "s| @EXTRA_LIBS@||" ${worksrcpath}/mhs.conf.in
        reinplace "s| @EXTRA_CFLAGS@| -arch ${configure.build_arch}|" ${worksrcpath}/mhs.conf.in
    } else {
        reinplace "s| @EXTRA_LIBS@||" ${worksrcpath}/mhs.conf.in
        reinplace "s| @EXTRA_CFLAGS@||" ${worksrcpath}/mhs.conf.in
    }
}

compiler.blacklist-append   *gcc-4.*

build.args-append           CONF=unix

if {${os.platform} eq "darwin" && ${os.major} < 16} {
    build.args-append       CCLIBS=-lMacportsLegacySupport
}

build.target                all

universal_variant           no

destroot.target             oldinstall
destroot.pre_args-append    PREFIX=${destroot}${prefix}

test.run                    yes
test.target                 everytestmhs
if {${os.platform} eq "darwin" && ${os.major} < 16} {
    test.args-append        CCLIBS=-lMacportsLegacySupport
}

notes "
Please set environment variable MHSDIR to ${prefix}/lib/mhs
"
