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

PortSystem          1.0
PortGroup           muniversal 1.0

name                mozjs17
version             17.0.0
revision            4
categories          lang
platforms           darwin
license             MPL-2
maintainers         juanrgar devans openmaintainer
description         JavaScript-C Engine
long_description    SpiderMonkey is Mozilla's JavaScript engine written in C/C++. \
                    It is used in various Mozilla products, including Firefox, \
                    and is available under the MPL2.

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/

checksums           rmd160  2fa3a891da2a7a09019f67c1555c03bcdc51e6c5 \
                    sha256  321e964fe9386785d3bf80870640f2fa1c683e32fe988eeb201b04471c172fba

# set pbranch to desired perl version
# currently 5.24 (#52081)

set pbranch         5.24

depends_build       port:autoconf213 \
                    port:xorg-libXt \
                    port:pkgconfig \
                    port:perl${pbranch}

depends_lib         port:nspr \
                    port:libffi

distname            mozjs${version}

autoconf.dir        ${worksrcpath}/js/src
configure.dir       ${autoconf.dir}
build.dir           ${configure.dir}

use_autoconf        yes
autoconf.cmd        autoconf213
compiler.blacklist  *llvm-gcc-*

configure.perl      ${prefix}/bin/perl${pbranch}
configure.args      --with-system-nspr \
                    --enable-system-ffi \
                    --disable-readline \
                    --enable-threadsafe

configure.ccache    no

patchfiles          patch-js-src-configure.diff \
                    patch-js-src-jsinterp.cpp.diff \
                    patch-mfbt-double-conversion-utils.h.diff \
                    patch-js-src-config-milestone.pl.diff

variant readline description {Link js shell to system readline library} {
    depends_lib-append port:readline
    configure.args-delete --disable-readline
    configure.args-append --enable-readline
}

variant llvm_hacks description {Enable workarounds required for several LLVM instrumentations} {
    configure.args-append --enable-llvm-hacks
}

variant profiling description {Set compile flags necessary for using sampling profilers (e.g. shark, perf)} {
    configure.args-append --enable-profiling
}

# Use absolute path for install_name
post-patch {
    reinplace "s|@executable_path|${prefix}/lib|g" ${configure.dir}/config/rules.mk
}

if {[variant_isset universal]} {
    set merger_host(x86_64) x86_64-apple-${os.platform}${os.major}
    set merger_host(i386) i686-apple-${os.platform}${os.major}
    set merger_configure_args(x86_64) "--build=x86_64-apple-${os.platform}${os.major} --target=x86_64-apple-${os.platform}${os.major}"
    set merger_configure_args(i386) "--build=i686-apple-${os.platform}${os.major} --target=i686-apple-${os.platform}${os.major}"
} else {
    if {${build_arch} eq "i386"} {
        configure.args-append \
            --host=i686-apple-${os.platform}${os.major} \
            --build=i686-apple-${os.platform}${os.major} \
            --target=i686-apple-${os.platform}${os.major}
    } elseif {${build_arch} eq "x86_64"} {
        configure.args-append \
            --host=${build_arch}-apple-${os.platform}${os.major} \
            --build=${build_arch}-apple-${os.platform}${os.major} \
            --target=${build_arch}-apple-${os.platform}${os.major}
    }
}

platform darwin 8 {
    depends_build-append port:gmake
    build.cmd       ${prefix}/bin/gmake
}

livecheck.type      regex
livecheck.url       [lindex ${master_sites} 0]
livecheck.regex     "mozjs-*(17(?:\\.\\d+)*)"