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

# clock_gettime
legacysupport.newest_darwin_requires_legacy 15

name            libusb
categories      devel

description     library for USB device access
long_description \
    library for use by user level applications to \
    access USB devices regardless of OS
homepage        https://libusb.info/

platforms       darwin
license         LGPL-2.1+
maintainers     {michaelld @michaelld} openmaintainer

use_parallel_build no

# compiler with C11 support is required to build
# libusb as of version 1.0.24
compiler.c_standard 2011
# fatal error: 'stdatomic.h' file not found
compiler.blacklist-append {clang < 700}

subport libusb-devel {}

if {${subport} eq ${name}} {

    github.setup    libusb  libusb 1.0.25 v
    checksums       rmd160  0f2e0ae53ed6ba4d0ef9f51eb5564114b6c5e5e0 \
                    sha256  d60b88837a3a59abc8cac977e0f115e0796a3405cee3bde657255f3d8770fe76 \
                    size    374050
    revision        0

    conflicts       libusb-devel

    # overload the github livecheck regex to look for versions that
    # are just numbers and '.', no letters (e.g., "1.0.19rc1").

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

} else {
    # IOKit/USB.h - fixes GCC 4.5+ issue pre-Catalina
    # https://trac.macports.org/ticket/61868
    # (As of 2021-11-07 the fix requires legacy-support-devel - bump
    # this logic to the top once it is included in mainline legacy-support)
    legacysupport.newest_darwin_requires_legacy 18

    long_description {*}${long_description} \
        This port provides devel version of ${name}, updated weekly to monthly.

    github.setup    libusb  libusb 4622bfcf44db373c53502e3fe873bd611e8332f6
    version         20220131-[string range ${github.version} 0 7]
    checksums       rmd160  0f2e0ae53ed6ba4d0ef9f51eb5564114b6c5e5e0 \
                    sha256  d60b88837a3a59abc8cac977e0f115e0796a3405cee3bde657255f3d8770fe76 \
                    size    374050
    revision        0

    conflicts       libusb

    # because I messed up a version as "202105416-35e8ee98_0", which
    # because of the messed up date is always greater than a correctly
    # formatted date, which means livecheck will never show a newer version.
    epoch           1

}

patchfiles patch-gcc-pragma-options-align-reset.diff

depends_build-append \
                 port:libtool \
                 port:automake \
                 port:autoconf

configure.cmd    ./autogen.sh

# https://trac.macports.org/ticket/64602
configure.checks.implicit_function_declaration.whitelist-append strchr

build.args-append AM_DEFAULT_VERBOSITY=1
