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) << 56 << 57 # Set compile option CFLAGS 55 # Set compile option CFLAGS 58 ifdef EXTRA_CFLAGS 56 ifdef EXTRA_CFLAGS 59 CFLAGS := $(EXTRA_CFLAGS) 57 CFLAGS := $(EXTRA_CFLAGS) 60 else 58 else 61 CFLAGS := -g -Wall 59 CFLAGS := -g -Wall 62 endif 60 endif 63 61 64 INCLUDES = \ 62 INCLUDES = \ 65 -I$(srctree)/tools/lib/perf/include \ 63 -I$(srctree)/tools/lib/perf/include \ 66 -I$(srctree)/tools/lib/ \ 64 -I$(srctree)/tools/lib/ \ 67 -I$(srctree)/tools/include \ 65 -I$(srctree)/tools/include \ 68 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \ 66 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \ 69 -I$(srctree)/tools/arch/$(SRCARCH)/include/uap 67 -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \ 70 -I$(srctree)/tools/include/uapi 68 -I$(srctree)/tools/include/uapi 71 69 72 # Append required CFLAGS 70 # Append required CFLAGS 73 override CFLAGS += $(EXTRA_WARNINGS) 71 override CFLAGS += $(EXTRA_WARNINGS) 74 override CFLAGS += -Werror -Wall 72 override CFLAGS += -Werror -Wall 75 override CFLAGS += -fPIC 73 override CFLAGS += -fPIC 76 override CFLAGS += $(INCLUDES) 74 override CFLAGS += $(INCLUDES) 77 override CFLAGS += -fvisibility=hidden 75 override CFLAGS += -fvisibility=hidden 78 76 79 all: 77 all: 80 78 81 export srctree OUTPUT CC LD CFLAGS V 79 export srctree OUTPUT CC LD CFLAGS V 82 export DESTDIR DESTDIR_SQ 80 export DESTDIR DESTDIR_SQ 83 81 84 include $(srctree)/tools/build/Makefile.includ 82 include $(srctree)/tools/build/Makefile.include 85 83 86 VERSION_SCRIPT := libperf.map 84 VERSION_SCRIPT := libperf.map 87 85 88 PATCHLEVEL = $(LIBPERF_PATCHLEVEL) 86 PATCHLEVEL = $(LIBPERF_PATCHLEVEL) 89 EXTRAVERSION = $(LIBPERF_EXTRAVERSION) 87 EXTRAVERSION = $(LIBPERF_EXTRAVERSION) 90 VERSION = $(LIBPERF_VERSION).$(LIBPERF_P 88 VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION) 91 89 92 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) 90 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) 93 LIBPERF_A := $(OUTPUT)libperf.a 91 LIBPERF_A := $(OUTPUT)libperf.a 94 LIBPERF_IN := $(OUTPUT)libperf-in.o 92 LIBPERF_IN := $(OUTPUT)libperf-in.o 95 LIBPERF_PC := $(OUTPUT)libperf.pc 93 LIBPERF_PC := $(OUTPUT)libperf.pc 96 94 97 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.s 95 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so* 98 96 99 LIB_DIR := $(srctree)/tools/lib/api/ 97 LIB_DIR := $(srctree)/tools/lib/api/ 100 98 101 ifneq ($(OUTPUT),) 99 ifneq ($(OUTPUT),) 102 ifneq ($(subdir),) 100 ifneq ($(subdir),) 103 API_PATH=$(OUTPUT)/../lib/api/ 101 API_PATH=$(OUTPUT)/../lib/api/ 104 else 102 else 105 API_PATH=$(OUTPUT) 103 API_PATH=$(OUTPUT) 106 endif 104 endif 107 else 105 else 108 API_PATH=$(LIB_DIR) 106 API_PATH=$(LIB_DIR) 109 endif 107 endif 110 108 111 LIBAPI = $(API_PATH)libapi.a 109 LIBAPI = $(API_PATH)libapi.a 112 export LIBAPI 110 export LIBAPI 113 111 114 $(LIBAPI): FORCE 112 $(LIBAPI): FORCE 115 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) 113 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a 116 114 117 $(LIBAPI)-clean: 115 $(LIBAPI)-clean: 118 $(call QUIET_CLEAN, libapi) 116 $(call QUIET_CLEAN, libapi) 119 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) 117 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null 120 118 121 $(LIBPERF_IN): FORCE 119 $(LIBPERF_IN): FORCE 122 $(Q)$(MAKE) $(build)=libperf 120 $(Q)$(MAKE) $(build)=libperf 123 121 124 $(LIBPERF_A): $(LIBPERF_IN) 122 $(LIBPERF_A): $(LIBPERF_IN) 125 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $( 123 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) 126 124 127 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI) 125 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI) 128 $(QUIET_LINK)$(CC) --shared -Wl,-sonam 126 $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \ 129 -Wl,--vers 127 -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@ 130 @ln -sf $(@F) $(OUTPUT)libperf.so 128 @ln -sf $(@F) $(OUTPUT)libperf.so 131 @ln -sf $(@F) $(OUTPUT)libperf.so.$(LI 129 @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION) 132 130 133 131 134 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC) 132 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC) 135 133 136 all: fixdep 134 all: fixdep 137 $(Q)$(MAKE) libs 135 $(Q)$(MAKE) libs 138 136 139 clean: $(LIBAPI)-clean 137 clean: $(LIBAPI)-clean 140 $(call QUIET_CLEAN, libperf) $(RM) $(L 138 $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ 141 *.o *~ *.a *.so *.so.$(VERSION !! 139 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC) 142 $(TESTS_STATIC) $(TESTS_SHARED !! 140 $(Q)$(MAKE) -C tests clean 143 << 144 TESTS_IN = tests-in.o << 145 << 146 TESTS_STATIC = $(OUTPUT)tests-static << 147 TESTS_SHARED = $(OUTPUT)tests-shared << 148 << 149 $(TESTS_IN): FORCE << 150 $(Q)$(MAKE) $(build)=tests << 151 << 152 $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LI << 153 $(QUIET_LINK)$(CC) -o $@ $^ << 154 141 155 $(TESTS_SHARED): $(TESTS_IN) $(LIBAPI) !! 142 tests: libs 156 $(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTP !! 143 $(Q)$(MAKE) -C tests 157 !! 144 $(Q)$(MAKE) -C tests run 158 make-tests: libs $(TESTS_SHARED) $(TESTS_STATI << 159 << 160 tests: make-tests << 161 @echo "running static:" << 162 @./$(TESTS_STATIC) $(TEST_ARGS) << 163 @echo "running dynamic:" << 164 @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $ << 165 145 166 $(LIBPERF_PC): 146 $(LIBPERF_PC): 167 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefi 147 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ 168 -e "s|@LIBDIR@|$(libdir_SQ)|" 148 -e "s|@LIBDIR@|$(libdir_SQ)|" \ 169 -e "s|@VERSION@|$(VERSION)|" \ 149 -e "s|@VERSION@|$(VERSION)|" \ 170 < libperf.pc.template > $@ 150 < libperf.pc.template > $@ 171 151 172 define do_install_mkdir 152 define do_install_mkdir 173 if [ ! -d '$(DESTDIR_SQ)$1' ]; then 153 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 174 $(INSTALL) -d -m 755 '$(DESTDI 154 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 175 fi 155 fi 176 endef 156 endef 177 157 178 define do_install 158 define do_install 179 if [ ! -d '$2' ]; then \ !! 159 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \ 180 $(INSTALL) -d -m 755 '$2'; \ !! 160 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \ 181 fi; \ !! 161 fi; \ 182 $(INSTALL) $1 $(if $3,-m $3,) '$2' !! 162 $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2' 183 endef 163 endef 184 164 185 install_lib: libs 165 install_lib: libs 186 $(call QUIET_INSTALL, $(LIBPERF_ALL)) 166 $(call QUIET_INSTALL, $(LIBPERF_ALL)) \ 187 $(call do_install_mkdir,$(libd 167 $(call do_install_mkdir,$(libdir_SQ)); \ 188 cp -fpR $(LIBPERF_ALL) $(DESTD 168 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) 189 169 190 HDRS := bpf_perf.h core.h cpumap.h threadmap.h !! 170 install_headers: 191 INTERNAL_HDRS := cpumap.h evlist.h evsel.h lib !! 171 $(call QUIET_INSTALL, headers) \ 192 !! 172 $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \ 193 INSTALL_HDRS_PFX := $(DESTDIR)$(prefix)/includ !! 173 $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \ 194 INSTALL_HDRS := $(addprefix $(INSTALL_HDRS_PFX !! 174 $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \ 195 INSTALL_INTERNAL_HDRS_PFX := $(DESTDIR)$(prefi !! 175 $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \ 196 INSTALL_INTERNAL_HDRS := $(addprefix $(INSTALL !! 176 $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \ 197 !! 177 $(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \ 198 $(INSTALL_HDRS): $(INSTALL_HDRS_PFX)/%.h: incl !! 178 $(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644); 199 $(call QUIET_INSTALL, $@) \ << 200 $(call do_install,$<,$(INSTALL << 201 << 202 $(INSTALL_INTERNAL_HDRS): $(INSTALL_INTERNAL_H << 203 $(call QUIET_INSTALL, $@) \ << 204 $(call do_install,$<,$(INSTALL << 205 << 206 install_headers: $(INSTALL_HDRS) $(INSTALL_INT << 207 $(call QUIET_INSTALL, libperf_headers) << 208 179 209 install_pkgconfig: $(LIBPERF_PC) 180 install_pkgconfig: $(LIBPERF_PC) 210 $(call QUIET_INSTALL, $(LIBPERF_PC)) \ 181 $(call QUIET_INSTALL, $(LIBPERF_PC)) \ 211 $(call do_install,$(LIBPERF_PC !! 182 $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644) 212 183 213 install_doc: 184 install_doc: 214 $(Q)$(MAKE) -C Documentation install-m 185 $(Q)$(MAKE) -C Documentation install-man install-html install-examples 215 186 216 install: install_lib install_headers install_p 187 install: install_lib install_headers install_pkgconfig install_doc 217 188 218 FORCE: 189 FORCE: 219 190 220 .PHONY: all install clean tests FORCE 191 .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.