# -*- 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.15.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    1.5.2

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  a0e0dd9cf2da647841e03345e713bfb3344f0fdd \
                    sha256  ea0c67652bf6893d34ee0f82c944f37e488f6147e9421bef1771cc6545b02ded \
                    size    196437

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  7a7c734df788908ac568c297478208ae488359bc \
                        sha256  101b39b1e2e9e529b3eedbdca1da71c80ff84c781f3504c05cf45774d52068de \
                        size    10362657
} else {
    checksums-append    ${impersonate_distfile} \
                        rmd160  2ff122b553b593b8567affd71af076de5268b4bf \
                        sha256  0b3cfa62fb4d682d745176e49b467c10bf403de280df8d11d5384c042839e9f2 \
                        size    10845158
}

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