# -*- 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               cmake 1.1
PortGroup               github 1.0
PortGroup               legacysupport 1.1

# arc4random_buf
legacysupport.newest_darwin_requires_legacy 10

name                    v8-11.6

# FIXME: consider adding support for dynamic libs:
# https://trac.macports.org/ticket/69352
github.setup            bnoordhuis v8-cmake 11.6.189.4
revision                0

categories              lang devel
license                 BSD
maintainers             {@barracuda156 gmail.com:vital.had} openmaintainer

description             Google’s open-source JavaScript engine
long_description        {*}${description}. CMake build system.
homepage                https://v8.dev

checksums               rmd160  50803cf19bb2b4b892bfc3b74b574100e20f21d9 \
                        sha256  6b8d05fb278db0309fd2c9c8e38f5cae3a927e0d296841cef029d86f7d072d5f \
                        size    31248378
github.tarball_from     archive

# FIXME: support PowerPC.
supported_archs         arm64 x86_64

set py_ver              3.12
set py_ver_nodot        [string map {. {}} ${py_ver}]

depends_build-append    port:gettext \
                        port:pkgconfig \
                        port:python${py_ver_nodot} \
                        port:py${py_ver_nodot}-jinja2
depends_lib-append      port:gettext-runtime \
                        path:lib/pkgconfig/glib-2.0.pc:glib2

configure.python        ${prefix}/bin/python${py_ver}

post-patch {
    fs-traverse f ${worksrcpath} {
        if {[string match *.py ${f}]} {
            reinplace -q "s|/usr/bin/env python3|${configure.python}|" ${f}
            reinplace -q "s|/usr/bin/env python|${configure.python}|" ${f}
        }
    }
}

compiler.cxx_standard   2017

configure.args-append   -DPYTHON_EXECUTABLE=${configure.python}

destroot {
    set v8_execprefix   ${prefix}/libexec/${name}
    set docdir          ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${v8_execprefix}/bin
    xinstall -d ${destroot}${v8_execprefix}/lib
    xinstall -d ${destroot}/${docdir}
    copy ${worksrcpath}/v8/include ${destroot}${v8_execprefix}
    foreach binary [list d8 mksnapshot torque] {
        copy ${cmake.build_dir}/${binary} ${destroot}${v8_execprefix}/bin
    }
    foreach slib [glob ${cmake.build_dir}/*.a] {
        copy ${slib} ${destroot}${v8_execprefix}/lib
    }
    copy ${worksrcpath}/v8/docs ${destroot}${docdir}
}
