18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
28c2ecf20Sopenharmony_ci# Most of this file is copied from tools/lib/bpf/Makefile
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciLIBPERF_VERSION = 0
58c2ecf20Sopenharmony_ciLIBPERF_PATCHLEVEL = 0
68c2ecf20Sopenharmony_ciLIBPERF_EXTRAVERSION = 1
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciMAKEFLAGS += --no-print-directory
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciifeq ($(srctree),)
118c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR)))
128c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
138c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree)))
148c2ecf20Sopenharmony_ci#$(info Determined 'srctree' to be $(srctree))
158c2ecf20Sopenharmony_ciendif
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ciINSTALL = install
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci# Use DESTDIR for installing into a different root directory.
208c2ecf20Sopenharmony_ci# This is useful for building a package. The program will be
218c2ecf20Sopenharmony_ci# installed in this directory as if it was the root directory.
228c2ecf20Sopenharmony_ci# Then the build tool can move it later.
238c2ecf20Sopenharmony_ciDESTDIR ?=
248c2ecf20Sopenharmony_ciDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ciinclude $(srctree)/tools/scripts/Makefile.include
278c2ecf20Sopenharmony_ciinclude $(srctree)/tools/scripts/Makefile.arch
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ciifeq ($(LP64), 1)
308c2ecf20Sopenharmony_ci  libdir_relative = lib64
318c2ecf20Sopenharmony_cielse
328c2ecf20Sopenharmony_ci  libdir_relative = lib
338c2ecf20Sopenharmony_ciendif
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciprefix ?=
368c2ecf20Sopenharmony_cilibdir = $(prefix)/$(libdir_relative)
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci# Shell quotes
398c2ecf20Sopenharmony_cilibdir_SQ = $(subst ','\'',$(libdir))
408c2ecf20Sopenharmony_cilibdir_relative_SQ = $(subst ','\'',$(libdir_relative))
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ciifeq ("$(origin V)", "command line")
438c2ecf20Sopenharmony_ci  VERBOSE = $(V)
448c2ecf20Sopenharmony_ciendif
458c2ecf20Sopenharmony_ciifndef VERBOSE
468c2ecf20Sopenharmony_ci  VERBOSE = 0
478c2ecf20Sopenharmony_ciendif
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ciifeq ($(VERBOSE),1)
508c2ecf20Sopenharmony_ci  Q =
518c2ecf20Sopenharmony_cielse
528c2ecf20Sopenharmony_ci  Q = @
538c2ecf20Sopenharmony_ciendif
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci# Set compile option CFLAGS
568c2ecf20Sopenharmony_ciifdef EXTRA_CFLAGS
578c2ecf20Sopenharmony_ci  CFLAGS := $(EXTRA_CFLAGS)
588c2ecf20Sopenharmony_cielse
598c2ecf20Sopenharmony_ci  CFLAGS := -g -Wall
608c2ecf20Sopenharmony_ciendif
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ciINCLUDES = \
638c2ecf20Sopenharmony_ci-I$(srctree)/tools/lib/perf/include \
648c2ecf20Sopenharmony_ci-I$(srctree)/tools/lib/ \
658c2ecf20Sopenharmony_ci-I$(srctree)/tools/include \
668c2ecf20Sopenharmony_ci-I$(srctree)/tools/arch/$(SRCARCH)/include/ \
678c2ecf20Sopenharmony_ci-I$(srctree)/tools/arch/$(SRCARCH)/include/uapi \
688c2ecf20Sopenharmony_ci-I$(srctree)/tools/include/uapi
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci# Append required CFLAGS
718c2ecf20Sopenharmony_cioverride CFLAGS += $(EXTRA_WARNINGS)
728c2ecf20Sopenharmony_cioverride CFLAGS += -Werror -Wall
738c2ecf20Sopenharmony_cioverride CFLAGS += -fPIC
748c2ecf20Sopenharmony_cioverride CFLAGS += $(INCLUDES)
758c2ecf20Sopenharmony_cioverride CFLAGS += -fvisibility=hidden
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ciall:
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciexport srctree OUTPUT CC LD CFLAGS V
808c2ecf20Sopenharmony_ciexport DESTDIR DESTDIR_SQ
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ciinclude $(srctree)/tools/build/Makefile.include
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ciVERSION_SCRIPT := libperf.map
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ciPATCHLEVEL    = $(LIBPERF_PATCHLEVEL)
878c2ecf20Sopenharmony_ciEXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
888c2ecf20Sopenharmony_ciVERSION       = $(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ciLIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
918c2ecf20Sopenharmony_ciLIBPERF_A  := $(OUTPUT)libperf.a
928c2ecf20Sopenharmony_ciLIBPERF_IN := $(OUTPUT)libperf-in.o
938c2ecf20Sopenharmony_ciLIBPERF_PC := $(OUTPUT)libperf.pc
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ciLIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ciLIB_DIR := $(srctree)/tools/lib/api/
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ciifneq ($(OUTPUT),)
1008c2ecf20Sopenharmony_ciifneq ($(subdir),)
1018c2ecf20Sopenharmony_ci  API_PATH=$(OUTPUT)/../lib/api/
1028c2ecf20Sopenharmony_cielse
1038c2ecf20Sopenharmony_ci  API_PATH=$(OUTPUT)
1048c2ecf20Sopenharmony_ciendif
1058c2ecf20Sopenharmony_cielse
1068c2ecf20Sopenharmony_ci  API_PATH=$(LIB_DIR)
1078c2ecf20Sopenharmony_ciendif
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciLIBAPI = $(API_PATH)libapi.a
1108c2ecf20Sopenharmony_ciexport LIBAPI
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci$(LIBAPI): FORCE
1138c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) $(OUTPUT)libapi.a
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci$(LIBAPI)-clean:
1168c2ecf20Sopenharmony_ci	$(call QUIET_CLEAN, libapi)
1178c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci$(LIBPERF_IN): FORCE
1208c2ecf20Sopenharmony_ci	$(Q)$(MAKE) $(build)=libperf
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci$(LIBPERF_A): $(LIBPERF_IN)
1238c2ecf20Sopenharmony_ci	$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci$(LIBPERF_SO): $(LIBPERF_IN) $(LIBAPI)
1268c2ecf20Sopenharmony_ci	$(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
1278c2ecf20Sopenharmony_ci                                    -Wl,--version-script=$(VERSION_SCRIPT) $^ -o $@
1288c2ecf20Sopenharmony_ci	@ln -sf $(@F) $(OUTPUT)libperf.so
1298c2ecf20Sopenharmony_ci	@ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cilibs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciall: fixdep
1358c2ecf20Sopenharmony_ci	$(Q)$(MAKE) libs
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciclean: $(LIBAPI)-clean
1388c2ecf20Sopenharmony_ci	$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
1398c2ecf20Sopenharmony_ci                *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
1408c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C tests clean
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_citests: libs
1438c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C tests
1448c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C tests run
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci$(LIBPERF_PC):
1478c2ecf20Sopenharmony_ci	$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
1488c2ecf20Sopenharmony_ci		-e "s|@LIBDIR@|$(libdir_SQ)|" \
1498c2ecf20Sopenharmony_ci		-e "s|@VERSION@|$(VERSION)|" \
1508c2ecf20Sopenharmony_ci		< libperf.pc.template > $@
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_cidefine do_install_mkdir
1538c2ecf20Sopenharmony_ci	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
1548c2ecf20Sopenharmony_ci		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
1558c2ecf20Sopenharmony_ci	fi
1568c2ecf20Sopenharmony_ciendef
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_cidefine do_install
1598c2ecf20Sopenharmony_ci	if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
1608c2ecf20Sopenharmony_ci		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
1618c2ecf20Sopenharmony_ci	fi;                                             \
1628c2ecf20Sopenharmony_ci	$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
1638c2ecf20Sopenharmony_ciendef
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ciinstall_lib: libs
1668c2ecf20Sopenharmony_ci	$(call QUIET_INSTALL, $(LIBPERF_ALL)) \
1678c2ecf20Sopenharmony_ci		$(call do_install_mkdir,$(libdir_SQ)); \
1688c2ecf20Sopenharmony_ci		cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ciinstall_headers:
1718c2ecf20Sopenharmony_ci	$(call QUIET_INSTALL, headers) \
1728c2ecf20Sopenharmony_ci		$(call do_install,include/perf/core.h,$(prefix)/include/perf,644); \
1738c2ecf20Sopenharmony_ci		$(call do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
1748c2ecf20Sopenharmony_ci		$(call do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
1758c2ecf20Sopenharmony_ci		$(call do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
1768c2ecf20Sopenharmony_ci		$(call do_install,include/perf/evsel.h,$(prefix)/include/perf,644); \
1778c2ecf20Sopenharmony_ci		$(call do_install,include/perf/event.h,$(prefix)/include/perf,644); \
1788c2ecf20Sopenharmony_ci		$(call do_install,include/perf/mmap.h,$(prefix)/include/perf,644);
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ciinstall_pkgconfig: $(LIBPERF_PC)
1818c2ecf20Sopenharmony_ci	$(call QUIET_INSTALL, $(LIBPERF_PC)) \
1828c2ecf20Sopenharmony_ci		$(call do_install,$(LIBPERF_PC),$(libdir_SQ)/pkgconfig,644)
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ciinstall_doc:
1858c2ecf20Sopenharmony_ci	$(Q)$(MAKE) -C Documentation install-man install-html install-examples
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ciinstall: install_lib install_headers install_pkgconfig install_doc
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ciFORCE:
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci.PHONY: all install clean tests FORCE
192