xref: /openbmc/linux/tools/perf/util/setup.py (revision f220d3eb)
1#!/usr/bin/python
2
3from os import getenv
4from subprocess import Popen, PIPE
5from re import sub
6
7def clang_has_option(option):
8    return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ]
9
10cc = getenv("CC")
11if 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
19from distutils.core import setup, Extension
20
21from distutils.command.build_ext   import build_ext   as _build_ext
22from distutils.command.install_lib import install_lib as _install_lib
23
24class 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
30class install_lib(_install_lib):
31    def finalize_options(self):
32        _install_lib.finalize_options(self)
33        self.build_dir = build_lib
34
35
36cflags = getenv('CFLAGS', '').split()
37# switch off several checks (need to be at the end of cflags list)
38cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter' ]
39if cc != "clang":
40    cflags += ['-Wno-cast-function-type' ]
41
42src_perf  = getenv('srctree') + '/tools/perf'
43build_lib = getenv('PYTHON_EXTBUILD_LIB')
44build_tmp = getenv('PYTHON_EXTBUILD_TMP')
45libtraceevent = getenv('LIBTRACEEVENT')
46libapikfs = getenv('LIBAPI')
47
48ext_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
52ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources))
53
54perf = Extension('perf',
55		  sources = ext_sources,
56		  include_dirs = ['util/include'],
57		  extra_compile_args = cflags,
58		  extra_objects = [libtraceevent, libapikfs],
59                 )
60
61setup(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})
70