We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
intel-tbb broken if no transactional memory
I tried to install intel-tbb on an old Intel x86-64 cluster at Rice.
The build fails with:

% spack  install  intel-tbb
...
     21    /work/hpc/krentel/work/spack-repo/lib/spack/env/gcc/g++ -o scheduler.o -c -MMD -DTBB_USE_DEBUG -DDO_ITT_NOTIFY -g -O0 -DUSE_PTHREAD -m64 -mrtm  -fPIC  -D__TBB_BUILD=1 -Wall -Wno-parentheses -Wno-non-virtual-dtor    -I../../src -I../../src/rml/include -I../../include ../../src/tbb/scheduler.cpp
     22    /tmp/cchPyt9b.s: Assembler messages:
  >> 23    /tmp/cchPyt9b.s:672: Error: no such instruction: `xtest'
  >> 24    /tmp/cchPyt9b.s:691: Error: no such instruction: `xend'

The problem is that xtest and xend are transactional memory
instructions and either the machine or the compiler don't understand
transactional memory.

/proc/cpuinfo reports:

processor	: 11
vendor_id	: GenuineIntel
cpu family	: 6
model		: 44
model name	: Intel(R) Xeon(R) CPU     X5660  @ 2.80GHz
stepping	: 2
microcode	: 16
cpu MHz		: 2800.047
cache size	: 12288 KB
...
flags		: fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm arat epb dtherm tpr_shadow vnmi flexpriority ept vpid

Looking inside the tbb source, we see in include/tbb/tbb_config.h:

#define __TBB_TSX_AVAILABLE  ((__TBB_x86_32 || __TBB_x86_64) && !__TBB_DEFINE_MIC)

So, the real problem is that Intel thinks that all 64-bit x86 machines
(except Xeon Phi/MIC) have transactional memory, and that's not true.

One solution would be to patch the #define to 0, but that would
disable all transactional memory.

I guess a more spack-ish solution would be to add a 'transactional-memory'
variant to intel-tbb and conditionally apply a patch, or otherwise set
__TBB_TSX_AVAILABLE to 0.

But what I really want is a better way to auto test if the given
machine (or host machine in a cross compile) supports some feature, in
this case transactional memory.  I'll open a separate issue for that.

Thanks,

--Mark

P.S. I did search for intel-tbb, but I didn't find anything related to
transactional memory.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `var/spack/repos/builtin/packages/intel-tbb/package.py`
Content:
```
1 ##############################################################################
2 # Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.
3 # Produced at the Lawrence Livermore National Laboratory.
4 #
5 # This file is part of Spack.
6 # Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.
7 # LLNL-CODE-647188
8 #
9 # For details, see https://github.com/spack/spack
10 # Please also see the NOTICE and LICENSE files for our notice and the LGPL.
11 #
12 # This program is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License (as
14 # published by the Free Software Foundation) version 2.1, February 1999.
15 #
16 # This program is distributed in the hope that it will be useful, but
17 # WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and
19 # conditions of the GNU Lesser General Public License for more details.
20 #
21 # You should have received a copy of the GNU Lesser General Public
22 # License along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ##############################################################################
25 from spack import *
26 import glob
27 import inspect
28 import platform
29 
30 
31 class IntelTbb(Package):
32     """Widely used C++ template library for task parallelism.
33     Intel Threading Building Blocks (Intel TBB) lets you easily write parallel
34     C++ programs that take full advantage of multicore performance, that are
35     portable and composable, and that have future-proof scalability.
36     """
37     homepage = "http://www.threadingbuildingblocks.org/"
38 
39     # See url_for_version() below.
40     version('2018.4', '5e2e6ba0e25624a94331c945856551c2')
41     version('2018.3', 'cd2e136598ffa5c136f077ee85a35b4c')
42     version('2018.2', '0b8dfe30917a54e40828eeb0ed7562ae')
43     version('2018.1', 'b2f2fa09adf44a22f4024049907f774b')
44     version('2018',   '7fb30d5ea2545f26ce02757d9ab05e6c')
45     version('2017.8', '7240f57f1aeea0e266a5e17ae68fdc16')
46     version('2017.7', '364f2a4b80e978f38a69cbf7c466b898')
47     version('2017.6', 'ec21254af4fc2a29574c272f501a3138')
48     version('2017.5', '85b41c64102c052e24d8a39f6193e599')
49     version('2017.4', '71526b2fef098515e212302d1455de7d')
50     version('2017.3', 'd7622eeaafeff8d271c7aa684bd82ddb')
51     version('2017.2', '9605cbea96998a10a186fc72c35cbd76')
52     version('2017.1', '6c0fe8aa7bc911a85e8e522e620511b3')
53     version('2017',   '9e7f9ea684ecf84ac74dcd3c6012cfa6')
54     version('4.4.6',  '20e15206f70c2651bfc964e451a443a0')
55     version('4.4.5',  '531a67cd98f9b4ec8ece95c5f8193a83')
56     version('4.4.4',  '61531b2e8684e06a621dcdca1a7a420e')
57     version('4.4.3',  '8e3e39e1fdfb3f7c3a5ac8ec1afe186e')
58     version('4.4.2',  'e92b110e8eb238741b00e3789b39969e')
59     version('4.4.1',  'a02c9958f02c1b5f3626874219979ae8')
60     version('4.4',    '1d512085221996eae6cec04e1a4cd3dd')
61 
62     provides('tbb')
63 
64     conflicts('%gcc@6.1:', when='@:4.4.3',
65               msg='4.4.4 or later required for GCC >= 6.1.')
66 
67     variant('shared', default=True,
68             description='Builds a shared version of TBB libraries')
69 
70     variant('cxxstd',
71             default='default',
72             values=('default', '98', '11', '14', '17'),
73             multi=False,
74             description='Use the specified C++ standard when building.')
75 
76     # Build and install CMake config files if we're new enough.
77     depends_on('cmake@3.0.0:', type='build', when='@2017.0:')
78 
79     # Deactivate use of RTM with GCC when on an OS with an elderly assembler.
80     patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=rhel6')
81     patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=scientific6')
82     patch("tbb_gcc_rtm_key.patch", level=0, when='%gcc@4.8.0: os=centos6')
83 
84     # Patch cmakeConfig.cmake.in to find the libraries where we install them.
85     patch("tbb_cmakeConfig.patch", level=0, when='@2017.0:')
86 
87     def url_for_version(self, version):
88         url = 'https://github.com/01org/tbb/archive/{0}.tar.gz'
89         if (version[0] >= 2017) and len(version) > 1:
90             return url.format('{0}_U{1}'.format(version[0], version[1]))
91         else:
92             return url.format(version)
93 
94     def coerce_to_spack(self, tbb_build_subdir):
95         for compiler in ["icc", "gcc", "clang"]:
96             fs = glob.glob(join_path(tbb_build_subdir,
97                                      "*.%s.inc" % compiler))
98             for f in fs:
99                 lines = open(f).readlines()
100                 of = open(f, "w")
101                 for l in lines:
102                     if l.strip().startswith("CPLUS ="):
103                         of.write("# coerced to spack\n")
104                         of.write("CPLUS = $(CXX)\n")
105                     elif l.strip().startswith("CPLUS ="):
106                         of.write("# coerced to spack\n")
107                         of.write("CONLY = $(CC)\n")
108                     else:
109                         of.write(l)
110 
111     def install(self, spec, prefix):
112         # We need to follow TBB's compiler selection logic to get the proper
113         # build + link flags but we still need to use spack's compiler wrappers
114         # to accomplish this, we do two things:
115         #
116         # * Look at the spack spec to determine which compiler we should pass
117         #   to tbb's Makefile;
118         #
119         # * patch tbb's build system to use the compiler wrappers (CC, CXX) for
120         #   icc, gcc, clang (see coerce_to_spack());
121         #
122         self.coerce_to_spack("build")
123 
124         if spec.satisfies('%clang'):
125             tbb_compiler = "clang"
126         elif spec.satisfies('%intel'):
127             tbb_compiler = "icc"
128         else:
129             tbb_compiler = "gcc"
130 
131         mkdirp(prefix)
132         mkdirp(prefix.lib)
133 
134         make_opts = []
135 
136         # Static builds of TBB are enabled by including 'big_iron.inc' file
137         # See caveats in 'big_iron.inc' for limits on using TBB statically
138         # Lore states this file must be handed to make before other options
139         if '+shared' not in self.spec:
140             make_opts.append("extra_inc=big_iron.inc")
141 
142         if spec.variants['cxxstd'].value != 'default':
143             make_opts.append('stdver=c++{0}'.
144                              format(spec.variants['cxxstd'].value))
145 
146         #
147         # tbb does not have a configure script or make install target
148         # we simply call make, and try to put the pieces together
149         #
150         make_opts.append("compiler={0}".format(tbb_compiler))
151         make(*make_opts)
152 
153         # install headers to {prefix}/include
154         install_tree('include', prefix.include)
155 
156         # install libs to {prefix}/lib
157         tbb_lib_names = ["libtbb",
158                          "libtbbmalloc",
159                          "libtbbmalloc_proxy"]
160 
161         for lib_name in tbb_lib_names:
162             # install release libs
163             fs = glob.glob(join_path("build", "*release", lib_name + ".*"))
164             for f in fs:
165                 install(f, prefix.lib)
166             # install debug libs if they exist
167             fs = glob.glob(join_path("build", "*debug", lib_name + "_debug.*"))
168             for f in fs:
169                 install(f, prefix.lib)
170 
171         if self.spec.satisfies('@2017.0:'):
172             # Generate and install the CMake Config file.
173             cmake_args = ('-DTBB_ROOT={0}'.format(prefix),
174                           '-DTBB_OS={0}'.format(platform.system()),
175                           '-P',
176                           'tbb_config_generator.cmake')
177             with working_dir(join_path(self.stage.source_path, 'cmake')):
178                 inspect.getmodule(self).cmake(*cmake_args)
179
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/var/spack/repos/builtin/packages/intel-tbb/package.py b/var/spack/repos/builtin/packages/intel-tbb/package.py
--- a/var/spack/repos/builtin/packages/intel-tbb/package.py
+++ b/var/spack/repos/builtin/packages/intel-tbb/package.py
@@ -73,6 +73,9 @@
             multi=False,
             description='Use the specified C++ standard when building.')
 
+    variant('tm', default=True,
+            description='Enable use of transactional memory on x86')
+
     # Build and install CMake config files if we're new enough.
     depends_on('cmake@3.0.0:', type='build', when='@2017.0:')
 
@@ -84,6 +87,9 @@
     # Patch cmakeConfig.cmake.in to find the libraries where we install them.
     patch("tbb_cmakeConfig.patch", level=0, when='@2017.0:')
 
+    # Some very old systems don't support transactional memory.
+    patch("disable-tm.patch", when='~tm')
+
     def url_for_version(self, version):
         url = 'https://github.com/01org/tbb/archive/{0}.tar.gz'
         if (version[0] >= 2017) and len(version) > 1:

{"golden_diff": "diff --git a/var/spack/repos/builtin/packages/intel-tbb/package.py b/var/spack/repos/builtin/packages/intel-tbb/package.py\n--- a/var/spack/repos/builtin/packages/intel-tbb/package.py\n+++ b/var/spack/repos/builtin/packages/intel-tbb/package.py\n@@ -73,6 +73,9 @@\n             multi=False,\n             description='Use the specified C++ standard when building.')\n \n+    variant('tm', default=True,\n+            description='Enable use of transactional memory on x86')\n+\n     # Build and install CMake config files if we're new enough.\n     depends_on('cmake@3.0.0:', type='build', when='@2017.0:')\n \n@@ -84,6 +87,9 @@\n     # Patch cmakeConfig.cmake.in to find the libraries where we install them.\n     patch(\"tbb_cmakeConfig.patch\", level=0, when='@2017.0:')\n \n+    # Some very old systems don't support transactional memory.\n+    patch(\"disable-tm.patch\", when='~tm')\n+\n     def url_for_version(self, version):\n         url = 'https://github.com/01org/tbb/archive/{0}.tar.gz'\n         if (version[0] >= 2017) and len(version) > 1:\n", "issue": "intel-tbb broken if no transactional memory\nI tried to install intel-tbb on an old Intel x86-64 cluster at Rice.\r\nThe build fails with:\r\n\r\n% spack  install  intel-tbb\r\n...\r\n     21    /work/hpc/krentel/work/spack-repo/lib/spack/env/gcc/g++ -o scheduler.o -c -MMD -DTBB_USE_DEBUG -DDO_ITT_NOTIFY -g -O0 -DUSE_PTHREAD -m64 -mrtm  -fPIC  -D__TBB_BUILD=1 -Wall -Wno-parentheses -Wno-non-virtual-dtor    -I../../src -I../../src/rml/include -I../../include ../../src/tbb/scheduler.cpp\r\n     22    /tmp/cchPyt9b.s: Assembler messages:\r\n  >> 23    /tmp/cchPyt9b.s:672: Error: no such instruction: `xtest'\r\n  >> 24    /tmp/cchPyt9b.s:691: Error: no such instruction: `xend'\r\n\r\nThe problem is that xtest and xend are transactional memory\r\ninstructions and either the machine or the compiler don't understand\r\ntransactional memory.\r\n\r\n/proc/cpuinfo reports:\r\n\r\nprocessor\t: 11\r\nvendor_id\t: GenuineIntel\r\ncpu family\t: 6\r\nmodel\t\t: 44\r\nmodel name\t: Intel(R) Xeon(R) CPU     X5660  @ 2.80GHz\r\nstepping\t: 2\r\nmicrocode\t: 16\r\ncpu MHz\t\t: 2800.047\r\ncache size\t: 12288 KB\r\n...\r\nflags\t\t: fpu vme de pse tsc msr pae mce cx8 apic mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 popcnt aes lahf_lm arat epb dtherm tpr_shadow vnmi flexpriority ept vpid\r\n\r\nLooking inside the tbb source, we see in include/tbb/tbb_config.h:\r\n\r\n#define __TBB_TSX_AVAILABLE  ((__TBB_x86_32 || __TBB_x86_64) && !__TBB_DEFINE_MIC)\r\n\r\nSo, the real problem is that Intel thinks that all 64-bit x86 machines\r\n(except Xeon Phi/MIC) have transactional memory, and that's not true.\r\n\r\nOne solution would be to patch the #define to 0, but that would\r\ndisable all transactional memory.\r\n\r\nI guess a more spack-ish solution would be to add a 'transactional-memory'\r\nvariant to intel-tbb and conditionally apply a patch, or otherwise set\r\n__TBB_TSX_AVAILABLE to 0.\r\n\r\nBut what I really want is a better way to auto test if the given\r\nmachine (or host machine in a cross compile) supports some feature, in\r\nthis case transactional memory.  I'll open a separate issue for that.\r\n\r\nThanks,\r\n\r\n--Mark\r\n\r\nP.S. I did search for intel-tbb, but I didn't find anything related to\r\ntransactional memory.\r\n\n", "before_files": [{"content": "##############################################################################\n# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.\n# Produced at the Lawrence Livermore National Laboratory.\n#\n# This file is part of Spack.\n# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.\n# LLNL-CODE-647188\n#\n# For details, see https://github.com/spack/spack\n# Please also see the NOTICE and LICENSE files for our notice and the LGPL.\n#\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU Lesser General Public License (as\n# published by the Free Software Foundation) version 2.1, February 1999.\n#\n# This program is distributed in the hope that it will be useful, but\n# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and\n# conditions of the GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this program; if not, write to the Free Software\n# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n##############################################################################\nfrom spack import *\nimport glob\nimport inspect\nimport platform\n\n\nclass IntelTbb(Package):\n    \"\"\"Widely used C++ template library for task parallelism.\n    Intel Threading Building Blocks (Intel TBB) lets you easily write parallel\n    C++ programs that take full advantage of multicore performance, that are\n    portable and composable, and that have future-proof scalability.\n    \"\"\"\n    homepage = \"http://www.threadingbuildingblocks.org/\"\n\n    # See url_for_version() below.\n    version('2018.4', '5e2e6ba0e25624a94331c945856551c2')\n    version('2018.3', 'cd2e136598ffa5c136f077ee85a35b4c')\n    version('2018.2', '0b8dfe30917a54e40828eeb0ed7562ae')\n    version('2018.1', 'b2f2fa09adf44a22f4024049907f774b')\n    version('2018',   '7fb30d5ea2545f26ce02757d9ab05e6c')\n    version('2017.8', '7240f57f1aeea0e266a5e17ae68fdc16')\n    version('2017.7', '364f2a4b80e978f38a69cbf7c466b898')\n    version('2017.6', 'ec21254af4fc2a29574c272f501a3138')\n    version('2017.5', '85b41c64102c052e24d8a39f6193e599')\n    version('2017.4', '71526b2fef098515e212302d1455de7d')\n    version('2017.3', 'd7622eeaafeff8d271c7aa684bd82ddb')\n    version('2017.2', '9605cbea96998a10a186fc72c35cbd76')\n    version('2017.1', '6c0fe8aa7bc911a85e8e522e620511b3')\n    version('2017',   '9e7f9ea684ecf84ac74dcd3c6012cfa6')\n    version('4.4.6',  '20e15206f70c2651bfc964e451a443a0')\n    version('4.4.5',  '531a67cd98f9b4ec8ece95c5f8193a83')\n    version('4.4.4',  '61531b2e8684e06a621dcdca1a7a420e')\n    version('4.4.3',  '8e3e39e1fdfb3f7c3a5ac8ec1afe186e')\n    version('4.4.2',  'e92b110e8eb238741b00e3789b39969e')\n    version('4.4.1',  'a02c9958f02c1b5f3626874219979ae8')\n    version('4.4',    '1d512085221996eae6cec04e1a4cd3dd')\n\n    provides('tbb')\n\n    conflicts('%gcc@6.1:', when='@:4.4.3',\n              msg='4.4.4 or later required for GCC >= 6.1.')\n\n    variant('shared', default=True,\n            description='Builds a shared version of TBB libraries')\n\n    variant('cxxstd',\n            default='default',\n            values=('default', '98', '11', '14', '17'),\n            multi=False,\n            description='Use the specified C++ standard when building.')\n\n    # Build and install CMake config files if we're new enough.\n    depends_on('cmake@3.0.0:', type='build', when='@2017.0:')\n\n    # Deactivate use of RTM with GCC when on an OS with an elderly assembler.\n    patch(\"tbb_gcc_rtm_key.patch\", level=0, when='%gcc@4.8.0: os=rhel6')\n    patch(\"tbb_gcc_rtm_key.patch\", level=0, when='%gcc@4.8.0: os=scientific6')\n    patch(\"tbb_gcc_rtm_key.patch\", level=0, when='%gcc@4.8.0: os=centos6')\n\n    # Patch cmakeConfig.cmake.in to find the libraries where we install them.\n    patch(\"tbb_cmakeConfig.patch\", level=0, when='@2017.0:')\n\n    def url_for_version(self, version):\n        url = 'https://github.com/01org/tbb/archive/{0}.tar.gz'\n        if (version[0] >= 2017) and len(version) > 1:\n            return url.format('{0}_U{1}'.format(version[0], version[1]))\n        else:\n            return url.format(version)\n\n    def coerce_to_spack(self, tbb_build_subdir):\n        for compiler in [\"icc\", \"gcc\", \"clang\"]:\n            fs = glob.glob(join_path(tbb_build_subdir,\n                                     \"*.%s.inc\" % compiler))\n            for f in fs:\n                lines = open(f).readlines()\n                of = open(f, \"w\")\n                for l in lines:\n                    if l.strip().startswith(\"CPLUS =\"):\n                        of.write(\"# coerced to spack\\n\")\n                        of.write(\"CPLUS = $(CXX)\\n\")\n                    elif l.strip().startswith(\"CPLUS =\"):\n                        of.write(\"# coerced to spack\\n\")\n                        of.write(\"CONLY = $(CC)\\n\")\n                    else:\n                        of.write(l)\n\n    def install(self, spec, prefix):\n        # We need to follow TBB's compiler selection logic to get the proper\n        # build + link flags but we still need to use spack's compiler wrappers\n        # to accomplish this, we do two things:\n        #\n        # * Look at the spack spec to determine which compiler we should pass\n        #   to tbb's Makefile;\n        #\n        # * patch tbb's build system to use the compiler wrappers (CC, CXX) for\n        #   icc, gcc, clang (see coerce_to_spack());\n        #\n        self.coerce_to_spack(\"build\")\n\n        if spec.satisfies('%clang'):\n            tbb_compiler = \"clang\"\n        elif spec.satisfies('%intel'):\n            tbb_compiler = \"icc\"\n        else:\n            tbb_compiler = \"gcc\"\n\n        mkdirp(prefix)\n        mkdirp(prefix.lib)\n\n        make_opts = []\n\n        # Static builds of TBB are enabled by including 'big_iron.inc' file\n        # See caveats in 'big_iron.inc' for limits on using TBB statically\n        # Lore states this file must be handed to make before other options\n        if '+shared' not in self.spec:\n            make_opts.append(\"extra_inc=big_iron.inc\")\n\n        if spec.variants['cxxstd'].value != 'default':\n            make_opts.append('stdver=c++{0}'.\n                             format(spec.variants['cxxstd'].value))\n\n        #\n        # tbb does not have a configure script or make install target\n        # we simply call make, and try to put the pieces together\n        #\n        make_opts.append(\"compiler={0}\".format(tbb_compiler))\n        make(*make_opts)\n\n        # install headers to {prefix}/include\n        install_tree('include', prefix.include)\n\n        # install libs to {prefix}/lib\n        tbb_lib_names = [\"libtbb\",\n                         \"libtbbmalloc\",\n                         \"libtbbmalloc_proxy\"]\n\n        for lib_name in tbb_lib_names:\n            # install release libs\n            fs = glob.glob(join_path(\"build\", \"*release\", lib_name + \".*\"))\n            for f in fs:\n                install(f, prefix.lib)\n            # install debug libs if they exist\n            fs = glob.glob(join_path(\"build\", \"*debug\", lib_name + \"_debug.*\"))\n            for f in fs:\n                install(f, prefix.lib)\n\n        if self.spec.satisfies('@2017.0:'):\n            # Generate and install the CMake Config file.\n            cmake_args = ('-DTBB_ROOT={0}'.format(prefix),\n                          '-DTBB_OS={0}'.format(platform.system()),\n                          '-P',\n                          'tbb_config_generator.cmake')\n            with working_dir(join_path(self.stage.source_path, 'cmake')):\n                inspect.getmodule(self).cmake(*cmake_args)\n", "path": "var/spack/repos/builtin/packages/intel-tbb/package.py"}], "after_files": [{"content": "##############################################################################\n# Copyright (c) 2013-2018, Lawrence Livermore National Security, LLC.\n# Produced at the Lawrence Livermore National Laboratory.\n#\n# This file is part of Spack.\n# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved.\n# LLNL-CODE-647188\n#\n# For details, see https://github.com/spack/spack\n# Please also see the NOTICE and LICENSE files for our notice and the LGPL.\n#\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU Lesser General Public License (as\n# published by the Free Software Foundation) version 2.1, February 1999.\n#\n# This program is distributed in the hope that it will be useful, but\n# WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and\n# conditions of the GNU Lesser General Public License for more details.\n#\n# You should have received a copy of the GNU Lesser General Public\n# License along with this program; if not, write to the Free Software\n# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n##############################################################################\nfrom spack import *\nimport glob\nimport inspect\nimport platform\n\n\nclass IntelTbb(Package):\n    \"\"\"Widely used C++ template library for task parallelism.\n    Intel Threading Building Blocks (Intel TBB) lets you easily write parallel\n    C++ programs that take full advantage of multicore performance, that are\n    portable and composable, and that have future-proof scalability.\n    \"\"\"\n    homepage = \"http://www.threadingbuildingblocks.org/\"\n\n    # See url_for_version() below.\n    version('2018.4', '5e2e6ba0e25624a94331c945856551c2')\n    version('2018.3', 'cd2e136598ffa5c136f077ee85a35b4c')\n    version('2018.2', '0b8dfe30917a54e40828eeb0ed7562ae')\n    version('2018.1', 'b2f2fa09adf44a22f4024049907f774b')\n    version('2018',   '7fb30d5ea2545f26ce02757d9ab05e6c')\n    version('2017.8', '7240f57f1aeea0e266a5e17ae68fdc16')\n    version('2017.7', '364f2a4b80e978f38a69cbf7c466b898')\n    version('2017.6', 'ec21254af4fc2a29574c272f501a3138')\n    version('2017.5', '85b41c64102c052e24d8a39f6193e599')\n    version('2017.4', '71526b2fef098515e212302d1455de7d')\n    version('2017.3', 'd7622eeaafeff8d271c7aa684bd82ddb')\n    version('2017.2', '9605cbea96998a10a186fc72c35cbd76')\n    version('2017.1', '6c0fe8aa7bc911a85e8e522e620511b3')\n    version('2017',   '9e7f9ea684ecf84ac74dcd3c6012cfa6')\n    version('4.4.6',  '20e15206f70c2651bfc964e451a443a0')\n    version('4.4.5',  '531a67cd98f9b4ec8ece95c5f8193a83')\n    version('4.4.4',  '61531b2e8684e06a621dcdca1a7a420e')\n    version('4.4.3',  '8e3e39e1fdfb3f7c3a5ac8ec1afe186e')\n    version('4.4.2',  'e92b110e8eb238741b00e3789b39969e')\n    version('4.4.1',  'a02c9958f02c1b5f3626874219979ae8')\n    version('4.4',    '1d512085221996eae6cec04e1a4cd3dd')\n\n    provides('tbb')\n\n    conflicts('%gcc@6.1:', when='@:4.4.3',\n              msg='4.4.4 or later required for GCC >= 6.1.')\n\n    variant('shared', default=True,\n            description='Builds a shared version of TBB libraries')\n\n    variant('cxxstd',\n            default='default',\n            values=('default', '98', '11', '14', '17'),\n            multi=False,\n            description='Use the specified C++ standard when building.')\n\n    variant('tm', default=True,\n            description='Enable use of transactional memory on x86')\n\n    # Build and install CMake config files if we're new enough.\n    depends_on('cmake@3.0.0:', type='build', when='@2017.0:')\n\n    # Deactivate use of RTM with GCC when on an OS with an elderly assembler.\n    patch(\"tbb_gcc_rtm_key.patch\", level=0, when='%gcc@4.8.0: os=rhel6')\n    patch(\"tbb_gcc_rtm_key.patch\", level=0, when='%gcc@4.8.0: os=scientific6')\n    patch(\"tbb_gcc_rtm_key.patch\", level=0, when='%gcc@4.8.0: os=centos6')\n\n    # Patch cmakeConfig.cmake.in to find the libraries where we install them.\n    patch(\"tbb_cmakeConfig.patch\", level=0, when='@2017.0:')\n\n    # Some very old systems don't support transactional memory.\n    patch(\"disable-tm.patch\", when='~tm')\n\n    def url_for_version(self, version):\n        url = 'https://github.com/01org/tbb/archive/{0}.tar.gz'\n        if (version[0] >= 2017) and len(version) > 1:\n            return url.format('{0}_U{1}'.format(version[0], version[1]))\n        else:\n            return url.format(version)\n\n    def coerce_to_spack(self, tbb_build_subdir):\n        for compiler in [\"icc\", \"gcc\", \"clang\"]:\n            fs = glob.glob(join_path(tbb_build_subdir,\n                                     \"*.%s.inc\" % compiler))\n            for f in fs:\n                lines = open(f).readlines()\n                of = open(f, \"w\")\n                for l in lines:\n                    if l.strip().startswith(\"CPLUS =\"):\n                        of.write(\"# coerced to spack\\n\")\n                        of.write(\"CPLUS = $(CXX)\\n\")\n                    elif l.strip().startswith(\"CPLUS =\"):\n                        of.write(\"# coerced to spack\\n\")\n                        of.write(\"CONLY = $(CC)\\n\")\n                    else:\n                        of.write(l)\n\n    def install(self, spec, prefix):\n        # We need to follow TBB's compiler selection logic to get the proper\n        # build + link flags but we still need to use spack's compiler wrappers\n        # to accomplish this, we do two things:\n        #\n        # * Look at the spack spec to determine which compiler we should pass\n        #   to tbb's Makefile;\n        #\n        # * patch tbb's build system to use the compiler wrappers (CC, CXX) for\n        #   icc, gcc, clang (see coerce_to_spack());\n        #\n        self.coerce_to_spack(\"build\")\n\n        if spec.satisfies('%clang'):\n            tbb_compiler = \"clang\"\n        elif spec.satisfies('%intel'):\n            tbb_compiler = \"icc\"\n        else:\n            tbb_compiler = \"gcc\"\n\n        mkdirp(prefix)\n        mkdirp(prefix.lib)\n\n        make_opts = []\n\n        # Static builds of TBB are enabled by including 'big_iron.inc' file\n        # See caveats in 'big_iron.inc' for limits on using TBB statically\n        # Lore states this file must be handed to make before other options\n        if '+shared' not in self.spec:\n            make_opts.append(\"extra_inc=big_iron.inc\")\n\n        if spec.variants['cxxstd'].value != 'default':\n            make_opts.append('stdver=c++{0}'.\n                             format(spec.variants['cxxstd'].value))\n\n        #\n        # tbb does not have a configure script or make install target\n        # we simply call make, and try to put the pieces together\n        #\n        make_opts.append(\"compiler={0}\".format(tbb_compiler))\n        make(*make_opts)\n\n        # install headers to {prefix}/include\n        install_tree('include', prefix.include)\n\n        # install libs to {prefix}/lib\n        tbb_lib_names = [\"libtbb\",\n                         \"libtbbmalloc\",\n                         \"libtbbmalloc_proxy\"]\n\n        for lib_name in tbb_lib_names:\n            # install release libs\n            fs = glob.glob(join_path(\"build\", \"*release\", lib_name + \".*\"))\n            for f in fs:\n                install(f, prefix.lib)\n            # install debug libs if they exist\n            fs = glob.glob(join_path(\"build\", \"*debug\", lib_name + \"_debug.*\"))\n            for f in fs:\n                install(f, prefix.lib)\n\n        if self.spec.satisfies('@2017.0:'):\n            # Generate and install the CMake Config file.\n            cmake_args = ('-DTBB_ROOT={0}'.format(prefix),\n                          '-DTBB_OS={0}'.format(platform.system()),\n                          '-P',\n                          'tbb_config_generator.cmake')\n            with working_dir(join_path(self.stage.source_path, 'cmake')):\n                inspect.getmodule(self).cmake(*cmake_args)\n", "path": "var/spack/repos/builtin/packages/intel-tbb/package.py"}]}