# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libicsneo
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
replaces=("${MINGW_PACKAGE_PREFIX}-${_realname}-git")
conflicts=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
pkgver=0.1.2
pkgrel=2
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
pkgdesc="The Intrepid Control Systems Open Cross-Platform Device Communication API (mingw-w64)"
license=("custom")
url="https://github.com/intrepidcs/libicsneo"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx")
options=('strip' '!debug' 'staticlibs')
source=(${_realname}-${pkgver}.tar.gz::https://github.com/intrepidcs/libicsneo/archive/v${pkgver}.tar.gz
        001-mingw-build.patch
        002-install-targets.patch
        003-dynamic-library-name.patch)
sha256sums=('5d69d80d52bcd0ba7d2206c47b4f4fec97c9b0f4ce0e6fe5dbbab0eb5b54c5ff'
            'fe44449cdd96d59a45d8a777acf0e2d0a99ca6b377de1f508165a5822e6f3551'
            '2f10b06784908f99f26bb9aec6e9f9ce4f32056dc3be6aa5c88147cfa9e5caa9'
            '2517ae5321d4d6dd7fdbbb2730a8d0eedc5da1587ab97117899e5c85d066b3eb')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-mingw-build.patch
  patch -p1 -i ${srcdir}/002-install-targets.patch
  patch -p1 -i ${srcdir}/003-dynamic-library-name.patch
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  cp -rf ${_realname}-${pkgver} ${srcdir}/build-${MINGW_CHOST}
  cd ${srcdir}/build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "MSYS Makefiles" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    .

  make
}

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
