9 MAKEFLAGS += --no-print-directory
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.
18 $(if $(or $(findstring environment,$(origin $(1))),\
19 $(findstring command line,$(origin $(1)))),,\
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)
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.
35 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
39 bindir = $(prefix)/$(bindir_relative)
40 man_dir = $(prefix)/share/man
41 man_dir_SQ = '$(subst ','\'',$(man_dir))'
43 export man_dir man_dir_SQ INSTALL
44 export DESTDIR DESTDIR_SQ
48 # Set plugin_dir to preffered global plugin location
49 # If we install under $HOME directory we go under
50 # $(HOME)/.traceevent/plugins
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.
57 ifeq ($(prefix),$(HOME))
58 override plugin_dir = $(HOME)/.traceevent/plugins
61 override plugin_dir = $(prefix)/lib/traceevent/plugins
65 ifeq ($(set_plugin_dir),1)
66 PLUGIN_DIR = -DPLUGIN_DIR="$(DESTDIR)/$(plugin_dir)"
67 PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
70 # copy a bit from Linux kbuild
72 ifeq ("$(origin V)", "command line")
79 ifeq ("$(origin O)", "command line")
84 ifneq ($(BUILD_OUTPUT),)
87 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(BUILD_OUTPUT) \
88 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
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))
98 $(MAKECMDGOALS): sub-make
101 $(call build_output, $(MAKECMDGOALS))
104 # Leave processing to above invocation of make
110 # We process the rest of the Makefile if this is the final invocation of make
111 ifeq ($(skip-makefile),)
113 srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
118 export prefix bindir src obj
121 bindir_SQ = $(subst ','\'',$(bindir))
122 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
123 plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
125 LIB_FILE = libtraceevent.a libtraceevent.so
131 VERSION = $(EP_VERSION)
132 PATCHLEVEL = $(EP_PATCHLEVEL)
133 EXTRAVERSION = $(EP_EXTRAVERSION)
140 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
142 INCLUDES = -I. $(CONFIG_INCLUDES)
144 # Set compile option CFLAGS if not set elsewhere
147 # Append required CFLAGS
148 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
149 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
156 print_shared_lib_compile =
157 print_plugin_obj_compile =
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;
173 ($(print_fpic_compile) \
174 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
177 ($(print_app_build) \
178 $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
180 do_compile_shared_library = \
181 ($(print_shared_lib_compile) \
182 $(CC) --shared $^ -o $@)
184 do_compile_plugin_obj = \
185 ($(print_plugin_obj_compile) \
186 $(CC) -c $(CFLAGS) -fPIC -o $@ $<)
189 ($(print_plugin_build) \
190 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
192 do_build_static_lib = \
193 ($(print_static_lib_build) \
194 $(RM) $@; $(AR) rcs $@ $^)
199 $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
202 $(obj)/%.o: $(src)/%.c
203 $(Q)$(call do_compile)
206 $(Q)$(call do_compile)
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
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
224 PLUGINS := $(PLUGIN_OBJS:.o=.so)
226 ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
228 CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
230 TARGETS = $(CMD_TARGETS)
235 all_cmd: $(CMD_TARGETS)
237 libtraceevent.so: $(PEVENT_LIB_OBJS)
238 $(Q)$(do_compile_shared_library)
240 libtraceevent.a: $(PEVENT_LIB_OBJS)
241 $(Q)$(do_build_static_lib)
245 $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
246 $(Q)$(do_fpic_compile)
248 $(PLUGIN_OBJS): %.o : $(src)/%.c
249 $(Q)$(do_compile_plugin_obj)
251 $(PLUGINS): %.so: %.o
252 $(Q)$(do_plugin_build)
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); \
264 define update_version.h
265 ($(call make_version.h, $@.tmp); \
266 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
275 $(Q)$(N)$(call update_version.h)
277 VERSION_FILES = ep_version.h
281 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
291 all_objs := $(sort $(ALL_OBJS))
292 all_deps := $(all_objs:%.o=.%.d)
294 # let .d file also depends on the source and header files
297 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
298 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
302 $(all_deps): .%.d: $(src)/%.c
303 $(Q)$(call check_deps)
305 $(all_objs) : %.o : .%.d
307 dep_includes := $(wildcard $(all_deps))
309 ifneq ($(dep_includes),)
310 include $(dep_includes)
313 ### Detect environment changes
314 TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
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; \
325 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
326 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
330 find . -name '*.[ch]' | xargs etags \
331 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
335 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
336 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
338 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
341 install_lib: all_cmd install_plugins
342 $(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
344 PLUGINS_INSTALL = $(subst .so,.install,$(PLUGINS))
346 $(PLUGINS_INSTALL): %.install : %.so force
347 $(Q)$(call do_install,$<,$(plugin_dir_SQ))
349 install_plugins: $(PLUGINS_INSTALL)
354 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
355 $(RM) TRACEEVENT-CFLAGS tags TAGS
357 endif # skip-makefile
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.