hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/tools/perf/util/setup.py
....@@ -1,20 +1,32 @@
1
-#!/usr/bin/python
2
-
3
-from os import getenv
1
+from os import getenv, path
42 from subprocess import Popen, PIPE
53 from re import sub
64
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
-
105 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])
1830
1931 from distutils.core import setup, Extension
2032
....@@ -36,7 +48,7 @@
3648 cflags = getenv('CFLAGS', '').split()
3749 # switch off several checks (need to be at the end of cflags list)
3850 cflags += ['-fno-strict-aliasing', '-Wno-write-strings', '-Wno-unused-parameter', '-Wno-redundant-decls' ]
39
-if cc != "clang":
51
+if not cc_is_clang:
4052 cflags += ['-Wno-cast-function-type' ]
4153
4254 src_perf = getenv('srctree') + '/tools/perf'
....@@ -44,6 +56,7 @@
4456 build_tmp = getenv('PYTHON_EXTBUILD_TMP')
4557 libtraceevent = getenv('LIBTRACEEVENT')
4658 libapikfs = getenv('LIBAPI')
59
+libperf = getenv('LIBPERF')
4760
4861 ext_sources = [f.strip() for f in open('util/python-ext-sources')
4962 if len(f.strip()) > 0 and f[0] != '#']
....@@ -51,11 +64,18 @@
5164 # use full paths with source files
5265 ext_sources = list(map(lambda x: '%s/%s' % (src_perf, x) , ext_sources))
5366
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
+
5473 perf = Extension('perf',
5574 sources = ext_sources,
5675 include_dirs = ['util/include'],
76
+ libraries = extra_libraries,
5777 extra_compile_args = cflags,
58
- extra_objects = [libtraceevent, libapikfs],
78
+ extra_objects = [libtraceevent, libapikfs, libperf],
5979 )
6080
6181 setup(name='perf',