]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/perf/config/Makefile
perf build: Add builtin objects building
[mirror_ubuntu-hirsute-kernel.git] / tools / perf / config / Makefile
CommitLineData
8bd407b9 1
a6cf5f39
JO
2ifeq ($(src-perf),)
3src-perf := $(srctree)/tools/perf
4endif
8bd407b9 5
a6cf5f39
JO
6ifeq ($(obj-perf),)
7obj-perf := $(OUTPUT)
8bd407b9
JO
8endif
9
a6cf5f39
JO
10ifneq ($(obj-perf),)
11obj-perf := $(abspath $(obj-perf))/
12endif
13
fcfd6611
JO
14$(shell echo -n > .config-detected)
15detected = $(shell echo "$(1)=y" >> .config-detected)
16detected_var = $(shell echo "$(1)=$($(1))" >> .config-detected)
17
a6cf5f39
JO
18LIB_INCLUDE := $(srctree)/tools/lib/
19CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
20
21include $(src-perf)/config/Makefile.arch
22
f39e042a
JO
23$(call detected_var,ARCH)
24
a6cf5f39
JO
25NO_PERF_REGS := 1
26
27# Additional ARCH settings for x86
28ifeq ($(ARCH),x86)
f39e042a 29 $(call detected,CONFIG_X86)
c6e5e9fb 30 ifeq (${IS_64_BIT}, 1)
89fe808a 31 CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
8e1b3f68 32 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
8a0c4c28 33 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
72965b87 34 $(call detected,CONFIG_X86_64)
8a0c4c28
AH
35 else
36 LIBUNWIND_LIBS = -lunwind -lunwind-x86
8e1b3f68
JO
37 endif
38 NO_PERF_REGS := 0
8bd407b9 39endif
8ab596af 40
7495f374
WD
41ifeq ($(ARCH),arm)
42 NO_PERF_REGS := 0
43 LIBUNWIND_LIBS = -lunwind -lunwind-arm
44endif
8bd407b9 45
8ab596af
JP
46ifeq ($(ARCH),arm64)
47 NO_PERF_REGS := 0
48 LIBUNWIND_LIBS = -lunwind -lunwind-aarch64
49endif
50
90fa9deb 51# So far there's only x86 and arm libdw unwind support merged in perf.
4dc549e5
JO
52# Disable it on all other architectures in case libdw unwind
53# support is detected in system. Add supported architectures
54# to the check.
90fa9deb 55ifneq ($(ARCH),$(filter $(ARCH),x86 arm))
4dc549e5
JO
56 NO_LIBDW_DWARF_UNWIND := 1
57endif
58
1448fef4
JP
59ifeq ($(LIBUNWIND_LIBS),)
60 NO_LIBUNWIND := 1
61else
62 #
63 # For linking with debug library, run like:
64 #
65 # make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
66 #
67 ifdef LIBUNWIND_DIR
68 LIBUNWIND_CFLAGS = -I$(LIBUNWIND_DIR)/include
69 LIBUNWIND_LDFLAGS = -L$(LIBUNWIND_DIR)/lib
70 endif
71 LIBUNWIND_LDFLAGS += $(LIBUNWIND_LIBS)
72
73 # Set per-feature check compilation flags
74 FEATURE_CHECK_CFLAGS-libunwind = $(LIBUNWIND_CFLAGS)
75 FEATURE_CHECK_LDFLAGS-libunwind = $(LIBUNWIND_LDFLAGS)
76 FEATURE_CHECK_CFLAGS-libunwind-debug-frame = $(LIBUNWIND_CFLAGS)
77 FEATURE_CHECK_LDFLAGS-libunwind-debug-frame = $(LIBUNWIND_LDFLAGS)
1448fef4
JP
78endif
79
8bd407b9 80ifeq ($(NO_PERF_REGS),0)
89fe808a 81 CFLAGS += -DHAVE_PERF_REGS_SUPPORT
8bd407b9 82endif
a32f4936 83
45757895
JO
84ifndef NO_LIBELF
85 # for linking with debug library, run like:
86 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
87 ifdef LIBDW_DIR
88 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
89 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
45757895 90 endif
2c529e4e
RR
91 FEATURE_CHECK_CFLAGS-libdw-dwarf-unwind := $(LIBDW_CFLAGS)
92 FEATURE_CHECK_LDFLAGS-libdw-dwarf-unwind := $(LIBDW_LDFLAGS) -ldw
45757895
JO
93endif
94
7c53746e
JO
95# include ARCH specific config
96-include $(src-perf)/arch/$(ARCH)/Makefile
97
7c53746e 98include $(src-perf)/config/utilities.mak
a32f4936
JO
99
100ifeq ($(call get-executable,$(FLEX)),)
8e1b3f68 101 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
a32f4936
JO
102endif
103
104ifeq ($(call get-executable,$(BISON)),)
8e1b3f68 105 dummy := $(error Error: $(BISON) is missing on this system, please install it)
a32f4936 106endif
362493f0
JO
107
108# Treat warnings as errors unless directed not to
109ifneq ($(WERROR),0)
8e1b3f68 110 CFLAGS += -Werror
362493f0
JO
111endif
112
74af377b
AH
113ifndef DEBUG
114 DEBUG := 0
115endif
116
fcf92585 117ifeq ($(DEBUG),0)
8e1b3f68 118 CFLAGS += -O6
362493f0
JO
119endif
120
121ifdef PARSER_DEBUG
8e1b3f68
JO
122 PARSER_DEBUG_BISON := -t
123 PARSER_DEBUG_FLEX := -d
124 CFLAGS += -DPARSER_DEBUG
362493f0
JO
125endif
126
56c7d79e 127ifndef NO_LIBPYTHON
d6a947fb
TI
128 # Try different combinations to accommodate systems that only have
129 # python[2][-config] in weird combinations but always preferring
130 # python2 and python2-config as per pep-0394. If we catch a
131 # python[-config] in version 3, the version check will kill it.
132 PYTHON2 := $(if $(call get-executable,python2),python2,python)
133 override PYTHON := $(call get-executable-or-default,PYTHON,$(PYTHON2))
134 PYTHON2_CONFIG := \
135 $(if $(call get-executable,$(PYTHON)-config),$(PYTHON)-config,python-config)
56c7d79e 136 override PYTHON_CONFIG := \
d6a947fb 137 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON2_CONFIG))
56c7d79e
NK
138
139 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
140
141 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
142 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
143
144 FEATURE_CHECK_CFLAGS-libpython := $(PYTHON_EMBED_CCOPTS)
145 FEATURE_CHECK_LDFLAGS-libpython := $(PYTHON_EMBED_LDOPTS)
146 FEATURE_CHECK_CFLAGS-libpython-version := $(PYTHON_EMBED_CCOPTS)
147 FEATURE_CHECK_LDFLAGS-libpython-version := $(PYTHON_EMBED_LDOPTS)
148endif
149
2fe73746
JO
150CFLAGS += -fno-omit-frame-pointer
151CFLAGS += -ggdb3
152CFLAGS += -funwind-tables
153CFLAGS += -Wall
154CFLAGS += -Wextra
155CFLAGS += -std=gnu99
9c12cf95 156
6392b4eb
MK
157# Enforce a non-executable stack, as we may regress (again) in the future by
158# adding assembler files missing the .GNU-stack linker note.
159LDFLAGS += -Wl,-z,noexecstack
160
5e2d4d0e 161EXTLIBS = -lpthread -lrt -lm -ldl
362493f0 162
1c2d1d8c
IM
163ifneq ($(OUTPUT),)
164 OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
165 $(shell mkdir -p $(OUTPUT_FEATURES))
166endif
167
baa9c30e 168feature_check = $(eval $(feature_check_code))
b6aa9979 169define feature_check_code
56560ec6 170 feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS) $(FEATURE_CHECK_CFLAGS-$(1))" LDFLAGS="$(LDFLAGS) $(FEATURE_CHECK_LDFLAGS-$(1))" -C config/feature-checks test-$1.bin >/dev/null 2>/dev/null && echo 1 || echo 0)
baa9c30e
IM
171endef
172
173feature_set = $(eval $(feature_set_code))
174define feature_set_code
175 feature-$(1) := 1
b6aa9979
IM
176endef
177
178#
179# Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
180#
b6aa9979 181
f1138ec6
IM
182#
183# Note that this is not a complete list of all feature tests, just
184# those that are typically built on a fully configured system.
185#
186# [ Feature tests not mentioned here have to be built explicitly in
187# the rule that uses them - an example for that is the 'bionic'
188# feature check. ]
189#
190CORE_FEATURE_TESTS = \
191 backtrace \
192 dwarf \
1ea6f99e 193 fortify-source \
f6d31369 194 sync-compare-and-swap \
e12762cf 195 glibc \
7ef9e055 196 gtk2 \
c7a79e96 197 gtk2-infobar \
f1138ec6
IM
198 libaudit \
199 libbfd \
200 libelf \
201 libelf-getphdrnum \
202 libelf-mmap \
203 libnuma \
7181a671 204 libperl \
9734163b 205 libpython \
95d061c8 206 libpython-version \
f1138ec6
IM
207 libslang \
208 libunwind \
459a3df7 209 pthread-attr-setaffinity-np \
bb4c5500 210 stackprotector-all \
0a4f2b6a 211 timerfd \
e92ce12e
NK
212 libdw-dwarf-unwind \
213 zlib
b6aa9979 214
0695e57b
JO
215LIB_FEATURE_TESTS = \
216 dwarf \
217 glibc \
218 gtk2 \
219 libaudit \
220 libbfd \
221 libelf \
222 libnuma \
223 libperl \
224 libpython \
225 libslang \
0a4f2b6a 226 libunwind \
e92ce12e
NK
227 libdw-dwarf-unwind \
228 zlib
0695e57b
JO
229
230VF_FEATURE_TESTS = \
231 backtrace \
232 fortify-source \
f6d31369 233 sync-compare-and-swap \
0695e57b
JO
234 gtk2-infobar \
235 libelf-getphdrnum \
236 libelf-mmap \
237 libpython-version \
459a3df7 238 pthread-attr-setaffinity-np \
0695e57b
JO
239 stackprotector-all \
240 timerfd \
241 libunwind-debug-frame \
2cf90407
JO
242 bionic \
243 liberty \
244 liberty-z \
e477f3f0
AH
245 cplus-demangle \
246 compile-32 \
247 compile-x32
0695e57b 248
c4eb6c0e
JO
249# Set FEATURE_CHECK_(C|LD)FLAGS-all for all CORE_FEATURE_TESTS features.
250# If in the future we need per-feature checks/flags for features not
251# mentioned in this list we need to refactor this ;-).
252set_test_all_flags = $(eval $(set_test_all_flags_code))
253define set_test_all_flags_code
254 FEATURE_CHECK_CFLAGS-all += $(FEATURE_CHECK_CFLAGS-$(1))
255 FEATURE_CHECK_LDFLAGS-all += $(FEATURE_CHECK_LDFLAGS-$(1))
256endef
257
258$(foreach feat,$(CORE_FEATURE_TESTS),$(call set_test_all_flags,$(feat)))
259
baa9c30e
IM
260#
261# Special fast-path for the 'all features are available' case:
262#
b3b64a12
IM
263$(call feature_check,all,$(MSG))
264
265#
266# Just in case the build freshly failed, make sure we print the
267# feature matrix:
268#
baa9c30e 269ifeq ($(feature-all), 1)
f1138ec6
IM
270 #
271 # test-all.c passed - just set all the core feature flags to 1:
272 #
273 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
baa9c30e 274else
56560ec6 275 $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(addsuffix .bin,$(CORE_FEATURE_TESTS)) >/dev/null 2>&1)
f1138ec6 276 $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
baa9c30e
IM
277endif
278
90ac5422 279ifeq ($(feature-stackprotector-all), 1)
8e1b3f68 280 CFLAGS += -fstack-protector-all
362493f0
JO
281endif
282
fcf92585 283ifeq ($(DEBUG),0)
1ea6f99e 284 ifeq ($(feature-fortify-source), 1)
8e1b3f68
JO
285 CFLAGS += -D_FORTIFY_SOURCE=2
286 endif
362493f0
JO
287endif
288
2fe73746
JO
289CFLAGS += -I$(src-perf)/util/include
290CFLAGS += -I$(src-perf)/arch/$(ARCH)/include
8a625c1f 291CFLAGS += -I$(srctree)/tools/include/
2fe73746
JO
292CFLAGS += -I$(srctree)/arch/$(ARCH)/include/uapi
293CFLAGS += -I$(srctree)/arch/$(ARCH)/include
294CFLAGS += -I$(srctree)/include/uapi
295CFLAGS += -I$(srctree)/include
7c53746e
JO
296
297# $(obj-perf) for generated common-cmds.h
298# $(obj-perf)/util for generated bison/flex headers
299ifneq ($(OUTPUT),)
2fe73746
JO
300CFLAGS += -I$(obj-perf)/util
301CFLAGS += -I$(obj-perf)
7c53746e
JO
302endif
303
2fe73746
JO
304CFLAGS += -I$(src-perf)/util
305CFLAGS += -I$(src-perf)
4e319027 306CFLAGS += -I$(LIB_INCLUDE)
7c53746e 307
2fe73746 308CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
362493f0 309
f6d31369
AH
310ifeq ($(feature-sync-compare-and-swap), 1)
311 CFLAGS += -DHAVE_SYNC_COMPARE_AND_SWAP_SUPPORT
312endif
313
459a3df7
VG
314ifeq ($(feature-pthread-attr-setaffinity-np), 1)
315 CFLAGS += -DHAVE_PTHREAD_ATTR_SETAFFINITY_NP
316endif
317
4e22db46 318ifndef NO_BIONIC
5febff00 319 $(call feature_check,bionic)
78e9d655
IM
320 ifeq ($(feature-bionic), 1)
321 BIONIC := 1
322 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
323 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
324 endif
362493f0 325endif
cf4cca10
JO
326
327ifdef NO_LIBELF
8e1b3f68
JO
328 NO_DWARF := 1
329 NO_DEMANGLE := 1
330 NO_LIBUNWIND := 1
5ea84154 331 NO_LIBDW_DWARF_UNWIND := 1
cf4cca10 332else
8f7f8005 333 ifeq ($(feature-libelf), 0)
e12762cf 334 ifeq ($(feature-glibc), 1)
50eed7a7
IM
335 LIBC_SUPPORT := 1
336 endif
337 ifeq ($(BIONIC),1)
338 LIBC_SUPPORT := 1
339 endif
340 ifeq ($(LIBC_SUPPORT),1)
341 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
342
343 NO_LIBELF := 1
344 NO_DWARF := 1
345 NO_DEMANGLE := 1
94589557
ACM
346 NO_LIBUNWIND := 1
347 NO_LIBDW_DWARF_UNWIND := 1
50eed7a7 348 else
f9ca2d89
ACM
349 ifneq ($(filter s% -static%,$(LDFLAGS),),)
350 msg := $(error No static glibc found, please install glibc-static);
351 else
352 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]);
353 endif
50eed7a7 354 endif
8e1b3f68 355 else
0a4f2b6a
JO
356 ifndef NO_LIBDW_DWARF_UNWIND
357 ifneq ($(feature-libdw-dwarf-unwind),1)
358 NO_LIBDW_DWARF_UNWIND := 1
359 msg := $(warning No libdw DWARF unwind found, Please install elfutils-devel/libdw-dev >= 0.158 and/or set LIBDW_DIR);
360 endif
361 endif
8295d4e2 362 ifneq ($(feature-dwarf), 1)
50eed7a7
IM
363 msg := $(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);
364 NO_DWARF := 1
365 endif # Dwarf support
0648f839 366 endif # libelf support
cf4cca10
JO
367endif # NO_LIBELF
368
369ifndef NO_LIBELF
fb3d333b 370 CFLAGS += -DHAVE_LIBELF_SUPPORT
5e2d4d0e 371 EXTLIBS += -lelf
779724fd 372
8869b17e 373 ifeq ($(feature-libelf-mmap), 1)
fb3d333b
IM
374 CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
375 endif
779724fd 376
b7bcef6f 377 ifeq ($(feature-libelf-getphdrnum), 1)
fb3d333b
IM
378 CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
379 endif
380
381 # include ARCH specific config
382 -include $(src-perf)/arch/$(ARCH)/Makefile
779724fd 383
fb3d333b
IM
384 ifndef NO_DWARF
385 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
386 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
387 NO_DWARF := 1
388 else
389 CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
390 LDFLAGS += $(LIBDW_LDFLAGS)
5e2d4d0e 391 EXTLIBS += -ldw
fb3d333b
IM
392 endif # PERF_HAVE_DWARF_REGS
393 endif # NO_DWARF
cf4cca10 394endif # NO_LIBELF
0e433feb 395
65ccb4fa
AB
396ifeq ($(ARCH),powerpc)
397 ifndef NO_DWARF
398 CFLAGS += -DHAVE_SKIP_CALLCHAIN_IDX
399 endif
400endif
401
0e433feb 402ifndef NO_LIBUNWIND
058f952d 403 ifneq ($(feature-libunwind), 1)
0a4f2b6a 404 msg := $(warning No libunwind found. Please install libunwind-dev[el] >= 1.1 and/or set LIBUNWIND_DIR);
308e1e70 405 NO_LIBUNWIND := 1
0a4f2b6a
JO
406 endif
407endif
408
409dwarf-post-unwind := 1
410dwarf-post-unwind-text := BUG
411
412# setup DWARF post unwinder
413ifdef NO_LIBUNWIND
414 ifdef NO_LIBDW_DWARF_UNWIND
415 msg := $(warning Disabling post unwind, no support found.);
416 dwarf-post-unwind := 0
f47671e2 417 else
0a4f2b6a
JO
418 dwarf-post-unwind-text := libdw
419 endif
420else
421 dwarf-post-unwind-text := libunwind
422 # Enable libunwind support by default.
423 ifndef NO_LIBDW_DWARF_UNWIND
424 NO_LIBDW_DWARF_UNWIND := 1
425 endif
426endif
427
428ifeq ($(dwarf-post-unwind),1)
429 CFLAGS += -DHAVE_DWARF_UNWIND_SUPPORT
f39e042a 430 $(call detected,CONFIG_DWARF_UNWIND)
0a4f2b6a
JO
431else
432 NO_DWARF_UNWIND := 1
433endif
434
435ifndef NO_LIBUNWIND
8ab596af 436 ifeq ($(ARCH),$(filter $(ARCH),arm arm64))
0a4f2b6a
JO
437 $(call feature_check,libunwind-debug-frame)
438 ifneq ($(feature-libunwind-debug-frame), 1)
439 msg := $(warning No debug_frame support found in libunwind);
f47671e2
LT
440 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
441 endif
0a4f2b6a
JO
442 else
443 # non-ARM has no dwarf_find_debug_frame() function:
444 CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
445 endif
446 CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
447 EXTLIBS += $(LIBUNWIND_LIBS)
448 CFLAGS += $(LIBUNWIND_CFLAGS)
449 LDFLAGS += $(LIBUNWIND_LDFLAGS)
058f952d 450endif
a8279525
JO
451
452ifndef NO_LIBAUDIT
d795a658 453 ifneq ($(feature-libaudit), 1)
8e1b3f68
JO
454 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
455 NO_LIBAUDIT := 1
456 else
89fe808a 457 CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
8e1b3f68 458 EXTLIBS += -laudit
285ab8bf 459 $(call detected,CONFIG_AUDIT)
8e1b3f68 460 endif
a8279525 461endif
4a8f888a
JO
462
463ifdef NO_NEWT
8e1b3f68 464 NO_SLANG=1
4a8f888a
JO
465endif
466
467ifndef NO_SLANG
b9498b50 468 ifneq ($(feature-libslang), 1)
8e1b3f68
JO
469 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
470 NO_SLANG := 1
471 else
472 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
473 CFLAGS += -I/usr/include/slang
89fe808a 474 CFLAGS += -DHAVE_SLANG_SUPPORT
8e1b3f68
JO
475 EXTLIBS += -lslang
476 endif
4a8f888a 477endif
58cabf6a
JO
478
479ifndef NO_GTK2
a8a5cd8b 480 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null)
7ef9e055 481 ifneq ($(feature-gtk2), 1)
8e1b3f68
JO
482 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
483 NO_GTK2 := 1
484 else
c7a79e96 485 ifeq ($(feature-gtk2-infobar), 1)
fc67297b 486 GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
8e1b3f68 487 endif
89fe808a 488 CFLAGS += -DHAVE_GTK2_SUPPORT
a8a5cd8b
MR
489 GTK_CFLAGS += $(shell $(PKG_CONFIG) --cflags gtk+-2.0 2>/dev/null)
490 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-2.0 2>/dev/null)
e2137086 491 EXTLIBS += -ldl
8e1b3f68 492 endif
58cabf6a 493endif
3082cb33
JO
494
495grep-libs = $(filter -l%,$(1))
496strip-libs = $(filter-out -l%,$(1))
497
498ifdef NO_LIBPERL
8e1b3f68 499 CFLAGS += -DNO_LIBPERL
3082cb33 500else
8e1b3f68
JO
501 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
502 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
503 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
504 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
505 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
506
7181a671 507 ifneq ($(feature-libperl), 1)
8e1b3f68
JO
508 CFLAGS += -DNO_LIBPERL
509 NO_LIBPERL := 1
6a2f2543 510 msg := $(warning Missing perl devel files. Disabling perl scripting support, consider installing perl-ExtUtils-Embed);
8e1b3f68
JO
511 else
512 LDFLAGS += $(PERL_EMBED_LDFLAGS)
513 EXTLIBS += $(PERL_EMBED_LIBADD)
514 endif
3082cb33 515endif
6e533cf1 516
87419c9a
DA
517ifeq ($(feature-timerfd), 1)
518 CFLAGS += -DHAVE_TIMERFD_SUPPORT
519else
520 msg := $(warning No timerfd support. Disables 'perf kvm stat live');
521endif
522
6e533cf1
JO
523disable-python = $(eval $(disable-python_code))
524define disable-python_code
9c12cf95 525 CFLAGS += -DNO_LIBPYTHON
6e533cf1
JO
526 $(if $(1),$(warning No $(1) was found))
527 $(warning Python support will not be built)
528 NO_LIBPYTHON := 1
529endef
530
56c7d79e
NK
531ifdef NO_LIBPYTHON
532 $(call disable-python)
6e533cf1
JO
533else
534
56c7d79e
NK
535 ifndef PYTHON
536 $(call disable-python,python interpreter)
6e533cf1 537 else
56c7d79e 538 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
6e533cf1
JO
539
540 ifndef PYTHON_CONFIG
541 $(call disable-python,python-config tool)
542 else
543
544 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
545
546 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
547 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
548 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
549 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
550 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
551
9734163b 552 ifneq ($(feature-libpython), 1)
6e533cf1
JO
553 $(call disable-python,Python.h (for Python 2.x))
554 else
555
95d061c8 556 ifneq ($(feature-libpython-version), 1)
6e533cf1
JO
557 $(warning Python 3 is not yet supported; please set)
558 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
559 $(warning If you also have Python 2 installed, then)
560 $(warning try something like:)
561 $(warning $(and ,))
562 $(warning $(and ,) make PYTHON=python2)
563 $(warning $(and ,))
564 $(warning Otherwise, disable Python support entirely:)
565 $(warning $(and ,))
566 $(warning $(and ,) make NO_LIBPYTHON=1)
567 $(warning $(and ,))
568 $(error $(and ,))
569 else
1e9f7aad 570 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
6e533cf1 571 EXTLIBS += $(PYTHON_EMBED_LIBADD)
7c53746e 572 LANG_BINDINGS += $(obj-perf)python/perf.so
6e533cf1
JO
573 endif
574 endif
575 endif
576 endif
577endif
c3cf8368 578
3e6a147d 579ifeq ($(feature-libbfd), 1)
2cf90407
JO
580 EXTLIBS += -lbfd
581
582 # call all detections now so we get correct
583 # status in VF output
584 $(call feature_check,liberty)
585 $(call feature_check,liberty-z)
586 $(call feature_check,cplus-demangle)
587
588 ifeq ($(feature-liberty), 1)
589 EXTLIBS += -liberty
590 else
591 ifeq ($(feature-liberty-z), 1)
592 EXTLIBS += -liberty -lz
593 endif
594 endif
3e6a147d
JO
595endif
596
c3cf8368 597ifdef NO_DEMANGLE
8e1b3f68 598 CFLAGS += -DNO_DEMANGLE
c3cf8368 599else
89fe808a 600 ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
8e1b3f68 601 EXTLIBS += -liberty
89fe808a 602 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
8e1b3f68 603 else
3e6a147d 604 ifneq ($(feature-libbfd), 1)
2cf90407
JO
605 ifneq ($(feature-liberty), 1)
606 ifneq ($(feature-liberty-z), 1)
607 # we dont have neither HAVE_CPLUS_DEMANGLE_SUPPORT
608 # or any of 'bfd iberty z' trinity
1c47661a 609 ifeq ($(feature-cplus-demangle), 1)
8e1b3f68 610 EXTLIBS += -liberty
89fe808a 611 CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
8e1b3f68
JO
612 else
613 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
614 CFLAGS += -DNO_DEMANGLE
615 endif
616 endif
617 endif
618 endif
619 endif
c3cf8368 620endif
a1c7c9e7 621
3e6a147d
JO
622ifneq ($(filter -lbfd,$(EXTLIBS)),)
623 CFLAGS += -DHAVE_LIBBFD_SUPPORT
624endif
625
e92ce12e
NK
626ifndef NO_ZLIB
627 ifeq ($(feature-zlib), 1)
628 CFLAGS += -DHAVE_ZLIB_SUPPORT
629 EXTLIBS += -lz
630 else
631 NO_ZLIB := 1
632 endif
633endif
634
a1c7c9e7 635ifndef NO_BACKTRACE
4cc9117a 636 ifeq ($(feature-backtrace), 1)
89fe808a 637 CFLAGS += -DHAVE_BACKTRACE_SUPPORT
8e1b3f68 638 endif
a1c7c9e7 639endif
58a0abd7
JO
640
641ifndef NO_LIBNUMA
3ae069cf 642 ifeq ($(feature-libnuma), 0)
6305edfc 643 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numactl-devel/libnuma-devel/libnuma-dev);
8e1b3f68
JO
644 NO_LIBNUMA := 1
645 else
89fe808a 646 CFLAGS += -DHAVE_LIBNUMA_SUPPORT
8e1b3f68 647 EXTLIBS += -lnuma
72965b87 648 $(call detected,CONFIG_NUMA)
8e1b3f68 649 endif
58a0abd7 650endif
cd1c39f2 651
da50ad69
AY
652ifdef HAVE_KVM_STAT_SUPPORT
653 CFLAGS += -DHAVE_KVM_STAT_SUPPORT
654endif
655
e477f3f0
AH
656ifeq (${IS_64_BIT}, 1)
657 ifndef NO_PERF_READ_VDSO32
658 $(call feature_check,compile-32)
46b1fa85
AH
659 ifeq ($(feature-compile-32), 1)
660 CFLAGS += -DHAVE_PERF_READ_VDSO32
661 else
e477f3f0
AH
662 NO_PERF_READ_VDSO32 := 1
663 endif
664 endif
665 ifneq (${IS_X86_64}, 1)
666 NO_PERF_READ_VDSOX32 := 1
667 endif
668 ifndef NO_PERF_READ_VDSOX32
669 $(call feature_check,compile-x32)
46b1fa85
AH
670 ifeq ($(feature-compile-x32), 1)
671 CFLAGS += -DHAVE_PERF_READ_VDSOX32
672 else
e477f3f0
AH
673 NO_PERF_READ_VDSOX32 := 1
674 endif
675 endif
676else
677 NO_PERF_READ_VDSO32 := 1
678 NO_PERF_READ_VDSOX32 := 1
679endif
680
cd1c39f2
JO
681# Among the variables below, these:
682# perfexecdir
683# template_dir
684# mandir
685# infodir
686# htmldir
687# ETC_PERFCONFIG (but not sysconfdir)
688# can be specified as a relative path some/where/else;
689# this is interpreted as relative to $(prefix) and "perf" at
690# runtime figures out where they are based on the path to the executable.
691# This can help installing the suite in a relocatable way.
692
693# Make the path relative to DESTDIR, not to prefix
694ifndef DESTDIR
fc9cabea 695prefix ?= $(HOME)
cd1c39f2
JO
696endif
697bindir_relative = bin
698bindir = $(prefix)/$(bindir_relative)
699mandir = share/man
700infodir = share/info
701perfexecdir = libexec/perf-core
702sharedir = $(prefix)/share
703template_dir = share/perf-core/templates
704htmldir = share/doc/perf-doc
705ifeq ($(prefix),/usr)
706sysconfdir = /etc
707ETC_PERFCONFIG = $(sysconfdir)/perfconfig
708else
709sysconfdir = $(prefix)/etc
710ETC_PERFCONFIG = etc/perfconfig
711endif
6997af72 712ifndef lib
fc67297b
NK
713ifeq ($(IS_X86_64),1)
714lib = lib64
715else
cd1c39f2 716lib = lib
fc67297b 717endif
6997af72 718endif # lib
fc67297b 719libdir = $(prefix)/$(lib)
cd1c39f2
JO
720
721# Shell quote (do not use $(call) to accommodate ancient setups);
722ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
723DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
724bindir_SQ = $(subst ','\'',$(bindir))
725mandir_SQ = $(subst ','\'',$(mandir))
726infodir_SQ = $(subst ','\'',$(infodir))
727perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
728template_dir_SQ = $(subst ','\'',$(template_dir))
729htmldir_SQ = $(subst ','\'',$(htmldir))
730prefix_SQ = $(subst ','\'',$(prefix))
731sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
fc67297b 732libdir_SQ = $(subst ','\'',$(libdir))
cd1c39f2
JO
733
734ifneq ($(filter /%,$(firstword $(perfexecdir))),)
735perfexec_instdir = $(perfexecdir)
736else
737perfexec_instdir = $(prefix)/$(perfexecdir)
738endif
739perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
3d7c0144
JO
740
741# If we install to $(HOME) we keep the traceevent default:
742# $(HOME)/.traceevent/plugins
743# Otherwise we install plugins into the global $(libdir).
744ifdef DESTDIR
745plugindir=$(libdir)/traceevent/plugins
b935a58d 746plugindir_SQ= $(subst ','\'',$(plugindir))
3d7c0144 747endif
0695e57b
JO
748
749#
750# Print the result of the feature test:
751#
8d79076a 752feature_print_status = $(eval $(feature_print_status_code)) $(info $(MSG))
0695e57b 753
8d79076a 754define feature_print_status_code
0695e57b
JO
755 ifeq ($(feature-$(1)), 1)
756 MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
757 else
758 MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
759 endif
760endef
761
8d79076a
JO
762feature_print_var = $(eval $(feature_print_var_code)) $(info $(MSG))
763define feature_print_var_code
764 MSG = $(shell printf '...%30s: %s' $(1) $($(1)))
765endef
766
767feature_print_text = $(eval $(feature_print_text_code)) $(info $(MSG))
768define feature_print_text_code
769 MSG = $(shell printf '...%30s: %s' $(1) $(2))
770endef
771
0695e57b
JO
772PERF_FEATURES := $(foreach feat,$(LIB_FEATURE_TESTS),feature-$(feat)($(feature-$(feat))))
773PERF_FEATURES_FILE := $(shell touch $(OUTPUT)PERF-FEATURES; cat $(OUTPUT)PERF-FEATURES)
774
0a4f2b6a
JO
775ifeq ($(dwarf-post-unwind),1)
776 PERF_FEATURES += dwarf-post-unwind($(dwarf-post-unwind-text))
777endif
778
0695e57b
JO
779# The $(display_lib) controls the default detection message
780# output. It's set if:
781# - detected features differes from stored features from
782# last build (in PERF-FEATURES file)
783# - one of the $(LIB_FEATURE_TESTS) is not detected
784# - VF is enabled
785
786ifneq ("$(PERF_FEATURES)","$(PERF_FEATURES_FILE)")
787 $(shell echo "$(PERF_FEATURES)" > $(OUTPUT)PERF-FEATURES)
788 display_lib := 1
789endif
790
791feature_check = $(eval $(feature_check_code))
792define feature_check_code
793 ifneq ($(feature-$(1)), 1)
794 display_lib := 1
795 endif
796endef
797
798$(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_check,$(feat)))
799
800ifeq ($(VF),1)
801 display_lib := 1
802 display_vf := 1
803endif
804
805ifeq ($(display_lib),1)
806 $(info )
807 $(info Auto-detecting system features:)
8d79076a 808 $(foreach feat,$(LIB_FEATURE_TESTS),$(call feature_print_status,$(feat),))
0a4f2b6a
JO
809
810 ifeq ($(dwarf-post-unwind),1)
811 $(call feature_print_text,"DWARF post unwind library", $(dwarf-post-unwind-text))
812 endif
0695e57b
JO
813endif
814
815ifeq ($(display_vf),1)
8d79076a
JO
816 $(foreach feat,$(VF_FEATURE_TESTS),$(call feature_print_status,$(feat),))
817 $(info )
818 $(call feature_print_var,prefix)
819 $(call feature_print_var,bindir)
820 $(call feature_print_var,libdir)
821 $(call feature_print_var,sysconfdir)
0a4f2b6a
JO
822 $(call feature_print_var,LIBUNWIND_DIR)
823 $(call feature_print_var,LIBDW_DIR)
0695e57b
JO
824endif
825
826ifeq ($(display_lib),1)
827 $(info )
828endif
f39e042a
JO
829
830$(call detected_var,bindir_SQ)
831$(call detected_var,PYTHON_WORD)
832ifneq ($(OUTPUT),)
833$(call detected_var,OUTPUT)
834endif
285ab8bf
JO
835$(call detected_var,htmldir_SQ)
836$(call detected_var,infodir_SQ)
837$(call detected_var,mandir_SQ)