#Maintainer: Ma, Leon <akml@163.com>

_realname=global
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=6.6.14
pkgrel=3
pkgdesc="GNU GLOBAL source code tagging system (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.gnu.org/software/global'
license=('spdx:GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-libltdl"
         "${MINGW_PACKAGE_PREFIX}-libsystre"
         "${MINGW_PACKAGE_PREFIX}-ncurses")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-gperf"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
source=("https://ftp.gnu.org/gnu/${_realname}/${_realname}-${pkgver}.tar.gz"{,.sig}
        '001-global-6.6.2-mingw64.patch')
sha256sums=('f6e7fd0b68aed292e85bb686616baf6551d5c9424adcddca11d808ba318cb320'
            'SKIP'
            '4fb462354b18f46e51f376424f38435c3bb9f480ee01956d208036dd35e14a8b')
validpgpkeys=('26F631B43D624A927E6F1C33969C3BE389DDA6EB') # Shigio YAMAGUCHI <shigio@gnu.org>

prepare() {
  cd ${_realname}-${pkgver}

  patch -p1 -i "${srcdir}"/001-global-6.6.2-mingw64.patch

  autoconf -fiv
}

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

  export lt_cv_deplibs_check_method='pass_all'

  CFLAGS+=" -std=gnu17 -Wno-incompatible-pointer-types" \
  CPPFLAGS="-I${MINGW_PREFIX}/include/ncurses" \
  LDFLAGS="`pkgconf.exe --libs ncursesw`" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --with-ncurses=${MINGW_PREFIX}

  make
}

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

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

  make install DESTDIR="${pkgdir}"

  install -vDm 644 "$srcdir/"${_realname}-${pkgver}/LICENSE \
    -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
  install -vDm 644 "$srcdir/"${_realname}-${pkgver}/COPYING* \
    -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
}
