# $Id$

PortSystem 1.0

name                fsharp
version             1.9.4.19
categories          lang
license             Restrictive Noncommercial
maintainers         nomaintainer
supported_archs     noarch

description         F# is a typed functional programming language.
long_description    F# is a typed functional programming language \
                    for the .NET Framework. It combines the succinctness, \
                    expressivity, and compositionality of typed functional \
                    programming with the runtime support, libraries, \
                    interoperability, tools and object model of .NET. \
                    F# stems from the ML family of languages and has a \
                    core language compatible with that of OCaml, though \
                    also draws from C# and Haskell.
homepage            http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/
platforms           darwin

use_zip             yes

master_sites        ftp://ftp.research.microsoft.com/downloads/6f48a466-4294-4973-9e15-25e0ddff422f
checksums           md5 d51c93d29599540a957f94ff387e65fa \
                    sha1 655a790fd98f7b68c19722b0a29e9d1048c39e0f

depends_lib         port:mono

worksrcdir          FSharp-${version}

use_configure       no

post-patch {
    reinplace "s|gacutil -i|gacutil -i -root ${destroot}${prefix}/lib/|g" ${worksrcpath}/install-mono.sh
    reinplace "s|^echo.*||g" ${worksrcpath}/install-mono.sh
}

build {
}

destroot {
    # Install the assemblies
    system "cd ${worksrcpath} && bash install-mono.sh"

    # Copy the entire lot to ${prefix}/share
    set sharedir ${prefix}/share/fsharp-${version}
    file copy ${worksrcpath} ${destroot}/${sharedir}

    # Create launchers for the binaries
    foreach binary [glob -dir ${worksrcpath}/bin *.exe] {
        # fsc is a windows binary
        if {[file tail $binary] == "fsc.exe"} {
            continue
        }

        set destfile [file join "${destroot}${prefix}/bin/" [file tail [file rootname $binary]]]
        set linkdest [file join ${sharedir}/bin/ [file tail $binary]]

        # Write the launcher script
        set fd [open ${destfile} "w"]
        puts $fd "#/bin/sh"
        puts $fd "if \[ -z \$DYLD_FALLBACK_LIBRARY_PATH \]; then"
        puts $fd "    export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib:/lib:/usr/lib:${prefix}/lib"
        puts $fd "fi"
        puts $fd "exec ${prefix}/bin/mono ${linkdest} \$\*"
        close $fd

        system "chmod +x ${destfile}"
    }
}