blob: d0e0ca12aa10bf23df638627ace5917931113358 [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
Steven Rostedtf7d82352012-04-06 00:47:53 +020070# copy a bit from Linux kbuild
71
72ifeq ("$(origin V)", "command line")
73 VERBOSE = $(V)
74endif
75ifndef VERBOSE
76 VERBOSE = 0
77endif
78
79ifeq ("$(origin O)", "command line")
80 BUILD_OUTPUT := $(O)
81endif
82
83ifeq ($(BUILD_SRC),)
84ifneq ($(BUILD_OUTPUT),)
85
86define build_output
Arnaldo Carvalho de Melo456da532013-08-26 13:04:04 -030087 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(BUILD_OUTPUT) \
Steven Rostedtf7d82352012-04-06 00:47:53 +020088 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
89endef
90
91saved-output := $(BUILD_OUTPUT)
92BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
93$(if $(BUILD_OUTPUT),, \
94 $(error output directory "$(saved-output)" does not exist))
95
96all: sub-make
97
Namhyung Kim4ccdf572013-06-04 14:20:17 +090098$(MAKECMDGOALS): sub-make
Steven Rostedtf7d82352012-04-06 00:47:53 +020099
100sub-make: force
101 $(call build_output, $(MAKECMDGOALS))
102
103
104# Leave processing to above invocation of make
105skip-makefile := 1
106
107endif # BUILD_OUTPUT
108endif # BUILD_SRC
109
110# We process the rest of the Makefile if this is the final invocation of make
111ifeq ($(skip-makefile),)
112
113srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
114objtree := $(CURDIR)
115src := $(srctree)
116obj := $(objtree)
117
118export prefix bindir src obj
119
120# Shell quotes
121bindir_SQ = $(subst ','\'',$(bindir))
122bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100123plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
Steven Rostedtf7d82352012-04-06 00:47:53 +0200124
125LIB_FILE = libtraceevent.a libtraceevent.so
126
127CONFIG_INCLUDES =
128CONFIG_LIBS =
129CONFIG_FLAGS =
130
131VERSION = $(EP_VERSION)
132PATCHLEVEL = $(EP_PATCHLEVEL)
133EXTRAVERSION = $(EP_EXTRAVERSION)
134
135OBJ = $@
136N =
137
138export Q VERBOSE
139
140EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
141
Jack Mitchellb9e8c372013-03-08 11:21:52 +0000142INCLUDES = -I. $(CONFIG_INCLUDES)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200143
144# Set compile option CFLAGS if not set elsewhere
145CFLAGS ?= -g -Wall
146
147# Append required CFLAGS
148override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
Arnaldo Carvalho de Meloc0558752012-09-12 14:29:40 -0300149override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
Steven Rostedtf7d82352012-04-06 00:47:53 +0200150
151ifeq ($(VERBOSE),1)
152 Q =
153 print_compile =
154 print_app_build =
155 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_compile = echo ' CC '$(OBJ);
163 print_app_build = echo ' BUILD '$(OBJ);
164 print_fpic_compile = echo ' CC FPIC '$(OBJ);
165 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
Jiri Olsae0e96d02013-12-03 14:09:17 +0100166 print_plugin_obj_compile = echo ' CC FPIC '$(OBJ);
167 print_plugin_build = echo ' BUILD PLUGIN '$(OBJ);
Ingo Molnar65fb0992013-10-09 11:49:27 +0200168 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
Jiri Olsaf33c5cd2013-12-03 14:09:20 +0100169 print_install = echo ' INSTALL '$1;
Steven Rostedtf7d82352012-04-06 00:47:53 +0200170endif
171
172do_fpic_compile = \
173 ($(print_fpic_compile) \
174 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
175
176do_app_build = \
177 ($(print_app_build) \
178 $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
179
180do_compile_shared_library = \
181 ($(print_shared_lib_compile) \
182 $(CC) --shared $^ -o $@)
183
184do_compile_plugin_obj = \
185 ($(print_plugin_obj_compile) \
186 $(CC) -c $(CFLAGS) -fPIC -o $@ $<)
187
188do_plugin_build = \
189 ($(print_plugin_build) \
190 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
191
192do_build_static_lib = \
193 ($(print_static_lib_build) \
194 $(RM) $@; $(AR) rcs $@ $^)
195
196
197define do_compile
198 $(print_compile) \
199 $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
200endef
201
202$(obj)/%.o: $(src)/%.c
203 $(Q)$(call do_compile)
204
205%.o: $(src)/%.c
206 $(Q)$(call do_compile)
207
Jiri Olsac877bbd2013-12-03 14:09:16 +0100208PEVENT_LIB_OBJS = event-parse.o
209PEVENT_LIB_OBJS += event-plugin.o
210PEVENT_LIB_OBJS += trace-seq.o
211PEVENT_LIB_OBJS += parse-filter.o
212PEVENT_LIB_OBJS += parse-utils.o
Namhyung Kimd6c25222013-06-04 14:20:21 +0900213PEVENT_LIB_OBJS += kbuffer-parse.o
Steven Rostedtf7d82352012-04-06 00:47:53 +0200214
Jiri Olsad9d13f82013-12-03 14:09:27 +0100215PLUGIN_OBJS = plugin_jbd2.o
216PLUGIN_OBJS += plugin_hrtimer.o
Jiri Olsaf8256282013-12-03 14:09:28 +0100217PLUGIN_OBJS += plugin_kmem.o
Jiri Olsa35d79f9f2013-12-03 14:09:29 +0100218PLUGIN_OBJS += plugin_kvm.o
Jiri Olsade705e22013-12-03 14:09:30 +0100219PLUGIN_OBJS += plugin_mac80211.o
Jiri Olsae0549f12013-12-03 14:09:26 +0100220
Jiri Olsae0e96d02013-12-03 14:09:17 +0100221PLUGINS := $(PLUGIN_OBJS:.o=.so)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200222
Jiri Olsae0e96d02013-12-03 14:09:17 +0100223ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
224
225CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200226
227TARGETS = $(CMD_TARGETS)
228
229
230all: all_cmd
231
232all_cmd: $(CMD_TARGETS)
233
234libtraceevent.so: $(PEVENT_LIB_OBJS)
235 $(Q)$(do_compile_shared_library)
236
237libtraceevent.a: $(PEVENT_LIB_OBJS)
238 $(Q)$(do_build_static_lib)
239
Jiri Olsae0e96d02013-12-03 14:09:17 +0100240plugins: $(PLUGINS)
241
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900242$(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200243 $(Q)$(do_fpic_compile)
244
Jiri Olsae0e96d02013-12-03 14:09:17 +0100245$(PLUGIN_OBJS): %.o : $(src)/%.c
246 $(Q)$(do_compile_plugin_obj)
247
248$(PLUGINS): %.so: %.o
249 $(Q)$(do_plugin_build)
250
Steven Rostedtf7d82352012-04-06 00:47:53 +0200251define make_version.h
252 (echo '/* This file is automatically generated. Do not modify. */'; \
253 echo \#define VERSION_CODE $(shell \
254 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
255 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
256 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
257 echo '#define FILE_VERSION '$(FILE_VERSION); \
258 ) > $1
259endef
260
261define update_version.h
262 ($(call make_version.h, $@.tmp); \
263 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
264 rm -f $@.tmp; \
265 else \
266 echo ' UPDATE $@'; \
267 mv -f $@.tmp $@; \
268 fi);
269endef
270
271ep_version.h: force
272 $(Q)$(N)$(call update_version.h)
273
274VERSION_FILES = ep_version.h
275
276define update_dir
277 (echo $1 > $@.tmp; \
278 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
279 rm -f $@.tmp; \
280 else \
281 echo ' UPDATE $@'; \
282 mv -f $@.tmp $@; \
283 fi);
284endef
285
286## make deps
287
288all_objs := $(sort $(ALL_OBJS))
289all_deps := $(all_objs:%.o=.%.d)
290
Namhyung Kim860df582012-06-22 14:37:36 +0900291# let .d file also depends on the source and header files
Steven Rostedtf7d82352012-04-06 00:47:53 +0200292define check_deps
Namhyung Kim860df582012-06-22 14:37:36 +0900293 @set -e; $(RM) $@; \
Namhyung Kimb6f4f802012-10-26 17:55:48 +0900294 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
Namhyung Kim860df582012-06-22 14:37:36 +0900295 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
296 $(RM) $@.$$$$
Steven Rostedtf7d82352012-04-06 00:47:53 +0200297endef
298
Steven Rostedtf7d82352012-04-06 00:47:53 +0200299$(all_deps): .%.d: $(src)/%.c
300 $(Q)$(call check_deps)
301
302$(all_objs) : %.o : .%.d
303
304dep_includes := $(wildcard $(all_deps))
305
306ifneq ($(dep_includes),)
307 include $(dep_includes)
308endif
309
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900310### Detect environment changes
311TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
312
313TRACEEVENT-CFLAGS: force
314 @FLAGS='$(TRACK_CFLAGS)'; \
315 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
Ingo Molnar65fb0992013-10-09 11:49:27 +0200316 echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900317 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
318 fi
319
Steven Rostedtf7d82352012-04-06 00:47:53 +0200320tags: force
321 $(RM) tags
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900322 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
323 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200324
325TAGS: force
326 $(RM) TAGS
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900327 find . -name '*.[ch]' | xargs etags \
328 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200329
330define do_install
331 $(print_install) \
332 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
333 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
334 fi; \
335 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
336endef
337
Jiri Olsae0e96d02013-12-03 14:09:17 +0100338install_lib: all_cmd install_plugins
Steven Rostedtf7d82352012-04-06 00:47:53 +0200339 $(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
340
Jiri Olsae0e96d02013-12-03 14:09:17 +0100341PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS))
342
343$(PLUGINS_INSTALL): %.install : %.so force
344 $(Q)$(call do_install,$<,$(plugin_dir_SQ))
345
346install_plugins: $(PLUGINS_INSTALL)
347
Steven Rostedtf7d82352012-04-06 00:47:53 +0200348install: install_lib
349
350clean:
Konstantin Stepanyukf526a4c2012-06-27 15:52:14 -0600351 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
Namhyung Kim52b5c0d2012-07-06 16:21:32 +0900352 $(RM) TRACEEVENT-CFLAGS tags TAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200353
354endif # skip-makefile
355
356PHONY += force
357force:
358
359# Declare the contents of the .PHONY variable as phony. We keep that
360# information in a variable so we can use it in if_changed and friends.
361.PHONY: $(PHONY)