# -*- 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 84538 2011-09-27 19:19:28Z snc@macports.org $

PortSystem 1.0
PortGroup  muniversal 1.0

name                spidermonkey
epoch               1
version             1.7.0
revision            5
categories          lang
platforms           darwin
maintainers         akitada openmaintainer
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-${version}
checksums           md5 5571134c3863686b623ebe4e6b1f6fe6 \
                    sha1 1a99e8e10cb6600a03ea98895583a8ed42136d1f \
                    rmd160 6eadf1ac7c10a13b3db3d499856c9e18ddbcdfdb

depends_build       port:readline
depends_lib         port:nspr
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 { ![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       http://ftp.mozilla.org/pub/mozilla.org/js/
livecheck.regex     {js-(\d+(?:\.\d+){2,})\.}
