blob: e852a8d54d841496f39e1b71c8bd6864072802ba [file] [log] [blame]
Steven Rostedtf7d82352012-04-06 00:47:53 +02001# 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))'
Steven Rostedtf7d82352012-04-06 00:47:53 +020042
Namhyung Kim9f1efa82013-06-04 14:20:16 +090043export man_dir man_dir_SQ INSTALL
Steven Rostedtf7d82352012-04-06 00:47:53 +020044export DESTDIR DESTDIR_SQ
45
Jiri Olsae0e96d02013-12-03 14:09:17 +010046set_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="$(DESTDIR)/$(plugin_dir)"
67PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68endif
69
Jiri Olsac3d090f2013-12-19 14:42:02 +010070include $(if $(BUILD_SRC),$(BUILD_SRC)/)../../scripts/Makefile.include
71
Steven Rostedtf7d82352012-04-06 00:47:53 +020072# 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 ($(BUILD_OUTPUT),)
87
88define build_output
Arnaldo Carvalho de Melo456da532013-08-26 13:04:04 -030089 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(BUILD_OUTPUT) \
Steven Rostedtf7d82352012-04-06 00:47:53 +020090 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
91endef
92
93saved-output := $(BUILD_OUTPUT)
94BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
95$(if $(BUILD_OUTPUT),, \
96 $(error output directory "$(saved-output)" does not exist))
97
98all: sub-make
99
Namhyung Kim4ccdf572013-06-04 14:20:17 +0900100$(MAKECMDGOALS): sub-make
Steven Rostedtf7d82352012-04-06 00:47:53 +0200101
102sub-make: force
103 $(call build_output, $(MAKECMDGOALS))
104
105
106# Leave processing to above invocation of make
107skip-makefile := 1
108
109endif # BUILD_OUTPUT
110endif # BUILD_SRC
111
112# We process the rest of the Makefile if this is the final invocation of make
113ifeq ($(skip-makefile),)
114
115srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
116objtree := $(CURDIR)
117src := $(srctree)
118obj := $(objtree)
119
120export prefix bindir src obj
121
122# Shell quotes
123bindir_SQ = $(subst ','\'',$(bindir))
124bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100125plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
Steven Rostedtf7d82352012-04-06 00:47:53 +0200126
127LIB_FILE = libtraceevent.a libtraceevent.so
128
129CONFIG_INCLUDES =
130CONFIG_LIBS =
131CONFIG_FLAGS =
132
133VERSION = $(EP_VERSION)
134PATCHLEVEL = $(EP_PATCHLEVEL)
135EXTRAVERSION = $(EP_EXTRAVERSION)
136
137OBJ = $@
138N =
139
140export Q VERBOSE
141
142EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
143
Jack Mitchellb9e8c372013-03-08 11:21:52 +0000144INCLUDES = -I. $(CONFIG_INCLUDES)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200145
146# Set compile option CFLAGS if not set elsewhere
147CFLAGS ?= -g -Wall
148
149# Append required CFLAGS
150override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
Arnaldo Carvalho de Meloc055875b72012-09-12 14:29:40 -0300151override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
Steven Rostedtf7d82352012-04-06 00:47:53 +0200152
153ifeq ($(VERBOSE),1)
154 Q =
Steven Rostedtf7d82352012-04-06 00:47:53 +0200155 print_fpic_compile =
156 print_shared_lib_compile =
157 print_plugin_obj_compile =
158 print_plugin_build =
159 print_install =
160else
161 Q = @
Ingo Molnar65fb0992013-10-09 11:49:27 +0200162 print_fpic_compile = echo ' CC FPIC '$(OBJ);
163 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
Jiri Olsae0e96d02013-12-03 14:09:17 +0100164 print_plugin_obj_compile = echo ' CC FPIC '$(OBJ);
165 print_plugin_build = echo ' BUILD PLUGIN '$(OBJ);
Ingo Molnar65fb0992013-10-09 11:49:27 +0200166 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
Jiri Olsaf33c5cd2013-12-03 14:09:20 +0100167 print_install = echo ' INSTALL '$1;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200168endif
169
170do_fpic_compile = \
171 ($(print_fpic_compile) \
172 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
173
Steven Rostedtf7d82352012-04-06 00:47:53 +0200174do_compile_shared_library = \
175 ($(print_shared_lib_compile) \
176 $(CC) --shared $^ -o $@)
177
178do_compile_plugin_obj = \
179 ($(print_plugin_obj_compile) \
180 $(CC) -c $(CFLAGS) -fPIC -o $@ $<)
181
182do_plugin_build = \
183 ($(print_plugin_build) \
184 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
185
186do_build_static_lib = \
187 ($(print_static_lib_build) \
188 $(RM) $@; $(AR) rcs $@ $^)
189
190
Jiri Olsac3d090f2013-12-19 14:42:02 +0100191do_compile = $(QUIET_CC)$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200192
193$(obj)/%.o: $(src)/%.c
Jiri Olsac3d090f2013-12-19 14:42:02 +0100194 $(call do_compile)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200195
196%.o: $(src)/%.c
Jiri Olsac3d090f2013-12-19 14:42:02 +0100197 $(call do_compile)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200198
Jiri Olsac877bbd2013-12-03 14:09:16 +0100199PEVENT_LIB_OBJS = event-parse.o
200PEVENT_LIB_OBJS += event-plugin.o
201PEVENT_LIB_OBJS += trace-seq.o
202PEVENT_LIB_OBJS += parse-filter.o
203PEVENT_LIB_OBJS += parse-utils.o
Namhyung Kimd6c25222013-06-04 14:20:21 +0900204PEVENT_LIB_OBJS += kbuffer-parse.o
Steven Rostedtf7d82352012-04-06 00:47:53 +0200205
Jiri Olsad9d13f82013-12-03 14:09:27 +0100206PLUGIN_OBJS = plugin_jbd2.o
207PLUGIN_OBJS += plugin_hrtimer.o
Jiri Olsaf8256282013-12-03 14:09:28 +0100208PLUGIN_OBJS += plugin_kmem.o
Jiri Olsa35d79f9f2013-12-03 14:09:29 +0100209PLUGIN_OBJS += plugin_kvm.o
Jiri Olsade705e22013-12-03 14:09:30 +0100210PLUGIN_OBJS += plugin_mac80211.o
Jiri Olsa83e815e2013-12-03 14:09:31 +0100211PLUGIN_OBJS += plugin_sched_switch.o
Jiri Olsa07a180a2013-12-03 14:09:32 +0100212PLUGIN_OBJS += plugin_function.o
Jiri Olsa40c03ad2013-12-03 14:09:33 +0100213PLUGIN_OBJS += plugin_xen.o
Jiri Olsa04010922013-12-03 14:09:34 +0100214PLUGIN_OBJS += plugin_scsi.o
Jiri Olsa94371472013-12-03 14:09:35 +0100215PLUGIN_OBJS += plugin_cfg80211.o
Jiri Olsae0549f12013-12-03 14:09:26 +0100216
Jiri Olsae0e96d02013-12-03 14:09:17 +0100217PLUGINS := $(PLUGIN_OBJS:.o=.so)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200218
Jiri Olsae0e96d02013-12-03 14:09:17 +0100219ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
220
221CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200222
223TARGETS = $(CMD_TARGETS)
224
225
226all: all_cmd
227
228all_cmd: $(CMD_TARGETS)
229
230libtraceevent.so: $(PEVENT_LIB_OBJS)
231 $(Q)$(do_compile_shared_library)
232
233libtraceevent.a: $(PEVENT_LIB_OBJS)
234 $(Q)$(do_build_static_lib)
235
Jiri Olsae0e96d02013-12-03 14:09:17 +0100236plugins: $(PLUGINS)
237
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900238$(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200239 $(Q)$(do_fpic_compile)
240
Jiri Olsae0e96d02013-12-03 14:09:17 +0100241$(PLUGIN_OBJS): %.o : $(src)/%.c
242 $(Q)$(do_compile_plugin_obj)
243
244$(PLUGINS): %.so: %.o
245 $(Q)$(do_plugin_build)
246
Steven Rostedtf7d82352012-04-06 00:47:53 +0200247define make_version.h
248 (echo '/* This file is automatically generated. Do not modify. */'; \
249 echo \#define VERSION_CODE $(shell \
250 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
251 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
252 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
253 echo '#define FILE_VERSION '$(FILE_VERSION); \
254 ) > $1
255endef
256
257define update_version.h
258 ($(call make_version.h, $@.tmp); \
259 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
260 rm -f $@.tmp; \
261 else \
262 echo ' UPDATE $@'; \
263 mv -f $@.tmp $@; \
264 fi);
265endef
266
267ep_version.h: force
268 $(Q)$(N)$(call update_version.h)
269
270VERSION_FILES = ep_version.h
271
272define update_dir
273 (echo $1 > $@.tmp; \
274 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
275 rm -f $@.tmp; \
276 else \
277 echo ' UPDATE $@'; \
278 mv -f $@.tmp $@; \
279 fi);
280endef
281
282## make deps
283
284all_objs := $(sort $(ALL_OBJS))
285all_deps := $(all_objs:%.o=.%.d)
286
Namhyung Kim860df582012-06-22 14:37:36 +0900287# let .d file also depends on the source and header files
Steven Rostedtf7d82352012-04-06 00:47:53 +0200288define check_deps
Namhyung Kim860df582012-06-22 14:37:36 +0900289 @set -e; $(RM) $@; \
Namhyung Kimb6f4f802012-10-26 17:55:48 +0900290 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
Namhyung Kim860df582012-06-22 14:37:36 +0900291 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
292 $(RM) $@.$$$$
Steven Rostedtf7d82352012-04-06 00:47:53 +0200293endef
294
Steven Rostedtf7d82352012-04-06 00:47:53 +0200295$(all_deps): .%.d: $(src)/%.c
296 $(Q)$(call check_deps)
297
298$(all_objs) : %.o : .%.d
299
300dep_includes := $(wildcard $(all_deps))
301
302ifneq ($(dep_includes),)
303 include $(dep_includes)
304endif
305
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900306### Detect environment changes
307TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
308
309TRACEEVENT-CFLAGS: force
310 @FLAGS='$(TRACK_CFLAGS)'; \
311 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
Ingo Molnar65fb0992013-10-09 11:49:27 +0200312 echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900313 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
314 fi
315
Steven Rostedtf7d82352012-04-06 00:47:53 +0200316tags: force
317 $(RM) tags
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900318 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
319 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200320
321TAGS: force
322 $(RM) TAGS
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900323 find . -name '*.[ch]' | xargs etags \
324 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200325
326define do_install
327 $(print_install) \
328 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
329 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
330 fi; \
331 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
332endef
333
Jiri Olsae0e96d02013-12-03 14:09:17 +0100334install_lib: all_cmd install_plugins
Steven Rostedtf7d82352012-04-06 00:47:53 +0200335 $(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
336
Jiri Olsae0e96d02013-12-03 14:09:17 +0100337PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS))
338
339$(PLUGINS_INSTALL): %.install : %.so force
340 $(Q)$(call do_install,$<,$(plugin_dir_SQ))
341
342install_plugins: $(PLUGINS_INSTALL)
343
Steven Rostedtf7d82352012-04-06 00:47:53 +0200344install: install_lib
345
346clean:
Konstantin Stepanyukf526a4c2012-06-27 15:52:14 -0600347 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900348 $(RM) TRACEEVENT-CFLAGS tags TAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200349
350endif # skip-makefile
351
352PHONY += force
353force:
354
355# Declare the contents of the .PHONY variable as phony. We keep that
356# information in a variable so we can use it in if_changed and friends.
357.PHONY: $(PHONY)