# -*- 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           cmake 1.1
PortGroup           openssl 1.0
PortGroup           legacysupport 1.1

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

name                libfido2
version             1.17.0
revision            0

homepage            https://developers.yubico.com/libfido2/
master_sites        ${homepage}Releases/
distname            ${name}-${version}

categories          security crypto
maintainers         {@trodemaster icloud.com:manuals-unread2u} openmaintainer

license             bsd
description         library to communicate with a FIDO device over USB
long_description    provides library functionality and command-line tools to communicate with a FIDO device over USB, and to verify attestation and assertion signatures.

checksums           rmd160  cdb493d47e411f1e5d77bd9f056ee896b3836180 \
                    sha256  c1012c8871d71b65872fd5ff1a9d6b0838a55683a03e85ba97479ce57129c736 \
                    size    714675

depends_build-append \
                    port:mandoc \
                    port:pkgconfig

depends_lib-append  port:libcbor

platform darwin {
    if {${os.major} < 16} {
        # kIOHIDManagerOptionNone undefined before macOS 10.12
        patchfiles-append \
                    patch-compat-pre1012.diff
    }
    if {${os.major} < 14} {
        # 10.9 and below: old Apple Clang mishandles __attribute__((fallthrough))
        patchfiles-append \
                    patch-fallthrough.diff
    }
    if {${os.major} < 13} {
        # 10.8 and below: bzero hidden by _POSIX_C_SOURCE, needs explicit declaration
        patchfiles-append \
                    patch-bzero.diff
    }
    if {${os.major} < 11} {
        # 10.5 and 10.6: F_SETNOSIGPIPE unavailable
        patchfiles-append \
                    patch-nosigpipe.diff
        # 10.5 and 10.6: Apple Clang does not recognize FALLTHROUGH comment form
        patchfiles-append \
                    patch-cmake-no-fallthrough.diff
    }
    if {${os.major} < 10} {
        # 10.5 only: IOHIDDeviceGetService/IORegistryEntryGetRegistryEntryID unavailable
        patchfiles-append \
                    patch-hid_osx.diff
    }
    if {[string match *gcc* ${configure.compiler}]} {
        patchfiles-append \
                    patch-apple-gcc.diff
    }
    if {${build_arch} in [list ppc ppc64]} {
        patchfiles-append \
                    patch-werror.diff
    }
}

compiler.thread_local_storage yes

configure.args-append \
                    -DBUILD_EXAMPLES=OFF \
                    -DBUILD_SHARED_LIBS=ON \
                    -DBUILD_STATIC_LIBS=ON \
                    -DBUILD_TESTS=ON \
                    -DBUILD_TOOLS=ON \
                    -DUSE_HIDAPI=OFF

test.run            yes
# We want tests use the newly-built lib and not the one that may be installed in the prefix.
# Otherwise some tests may fail with missing symbols.
test.env-append     DYLD_LIBRARY_PATH=${cmake.build_dir}/src
