# Maintainer: Oscar Fuentes <ofv@wanadoo.es>

_realname=ctags
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.8
pkgrel=5
pkgdesc="A multilanguage implementation of Ctags (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://ctags.sourceforge.io/"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("https://prdownloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.tar.gz"
        '001-fix-unused-attribute.patch')
sha256sums=('0e44b45dcabe969e0bbbb11e30c246f81abe5d32012db37395eb57d66e9e99c7'
            '3bf68f062ba72cdfe11e9b5fd823af036f91c63dc05902875f86b8e422f6147f')

_ctags_srcdir=${_realname}-${pkgver}

prepare() {
  cd ${_ctags_srcdir}
  patch -p1 -i ${srcdir}/001-fix-unused-attribute.patch
}

build() {
  cd ${_ctags_srcdir}
  # The configure-based build has issues with features that depend
  # on regular expressions (such as --langdef, --regex-lang, etc.)
  # It is a bit tricky to enable proper regex support on the posix
  # build (LIBS=pcreposix configure --with-posix-regex), and then
  # the executable segfaults when regexs are involved.
  make -f mk_mingw.mak
}

package() {
  _root_dest="${pkgdir}/${MINGW_PREFIX}"
  mkdir -p "${_root_dest}/bin"
  cp "${_ctags_srcdir}/ctags.exe" "${_root_dest}/bin"
  _man_dest="${_root_dest}/share/man/man1"
  mkdir -p "${_man_dest}"
  cp "${_ctags_srcdir}/ctags.1" "${_man_dest}"
}
