# -*- 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               legacysupport 1.0

name                    mono
# please update msbuild when updating mono
version                 6.12.0.182
revision                1
epoch                   1
categories              devel lang mono
platforms               darwin
license                 {GPL-2 LGPL-2 MIT}
maintainers             {mcalhoun @MarcusCalhoun-Lopez} openmaintainer
description             Implementation of the .NET Development Framework
long_description        Mono is an effort to create an open source implementation of the .NET \
                        Development Framework including a C# compiler.

homepage                https://www.mono-project.com/
master_sites            https://download.mono-project.com/sources/mono/
use_xz                  yes
universal_variant       no

checksums               rmd160  917021fc3fd08cad611d46aa7a9c19a19a64d094 \
                        sha256  57366a6ab4f3b5ecf111d48548031615b3a100db87c679fc006e8c8a4efd9424 \
                        size    303230932

patchfiles-append       patch-aot-compiler.c.diff \
                        dynamic_lookup-11.patch \
                        patch-xcode_14.diff
# https://github.com/dotnet/runtime/pull/91808
patchfiles-append       patch-icall-_Bool.diff

# autoreconf is needed just for the arm64 until upstream fixes the tooling
use_autoreconf          yes
autoreconf.args         -fvi

if {!${configure.ccache}} {
    patchfiles-append   patch-no_ccache.diff
}

depends_build-append    path:bin/cmake:cmake \
                        port:ninja \
                        port:pkgconfig \
                        bin:perl:perl5 \
                        port:cctools \
                        port:python311

depends_lib-append      port:zlib \
                        port:libiconv \
                        port:gettext \
                        port:kerberos5

configure.args          --enable-nls \
                        --enable-dtrace=no \
                        --with-sigaltstack=no \
                        --with-libgdiplus=${prefix}/lib/libgdiplus.dylib

test.run                yes
test.target             check

compiler.cxx_standard   2011

configure.python        ${prefix}/bin/python3.11

# avoid conflict with port brotli
configure.cppflags-delete -I${prefix}/include
configure.ldflags-delete  -L${prefix}/lib

post-patch {
    if {${os.major} < 9} {
        reinplace "s:MAC_OS_X_VERSION_10_5:1050:g" \
            ${worksrcpath}/libgc/darwin_stop_world.c \
            ${worksrcpath}/mono/utils/mono-sigcontext.h

        reinplace "s/arch_state->__/arch_state->/g" \
            ${worksrcpath}/mono/utils/mach-support-x86.c
        reinplace "s/struct __darwin_mcontext32/struct mcontext/g" \
            ${worksrcpath}/mono/utils/mach-support-x86.c
        reinplace "s/ctx->__/ctx->/g" \
            ${worksrcpath}/mono/utils/mach-support-x86.c
    }

    # ensure we are UsingTheRightCompiler (https://trac.macports.org/wiki/UsingTheRightCompiler)
    reinplace "s:__MACPORTS_CC__:${configure.cc}:g" \
        ${worksrcpath}/mono/mini/aot-compiler.c
}

post-destroot {
    set docdir ${prefix}/share/doc/${name}

    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} COPYING.LIB NEWS README.md \
        ${destroot}${docdir}
}

livecheck.url           https://www.mono-project.com/download/stable/
livecheck.regex         "Stable \\((\\d+(?:\\.\\d+)+)\\)"
