2
from subprocess import Popen, PIPE
5
from distutils.core import setup
6
from distutils.extension import Extension
7
from distutils.spawn import find_executable
8
from distutils.sysconfig import get_config_vars
10
# numpy is required -- attempt import
14
print "numpy is required"
17
# mpi4py is required -- attempt import
21
print "mpi4py is required"
24
# cython is optional -- attempt import
27
from Cython.Build import cythonize
28
from Cython.Distutils import build_ext
33
# need to find 'ga-config' to gather how GA was configured
34
ga_config = find_executable("ga-config", None)
36
raise ValueError, "ga-config not found in path -- required"
37
p = Popen("%s --cc" % ga_config, shell=True, stdout=PIPE, stderr=PIPE,
39
ga_cc,ignore = p.communicate()
40
p = Popen("%s --cppflags" % ga_config, shell=True, stdout=PIPE, stderr=PIPE,
42
ga_cppflags,ignore = p.communicate()
43
p = Popen("%s --ldflags" % ga_config, shell=True, stdout=PIPE, stderr=PIPE,
45
ga_ldflags,ignore = p.communicate()
46
p = Popen("%s --libs" % ga_config, shell=True, stdout=PIPE, stderr=PIPE,
48
ga_clibs,ignore = p.communicate()
50
if 'CC' not in os.environ:
51
os.environ['CC'] = ga_cc
52
if 'LDSHARED' not in os.environ:
53
# take a lucky guess and reuse the same flags Python used
54
flags = get_config_vars('LDSHARED')[0].strip().split()
57
os.environ['LDSHARED'] = ' '.join(flags)
58
if 'ARCHFLAGS' not in os.environ:
59
os.environ['ARCHFLAGS'] = ''
61
# On osx, '-framework Accelerate' doesn't link the actual LAPACK and BLAS
62
# libraries. Locate them manually if GA was configured to use them.
66
if 'Accelerate' in ga_clibs or 'vecLib' in ga_clibs:
67
path = "/System/Library/Frameworks/Accelerate.framework/Frameworks/vecLib.framework/Versions/A"
69
if os.path.exists(path):
70
linalg_library = [path]
71
linalg_lib = ["LAPACK","BLAS"]
72
# remove '-framework Accelerate' from flags
73
ga_clibs = ga_clibs.replace("-framework","")
74
ga_clibs = ga_clibs.replace("Accelerate","")
75
ga_clibs = ga_clibs.replace("vecLib","")
77
include_dirs = [numpy.get_include(), mpi4py.get_include()]
82
for dir in ga_cppflags.split():
84
include_dirs.append(dir.replace("-I",""))
85
for dir in ga_ldflags.split():
87
library_dirs.append(dir.replace("-L",""))
88
for part in ga_clibs.split():
91
library_dirs.append(part.replace("-L",""))
93
libraries.append(part.replace("-l",""))
95
include_dirs.extend(linalg_include)
96
library_dirs.extend(linalg_library)
97
libraries.extend(linalg_lib)
99
ga4py_ga_sources = ["ga4py/ga.c"]
100
ga4py_gain_core_sources = ["ga4py/gain/core.c"]
101
ga4py_gain_misc_sources = ["ga4py/gain/misc.c"]
102
ga4py_gain_notimplemented_sources = ["ga4py/gain/notimplemented.c"]
103
ga4py_gain_random_sources = ["ga4py/gain/random.c"]
104
ga4py_gain_util_sources = ["ga4py/gain/util.c"]
106
ga4py_ga_sources = ["ga4py/ga.pyx"]
107
ga4py_gain_core_sources = ["ga4py/gain/core.pyx"]
108
ga4py_gain_misc_sources = ["ga4py/gain/misc.pyx"]
109
ga4py_gain_notimplemented_sources = ["ga4py/gain/notimplemented.pyx"]
110
ga4py_gain_random_sources = ["ga4py/gain/random.pyx"]
111
ga4py_gain_util_sources = ["ga4py/gain/util.pyx"]
113
include_dirs.append(".")
118
sources=ga4py_ga_sources,
119
include_dirs=include_dirs,
120
library_dirs=library_dirs,
124
name="ga4py.gain.core",
125
sources=ga4py_gain_core_sources,
126
include_dirs=include_dirs,
127
library_dirs=library_dirs,
131
name="ga4py.gain.misc",
132
sources=ga4py_gain_misc_sources,
133
include_dirs=include_dirs,
134
library_dirs=library_dirs,
138
name="ga4py.gain.notimplemented",
139
sources=ga4py_gain_notimplemented_sources,
140
include_dirs=include_dirs,
141
library_dirs=library_dirs,
145
name="ga4py.gain.random",
146
sources=ga4py_gain_random_sources,
147
include_dirs=include_dirs,
148
library_dirs=library_dirs,
152
name="ga4py.gain.util",
153
sources=ga4py_gain_util_sources,
154
include_dirs=include_dirs,
155
library_dirs=library_dirs,
161
ext_modules = cythonize(ext_modules, include_path=include_dirs)
163
#cmdclass = {'build_ext': build_ext}
168
name = "Global Arrays",
169
packages = ["ga4py","ga4py.gain"],
170
ext_modules = ext_modules,