# -*- 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       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.29 v
    github.tarball_from releases
    use_bzip2       yes
    checksums       rmd160  f11d0553d80164788b20576df9f1e964979831fc \
                    sha256  5977fc950f8d1395ccea9bd48c06b3f808fd3c2c961b44b0c2e6e29fc3a70a85 \
                    size    645381
    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:automake \
                     port:autoconf

    configure.cmd    ./autogen.sh
}

depends_build-append \
                 port:pkgconfig

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

build.args-append AM_DEFAULT_VERBOSITY=1
