90
96
EXTLIBS = -lelf -lpthread -lrt -lm -ldl
92
ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y)
99
OUTPUT_FEATURES = $(OUTPUT)config/feature-checks/
100
$(shell mkdir -p $(OUTPUT_FEATURES))
103
feature_check = $(eval $(feature_check_code))
104
define feature_check_code
105
feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
108
feature_set = $(eval $(feature_set_code))
109
define feature_set_code
114
# Build the feature check binaries in parallel, ignore errors, ignore return value and suppress output:
118
# Note that this is not a complete list of all feature tests, just
119
# those that are typically built on a fully configured system.
121
# [ Feature tests not mentioned here have to be built explicitly in
122
# the rule that uses them - an example for that is the 'bionic'
125
CORE_FEATURE_TESTS = \
149
# So here we detect whether test-all was rebuilt, to be able
150
# to skip the print-out of the long features list if the file
151
# existed before and after it was built:
153
ifeq ($(wildcard $(OUTPUT)config/feature-checks/test-all),)
160
# Special fast-path for the 'all features are available' case:
162
$(call feature_check,all,$(MSG))
165
# Just in case the build freshly failed, make sure we print the
168
ifeq ($(feature-all), 0)
172
ifeq ($(test-all-failed),1)
174
$(info Auto-detecting system features:)
177
ifeq ($(feature-all), 1)
179
# test-all.c passed - just set all the core feature flags to 1:
181
$(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
183
$(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(EXTRA_CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
184
$(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
188
# Print the result of the feature test:
190
feature_print = $(eval $(feature_print_code)) $(info $(MSG))
192
define feature_print_code
193
ifeq ($(feature-$(1)), 1)
194
MSG = $(shell printf '...%30s: [ \033[32mon\033[m ]' $(1))
196
MSG = $(shell printf '...%30s: [ \033[31mOFF\033[m ]' $(1))
201
# Only print out our features if we rebuilt the testcases or if a test failed:
203
ifeq ($(test-all-failed), 1)
204
$(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_print,$(feat)))
208
ifeq ($(feature-stackprotector-all), 1)
93
209
CFLAGS += -fstack-protector-all
96
ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wstack-protector,-Wstack-protector),y)
212
ifeq ($(feature-stackprotector), 1)
97
213
CFLAGS += -Wstack-protector
100
ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-Wvolatile-register-var),y)
101
CFLAGS += -Wvolatile-register-var
105
ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y)
217
ifeq ($(feature-fortify-source), 1)
106
218
CFLAGS += -D_FORTIFY_SOURCE=2
128
240
CFLAGS += -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
131
ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
133
EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
134
EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
243
$(call feature_check,bionic)
244
ifeq ($(feature-bionic), 1)
246
EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
247
EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
141
254
NO_LIBUNWIND := 1
143
FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
144
ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF),libelf),y)
145
FLAGS_GLIBC=$(CFLAGS) $(LDFLAGS)
146
ifeq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC),glibc),y)
152
ifeq ($(LIBC_SUPPORT),1)
153
msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
159
msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
162
# for linking with debug library, run like:
163
# make DEBUG=1 LIBDW_DIR=/opt/libdw/
165
LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
166
LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
169
FLAGS_DWARF=$(CFLAGS) $(LIBDW_CFLAGS) -ldw -lz -lelf $(LIBDW_LDFLAGS) $(LDFLAGS) $(EXTLIBS)
170
ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF),libdw),y)
171
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);
173
endif # Dwarf support
174
endif # SOURCE_LIBELF
178
CFLAGS += -DLIBELF_SUPPORT
179
FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
180
ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
181
CFLAGS += -DLIBELF_MMAP
183
ifeq ($(call try-cc,$(SOURCE_ELF_GETPHDRNUM),$(FLAGS_LIBELF),-DHAVE_ELF_GETPHDRNUM),y)
184
CFLAGS += -DHAVE_ELF_GETPHDRNUM
187
# include ARCH specific config
188
-include $(src-perf)/arch/$(ARCH)/Makefile
191
ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
192
msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
195
CFLAGS += -DDWARF_SUPPORT $(LIBDW_CFLAGS)
196
LDFLAGS += $(LIBDW_LDFLAGS)
197
EXTLIBS += -lelf -ldw
198
endif # PERF_HAVE_DWARF_REGS
204
CFLAGS += -DLIBELF_SUPPORT
205
FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
206
ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
207
CFLAGS += -DLIBELF_MMAP
211
# There's only x86 (both 32 and 64) support for CFI unwind so far
217
# for linking with debug library, run like:
218
# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
220
LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
221
LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
224
FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(CFLAGS) $(LIBUNWIND_LDFLAGS) $(LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
225
ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND),libunwind),y)
226
msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
228
endif # Libunwind support
232
CFLAGS += -DLIBUNWIND_SUPPORT
256
ifeq ($(feature-libelf), 0)
257
ifeq ($(feature-glibc), 1)
263
ifeq ($(LIBC_SUPPORT),1)
264
msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
270
msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
273
# for linking with debug library, run like:
274
# make DEBUG=1 LIBDW_DIR=/opt/libdw/
276
LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
277
LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
280
ifneq ($(feature-dwarf), 1)
281
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);
283
endif # Dwarf support
284
endif # libelf support
288
CFLAGS += -DHAVE_LIBELF_SUPPORT
290
ifeq ($(feature-libelf-mmap), 1)
291
CFLAGS += -DHAVE_LIBELF_MMAP_SUPPORT
294
ifeq ($(feature-libelf-getphdrnum), 1)
295
CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
298
# include ARCH specific config
299
-include $(src-perf)/arch/$(ARCH)/Makefile
302
ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
303
msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
306
CFLAGS += -DHAVE_DWARF_SUPPORT $(LIBDW_CFLAGS)
307
LDFLAGS += $(LIBDW_LDFLAGS)
308
EXTLIBS += -lelf -ldw
309
endif # PERF_HAVE_DWARF_REGS
313
ifeq ($(LIBUNWIND_LIBS),)
319
# For linking with debug library, run like:
321
# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
324
LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
325
LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
328
ifneq ($(feature-libunwind), 1)
329
msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 1.1);
333
$(call feature_check,libunwind-debug-frame)
334
ifneq ($(feature-libunwind-debug-frame), 1)
335
msg := $(warning No debug_frame support found in libunwind);
336
CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
339
# non-ARM has no dwarf_find_debug_frame() function:
340
CFLAGS += -DNO_LIBUNWIND_DEBUG_FRAME
346
CFLAGS += -DHAVE_LIBUNWIND_SUPPORT
233
347
EXTLIBS += $(LIBUNWIND_LIBS)
234
348
CFLAGS += $(LIBUNWIND_CFLAGS)
235
349
LDFLAGS += $(LIBUNWIND_LDFLAGS)
238
352
ifndef NO_LIBAUDIT
239
FLAGS_LIBAUDIT = $(CFLAGS) $(LDFLAGS) -laudit
240
ifneq ($(call try-cc,$(SOURCE_LIBAUDIT),$(FLAGS_LIBAUDIT),libaudit),y)
353
ifneq ($(feature-libaudit), 1)
241
354
msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
244
CFLAGS += -DLIBAUDIT_SUPPORT
357
CFLAGS += -DHAVE_LIBAUDIT_SUPPORT
245
358
EXTLIBS += -laudit
254
FLAGS_SLANG=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -I/usr/include/slang -lslang
255
ifneq ($(call try-cc,$(SOURCE_SLANG),$(FLAGS_SLANG),libslang),y)
367
ifneq ($(feature-libslang), 1)
256
368
msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
259
371
# Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
260
372
CFLAGS += -I/usr/include/slang
261
CFLAGS += -DSLANG_SUPPORT
373
CFLAGS += -DHAVE_SLANG_SUPPORT
262
374
EXTLIBS += -lslang
267
379
FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
268
ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2),gtk2),y)
380
ifneq ($(feature-gtk2), 1)
269
381
msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
272
ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2),-DHAVE_GTK_INFO_BAR),y)
273
CFLAGS += -DHAVE_GTK_INFO_BAR
384
ifeq ($(feature-gtk2-infobar), 1)
385
GTK_CFLAGS := -DHAVE_GTK_INFO_BAR_SUPPORT
275
CFLAGS += -DGTK2_SUPPORT
276
CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
277
EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
387
CFLAGS += -DHAVE_GTK2_SUPPORT
388
GTK_CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
389
GTK_LIBS := $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
484
ifeq ($(feature-libbfd), 1)
365
488
ifdef NO_DEMANGLE
366
489
CFLAGS += -DNO_DEMANGLE
368
ifdef HAVE_CPLUS_DEMANGLE
491
ifdef HAVE_CPLUS_DEMANGLE_SUPPORT
369
492
EXTLIBS += -liberty
370
CFLAGS += -DHAVE_CPLUS_DEMANGLE
493
CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
372
FLAGS_BFD=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
373
has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
377
FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
378
has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
379
ifeq ($(has_bfd_iberty),y)
495
ifneq ($(feature-libbfd), 1)
496
$(call feature_check,liberty)
497
ifeq ($(feature-liberty), 1)
380
498
EXTLIBS += -lbfd -liberty
382
FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
383
has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
384
ifeq ($(has_bfd_iberty_z),y)
500
$(call feature_check,liberty-z)
501
ifeq ($(feature-liberty-z), 1)
385
502
EXTLIBS += -lbfd -liberty -lz
387
FLAGS_CPLUS_DEMANGLE=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -liberty
388
has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
389
ifeq ($(has_cplus_demangle),y)
504
$(call feature_check,cplus-demangle)
505
ifeq ($(feature-cplus-demangle), 1)
390
506
EXTLIBS += -liberty
391
CFLAGS += -DHAVE_CPLUS_DEMANGLE
507
CFLAGS += -DHAVE_CPLUS_DEMANGLE_SUPPORT
393
509
msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
394
510
CFLAGS += -DNO_DEMANGLE
403
ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY),y)
404
CFLAGS += -DHAVE_STRLCPY
518
ifneq ($(filter -lbfd,$(EXTLIBS)),)
519
CFLAGS += -DHAVE_LIBBFD_SUPPORT
408
522
ifndef NO_ON_EXIT
409
ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT),y)
410
CFLAGS += -DHAVE_ON_EXIT
523
ifeq ($(feature-on-exit), 1)
524
CFLAGS += -DHAVE_ON_EXIT_SUPPORT
414
528
ifndef NO_BACKTRACE
415
ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DBACKTRACE_SUPPORT),y)
416
CFLAGS += -DBACKTRACE_SUPPORT
529
ifeq ($(feature-backtrace), 1)
530
CFLAGS += -DHAVE_BACKTRACE_SUPPORT
420
534
ifndef NO_LIBNUMA
421
FLAGS_LIBNUMA = $(CFLAGS) $(LDFLAGS) -lnuma
422
ifneq ($(call try-cc,$(SOURCE_LIBNUMA),$(FLAGS_LIBNUMA),libnuma),y)
535
ifeq ($(feature-libnuma), 0)
423
536
msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
426
CFLAGS += -DLIBNUMA_SUPPORT
539
CFLAGS += -DHAVE_LIBNUMA_SUPPORT
427
540
EXTLIBS += -lnuma