# -*- 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
# $Id: Portfile 103815 2013-03-08 05:53:45Z ryandesign@macports.org $

PortSystem          1.0

name                mars
version             4.3
set releasedate     Jan2013
set fileversion     [join [split ${version} .] _]
revision            0
categories          java devel
platforms           darwin
supported_archs     noarch
license             MIT
maintainers         gmx.de:Torsten.Maehne openmaintainer

description         MARS (MIPS Assembler and Runtime Simulator)

long_description    MARS is a lightweight interactive development environment \
                    (IDE) for programming in MIPS assembly language, intended \
                    for educational-level use with Patterson and Hennessy's \
                    Computer Organization and Design.

homepage            http://courses.missouristate.edu/kenvollmar/mars/
master_sites        ${homepage}MARS_${fileversion}_${releasedate}/
distname            Mars${fileversion}
use_zip             yes
extract.suffix      .jar

checksums           sha1    5a8608ba0a8548d12c035d9817769d86edfa77f8 \
                    rmd160  21e419cd2cd181e48e651e6beeae88cd4273466f

depends_lib         bin:java:kaffe

use_configure       no

build               {}

destroot {
    # Install Mars JAR
    xinstall -m 755 -d ${destroot}${prefix}/share/java
    xinstall -m 644 -W ${distpath} ${distname}.jar ${destroot}${prefix}/share/java
    
    # Install and configure mars command line wrapper
    xinstall -m 755 ${filespath}/mars.in ${destroot}${prefix}/bin/mars
    reinplace "s|@MARSJARPATH@|${prefix}/share/java/${distname}.jar|g" ${destroot}${prefix}/bin/mars
}

# The only reason we extract the zip file is to get the image for the OS X app icon,
# so we don't need to extract it on other platforms.
if {${os.platform} != "darwin"} {
    extract.only
}

platform darwin {
    depends_build-append        port:makeicns
    
    extract.mkdir               yes
    pre-extract {
        extract.post_args-append    images/MarsThumbnail.gif
    }
    
    # Build a nice .app
    post-destroot {
        set MarsAppPath ${destroot}${applications_dir}/MARS.app
        # Build paths
        xinstall -m 755 -d ${MarsAppPath}/Contents/Resources/Java \
                           ${MarsAppPath}/Contents/MacOS
        # Basic package information
        xinstall -m 644 ${filespath}/PkgInfo ${MarsAppPath}/Contents/PkgInfo
        xinstall -m 644 ${filespath}/Info.plist.in ${MarsAppPath}/Contents/Info.plist
        # Set the version in the Info.plist
        reinplace "s|@VERSION@|${version}|g" ${MarsAppPath}/Contents/Info.plist
        # Set the JAR file name
        reinplace "s|@MARSJARFILE@|${distname}.jar|g" ${MarsAppPath}/Contents/Info.plist
        # Generate the icon
        system "${prefix}/bin/makeicns -in ${worksrcpath}/images/MarsThumbnail.gif -out ${MarsAppPath}/Contents/Resources/Mars.icns"
        # Link to the JAR file
        ln -s ${prefix}/share/java/${distname}.jar \
                        ${MarsAppPath}/Contents/Resources/Java/${distname}.jar
        # Copy the stub app
        xinstall -m 755 "/System/Library/Frameworks/JavaVM.framework/Versions/A/Resources/MacOS/JavaApplicationStub" \
                        ${MarsAppPath}/Contents/MacOS
    }
}
