1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
2 # Most of this file is copied from tools/lib/bpf/Makefile
6 LIBPERF_EXTRAVERSION
= 1
8 MAKEFLAGS
+= --no-print-directory
11 srctree
:= $(patsubst %/,%,$(dir $(CURDIR
)))
12 srctree
:= $(patsubst %/,%,$(dir $(srctree
)))
13 srctree
:= $(patsubst %/,%,$(dir $(srctree
)))
14 #$(info Determined 'srctree' to be $(srctree))
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.
24 DESTDIR_SQ
= '$(subst ','\'',$(DESTDIR
))'
26 include $(srctree)/tools/scripts/Makefile.include
27 include $(srctree)/tools/scripts/Makefile.arch
30 libdir_relative = lib64
36 libdir = $(prefix)/$(libdir_relative)
39 libdir_SQ = $(subst ','\'',$(libdir))
40 libdir_relative_SQ
= $(subst ','\'',$(libdir_relative))
42 ifeq ("$(origin V)", "command line")
55 TEST_ARGS := $(if $(V),-v)
57 # Set compile option CFLAGS
59 CFLAGS := $(EXTRA_CFLAGS)
65 -I$(srctree)/tools/lib/perf/include \
66 -I$(srctree)/tools/lib/ \
67 -I$(srctree)/tools/include \
68 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \
69 -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
70 -I$(srctree)/tools/include/uapi
72 # Append required CFLAGS
73 override CFLAGS += $(EXTRA_WARNINGS)
74 override CFLAGS += -Werror -Wall
75 override CFLAGS += -fPIC
76 override CFLAGS += $(INCLUDES)
77 override CFLAGS += -fvisibility=hidden
81 export srctree OUTPUT CC LD CFLAGS V
82 export DESTDIR DESTDIR_SQ
84 include $(srctree)/tools/build/Makefile.include
86 VERSION_SCRIPT := libperf.map
88 PATCHLEVEL = $(LIBPERF_PATCHLEVEL)
89 EXTRAVERSION = $(LIBPERF_EXTRAVERSION)
90 VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
92 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
93 LIBPERF_A := $(OUTPUT)libperf.a
94 LIBPERF_IN := $(OUTPUT)libperf-in.o
95 LIBPERF_PC := $(OUTPUT)libperf.pc
97 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
99 LIB_DIR := $(srctree)/tools/lib/api/
103 API_PATH=$(OUTPUT)/../lib/api/
111 LIBAPI = $(API_PATH)libapi.a
115 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
118 $(call QUIET_CLEAN, libapi)
119 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
122 $(Q)$(MAKE) $(build)=libperf
124 $(LIBPERF_A): $(LIBPERF_IN)
125 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
127 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
128 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
129 -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
130 @ln -sf $(@F) $(OUTPUT)libperf.so
131 @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
134 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
139 clean: $(LIBAPI)-clean
140 $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
141 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \
142 $(TESTS_STATIC) $(TESTS_SHARED)
144 TESTS_IN = tests-in.o
146 TESTS_STATIC = $(OUTPUT)tests-static
147 TESTS_SHARED = $(OUTPUT)tests-shared
150 $(Q)$(MAKE) $(build)=tests
152 $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
153 $(QUIET_LINK)$(CC) -o $@ $^
155 $(TESTS_SHARED): $(TESTS_IN) $(LIBAPI)
156 $(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTPUT),.) $^ -lperf
158 make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC)
161 @echo "running static:"
162 @./$(TESTS_STATIC) $(TEST_ARGS)
163 @echo "running dynamic:"
164 @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS)
167 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
168 -e "s|@LIBDIR@|$(libdir_SQ)|" \
169 -e "s|@VERSION@|$(VERSION)|" \
170 < libperf.pc.template > $@
172 define do_install_mkdir
173 if [ ! -d '$(DESTDIR_SQ
)$1' ]; then \
174 $(INSTALL) -d -m 755 '$(DESTDIR_SQ
)$1'; \
179 if [ ! -d '$2' ]; then \
180 $(INSTALL) -d -m 755 '$2'; \
182 $(INSTALL) $1 $(if $3,-m $3,) '$2'
186 $(call QUIET_INSTALL, $(LIBPERF_ALL)) \
187 $(call do_install_mkdir,$(libdir_SQ)); \
188 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
190 HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h
191 INTERNAL_HDRS := cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threadmap.h xyarray.h
193 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/perf
194 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
195 INSTALL_INTERNAL_HDRS_PFX := $(DESTDIR)$(prefix)/include/internal
196 INSTALL_INTERNAL_HDRS := $(addprefix $(INSTALL_INTERNAL_HDRS_PFX)/, $(INTERNAL_HDRS))
198 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: include/perf/%.h
199 $(call QUIET_INSTALL, $@) \
200 $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
202 $(INSTALL_INTERNAL_HDRS): $(INSTALL_INTERNAL_HDRS_PFX)/%.h: include/internal/%.h
203 $(call QUIET_INSTALL, $@) \
204 $(call do_install,$<,$(INSTALL_INTERNAL_HDRS_PFX)/,644)
206 install_headers: $(INSTALL_HDRS) $(INSTALL_INTERNAL_HDRS)
207 $(call QUIET_INSTALL, libperf_headers)
209 install_pkgconfig: $(LIBPERF_PC)
210 $(call QUIET_INSTALL, $(LIBPERF_PC)) \
211 $(call do_install,$(LIBPERF_PC),$(DESTDIR_SQ)$(libdir_SQ)/pkgconfig,644)
214 $(Q)$(MAKE) -C Documentation install-man install-html install-examples
216 install: install_lib install_headers install_pkgconfig install_doc
220 .PHONY: all install clean tests FORCE