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 # Set compile option CFLAGS
57 CFLAGS := $(EXTRA_CFLAGS)
63 -I$(srctree)/tools/lib/perf/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
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
79 export srctree OUTPUT CC LD CFLAGS V
80 export DESTDIR DESTDIR_SQ
82 include $(srctree)/tools/build/Makefile.include
84 VERSION_SCRIPT := libperf.map
86 PATCHLEVEL = $(LIBPERF_PATCHLEVEL)
87 EXTRAVERSION = $(LIBPERF_EXTRAVERSION)
88 VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
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
95 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
97 LIB_DIR := $(srctree)/tools/lib/api/
101 API_PATH=$(OUTPUT)/../lib/api/
109 LIBAPI = $(API_PATH)libapi.a
113 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
116 $(call QUIET_CLEAN, libapi)
117 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
120 $(Q)$(MAKE) $(build)=libperf
122 $(LIBPERF_A): $(LIBPERF_IN)
123 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
125 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
126 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
127 -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
128 @ln -sf $(@F) $(OUTPUT)libperf.so
129 @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
132 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
137 clean: $(LIBAPI)-clean
138 $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
139 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
140 $(Q)$(MAKE) -C tests clean
144 $(Q)$(MAKE) -C tests run
147 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
148 -e "s|@LIBDIR@|$(libdir_SQ)|" \
149 -e "s|@VERSION@|$(VERSION)|" \
150 < libperf.pc.template > $@
152 define do_install_mkdir
153 if [ ! -d '$(DESTDIR_SQ
)$1' ]; then \
154 $(INSTALL) -d -m 755 '$(DESTDIR_SQ
)$1'; \
159 if [ ! -d '$(DESTDIR_SQ
)$2' ]; then \
160 $(INSTALL) -d -m 755 '$(DESTDIR_SQ
)$2'; \
162 $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ
)$2'
166 $(call QUIET_INSTALL, $(LIBPERF_ALL)) \
167 $(call do_install_mkdir,$(libdir_SQ)); \
168 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
171 $(call QUIET_INSTALL, headers) \
172 $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
173 $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
174 $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
175 $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
176 $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \
177 $(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \
178 $(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644);
180 install_pkgconfig: $(LIBPERF_PC)
181 $(call QUIET_INSTALL, $(LIBPERF_PC)) \
182 $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644)
185 $(Q)$(MAKE) -C Documentation install-man install-html install-examples
187 install: install_lib install_headers install_pkgconfig install_doc
191 .PHONY: all install clean tests FORCE