]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/lib/traceevent/Makefile
Merge tag 'devicetree-for-4.20' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-hirsute-kernel.git] / tools / lib / traceevent / Makefile
CommitLineData
b2441318 1# SPDX-License-Identifier: GPL-2.0
f7d82350
SR
2# trace-cmd version
3EP_VERSION = 1
4EP_PATCHLEVEL = 1
5EP_EXTRAVERSION = 0
6
7# file format version
8FILE_VERSION = 6
9
10MAKEFLAGS += --no-print-directory
11
12
13# Makefiles suck: This macro sets a default value of $(2) for the
14# variable named by $(1), unless the variable has been set by
15# environment or command line. This is necessary for CC and AR
16# because make sets default values, so the simpler ?= approach
17# won't work as expected.
18define allow-override
19 $(if $(or $(findstring environment,$(origin $(1))),\
20 $(findstring command line,$(origin $(1)))),,\
21 $(eval $(1) = $(2)))
22endef
23
24# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
25$(call allow-override,CC,$(CROSS_COMPILE)gcc)
26$(call allow-override,AR,$(CROSS_COMPILE)ar)
e3d09ec8 27$(call allow-override,NM,$(CROSS_COMPILE)nm)
f7d82350
SR
28
29EXT = -std=gnu99
30INSTALL = install
31
32# Use DESTDIR for installing into a different root directory.
33# This is useful for building a package. The program will be
34# installed in this directory as if it was the root directory.
35# Then the build tool can move it later.
36DESTDIR ?=
37DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
38
bb53e176
WN
39LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
40ifeq ($(LP64), 1)
41 libdir_relative = lib64
42else
43 libdir_relative = lib
44endif
45
f7d82350 46prefix ?= /usr/local
bb53e176 47libdir = $(prefix)/$(libdir_relative)
f7d82350
SR
48man_dir = $(prefix)/share/man
49man_dir_SQ = '$(subst ','\'',$(man_dir))'
f7d82350 50
9f1efa82 51export man_dir man_dir_SQ INSTALL
f7d82350
SR
52export DESTDIR DESTDIR_SQ
53
e0e96d03
JO
54set_plugin_dir := 1
55
56# Set plugin_dir to preffered global plugin location
57# If we install under $HOME directory we go under
58# $(HOME)/.traceevent/plugins
59#
60# We dont set PLUGIN_DIR in case we install under $HOME
61# directory, because by default the code looks under:
62# $(HOME)/.traceevent/plugins by default.
63#
64ifeq ($(plugin_dir),)
65ifeq ($(prefix),$(HOME))
66override plugin_dir = $(HOME)/.traceevent/plugins
67set_plugin_dir := 0
68else
bb53e176 69override plugin_dir = $(libdir)/traceevent/plugins
e0e96d03
JO
70endif
71endif
72
73ifeq ($(set_plugin_dir),1)
b935a58d 74PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
e0e96d03
JO
75PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
76endif
77
2d58ab9b 78include ../../scripts/Makefile.include
c3d090f4 79
f7d82350
SR
80# copy a bit from Linux kbuild
81
82ifeq ("$(origin V)", "command line")
83 VERBOSE = $(V)
84endif
85ifndef VERBOSE
86 VERBOSE = 0
87endif
88
2d58ab9b 89ifeq ($(srctree),)
e19b7cee 90srctree := $(patsubst %/,%,$(dir $(CURDIR)))
2d58ab9b
JO
91srctree := $(patsubst %/,%,$(dir $(srctree)))
92srctree := $(patsubst %/,%,$(dir $(srctree)))
93#$(info Determined 'srctree' to be $(srctree))
f7d82350
SR
94endif
95
bb53e176 96export prefix libdir src obj
f7d82350
SR
97
98# Shell quotes
bb53e176
WN
99libdir_SQ = $(subst ','\'',$(libdir))
100libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
e0e96d03 101plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
f7d82350 102
f7d82350
SR
103CONFIG_INCLUDES =
104CONFIG_LIBS =
105CONFIG_FLAGS =
106
107VERSION = $(EP_VERSION)
108PATCHLEVEL = $(EP_PATCHLEVEL)
109EXTRAVERSION = $(EP_EXTRAVERSION)
110
111OBJ = $@
112N =
113
f7d82350
SR
114EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
115
fe316723
JO
116LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
117LIB_INSTALL = libtraceevent.a libtraceevent.so*
118
2d58ab9b 119INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
f7d82350 120
2d58ab9b
JO
121# Set compile option CFLAGS
122ifdef EXTRA_CFLAGS
123 CFLAGS := $(EXTRA_CFLAGS)
124else
125 CFLAGS := -g -Wall
126endif
f7d82350
SR
127
128# Append required CFLAGS
2d58ab9b 129override CFLAGS += -fPIC
f7d82350 130override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
c055875b 131override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
f7d82350
SR
132
133ifeq ($(VERBOSE),1)
134 Q =
f7d82350
SR
135else
136 Q = @
f7d82350
SR
137endif
138
505d3085 139# Disable command line variables (CFLAGS) override from top
2d58ab9b
JO
140# level Makefile (perf), otherwise build Makefile will get
141# the same command line setup.
142MAKEOVERRIDES=
f7d82350 143
2d58ab9b
JO
144export srctree OUTPUT CC LD CFLAGS V
145build := -f $(srctree)/tools/build/Makefile.build dir=. obj
f7d82350 146
2d58ab9b
JO
147PLUGINS = plugin_jbd2.so
148PLUGINS += plugin_hrtimer.so
149PLUGINS += plugin_kmem.so
150PLUGINS += plugin_kvm.so
151PLUGINS += plugin_mac80211.so
152PLUGINS += plugin_sched_switch.so
153PLUGINS += plugin_function.so
154PLUGINS += plugin_xen.so
155PLUGINS += plugin_scsi.so
156PLUGINS += plugin_cfg80211.so
f7d82350 157
2d58ab9b
JO
158PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
159PLUGINS_IN := $(PLUGINS:.so=-in.o)
f7d82350 160
39944a76
JO
161TE_IN := $(OUTPUT)libtraceevent-in.o
162LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
e3d09ec8 163DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
f7d82350 164
39944a76 165CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE)
f7d82350
SR
166
167TARGETS = $(CMD_TARGETS)
168
f7d82350
SR
169all: all_cmd
170
171all_cmd: $(CMD_TARGETS)
172
2d58ab9b
JO
173$(TE_IN): force
174 $(Q)$(MAKE) $(build)=libtraceevent
175
fe316723
JO
176$(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
177 $(QUIET_LINK)$(CC) --shared $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
178 @ln -sf $(@F) $(OUTPUT)libtraceevent.so
179 @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
f7d82350 180
2d58ab9b 181$(OUTPUT)libtraceevent.a: $(TE_IN)
e6262e23 182 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
f7d82350 183
e3d09ec8
HK
184$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
185 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
186
e0e96d03
JO
187plugins: $(PLUGINS)
188
2d58ab9b
JO
189__plugin_obj = $(notdir $@)
190 plugin_obj = $(__plugin_obj:-in.o=)
f7d82350 191
2d58ab9b
JO
192$(PLUGINS_IN): force
193 $(Q)$(MAKE) $(build)=$(plugin_obj)
e0e96d03 194
2d58ab9b
JO
195$(OUTPUT)%.so: $(OUTPUT)%-in.o
196 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
e0e96d03 197
f7d82350 198define make_version.h
198430b5
JO
199 (echo '/* This file is automatically generated. Do not modify. */'; \
200 echo \#define VERSION_CODE $(shell \
201 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
202 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
203 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
204 echo '#define FILE_VERSION '$(FILE_VERSION); \
205 ) > $1
f7d82350
SR
206endef
207
208define update_version.h
198430b5
JO
209 ($(call make_version.h, $@.tmp); \
210 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
211 rm -f $@.tmp; \
212 else \
213 echo ' UPDATE $@'; \
214 mv -f $@.tmp $@; \
215 fi);
f7d82350
SR
216endef
217
218ep_version.h: force
219 $(Q)$(N)$(call update_version.h)
220
221VERSION_FILES = ep_version.h
222
223define update_dir
198430b5
JO
224 (echo $1 > $@.tmp; \
225 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
226 rm -f $@.tmp; \
227 else \
228 echo ' UPDATE $@'; \
229 mv -f $@.tmp $@; \
230 fi);
f7d82350
SR
231endef
232
f7d82350
SR
233tags: force
234 $(RM) tags
6545e3a8 235 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
d97f4ef1 236 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
f7d82350
SR
237
238TAGS: force
239 $(RM) TAGS
6545e3a8 240 find . -name '*.[ch]' | xargs etags \
d97f4ef1 241 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
f7d82350 242
c121bdbb
JO
243define do_install_mkdir
244 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
245 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
246 fi
247endef
248
f7d82350 249define do_install
c121bdbb 250 $(call do_install_mkdir,$2); \
722a4984 251 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
f7d82350
SR
252endef
253
02a82c7b
JO
254define do_install_plugins
255 for plugin in $1; do \
256 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
257 done
258endef
e0e96d03 259
e3d09ec8 260define do_generate_dynamic_list_file
6467753d
DCC
261 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
262 xargs echo "U W w" | tr ' ' '\n' | sort -u | xargs echo`;\
263 if [ "$$symbol_type" = "U W w" ];then \
264 (echo '{'; \
265 $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\
266 echo '};'; \
267 ) > $2; \
268 else \
269 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
270 fi
e3d09ec8
HK
271endef
272
02a82c7b 273install_lib: all_cmd install_plugins
39944a76 274 $(call QUIET_INSTALL, $(LIB_TARGET)) \
fe316723
JO
275 $(call do_install_mkdir,$(libdir_SQ)); \
276 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
e0e96d03 277
02a82c7b
JO
278install_plugins: $(PLUGINS)
279 $(call QUIET_INSTALL, trace_plugins) \
280 $(call do_install_plugins, $(PLUGINS))
e0e96d03 281
722a4984
JO
282install_headers:
283 $(call QUIET_INSTALL, headers) \
284 $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \
285 $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \
286 $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644)
287
f7d82350
SR
288install: install_lib
289
290clean:
4a953c71 291 $(call QUIET_CLEAN, libtraceevent) \
c867b150 292 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
4a953c71 293 $(RM) TRACEEVENT-CFLAGS tags TAGS
f7d82350 294
9bb8e5ed 295PHONY += force plugins
f7d82350
SR
296force:
297
298# Declare the contents of the .PHONY variable as phony. We keep that
299# information in a variable so we can use it in if_changed and friends.
300.PHONY: $(PHONY)