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
46 # copy a bit from Linux kbuild
48 ifeq ("$(origin V)", "command line")
55 ifeq ("$(origin O)", "command line")
60 ifneq ($(BUILD_OUTPUT),)
63 $(if $(VERBOSE:1=),@)+$(MAKE) -C $(BUILD_OUTPUT) \
64 BUILD_SRC=$(CURDIR) -f $(CURDIR)/Makefile $1
67 saved-output := $(BUILD_OUTPUT)
68 BUILD_OUTPUT := $(shell cd $(BUILD_OUTPUT) && /bin/pwd)
69 $(if $(BUILD_OUTPUT),, \
70 $(error output directory "$(saved-output)" does not exist))
74 $(MAKECMDGOALS): sub-make
77 $(call build_output, $(MAKECMDGOALS))
80 # Leave processing to above invocation of make
86 # We process the rest of the Makefile if this is the final invocation of make
87 ifeq ($(skip-makefile),)
89 srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
94 export prefix bindir src obj
97 bindir_SQ = $(subst ','\'',$(bindir))
98 bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
100 LIB_FILE = libtraceevent.a libtraceevent.so
106 VERSION = $(EP_VERSION)
107 PATCHLEVEL = $(EP_PATCHLEVEL)
108 EXTRAVERSION = $(EP_EXTRAVERSION)
115 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
117 INCLUDES = -I. $(CONFIG_INCLUDES)
119 # Set compile option CFLAGS if not set elsewhere
122 # Append required CFLAGS
123 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
124 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
131 print_shared_lib_compile =
132 print_plugin_obj_compile =
137 print_compile = echo ' CC '$(OBJ);
138 print_app_build = echo ' BUILD '$(OBJ);
139 print_fpic_compile = echo ' CC FPIC '$(OBJ);
140 print_shared_lib_compile = echo ' BUILD SHARED LIB '$(OBJ);
141 print_plugin_obj_compile = echo ' CC PLUGIN OBJ '$(OBJ);
142 print_plugin_build = echo ' CC PLUGI '$(OBJ);
143 print_static_lib_build = echo ' BUILD STATIC LIB '$(OBJ);
144 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
148 ($(print_fpic_compile) \
149 $(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@)
152 ($(print_app_build) \
153 $(CC) $^ -rdynamic -o $@ $(CONFIG_LIBS) $(LIBS))
155 do_compile_shared_library = \
156 ($(print_shared_lib_compile) \
157 $(CC) --shared $^ -o $@)
159 do_compile_plugin_obj = \
160 ($(print_plugin_obj_compile) \
161 $(CC) -c $(CFLAGS) -fPIC -o $@ $<)
164 ($(print_plugin_build) \
165 $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
167 do_build_static_lib = \
168 ($(print_static_lib_build) \
169 $(RM) $@; $(AR) rcs $@ $^)
174 $(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
177 $(obj)/%.o: $(src)/%.c
178 $(Q)$(call do_compile)
181 $(Q)$(call do_compile)
183 PEVENT_LIB_OBJS = event-parse.o trace-seq.o parse-filter.o parse-utils.o
184 PEVENT_LIB_OBJS += kbuffer-parse.o
186 ALL_OBJS = $(PEVENT_LIB_OBJS)
188 CMD_TARGETS = $(LIB_FILE)
190 TARGETS = $(CMD_TARGETS)
195 all_cmd: $(CMD_TARGETS)
197 libtraceevent.so: $(PEVENT_LIB_OBJS)
198 $(Q)$(do_compile_shared_library)
200 libtraceevent.a: $(PEVENT_LIB_OBJS)
201 $(Q)$(do_build_static_lib)
203 $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
204 $(Q)$(do_fpic_compile)
206 define make_version.h
207 (echo '/* This file is automatically generated. Do not modify. */'; \
208 echo \#define VERSION_CODE $(shell \
209 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
210 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
211 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
212 echo '#define FILE_VERSION '$(FILE_VERSION); \
216 define update_version.h
217 ($(call make_version.h, $@.tmp); \
218 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
227 $(Q)$(N)$(call update_version.h)
229 VERSION_FILES = ep_version.h
233 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
243 all_objs := $(sort $(ALL_OBJS))
244 all_deps := $(all_objs:%.o=.%.d)
246 # let .d file also depends on the source and header files
249 $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
250 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
254 $(all_deps): .%.d: $(src)/%.c
255 $(Q)$(call check_deps)
257 $(all_objs) : %.o : .%.d
259 dep_includes := $(wildcard $(all_deps))
261 ifneq ($(dep_includes),)
262 include $(dep_includes)
265 ### Detect environment changes
266 TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
268 TRACEEVENT-CFLAGS: force
269 @FLAGS='$(TRACK_CFLAGS)'; \
270 if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
271 echo 1>&2 " * new build flags or cross compiler"; \
272 echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
277 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
278 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
282 find . -name '*.[ch]' | xargs etags \
283 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
287 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
288 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
290 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
294 $(Q)$(call do_install,$(LIB_FILE),$(bindir_SQ))
299 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d
300 $(RM) TRACEEVENT-CFLAGS tags TAGS
302 endif # skip-makefile
307 # Declare the contents of the .PHONY variable as phony. We keep that
308 # information in a variable so we can use it in if_changed and friends.