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
|
#!/usr/bin/env python
# To use:
# python setup.py install
#
import re
import build_config
import os, sys, string, re
from glob import glob
import numpy
import distutils
from distutils.command.install import install
from distutils.core import setup, Extension
def uniq(input):
output = []
for x in input:
if x not in output:
output.append(x)
return output
headers = glob (os.path.join ("*.h") ) + [ "hst_cpu/hst_cpu.h", "hst_cuda/hst_cuda.h", "dfi_cuda/dfi_cuda.h", "hst_opencl/hst_opencl.h" ];
header = headers + glob (os.path.join ("Include/Numeric","*.h") )
objects = ['PyHST_c.c',"Vhst_calculate_limits.c", "hst.c", "hst_setup.c", "hst_reconstructor.c", "debug.c", "hw_sched.c", "hw_thread.c", "hw_tools.c", "astra_fourier.c"]
if hasattr(build_config, 'CFLAGS'):
os.environ["CFLAGS"]=build_config.CFLAGS
if hasattr(build_config, 'INCLUDES'):
incdirs = build_config.INCLUDES
else:
incdirs = []
if hasattr(build_config, 'DEFINES'):
defines = build_config.DEFINES
else:
defines = []
if hasattr(build_config, 'LIBDIRS'):
libdirs = build_config.LIBDIRS
else:
libdirs = []
if hasattr(build_config, 'LIBS'):
libs = build_config.LIBS
else:
libs = []
regexp = re.compile("^-D")
for i, define in enumerate(defines):
pair = regexp.sub("", define).split('=',2)
if len(pair) < 2:
pair.append(1)
defines[i] = tuple(pair)
for i, lib in enumerate(libs):
m = re.search("^(.*)/([^/]+)$", lib)
if m:
path = m.group(1)
lib = m.group(2)
m = re.search("^(.*)\\.[^.]+$", lib)
if m:
lib = m.group(1)
m = re.search("^lib(.*)$", lib)
if m:
lib = m.group(1)
libs[i] = lib
libdirs.append(path)
libs += ['gcc']
libdirs += ['./']
# The version is set in Lib/numeric_version.py
cpu_build, cuda_build, opencl_build = False, False, False
dfi_build = False
define_arg = False
for i in range(len(sys.argv)):
arg = sys.argv[i]
if re.search("HW_USE_CUDA", arg):
cuda_build = True
if re.search("HW_USE_OPENCL", arg):
opencl_build = True
if re.search("HW_USE_CPU", arg):
cpu_build = True
if re.search("PYHST_ENABLE_DFI", arg):
dfi_build = True
if re.search("--define", arg):
define_arg = i
cmd_defines = sys.argv[define_arg + 1]
for define in cmd_defines.split(','):
pair = define.split('=',2)
if len(pair) < 2:
pair.append(1)
defines.append(tuple(pair))
del(sys.argv[define_arg:define_arg+2])
if cuda_build:
libdirs += ["hst_cuda", "dfi_cuda"]
libs += ["hst_cuda"]
if dfi_build:
libs += ["dfi_cuda"]
if opencl_build:
libdirs += ["hst_opencl"]
libs += ["hst_opencl"]
if cpu_build:
libdirs += ["hst_cpu"]
libs += ["hst_cpu"]
#if("PROFILE" in sys.argv):
# libs.extend(['c_p', 'm_p'])
#else:
libs.append('m')
setup (name = "extension",
description = " Extension to Python",
include_dirs = numpy.get_include(),
ext_modules = [Extension('PyHST_c',
objects,
depends = header + ["build_config.py"],
define_macros = uniq(defines),
libraries = uniq(libs),
library_dirs = uniq(libdirs),
include_dirs = uniq(incdirs),
),
]
)
|