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="$(plugin_dir)"
67 PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
70 include $(if $(BUILD_SRC),$(BUILD_SRC)/)../../scripts/Makefile.include
72 # copy a bit from Linux kbuild
74 ifeq ("$(origin V)", "command line")
81 ifeq ("$(origin O)", "command line")
89 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(OUTPUT) \
90 BUILD_SRC=$(CURDIR)/ -f $(CURDIR)/Makefile $1
95 $(MAKECMDGOALS): sub-make
98 $(call build_output, $(MAKECMDGOALS))
101 # Leave processing to above invocation of make
107 # We process the rest of the Makefile if this is the final invocation of make
108 ifeq ($(skip-makefile),)
110 srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
115 export prefix bindir src obj
118 bindir_SQ = $(subst ','\'',$(bindir))
119 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
120 plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
122 LIB_FILE = libtraceevent.a libtraceevent.so
128 VERSION = $(EP_VERSION)
129 PATCHLEVEL = $(EP_PATCHLEVEL)
130 EXTRAVERSION = $(EP_EXTRAVERSION)
137 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
139 INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
141 # Set compile option CFLAGS if not set elsewhere
144 # Append required CFLAGS
145 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
146 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
154 do_compile_shared_library = \
155 ($(print_shared_lib_compile) \
156 $(CC) --shared $^ -o $@)
159 ($(print_plugin_build) \
160 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
162 do_build_static_lib = \
163 ($(print_static_lib_build) \
164 $(RM) $@; $(AR) rcs $@ $^)
167 do_compile = $(QUIET_CC)$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
169 $(obj)/%.o: $(src)/%.c
175 PEVENT_LIB_OBJS = event-parse.o
176 PEVENT_LIB_OBJS += event-plugin.o
177 PEVENT_LIB_OBJS += trace-seq.o
178 PEVENT_LIB_OBJS += parse-filter.o
179 PEVENT_LIB_OBJS += parse-utils.o
180 PEVENT_LIB_OBJS += kbuffer-parse.o
182 PLUGIN_OBJS = plugin_jbd2.o
183 PLUGIN_OBJS += plugin_hrtimer.o
184 PLUGIN_OBJS += plugin_kmem.o
185 PLUGIN_OBJS += plugin_kvm.o
186 PLUGIN_OBJS += plugin_mac80211.o
187 PLUGIN_OBJS += plugin_sched_switch.o
188 PLUGIN_OBJS += plugin_function.o
189 PLUGIN_OBJS += plugin_xen.o
190 PLUGIN_OBJS += plugin_scsi.o
191 PLUGIN_OBJS += plugin_cfg80211.o
193 PLUGINS := $(PLUGIN_OBJS:.o=.so)
195 ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
197 CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
199 TARGETS = $(CMD_TARGETS)
204 all_cmd: $(CMD_TARGETS)
206 libtraceevent.so: $(PEVENT_LIB_OBJS)
207 $(QUIET_LINK)$(CC) --shared $^ -o $@
209 libtraceevent.a: $(PEVENT_LIB_OBJS)
210 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
214 $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
215 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@
217 $(PLUGIN_OBJS): %.o : $(src)/%.c
218 $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) -fPIC -o $@ $<
220 $(PLUGINS): %.so: %.o
221 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<
223 define 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); \
233 define update_version.h
234 ($(call make_version.h, $@.tmp); \
235 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
244 $(Q)$(N)$(call update_version.h)
246 VERSION_FILES = ep_version.h
250 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
260 all_objs := $(sort $(ALL_OBJS))
261 all_deps := $(all_objs:%.o=.%.d)
263 # let .d file also depends on the source and header files
266 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
267 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
271 $(all_deps): .%.d: $(src)/%.c
272 $(Q)$(call check_deps)
274 $(all_objs) : %.o : .%.d
276 dep_includes := $(wildcard $(all_deps))
278 ifneq ($(dep_includes),)
279 include $(dep_includes)
282 ### Detect environment changes
283 TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
285 TRACEEVENT-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; \
294 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
295 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
299 find . -name '*.[ch]' | xargs etags \
300 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
303 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
304 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
306 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
309 define do_install_plugins
310 for plugin in $1; do \
311 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
315 install_lib: all_cmd install_plugins
316 $(call QUIET_INSTALL, $(LIB_FILE)) \
317 $(call do_install,$(LIB_FILE),$(bindir_SQ))
319 install_plugins: $(PLUGINS)
320 $(call QUIET_INSTALL, trace_plugins) \
321 $(call do_install_plugins, $(PLUGINS))
326 $(call QUIET_CLEAN, libtraceevent) \
327 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
328 $(RM) TRACEEVENT-CFLAGS tags TAGS
330 endif # skip-makefile
332 PHONY += force plugins
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.