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