# Contributor : Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=log4cpp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.1.4
pkgrel=4
pkgdesc="C++ library for flexible logging, modeled after Log4j. (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="http://log4cpp.sourceforge.net/"
msys2_references=(
  'archlinux: log4cpp'
)
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools")
source=(https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz
        001-fix-build-on-mingw.patch
        002-aarch64-build.patch)
sha256sums=('696113659e426540625274a8b251052cc04306d8ee5c42a0c7639f39ca90c9d6'
            '675277fcf54f079b551481e32ffae90c1f42ebf7377284a5c9f8c3e329ac8e99'
            '8583de83a1bc580fc6164ceae6516d55a7833460d7d71080aa776104ede2e0fb')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

prepare() {
  cd ${_realname}

  apply_patch_with_msg \
    001-fix-build-on-mingw.patch \
    002-aarch64-build.patch

  ./autogen.sh
}

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

  LDFLAGS+=" -lws2_32 -lpthread" \
  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-shared \
    --disable-static \
    --disable-doxygen \
    --disable-dot \
    --without-idsa

  make
}

package() {
  cd build-${MSYSTEM}

  make DESTDIR="${pkgdir}" install

  install -Dm644 "${srcdir}"/${_realname}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
