2019-07-21 19:24:10 +08:00
|
|
|
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
|
|
|
# Most of this file is copied from tools/lib/bpf/Makefile
|
|
|
|
|
2019-07-21 19:24:11 +08:00
|
|
|
LIBPERF_VERSION = 0
|
|
|
|
LIBPERF_PATCHLEVEL = 0
|
|
|
|
LIBPERF_EXTRAVERSION = 1
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
MAKEFLAGS += --no-print-directory
|
|
|
|
|
|
|
|
ifeq ($(srctree),)
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
#$(info Determined 'srctree' to be $(srctree))
|
|
|
|
endif
|
|
|
|
|
2019-07-21 19:24:58 +08:00
|
|
|
INSTALL = install
|
|
|
|
|
|
|
|
# Use DESTDIR for installing into a different root directory.
|
|
|
|
# This is useful for building a package. The program will be
|
|
|
|
# installed in this directory as if it was the root directory.
|
|
|
|
# Then the build tool can move it later.
|
|
|
|
DESTDIR ?=
|
|
|
|
DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
include $(srctree)/tools/scripts/Makefile.include
|
|
|
|
include $(srctree)/tools/scripts/Makefile.arch
|
|
|
|
|
2019-07-21 19:24:58 +08:00
|
|
|
ifeq ($(LP64), 1)
|
|
|
|
libdir_relative = lib64
|
|
|
|
else
|
|
|
|
libdir_relative = lib
|
|
|
|
endif
|
|
|
|
|
|
|
|
prefix ?=
|
|
|
|
libdir = $(prefix)/$(libdir_relative)
|
|
|
|
|
|
|
|
# Shell quotes
|
|
|
|
libdir_SQ = $(subst ','\'',$(libdir))
|
|
|
|
libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
ifeq ("$(origin V)", "command line")
|
|
|
|
VERBOSE = $(V)
|
|
|
|
endif
|
|
|
|
ifndef VERBOSE
|
|
|
|
VERBOSE = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(VERBOSE),1)
|
|
|
|
Q =
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
endif
|
|
|
|
|
2021-07-06 23:16:58 +08:00
|
|
|
TEST_ARGS := $(if $(V),-v)
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
# Set compile option CFLAGS
|
|
|
|
ifdef EXTRA_CFLAGS
|
|
|
|
CFLAGS := $(EXTRA_CFLAGS)
|
|
|
|
else
|
|
|
|
CFLAGS := -g -Wall
|
|
|
|
endif
|
|
|
|
|
2019-08-19 05:02:58 +08:00
|
|
|
INCLUDES = \
|
2019-12-07 05:06:11 +08:00
|
|
|
-I$(srctree)/tools/lib/perf/include \
|
2019-08-19 05:02:58 +08:00
|
|
|
-I$(srctree)/tools/lib/ \
|
|
|
|
-I$(srctree)/tools/include \
|
|
|
|
-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
|
|
|
|
-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
|
|
|
|
-I$(srctree)/tools/include/uapi
|
2019-07-21 19:24:10 +08:00
|
|
|
|
|
|
|
# Append required CFLAGS
|
|
|
|
override CFLAGS += $(EXTRA_WARNINGS)
|
|
|
|
override CFLAGS += -Werror -Wall
|
|
|
|
override CFLAGS += -fPIC
|
|
|
|
override CFLAGS += $(INCLUDES)
|
|
|
|
override CFLAGS += -fvisibility=hidden
|
|
|
|
|
|
|
|
all:
|
|
|
|
|
|
|
|
export srctree OUTPUT CC LD CFLAGS V
|
2019-07-21 19:24:58 +08:00
|
|
|
export DESTDIR DESTDIR_SQ
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
include $(srctree)/tools/build/Makefile.include
|
|
|
|
|
2019-07-21 19:24:11 +08:00
|
|
|
VERSION_SCRIPT := libperf.map
|
|
|
|
|
|
|
|
PATCHLEVEL = $(LIBPERF_PATCHLEVEL)
|
|
|
|
EXTRAVERSION = $(LIBPERF_EXTRAVERSION)
|
|
|
|
VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
|
|
|
|
|
|
|
|
LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
|
2019-07-21 19:24:10 +08:00
|
|
|
LIBPERF_A := $(OUTPUT)libperf.a
|
|
|
|
LIBPERF_IN := $(OUTPUT)libperf-in.o
|
2019-07-21 19:24:58 +08:00
|
|
|
LIBPERF_PC := $(OUTPUT)libperf.pc
|
|
|
|
|
|
|
|
LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
|
2019-07-21 19:24:10 +08:00
|
|
|
|
2019-08-19 05:02:58 +08:00
|
|
|
LIB_DIR := $(srctree)/tools/lib/api/
|
|
|
|
|
|
|
|
ifneq ($(OUTPUT),)
|
|
|
|
ifneq ($(subdir),)
|
|
|
|
API_PATH=$(OUTPUT)/../lib/api/
|
|
|
|
else
|
|
|
|
API_PATH=$(OUTPUT)
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
API_PATH=$(LIB_DIR)
|
|
|
|
endif
|
|
|
|
|
|
|
|
LIBAPI = $(API_PATH)libapi.a
|
2019-10-17 18:59:12 +08:00
|
|
|
export LIBAPI
|
2019-08-19 05:02:58 +08:00
|
|
|
|
|
|
|
$(LIBAPI): FORCE
|
|
|
|
$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
|
|
|
|
|
|
|
|
$(LIBAPI)-clean:
|
|
|
|
$(call QUIET_CLEAN, libapi)
|
|
|
|
$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
$(LIBPERF_IN): FORCE
|
|
|
|
$(Q)$(MAKE) $(build)=libperf
|
|
|
|
|
|
|
|
$(LIBPERF_A): $(LIBPERF_IN)
|
|
|
|
$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
|
|
|
|
|
2019-08-19 05:02:58 +08:00
|
|
|
$(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
|
2019-07-21 19:24:11 +08:00
|
|
|
$(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
|
|
|
|
-Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
|
|
|
|
@ln -sf $(@F) $(OUTPUT)libperf.so
|
|
|
|
@ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
|
|
|
|
|
2019-07-21 19:24:10 +08:00
|
|
|
|
2019-07-21 19:24:58 +08:00
|
|
|
libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
|
2019-07-21 19:24:10 +08:00
|
|
|
|
|
|
|
all: fixdep
|
|
|
|
$(Q)$(MAKE) libs
|
|
|
|
|
2019-08-19 05:02:58 +08:00
|
|
|
clean: $(LIBAPI)-clean
|
2019-07-21 19:24:10 +08:00
|
|
|
$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
|
2021-07-06 23:16:58 +08:00
|
|
|
*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \
|
|
|
|
$(TESTS_STATIC) $(TESTS_SHARED)
|
|
|
|
|
|
|
|
TESTS_IN = tests-in.o
|
|
|
|
|
|
|
|
TESTS_STATIC = $(OUTPUT)tests-static
|
|
|
|
TESTS_SHARED = $(OUTPUT)tests-shared
|
|
|
|
|
|
|
|
$(TESTS_IN): FORCE
|
|
|
|
$(Q)$(MAKE) $(build)=tests
|
|
|
|
|
|
|
|
$(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
|
|
|
|
$(QUIET_LINK)$(CC) -o $@ $^
|
|
|
|
|
|
|
|
$(TESTS_SHARED): $(TESTS_IN) $(LIBAPI)
|
kbuild: replace $(if A,A,B) with $(or A,B)
$(or ...) is available since GNU Make 3.81, and useful to shorten the
code in some places.
Covert as follows:
$(if A,A,B) --> $(or A,B)
This patch also converts:
$(if A, A, B) --> $(or A, B)
Strictly speaking, the latter is not an equivalent conversion because
GNU Make keeps spaces after commas; if A is not empty, $(if A, A, B)
expands to " A", while $(or A, B) expands to "A".
Anyway, preceding spaces are not significant in the code hunks I touched.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
2022-02-11 13:14:11 +08:00
|
|
|
$(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTPUT),.) $^ -lperf
|
2021-07-06 23:16:58 +08:00
|
|
|
|
|
|
|
make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC)
|
2019-07-21 19:24:59 +08:00
|
|
|
|
2021-07-06 23:16:58 +08:00
|
|
|
tests: make-tests
|
|
|
|
@echo "running static:"
|
|
|
|
@./$(TESTS_STATIC) $(TEST_ARGS)
|
|
|
|
@echo "running dynamic:"
|
|
|
|
@LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS)
|
2019-07-21 19:24:58 +08:00
|
|
|
|
|
|
|
$(LIBPERF_PC):
|
|
|
|
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
|
|
|
|
-e "s|@LIBDIR@|$(libdir_SQ)|" \
|
|
|
|
-e "s|@VERSION@|$(VERSION)|" \
|
|
|
|
< libperf.pc.template > $@
|
|
|
|
|
|
|
|
define do_install_mkdir
|
|
|
|
if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
|
|
|
|
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
|
|
|
|
fi
|
|
|
|
endef
|
|
|
|
|
|
|
|
define do_install
|
2022-12-02 12:57:40 +08:00
|
|
|
if [ ! -d '$2' ]; then \
|
|
|
|
$(INSTALL) -d -m 755 '$2'; \
|
|
|
|
fi; \
|
|
|
|
$(INSTALL) $1 $(if $3,-m $3,) '$2'
|
2019-07-21 19:24:58 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
install_lib: libs
|
|
|
|
$(call QUIET_INSTALL, $(LIBPERF_ALL)) \
|
|
|
|
$(call do_install_mkdir,$(libdir_SQ)); \
|
|
|
|
cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
|
|
|
|
|
2022-12-02 12:57:40 +08:00
|
|
|
HDRS := bpf_perf.h core.h cpumap.h threadmap.h evlist.h evsel.h event.h mmap.h
|
2023-04-18 03:50:02 +08:00
|
|
|
INTERNAL_HDRS := cpumap.h evlist.h evsel.h lib.h mmap.h rc_check.h threadmap.h xyarray.h
|
2022-12-02 12:57:40 +08:00
|
|
|
|
|
|
|
INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/perf
|
|
|
|
INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS))
|
|
|
|
INSTALL_INTERNAL_HDRS_PFX := $(DESTDIR)$(prefix)/include/internal
|
|
|
|
INSTALL_INTERNAL_HDRS := $(addprefix $(INSTALL_INTERNAL_HDRS_PFX)/, $(INTERNAL_HDRS))
|
|
|
|
|
|
|
|
$(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: include/perf/%.h
|
|
|
|
$(call QUIET_INSTALL, $@) \
|
|
|
|
$(call do_install,$<,$(INSTALL_HDRS_PFX)/,644)
|
|
|
|
|
|
|
|
$(INSTALL_INTERNAL_HDRS): $(INSTALL_INTERNAL_HDRS_PFX)/%.h: include/internal/%.h
|
|
|
|
$(call QUIET_INSTALL, $@) \
|
|
|
|
$(call do_install,$<,$(INSTALL_INTERNAL_HDRS_PFX)/,644)
|
|
|
|
|
|
|
|
install_headers: $(INSTALL_HDRS) $(INSTALL_INTERNAL_HDRS)
|
|
|
|
$(call QUIET_INSTALL, libperf_headers)
|
2019-07-21 19:24:58 +08:00
|
|
|
|
|
|
|
install_pkgconfig: $(LIBPERF_PC)
|
|
|
|
$(call QUIET_INSTALL, $(LIBPERF_PC)) \
|
2022-12-16 17:50:41 +08:00
|
|
|
$(call do_install,$(LIBPERF_PC),$(DESTDIR_SQ)$(libdir_SQ)/pkgconfig,644)
|
2019-07-21 19:24:58 +08:00
|
|
|
|
2019-12-07 05:06:12 +08:00
|
|
|
install_doc:
|
|
|
|
$(Q)$(MAKE) -C Documentation install-man install-html install-examples
|
|
|
|
|
|
|
|
install: install_lib install_headers install_pkgconfig install_doc
|
2019-07-21 19:24:10 +08:00
|
|
|
|
|
|
|
FORCE:
|
|
|
|
|
2019-07-21 19:24:59 +08:00
|
|
|
.PHONY: all install clean tests FORCE
|