# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=editorconfig-qtcreator
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.3.6
pkgrel=1
pkgdesc='EditorConfig Plugin for QtCreator (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://github.com/editorconfig/editorconfig-qtcreator'
license=('spdx:LGPL-2.1-or-later OR LGPL-3.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-pcre2"
         "${MINGW_PACKAGE_PREFIX}-qt-creator"
         "${MINGW_PACKAGE_PREFIX}-editorconfig-core-c"
         "${MINGW_PACKAGE_PREFIX}-syntax-highlighting-qt5")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/editorconfig/editorconfig-qtcreator/archive/${pkgver}/${_realname}-${pkgver}.tar.gz"
        'editorconfig-qtcreator-0.3.6-set-cxx-standard.patch')
sha256sums=('b08acd26e601dbb408de8748b512f9e505865d55f2e8a4024930f44164d7882c'
            '707af33327e8351aec558e94e36ab539a1178a583fe4372379296e49cc8ae250')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}

  patch -p1 -i "${srcdir}"/editorconfig-qtcreator-0.3.6-set-cxx-standard.patch
}

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

  if check_option "debug" "y"; then
    _build_type=Debug
  else
    _build_type=Release
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=${_build_type} \
    ../${_realname}-${pkgver}

  cmake --build .
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  DESTDIR="${pkgdir}" cmake --install .

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.LGPLv21 \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPLv21
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE.LGPLv3 \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.LGPLv3
}

