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

set rev             1740f5c25bcac5a650ee3d1c1ec22bfa25fcd756
github.setup        gsource-mirror gn $rev
github.tarball_from archive

# git rev-list --count initial-commit..
version             2384
revision            0
categories          devel
license             BSD
maintainers         nomaintainer

description         meta-build system

long_description    GN is a meta-build system that generates build files for \
                    Ninja.

homepage            https://gn.googlesource.com/gn

checksums           rmd160  9e3d067d115265929ad1c45950c1661aaaf6299d \
                    sha256  53259f4e6d20372d0b9e0185292258277681e51a2722f99884a046c2c26cdebc \
                    size    1157829

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

depends_build       port:ninja \
                    port:python${py_ver_nodot}

depends_run         port:python${py_ver_nodot}

patchfiles          patch-commit-id.diff \
                    patch-macos-version.diff \
                    patch-objc.diff \
                    patch-ppc.diff \
                    patch-python.diff \
                    patch-semaphore.diff

post-patch {
    reinplace "s|@VERSION@|${version}|" ${worksrcpath}/build/gen.py
    reinplace "s|@COMMIT_ID@|[string range $rev 0 11]|" \
        ${worksrcpath}/build/gen.py
    reinplace "s|@DEPLOYMENT_TARGET@|${macosx_deployment_target}|" \
        ${worksrcpath}/build/gen.py
    reinplace "s|@PYTHON@|${configure.python}|" ${worksrcpath}/src/gn/setup.cc
}

compiler.cxx_standard   2020

configure.python    ${prefix}/bin/python${py_ver}
configure.cmd       ${configure.python} build/gen.py
configure.pre_args
configure.args      --allow-warnings

build.cmd           ${prefix}/bin/ninja
build.dir           ${worksrcpath}/out
build.target

destroot {
    copy ${worksrcpath}/out/gn ${destroot}${prefix}/bin/
    set docdir ${prefix}/share/doc/${name}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} AUTHORS LICENSE OWNERS README.md \
        ${destroot}${docdir}
    copy ${worksrcpath}/docs ${destroot}${docdir}
}

test.run            yes
test.cmd            ${worksrcpath}/out/gn_unittests
test.target
