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

github.setup        google angle $rev
github.tarball_from archive
version             2.1.26018
revision            1
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

# https://github.com/google/angle/blob/$rev/DEPS
set cr_build        71f8022b66936bfe33b3e795de29a38ade96816b
set cr_testing      1c01106921a36ef03694911f9fc38ac3aaa976b9
set cr_jsoncpp      f62d44704b4da6014aa231cfc116e7fd29617d2a
set cr_zlib         caf4afa1afc92e16fef429f182444bed98a46a6c
set spirv_headers   3397e1e4fe0a9964e1837c2934b81835093494b8
set spirv_tools     392b4893c4955125c1873c33a97f2a8ee8363bd3
set vk_headers      d1cd37e925510a167d4abef39340dbdea47d8989
set astc_encoder    2319d9c4d4af53a7fc7c52985e264ce6e8a02a9b
set jsoncpp         42e892d96e47b1f6e29844cc705e148ec4856448

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-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  c7e18e1e0b8a8b60ace319d889bc410aa3a0a774 \
                    sha256  f472cef50ea314b86eb96959a0746c815cdce3f6e4e78d0519b56faf6a6efc75 \
                    size    16143709 \
                    chromium-src-build-${cr_build}${extract.suffix} \
                    rmd160  d854eeec8b97f88f3befd4ff201eefed138cebb6 \
                    sha256  97c1de79e0225e004eabbde76a9e5aacde7ef9f29a3a1dd2acaa648431b7bc66 \
                    size    1702400 \
                    chromium-src-testing-${cr_testing}${extract.suffix} \
                    rmd160  1d4d9e4bc276c2c268c93a6fa7677715cb0b9871 \
                    sha256  6369dcc47417d92fd7b81d5be32f8917b6bb0e9bb4af3b7dfac85dec4ec3e471 \
                    size    2038390 \
                    chromium-src-third_party-jsoncpp-${cr_jsoncpp}${extract.suffix} \
                    rmd160  8611455ceb50dd821a942c3b10f2110c418fe182 \
                    sha256  7360eff9ce58208c68da260db23bdc29bbc00c769905af10aa45af0dd308aba4 \
                    size    4411 \
                    chromium-src-third_party-zlib-${cr_zlib}${extract.suffix} \
                    rmd160  d529ee8524575a4b5962558aab84c43dd5aae612 \
                    sha256  33babec363d373128865fe6edb5c7b98ea22aea8cdf3b9ef39f0a904fe6c1c5c \
                    size    615289 \
                    SPIRV-Headers-${spirv_headers}${extract.suffix} \
                    rmd160  e59e619ddeffc4a82f32cd42ceea8a1259b7bb84 \
                    sha256  fd3795146a3bcb74766086f42e2e239ca9eaa58d3008a0dea00aa8c522ef4702 \
                    size    545422 \
                    SPIRV-Tools-${spirv_tools}${extract.suffix} \
                    rmd160  9b1fc68d62bdf9d5608a2f7bfcb7b34d9498e178 \
                    sha256  f9ee955914370cae6a1462074349b665126191157cc5cc09c17d5e7f8120eb46 \
                    size    3389141 \
                    Vulkan-Headers-${vk_headers}${extract.suffix} \
                    rmd160  e7ad437dd4e37a79335a45ad56fbf821dc3261b5 \
                    sha256  d7497c83c62fb343b03849bf7bdffa124added47739a1dd539d63811b40a8830 \
                    size    2743683 \
                    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-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/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/
}

compiler.cxx_standard   2020

configure.cmd       gn
configure.pre_args  gen out/Release
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 \
                    angle_build_tests=false \
                    angle_enable_metal=false \
                    angle_enable_vulkan=false \
                    angle_enable_wgpu=false'

build.cmd           ninja
build.pre_args      -C out/Release

destroot.cmd        ninja
destroot.pre_args   -C out/Release
destroot.destdir
destroot.target     install_angle

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

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