setup.py 2.3 KB

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