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

name                    v8
version                 3.23.17.23
revision                3

platforms               darwin
supported_archs         i386 x86_64
categories              lang devel
maintainers             gmail.com:frodwith cal openmaintainer

homepage                http://code.google.com/p/v8/
license                 BSD
description             Google's open source JavaScript Engine
long_description        Library and command line shell for Google's \
                        high performance, open source Javascript engine.

depends_build           bin:svn:subversion

depends_lib             port:icu

variant universal       {}

fetch.type              svn
svn.url                 http://v8.googlecode.com/svn/tags/${version}
worksrcdir              ${version}

post-patch {
    # checkout fails on the buildbot without --trust-server-cert
    reinplace "s#svn checkout --force#svn checkout --force --non-interactive --trust-server-cert#g" ${worksrcpath}/Makefile
}

configure.cmd           make
configure.pre_args
configure.args          dependencies
# v8's configure script doesn't recognize the --disable-dependency-tracking flag
configure.universal_args-delete \
                        --disable-dependency-tracking


build.env-append        CC="${configure.cc}" \
                        CXX="${configure.cxx}" \
                        LINK="${configure.cxx}" \
                        CC.host="${configure.cc}" \
                        CFLAGS.host="${configure.cflags}" \
                        CXX.host="${configure.cxx}" \
                        CXXFLAGS.host="${configure.cxxflags}" \
                        LINK.host="${configure.cxx}" \
                        LDFLAGS.host="${configure.ldflags}" \
                        GYPFLAGS="-Duse_system_icu=1 -Dwerror="
if {[string match *clang* ${configure.compiler}]} {
    build.env-append    GYP_DEFINES=clang=1
}

if {[variant_isset universal]} {
    set archs ${universal_archs}
} else {
    set archs ${build_arch}
}
regsub "i386" ${archs} "ia32" archs
regsub "x86_64" ${archs} "x64" archs
set buildarchstring ""
foreach arch ${archs} {
    set buildarchstring "${buildarchstring} ${arch}.release"
}
build.pre_args
build.args              ${buildarchstring} library=shared

post-build {
    set libstr ""
    set exstr ""
    foreach arch ${archs} {
        append libstr "${worksrcpath}/out/${arch}.release/libv8.dylib "
        append exstr "${worksrcpath}/out/${arch}.release/d8 "
    }
    system "lipo -create ${libstr} -output ${worksrcpath}/libv8.dylib"
    system "lipo -create ${exstr} -output ${worksrcpath}/v8"
}

destroot {
    eval xinstall -m 0644 \
        [glob ${worksrcpath}/include/*.h] \
        ${destroot}${prefix}/include

    xinstall -d ${destroot}${prefix}/share/doc/${name}
    foreach file {AUTHORS ChangeLog LICENSE LICENSE.v8 LICENSE.strongtalk LICENSE.valgrind} {
        xinstall -m 0644 ${worksrcpath}/${file} ${destroot}${prefix}/share/doc/${name}
    }

    xinstall -m 0755 \
        ${worksrcpath}/libv8.dylib \
        ${destroot}${prefix}/lib

    xinstall -m 0755 \
        ${worksrcpath}/v8 \
        ${destroot}${prefix}/bin

    set libpath ${prefix}/lib/libv8.dylib

    system "install_name_tool -id ${libpath} ${destroot}${libpath}"
    system "install_name_tool -change /usr/local/lib/libv8.dylib ${libpath} ${destroot}${prefix}/bin/v8"
}

livecheck.type  regex
livecheck.url   http://omahaproxy.appspot.com/all?channel=stable&os=mac
livecheck.regex {,(\d+(\.\d+)*)$}