We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`/usr/local/cuda/lib` in Linux for Tegra
In CUDA for L4T (Linux for Tegra), shared objects are located in `/usr/local/cuda/lib`, not in `lib64`. I failed to install Chainer.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `chainer_setup_build.py`
Content:
```
1 from __future__ import print_function
2 import copy
3 import distutils
4 import os
5 from os import path
6 import pkg_resources
7 import shutil
8 import subprocess
9 import sys
10 import tempfile
11 
12 import setuptools
13 from setuptools.command import build_ext
14 
15 
16 dummy_extension = setuptools.Extension('chainer', ['chainer.c'])
17 
18 MODULES = [
19     {
20         'name': 'cuda',
21         'file': [
22             'cupy.core.core',
23             'cupy.core.flags',
24             'cupy.cuda.cublas',
25             'cupy.cuda.curand',
26             'cupy.cuda.device',
27             'cupy.cuda.driver',
28             'cupy.cuda.memory',
29             'cupy.cuda.function',
30             'cupy.cuda.runtime',
31             'cupy.util',
32         ],
33         'include': [
34             'cublas_v2.h',
35             'cuda.h',
36             'cuda_runtime.h',
37             'curand.h',
38         ],
39         'libraries': [
40             'cublas',
41             'cuda',
42             'cudart',
43             'curand',
44         ],
45     },
46     {
47         'name': 'cudnn',
48         'file': [
49             'cupy.cuda.cudnn',
50         ],
51         'include': [
52             'cudnn.h',
53         ],
54         'libraries': [
55             'cudnn',
56         ],
57     }
58 ]
59 
60 
61 def get_compiler_setting():
62     nvcc_path = search_on_path(('nvcc', 'nvcc.exe'))
63     cuda_path_default = None
64     if nvcc_path is None:
65         print('**************************************************************')
66         print('*** WARNING: nvcc not in path.')
67         print('*** WARNING: Please set path to nvcc.')
68         print('**************************************************************')
69     else:
70         cuda_path_default = path.normpath(
71             path.join(path.dirname(nvcc_path), '..'))
72 
73     cuda_path = os.environ.get('CUDA_PATH', '')  # Nvidia default on Windows
74     if len(cuda_path) > 0 and cuda_path != cuda_path_default:
75         print('**************************************************************')
76         print('*** WARNING: nvcc path != CUDA_PATH')
77         print('*** WARNING: nvcc path: %s', cuda_path_default)
78         print('*** WARNING: CUDA_PATH: %s', cuda_path)
79         print('**************************************************************')
80 
81     if not path.exists(cuda_path):
82         cuda_path = cuda_path_default
83 
84     if not cuda_path and path.exists('/usr/local/cuda'):
85         cuda_path = '/usr/local/cuda'
86 
87     include_dirs = []
88     library_dirs = []
89     define_macros = []
90 
91     if cuda_path:
92         include_dirs.append(path.join(cuda_path, 'include'))
93         if sys.platform == 'win32':
94             library_dirs.append(path.join(cuda_path, 'bin'))
95             library_dirs.append(path.join(cuda_path, 'lib', 'x64'))
96         elif sys.platform == 'darwin':
97             library_dirs.append(path.join(cuda_path, 'lib'))
98         else:
99             library_dirs.append(path.join(cuda_path, 'lib64'))
100     if sys.platform == 'darwin':
101         library_dirs.append('/usr/local/cuda/lib')
102 
103     return {
104         'include_dirs': include_dirs,
105         'library_dirs': library_dirs,
106         'define_macros': define_macros,
107         'language': 'c++',
108     }
109 
110 
111 def localpath(*args):
112     return path.abspath(path.join(path.dirname(__file__), *args))
113 
114 
115 def get_path(key):
116     return os.environ.get(key, '').split(os.pathsep)
117 
118 
119 def search_on_path(filenames):
120     for p in get_path('PATH'):
121         for filename in filenames:
122             full = path.join(p, filename)
123             if path.exists(full):
124                 return path.abspath(full)
125 
126 
127 def check_include(dirs, file_path):
128     return any(path.exists(path.join(dir, file_path)) for dir in dirs)
129 
130 
131 def check_readthedocs_environment():
132     return os.environ.get('READTHEDOCS', None) == 'True'
133 
134 
135 def check_library(compiler, includes=[], libraries=[],
136                   include_dirs=[], library_dirs=[]):
137     temp_dir = tempfile.mkdtemp()
138 
139     try:
140         source = '''
141         int main(int argc, char* argv[]) {
142           return 0;
143         }
144         '''
145         fname = os.path.join(temp_dir, 'a.cpp')
146         with open(fname, 'w') as f:
147             for header in includes:
148                 f.write('#include <%s>\n' % header)
149             f.write(source)
150 
151         try:
152             objects = compiler.compile([fname], output_dir=temp_dir,
153                                        include_dirs=include_dirs)
154         except distutils.errors.CompileError:
155             return False
156 
157         try:
158             compiler.link_shared_lib(objects,
159                                      os.path.join(temp_dir, 'a'),
160                                      libraries=libraries,
161                                      library_dirs=library_dirs)
162         except (distutils.errors.LinkError, TypeError):
163             return False
164 
165         return True
166 
167     finally:
168         shutil.rmtree(temp_dir, ignore_errors=True)
169 
170 
171 def make_extensions(options, compiler):
172 
173     """Produce a list of Extension instances which passed to cythonize()."""
174 
175     no_cuda = options['no_cuda']
176     settings = get_compiler_setting()
177 
178     try:
179         import numpy
180         numpy_include = numpy.get_include()
181     except AttributeError:
182         # if numpy is not installed get the headers from the .egg directory
183         import numpy.core
184         numpy_include = path.join(
185             path.dirname(numpy.core.__file__), 'include')
186     include_dirs = settings['include_dirs']
187     include_dirs.append(numpy_include)
188 
189     settings['include_dirs'] = [
190         x for x in include_dirs if path.exists(x)]
191     settings['library_dirs'] = [
192         x for x in settings['library_dirs'] if path.exists(x)]
193     if sys.platform != 'win32':
194         settings['runtime_library_dirs'] = settings['library_dirs']
195 
196     if options['linetrace']:
197         settings['define_macros'].append(('CYTHON_TRACE', '1'))
198         settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1'))
199     if no_cuda:
200         settings['define_macros'].append(('CUPY_NO_CUDA', '1'))
201 
202     ret = []
203     for module in MODULES:
204         print('Include directories:', settings['include_dirs'])
205         print('Library directories:', settings['library_dirs'])
206 
207         if not no_cuda:
208             if not check_library(compiler,
209                                  includes=module['include'],
210                                  include_dirs=settings['include_dirs']):
211                 print('**************************************************')
212                 print('*** Include files not found: %s' % module['include'])
213                 print('*** Skip installing %s support' % module['name'])
214                 print('*** Check your CPATH environment variable')
215                 print('**************************************************')
216                 continue
217 
218             if not check_library(compiler,
219                                  libraries=module['libraries'],
220                                  library_dirs=settings['library_dirs']):
221                 print('**************************************************')
222                 print('*** Cannot link libraries: %s' % module['libraries'])
223                 print('*** Skip installing %s support' % module['name'])
224                 print('*** Check your LIBRARY_PATH environment variable')
225                 print('**************************************************')
226                 continue
227 
228         s = settings.copy()
229         if not no_cuda:
230             s['libraries'] = module['libraries']
231         ret.extend([
232             setuptools.Extension(f, [path.join(*f.split('.')) + '.pyx'], **s)
233             for f in module['file']])
234     return ret
235 
236 
237 _arg_options = {}
238 
239 
240 def parse_args():
241     global _arg_options
242     _arg_options['profile'] = '--cupy-profile' in sys.argv
243     if _arg_options['profile']:
244         sys.argv.remove('--cupy-profile')
245 
246     cupy_coverage = '--cupy-coverage' in sys.argv
247     if cupy_coverage:
248         sys.argv.remove('--cupy-coverage')
249     _arg_options['linetrace'] = cupy_coverage
250     _arg_options['annotate'] = cupy_coverage
251 
252     _arg_options['no_cuda'] = '--cupy-no-cuda' in sys.argv
253     if _arg_options['no_cuda']:
254         sys.argv.remove('--cupy-no-cuda')
255     if check_readthedocs_environment():
256         _arg_options['no_cuda'] = True
257 
258 
259 def cythonize(extensions, force=False, annotate=False, compiler_directives={}):
260     cython_pkg = pkg_resources.get_distribution('cython')
261     cython_path = path.join(cython_pkg.location, 'cython.py')
262     print("cython path:%s" % cython_pkg.location)
263     cython_cmdbase = [sys.executable, cython_path]
264     subprocess.check_call(cython_cmdbase + ['--version'])
265 
266     cython_cmdbase.extend(['--fast-fail', '--verbose', '--cplus'])
267     ret = []
268     for ext in extensions:
269         cmd = list(cython_cmdbase)
270         for i in compiler_directives.items():
271             cmd.append('--directive')
272             cmd.append('%s=%s' % i)
273         cpp_files = [path.splitext(f)[0] + ".cpp" for f in ext.sources]
274         cmd += ext.sources
275         subprocess.check_call(cmd)
276         ext = copy.copy(ext)
277         ext.sources = cpp_files
278         ret.append(ext)
279     return ret
280 
281 
282 class chainer_build_ext(build_ext.build_ext):
283 
284     """`build_ext` command for cython files."""
285 
286     def finalize_options(self):
287         ext_modules = self.distribution.ext_modules
288         if dummy_extension in ext_modules:
289             print('Executing cythonize()')
290             print('Options:', _arg_options)
291 
292             directive_keys = ('linetrace', 'profile')
293             directives = {key: _arg_options[key] for key in directive_keys}
294 
295             cythonize_option_keys = ('annotate',)
296             cythonize_options = {
297                 key: _arg_options[key] for key in cythonize_option_keys}
298 
299             compiler = distutils.ccompiler.new_compiler(self.compiler)
300             distutils.sysconfig.customize_compiler(compiler)
301 
302             extensions = make_extensions(_arg_options, compiler)
303             extensions = cythonize(
304                 extensions,
305                 force=True,
306                 compiler_directives=directives,
307                 **cythonize_options)
308 
309             # Modify ext_modules for cython
310             ext_modules.remove(dummy_extension)
311             ext_modules.extend(extensions)
312 
313         build_ext.build_ext.finalize_options(self)
314
```
--- 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/chainer_setup_build.py b/chainer_setup_build.py
--- a/chainer_setup_build.py
+++ b/chainer_setup_build.py
@@ -93,10 +93,9 @@
         if sys.platform == 'win32':
             library_dirs.append(path.join(cuda_path, 'bin'))
             library_dirs.append(path.join(cuda_path, 'lib', 'x64'))
-        elif sys.platform == 'darwin':
-            library_dirs.append(path.join(cuda_path, 'lib'))
         else:
             library_dirs.append(path.join(cuda_path, 'lib64'))
+            library_dirs.append(path.join(cuda_path, 'lib'))
     if sys.platform == 'darwin':
         library_dirs.append('/usr/local/cuda/lib')

{"golden_diff": "diff --git a/chainer_setup_build.py b/chainer_setup_build.py\n--- a/chainer_setup_build.py\n+++ b/chainer_setup_build.py\n@@ -93,10 +93,9 @@\n         if sys.platform == 'win32':\n             library_dirs.append(path.join(cuda_path, 'bin'))\n             library_dirs.append(path.join(cuda_path, 'lib', 'x64'))\n-        elif sys.platform == 'darwin':\n-            library_dirs.append(path.join(cuda_path, 'lib'))\n         else:\n             library_dirs.append(path.join(cuda_path, 'lib64'))\n+            library_dirs.append(path.join(cuda_path, 'lib'))\n     if sys.platform == 'darwin':\n         library_dirs.append('/usr/local/cuda/lib')\n", "issue": "`/usr/local/cuda/lib` in Linux for Tegra\nIn CUDA for L4T (Linux for Tegra), shared objects are located in `/usr/local/cuda/lib`, not in `lib64`. I failed to install Chainer.\n\n", "before_files": [{"content": "from __future__ import print_function\nimport copy\nimport distutils\nimport os\nfrom os import path\nimport pkg_resources\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\n\nimport setuptools\nfrom setuptools.command import build_ext\n\n\ndummy_extension = setuptools.Extension('chainer', ['chainer.c'])\n\nMODULES = [\n    {\n        'name': 'cuda',\n        'file': [\n            'cupy.core.core',\n            'cupy.core.flags',\n            'cupy.cuda.cublas',\n            'cupy.cuda.curand',\n            'cupy.cuda.device',\n            'cupy.cuda.driver',\n            'cupy.cuda.memory',\n            'cupy.cuda.function',\n            'cupy.cuda.runtime',\n            'cupy.util',\n        ],\n        'include': [\n            'cublas_v2.h',\n            'cuda.h',\n            'cuda_runtime.h',\n            'curand.h',\n        ],\n        'libraries': [\n            'cublas',\n            'cuda',\n            'cudart',\n            'curand',\n        ],\n    },\n    {\n        'name': 'cudnn',\n        'file': [\n            'cupy.cuda.cudnn',\n        ],\n        'include': [\n            'cudnn.h',\n        ],\n        'libraries': [\n            'cudnn',\n        ],\n    }\n]\n\n\ndef get_compiler_setting():\n    nvcc_path = search_on_path(('nvcc', 'nvcc.exe'))\n    cuda_path_default = None\n    if nvcc_path is None:\n        print('**************************************************************')\n        print('*** WARNING: nvcc not in path.')\n        print('*** WARNING: Please set path to nvcc.')\n        print('**************************************************************')\n    else:\n        cuda_path_default = path.normpath(\n            path.join(path.dirname(nvcc_path), '..'))\n\n    cuda_path = os.environ.get('CUDA_PATH', '')  # Nvidia default on Windows\n    if len(cuda_path) > 0 and cuda_path != cuda_path_default:\n        print('**************************************************************')\n        print('*** WARNING: nvcc path != CUDA_PATH')\n        print('*** WARNING: nvcc path: %s', cuda_path_default)\n        print('*** WARNING: CUDA_PATH: %s', cuda_path)\n        print('**************************************************************')\n\n    if not path.exists(cuda_path):\n        cuda_path = cuda_path_default\n\n    if not cuda_path and path.exists('/usr/local/cuda'):\n        cuda_path = '/usr/local/cuda'\n\n    include_dirs = []\n    library_dirs = []\n    define_macros = []\n\n    if cuda_path:\n        include_dirs.append(path.join(cuda_path, 'include'))\n        if sys.platform == 'win32':\n            library_dirs.append(path.join(cuda_path, 'bin'))\n            library_dirs.append(path.join(cuda_path, 'lib', 'x64'))\n        elif sys.platform == 'darwin':\n            library_dirs.append(path.join(cuda_path, 'lib'))\n        else:\n            library_dirs.append(path.join(cuda_path, 'lib64'))\n    if sys.platform == 'darwin':\n        library_dirs.append('/usr/local/cuda/lib')\n\n    return {\n        'include_dirs': include_dirs,\n        'library_dirs': library_dirs,\n        'define_macros': define_macros,\n        'language': 'c++',\n    }\n\n\ndef localpath(*args):\n    return path.abspath(path.join(path.dirname(__file__), *args))\n\n\ndef get_path(key):\n    return os.environ.get(key, '').split(os.pathsep)\n\n\ndef search_on_path(filenames):\n    for p in get_path('PATH'):\n        for filename in filenames:\n            full = path.join(p, filename)\n            if path.exists(full):\n                return path.abspath(full)\n\n\ndef check_include(dirs, file_path):\n    return any(path.exists(path.join(dir, file_path)) for dir in dirs)\n\n\ndef check_readthedocs_environment():\n    return os.environ.get('READTHEDOCS', None) == 'True'\n\n\ndef check_library(compiler, includes=[], libraries=[],\n                  include_dirs=[], library_dirs=[]):\n    temp_dir = tempfile.mkdtemp()\n\n    try:\n        source = '''\n        int main(int argc, char* argv[]) {\n          return 0;\n        }\n        '''\n        fname = os.path.join(temp_dir, 'a.cpp')\n        with open(fname, 'w') as f:\n            for header in includes:\n                f.write('#include <%s>\\n' % header)\n            f.write(source)\n\n        try:\n            objects = compiler.compile([fname], output_dir=temp_dir,\n                                       include_dirs=include_dirs)\n        except distutils.errors.CompileError:\n            return False\n\n        try:\n            compiler.link_shared_lib(objects,\n                                     os.path.join(temp_dir, 'a'),\n                                     libraries=libraries,\n                                     library_dirs=library_dirs)\n        except (distutils.errors.LinkError, TypeError):\n            return False\n\n        return True\n\n    finally:\n        shutil.rmtree(temp_dir, ignore_errors=True)\n\n\ndef make_extensions(options, compiler):\n\n    \"\"\"Produce a list of Extension instances which passed to cythonize().\"\"\"\n\n    no_cuda = options['no_cuda']\n    settings = get_compiler_setting()\n\n    try:\n        import numpy\n        numpy_include = numpy.get_include()\n    except AttributeError:\n        # if numpy is not installed get the headers from the .egg directory\n        import numpy.core\n        numpy_include = path.join(\n            path.dirname(numpy.core.__file__), 'include')\n    include_dirs = settings['include_dirs']\n    include_dirs.append(numpy_include)\n\n    settings['include_dirs'] = [\n        x for x in include_dirs if path.exists(x)]\n    settings['library_dirs'] = [\n        x for x in settings['library_dirs'] if path.exists(x)]\n    if sys.platform != 'win32':\n        settings['runtime_library_dirs'] = settings['library_dirs']\n\n    if options['linetrace']:\n        settings['define_macros'].append(('CYTHON_TRACE', '1'))\n        settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1'))\n    if no_cuda:\n        settings['define_macros'].append(('CUPY_NO_CUDA', '1'))\n\n    ret = []\n    for module in MODULES:\n        print('Include directories:', settings['include_dirs'])\n        print('Library directories:', settings['library_dirs'])\n\n        if not no_cuda:\n            if not check_library(compiler,\n                                 includes=module['include'],\n                                 include_dirs=settings['include_dirs']):\n                print('**************************************************')\n                print('*** Include files not found: %s' % module['include'])\n                print('*** Skip installing %s support' % module['name'])\n                print('*** Check your CPATH environment variable')\n                print('**************************************************')\n                continue\n\n            if not check_library(compiler,\n                                 libraries=module['libraries'],\n                                 library_dirs=settings['library_dirs']):\n                print('**************************************************')\n                print('*** Cannot link libraries: %s' % module['libraries'])\n                print('*** Skip installing %s support' % module['name'])\n                print('*** Check your LIBRARY_PATH environment variable')\n                print('**************************************************')\n                continue\n\n        s = settings.copy()\n        if not no_cuda:\n            s['libraries'] = module['libraries']\n        ret.extend([\n            setuptools.Extension(f, [path.join(*f.split('.')) + '.pyx'], **s)\n            for f in module['file']])\n    return ret\n\n\n_arg_options = {}\n\n\ndef parse_args():\n    global _arg_options\n    _arg_options['profile'] = '--cupy-profile' in sys.argv\n    if _arg_options['profile']:\n        sys.argv.remove('--cupy-profile')\n\n    cupy_coverage = '--cupy-coverage' in sys.argv\n    if cupy_coverage:\n        sys.argv.remove('--cupy-coverage')\n    _arg_options['linetrace'] = cupy_coverage\n    _arg_options['annotate'] = cupy_coverage\n\n    _arg_options['no_cuda'] = '--cupy-no-cuda' in sys.argv\n    if _arg_options['no_cuda']:\n        sys.argv.remove('--cupy-no-cuda')\n    if check_readthedocs_environment():\n        _arg_options['no_cuda'] = True\n\n\ndef cythonize(extensions, force=False, annotate=False, compiler_directives={}):\n    cython_pkg = pkg_resources.get_distribution('cython')\n    cython_path = path.join(cython_pkg.location, 'cython.py')\n    print(\"cython path:%s\" % cython_pkg.location)\n    cython_cmdbase = [sys.executable, cython_path]\n    subprocess.check_call(cython_cmdbase + ['--version'])\n\n    cython_cmdbase.extend(['--fast-fail', '--verbose', '--cplus'])\n    ret = []\n    for ext in extensions:\n        cmd = list(cython_cmdbase)\n        for i in compiler_directives.items():\n            cmd.append('--directive')\n            cmd.append('%s=%s' % i)\n        cpp_files = [path.splitext(f)[0] + \".cpp\" for f in ext.sources]\n        cmd += ext.sources\n        subprocess.check_call(cmd)\n        ext = copy.copy(ext)\n        ext.sources = cpp_files\n        ret.append(ext)\n    return ret\n\n\nclass chainer_build_ext(build_ext.build_ext):\n\n    \"\"\"`build_ext` command for cython files.\"\"\"\n\n    def finalize_options(self):\n        ext_modules = self.distribution.ext_modules\n        if dummy_extension in ext_modules:\n            print('Executing cythonize()')\n            print('Options:', _arg_options)\n\n            directive_keys = ('linetrace', 'profile')\n            directives = {key: _arg_options[key] for key in directive_keys}\n\n            cythonize_option_keys = ('annotate',)\n            cythonize_options = {\n                key: _arg_options[key] for key in cythonize_option_keys}\n\n            compiler = distutils.ccompiler.new_compiler(self.compiler)\n            distutils.sysconfig.customize_compiler(compiler)\n\n            extensions = make_extensions(_arg_options, compiler)\n            extensions = cythonize(\n                extensions,\n                force=True,\n                compiler_directives=directives,\n                **cythonize_options)\n\n            # Modify ext_modules for cython\n            ext_modules.remove(dummy_extension)\n            ext_modules.extend(extensions)\n\n        build_ext.build_ext.finalize_options(self)\n", "path": "chainer_setup_build.py"}], "after_files": [{"content": "from __future__ import print_function\nimport copy\nimport distutils\nimport os\nfrom os import path\nimport pkg_resources\nimport shutil\nimport subprocess\nimport sys\nimport tempfile\n\nimport setuptools\nfrom setuptools.command import build_ext\n\n\ndummy_extension = setuptools.Extension('chainer', ['chainer.c'])\n\nMODULES = [\n    {\n        'name': 'cuda',\n        'file': [\n            'cupy.core.core',\n            'cupy.core.flags',\n            'cupy.cuda.cublas',\n            'cupy.cuda.curand',\n            'cupy.cuda.device',\n            'cupy.cuda.driver',\n            'cupy.cuda.memory',\n            'cupy.cuda.function',\n            'cupy.cuda.runtime',\n            'cupy.util',\n        ],\n        'include': [\n            'cublas_v2.h',\n            'cuda.h',\n            'cuda_runtime.h',\n            'curand.h',\n        ],\n        'libraries': [\n            'cublas',\n            'cuda',\n            'cudart',\n            'curand',\n        ],\n    },\n    {\n        'name': 'cudnn',\n        'file': [\n            'cupy.cuda.cudnn',\n        ],\n        'include': [\n            'cudnn.h',\n        ],\n        'libraries': [\n            'cudnn',\n        ],\n    }\n]\n\n\ndef get_compiler_setting():\n    nvcc_path = search_on_path(('nvcc', 'nvcc.exe'))\n    cuda_path_default = None\n    if nvcc_path is None:\n        print('**************************************************************')\n        print('*** WARNING: nvcc not in path.')\n        print('*** WARNING: Please set path to nvcc.')\n        print('**************************************************************')\n    else:\n        cuda_path_default = path.normpath(\n            path.join(path.dirname(nvcc_path), '..'))\n\n    cuda_path = os.environ.get('CUDA_PATH', '')  # Nvidia default on Windows\n    if len(cuda_path) > 0 and cuda_path != cuda_path_default:\n        print('**************************************************************')\n        print('*** WARNING: nvcc path != CUDA_PATH')\n        print('*** WARNING: nvcc path: %s', cuda_path_default)\n        print('*** WARNING: CUDA_PATH: %s', cuda_path)\n        print('**************************************************************')\n\n    if not path.exists(cuda_path):\n        cuda_path = cuda_path_default\n\n    if not cuda_path and path.exists('/usr/local/cuda'):\n        cuda_path = '/usr/local/cuda'\n\n    include_dirs = []\n    library_dirs = []\n    define_macros = []\n\n    if cuda_path:\n        include_dirs.append(path.join(cuda_path, 'include'))\n        if sys.platform == 'win32':\n            library_dirs.append(path.join(cuda_path, 'bin'))\n            library_dirs.append(path.join(cuda_path, 'lib', 'x64'))\n        else:\n            library_dirs.append(path.join(cuda_path, 'lib64'))\n            library_dirs.append(path.join(cuda_path, 'lib'))\n    if sys.platform == 'darwin':\n        library_dirs.append('/usr/local/cuda/lib')\n\n    return {\n        'include_dirs': include_dirs,\n        'library_dirs': library_dirs,\n        'define_macros': define_macros,\n        'language': 'c++',\n    }\n\n\ndef localpath(*args):\n    return path.abspath(path.join(path.dirname(__file__), *args))\n\n\ndef get_path(key):\n    return os.environ.get(key, '').split(os.pathsep)\n\n\ndef search_on_path(filenames):\n    for p in get_path('PATH'):\n        for filename in filenames:\n            full = path.join(p, filename)\n            if path.exists(full):\n                return path.abspath(full)\n\n\ndef check_include(dirs, file_path):\n    return any(path.exists(path.join(dir, file_path)) for dir in dirs)\n\n\ndef check_readthedocs_environment():\n    return os.environ.get('READTHEDOCS', None) == 'True'\n\n\ndef check_library(compiler, includes=[], libraries=[],\n                  include_dirs=[], library_dirs=[]):\n    temp_dir = tempfile.mkdtemp()\n\n    try:\n        source = '''\n        int main(int argc, char* argv[]) {\n          return 0;\n        }\n        '''\n        fname = os.path.join(temp_dir, 'a.cpp')\n        with open(fname, 'w') as f:\n            for header in includes:\n                f.write('#include <%s>\\n' % header)\n            f.write(source)\n\n        try:\n            objects = compiler.compile([fname], output_dir=temp_dir,\n                                       include_dirs=include_dirs)\n        except distutils.errors.CompileError:\n            return False\n\n        try:\n            compiler.link_shared_lib(objects,\n                                     os.path.join(temp_dir, 'a'),\n                                     libraries=libraries,\n                                     library_dirs=library_dirs)\n        except (distutils.errors.LinkError, TypeError):\n            return False\n\n        return True\n\n    finally:\n        shutil.rmtree(temp_dir, ignore_errors=True)\n\n\ndef make_extensions(options, compiler):\n\n    \"\"\"Produce a list of Extension instances which passed to cythonize().\"\"\"\n\n    no_cuda = options['no_cuda']\n    settings = get_compiler_setting()\n\n    try:\n        import numpy\n        numpy_include = numpy.get_include()\n    except AttributeError:\n        # if numpy is not installed get the headers from the .egg directory\n        import numpy.core\n        numpy_include = path.join(\n            path.dirname(numpy.core.__file__), 'include')\n    include_dirs = settings['include_dirs']\n    include_dirs.append(numpy_include)\n\n    settings['include_dirs'] = [\n        x for x in include_dirs if path.exists(x)]\n    settings['library_dirs'] = [\n        x for x in settings['library_dirs'] if path.exists(x)]\n    if sys.platform != 'win32':\n        settings['runtime_library_dirs'] = settings['library_dirs']\n\n    if options['linetrace']:\n        settings['define_macros'].append(('CYTHON_TRACE', '1'))\n        settings['define_macros'].append(('CYTHON_TRACE_NOGIL', '1'))\n    if no_cuda:\n        settings['define_macros'].append(('CUPY_NO_CUDA', '1'))\n\n    ret = []\n    for module in MODULES:\n        print('Include directories:', settings['include_dirs'])\n        print('Library directories:', settings['library_dirs'])\n\n        if not no_cuda:\n            if not check_library(compiler,\n                                 includes=module['include'],\n                                 include_dirs=settings['include_dirs']):\n                print('**************************************************')\n                print('*** Include files not found: %s' % module['include'])\n                print('*** Skip installing %s support' % module['name'])\n                print('*** Check your CPATH environment variable')\n                print('**************************************************')\n                continue\n\n            if not check_library(compiler,\n                                 libraries=module['libraries'],\n                                 library_dirs=settings['library_dirs']):\n                print('**************************************************')\n                print('*** Cannot link libraries: %s' % module['libraries'])\n                print('*** Skip installing %s support' % module['name'])\n                print('*** Check your LIBRARY_PATH environment variable')\n                print('**************************************************')\n                continue\n\n        s = settings.copy()\n        if not no_cuda:\n            s['libraries'] = module['libraries']\n        ret.extend([\n            setuptools.Extension(f, [path.join(*f.split('.')) + '.pyx'], **s)\n            for f in module['file']])\n    return ret\n\n\n_arg_options = {}\n\n\ndef parse_args():\n    global _arg_options\n    _arg_options['profile'] = '--cupy-profile' in sys.argv\n    if _arg_options['profile']:\n        sys.argv.remove('--cupy-profile')\n\n    cupy_coverage = '--cupy-coverage' in sys.argv\n    if cupy_coverage:\n        sys.argv.remove('--cupy-coverage')\n    _arg_options['linetrace'] = cupy_coverage\n    _arg_options['annotate'] = cupy_coverage\n\n    _arg_options['no_cuda'] = '--cupy-no-cuda' in sys.argv\n    if _arg_options['no_cuda']:\n        sys.argv.remove('--cupy-no-cuda')\n    if check_readthedocs_environment():\n        _arg_options['no_cuda'] = True\n\n\ndef cythonize(extensions, force=False, annotate=False, compiler_directives={}):\n    cython_pkg = pkg_resources.get_distribution('cython')\n    cython_path = path.join(cython_pkg.location, 'cython.py')\n    print(\"cython path:%s\" % cython_pkg.location)\n    cython_cmdbase = [sys.executable, cython_path]\n    subprocess.check_call(cython_cmdbase + ['--version'])\n\n    cython_cmdbase.extend(['--fast-fail', '--verbose', '--cplus'])\n    ret = []\n    for ext in extensions:\n        cmd = list(cython_cmdbase)\n        for i in compiler_directives.items():\n            cmd.append('--directive')\n            cmd.append('%s=%s' % i)\n        cpp_files = [path.splitext(f)[0] + \".cpp\" for f in ext.sources]\n        cmd += ext.sources\n        subprocess.check_call(cmd)\n        ext = copy.copy(ext)\n        ext.sources = cpp_files\n        ret.append(ext)\n    return ret\n\n\nclass chainer_build_ext(build_ext.build_ext):\n\n    \"\"\"`build_ext` command for cython files.\"\"\"\n\n    def finalize_options(self):\n        ext_modules = self.distribution.ext_modules\n        if dummy_extension in ext_modules:\n            print('Executing cythonize()')\n            print('Options:', _arg_options)\n\n            directive_keys = ('linetrace', 'profile')\n            directives = {key: _arg_options[key] for key in directive_keys}\n\n            cythonize_option_keys = ('annotate',)\n            cythonize_options = {\n                key: _arg_options[key] for key in cythonize_option_keys}\n\n            compiler = distutils.ccompiler.new_compiler(self.compiler)\n            distutils.sysconfig.customize_compiler(compiler)\n\n            extensions = make_extensions(_arg_options, compiler)\n            extensions = cythonize(\n                extensions,\n                force=True,\n                compiler_directives=directives,\n                **cythonize_options)\n\n            # Modify ext_modules for cython\n            ext_modules.remove(dummy_extension)\n            ext_modules.extend(extensions)\n\n        build_ext.build_ext.finalize_options(self)\n", "path": "chainer_setup_build.py"}]}