File: msys2_build.txt

package info (click to toggle)
python-gmpy2 2.1.0~a4-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,048 kB
  • sloc: ansic: 24,051; python: 325; makefile: 117
file content (335 lines) | stat: -rw-r--r-- 12,165 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
Building gmpy2 with MSYS2
=========================

Note: These instructions are a work in progress!

From the MSYS2 home page:

http://sourceforge.net/projects/msys2/

MSYS2 is a Cygwin-derived Posix-like environment for Windows. The name is a
contraction of Minimal SYStem 2, and aims to provide support to facilitate
using the bash shell, Autotools, revision control systems and the like for
building native Windows applications using MinGW-w64 toolchains.

Installing MSYS2
================

MSYS2 installation instructions can be found at:

http://sourceforge.net/p/msys2/wiki/MSYS2%20installation/

Some of the examples assume the 64-bit version of MSYS2 is installed. If you
install the 32-bit version of MSYS2, you will need to change any references
of C:\msys64 to C:\msys32.

After following the installation and upgrade steps documented above, you will
need to install the MinGW compiler toolchain(s). Both toolchains can be
installed at the same time. To install the 64-bit toolchain:

$ pacman -S mingw-w64-x86_64-toolchain

To install the 32-bit toolchain:

$ pacman -S mingw-w64-i686-toolchain

The following additional packages should also be installed:

$ pacman -S patch m4 lzip wget tar make diffutils

The MSYS2 build environment
===========================

The build process is split into two phases. During phase 1 we use the MSYS2
environment to build statically linked versions of GMP, MPFR, and MPC. Once
those libraries are build, we will use the Windows command prompt to build
the actual gmpy2 extension (DLL). We do not use the versions of Python
included with MSYS2 or MinGW to compile gmpy2.

Commands that must be executed from an MSYS2 shell are preceded by "$".
Commands that must be executed from a Windows command prompt are preceded
by ">". You will need to run the commands *after* "$" or ">".

The MSYS2 environment provides three different command line operating
environments.

 * msys2_shell.bat is the general-purpose shell but it does not provide
   access to the MinGW compiler suite.
 * mingw64_shell.bat provides access to the 64-bit MinGW compiler suite.
 * mingw32_shell.bat provides access to the 32-bit MinGW compiler suite.

MSYS2 does include versions of GMP, MPFR, and MPC but we will compile our
own version directly from the source. We will specify the options that are
appropriate for building a statically linked Windows DLL.

MSYS2 can support both MinGW32 and MinGW64 toolchains simultaneously. We
use /mingw32/opt and /mingw64/opt as the destinations for the 32-bit and
64-bit versions of GMP, MPFR, and MPC. The sources for GMP, MPFR, and MPC
will be placed in /mingw32/src or /mingw64/opt.

64-bit Build
============

# Start the appropriate shell: MSYS2 WinGW 64-bit

# Create a new directies as the destinations for GMP, MPFR, and MPC.

  $ mkdir /mingw64/opt
  $ mkdir /mingw64/src

# Download and uncompress GMP, MPFR, and MPC
  $ cd /mingw64/src

# Download GMP
  $ wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz
  $ tar xf gmp-6.1.2.tar.lz

# Download MPFR and any patches
  $ wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.bz2
  $ tar xf mpfr-3.1.5.tar.bz2
  $ cd mpfr-3.1.5/
  $ wget http://www.mpfr.org/mpfr-current/allpatches
  $ patch -N -Z -p1 < allpatches
  $ cd ..

# Download MPC
  $ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
  $ tar xf mpc-1.0.3.tar.gz

# Compile GMP
  $ cd gmp-6.1.2/
  $ ./configure --prefix=/mingw64/opt --enable-static --disable-shared --enable-fat --with-pic

    *Experimental for mingw64 build*

    mp_bitcnt_t should really be a 64-bit unsigned integer. The following sed
    command makes the change. It should only be used for 64-bit builds.

    This will require changes to gmpy2 source also. See gmpy2_convert_utils.h.

  $ mv gmp.h gmp.original
  $ sed 's/typedef\s*unsigned\s*long\s*int\s*mp_bitcnt_t/typedef unsigned long long int  mp_bitcnt_t/g' gmp.original > gmp.h

  $ make
  $ make check
  $ make install
  $ cd ..

# Compile MPFR
  $ cd mpfr-3.1.5/
  $ ./configure --prefix=/mingw64/opt --enable-static --disable-shared --disable-thread-safe --enable-gmp-internals --with-pic --with-gmp=/mingw64/opt
  $ make
  $ make check
  $ make install
  $ cd ..

# Compile MPC
  $ cd mpc-1.0.3/
  $ ./configure --prefix=/mingw64/opt --enable-static --disable-shared --with-pic --with-gmp=/mingw64/opt --with-mpfr=/mingw64/opt
  $ make
  $ make check
  $ make install
  $ cd ..

32-bit Build
============

# Start the appropriate shell: MSYS2 WinGW 32-bit

# Create a new directies as the destinations for GMP, MPFR, and MPC/

  $ mkdir /mingw32/opt
  $ mkdir /mingw32/src

# Download and uncompress GMP, MPFR, and MPC
  $ cd /mingw32/src

# Download GMP
  $ wget https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz
  $ tar xf gmp-6.1.2.tar.lz

# Download MPFR and any patches
  $ wget http://www.mpfr.org/mpfr-current/mpfr-3.1.5.tar.bz2
  $ tar xf mpfr-3.1.5.tar.bz2
  $ cd mpfr-3.1.5/
  $ wget http://www.mpfr.org/mpfr-current/allpatches
  $ patch -N -Z -p1 < allpatches
  $ cd ..

# Download MPC
  $ wget ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
  $ tar xf mpc-1.0.3.tar.gz

# Compile GMP
  $ cd gmp-6.1.2/
  $ ./configure --prefix=/mingw32/opt --enable-static --disable-shared --enable-fat --with-pic
  $ make
  $ make check
  $ make install
  $ cd ..

# Compile MPFR
  $ cd mpfr-3.1.5/
  $ ./configure --prefix=/mingw32/opt --enable-static --disable-shared --disable-thread-safe --enable-gmp-internals --with-pic --with-gmp=/mingw32/opt
  $ make
  $ make check
  $ make install
  $ cd ..

# Compile MPC
  $ cd mpc-1.0.3/
  $ ./configure --prefix=/mingw32/opt --enable-static --disable-shared --with-pic --with-gmp=/mingw32/opt --with-mpfr=/mingw32/opt
  $ make
  $ make check
  $ make install
  $ cd ..


The Windows build environment
=============================

# Configure Windows command prompt - GCC

  The MinGW toolchain must be accessible by the normal Windows installation of
  Python. The 64-bit MinGW toolchain is located in C:\msys64\mingw64\bin. The
  32-bit MinGW toolchain is located in C:\msys64\mingw32\bin. The MinGW
  location can be added to the system Path permanently or can be added manually
  after starting the Windows command prompt. We will do it manually. After
  starting the Windows command prompt, add either the 64-bit or 32-bit
  MinGW to the Path with one of the following commands:

  > set Path=C:\msys64\mingw64\bin;%Path%
  -- or --
  > set Path=C:\msys64\mingw32\bin;%Path%

  To verfiy the MinGW toolchain is accessible, the command "gcc -v" should
  return information about the gcc compiler.

  Note: All the remaining instructions assume this step has been completed and
        that "gcc -v" returns information for the correct version of gcc.

# Configure Windows command prompt - Python
  The Python interpreter does not need to be accessible via the path. You can
  specify the full path name to start a particular version. To simplify the
  compilation of multiple versions of gmpy2, I have adopted the following
  approach:

  # 32-bit versions of Python are installed in C:\32
  # 64-bit versions of Python are installed in C:\64
  # Aliases are defined to create shortcuts for invoking a Python interpreter

  I use the following batch file to configure a command prompt for 32-bit builds:

  @echo off
  doskey py26=C:\32\Python26\python.exe $*
  doskey py27=C:\32\Python27\python.exe $*
  doskey py34=C:\32\Python34\python.exe $*
  doskey py35=C:\32\Python35\python.exe $*
  doskey py36=C:\32\Python36\python.exe $*
  set Path=C:\msys64\mingw32\bin;%Path%

  I use the following batch file to configure a command prompt for 64-bit builds:

  @echo off
  doskey py26=C:\64\Python26\python.exe $*
  doskey py27=C:\64\Python27\python.exe $*
  doskey py34=C:\64\Python34\python.exe $*
  doskey py35=C:\64\Python35\python.exe $*
  doskey py36=C:\64\Python36\python.exe $*
  set Path=C:\msys64\mingw64\bin;%Path%

# Modify distutils library

  The gmpy2 extension is built using the distutils module. Recent versions of
  the gcc compiler no longer support an option that is used by older versions
  of distutils. In the file "cygwincompiler.py", remove all occurences of the
  "-mno-cygwin" option. The "-mno-cygwin" option was already removed in Python
  2.7.8, 3.3.5, and 3.4.1. The option was present in Python 2.6.6 and 3.2.5.
  You will need to check your specific version.

  In the file "cygwincompiler.py", find the definition for the class
  "Mingw32CCompiler". In the "__init__" function comment out the line:
  "self.dll_libraries = get_msvcr()".

  In the file "cygwincompiler.py", find the definition for the class
  "Mingw32CCompiler". Under self.set_executables(...), change -O to -O2 and
  add "-fno-strict-aliasing" and "-fwrapv". After changes, it should look like

    self.set_executables(compiler='gcc -O2 -Wall -fno-strict-aliasing -fwrapv',
                         compiler_so='gcc -mdll -O2 -Wall -fno-strict-aliasing -fwrapv',
                         compiler_cxx='g++ -O2 -Wall -fno-strict-aliasing -fwrapv',
                         linker_exe='gcc',
                         linker_so='%s %s %s'
                                    % (self.linker_dll, shared_option,
                                       entry_point))

# Patch C:\Python27\include\pyconfig.h

  In that file, search for the text #ifdef _WIN64 and cut out the following
  three lines:

  #ifdef _WIN64
  #define MS_WIN64
  #endif

  Search for the text #ifdef _MSC_VER earlier in the file. Paste in the
  cut-out lines, ABOVE the #ifdef _MSC_VER.

# Create a libpython.a file

  MinGW requires a libpythonXX.a file that contains information about the C-API
  functions that exist in pythonXX.dll. Follow these steps for your version of
  Python.

  Note: The DLL locations are from a Windows 10 64-bit system with both 32-bit
        and 64-bit versions of a Python version installed. Your location may
        vary.

  # For a 32-bit versions (with mingw32 on the path)
  > cd C:\32\Python27\libs
  > gendef c:\Windows\SysWOW64\python27.dll
  > dlltool --dllname c:\Windows\SysWOW64\python27.dll --def python27.def --output-lib libpython27.a

  # For a 64-bit version (with mingw64 on the path)
  > cd C:\64\Python27\libs
  > gendef c:\Windows\System32\python27.dll
  > dlltool --dllname c:\Windows\System32\python27.dll --def python27.def --output-lib libpython27.a

# To compile gmpy2

  py27 setup.py build_ext --msys2 --prefix=c:\msys64\mingwXX\opt

# To install to a local Python installation (after compiling)
  py27 setup.py install


-------------------

misc

cd C:\32\Python27\libs
gendef c:\Windows\SysWOW64\python27.dll
dlltool --dllname c:\Windows\SysWOW64\python27.dll --def python27.def --output-lib libpython27.a
cd C:\32\Python32\libs
gendef c:\Windows\SysWOW64\python32.dll
dlltool --dllname c:\Windows\SysWOW64\python32.dll --def python32.def --output-lib libpython32.a
cd C:\32\Python33\libs
gendef c:\Windows\SysWOW64\python33.dll
dlltool --dllname c:\Windows\SysWOW64\python33.dll --def python33.def --output-lib libpython33.a
cd C:\32\Python34\libs
gendef c:\Windows\SysWOW64\python34.dll
dlltool --dllname c:\Windows\SysWOW64\python34.dll --def python34.def --output-lib libpython34.a


cd C:\64\Python27\libs
gendef c:\Windows\System32\python27.dll
dlltool --dllname c:\Windows\System32\python27.dll --def python27.def --output-lib libpython27.a
cd C:\64\Python32\libs
gendef c:\Windows\System32\python32.dll
dlltool --dllname c:\Windows\System32\python32.dll --def python32.def --output-lib libpython32.a
cd C:\64\Python33\libs
gendef c:\Windows\System32\python33.dll
dlltool --dllname c:\Windows\System32\python33.dll --def python33.def --output-lib libpython33.a
cd C:\64\Python34\libs
gendef c:\Windows\System32\python34.dll
dlltool --dllname c:\Windows\System32\python34.dll --def python34.def --output-lib libpython34.a