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