# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=ada-url
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.3.0
pkgrel=1
pkgdesc="WHATWG-compliant and fast URL parser written in modern C++ (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url='https://github.com/ada-url/ada'
license=('spdx:Apache-2.0 OR MIT')
msys2_references=(
  'anitya: 370270'
  'archlinux: ada'
)
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-python"
             'git')
source=("git+${url}.git#tag=v${pkgver}")
sha256sums=('29ecabef234f9013e17e7580a9104b055215f8030c24c29e8cd8bee2300c27f5')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -Wno-dev \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${extra_config[@]}" \
      -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
      -DBUILD_SHARED_LIBS=ON \
      -DBUILD_TESTING=OFF \
      -DADA_TOOLS=OFF \
      -DPython3_EXECUTABLE="${MINGW_PREFIX}/bin/python.exe" \
      -S ada \
      -B "build-${MSYSTEM}"

  cmake --build "build-${MSYSTEM}"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}"

  install -Dm644 ada/LICENSE-{APACHE,MIT} -t "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/"
}
