perf tools: Merge all *LDFLAGS* make variable into LDFLAGS
[linux-2.6-block.git] / tools / perf / config / Makefile
CommitLineData
8bd407b9
JO
1uname_M := $(shell uname -m 2>/dev/null || echo not)
2
3ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ \
4 -e s/arm.*/arm/ -e s/sa110/arm/ \
5 -e s/s390x/s390/ -e s/parisc64/parisc/ \
6 -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
7 -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
8NO_PERF_REGS := 1
9c12cf95 9CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS)
8bd407b9
JO
10
11# Additional ARCH settings for x86
12ifeq ($(ARCH),i386)
13 override ARCH := x86
14 NO_PERF_REGS := 0
15 LIBUNWIND_LIBS = -lunwind -lunwind-x86
16endif
17
18ifeq ($(ARCH),x86_64)
19 override ARCH := x86
20 IS_X86_64 := 0
9c12cf95 21 ifeq (, $(findstring m32,$(CFLAGS)))
8bd407b9
JO
22 IS_X86_64 := $(shell echo __x86_64__ | ${CC} -E -x c - | tail -n 1)
23 endif
24 ifeq (${IS_X86_64}, 1)
25 RAW_ARCH := x86_64
9c12cf95 26 CFLAGS += -DARCH_X86_64
8bd407b9
JO
27 ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
28 endif
29 NO_PERF_REGS := 0
30 LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
31endif
32
33ifeq ($(NO_PERF_REGS),0)
9c12cf95 34 CFLAGS += -DHAVE_PERF_REGS
8bd407b9 35endif
a32f4936
JO
36
37-include config/feature-tests.mak
38
39ifeq ($(call get-executable,$(FLEX)),)
40 dummy := $(error Error: $(FLEX) is missing on this system, please install it)
41endif
42
43ifeq ($(call get-executable,$(BISON)),)
44 dummy := $(error Error: $(BISON) is missing on this system, please install it)
45endif
362493f0
JO
46
47# Treat warnings as errors unless directed not to
48ifneq ($(WERROR),0)
9c12cf95 49 CFLAGS += -Werror
362493f0
JO
50endif
51
52ifeq ("$(origin DEBUG)", "command line")
53 PERF_DEBUG = $(DEBUG)
54endif
55ifndef PERF_DEBUG
9c12cf95 56 CFLAGS += -O6
362493f0
JO
57endif
58
59ifdef PARSER_DEBUG
9c12cf95
JO
60 PARSER_DEBUG_BISON := -t
61 PARSER_DEBUG_FLEX := -d
62 CFLAGS += -DPARSER_DEBUG
362493f0
JO
63endif
64
9c12cf95
JO
65CFLAGS += \
66 -fno-omit-frame-pointer \
67 -ggdb3 \
68 -funwind-tables \
69 -Wall \
70 -Wextra \
71 -std=gnu99
72
362493f0 73EXTLIBS = -lpthread -lrt -lelf -lm
362493f0
JO
74
75ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y)
9c12cf95 76 CFLAGS += -fstack-protector-all
362493f0
JO
77endif
78
79ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wstack-protector,-Wstack-protector),y)
9c12cf95 80 CFLAGS += -Wstack-protector
362493f0
JO
81endif
82
83ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -Wvolatile-register-var,-Wvolatile-register-var),y)
9c12cf95 84 CFLAGS += -Wvolatile-register-var
362493f0
JO
85endif
86
87ifndef PERF_DEBUG
88 ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -D_FORTIFY_SOURCE=2,-D_FORTIFY_SOURCE=2),y)
9c12cf95 89 CFLAGS += -D_FORTIFY_SOURCE=2
362493f0
JO
90 endif
91endif
92
9c12cf95 93CFLAGS += \
362493f0
JO
94 -Iutil/include \
95 -Iarch/$(ARCH)/include \
96 $(if $(objtree),-I$(objtree)/arch/$(ARCH)/include/generated/uapi) \
97 -I$(srctree)/arch/$(ARCH)/include/uapi \
98 -I$(srctree)/arch/$(ARCH)/include \
99 $(if $(objtree),-I$(objtree)/include/generated/uapi) \
100 -I$(srctree)/include/uapi \
101 -I$(srctree)/include \
102 -I$(OUTPUT)util \
103 -Iutil \
104 -I. \
105 -I$(TRACE_EVENT_DIR) \
106 -I../lib/ \
107 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
108
362493f0
JO
109ifeq ($(call try-cc,$(SOURCE_BIONIC),$(CFLAGS),bionic),y)
110 BIONIC := 1
111 EXTLIBS := $(filter-out -lrt,$(EXTLIBS))
112 EXTLIBS := $(filter-out -lpthread,$(EXTLIBS))
362493f0 113endif
cf4cca10
JO
114
115ifdef NO_LIBELF
116 NO_DWARF := 1
117 NO_DEMANGLE := 1
118 NO_LIBUNWIND := 1
119else
1e9f7aad 120FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
cf4cca10 121ifneq ($(call try-cc,$(SOURCE_LIBELF),$(FLAGS_LIBELF),libelf),y)
1e9f7aad 122 FLAGS_GLIBC=$(CFLAGS) $(LDFLAGS)
cf4cca10
JO
123 ifeq ($(call try-cc,$(SOURCE_GLIBC),$(FLAGS_GLIBC),glibc),y)
124 LIBC_SUPPORT := 1
125 endif
126 ifeq ($(BIONIC),1)
127 LIBC_SUPPORT := 1
128 endif
129 ifeq ($(LIBC_SUPPORT),1)
130 msg := $(warning No libelf found, disables 'probe' tool, please install elfutils-libelf-devel/libelf-dev);
131
132 NO_LIBELF := 1
133 NO_DWARF := 1
134 NO_DEMANGLE := 1
135 else
136 msg := $(error No gnu/libc-version.h found, please install glibc-dev[el]/glibc-static);
137 endif
138else
139 # for linking with debug library, run like:
140 # make DEBUG=1 LIBDW_DIR=/opt/libdw/
141 ifdef LIBDW_DIR
142 LIBDW_CFLAGS := -I$(LIBDW_DIR)/include
143 LIBDW_LDFLAGS := -L$(LIBDW_DIR)/lib
144 endif
145
1e9f7aad 146 FLAGS_DWARF=$(CFLAGS) $(LIBDW_CFLAGS) -ldw -lelf $(LIBDW_LDFLAGS) $(LDFLAGS) $(EXTLIBS)
cf4cca10
JO
147 ifneq ($(call try-cc,$(SOURCE_DWARF),$(FLAGS_DWARF),libdw),y)
148 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);
149 NO_DWARF := 1
150 endif # Dwarf support
151endif # SOURCE_LIBELF
152endif # NO_LIBELF
153
154ifndef NO_LIBELF
9c12cf95 155CFLAGS += -DLIBELF_SUPPORT
1e9f7aad 156FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
cf4cca10 157ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
9c12cf95 158 CFLAGS += -DLIBELF_MMAP
cf4cca10 159endif
779724fd
JO
160
161# include ARCH specific config
162-include arch/$(ARCH)/Makefile
163
164ifndef NO_DWARF
165ifeq ($(origin PERF_HAVE_DWARF_REGS), undefined)
166 msg := $(warning DWARF register mappings have not been defined for architecture $(ARCH), DWARF support disabled);
167 NO_DWARF := 1
168else
9c12cf95 169 CFLAGS += -DDWARF_SUPPORT $(LIBDW_CFLAGS)
1e9f7aad 170 LDFLAGS += $(LIBDW_LDFLAGS)
779724fd
JO
171 EXTLIBS += -lelf -ldw
172endif # PERF_HAVE_DWARF_REGS
173endif # NO_DWARF
174
cf4cca10 175endif # NO_LIBELF
0e433feb 176
1e9f7aad
JO
177ifndef NO_LIBELF
178CFLAGS += -DLIBELF_SUPPORT
179FLAGS_LIBELF=$(CFLAGS) $(LDFLAGS) $(EXTLIBS)
180ifeq ($(call try-cc,$(SOURCE_ELF_MMAP),$(FLAGS_LIBELF),-DLIBELF_MMAP),y)
181 CFLAGS += -DLIBELF_MMAP
182endif # try-cc
183endif # NO_LIBELF
184
0e433feb
JO
185# There's only x86 (both 32 and 64) support for CFI unwind so far
186ifneq ($(ARCH),x86)
187 NO_LIBUNWIND := 1
188endif
189
190ifndef NO_LIBUNWIND
191# for linking with debug library, run like:
192# make DEBUG=1 LIBUNWIND_DIR=/opt/libunwind/
193ifdef LIBUNWIND_DIR
194 LIBUNWIND_CFLAGS := -I$(LIBUNWIND_DIR)/include
195 LIBUNWIND_LDFLAGS := -L$(LIBUNWIND_DIR)/lib
196endif
197
1e9f7aad 198FLAGS_UNWIND=$(LIBUNWIND_CFLAGS) $(CFLAGS) $(LIBUNWIND_LDFLAGS) $(LDFLAGS) $(EXTLIBS) $(LIBUNWIND_LIBS)
0e433feb
JO
199ifneq ($(call try-cc,$(SOURCE_LIBUNWIND),$(FLAGS_UNWIND),libunwind),y)
200 msg := $(warning No libunwind found, disabling post unwind support. Please install libunwind-dev[el] >= 0.99);
201 NO_LIBUNWIND := 1
202endif # Libunwind support
203endif # NO_LIBUNWIND
204
205ifndef NO_LIBUNWIND
9c12cf95 206 CFLAGS += -DLIBUNWIND_SUPPORT
0e433feb 207 EXTLIBS += $(LIBUNWIND_LIBS)
9c12cf95 208 CFLAGS += $(LIBUNWIND_CFLAGS)
1e9f7aad 209 LDFLAGS += $(LIBUNWIND_LDFLAGS)
0e433feb 210endif # NO_LIBUNWIND
a8279525
JO
211
212ifndef NO_LIBAUDIT
1e9f7aad 213 FLAGS_LIBAUDIT = $(CFLAGS) $(LDFLAGS) -laudit
a8279525
JO
214 ifneq ($(call try-cc,$(SOURCE_LIBAUDIT),$(FLAGS_LIBAUDIT),libaudit),y)
215 msg := $(warning No libaudit.h found, disables 'trace' tool, please install audit-libs-devel or libaudit-dev);
216 NO_LIBAUDIT := 1
217 else
9c12cf95 218 CFLAGS += -DLIBAUDIT_SUPPORT
a8279525
JO
219 EXTLIBS += -laudit
220 endif
221endif
4a8f888a
JO
222
223ifdef NO_NEWT
224 NO_SLANG=1
225endif
226
227ifndef NO_SLANG
1e9f7aad 228 FLAGS_SLANG=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -I/usr/include/slang -lslang
4a8f888a
JO
229 ifneq ($(call try-cc,$(SOURCE_SLANG),$(FLAGS_SLANG),libslang),y)
230 msg := $(warning slang not found, disables TUI support. Please install slang-devel or libslang-dev);
231 NO_SLANG := 1
232 else
233 # Fedora has /usr/include/slang/slang.h, but ubuntu /usr/include/slang.h
9c12cf95
JO
234 CFLAGS += -I/usr/include/slang
235 CFLAGS += -DSLANG_SUPPORT
4a8f888a
JO
236 EXTLIBS += -lslang
237 endif
238endif
58cabf6a
JO
239
240ifndef NO_GTK2
1e9f7aad 241 FLAGS_GTK2=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null)
58cabf6a
JO
242 ifneq ($(call try-cc,$(SOURCE_GTK2),$(FLAGS_GTK2),gtk2),y)
243 msg := $(warning GTK2 not found, disables GTK2 support. Please install gtk2-devel or libgtk2.0-dev);
244 NO_GTK2 := 1
245 else
246 ifeq ($(call try-cc,$(SOURCE_GTK2_INFOBAR),$(FLAGS_GTK2),-DHAVE_GTK_INFO_BAR),y)
9c12cf95 247 CFLAGS += -DHAVE_GTK_INFO_BAR
58cabf6a 248 endif
9c12cf95
JO
249 CFLAGS += -DGTK2_SUPPORT
250 CFLAGS += $(shell pkg-config --cflags gtk+-2.0 2>/dev/null)
58cabf6a
JO
251 EXTLIBS += $(shell pkg-config --libs gtk+-2.0 2>/dev/null)
252 endif
253endif
3082cb33
JO
254
255grep-libs = $(filter -l%,$(1))
256strip-libs = $(filter-out -l%,$(1))
257
258ifdef NO_LIBPERL
9c12cf95 259 CFLAGS += -DNO_LIBPERL
3082cb33
JO
260else
261 PERL_EMBED_LDOPTS = $(shell perl -MExtUtils::Embed -e ldopts 2>/dev/null)
262 PERL_EMBED_LDFLAGS = $(call strip-libs,$(PERL_EMBED_LDOPTS))
263 PERL_EMBED_LIBADD = $(call grep-libs,$(PERL_EMBED_LDOPTS))
264 PERL_EMBED_CCOPTS = `perl -MExtUtils::Embed -e ccopts 2>/dev/null`
265 FLAGS_PERL_EMBED=$(PERL_EMBED_CCOPTS) $(PERL_EMBED_LDOPTS)
266
267 ifneq ($(call try-cc,$(SOURCE_PERL_EMBED),$(FLAGS_PERL_EMBED),perl),y)
9c12cf95 268 CFLAGS += -DNO_LIBPERL
3082cb33
JO
269 NO_LIBPERL := 1
270 else
1e9f7aad 271 LDFLAGS += $(PERL_EMBED_LDFLAGS)
3082cb33
JO
272 EXTLIBS += $(PERL_EMBED_LIBADD)
273 endif
274endif
6e533cf1
JO
275
276disable-python = $(eval $(disable-python_code))
277define disable-python_code
9c12cf95 278 CFLAGS += -DNO_LIBPYTHON
6e533cf1
JO
279 $(if $(1),$(warning No $(1) was found))
280 $(warning Python support will not be built)
281 NO_LIBPYTHON := 1
282endef
283
284override PYTHON := \
285 $(call get-executable-or-default,PYTHON,python)
286
287ifndef PYTHON
288 $(call disable-python,python interpreter)
289else
290
291 PYTHON_WORD := $(call shell-wordify,$(PYTHON))
292
293 ifdef NO_LIBPYTHON
294 $(call disable-python)
295 else
296
297 override PYTHON_CONFIG := \
298 $(call get-executable-or-default,PYTHON_CONFIG,$(PYTHON)-config)
299
300 ifndef PYTHON_CONFIG
301 $(call disable-python,python-config tool)
302 else
303
304 PYTHON_CONFIG_SQ := $(call shell-sq,$(PYTHON_CONFIG))
305
306 PYTHON_EMBED_LDOPTS := $(shell $(PYTHON_CONFIG_SQ) --ldflags 2>/dev/null)
307 PYTHON_EMBED_LDFLAGS := $(call strip-libs,$(PYTHON_EMBED_LDOPTS))
308 PYTHON_EMBED_LIBADD := $(call grep-libs,$(PYTHON_EMBED_LDOPTS))
309 PYTHON_EMBED_CCOPTS := $(shell $(PYTHON_CONFIG_SQ) --cflags 2>/dev/null)
310 FLAGS_PYTHON_EMBED := $(PYTHON_EMBED_CCOPTS) $(PYTHON_EMBED_LDOPTS)
311
312 ifneq ($(call try-cc,$(SOURCE_PYTHON_EMBED),$(FLAGS_PYTHON_EMBED),python),y)
313 $(call disable-python,Python.h (for Python 2.x))
314 else
315
316 ifneq ($(call try-cc,$(SOURCE_PYTHON_VERSION),$(FLAGS_PYTHON_EMBED),python version),y)
317 $(warning Python 3 is not yet supported; please set)
318 $(warning PYTHON and/or PYTHON_CONFIG appropriately.)
319 $(warning If you also have Python 2 installed, then)
320 $(warning try something like:)
321 $(warning $(and ,))
322 $(warning $(and ,) make PYTHON=python2)
323 $(warning $(and ,))
324 $(warning Otherwise, disable Python support entirely:)
325 $(warning $(and ,))
326 $(warning $(and ,) make NO_LIBPYTHON=1)
327 $(warning $(and ,))
328 $(error $(and ,))
329 else
1e9f7aad 330 LDFLAGS += $(PYTHON_EMBED_LDFLAGS)
6e533cf1
JO
331 EXTLIBS += $(PYTHON_EMBED_LIBADD)
332 LANG_BINDINGS += $(OUTPUT)python/perf.so
333 endif
334 endif
335 endif
336 endif
337endif
c3cf8368
JO
338
339ifdef NO_DEMANGLE
9c12cf95 340 CFLAGS += -DNO_DEMANGLE
c3cf8368
JO
341else
342 ifdef HAVE_CPLUS_DEMANGLE
343 EXTLIBS += -liberty
9c12cf95 344 CFLAGS += -DHAVE_CPLUS_DEMANGLE
c3cf8368 345 else
1e9f7aad 346 FLAGS_BFD=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -DPACKAGE='perf' -lbfd
c3cf8368
JO
347 has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD),libbfd)
348 ifeq ($(has_bfd),y)
349 EXTLIBS += -lbfd
350 else
351 FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
352 has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY),liberty)
353 ifeq ($(has_bfd_iberty),y)
354 EXTLIBS += -lbfd -liberty
355 else
356 FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
357 has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z),libz)
358 ifeq ($(has_bfd_iberty_z),y)
359 EXTLIBS += -lbfd -liberty -lz
360 else
1e9f7aad 361 FLAGS_CPLUS_DEMANGLE=$(CFLAGS) $(LDFLAGS) $(EXTLIBS) -liberty
c3cf8368
JO
362 has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE),demangle)
363 ifeq ($(has_cplus_demangle),y)
364 EXTLIBS += -liberty
9c12cf95 365 CFLAGS += -DHAVE_CPLUS_DEMANGLE
c3cf8368
JO
366 else
367 msg := $(warning No bfd.h/libbfd found, install binutils-dev[el]/zlib-static to gain symbol demangling)
9c12cf95 368 CFLAGS += -DNO_DEMANGLE
c3cf8368
JO
369 endif
370 endif
371 endif
372 endif
373 endif
374endif
a1c7c9e7
JO
375
376ifndef NO_STRLCPY
377 ifeq ($(call try-cc,$(SOURCE_STRLCPY),,-DHAVE_STRLCPY),y)
9c12cf95 378 CFLAGS += -DHAVE_STRLCPY
a1c7c9e7
JO
379 endif
380endif
381
382ifndef NO_ON_EXIT
383 ifeq ($(call try-cc,$(SOURCE_ON_EXIT),,-DHAVE_ON_EXIT),y)
9c12cf95 384 CFLAGS += -DHAVE_ON_EXIT
a1c7c9e7
JO
385 endif
386endif
387
388ifndef NO_BACKTRACE
389 ifeq ($(call try-cc,$(SOURCE_BACKTRACE),,-DBACKTRACE_SUPPORT),y)
9c12cf95 390 CFLAGS += -DBACKTRACE_SUPPORT
a1c7c9e7
JO
391 endif
392endif
58a0abd7
JO
393
394ifndef NO_LIBNUMA
1e9f7aad 395 FLAGS_LIBNUMA = $(CFLAGS) $(LDFLAGS) -lnuma
58a0abd7
JO
396 ifneq ($(call try-cc,$(SOURCE_LIBNUMA),$(FLAGS_LIBNUMA),libnuma),y)
397 msg := $(warning No numa.h found, disables 'perf bench numa mem' benchmark, please install numa-libs-devel or libnuma-dev);
398 NO_LIBNUMA := 1
399 else
9c12cf95 400 CFLAGS += -DLIBNUMA_SUPPORT
58a0abd7
JO
401 EXTLIBS += -lnuma
402 endif
403endif
cd1c39f2
JO
404
405# Among the variables below, these:
406# perfexecdir
407# template_dir
408# mandir
409# infodir
410# htmldir
411# ETC_PERFCONFIG (but not sysconfdir)
412# can be specified as a relative path some/where/else;
413# this is interpreted as relative to $(prefix) and "perf" at
414# runtime figures out where they are based on the path to the executable.
415# This can help installing the suite in a relocatable way.
416
417# Make the path relative to DESTDIR, not to prefix
418ifndef DESTDIR
419prefix = $(HOME)
420endif
421bindir_relative = bin
422bindir = $(prefix)/$(bindir_relative)
423mandir = share/man
424infodir = share/info
425perfexecdir = libexec/perf-core
426sharedir = $(prefix)/share
427template_dir = share/perf-core/templates
428htmldir = share/doc/perf-doc
429ifeq ($(prefix),/usr)
430sysconfdir = /etc
431ETC_PERFCONFIG = $(sysconfdir)/perfconfig
432else
433sysconfdir = $(prefix)/etc
434ETC_PERFCONFIG = etc/perfconfig
435endif
436lib = lib
437
438# Shell quote (do not use $(call) to accommodate ancient setups);
439ETC_PERFCONFIG_SQ = $(subst ','\'',$(ETC_PERFCONFIG))
440DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
441bindir_SQ = $(subst ','\'',$(bindir))
442mandir_SQ = $(subst ','\'',$(mandir))
443infodir_SQ = $(subst ','\'',$(infodir))
444perfexecdir_SQ = $(subst ','\'',$(perfexecdir))
445template_dir_SQ = $(subst ','\'',$(template_dir))
446htmldir_SQ = $(subst ','\'',$(htmldir))
447prefix_SQ = $(subst ','\'',$(prefix))
448sysconfdir_SQ = $(subst ','\'',$(sysconfdir))
449
450ifneq ($(filter /%,$(firstword $(perfexecdir))),)
451perfexec_instdir = $(perfexecdir)
452else
453perfexec_instdir = $(prefix)/$(perfexecdir)
454endif
455perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir))