# -*- 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 92722 2012-05-04 21:35:39Z ciserlohn@macports.org $

PortSystem              1.0

name                    nodejs
version                 0.6.17
categories              devel net
platforms               darwin
license                 {MIT BSD}
maintainers             ciserlohn

description             Evented I/O for V8 JavaScript

long_description        Node's goal is to provide an easy way to build scalable network programs in JavaScript. \
                        Node is similar in design to and influenced by systems like Ruby's Event \
                        Machine or Python's Twisted. Node takes the event model a bit further-it \
                        presents the event loop as a language construct instead of as a library.

conflicts               nodejs-devel

homepage                http://nodejs.org/
master_sites            ${homepage}dist/v${version}

checksums               rmd160  44d11df9efd2ad519cfff3b172b265ea7ab9b6ca \
                        sha256  8dfe5948de27e37a14af184f06e7bd89a23c3b248af44c8ef5cffcd0e4c65778

distname                node-v${version}

proc rec_glob {basedir pattern} {
    set files [glob -directory $basedir -nocomplain -type f $pattern]
    foreach dir [glob -directory $basedir -nocomplain -type d *] {
        eval lappend files [rec_glob $dir $pattern]
    }
    return $files
}

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

post-patch {
    foreach f [concat ${worksrcpath}/wscript \
                   ${worksrcpath}/configure-gyp \
                   ${worksrcpath}/tools/node-waf \
                   ${worksrcpath}/tools/waf-light \
                   ${worksrcpath}/tools/gyp/gyp \
                   ${worksrcpath}/tools/gyp_node \
                   ${worksrcpath}/deps/uv/gyp_uv \
                   [rec_glob ${worksrcpath} *.py]] {
        reinplace "s|/usr/bin/env python|${configure.python}|" ${f}
    }
}

configure.args          --without-ssl
configure.args-append   --without-npm

variant python25 conflicts python26 python27 description {Use python 2.5} {
    depends_lib         port:python25
    configure.python    ${prefix}/bin/python2.5
}

variant python26 conflicts python25 python27 description {Use python 2.6} {
    depends_lib         port:python26
    configure.python    ${prefix}/bin/python2.6
}

variant python27 conflicts python25 python26 description {Use python 2.7} {
    depends_lib         port:python27
    configure.python    ${prefix}/bin/python2.7
}

if {![variant_isset python25] && ![variant_isset python26]} {
    default_variants +python27
}

variant ssl description {Add secure socket layer support} {
    depends_build-append    port:pkgconfig
    depends_lib-append      port:openssl
    configure.args-delete   --without-ssl
}

default_variants        +ssl

# V8 only supports ARM and IA-32 processors
supported_archs         i386 x86_64

universal_variant       no

# "V8 doesn't like cache."
configure.ccache        no

test.run                yes

use_parallel_build      no

configure.args-append   --dest-cpu=${build_arch}

build.args-append   CC=${configure.cc} \
                    CXX=${configure.cxx} \
                    CPP=${configure.cpp} \
                    CFLAGS="${configure.cflags} ${configure.cc_archflags}" \
                    LDFLAGS="${configure.ldflags} ${configure.ld_archflags}" \
                    PYTHON=${configure.python}

post-destroot {
    set docdir ${destroot}${prefix}/share/doc/${name}
    xinstall -d ${docdir}
    xinstall -m 644 -W ${worksrcpath} \
        AUTHORS \
        ChangeLog \
        LICENSE \
        README.md \
        ${docdir}
}

if {${os.major} < 9} {
    pre-fetch {
        ui_error "${name} ${version} requires Mac OS X 10.5 or greater."
        return -code error "incompatible Mac OS X version"
    }
}

livecheck.type      regex
livecheck.regex     node-v(\\d+\\.\[02468\]+\\.\\d+)
