18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci#MAKEFLAGS += --no-print-directory 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci# Makefiles suck: This macro sets a default value of $(2) for the 78c2ecf20Sopenharmony_ci# variable named by $(1), unless the variable has been set by 88c2ecf20Sopenharmony_ci# environment or command line. This is necessary for CC and AR 98c2ecf20Sopenharmony_ci# because make sets default values, so the simpler ?= approach 108c2ecf20Sopenharmony_ci# won't work as expected. 118c2ecf20Sopenharmony_cidefine allow-override 128c2ecf20Sopenharmony_ci $(if $(or $(findstring environment,$(origin $(1))),\ 138c2ecf20Sopenharmony_ci $(findstring command line,$(origin $(1)))),,\ 148c2ecf20Sopenharmony_ci $(eval $(1) = $(2))) 158c2ecf20Sopenharmony_ciendef 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. 188c2ecf20Sopenharmony_ci$(call allow-override,CC,$(CROSS_COMPILE)gcc) 198c2ecf20Sopenharmony_ci$(call allow-override,AR,$(CROSS_COMPILE)ar) 208c2ecf20Sopenharmony_ci$(call allow-override,NM,$(CROSS_COMPILE)nm) 218c2ecf20Sopenharmony_ci$(call allow-override,PKG_CONFIG,pkg-config) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ciEXT = -std=gnu99 248c2ecf20Sopenharmony_ciINSTALL = install 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci# Use DESTDIR for installing into a different root directory. 278c2ecf20Sopenharmony_ci# This is useful for building a package. The program will be 288c2ecf20Sopenharmony_ci# installed in this directory as if it was the root directory. 298c2ecf20Sopenharmony_ci# Then the build tool can move it later. 308c2ecf20Sopenharmony_ciDESTDIR ?= 318c2ecf20Sopenharmony_ciDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ciLP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) 348c2ecf20Sopenharmony_ciifeq ($(LP64), 1) 358c2ecf20Sopenharmony_ci libdir_relative_tmp = lib64 368c2ecf20Sopenharmony_cielse 378c2ecf20Sopenharmony_ci libdir_relative_tmp = lib 388c2ecf20Sopenharmony_ciendif 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cilibdir_relative ?= $(libdir_relative_tmp) 418c2ecf20Sopenharmony_ciprefix ?= /usr/local 428c2ecf20Sopenharmony_cilibdir = $(prefix)/$(libdir_relative) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ciset_plugin_dir := 1 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci# Set plugin_dir to preffered global plugin location 478c2ecf20Sopenharmony_ci# If we install under $HOME directory we go under 488c2ecf20Sopenharmony_ci# $(HOME)/.local/lib/traceevent/plugins 498c2ecf20Sopenharmony_ci# 508c2ecf20Sopenharmony_ci# We dont set PLUGIN_DIR in case we install under $HOME 518c2ecf20Sopenharmony_ci# directory, because by default the code looks under: 528c2ecf20Sopenharmony_ci# $(HOME)/.local/lib/traceevent/plugins by default. 538c2ecf20Sopenharmony_ci# 548c2ecf20Sopenharmony_ciifeq ($(plugin_dir),) 558c2ecf20Sopenharmony_ciifeq ($(prefix),$(HOME)) 568c2ecf20Sopenharmony_cioverride plugin_dir = $(HOME)/.local/lib/traceevent/plugins 578c2ecf20Sopenharmony_ciset_plugin_dir := 0 588c2ecf20Sopenharmony_cielse 598c2ecf20Sopenharmony_cioverride plugin_dir = $(libdir)/traceevent/plugins 608c2ecf20Sopenharmony_ciendif 618c2ecf20Sopenharmony_ciendif 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciifeq ($(set_plugin_dir),1) 648c2ecf20Sopenharmony_ciPLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" 658c2ecf20Sopenharmony_ciPLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' 668c2ecf20Sopenharmony_ciendif 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ciinclude ../../../scripts/Makefile.include 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci# copy a bit from Linux kbuild 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ciifeq ("$(origin V)", "command line") 738c2ecf20Sopenharmony_ci VERBOSE = $(V) 748c2ecf20Sopenharmony_ciendif 758c2ecf20Sopenharmony_ciifndef VERBOSE 768c2ecf20Sopenharmony_ci VERBOSE = 0 778c2ecf20Sopenharmony_ciendif 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ciifeq ($(srctree),) 808c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR))) 818c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree))) 828c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree))) 838c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree))) 848c2ecf20Sopenharmony_ci#$(info Determined 'srctree' to be $(srctree)) 858c2ecf20Sopenharmony_ciendif 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ciexport prefix libdir src obj 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci# Shell quotes 908c2ecf20Sopenharmony_ciplugin_dir_SQ = $(subst ','\'',$(plugin_dir)) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciCONFIG_INCLUDES = 938c2ecf20Sopenharmony_ciCONFIG_LIBS = 948c2ecf20Sopenharmony_ciCONFIG_FLAGS = 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ciOBJ = $@ 978c2ecf20Sopenharmony_ciN = 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciINCLUDES = -I. -I.. -I $(srctree)/tools/include $(CONFIG_INCLUDES) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci# Set compile option CFLAGS 1028c2ecf20Sopenharmony_ciifdef EXTRA_CFLAGS 1038c2ecf20Sopenharmony_ci CFLAGS := $(EXTRA_CFLAGS) 1048c2ecf20Sopenharmony_cielse 1058c2ecf20Sopenharmony_ci CFLAGS := -g -Wall 1068c2ecf20Sopenharmony_ciendif 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci# Append required CFLAGS 1098c2ecf20Sopenharmony_cioverride CFLAGS += -fPIC 1108c2ecf20Sopenharmony_cioverride CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 1118c2ecf20Sopenharmony_cioverride CFLAGS += $(udis86-flags) -D_GNU_SOURCE 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ciifeq ($(VERBOSE),1) 1148c2ecf20Sopenharmony_ci Q = 1158c2ecf20Sopenharmony_cielse 1168c2ecf20Sopenharmony_ci Q = @ 1178c2ecf20Sopenharmony_ciendif 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci# Disable command line variables (CFLAGS) override from top 1208c2ecf20Sopenharmony_ci# level Makefile (perf), otherwise build Makefile will get 1218c2ecf20Sopenharmony_ci# the same command line setup. 1228c2ecf20Sopenharmony_ciMAKEOVERRIDES= 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ciexport srctree OUTPUT CC LD CFLAGS V 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_cibuild := -f $(srctree)/tools/build/Makefile.build dir=. obj 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ciDYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ciPLUGINS = plugin_jbd2.so 1318c2ecf20Sopenharmony_ciPLUGINS += plugin_hrtimer.so 1328c2ecf20Sopenharmony_ciPLUGINS += plugin_kmem.so 1338c2ecf20Sopenharmony_ciPLUGINS += plugin_kvm.so 1348c2ecf20Sopenharmony_ciPLUGINS += plugin_mac80211.so 1358c2ecf20Sopenharmony_ciPLUGINS += plugin_sched_switch.so 1368c2ecf20Sopenharmony_ciPLUGINS += plugin_function.so 1378c2ecf20Sopenharmony_ciPLUGINS += plugin_futex.so 1388c2ecf20Sopenharmony_ciPLUGINS += plugin_xen.so 1398c2ecf20Sopenharmony_ciPLUGINS += plugin_scsi.so 1408c2ecf20Sopenharmony_ciPLUGINS += plugin_cfg80211.so 1418c2ecf20Sopenharmony_ciPLUGINS += plugin_tlb.so 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ciPLUGINS := $(addprefix $(OUTPUT),$(PLUGINS)) 1448c2ecf20Sopenharmony_ciPLUGINS_IN := $(PLUGINS:.so=-in.o) 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ciplugins: $(PLUGINS) $(DYNAMIC_LIST_FILE) 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci__plugin_obj = $(notdir $@) 1498c2ecf20Sopenharmony_ci plugin_obj = $(__plugin_obj:-in.o=) 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci$(PLUGINS_IN): force 1528c2ecf20Sopenharmony_ci $(Q)$(MAKE) $(build)=$(plugin_obj) 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS) 1558c2ecf20Sopenharmony_ci $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@) 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci$(OUTPUT)%.so: $(OUTPUT)%-in.o 1588c2ecf20Sopenharmony_ci $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^ 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cidefine update_dir 1618c2ecf20Sopenharmony_ci (echo $1 > $@.tmp; \ 1628c2ecf20Sopenharmony_ci if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 1638c2ecf20Sopenharmony_ci rm -f $@.tmp; \ 1648c2ecf20Sopenharmony_ci else \ 1658c2ecf20Sopenharmony_ci echo ' UPDATE $@'; \ 1668c2ecf20Sopenharmony_ci mv -f $@.tmp $@; \ 1678c2ecf20Sopenharmony_ci fi); 1688c2ecf20Sopenharmony_ciendef 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_citags: force 1718c2ecf20Sopenharmony_ci $(RM) tags 1728c2ecf20Sopenharmony_ci find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 1738c2ecf20Sopenharmony_ci --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ciTAGS: force 1768c2ecf20Sopenharmony_ci $(RM) TAGS 1778c2ecf20Sopenharmony_ci find . -name '*.[ch]' | xargs etags \ 1788c2ecf20Sopenharmony_ci --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' 1798c2ecf20Sopenharmony_ci 1808c2ecf20Sopenharmony_cidefine do_install_mkdir 1818c2ecf20Sopenharmony_ci if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 1828c2ecf20Sopenharmony_ci $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 1838c2ecf20Sopenharmony_ci fi 1848c2ecf20Sopenharmony_ciendef 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_cidefine do_install 1878c2ecf20Sopenharmony_ci $(call do_install_mkdir,$2); \ 1888c2ecf20Sopenharmony_ci $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' 1898c2ecf20Sopenharmony_ciendef 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cidefine do_install_plugins 1928c2ecf20Sopenharmony_ci for plugin in $1; do \ 1938c2ecf20Sopenharmony_ci $(call do_install,$$plugin,$(plugin_dir_SQ)); \ 1948c2ecf20Sopenharmony_ci done 1958c2ecf20Sopenharmony_ciendef 1968c2ecf20Sopenharmony_ci 1978c2ecf20Sopenharmony_cidefine do_generate_dynamic_list_file 1988c2ecf20Sopenharmony_ci symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \ 1998c2ecf20Sopenharmony_ci xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\ 2008c2ecf20Sopenharmony_ci if [ "$$symbol_type" = "U W" ];then \ 2018c2ecf20Sopenharmony_ci (echo '{'; \ 2028c2ecf20Sopenharmony_ci $(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\ 2038c2ecf20Sopenharmony_ci echo '};'; \ 2048c2ecf20Sopenharmony_ci ) > $2; \ 2058c2ecf20Sopenharmony_ci else \ 2068c2ecf20Sopenharmony_ci (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\ 2078c2ecf20Sopenharmony_ci fi 2088c2ecf20Sopenharmony_ciendef 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ciinstall: $(PLUGINS) 2118c2ecf20Sopenharmony_ci $(call QUIET_INSTALL, trace_plugins) \ 2128c2ecf20Sopenharmony_ci $(call do_install_plugins, $(PLUGINS)) 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciclean: 2158c2ecf20Sopenharmony_ci $(call QUIET_CLEAN, trace_plugins) \ 2168c2ecf20Sopenharmony_ci $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ 2178c2ecf20Sopenharmony_ci $(RM) $(OUTPUT)libtraceevent-dynamic-list \ 2188c2ecf20Sopenharmony_ci $(RM) TRACEEVENT-CFLAGS tags TAGS; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ciPHONY += force plugins 2218c2ecf20Sopenharmony_ciforce: 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci# Declare the contents of the .PHONY variable as phony. We keep that 2248c2ecf20Sopenharmony_ci# information in a variable so we can use it in if_changed and friends. 2258c2ecf20Sopenharmony_ci.PHONY: $(PHONY) 226