| .. | .. |
|---|
| 1 | | -#!/usr/bin/python |
|---|
| 2 | | - |
|---|
| 3 | | -from os import getenv |
|---|
| 1 | +from os import getenv, path |
|---|
| 4 | 2 | from subprocess import Popen, PIPE |
|---|
| 5 | 3 | from re import sub |
|---|
| 6 | 4 | |
|---|
| 7 | | -def clang_has_option(option): |
|---|
| 8 | | - return [o for o in Popen(['clang', option], stderr=PIPE).stderr.readlines() if "unknown argument" in o] == [ ] |
|---|
| 9 | | - |
|---|
| 10 | 5 | cc = getenv("CC") |
|---|
| 11 | | -if 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"]) |
|---|
| 6 | +cc_is_clang = b"clang version" in Popen([cc.split()[0], "-v"], stderr=PIPE).stderr.readline() |
|---|
| 7 | +src_feature_tests = getenv('srctree') + '/tools/build/feature' |
|---|
| 8 | + |
|---|
| 9 | +def clang_has_option(option): |
|---|
| 10 | + cc_output = Popen([cc, option, path.join(src_feature_tests, "test-hello.c") ], stderr=PIPE).stderr.readlines() |
|---|
| 11 | + return [o for o in cc_output if ((b"unknown argument" in o) or (b"is not supported" in o))] == [ ] |
|---|
| 12 | + |
|---|
| 13 | +if cc_is_clang: |
|---|
| 14 | + from distutils.sysconfig import get_config_vars |
|---|
| 15 | + vars = get_config_vars() |
|---|
| 16 | + for var in ('CFLAGS', 'OPT'): |
|---|
| 17 | + vars[var] = sub("-specs=[^ ]+", "", vars[var]) |
|---|
| 18 | + if not clang_has_option("-mcet"): |
|---|
| 19 | + vars[var] = sub("-mcet", "", vars[var]) |
|---|
| 20 | + if not clang_has_option("-fcf-protection"): |
|---|
| 21 | + vars[var] = sub("-fcf-protection", "", vars[var]) |
|---|
| 22 | + if not clang_has_option("-fstack-clash-protection"): |
|---|
| 23 | + vars[var] = sub("-fstack-clash-protection", "", vars[var]) |
|---|
| 24 | + if not clang_has_option("-fstack-protector-strong"): |
|---|
| 25 | + vars[var] = sub("-fstack-protector-strong", "", vars[var]) |
|---|
| 26 | + if not clang_has_option("-fno-semantic-interposition"): |
|---|
| 27 | + vars[var] = sub("-fno-semantic-interposition", "", vars[var]) |
|---|
| 28 | + if not clang_has_option("-ffat-lto-objects"): |
|---|
| 29 | + vars[var] = sub("-ffat-lto-objects", "", vars[var]) |
|---|
| 18 | 30 | |
|---|
| 19 | 31 | from distutils.core import setup, Extension |
|---|
| 20 | 32 | |
|---|
| .. | .. |
|---|
| 36 | 48 | cflags = getenv('CFLAGS', '').split() |
|---|
| 37 | 49 | # switch off several checks (need to be at the end of cflags list) |
|---|
| 38 | 50 | cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ] |
|---|
| 39 | | -if cc != "clang": |
|---|
| 51 | +if not cc_is_clang: |
|---|
| 40 | 52 | cflags += ['-Wno-cast-function-type' ] |
|---|
| 41 | 53 | |
|---|
| 42 | 54 | src_perf = getenv('srctree') + '/tools/perf' |
|---|
| .. | .. |
|---|
| 44 | 56 | build_tmp = getenv('PYTHON_EXTBUILD_TMP') |
|---|
| 45 | 57 | libtraceevent = getenv('LIBTRACEEVENT') |
|---|
| 46 | 58 | libapikfs = getenv('LIBAPI') |
|---|
| 59 | +libperf = getenv('LIBPERF') |
|---|
| 47 | 60 | |
|---|
| 48 | 61 | ext_sources = [f.strip() for f in open('util/python-ext-sources') |
|---|
| 49 | 62 | if len(f.strip()) > 0 and f[0] != '#'] |
|---|
| .. | .. |
|---|
| 51 | 64 | # use full paths with source files |
|---|
| 52 | 65 | ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources)) |
|---|
| 53 | 66 | |
|---|
| 67 | +extra_libraries = [] |
|---|
| 68 | +if '-DHAVE_LIBNUMA_SUPPORT' in cflags: |
|---|
| 69 | + extra_libraries = [ 'numa' ] |
|---|
| 70 | +if '-DHAVE_LIBCAP_SUPPORT' in cflags: |
|---|
| 71 | + extra_libraries += [ 'cap' ] |
|---|
| 72 | + |
|---|
| 54 | 73 | perf = Extension('perf', |
|---|
| 55 | 74 | sources = ext_sources, |
|---|
| 56 | 75 | include_dirs = ['util/include'], |
|---|
| 76 | + libraries = extra_libraries, |
|---|
| 57 | 77 | extra_compile_args = cflags, |
|---|
| 58 | | - extra_objects = [libtraceevent, libapikfs], |
|---|
| 78 | + extra_objects = [libtraceevent, libapikfs, libperf], |
|---|
| 59 | 79 | ) |
|---|
| 60 | 80 | |
|---|
| 61 | 81 | setup(name='perf', |
|---|