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

name                spidermonkey
epoch               1
version             1.7.0
revision            8
categories          lang
platforms           darwin
maintainers         nomaintainer
license             {MPL-1.1 GPL-2+ LGPL-2.1+}
description         JavaScript-C Engine
long_description    ${description}

homepage            https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey
master_sites        https://ftp.mozilla.org/pub/js/
distname            js-${version}
checksums           md5 5571134c3863686b623ebe4e6b1f6fe6 \
                    sha1 1a99e8e10cb6600a03ea98895583a8ed42136d1f \
                    rmd160 6eadf1ac7c10a13b3db3d499856c9e18ddbcdfdb

# Both usd and spidermonkey attempt to create a library file called
# ${prefix}/lib/libjs.dylib. Unfortunately, these are not the same
# library, they just happen to be named the same.
# (https://trac.macports.org/ticket/63258)
# This issue has been reported upstream:
# https://github.com/PixarAnimationStudios/USD/issues/1615
conflicts           usd

depends_lib         port:nspr \
                    port:readline

worksrcdir          js/src

patchfiles          spidermonkey-1.5-build.patch \
                    spidermonkey-1.5-threadsafe.diff \
                    spidermonkey-1.5-header.diff \
                    patch-config-Darwin.mk \
                    patch-jsprf.c

post-patch {
    reinplace "s|__PREFIX__|${prefix}|g" \
        ${worksrcpath}/Makefile.ref
    reinplace "s|__USER__|${install.user}|g" \
        ${worksrcpath}/Makefile.ref
    reinplace "s|__GROUP__|${install.group}|g" \
        ${worksrcpath}/Makefile.ref
}

use_configure   no

use_parallel_build  no

build.args          -f Makefile.ref \
                    LIBDIR="/lib" \
                    SO_SUFFIX=dylib \
                    JS_THREADSAFE=1 \
                    JS_READLINE=1

if {!(${universal_possible} && [variant_isset universal])} {
    build.args-append CC='${configure.cc} -arch ${build_arch}'
} else {
    set merger_must_run_binaries "yes"
    foreach arch {i386 x86_64 ppc ppc64} {
        lappend merger_build_args(${arch}) CC='${configure.cc} -arch ${arch}'
    }
}

variant fileobject description {add File object support} {
    build.args-append \
        JS_HAS_FILE_OBJECT=1
}

destroot.args       -f Makefile.ref LIBDIR="/lib" SO_SUFFIX=dylib

livecheck.type      regex
livecheck.url       https://ftp.mozilla.org/pub/js/
livecheck.regex     {>js-(\d+(?:\.\d+){2,})\.}
