# -*- 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.16.5.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  a34588a5cac6cd4e20321c2066d80203e28c26ac \
                            sha256  4f10a2dd9844097a3b40a68a8d0709d66f785da4d869f91a17f873e5ff3bf58d \
                            size    3897097
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}|g" ${worksrcpath}/mhs.conf.in
    if {${os.platform} eq "darwin" && ${os.major} < 16} {
        reinplace "s| @EXTRA_LIBS@| -L${prefix}/lib -lMacportsLegacySupport|g" \
            ${worksrcpath}/mhs.conf.in
        reinplace "s| @EXTRA_CFLAGS@| -isystem${prefix}/include/LegacySupport -arch ${configure.build_arch}|g" \
            ${worksrcpath}/mhs.conf.in
    } elseif {${os.platform} eq "darwin"} {
        reinplace "s| @EXTRA_LIBS@||g" ${worksrcpath}/mhs.conf.in
        reinplace "s| @EXTRA_CFLAGS@| -arch ${configure.build_arch}|g" ${worksrcpath}/mhs.conf.in
    } else {
        reinplace "s| @EXTRA_LIBS@||g" ${worksrcpath}/mhs.conf.in
        reinplace "s| @EXTRA_CFLAGS@||g" ${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
"
