xref: /OK3568_Linux_fs/kernel/tools/lib/traceevent/plugins/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun#MAKEFLAGS += --no-print-directory
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun# Makefiles suck: This macro sets a default value of $(2) for the
7*4882a593Smuzhiyun# variable named by $(1), unless the variable has been set by
8*4882a593Smuzhiyun# environment or command line. This is necessary for CC and AR
9*4882a593Smuzhiyun# because make sets default values, so the simpler ?= approach
10*4882a593Smuzhiyun# won't work as expected.
11*4882a593Smuzhiyundefine allow-override
12*4882a593Smuzhiyun  $(if $(or $(findstring environment,$(origin $(1))),\
13*4882a593Smuzhiyun            $(findstring command line,$(origin $(1)))),,\
14*4882a593Smuzhiyun    $(eval $(1) = $(2)))
15*4882a593Smuzhiyunendef
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
18*4882a593Smuzhiyun$(call allow-override,CC,$(CROSS_COMPILE)gcc)
19*4882a593Smuzhiyun$(call allow-override,AR,$(CROSS_COMPILE)ar)
20*4882a593Smuzhiyun$(call allow-override,NM,$(CROSS_COMPILE)nm)
21*4882a593Smuzhiyun$(call allow-override,PKG_CONFIG,pkg-config)
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunEXT = -std=gnu99
24*4882a593SmuzhiyunINSTALL = install
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun# Use DESTDIR for installing into a different root directory.
27*4882a593Smuzhiyun# This is useful for building a package. The program will be
28*4882a593Smuzhiyun# installed in this directory as if it was the root directory.
29*4882a593Smuzhiyun# Then the build tool can move it later.
30*4882a593SmuzhiyunDESTDIR ?=
31*4882a593SmuzhiyunDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunLP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
34*4882a593Smuzhiyunifeq ($(LP64), 1)
35*4882a593Smuzhiyun  libdir_relative_tmp = lib64
36*4882a593Smuzhiyunelse
37*4882a593Smuzhiyun  libdir_relative_tmp = lib
38*4882a593Smuzhiyunendif
39*4882a593Smuzhiyun
40*4882a593Smuzhiyunlibdir_relative ?= $(libdir_relative_tmp)
41*4882a593Smuzhiyunprefix ?= /usr/local
42*4882a593Smuzhiyunlibdir = $(prefix)/$(libdir_relative)
43*4882a593Smuzhiyun
44*4882a593Smuzhiyunset_plugin_dir := 1
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun# Set plugin_dir to preffered global plugin location
47*4882a593Smuzhiyun# If we install under $HOME directory we go under
48*4882a593Smuzhiyun# $(HOME)/.local/lib/traceevent/plugins
49*4882a593Smuzhiyun#
50*4882a593Smuzhiyun# We dont set PLUGIN_DIR in case we install under $HOME
51*4882a593Smuzhiyun# directory, because by default the code looks under:
52*4882a593Smuzhiyun# $(HOME)/.local/lib/traceevent/plugins by default.
53*4882a593Smuzhiyun#
54*4882a593Smuzhiyunifeq ($(plugin_dir),)
55*4882a593Smuzhiyunifeq ($(prefix),$(HOME))
56*4882a593Smuzhiyunoverride plugin_dir = $(HOME)/.local/lib/traceevent/plugins
57*4882a593Smuzhiyunset_plugin_dir := 0
58*4882a593Smuzhiyunelse
59*4882a593Smuzhiyunoverride plugin_dir = $(libdir)/traceevent/plugins
60*4882a593Smuzhiyunendif
61*4882a593Smuzhiyunendif
62*4882a593Smuzhiyun
63*4882a593Smuzhiyunifeq ($(set_plugin_dir),1)
64*4882a593SmuzhiyunPLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
65*4882a593SmuzhiyunPLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
66*4882a593Smuzhiyunendif
67*4882a593Smuzhiyun
68*4882a593Smuzhiyuninclude ../../../scripts/Makefile.include
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun# copy a bit from Linux kbuild
71*4882a593Smuzhiyun
72*4882a593Smuzhiyunifeq ("$(origin V)", "command line")
73*4882a593Smuzhiyun  VERBOSE = $(V)
74*4882a593Smuzhiyunendif
75*4882a593Smuzhiyunifndef VERBOSE
76*4882a593Smuzhiyun  VERBOSE = 0
77*4882a593Smuzhiyunendif
78*4882a593Smuzhiyun
79*4882a593Smuzhiyunifeq ($(srctree),)
80*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
81*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(srctree)))
82*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(srctree)))
83*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(srctree)))
84*4882a593Smuzhiyun#$(info Determined 'srctree' to be $(srctree))
85*4882a593Smuzhiyunendif
86*4882a593Smuzhiyun
87*4882a593Smuzhiyunexport prefix libdir src obj
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun# Shell quotes
90*4882a593Smuzhiyunplugin_dir_SQ = $(subst ','\'',$(plugin_dir))
91*4882a593Smuzhiyun
92*4882a593SmuzhiyunCONFIG_INCLUDES =
93*4882a593SmuzhiyunCONFIG_LIBS    =
94*4882a593SmuzhiyunCONFIG_FLAGS   =
95*4882a593Smuzhiyun
96*4882a593SmuzhiyunOBJ            = $@
97*4882a593SmuzhiyunN              =
98*4882a593Smuzhiyun
99*4882a593SmuzhiyunINCLUDES = -I. -I.. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun# Set compile option CFLAGS
102*4882a593Smuzhiyunifdef EXTRA_CFLAGS
103*4882a593Smuzhiyun  CFLAGS := $(EXTRA_CFLAGS)
104*4882a593Smuzhiyunelse
105*4882a593Smuzhiyun  CFLAGS := -g -Wall
106*4882a593Smuzhiyunendif
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun# Append required CFLAGS
109*4882a593Smuzhiyunoverride CFLAGS += -fPIC
110*4882a593Smuzhiyunoverride CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
111*4882a593Smuzhiyunoverride CFLAGS += $(udis86-flags) -D_GNU_SOURCE
112*4882a593Smuzhiyun
113*4882a593Smuzhiyunifeq ($(VERBOSE),1)
114*4882a593Smuzhiyun  Q =
115*4882a593Smuzhiyunelse
116*4882a593Smuzhiyun  Q = @
117*4882a593Smuzhiyunendif
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun# Disable command line variables (CFLAGS) override from top
120*4882a593Smuzhiyun# level Makefile (perf), otherwise build Makefile will get
121*4882a593Smuzhiyun# the same command line setup.
122*4882a593SmuzhiyunMAKEOVERRIDES=
123*4882a593Smuzhiyun
124*4882a593Smuzhiyunexport srctree OUTPUT CC LD CFLAGS V
125*4882a593Smuzhiyun
126*4882a593Smuzhiyunbuild := -f $(srctree)/tools/build/Makefile.build dir=. obj
127*4882a593Smuzhiyun
128*4882a593SmuzhiyunDYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
129*4882a593Smuzhiyun
130*4882a593SmuzhiyunPLUGINS  = plugin_jbd2.so
131*4882a593SmuzhiyunPLUGINS += plugin_hrtimer.so
132*4882a593SmuzhiyunPLUGINS += plugin_kmem.so
133*4882a593SmuzhiyunPLUGINS += plugin_kvm.so
134*4882a593SmuzhiyunPLUGINS += plugin_mac80211.so
135*4882a593SmuzhiyunPLUGINS += plugin_sched_switch.so
136*4882a593SmuzhiyunPLUGINS += plugin_function.so
137*4882a593SmuzhiyunPLUGINS += plugin_futex.so
138*4882a593SmuzhiyunPLUGINS += plugin_xen.so
139*4882a593SmuzhiyunPLUGINS += plugin_scsi.so
140*4882a593SmuzhiyunPLUGINS += plugin_cfg80211.so
141*4882a593SmuzhiyunPLUGINS += plugin_tlb.so
142*4882a593Smuzhiyun
143*4882a593SmuzhiyunPLUGINS    := $(addprefix $(OUTPUT),$(PLUGINS))
144*4882a593SmuzhiyunPLUGINS_IN := $(PLUGINS:.so=-in.o)
145*4882a593Smuzhiyun
146*4882a593Smuzhiyunplugins: $(PLUGINS) $(DYNAMIC_LIST_FILE)
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun__plugin_obj = $(notdir $@)
149*4882a593Smuzhiyun  plugin_obj = $(__plugin_obj:-in.o=)
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun$(PLUGINS_IN): force
152*4882a593Smuzhiyun	$(Q)$(MAKE) $(build)=$(plugin_obj)
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
155*4882a593Smuzhiyun	$(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun$(OUTPUT)%.so: $(OUTPUT)%-in.o
158*4882a593Smuzhiyun	$(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
159*4882a593Smuzhiyun
160*4882a593Smuzhiyundefine update_dir
161*4882a593Smuzhiyun  (echo $1 > $@.tmp;                           \
162*4882a593Smuzhiyun   if [ -r $@ ] && cmp -s $@ $@.tmp; then      \
163*4882a593Smuzhiyun     rm -f $@.tmp;                             \
164*4882a593Smuzhiyun   else                                                \
165*4882a593Smuzhiyun     echo '  UPDATE                 $@';       \
166*4882a593Smuzhiyun     mv -f $@.tmp $@;                          \
167*4882a593Smuzhiyun   fi);
168*4882a593Smuzhiyunendef
169*4882a593Smuzhiyun
170*4882a593Smuzhiyuntags:	force
171*4882a593Smuzhiyun	$(RM) tags
172*4882a593Smuzhiyun	find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
173*4882a593Smuzhiyun	--regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
174*4882a593Smuzhiyun
175*4882a593SmuzhiyunTAGS:	force
176*4882a593Smuzhiyun	$(RM) TAGS
177*4882a593Smuzhiyun	find . -name '*.[ch]' | xargs etags \
178*4882a593Smuzhiyun	--regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
179*4882a593Smuzhiyun
180*4882a593Smuzhiyundefine do_install_mkdir
181*4882a593Smuzhiyun	if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
182*4882a593Smuzhiyun		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
183*4882a593Smuzhiyun	fi
184*4882a593Smuzhiyunendef
185*4882a593Smuzhiyun
186*4882a593Smuzhiyundefine do_install
187*4882a593Smuzhiyun	$(call do_install_mkdir,$2);                    \
188*4882a593Smuzhiyun	$(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
189*4882a593Smuzhiyunendef
190*4882a593Smuzhiyun
191*4882a593Smuzhiyundefine do_install_plugins
192*4882a593Smuzhiyun       for plugin in $1; do                            \
193*4882a593Smuzhiyun         $(call do_install,$$plugin,$(plugin_dir_SQ)); \
194*4882a593Smuzhiyun       done
195*4882a593Smuzhiyunendef
196*4882a593Smuzhiyun
197*4882a593Smuzhiyundefine do_generate_dynamic_list_file
198*4882a593Smuzhiyun	symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
199*4882a593Smuzhiyun	xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\
200*4882a593Smuzhiyun	if [ "$$symbol_type" = "U W" ];then				\
201*4882a593Smuzhiyun		(echo '{';                                              \
202*4882a593Smuzhiyun		$(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\
203*4882a593Smuzhiyun		echo '};';                                              \
204*4882a593Smuzhiyun		) > $2;                                                 \
205*4882a593Smuzhiyun	else                                                            \
206*4882a593Smuzhiyun		(echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
207*4882a593Smuzhiyun		fi
208*4882a593Smuzhiyunendef
209*4882a593Smuzhiyun
210*4882a593Smuzhiyuninstall: $(PLUGINS)
211*4882a593Smuzhiyun	$(call QUIET_INSTALL, trace_plugins) \
212*4882a593Smuzhiyun	$(call do_install_plugins, $(PLUGINS))
213*4882a593Smuzhiyun
214*4882a593Smuzhiyunclean:
215*4882a593Smuzhiyun	$(call QUIET_CLEAN, trace_plugins) \
216*4882a593Smuzhiyun		$(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
217*4882a593Smuzhiyun		$(RM) $(OUTPUT)libtraceevent-dynamic-list \
218*4882a593Smuzhiyun		$(RM) TRACEEVENT-CFLAGS tags TAGS;
219*4882a593Smuzhiyun
220*4882a593SmuzhiyunPHONY += force plugins
221*4882a593Smuzhiyunforce:
222*4882a593Smuzhiyun
223*4882a593Smuzhiyun# Declare the contents of the .PHONY variable as phony.  We keep that
224*4882a593Smuzhiyun# information in a variable so we can use it in if_changed and friends.
225*4882a593Smuzhiyun.PHONY: $(PHONY)
226