# Maintainer: David Grayson <davidegrayson@gmail.com>

_realname=libftdi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5
pkgrel=1
pkgdesc='Library to talk to FTDI chips, with Python 3 bindings (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.intra2net.com/en/developer/libftdi/"
license=('LGPL', 'GPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-swig"
             "${MINGW_PACKAGE_PREFIX}-python")
depends=("${MINGW_PACKAGE_PREFIX}-libusb"
         "${MINGW_PACKAGE_PREFIX}-confuse"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-libiconv")
optdepends=("${MINGW_PACKAGE_PREFIX}-python: Python bindings to libftdi")
options=('staticlibs' 'strip')
source=("https://www.intra2net.com/en/developer/libftdi/download/libftdi1-${pkgver}.tar.bz2")
sha256sums=('7c7091e9c86196148bd41177b4590dccb1510bfe6cea5bf7407ff194482eb049')

prepare() {
  cd ${_realname}1-${pkgver}
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DEXAMPLES=OFF \
    -DPYTHON_BINDINGS=ON \
    -DLINK_PYTHON_LIBRARY=ON \
    -DDOCUMENTATION=OFF \
    "../${_realname}1-${pkgver}/"

  make
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  PATH=$PATH:"${srcdir}/build-${MINGW_CHOST}/src" make check
}

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

  cd "${srcdir}/${_realname}1-${pkgver}"
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"
  cp COPYING* "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}"

  sed -i "s;$(cygpath -m /);/;" \
      "${pkgdir}${MINGW_PREFIX}/lib/cmake/${_realname}1"/*.cmake
}
