# -*- 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           github 1.0
PortGroup           makefile 1.0
PortGroup           openssl 1.0

github.setup        MLton mlton 475cf2b14993869711f1a93a15a9fa854b5126ed
version             20240519
revision            2
categories          lang ml
maintainers         {@barracuda156 gmail.com:vital.had} openmaintainer
license             HPND
description         Whole-program optimizing compiler for the SML
long_description    MLton is a whole-program optimizing compiler for the Standard ML programming language. \
                    MLton generates small executables with excellent runtime performance, utilizing untagged and unboxed native integers, \
                    reals, and words, unboxed native arrays, fast arbitrary-precision arithmetic based on GMP, and multiple code generation \
                    and garbage collection strategies. In addition, MLton provides a feature rich Standard ML programming environment, \
                    with full support for SML97 as given in The Definition of Standard ML (Revised), a number of useful language extensions, \
                    a complete implementation of the Standard ML Basis Library, various useful libraries, a simple and fast C foreign function interface, \
                    the ML Basis system for programming with source libraries, and tools such as a lexer generator, a parser generator and a profiler.
homepage            http://www.mlton.org
checksums           rmd160  37e2f94ad4b9934a29374587bfb75f98663691cf \
                    sha256  4b967f3826b1e697dd7655d29fa91fbe110c63f22781d6bcf3c6a2cfd15bfcbb \
                    size    14381913
github.tarball_from archive

depends_build-append \
                    port:bash \
                    port:git \
                    port:grep \
                    port:gsed \
                    port:mlton-bootstrap \
                    port:rsync
depends_lib-append  port:gmp

patchfiles-append   patch-settings-for-Macports.diff

post-patch {
    reinplace "s,@MLTON@,${prefix}/libexec/mlton-bootstrap/bin," ${worksrcpath}/Makefile.config
    reinplace "s,@VERSION@,${version}," ${worksrcpath}/Makefile.config
    reinplace "s,@PREFIX@,${prefix},g" ${worksrcpath}/Makefile.config ${worksrcpath}/bin/mlbdeps
}

build.env-append    SH=${prefix}/bin/bash

compiler.c_standard 2011
compiler.blacklist-append {clang < 900}

# mlton bakes in C compiler into its script, like R does.
# We have to ensure that both mlton-bootstrap and mlton use the identical compiler.
# For now set it to use clang-16 or gcc-13. When newer compilers are enabled,
# it should be done for mlton-bootstrap and mlton together, with revbumping both.
compiler.blacklist-append {macports-clang-1[7-9]} {macports-gcc-1[4-9]}

build.args-append   CC=${configure.cc} \
                    WITH_GMP_DIR=${prefix}

platform darwin 10 {
    if {${configure.build_arch} eq "ppc"} {
        # This is only needed on Rosetta, but will not hurt native 10.6 ppc either.
        patchfiles-append \
                    patch-rosetta.diff
    } elseif {${configure.build_arch} eq "x86_64"} {
        # https://trac.macports.org/ticket/68488
        patchfiles-append \
                    patch-10.6-x86_64.diff
    }
}

# https://github.com/MLton/mlton/issues/571
post-destroot {
    reinplace "s,${workpath}/compwrap/cc,," ${destroot}${prefix}/lib/mlton/targets/self/vars
}

universal_variant   no
