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 |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 15 | |
David Cournapeau | 0c7af4b | 2011-03-07 00:30:42 | [diff] [blame] | 16 | # Ugly but necessary hack: import numpy here so that wscript in sub directories |
| 17 | # will see this numpy and not an already installed one |
| 18 | import __builtin__ |
| 19 | __builtin__.__NUMPY_SETUP__ = True |
| 20 | |
David Cournapeau | a52f88f | 2011-04-06 00:18:04 | [diff] [blame] | 21 | from bento.commands import hooks |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 22 | from bento.utils.utils \ |
| 23 | import \ |
| 24 | cmd_is_runnable |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 25 | |
David Cournapeau | aa7e9bd | 2011-03-15 15:39:15 | [diff] [blame] | 26 | import waflib |
| 27 | |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 28 | sys.path.insert(0, os.getcwd()) |
| 29 | try: |
| 30 | _SETUP_PY = __import__("setup") |
| 31 | finally: |
| 32 | sys.path.pop(0) |
| 33 | |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 34 | def check_blas_lapack(conf): |
| 35 | conf.env.HAS_CBLAS = False |
| 36 | if sys.platform == "win32": |
David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 37 | 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 Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 47 | except waflib.Errors.ConfigurationError: |
| 48 | conf.env.HAS_LAPACK = False |
David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 49 | |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 50 | try: |
David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 51 | 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 Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 55 | conf.env.HAS_LAPACK = False |
| 56 | |
David Cournapeau | 7129d90 | 2011-08-26 11:43:38 | [diff] [blame] | 57 | |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 58 | elif sys.platform == "darwin": |
| 59 | try: |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 60 | conf.check(framework="Accelerate", msg="Checking for framework Accelerate (CBLAS)", uselib_store="CBLAS") |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 61 | conf.env.HAS_CBLAS = True |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 62 | except waflib.Errors.ConfigurationError: |
| 63 | conf.env.HAS_CBLAS = False |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 64 | |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 65 | try: |
| 66 | conf.check(framework="Accelerate", msg="Checking for framework Accelerate (LAPACK)", uselib_store="LAPACK") |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 67 | conf.env.HAS_LAPACK = True |
| 68 | except waflib.Errors.ConfigurationError: |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 69 | conf.env.HAS_LAPACK = False |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 70 | else: |
| 71 | try: |
| 72 | conf.check_cc(lib=["cblas", "atlas"], uselib_store="CBLAS") |
| 73 | conf.env.HAS_CBLAS = True |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 74 | except waflib.Errors.ConfigurationError: |
| 75 | conf.env.HAS_CBLAS = False |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 76 | |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 77 | try: |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 78 | conf.check_cc(lib=["lapack", "f77blas", "cblas", "atlas"], |
| 79 | uselib_store="LAPACK") |
| 80 | conf.env.HAS_LAPACK = True |
| 81 | except waflib.Errors.ConfigurationError: |
David Cournapeau | fd78546 | 2012-05-31 15:14:14 | [diff] [blame] | 82 | conf.env.HAS_LAPACK = False |
David Cournapeau | d2f648a | 2011-03-07 00:02:32 | [diff] [blame] | 83 | |
| 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 Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 90 | def 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 Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 99 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 100 | def _register_metadata(context): |
| 101 | git_revision = compute_git_revision(context.top_node) |
| 102 | full_version = context.pkg.version |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 103 | if not _SETUP_PY.ISRELEASED: |
| 104 | full_version += '.dev-' + git_revision[:7] |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 105 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 106 | 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 Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 109 | |
David Cournapeau | 87295b3 | 2012-05-31 09:25:20 | [diff] [blame] | 110 | @hooks.post_configure |
| 111 | def post_configure(context): |
David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 112 | conf = context.waf_context |
David Cournapeau | 3cb783e | 2012-04-16 18:31:44 | [diff] [blame] | 113 | if conf.env["CC_NAME"] == "gcc": |
| 114 | conf.env.CFLAGS_PYEXT.append("-Wfatal-errors") |
| 115 | check_blas_lapack(conf) |
| 116 | |
David Cournapeau | 0d8b636 | 2011-06-14 23:40:26 | [diff] [blame] | 117 | @hooks.pre_build |
David Cournapeau | a52f88f | 2011-04-06 00:18:04 | [diff] [blame] | 118 | def pre_build(context): |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 119 | _register_metadata(context) |
David Cournapeau | 7f302cc | 2011-11-21 06:03:44 | [diff] [blame] | 120 | |
David Cournapeau | 6fe584f | 2012-06-11 10:14:58 | [diff] [blame] | 121 | @hooks.pre_sdist |
| 122 | def pre_sdist(context): |
| 123 | _register_metadata(context) |