# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=wxWidgets
_wx_basever=3.3
# Example _wx_buildver value is "-rc"
_wx_buildver=

pkgbase=mingw-w64-${_realname,,}${_wx_basever}
pkgname=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-cb_headers"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common-libs"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-gtk3-libs"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-qt-libs"
         "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-qt")
pkgver=${_wx_basever}.1
pkgrel=3
pkgdesc="A C++ library that lets developers create applications for Windows, Linux and UNIX (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
url="https://wxwidgets.org/"
msys2_repository_url="https://github.com/wxWidgets/wxWidgets"
msys2_references=(
  "cpe: cpe:/a:wxwidgets:wxwidgets"
)
license=('spdx:wxWindows')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-curl"
  "${MINGW_PACKAGE_PREFIX}-cairo"
  "${MINGW_PACKAGE_PREFIX}-gspell"
  "${MINGW_PACKAGE_PREFIX}-gtk3"
  "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
  "${MINGW_PACKAGE_PREFIX}-libnotify"
  "${MINGW_PACKAGE_PREFIX}-libpng"
  "${MINGW_PACKAGE_PREFIX}-libtiff"
  "${MINGW_PACKAGE_PREFIX}-libwebp"
  "${MINGW_PACKAGE_PREFIX}-pcre2"
  "${MINGW_PACKAGE_PREFIX}-zlib"
  "${MINGW_PACKAGE_PREFIX}-qt5-base"
)
#options=('!strip' 'debug') # Best options for debugging CodeLite crashes
source=(
  https://github.com/wxWidgets/wxWidgets/releases/download/v${pkgver}${_wx_buildver}/${_realname}-${pkgver}${_wx_buildver}.tar.bz2
  001-wxWidgets-3.0.2-relocate-prefix-in-bin-wx-config.patch
  004-use-copy-instead-of-symlink-on-windows.patch
)
sha256sums=('f936c8d694f9c49a367a376f99c751467150a4ed7cbf8f4723ef19b2d2d9998d'
            '5160ce46b7dc0958691ea2c5d6da50179152d580e80bc0aab63751cef192f285'
            '99012dfafda3ef9fcd14a123e1bc9c23818d9d82e64d774d1e40752b75413447')

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

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

  # Fix MSys2 Run-Time wx-config bug.
  apply_patch_with_msg \
    001-wxWidgets-3.0.2-relocate-prefix-in-bin-wx-config.patch

  apply_patch_with_msg \
    004-use-copy-instead-of-symlink-on-windows.patch
}

build() {
  ####
  # Configure options added to support other software:
  #   -DwxUSE_GRAPHICS_CONTEXT=ON   codelite
  #   -DwxUSE_GRAPHICS_DIRECT2D     codeblocks
  #
  # Configure options added to check for build issues
  #   -DwxBUILD_PRECOMP=OFF
  #
  # Configure options added to avoid possible future issues
  #   -DCMAKE_CXX_STANDARD=17
  #   -DwxUSE_STL=ON
  #
  # Configure options added to avoid warnings:
  #   -DwxUSE_REGEX=builtin
  #
  # Configure options known to cause build errors:
  #   -DwxUSE_REGKEY=OFF                                compile error
  #
  # Configure options known to cause build errors under wxGTK/Win:
  #   -DwxUSE_OPENGL=ON                                 configure error
  #   -DwxUSE_ACCESSIBILITY=ON                          compile error
  #     "wxUSE_ACCESSIBILITY is currently only supported under wxMSW"
  #
  # Configure options added to avoid wxGTK/Win build errors:
  #   -DwxUSE_OPENGL=OFF
  #
  ####

  declare -a _common_config
  _common_config+=(
    -G"Ninja"
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX}
    -DCMAKE_CXX_STANDARD=17
    -DwxBUILD_INSTALL_PLATFORM_SUBDIR=OFF
    -DwxBUILD_INSTALL=ON
    -DwxBUILD_WIN32_MSVC_NAMING=OFF
    -DwxUSE_IFF=ON
    -DwxUSE_GRAPHICS_CONTEXT=ON
    -DwxUSE_GRAPHICS_DIRECT2D=ON
    -DwxBUILD_MONOLITHIC=OFF
    -DwxBUILD_PRECOMP=OFF
    -DwxBUILD_TESTS=OFF
    -DwxUSE_LIBLZMA=ON
    -DwxUSE_WEBREQUEST_WINHTTP=ON
    -DwxUSE_STACKWALKER=ON
    -DwxUSE_DBGHELP=ON
  )

  if check_option "debug" "y"; then
    _common_config+=("-DCMAKE_BUILD_TYPE=Debug")
  else
    _common_config+=("-DCMAKE_BUILD_TYPE=Release" "-DwxBUILD_OPTIMISE=ON")
  fi

  CXXFLAGS+=" -Wno-ignored-attributes -Wno-enum-compare-switch -Wno-deprecated-declarations"

  for _toolkit in msw gtk3 qt; do
    for _libtype in shared static; do

      if [[ ${_toolkit} == qt && ${_libtype} == static ]]; then
        continue
      fi
      if [[ ${_toolkit} == gtk3 ]]; then
        _opengl="OFF"
      else
        _opengl="ON"
      fi
      if [[ ${_libtype} == shared ]]; then
        _is_shared="ON"
        _is_external="sys"
      else
        _is_shared="OFF"
        _is_external="builtin"
      fi

      MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
        cmake \
          -DBUILD_SHARED_LIBS=${_is_shared} \
          -DwxBUILD_SHARED=${_is_shared} \
          -DwxUSE_WEBREQUEST_CURL=${_is_shared} \
          -DwxBUILD_TOOLKIT=${_toolkit} \
          -DwxUSE_EXPAT=${_is_external} \
          -DwxUSE_LIBJPEG=${_is_external} \
          -DwxUSE_LIBPNG=${_is_external} \
          -DwxUSE_LIBTIFF=${_is_external} \
          -DwxUSE_LIBWEBP=${_is_external} \
          -DwxUSE_REGEX=${_is_external} \
          -DwxUSE_ZLIB=${_is_external} \
          -DwxUSE_OPENGL=${_opengl} \
          "${_common_config[@]}" \
          -S ${_realname}-${pkgver}${_wx_buildver} \
          -B build-${_toolkit}-${MSYSTEM}-${_libtype}

      cmake --build build-${_toolkit}-${MSYSTEM}-${_libtype}

      DESTDIR="${srcdir}"/install-${_toolkit}-${MSYSTEM}-${_libtype} \
      cmake --install build-${_toolkit}-${MSYSTEM}-${_libtype}

    done
  done
}

check() {
  cd "${srcdir}/build-msw-${MSYSTEM}-shared/samples"    && make -k --jobs=1 || true
#  cd "${srcdir}/build-msw-${MSYSTEM}-shared/tests"      && make -k --jobs=1 || true

#  cd "${srcdir}"/build-gtk3-${MSYSTEM}-shared/samples   && make -k --jobs=1 # || true
#  cd "${srcdir}"/build-gtk3-${MSYSTEM}-shared/tests     && make -k --jobs=1 # || true
}

package_wxwidgets3.3-common() {
  pkgdesc="Static libraries and headers for wxWidgets ${_wx_basever} (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common-libs"
           "${MINGW_PACKAGE_PREFIX}-cc-libs")
  provides=("${MINGW_PACKAGE_PREFIX}-wxwidgets-common")
  conflicts=("${MINGW_PACKAGE_PREFIX}-wxwidgets-common")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share
  cp -a --recursive "${srcdir}/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/share/" \
      "${pkgdir}"${MINGW_PREFIX}/

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include
  cp -a --recursive "${srcdir}/install-qt-${MSYSTEM}-shared${MINGW_PREFIX}/include/" \
      "${pkgdir}"${MINGW_PREFIX}/

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include
  cp -a --recursive "${srcdir}/install-gtk3-${MSYSTEM}-shared${MINGW_PREFIX}/include/" \
      "${pkgdir}"${MINGW_PREFIX}/

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include
  cp -a --recursive "${srcdir}/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/include/" \
      "${pkgdir}"${MINGW_PREFIX}/

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/bin/wxrc*.* "${pkgdir}"${MINGW_PREFIX}/bin/

  install -Dm644 ${_realname}-${pkgver}${_wx_buildver}/wxwin.m4 \
    -t "${pkgdir}"${MINGW_PREFIX}/share/aclocal

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib
  cp -a "${srcdir}"/install-qt-${MSYSTEM}-shared${MINGW_PREFIX}/lib/*.a  "${pkgdir}"${MINGW_PREFIX}/lib/
  cp -a "${srcdir}"/install-gtk3-${MSYSTEM}-static${MINGW_PREFIX}/lib/*.a "${pkgdir}"${MINGW_PREFIX}/lib/
  cp -a "${srcdir}"/install-gtk3-${MSYSTEM}-shared${MINGW_PREFIX}/lib/*.a "${pkgdir}"${MINGW_PREFIX}/lib/
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-static${MINGW_PREFIX}/lib/*.a  "${pkgdir}"${MINGW_PREFIX}/lib/
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/lib/*.a  "${pkgdir}"${MINGW_PREFIX}/lib/
}

package_wxwidgets3.3-msw-cb_headers() {
  pkgdesc="private wxWidgets ${_wx_basever} MSW headers needed by Code::Blocks (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common")
  provides=("${MINGW_PACKAGE_PREFIX}-wxwidgets-msw-cb_headers")
  conflicts=("${MINGW_PACKAGE_PREFIX}-wxwidgets-msw-cb_headers")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/include/wx-${_wx_basever}/wx/msw/private
  cd "${pkgdir}"${MINGW_PREFIX}/include/wx-${_wx_basever}/wx/msw/private
  cp "${srcdir}"/${_realname}-${pkgver}${_wx_buildver}/include/wx/msw/private/comptr.h ./
  cp "${srcdir}"/${_realname}-${pkgver}${_wx_buildver}/include/wx/msw/private/graphicsd2d.h ./
  cp "${srcdir}"/${_realname}-${pkgver}${_wx_buildver}/include/wx/msw/private/keyboard.h ./
}

package_wxwidgets3.3-common-libs() {
  pkgdesc="wxBase shared libraries for wxwidgets ${_wx_basever} (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-curl"
           "${MINGW_PACKAGE_PREFIX}-expat"
           "${MINGW_PACKAGE_PREFIX}-cc-libs"
           "${MINGW_PACKAGE_PREFIX}-pcre2"
           "${MINGW_PACKAGE_PREFIX}-xz"
           "${MINGW_PACKAGE_PREFIX}-zlib")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/bin/*.dll "${pkgdir}"${MINGW_PREFIX}/bin/

  rm    "$pkgdir"${MINGW_PREFIX}/bin/wxmsw*.dll   # in msw libs package

  # License files
  cd "${srcdir}"/${_realname}-${pkgver}${_wx_buildver}/docs
  install -Dm644 preamble.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}${_wx_basever}/preamble.txt"
  install -Dm644 licence.txt  "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}${_wx_basever}/licence.txt"
  install -Dm644 licendoc.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}${_wx_basever}/licendoc.txt"
  install -Dm644 lgpl.txt     "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}${_wx_basever}/lgpl.txt"
  install -Dm644 gpl.txt      "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}${_wx_basever}/gpl.txt"
  install -Dm644 xserver.txt  "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}${_wx_basever}/xserver.txt"
}

package_wxwidgets3.3-msw-libs() {
  pkgdesc="wxMSW shared libraries for wxwidgets ${_wx_basever} (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
           "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
           "${MINGW_PACKAGE_PREFIX}-libpng"
           "${MINGW_PACKAGE_PREFIX}-libtiff"
           "${MINGW_PACKAGE_PREFIX}-libwebp"
           "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common-libs")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/bin/*.dll "${pkgdir}"${MINGW_PREFIX}/bin/

  rm    "$pkgdir"${MINGW_PREFIX}/bin/wxbase*.dll  # in base libs package
}

package_wxwidgets3.3-msw() {
  pkgdesc="A C++ library that lets developers create applications for Windows, Linux and UNIX (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-msw-libs"
           "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common")
  provides=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}"
            "${MINGW_PACKAGE_PREFIX}-wxwidgets-msw")
  conflicts=("${MINGW_PACKAGE_PREFIX}-wxwidgets-msw")


  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib
  cp -a --recursive "${srcdir}/install-msw-${MSYSTEM}-static${MINGW_PREFIX}/lib/wx/" \
      "${pkgdir}"${MINGW_PREFIX}/lib

  cp -a --recursive "${srcdir}/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/lib/wx/" \
      "${pkgdir}"${MINGW_PREFIX}/lib

  cp -a --recursive "${srcdir}"/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/lib/cmake/ \
      "${pkgdir}"${MINGW_PREFIX}/lib

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-static${MINGW_PREFIX}/bin/wx-config* "${pkgdir}"${MINGW_PREFIX}/bin/
  mv "${pkgdir}"${MINGW_PREFIX}/bin/wx-config{,-static}
  cp -a "${srcdir}"/install-msw-${MSYSTEM}-shared${MINGW_PREFIX}/bin/wx-config* "${pkgdir}"${MINGW_PREFIX}/bin/

  # Replace real full path with psuedo full path; to prevent
  # WARNING: Package contains reference to $(cygpath -m /)
  local MINGW_PREFIX_WIN=$(cygpath -am ${MINGW_PREFIX})
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config"
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config-static"
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/msw-unicode-${_wx_basever}"
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/msw-unicode-static-${_wx_basever}"

  # Workaround for https://github.com/wxWidgets/wxWidgets/issues/23314
  if [[ ${MSYSTEM} == CLANG* ]]; then
    sed -s "s|\"-mthreads\"|\"\"|g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config"
    sed -s "s|\"-mthreads\"|\"\"|g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config-static"
  fi

  # CLANG gives warnings and in some cases errors on "-mwindows" option while building wxPython
  if [[ ${MSYSTEM} == CLANG* ]]; then
    sed -s "s| -mwindows||g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config"
    sed -s "s| -mwindows||g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config-static"
    sed -s "s| -mwindows||g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/msw-unicode-${_wx_basever}"
    sed -s "s| -mwindows||g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/msw-unicode-static-${_wx_basever}"
  fi

  # create wx-config copy with version file suffix
  cp -a "${pkgdir}"${MINGW_PREFIX}/bin/wx-config{,-${_wx_basever}}
}

package_wxwidgets3.3-gtk3-libs() {
  pkgdesc="GTK+3 implementated shared libraries for wxwidgets ${_wx_basever} (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-cairo"
           "${MINGW_PACKAGE_PREFIX}-cc-libs"
           "${MINGW_PACKAGE_PREFIX}-fontconfig"
           "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
           "${MINGW_PACKAGE_PREFIX}-gettext-runtime"
           "${MINGW_PACKAGE_PREFIX}-glib2"
           "${MINGW_PACKAGE_PREFIX}-gspell"
           "${MINGW_PACKAGE_PREFIX}-gtk3"
           "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
           "${MINGW_PACKAGE_PREFIX}-libpng"
           "${MINGW_PACKAGE_PREFIX}-libtiff"
           "${MINGW_PACKAGE_PREFIX}-libwebp"
           "${MINGW_PACKAGE_PREFIX}-pango"
           "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common-libs")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-gtk3-${MSYSTEM}-shared${MINGW_PREFIX}/bin/*.dll "${pkgdir}"${MINGW_PREFIX}/bin/

  rm    "$pkgdir"${MINGW_PREFIX}/bin/wxbase*.dll  # in base libs package
}

package_wxwidgets3.3-gtk3() {
  pkgdesc="GTK+3 implementation of wxWidgets ${_wx_basever} C++ GUI API (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-gtk3-libs"
           "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common")
  provides=("${MINGW_PACKAGE_PREFIX}-wxwidgets-gtk3")
  conflicts=("${MINGW_PACKAGE_PREFIX}-wxwidgets-gtk3")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib
  cp -a --recursive "${srcdir}/install-gtk3-${MSYSTEM}-static${MINGW_PREFIX}/lib/wx/" \
      "${pkgdir}"${MINGW_PREFIX}/lib

  cp -a --recursive "${srcdir}/install-gtk3-${MSYSTEM}-shared${MINGW_PREFIX}/lib/wx/" \
      "${pkgdir}"${MINGW_PREFIX}/lib

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-gtk3-${MSYSTEM}-static${MINGW_PREFIX}/bin/wx-config* "${pkgdir}"${MINGW_PREFIX}/bin/
  cp -a "${srcdir}"/install-gtk3-${MSYSTEM}-shared${MINGW_PREFIX}/bin/wx-config* "${pkgdir}"${MINGW_PREFIX}/bin/

  mv "$pkgdir"${MINGW_PREFIX}/bin/wx-config{,-gtk3} # Conflicts with msw

  # Replace real full path with psuedo full path; to prevent
  # WARNING: Package contains reference to $(cygpath -m /)
  local MINGW_PREFIX_WIN=$(cygpath -am ${MINGW_PREFIX})
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config-gtk3"
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/gtk3-unicode-${_wx_basever}"
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/gtk3-unicode-static-${_wx_basever}"

  # create wx-config-gtk3 copy with version file suffix
  cp -a "${pkgdir}"${MINGW_PREFIX}/bin/wx-config-gtk3{,-${_wx_basever}}
}

package_wxwidgets3.3-qt-libs() {
  pkgdesc="Qt implementated shared libraries for wxwidgets ${_wx_basever} (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
           "${MINGW_PACKAGE_PREFIX}-qt5-base"
           "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
           "${MINGW_PACKAGE_PREFIX}-libpng"
           "${MINGW_PACKAGE_PREFIX}-libtiff"
           "${MINGW_PACKAGE_PREFIX}-libwebp"
           "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common-libs")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-qt-${MSYSTEM}-shared${MINGW_PREFIX}/bin/*.dll "${pkgdir}"${MINGW_PREFIX}/bin/

  rm    "$pkgdir"${MINGW_PREFIX}/bin/wxbase*.dll  # in base libs package
}

package_wxwidgets3.3-qt() {
  pkgdesc="Qt implementation of wxWidgets ${_wx_basever} C++ GUI API (mingw-w64)"
  depends=("${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-qt-libs"
           "${MINGW_PACKAGE_PREFIX}-wxwidgets${_wx_basever}-common")
  provides=("${MINGW_PACKAGE_PREFIX}-wxwidgets-qt")
  conflicts=("${MINGW_PACKAGE_PREFIX}-wxwidgets-qt")

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/lib
  cp -a --recursive "${srcdir}"/install-qt-${MSYSTEM}-shared${MINGW_PREFIX}/lib/wx/ \
      "${pkgdir}"${MINGW_PREFIX}/lib

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/bin
  cp -a "${srcdir}"/install-qt-${MSYSTEM}-shared${MINGW_PREFIX}/bin/wx-config* "${pkgdir}"${MINGW_PREFIX}/bin/

  mv "$pkgdir"${MINGW_PREFIX}/bin/wx-config{,-qt} # Conflicts with msw

  # Replace real full path with psuedo full path; to prevent
  # WARNING: Package contains reference to $(cygpath -m /)
  local MINGW_PREFIX_WIN=$(cygpath -am ${MINGW_PREFIX})
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/bin/wx-config-qt"
  sed -s "s|${MINGW_PREFIX_WIN}|\$\{prefix\}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/wx/config/qt-unicode-${_wx_basever}"

  # create wx-config-qt copy with version file suffix
  cp -a "${pkgdir}"${MINGW_PREFIX}/bin/wx-config-qt{,-${_wx_basever}}
}

# 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;
