blob: d3db21fa0afcb31776c64c85be5f46efa6fe8a93 [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
David Cournapeaua52f88f2011-04-06 00:18:0421from bento.commands import hooks
David Cournapeau6fe584f2012-06-11 10:14:5822from bento.utils.utils \
23 import \
24 cmd_is_runnable
David Cournapeaud2f648a2011-03-07 00:02:3225
David Cournapeauaa7e9bd2011-03-15 15:39:1526import waflib
27
David Cournapeau7f302cc2011-11-21 06:03:4428sys.path.insert(0, os.getcwd())
29try:
30 _SETUP_PY = __import__("setup")
31finally:
32 sys.path.pop(0)
33
David Cournapeaud2f648a2011-03-07 00:02:3234def check_blas_lapack(conf):
35 conf.env.HAS_CBLAS = False
36 if sys.platform == "win32":
David Cournapeau7129d902011-08-26 11:43:3837 mkl_libs = "mkl_lapack95,mkl_blas95,mkl_intel_c,mkl_intel_thread,mkl_core,libiomp5md".split(",")
38 mkl_base = r"C:\Program Files\Intel\Compiler\11.1\051"
39 conf.env.INCLUDES.append("%s\mkl\include" % mkl_base)
40 conf.env.LIBPATH.extend(["%s\mkl\ia32\lib" % mkl_base,
41 "%s\lib\ia32" % mkl_base])
42
43 try:
44 conf.check_cc(lib=mkl_libs, msg="Checking for MKL (CBLAS)",
45 uselib_store="CBLAS")
46 conf.env.HAS_CBLAS = True
David Cournapeaufd785462012-05-31 15:14:1447 except waflib.Errors.ConfigurationError:
48 conf.env.HAS_LAPACK = False
David Cournapeau7129d902011-08-26 11:43:3849
David Cournapeaufd785462012-05-31 15:14:1450 try:
David Cournapeau7129d902011-08-26 11:43:3851 conf.check_cc(lib=mkl_libs, msg="Checking for MKL (LAPACK)",
52 uselib_store="LAPACK")
53 conf.env.HAS_LAPACK = True
54 except waflib.Errors.ConfigurationError:
David Cournapeaufd785462012-05-31 15:14:1455 conf.env.HAS_LAPACK = False
56
David Cournapeau7129d902011-08-26 11:43:3857
David Cournapeaud2f648a2011-03-07 00:02:3258 elif sys.platform == "darwin":
59 try:
David Cournapeaufd785462012-05-31 15:14:1460 conf.check(framework="Accelerate", msg="Checking for framework Accelerate (CBLAS)", uselib_store="CBLAS")
David Cournapeaud2f648a2011-03-07 00:02:3261 conf.env.HAS_CBLAS = True
David Cournapeaufd785462012-05-31 15:14:1462 except waflib.Errors.ConfigurationError:
63 conf.env.HAS_CBLAS = False
David Cournapeaud2f648a2011-03-07 00:02:3264
David Cournapeaufd785462012-05-31 15:14:1465 try:
66 conf.check(framework="Accelerate", msg="Checking for framework Accelerate (LAPACK)", uselib_store="LAPACK")
David Cournapeaud2f648a2011-03-07 00:02:3267 conf.env.HAS_LAPACK = True
68 except waflib.Errors.ConfigurationError:
David Cournapeaufd785462012-05-31 15:14:1469 conf.env.HAS_LAPACK = False
David Cournapeaud2f648a2011-03-07 00:02:3270 else:
71 try:
72 conf.check_cc(lib=["cblas", "atlas"], uselib_store="CBLAS")
73 conf.env.HAS_CBLAS = True
David Cournapeaufd785462012-05-31 15:14:1474 except waflib.Errors.ConfigurationError:
75 conf.env.HAS_CBLAS = False
David Cournapeaud2f648a2011-03-07 00:02:3276
David Cournapeaufd785462012-05-31 15:14:1477 try:
David Cournapeaud2f648a2011-03-07 00:02:3278 conf.check_cc(lib=["lapack", "f77blas", "cblas", "atlas"],
79 uselib_store="LAPACK")
80 conf.env.HAS_LAPACK = True
81 except waflib.Errors.ConfigurationError:
David Cournapeaufd785462012-05-31 15:14:1482 conf.env.HAS_LAPACK = False
David Cournapeaud2f648a2011-03-07 00:02:3283
84 # You can manually set up blas/lapack as follows:
85 #conf.env.HAS_CBLAS = True
86 #conf.env.LIB_CBLAS = ["cblas", "atlas"]
87 #conf.env.HAS_LAPACK = True
88 #conf.env.LIB_LAPACK = ["lapack", "f77blas", "cblas", "atlas"]
89
David Cournapeau6fe584f2012-06-11 10:14:5890def compute_git_revision(top_node):
91 git_repo_node = top_node.find_node(".git")
92 if git_repo_node and cmd_is_runnable(["git", "--version"]):
93 s = subprocess.Popen(["git", "rev-parse", "HEAD"],
94 stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=top_node.abspath())
95 out = s.communicate()[0]
96 return out.decode().strip()
97 else:
98 return ""
David Cournapeau7f302cc2011-11-21 06:03:4499
David Cournapeau6fe584f2012-06-11 10:14:58100def _register_metadata(context):
101 git_revision = compute_git_revision(context.top_node)
102 full_version = context.pkg.version
David Cournapeau7f302cc2011-11-21 06:03:44103 if not _SETUP_PY.ISRELEASED:
104 full_version += '.dev-' + git_revision[:7]
David Cournapeau7f302cc2011-11-21 06:03:44105
David Cournapeau6fe584f2012-06-11 10:14:58106 context.register_metadata("git_revision", git_revision)
107 context.register_metadata("is_released", _SETUP_PY.ISRELEASED)
108 context.register_metadata("full_version", full_version)
David Cournapeau7f302cc2011-11-21 06:03:44109
David Cournapeau87295b32012-05-31 09:25:20110@hooks.post_configure
111def post_configure(context):
David Cournapeau3cb783e2012-04-16 18:31:44112 conf = context.waf_context
David Cournapeau3cb783e2012-04-16 18:31:44113 if conf.env["CC_NAME"] == "gcc":
114 conf.env.CFLAGS_PYEXT.append("-Wfatal-errors")
115 check_blas_lapack(conf)
116
David Cournapeau0d8b6362011-06-14 23:40:26117@hooks.pre_build
David Cournapeaua52f88f2011-04-06 00:18:04118def pre_build(context):
David Cournapeau6fe584f2012-06-11 10:14:58119 _register_metadata(context)
David Cournapeau7f302cc2011-11-21 06:03:44120
David Cournapeau6fe584f2012-06-11 10:14:58121@hooks.pre_sdist
122def pre_sdist(context):
123 _register_metadata(context)