blob: e5d1a89c5cbd0a55e1cc48354caf0bbbc5534b6e [file] [log] [blame]
David Cournapeau3763b572011-08-27 22:25:141"""
David Cournapeauda2af082011-09-08 15:31:122See BENTO_BUILD.txt.
David Cournapeau3763b572011-08-27 22:25:143
4Caveats:
5
6 - no automatic detection for BLAS/LAPACK/etc... You need to set it up
7 manually for now (except on Mac OS X and Debian/Ubuntu). The upside is
8 that it is extremely easy to do so
9 - bento is still in flux, and some things may changes between releases.
David Cournapeau3763b572011-08-27 22:25:1410"""
11
David Cournapeau78470432011-05-30 00:10:3512import os
David Cournapeaud2f648a2011-03-07 00:02:3213import sys
David Cournapeau7f302cc2011-11-21 06:03:4414import subprocess
David Cournapeaud2f648a2011-03-07 00:02:3215
David Cournapeau0c7af4b2011-03-07 00:30:4216# Ugly but necessary hack: import numpy here so that wscript in sub directories
17# will see this numpy and not an already installed one
18import __builtin__
19__builtin__.__NUMPY_SETUP__ = True
20
Ralf Gommers3d431ab2013-05-04 17:28:0921import waflib
22
23from numpy.distutils.conv_template \
24 import \
25 process_str as process_c_str
26
David Cournapeaua52f88f2011-04-06 00:18:0427from bento.commands import hooks
David Cournapeau6fe584f2012-06-11 10:14:5828from bento.utils.utils \
29 import \
30 cmd_is_runnable
David Cournapeau20825a92012-09-09 16:53:2231from bento.backends.waf_backend \
32 import \
33 WAF_TOOLDIR
David Cournapeaufd9ee732012-10-09 21:10:5434from bento.backends.waf_tools \
35 import \
36 blas_lapack
David Cournapeauaa7e9bd2011-03-15 15:39:1537
David Cournapeau7f302cc2011-11-21 06:03:4438sys.path.insert(0, os.getcwd())
39try:
40 _SETUP_PY = __import__("setup")
41finally:
42 sys.path.pop(0)
43
David Cournapeau6fe584f2012-06-11 10:14:5844def compute_git_revision(top_node):
45 git_repo_node = top_node.find_node(".git")
46 if git_repo_node and cmd_is_runnable(["git", "--version"]):
47 s = subprocess.Popen(["git", "rev-parse", "HEAD"],
48 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=top_node.abspath())
49 out = s.communicate()[0]
50 return out.decode().strip()
51 else:
52 return ""
David Cournapeau7f302cc2011-11-21 06:03:4453
David Cournapeau6fe584f2012-06-11 10:14:5854def _register_metadata(context):
55 git_revision = compute_git_revision(context.top_node)
56 full_version = context.pkg.version
David Cournapeau7f302cc2011-11-21 06:03:4457 if not _SETUP_PY.ISRELEASED:
58 full_version += '.dev-' + git_revision[:7]
David Cournapeau7f302cc2011-11-21 06:03:4459
David Cournapeau6fe584f2012-06-11 10:14:5860 context.register_metadata("git_revision", git_revision)
61 context.register_metadata("is_released", _SETUP_PY.ISRELEASED)
62 context.register_metadata("full_version", full_version)
David Cournapeau7f302cc2011-11-21 06:03:4463
Julian Taylorc9fd6342014-04-05 11:13:1364def _generate_cython():
65 print("Cythonizing sources")
66 cwd = os.path.abspath(os.path.dirname(__file__))
67 p = subprocess.call([sys.executable,
68 os.path.join(cwd, 'tools', 'cythonize.py'),
69 'numpy'],
70 cwd=cwd)
71 if p != 0:
72 raise RuntimeError("Running cythonize failed!")
73
David Cournapeau87295b32012-05-31 09:25:2074@hooks.post_configure
75def post_configure(context):
David Cournapeau3cb783e2012-04-16 18:31:4476 conf = context.waf_context
David Cournapeau3cb783e2012-04-16 18:31:4477 if conf.env["CC_NAME"] == "gcc":
78 conf.env.CFLAGS_PYEXT.append("-Wfatal-errors")
David Cournapeau20825a92012-09-09 16:53:2279
80 conf.load("arch", tooldir=[WAF_TOOLDIR])
81 if sys.platform == "darwin":
82 conf.env["MACOSX_DEPLOYMENT_TARGET"] = "10.4"
83 conf.check_cc_default_arch()
84 archs = [conf.env.DEFAULT_CC_ARCH]
85 conf.env.ARCH = archs
86
David Cournapeaufd9ee732012-10-09 21:10:5487 blas_lapack.check_blas_lapack(context)
David Cournapeau3cb783e2012-04-16 18:31:4488
Julian Taylorc9fd6342014-04-05 11:13:1389 _generate_cython()
90
David Cournapeau0d8b6362011-06-14 23:40:2691@hooks.pre_build
David Cournapeaua52f88f2011-04-06 00:18:0492def pre_build(context):
David Cournapeau6fe584f2012-06-11 10:14:5893 _register_metadata(context)
David Cournapeau7f302cc2011-11-21 06:03:4494
David Cournapeau6fe584f2012-06-11 10:14:5895@hooks.pre_sdist
96def pre_sdist(context):
97 _register_metadata(context)
David Cournapeaueed23722012-09-09 21:19:0598
99@hooks.options
100def options(global_context):
David Cournapeaufd9ee732012-10-09 21:10:54101 blas_lapack.add_options(global_context)
Ralf Gommers3d431ab2013-05-04 17:28:09102
103
104class CTemplateTask(waflib.Task.Task):
105 color = 'BLUE'
106 before = ['c']
107 def run(self):
108 s = self.inputs[0]
109 cnt = s.read()
110 writestr = process_c_str(cnt)
111 o = self.outputs[0]
112 o.write(writestr)
113
114@waflib.TaskGen.extension(".src")
115def c_template(self, node):
116 outs = []
117 outs.append(node.change_ext(""))
118
119 tsk = self.create_task('CTemplateTask', node, outs)
Ralf Gommers55c76f62013-12-08 15:16:11120 if "c" in self.features and not node.name[-6:] == (".h.src"):
Ralf Gommers3d431ab2013-05-04 17:28:09121 self.source.append(outs[0])