18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci# trace-cmd version 38c2ecf20Sopenharmony_ciEP_VERSION = 1 48c2ecf20Sopenharmony_ciEP_PATCHLEVEL = 1 58c2ecf20Sopenharmony_ciEP_EXTRAVERSION = 0 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci# file format version 88c2ecf20Sopenharmony_ciFILE_VERSION = 6 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ciMAKEFLAGS += --no-print-directory 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci# Makefiles suck: This macro sets a default value of $(2) for the 148c2ecf20Sopenharmony_ci# variable named by $(1), unless the variable has been set by 158c2ecf20Sopenharmony_ci# environment or command line. This is necessary for CC and AR 168c2ecf20Sopenharmony_ci# because make sets default values, so the simpler ?= approach 178c2ecf20Sopenharmony_ci# won't work as expected. 188c2ecf20Sopenharmony_cidefine allow-override 198c2ecf20Sopenharmony_ci $(if $(or $(findstring environment,$(origin $(1))),\ 208c2ecf20Sopenharmony_ci $(findstring command line,$(origin $(1)))),,\ 218c2ecf20Sopenharmony_ci $(eval $(1) = $(2))) 228c2ecf20Sopenharmony_ciendef 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. 258c2ecf20Sopenharmony_ci$(call allow-override,CC,$(CROSS_COMPILE)gcc) 268c2ecf20Sopenharmony_ci$(call allow-override,AR,$(CROSS_COMPILE)ar) 278c2ecf20Sopenharmony_ci$(call allow-override,NM,$(CROSS_COMPILE)nm) 288c2ecf20Sopenharmony_ci$(call allow-override,PKG_CONFIG,pkg-config) 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ciEXT = -std=gnu99 318c2ecf20Sopenharmony_ciINSTALL = install 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci# Use DESTDIR for installing into a different root directory. 348c2ecf20Sopenharmony_ci# This is useful for building a package. The program will be 358c2ecf20Sopenharmony_ci# installed in this directory as if it was the root directory. 368c2ecf20Sopenharmony_ci# Then the build tool can move it later. 378c2ecf20Sopenharmony_ciDESTDIR ?= 388c2ecf20Sopenharmony_ciDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ciLP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) 418c2ecf20Sopenharmony_ciifeq ($(LP64), 1) 428c2ecf20Sopenharmony_ci libdir_relative_temp = lib64 438c2ecf20Sopenharmony_cielse 448c2ecf20Sopenharmony_ci libdir_relative_temp = lib 458c2ecf20Sopenharmony_ciendif 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_cilibdir_relative ?= $(libdir_relative_temp) 488c2ecf20Sopenharmony_ciprefix ?= /usr/local 498c2ecf20Sopenharmony_cilibdir = $(prefix)/$(libdir_relative) 508c2ecf20Sopenharmony_ciman_dir = $(prefix)/share/man 518c2ecf20Sopenharmony_ciman_dir_SQ = '$(subst ','\'',$(man_dir))' 528c2ecf20Sopenharmony_cipkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \ 538c2ecf20Sopenharmony_ci --variable pc_path pkg-config | tr ":" " ")) 548c2ecf20Sopenharmony_ciincludedir_relative = traceevent 558c2ecf20Sopenharmony_ciincludedir = $(prefix)/include/$(includedir_relative) 568c2ecf20Sopenharmony_ciincludedir_SQ = '$(subst ','\'',$(includedir))' 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ciexport man_dir man_dir_SQ INSTALL 598c2ecf20Sopenharmony_ciexport DESTDIR DESTDIR_SQ 608c2ecf20Sopenharmony_ciexport EVENT_PARSE_VERSION 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciinclude ../../scripts/Makefile.include 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci# copy a bit from Linux kbuild 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ciifeq ("$(origin V)", "command line") 678c2ecf20Sopenharmony_ci VERBOSE = $(V) 688c2ecf20Sopenharmony_ciendif 698c2ecf20Sopenharmony_ciifndef VERBOSE 708c2ecf20Sopenharmony_ci VERBOSE = 0 718c2ecf20Sopenharmony_ciendif 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ciifeq ($(srctree),) 748c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(CURDIR))) 758c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree))) 768c2ecf20Sopenharmony_cisrctree := $(patsubst %/,%,$(dir $(srctree))) 778c2ecf20Sopenharmony_ci#$(info Determined 'srctree' to be $(srctree)) 788c2ecf20Sopenharmony_ciendif 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ciexport prefix libdir src obj 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci# Shell quotes 838c2ecf20Sopenharmony_cilibdir_SQ = $(subst ','\'',$(libdir)) 848c2ecf20Sopenharmony_cilibdir_relative_SQ = $(subst ','\'',$(libdir_relative)) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ciCONFIG_INCLUDES = 878c2ecf20Sopenharmony_ciCONFIG_LIBS = 888c2ecf20Sopenharmony_ciCONFIG_FLAGS = 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ciVERSION = $(EP_VERSION) 918c2ecf20Sopenharmony_ciPATCHLEVEL = $(EP_PATCHLEVEL) 928c2ecf20Sopenharmony_ciEXTRAVERSION = $(EP_EXTRAVERSION) 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ciOBJ = $@ 958c2ecf20Sopenharmony_ciN = 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ciEVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciLIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION) 1008c2ecf20Sopenharmony_ciLIB_INSTALL = libtraceevent.a libtraceevent.so* 1018c2ecf20Sopenharmony_ciLIB_INSTALL := $(addprefix $(OUTPUT),$(LIB_INSTALL)) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ciINCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES) 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci# Set compile option CFLAGS 1068c2ecf20Sopenharmony_ciifdef EXTRA_CFLAGS 1078c2ecf20Sopenharmony_ci CFLAGS := $(EXTRA_CFLAGS) 1088c2ecf20Sopenharmony_cielse 1098c2ecf20Sopenharmony_ci CFLAGS := -g -Wall 1108c2ecf20Sopenharmony_ciendif 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci# Append required CFLAGS 1138c2ecf20Sopenharmony_cioverride CFLAGS += -fPIC 1148c2ecf20Sopenharmony_cioverride CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 1158c2ecf20Sopenharmony_cioverride CFLAGS += $(udis86-flags) -D_GNU_SOURCE 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ciifeq ($(VERBOSE),1) 1188c2ecf20Sopenharmony_ci Q = 1198c2ecf20Sopenharmony_cielse 1208c2ecf20Sopenharmony_ci Q = @ 1218c2ecf20Sopenharmony_ciendif 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci# Disable command line variables (CFLAGS) override from top 1248c2ecf20Sopenharmony_ci# level Makefile (perf), otherwise build Makefile will get 1258c2ecf20Sopenharmony_ci# the same command line setup. 1268c2ecf20Sopenharmony_ciMAKEOVERRIDES= 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ciexport srctree OUTPUT CC LD CFLAGS V 1298c2ecf20Sopenharmony_cibuild := -f $(srctree)/tools/build/Makefile.build dir=. obj 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ciTE_IN := $(OUTPUT)libtraceevent-in.o 1328c2ecf20Sopenharmony_ciLIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciCMD_TARGETS = $(LIB_TARGET) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ciTARGETS = $(CMD_TARGETS) 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ciall: all_cmd plugins 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ciall_cmd: $(CMD_TARGETS) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci$(TE_IN): force 1438c2ecf20Sopenharmony_ci $(Q)$(MAKE) $(build)=libtraceevent 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci$(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN) 1468c2ecf20Sopenharmony_ci $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ 1478c2ecf20Sopenharmony_ci @ln -sf $(@F) $(OUTPUT)libtraceevent.so 1488c2ecf20Sopenharmony_ci @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION) 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci$(OUTPUT)libtraceevent.a: $(TE_IN) 1518c2ecf20Sopenharmony_ci $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_ci$(OUTPUT)%.so: $(OUTPUT)%-in.o 1548c2ecf20Sopenharmony_ci $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^ 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_cidefine make_version.h 1578c2ecf20Sopenharmony_ci (echo '/* This file is automatically generated. Do not modify. */'; \ 1588c2ecf20Sopenharmony_ci echo \#define VERSION_CODE $(shell \ 1598c2ecf20Sopenharmony_ci expr $(VERSION) \* 256 + $(PATCHLEVEL)); \ 1608c2ecf20Sopenharmony_ci echo '#define EXTRAVERSION ' $(EXTRAVERSION); \ 1618c2ecf20Sopenharmony_ci echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \ 1628c2ecf20Sopenharmony_ci echo '#define FILE_VERSION '$(FILE_VERSION); \ 1638c2ecf20Sopenharmony_ci ) > $1 1648c2ecf20Sopenharmony_ciendef 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cidefine update_version.h 1678c2ecf20Sopenharmony_ci ($(call make_version.h, $@.tmp); \ 1688c2ecf20Sopenharmony_ci if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 1698c2ecf20Sopenharmony_ci rm -f $@.tmp; \ 1708c2ecf20Sopenharmony_ci else \ 1718c2ecf20Sopenharmony_ci echo ' UPDATE $@'; \ 1728c2ecf20Sopenharmony_ci mv -f $@.tmp $@; \ 1738c2ecf20Sopenharmony_ci fi); 1748c2ecf20Sopenharmony_ciendef 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ciep_version.h: force 1778c2ecf20Sopenharmony_ci $(Q)$(N)$(call update_version.h) 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ciVERSION_FILES = ep_version.h 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cidefine update_dir 1828c2ecf20Sopenharmony_ci (echo $1 > $@.tmp; \ 1838c2ecf20Sopenharmony_ci if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 1848c2ecf20Sopenharmony_ci rm -f $@.tmp; \ 1858c2ecf20Sopenharmony_ci else \ 1868c2ecf20Sopenharmony_ci echo ' UPDATE $@'; \ 1878c2ecf20Sopenharmony_ci mv -f $@.tmp $@; \ 1888c2ecf20Sopenharmony_ci fi); 1898c2ecf20Sopenharmony_ciendef 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_citags: force 1928c2ecf20Sopenharmony_ci $(RM) tags 1938c2ecf20Sopenharmony_ci find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 1948c2ecf20Sopenharmony_ci --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_ciTAGS: force 1978c2ecf20Sopenharmony_ci $(RM) TAGS 1988c2ecf20Sopenharmony_ci find . -name '*.[ch]' | xargs etags \ 1998c2ecf20Sopenharmony_ci --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cidefine do_install_mkdir 2028c2ecf20Sopenharmony_ci if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 2038c2ecf20Sopenharmony_ci $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 2048c2ecf20Sopenharmony_ci fi 2058c2ecf20Sopenharmony_ciendef 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_cidefine do_install 2088c2ecf20Sopenharmony_ci $(call do_install_mkdir,$2); \ 2098c2ecf20Sopenharmony_ci $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' 2108c2ecf20Sopenharmony_ciendef 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ciPKG_CONFIG_SOURCE_FILE = libtraceevent.pc 2138c2ecf20Sopenharmony_ciPKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE)) 2148c2ecf20Sopenharmony_cidefine do_install_pkgconfig_file 2158c2ecf20Sopenharmony_ci if [ -n "${pkgconfig_dir}" ]; then \ 2168c2ecf20Sopenharmony_ci cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE}; \ 2178c2ecf20Sopenharmony_ci sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \ 2188c2ecf20Sopenharmony_ci sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \ 2198c2ecf20Sopenharmony_ci sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \ 2208c2ecf20Sopenharmony_ci sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \ 2218c2ecf20Sopenharmony_ci $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \ 2228c2ecf20Sopenharmony_ci else \ 2238c2ecf20Sopenharmony_ci (echo Failed to locate pkg-config directory) 1>&2; \ 2248c2ecf20Sopenharmony_ci fi 2258c2ecf20Sopenharmony_ciendef 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ciinstall_lib: all_cmd install_plugins install_headers install_pkgconfig 2288c2ecf20Sopenharmony_ci $(call QUIET_INSTALL, $(LIB_TARGET)) \ 2298c2ecf20Sopenharmony_ci $(call do_install_mkdir,$(libdir_SQ)); \ 2308c2ecf20Sopenharmony_ci cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ) 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ciinstall_pkgconfig: 2338c2ecf20Sopenharmony_ci $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \ 2348c2ecf20Sopenharmony_ci $(call do_install_pkgconfig_file,$(prefix)) 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_ciinstall_headers: 2378c2ecf20Sopenharmony_ci $(call QUIET_INSTALL, headers) \ 2388c2ecf20Sopenharmony_ci $(call do_install,event-parse.h,$(includedir_SQ),644); \ 2398c2ecf20Sopenharmony_ci $(call do_install,event-utils.h,$(includedir_SQ),644); \ 2408c2ecf20Sopenharmony_ci $(call do_install,trace-seq.h,$(includedir_SQ),644); \ 2418c2ecf20Sopenharmony_ci $(call do_install,kbuffer.h,$(includedir_SQ),644) 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ciinstall: install_lib 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ciclean: clean_plugins 2468c2ecf20Sopenharmony_ci $(call QUIET_CLEAN, libtraceevent) \ 2478c2ecf20Sopenharmony_ci $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ 2488c2ecf20Sopenharmony_ci $(RM) TRACEEVENT-CFLAGS tags TAGS; \ 2498c2ecf20Sopenharmony_ci $(RM) $(PKG_CONFIG_FILE) 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ciPHONY += doc 2528c2ecf20Sopenharmony_cidoc: 2538c2ecf20Sopenharmony_ci $(call descend,Documentation) 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ciPHONY += doc-clean 2568c2ecf20Sopenharmony_cidoc-clean: 2578c2ecf20Sopenharmony_ci $(call descend,Documentation,clean) 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ciPHONY += doc-install 2608c2ecf20Sopenharmony_cidoc-install: 2618c2ecf20Sopenharmony_ci $(call descend,Documentation,install) 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ciPHONY += doc-uninstall 2648c2ecf20Sopenharmony_cidoc-uninstall: 2658c2ecf20Sopenharmony_ci $(call descend,Documentation,uninstall) 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ciPHONY += help 2688c2ecf20Sopenharmony_cihelp: 2698c2ecf20Sopenharmony_ci @echo 'Possible targets:' 2708c2ecf20Sopenharmony_ci @echo'' 2718c2ecf20Sopenharmony_ci @echo ' all - default, compile the library and the'\ 2728c2ecf20Sopenharmony_ci 'plugins' 2738c2ecf20Sopenharmony_ci @echo ' plugins - compile the plugins' 2748c2ecf20Sopenharmony_ci @echo ' install - install the library, the plugins,'\ 2758c2ecf20Sopenharmony_ci 'the header and pkgconfig files' 2768c2ecf20Sopenharmony_ci @echo ' clean - clean the library and the plugins object files' 2778c2ecf20Sopenharmony_ci @echo ' doc - compile the documentation files - man'\ 2788c2ecf20Sopenharmony_ci 'and html pages, in the Documentation directory' 2798c2ecf20Sopenharmony_ci @echo ' doc-clean - clean the documentation files' 2808c2ecf20Sopenharmony_ci @echo ' doc-install - install the man pages' 2818c2ecf20Sopenharmony_ci @echo ' doc-uninstall - uninstall the man pages' 2828c2ecf20Sopenharmony_ci @echo'' 2838c2ecf20Sopenharmony_ci 2848c2ecf20Sopenharmony_ciPHONY += plugins 2858c2ecf20Sopenharmony_ciplugins: 2868c2ecf20Sopenharmony_ci $(call descend,plugins) 2878c2ecf20Sopenharmony_ci 2888c2ecf20Sopenharmony_ciPHONY += install_plugins 2898c2ecf20Sopenharmony_ciinstall_plugins: 2908c2ecf20Sopenharmony_ci $(call descend,plugins,install) 2918c2ecf20Sopenharmony_ci 2928c2ecf20Sopenharmony_ciPHONY += clean_plugins 2938c2ecf20Sopenharmony_ciclean_plugins: 2948c2ecf20Sopenharmony_ci $(call descend,plugins,clean) 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ciforce: 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci# Declare the contents of the .PHONY variable as phony. We keep that 2998c2ecf20Sopenharmony_ci# information in a variable so we can use it in if_changed and friends. 3008c2ecf20Sopenharmony_ci.PHONY: $(PHONY) 301