# -*- 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
PortGroup           muniversal 1.0
PortGroup           deprecated 1.0

# Firefox 52 ESR hit EOL on 2018-09-05
deprecated.eol_version yes

name                mozjs52
version             52.6.0
revision            10
categories          lang
platforms           darwin
license             {MPL-2 LGPL-2.1+}
maintainers         {devans @dbevans} 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. This port is now deprecated in favor \
                    of mozjs60.

homepage            https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey
# build from GNOME releng tarball
master_sites        http://ftp.gnome.org/pub/GNOME/teams/releng/tarballs-needing-help/mozjs/

distname            mozjs-${version}gnome1
use_xz              yes

checksums           rmd160  b8815d4e62c36c41dc4e568d44a7430a4da2c86e \
                    sha256  786647e0ee743ab8ebd67d307ab406f93d50363ead7d7d05e29eeb113ebbf525 \
                    size    24712740

depends_build       port:autoconf213 \
                    port:pkgconfig \
                    port:python27

depends_lib         path:lib/pkgconfig/icu-uc.pc:icu \
                    port:nspr \
                    port:xorg-libX11 \
                    port:xorg-libXt

# When modifying this blacklist, also update the gjs blacklist.
# Requires clang-3.6 or equivalent
# While clang-602.0.53 (Xcode 6.4) is based on 3.6, it apparently doesn't pass the configure check
compiler.blacklist  *gcc-3.* *gcc-4.* {clang < 700} macports-clang-3.3 macports-clang-3.4
compiler.fallback-append macports-clang-5.0 macports-clang-3.7

if { ${os.platform} eq "darwin" && ${os.major} < 11 } {
    depends_build-append port:cctools
    configure.env-append AR=${prefix}/bin/ar
}

extract.mkdir       yes

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

configure.perl      /usr/bin/perl
configure.python    ${prefix}/bin/python2.7

configure.env-append \
                    SHELL=/bin/bash

configure.dir       ${worksrcpath}/js/src/obj
configure.cmd       ../configure

configure.args      --with-system-icu \
                    --with-system-nspr \
                    --disable-readline \
                    --enable-threadsafe

build.env-append    SHELL=/bin/bash
build.dir           ${worksrcpath}/js/src/obj
destroot.dir        ${worksrcpath}/js/src/obj

variant readline description {Link js shell to system readline library} {
    depends_lib-append port:readline
    configure.args-replace --disable-readline --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
}

if {${universal_possible} && [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}
    }
}

livecheck.type      none
