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

qt5.depends_component \
                    qtdeclarative \
                    qtmultimedia \
                    qtquickcontrols \
                    qtquickcontrols2

name                yubico-authenticator
github.setup        Yubico yubioath-desktop 5.1.0
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            4
categories          aqua security
license             BSD
maintainers         nomaintainer

description         Tool for generating one-time password codes with YubiKey
long_description \
    Cross-platform application for generating Open Authentication (OATH) \
    time-based TOTP and event-based HOTP one-time password codes, with the help \
    of a YubiKey that protects the shared secrets.

homepage            https://developers.yubico.com/yubioath-desktop/
master_sites        macports_distfiles

checksums           rmd160  b35ab9626d8eff8eb4cf02bb6a050bac47107ea6 \
                    sha256  78822b192da2a5747a8a6633c66a00efff96011cad2fdc77c248f60374eec115 \
                    size    6322358

# Python version must be synced with pyotherside and yubikey-manager4 ports
set python.branch   3.12
set python.version  [join [split ${python.branch} "."] ""]
set python.prefix   ${frameworks_dir}/Python.framework/Versions/${python.branch}
set python.pkgd     ${python.prefix}/lib/python${python.branch}/site-packages
set python.bin      ${python.prefix}/bin/python${python.branch}

depends_lib-append  port:pyotherside

depends_run-append  port:yubikey-manager4

# https://trac.macports.org/ticket/65107
if { ${os.platform} eq "darwin" && (( ${os.major} >= 15 && ${os.major} <= 16 ) || ${os.major} >= 20 ) } {
    use_xcode   yes
}

qt5.min_version     5.7

patchfiles          0001-Remove-pip-installation-for-packaging-in-MacPorts.patch
patch.pre_args-replace  -p0 -p1

post-patch {
    reinplace "s|PYTHON_CMD = python3|PYTHON_CMD = ${python.bin}|" \
        ${worksrcpath}/yubioath-desktop.pro
}

destroot {
    # Install bundled Python code
    xinstall -d ${destroot}/${python.pkgd}
    copy {*}[glob ${worksrcpath}/py/*] ${destroot}${python.pkgd}/

    # Bundled Python is now a symlink to global site-packages
    ln -s ${python.pkgd} ${worksrcpath}/yubioath-desktop.app/Contents/MacOS/pymodules

    # The default install task insists on putting it in $(INSTALL_ROOT)/usr/bin
    # so we do our own thing here.
    system -W ${worksrcpath}/yubioath-desktop.app \
           "strip Contents/MacOS/yubioath-desktop"
    copy ${worksrcpath}/yubioath-desktop.app "${destroot}/${applications_dir}/Yubico Authenticator.app"
}

github.livecheck.regex  {([0-9.]+)}
