1# SPDX-License-Identifier: GPL-2.0 2 3#MAKEFLAGS += --no-print-directory 4 5 6# Makefiles suck: This macro sets a default value of $(2) for the 7# variable named by $(1), unless the variable has been set by 8# environment or command line. This is necessary for CC and AR 9# because make sets default values, so the simpler ?= approach 10# won't work as expected. 11define allow-override 12 $(if $(or $(findstring environment,$(origin $(1))),\ 13 $(findstring command line,$(origin $(1)))),,\ 14 $(eval $(1) = $(2))) 15endef 16 17# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. 18$(call allow-override,CC,$(CROSS_COMPILE)gcc) 19$(call allow-override,AR,$(CROSS_COMPILE)ar) 20$(call allow-override,NM,$(CROSS_COMPILE)nm) 21$(call allow-override,PKG_CONFIG,pkg-config) 22 23EXT = -std=gnu99 24INSTALL = install 25 26# Use DESTDIR for installing into a different root directory. 27# This is useful for building a package. The program will be 28# installed in this directory as if it was the root directory. 29# Then the build tool can move it later. 30DESTDIR ?= 31DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' 32 33LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) 34ifeq ($(LP64), 1) 35 libdir_relative_tmp = lib64 36else 37 libdir_relative_tmp = lib 38endif 39 40libdir_relative ?= $(libdir_relative_tmp) 41prefix ?= /usr/local 42libdir = $(prefix)/$(libdir_relative) 43 44include ../scripts/utils.mk 45 46# copy a bit from Linux kbuild 47 48ifeq ("$(origin V)", "command line") 49 VERBOSE = $(V) 50endif 51ifndef VERBOSE 52 VERBOSE = 0 53endif 54 55# Shell quotes 56plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) 57 58CONFIG_INCLUDES = 59CONFIG_LIBS = 60CONFIG_FLAGS = 61 62OBJ = $@ 63N = 64 65INCLUDES = -I. -I.. -I../src -I $(srctree)/include -I $(EP_HEADERS_DIR) $(CONFIG_INCLUDES) 66 67# Set compile option CFLAGS 68ifdef EXTRA_CFLAGS 69 CFLAGS := $(EXTRA_CFLAGS) 70else 71 CFLAGS := -g -Wall 72endif 73 74# Append required CFLAGS 75override CFLAGS += -fPIC 76override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 77override CFLAGS += $(udis86-flags) -D_GNU_SOURCE 78 79ifeq ($(VERBOSE),1) 80 Q = 81else 82 Q = @ 83endif 84 85export srctree OUTPUT CC LD CFLAGS V 86 87DYNAMIC_LIST_FILE := $(bdir)/libtraceevent-dynamic-list 88 89PLUGINS = plugin_jbd2.so 90PLUGINS += plugin_hrtimer.so 91PLUGINS += plugin_kmem.so 92PLUGINS += plugin_kvm.so 93PLUGINS += plugin_mac80211.so 94PLUGINS += plugin_sched_switch.so 95PLUGINS += plugin_function.so 96PLUGINS += plugin_futex.so 97PLUGINS += plugin_xen.so 98PLUGINS += plugin_scsi.so 99PLUGINS += plugin_cfg80211.so 100PLUGINS += plugin_tlb.so 101 102PLUGINS := $(PLUGINS:%.so=$(bdir)/%.so) 103DEPS := $(PLUGINS:$(bdir)/%.so=$(bdir)/.%.d) 104 105plugins: $(PLUGINS) $(DYNAMIC_LIST_FILE) 106 107$(PLUGINS): | $(bdir) 108$(DEPS): | $(bdir) 109 110$(bdir)/%.so: $(srctree)/plugins/%.c 111 $(Q)$(call do_plugin_build) 112 113define update_dir 114 (echo $1 > $@.tmp; \ 115 if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 116 rm -f $@.tmp; \ 117 else \ 118 echo ' UPDATE $@'; \ 119 mv -f $@.tmp $@; \ 120 fi); 121endef 122 123tags: force 124 $(RM) tags 125 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 126 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' 127 128TAGS: force 129 $(RM) TAGS 130 find . -name '*.[ch]' | xargs etags \ 131 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' 132 133define do_install_plugins 134 for plugin in $1; do \ 135 $(call do_install,$$plugin,$(plugin_dir_SQ)); \ 136 done 137endef 138 139define do_generate_dynamic_list_file 140 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \ 141 xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\ 142 if [ "$$symbol_type" = "U W" ];then \ 143 (echo '{'; \ 144 $(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\ 145 echo '};'; \ 146 ) > $2; \ 147 else \ 148 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\ 149 fi 150endef 151 152$(DYNAMIC_LIST_FILE): $(PLUGINS) 153 $(Q)($(print_gen)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)) 154 155install: $(PLUGINS) 156 $(Q)$(call do_install_plugins, $(PLUGINS)) 157 158clean: 159 $(Q)$(call do_clean, $(DYNAMIC_LIST_FILE) $(PLUGINS)) 160 161PHONY += force plugins $(DYNAMIC_LIST_FILE) 162force: 163 164# Declare the contents of the .PHONY variable as phony. We keep that 165# information in a variable so we can use it in if_changed and friends. 166.PHONY: $(PHONY) 167