# -*- 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 104246 2013-03-21 23:35:03Z cal@macports.org $

PortSystem              1.0
PortGroup               github 1.0

github.setup            v8 v8 3.17.15
checksums               rmd160  e7d4bb8ef028add13f285f1d2cfe054f3cdda305 \
                        sha256  74a31dd7e50fe8813846ba7cf04caca8d0641251b7779ab60df069fcebffce2c

platforms               darwin
supported_archs         i386 x86_64
license                 BSD

categories              lang devel
maintainers             gmail.com:frodwith cal openmaintainer

description             Google's open source JavaScript Engine
long_description        Library and command line shell for Google's \
                        high performance, open source Javascript engine.

homepage                http://code.google.com/p/v8/

depends_build           bin:svn:subversion

variant universal       {}

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}
if {${configure.compiler} == "clang"} {
    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 werror=no

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"
}
