setup.py 2.3 KB

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