Makefile.config 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. # SPDX-License-Identifier: GPL-2.0-only
  2. ifeq ($(src-perf),)
  3. src-perf := $(srctree)/tools/perf
  4. endif
  5. ifeq ($(obj-perf),)
  6. obj-perf := $(OUTPUT)
  7. endif
  8. ifneq ($(obj-perf),)
  9. obj-perf := $(abspath $(obj-perf))/
  10. endif
  11. $(shell printf "" > $(OUTPUT).config-detected)
  12. detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected)
  13. detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected)
  14. CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
  15. HOSTCFLAGS := $(filter-out -Wnested-externs,$(EXTRA_WARNINGS))
  16. # Enabled Wthread-safety analysis for clang builds.
  17. ifeq ($(CC_NO_CLANG), 0)
  18. CFLAGS += -Wthread-safety
  19. endif
  20. include $(srctree)/tools/scripts/Makefile.arch
  21. $(call detected_var,SRCARCH)
  22. ifneq ($(NO_SYSCALL_TABLE),1)
  23. NO_SYSCALL_TABLE := 1
  24. ifeq ($(SRCARCH),$(filter $(SRCARCH),x86 powerpc arm64 s390 mips loongarch))
  25. NO_SYSCALL_TABLE := 0
  26. endif
  27. ifneq ($(NO_SYSCALL_TABLE),1)
  28. CFLAGS += -DHAVE_SYSCALL_TABLE_SUPPORT
  29. endif
  30. endif
  31. # Additional ARCH settings for ppc
  32. ifeq ($(SRCARCH),powerpc)
  33. CFLAGS += -I$(OUTPUT)arch/powerpc/include/generated
  34. LIBUNWIND_LIBS := -lunwind -lunwind-ppc64
  35. endif
  36. # Additional ARCH settings for x86
  37. ifeq ($(SRCARCH),x86)
  38. $(call detected,CONFIG_X86)
  39. CFLAGS += -I$(OUTPUT)arch/x86/include/generated
  40. ifeq (${IS_64_BIT}, 1)
  41. CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
  42. ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
  43. LIBUNWIND_LIBS = -lunwind-x86_64 -lunwind -llzma
  44. $(call detected,CONFIG_X86_64)
  45. else
  46. LIBUNWIND_LIBS = -lunwind-x86 -llzma -lunwind
  47. endif
  48. endif
  49. ifeq ($(SRCARCH),arm)
  50. LIBUNWIND_LIBS = -lunwind -lunwind-arm
  51. endif
  52. ifeq ($(SRCARCH),arm64)
  53. CFLAGS += -I$(OUTPUT)arch/arm64/include/generated
  54. LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
  55. endif
  56. ifeq ($(SRCARCH),loongarch)
  57. CFLAGS += -I$(OUTPUT)arch/loongarch/include/generated
  58. LIBUNWIND_LIBS = -lunwind -lunwind-loongarch64
  59. endif
  60. ifeq ($(ARCH),s390)
  61. CFLAGS += -fPIC -I$(OUTPUT)arch/s390/include/generated
  62. endif
  63. ifeq ($(ARCH),mips)
  64. CFLAGS += -I$(OUTPUT)arch/mips/include/generated
  65. LIBUNWIND_LIBS = -lunwind -lunwind-mips
  66. endif
  67. # So far there's only x86 and arm libdw unwind support merged in perf.
  68. # Disable it on all other architectures in case libdw unwind
  69. # support is detected in system. Add supported architectures
  70. # to the check.
  71. ifneq ($(SRCARCH),$(filter $(SRCARCH),x86 arm arm64 powerpc s390 csky riscv loongarch))
  72. NO_LIBDW_DWARF_UNWIND := 1
  73. endif
  74. ifeq ($(LIBUNWIND_LIBS),)
  75. NO_LIBUNWIND := 1
  76. endif
  77. #
  78. # For linking with debug library, run like:
  79. #
  80. # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
  81. #
  82. libunwind_arch_set_flags = $(eval $(libunwind_arch_set_flags_code))
  83. define libunwind_arch_set_flags_code
  84. FEATURE_CHECK_CFLAGS-libunwind-$(1) = -I$(LIBUNWIND_DIR)/include
  85. FEATURE_CHECK_LDFLAGS-libunwind-$(1) = -L$(LIBUNWIND_DIR)/lib
  86. endef
  87. ifdef LIBUNWIND_DIR
  88. LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
  89. LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
  90. LIBUNWIND_ARCHS = x86 x86_64 arm aarch64 debug-frame-arm debug-frame-aarch64 loongarch
  91. $(foreach libunwind_arch,$(LIBUNWIND_ARCHS),$(call libunwind_arch_set_flags,$(libunwind_arch)))
  92. endif
  93. # Set per-feature check compilation flags
  94. FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
  95. FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
  96. FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
  97. FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS) $(LIBUNWIND_LIBS)
  98. FEATURE_CHECK_LDFLAGS-libunwind-arm += -lunwind -lunwind-arm
  99. FEATURE_CHECK_LDFLAGS-libunwind-aarch64 += -lunwind -lunwind-aarch64
  100. FEATURE_CHECK_LDFLAGS-libunwind-x86 += -lunwind -llzma -lunwind-x86
  101. FEATURE_CHECK_LDFLAGS-libunwind-x86_64 += -lunwind -llzma -lunwind-x86_64
  102. FEATURE_CHECK_LDFLAGS-libcrypto = -lcrypto
  103. ifdef CSINCLUDES
  104. LIBOPENCSD_CFLAGS := -I$(CSINCLUDES)
  105. endif
  106. OPENCSDLIBS := -lopencsd_c_api -lopencsd
  107. ifeq ($(findstring -static,${LDFLAGS}),-static)
  108. OPENCSDLIBS += -lstdc++
  109. endif
  110. ifdef CSLIBS
  111. LIBOPENCSD_LDFLAGS := -L$(CSLIBS)
  112. endif
  113. FEATURE_CHECK_CFLAGS-libopencsd := $(LIBOPENCSD_CFLAGS)
  114. FEATURE_CHECK_LDFLAGS-libopencsd := $(LIBOPENCSD_LDFLAGS) $(OPENCSDLIBS)
  115. # for linking with debug library, run like:
  116. # make DEBUG=1 LIBDW_DIR=/opt/libdw/
  117. ifdef LIBDW_DIR
  118. LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
  119. LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
  120. endif
  121. DWARFLIBS := -ldw
  122. ifeq ($(findstring -static,${LDFLAGS}),-static)
  123. DWARFLIBS += -lelf -lz -llzma -lbz2 -lzstd
  124. LIBDW_VERSION := $(shell $(PKG_CONFIG) --modversion libdw).0.0
  125. LIBDW_VERSION_1 := $(word 1, $(subst ., ,$(LIBDW_VERSION)))
  126. LIBDW_VERSION_2 := $(word 2, $(subst ., ,$(LIBDW_VERSION)))
  127. # Elfutils merged libebl.a into libdw.a starting from version 0.177,
  128. # Link libebl.a only if libdw is older than this version.
  129. ifeq ($(shell test $(LIBDW_VERSION_2) -lt 177; echo $$?),0)
  130. DWARFLIBS += -lebl
  131. endif
  132. # Must put -ldl after -lebl for dependency
  133. DWARFLIBS += -ldl
  134. endif
  135. FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
  136. FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) $(DWARFLIBS)
  137. # for linking with debug library, run like:
  138. # make DEBUG=1 LIBBABELTRACE_DIR=/opt/libbabeltrace/
  139. ifdef LIBBABELTRACE_DIR
  140. LIBBABELTRACE_CFLAGS := -I$(LIBBABELTRACE_DIR)/include
  141. LIBBABELTRACE_LDFLAGS := -L$(LIBBABELTRACE_DIR)/lib
  142. endif
  143. FEATURE_CHECK_CFLAGS-libbabeltrace := $(LIBBABELTRACE_CFLAGS)
  144. FEATURE_CHECK_LDFLAGS-libbabeltrace := $(LIBBABELTRACE_LDFLAGS) -lbabeltrace-ctf
  145. # for linking with debug library, run like:
  146. # make DEBUG=1 LIBCAPSTONE_DIR=/opt/capstone/
  147. ifdef LIBCAPSTONE_DIR
  148. LIBCAPSTONE_CFLAGS := -I$(LIBCAPSTONE_DIR)/include
  149. LIBCAPSTONE_LDFLAGS := -L$(LIBCAPSTONE_DIR)/
  150. endif
  151. FEATURE_CHECK_CFLAGS-libcapstone := $(LIBCAPSTONE_CFLAGS)
  152. FEATURE_CHECK_LDFLAGS-libcapstone := $(LIBCAPSTONE_LDFLAGS) -lcapstone
  153. ifdef LIBZSTD_DIR
  154. LIBZSTD_CFLAGS := -I$(LIBZSTD_DIR)/lib
  155. LIBZSTD_LDFLAGS := -L$(LIBZSTD_DIR)/lib
  156. endif
  157. FEATURE_CHECK_CFLAGS-libzstd := $(LIBZSTD_CFLAGS)
  158. FEATURE_CHECK_LDFLAGS-libzstd := $(LIBZSTD_LDFLAGS)
  159. # for linking with debug library, run like:
  160. # make DEBUG=1 PKG_CONFIG_PATH=/opt/libtraceevent/(lib|lib64)/pkgconfig
  161. ifneq ($(NO_LIBTRACEEVENT),1)
  162. ifeq ($(call get-executable,$(PKG_CONFIG)),)
  163. $(error Error: $(PKG_CONFIG) needed by libtraceevent is missing on this system, please install it)
  164. endif
  165. endif
  166. FEATURE_CHECK_CFLAGS-bpf = -I. -I$(srctree)/tools/include -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi -I$(srctree)/tools/include/uapi
  167. # include ARCH specific config
  168. -include $(src-perf)/arch/$(SRCARCH)/Makefile
  169. ifdef PERF_HAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
  170. CFLAGS += -DHAVE_ARCH_REGS_QUERY_REGISTER_OFFSET
  171. endif
  172. include $(srctree)/tools/scripts/utilities.mak
  173. ifeq ($(call get-executable,$(FLEX)),)
  174. $(error Error: $(FLEX) is missing on this system, please install it)
  175. endif
  176. ifeq ($(call get-executable,$(BISON)),)
  177. $(error Error: $(BISON) is missing on this system, please install it)
  178. endif
  179. ifneq ($(OUTPUT),)
  180. ifeq ($(shell expr $(shell $(BISON) --version | grep bison | sed -e 's/.\+ \([0-9]\+\).\([0-9]\+\).\([0-9]\+\)/\1\2\3/g') \>\= 371), 1)
  181. BISON_FILE_PREFIX_MAP := --file-prefix-map=$(OUTPUT)=
  182. endif
  183. endif
  184. # Treat warnings as errors unless directed not to
  185. ifneq ($(WERROR),0)
  186. CORE_CFLAGS += -Werror
  187. CXXFLAGS += -Werror
  188. HOSTCFLAGS += -Werror
  189. endif
  190. ifndef DEBUG
  191. DEBUG := 0
  192. endif
  193. ifeq ($(DEBUG),0)
  194. CORE_CFLAGS += -DNDEBUG=1
  195. CORE_CFLAGS += -O3
  196. else
  197. CORE_CFLAGS += -g
  198. CXXFLAGS += -g
  199. endif
  200. ifdef PARSER_DEBUG
  201. PARSER_DEBUG_BISON := -t
  202. PARSER_DEBUG_FLEX := -d
  203. CFLAGS += -DPARSER_DEBUG
  204. $(call detected_var,PARSER_DEBUG_BISON)
  205. $(call detected_var,PARSER_DEBUG_FLEX)
  206. endif
  207. ifdef LTO
  208. CORE_CFLAGS += -flto
  209. CXXFLAGS += -flto
  210. endif
  211. # Try different combinations to accommodate systems that only have
  212. # python[2][3]-config in weird combinations in the following order of
  213. # priority from lowest to highest:
  214. # * python2-config as per pep-0394.
  215. # * python-config
  216. # * python3-config
  217. # * $(PYTHON)-config (If PYTHON is user supplied but PYTHON_CONFIG isn't)
  218. #
  219. PYTHON_AUTO := python-config
  220. PYTHON_AUTO := $(if $(call get-executable,python2-config),python2-config,$(PYTHON_AUTO))
  221. PYTHON_AUTO := $(if $(call get-executable,python-config),python-config,$(PYTHON_AUTO))
  222. PYTHON_AUTO := $(if $(call get-executable,python3-config),python3-config,$(PYTHON_AUTO))
  223. # If PYTHON is defined but PYTHON_CONFIG isn't, then take $(PYTHON)-config as if it was the user
  224. # supplied value for PYTHON_CONFIG. Because it's "user supplied", error out if it doesn't exist.
  225. ifdef PYTHON
  226. ifndef PYTHON_CONFIG
  227. PYTHON_CONFIG_AUTO := $(call get-executable,$(PYTHON)-config)
  228. PYTHON_CONFIG := $(if $(PYTHON_CONFIG_AUTO),$(PYTHON_CONFIG_AUTO),\
  229. $(call $(error $(PYTHON)-config not found)))
  230. endif
  231. endif
  232. # Select either auto detected python and python-config or use user supplied values if they are
  233. # defined. get-executable-or-default fails with an error if the first argument is supplied but
  234. # doesn't exist.
  235. override PYTHON_CONFIG := $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON_AUTO))
  236. override PYTHON := $(call get-executable-or-default,PYTHON,$(subst -config,,$(PYTHON_CONFIG)))
  237. grep-libs = $(filter -l%,$(1))
  238. strip-libs = $(filter-out -l%,$(1))
  239. PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
  240. # Python 3.8 changed the output of `python-config --ldflags` to not include the
  241. # '-lpythonX.Y' flag unless '--embed' is also passed. The feature check for
  242. # libpython fails if that flag is not included in LDFLAGS
  243. ifeq ($(shell $(PYTHON_CONFIG_SQ) --ldflags --embed 2>&1 1>/dev/null; echo $$?), 0)
  244. PYTHON_CONFIG_LDFLAGS := --ldflags --embed
  245. else
  246. PYTHON_CONFIG_LDFLAGS := --ldflags
  247. endif
  248. ifdef PYTHON_CONFIG
  249. PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) $(PYTHON_CONFIG_LDFLAGS) 2>/dev/null)
  250. # Update the python flags for cross compilation
  251. ifdef CROSS_COMPILE
  252. PYTHON_NATIVE := $(shell echo $(PYTHON_EMBED_LDOPTS) | sed 's/\(-L.*\/\)\(.*-linux-gnu\).*/\2/')
  253. PYTHON_EMBED_LDOPTS := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EMBED_LDOPTS))
  254. endif
  255. PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
  256. PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) -lutil
  257. PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --includes 2>/dev/null)
  258. FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
  259. ifeq ($(CC_NO_CLANG), 0)
  260. PYTHON_EMBED_CCOPTS := $(filter-out -ffat-lto-objects, $(PYTHON_EMBED_CCOPTS))
  261. endif
  262. endif
  263. FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
  264. FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
  265. FEATURE_CHECK_LDFLAGS-libaio = -lrt
  266. FEATURE_CHECK_LDFLAGS-disassembler-four-args = -lbfd -lopcodes -ldl
  267. FEATURE_CHECK_LDFLAGS-disassembler-init-styled = -lbfd -lopcodes -ldl
  268. CORE_CFLAGS += -fno-omit-frame-pointer
  269. CORE_CFLAGS += -Wall
  270. CORE_CFLAGS += -Wextra
  271. CORE_CFLAGS += -std=gnu11
  272. CXXFLAGS += -std=gnu++17 -fno-exceptions -fno-rtti
  273. CXXFLAGS += -Wall
  274. CXXFLAGS += -Wextra
  275. CXXFLAGS += -fno-omit-frame-pointer
  276. HOSTCFLAGS += -Wall
  277. HOSTCFLAGS += -Wextra
  278. # Enforce a non-executable stack, as we may regress (again) in the future by
  279. # adding assembler files missing the .GNU-stack linker note.
  280. LDFLAGS += -Wl,-z,noexecstack
  281. EXTLIBS = -lpthread -lrt -lm -ldl
  282. ifneq ($(TCMALLOC),)
  283. CFLAGS += -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
  284. EXTLIBS += -ltcmalloc
  285. endif
  286. ifeq ($(FEATURES_DUMP),)
  287. # We will display at the end of this Makefile.config, using $(call feature_display_entries)
  288. # As we may retry some feature detection here, see the disassembler-four-args case, for instance
  289. FEATURE_DISPLAY_DEFERRED := 1
  290. include $(srctree)/tools/build/Makefile.feature
  291. else
  292. include $(FEATURES_DUMP)
  293. endif
  294. ifeq ($(feature-stackprotector-all), 1)
  295. CORE_CFLAGS += -fstack-protector-all
  296. endif
  297. ifeq ($(DEBUG),0)
  298. ifeq ($(feature-fortify-source), 1)
  299. CORE_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
  300. endif
  301. endif
  302. INC_FLAGS += -I$(src-perf)/util/include
  303. INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
  304. INC_FLAGS += -I$(srctree)/tools/include/
  305. INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi
  306. INC_FLAGS += -I$(srctree)/tools/include/uapi
  307. INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/include/
  308. INC_FLAGS += -I$(srctree)/tools/arch/$(SRCARCH)/
  309. # $(obj-perf) for generated common-cmds.h
  310. # $(obj-perf)/util for generated bison/flex headers
  311. ifneq ($(OUTPUT),)
  312. INC_FLAGS += -I$(obj-perf)/util
  313. INC_FLAGS += -I$(obj-perf)
  314. endif
  315. INC_FLAGS += -I$(src-perf)/util
  316. INC_FLAGS += -I$(src-perf)
  317. CORE_CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
  318. CFLAGS += $(CORE_CFLAGS) $(INC_FLAGS)
  319. CXXFLAGS += $(INC_FLAGS)
  320. LIBPERF_CFLAGS := $(CORE_CFLAGS) $(EXTRA_CFLAGS)
  321. ifeq ($(feature-pthread-attr-setaffinity-np), 1)
  322. CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
  323. endif
  324. ifeq ($(feature-pthread-barrier), 1)
  325. CFLAGS += -DHAVE_PTHREAD_BARRIER
  326. endif
  327. ifndef NO_BIONIC
  328. $(call feature_check,bionic)
  329. ifeq ($(feature-bionic), 1)
  330. BIONIC := 1
  331. CFLAGS += -DLACKS_SIGQUEUE_PROTOTYPE
  332. CFLAGS += -DLACKS_OPEN_MEMSTREAM_PROTOTYPE
  333. EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
  334. EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
  335. endif
  336. endif
  337. ifeq ($(feature-eventfd), 1)
  338. CFLAGS += -DHAVE_EVENTFD_SUPPORT
  339. endif
  340. ifeq ($(feature-get_current_dir_name), 1)
  341. CFLAGS += -DHAVE_GET_CURRENT_DIR_NAME
  342. endif
  343. ifeq ($(feature-gettid), 1)
  344. CFLAGS += -DHAVE_GETTID
  345. endif
  346. ifeq ($(feature-file-handle), 1)
  347. CFLAGS += -DHAVE_FILE_HANDLE
  348. endif
  349. ifdef NO_LIBELF
  350. NO_DWARF := 1
  351. NO_LIBUNWIND := 1
  352. NO_LIBDW_DWARF_UNWIND := 1
  353. NO_LIBBPF := 1
  354. NO_JVMTI := 1
  355. else
  356. ifeq ($(feature-libelf), 0)
  357. ifeq ($(feature-glibc), 1)
  358. LIBC_SUPPORT := 1
  359. endif
  360. ifeq ($(BIONIC),1)
  361. LIBC_SUPPORT := 1
  362. endif
  363. ifeq ($(LIBC_SUPPORT),1)
  364. $(error ERROR: No libelf found. Disables 'probe' tool, jvmti and BPF support. Please install libelf-dev, libelf-devel, elfutils-libelf-devel or build with NO_LIBELF=1.)
  365. else
  366. ifneq ($(filter s% -fsanitize=address%,$(EXTRA_CFLAGS),),)
  367. ifneq ($(shell ldconfig -p | grep libasan >/dev/null 2>&1; echo $$?), 0)
  368. $(error No libasan found, please install libasan)
  369. endif
  370. endif
  371. ifneq ($(filter s% -fsanitize=undefined%,$(EXTRA_CFLAGS),),)
  372. ifneq ($(shell ldconfig -p | grep libubsan >/dev/null 2>&1; echo $$?), 0)
  373. $(error No libubsan found, please install libubsan)
  374. endif
  375. endif
  376. ifneq ($(filter s% -static%,$(LDFLAGS),),)
  377. $(error No static glibc found, please install glibc-static)
  378. else
  379. $(error No gnu/libc-version.h found, please install glibc-dev[el])
  380. endif
  381. endif
  382. else
  383. ifndef NO_LIBDW_DWARF_UNWIND
  384. ifneq ($(feature-libdw-dwarf-unwind),1)
  385. NO_LIBDW_DWARF_UNWIND := 1
  386. $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR)
  387. endif
  388. endif
  389. ifneq ($(feature-dwarf), 1)
  390. ifndef NO_DWARF
  391. $(warning No libdw.h found or old libdw.h found or elfutils is older than 0.138, disables dwarf support. Please install new elfutils-devel/libdw-dev)
  392. NO_DWARF := 1
  393. endif
  394. else
  395. ifneq ($(feature-dwarf_getlocations), 1)
  396. $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.157)
  397. else
  398. CFLAGS += -DHAVE_DWARF_GETLOCATIONS_SUPPORT
  399. endif # dwarf_getlocations
  400. ifneq ($(feature-dwarf_getcfi), 1)
  401. $(warning Old libdw.h, finding variables at given 'perf probe' point will not work, install elfutils-devel/libdw-dev >= 0.142)
  402. else
  403. CFLAGS += -DHAVE_DWARF_CFI_SUPPORT
  404. endif # dwarf_getcfi
  405. endif # Dwarf support
  406. endif # libelf support
  407. endif # NO_LIBELF
  408. ifeq ($(feature-libaio), 1)
  409. ifndef NO_AIO
  410. CFLAGS += -DHAVE_AIO_SUPPORT
  411. endif
  412. endif
  413. ifdef NO_DWARF
  414. NO_LIBDW_DWARF_UNWIND := 1
  415. endif
  416. ifeq ($(feature-scandirat), 1)
  417. # Ignore having scandirat with memory sanitizer that lacks an interceptor.
  418. ifeq ($(filter s% -fsanitize=memory%,$(EXTRA_CFLAGS),),)
  419. CFLAGS += -DHAVE_SCANDIRAT_SUPPORT
  420. endif
  421. endif
  422. ifeq ($(feature-sched_getcpu), 1)
  423. CFLAGS += -DHAVE_SCHED_GETCPU_SUPPORT
  424. endif
  425. ifeq ($(feature-setns), 1)
  426. CFLAGS += -DHAVE_SETNS_SUPPORT
  427. $(call detected,CONFIG_SETNS)
  428. endif
  429. ifeq ($(feature-reallocarray), 0)
  430. CFLAGS += -DCOMPAT_NEED_REALLOCARRAY
  431. endif
  432. ifdef CORESIGHT
  433. $(call feature_check,libopencsd)
  434. ifeq ($(feature-libopencsd), 1)
  435. CFLAGS += -DHAVE_CSTRACE_SUPPORT $(LIBOPENCSD_CFLAGS)
  436. LDFLAGS += $(LIBOPENCSD_LDFLAGS)
  437. EXTLIBS += $(OPENCSDLIBS)
  438. $(call detected,CONFIG_LIBOPENCSD)
  439. ifdef CSTRACE_RAW
  440. CFLAGS += -DCS_DEBUG_RAW
  441. ifeq (${CSTRACE_RAW}, packed)
  442. CFLAGS += -DCS_RAW_PACKED
  443. endif
  444. endif
  445. else
  446. $(error Error: No libopencsd library found or the version is not up-to-date. Please install recent libopencsd to build with CORESIGHT=1)
  447. endif
  448. endif
  449. ifndef NO_ZLIB
  450. ifeq ($(feature-zlib), 1)
  451. CFLAGS += -DHAVE_ZLIB_SUPPORT
  452. EXTLIBS += -lz
  453. $(call detected,CONFIG_ZLIB)
  454. else
  455. NO_ZLIB := 1
  456. endif
  457. endif
  458. ifndef NO_LIBELF
  459. CFLAGS += -DHAVE_LIBELF_SUPPORT
  460. EXTLIBS += -lelf
  461. $(call detected,CONFIG_LIBELF)
  462. ifeq ($(feature-libelf-getphdrnum), 1)
  463. CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
  464. endif
  465. ifeq ($(feature-libelf-gelf_getnote), 1)
  466. CFLAGS += -DHAVE_GELF_GETNOTE_SUPPORT
  467. else
  468. $(warning gelf_getnote() not found on libelf, SDT support disabled)
  469. endif
  470. ifeq ($(feature-libelf-getshdrstrndx), 1)
  471. CFLAGS += -DHAVE_ELF_GETSHDRSTRNDX_SUPPORT
  472. endif
  473. ifndef NO_LIBDEBUGINFOD
  474. $(call feature_check,libdebuginfod)
  475. ifeq ($(feature-libdebuginfod), 1)
  476. CFLAGS += -DHAVE_DEBUGINFOD_SUPPORT
  477. EXTLIBS += -ldebuginfod
  478. else
  479. $(warning No elfutils/debuginfod.h found, no debuginfo server support, please install libdebuginfod-dev/elfutils-debuginfod-client-devel or equivalent)
  480. endif
  481. endif
  482. ifndef NO_DWARF
  483. ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
  484. $(warning DWARF register mappings have not been defined for architecture $(SRCARCH), DWARF support disabled)
  485. NO_DWARF := 1
  486. else
  487. CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
  488. LDFLAGS += $(LIBDW_LDFLAGS)
  489. EXTLIBS += ${DWARFLIBS}
  490. $(call detected,CONFIG_DWARF)
  491. endif # PERF_HAVE_DWARF_REGS
  492. endif # NO_DWARF
  493. ifndef NO_LIBBPF
  494. ifeq ($(feature-bpf), 1)
  495. # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status
  496. $(call feature_check,libbpf)
  497. ifdef LIBBPF_DYNAMIC
  498. ifeq ($(feature-libbpf), 1)
  499. EXTLIBS += -lbpf
  500. CFLAGS += -DHAVE_LIBBPF_SUPPORT
  501. $(call detected,CONFIG_LIBBPF)
  502. $(call detected,CONFIG_LIBBPF_DYNAMIC)
  503. else
  504. $(error Error: No libbpf devel library found or older than v1.0, please install/update libbpf-devel)
  505. endif
  506. else
  507. ifeq ($(NO_ZLIB), 1)
  508. $(warning Warning: Statically building libbpf not possible as zlib is missing)
  509. NO_LIBBPF := 1
  510. else
  511. # Libbpf will be built as a static library from tools/lib/bpf.
  512. LIBBPF_STATIC := 1
  513. $(call detected,CONFIG_LIBBPF)
  514. CFLAGS += -DHAVE_LIBBPF_SUPPORT
  515. endif
  516. endif
  517. endif
  518. endif # NO_LIBBPF
  519. endif # NO_LIBELF
  520. ifndef NO_SDT
  521. ifneq ($(feature-sdt), 1)
  522. $(warning No sys/sdt.h found, no SDT events are defined, please install systemtap-sdt-devel or systemtap-sdt-dev)
  523. NO_SDT := 1;
  524. else
  525. CFLAGS += -DHAVE_SDT_EVENT
  526. $(call detected,CONFIG_SDT_EVENT)
  527. endif
  528. endif
  529. ifdef PERF_HAVE_JITDUMP
  530. ifndef NO_LIBELF
  531. $(call detected,CONFIG_JITDUMP)
  532. CFLAGS += -DHAVE_JITDUMP
  533. endif
  534. endif
  535. ifeq ($(SRCARCH),powerpc)
  536. ifndef NO_DWARF
  537. CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
  538. endif
  539. endif
  540. ifndef NO_LIBUNWIND
  541. have_libunwind :=
  542. $(call feature_check,libunwind-x86)
  543. ifeq ($(feature-libunwind-x86), 1)
  544. $(call detected,CONFIG_LIBUNWIND_X86)
  545. CFLAGS += -DHAVE_LIBUNWIND_X86_SUPPORT
  546. LDFLAGS += -lunwind-x86
  547. EXTLIBS_LIBUNWIND += -lunwind-x86
  548. have_libunwind = 1
  549. endif
  550. $(call feature_check,libunwind-aarch64)
  551. ifeq ($(feature-libunwind-aarch64), 1)
  552. $(call detected,CONFIG_LIBUNWIND_AARCH64)
  553. CFLAGS += -DHAVE_LIBUNWIND_AARCH64_SUPPORT
  554. LDFLAGS += -lunwind-aarch64
  555. EXTLIBS_LIBUNWIND += -lunwind-aarch64
  556. have_libunwind = 1
  557. $(call feature_check,libunwind-debug-frame-aarch64)
  558. ifneq ($(feature-libunwind-debug-frame-aarch64), 1)
  559. $(warning No debug_frame support found in libunwind-aarch64)
  560. CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME_AARCH64
  561. endif
  562. endif
  563. ifneq ($(feature-libunwind), 1)
  564. $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR)
  565. NO_LOCAL_LIBUNWIND := 1
  566. else
  567. have_libunwind := 1
  568. $(call detected,CONFIG_LOCAL_LIBUNWIND)
  569. endif
  570. ifneq ($(have_libunwind), 1)
  571. NO_LIBUNWIND := 1
  572. endif
  573. else
  574. NO_LOCAL_LIBUNWIND := 1
  575. endif
  576. ifndef NO_LIBBPF
  577. ifneq ($(feature-bpf), 1)
  578. $(warning BPF API too old. Please install recent kernel headers. BPF support in 'perf record' is disabled.)
  579. NO_LIBBPF := 1
  580. endif
  581. endif
  582. ifndef BUILD_BPF_SKEL
  583. # BPF skeletons control a large number of perf features, by default
  584. # they are enabled.
  585. BUILD_BPF_SKEL := 1
  586. endif
  587. ifeq ($(BUILD_BPF_SKEL),1)
  588. ifeq ($(filter -DHAVE_LIBELF_SUPPORT, $(CFLAGS)),)
  589. $(warning Warning: Disabled BPF skeletons as libelf is required by bpftool)
  590. BUILD_BPF_SKEL := 0
  591. else ifeq ($(filter -DHAVE_ZLIB_SUPPORT, $(CFLAGS)),)
  592. $(warning Warning: Disabled BPF skeletons as zlib is required by bpftool)
  593. BUILD_BPF_SKEL := 0
  594. else ifeq ($(filter -DHAVE_LIBBPF_SUPPORT, $(CFLAGS)),)
  595. $(warning Warning: Disabled BPF skeletons as libbpf is required)
  596. BUILD_BPF_SKEL := 0
  597. else ifeq ($(call get-executable,$(CLANG)),)
  598. $(warning Warning: Disabled BPF skeletons as clang ($(CLANG)) is missing)
  599. BUILD_BPF_SKEL := 0
  600. else
  601. CLANG_VERSION := $(shell $(CLANG) --version | head -1 | sed 's/.*clang version \([[:digit:]]\+.[[:digit:]]\+.[[:digit:]]\+\).*/\1/g')
  602. ifeq ($(call version-lt3,$(CLANG_VERSION),12.0.1),1)
  603. $(warning Warning: Disabled BPF skeletons as reliable BTF generation needs at least $(CLANG) version 12.0.1)
  604. BUILD_BPF_SKEL := 0
  605. endif
  606. endif
  607. ifeq ($(BUILD_BPF_SKEL),1)
  608. $(call feature_check,clang-bpf-co-re)
  609. ifeq ($(feature-clang-bpf-co-re), 0)
  610. $(warning Warning: Disabled BPF skeletons as clang is too old)
  611. BUILD_BPF_SKEL := 0
  612. endif
  613. endif
  614. ifeq ($(BUILD_BPF_SKEL),1)
  615. $(call detected,CONFIG_PERF_BPF_SKEL)
  616. CFLAGS += -DHAVE_BPF_SKEL
  617. endif
  618. endif
  619. ifndef GEN_VMLINUX_H
  620. VMLINUX_H=$(src-perf)/util/bpf_skel/vmlinux/vmlinux.h
  621. endif
  622. dwarf-post-unwind := 1
  623. dwarf-post-unwind-text := BUG
  624. # setup DWARF post unwinder
  625. ifdef NO_LIBUNWIND
  626. ifdef NO_LIBDW_DWARF_UNWIND
  627. $(warning Disabling post unwind, no support found.)
  628. dwarf-post-unwind := 0
  629. else
  630. dwarf-post-unwind-text := libdw
  631. $(call detected,CONFIG_LIBDW_DWARF_UNWIND)
  632. endif
  633. else
  634. dwarf-post-unwind-text := libunwind
  635. $(call detected,CONFIG_LIBUNWIND)
  636. # Enable libunwind support by default.
  637. ifndef NO_LIBDW_DWARF_UNWIND
  638. NO_LIBDW_DWARF_UNWIND := 1
  639. endif
  640. endif
  641. ifeq ($(dwarf-post-unwind),1)
  642. CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
  643. $(call detected,CONFIG_DWARF_UNWIND)
  644. else
  645. NO_DWARF_UNWIND := 1
  646. endif
  647. ifndef NO_LOCAL_LIBUNWIND
  648. ifeq ($(SRCARCH),$(filter $(SRCARCH),arm arm64))
  649. $(call feature_check,libunwind-debug-frame)
  650. ifneq ($(feature-libunwind-debug-frame), 1)
  651. $(warning No debug_frame support found in libunwind)
  652. CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
  653. endif
  654. else
  655. # non-ARM has no dwarf_find_debug_frame() function:
  656. CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
  657. endif
  658. EXTLIBS += $(LIBUNWIND_LIBS)
  659. LDFLAGS += $(LIBUNWIND_LIBS)
  660. endif
  661. ifeq ($(findstring -static,${LDFLAGS}),-static)
  662. # gcc -static links libgcc_eh which contans piece of libunwind
  663. LIBUNWIND_LDFLAGS += -Wl,--allow-multiple-definition
  664. endif
  665. ifndef NO_LIBUNWIND
  666. CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
  667. CFLAGS += $(LIBUNWIND_CFLAGS)
  668. LDFLAGS += $(LIBUNWIND_LDFLAGS)
  669. EXTLIBS += $(EXTLIBS_LIBUNWIND)
  670. endif
  671. ifneq ($(NO_LIBTRACEEVENT),1)
  672. ifeq ($(NO_SYSCALL_TABLE),0)
  673. $(call detected,CONFIG_TRACE)
  674. else
  675. ifndef NO_LIBAUDIT
  676. $(call feature_check,libaudit)
  677. ifneq ($(feature-libaudit), 1)
  678. $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev)
  679. NO_LIBAUDIT := 1
  680. else
  681. CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
  682. EXTLIBS += -laudit
  683. $(call detected,CONFIG_TRACE)
  684. endif
  685. endif
  686. endif
  687. endif
  688. ifndef NO_LIBCRYPTO
  689. ifneq ($(feature-libcrypto), 1)
  690. $(warning No libcrypto.h found, disables jitted code injection, please install openssl-devel or libssl-dev)
  691. NO_LIBCRYPTO := 1
  692. else
  693. CFLAGS += -DHAVE_LIBCRYPTO_SUPPORT
  694. EXTLIBS += -lcrypto
  695. $(call detected,CONFIG_CRYPTO)
  696. endif
  697. endif
  698. ifndef NO_SLANG
  699. ifneq ($(feature-libslang), 1)
  700. ifneq ($(feature-libslang-include-subdir), 1)
  701. $(warning slang not found, disables TUI support. Please install slang-devel, libslang-dev or libslang2-dev)
  702. NO_SLANG := 1
  703. else
  704. CFLAGS += -DHAVE_SLANG_INCLUDE_SUBDIR
  705. endif
  706. endif
  707. ifndef NO_SLANG
  708. # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
  709. CFLAGS += -DHAVE_SLANG_SUPPORT
  710. EXTLIBS += -lslang
  711. $(call detected,CONFIG_SLANG)
  712. endif
  713. endif
  714. ifdef GTK2
  715. FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
  716. $(call feature_check,gtk2)
  717. ifneq ($(feature-gtk2), 1)
  718. $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev)
  719. NO_GTK2 := 1
  720. else
  721. $(call feature_check,gtk2-infobar)
  722. ifeq ($(feature-gtk2-infobar), 1)
  723. GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
  724. endif
  725. CFLAGS += -DHAVE_GTK2_SUPPORT
  726. GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
  727. GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
  728. EXTLIBS += -ldl
  729. endif
  730. endif
  731. ifdef NO_LIBPERL
  732. CFLAGS += -DNO_LIBPERL
  733. else
  734. PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
  735. PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
  736. PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
  737. PERL_EMBED_CCOPTS = $(shell perl -MExtUtils::Embed -e ccopts 2>/dev/null)
  738. PERL_EMBED_CCOPTS := $(filter-out -specs=%,$(PERL_EMBED_CCOPTS))
  739. PERL_EMBED_CCOPTS := $(filter-out -flto=auto -ffat-lto-objects, $(PERL_EMBED_CCOPTS))
  740. PERL_EMBED_LDOPTS := $(filter-out -specs=%,$(PERL_EMBED_LDOPTS))
  741. FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
  742. ifneq ($(feature-libperl), 1)
  743. CFLAGS += -DNO_LIBPERL
  744. NO_LIBPERL := 1
  745. $(warning Missing perl devel files. Disabling perl scripting support, please install perl-ExtUtils-Embed/libperl-dev)
  746. else
  747. LDFLAGS += $(PERL_EMBED_LDFLAGS)
  748. EXTLIBS += $(PERL_EMBED_LIBADD)
  749. CFLAGS += -DHAVE_LIBPERL_SUPPORT
  750. ifeq ($(CC_NO_CLANG), 0)
  751. CFLAGS += -Wno-compound-token-split-by-macro
  752. endif
  753. $(call detected,CONFIG_LIBPERL)
  754. endif
  755. endif
  756. ifeq ($(feature-timerfd), 1)
  757. CFLAGS += -DHAVE_TIMERFD_SUPPORT
  758. else
  759. $(warning No timerfd support. Disables 'perf kvm stat live')
  760. endif
  761. disable-python = $(eval $(disable-python_code))
  762. define disable-python_code
  763. CFLAGS += -DNO_LIBPYTHON
  764. $(warning $1)
  765. NO_LIBPYTHON := 1
  766. endef
  767. PYTHON_EXTENSION_SUFFIX := '.so'
  768. ifdef NO_LIBPYTHON
  769. $(call disable-python,Python support disabled by user)
  770. else
  771. ifndef PYTHON
  772. $(call disable-python,No python interpreter was found: disables Python support - please install python-devel/python-dev)
  773. else
  774. PYTHON_WORD := $(call shell-wordify,$(PYTHON))
  775. ifndef PYTHON_CONFIG
  776. $(call disable-python,No 'python-config' tool was found: disables Python support - please install python-devel/python-dev)
  777. else
  778. ifneq ($(feature-libpython), 1)
  779. $(call disable-python,No 'Python.h' was found: disables Python support - please install python-devel/python-dev)
  780. else
  781. LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
  782. EXTLIBS += $(PYTHON_EMBED_LIBADD)
  783. PYTHON_SETUPTOOLS_INSTALLED := $(shell $(PYTHON) -c 'import setuptools;' 2> /dev/null && echo "yes" || echo "no")
  784. ifeq ($(PYTHON_SETUPTOOLS_INSTALLED), yes)
  785. PYTHON_EXTENSION_SUFFIX := $(shell $(PYTHON) -c 'from importlib import machinery; print(machinery.EXTENSION_SUFFIXES[0])')
  786. ifdef CROSS_COMPILE
  787. PYTHON_EXTENSION_SUFFIX := $(subst $(PYTHON_NATIVE),$(shell $(CC) -dumpmachine),$(PYTHON_EXTENSION_SUFFIX))
  788. endif
  789. LANG_BINDINGS += $(obj-perf)python/perf$(PYTHON_EXTENSION_SUFFIX)
  790. else
  791. $(warning Missing python setuptools, the python binding won't be built, please install python3-setuptools or equivalent)
  792. endif
  793. CFLAGS += -DHAVE_LIBPYTHON_SUPPORT
  794. $(call detected,CONFIG_LIBPYTHON)
  795. ifeq ($(filter -fPIC,$(CFLAGS)),)
  796. # Building a shared library requires position independent code.
  797. CFLAGS += -fPIC
  798. CXXFLAGS += -fPIC
  799. endif
  800. endif
  801. endif
  802. endif
  803. endif
  804. ifneq ($(NO_JEVENTS),1)
  805. ifeq ($(wildcard pmu-events/arch/$(SRCARCH)/mapfile.csv),)
  806. NO_JEVENTS := 1
  807. endif
  808. endif
  809. ifneq ($(NO_JEVENTS),1)
  810. NO_JEVENTS := 0
  811. ifndef PYTHON
  812. $(error ERROR: No python interpreter needed for jevents generation. Install python or build with NO_JEVENTS=1.)
  813. else
  814. # jevents.py uses f-strings present in Python 3.6 released in Dec. 2016.
  815. JEVENTS_PYTHON_GOOD := $(shell $(PYTHON) -c 'import sys;print("1" if(sys.version_info.major >= 3 and sys.version_info.minor >= 6) else "0")' 2> /dev/null)
  816. ifneq ($(JEVENTS_PYTHON_GOOD), 1)
  817. $(error ERROR: Python interpreter needed for jevents generation too old (older than 3.6). Install a newer python or build with NO_JEVENTS=1.)
  818. endif
  819. endif
  820. endif
  821. ifdef BUILD_NONDISTRO
  822. ifeq ($(feature-libbfd), 1)
  823. EXTLIBS += -lbfd -lopcodes
  824. else
  825. # we are on a system that requires -liberty and (maybe) -lz
  826. # to link against -lbfd; test each case individually here
  827. # call all detections now so we get correct
  828. # status in VF output
  829. $(call feature_check,libbfd-liberty)
  830. $(call feature_check,libbfd-liberty-z)
  831. ifeq ($(feature-libbfd-liberty), 1)
  832. EXTLIBS += -lbfd -lopcodes -liberty
  833. FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -ldl
  834. FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -ldl
  835. else
  836. ifeq ($(feature-libbfd-liberty-z), 1)
  837. EXTLIBS += -lbfd -lopcodes -liberty -lz
  838. FEATURE_CHECK_LDFLAGS-disassembler-four-args += -liberty -lz -ldl
  839. FEATURE_CHECK_LDFLAGS-disassembler-init-styled += -liberty -lz -ldl
  840. endif
  841. endif
  842. $(call feature_check,disassembler-four-args)
  843. $(call feature_check,disassembler-init-styled)
  844. endif
  845. CFLAGS += -DHAVE_LIBBFD_SUPPORT
  846. CXXFLAGS += -DHAVE_LIBBFD_SUPPORT
  847. ifeq ($(feature-libbfd-buildid), 1)
  848. CFLAGS += -DHAVE_LIBBFD_BUILDID_SUPPORT
  849. else
  850. $(warning Old version of libbfd/binutils things like PE executable profiling will not be available)
  851. endif
  852. endif
  853. ifndef NO_LIBLLVM
  854. $(call feature_check,llvm-perf)
  855. ifeq ($(feature-llvm-perf), 1)
  856. CFLAGS += -DHAVE_LIBLLVM_SUPPORT
  857. CFLAGS += $(shell $(LLVM_CONFIG) --cflags)
  858. CXXFLAGS += -DHAVE_LIBLLVM_SUPPORT
  859. CXXFLAGS += $(shell $(LLVM_CONFIG) --cxxflags)
  860. LIBLLVM = $(shell $(LLVM_CONFIG) --libs all) $(shell $(LLVM_CONFIG) --system-libs)
  861. EXTLIBS += -L$(shell $(LLVM_CONFIG) --libdir) $(LIBLLVM)
  862. EXTLIBS += -lstdc++
  863. $(call detected,CONFIG_LIBLLVM)
  864. else
  865. $(warning No libllvm 13+ found, slower source file resolution, please install llvm-devel/llvm-dev)
  866. NO_LIBLLVM := 1
  867. endif
  868. endif
  869. ifndef NO_DEMANGLE
  870. $(call feature_check,cxa-demangle)
  871. ifeq ($(feature-cxa-demangle), 1)
  872. EXTLIBS += -lstdc++
  873. CFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
  874. CXXFLAGS += -DHAVE_CXA_DEMANGLE_SUPPORT
  875. $(call detected,CONFIG_CXX_DEMANGLE)
  876. endif
  877. ifdef BUILD_NONDISTRO
  878. ifeq ($(filter -liberty,$(EXTLIBS)),)
  879. $(call feature_check,cplus-demangle)
  880. ifeq ($(feature-cplus-demangle), 1)
  881. EXTLIBS += -liberty
  882. endif
  883. endif
  884. ifneq ($(filter -liberty,$(EXTLIBS)),)
  885. CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  886. CXXFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
  887. endif
  888. endif
  889. endif
  890. ifndef NO_LZMA
  891. ifeq ($(feature-lzma), 1)
  892. CFLAGS += -DHAVE_LZMA_SUPPORT
  893. EXTLIBS += -llzma
  894. $(call detected,CONFIG_LZMA)
  895. else
  896. $(warning No liblzma found, disables xz kernel module decompression, please install xz-devel/liblzma-dev)
  897. NO_LZMA := 1
  898. endif
  899. endif
  900. ifndef NO_LIBZSTD
  901. ifeq ($(feature-libzstd), 1)
  902. CFLAGS += -DHAVE_ZSTD_SUPPORT
  903. CFLAGS += $(LIBZSTD_CFLAGS)
  904. LDFLAGS += $(LIBZSTD_LDFLAGS)
  905. EXTLIBS += -lzstd
  906. $(call detected,CONFIG_ZSTD)
  907. else
  908. $(warning No libzstd found, disables trace compression, please install libzstd-dev[el] and/or set LIBZSTD_DIR)
  909. NO_LIBZSTD := 1
  910. endif
  911. endif
  912. ifndef NO_BACKTRACE
  913. ifeq ($(feature-backtrace), 1)
  914. CFLAGS += -DHAVE_BACKTRACE_SUPPORT
  915. endif
  916. endif
  917. ifndef NO_LIBNUMA
  918. ifeq ($(feature-libnuma), 0)
  919. $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev)
  920. NO_LIBNUMA := 1
  921. else
  922. ifeq ($(feature-numa_num_possible_cpus), 0)
  923. $(warning Old numa library found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev >= 2.0.8)
  924. NO_LIBNUMA := 1
  925. else
  926. CFLAGS += -DHAVE_LIBNUMA_SUPPORT
  927. EXTLIBS += -lnuma
  928. $(call detected,CONFIG_NUMA)
  929. endif
  930. endif
  931. endif
  932. ifdef HAVE_KVM_STAT_SUPPORT
  933. CFLAGS += -DHAVE_KVM_STAT_SUPPORT
  934. endif
  935. ifeq ($(feature-disassembler-four-args), 1)
  936. CFLAGS += -DDISASM_FOUR_ARGS_SIGNATURE
  937. endif
  938. ifeq ($(feature-disassembler-init-styled), 1)
  939. CFLAGS += -DDISASM_INIT_STYLED
  940. endif
  941. ifeq (${IS_64_BIT}, 1)
  942. ifndef NO_PERF_READ_VDSO32
  943. $(call feature_check,compile-32)
  944. ifeq ($(feature-compile-32), 1)
  945. CFLAGS += -DHAVE_PERF_READ_VDSO32
  946. else
  947. NO_PERF_READ_VDSO32 := 1
  948. endif
  949. endif
  950. ifneq ($(SRCARCH), x86)
  951. NO_PERF_READ_VDSOX32 := 1
  952. endif
  953. ifndef NO_PERF_READ_VDSOX32
  954. $(call feature_check,compile-x32)
  955. ifeq ($(feature-compile-x32), 1)
  956. CFLAGS += -DHAVE_PERF_READ_VDSOX32
  957. else
  958. NO_PERF_READ_VDSOX32 := 1
  959. endif
  960. endif
  961. else
  962. NO_PERF_READ_VDSO32 := 1
  963. NO_PERF_READ_VDSOX32 := 1
  964. endif
  965. ifndef NO_LIBBABELTRACE
  966. $(call feature_check,libbabeltrace)
  967. ifeq ($(feature-libbabeltrace), 1)
  968. CFLAGS += -DHAVE_LIBBABELTRACE_SUPPORT $(LIBBABELTRACE_CFLAGS)
  969. LDFLAGS += $(LIBBABELTRACE_LDFLAGS)
  970. EXTLIBS += -lbabeltrace-ctf
  971. $(call detected,CONFIG_LIBBABELTRACE)
  972. else
  973. $(warning No libbabeltrace found, disables 'perf data' CTF format support, please install libbabeltrace-dev[el]/libbabeltrace-ctf-dev)
  974. endif
  975. endif
  976. ifndef NO_CAPSTONE
  977. $(call feature_check,libcapstone)
  978. ifeq ($(feature-libcapstone), 1)
  979. CFLAGS += -DHAVE_LIBCAPSTONE_SUPPORT $(LIBCAPSTONE_CFLAGS)
  980. LDFLAGS += $(LICAPSTONE_LDFLAGS)
  981. EXTLIBS += -lcapstone
  982. $(call detected,CONFIG_LIBCAPSTONE)
  983. else
  984. msg := $(warning No libcapstone found, disables disasm engine support for 'perf script', please install libcapstone-dev/capstone-devel);
  985. endif
  986. endif
  987. ifndef NO_AUXTRACE
  988. ifeq ($(SRCARCH),x86)
  989. ifeq ($(feature-get_cpuid), 0)
  990. $(warning Your gcc lacks the __get_cpuid() builtin, disables support for auxtrace/Intel PT, please install a newer gcc)
  991. NO_AUXTRACE := 1
  992. endif
  993. endif
  994. ifndef NO_AUXTRACE
  995. $(call detected,CONFIG_AUXTRACE)
  996. CFLAGS += -DHAVE_AUXTRACE_SUPPORT
  997. endif
  998. endif
  999. ifdef EXTRA_TESTS
  1000. $(call detected,CONFIG_EXTRA_TESTS)
  1001. CFLAGS += -DHAVE_EXTRA_TESTS
  1002. endif
  1003. ifndef NO_JVMTI
  1004. ifneq (,$(wildcard /usr/sbin/update-java-alternatives))
  1005. JDIR=$(shell /usr/sbin/update-java-alternatives -l | head -1 | awk '{print $$3}')
  1006. else
  1007. ifneq (,$(wildcard /usr/sbin/alternatives))
  1008. JDIR=$(shell /usr/sbin/alternatives --display java | tail -1 | cut -d' ' -f 5 | sed -e 's%/jre/bin/java.%%g' -e 's%/bin/java.%%g')
  1009. endif
  1010. endif
  1011. ifndef JDIR
  1012. $(warning No alternatives command found, you need to set JDIR= to point to the root of your Java directory)
  1013. NO_JVMTI := 1
  1014. endif
  1015. endif
  1016. ifndef NO_JVMTI
  1017. FEATURE_CHECK_CFLAGS-jvmti := -I$(JDIR)/include -I$(JDIR)/include/linux
  1018. $(call feature_check,jvmti)
  1019. ifeq ($(feature-jvmti), 1)
  1020. $(call detected_var,JDIR)
  1021. ifndef NO_JVMTI_CMLR
  1022. FEATURE_CHECK_CFLAGS-jvmti-cmlr := $(FEATURE_CHECK_CFLAGS-jvmti)
  1023. $(call feature_check,jvmti-cmlr)
  1024. ifeq ($(feature-jvmti-cmlr), 1)
  1025. CFLAGS += -DHAVE_JVMTI_CMLR
  1026. endif
  1027. endif # NO_JVMTI_CMLR
  1028. else
  1029. $(warning No openjdk development package found, please install JDK package, e.g. openjdk-8-jdk, java-1.8.0-openjdk-devel)
  1030. NO_JVMTI := 1
  1031. endif
  1032. endif
  1033. ifndef NO_LIBPFM4
  1034. $(call feature_check,libpfm4)
  1035. ifeq ($(feature-libpfm4), 1)
  1036. CFLAGS += -DHAVE_LIBPFM
  1037. EXTLIBS += -lpfm
  1038. ASCIIDOC_EXTRA = -aHAVE_LIBPFM=1
  1039. $(call detected,CONFIG_LIBPFM4)
  1040. else
  1041. $(warning libpfm4 not found, disables libpfm4 support. Please install libpfm4-dev)
  1042. endif
  1043. endif
  1044. # libtraceevent is a recommended dependency picked up from the system.
  1045. ifneq ($(NO_LIBTRACEEVENT),1)
  1046. $(call feature_check,libtraceevent)
  1047. ifeq ($(feature-libtraceevent), 1)
  1048. CFLAGS += -DHAVE_LIBTRACEEVENT $(shell $(PKG_CONFIG) --cflags libtraceevent)
  1049. LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtraceevent)
  1050. EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtraceevent)
  1051. LIBTRACEEVENT_VERSION := $(shell $(PKG_CONFIG) --modversion libtraceevent).0.0
  1052. LIBTRACEEVENT_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
  1053. LIBTRACEEVENT_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
  1054. LIBTRACEEVENT_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEEVENT_VERSION)))
  1055. LIBTRACEEVENT_VERSION_CPP := $(shell expr $(LIBTRACEEVENT_VERSION_1) \* 255 \* 255 + $(LIBTRACEEVENT_VERSION_2) \* 255 + $(LIBTRACEEVENT_VERSION_3))
  1056. CFLAGS += -DLIBTRACEEVENT_VERSION=$(LIBTRACEEVENT_VERSION_CPP)
  1057. $(call detected,CONFIG_LIBTRACEEVENT)
  1058. else
  1059. $(error ERROR: libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel and/or set LIBTRACEEVENT_DIR or build with NO_LIBTRACEEVENT=1)
  1060. endif
  1061. $(call feature_check,libtracefs)
  1062. ifeq ($(feature-libtracefs), 1)
  1063. CFLAGS += $(shell $(PKG_CONFIG) --cflags libtracefs)
  1064. LDFLAGS += $(shell $(PKG_CONFIG) --libs-only-L libtracefs)
  1065. EXTLIBS += $(shell $(PKG_CONFIG) --libs-only-l libtracefs)
  1066. LIBTRACEFS_VERSION := $(shell $(PKG_CONFIG) --modversion libtracefs).0.0
  1067. LIBTRACEFS_VERSION_1 := $(word 1, $(subst ., ,$(LIBTRACEFS_VERSION)))
  1068. LIBTRACEFS_VERSION_2 := $(word 2, $(subst ., ,$(LIBTRACEFS_VERSION)))
  1069. LIBTRACEFS_VERSION_3 := $(word 3, $(subst ., ,$(LIBTRACEFS_VERSION)))
  1070. LIBTRACEFS_VERSION_CPP := $(shell expr $(LIBTRACEFS_VERSION_1) \* 255 \* 255 + $(LIBTRACEFS_VERSION_2) \* 255 + $(LIBTRACEFS_VERSION_3))
  1071. CFLAGS += -DLIBTRACEFS_VERSION=$(LIBTRACEFS_VERSION_CPP)
  1072. else
  1073. $(warning libtracefs is missing. Please install libtracefs-dev/libtracefs-devel)
  1074. endif
  1075. endif
  1076. # Among the variables below, these:
  1077. # perfexecdir
  1078. # libbpf_include_dir
  1079. # perf_examples_dir
  1080. # template_dir
  1081. # mandir
  1082. # infodir
  1083. # htmldir
  1084. # ETC_PERFCONFIG (but not sysconfdir)
  1085. # can be specified as a relative path some/where/else;
  1086. # this is interpreted as relative to $(prefix) and "perf" at
  1087. # runtime figures out where they are based on the path to the executable.
  1088. # This can help installing the suite in a relocatable way.
  1089. # Make the path relative to DESTDIR, not to prefix
  1090. ifndef DESTDIR
  1091. prefix ?= $(HOME)
  1092. endif
  1093. bindir_relative = bin
  1094. bindir = $(abspath $(prefix)/$(bindir_relative))
  1095. includedir_relative = include
  1096. includedir = $(abspath $(prefix)/$(includedir_relative))
  1097. mandir = share/man
  1098. infodir = share/info
  1099. perfexecdir = libexec/perf-core
  1100. # FIXME: system's libbpf header directory, where we expect to find bpf/bpf_helpers.h, for instance
  1101. libbpf_include_dir = /usr/include
  1102. perf_examples_dir = lib/perf/examples
  1103. sharedir = $(prefix)/share
  1104. template_dir = share/perf-core/templates
  1105. STRACE_GROUPS_DIR = share/perf-core/strace/groups
  1106. htmldir = share/doc/perf-doc
  1107. tipdir = share/doc/perf-tip
  1108. srcdir = $(srctree)/tools/perf
  1109. ifeq ($(prefix),/usr)
  1110. sysconfdir = /etc
  1111. ETC_PERFCONFIG = $(sysconfdir)/perfconfig
  1112. else
  1113. sysconfdir = $(prefix)/etc
  1114. ETC_PERFCONFIG = etc/perfconfig
  1115. endif
  1116. ifndef lib
  1117. ifeq ($(SRCARCH)$(IS_64_BIT), x861)
  1118. lib = lib64
  1119. else
  1120. lib = lib
  1121. endif
  1122. endif # lib
  1123. libdir = $(prefix)/$(lib)
  1124. # Shell quote (do not use $(call) to accommodate ancient setups);
  1125. ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
  1126. STRACE_GROUPS_DIR_SQ = $(subst ','\'',$(STRACE_GROUPS_DIR))
  1127. DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
  1128. bindir_SQ = $(subst ','\'',$(bindir))
  1129. includedir_SQ = $(subst ','\'',$(includedir))
  1130. mandir_SQ = $(subst ','\'',$(mandir))
  1131. infodir_SQ = $(subst ','\'',$(infodir))
  1132. perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
  1133. libbpf_include_dir_SQ = $(subst ','\'',$(libbpf_include_dir))
  1134. perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir))
  1135. template_dir_SQ = $(subst ','\'',$(template_dir))
  1136. htmldir_SQ = $(subst ','\'',$(htmldir))
  1137. tipdir_SQ = $(subst ','\'',$(tipdir))
  1138. prefix_SQ = $(subst ','\'',$(prefix))
  1139. sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
  1140. libdir_SQ = $(subst ','\'',$(libdir))
  1141. srcdir_SQ = $(subst ','\'',$(srcdir))
  1142. ifneq ($(filter /%,$(firstword $(perfexecdir))),)
  1143. perfexec_instdir = $(perfexecdir)
  1144. perf_include_instdir = $(libbpf_include_dir)
  1145. perf_examples_instdir = $(perf_examples_dir)
  1146. STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR)
  1147. tip_instdir = $(tipdir)
  1148. else
  1149. perfexec_instdir = $(prefix)/$(perfexecdir)
  1150. perf_include_instdir = $(prefix)/$(libbpf_include_dir)
  1151. perf_examples_instdir = $(prefix)/$(perf_examples_dir)
  1152. STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR)
  1153. tip_instdir = $(prefix)/$(tipdir)
  1154. endif
  1155. perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
  1156. perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir))
  1157. perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir))
  1158. STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR))
  1159. tip_instdir_SQ = $(subst ','\'',$(tip_instdir))
  1160. export perfexec_instdir_SQ
  1161. print_var = $(eval $(print_var_code)) $(info $(MSG))
  1162. define print_var_code
  1163. MSG = $(shell printf '...%40s: %s' $(1) $($(1)))
  1164. endef
  1165. ifeq ($(feature_display),1)
  1166. $(call feature_display_entries)
  1167. endif
  1168. ifeq ($(VF),1)
  1169. # Display EXTRA features which are detected manualy
  1170. # from here with feature_check call and thus cannot
  1171. # be partof global state output.
  1172. $(foreach feat,$(FEATURE_TESTS_EXTRA),$(call feature_print_status,$(feat),) $(info $(MSG)))
  1173. $(call print_var,prefix)
  1174. $(call print_var,bindir)
  1175. $(call print_var,libdir)
  1176. $(call print_var,sysconfdir)
  1177. $(call print_var,LIBUNWIND_DIR)
  1178. $(call print_var,LIBDW_DIR)
  1179. $(call print_var,JDIR)
  1180. ifeq ($(dwarf-post-unwind),1)
  1181. $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text)) $(info $(MSG))
  1182. endif
  1183. endif
  1184. $(info )
  1185. $(call detected_var,bindir_SQ)
  1186. $(call detected_var,PYTHON_WORD)
  1187. ifneq ($(OUTPUT),)
  1188. $(call detected_var,OUTPUT)
  1189. endif
  1190. $(call detected_var,htmldir_SQ)
  1191. $(call detected_var,infodir_SQ)
  1192. $(call detected_var,mandir_SQ)
  1193. $(call detected_var,ETC_PERFCONFIG_SQ)
  1194. $(call detected_var,STRACE_GROUPS_DIR_SQ)
  1195. $(call detected_var,prefix_SQ)
  1196. $(call detected_var,perfexecdir_SQ)
  1197. $(call detected_var,libbpf_include_dir_SQ)
  1198. $(call detected_var,perf_examples_dir_SQ)
  1199. $(call detected_var,tipdir_SQ)
  1200. $(call detected_var,srcdir_SQ)
  1201. $(call detected_var,LIBDIR)
  1202. $(call detected_var,GTK_CFLAGS)
  1203. $(call detected_var,PERL_EMBED_CCOPTS)
  1204. $(call detected_var,PYTHON_EMBED_CCOPTS)
  1205. ifneq ($(BISON_FILE_PREFIX_MAP),)
  1206. $(call detected_var,BISON_FILE_PREFIX_MAP)
  1207. endif
  1208. # re-generate FEATURE-DUMP as we may have called feature_check, found out
  1209. # extra libraries to add to LDFLAGS of some other test and then redo those
  1210. # tests, see the block about libbfd, disassembler-four-args, for instance.
  1211. $(shell rm -f $(FEATURE_DUMP_FILENAME))
  1212. $(foreach feat,$(FEATURE_TESTS),$(shell echo "$(call feature_assign,$(feat))" >> $(FEATURE_DUMP_FILENAME)))