1ifeq ("$(origin O)", "command line") 2 OUTPUT := $(O)/ 3endif 4 5# The default target of this Makefile is... 6all: 7 8include config/utilities.mak 9 10ifneq ($(OUTPUT),) 11# check that the output directory actually exists 12OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd) 13$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) 14endif 15 16# Define V to have a more verbose compile. 17# 18# Define PYTHON to point to the python binary if the default 19# `python' is not correct; for example: PYTHON=python2 20# 21# Define PYTHON_CONFIG to point to the python-config binary if 22# the default `$(PYTHON)-config' is not correct. 23# 24# Define ASCIIDOC8 if you want to format documentation with AsciiDoc 8 25# 26# Define DOCBOOK_XSL_172 if you want to format man pages with DocBook XSL v1.72. 27# 28# Define LDFLAGS=-static to build a static binary. 29# 30# Define EXTRA_CFLAGS=-m64 or EXTRA_CFLAGS=-m32 as appropriate for cross-builds. 31# 32# Define NO_DWARF if you do not want debug-info analysis feature at all. 33 34$(OUTPUT)PERF-VERSION-FILE: .FORCE-PERF-VERSION-FILE 35 @$(SHELL_PATH) util/PERF-VERSION-GEN $(OUTPUT) 36-include $(OUTPUT)PERF-VERSION-FILE 37 38uname_M := $(shell uname -m 2>/dev/null || echo not) 39 40ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \ 41 -e s/arm.*/arm/ -e s/sa110/arm/ \ 42 -e s/s390x/s390/ -e s/parisc64/parisc/ \ 43 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \ 44 -e s/sh[234].*/sh/ ) 45 46# Additional ARCH settings for x86 47ifeq ($(ARCH),i386) 48 ARCH := x86 49endif 50ifeq ($(ARCH),x86_64) 51 RAW_ARCH := x86_64 52 ARCH := x86 53 ARCH_CFLAGS := -DARCH_X86_64 54 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S 55endif 56 57# 58# Include saner warnings here, which can catch bugs: 59# 60 61EXTRA_WARNINGS := -Wformat 62EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security 63EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k 64EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow 65EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self 66EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked 67EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls 68EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3 69EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default 70EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum 71EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers 72EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef 73EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings 74EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast 75EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations 76EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes 77EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs 78EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition 79EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes 80EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement 81 82ifeq ("$(origin DEBUG)", "command line") 83 PERF_DEBUG = $(DEBUG) 84endif 85ifndef PERF_DEBUG 86 CFLAGS_OPTIMIZE = -O6 87endif 88 89CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) 90EXTLIBS = -lpthread -lrt -lelf -lm 91ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 92ALL_LDFLAGS = $(LDFLAGS) 93STRIP ?= strip 94 95# Among the variables below, these: 96# perfexecdir 97# template_dir 98# mandir 99# infodir 100# htmldir 101# ETC_PERFCONFIG (but not sysconfdir) 102# can be specified as a relative path some/where/else; 103# this is interpreted as relative to $(prefix) and "perf" at 104# runtime figures out where they are based on the path to the executable. 105# This can help installing the suite in a relocatable way. 106 107# Make the path relative to DESTDIR, not to prefix 108ifndef DESTDIR 109prefix = $(HOME) 110endif 111bindir_relative = bin 112bindir = $(prefix)/$(bindir_relative) 113mandir = share/man 114infodir = share/info 115perfexecdir = libexec/perf-core 116sharedir = $(prefix)/share 117template_dir = share/perf-core/templates 118htmldir = share/doc/perf-doc 119ifeq ($(prefix),/usr) 120sysconfdir = /etc 121ETC_PERFCONFIG = $(sysconfdir)/perfconfig 122else 123sysconfdir = $(prefix)/etc 124ETC_PERFCONFIG = etc/perfconfig 125endif 126lib = lib 127 128export prefix bindir sharedir sysconfdir 129 130CC = $(CROSS_COMPILE)gcc 131AR = $(CROSS_COMPILE)ar 132RM = rm -f 133MKDIR = mkdir 134FIND = find 135INSTALL = install 136 137# sparse is architecture-neutral, which means that we need to tell it 138# explicitly what architecture to check for. Fix this up for yours.. 139SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ 140 141-include feature-tests.mak 142 143ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y) 144 CFLAGS := $(CFLAGS) -fstack-protector-all 145endif 146 147ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wstack-protector),y) 148 CFLAGS := $(CFLAGS) -Wstack-protector 149endif 150 151ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wvolatile-register-var),y) 152 CFLAGS := $(CFLAGS) -Wvolatile-register-var 153endif 154 155### --- END CONFIGURATION SECTION --- 156 157# Those must not be GNU-specific; they are shared with perl/ which may 158# be built by a different compiler. (Note that this is an artifact now 159# but it still might be nice to keep that distinction.) 160BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include 161BASIC_LDFLAGS = 162 163# Guard against environment variables 164BUILTIN_OBJS = 165LIB_H = 166LIB_OBJS = 167PYRF_OBJS = 168SCRIPT_SH = 169 170SCRIPT_SH += perf-archive.sh 171 172grep-libs = $(filter -l%,$(1)) 173strip-libs = $(filter-out -l%,$(1)) 174 175$(OUTPUT)python/perf.so: $(PYRF_OBJS) 176 $(QUIET_GEN)CFLAGS='$(BASIC_CFLAGS)' $(PYTHON_WORD) util/setup.py \ 177 --quiet build_ext \ 178 --build-lib='$(OUTPUT)python' \ 179 --build-temp='$(OUTPUT)python/temp' 180# 181# No Perl scripts right now: 182# 183 184SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH)) 185 186# 187# Single 'perf' binary right now: 188# 189PROGRAMS += $(OUTPUT)perf 190 191LANG_BINDINGS = 192 193# what 'all' will build and 'install' will install, in perfexecdir 194ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS) 195 196# what 'all' will build but not install in perfexecdir 197OTHER_PROGRAMS = $(OUTPUT)perf 198 199# Set paths to tools early so that they can be used for version tests. 200ifndef SHELL_PATH 201 SHELL_PATH = /bin/sh 202endif 203ifndef PERL_PATH 204 PERL_PATH = /usr/bin/perl 205endif 206 207export PERL_PATH 208 209LIB_FILE=$(OUTPUT)libperf.a 210 211LIB_H += ../../include/linux/perf_event.h 212LIB_H += ../../include/linux/rbtree.h 213LIB_H += ../../include/linux/list.h 214LIB_H += ../../include/linux/hash.h 215LIB_H += ../../include/linux/stringify.h 216LIB_H += util/include/linux/bitmap.h 217LIB_H += util/include/linux/bitops.h 218LIB_H += util/include/linux/compiler.h 219LIB_H += util/include/linux/ctype.h 220LIB_H += util/include/linux/kernel.h 221LIB_H += util/include/linux/list.h 222LIB_H += util/include/linux/module.h 223LIB_H += util/include/linux/poison.h 224LIB_H += util/include/linux/prefetch.h 225LIB_H += util/include/linux/rbtree.h 226LIB_H += util/include/linux/string.h 227LIB_H += util/include/linux/types.h 228LIB_H += util/include/linux/linkage.h 229LIB_H += util/include/asm/asm-offsets.h 230LIB_H += util/include/asm/bug.h 231LIB_H += util/include/asm/byteorder.h 232LIB_H += util/include/asm/hweight.h 233LIB_H += util/include/asm/swab.h 234LIB_H += util/include/asm/system.h 235LIB_H += util/include/asm/uaccess.h 236LIB_H += util/include/dwarf-regs.h 237LIB_H += util/include/asm/dwarf2.h 238LIB_H += util/include/asm/cpufeature.h 239LIB_H += perf.h 240LIB_H += util/annotate.h 241LIB_H += util/cache.h 242LIB_H += util/callchain.h 243LIB_H += util/build-id.h 244LIB_H += util/debug.h 245LIB_H += util/debugfs.h 246LIB_H += util/event.h 247LIB_H += util/evsel.h 248LIB_H += util/evlist.h 249LIB_H += util/exec_cmd.h 250LIB_H += util/types.h 251LIB_H += util/levenshtein.h 252LIB_H += util/map.h 253LIB_H += util/parse-options.h 254LIB_H += util/parse-events.h 255LIB_H += util/quote.h 256LIB_H += util/util.h 257LIB_H += util/xyarray.h 258LIB_H += util/header.h 259LIB_H += util/help.h 260LIB_H += util/session.h 261LIB_H += util/strbuf.h 262LIB_H += util/strlist.h 263LIB_H += util/strfilter.h 264LIB_H += util/svghelper.h 265LIB_H += util/run-command.h 266LIB_H += util/sigchain.h 267LIB_H += util/symbol.h 268LIB_H += util/color.h 269LIB_H += util/values.h 270LIB_H += util/sort.h 271LIB_H += util/hist.h 272LIB_H += util/thread.h 273LIB_H += util/thread_map.h 274LIB_H += util/trace-event.h 275LIB_H += util/probe-finder.h 276LIB_H += util/probe-event.h 277LIB_H += util/pstack.h 278LIB_H += util/cpumap.h 279LIB_H += util/top.h 280LIB_H += $(ARCH_INCLUDE) 281LIB_H += util/cgroup.h 282 283LIB_OBJS += $(OUTPUT)util/abspath.o 284LIB_OBJS += $(OUTPUT)util/alias.o 285LIB_OBJS += $(OUTPUT)util/annotate.o 286LIB_OBJS += $(OUTPUT)util/build-id.o 287LIB_OBJS += $(OUTPUT)util/config.o 288LIB_OBJS += $(OUTPUT)util/ctype.o 289LIB_OBJS += $(OUTPUT)util/debugfs.o 290LIB_OBJS += $(OUTPUT)util/environment.o 291LIB_OBJS += $(OUTPUT)util/event.o 292LIB_OBJS += $(OUTPUT)util/evlist.o 293LIB_OBJS += $(OUTPUT)util/evsel.o 294LIB_OBJS += $(OUTPUT)util/exec_cmd.o 295LIB_OBJS += $(OUTPUT)util/help.o 296LIB_OBJS += $(OUTPUT)util/levenshtein.o 297LIB_OBJS += $(OUTPUT)util/parse-options.o 298LIB_OBJS += $(OUTPUT)util/parse-events.o 299LIB_OBJS += $(OUTPUT)util/path.o 300LIB_OBJS += $(OUTPUT)util/rbtree.o 301LIB_OBJS += $(OUTPUT)util/bitmap.o 302LIB_OBJS += $(OUTPUT)util/hweight.o 303LIB_OBJS += $(OUTPUT)util/run-command.o 304LIB_OBJS += $(OUTPUT)util/quote.o 305LIB_OBJS += $(OUTPUT)util/strbuf.o 306LIB_OBJS += $(OUTPUT)util/string.o 307LIB_OBJS += $(OUTPUT)util/strlist.o 308LIB_OBJS += $(OUTPUT)util/strfilter.o 309LIB_OBJS += $(OUTPUT)util/top.o 310LIB_OBJS += $(OUTPUT)util/usage.o 311LIB_OBJS += $(OUTPUT)util/wrapper.o 312LIB_OBJS += $(OUTPUT)util/sigchain.o 313LIB_OBJS += $(OUTPUT)util/symbol.o 314LIB_OBJS += $(OUTPUT)util/color.o 315LIB_OBJS += $(OUTPUT)util/pager.o 316LIB_OBJS += $(OUTPUT)util/header.o 317LIB_OBJS += $(OUTPUT)util/callchain.o 318LIB_OBJS += $(OUTPUT)util/values.o 319LIB_OBJS += $(OUTPUT)util/debug.o 320LIB_OBJS += $(OUTPUT)util/map.o 321LIB_OBJS += $(OUTPUT)util/pstack.o 322LIB_OBJS += $(OUTPUT)util/session.o 323LIB_OBJS += $(OUTPUT)util/thread.o 324LIB_OBJS += $(OUTPUT)util/thread_map.o 325LIB_OBJS += $(OUTPUT)util/trace-event-parse.o 326LIB_OBJS += $(OUTPUT)util/trace-event-read.o 327LIB_OBJS += $(OUTPUT)util/trace-event-info.o 328LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o 329LIB_OBJS += $(OUTPUT)util/svghelper.o 330LIB_OBJS += $(OUTPUT)util/sort.o 331LIB_OBJS += $(OUTPUT)util/hist.o 332LIB_OBJS += $(OUTPUT)util/probe-event.o 333LIB_OBJS += $(OUTPUT)util/util.o 334LIB_OBJS += $(OUTPUT)util/xyarray.o 335LIB_OBJS += $(OUTPUT)util/cpumap.o 336LIB_OBJS += $(OUTPUT)util/cgroup.o 337 338BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o 339 340BUILTIN_OBJS += $(OUTPUT)builtin-bench.o 341 342# Benchmark modules 343BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o 344BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o 345ifeq ($(RAW_ARCH),x86_64) 346BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy-x86-64-asm.o 347endif 348BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o 349 350BUILTIN_OBJS += $(OUTPUT)builtin-diff.o 351BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o 352BUILTIN_OBJS += $(OUTPUT)builtin-help.o 353BUILTIN_OBJS += $(OUTPUT)builtin-sched.o 354BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o 355BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o 356BUILTIN_OBJS += $(OUTPUT)builtin-list.o 357BUILTIN_OBJS += $(OUTPUT)builtin-record.o 358BUILTIN_OBJS += $(OUTPUT)builtin-report.o 359BUILTIN_OBJS += $(OUTPUT)builtin-stat.o 360BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o 361BUILTIN_OBJS += $(OUTPUT)builtin-top.o 362BUILTIN_OBJS += $(OUTPUT)builtin-script.o 363BUILTIN_OBJS += $(OUTPUT)builtin-probe.o 364BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o 365BUILTIN_OBJS += $(OUTPUT)builtin-lock.o 366BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o 367BUILTIN_OBJS += $(OUTPUT)builtin-test.o 368BUILTIN_OBJS += $(OUTPUT)builtin-inject.o 369 370PERFLIBS = $(LIB_FILE) 371 372# Files needed for the python binding, perf.so 373# pyrf is just an internal name needed for all those wrappers. 374# This has to be in sync with what is in the 'sources' variable in 375# tools/perf/util/setup.py 376 377PYRF_OBJS += $(OUTPUT)util/cpumap.o 378PYRF_OBJS += $(OUTPUT)util/ctype.o 379PYRF_OBJS += $(OUTPUT)util/evlist.o 380PYRF_OBJS += $(OUTPUT)util/evsel.o 381PYRF_OBJS += $(OUTPUT)util/python.o 382PYRF_OBJS += $(OUTPUT)util/thread_map.o 383PYRF_OBJS += $(OUTPUT)util/util.o 384PYRF_OBJS += $(OUTPUT)util/xyarray.o 385 386# 387# Platform specific tweaks 388# 389 390# We choose to avoid "if .. else if .. else .. endif endif" 391# because maintaining the nesting to match is a pain. If 392# we had "elif" things would have been much nicer... 393 394-include config.mak.autogen 395-include config.mak 396 397ifndef NO_DWARF 398FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS) 399ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF)),y) 400 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); 401 NO_DWARF := 1 402endif # Dwarf support 403endif # NO_DWARF 404 405-include arch/$(ARCH)/Makefile 406 407ifneq ($(OUTPUT),) 408 BASIC_CFLAGS += -I$(OUTPUT) 409endif 410 411FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) 412ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF)),y) 413 FLAGS_GLIBC=$(ALL_CFLAGS) $(ALL_LDFLAGS) 414 ifneq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC)),y) 415 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static); 416 else 417 msg := $(error No libelf.h/libelf found, please install libelf-dev/elfutils-libelf-devel); 418 endif 419endif 420 421ifneq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_COMMON)),y) 422 BASIC_CFLAGS += -DLIBELF_NO_MMAP 423endif 424 425ifndef NO_DWARF 426ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined) 427 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled); 428else 429 BASIC_CFLAGS += -DDWARF_SUPPORT 430 EXTLIBS += -lelf -ldw 431 LIB_OBJS += $(OUTPUT)util/probe-finder.o 432endif # PERF_HAVE_DWARF_REGS 433endif # NO_DWARF 434 435ifdef NO_NEWT 436 BASIC_CFLAGS += -DNO_NEWT_SUPPORT 437else 438 FLAGS_NEWT=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lnewt 439 ifneq ($(call try-cc,$(SOURCE_NEWT),$(FLAGS_NEWT)),y) 440 msg := $(warning newt not found, disables TUI support. Please install newt-devel or libnewt-dev); 441 BASIC_CFLAGS += -DNO_NEWT_SUPPORT 442 else 443 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h 444 BASIC_CFLAGS += -I/usr/include/slang 445 EXTLIBS += -lnewt -lslang 446 LIB_OBJS += $(OUTPUT)util/ui/setup.o 447 LIB_OBJS += $(OUTPUT)util/ui/browser.o 448 LIB_OBJS += $(OUTPUT)util/ui/browsers/annotate.o 449 LIB_OBJS += $(OUTPUT)util/ui/browsers/hists.o 450 LIB_OBJS += $(OUTPUT)util/ui/browsers/map.o 451 LIB_OBJS += $(OUTPUT)util/ui/browsers/top.o 452 LIB_OBJS += $(OUTPUT)util/ui/helpline.o 453 LIB_OBJS += $(OUTPUT)util/ui/progress.o 454 LIB_OBJS += $(OUTPUT)util/ui/util.o 455 LIB_H += util/ui/browser.h 456 LIB_H += util/ui/browsers/map.h 457 LIB_H += util/ui/helpline.h 458 LIB_H += util/ui/libslang.h 459 LIB_H += util/ui/progress.h 460 LIB_H += util/ui/util.h 461 LIB_H += util/ui/ui.h 462 endif 463endif 464 465ifdef NO_LIBPERL 466 BASIC_CFLAGS += -DNO_LIBPERL 467else 468 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null) 469 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS)) 470 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS)) 471 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null` 472 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS) 473 474 ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED)),y) 475 BASIC_CFLAGS += -DNO_LIBPERL 476 else 477 ALL_LDFLAGS += $(PERL_EMBED_LDFLAGS) 478 EXTLIBS += $(PERL_EMBED_LIBADD) 479 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-perl.o 480 LIB_OBJS += $(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o 481 endif 482endif 483 484disable-python = $(eval $(disable-python_code)) 485define disable-python_code 486 BASIC_CFLAGS += -DNO_LIBPYTHON 487 $(if $(1),$(warning No $(1) was found)) 488 $(warning Python support won't be built) 489endef 490 491override PYTHON := \ 492 $(call get-executable-or-default,PYTHON,python) 493 494ifndef PYTHON 495 $(call disable-python,python interpreter) 496 python-clean := 497else 498 499 PYTHON_WORD := $(call shell-wordify,$(PYTHON)) 500 501 python-clean := $(PYTHON_WORD) util/setup.py clean \ 502 --build-lib='$(OUTPUT)python' \ 503 --build-temp='$(OUTPUT)python/temp' 504 505 ifdef NO_LIBPYTHON 506 $(call disable-python) 507 else 508 509 override PYTHON_CONFIG := \ 510 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config) 511 512 ifndef PYTHON_CONFIG 513 $(call disable-python,python-config tool) 514 else 515 516 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG)) 517 518 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null) 519 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS)) 520 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS)) 521 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null) 522 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS) 523 524 ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED)),y) 525 $(call disable-python,Python.h (for Python 2.x)) 526 else 527 528 ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED)),y) 529 $(warning Python 3 is not yet supported; please set) 530 $(warning PYTHON and/or PYTHON_CONFIG appropriately.) 531 $(warning If you also have Python 2 installed, then) 532 $(warning try something like:) 533 $(warning $(and ,)) 534 $(warning $(and ,) make PYTHON=python2) 535 $(warning $(and ,)) 536 $(warning Otherwise, disable Python support entirely:) 537 $(warning $(and ,)) 538 $(warning $(and ,) make NO_LIBPYTHON=1) 539 $(warning $(and ,)) 540 $(error $(and ,)) 541 else 542 ALL_LDFLAGS += $(PYTHON_EMBED_LDFLAGS) 543 EXTLIBS += $(PYTHON_EMBED_LIBADD) 544 LIB_OBJS += $(OUTPUT)util/scripting-engines/trace-event-python.o 545 LIB_OBJS += $(OUTPUT)scripts/python/Perf-Trace-Util/Context.o 546 LANG_BINDINGS += $(OUTPUT)python/perf.so 547 endif 548 549 endif 550 endif 551 endif 552endif 553 554ifdef NO_DEMANGLE 555 BASIC_CFLAGS += -DNO_DEMANGLE 556else 557 ifdef HAVE_CPLUS_DEMANGLE 558 EXTLIBS += -liberty 559 BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE 560 else 561 FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd 562 has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD)) 563 ifeq ($(has_bfd),y) 564 EXTLIBS += -lbfd 565 else 566 FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty 567 has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY)) 568 ifeq ($(has_bfd_iberty),y) 569 EXTLIBS += -lbfd -liberty 570 else 571 FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz 572 has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z)) 573 ifeq ($(has_bfd_iberty_z),y) 574 EXTLIBS += -lbfd -liberty -lz 575 else 576 FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty 577 has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE)) 578 ifeq ($(has_cplus_demangle),y) 579 EXTLIBS += -liberty 580 BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE 581 else 582 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling) 583 BASIC_CFLAGS += -DNO_DEMANGLE 584 endif 585 endif 586 endif 587 endif 588 endif 589endif 590 591 592ifdef NO_STRLCPY 593 BASIC_CFLAGS += -DNO_STRLCPY 594else 595 ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y) 596 BASIC_CFLAGS += -DNO_STRLCPY 597 endif 598endif 599 600ifneq ($(findstring $(MAKEFLAGS),s),s) 601ifndef V 602 QUIET_CC = @echo ' ' CC $@; 603 QUIET_AR = @echo ' ' AR $@; 604 QUIET_LINK = @echo ' ' LINK $@; 605 QUIET_MKDIR = @echo ' ' MKDIR $@; 606 QUIET_GEN = @echo ' ' GEN $@; 607endif 608endif 609 610ifdef ASCIIDOC8 611 export ASCIIDOC8 612endif 613 614# Shell quote (do not use $(call) to accommodate ancient setups); 615 616ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG)) 617 618DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) 619bindir_SQ = $(subst ','\'',$(bindir)) 620bindir_relative_SQ = $(subst ','\'',$(bindir_relative)) 621mandir_SQ = $(subst ','\'',$(mandir)) 622infodir_SQ = $(subst ','\'',$(infodir)) 623perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) 624template_dir_SQ = $(subst ','\'',$(template_dir)) 625htmldir_SQ = $(subst ','\'',$(htmldir)) 626prefix_SQ = $(subst ','\'',$(prefix)) 627 628SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) 629 630LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive $(EXTLIBS) 631 632ALL_CFLAGS += $(BASIC_CFLAGS) 633ALL_CFLAGS += $(ARCH_CFLAGS) 634ALL_LDFLAGS += $(BASIC_LDFLAGS) 635 636export INSTALL SHELL_PATH 637 638 639### Build rules 640 641SHELL = $(SHELL_PATH) 642 643all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS) 644 645please_set_SHELL_PATH_to_a_more_modern_shell: 646 @$$(:) 647 648shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell 649 650strip: $(PROGRAMS) $(OUTPUT)perf 651 $(STRIP) $(STRIP_OPTS) $(PROGRAMS) $(OUTPUT)perf 652 653$(OUTPUT)perf.o: perf.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 654 $(QUIET_CC)$(CC) -DPERF_VERSION='"$(PERF_VERSION)"' \ 655 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ 656 $(ALL_CFLAGS) -c $(filter %.c,$^) -o $@ 657 658$(OUTPUT)perf: $(OUTPUT)perf.o $(BUILTIN_OBJS) $(PERFLIBS) 659 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(OUTPUT)perf.o \ 660 $(BUILTIN_OBJS) $(LIBS) -o $@ 661 662$(OUTPUT)builtin-help.o: builtin-help.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 663 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 664 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ 665 '-DPERF_MAN_PATH="$(mandir_SQ)"' \ 666 '-DPERF_INFO_PATH="$(infodir_SQ)"' $< 667 668$(OUTPUT)builtin-timechart.o: builtin-timechart.c $(OUTPUT)common-cmds.h $(OUTPUT)PERF-CFLAGS 669 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 670 '-DPERF_HTML_PATH="$(htmldir_SQ)"' \ 671 '-DPERF_MAN_PATH="$(mandir_SQ)"' \ 672 '-DPERF_INFO_PATH="$(infodir_SQ)"' $< 673 674$(OUTPUT)common-cmds.h: util/generate-cmdlist.sh command-list.txt 675 676$(OUTPUT)common-cmds.h: $(wildcard Documentation/perf-*.txt) 677 $(QUIET_GEN). util/generate-cmdlist.sh > $@+ && mv $@+ $@ 678 679$(SCRIPTS) : % : %.sh 680 $(QUIET_GEN)$(INSTALL) '$@.sh' '$(OUTPUT)$@' 681 682# These can record PERF_VERSION 683$(OUTPUT)perf.o perf.spec \ 684 $(SCRIPTS) \ 685 : $(OUTPUT)PERF-VERSION-FILE 686 687$(OUTPUT)%.o: %.c $(OUTPUT)PERF-CFLAGS 688 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< 689$(OUTPUT)%.s: %.c $(OUTPUT)PERF-CFLAGS 690 $(QUIET_CC)$(CC) -S $(ALL_CFLAGS) $< 691$(OUTPUT)%.o: %.S 692 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $< 693 694$(OUTPUT)util/exec_cmd.o: util/exec_cmd.c $(OUTPUT)PERF-CFLAGS 695 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) \ 696 '-DPERF_EXEC_PATH="$(perfexecdir_SQ)"' \ 697 '-DBINDIR="$(bindir_relative_SQ)"' \ 698 '-DPREFIX="$(prefix_SQ)"' \ 699 $< 700 701$(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS 702 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 703 704$(OUTPUT)util/ui/browser.o: util/ui/browser.c $(OUTPUT)PERF-CFLAGS 705 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 706 707$(OUTPUT)util/ui/browsers/annotate.o: util/ui/browsers/annotate.c $(OUTPUT)PERF-CFLAGS 708 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 709 710$(OUTPUT)util/ui/browsers/top.o: util/ui/browsers/top.c $(OUTPUT)PERF-CFLAGS 711 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 712 713$(OUTPUT)util/ui/browsers/hists.o: util/ui/browsers/hists.c $(OUTPUT)PERF-CFLAGS 714 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 715 716$(OUTPUT)util/ui/browsers/map.o: util/ui/browsers/map.c $(OUTPUT)PERF-CFLAGS 717 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DENABLE_SLFUTURE_CONST $< 718 719$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS 720 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $< 721 722$(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS 723 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< 724 725$(OUTPUT)scripts/perl/Perf-Trace-Util/Context.o: scripts/perl/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS 726 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< 727 728$(OUTPUT)util/scripting-engines/trace-event-python.o: util/scripting-engines/trace-event-python.c $(OUTPUT)PERF-CFLAGS 729 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $< 730 731$(OUTPUT)scripts/python/Perf-Trace-Util/Context.o: scripts/python/Perf-Trace-Util/Context.c $(OUTPUT)PERF-CFLAGS 732 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PYTHON_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-nested-externs $< 733 734$(OUTPUT)perf-%: %.o $(PERFLIBS) 735 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) 736 737$(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H) 738$(patsubst perf-%,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h) 739 740# we compile into subdirectories. if the target directory is not the source directory, they might not exists. So 741# we depend the various files onto their directories. 742DIRECTORY_DEPS = $(LIB_OBJS) $(BUILTIN_OBJS) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h 743$(DIRECTORY_DEPS): | $(sort $(dir $(DIRECTORY_DEPS))) 744# In the second step, we make a rule to actually create these directories 745$(sort $(dir $(DIRECTORY_DEPS))): 746 $(QUIET_MKDIR)$(MKDIR) -p $@ 2>/dev/null 747 748$(LIB_FILE): $(LIB_OBJS) 749 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIB_OBJS) 750 751help: 752 @echo 'Perf make targets:' 753 @echo ' doc - make *all* documentation (see below)' 754 @echo ' man - make manpage documentation (access with man <foo>)' 755 @echo ' html - make html documentation' 756 @echo ' info - make GNU info documentation (access with info <foo>)' 757 @echo ' pdf - make pdf documentation' 758 @echo ' TAGS - use etags to make tag information for source browsing' 759 @echo ' tags - use ctags to make tag information for source browsing' 760 @echo ' cscope - use cscope to make interactive browsing database' 761 @echo '' 762 @echo 'Perf install targets:' 763 @echo ' NOTE: documentation build requires asciidoc, xmlto packages to be installed' 764 @echo ' HINT: use "make prefix=<path> <install target>" to install to a particular' 765 @echo ' path like make prefix=/usr/local install install-doc' 766 @echo ' install - install compiled binaries' 767 @echo ' install-doc - install *all* documentation' 768 @echo ' install-man - install manpage documentation' 769 @echo ' install-html - install html documentation' 770 @echo ' install-info - install GNU info documentation' 771 @echo ' install-pdf - install pdf documentation' 772 @echo '' 773 @echo ' quick-install-doc - alias for quick-install-man' 774 @echo ' quick-install-man - install the documentation quickly' 775 @echo ' quick-install-html - install the html documentation quickly' 776 @echo '' 777 @echo 'Perf maintainer targets:' 778 @echo ' distclean - alias to clean' 779 @echo ' clean - clean all binary objects and build output' 780 781doc: 782 $(MAKE) -C Documentation all 783 784man: 785 $(MAKE) -C Documentation man 786 787html: 788 $(MAKE) -C Documentation html 789 790info: 791 $(MAKE) -C Documentation info 792 793pdf: 794 $(MAKE) -C Documentation pdf 795 796TAGS: 797 $(RM) TAGS 798 $(FIND) . -name '*.[hcS]' -print | xargs etags -a 799 800tags: 801 $(RM) tags 802 $(FIND) . -name '*.[hcS]' -print | xargs ctags -a 803 804cscope: 805 $(RM) cscope* 806 $(FIND) . -name '*.[hcS]' -print | xargs cscope -b 807 808### Detect prefix changes 809TRACK_CFLAGS = $(subst ','\'',$(ALL_CFLAGS)):\ 810 $(bindir_SQ):$(perfexecdir_SQ):$(template_dir_SQ):$(prefix_SQ) 811 812$(OUTPUT)PERF-CFLAGS: .FORCE-PERF-CFLAGS 813 @FLAGS='$(TRACK_CFLAGS)'; \ 814 if test x"$$FLAGS" != x"`cat $(OUTPUT)PERF-CFLAGS 2>/dev/null`" ; then \ 815 echo 1>&2 " * new build flags or prefix"; \ 816 echo "$$FLAGS" >$(OUTPUT)PERF-CFLAGS; \ 817 fi 818 819### Testing rules 820 821# GNU make supports exporting all variables by "export" without parameters. 822# However, the environment gets quite big, and some programs have problems 823# with that. 824 825check: $(OUTPUT)common-cmds.h 826 if sparse; \ 827 then \ 828 for i in *.c */*.c; \ 829 do \ 830 sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; \ 831 done; \ 832 else \ 833 exit 1; \ 834 fi 835 836### Installation rules 837 838ifneq ($(filter /%,$(firstword $(perfexecdir))),) 839perfexec_instdir = $(perfexecdir) 840else 841perfexec_instdir = $(prefix)/$(perfexecdir) 842endif 843perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) 844 845install: all 846 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)' 847 $(INSTALL) $(OUTPUT)perf '$(DESTDIR_SQ)$(bindir_SQ)' 848 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' 849 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' 850 $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' 851 $(INSTALL) scripts/perl/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/Perf-Trace-Util/lib/Perf/Trace' 852 $(INSTALL) scripts/perl/*.pl -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl' 853 $(INSTALL) scripts/perl/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/perl/bin' 854 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' 855 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' 856 $(INSTALL) scripts/python/Perf-Trace-Util/lib/Perf/Trace/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/Perf-Trace-Util/lib/Perf/Trace' 857 $(INSTALL) scripts/python/*.py -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python' 858 $(INSTALL) scripts/python/bin/* -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)/scripts/python/bin' 859 860install-doc: 861 $(MAKE) -C Documentation install 862 863install-man: 864 $(MAKE) -C Documentation install-man 865 866install-html: 867 $(MAKE) -C Documentation install-html 868 869install-info: 870 $(MAKE) -C Documentation install-info 871 872install-pdf: 873 $(MAKE) -C Documentation install-pdf 874 875quick-install-doc: 876 $(MAKE) -C Documentation quick-install 877 878quick-install-man: 879 $(MAKE) -C Documentation quick-install-man 880 881quick-install-html: 882 $(MAKE) -C Documentation quick-install-html 883 884### Cleaning rules 885 886clean: 887 $(RM) $(OUTPUT){*.o,*/*.o,*/*/*.o,*/*/*/*.o,$(LIB_FILE),perf-archive} 888 $(RM) $(ALL_PROGRAMS) perf 889 $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* 890 $(MAKE) -C Documentation/ clean 891 $(RM) $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)PERF-CFLAGS 892 $(python-clean) 893 894.PHONY: all install clean strip 895.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell 896.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope .FORCE-PERF-CFLAGS 897