-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
167 lines (151 loc) · 5.27 KB
/
setup.py
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
import sys, os
from distutils.core import setup, Extension
# Fail gracefully for old versions of Python.
if sys.version[:3] < '2.6':
sys.stdout.write("GMPY2 requires Python 2.6 or later.\n")
sys.stdout.write("Please use GMPY 1.x for earlier versions of Python.\n")
sys.exit()
# Check for build options:
# -DMPIR -> use MPIR instead of GMP
# -DGMP -> use GMP instead of MPIR
# Windows build defaults to MPIR.
if sys.version.find('MSC') == -1:
mplib='gmp'
else:
mplib='mpir'
local_dir = None
running_build = False
for token in sys.argv:
if token.upper().startswith('-DMPIR'):
mplib='mpir'
if token.upper().startswith('-DGMP'):
mplib='gmp'
if token.upper().startswith('BUILD'):
running_build = True
if token.upper().startswith('-DDIR'):
try:
local_dir = token.split('=')[1]
except:
pass
use_mpc = False
use_mpfr = False
incdirs = None
libdirs = None
rundirs = None
my_extra_link_args = None
# determine include and library dirs
if running_build and sys.version.find('MSC') == -1:
# Unix-like build (including MacOSX)
incdirs = ['./src']
dirord = ['/opt/local', '/opt', '/usr/local']
if local_dir:
dirord = [local_dir] + dirord
for adir in dirord:
lookin = '%s/include' % adir
if os.path.isfile(lookin + '/' + mplib + '.h'):
incdirs = [lookin]
# Verify that MPFR and MPC exist in the same directory
if not os.path.isfile(lookin + '/mpfr.h'):
use_mpfr = False
if not os.path.isfile(lookin + '/mpc.h'):
use_mpc = False
break
for adir in dirord:
lookin = '%s/lib' % adir
if os.path.isfile(lookin + '/lib' + mplib + '.a'):
libdirs = [lookin]
if local_dir and lookin.startswith(local_dir):
rundirs = [lookin]
# Verify that MPFR and MPC exist in the same directory
if not os.path.isfile(lookin + '/libmpfr.a'):
use_mpfr = False
if not os.path.isfile(lookin + '/libmpc.a'):
use_mpc = False
break
# Validate include and library directories on Windows
if running_build and sys.version.find('MSC') != -1:
rundirs = None
my_extra_link_args = ["/MANIFEST"]
if not local_dir:
sys.stdout.write("Please specify parent directory of include and lib\n")
sys.stdout.write("directories using -Ddir=<path>.");
sys.exit()
testpath = local_dir + '\\include'
if os.path.isfile(testpath + '\\' + mplib + '.h'):
incdirs = [testpath]
if not os.path.isfile(testpath + '\\mpfr.h'):
use_mpfr = False
if not os.path.isfile(testpath + '\\mpc.h'):
use_mpc = False
testpath = local_dir + '\\lib'
if os.path.isfile(testpath + '\\' + mplib + '.lib'):
libdirs = [testpath]
if not os.path.isfile(testpath + '\\mpfr.lib'):
use_mpfr = False
if not os.path.isfile(testpath + '\\mpc.lib'):
use_mpc = False
# Use options to prevent use of MPFR and MPC even if found.
# -DNOMPC -> build without MPC library
# -DNOMPFR -> build without MPFR library
for token in sys.argv:
if token.upper() == '-DNOMPC':
use_mpc = False
if token.upper() == '-DNOMPFR':
use_mpfr = False
if not use_mpfr:
use_mpc = False
# Configure the defines...
defines = []
if mplib == 'mpir':
defines.append( ('MPIR', 1) )
if use_mpfr:
defines.append( ('WITHMPFR', 1) )
else:
defines.append( ('NOMPFR', 1) )
if use_mpc:
defines.append( ('WITHMPC', 1) )
else:
defines.append( ('NOMPC', 1) )
# Build list of the required libraries...
libs = [mplib]
if use_mpfr:
libs.append('mpfr')
if use_mpc:
libs.append('mpc')
# Error message if libraries can not be found...
if running_build and not libdirs:
sys.stdout.write("GMPY2 can not find the requires libraries.\n")
sys.exit()
# decomment next line (w/gcc, only!) to support gcov
# os.environ['CFLAGS'] = '-fprofile-arcs -ftest-coverage -O0'
# prepare the extension for building
gmpy2_ext = Extension('gmpy2', sources=['src/gmpy2.c'],
include_dirs=incdirs,
library_dirs=libdirs,
libraries=libs,
runtime_library_dirs=rundirs,
define_macros = defines,
extra_link_args = my_extra_link_args)
setup (name = "gmpy2",
version = "2.0.0b3",
maintainer = "Case Van Horsen",
maintainer_email = "casevh@gmail.com",
url = "http://code.google.com/p/gmpy/",
description = "GMP/MPIR, MPFR, and MPC interface to Python 2.6+ and 3.x",
classifiers = [
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'Natural Language :: English',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Programming Language :: C',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Software Development :: Libraries :: Python Modules',
],
ext_modules = [ gmpy2_ext ]
)