Loading...
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))'
42
43export man_dir man_dir_SQ INSTALL
44export DESTDIR DESTDIR_SQ
45
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)
66PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
67PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68endif
69
70include $(if $(BUILD_SRC),$(BUILD_SRC)/)../../scripts/Makefile.include
71
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),)
86ifneq ($(OUTPUT),)
87
88define build_output
89 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(OUTPUT) \
90 BUILD_SRC=$(CURDIR)/ -f $(CURDIR)/Makefile $1
91endef
92
93all: sub-make
94
95$(MAKECMDGOALS): sub-make
96
97sub-make: force
98 $(call build_output, $(MAKECMDGOALS))
99
100
101# Leave processing to above invocation of make
102skip-makefile := 1
103
104endif # OUTPUT
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))
120plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
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
139INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
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)
146override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
147
148ifeq ($(VERBOSE),1)
149 Q =
150else
151 Q = @
152endif
153
154do_compile_shared_library = \
155 ($(print_shared_lib_compile) \
156 $(CC) --shared $^ -o $@)
157
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
167do_compile = $(QUIET_CC)$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
168
169$(obj)/%.o: $(src)/%.c
170 $(call do_compile)
171
172%.o: $(src)/%.c
173 $(call do_compile)
174
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
180PEVENT_LIB_OBJS += kbuffer-parse.o
181
182PLUGIN_OBJS = plugin_jbd2.o
183PLUGIN_OBJS += plugin_hrtimer.o
184PLUGIN_OBJS += plugin_kmem.o
185PLUGIN_OBJS += plugin_kvm.o
186PLUGIN_OBJS += plugin_mac80211.o
187PLUGIN_OBJS += plugin_sched_switch.o
188PLUGIN_OBJS += plugin_function.o
189PLUGIN_OBJS += plugin_xen.o
190PLUGIN_OBJS += plugin_scsi.o
191PLUGIN_OBJS += plugin_cfg80211.o
192
193PLUGINS := $(PLUGIN_OBJS:.o=.so)
194
195ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
196
197CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
198
199TARGETS = $(CMD_TARGETS)
200
201
202all: all_cmd
203
204all_cmd: $(CMD_TARGETS)
205
206libtraceevent.so: $(PEVENT_LIB_OBJS)
207 $(QUIET_LINK)$(CC) --shared $^ -o $@
208
209libtraceevent.a: $(PEVENT_LIB_OBJS)
210 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
211
212plugins: $(PLUGINS)
213
214$(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
215 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@
216
217$(PLUGIN_OBJS): %.o : $(src)/%.c
218 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) -fPIC -o $@ $<
219
220$(PLUGINS): %.so: %.o
221 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<
222
223define make_version.h
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
231endef
232
233define update_version.h
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);
241endef
242
243ep_version.h: force
244 $(Q)$(N)$(call update_version.h)
245
246VERSION_FILES = ep_version.h
247
248define update_dir
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);
256endef
257
258## make deps
259
260all_objs := $(sort $(ALL_OBJS))
261all_deps := $(all_objs:%.o=.%.d)
262
263# let .d file also depends on the source and header files
264define check_deps
265 @set -e; $(RM) $@; \
266 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
267 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
268 $(RM) $@.$$$$
269endef
270
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
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 \
288 echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
289 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
290 fi
291
292tags: force
293 $(RM) tags
294 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
295 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
296
297TAGS: force
298 $(RM) TAGS
299 find . -name '*.[ch]' | xargs etags \
300 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
301
302define do_install
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
309define do_install_plugins
310 for plugin in $1; do \
311 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
312 done
313endef
314
315install_lib: all_cmd install_plugins
316 $(call QUIET_INSTALL, $(LIB_FILE)) \
317 $(call do_install,$(LIB_FILE),$(bindir_SQ))
318
319install_plugins: $(PLUGINS)
320 $(call QUIET_INSTALL, trace_plugins) \
321 $(call do_install_plugins, $(PLUGINS))
322
323install: install_lib
324
325clean:
326 $(call QUIET_CLEAN, libtraceevent) \
327 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
328 $(RM) TRACEEVENT-CFLAGS tags TAGS
329
330endif # skip-makefile
331
332PHONY += force plugins
333force:
334
335plugins:
336 @echo > /dev/null
337
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)
1# SPDX-License-Identifier: GPL-2.0
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)
27$(call allow-override,NM,$(CROSS_COMPILE)nm)
28$(call allow-override,PKG_CONFIG,pkg-config)
29
30EXT = -std=gnu99
31INSTALL = install
32
33# Use DESTDIR for installing into a different root directory.
34# This is useful for building a package. The program will be
35# installed in this directory as if it was the root directory.
36# Then the build tool can move it later.
37DESTDIR ?=
38DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
39
40LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
41ifeq ($(LP64), 1)
42 libdir_relative_temp = lib64
43else
44 libdir_relative_temp = lib
45endif
46
47libdir_relative ?= $(libdir_relative_temp)
48prefix ?= /usr/local
49libdir = $(prefix)/$(libdir_relative)
50man_dir = $(prefix)/share/man
51man_dir_SQ = '$(subst ','\'',$(man_dir))'
52pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \
53 --variable pc_path pkg-config | tr ":" " "))
54includedir_relative = traceevent
55includedir = $(prefix)/include/$(includedir_relative)
56includedir_SQ = '$(subst ','\'',$(includedir))'
57
58export man_dir man_dir_SQ INSTALL
59export DESTDIR DESTDIR_SQ
60export EVENT_PARSE_VERSION
61
62include ../../scripts/Makefile.include
63
64# copy a bit from Linux kbuild
65
66ifeq ("$(origin V)", "command line")
67 VERBOSE = $(V)
68endif
69ifndef VERBOSE
70 VERBOSE = 0
71endif
72
73ifeq ($(srctree),)
74srctree := $(patsubst %/,%,$(dir $(CURDIR)))
75srctree := $(patsubst %/,%,$(dir $(srctree)))
76srctree := $(patsubst %/,%,$(dir $(srctree)))
77#$(info Determined 'srctree' to be $(srctree))
78endif
79
80export prefix libdir src obj
81
82# Shell quotes
83libdir_SQ = $(subst ','\'',$(libdir))
84libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
85
86CONFIG_INCLUDES =
87CONFIG_LIBS =
88CONFIG_FLAGS =
89
90VERSION = $(EP_VERSION)
91PATCHLEVEL = $(EP_PATCHLEVEL)
92EXTRAVERSION = $(EP_EXTRAVERSION)
93
94OBJ = $@
95N =
96
97EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
98
99LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
100LIB_INSTALL = libtraceevent.a libtraceevent.so*
101LIB_INSTALL := $(addprefix $(OUTPUT),$(LIB_INSTALL))
102
103INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
104
105# Set compile option CFLAGS
106ifdef EXTRA_CFLAGS
107 CFLAGS := $(EXTRA_CFLAGS)
108else
109 CFLAGS := -g -Wall
110endif
111
112# Append required CFLAGS
113override CFLAGS += -fPIC
114override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
115override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
116
117ifeq ($(VERBOSE),1)
118 Q =
119else
120 Q = @
121endif
122
123# Disable command line variables (CFLAGS) override from top
124# level Makefile (perf), otherwise build Makefile will get
125# the same command line setup.
126MAKEOVERRIDES=
127
128export srctree OUTPUT CC LD CFLAGS V
129build := -f $(srctree)/tools/build/Makefile.build dir=. obj
130
131TE_IN := $(OUTPUT)libtraceevent-in.o
132LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
133
134CMD_TARGETS = $(LIB_TARGET)
135
136TARGETS = $(CMD_TARGETS)
137
138all: all_cmd plugins
139
140all_cmd: $(CMD_TARGETS)
141
142$(TE_IN): force
143 $(Q)$(MAKE) $(build)=libtraceevent
144
145$(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
146 $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
147 @ln -sf $(@F) $(OUTPUT)libtraceevent.so
148 @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
149
150$(OUTPUT)libtraceevent.a: $(TE_IN)
151 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
152
153$(OUTPUT)%.so: $(OUTPUT)%-in.o
154 $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
155
156define make_version.h
157 (echo '/* This file is automatically generated. Do not modify. */'; \
158 echo \#define VERSION_CODE $(shell \
159 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
160 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
161 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
162 echo '#define FILE_VERSION '$(FILE_VERSION); \
163 ) > $1
164endef
165
166define update_version.h
167 ($(call make_version.h, $@.tmp); \
168 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
169 rm -f $@.tmp; \
170 else \
171 echo ' UPDATE $@'; \
172 mv -f $@.tmp $@; \
173 fi);
174endef
175
176ep_version.h: force
177 $(Q)$(N)$(call update_version.h)
178
179VERSION_FILES = ep_version.h
180
181define update_dir
182 (echo $1 > $@.tmp; \
183 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
184 rm -f $@.tmp; \
185 else \
186 echo ' UPDATE $@'; \
187 mv -f $@.tmp $@; \
188 fi);
189endef
190
191tags: force
192 $(RM) tags
193 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
194 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
195
196TAGS: force
197 $(RM) TAGS
198 find . -name '*.[ch]' | xargs etags \
199 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
200
201define do_install_mkdir
202 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
203 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
204 fi
205endef
206
207define do_install
208 $(call do_install_mkdir,$2); \
209 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
210endef
211
212PKG_CONFIG_SOURCE_FILE = libtraceevent.pc
213PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE))
214define do_install_pkgconfig_file
215 if [ -n "${pkgconfig_dir}" ]; then \
216 cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE}; \
217 sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \
218 sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \
219 sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \
220 sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \
221 $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \
222 else \
223 (echo Failed to locate pkg-config directory) 1>&2; \
224 fi
225endef
226
227install_lib: all_cmd install_plugins install_headers install_pkgconfig
228 $(call QUIET_INSTALL, $(LIB_TARGET)) \
229 $(call do_install_mkdir,$(libdir_SQ)); \
230 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
231
232install_pkgconfig:
233 $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \
234 $(call do_install_pkgconfig_file,$(prefix))
235
236install_headers:
237 $(call QUIET_INSTALL, headers) \
238 $(call do_install,event-parse.h,$(includedir_SQ),644); \
239 $(call do_install,event-utils.h,$(includedir_SQ),644); \
240 $(call do_install,trace-seq.h,$(includedir_SQ),644); \
241 $(call do_install,kbuffer.h,$(includedir_SQ),644)
242
243install: install_lib
244
245clean: clean_plugins
246 $(call QUIET_CLEAN, libtraceevent) \
247 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
248 $(RM) TRACEEVENT-CFLAGS tags TAGS; \
249 $(RM) $(PKG_CONFIG_FILE)
250
251PHONY += doc
252doc:
253 $(call descend,Documentation)
254
255PHONY += doc-clean
256doc-clean:
257 $(call descend,Documentation,clean)
258
259PHONY += doc-install
260doc-install:
261 $(call descend,Documentation,install)
262
263PHONY += doc-uninstall
264doc-uninstall:
265 $(call descend,Documentation,uninstall)
266
267PHONY += help
268help:
269 @echo 'Possible targets:'
270 @echo''
271 @echo ' all - default, compile the library and the'\
272 'plugins'
273 @echo ' plugins - compile the plugins'
274 @echo ' install - install the library, the plugins,'\
275 'the header and pkgconfig files'
276 @echo ' clean - clean the library and the plugins object files'
277 @echo ' doc - compile the documentation files - man'\
278 'and html pages, in the Documentation directory'
279 @echo ' doc-clean - clean the documentation files'
280 @echo ' doc-install - install the man pages'
281 @echo ' doc-uninstall - uninstall the man pages'
282 @echo''
283
284PHONY += plugins
285plugins:
286 $(call descend,plugins)
287
288PHONY += install_plugins
289install_plugins:
290 $(call descend,plugins,install)
291
292PHONY += clean_plugins
293clean_plugins:
294 $(call descend,plugins,clean)
295
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)