# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Saul Ibarra Corretge <saghul@gmail.com>
# Contributor: Frode Solheim <frode@fs-uae.net>

_primary_python="no"
_pybasever=3.11
_realname=python

if [[ "${_primary_python}" == "yes" ]]; then
  pkgbase="mingw-w64-${_realname}"
  pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
  provides=("${MINGW_PACKAGE_PREFIX}-python3"
            "${MINGW_PACKAGE_PREFIX}-python${_pybasever}")
  conflicts=("${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python${_pybasever}"
            "${MINGW_PACKAGE_PREFIX}-python2<2.7.16-7")
  replaces=("${MINGW_PACKAGE_PREFIX}-python3"
            "${MINGW_PACKAGE_PREFIX}-python${_pybasever}")
else
  pkgbase="mingw-w64-${_realname}${_pybasever}"
  pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}${_pybasever}")
fi
pkgver=${_pybasever}.4
pkgrel=1
pkgdesc="A high-level scripting language (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('PSF')
url="https://www.python.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-bzip2"
         "${MINGW_PACKAGE_PREFIX}-libffi"
         "${MINGW_PACKAGE_PREFIX}-mpdecimal"
         "${MINGW_PACKAGE_PREFIX}-ncurses"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-tcl"
         "${MINGW_PACKAGE_PREFIX}-tk"
         "${MINGW_PACKAGE_PREFIX}-zlib"
         "${MINGW_PACKAGE_PREFIX}-xz"
         "${MINGW_PACKAGE_PREFIX}-tzdata")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "autoconf-archive"
)
options=('makeflags') # 'debug' '!strip')
source=("https://www.python.org/ftp/python/${pkgver%rc?}/Python-${pkgver}.tar.xz"
        0001-sysconfig-make-_sysconfigdata.py-relocatable.patch
        0002-build-add-with-nt-threads-and-make-it-default-on-min.patch
        0003-Define-MS_WINDOWS-and-others-when-compiling-with-MIN.patch
        0004-configure-add-MACHDEP-and-platform-on-MINGW.patch
        0005-Add-default-configuration-for-MINGW.patch
        0006-configure-enable-largefile-support-by-default-for-Mi.patch
        0007-Add-PC-to-CPPFLAGS-and-to-SRCDIRS-on-Mingw.patch
        0008-posixmodule.c-Define-necessary-headers-for-compiling.patch
        0009-Build-winreg-by-default-when-compiling-for-MINGW.patch
        0010-pyport.h-Add-support-for-MINGW.patch
        0011-configure-add-options-so-that-shared-build-is-possib.patch
        0012-Add-dynamic-loading-support-for-MINGW.patch
        0013-Ignore-main-program-for-frozen-scripts-on-MINGW.patch
        0014-Add-missing-library-for-multiprocessing-module.patch
        0015-selectmodule-add-support-for-MINGW.patch
        0016-setup.py-add-libraries-to-fix-compile-of-ctypes-on-M.patch
        0017-Detect-winsock2-and-setup-_socket-module-on-MINGW.patch
        0018-Enable-some-windows-specific-modules.patch
        0019-sysconfig-MINGW-build-extensions-with-GCC.patch
        0020-sysconfig-treat-MINGW-builds-as-POSIX-builds.patch
        0021-Add-support-for-stdcall-without-underscore.patch
        0022-Use-replace-instead-rename-to-avoid-failure-on-windo.patch
        0023-Customize-site-for-MINGW.patch
        0024-add-python-config-sh.patch
        0025-setup.py-add-export_symbols-to-fix-compile-of-ctypes.patch
        0026-mingw-prefer-unix-sep-if-MSYSTEM-environment-variabl.patch
        0027-msys-cygwin-semi-native-build-sysconfig.patch
        0028-sysconfig-mingw-sysconfig-like-posix.patch
        0029-cross-dont-add-multiarch-paths-if-cross-compiling.patch
        0030-mingw-use-backslashes-in-compileall-py.patch
        0031-msys-convert_path-fix-and-root-hack.patch
        0032-mingw-pdcurses_ISPAD.patch
        0033-msys-monkeypatch-os-system-via-sh-exe.patch
        0034-msys-replace-slashes-used-in-io-redirection.patch
        0035-remove_path_max.default.patch
        0036-dont-link-with-gettext.patch
        0037-ctypes-python-dll.patch
        0038-gdbm-module-includes.patch
        0039-use-gnu_printf-in-format.patch
        0040-mingw-fix-ssl-dont-use-enum_certificates.patch
        0041-fix-using-dllhandle-and-winver-mingw.patch
        0042-Add-AMD64-to-sys-config-so-msvccompiler-get_build_ve.patch
        0043-MINGW-link-with-additional-library.patch
        0044-install-msilib.patch
        0045-fix-signal-module-build.patch
        0046-build-build-winconsoleio-and-_testconsole.patch
        0047-expose-sem_unlink.patch
        0048-cygpty-isatty.patch
        0049-disable-broken-gdbm-module.patch
        0050-build-link-win-resource-files-and-build-pythonw.patch
        0051-disable-readline.patch
        0052-fix-isselectable.patch
        0053-_xxsubinterpretersmodule.patch
        0054-configure.ac-fix-inet_pton-check.patch
        0055-set-venv-activate-path-unix.patch
        0056-pass-gen-profile-ldflags.patch
        0057-pkg-config-windows-must-link-ext-with-python-lib.patch
        0058-importlib-bootstrap-path-sep.patch
        0059-pathlib-path-sep.patch
        0060-warnings-fixes.patch
        0061-fix-build-testinternalcapi.patch
        0062-extend-MS_WINDOWS-flag.patch
        0063-clang-arm64.patch
        0064-configure.ac-set-MINGW-stack-reserve.patch
        0065-Don-t-use-os.pathsep-to-find-EOF.patch
        0066-Fix-extension-suffix-for-c-extensions-on-mingw.patch
        0067-Change-the-get_platform-method-in-sysconfig.patch
        0068-distutils-compiler-customize-mingw-cygwin-compilers.patch
        0069-distutils-compiler-enable-new-dtags.patch
        0070-distutils-MINGW-build-extensions-with-GCC.patch
        0071-distutils-use-Mingw32CCompiler-as-default-compiler-f.patch
        0072-distutils-find-import-library.patch
        0073-distutils-avoid-circular-dependency-from-time-module.patch
        0074-distutils-generalization-of-posix-build-in-distutils.patch
        0075-distutils-mingw-sysconfig-like-posix.patch
        0076-distutils-get_versions-fixes.patch
        0077-distutils-install-layout-as-posix.patch
        0078-distutils-msys-convert_path-fix-and-root-hack.patch
        0079-distutils-mingw-build-optimized-ext.patch
        0080-distutils-cygwinccompiler-dont-strip-modules-if-pyde.patch
        0081-distutils-get-compilers-from-env-vars.patch
        0082-distutils-add-windmc-to-cygwinccompiler.patch
        0083-distutils-fix-msvc9-import.patch
        0084-distutils-mingw-add-LIBPL-to-library-dirs.patch
        0085-distutils-Change-the-get_platform-method-in-distutil.patch
        0086-build-Fix-ncursesw-include-lookup.patch
        0087-tests-fix-test_bytes.patch
        0088-time-fix-strftime-not-raising-for-invalid-year-value.patch
        0089-ctypes-find_library-c-should-return-None-with-ucrt.patch
        0090-build-Disable-checks-for-dlopen-dlfcn.patch
        0091-Fix-install-location-of-the-import-library.patch
        0092-Set-MSYS2_ARG_CONV_EXCL-for-the-shared-Python-module.patch
        0093-build-Integrate-venvlauncher-build-installation-into.patch
        0094-configure.ac-set-_WIN32_WINNT-version.patch
        0095-configure.ac-don-t-check-for-clock_-functions.patch
        0096-expanduser-normpath-paths-coming-from-env-vars.patch
        0097-CI-test-the-build-and-add-some-mingw-specific-tests.patch
        0098-Prefer-sysconfig.python_build.patch
        0099-Define-PY3_DLLNAME-to-fix-build.patch
        0100-distutils-remove-checks-for-ancient-gcc-binutils.patch
        0101-distutils-split-CC-env-var-before-passing-to-subproc.patch
        0102-_testconsole.c-Fix-casing-path-sep.patch
        0103-Return-consistent-architecture-markers-for-python-on.patch
        0104-distutils-add-back-gcc_version.patch
        0105-fix-mingw-cross-compiling-in-setup.py.patch
        0106-handle-ncursesw-pkg-config-when-cross-compiling.patch
        0107-mingw_smoketests-fix-_UCRT-condition.patch
        0108-Modify-sys.winver-to-match-upstream.patch
        0109-Change-user-site-packages-path-to-include-the-enviro.patch
        0110-configure-Include-a-header-in-the-check-for-_beginth.patch
        0111-configure.ac-Default-to-without-c-locale-coercion-on.patch
        0112-Fix-failing-tests.patch
        0113-distutils-add-build-root-to-libdirs-when-building-un.patch
        0114-Don-t-change-os.sep-with-an-empty-MSYSTEM-env-var-no.patch
        0115-def-VPATH-when-compiling-Python-sysmodule.c.patch
        0116-Make-_Py_CheckPython3-extern.patch
        0117-link-with-bcrypt.patch
        0118-correctly-find-native-python.patch
        0119-Add-extra-flags-for-_bootstrap_python.patch
        0120-posixmodule-undefine-HAVE_OPENDIR.patch
        0121-getpath.py-add-support-for-mingw.patch
        0122-Don-t-build-_posixsubprocess-on-Windows.patch
        0123-_ssl-link-with-ws2_32.patch
        0124-Fix-building-_socket-module.patch
        0125-Always-normalize-path-in-abspath.patch
        0126-Include-winsock.h-when-checking-for-netdb-function.patch
        0127-include-_multiprocessing-semaphore.c-on-win32.patch
        0128-configure-build-mmap-module-on-win32.patch
        0129-venv-creation-fixes.patch
        0130-move-the-shutdown-function-where-winsock.h-is-includ.patch
        0131-configure.ac-set-BUILDEXEEXT-and-EXEEXT.patch
        0132-configure.ac-fix-building-some-test-modules.patch
        0133-Don-t-convert-sysconfig.get_config_var-VPATH-to-an-a.patch
        0134-Always-convert-to-before-passing-though-pathcch-func.patch
        0135-Build-venvlauncher.exe-from-PC-launcher.c.patch
        0136-getpath.py-fix-dirname.patch
        0137-gh-105821-Use-a-raw-f-string-in-test_httpservers.py-.patch)

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

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

 apply_patch_with_msg 0001-sysconfig-make-_sysconfigdata.py-relocatable.patch \
  0002-build-add-with-nt-threads-and-make-it-default-on-min.patch \
  0003-Define-MS_WINDOWS-and-others-when-compiling-with-MIN.patch \
  0004-configure-add-MACHDEP-and-platform-on-MINGW.patch \
  0005-Add-default-configuration-for-MINGW.patch \
  0006-configure-enable-largefile-support-by-default-for-Mi.patch \
  0007-Add-PC-to-CPPFLAGS-and-to-SRCDIRS-on-Mingw.patch \
  0008-posixmodule.c-Define-necessary-headers-for-compiling.patch \
  0009-Build-winreg-by-default-when-compiling-for-MINGW.patch \
  0010-pyport.h-Add-support-for-MINGW.patch \
  0011-configure-add-options-so-that-shared-build-is-possib.patch \
  0012-Add-dynamic-loading-support-for-MINGW.patch \
  0013-Ignore-main-program-for-frozen-scripts-on-MINGW.patch \
  0014-Add-missing-library-for-multiprocessing-module.patch \
  0015-selectmodule-add-support-for-MINGW.patch \
  0016-setup.py-add-libraries-to-fix-compile-of-ctypes-on-M.patch \
  0017-Detect-winsock2-and-setup-_socket-module-on-MINGW.patch \
  0018-Enable-some-windows-specific-modules.patch \
  0019-sysconfig-MINGW-build-extensions-with-GCC.patch \
  0020-sysconfig-treat-MINGW-builds-as-POSIX-builds.patch \
  0021-Add-support-for-stdcall-without-underscore.patch \
  0022-Use-replace-instead-rename-to-avoid-failure-on-windo.patch \
  0023-Customize-site-for-MINGW.patch \
  0024-add-python-config-sh.patch \
  0025-setup.py-add-export_symbols-to-fix-compile-of-ctypes.patch \
  0026-mingw-prefer-unix-sep-if-MSYSTEM-environment-variabl.patch \
  0027-msys-cygwin-semi-native-build-sysconfig.patch \
  0028-sysconfig-mingw-sysconfig-like-posix.patch \
  0029-cross-dont-add-multiarch-paths-if-cross-compiling.patch \
  0030-mingw-use-backslashes-in-compileall-py.patch \
  0031-msys-convert_path-fix-and-root-hack.patch \
  0032-mingw-pdcurses_ISPAD.patch \
  0033-msys-monkeypatch-os-system-via-sh-exe.patch \
  0034-msys-replace-slashes-used-in-io-redirection.patch \
  0035-remove_path_max.default.patch \
  0036-dont-link-with-gettext.patch \
  0037-ctypes-python-dll.patch \
  0038-gdbm-module-includes.patch \
  0039-use-gnu_printf-in-format.patch \
  0040-mingw-fix-ssl-dont-use-enum_certificates.patch \
  0041-fix-using-dllhandle-and-winver-mingw.patch \
  0042-Add-AMD64-to-sys-config-so-msvccompiler-get_build_ve.patch \
  0043-MINGW-link-with-additional-library.patch \
  0044-install-msilib.patch \
  0045-fix-signal-module-build.patch \
  0046-build-build-winconsoleio-and-_testconsole.patch \
  0047-expose-sem_unlink.patch \
  0048-cygpty-isatty.patch \
  0049-disable-broken-gdbm-module.patch \
  0050-build-link-win-resource-files-and-build-pythonw.patch \
  0051-disable-readline.patch \
  0052-fix-isselectable.patch \
  0053-_xxsubinterpretersmodule.patch \
  0054-configure.ac-fix-inet_pton-check.patch \
  0055-set-venv-activate-path-unix.patch \
  0056-pass-gen-profile-ldflags.patch \
  0057-pkg-config-windows-must-link-ext-with-python-lib.patch \
  0058-importlib-bootstrap-path-sep.patch \
  0059-pathlib-path-sep.patch \
  0060-warnings-fixes.patch \
  0061-fix-build-testinternalcapi.patch \
  0062-extend-MS_WINDOWS-flag.patch \
  0063-clang-arm64.patch \
  0064-configure.ac-set-MINGW-stack-reserve.patch \
  0065-Don-t-use-os.pathsep-to-find-EOF.patch \
  0066-Fix-extension-suffix-for-c-extensions-on-mingw.patch \
  0067-Change-the-get_platform-method-in-sysconfig.patch \
  0068-distutils-compiler-customize-mingw-cygwin-compilers.patch \
  0069-distutils-compiler-enable-new-dtags.patch \
  0070-distutils-MINGW-build-extensions-with-GCC.patch \
  0071-distutils-use-Mingw32CCompiler-as-default-compiler-f.patch \
  0072-distutils-find-import-library.patch \
  0073-distutils-avoid-circular-dependency-from-time-module.patch \
  0074-distutils-generalization-of-posix-build-in-distutils.patch \
  0075-distutils-mingw-sysconfig-like-posix.patch \
  0076-distutils-get_versions-fixes.patch \
  0077-distutils-install-layout-as-posix.patch \
  0078-distutils-msys-convert_path-fix-and-root-hack.patch \
  0079-distutils-mingw-build-optimized-ext.patch \
  0080-distutils-cygwinccompiler-dont-strip-modules-if-pyde.patch \
  0081-distutils-get-compilers-from-env-vars.patch \
  0082-distutils-add-windmc-to-cygwinccompiler.patch \
  0083-distutils-fix-msvc9-import.patch \
  0084-distutils-mingw-add-LIBPL-to-library-dirs.patch \
  0085-distutils-Change-the-get_platform-method-in-distutil.patch \
  0086-build-Fix-ncursesw-include-lookup.patch \
  0087-tests-fix-test_bytes.patch \
  0088-time-fix-strftime-not-raising-for-invalid-year-value.patch \
  0089-ctypes-find_library-c-should-return-None-with-ucrt.patch \
  0090-build-Disable-checks-for-dlopen-dlfcn.patch \
  0091-Fix-install-location-of-the-import-library.patch \
  0092-Set-MSYS2_ARG_CONV_EXCL-for-the-shared-Python-module.patch \
  0093-build-Integrate-venvlauncher-build-installation-into.patch \
  0094-configure.ac-set-_WIN32_WINNT-version.patch \
  0095-configure.ac-don-t-check-for-clock_-functions.patch \
  0096-expanduser-normpath-paths-coming-from-env-vars.patch \
  0097-CI-test-the-build-and-add-some-mingw-specific-tests.patch \
  0098-Prefer-sysconfig.python_build.patch \
  0099-Define-PY3_DLLNAME-to-fix-build.patch \
  0100-distutils-remove-checks-for-ancient-gcc-binutils.patch \
  0101-distutils-split-CC-env-var-before-passing-to-subproc.patch \
  0102-_testconsole.c-Fix-casing-path-sep.patch \
  0103-Return-consistent-architecture-markers-for-python-on.patch \
  0104-distutils-add-back-gcc_version.patch \
  0105-fix-mingw-cross-compiling-in-setup.py.patch \
  0106-handle-ncursesw-pkg-config-when-cross-compiling.patch \
  0107-mingw_smoketests-fix-_UCRT-condition.patch \
  0108-Modify-sys.winver-to-match-upstream.patch \
  0109-Change-user-site-packages-path-to-include-the-enviro.patch \
  0110-configure-Include-a-header-in-the-check-for-_beginth.patch \
  0111-configure.ac-Default-to-without-c-locale-coercion-on.patch \
  0112-Fix-failing-tests.patch \
  0113-distutils-add-build-root-to-libdirs-when-building-un.patch \
  0114-Don-t-change-os.sep-with-an-empty-MSYSTEM-env-var-no.patch \
  0115-def-VPATH-when-compiling-Python-sysmodule.c.patch \
  0116-Make-_Py_CheckPython3-extern.patch \
  0117-link-with-bcrypt.patch \
  0118-correctly-find-native-python.patch \
  0119-Add-extra-flags-for-_bootstrap_python.patch \
  0120-posixmodule-undefine-HAVE_OPENDIR.patch \
  0121-getpath.py-add-support-for-mingw.patch \
  0122-Don-t-build-_posixsubprocess-on-Windows.patch \
  0123-_ssl-link-with-ws2_32.patch \
  0124-Fix-building-_socket-module.patch \
  0125-Always-normalize-path-in-abspath.patch \
  0126-Include-winsock.h-when-checking-for-netdb-function.patch \
  0127-include-_multiprocessing-semaphore.c-on-win32.patch \
  0128-configure-build-mmap-module-on-win32.patch \
  0129-venv-creation-fixes.patch \
  0130-move-the-shutdown-function-where-winsock.h-is-includ.patch \
  0131-configure.ac-set-BUILDEXEEXT-and-EXEEXT.patch \
  0132-configure.ac-fix-building-some-test-modules.patch \
  0133-Don-t-convert-sysconfig.get_config_var-VPATH-to-an-a.patch \
  0134-Always-convert-to-before-passing-though-pathcch-func.patch \
  0135-Build-venvlauncher.exe-from-PC-launcher.c.patch \
  0136-getpath.py-fix-dirname.patch \
  0137-gh-105821-Use-a-raw-f-string-in-test_httpservers.py-.patch
 
  autoreconf -vfi
}

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--enable-optimizations")
    # Upstream defaults to -O3, so we can do too
    CFLAGS+=" -O3"
    # FIXME: https://github.com/msys2-contrib/cpython-mingw/issues/10
    # _extra_config+=("--with-lto")
  else
    CFLAGS+=" -O0 -ggdb"
    CXXFLAGS+=" -O0 -ggdb"
    _extra_config+=("--with-pydebug")
  fi

  case "${CARCH}" in
    i686)
      LDFLAGS+=" -Wl,--large-address-aware"
    ;;
  esac

  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../Python-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --host=${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --enable-shared \
    --with-system-expat \
    --with-system-ffi \
    --with-system-libmpdec \
    --without-ensurepip \
    --enable-loadable-sqlite-extensions \
    --with-tzpath=${MINGW_PREFIX}/share/zoneinfo \
    "${_extra_config[@]}"

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  # Some basic tests to ensure nothing major or MSYS2 specific features are broken
  ./python.exe "../Python-${pkgver}/mingw_smoketests.py"
  MSYSTEM= ./python.exe "../Python-${pkgver}/mingw_smoketests.py"
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  make -j1 install DESTDIR="${pkgdir}"

  # gdb pretty printers for debugging Python itself; to use:
  # python
  # sys.path.append('C:/msys64/mingw64/share/gdb/python3')
  # import python_gdb
  # reload(python_gdb)
  # end
  if [[ "${_primary_python}" == "yes" ]]; then
    [[ -d "${pkgdir}${MINGW_PREFIX}"/share/gdb/python3/ ]] || mkdir -p "${pkgdir}${MINGW_PREFIX}"/share/gdb/python3/
    cp -f python.exe-gdb.py "${pkgdir}${MINGW_PREFIX}"/share/gdb/python3/python_gdb.py
  fi

  # some useful "stuff"
  install -dm755 "${pkgdir}${MINGW_PREFIX}"/lib/python${_pybasever}/Tools/{i18n,scripts}
  install -m755 "${srcdir}/Python-${pkgver}"/Tools/i18n/{msgfmt,pygettext}.py "${pkgdir}${MINGW_PREFIX}"/lib/python${_pybasever}/Tools/i18n/
  install -m755 "${srcdir}/Python-${pkgver}"/Tools/scripts/{README,*py} "${pkgdir}${MINGW_PREFIX}"/lib/python${_pybasever}/Tools/scripts/

  # fixup shebangs
  for fscripts in 2to3 2to3-${_pybasever} idle3 idle${_pybasever} pydoc3 pydoc${_pybasever}; do
    sed -i "s|$(cygpath -w ${MINGW_PREFIX} | sed 's|\\|\\\\|g')/bin/python${_pybasever}.exe|/usr/bin/env python${_pybasever}.exe|g" \
      "${pkgdir}${MINGW_PREFIX}"/bin/${fscripts}
  done

  # default aliases for all scripts/binaries
  if [[ "${_primary_python}" == "yes" ]]; then
    # Default names are aliases for Python now
    cp "${pkgdir}${MINGW_PREFIX}"/bin/python3.exe "${pkgdir}${MINGW_PREFIX}"/bin/python.exe
    cp "${pkgdir}${MINGW_PREFIX}"/bin/python3w.exe "${pkgdir}${MINGW_PREFIX}"/bin/pythonw.exe
    cp "${pkgdir}${MINGW_PREFIX}"/bin/python3-config "${pkgdir}${MINGW_PREFIX}"/bin/python-config
    cp "${pkgdir}${MINGW_PREFIX}"/bin/idle3 "${pkgdir}${MINGW_PREFIX}"/bin/idle
    cp "${pkgdir}${MINGW_PREFIX}"/bin/pydoc3 "${pkgdir}${MINGW_PREFIX}"/bin/pydoc
  fi

  # delete anything that could conflict with the primary Python
  if [[ "${_primary_python}" != "yes" ]]; then
    rm "${pkgdir}${MINGW_PREFIX}"/bin/python3.exe
    rm "${pkgdir}${MINGW_PREFIX}"/bin/python3w.exe
    rm "${pkgdir}${MINGW_PREFIX}"/bin/python3-config
    rm "${pkgdir}${MINGW_PREFIX}"/bin/idle3
    rm "${pkgdir}${MINGW_PREFIX}"/bin/pydoc3
    rm "${pkgdir}${MINGW_PREFIX}"/bin/2to3
    rm "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/python3-embed.pc
    rm "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/python3.pc
    rm "${pkgdir}${MINGW_PREFIX}"/share/man/man1/python3.1
  fi
}

sha256sums=('2f0e409df2ab57aa9fc4cbddfb976af44e4e55bf6f619eee6bc5c2297264a7f6'
            '7c38ba1d4a42333cbc135b2204f0dbfb7808d3154d32f872c73453b8c92be578'
            'c2924a50064a6812da5acd6517bcc338b7c50e2b820429857dcb8cc84a81bb31'
            'f59a2742da5b553ed3ee870f19bb70706258e32e0d0525dba0667c4211cef43a'
            '27d6f3c66df825f660fa846103eacb31dcca1245866385e686635a579e4058ba'
            'e0dadbd9bae1653253659699f2eeb701502145324be48f4f28542b66f7ba231e'
            'c46af613aef96fb9459e53759a8c7391d3998333a5313280f6ed53c4e7c479be'
            '7854a2d2c16991d70a8ae18b4038920cb8a418f88e70367c828841a8664ea5eb'
            '1375b577c7c77525a00fa369374730fe9dc7b2ed1c0fd3d3474b5d293bb47ec8'
            'aa64de1cf1a986f722fa4e4a1827dfa05446d952608a90bf4d97c4b8ad6e756e'
            '0e7b8141e7389db46612f42190b672d233ab20b154bd045362c8051c083485c6'
            '546dd070672e8bc78f9ccadc3fd7b08b13fb7b7b131b26d315763c608e9ed5ed'
            '63ba7bc7b8ae2e6fd10951cfd31b77e1769ed479a7b6dfbd1f31b1c789c3c575'
            '554b14ab9f1660b709b1c5274cd6b5bb30f1f36bcf6a1de8582495f7d7749de4'
            'ce77e7198d3d9e75ee14c1f2ae9ff413b3f231889a444d4d742b39151c7c8184'
            'bcc2a7551fb3af0adef402b6fc110fcc499b34890e682d14b48ffc75bfbc8cba'
            '2c20809a96b2694ba1d98e886142f08e7427696ab18c69892541a44556c0c83a'
            'e9a935385fe3fc378c0b2f1fd59ac28d6545fe8f9655cf2264f8fa89518c3efb'
            '3e807bc017e36432c94b65a2824ce1c3bbec9f43fb4adff43f5bcfca865967dc'
            '87ba4c3ef119f3c45c9e9f51635600c69e4d90ef7a40a59b1e31694b178c0d64'
            '07d915818221dab4e6ad614507b93b223313a24396d4f424c4ed69d299b3a2cf'
            '60f5002c7cdefa3d436d7abbde5d6eaeb7a208487d7cdf1f2c3ed2a7703e13f2'
            '4d016434aca07382f4dc1dd578c580b21dda7debff014ecdc79927cbf3ef4490'
            'a7ad07a1154f140c403441f0bec955749263d771103b6aacdafbea2b6f7d459d'
            '8083cd1e98d1ef36f43ee0f896c73223faf3936d6df0df1e0698e1e9c2445db7'
            'fbfd67c372ff851857ecc3589377656f3e01a026fff3848ada27ff4d79d2c312'
            '32b5f88d82b8da300a3b2d72de223b34d22d71c2c6149d28ab100a106f338618'
            '896e112075b98173023cc1f2d9c7b242ae6c5089028def0821ac11fbf444c758'
            'a54496dd4b1ce6d54138f5a7cc1e3bea3dfad20a54a211397eb4701cd5d082b3'
            '2fd5509427f145632df4df17a432703c41262cc96e5e5d1f1b5898037c3eef55'
            'e90fef74ea28742f6898eda1a97b219500f437054887541af1051bd23c11c35b'
            '23b80033f1ea0af7003e2f448e3302b268f048fe0e807ad53303f4aa8b2842a8'
            '645e4d7b84c92dc35ae42fe94419d977309ba66796c1bdb5b9d9f7515c846bdc'
            '77255284928cce6b7890ca681a6365da539cc0c7c702f7658aaab0dfd8ec602b'
            'f5c9e14cb55f0f0be2df342909104704e668ce3d573d1ca0b00fef256c6451f4'
            '0b4aff282cbc79b5fe2b1d39035876691ceb7d400721062d62c4b18398307cd9'
            '2d473e376d30dca18263d3e45052d342e1d06bb2543c5476928dd97168a66437'
            'ec9d0cee9e672bc6e2b0a4938ed6df659731a65ec8e9c57e91ef575b459c02c1'
            '42bf30b10bcdf1be78174b0816531a6bc7d777b9509eb76201d4345a04ba906a'
            'fb4041039f8f7c51bf7792d4e29742a1925bfe992c963cb7922286d5f42fa06a'
            '681c6eb5be82f986a7534ff2c6155e3fb8c8f94d68624c78faade14e0ad0d976'
            '73a2274fdc8f469fc4c688f3c23b40751d5be7c7d701e083c77569fff926c3fb'
            '685ca9049d2f859ecd7dd340de19ffcdbc44fdbe3918f0bc10195394ad749412'
            '5d5bc07ef9465a86fff53ddefff45b2e5256e9dc76f8ad4f525ef266942be262'
            'bcb1c6a50a82169bb63f78b0f03b10ad2c902f2c83935b418ef0062a24232adf'
            '4ee9ef6172936d5c6f4061381290cb51488e5bfbef82eb6996d3245312289101'
            '98c66483511061e43f1bbed5e08b741f38b2eaa4dbc1e78feac8da5f7f63ad3d'
            '59c3eb2b2010c975d6a5c08d20af4068124cab852d95de7fcbc11c2d8690ecdb'
            '3158b3d7f50e4d4b9bd140be44f0d503093aa5ac2b9156b6e2fb3ef4de6e07dd'
            '973fb7d13d1c26d432140159fc3eee5f9f6c2774307541dc66e658e9dc454c23'
            'e911bc084a58d6748aefa2aac4d86c8eaba8000eabeca61b5f362d01f682529e'
            '196972fa3f43973f33573040657e39aea5a1e566466e078541968f1a48fa8e70'
            'a0841b73f8ff7dd6511c4211d6cc2cbe8fdebb1bc3bcb362a8cfc78d5d4da693'
            '6afb535acecabed9caad09d67df9c10f1d630c22df55da6fd6dfcd5a66c0e57c'
            'f94e1fc91ec2c4d36fa660fb77b977d50bb4e4e9496e7a7138f68e30fc234489'
            '70d359e6e71f04fb70bef3a982a7ad5dade33f0c38a362987b89cdf9f772fe6d'
            '0ca2ec95ed223aa8ec6e7c487bd8049d20a3abc482ddad8945a61a6f31eef31f'
            '313bc469fe5d4a93ff708f7495bac70d003b3e743451202c713949dba651e9ef'
            'bb32104a8acf668c196773f5fc219a644f6a8aeec600259599c28a8878f53d0b'
            '22e8f22f8a873258f496c752130cb3d4fee894c3dcf4cb6c9a627cc6cc673a70'
            '09198b05ba58765a8dbca8806f0567f6c94b64f513c4a390b302b4675500da7b'
            '103ee3d0f657da0c57fedb274977701c51c55329c259061269df3ded2a12b800'
            'b3854006e567e405e0ab67551377080f2b400a2e5d6de18ba4ba5c95bd1e9446'
            '7c445306d076e5d3e26e151471908317a33a66f2822af719c893e89703311063'
            'b083ccec232a475ad30768dfbaa68817b5c3c452dc3b073bfdb1dc62247a403e'
            'f7e48a2d89ed4d4b9b75622b536960be56394b109ca9184cb20e9e40e87d6bd3'
            '969f6a83264e2eb1c560e5615f64b944993693bf1b6b44254b90e5e3901dc200'
            '0f8e3bb0e94e24c947335ab53bf5826a4f8af92f4816fa9bf7a52657cc77033d'
            '86111b3abad1cffe4139bca16a9e21926bb74ff5c1152aee601136634d0bb9cb'
            'f70781be78793157489870d674905000ba30242067a27d716c97a50463dc4265'
            '9eb2caea45fd12ec956c7b2c91857a3851ec98f6e255e04fd62d6e086b719516'
            '5d55673cf36cfd37d56c97c817c362b0008df6a71222b7dd7299710b135971ac'
            '975bfafd20817b1baca94215072c88e7aa5f7798356883252126d1e0de0b41b1'
            '7ad97517e3fe786312ffb19ee719a5c7edf05fb4f3b5397a841511d49d667554'
            'e6b931e2752067b48ac48e1719ffeb0e8ff09b85ca13c2efb0621338e9fc7734'
            '3af5dd26d89b1e1e002872b64876a9b4363509441ec7eff300b90e2fa88a8b9e'
            '5132f8a378cad41b14be871ad5f8fd7ca65c7a1b3d80265b2ce555b1d5e38e7b'
            '5b838668c4d643c9899f6f118a83cbf68ce29819b21cb59e9cba1b6f66d1f2d7'
            '969d3d3162e77b6731f3c55054a12d38cfb31f54ebc7be7bdefaa2d2ed5fec3f'
            '0678453ed5e8012e1b7bde4cbdb7cd24364ea54a9b9104d831551292428f53d4'
            '7379d6784878f7a8e39c157a2f52c28f7c6e73cac89ee138881ecb70b0a4b436'
            'b2d53a7691b1785d22c5f4a85c6e15740183d6d0aff9d58f0a72d93493f190b5'
            'ef4baaffec9eb8731bc34e4ff3bb26139fa81225b404a36d43e83d0aa44b4dd6'
            '2aebfa2dc23feb20ee711d7c07b1680847c1bb97bf27641ce18c7d2141efbd8c'
            '013d3b09f63779282b6302fcccf64a10963e7a1212f4d806857e90acfaf08b26'
            'a08284b8b84ef431b462615385287487025b75759071dc19a89561a288a29545'
            '870bf493d91bdb688f0ab255bc8d0597015b0e95d87e1871bb1611f6e3df223b'
            'ef063fd360483a25df4a2c289c0ee192af2931bb93e20f28e818b8507c43c797'
            'b79fe9d74de36d47c800edd630d87bb3d690137436236e5fca800618deb75190'
            '4a2ff1ef886094ddbb81c719127912068ed4a10cf226e2ca7188e6309d7a6482'
            '729d50d20837fb8c874be0fa4bab0b0daf74472fcc9c3422331a512bc8490b07'
            '4ee8d9ab31b98eacc28b295c1f1fa5757821dcd5a2f194bddee18ce448ef9e43'
            '107ef7dae9912e3618fa082f28b37d442857876e66a34a2ee5cd1fa67ffe18d0'
            '4c06ab55fb4dfed76afdba583bdf63ae2ca602d27ad29c249830dc582a6e9703'
            '1db64b6d648bfceffacbe189617b7b9aedd115924b53b8319dc28dcc9d013286'
            '5d4415776d65d470718618aae61177894e971f7e399cfd0033ea15a84bcc6608'
            '315ebe480f98e74a413aecdf2e024e16ba217130cc705a85e3ed2d6560567a8e'
            '760d2bde5f9313635618a75f760d420c80c150014e16f191766096e43475713b'
            '95d02d930c18c61de2e5353acaae01c21a3786e69c885f4613c8ee57327d5142'
            '931ee0d29fc870a27bf81343b4effd78c8eb29fd0b5a899237720e285974cd5f'
            '19e2d8f4033bcdb32542fbb78dd80607ebb2c34094feb9def64f2b51bbaf7d7a'
            'c3161ac9a8ae372b8dfa53e8a9090ac2e5db601c8357e65c81ae45150b1ffa59'
            '382421e90a0589447211a9b2077384660c1070c6a6989e5925fd1eeb3884b8f9'
            '62108048b871e39bdcc4a4744683e3287d53c95dce2ae24d6a778e0c824c4d2d'
            'f8fba7c352c7e7de5ccf5f3842b85a611905330c1a4015b52f23d69ac8f3f405'
            '4089def22a300d6030830d8a38d1012a96bc5fbf7ef43841293c032420497d5b'
            'e77ebeeb038226427503c8ce90fda687c98cfeed54374285bb5ee2e14565a717'
            '5193eb0c685cbf9ea0774141863502a1b0ed78128fb35fde1c56884ee7daa52b'
            '2931ac24439b8f27f11ec2424386c7e05d085a15df69841ad7f5702d429b1b70'
            'bd92f00f37cb9791b8bb016d6612d91f1fb5af60a926061be61a080f58caeb7c'
            '8dd61b4eabdd58b3e7d52b8228980527d984604f4d09953cbd0bb6b6e2db9ffa'
            '67af24993ffd96d03a0b6a78561f9f1831d60321e9cf6ba2c9d56ccb3a79bf44'
            '7ee8c71f2b4a572f19930f5092cb40248a608c8363bf1ad8b0d57c0d82b465fd'
            '1a640bfc9c93d9531f469f4bee06f04ef7908f2e5ebd29fd3db541be8a01bd13'
            'a056db2b15b2358e55b5955282fe94d84e2ddd632bf21e8bd52e40e198747ebc'
            'e63cfd594ad071378a6f04f73db64c8a9cd7841af160cd7f689f336736e85b6b'
            '49865455aab3c8179e73265956520be469b463b7e5372643ff0e9860e225ece4'
            '18cd4dd4974fe46f6d5c67d478757665febcdf283c6e63a9c4e1d5f21770ff19'
            '983d7b914f1fca00db3602bef855406ccafbcbaca1225ab646174e5460d201dd'
            '8d9fe440778cba0aafda19fca409f2dd386466e059b67bd45ee11b047c7dd7c9'
            'fd8be8e0eecb90ef496fdf618f08339ca2fcbb5691114030706448850c0f9660'
            '92625cc2d95a1c6f733c6a1c494c063da8c6322f4fd9fa9227613abb2c032824'
            '573727885013a41c49824ae39af3a9449b588c32223d8757c9252ee294bc6a74'
            '9657c6358e3273ad5846dbe1737cfa85c153cbcb72c305807eae5bedcc4c60ef'
            'faad5b6b177521ec6fa1b18856d36647b4ccbc22cc762cf45f29f5419723ae57'
            '2081d1b2a9427b69e7aa5cd2db4f10f835b6946c9f4eaa8d0933ae112c27eb39'
            '3c1f99a905a0c9f4a3b4d0c6cb6150386880ab17edc26a787a7a528d3915129d'
            'e6ea87a1d99b6cdf7733e11fefce876432949d0205aaac4986cce6e37624191c'
            'cea68d5f417e5381ccd622bf846b786c8f20b7c8a7b01d85bce922aab765aaad'
            '258be3a03defc465eaccfac227d3094e6ebe0dcd8f547efccf9c0560676d9cdb'
            '082f02aa3335d580189ac1a45e6fce61771c9121a49339a8d0caf341e033b14e'
            '015555ef165facec56952a971295ac1390883e103ca057290038fcb840ae5476'
            '509701ba03c12ef2115b9e795ef0a899b3334c4dce6e53d0bfac2c8969e69ed7'
            '3897c89f18094859a4396a73f684d5a28bdf4f91c4cc3217916ed9619cb3d268'
            'e8f50dcfa612ba12671b0ed834fb2d18f71585935f4eed4315726ee96aed52f9'
            '0553df59f5772410f7ce0bd6fffd082f90e1e9a2b065782f2bef1adb25ff2dd8'
            '07632fe995fec29b4ebd397d555bc0439707c2cbfe17b89673c76ec716f46f1b'
            'e1902d363b5c4ddf8c94a1892d13709423bd72c08423351b2c2e655fdad72a5a')
