# $Id: Portfile 92517 2012-04-30 19:03:23Z ryandesign@macports.org $

PortSystem 1.0

name             mono
version             2.10.9
categories       devel lang mono
platforms        darwin
license          {GPL-2 LGPL-2 MIT}
maintainers      nomaintainer
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         http://www.go-mono.com/
master_sites     http://download.mono-project.com/sources/mono/
use_bzip2        yes
universal_variant no

checksums           rmd160  ac9784c413eb2cdb490750a86a96cce5c11ad5bd \
                    sha256  541038cd4edd4a1c485638d49697d45015ef7483bcb21bb6165e4d7eb770c9a5

depends_build    port:pkgconfig port:gawk
depends_lib      port:gettext path:lib/pkgconfig/glib-2.0.pc:glib2 \
                 port:libiconv port:zlib port:libgdiplus port:xorg-libX11

# Do NOT pick up external boehmgc (prefixing CPPFLAGS or CFLAGS does not suffice -- ugly++)
configure.cc-append	"-I${worksrcpath}/libgc/include"

configure.args   --with-gc=included \
                 --with-preview=yes \
                 --without-sigaltstack \
                 --with-libgdiplus=${prefix} \
                 --disable-dtrace
configure.ldflags-append -lintl -lcharset

use_parallel_build no

test.run         yes
test.target      check

post-patch {
    reinplace "s/-pthread/-lpthread/g" ${worksrcpath}/configure
    reinplace s|@PREFIX@|$prefix|g $worksrcpath/data/config.in

    if {${os.major} < 9} {
        # Should this always be done?
        reinplace "s/-mmacosx-version-min=10.5//" ${worksrcpath}/configure

        reinplace "s:MAC_OS_X_VERSION_10_5:1050:g" \
            ${worksrcpath}/libgc/darwin_stop_world.c \
            ${worksrcpath}/mono/mini/mini-darwin.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
    }
}

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

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

    xinstall -m 0644 -W ${worksrcpath}/docs assembly-bundle embedded-api exceptions \
        gc-issues jit-thoughts jit-trampolines object-layout stack-alignment unmanaged-calls \
        ${destroot}${docdir}

    set libgc_docdir ${prefix}/share/doc/ligbc-mono-6.6

    eval move ${destroot}${prefix}/share/libgc-mono \
        ${destroot}${libgc_docdir}

    xinstall -d ${destroot}${libgc_docdir}/html

    eval move [glob ${destroot}${libgc_docdir}/*.html] \
        ${destroot}${libgc_docdir}/html
}

platform darwin 9 {
    # is this still needed?
    patchfiles-append patch-interp.h.diff
}

livecheck.type  regex
livecheck.url   ${homepage}mono-downloads/release_data.js
livecheck.regex {stable_version = "(.+)"}
