Blob Blame Raw
%{?mingw_package_header}

%global pkgname python2
%global py_ver 2.7
%define mingw32_py2_libdir       %{mingw32_libdir}/python%{py_ver}
%define mingw64_py2_libdir       %{mingw64_libdir}/python%{py_ver}
%define mingw32_py2_hostlibdir   %{_prefix}/%{mingw32_target}/lib/python%{py_ver}
%define mingw64_py2_hostlibdir   %{_prefix}/%{mingw64_target}/lib/python%{py_ver}
%define mingw32_py2_incdir       %{mingw32_includedir}/python%{py_ver}
%define mingw64_py2_incdir       %{mingw64_includedir}/python%{py_ver}
%define mingw32_python2_sitearch %{mingw32_libdir}/python%{py_ver}/site-packages
%define mingw64_python2_sitearch %{mingw64_libdir}/python%{py_ver}/site-packages

# Some of the files below /usr/lib/pythonMAJOR.MINOR/test  (e.g. bad_coding.py)
# are deliberately invalid, leading to SyntaxError exceptions if they get
# byte-compiled.
%global _python_bytecompile_errors_terminate_build 0

Name:          mingw-%{pkgname}
Version:       2.7.16
Release:       1%{?dist}
Summary:       MinGW Windows %{pkgname}

BuildArch:     noarch
License:       Python
URL:           https://www.python.org/
Source0:       http://www.python.org/ftp/python/%{version}/Python-%{version}.tar.xz

## From https://github.com/Alexpux/MINGW-packages/tree/master/mingw-w64-python2
# Ray Donnelly's should-be-upstreamed patches
Patch0:        0000-make-_sysconfigdata.py-relocatable.patch
Patch1:        0001-fix-_nt_quote_args-using-subprocess-list2cmdline.patch
# Roumen Petrov's core patches
Patch2:        0100-MINGW-BASE-use-NT-thread-model.patch
Patch3:        0110-MINGW-translate-gcc-internal-defines-to-python-platf.patch
Patch4:        0120-MINGW-use-header-in-lowercase.patch
Patch5:        0130-MINGW-configure-MACHDEP-and-platform-for-build.patch
Patch6:        0140-MINGW-preset-configure-defaults.patch
Patch7:        0150-MINGW-configure-largefile-support-for-windows-builds.patch
Patch8:        0160-MINGW-add-wincrypt.h-in-Python-random.c.patch
Patch9:        0180-MINGW-init-system-calls.patch
Patch10:       0190-MINGW-detect-REPARSE_DATA_BUFFER.patch
Patch11:       0200-MINGW-build-in-windows-modules-winreg.patch
Patch12:       0210-MINGW-determine-if-pwdmodule-should-be-used.patch
Patch13:       0220-MINGW-default-sys.path-calculations-for-windows-plat.patch
Patch14:       0230-MINGW-AC_LIBOBJ-replacement-of-fileblocks.patch
# Roumen Petrov's compiler patch
Patch15:       0250-MINGW-compiler-customize-mingw-cygwin-compilers.patch
# Roumen Petrov's extensions patches
Patch16:       0270-CYGWIN-issue13756-Python-make-fail-on-cygwin.patch
Patch17:       0290-issue6672-v2-Add-Mingw-recognition-to-pyport.h-to-al.patch
Patch18:       0300-MINGW-configure-for-shared-build.patch
Patch19:       0310-MINGW-dynamic-loading-support.patch
Patch20:       0320-MINGW-implement-exec-prefix.patch
Patch21:       0330-MINGW-ignore-main-program-for-frozen-scripts.patch
Patch22:       0340-MINGW-setup-exclude-termios-module.patch
Patch23:       0350-MINGW-setup-_multiprocessing-module.patch
Patch24:       0360-MINGW-setup-select-module.patch
Patch25:       0370-MINGW-setup-_ctypes-module-with-system-libffi.patch
Patch26:       0380-MINGW-defect-winsock2-and-setup-_socket-module.patch
Patch27:       0390-MINGW-exclude-unix-only-modules.patch
Patch28:       0400-MINGW-setup-msvcrt-module.patch
Patch29:       0410-MINGW-build-extensions-with-GCC.patch
Patch30:       0420-MINGW-use-Mingw32CCompiler-as-default-compiler-for-m.patch
Patch31:       0430-MINGW-find-import-library.patch
Patch32:       0440-MINGW-setup-_ssl-module.patch
Patch33:       0460-MINGW-generalization-of-posix-build-in-sysconfig.py.patch
Patch34:       0462-MINGW-support-stdcall-without-underscore.patch
Patch35:       0480-MINGW-generalization-of-posix-build-in-distutils-sys.patch
Patch36:       0490-MINGW-customize-site.patch
# Ray Donnelly's general/cross patches
Patch37:       0500-add-python-config-sh.patch
Patch38:       0510-cross-darwin-feature.patch
Patch39:       0520-py3k-mingw-ntthreads-vs-pthreads.patch
Patch40:       0530-mingw-system-libffi.patch
Patch41:       0540-mingw-semicolon-DELIM.patch
Patch42:       0550-mingw-regen-use-stddef_h.patch
Patch43:       0560-mingw-use-posix-getpath.patch
Patch44:       0565-mingw-add-ModuleFileName-dir-to-PATH.patch
Patch45:       0570-mingw-add-BUILDIN_WIN32_MODULEs-time-msvcrt.patch
Patch46:       0580-mingw32-test-REPARSE_DATA_BUFFER.patch
Patch47:       0590-mingw-INSTALL_SHARED-LDLIBRARY-LIBPL.patch
Patch48:       0600-msys-mingw-prefer-unix-sep-if-MSYSTEM.patch
Patch49:       0610-msys-cygwin-semi-native-build-sysconfig.patch
Patch50:       0620-mingw-sysconfig-like-posix.patch
Patch51:       0630-mingw-_winapi_as_builtin_for_Popen_in_cygwinccompiler.patch
Patch52:       0640-mingw-x86_64-size_t-format-specifier-pid_t.patch
Patch53:       0650-cross-dont-add-multiarch-paths-if-cross-compiling.patch
Patch54:       0660-mingw-use-backslashes-in-compileall-py.patch
Patch55:       0670-msys-convert_path-fix-and-root-hack.patch
Patch56:       0690-allow-static-tcltk.patch
Patch57:       0710-CROSS-properly-detect-WINDOW-_flags-for-different-nc.patch
Patch58:       0720-mingw-pdcurses_ISPAD.patch
Patch59:       0740-grammar-fixes.patch
Patch60:       0750-Add-interp-Python-DESTSHARED-to-PYTHONPATH-b4-pybuilddir-txt-dir.patch
Patch61:       0760-msys-monkeypatch-os-system-via-sh-exe.patch
Patch62:       0770-msys-replace-slashes-used-in-io-redirection.patch
Patch63:       0790-mingw-add-_exec_prefix-for-tcltk-dlls.patch
Patch64:       0800-mingw-install-layout-as-posix.patch
Patch65:       0820-mingw-reorder-bininstall-ln-symlink-creation.patch
Patch66:       0830-add-build-sysroot-config-option.patch
Patch67:       0840-add-builddir-to-library_dirs.patch
Patch68:       0845-Remove-compiler-lib-dirs-from-extension-lib-dirs.patch
Patch69:       0850-cross-PYTHON_FOR_BUILD-gteq-276-and-fullpath-it.patch
Patch70:       0855-mingw-fix-ssl-dont-use-enum_certificates.patch
Patch71:       0860-mingw-build-optimized-ext.patch
Patch72:       0870-mingw-add-LIBPL-to-library-dirs.patch
Patch73:       0910-fix-using-dllhandle-and-winver-mingw.patch
Patch74:       0970-Add-AMD64-to-sys-config-so-msvccompiler-get_build_version-works.patch
Patch75:       0980-mingw-readline-features-skip.patch
# Alexey Pavlov's mingw-w64 patches
Patch76:       1000-dont-link-with-gettext.patch
Patch77:       1010-ctypes-python-dll.patch
Patch78:       1020-gdbm-module-includes.patch
Patch79:       1030-use-gnu_printf-in-format.patch
Patch80:       1040-install-msilib.patch
Patch81:       1050-skip-add-db-includes-for-win.patch
# Renato Silva's patch to distutils
Patch82:       2000-distutils-add-windmc-to-cygwinccompiler.patch
Patch83:       2700-cygpty-isatty-disable-readline.patch

# Own patches:
# Fix FTBFS due to missing libs
Patch84:       3000-scoketmodule-libs.patch
# Also build the winreg module, adapted from https://bugs.python.org/issue17600
#Patch85:       3001-mingw-winreg.patch
# Fix PYFORMAT_LONG_LONG not defined, caused by configure test failing due to use of uninitialized variable
Patch86:       3002-pyformat_long_long.patch


BuildRequires: automake autoconf libtool
BuildRequires: python2-devel

BuildRequires: mingw32-filesystem >= 102
BuildRequires: mingw32-gcc
# Needed for correct value of CXX in _sysconfigdata.py
BuildRequires: mingw32-gcc-c++
BuildRequires: mingw32-bzip2
BuildRequires: mingw32-dlfcn
BuildRequires: mingw32-expat
BuildRequires: mingw32-libffi
BuildRequires: mingw32-openssl
BuildRequires: mingw32-readline
BuildRequires: mingw32-sqlite
BuildRequires: mingw32-tcl
BuildRequires: mingw32-tk
BuildRequires: mingw32-zlib

BuildRequires: mingw64-filesystem >= 102
BuildRequires: mingw64-gcc
# Needed for correct value of CXX in _sysconfigdata.py
BuildRequires: mingw64-gcc-c++
BuildRequires: mingw64-bzip2
BuildRequires: mingw64-dlfcn
BuildRequires: mingw64-expat
BuildRequires: mingw64-libffi
BuildRequires: mingw64-openssl
BuildRequires: mingw64-readline
BuildRequires: mingw64-sqlite
BuildRequires: mingw64-tcl
BuildRequires: mingw64-tk
BuildRequires: mingw64-zlib


%description
MinGW Windows %{pkgname} library.


%package -n mingw32-%{pkgname}
Summary:       MinGW Windows %{pkgname} library
Requires:      python2

%description -n mingw32-%{pkgname}
MinGW Windows %{pkgname} library.


%package -n mingw64-%{pkgname}
Summary:       MinGW Windows %{pkgname} library
Requires:      python2

%description -n mingw64-%{pkgname}
MinGW Windows %{pkgname} library.


%{?mingw_debug_package}


%prep
%setup -q -n Python-%{version}

# these are created by patches
rm -f Misc/config_mingw \
    Misc/cross_mingw32 \
    Misc/python-config.sh.in \
    Misc/cross_mingw32 \
    Misc/python-config-u.sh.in \
    Python/fileblocks.c \
    Lib/list2cmdline.py

%patch0 -p1
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%patch7 -p1
%patch8 -p1
%patch9 -p1
%patch10 -p1
%patch11 -p1
%patch12 -p1
%patch13 -p1
%patch14 -p1
%patch15 -p1
%patch16 -p1
%patch17 -p1
%patch18 -p1
%patch19 -p1
%patch20 -p1
%patch21 -p1
%patch22 -p1
%patch23 -p1
%patch24 -p1
%patch25 -p1
%patch26 -p1
%patch27 -p1
%patch28 -p1
%patch29 -p1
%patch30 -p1
%patch31 -p1
%patch32 -p1
%patch33 -p1
%patch34 -p1
%patch35 -p1
%patch36 -p1
%patch37 -p1
%patch38 -p1
%patch39 -p1
%patch40 -p1
%patch41 -p1
%patch42 -p1
%patch43 -p1
%patch44 -p1
%patch45 -p1
%patch46 -p1
%patch47 -p1
%patch48 -p1
%patch49 -p1
%patch50 -p1
%patch51 -p1
%patch52 -p1
%patch53 -p1
%patch54 -p1
%patch55 -p1
%patch56 -p1
%patch57 -p1
%patch58 -p1
%patch59 -p1
%patch60 -p1
%patch61 -p1
%patch62 -p1
%patch63 -p1
%patch64 -p1
%patch65 -p1
%patch66 -p1
%patch67 -p1
%patch68 -p1
%patch69 -p1
%patch70 -p1
%patch71 -p1
%patch72 -p1
%patch73 -p1
%patch74 -p1
%patch75 -p1
%patch76 -p1
%patch77 -p1
%patch78 -p1
%patch79 -p1
%patch80 -p1
%patch81 -p1
%patch82 -p1
%patch83 -p1
%patch84 -p1
#patch85 -p1
%patch86 -p1

autoreconf -vfi

# Temporary workaround for FS#22322
# See https://bugs.python.org/issue10835 for upstream report
#sed -i "/progname =/s/python/python${_pybasever}/" Python/pythonrun.c

# Enable built-in SQLite module to load extensions (fix FS#22122)
sed -i "/SQLITE_OMIT_LOAD_EXTENSION/d" setup.py

# FS#23997
sed -i -e "s|^#.* /usr/local/bin/python|#!/usr/bin/env python2|" Lib/cgi.py

sed -i "s/python2.3/python2/g" Lib/distutils/tests/test_build_scripts.py Lib/distutils/tests/test_install_scripts.py Tools/scripts/gprof2html.py

touch Include/graminit.h
touch Python/graminit.c
touch Parser/Python.asdl
touch Parser/asdl.py
touch Parser/asdl_c.py
touch Include/Python-ast.h
touch Python/Python-ast.c
echo \"\" > Parser/pgen.stamp

# Ensure that we are using the system copy of various libraries (expat, zlib and libffi),
# rather than copies shipped in the tarball
rm -r Modules/expat
rm -r Modules/zlib
rm -r Modules/_ctypes/{darwin,libffi}*

# An include which is otherwise not found
(cd Include && ln -s ../PC/errmap.h)


%build
mkdir build_win32
(
cd build_win32
export OPT="%mingw32_cflags -D_GNU_SOURCE -fwrapv -D__USE_MINGW_ANSI_STDIO=1"
export CXXFLAGS="$OPT"
export CFLAGS="$OPT `mingw32-pkg-config --cflags openssl`"

export LDFLAGS="%{mingw32_ldflags}"
export LDFLAGS="$LDFLAGS `mingw32-pkg-config --libs-only-L openssl`"

export CC="%{mingw32_cc}"
export LINKCC="%{mingw32_cc}"

export LIBFFI_INCLUDEDIR=`mingw32-pkg-config libffi --cflags-only-I | sed "s|\-I||g"`

# Workaround for conftest error on 64-bit builds
# export ac_cv_working_tzset=no

MSYSTEM=MINGW %mingw32_configure \
--enable-shared \
--with-threads \
--with-system-expat \
--with-system-ffi
#--with-dbmliborder='gdbm:ndbm'

%mingw32_make %{?_smp_mflags} EXTRA_CFLAGS="$CFLAGS"
)

mkdir build_win64
(
cd build_win64
export OPT="%mingw64_cflags -D_GNU_SOURCE -fwrapv -D__USE_MINGW_ANSI_STDIO=1"
export CXXFLAGS="$OPT"
export CFLAGS="$OPT `mingw64-pkg-config --cflags openssl`"

export LDFLAGS="%{mingw64_ldflags}"
export LDFLAGS="$LDFLAGS `mingw64-pkg-config --libs-only-L openssl`"

export CC="%{mingw64_cc}"
export LINKCC="%{mingw64_cc}"

export LIBFFI_INCLUDEDIR=`mingw64-pkg-config libffi --cflags-only-I | sed "s|\-I||g"`

# Workaround for conftest error on 64-bit builds
# export ac_cv_working_tzset=no

MSYSTEM=MINGW %mingw64_configure \
--enable-shared \
--with-threads \
--with-system-expat \
--with-system-ffi
#--with-dbmliborder='gdbm:ndbm'

%mingw64_make %{?_smp_mflags} EXTRA_CFLAGS="$CFLAGS"
)


%install
%mingw32_make -C build_win32 DESTDIR=%{buildroot} install
%mingw64_make -C build_win64 DESTDIR=%{buildroot} install

mv %{buildroot}%{mingw32_bindir}/smtpd.py %{buildroot}%{mingw32_py2_libdir}/
mv %{buildroot}%{mingw64_bindir}/smtpd.py %{buildroot}%{mingw64_py2_libdir}/

# Link static and import library to correct location
ln -s %{mingw32_py2_libdir}/config/libpython%{py_ver}.dll.a %{buildroot}%{mingw32_libdir}/libpython%{py_ver}.dll.a
ln -s %{mingw64_py2_libdir}/config/libpython%{py_ver}.dll.a %{buildroot}%{mingw64_libdir}/libpython%{py_ver}.dll.a
ln -s %{mingw32_py2_libdir}/config/libpython%{py_ver}.a %{buildroot}%{mingw32_libdir}/libpython%{py_ver}.a
ln -s %{mingw64_py2_libdir}/config/libpython%{py_ver}.a %{buildroot}%{mingw64_libdir}/libpython%{py_ver}.a

# Copy some useful "stuff"
install -dm755 %{buildroot}%{mingw32_py2_libdir}/Tools/{i18n,scripts}
install -dm755 %{buildroot}%{mingw64_py2_libdir}/Tools/{i18n,scripts}
install -pm755 Tools/i18n/{msgfmt,pygettext}.py %{buildroot}%{mingw32_py2_libdir}/Tools/i18n/
install -pm755 Tools/i18n/{msgfmt,pygettext}.py %{buildroot}%{mingw64_py2_libdir}/Tools/i18n/
install -pm755 Tools/scripts/{README,*py} %{buildroot}%{mingw32_py2_libdir}/Tools/scripts/
install -pm755 Tools/scripts/{README,*py} %{buildroot}%{mingw64_py2_libdir}/Tools/scripts/

# Cleanup shebangs
find %{buildroot}%{mingw32_py2_libdir}/ -name '*.py' | xargs sed -i "s|#[ ]*![ ]*/usr/bin/env python$|#!/usr/bin/python2|"
find %{buildroot}%{mingw64_py2_libdir}/ -name '*.py' | xargs sed -i "s|#[ ]*![ ]*/usr/bin/env python$|#!/usr/bin/python2|"

# Fix shebangs referencing full mingw prefix
for file in 2to3 idle pydoc python%{py_ver}-config; do
    sed -i "s|%{mingw32_bindir}/python%{py_ver}.exe|/usr/bin/python2|g" %{buildroot}%{mingw32_bindir}/$file
    sed -i "s|%{mingw64_bindir}/python%{py_ver}.exe|/usr/bin/python2|g" %{buildroot}%{mingw64_bindir}/$file
done
sed -i "s|%{mingw32_bindir}/python%{py_ver}.exe|/usr/bin/python2|g" %{buildroot}%{mingw32_py2_libdir}/smtpd.py
sed -i "s|%{mingw64_bindir}/python%{py_ver}.exe|/usr/bin/python2|g" %{buildroot}%{mingw64_py2_libdir}/smtpd.py

# Clean-up references to build directory
for file in config/Makefile _sysconfigdata.py; do
    sed -i "s|%{_builddir}|/build|g" %{buildroot}%{mingw32_py2_libdir}/$file
    sed -i "s|%{_builddir}|/build|g" %{buildroot}%{mingw64_py2_libdir}/$file
done

# Fix permissons
find %{buildroot} -type f | xargs chmod 0644
find %{buildroot} -type f \( -name "*.dll" -o -name "*.exe" \) | xargs chmod 0755

# Create python executable with windows subsystem
cp -a %{buildroot}%{mingw32_bindir}/python2.exe %{buildroot}%{mingw32_bindir}/python2w.exe
cp -a %{buildroot}%{mingw64_bindir}/python2.exe %{buildroot}%{mingw64_bindir}/python2w.exe
%{mingw32_objcopy} --subsystem windows %{buildroot}%{mingw32_bindir}/python2w.exe
%{mingw64_objcopy} --subsystem windows %{buildroot}%{mingw64_bindir}/python2w.exe

# Don't ship manpages
rm -rf %{buildroot}%{mingw32_mandir}
rm -rf %{buildroot}%{mingw64_mandir}
rmdir %{buildroot}%{mingw32_datadir}
rmdir %{buildroot}%{mingw64_datadir}

# Mingw python host wrappers
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_prefix}/%{mingw32_target}/bin/
mkdir -p %{buildroot}%{_prefix}/%{mingw64_target}/bin/

cat > %{buildroot}%{_prefix}/%{mingw32_target}/bin/python2 <<EOF
#!/bin/sh
pylibdynload=\$(/usr/bin/python2 -c 'import sysconfig; import os; print(os.path.join(sysconfig.get_path("platstdlib"), "lib-dynload"))')
PYTHONHOME=%{mingw32_prefix} PYTHONPATH=\$PYTHONPATH:%{mingw32_py2_hostlibdir}:%{mingw32_py2_hostlibdir}/site-packages:\$pylibdynload:%{mingw32_py2_libdir}:%{mingw32_python2_sitearch} /usr/bin/python2 "\$@"
EOF

cat > %{buildroot}%{_prefix}/%{mingw64_target}/bin/python2 <<EOF
#!/bin/sh
pylibdynload=\$(/usr/bin/python2 -c 'import sysconfig; import os; print(os.path.join(sysconfig.get_path("platstdlib"), "lib-dynload"))')
PYTHONHOME=%{mingw64_prefix} PYTHONPATH=\$PYTHONPATH:%{mingw64_py2_hostlibdir}:%{mingw64_py2_hostlibdir}/site-packages:\$pylibdynload:%{mingw64_py2_libdir}:%{mingw64_python2_sitearch} /usr/bin/python2 "\$@"
EOF

chmod +x %{buildroot}%{_prefix}/%{mingw32_target}/bin/python2
chmod +x %{buildroot}%{_prefix}/%{mingw64_target}/bin/python2

ln -s %{_prefix}/%{mingw32_target}/bin/python2 %{buildroot}%{_bindir}/mingw32-python2
ln -s %{_prefix}/%{mingw64_target}/bin/python2 %{buildroot}%{_bindir}/mingw64-python2
ln -s %{_bindir}/mingw32-python2 %{buildroot}%{_bindir}/mingw32-python
ln -s %{_bindir}/mingw64-python2 %{buildroot}%{_bindir}/mingw64-python

# Host site-packages skeleton
mkdir -p %{buildroot}%{mingw32_py2_hostlibdir}/site-packages
mkdir -p %{buildroot}%{mingw64_py2_hostlibdir}/site-packages

# Hackishly faked distutils/sysconfig.py
mkdir -p %{buildroot}%{mingw32_py2_hostlibdir}/distutils
mkdir -p %{buildroot}%{mingw64_py2_hostlibdir}/distutils
pushd %{buildroot}%{mingw32_libdir}/python%{py_ver}/distutils/
for file in *.py; do
    ln -s %{mingw32_libdir}/python%{py_ver}/distutils/$file %{buildroot}%{mingw32_py2_hostlibdir}/distutils/$file
done
popd
pushd %{buildroot}%{mingw64_libdir}/python%{py_ver}/distutils/
for file in *.py; do
    ln -s %{mingw64_libdir}/python%{py_ver}/distutils/$file %{buildroot}%{mingw64_py2_hostlibdir}/distutils/$file
done
popd
ln -s %{mingw32_py2_libdir}/distutils/command %{buildroot}%{mingw32_py2_hostlibdir}/distutils/command
ln -s %{mingw64_py2_libdir}/distutils/command %{buildroot}%{mingw64_py2_hostlibdir}/distutils/command
rm %{buildroot}%{mingw32_py2_hostlibdir}/distutils/sysconfig.py
rm %{buildroot}%{mingw64_py2_hostlibdir}/distutils/sysconfig.py
cat > %{buildroot}%{mingw32_py2_hostlibdir}/distutils/sysconfig.py <<EOF
import imp
_sysconfig = imp.load_source('_sysconfig', '%{mingw32_py2_libdir}/distutils/sysconfig.py')
from _sysconfig import *
# Overwrite methods from sysconfig
get_python_inc = lambda plat_specific=0, prefix=None: "%{mingw32_py2_incdir}"
get_python_lib = lambda plat_specific=0, standard_lib=0, prefix=None: "%{mingw32_python2_sitearch}"
EOF
cat > %{buildroot}%{mingw64_py2_hostlibdir}/distutils/sysconfig.py <<EOF
import imp
_sysconfig = imp.load_source('_sysconfig', '%{mingw64_py2_libdir}/distutils/sysconfig.py')
from _sysconfig import *
# Overwrite methods from sysconfig
get_python_inc = lambda plat_specific=0, prefix=None: "%{mingw64_py2_incdir}"
get_python_lib = lambda plat_specific=0, standard_lib=0, prefix=None: "%{mingw64_python2_sitearch}"
EOF

# mingw-python rpm macros
mkdir -p %{buildroot}%{_rpmconfigdir}/macros.d
cat > %{buildroot}%{_rpmconfigdir}/macros.d/macros.mingw32-python <<EOF
%%mingw32_python2 %{_prefix}/%{mingw32_target}/bin/python2
%%mingw32_python2_sitearch %{mingw32_python2_sitearch}
%%mingw32_python2_version %{py_ver}
EOF
cat > %{buildroot}%{_rpmconfigdir}/macros.d/macros.mingw64-python <<EOF
%%mingw64_python2 %{_prefix}/%{mingw64_target}/bin/python2
%%mingw64_python2_sitearch %{mingw64_python2_sitearch}
%%mingw64_python2_version %{py_ver}
EOF

# TODO: These cause unsatisfyable requires on msvcr71.dll
rm -f %{buildroot}%{mingw32_py2_libdir}/distutils/command/wininst-7.1.exe
rm -f %{buildroot}%{mingw64_py2_libdir}/distutils/command/wininst-7.1.exe

# Exclude debug files from the main files (note: the debug files are only created after %%install, so we can't search for them directly)
find %{buildroot}%{mingw32_prefix} | grep -E '.(exe|dll|pyd)$' | sed 's|^%{buildroot}\(.*\)$|%%exclude \1.debug|' > mingw32-%{pkgname}.debugfiles
find %{buildroot}%{mingw64_prefix} | grep -E '.(exe|dll|pyd)$' | sed 's|^%{buildroot}\(.*\)$|%%exclude \1.debug|' > mingw64-%{pkgname}.debugfiles


%files -n mingw32-%{pkgname} -f mingw32-%{pkgname}.debugfiles
%license LICENSE
%{_bindir}/mingw32-python
%{_bindir}/mingw32-python2
%{_rpmconfigdir}/macros.d/macros.mingw32-python
%{_prefix}/%{mingw32_target}/bin/python2
%{mingw32_py2_hostlibdir}/
%{mingw32_bindir}/*.exe
%{mingw32_bindir}/2to3
%{mingw32_bindir}/idle
%{mingw32_bindir}/pydoc
%{mingw32_bindir}/python-config
%{mingw32_bindir}/python-config-u.sh
%{mingw32_bindir}/python-config.sh
%{mingw32_bindir}/python2-config
%{mingw32_bindir}/python%{py_ver}-config
%{mingw32_bindir}/libpython%{py_ver}.dll
%{mingw32_py2_incdir}/
%{mingw32_libdir}/libpython%{py_ver}.dll.a
%{mingw32_libdir}/libpython%{py_ver}.a
%{mingw32_py2_libdir}/
%{mingw32_libdir}/pkgconfig/*.pc

%files -n mingw64-%{pkgname} -f mingw64-%{pkgname}.debugfiles
%license LICENSE
%{_bindir}/mingw64-python
%{_bindir}/mingw64-python2
%{_rpmconfigdir}/macros.d/macros.mingw64-python
%{_prefix}/%{mingw64_target}/bin/python2
%{mingw64_py2_hostlibdir}/
%{mingw64_bindir}/*.exe
%{mingw64_bindir}/2to3
%{mingw64_bindir}/idle
%{mingw64_bindir}/pydoc
%{mingw64_bindir}/python-config
%{mingw64_bindir}/python-config-u.sh
%{mingw64_bindir}/python-config.sh
%{mingw64_bindir}/python2-config
%{mingw64_bindir}/python%{py_ver}-config
%{mingw64_bindir}/libpython%{py_ver}.dll
%{mingw64_py2_incdir}/
%{mingw64_libdir}/libpython%{py_ver}.dll.a
%{mingw64_libdir}/libpython%{py_ver}.a
%{mingw64_py2_libdir}/
%{mingw64_libdir}/pkgconfig/*.pc


%changelog
* Mon Mar 04 2019 Sandro Mani <manisandro@gmail.com> - 2.7.16-1
- Update to 2.7.16

* Fri Feb 01 2019 Fedora Release Engineering <releng@fedoraproject.org> - 2.7.15-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Fri Aug 24 2018 Richard W.M. Jones <rjones@redhat.com> - 2.7.15-4
- Rebuild for new mingw-openssl.

* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.7.15-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Tue May 08 2018 Sandro Mani <manisandro@gmail.com> - 2.7.15-2
- BR: mingw{32,64}-sqlite for sqlite support

* Wed May 02 2018 Sandro Mani <manisandro@gmail.com> - 2.7.15-1
- Update to 2.7.15

* Thu Feb 08 2018 Fedora Release Engineering <releng@fedoraproject.org> - 2.7.14-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Sun Nov 05 2017 Sandro Mani <manisandro@gmail.com> - 2.7.14-2
- Fix PYFORMAT_LONG_LONG not defined

* Tue Oct 31 2017 Sandro Mani <manisandro@gmail.com> - 2.7.14-1
- Update to 2.7.14

* Thu Sep 28 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-12
- Also build the winreg module

* Tue Sep 19 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-11
- Rebuild (mingw-binutils)

* Mon Sep 18 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-10
- Fix potential endless recursion in mingw-python wrapper scripts

* Sat Sep 09 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-9
- Rebuild (mingw-filesystem)

* Thu Sep 07 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-8
- Use is_cygpty() to detect a terminal; disable readline with a real Windows console
- Dynamically determine native lib-dynload location and add it to path in mingw-python wrappers

* Sun Sep 03 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-7
- BR: mingw{32,64}-gcc-c++ to fix CXX in _sysconfigdata.py

* Fri Sep 01 2017 Sandro Mani <manisandro@gmail.coM> - 2.7.13-6
- Link lib-dynload from native package

* Fri Sep 01 2017 Sandro Mani <manisandro@gmail.coM> - 2.7.13-5
- Release bump

* Fri Sep 01 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-4
- Fix mingw-python wrappers
- Add mingw_python2 macros

* Thu Aug 31 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-3
- Set PYTHONHOME in mingw-python wrappers

* Thu Aug 24 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-2
- Add missing distutils/command symlink to hostlibs
- Add py2_libdir to PYTHONPATH in mingw-python wrappers

* Sat Jan 21 2017 Sandro Mani <manisandro@gmail.com> - 2.7.13-1
- Initial package