Makefile.config 41 KB

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