forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbscript
152 lines (132 loc) · 4.77 KB
/
bscript
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
import sys
import shutil
# Ugly but necessary hack: import numpy here so that wscript in sub directories
# will see this numpy and not an already installed one
import __builtin__
__builtin__.__NUMPY_SETUP__ = True
from bento.commands import hooks
from bento.commands.extras.waf \
import \
ConfigureWafContext, BuildWafContext
import waflib
def check_blas_lapack(conf):
conf.env.HAS_CBLAS = False
if sys.platform == "win32":
print("No blas/lapack check implemented on win32")
elif sys.platform == "darwin":
try:
conf.check(framework="Accelerate", msg="Checking for framework Accelerate", uselib_store="CBLAS")
conf.env.HAS_CBLAS = True
conf.check(framework="Accelerate", msg="Checking for framework Accelerate", uselib_store="LAPACK")
conf.env.HAS_LAPACK = True
except waflib.Errors.ConfigurationError:
pass
else:
try:
conf.check_cc(lib=["cblas", "atlas"], uselib_store="CBLAS")
conf.env.HAS_CBLAS = True
conf.check_cc(lib=["lapack", "f77blas", "cblas", "atlas"],
uselib_store="LAPACK")
conf.env.HAS_LAPACK = True
except waflib.Errors.ConfigurationError:
pass
# You can manually set up blas/lapack as follows:
#conf.env.HAS_CBLAS = True
#conf.env.LIB_CBLAS = ["cblas", "atlas"]
#conf.env.HAS_LAPACK = True
#conf.env.LIB_LAPACK = ["lapack", "f77blas", "cblas", "atlas"]
def remove_flag(name, flag):
while True:
if name in flag:
i = flag.index(name)
flag.pop(i)
else:
break
def remove_flag_postvalue(name, flag):
while True:
if name in flag:
i = flag.index(name)
flag.pop(i)
flag.pop(i)
else:
break
def remove_flag_prevalue(name, flag):
while True:
if name in flag:
i = flag.index(name)
flag.pop(i-1)
flag.pop(i-1)
else:
break
@hooks.pre_configure()
def pre_configure(context):
conf = context.waf_context
conf.load("compiler_c")
conf.load("python")
conf.check_python_version((2, 4, 0))
conf.check_python_headers()
if sys.platform == "darwin":
# FIXME: fix upstream waf tool to work on mac os X
conf.env.CC = ["/usr/bin/gcc-4.0"]
conf.env.LINK_CC = ["/usr/bin/gcc-4.0"]
# FIXME: fix upstream waf tool to avoid linking against libpython2.6.so
# (cause crashes when importing the extension)
name = "python%s" % ".".join([str(i) for i in sys.version_info[:2]])
remove_flag(name, conf.env.LIB_PYEXT)
remove_flag("-dynamiclib", conf.env.LINKFLAGS_cshlib)
remove_flag_postvalue("-compatibility_version", conf.env.CFLAGS_cshlib)
remove_flag_postvalue("-current_version", conf.env.CFLAGS_cshlib)
remove_flag_prevalue("ppc", conf.env.CFLAGS_PYEXT)
remove_flag_prevalue("ppc", conf.env.LINKFLAGS_PYEXT)
conf.env.LINKFLAGS_cshlib.extend(["-undefined", "dynamic_lookup", "-bundle"])
conf.env.CFLAGS_PYEXT.append("-Wfatal-errors")
check_blas_lapack(conf)
# FIXME: abstract those module gen tasks...
class write_module(waflib.Task.Task):
color = "CYAN"
vars = ["CONTENT"]
def run(self):
# FIXME: put actual data here
self.outputs[0].write(self.env.CONTENT)
@waflib.TaskGen.feature("gen_pymodule")
def process_write_config(self):
if not hasattr(self, "content"):
raise ValueError("task gen %r expects a 'content' argument" % self.name)
else:
self.env.CONTENT = self.content
tsk = self.create_task("write_module")
tsk.set_outputs(self.path.find_or_declare(self.target))
return tsk
@hooks.pre_build()
def pre_build(context):
bld = context.waf_context
bld(features="gen_pymodule",
target="numpy/__config__.py",
content="""\
def show():
pass
""",
always=True)
bld(features="gen_pymodule",
target="numpy/version.py",
content="""\
git_revision = ""
version = ""
""",
always=True)
@hooks.post_build()
def post_build(context):
bld = context.waf_context
# Poor man's and temporary replacement for in-place build
if "-i" in sys.argv:
for g in bld.groups:
for task_gen in g:
if "gen_pymodule" in task_gen.features:
if len(task_gen.tasks) > 0:
task = task_gen.tasks[0]
for output in task.outputs:
if output.is_child_of(bld.bldnode):
shutil.copy(output.abspath(), output.path_from(bld.bldnode))
def startup(context):
context.register_context("configure", ConfigureWafContext)
context.register_context("build", BuildWafContext)