setup.py 3.3 KB

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