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

_realname=libcddb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.3.2
pkgrel=5
pkgdesc="Library that implements the different protocols (CDDBP, HTTP, SMTP) to access data on a CDDB server (e.g. http://freedb.org) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('LGPL')
url="https://sourceforge.net/projects/libcddb/"
options=('staticlibs' 'strip')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libsystre")
source=(https://downloads.sourceforge.net/sourceforge/${_realname}/${_realname}-${pkgver}.tar.bz2
        0001-include-winsock2-before-windows.mingw.patch
        0002-fix-header-conflict.mingw.patch
        0003-silent-rules.mingw.patch
        0004-hack-around-dummy-alarm.mingw.patch
        0005-fix-m4-dir.all.patch
        0006-update-gettext-req.mingw.patch
        0007-link-to-libiconv-properly.mingw.patch
        0008-properly-refer-to-libiconv-in-pkgconfig.patch)
sha256sums=('35ce0ee1741ea38def304ddfe84a958901413aa829698357f0bee5bb8f0a223b'
            'c937a466fbb2f8f9709859e0f5b1e398b36dfcb9e0b70b2fb460175a4831bedd'
            '9db0a0dd613082651fc1278fadc532c50b3ff4cf0cb29178dd98b181914796fc'
            '8b2aaad7b6654286132a9277183b83348fdbb37216435900aeef03b5e07e8e77'
            'a15e218718eaf20cfa2cc683c344399f3a7407a5596a1e5b6fd02115855b0d35'
            'cd3f07945f81144ac04c429403f39eef4edc65aebc9a902433c693fc88d8bb01'
            '7c8f601be359e1cb481966960354e92f98cb8082be060fabfe17cafad9750ca4'
            '972bd2c410c752a8719cf0fccf128216a5347cd5b4fbebd290d2a07e016a8807'
            'ba20cc2b21183c5ede50ebf197c1e80ac20c38c3b4f151771dd895cba67ca15e')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0001-include-winsock2-before-windows.mingw.patch
  patch -p1 -i ${srcdir}/0002-fix-header-conflict.mingw.patch
  patch -p1 -i ${srcdir}/0003-silent-rules.mingw.patch
  patch -p1 -i ${srcdir}/0004-hack-around-dummy-alarm.mingw.patch
  patch -p1 -i ${srcdir}/0005-fix-m4-dir.all.patch
  patch -p1 -i ${srcdir}/0006-update-gettext-req.mingw.patch
  patch -p1 -i ${srcdir}/0007-link-to-libiconv-properly.mingw.patch
  patch -p1 -i ${srcdir}/0008-properly-refer-to-libiconv-in-pkgconfig.patch

  WANT_AUTOMAKE=latest autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-rpath

  make
}

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