# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=tuxpaint
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-${_realname}-docs")
pkgver=0.9.35
pkgrel=4
pkgdesc='Drawing program designed for young children (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://tuxpaint.org/'
license=('spdx:GPL-2.0-only')
depends=("${MINGW_PACKAGE_PREFIX}-cairo"
         "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-fontconfig"
         "${MINGW_PACKAGE_PREFIX}-pango"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-fribidi"
         "${MINGW_PACKAGE_PREFIX}-librsvg"
         "${MINGW_PACKAGE_PREFIX}-libimagequant"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-SDL2_image"
         "${MINGW_PACKAGE_PREFIX}-SDL2_gfx"
         "${MINGW_PACKAGE_PREFIX}-SDL2_mixer"
         "${MINGW_PACKAGE_PREFIX}-SDL2_pango"
         "${MINGW_PACKAGE_PREFIX}-SDL2_ttf")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-gperf"
             "${MINGW_PACKAGE_PREFIX}-imagemagick"
             "${MINGW_PACKAGE_PREFIX}-libpaper"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
options=('!emptydirs')
optdepends=(#"${MINGW_PACKAGE_PREFIX}-tuxpaint-stamps: more stamps"
            #"${MINGW_PACKAGE_PREFIX}-tuxpaint-config: configuration manager"
            "${MINGW_PACKAGE_PREFIX}-fontforge: zh_tw doc generator script")
source=("https://downloads.sourceforge.net/sourceforge/tuxpaint/${_realname}-${pkgver}.tar.gz"
        "001-makefile.patch")
sha256sums=('c1c18af91be77e94fdaab2c928204c4c39ba39ac5da2f441aaf2ecab6d8bd0ad'
            'c4a9defa16fa0e7e83f682e364d0af3ff84d932c394ef21048a832ae9311a16f')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
  tar -xzf "${_realname}-${pkgver}.tar.gz" || true
  cd "${_realname}-${pkgver}"

  patch -Np1 -i "${srcdir}/001-makefile.patch"
}

build() {
  make -C "${_realname}-${pkgver}"\
    PREFIX="${MINGW_PREFIX}" \
    LDFLAGS="${LDFLAGS}" \
    OPTFLAGS="${CFLAGS} -ffast-math" FASTMATH="${CFLAGS} -ffast-math" \
    all
}

package_tuxpaint() {
  backup=("${MINGW_PREFIX:1}/etc/tuxpaint/tuxpaint.conf")

  make -C "${_realname}-${pkgver}" \
    PREFIX="${MINGW_PREFIX}" \
    GNOME_PREFIX="${MINGW_PREFIX}" \
    COMPLETIONDIR="${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions" \
    DESTDIR="${pkgdir}" \
    PACKAGE_ONLY=yes \
    install

  mkdir -p "dest${MINGW_PREFIX}/share/doc"
  mv "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}-${pkgver}" "dest${MINGW_PREFIX}/share/doc/${_realname}"
}

package_tuxpaint-docs() {
  pkgdesc+=" (Documentation)"
  depends=()
  optdepends=()

  mv dest/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;
