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

set js_version      1.8.5
name                spidermonkey[strsed ${js_version} {g/\.//}]
version             1.0.0
revision            2
categories          lang
platforms           darwin
maintainers         nomaintainer
license             {MPL-1.1 GPL-2+ LGPL-2.1+}
description         JavaScript-C Engine
long_description    ${description}

homepage            http://www.mozilla.org/js/spidermonkey/
master_sites        http://ftp.mozilla.org/pub/mozilla.org/js/ \
                    ftp://ftp.mozilla.org/pub/mozilla.org/js/ \
                    http://ftp.mozilla.org/pub/mozilla.org/js/older-packages/ \
                    ftp://ftp.mozilla.org/pub/mozilla.org/js/older-packages/
distname            js[strsed ${js_version} {g/\.//}]-${version}
checksums           rmd160  23e6ddc81d5b63e015aecc1a104b2d3d3ced5005 \
                    sha256  5d12f7e1f5b4a99436685d97b9b7b75f094d33580227aa998c406bbae6f2a687 \
                    size    6164605

depends_lib         port:nspr \
                    port:readline

worksrcdir          js-${js_version}/js/src

patchfiles          patch-DESTDIR.diff \
                    patch-includedir.diff

configure.args      --enable-readline \
                    --enable-threadsafe \
                    --enable-macos-target=${macosx_deployment_target} \
                    --with-system-nspr

test.run            yes
test.target         check

if {${os.platform} eq "darwin" && (${os.major} < 11 || ${os.major} > 20)} {
    depends_build-append \
                    port:python27
    license_noconflict \
                    python27
    configure.python \
                    ${prefix}/bin/python2.7
}

post-patch {
    reinplace "s|asm volatile|asm|g" ${worksrcpath}/methodjit/MethodJIT.cpp
}

post-destroot {
    # The script name is not versioned so it would conflict with other
    # spidermonkey versions. And the script isn't generated correctly on Darwin
    # anyway: https://developer.mozilla.org/en/SpiderMonkey/1.8.5#js-config
    # Programs should use "pkg-config mozjs185" instead of js-config.
    delete ${destroot}${prefix}/bin/js-config
}

universal_variant   no

livecheck.type      regex
livecheck.url       http://ftp.mozilla.org/pub/mozilla.org/js/
livecheck.regex     js[strsed ${js_version} {g/\.//}]-(\[0-9.\]+)${extract.suffix}
