perf tools: git mv tools/perf/{features-tests.mak,config/}
[linux-flexiantxendom0-3.2.10.git] / tools / perf / Makefile
1 ifeq ("$(origin O)", "command line")
2         OUTPUT := $(O)/
3 endif
4
5 # The default target of this Makefile is...
6 all:
7
8 include config/utilities.mak
9
10 ifneq ($(OUTPUT),)
11 # check that the output directory actually exists
12 OUTDIR := $(shell cd $(OUTPUT) && /bin/pwd)
13 $(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist))
14 endif
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
38 uname_M := $(shell uname -m 2>/dev/null || echo not)
39
40 ARCH ?= $(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
47 ifeq ($(ARCH),i386)
48         ARCH := x86
49 endif
50 ifeq ($(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
55 endif
56
57 #
58 # Include saner warnings here, which can catch bugs:
59 #
60
61 EXTRA_WARNINGS := -Wformat
62 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-security
63 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wformat-y2k
64 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wshadow
65 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Winit-self
66 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wpacked
67 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wredundant-decls
68 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-aliasing=3
69 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-default
70 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wswitch-enum
71 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wno-system-headers
72 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wundef
73 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wwrite-strings
74 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wbad-function-cast
75 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-declarations
76 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wmissing-prototypes
77 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wnested-externs
78 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wold-style-definition
79 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wstrict-prototypes
80 EXTRA_WARNINGS := $(EXTRA_WARNINGS) -Wdeclaration-after-statement
81
82 ifeq ("$(origin DEBUG)", "command line")
83   PERF_DEBUG = $(DEBUG)
84 endif
85 ifndef PERF_DEBUG
86   CFLAGS_OPTIMIZE = -O6
87 endif
88
89 CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
90 EXTLIBS = -lpthread -lrt -lelf -lm
91 ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
92 ALL_LDFLAGS = $(LDFLAGS)
93 STRIP ?= 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
108 ifndef DESTDIR
109 prefix = $(HOME)
110 endif
111 bindir_relative = bin
112 bindir = $(prefix)/$(bindir_relative)
113 mandir = share/man
114 infodir = share/info
115 perfexecdir = libexec/perf-core
116 sharedir = $(prefix)/share
117 template_dir = share/perf-core/templates
118 htmldir = share/doc/perf-doc
119 ifeq ($(prefix),/usr)
120 sysconfdir = /etc
121 ETC_PERFCONFIG = $(sysconfdir)/perfconfig
122 else
123 sysconfdir = $(prefix)/etc
124 ETC_PERFCONFIG = etc/perfconfig
125 endif
126 lib = lib
127
128 export prefix bindir sharedir sysconfdir
129
130 CC = $(CROSS_COMPILE)gcc
131 AR = $(CROSS_COMPILE)ar
132 RM = rm -f
133 MKDIR = mkdir
134 FIND = find
135 INSTALL = 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..
139 SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__
140
141 -include config/feature-tests.mak
142
143 ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -fstack-protector-all),y)
144         CFLAGS := $(CFLAGS) -fstack-protector-all
145 endif
146
147 ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wstack-protector),y)
148        CFLAGS := $(CFLAGS) -Wstack-protector
149 endif
150
151 ifeq ($(call try-cc,$(SOURCE_HELLO),-Werror -Wvolatile-register-var),y)
152        CFLAGS := $(CFLAGS) -Wvolatile-register-var
153 endif
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.)
160 BASIC_CFLAGS = -Iutil/include -Iarch/$(ARCH)/include
161 BASIC_LDFLAGS =
162
163 # Guard against environment variables
164 BUILTIN_OBJS =
165 LIB_H =
166 LIB_OBJS =
167 PYRF_OBJS =
168 SCRIPT_SH =
169
170 SCRIPT_SH += perf-archive.sh
171
172 grep-libs = $(filter -l%,$(1))
173 strip-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
184 SCRIPTS = $(patsubst %.sh,%,$(SCRIPT_SH))
185
186 #
187 # Single 'perf' binary right now:
188 #
189 PROGRAMS += $(OUTPUT)perf
190
191 LANG_BINDINGS =
192
193 # what 'all' will build and 'install' will install, in perfexecdir
194 ALL_PROGRAMS = $(PROGRAMS) $(SCRIPTS)
195
196 # what 'all' will build but not install in perfexecdir
197 OTHER_PROGRAMS = $(OUTPUT)perf
198
199 # Set paths to tools early so that they can be used for version tests.
200 ifndef SHELL_PATH
201         SHELL_PATH = /bin/sh
202 endif
203 ifndef PERL_PATH
204         PERL_PATH = /usr/bin/perl
205 endif
206
207 export PERL_PATH
208
209 LIB_FILE=$(OUTPUT)libperf.a
210
211 LIB_H += ../../include/linux/perf_event.h
212 LIB_H += ../../include/linux/rbtree.h
213 LIB_H += ../../include/linux/list.h
214 LIB_H += ../../include/linux/hash.h
215 LIB_H += ../../include/linux/stringify.h
216 LIB_H += util/include/linux/bitmap.h
217 LIB_H += util/include/linux/bitops.h
218 LIB_H += util/include/linux/compiler.h
219 LIB_H += util/include/linux/ctype.h
220 LIB_H += util/include/linux/kernel.h
221 LIB_H += util/include/linux/list.h
222 LIB_H += util/include/linux/module.h
223 LIB_H += util/include/linux/poison.h
224 LIB_H += util/include/linux/prefetch.h
225 LIB_H += util/include/linux/rbtree.h
226 LIB_H += util/include/linux/string.h
227 LIB_H += util/include/linux/types.h
228 LIB_H += util/include/linux/linkage.h
229 LIB_H += util/include/asm/asm-offsets.h
230 LIB_H += util/include/asm/bug.h
231 LIB_H += util/include/asm/byteorder.h
232 LIB_H += util/include/asm/hweight.h
233 LIB_H += util/include/asm/swab.h
234 LIB_H += util/include/asm/system.h
235 LIB_H += util/include/asm/uaccess.h
236 LIB_H += util/include/dwarf-regs.h
237 LIB_H += util/include/asm/dwarf2.h
238 LIB_H += util/include/asm/cpufeature.h
239 LIB_H += perf.h
240 LIB_H += util/annotate.h
241 LIB_H += util/cache.h
242 LIB_H += util/callchain.h
243 LIB_H += util/build-id.h
244 LIB_H += util/debug.h
245 LIB_H += util/debugfs.h
246 LIB_H += util/event.h
247 LIB_H += util/evsel.h
248 LIB_H += util/evlist.h
249 LIB_H += util/exec_cmd.h
250 LIB_H += util/types.h
251 LIB_H += util/levenshtein.h
252 LIB_H += util/map.h
253 LIB_H += util/parse-options.h
254 LIB_H += util/parse-events.h
255 LIB_H += util/quote.h
256 LIB_H += util/util.h
257 LIB_H += util/xyarray.h
258 LIB_H += util/header.h
259 LIB_H += util/help.h
260 LIB_H += util/session.h
261 LIB_H += util/strbuf.h
262 LIB_H += util/strlist.h
263 LIB_H += util/strfilter.h
264 LIB_H += util/svghelper.h
265 LIB_H += util/run-command.h
266 LIB_H += util/sigchain.h
267 LIB_H += util/symbol.h
268 LIB_H += util/color.h
269 LIB_H += util/values.h
270 LIB_H += util/sort.h
271 LIB_H += util/hist.h
272 LIB_H += util/thread.h
273 LIB_H += util/thread_map.h
274 LIB_H += util/trace-event.h
275 LIB_H += util/probe-finder.h
276 LIB_H += util/probe-event.h
277 LIB_H += util/pstack.h
278 LIB_H += util/cpumap.h
279 LIB_H += util/top.h
280 LIB_H += $(ARCH_INCLUDE)
281 LIB_H += util/cgroup.h
282
283 LIB_OBJS += $(OUTPUT)util/abspath.o
284 LIB_OBJS += $(OUTPUT)util/alias.o
285 LIB_OBJS += $(OUTPUT)util/annotate.o
286 LIB_OBJS += $(OUTPUT)util/build-id.o
287 LIB_OBJS += $(OUTPUT)util/config.o
288 LIB_OBJS += $(OUTPUT)util/ctype.o
289 LIB_OBJS += $(OUTPUT)util/debugfs.o
290 LIB_OBJS += $(OUTPUT)util/environment.o
291 LIB_OBJS += $(OUTPUT)util/event.o
292 LIB_OBJS += $(OUTPUT)util/evlist.o
293 LIB_OBJS += $(OUTPUT)util/evsel.o
294 LIB_OBJS += $(OUTPUT)util/exec_cmd.o
295 LIB_OBJS += $(OUTPUT)util/help.o
296 LIB_OBJS += $(OUTPUT)util/levenshtein.o
297 LIB_OBJS += $(OUTPUT)util/parse-options.o
298 LIB_OBJS += $(OUTPUT)util/parse-events.o
299 LIB_OBJS += $(OUTPUT)util/path.o
300 LIB_OBJS += $(OUTPUT)util/rbtree.o
301 LIB_OBJS += $(OUTPUT)util/bitmap.o
302 LIB_OBJS += $(OUTPUT)util/hweight.o
303 LIB_OBJS += $(OUTPUT)util/run-command.o
304 LIB_OBJS += $(OUTPUT)util/quote.o
305 LIB_OBJS += $(OUTPUT)util/strbuf.o
306 LIB_OBJS += $(OUTPUT)util/string.o
307 LIB_OBJS += $(OUTPUT)util/strlist.o
308 LIB_OBJS += $(OUTPUT)util/strfilter.o
309 LIB_OBJS += $(OUTPUT)util/top.o
310 LIB_OBJS += $(OUTPUT)util/usage.o
311 LIB_OBJS += $(OUTPUT)util/wrapper.o
312 LIB_OBJS += $(OUTPUT)util/sigchain.o
313 LIB_OBJS += $(OUTPUT)util/symbol.o
314 LIB_OBJS += $(OUTPUT)util/color.o
315 LIB_OBJS += $(OUTPUT)util/pager.o
316 LIB_OBJS += $(OUTPUT)util/header.o
317 LIB_OBJS += $(OUTPUT)util/callchain.o
318 LIB_OBJS += $(OUTPUT)util/values.o
319 LIB_OBJS += $(OUTPUT)util/debug.o
320 LIB_OBJS += $(OUTPUT)util/map.o
321 LIB_OBJS += $(OUTPUT)util/pstack.o
322 LIB_OBJS += $(OUTPUT)util/session.o
323 LIB_OBJS += $(OUTPUT)util/thread.o
324 LIB_OBJS += $(OUTPUT)util/thread_map.o
325 LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
326 LIB_OBJS += $(OUTPUT)util/trace-event-read.o
327 LIB_OBJS += $(OUTPUT)util/trace-event-info.o
328 LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
329 LIB_OBJS += $(OUTPUT)util/svghelper.o
330 LIB_OBJS += $(OUTPUT)util/sort.o
331 LIB_OBJS += $(OUTPUT)util/hist.o
332 LIB_OBJS += $(OUTPUT)util/probe-event.o
333 LIB_OBJS += $(OUTPUT)util/util.o
334 LIB_OBJS += $(OUTPUT)util/xyarray.o
335 LIB_OBJS += $(OUTPUT)util/cpumap.o
336 LIB_OBJS += $(OUTPUT)util/cgroup.o
337
338 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
339
340 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
341
342 # Benchmark modules
343 BUILTIN_OBJS += $(OUTPUT)bench/sched-messaging.o
344 BUILTIN_OBJS += $(OUTPUT)bench/sched-pipe.o
345 ifeq ($(RAW_ARCH),x86_64)
346 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy-x86-64-asm.o
347 endif
348 BUILTIN_OBJS += $(OUTPUT)bench/mem-memcpy.o
349
350 BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
351 BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
352 BUILTIN_OBJS += $(OUTPUT)builtin-help.o
353 BUILTIN_OBJS += $(OUTPUT)builtin-sched.o
354 BUILTIN_OBJS += $(OUTPUT)builtin-buildid-list.o
355 BUILTIN_OBJS += $(OUTPUT)builtin-buildid-cache.o
356 BUILTIN_OBJS += $(OUTPUT)builtin-list.o
357 BUILTIN_OBJS += $(OUTPUT)builtin-record.o
358 BUILTIN_OBJS += $(OUTPUT)builtin-report.o
359 BUILTIN_OBJS += $(OUTPUT)builtin-stat.o
360 BUILTIN_OBJS += $(OUTPUT)builtin-timechart.o
361 BUILTIN_OBJS += $(OUTPUT)builtin-top.o
362 BUILTIN_OBJS += $(OUTPUT)builtin-script.o
363 BUILTIN_OBJS += $(OUTPUT)builtin-probe.o
364 BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
365 BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
366 BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
367 BUILTIN_OBJS += $(OUTPUT)builtin-test.o
368 BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
369
370 PERFLIBS = $(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
377 PYRF_OBJS += $(OUTPUT)util/cpumap.o
378 PYRF_OBJS += $(OUTPUT)util/ctype.o
379 PYRF_OBJS += $(OUTPUT)util/evlist.o
380 PYRF_OBJS += $(OUTPUT)util/evsel.o
381 PYRF_OBJS += $(OUTPUT)util/python.o
382 PYRF_OBJS += $(OUTPUT)util/thread_map.o
383 PYRF_OBJS += $(OUTPUT)util/util.o
384 PYRF_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
397 ifndef NO_DWARF
398 FLAGS_DWARF=$(ALL_CFLAGS) -ldw -lelf $(ALL_LDFLAGS) $(EXTLIBS)
399 ifneq ($(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
402 endif # Dwarf support
403 endif # NO_DWARF
404
405 -include arch/$(ARCH)/Makefile
406
407 ifneq ($(OUTPUT),)
408         BASIC_CFLAGS += -I$(OUTPUT)
409 endif
410
411 FLAGS_LIBELF=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS)
412 ifneq ($(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
419 endif
420
421 ifneq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_COMMON)),y)
422         BASIC_CFLAGS += -DLIBELF_NO_MMAP
423 endif
424
425 ifndef NO_DWARF
426 ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
427         msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
428 else
429         BASIC_CFLAGS += -DDWARF_SUPPORT
430         EXTLIBS += -lelf -ldw
431         LIB_OBJS += $(OUTPUT)util/probe-finder.o
432 endif # PERF_HAVE_DWARF_REGS
433 endif # NO_DWARF
434
435 ifdef NO_NEWT
436         BASIC_CFLAGS += -DNO_NEWT_SUPPORT
437 else
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
463 endif
464
465 ifdef NO_LIBPERL
466         BASIC_CFLAGS += -DNO_LIBPERL
467 else
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
482 endif
483
484 disable-python = $(eval $(disable-python_code))
485 define disable-python_code
486   BASIC_CFLAGS += -DNO_LIBPYTHON
487   $(if $(1),$(warning No $(1) was found))
488   $(warning Python support won't be built)
489 endef
490
491 override PYTHON := \
492   $(call get-executable-or-default,PYTHON,python)
493
494 ifndef PYTHON
495   $(call disable-python,python interpreter)
496   python-clean :=
497 else
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
552 endif
553
554 ifdef NO_DEMANGLE
555         BASIC_CFLAGS += -DNO_DEMANGLE
556 else
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
589 endif
590
591
592 ifdef NO_STRLCPY
593         BASIC_CFLAGS += -DNO_STRLCPY
594 else
595         ifneq ($(call try-cc,$(SOURCE_STRLCPY),),y)
596                 BASIC_CFLAGS += -DNO_STRLCPY
597         endif
598 endif
599
600 ifneq ($(findstring $(MAKEFLAGS),s),s)
601 ifndef 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 $@;
607 endif
608 endif
609
610 ifdef ASCIIDOC8
611         export ASCIIDOC8
612 endif
613
614 # Shell quote (do not use $(call) to accommodate ancient setups);
615
616 ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
617
618 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
619 bindir_SQ = $(subst ','\'',$(bindir))
620 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
621 mandir_SQ = $(subst ','\'',$(mandir))
622 infodir_SQ = $(subst ','\'',$(infodir))
623 perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
624 template_dir_SQ = $(subst ','\'',$(template_dir))
625 htmldir_SQ = $(subst ','\'',$(htmldir))
626 prefix_SQ = $(subst ','\'',$(prefix))
627
628 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
629
630 LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive $(EXTLIBS)
631
632 ALL_CFLAGS += $(BASIC_CFLAGS)
633 ALL_CFLAGS += $(ARCH_CFLAGS)
634 ALL_LDFLAGS += $(BASIC_LDFLAGS)
635
636 export INSTALL SHELL_PATH
637
638
639 ### Build rules
640
641 SHELL = $(SHELL_PATH)
642
643 all: shell_compatibility_test $(ALL_PROGRAMS) $(LANG_BINDINGS) $(OTHER_PROGRAMS)
644
645 please_set_SHELL_PATH_to_a_more_modern_shell:
646         @$$(:)
647
648 shell_compatibility_test: please_set_SHELL_PATH_to_a_more_modern_shell
649
650 strip: $(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.
742 DIRECTORY_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
751 help:
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
781 doc:
782         $(MAKE) -C Documentation all
783
784 man:
785         $(MAKE) -C Documentation man
786
787 html:
788         $(MAKE) -C Documentation html
789
790 info:
791         $(MAKE) -C Documentation info
792
793 pdf:
794         $(MAKE) -C Documentation pdf
795
796 TAGS:
797         $(RM) TAGS
798         $(FIND) . -name '*.[hcS]' -print | xargs etags -a
799
800 tags:
801         $(RM) tags
802         $(FIND) . -name '*.[hcS]' -print | xargs ctags -a
803
804 cscope:
805         $(RM) cscope*
806         $(FIND) . -name '*.[hcS]' -print | xargs cscope -b
807
808 ### Detect prefix changes
809 TRACK_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
825 check: $(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
838 ifneq ($(filter /%,$(firstword $(perfexecdir))),)
839 perfexec_instdir = $(perfexecdir)
840 else
841 perfexec_instdir = $(prefix)/$(perfexecdir)
842 endif
843 perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))
844
845 install: 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
860 install-doc:
861         $(MAKE) -C Documentation install
862
863 install-man:
864         $(MAKE) -C Documentation install-man
865
866 install-html:
867         $(MAKE) -C Documentation install-html
868
869 install-info:
870         $(MAKE) -C Documentation install-info
871
872 install-pdf:
873         $(MAKE) -C Documentation install-pdf
874
875 quick-install-doc:
876         $(MAKE) -C Documentation quick-install
877
878 quick-install-man:
879         $(MAKE) -C Documentation quick-install-man
880
881 quick-install-html:
882         $(MAKE) -C Documentation quick-install-html
883
884 ### Cleaning rules
885
886 clean:
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