# Maintainer: Renato Silva <br.renatosilva@gmail.com>

_realname=libmongoose
pkgbase="mingw-w64-${_realname}"
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
pkgver=7.16
pkgrel=1
pkgdesc='Embedded web server for C/C++ (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/cesanta/mongoose"
msys2_references=(
  'aur: mongoose'
  "cpe: cpe:/a:cesanta:mongoose"
)
license=('spdx:GPL-2.0-only')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/cesanta/mongoose/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        mongoose.pc
        Makefile)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('f2c42135f7bc34b3d10b6401e9326a20ba5dd42d4721b6a526826ba31c1679fd'
            '7ff212f0d496a1082282f4722113084f9037d7c501ec90ca124e4de0cc2b2545'
            '7ca7ecff9d1e16ab7cde71698509f8b5d002f56ec33b797f5ff0ef8c9e06371c')

prepare() {
  tar -xzf "${srcdir}"/${_realname}-${pkgver}.tar.gz -C "${srcdir}" || true

  cp Makefile mongoose-${pkgver}/
  cp mongoose.pc mongoose-${pkgver}/
}

build() {
  cd "${srcdir}/mongoose-${pkgver}"
  make PREFIX=${MINGW_PREFIX} CC=cc AR=ar -j1
}

package() {
  cd "${srcdir}/mongoose-${pkgver}"
  make PREFIX=${MINGW_PREFIX} DESTDIR="${pkgdir}" install
  install -D -m644 mongoose.pc "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/mongoose.pc"
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  sed -e "s|@@PREFIX@@|${MINGW_PREFIX}|g" \
      -e "s|@@VERSION@@|${pkgver}|g" \
      -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/mongoose.pc"
}
