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

github.setup        google angle $rev
github.tarball_from archive

# Major and minor version from src/common/angle_version.h
# Patch version using `git rev-list HEAD --count`
version             2.1.27036
revision            0
categories          graphics devel
license             BSD
maintainers         {makr @mohd-akram} openmaintainer

description         OpenGL ES implementation

long_description    A cross-platform, conformant OpenGL ES implementation.

homepage            https://angleproject.org

# grep -E 'jsoncpp_revision.:|(build.git|testing|astc-encoder|rust|SPIRV-(Headers|Tools)|Vulkan-Headers|zlib)@' DEPS
set jsoncpp         42e892d96e47b1f6e29844cc705e148ec4856448
set cr_jsoncpp      f62d44704b4da6014aa231cfc116e7fd29617d2a
set cr_build        6efd145f258a1ba389bd1ee5e32c2f0a80193f95
set cr_testing      67ba60aaf81dc778947026122385872dceffae20
set astc_encoder    2319d9c4d4af53a7fc7c52985e264ce6e8a02a9b
set cr_rust         7649ef4b38da70bd03ca037078f6a2157cd8ed6a
set spirv_headers   f31ca173eff866369e54d35e53375fadbabd58f4
set spirv_tools     f139c64525c7c449c83d299a9fda4e1657bf37ab
set vk_headers      49f1a381e2aec33ef32adf4a377b5a39ec016ec4
set cr_zlib         7eda07b1e067ef3fd7eea0419c88b5af45c9a776

master_sites-append https://github.com/gsource-mirror/chromium-src-build/archive/${cr_build}:chromium-build
distfiles-append    chromium-src-build-${cr_build}${extract.suffix}:chromium-build

master_sites-append https://github.com/gsource-mirror/chromium-src-testing/archive/${cr_testing}:chromium-testing
distfiles-append    chromium-src-testing-${cr_testing}${extract.suffix}:chromium-testing

master_sites-append https://github.com/gsource-mirror/chromium-src-third_party-jsoncpp/archive/${cr_jsoncpp}:chromium-jsoncpp
distfiles-append    chromium-src-third_party-jsoncpp-${cr_jsoncpp}${extract.suffix}:chromium-jsoncpp

master_sites-append https://github.com/gsource-mirror/chromium-src-third_party-rust/archive/${cr_rust}:chromium-rust
distfiles-append    chromium-src-third_party-rust-${cr_rust}${extract.suffix}:chromium-rust

master_sites-append https://github.com/gsource-mirror/chromium-src-third_party-zlib/archive/${cr_zlib}:chromium-zlib
distfiles-append    chromium-src-third_party-zlib-${cr_zlib}${extract.suffix}:chromium-zlib

master_sites-append https://github.com/KhronosGroup/SPIRV-Headers/archive/${spirv_headers}:spirv-headers
distfiles-append    SPIRV-Headers-${spirv_headers}${extract.suffix}:spirv-headers

master_sites-append https://github.com/KhronosGroup/SPIRV-Tools/archive/${spirv_tools}:spirv-tools
distfiles-append    SPIRV-Tools-${spirv_tools}${extract.suffix}:spirv-tools

master_sites-append https://github.com/KhronosGroup/Vulkan-Headers/archive/${vk_headers}:vulkan-headers
distfiles-append    Vulkan-Headers-${vk_headers}${extract.suffix}:vulkan-headers

master_sites-append https://github.com/ARM-software/astc-encoder/archive/${astc_encoder}:astc-encoder
distfiles-append    astc-encoder-${astc_encoder}${extract.suffix}:astc-encoder

master_sites-append https://github.com/open-source-parsers/jsoncpp/archive/${jsoncpp}:jsoncpp
distfiles-append    jsoncpp-${jsoncpp}${extract.suffix}:jsoncpp

checksums           ${distname}${extract.suffix} \
                    rmd160  5330a5c9da73f866a2951186df5bb0665bba5f5b \
                    sha256  0f9e98f77a2158d2dd0b6f59166a203eeed96db0bda06bfd3df7da29b57a11dd \
                    size    16490780 \
                    chromium-src-build-${cr_build}${extract.suffix} \
                    rmd160  1f60720dbf4f8f50730c6c955b4c825c2a408be4 \
                    sha256  27df4bcab7fcca19624eee994f2493947e4921ff9a4479d6f768d3b7a2db92b8 \
                    size    1750696 \
                    chromium-src-testing-${cr_testing}${extract.suffix} \
                    rmd160  86c07dfa32ada24d30da39becd6e2dc24f5dafa5 \
                    sha256  b48a611a55d5a1504db92ba1d4a23f1356fdf71f4fd40a24dfe4b614ce6da907 \
                    size    2048578 \
                    chromium-src-third_party-jsoncpp-${cr_jsoncpp}${extract.suffix} \
                    rmd160  8611455ceb50dd821a942c3b10f2110c418fe182 \
                    sha256  7360eff9ce58208c68da260db23bdc29bbc00c769905af10aa45af0dd308aba4 \
                    size    4411 \
                    chromium-src-third_party-rust-${cr_rust}${extract.suffix} \
                    rmd160  35dec4cb4c7ded098dcae071834733c4b96c056d \
                    sha256  3c0d603d62d2e95a3f58928ce9bb9135b87ab81aa562cc5c2a5338f515ca27e6 \
                    size    25462701 \
                    chromium-src-third_party-zlib-${cr_zlib}${extract.suffix} \
                    rmd160  8471fd263ec158e1c7f1fe49c7dcff81d55a1a22 \
                    sha256  e9cc9b3caba8439612313ed15c697035fc4edd78c694b4ec5714c6b8c9d815a0 \
                    size    618100 \
                    SPIRV-Headers-${spirv_headers}${extract.suffix} \
                    rmd160  f781d2d86ecc37d5e7bccd16ccbf6a8b8c1dde09 \
                    sha256  cc3295d4ae59dbfae95467d7d6b3f57341f4a666dfe1013aaa612aa06a3a99ca \
                    size    561686 \
                    SPIRV-Tools-${spirv_tools}${extract.suffix} \
                    rmd160  5218be3d9c50711c4a69216a55cca5153b2a7228 \
                    sha256  53d6ddd07fbeca968320dfb4c615da352585e23970bb9292f541efa2af2cfd20 \
                    size    3471614 \
                    Vulkan-Headers-${vk_headers}${extract.suffix} \
                    rmd160  4a09013f43fc3096af840989972dfc59594ec5c8 \
                    sha256  6d7f8b67ba8f1e48dc8a9761510542eae8e1cd1f4918096ec283800b25fe2f90 \
                    size    3064292 \
                    astc-encoder-${astc_encoder}${extract.suffix} \
                    rmd160  1c792cca8415346924640772699e6ffc2d3871f4 \
                    sha256  8b5068ef28a8db1cb354d89d9cefd19d43eddfc72c3468fce7ebb92b2431d4c4 \
                    size    36161899 \
                    jsoncpp-${jsoncpp}${extract.suffix} \
                    rmd160  2938aba554af493df2cc854497fa3a00d55521ee \
                    sha256  0b40e4598d68d3dbd8cab90b249e18f1363ecc694c38f727851f4db34b6887ec \
                    size    216350

depends_build       port:gn \
                    port:ninja \
                    port:rapidjson

use_xcode           yes

patchfiles          patch-commit-id.diff \
                    patch-apple-toolchain.diff \
                    patch-src-common-platform.diff

post-extract {
    delete ${worksrcpath}/build
    move ${workpath}/chromium-src-build-${cr_build} ${worksrcpath}/build

    delete ${worksrcpath}/testing
    move ${workpath}/chromium-src-testing-${cr_testing} ${worksrcpath}/testing

    delete ${worksrcpath}/third_party/jsoncpp
    move ${workpath}/chromium-src-third_party-jsoncpp-${cr_jsoncpp} \
        ${worksrcpath}/third_party/jsoncpp

    delete ${worksrcpath}/third_party/rust
    move ${workpath}/chromium-src-third_party-rust-${cr_rust} \
        ${worksrcpath}/third_party/rust

    delete ${worksrcpath}/third_party/zlib
    move ${workpath}/chromium-src-third_party-zlib-${cr_zlib} \
        ${worksrcpath}/third_party/zlib

    delete ${worksrcpath}/third_party/spirv-headers/src
    move ${workpath}/SPIRV-Headers-${spirv_headers} \
        ${worksrcpath}/third_party/spirv-headers/src

    delete ${worksrcpath}/third_party/spirv-tools/src
    move ${workpath}/SPIRV-Tools-${spirv_tools} \
        ${worksrcpath}/third_party/spirv-tools/src

    delete ${worksrcpath}/third_party/vulkan-headers/src
    move ${workpath}/Vulkan-Headers-${vk_headers} \
        ${worksrcpath}/third_party/vulkan-headers/src

    delete ${worksrcpath}/third_party/astc-encoder/src
    move ${workpath}/astc-encoder-${astc_encoder} \
        ${worksrcpath}/third_party/astc-encoder/src

    delete ${worksrcpath}/third_party/jsoncpp/source
    move ${workpath}/jsoncpp-${jsoncpp} \
        ${worksrcpath}/third_party/jsoncpp/source

    copy ${filespath}/gclient_args.gni ${worksrcpath}/build/config/
}

post-patch {
    reinplace "s|@COMMIT_POSITION@|[lindex [split ${version} .] 2]|" \
        ${worksrcpath}/src/commit_id.py
}

compiler.cxx_standard   2020

configure.cmd       gn
configure.pre_args  gen out
configure.args      --args='\
                    mac_sdk_min=\"0\" \
                    install_prefix=\"${destroot}${prefix}\" \
                    is_official_build=true \
                    is_clang=false \
                    treat_warnings_as_errors=false \
                    fatal_linker_warnings=false \
                    use_custom_libcxx=false \
                    rust_sysroot_absolute=\"${prefix}\" \
                    angle_build_tests=false \
                    angle_enable_metal=false \
                    angle_enable_vulkan=false'

build.cmd           ninja
build.target        angle
build.args          -C out
build.env           ANGLE_UPSTREAM_HASH=[string range $rev 0 11]

destroot.cmd        ninja
destroot.target     install_angle
destroot.args       -C out
destroot.destdir

platform darwin {
    post-destroot {
        foreach f [glob -tails -directory ${destroot} ${prefix}/lib/*.dylib] {
            system "install_name_tool -id /$f ${destroot}/$f"
        }

        system "install_name_tool -change ./libGLESv2.dylib \
            ${prefix}/lib/libGLESv2.dylib \
            ${destroot}${prefix}/lib/libGLESv1_CM.dylib"

        reinplace "s|^prefix=.*$|prefix=${prefix}|" \
            {*}[glob ${destroot}${prefix}/lib/pkgconfig/*.pc]

        delete \
            ${destroot}${prefix}/include/CL \
            ${destroot}${prefix}/include/GLX \
            ${destroot}${prefix}/include/WGL \
            ${destroot}${prefix}/include/GLSLANG \
            ${destroot}${prefix}/include/vulkan \
            ${destroot}${prefix}/include/platform \
            {*}[glob ${destroot}${prefix}/include/*.h] \
            {*}[glob ${destroot}${prefix}/include/*/README.md] \
            {*}[glob ${destroot}${prefix}/include/*/.clang-format]
    }
}

livecheck.url       https://chromiumdash.appspot.com/fetch_releases?channel=Stable&platform=Mac
livecheck.regex     {"angle":"([0-9a-f]+)"}
livecheck.version   $rev
