1# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) 2# Most of this file is copied from tools/lib/bpf/Makefile 3 4LIBPERF_VERSION = 0 5LIBPERF_PATCHLEVEL = 0 6LIBPERF_EXTRAVERSION = 1 7 8MAKEFLAGS += --no-print-directory 9 10ifeq ($(srctree),) 11srctree := $(patsubst %/,%,$(dir $(CURDIR))) 12srctree := $(patsubst %/,%,$(dir $(srctree))) 13srctree := $(patsubst %/,%,$(dir $(srctree))) 14#$(info Determined 'srctree' to be $(srctree)) 15endif 16 17INSTALL = install 18 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. 23DESTDIR ?= 24DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 25 26include $(srctree)/tools/scripts/Makefile.include 27include $(srctree)/tools/scripts/Makefile.arch 28 29ifeq ($(LP64), 1) 30 libdir_relative = lib64 31else 32 libdir_relative = lib 33endif 34 35prefix ?= 36libdir = $(prefix)/$(libdir_relative) 37 38# Shell quotes 39libdir_SQ = $(subst ','\'',$(libdir)) 40libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) 41 42ifeq ("$(origin V)", "command line") 43 VERBOSE = $(V) 44endif 45ifndef VERBOSE 46 VERBOSE = 0 47endif 48 49ifeq ($(VERBOSE),1) 50 Q = 51else 52 Q = @ 53endif 54 55TEST_ARGS := $(if $(V),-v) 56 57# Set compile option CFLAGS 58ifdef EXTRA_CFLAGS 59 CFLAGS := $(EXTRA_CFLAGS) 60else 61 CFLAGS := -g -Wall 62endif 63 64INCLUDES = \ 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 71 72# Append required CFLAGS 73override CFLAGS += $(EXTRA_WARNINGS) 74override CFLAGS += -Werror -Wall 75override CFLAGS += -fPIC 76override CFLAGS += $(INCLUDES) 77override CFLAGS += -fvisibility=hidden 78 79all: 80 81export srctree OUTPUT CC LD CFLAGS V 82export DESTDIR DESTDIR_SQ 83 84include $(srctree)/tools/build/Makefile.include 85 86VERSION_SCRIPT := libperf.map 87 88PATCHLEVEL = $(LIBPERF_PATCHLEVEL) 89EXTRAVERSION = $(LIBPERF_EXTRAVERSION) 90VERSION = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION) 91 92LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION) 93LIBPERF_A := $(OUTPUT)libperf.a 94LIBPERF_IN := $(OUTPUT)libperf-in.o 95LIBPERF_PC := $(OUTPUT)libperf.pc 96 97LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so* 98 99LIB_DIR := $(srctree)/tools/lib/api/ 100 101ifneq ($(OUTPUT),) 102ifneq ($(subdir),) 103 API_PATH=$(OUTPUT)/../lib/api/ 104else 105 API_PATH=$(OUTPUT) 106endif 107else 108 API_PATH=$(LIB_DIR) 109endif 110 111LIBAPI = $(API_PATH)libapi.a 112export LIBAPI 113 114$(LIBAPI): FORCE 115 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a 116 117$(LIBAPI)-clean: 118 $(call QUIET_CLEAN, libapi) 119 $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null 120 121$(LIBPERF_IN): FORCE 122 $(Q)$(MAKE) $(build)=libperf 123 124$(LIBPERF_A): $(LIBPERF_IN) 125 $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN) 126 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) 132 133 134libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC) 135 136all: fixdep 137 $(Q)$(MAKE) libs 138 139clean: $(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) 143 144TESTS_IN = tests-in.o 145 146TESTS_STATIC = $(OUTPUT)tests-static 147TESTS_SHARED = $(OUTPUT)tests-shared 148 149$(TESTS_IN): FORCE 150 $(Q)$(MAKE) $(build)=tests 151 152$(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI) 153 $(QUIET_LINK)$(CC) -o $@ $^ 154 155$(TESTS_SHARED): $(TESTS_IN) $(LIBAPI) 156 $(QUIET_LINK)$(CC) -o $@ -L$(if $(OUTPUT),$(OUTPUT),.) $^ -lperf 157 158make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC) 159 160tests: make-tests 161 @echo "running static:" 162 @./$(TESTS_STATIC) $(TEST_ARGS) 163 @echo "running dynamic:" 164 @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS) 165 166$(LIBPERF_PC): 167 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \ 168 -e "s|@LIBDIR@|$(libdir_SQ)|" \ 169 -e "s|@VERSION@|$(VERSION)|" \ 170 < libperf.pc.template > $@ 171 172define do_install_mkdir 173 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 174 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 175 fi 176endef 177 178define do_install 179 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \ 180 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \ 181 fi; \ 182 $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2' 183endef 184 185install_lib: libs 186 $(call QUIET_INSTALL, $(LIBPERF_ALL)) \ 187 $(call do_install_mkdir,$(libdir_SQ)); \ 188 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ) 189 190install_headers: 191 $(call QUIET_INSTALL, headers) \ 192 $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \ 193 $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \ 194 $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \ 195 $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \ 196 $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \ 197 $(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \ 198 $(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644); 199 200install_pkgconfig: $(LIBPERF_PC) 201 $(call QUIET_INSTALL, $(LIBPERF_PC)) \ 202 $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644) 203 204install_doc: 205 $(Q)$(MAKE) -C Documentation install-man install-html install-examples 206 207install: install_lib install_headers install_pkgconfig install_doc 208 209FORCE: 210 211.PHONY: all install clean tests FORCE 212