# Contributor (MSYS2): David Macek <david.macek.0@gmail.com>
# Maintainer (Arch Linux): Alexander Rødseth <rodseth@gmail.com>
# Contributor (Arch Linux): Angel Velasquez <angvp@archlinux.org>
# Contributor (Arch Linux): Ionut Biru  <ibiru@archlinux.ro>
# Contributor (Arch Linux): William Rea <sillywilly@gmail.com>
# Contributor (Arch Linux): Allan McRae <mcrae_allan@hotmail.com>

_realname=geany
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.37.1
pkgrel=1
pkgdesc='Fast and lightweight IDE (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.geany.org/'
license=('GPL')
depends=("${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-adwaita-icon-theme"
         "${MINGW_PACKAGE_PREFIX}-gtk-update-icon-cache"
         "${MINGW_PACKAGE_PREFIX}-python")
makedepends=('perlxml'
             'intltool'
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python-docutils")
optdepends=("${MINGW_PACKAGE_PREFIX}-geany-plugins: various extra features")
source=(#https://download.geany.org/${_realname}-${pkgver}.tar.bz2{,.sig}
        ${_realname}-${pkgver}.tar.gz::https://github.com/geany/geany/archive/${pkgver}.tar.gz
        "0001-Fix-windres-invocation.patch" # we don't yet have prefixed windres sadly
        "0002-Use-FHS.patch") # even upstream says FIXME :)
validpgpkeys=('ACA0246889FB96B63382111724CCD8550E5D1CAE'
              '457990C86F91F33DE05EBF1BCC03633F700990F2')
sha256sums=('17aee626c29f30ecfae034924e32a6c7f09cc651d3f80ccf7cd225ee0090a2ad'
            '9f5781f0ac781dcbad74dd5ac7c56f5991dbe98c681dc7560f9edff88f633311'
            'd5928b6afb63590657e9a242285396a44dc2bab7e58fed4e34272937210a923e')

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

  # Python2 fix
  sed -i '0,/on/s//on2/' data/templates/files/main.py

  # Syntax highlighting for PKGBUILD files
  sed -i 's/Sh=/Sh=PKGBUILD;/' data/filetype_extensions.conf
  
  patch -p1 -i "${srcdir}/0001-Fix-windres-invocation.patch"
  patch -p1 -i "${srcdir}/0002-Use-FHS.patch"
  
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  mkdir -p "build-${MINGW_CHOST}"
  cd "build-${MINGW_CHOST}"

  # libiberty
  export LDFLAGS+=" -L${MINGW_PREFIX}/lib/binutils"

  # config.h
  export PLUGIN_CFLAGS+=" -I$(pwd)"

  ../${_realname}-${pkgver}/configure \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-gtk3 \
    --disable-pdf-docs \
    --disable-api-docs

  make
}

package() {
  cd "build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  rm -r "${pkgdir}${MINGW_PREFIX}/share/applications"
  rm -r "${pkgdir}${MINGW_PREFIX}/share/icons/hicolor/index.theme"
}
