# Contributor: LI Xuzhang <lixuzhang@gmail.com>
# Contributor: Stas Elensky <stas-at-flexsys-dot-com-dot-ua>

_realname=libmodbus
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
pkgver=658.0e2f470
pkgrel=1
pkgdesc="A Modbus library for Linux, Mac OS X, FreeBSD, QNX and Win32 (mingw-w64)"
url="https://libmodbus.org/"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
license=('LGPL')
makedepends=("git" "asciidoc"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('strip' 'staticlibs' '!buildflags' '!emptydirs' '!debug')
source=("${_realname}::git+https://github.com/stephane/libmodbus")
sha256sums=('SKIP')

pkgver() {
  cd ${_realname}
  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
  #git describe --tags |sed 's+-+.+g'
}

prepare() {
  cd ${_realname}
  ./autogen.sh
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

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