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

name                py-curl-cffi
python.rootname     curl_cffi
version             0.16.0
revision            0

license             MIT
maintainers         {mps @Schamschula} openmaintainer
description         Python binding for curl-impersonate fork via cffi.
long_description    {*}${description}
homepage            https://github.com/lexiforest/curl_cffi

set curl_impersonate_version    2.0.0

master_sites        https://github.com/lexiforest/curl_cffi/releases/download/v${version}/:curl-cffi \
                    https://github.com/lexiforest/curl-impersonate/releases/download/v${curl_impersonate_version}/:libcurl-impersonate

set cffi_distfile   ${python.rootname}-${version}${extract.suffix}
set impersonate_distfile \
                    libcurl-impersonate-v${curl_impersonate_version}.${configure.build_arch}-macos${extract.suffix}

checksums           ${cffi_distfile} \
                    rmd160  31dbfe700f3d028976b4e3faf248b89f3a3ebd2e \
                    sha256  b00b423da8028eb6221e3b63bcd63d681150c07cee8b16000d1f7ea292731895 \
                    size    238344

extract.only        ${cffi_distfile}
distfiles           ${cffi_distfile}:curl-cffi \
                    ${impersonate_distfile}:libcurl-impersonate

supported_archs     arm64 x86_64
universal_variant   no

python.versions     310 311 312 313 314

# See: https://github.com/lexiforest/curl-impersonate
if {${configure.build_arch} eq "arm64"} {
    checksums-append    ${impersonate_distfile} \
                        rmd160  ad01faa75b3265ec79f663e42937894c1e2c30d8 \
                        sha256  f8cc4ee6e4cc942fe6b52d905f8fe03ddebda5ffc428683e3b4e0f613cbfff17 \
                        size    13466475
} else {
    checksums-append    ${impersonate_distfile} \
                        rmd160  45428937579351fa0fe389596560befe74a020f8 \
                        sha256  253a3a8d5c37d81d7c5250b971e810c72360dd44326cf3c6bed25a6ff1ee562f \
                        size    14145129
}

if {${name} ne ${subport}} {
    patchfiles      patch-scripts-build.py.diff

    depends_lib-append  \
                    port:py${python.version}-cffi \
                    port:py${python.version}-certifi

    post-extract {
        ln -s ${distpath}/${impersonate_distfile} \
            ${worksrcpath}/libcurl-impersonate${extract.suffix}
    }
}
