# -*- 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 20241230 on- -release
revision            1
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  9d9b22d52ba160cbb6f2d4b0b7d27ba60c6639c1 \
                    sha256  08bfcdafc95c050e8150762093ccbb5da1d182455a6fd589267fcada5f9be489 \
                    size    14419875
github.tarball_from archive

depends_build-append \
                    port:bash \
                    path:bin/git: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-19 or gcc-16. When newer compilers are enabled,
# it should be done for mlton-bootstrap and mlton together, with revbumping both.
compiler.blacklist-append {macports-clang-2[0-9]} {macports-gcc-1[7-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
