1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2- 1 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2 # Most of this file is copied from tools/lib/b 2 # Most of this file is copied from tools/lib/bpf/Makefile 3 3 4 LIBPERF_VERSION = 0 4 LIBPERF_VERSION = 0 5 LIBPERF_PATCHLEVEL = 0 5 LIBPERF_PATCHLEVEL = 0 6 LIBPERF_EXTRAVERSION = 1 6 LIBPERF_EXTRAVERSION = 1 7 7 8 MAKEFLAGS += --no-print-directory 8 MAKEFLAGS += --no-print-directory 9 9 10 ifeq ($(srctree),) 10 ifeq ($(srctree),) 11 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 11 srctree := $(patsubst %/,%,$(dir $(CURDIR))) 12 srctree := $(patsubst %/,%,$(dir $(srctree))) 12 srctree := $(patsubst %/,%,$(dir $(srctree))) 13 srctree := $(patsubst %/,%,$(dir $(srctree))) 13 srctree := $(patsubst %/,%,$(dir $(srctree))) 14 #$(info Determined 'srctree' to be $(srctree)) 14 #$(info Determined 'srctree' to be $(srctree)) 15 endif 15 endif 16 16 17 INSTALL = install 17 INSTALL = install 18 18 19 # Use DESTDIR for installing into a different 19 # Use DESTDIR for installing into a different root directory. 20 # This is useful for building a package. The p 20 # This is useful for building a package. The program will be 21 # installed in this directory as if it was the 21 # installed in this directory as if it was the root directory. 22 # Then the build tool can move it later. 22 # Then the build tool can move it later. 23 DESTDIR ?= 23 DESTDIR ?= 24 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 24 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 25 25 26 include $(srctree)/tools/scripts/Makefile.incl 26 include $(srctree)/tools/scripts/Makefile.include 27 include $(srctree)/tools/scripts/Makefile.arch 27 include $(srctree)/tools/scripts/Makefile.arch 28 28 29 ifeq ($(LP64), 1) 29 ifeq ($(LP64), 1) 30 libdir_relative = lib64 30 libdir_relative = lib64 31 else 31 else 32 libdir_relative = lib 32 libdir_relative = lib 33 endif 33 endif 34 34 35 prefix ?= 35 prefix ?= 36 libdir = $(prefix)/$(libdir_relative) 36 libdir = $(prefix)/$(libdir_relative) 37 37 38 # Shell quotes 38 # Shell quotes 39 libdir_SQ = $(subst ','\'',$(libdir)) 39 libdir_SQ = $(subst ','\'',$(libdir)) 40 libdir_relative_SQ = $(subst ','\'',$(libdir_r 40 libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) 41 41 42 ifeq ("$(origin V)", "command line") 42 ifeq ("$(origin V)", "command line") 43 VERBOSE = $(V) 43 VERBOSE = $(V) 44 endif 44 endif 45 ifndef VERBOSE 45 ifndef VERBOSE 46 VERBOSE = 0 46 VERBOSE = 0 47 endif 47 endif 48 48 49 ifeq ($(VERBOSE),1) 49 ifeq ($(VERBOSE),1) 50 Q = 50 Q = 51 else 51 else 52 Q = @ 52 Q = @ 53 endif 53 endif 54 54 55 TEST_ARGS := $(if $(V),-v) 55 TEST_ARGS := $(if $(V),-v) 56 56 57 # Set compile option CFLAGS 57 # Set compile option CFLAGS 58 ifdef EXTRA_CFLAGS 58 ifdef EXTRA_CFLAGS 59 CFLAGS := $(EXTRA_CFLAGS) 59 CFLAGS := $(EXTRA_CFLAGS) 60 else 60 else 61 CFLAGS := -g -Wall 61 CFLAGS := -g -Wall 62 endif 62 endif 63 63 64 INCLUDES = \ 64 INCLUDES = \ 65 -I$(srctree)/tools/lib/perf/include \ 65 -I$(srctree)/tools/lib/perf/include \ 66 -I$(srctree)/tools/lib/ \ 66 -I$(srctree)/tools/lib/ \ 67 -I$(srctree)/tools/include \ 67 -I$(srctree)/tools/include \ 68 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \ 68 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \ 69 -I$(srctree)/tools/arch/$(SRCARCH)/include/uap 69 -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \ 70 -I$(srctree)/tools/include/uapi 70 -I$(srctree)/tools/include/uapi 71 71 72 # Append required CFLAGS 72 # Append required CFLAGS 73 override CFLAGS += $(EXTRA_WARNINGS) 73 override CFLAGS += $(EXTRA_WARNINGS) 74 override CFLAGS += -Werror -Wall 74 override CFLAGS += -Werror -Wall 75 override CFLAGS += -fPIC 75 override CFLAGS += -fPIC 76 override CFLAGS += $(INCLUDES) 76 override CFLAGS += $(INCLUDES) 77 override CFLAGS += -fvisibility=hidden 77 override CFLAGS += -fvisibility=hidden 78 78 79 all: 79 all: 80 80 81 export srctree OUTPUT CC LD CFLAGS V 81 export srctree OUTPUT CC LD CFLAGS V 82 export DESTDIR DESTDIR_SQ 82 export DESTDIR DESTDIR_SQ 83 83 84 include $(srctree)/tools/build/Makefile.includ 84 include $(srctree)/tools/build/Makefile.include 85 85 86 VERSION_SCRIPT := libperf.map 86 VERSION_SCRIPT := libperf.map 87 87 88 PATCHLEVEL = $(LIBPERF_PATCHLEVEL) 88 PATCHLEVEL = $(LIBPERF_PATCHLEVEL) 89 EXTRAVERSION = $(LIBPERF_EXTRAVERSION) 89 EXTRAVERSION = $(LIBPERF_EXTRAVERSION) 90 VERSION = $(LIBPERF_VERSION).$(LIBPERF_P 90 VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION) 91 91 92 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) 92 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) 93 LIBPERF_A := $(OUTPUT)libperf.a 93 LIBPERF_A := $(OUTPUT)libperf.a 94 LIBPERF_IN := $(OUTPUT)libperf-in.o 94 LIBPERF_IN := $(OUTPUT)libperf-in.o 95 LIBPERF_PC := $(OUTPUT)libperf.pc 95 LIBPERF_PC := $(OUTPUT)libperf.pc 96 96 97 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.s 97 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so* 98 98 99 LIB_DIR := $(srctree)/tools/lib/api/ 99 LIB_DIR := $(srctree)/tools/lib/api/ 100 100 101 ifneq ($(OUTPUT),) 101 ifneq ($(OUTPUT),) 102 ifneq ($(subdir),) 102 ifneq ($(subdir),) 103 API_PATH=$(OUTPUT)/../lib/api/ 103 API_PATH=$(OUTPUT)/../lib/api/ 104 else 104 else 105 API_PATH=$(OUTPUT) 105 API_PATH=$(OUTPUT) 106 endif 106 endif 107 else 107 else 108 API_PATH=$(LIB_DIR) 108 API_PATH=$(LIB_DIR) 109 endif 109 endif 110 110 111 LIBAPI = $(API_PATH)libapi.a 111 LIBAPI = $(API_PATH)libapi.a 112 export LIBAPI 112 export LIBAPI 113 113 114 $(LIBAPI): FORCE 114 $(LIBAPI): FORCE 115 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) 115 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a 116 116 117 $(LIBAPI)-clean: 117 $(LIBAPI)-clean: 118 $(call QUIET_CLEAN, libapi) 118 $(call QUIET_CLEAN, libapi) 119 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) 119 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null 120 120 121 $(LIBPERF_IN): FORCE 121 $(LIBPERF_IN): FORCE 122 $(Q)$(MAKE) $(build)=libperf 122 $(Q)$(MAKE) $(build)=libperf 123 123 124 $(LIBPERF_A): $(LIBPERF_IN) 124 $(LIBPERF_A): $(LIBPERF_IN) 125 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $( 125 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) 126 126 127 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI) 127 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI) 128 $(QUIET_LINK)$(CC) --shared -Wl,-sonam 128 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \ 129 -Wl,--vers 129 -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@ 130 @ln -sf $(@F) $(OUTPUT)libperf.so 130 @ln -sf $(@F) $(OUTPUT)libperf.so 131 @ln -sf $(@F) $(OUTPUT)libperf.so.$(LI 131 @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION) 132 132 133 133 134 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC) 134 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC) 135 135 136 all: fixdep 136 all: fixdep 137 $(Q)$(MAKE) libs 137 $(Q)$(MAKE) libs 138 138 139 clean: $(LIBAPI)-clean 139 clean: $(LIBAPI)-clean 140 $(call QUIET_CLEAN, libperf) $(RM) $(L 140 $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ 141 *.o *~ *.a *.so *.so.$(VERSION 141 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \ 142 $(TESTS_STATIC) $(TESTS_SHARED 142 $(TESTS_STATIC) $(TESTS_SHARED) 143 143 144 TESTS_IN = tests-in.o 144 TESTS_IN = tests-in.o 145 145 146 TESTS_STATIC = $(OUTPUT)tests-static 146 TESTS_STATIC = $(OUTPUT)tests-static 147 TESTS_SHARED = $(OUTPUT)tests-shared 147 TESTS_SHARED = $(OUTPUT)tests-shared 148 148 149 $(TESTS_IN): FORCE 149 $(TESTS_IN): FORCE 150 $(Q)$(MAKE) $(build)=tests 150 $(Q)$(MAKE) $(build)=tests 151 151 152 $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LI 152 $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI) 153 $(QUIET_LINK)$(CC) -o $@ $^ 153 $(QUIET_LINK)$(CC) -o $@ $^ 154 154 155 $(TESTS_SHARED): $(TESTS_IN) $(LIBAPI) 155 $(TESTS_SHARED): $(TESTS_IN) $(LIBAPI) 156 $(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTP 156 $(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTPUT),.) $^ -lperf 157 157 158 make-tests: libs $(TESTS_SHARED) $(TESTS_STATI 158 make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC) 159 159 160 tests: make-tests 160 tests: make-tests 161 @echo "running static:" 161 @echo "running static:" 162 @./$(TESTS_STATIC) $(TEST_ARGS) 162 @./$(TESTS_STATIC) $(TEST_ARGS) 163 @echo "running dynamic:" 163 @echo "running dynamic:" 164 @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $ 164 @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS) 165 165 166 $(LIBPERF_PC): 166 $(LIBPERF_PC): 167 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefi 167 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ 168 -e "s|@LIBDIR@|$(libdir_SQ)|" 168 -e "s|@LIBDIR@|$(libdir_SQ)|" \ 169 -e "s|@VERSION@|$(VERSION)|" \ 169 -e "s|@VERSION@|$(VERSION)|" \ 170 < libperf.pc.template > $@ 170 < libperf.pc.template > $@ 171 171 172 define do_install_mkdir 172 define do_install_mkdir 173 if [ ! -d '$(DESTDIR_SQ)$1' ]; then 173 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 174 $(INSTALL) -d -m 755 '$(DESTDI 174 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 175 fi 175 fi 176 endef 176 endef 177 177 178 define do_install 178 define do_install 179 if [ ! -d '$2' ]; then \ 179 if [ ! -d '$2' ]; then \ 180 $(INSTALL) -d -m 755 '$2'; \ 180 $(INSTALL) -d -m 755 '$2'; \ 181 fi; \ 181 fi; \ 182 $(INSTALL) $1 $(if $3,-m $3,) '$2' 182 $(INSTALL) $1 $(if $3,-m $3,) '$2' 183 endef 183 endef 184 184 185 install_lib: libs 185 install_lib: libs 186 $(call QUIET_INSTALL, $(LIBPERF_ALL)) 186 $(call QUIET_INSTALL, $(LIBPERF_ALL)) \ 187 $(call do_install_mkdir,$(libd 187 $(call do_install_mkdir,$(libdir_SQ)); \ 188 cp -fpR $(LIBPERF_ALL) $(DESTD 188 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) 189 189 190 HDRS := bpf_perf.h core.h cpumap.h threadmap.h 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 !! 191 INTERNAL_HDRS := cpumap.h evlist.h evsel.h lib.h mmap.h threadmap.h xyarray.h 192 192 193 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/includ 193 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/include/perf 194 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX 194 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX)/, $(HDRS)) 195 INSTALL_INTERNAL_HDRS_PFX := $(DESTDIR)$(prefi 195 INSTALL_INTERNAL_HDRS_PFX := $(DESTDIR)$(prefix)/include/internal 196 INSTALL_INTERNAL_HDRS := $(addprefix $(INSTALL 196 INSTALL_INTERNAL_HDRS := $(addprefix $(INSTALL_INTERNAL_HDRS_PFX)/, $(INTERNAL_HDRS)) 197 197 198 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: incl 198 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: include/perf/%.h 199 $(call QUIET_INSTALL, $@) \ 199 $(call QUIET_INSTALL, $@) \ 200 $(call do_install,$<,$(INSTALL 200 $(call do_install,$<,$(INSTALL_HDRS_PFX)/,644) 201 201 202 $(INSTALL_INTERNAL_HDRS): $(INSTALL_INTERNAL_H 202 $(INSTALL_INTERNAL_HDRS): $(INSTALL_INTERNAL_HDRS_PFX)/%.h: include/internal/%.h 203 $(call QUIET_INSTALL, $@) \ 203 $(call QUIET_INSTALL, $@) \ 204 $(call do_install,$<,$(INSTALL 204 $(call do_install,$<,$(INSTALL_INTERNAL_HDRS_PFX)/,644) 205 205 206 install_headers: $(INSTALL_HDRS) $(INSTALL_INT 206 install_headers: $(INSTALL_HDRS) $(INSTALL_INTERNAL_HDRS) 207 $(call QUIET_INSTALL, libperf_headers) 207 $(call QUIET_INSTALL, libperf_headers) 208 208 209 install_pkgconfig: $(LIBPERF_PC) 209 install_pkgconfig: $(LIBPERF_PC) 210 $(call QUIET_INSTALL, $(LIBPERF_PC)) \ 210 $(call QUIET_INSTALL, $(LIBPERF_PC)) \ 211 $(call do_install,$(LIBPERF_PC 211 $(call do_install,$(LIBPERF_PC),$(DESTDIR_SQ)$(libdir_SQ)/pkgconfig,644) 212 212 213 install_doc: 213 install_doc: 214 $(Q)$(MAKE) -C Documentation install-m 214 $(Q)$(MAKE) -C Documentation install-man install-html install-examples 215 215 216 install: install_lib install_headers install_p 216 install: install_lib install_headers install_pkgconfig install_doc 217 217 218 FORCE: 218 FORCE: 219 219 220 .PHONY: all install clean tests FORCE 220 .PHONY: all install clean tests FORCE
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.