# Maintainer: taozuhong <taozuhong@gmail.com>

_realname=scintilla
pkgbase=mingw-w64-${_realname}-gtk3
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-gtk3"
pkgver=4.4.6
pkgrel=1
pkgdesc="A text widget adding syntax highlighting and more to GNOME (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.scintilla.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-python3")
depends=("${MINGW_PACKAGE_PREFIX}-gtk3")
source=("https://www.scintilla.org/scintilla446.tgz"
        "scintilla.pc")
sha256sums=('2df9306ec4539f4fe13f86bab8f2419ba90464933d7cca846d7bb6e7046ec2dc'
            '140186d83987804dd7ccb8b8099499dc1daf63362d64122fe8b97a8d9278c72f')

prepare() {
  cd ${_realname}
  
  export windir=${WINDIR}
}

build() {  
  cd ${srcdir}/${_realname}/gtk
  make GTK3=1 PREFIX='${MINGW_PREFIX}' BUILD='${MINGW_CHOST}' HOST='${MINGW_CHOST}' TARGET='${MINGW_CHOST}'
  
  cp -f "${srcdir}/${_realname}.pc" "${srcdir}/${_realname}/bin/${_realname}.pc"
  sed -i -e "s#@prefix@#${MINGW_PREFIX}#g" "${srcdir}/${_realname}/bin/${_realname}.pc"
}

package() {  
  # pkg-config
  install -Dm644 "${srcdir}/${_realname}.pc" "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}-gtk3.pc"
  
  # library
  install -Dm644 "${srcdir}/${_realname}/bin/liblexilla.a" "${pkgdir}${MINGW_PREFIX}/lib/liblexilla.a"
  install -Dm644 "${srcdir}/${_realname}/bin/scintilla.a" "${pkgdir}${MINGW_PREFIX}/lib/scintilla.a"
  install -Dm644 "${srcdir}/${_realname}/bin/lexilla.dll" "${pkgdir}${MINGW_PREFIX}/bin/lexilla.dll"
  install -Dm644 "${srcdir}/${_realname}/bin/libscintilla.dll" "${pkgdir}${MINGW_PREFIX}/bin/libscintilla.dll"
  
  # include
  install -Dm644 "${srcdir}/${_realname}/include/ILexer.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/ILexer.h"
  install -Dm644 "${srcdir}/${_realname}/include/ILoader.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/ILoader.h"
  install -Dm644 "${srcdir}/${_realname}/include/Platform.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/Platform.h"
  install -Dm644 "${srcdir}/${_realname}/include/Sci_Position.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/Sci_Position.h"
  install -Dm644 "${srcdir}/${_realname}/include/SciLexer.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/SciLexer.h"
  install -Dm644 "${srcdir}/${_realname}/include/Scintilla.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/Scintilla.h"
  install -Dm644 "${srcdir}/${_realname}/include/Scintilla.iface" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/Scintilla.iface"
  install -Dm644 "${srcdir}/${_realname}/include/ScintillaWidget.h" "${pkgdir}${MINGW_PREFIX}/include/${_realname}/ScintillaWidget.h"
  
  # License
  install -Dm644 "${srcdir}/${_realname}/License.txt" "${pkgdir}${MINGW_PREFIX}/share/${_realname}/License.txt"
  install -Dm644 "${srcdir}/${_realname}/version.txt" "${pkgdir}${MINGW_PREFIX}/share/${_realname}/version.txt"
  install -Dm644 "${srcdir}/${_realname}/README" "${pkgdir}${MINGW_PREFIX}/share/${_realname}/README"
}
