Merge tag 'for-5.4-rc2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[linux-2.6-microblaze.git] / tools / perf / lib / Makefile
1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 # Most of this file is copied from tools/lib/bpf/Makefile
3
4 LIBPERF_VERSION = 0
5 LIBPERF_PATCHLEVEL = 0
6 LIBPERF_EXTRAVERSION = 1
7
8 MAKEFLAGS += --no-print-directory
9
10 ifeq ($(srctree),)
11 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 srctree := $(patsubst %/,%,$(dir $(srctree)))
14 #$(info Determined 'srctree' to be $(srctree))
15 endif
16
17 INSTALL = install
18
19 # Use DESTDIR for installing into a different root directory.
20 # This is useful for building a package. The program will be
21 # installed in this directory as if it was the root directory.
22 # Then the build tool can move it later.
23 DESTDIR ?=
24 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
25
26 include $(srctree)/tools/scripts/Makefile.include
27 include $(srctree)/tools/scripts/Makefile.arch
28
29 ifeq ($(LP64), 1)
30   libdir_relative = lib64
31 else
32   libdir_relative = lib
33 endif
34
35 prefix ?=
36 libdir = $(prefix)/$(libdir_relative)
37
38 # Shell quotes
39 libdir_SQ = $(subst ','\'',$(libdir))
40 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
41
42 ifeq ("$(origin V)", "command line")
43   VERBOSE = $(V)
44 endif
45 ifndef VERBOSE
46   VERBOSE = 0
47 endif
48
49 ifeq ($(VERBOSE),1)
50   Q =
51 else
52   Q = @
53 endif
54
55 # Set compile option CFLAGS
56 ifdef EXTRA_CFLAGS
57   CFLAGS := $(EXTRA_CFLAGS)
58 else
59   CFLAGS := -g -Wall
60 endif
61
62 INCLUDES = \
63 -I$(srctree)/tools/perf/lib/include \
64 -I$(srctree)/tools/lib/ \
65 -I$(srctree)/tools/include \
66 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \
67 -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
68 -I$(srctree)/tools/include/uapi
69
70 # Append required CFLAGS
71 override CFLAGS += $(EXTRA_WARNINGS)
72 override CFLAGS += -Werror -Wall
73 override CFLAGS += -fPIC
74 override CFLAGS += $(INCLUDES)
75 override CFLAGS += -fvisibility=hidden
76
77 all:
78
79 export srctree OUTPUT CC LD CFLAGS V
80 export DESTDIR DESTDIR_SQ
81
82 include $(srctree)/tools/build/Makefile.include
83
84 VERSION_SCRIPT := libperf.map
85
86 PATCHLEVEL    = $(LIBPERF_PATCHLEVEL)
87 EXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
88 VERSION       = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
89
90 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
91 LIBPERF_A  := $(OUTPUT)libperf.a
92 LIBPERF_IN := $(OUTPUT)libperf-in.o
93 LIBPERF_PC := $(OUTPUT)libperf.pc
94
95 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
96
97 LIB_DIR := $(srctree)/tools/lib/api/
98
99 ifneq ($(OUTPUT),)
100 ifneq ($(subdir),)
101   API_PATH=$(OUTPUT)/../lib/api/
102 else
103   API_PATH=$(OUTPUT)
104 endif
105 else
106   API_PATH=$(LIB_DIR)
107 endif
108
109 LIBAPI = $(API_PATH)libapi.a
110
111 $(LIBAPI): FORCE
112         $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
113
114 $(LIBAPI)-clean:
115         $(call QUIET_CLEAN, libapi)
116         $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
117
118 $(LIBPERF_IN): FORCE
119         $(Q)$(MAKE) $(build)=libperf
120
121 $(LIBPERF_A): $(LIBPERF_IN)
122         $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
123
124 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
125         $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
126                                     -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
127         @ln -sf $(@F) $(OUTPUT)libperf.so
128         @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
129
130
131 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
132
133 all: fixdep
134         $(Q)$(MAKE) libs
135
136 clean: $(LIBAPI)-clean
137         $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
138                 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
139         $(Q)$(MAKE) -C tests clean
140
141 tests: libs
142         $(Q)$(MAKE) -C tests
143         $(Q)$(MAKE) -C tests run
144
145 $(LIBPERF_PC):
146         $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
147                 -e "s|@LIBDIR@|$(libdir_SQ)|" \
148                 -e "s|@VERSION@|$(VERSION)|" \
149                 < libperf.pc.template > $@
150
151 define do_install_mkdir
152         if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
153                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
154         fi
155 endef
156
157 define do_install
158         if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
159                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
160         fi;                                             \
161         $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
162 endef
163
164 install_lib: libs
165         $(call QUIET_INSTALL, $(LIBPERF_ALL)) \
166                 $(call do_install_mkdir,$(libdir_SQ)); \
167                 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
168
169 install_headers:
170         $(call QUIET_INSTALL, headers) \
171                 $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
172                 $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
173                 $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
174                 $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
175                 $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644);
176                 $(call do_install,include/perf/event.h,$(prefix)/include/perf,644);
177
178 install_pkgconfig: $(LIBPERF_PC)
179         $(call QUIET_INSTALL, $(LIBPERF_PC)) \
180                 $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644)
181
182 install: install_lib install_headers install_pkgconfig
183
184 FORCE:
185
186 .PHONY: all install clean tests FORCE