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

_realname=source-highlight
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.1.9
pkgrel=3
pkgdesc="Convert source code to syntax highlighted document (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
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}-graphviz")
source=("https://ftp.gnu.org/gnu/src-highlite/${_realname}-${pkgver}.tar.gz"
        "3.1.4-no-undefined.patch")
sha256sums=('3a7fd28378cb5416f8de2c9e77196ec915145d44e30ff4e0ee8beb3fe6211c91'
            '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_p2_with_msg 3.1.4-no-undefined.patch
  autoreconf -fiv
}

build() {
  cd "$srcdir"/${_realname}-${pkgver}
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_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-${CARCH}
  make install DESTDIR="${pkgdir}"
  #Fix documentation to give a sensible path for source.
#  local _src="$(cygpath -m ${srcdir}/src)"
  
}
