# -*- 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/

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.27 v
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    checksums       rmd160  69dc0e9404182e0a772f05eb1e51180fdd6d7c0b \
                    sha256  24fd52178a466ef26d33966a4f5703d02dd320d7a57b8ae800e8283ace639ec2 \
                    size    404258
    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 f3619c4078a921c3d6bf3238ff7a8dc70d60e40e
    # Change github.tarball_from to 'releases' or 'archive' next update
    github.tarball_from tarball
    version         20220904-[string range ${github.version} 0 7]
    checksums       rmd160  883d2199713f7ac92311f870b767b84a65adb72f \
                    sha256  1095102edc11cbba1ad087ba922fb1fd6746309ad449e9a36b633e940804e3b4 \
                    size    383327
    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

}

depends_build-append \
                 port:libtool \
                 port:pkgconfig \
                 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
