Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
0002 # Most of this file is copied from tools/lib/bpf/Makefile
0003 
0004 LIBPERF_VERSION = 0
0005 LIBPERF_PATCHLEVEL = 0
0006 LIBPERF_EXTRAVERSION = 1
0007 
0008 MAKEFLAGS += --no-print-directory
0009 
0010 ifeq ($(srctree),)
0011 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
0012 srctree := $(patsubst %/,%,$(dir $(srctree)))
0013 srctree := $(patsubst %/,%,$(dir $(srctree)))
0014 #$(info Determined 'srctree' to be $(srctree))
0015 endif
0016 
0017 INSTALL = install
0018 
0019 # Use DESTDIR for installing into a different root directory.
0020 # This is useful for building a package. The program will be
0021 # installed in this directory as if it was the root directory.
0022 # Then the build tool can move it later.
0023 DESTDIR ?=
0024 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
0025 
0026 include $(srctree)/tools/scripts/Makefile.include
0027 include $(srctree)/tools/scripts/Makefile.arch
0028 
0029 ifeq ($(LP64), 1)
0030   libdir_relative = lib64
0031 else
0032   libdir_relative = lib
0033 endif
0034 
0035 prefix ?=
0036 libdir = $(prefix)/$(libdir_relative)
0037 
0038 # Shell quotes
0039 libdir_SQ = $(subst ','\'',$(libdir))
0040 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
0041 
0042 ifeq ("$(origin V)", "command line")
0043   VERBOSE = $(V)
0044 endif
0045 ifndef VERBOSE
0046   VERBOSE = 0
0047 endif
0048 
0049 ifeq ($(VERBOSE),1)
0050   Q =
0051 else
0052   Q = @
0053 endif
0054 
0055 TEST_ARGS := $(if $(V),-v)
0056 
0057 # Set compile option CFLAGS
0058 ifdef EXTRA_CFLAGS
0059   CFLAGS := $(EXTRA_CFLAGS)
0060 else
0061   CFLAGS := -g -Wall
0062 endif
0063 
0064 INCLUDES = \
0065 -I$(srctree)/tools/lib/perf/include \
0066 -I$(srctree)/tools/lib/ \
0067 -I$(srctree)/tools/include \
0068 -I$(srctree)/tools/arch/$(SRCARCH)/include/ \
0069 -I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
0070 -I$(srctree)/tools/include/uapi
0071 
0072 # Append required CFLAGS
0073 override CFLAGS += $(EXTRA_WARNINGS)
0074 override CFLAGS += -Werror -Wall
0075 override CFLAGS += -fPIC
0076 override CFLAGS += $(INCLUDES)
0077 override CFLAGS += -fvisibility=hidden
0078 
0079 all:
0080 
0081 export srctree OUTPUT CC LD CFLAGS V
0082 export DESTDIR DESTDIR_SQ
0083 
0084 include $(srctree)/tools/build/Makefile.include
0085 
0086 VERSION_SCRIPT := libperf.map
0087 
0088 PATCHLEVEL    = $(LIBPERF_PATCHLEVEL)
0089 EXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
0090 VERSION       = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
0091 
0092 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
0093 LIBPERF_A  := $(OUTPUT)libperf.a
0094 LIBPERF_IN := $(OUTPUT)libperf-in.o
0095 LIBPERF_PC := $(OUTPUT)libperf.pc
0096 
0097 LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
0098 
0099 LIB_DIR := $(srctree)/tools/lib/api/
0100 
0101 ifneq ($(OUTPUT),)
0102 ifneq ($(subdir),)
0103   API_PATH=$(OUTPUT)/../lib/api/
0104 else
0105   API_PATH=$(OUTPUT)
0106 endif
0107 else
0108   API_PATH=$(LIB_DIR)
0109 endif
0110 
0111 LIBAPI = $(API_PATH)libapi.a
0112 export LIBAPI
0113 
0114 $(LIBAPI): FORCE
0115         $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
0116 
0117 $(LIBAPI)-clean:
0118         $(call QUIET_CLEAN, libapi)
0119         $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
0120 
0121 $(LIBPERF_IN): FORCE
0122         $(Q)$(MAKE) $(build)=libperf
0123 
0124 $(LIBPERF_A): $(LIBPERF_IN)
0125         $(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
0126 
0127 $(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
0128         $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
0129                                     -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
0130         @ln -sf $(@F) $(OUTPUT)libperf.so
0131         @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
0132 
0133 
0134 libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
0135 
0136 all: fixdep
0137         $(Q)$(MAKE) libs
0138 
0139 clean: $(LIBAPI)-clean
0140         $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
0141                 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \
0142                 $(TESTS_STATIC) $(TESTS_SHARED)
0143 
0144 TESTS_IN = tests-in.o
0145 
0146 TESTS_STATIC = $(OUTPUT)tests-static
0147 TESTS_SHARED = $(OUTPUT)tests-shared
0148 
0149 $(TESTS_IN): FORCE
0150         $(Q)$(MAKE) $(build)=tests
0151 
0152 $(TESTS_STATIC): $(TESTS_IN) $(LIBPERF_A) $(LIBAPI)
0153         $(QUIET_LINK)$(CC) -o $@ $^
0154 
0155 $(TESTS_SHARED): $(TESTS_IN) $(LIBAPI)
0156         $(QUIET_LINK)$(CC) -o $@ -L$(or $(OUTPUT),.) $^ -lperf
0157 
0158 make-tests: libs $(TESTS_SHARED) $(TESTS_STATIC)
0159 
0160 tests: make-tests
0161         @echo "running static:"
0162         @./$(TESTS_STATIC) $(TEST_ARGS)
0163         @echo "running dynamic:"
0164         @LD_LIBRARY_PATH=. ./$(TESTS_SHARED) $(TEST_ARGS)
0165 
0166 $(LIBPERF_PC):
0167         $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
0168                 -e "s|@LIBDIR@|$(libdir_SQ)|" \
0169                 -e "s|@VERSION@|$(VERSION)|" \
0170                 < libperf.pc.template > $@
0171 
0172 define do_install_mkdir
0173         if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
0174                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
0175         fi
0176 endef
0177 
0178 define do_install
0179         if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
0180                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
0181         fi;                                             \
0182         $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
0183 endef
0184 
0185 install_lib: libs
0186         $(call QUIET_INSTALL, $(LIBPERF_ALL)) \
0187                 $(call do_install_mkdir,$(libdir_SQ)); \
0188                 cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
0189 
0190 install_headers:
0191         $(call QUIET_INSTALL, headers) \
0192                 $(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
0193                 $(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
0194                 $(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
0195                 $(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
0196                 $(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \
0197                 $(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \
0198                 $(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644);
0199 
0200 install_pkgconfig: $(LIBPERF_PC)
0201         $(call QUIET_INSTALL, $(LIBPERF_PC)) \
0202                 $(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644)
0203 
0204 install_doc:
0205         $(Q)$(MAKE) -C Documentation install-man install-html install-examples
0206 
0207 install: install_lib install_headers install_pkgconfig install_doc
0208 
0209 FORCE:
0210 
0211 .PHONY: all install clean tests FORCE