# Maintainer: Andrew Leech <andrew@alelec.net>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=libusb-compat
pkgbase="mingw-w64-${_realname}-git"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=r76.b5db9d0
pkgrel=2
pkgdesc="Allows applications written for libusb-0.1 to work with libusb-1.0 (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://libusb.info/"
msys2_repository_url="https://github.com/libusb/libusb-compat-0.1"
license=('spdx:LGPL-2.1-or-later')
depends=(${MINGW_PACKAGE_PREFIX}-libusb)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "git")
_commit="b5db9d0"
source=("${_realname}::git+https://github.com/libusb/libusb-compat-0.1.git#commit=${_commit}")
sha256sums=('SKIP')

pkgver() {
  cd "${srcdir}/${_realname}"
  printf "r%s.%s" "$(git rev-list --count "${_commit}")" "$(git rev-parse --short "${_commit}")"
}

prepare() {
  cd "${srcdir}/${_realname}"

  ./bootstrap.sh
}

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  ../${_realname}/configure \
      --prefix=${MINGW_PREFIX} \
      --{host,build}=${MINGW_CHOST} \
      --includedir=${MINGW_PREFIX}/include/libusb-compat \
      --disable-dependency-tracking \
      --enable-static \
      --enable-shared

  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
}
