]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/lib/traceevent/Makefile
perf tools: Fix traceevent plugin path definitions
[mirror_ubuntu-bionic-kernel.git] / tools / lib / traceevent / Makefile
CommitLineData
f7d82350
SR
1# trace-cmd version
2EP_VERSION = 1
3EP_PATCHLEVEL = 1
4EP_EXTRAVERSION = 0
5
6# file format version
7FILE_VERSION = 6
8
9MAKEFLAGS += --no-print-directory
10
11
12# Makefiles suck: This macro sets a default value of $(2) for the
13# variable named by $(1), unless the variable has been set by
14# environment or command line. This is necessary for CC and AR
15# because make sets default values, so the simpler ?= approach
16# won't work as expected.
17define allow-override
18 $(if $(or $(findstring environment,$(origin $(1))),\
19 $(findstring command line,$(origin $(1)))),,\
20 $(eval $(1) = $(2)))
21endef
22
23# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
24$(call allow-override,CC,$(CROSS_COMPILE)gcc)
25$(call allow-override,AR,$(CROSS_COMPILE)ar)
26
27EXT = -std=gnu99
28INSTALL = install
29
30# Use DESTDIR for installing into a different root directory.
31# This is useful for building a package. The program will be
32# installed in this directory as if it was the root directory.
33# Then the build tool can move it later.
34DESTDIR ?=
35DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
36
37prefix ?= /usr/local
38bindir_relative = bin
39bindir = $(prefix)/$(bindir_relative)
40man_dir = $(prefix)/share/man
41man_dir_SQ = '$(subst ','\'',$(man_dir))'
f7d82350 42
9f1efa82 43export man_dir man_dir_SQ INSTALL
f7d82350
SR
44export DESTDIR DESTDIR_SQ
45
e0e96d03
JO
46set_plugin_dir := 1
47
48# Set plugin_dir to preffered global plugin location
49# If we install under $HOME directory we go under
50# $(HOME)/.traceevent/plugins
51#
52# We dont set PLUGIN_DIR in case we install under $HOME
53# directory, because by default the code looks under:
54# $(HOME)/.traceevent/plugins by default.
55#
56ifeq ($(plugin_dir),)
57ifeq ($(prefix),$(HOME))
58override plugin_dir = $(HOME)/.traceevent/plugins
59set_plugin_dir := 0
60else
61override plugin_dir = $(prefix)/lib/traceevent/plugins
62endif
63endif
64
65ifeq ($(set_plugin_dir),1)
b935a58d 66PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
e0e96d03
JO
67PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68endif
69
c3d090f4
JO
70include $(if $(BUILD_SRC),$(BUILD_SRC)/)../../scripts/Makefile.include
71
f7d82350
SR
72# copy a bit from Linux kbuild
73
74ifeq ("$(origin V)", "command line")
75 VERBOSE = $(V)
76endif
77ifndef VERBOSE
78 VERBOSE = 0
79endif
80
81ifeq ("$(origin O)", "command line")
82 BUILD_OUTPUT := $(O)
83endif
84
85ifeq ($(BUILD_SRC),)
4c7aafc9 86ifneq ($(OUTPUT),)
f7d82350
SR
87
88define build_output
198430b5
JO
89 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(OUTPUT) \
90 BUILD_SRC=$(CURDIR)/ -f $(CURDIR)/Makefile $1
f7d82350
SR
91endef
92
f7d82350
SR
93all: sub-make
94
4ccdf57d 95$(MAKECMDGOALS): sub-make
f7d82350
SR
96
97sub-make: force
98 $(call build_output, $(MAKECMDGOALS))
99
100
101# Leave processing to above invocation of make
102skip-makefile := 1
103
4c7aafc9 104endif # OUTPUT
f7d82350
SR
105endif # BUILD_SRC
106
107# We process the rest of the Makefile if this is the final invocation of make
108ifeq ($(skip-makefile),)
109
110srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
111objtree := $(CURDIR)
112src := $(srctree)
113obj := $(objtree)
114
115export prefix bindir src obj
116
117# Shell quotes
118bindir_SQ = $(subst ','\'',$(bindir))
119bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
e0e96d03 120plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
f7d82350
SR
121
122LIB_FILE = libtraceevent.a libtraceevent.so
123
124CONFIG_INCLUDES =
125CONFIG_LIBS =
126CONFIG_FLAGS =
127
128VERSION = $(EP_VERSION)
129PATCHLEVEL = $(EP_PATCHLEVEL)
130EXTRAVERSION = $(EP_EXTRAVERSION)
131
132OBJ = $@
133N =
134
135export Q VERBOSE
136
137EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
138
3c6d8d84 139INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
f7d82350
SR
140
141# Set compile option CFLAGS if not set elsewhere
142CFLAGS ?= -g -Wall
143
144# Append required CFLAGS
145override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
c055875b 146override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
f7d82350
SR
147
148ifeq ($(VERBOSE),1)
149 Q =
f7d82350
SR
150else
151 Q = @
f7d82350
SR
152endif
153
f7d82350
SR
154do_compile_shared_library = \
155 ($(print_shared_lib_compile) \
156 $(CC) --shared $^ -o $@)
157
f7d82350
SR
158do_plugin_build = \
159 ($(print_plugin_build) \
160 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
161
162do_build_static_lib = \
163 ($(print_static_lib_build) \
164 $(RM) $@; $(AR) rcs $@ $^)
165
166
c3d090f4 167do_compile = $(QUIET_CC)$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
f7d82350
SR
168
169$(obj)/%.o: $(src)/%.c
c3d090f4 170 $(call do_compile)
f7d82350
SR
171
172%.o: $(src)/%.c
c3d090f4 173 $(call do_compile)
f7d82350 174
c877bbd8
JO
175PEVENT_LIB_OBJS = event-parse.o
176PEVENT_LIB_OBJS += event-plugin.o
177PEVENT_LIB_OBJS += trace-seq.o
178PEVENT_LIB_OBJS += parse-filter.o
179PEVENT_LIB_OBJS += parse-utils.o
d6c25223 180PEVENT_LIB_OBJS += kbuffer-parse.o
f7d82350 181
d9d13f8b
JO
182PLUGIN_OBJS = plugin_jbd2.o
183PLUGIN_OBJS += plugin_hrtimer.o
f8256288 184PLUGIN_OBJS += plugin_kmem.o
35d79f9f 185PLUGIN_OBJS += plugin_kvm.o
de705e2e 186PLUGIN_OBJS += plugin_mac80211.o
83e815ee 187PLUGIN_OBJS += plugin_sched_switch.o
07a180a0 188PLUGIN_OBJS += plugin_function.o
40c03ad5 189PLUGIN_OBJS += plugin_xen.o
04010929 190PLUGIN_OBJS += plugin_scsi.o
94371473 191PLUGIN_OBJS += plugin_cfg80211.o
e0549f11 192
e0e96d03
JO
193PLUGINS := $(PLUGIN_OBJS:.o=.so)
194
195ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
f7d82350 196
e0e96d03 197CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
f7d82350
SR
198
199TARGETS = $(CMD_TARGETS)
200
201
202all: all_cmd
203
204all_cmd: $(CMD_TARGETS)
205
206libtraceevent.so: $(PEVENT_LIB_OBJS)
e6262e23 207 $(QUIET_LINK)$(CC) --shared $^ -o $@
f7d82350
SR
208
209libtraceevent.a: $(PEVENT_LIB_OBJS)
e6262e23 210 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
f7d82350 211
e0e96d03
JO
212plugins: $(PLUGINS)
213
52b5c0d4 214$(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
bdebbacd 215 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@
f7d82350 216
e0e96d03 217$(PLUGIN_OBJS): %.o : $(src)/%.c
bdebbacd 218 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) -fPIC -o $@ $<
e0e96d03
JO
219
220$(PLUGINS): %.so: %.o
e6262e23 221 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<
e0e96d03 222
f7d82350 223define make_version.h
198430b5
JO
224 (echo '/* This file is automatically generated. Do not modify. */'; \
225 echo \#define VERSION_CODE $(shell \
226 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
227 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
228 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
229 echo '#define FILE_VERSION '$(FILE_VERSION); \
230 ) > $1
f7d82350
SR
231endef
232
233define update_version.h
198430b5
JO
234 ($(call make_version.h, $@.tmp); \
235 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
236 rm -f $@.tmp; \
237 else \
238 echo ' UPDATE $@'; \
239 mv -f $@.tmp $@; \
240 fi);
f7d82350
SR
241endef
242
243ep_version.h: force
244 $(Q)$(N)$(call update_version.h)
245
246VERSION_FILES = ep_version.h
247
248define update_dir
198430b5
JO
249 (echo $1 > $@.tmp; \
250 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
251 rm -f $@.tmp; \
252 else \
253 echo ' UPDATE $@'; \
254 mv -f $@.tmp $@; \
255 fi);
f7d82350
SR
256endef
257
258## make deps
259
260all_objs := $(sort $(ALL_OBJS))
261all_deps := $(all_objs:%.o=.%.d)
262
860df583 263# let .d file also depends on the source and header files
f7d82350 264define check_deps
198430b5
JO
265 @set -e; $(RM) $@; \
266 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
267 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
268 $(RM) $@.$$$$
f7d82350
SR
269endef
270
f7d82350
SR
271$(all_deps): .%.d: $(src)/%.c
272 $(Q)$(call check_deps)
273
274$(all_objs) : %.o : .%.d
275
276dep_includes := $(wildcard $(all_deps))
277
278ifneq ($(dep_includes),)
279 include $(dep_includes)
280endif
281
52b5c0d4
NK
282### Detect environment changes
283TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
284
285TRACEEVENT-CFLAGS: force
286 @FLAGS='$(TRACK_CFLAGS)'; \
287 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
65fb0992 288 echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
52b5c0d4
NK
289 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
290 fi
291
f7d82350
SR
292tags: force
293 $(RM) tags
6545e3a8
NK
294 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
295 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
f7d82350
SR
296
297TAGS: force
298 $(RM) TAGS
6545e3a8
NK
299 find . -name '*.[ch]' | xargs etags \
300 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
f7d82350
SR
301
302define do_install
f7d82350
SR
303 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
304 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
305 fi; \
306 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
307endef
308
02a82c7b
JO
309define do_install_plugins
310 for plugin in $1; do \
311 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
312 done
313endef
e0e96d03 314
02a82c7b
JO
315install_lib: all_cmd install_plugins
316 $(call QUIET_INSTALL, $(LIB_FILE)) \
317 $(call do_install,$(LIB_FILE),$(bindir_SQ))
e0e96d03 318
02a82c7b
JO
319install_plugins: $(PLUGINS)
320 $(call QUIET_INSTALL, trace_plugins) \
321 $(call do_install_plugins, $(PLUGINS))
e0e96d03 322
f7d82350
SR
323install: install_lib
324
325clean:
4a953c71
JO
326 $(call QUIET_CLEAN, libtraceevent) \
327 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
328 $(RM) TRACEEVENT-CFLAGS tags TAGS
f7d82350
SR
329
330endif # skip-makefile
331
9bb8e5ed 332PHONY += force plugins
f7d82350
SR
333force:
334
9bb8e5ed
JO
335plugins:
336 @echo > /dev/null
337
f7d82350
SR
338# Declare the contents of the .PHONY variable as phony. We keep that
339# information in a variable so we can use it in if_changed and friends.
340.PHONY: $(PHONY)