tools lib traceevent: Add xen plugin
[platform/adaptation/renesas_rcar/renesas_kernel.git] / tools / lib / traceevent / Makefile
1 # trace-cmd version
2 EP_VERSION = 1
3 EP_PATCHLEVEL = 1
4 EP_EXTRAVERSION = 0
5
6 # file format version
7 FILE_VERSION = 6
8
9 MAKEFLAGS += --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.
17 define allow-override
18   $(if $(or $(findstring environment,$(origin $(1))),\
19             $(findstring command line,$(origin $(1)))),,\
20     $(eval $(1) = $(2)))
21 endef
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
27 EXT = -std=gnu99
28 INSTALL = 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.
34 DESTDIR ?=
35 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
36
37 prefix ?= /usr/local
38 bindir_relative = bin
39 bindir = $(prefix)/$(bindir_relative)
40 man_dir = $(prefix)/share/man
41 man_dir_SQ = '$(subst ','\'',$(man_dir))'
42
43 export man_dir man_dir_SQ INSTALL
44 export DESTDIR DESTDIR_SQ
45
46 set_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 #
56 ifeq ($(plugin_dir),)
57 ifeq ($(prefix),$(HOME))
58 override plugin_dir = $(HOME)/.traceevent/plugins
59 set_plugin_dir := 0
60 else
61 override plugin_dir = $(prefix)/lib/traceevent/plugins
62 endif
63 endif
64
65 ifeq ($(set_plugin_dir),1)
66 PLUGIN_DIR = -DPLUGIN_DIR="$(DESTDIR)/$(plugin_dir)"
67 PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68 endif
69
70 # copy a bit from Linux kbuild
71
72 ifeq ("$(origin V)", "command line")
73   VERBOSE = $(V)
74 endif
75 ifndef VERBOSE
76   VERBOSE = 0
77 endif
78
79 ifeq ("$(origin O)", "command line")
80   BUILD_OUTPUT := $(O)
81 endif
82
83 ifeq ($(BUILD_SRC),)
84 ifneq ($(BUILD_OUTPUT),)
85
86 define build_output
87         $(if $(VERBOSE:1=),@)+$(MAKE) -C $(BUILD_OUTPUT)        \
88         BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
89 endef
90
91 saved-output := $(BUILD_OUTPUT)
92 BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
93 $(if $(BUILD_OUTPUT),, \
94      $(error output directory "$(saved-output)" does not exist))
95
96 all: sub-make
97
98 $(MAKECMDGOALS): sub-make
99
100 sub-make: force
101         $(call build_output, $(MAKECMDGOALS))
102
103
104 # Leave processing to above invocation of make
105 skip-makefile := 1
106
107 endif # BUILD_OUTPUT
108 endif # BUILD_SRC
109
110 # We process the rest of the Makefile if this is the final invocation of make
111 ifeq ($(skip-makefile),)
112
113 srctree         := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
114 objtree         := $(CURDIR)
115 src             := $(srctree)
116 obj             := $(objtree)
117
118 export prefix bindir src obj
119
120 # Shell quotes
121 bindir_SQ = $(subst ','\'',$(bindir))
122 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
123 plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
124
125 LIB_FILE = libtraceevent.a libtraceevent.so
126
127 CONFIG_INCLUDES = 
128 CONFIG_LIBS     =
129 CONFIG_FLAGS    =
130
131 VERSION         = $(EP_VERSION)
132 PATCHLEVEL      = $(EP_PATCHLEVEL)
133 EXTRAVERSION    = $(EP_EXTRAVERSION)
134
135 OBJ             = $@
136 N               =
137
138 export Q VERBOSE
139
140 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
141
142 INCLUDES = -I. $(CONFIG_INCLUDES)
143
144 # Set compile option CFLAGS if not set elsewhere
145 CFLAGS ?= -g -Wall
146
147 # Append required CFLAGS
148 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
149 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
150
151 ifeq ($(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 =
160 else
161   Q = @
162   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);
166   print_plugin_obj_compile =    echo '  CC FPIC  '$(OBJ);
167   print_plugin_build =          echo '  BUILD    PLUGIN '$(OBJ);
168   print_static_lib_build =      echo '  BUILD    STATIC LIB '$(OBJ);
169   print_install =               echo '  INSTALL  '$1;
170 endif
171
172 do_fpic_compile =                                       \
173         ($(print_fpic_compile)                          \
174         $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
175
176 do_app_build =                                          \
177         ($(print_app_build)                             \
178         $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
179
180 do_compile_shared_library =                     \
181         ($(print_shared_lib_compile)            \
182         $(CC) --shared $^ -o $@)
183
184 do_compile_plugin_obj =                         \
185         ($(print_plugin_obj_compile)            \
186         $(CC) -c $(CFLAGS) -fPIC -o $@ $<)
187
188 do_plugin_build =                               \
189         ($(print_plugin_build)                  \
190         $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
191
192 do_build_static_lib =                           \
193         ($(print_static_lib_build)              \
194         $(RM) $@;  $(AR) rcs $@ $^)
195
196
197 define do_compile
198         $(print_compile)                                                \
199         $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
200 endef
201
202 $(obj)/%.o: $(src)/%.c
203         $(Q)$(call do_compile)
204
205 %.o: $(src)/%.c
206         $(Q)$(call do_compile)
207
208 PEVENT_LIB_OBJS  = event-parse.o
209 PEVENT_LIB_OBJS += event-plugin.o
210 PEVENT_LIB_OBJS += trace-seq.o
211 PEVENT_LIB_OBJS += parse-filter.o
212 PEVENT_LIB_OBJS += parse-utils.o
213 PEVENT_LIB_OBJS += kbuffer-parse.o
214
215 PLUGIN_OBJS  = plugin_jbd2.o
216 PLUGIN_OBJS += plugin_hrtimer.o
217 PLUGIN_OBJS += plugin_kmem.o
218 PLUGIN_OBJS += plugin_kvm.o
219 PLUGIN_OBJS += plugin_mac80211.o
220 PLUGIN_OBJS += plugin_sched_switch.o
221 PLUGIN_OBJS += plugin_function.o
222 PLUGIN_OBJS += plugin_xen.o
223
224 PLUGINS := $(PLUGIN_OBJS:.o=.so)
225
226 ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
227
228 CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
229
230 TARGETS = $(CMD_TARGETS)
231
232
233 all: all_cmd
234
235 all_cmd: $(CMD_TARGETS)
236
237 libtraceevent.so: $(PEVENT_LIB_OBJS)
238         $(Q)$(do_compile_shared_library)
239
240 libtraceevent.a: $(PEVENT_LIB_OBJS)
241         $(Q)$(do_build_static_lib)
242
243 plugins: $(PLUGINS)
244
245 $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
246         $(Q)$(do_fpic_compile)
247
248 $(PLUGIN_OBJS): %.o : $(src)/%.c
249         $(Q)$(do_compile_plugin_obj)
250
251 $(PLUGINS): %.so: %.o
252         $(Q)$(do_plugin_build)
253
254 define make_version.h
255         (echo '/* This file is automatically generated. Do not modify. */';             \
256         echo \#define VERSION_CODE $(shell                                              \
257         expr $(VERSION) \* 256 + $(PATCHLEVEL));                                        \
258         echo '#define EXTRAVERSION ' $(EXTRAVERSION);                                   \
259         echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"';     \
260         echo '#define FILE_VERSION '$(FILE_VERSION);                                    \
261         ) > $1
262 endef
263
264 define update_version.h
265         ($(call make_version.h, $@.tmp);                \
266         if [ -r $@ ] && cmp -s $@ $@.tmp; then          \
267                 rm -f $@.tmp;                           \
268         else                                            \
269                 echo '  UPDATE                 $@';     \
270                 mv -f $@.tmp $@;                        \
271         fi);
272 endef
273
274 ep_version.h: force
275         $(Q)$(N)$(call update_version.h)
276
277 VERSION_FILES = ep_version.h
278
279 define update_dir
280         (echo $1 > $@.tmp;      \
281         if [ -r $@ ] && cmp -s $@ $@.tmp; then          \
282                 rm -f $@.tmp;                           \
283         else                                            \
284                 echo '  UPDATE                 $@';     \
285                 mv -f $@.tmp $@;                        \
286         fi);
287 endef
288
289 ## make deps
290
291 all_objs := $(sort $(ALL_OBJS))
292 all_deps := $(all_objs:%.o=.%.d)
293
294 # let .d file also depends on the source and header files
295 define check_deps
296                 @set -e; $(RM) $@; \
297                 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
298                 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
299                 $(RM) $@.$$$$
300 endef
301
302 $(all_deps): .%.d: $(src)/%.c
303         $(Q)$(call check_deps)
304
305 $(all_objs) : %.o : .%.d
306
307 dep_includes := $(wildcard $(all_deps))
308
309 ifneq ($(dep_includes),)
310  include $(dep_includes)
311 endif
312
313 ### Detect environment changes
314 TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
315
316 TRACEEVENT-CFLAGS: force
317         @FLAGS='$(TRACK_CFLAGS)'; \
318             if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
319                 echo 1>&2 "  FLAGS:   * new build flags or cross compiler"; \
320                 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
321             fi
322
323 tags:   force
324         $(RM) tags
325         find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
326         --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
327
328 TAGS:   force
329         $(RM) TAGS
330         find . -name '*.[ch]' | xargs etags \
331         --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
332
333 define do_install
334         $(print_install)                                \
335         if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
336                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
337         fi;                                             \
338         $(INSTALL) $1 '$(DESTDIR_SQ)$2'
339 endef
340
341 install_lib: all_cmd install_plugins
342         $(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
343
344 PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS))
345
346 $(PLUGINS_INSTALL): %.install : %.so force
347         $(Q)$(call do_install,$<,$(plugin_dir_SQ))
348
349 install_plugins: $(PLUGINS_INSTALL)
350
351 install: install_lib
352
353 clean:
354         $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
355         $(RM) TRACEEVENT-CFLAGS tags TAGS
356
357 endif # skip-makefile
358
359 PHONY += force
360 force:
361
362 # Declare the contents of the .PHONY variable as phony.  We keep that
363 # information in a variable so we can use it in if_changed and friends.
364 .PHONY: $(PHONY)