Back to home page

OSCL-LXR

 
 

    


0001 from os import getenv, path
0002 from subprocess import Popen, PIPE
0003 from re import sub
0004 
0005 cc = getenv("CC")
0006 cc_is_clang = b"clang version" in Popen([cc.split()[0], "-v"], stderr=PIPE).stderr.readline()
0007 src_feature_tests  = getenv('srctree') + '/tools/build/feature'
0008 
0009 def clang_has_option(option):
0010     cc_output = Popen([cc, option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines()
0011     return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o))] == [ ]
0012 
0013 if cc_is_clang:
0014     from sysconfig import get_config_vars
0015     vars = get_config_vars()
0016     for var in ('CFLAGS', 'OPT'):
0017         vars[var] = sub("-specs=[^ ]+", "", vars[var])
0018         if not clang_has_option("-mcet"):
0019             vars[var] = sub("-mcet", "", vars[var])
0020         if not clang_has_option("-fcf-protection"):
0021             vars[var] = sub("-fcf-protection", "", vars[var])
0022         if not clang_has_option("-fstack-clash-protection"):
0023             vars[var] = sub("-fstack-clash-protection", "", vars[var])
0024         if not clang_has_option("-fstack-protector-strong"):
0025             vars[var] = sub("-fstack-protector-strong", "", vars[var])
0026         if not clang_has_option("-fno-semantic-interposition"):
0027             vars[var] = sub("-fno-semantic-interposition", "", vars[var])
0028         if not clang_has_option("-ffat-lto-objects"):
0029             vars[var] = sub("-ffat-lto-objects", "", vars[var])
0030 
0031 from setuptools import setup, Extension
0032 
0033 from setuptools.command.build_ext   import build_ext   as _build_ext
0034 from setuptools.command.install_lib import install_lib as _install_lib
0035 
0036 class build_ext(_build_ext):
0037     def finalize_options(self):
0038         _build_ext.finalize_options(self)
0039         self.build_lib  = build_lib
0040         self.build_temp = build_tmp
0041 
0042 class install_lib(_install_lib):
0043     def finalize_options(self):
0044         _install_lib.finalize_options(self)
0045         self.build_dir = build_lib
0046 
0047 
0048 cflags = getenv('CFLAGS', '').split()
0049 # switch off several checks (need to be at the end of cflags list)
0050 cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls', '-DPYTHON_PERF' ]
0051 if cc_is_clang:
0052     cflags += ["-Wno-unused-command-line-argument" ]
0053 else:
0054     cflags += ['-Wno-cast-function-type' ]
0055 
0056 src_perf  = getenv('srctree') + '/tools/perf'
0057 build_lib = getenv('PYTHON_EXTBUILD_LIB')
0058 build_tmp = getenv('PYTHON_EXTBUILD_TMP')
0059 libtraceevent = getenv('LIBTRACEEVENT')
0060 libapikfs = getenv('LIBAPI')
0061 libperf = getenv('LIBPERF')
0062 
0063 ext_sources = [f.strip() for f in open('util/python-ext-sources')
0064                 if len(f.strip()) > 0 and f[0] != '#']
0065 
0066 # use full paths with source files
0067 ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources))
0068 
0069 extra_libraries = []
0070 if '-DHAVE_LIBNUMA_SUPPORT' in cflags:
0071     extra_libraries = [ 'numa' ]
0072 if '-DHAVE_LIBCAP_SUPPORT' in cflags:
0073     extra_libraries += [ 'cap' ]
0074 
0075 perf = Extension('perf',
0076           sources = ext_sources,
0077           include_dirs = ['util/include'],
0078           libraries = extra_libraries,
0079           extra_compile_args = cflags,
0080           extra_objects = [libtraceevent, libapikfs, libperf],
0081                  )
0082 
0083 setup(name='perf',
0084       version='0.1',
0085       description='Interface with the Linux profiling infrastructure',
0086       author='Arnaldo Carvalho de Melo',
0087       author_email='acme@redhat.com',
0088       license='GPLv2',
0089       url='http://perf.wiki.kernel.org',
0090       ext_modules=[perf],
0091       cmdclass={'build_ext': build_ext, 'install_lib': install_lib})