# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=source-highlight
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.1.9
pkgrel=5
pkgdesc="Convert source code to syntax highlighted document (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.gnu.org/software/src-highlite/"
license=('GPL')
depends=("bash" "${MINGW_PACKAGE_PREFIX}-boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-ctags" 
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-graphviz"
             "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://ftp.gnu.org/gnu/src-highlite/${_realname}-${pkgver}.tar.gz"
        "source-highlight-gcc11.patch"
        "3.1.4-no-undefined.patch")
sha256sums=('3a7fd28378cb5416f8de2c9e77196ec915145d44e30ff4e0ee8beb3fe6211c91'
            '7dbbdb7a1363d650aee75337f1204761754d9ad82a7c873c3f8b3f0ba07e814d'
            '971063177b338e9a037b755c9ade11f8a2d6ec44be576da24e0a73d33fe63fc7')

apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp1 -i "${srcdir}/$_patch"
  done
}

apply_patch_p2_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying $_patch"
    patch -Nbp2 -i "${srcdir}/$_patch"
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ]; then
      rm -rf $_fname
    fi
  done
}

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  apply_patch_with_msg source-highlight-gcc11.patch
  apply_patch_p2_with_msg 3.1.4-no-undefined.patch
  autoreconf -fiv
}

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

  # For generated source file by flex
  export CXXFLAGS+=" -Wno-register"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-boost-libdir=${MINGW_PREFIX}/lib \
    --with-bash-completion=no \
    --with-doxygen=on
# Fix source documentation so your packaging dirs don't appear
  sed "s|STRIP_FROM_PATH =*|STRIP_FROM_PATH = $(cygpath -m ${srcdir})|g" \
     -i lib/srchilite/srchilite.doxyfile
  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make install DESTDIR="${pkgdir}"
  #Fix documentation to give a sensible path for source.
#  local _src="$(cygpath -m ${srcdir}/src)"
  
}
