| David Cournapeau | 3763b57 | 2011-08-27 22:25:14 | [diff] [blame] | 1 | """ |
| David Cournapeau | da2af08 | 2011-09-08 15:31:12 | [diff] [blame] | 2 | See BENTO_BUILD.txt. |
| David Cournapeau | 3763b57 | 2011-08-27 22:25:14 | [diff] [blame] | 3 | |
| 4 | Caveats: |
| 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 Cournapeau | 3763b57 | 2011-08-27 22:25:14 | [diff] [blame] | 10 | """ |
| 11 | |
| David Cournapeau | 7847043 | 2011-05-30 00:10:35 | [diff] [blame] | 12 | import os |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 13 | import sys |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 14 | import subprocess |
| 15 | import string |
| 16 | |
| 17 | import os.path as op |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 18 | |
| David Cournapeau | 0c7af4b | 2011-03-07 00:30:42 | [diff] [blame] | 19 | # Ugly but necessary hack: import numpy here so that wscript in sub directories |
| 20 | # will see this numpy and not an already installed one |
| 21 | import __builtin__ |
| 22 | __builtin__.__NUMPY_SETUP__ = True |
| 23 | |
| David Cournapeau | a52f88f | 2011-04-06 00:18:04 | [diff] [blame] | 24 | from bento.commands import hooks |
| David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 25 | from bento.utils.utils \ |
| 26 | import \ |
| 27 | cmd_is_runnable |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 28 | |
| David Cournapeau | aa7e9bd | 2011-03-15 15:39:15 | [diff] [blame] | 29 | import waflib |
| 30 | |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 31 | sys.path.insert(0, os.getcwd()) |
| 32 | try: |
| 33 | _SETUP_PY = __import__("setup") |
| 34 | finally: |
| 35 | sys.path.pop(0) |
| 36 | |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 37 | def check_blas_lapack(conf): |
| 38 | conf.env.HAS_CBLAS = False |
| 39 | if sys.platform == "win32": |
| David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 40 | mkl_libs = "mkl_lapack95,mkl_blas95,mkl_intel_c,mkl_intel_thread,mkl_core,libiomp5md".split(",") |
| 41 | mkl_base = r"C:\Program Files\Intel\Compiler\11.1\051" |
| 42 | conf.env.INCLUDES.append("%s\mkl\include" % mkl_base) |
| 43 | conf.env.LIBPATH.extend(["%s\mkl\ia32\lib" % mkl_base, |
| 44 | "%s\lib\ia32" % mkl_base]) |
| 45 | |
| 46 | try: |
| 47 | conf.check_cc(lib=mkl_libs, msg="Checking for MKL (CBLAS)", |
| 48 | uselib_store="CBLAS") |
| 49 | conf.env.HAS_CBLAS = True |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 50 | except waflib.Errors.ConfigurationError: |
| 51 | conf.env.HAS_LAPACK = False |
| David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 52 | |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 53 | try: |
| David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 54 | conf.check_cc(lib=mkl_libs, msg="Checking for MKL (LAPACK)", |
| 55 | uselib_store="LAPACK") |
| 56 | conf.env.HAS_LAPACK = True |
| 57 | except waflib.Errors.ConfigurationError: |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 58 | conf.env.HAS_LAPACK = False |
| 59 | |
| David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 60 | |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 61 | elif sys.platform == "darwin": |
| 62 | try: |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 63 | conf.check(framework="Accelerate", msg="Checking for framework Accelerate (CBLAS)", uselib_store="CBLAS") |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 64 | conf.env.HAS_CBLAS = True |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 65 | except waflib.Errors.ConfigurationError: |
| 66 | conf.env.HAS_CBLAS = False |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 67 | |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 68 | try: |
| 69 | conf.check(framework="Accelerate", msg="Checking for framework Accelerate (LAPACK)", uselib_store="LAPACK") |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 70 | conf.env.HAS_LAPACK = True |
| 71 | except waflib.Errors.ConfigurationError: |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 72 | conf.env.HAS_LAPACK = False |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 73 | else: |
| 74 | try: |
| 75 | conf.check_cc(lib=["cblas", "atlas"], uselib_store="CBLAS") |
| 76 | conf.env.HAS_CBLAS = True |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 77 | except waflib.Errors.ConfigurationError: |
| 78 | conf.env.HAS_CBLAS = False |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 79 | |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 80 | try: |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 81 | conf.check_cc(lib=["lapack", "f77blas", "cblas", "atlas"], |
| 82 | uselib_store="LAPACK") |
| 83 | conf.env.HAS_LAPACK = True |
| 84 | except waflib.Errors.ConfigurationError: |
| David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 85 | conf.env.HAS_LAPACK = False |
| David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 86 | |
| 87 | # You can manually set up blas/lapack as follows: |
| 88 | #conf.env.HAS_CBLAS = True |
| 89 | #conf.env.LIB_CBLAS = ["cblas", "atlas"] |
| 90 | #conf.env.HAS_LAPACK = True |
| 91 | #conf.env.LIB_LAPACK = ["lapack", "f77blas", "cblas", "atlas"] |
| 92 | |
| David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 93 | def compute_git_revision(top_node): |
| 94 | git_repo_node = top_node.find_node(".git") |
| 95 | if git_repo_node and cmd_is_runnable(["git", "--version"]): |
| 96 | s = subprocess.Popen(["git", "rev-parse", "HEAD"], |
| 97 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=top_node.abspath()) |
| 98 | out = s.communicate()[0] |
| 99 | return out.decode().strip() |
| 100 | else: |
| 101 | return "" |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 102 | |
| David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 103 | def _register_metadata(context): |
| 104 | git_revision = compute_git_revision(context.top_node) |
| 105 | full_version = context.pkg.version |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 106 | if not _SETUP_PY.ISRELEASED: |
| 107 | full_version += '.dev-' + git_revision[:7] |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 108 | |
| David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 109 | context.register_metadata("git_revision", git_revision) |
| 110 | context.register_metadata("is_released", _SETUP_PY.ISRELEASED) |
| 111 | context.register_metadata("full_version", full_version) |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 112 | |
| David Cournapeau | 87295b3 | 2012-05-31 09:25:20 | [diff] [blame] | 113 | @hooks.post_configure |
| 114 | def post_configure(context): |
| David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 115 | conf = context.waf_context |
| David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 116 | if conf.env["CC_NAME"] == "gcc": |
| 117 | conf.env.CFLAGS_PYEXT.append("-Wfatal-errors") |
| 118 | check_blas_lapack(conf) |
| 119 | |
| David Cournapeau | 0d8b636 | 2011-06-14 23:40:26 | [diff] [blame] | 120 | @hooks.pre_build |
| David Cournapeau | a52f88f | 2011-04-06 00:18:04 | [diff] [blame] | 121 | def pre_build(context): |
| David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 122 | _register_metadata(context) |
| David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 123 | |
| David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 124 | @hooks.pre_sdist |
| 125 | def pre_sdist(context): |
| 126 | _register_metadata(context) |