GNU Linux-libre 4.19.211-gnu1
[releases.git] / tools / perf / util / setup.py
1 #!/usr/bin/python
2
3 from os import getenv
4 from subprocess import Popen, PIPE
5 from re import sub
6
7 def clang_has_option(option):
8     return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ]
9
10 cc = getenv("CC")
11 if cc == "clang":
12     from _sysconfigdata import build_time_vars
13     build_time_vars["CFLAGS"] = sub("-specs=[^ ]+", "", build_time_vars["CFLAGS"])
14     if not clang_has_option("-mcet"):
15         build_time_vars["CFLAGS"] = sub("-mcet", "", build_time_vars["CFLAGS"])
16     if not clang_has_option("-fcf-protection"):
17         build_time_vars["CFLAGS"] = sub("-fcf-protection", "", build_time_vars["CFLAGS"])
18
19 from distutils.core import setup, Extension
20
21 from distutils.command.build_ext   import build_ext   as _build_ext
22 from distutils.command.install_lib import install_lib as _install_lib
23
24 class build_ext(_build_ext):
25     def finalize_options(self):
26         _build_ext.finalize_options(self)
27         self.build_lib  = build_lib
28         self.build_temp = build_tmp
29
30 class install_lib(_install_lib):
31     def finalize_options(self):
32         _install_lib.finalize_options(self)
33         self.build_dir = build_lib
34
35
36 cflags = getenv('CFLAGS', '').split()
37 # switch off several checks (need to be at the end of cflags list)
38 cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
39 if cc != "clang":
40     cflags += ['-Wno-cast-function-type' ]
41
42 src_perf  = getenv('srctree') + '/tools/perf'
43 build_lib = getenv('PYTHON_EXTBUILD_LIB')
44 build_tmp = getenv('PYTHON_EXTBUILD_TMP')
45 libtraceevent = getenv('LIBTRACEEVENT')
46 libapikfs = getenv('LIBAPI')
47
48 ext_sources = [f.strip() for f in open('util/python-ext-sources')
49                                 if len(f.strip()) > 0 and f[0] != '#']
50
51 # use full paths with source files
52 ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources))
53
54 perf = Extension('perf',
55                   sources = ext_sources,
56                   include_dirs = ['util/include'],
57                   extra_compile_args = cflags,
58                   extra_objects = [libtraceevent, libapikfs],
59                  )
60
61 setup(name='perf',
62       version='0.1',
63       description='Interface with the Linux profiling infrastructure',
64       author='Arnaldo Carvalho de Melo',
65       author_email='acme@redhat.com',
66       license='GPLv2',
67       url='http://perf.wiki.kernel.org',
68       ext_modules=[perf],
69       cmdclass={'build_ext': build_ext, 'install_lib': install_lib})