# 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.10
_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}.5
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-restore-setup-config.patch
        0003-build-add-with-nt-threads-and-make-it-default-on-min.patch
        0004-MINGW-translate-gcc-internal-defines-to-python-platf.patch
        0005-MINGW-configure-MACHDEP-and-platform-for-build.patch
        0006-MINGW-preset-configure-defaults.patch
        0007-MINGW-configure-largefile-support-for-windows-builds.patch
        0008-MINGW-add-srcdir-PC-to-CPPFLAGS.patch
        0009-MINGW-init-system-calls.patch
        0010-MINGW-build-in-windows-modules-winreg.patch
        0011-MINGW-determine-if-pwdmodule-should-be-used.patch
        0012-issue6672-v2-Add-Mingw-recognition-to-pyport.h-to-al.patch
        0013-MINGW-configure-for-shared-build.patch
        0014-MINGW-dynamic-loading-support.patch
        0015-MINGW-ignore-main-program-for-frozen-scripts.patch
        0016-MINGW-setup-_multiprocessing-module.patch
        0017-MINGW-setup-select-module.patch
        0018-MINGW-setup-_ctypes-module-with-system-libffi.patch
        0019-MINGW-defect-winsock2-and-setup-_socket-module.patch
        0020-MINGW-exclude-unix-only-modules.patch
        0021-MINGW-setup-msvcrt-and-_winapi-modules.patch
        0022-sysconfig-MINGW-build-extensions-with-GCC.patch
        0023-MINGW-setup-_ssl-module.patch
        0024-MINGW-generalization-of-posix-build-in-sysconfig.py.patch
        0025-MINGW-support-stdcall-without-underscore.patch
        0026-use-replace-instead-rename-to-avoid-failure-on-windo.patch
        0027-MINGW-customize-site.patch
        0028-add-python-config-sh.patch
        0029-cross-darwin-feature.patch
        0030-mingw-system-libffi.patch
        0031-msys-mingw-prefer-unix-sep-if-MSYSTEM.patch
        0032-mingw-use-posix-getpath.patch
        0033-mingw-add-ModuleFileName-dir-to-PATH.patch
        0034-mingw-add-BUILDIN_WIN32_MODULEs-time-msvcrt.patch
        0035-msys-cygwin-semi-native-build-sysconfig.patch
        0036-sysconfig-mingw-sysconfig-like-posix.patch
        0037-build-_winapi-earlier-so-we-can-use-it-in-distutils-.patch
        0038-cross-dont-add-multiarch-paths-if-cross-compiling.patch
        0039-mingw-use-backslashes-in-compileall-py.patch
        0040-msys-convert_path-fix-and-root-hack.patch
        0041-allow-static-tcltk.patch
        0042-mingw-pdcurses_ISPAD.patch
        0043-builddir-fixes.patch
        0044-msys-monkeypatch-os-system-via-sh-exe.patch
        0045-msys-replace-slashes-used-in-io-redirection.patch
        0046-remove_path_max.default.patch
        0047-dont-link-with-gettext.patch
        0048-ctypes-python-dll.patch
        0049-gdbm-module-includes.patch
        0050-use-gnu_printf-in-format.patch
        0051-mingw-fix-ssl-dont-use-enum_certificates.patch
        0052-fix-using-dllhandle-and-winver-mingw.patch
        0053-Add-AMD64-to-sys-config-so-msvccompiler-get_build_ve.patch
        0054-MINGW-link-with-additional-library.patch
        0055-install-msilib.patch
        0056-fix-signal-module-build.patch
        0057-build-build-winconsoleio-and-_testconsole.patch
        0058-expose-sem_unlink.patch
        0059-cygpty-isatty.patch
        0060-disable-broken-gdbm-module.patch
        0061-build-link-win-resource-files-and-build-pythonw.patch
        0062-disable-readline.patch
        0063-fix-isselectable.patch
        0064-use-_wcsnicmp-instead-wcsncasecmp.patch
        0065-_xxsubinterpretersmodule.patch
        0066-sqlite3-module-defines.patch
        0067-configure.ac-fix-inet_pton-check.patch
        0068-set-venv-activate-path-unix.patch
        0069-venv-creation-fixes.patch
        0070-pass-gen-profile-ldflags.patch
        0071-pkg-config-windows-must-link-ext-with-python-lib.patch
        0072-importlib-bootstrap-path-sep.patch
        0073-pathlib-path-sep.patch
        0074-warnings-fixes.patch
        0075-fix-build-testinternalcapi.patch
        0076-extend-MS_WINDOWS-flag.patch
        0077-clang-arm64.patch
        0078-configure.ac-set-MINGW-stack-reserve.patch
        0079-Don-t-use-os.pathsep-to-find-EOF.patch
        0080-Fix-extension-suffix-for-c-extensions-on-mingw.patch
        0081-Change-the-get_platform-method-in-sysconfig.patch
        0082-distutils-compiler-customize-mingw-cygwin-compilers.patch
        0083-distutils-compiler-enable-new-dtags.patch
        0084-distutils-MINGW-build-extensions-with-GCC.patch
        0085-distutils-use-Mingw32CCompiler-as-default-compiler-f.patch
        0086-distutils-find-import-library.patch
        0087-distutils-avoid-circular-dependency-from-time-module.patch
        0088-distutils-generalization-of-posix-build-in-distutils.patch
        0089-distutils-mingw-sysconfig-like-posix.patch
        0090-distutils-get_versions-fixes.patch
        0091-distutils-install-layout-as-posix.patch
        0092-distutils-msys-convert_path-fix-and-root-hack.patch
        0093-distutils-mingw-build-optimized-ext.patch
        0094-distutils-cygwinccompiler-dont-strip-modules-if-pyde.patch
        0095-distutils-get-compilers-from-env-vars.patch
        0096-distutils-add-windmc-to-cygwinccompiler.patch
        0097-distutils-fix-msvc9-import.patch
        0098-distutils-mingw-add-LIBPL-to-library-dirs.patch
        0099-distutils-Change-the-get_platform-method-in-distutil.patch
        0100-build-Fix-ncursesw-include-lookup.patch
        0101-tests-fix-test_bytes.patch
        0102-time-fix-strftime-not-raising-for-invalid-year-value.patch
        0103-ctypes-find_library-c-should-return-None-with-ucrt.patch
        0104-build-Disable-checks-for-dlopen-dlfcn.patch
        0105-Fix-install-location-of-the-import-library.patch
        0106-Set-MSYS2_ARG_CONV_EXCL-for-the-shared-Python-module.patch
        0107-build-Integrate-venvlauncher-build-installation-into.patch
        0108-configure.ac-set-_WIN32_WINNT-version.patch
        0109-configure.ac-don-t-check-for-clock_-functions.patch
        0110-expanduser-normpath-paths-coming-from-env-vars.patch
        0111-Add-support-for-Windows-7-Python-3.10.patch
        0112-CI-test-the-build-and-add-some-mingw-specific-tests.patch
        0113-smoketests-test-that-_decimal-exists.patch
        0114-Prefer-sysconfig.python_build.patch
        0115-Define-PY3_DLLNAME-to-fix-build.patch
        0116-distutils-remove-checks-for-ancient-gcc-binutils.patch
        0117-distutils-split-CC-env-var-before-passing-to-subproc.patch
        0118-_testconsole.c-Fix-casing-path-sep.patch
        0119-Return-consistent-architecture-markers-for-python-on.patch
        0120-distutils-add-back-gcc_version.patch
        0121-fix-mingw-cross-compiling-in-setup.py.patch
        0122-Use-actions-setup-python-for-setting-up-correct-vers.patch
        0123-handle-ncursesw-pkg-config-when-cross-compiling.patch
        0124-CI-add-cross-llvm-mingw-jobs.patch
        0125-Skip-building-c-extensions-if-python-is-running-in-b.patch
        0126-mingw_smoketests-fix-_UCRT-condition.patch
        0127-CI-fix-sed-pattern-for-python-config.py-shebang.patch
        0128-Modify-sys.winver-to-match-upstream.patch
        0129-Change-user-site-packages-path-to-include-the-enviro.patch
        0130-Build-venvlauncher.exe-from-PC-launcher.c.patch
        0131-PC-launcher.c-Use-function-available-in-original-msv.patch
        0132-Add-a-test-for-checking-the-new-launchers.patch
        0133-Revert-Add-a-test-for-checking-the-new-launchers.patch
        0134-Revert-PC-launcher.c-Use-function-available-in-origi.patch
        0135-Revert-Build-venvlauncher.exe-from-PC-launcher.c.patch
        0136-configure-Include-a-header-in-the-check-for-_beginth.patch
        0137-configure.ac-Default-to-without-c-locale-coercion-on.patch
        0138-CI-remove-without-c-locale-coercion.patch
        0139-Commit-regenerated-importlib.patch
        0140-fixup-cygpty-isatty.patch
        0141-Fix-failing-tests.patch
        0142-distutils-add-build-root-to-libdirs-when-building-un.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-restore-setup-config.patch \
  0003-build-add-with-nt-threads-and-make-it-default-on-min.patch \
  0004-MINGW-translate-gcc-internal-defines-to-python-platf.patch \
  0005-MINGW-configure-MACHDEP-and-platform-for-build.patch \
  0006-MINGW-preset-configure-defaults.patch \
  0007-MINGW-configure-largefile-support-for-windows-builds.patch \
  0008-MINGW-add-srcdir-PC-to-CPPFLAGS.patch \
  0009-MINGW-init-system-calls.patch \
  0010-MINGW-build-in-windows-modules-winreg.patch \
  0011-MINGW-determine-if-pwdmodule-should-be-used.patch \
  0012-issue6672-v2-Add-Mingw-recognition-to-pyport.h-to-al.patch \
  0013-MINGW-configure-for-shared-build.patch \
  0014-MINGW-dynamic-loading-support.patch \
  0015-MINGW-ignore-main-program-for-frozen-scripts.patch \
  0016-MINGW-setup-_multiprocessing-module.patch \
  0017-MINGW-setup-select-module.patch \
  0018-MINGW-setup-_ctypes-module-with-system-libffi.patch \
  0019-MINGW-defect-winsock2-and-setup-_socket-module.patch \
  0020-MINGW-exclude-unix-only-modules.patch \
  0021-MINGW-setup-msvcrt-and-_winapi-modules.patch \
  0022-sysconfig-MINGW-build-extensions-with-GCC.patch \
  0023-MINGW-setup-_ssl-module.patch \
  0024-MINGW-generalization-of-posix-build-in-sysconfig.py.patch \
  0025-MINGW-support-stdcall-without-underscore.patch \
  0026-use-replace-instead-rename-to-avoid-failure-on-windo.patch \
  0027-MINGW-customize-site.patch \
  0028-add-python-config-sh.patch \
  0029-cross-darwin-feature.patch \
  0030-mingw-system-libffi.patch \
  0031-msys-mingw-prefer-unix-sep-if-MSYSTEM.patch \
  0032-mingw-use-posix-getpath.patch \
  0033-mingw-add-ModuleFileName-dir-to-PATH.patch \
  0034-mingw-add-BUILDIN_WIN32_MODULEs-time-msvcrt.patch \
  0035-msys-cygwin-semi-native-build-sysconfig.patch \
  0036-sysconfig-mingw-sysconfig-like-posix.patch \
  0037-build-_winapi-earlier-so-we-can-use-it-in-distutils-.patch \
  0038-cross-dont-add-multiarch-paths-if-cross-compiling.patch \
  0039-mingw-use-backslashes-in-compileall-py.patch \
  0040-msys-convert_path-fix-and-root-hack.patch \
  0041-allow-static-tcltk.patch \
  0042-mingw-pdcurses_ISPAD.patch \
  0043-builddir-fixes.patch \
  0044-msys-monkeypatch-os-system-via-sh-exe.patch \
  0045-msys-replace-slashes-used-in-io-redirection.patch \
  0046-remove_path_max.default.patch \
  0047-dont-link-with-gettext.patch \
  0048-ctypes-python-dll.patch \
  0049-gdbm-module-includes.patch \
  0050-use-gnu_printf-in-format.patch \
  0051-mingw-fix-ssl-dont-use-enum_certificates.patch \
  0052-fix-using-dllhandle-and-winver-mingw.patch \
  0053-Add-AMD64-to-sys-config-so-msvccompiler-get_build_ve.patch \
  0054-MINGW-link-with-additional-library.patch \
  0055-install-msilib.patch \
  0056-fix-signal-module-build.patch \
  0057-build-build-winconsoleio-and-_testconsole.patch \
  0058-expose-sem_unlink.patch \
  0059-cygpty-isatty.patch \
  0060-disable-broken-gdbm-module.patch \
  0061-build-link-win-resource-files-and-build-pythonw.patch \
  0062-disable-readline.patch \
  0063-fix-isselectable.patch \
  0064-use-_wcsnicmp-instead-wcsncasecmp.patch \
  0065-_xxsubinterpretersmodule.patch \
  0066-sqlite3-module-defines.patch \
  0067-configure.ac-fix-inet_pton-check.patch \
  0068-set-venv-activate-path-unix.patch \
  0069-venv-creation-fixes.patch \
  0070-pass-gen-profile-ldflags.patch \
  0071-pkg-config-windows-must-link-ext-with-python-lib.patch \
  0072-importlib-bootstrap-path-sep.patch \
  0073-pathlib-path-sep.patch \
  0074-warnings-fixes.patch \
  0075-fix-build-testinternalcapi.patch \
  0076-extend-MS_WINDOWS-flag.patch \
  0077-clang-arm64.patch \
  0078-configure.ac-set-MINGW-stack-reserve.patch \
  0079-Don-t-use-os.pathsep-to-find-EOF.patch \
  0080-Fix-extension-suffix-for-c-extensions-on-mingw.patch \
  0081-Change-the-get_platform-method-in-sysconfig.patch \
  0082-distutils-compiler-customize-mingw-cygwin-compilers.patch \
  0083-distutils-compiler-enable-new-dtags.patch \
  0084-distutils-MINGW-build-extensions-with-GCC.patch \
  0085-distutils-use-Mingw32CCompiler-as-default-compiler-f.patch \
  0086-distutils-find-import-library.patch \
  0087-distutils-avoid-circular-dependency-from-time-module.patch \
  0088-distutils-generalization-of-posix-build-in-distutils.patch \
  0089-distutils-mingw-sysconfig-like-posix.patch \
  0090-distutils-get_versions-fixes.patch \
  0091-distutils-install-layout-as-posix.patch \
  0092-distutils-msys-convert_path-fix-and-root-hack.patch \
  0093-distutils-mingw-build-optimized-ext.patch \
  0094-distutils-cygwinccompiler-dont-strip-modules-if-pyde.patch \
  0095-distutils-get-compilers-from-env-vars.patch \
  0096-distutils-add-windmc-to-cygwinccompiler.patch \
  0097-distutils-fix-msvc9-import.patch \
  0098-distutils-mingw-add-LIBPL-to-library-dirs.patch \
  0099-distutils-Change-the-get_platform-method-in-distutil.patch \
  0100-build-Fix-ncursesw-include-lookup.patch \
  0101-tests-fix-test_bytes.patch \
  0102-time-fix-strftime-not-raising-for-invalid-year-value.patch \
  0103-ctypes-find_library-c-should-return-None-with-ucrt.patch \
  0104-build-Disable-checks-for-dlopen-dlfcn.patch \
  0105-Fix-install-location-of-the-import-library.patch \
  0106-Set-MSYS2_ARG_CONV_EXCL-for-the-shared-Python-module.patch \
  0107-build-Integrate-venvlauncher-build-installation-into.patch \
  0108-configure.ac-set-_WIN32_WINNT-version.patch \
  0109-configure.ac-don-t-check-for-clock_-functions.patch \
  0110-expanduser-normpath-paths-coming-from-env-vars.patch \
  0111-Add-support-for-Windows-7-Python-3.10.patch \
  0112-CI-test-the-build-and-add-some-mingw-specific-tests.patch \
  0113-smoketests-test-that-_decimal-exists.patch \
  0114-Prefer-sysconfig.python_build.patch \
  0115-Define-PY3_DLLNAME-to-fix-build.patch \
  0116-distutils-remove-checks-for-ancient-gcc-binutils.patch \
  0117-distutils-split-CC-env-var-before-passing-to-subproc.patch \
  0118-_testconsole.c-Fix-casing-path-sep.patch \
  0119-Return-consistent-architecture-markers-for-python-on.patch \
  0120-distutils-add-back-gcc_version.patch \
  0121-fix-mingw-cross-compiling-in-setup.py.patch \
  0122-Use-actions-setup-python-for-setting-up-correct-vers.patch \
  0123-handle-ncursesw-pkg-config-when-cross-compiling.patch \
  0124-CI-add-cross-llvm-mingw-jobs.patch \
  0125-Skip-building-c-extensions-if-python-is-running-in-b.patch \
  0126-mingw_smoketests-fix-_UCRT-condition.patch \
  0127-CI-fix-sed-pattern-for-python-config.py-shebang.patch \
  0128-Modify-sys.winver-to-match-upstream.patch \
  0129-Change-user-site-packages-path-to-include-the-enviro.patch \
  0130-Build-venvlauncher.exe-from-PC-launcher.c.patch \
  0131-PC-launcher.c-Use-function-available-in-original-msv.patch \
  0132-Add-a-test-for-checking-the-new-launchers.patch \
  0133-Revert-Add-a-test-for-checking-the-new-launchers.patch \
  0134-Revert-PC-launcher.c-Use-function-available-in-origi.patch \
  0135-Revert-Build-venvlauncher.exe-from-PC-launcher.c.patch \
  0136-configure-Include-a-header-in-the-check-for-_beginth.patch \
  0137-configure.ac-Default-to-without-c-locale-coercion-on.patch \
  0138-CI-remove-without-c-locale-coercion.patch \
  0139-Commit-regenerated-importlib.patch \
  0140-fixup-cygpty-isatty.patch \
  0141-Fix-failing-tests.patch \
  0142-distutils-add-build-root-to-libdirs-when-building-un.patch
 
  autoreconf -vfi
}

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("--enable-optimizations")
    # 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

  [[ -d "${srcdir}/build-${CARCH}" ]] && rm -rf "${srcdir}/build-${CARCH}"
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"

  ../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-${CARCH}"

  # 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-${CARCH}"

  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=('8437efd5b106ef0a75aabfbf23d880625120a73a86a22ade4d2e2e68d7b74486'
            '8179ade28e913c666d6ec3aeb91e445af24673f0e5983578ab308011bab29229'
            '6215c693331d57a909738e03838d65e0ba0b69f2168d3147b47b2b705b850a7c'
            '1a95b4b1c852bcdbdd7f926ba2cef39bfe45c93f320fd98d30975549e30e34a1'
            'c92e6b3336b5f42373ca51f17d9841ca846fa75c5137ceefae3d069021695747'
            'e5c4cc4c15231f9726d6757c880569f0d1eee13f206398174e217da98372bb44'
            '694458c0525a183d6a654d89c093968aa625dbd32028aae0391497baa739d0d6'
            '18c483c6541be6db2f86e558608e96090446abeaac1002eb00c76fccbebe7070'
            '8002d624cae5ab684079cef52ea2950502e6dfbdd794f19f0ed8a707df6a45b6'
            '0c361cc8e246099c6afd38b0552a4ffb6fc6f2a524c26fa8877da5504c8bfa56'
            '8f3159cf4511cc9fb36bdd6932b7ddfca4ecb0b0d22bb163c6db2d00a311b892'
            '41eb733cb2f6c9f7d0e7fa187fb9a1bd6aa904ac77b019a4689ad23d380d74e7'
            'd31e31e92b9202d47143b2304b2da8611ec9836933e4ba7e9167d3a924d518e5'
            '1df5f640ccb98f28dca9875d6dd3a299587bfc986d0a3976f41c552cf2113deb'
            'e2eac3a7441b60b8559fe851468da7152ae55c25a638655c5c3f51b6a0940116'
            'e4db7043d238ede046e3774aa6061de6513abe640826a816340770ccf0711562'
            '082db2e2132376b16d475e4b1a3bf5630fbd80b645f485e0a50b3e8c2887bf02'
            'f057f65f0de5d6bcbdc7166c3a24233a9c5bd615e27e179e739579708290eb0b'
            'a8988b8ef2bcddc98e967e7d2e7c1c6f7133e62433a3c8ef942a70353c065dbc'
            '59910d2e67e690ee78f2dfc89de65b064ea2c2cd3ecb055466b4002762005ac8'
            '398292cdb26f31cd8c75d2ef18ae4decf3e5a9dd52bf8e8ff6b81e89ecc6df9d'
            '487aaf372987d6abf7db0201fb7cbe6f15e5355e123756eb435df2a66d239dce'
            '7de3fef1b2e6a2171bac65c2bd9738388b1e62bd9024b1ee3c1a5b85d5141779'
            'ea49584a7877300432da6b372d59b1c28b2b4314e9cc2d3f9809ecabd9e755f4'
            'c76129330c037916e7093174a522ba751794c76880461db0863090e792ba639e'
            '53c068a281a4090227af897e0918b61ec163ca737475d9795e14b3fca1be3657'
            '5c1a1371eb7ecd00ec22fcb7f0871e5851fa8943e1da93af3b04338bcfe8721b'
            '49d29ddd102b5838a0282fb6d534a42164ed23dc023849bfee41ac30e8f323b3'
            '03ad89d8e7425419dcba6de13956f11497c8372a0a9de568e79533934b0497ea'
            '6b8dbe6e413a1e77c3dcc9c5cb3097bfd0f02272b229253e925ad3abdc22d324'
            '1312aeea7667006be3a0bb3f7e7127295d80f58603f3092877f960e6259fa6f7'
            '97db86e3f70dd4b3a4b9d1c73969f3558d44d948d5945166390f03e4139ddb22'
            '94f3759a71a66058915b07d4caaf646aa55749399d8d09df0f1197f270178121'
            '8391d7740214c927bd66236ddc15d2379f630a09a9a02b10880320c73000ce22'
            'e7b0b2fe715da7c7d35308bcff94c8acc4645156d5746129e05197eda6979b1b'
            '294bfe6a0475a8c0b973cb6f7fade020a8ee53754825f8f9eb0b660b3822b795'
            'aa6b408832094ea616a90e06d3a598006e3d76c5d7ae9324c54b00921d6cedb8'
            '0858220e65157b16ab736f5ef7c68b24751e5df19d8b823b9d2539b18c52746f'
            'e7adef72fdc63d2602afb89894fd9306ef8d1716e5a8e1ab90a99b6d475e5502'
            'cc7ff916cd1594df8501d0e42e6806ec1723953a5de53b79ea00d1d24277d60e'
            '76b2a13dc029bf85bd19722f70c07a553736b9593d9cbf5ebb43247f3c7a7244'
            'ab8906966c9e507bc84a09bce71900c84fe75d5057b8964b2af48ed261f8786c'
            '6c8e87fa80b45a817220bf2eea41301370037a9c1a1fd4b162e9971291e01ee2'
            'db9ceae0f1e66c84135104ccbfb17050dcb4bc5f9f448ba15eaaf7c68645a2a4'
            'cf4376c66235cd4b770a953a27cb0ac025151700dae61517582c9593363d9325'
            '3c694c395d826267b641ae835acd757f3e512496a2965388ca19fca1acedb983'
            'a19ed7149e8ff7d63aa978da0819631edb59f190a3cb44d3c449dda5b91dfaa5'
            '74d39dcfdd151f38c3c656f3d6bfde639e16103b5239aeb998f1890eda113e10'
            'bbac7af0cb17c4e592439137b495c1f193a6b7f0f4fa7a3c208113f7a8e7eb9a'
            '06ba6927270fd0a12470a6c983cb22d43cfd67b925bec3df14f90a85fe5ffefe'
            '56c7f3604422a6ba6d1d03bfc42ad04622cc825eb52bc11e932d3f9a5904184f'
            '44ba5bc0caf933302434bc6e07b22b99b03852503dea54f6419b2e3b2512a4b5'
            'eb0255a6bd260e7c444dc425c1173d813f8a4f701910b402d8513abd8cadebac'
            '2a213ec7588f253a15aa3a2379a2234fc7df918a28a10c5c1fc392bee479e0bc'
            '5c8d8afd15f527091f23520983bb70374676c31f2792199ab2d477e3ac6bcfcb'
            'ee4234ca3eb6aa613e0a819aa1c62b118114b73701c78cb671a116e83fdea49a'
            '83a04542c51804eeaa95c6e0b609bc828be57a1e765e6d52840c2a67dc16b9f8'
            'b93da93a21e6c7180c1a439e89d1e38eff4943f4ad87c4fb869183ba06df73e2'
            '268292f77d09fb574895dacdd665609bda5635813f78ea555c55b6d553acba59'
            '856a900a257e13d999e9772d0e6cffa9e32e4dd0c94a04a1e54ee1a49b15ced2'
            '969acf62b483b4f93f3e3409cf380c4a2ff78f4b97e8e63991d71ca3b36b5a6f'
            'ce8e36db34260f6ee60f495e08295e160282b2338f87dc47b00d39cd07b0f764'
            '6b0358f7afe1e564c2074714b480c5ae3eb48164e54972063810d6dfb9c69741'
            'cbdeba0f43d3dcc68598e9e7c965591a5837f3cbb7e06af8868a9a70e8c2af07'
            '7bb6b9ede91ec46085103ccdf61bd7a1ee012b234e945959c9c5e6f63b44a214'
            '83b2dae29b3c0cbd0739e98ff3914b3259f2201c570e4090f955296944180d61'
            '6e9715b10b1f5969aa7ccc990846561d7f5f7d263b014ee865fa6c61ae0f3ba5'
            '8ea7007cdfbb3284ef295ef8ec4ad396ebfaf17bcdb884630759533567a25781'
            '698b9c5ec98d74c82e0187385d726ad24fef0329ff9c16b7a9a8d3c1e3f5459c'
            'f09adc9624db9f1f153b421b0da9a3abe8505a7d9c47c4dcef8e360a4f6337b7'
            '0c6dda49fd846fcbe48d7cd67e4cfc89d124f4ec4705b8f6f2110238deeeb812'
            'fccc437c4ec57441ec8c96e822255d2107964d451337176a1fef1f06940efa69'
            '392fa6cb36c3a0e8a0d3381cc34c7fe41b2f90f7f031fc20e512a39fb08cbb1c'
            '576928325ef7341e6a913360c1d3f9d58ef61e9570d6abcd8f602364d81f9fca'
            'd6f1839bffaf6621bb5fa7a80bf48dfd279da31f7324013d1912e6546682cddd'
            '59c550ef19d8bdfdece93f2be933ae93455ddc8e53bde3f46f3f274375a26708'
            '6e07373a2dd56c7b3076c841db8cad8f3a73090fa1ae8cae639e673d97afff72'
            '5a2b9aab82f5dba4478bfc978d468a74d8defd47ac176999b9d08d449b64d107'
            'ca3bb9647f624a3c97e0712e9bda0bcfc322b5d0d5a049d2b3bbb96a5071e313'
            'c890e010cf518495b551b97b53fc15d5fb048bb84f1e0159bd15a649b08ec1dd'
            'a7c3c9f2addd841d93a2a7ed4786833d117fa5861742d85e1b7eaa86c11e146f'
            '1c2b674196759afc2a27a626d247fc518f319541defec4dee3951691f717bb02'
            'd2e9c7a069fd79ccf293cb0d4d217f5bdb34af9461500b7e51b6fa2cc80b1cf1'
            'dd471fb3ac570d5642dc4069193e96d4ee4a5ff3354f5277c2caed1d46fa731d'
            '31ace548f9f96426a398e94fb3add7caa39ec4e43afc4b16d33babd7e2c077fe'
            '37111bb5140be3e0f8e6d6b41925d303ae2d567201b9a2ff86f2a01f3c3bd5b7'
            'c111516d3f76d06d5d8541a7275fe9c4b02fb4e57d5e1e67f22532a5d3a14740'
            '3dcf30c73560a889419f9a0d1f8a25ae94ff183c460c3a7dd828bce4d7004437'
            '5c0f52bac3b761cff67add5af3a449af8c311a0998f51f2bc85cb769e3f8db07'
            '9fb6c7c85503b88ef78f69a976a403b92a317dc36033995f0f868dbd3fa3e8c4'
            '9803fd3de6262d40685e6336d75eb88c5adc782239d2cdeaebe725c14952ae87'
            '499b4851aa1f303eb4f2427f87b356e6d62846e1796d5a878285963e84a1e05e'
            '810e9ac1dccdc3ad88910d5d68284c175daafb7dafbb7af95ce7e8f7201a4c60'
            'e224f1cafbef386282cb47aeecdf8d7b699afd4443e553e04c2b354a61bfa426'
            'c3071926ec2519e53abcf43cfb68a0042a8fe09a70be57febf38d4bbefbe0547'
            '38aa9dd83bd0187412e45c82ce6a4a579a67b8ba0ce7c8110a2b3798695ced04'
            '7ddbef8acbb527290758eb811866aae094ce643be5311b4b74bd40cecd3cade3'
            '905ce1e0d9a5d6bff42bdcc94f1421e04c7ddfe4b418d524afc438a484a0be5e'
            'f91f5a0e7f0c039036a4ae615a0e651282bacbf72ebc896c646db94c8c5fb820'
            'a70db3ef033a57263e336b2be71e28a669c02e9acbae8908c4bed1b2fdaa03f9'
            '6506d7726b6ae2cdfcd04ce74fd61005e3c3d9833ae785ec6d8563856487f20f'
            'b5a67f11381e2400016e212e7991ecd7c56cd2a285e433bfc6ae49e808b47624'
            'e000fcbcf1f10994ca7f220cc5031e67ebef1301e25dc626a163bff3d61c682c'
            'fbb9cdd4733e3e167af4ac99d78d33e11fb6b84ed4794ae89b63c885b7af9d88'
            '84653556f9d5457788268057c4c9db238e8afeeb0a15381e2433a07024593b5c'
            '9003f81a8a842e23bf57c1c5d575e9aff295b28ffa841cee045c45fe929433a9'
            '666819a7bba15dd2f40a38dca729817777f1d6d0b14821838bb8282e8969dad0'
            'ba25ebf0d98acaf37e25f0a654dead307bc303f512ac5f97466a1335229b3472'
            'cbc342a4580678c31ec8a770baebc2149b0bdd08e8fb7c52a177df87f8ede591'
            '2ea6f5cd8af168f4ae899509562a6e7c606f9a5ead123e76e344a74eaf58635c'
            'bd77affb9d4e9e803235f6d47f0d85c33d5b8e3f22f772eb2453c88b9e1c652a'
            'a1db8cf604ee8728e4a8c210638edcffcdabb11af3a3cc4e334b5c0461659c4e'
            '254feb446692029e05b51ce15a9548fcb6e56bef183d6b8bb8b23e83d960bee2'
            '536256c1e767245ff121077a365b792269758aeada8231de574bf5f9d421bfd2'
            '14dad5647116d552eb3360d2b85ad45116ea2d6e8fbceae7424e0303b3591db8'
            '618c244176587b1dacfe5159140588b2b71ee050be3c587cb1e7ce7b79443273'
            '75276bd46003ba9961999653df5b50b5c47ba8893eebba83116d1bfd3ebb9e85'
            'c569d7da18fc2c54fdb7d3849a4cd09d20e4dae09cb3e1cc7d8967a8fc33be88'
            '3d941a4f9cbbb54840d355605529e9eba6dc3f16f3b505d9e3d88769019c93c9'
            '989fda2d113974fb32460e9b3deca08eb8e8f92bd889435653ed12a6e57247d3'
            'c2d53ff9edff55ede5b422d1fcf39634f693dcb47f71e55803ec4c2c703e93e3'
            'a215825182ddbdea82741599294b706ffbb3c6e9a4afa2131df486fc1a2f7251'
            '1b4271bdd600511386d6fa73116b5004aecf988718110363ce439219a3a5c63e'
            '42bd8900d2bdf61b2e9394aa71eeae1734289cdfb579d840b9367f1ada8a5d76'
            '0c6ed1ef95eba1b3700d3d5e328bd90592990b799f91675fc5876f69bbd6f97e'
            '882b2a1a7806ee99d674b127268d8e250d7760fc7cc3b011af9c6b1547ca49bc'
            '9e14f9f562cca4cb3b15fe3ab96c5372495d2dea0a5ab1957a97ba5c8aa5983b'
            'fb83985c92386bbd255cb1a504dab17b363de50a9f60460afd1c510d1cf05b1f'
            'c7a2d8b8ff8bfa82d6211ef191d24fae5c50cd57229ab62614d763fc4dcab207'
            '39b82294d0bcbcf1bd25f63700d599be71bba9552fd42593e53672de9bf1491e'
            '79a586c3c5520555ccf245139a8cf8222412847120036e2031a254c9b0baeae9'
            '4aaa2e7cda6f7713f738bd255e232796f8c0895074ea621b95639a9495272ac9'
            '5109ade01feac9af80db0e663aca973fc56c372ec0743ba9aa3f0f0a8d3d746a'
            'afdab668539ecc7bf26ddf4aa44037566f5bea33ac654f789caf3d918ac56bba'
            'aaef2f1279204b5aa06e4854b437f6dad35d1aec6e99a3dd9c1eb6271b9f66a3'
            'ec4b4cded1c7f9859c1461868d594d4a7e5e6d691f4b96fcedf7001ec832d09e'
            'eb44d038eafdb3f2f29ccaa16493b93c71bbd205761cd03540164c17e351061d'
            '5a34503b5dbf27d7569a0154057f3607066e598d71358d297618022bfb011842'
            '73f888b8cc71dc12460530ed46a349044b70b04f78c4abcf2a710f9dd12405b1'
            '2ffd218b1e4b20e70e21f880f7949e5f7b811ffdd3d1897880c7f5221737dc3b'
            '88420b76eb5fabf6062bd2af390a51bf5c392cbeb84e8cbc8232d6fa11c4cd42'
            '71ead9b8932aee75793e3e3e168bcb2dd5996933510156719325c47158b179a4'
            '674d5111a7fde354a238b97676ac617b2896693c205813590129d88cd933e743')
