# -*- 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                barracuda156 minimark e7c39bbeeac6c69be7c36348d94ca17045e83076
version                     0.1.0
revision                    4
categories                  textproc haskell
maintainers                 {@barracuda156 macos-powerpc.org:barracuda}
# MicroHS uses Apache-2
license                     Apache-2 BSD

description                 Terminal Markdown viewer and converter with TeX math
long_description            Terminal Markdown renderer and mini-pandoc (ANSI, HTML, LaTeX \
                            and plain writers) with Unicode TeX math rendering, written \
                            in MicroHs Haskell.
checksums                   rmd160  1009f899f1e27b9ac9b93050be002ff97bdb97c7 \
                            sha256  f4beb1e618e365e1666f3ebebb14cc51cda310edd5ae3fb5d09746c2522ce153 \
                            size    366817
github.tarball_from         archive

# At any given moment patches may not be present, but keep this for convenience of testing:
patch.pre_args-replace      -p0 -p1

depends_build               port:MicroHS

# Match MicroHS
compiler.blacklist-append   *gcc-4.*

universal_variant           no

depends_lib-append          port:zlib

build.target                minimark-mhs

# mhs -tenvironment reads CC / MHSCCFLAGS / MHSCCLIBS / MHSCONF from
# the environment, so MacPorts controls the C compiler and flags.
# -DHEAP_CELLS=8000000 bakes a ~64MB default runtime heap into the binary
# (32-bit cells) instead of MicroHs's 400MB default — right for a G4;
# override at run time with `minimark +RTS -HxM -RTS` if ever needed.
# The +RTS -H16M -RTS on mhs itself caps the *compiler's* heap (~128MB
# on 32-bit) so the build fits small-RAM machines.
build.args                  MHS="${prefix}/bin/mhs +RTS -H16M -RTS -tenvironment" \
                            MHSFLAGS="-isrc"
build.env-append            MHSDIR=${prefix}/lib/mhs \
                            CC=${configure.cc} \
                            "MHSCCFLAGS=${configure.cflags} -I${prefix}/include -DHEAP_CELLS=8000000" \
                            MHSCONF=unix

if {${os.platform} eq "darwin" && ${os.major} < 16} {
    build.env-append        "MHSCCLIBS=-L${prefix}/lib -lz -lMacportsLegacySupport -lm"
} else {
    build.env-append        "MHSCCLIBS=-L${prefix}/lib -lz -lm"
}

destroot {
    xinstall -m 755 ${worksrcpath}/minimark ${destroot}${prefix}/bin/
    xinstall -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 ${worksrcpath}/README.md \
        ${destroot}${prefix}/share/doc/${name}
}

# Do not use by default, exists for testing:
variant bootstrap_c description "Build from pregenerated C without MicroHS" {
    depends_build-delete    port:MicroHS
    build.target            bootstrap
    build.env               "CFLAGS=${configure.cflags} -DHEAP_CELLS=8000000"
    if {${os.platform} eq   "darwin" && ${os.major} < 16} {
        build.args-append   LIBS=-lMacportsLegacySupport
    }
}
