Makefile 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. # trace-cmd version
  2. EP_VERSION = 1
  3. EP_PATCHLEVEL = 1
  4. EP_EXTRAVERSION = 0
  5. # file format version
  6. FILE_VERSION = 6
  7. MAKEFLAGS += --no-print-directory
  8. # Makefiles suck: This macro sets a default value of $(2) for the
  9. # variable named by $(1), unless the variable has been set by
  10. # environment or command line. This is necessary for CC and AR
  11. # because make sets default values, so the simpler ?= approach
  12. # won't work as expected.
  13. define allow-override
  14. $(if $(or $(findstring environment,$(origin $(1))),\
  15. $(findstring command line,$(origin $(1)))),,\
  16. $(eval $(1) = $(2)))
  17. endef
  18. # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
  19. $(call allow-override,CC,$(CROSS_COMPILE)gcc)
  20. $(call allow-override,AR,$(CROSS_COMPILE)ar)
  21. EXT = -std=gnu99
  22. INSTALL = install
  23. # Use DESTDIR for installing into a different root directory.
  24. # This is useful for building a package. The program will be
  25. # installed in this directory as if it was the root directory.
  26. # Then the build tool can move it later.
  27. DESTDIR ?=
  28. DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
  29. prefix ?= /usr/local
  30. bindir_relative = bin
  31. bindir = $(prefix)/$(bindir_relative)
  32. man_dir = $(prefix)/share/man
  33. man_dir_SQ = '$(subst ','\'',$(man_dir))'
  34. export man_dir man_dir_SQ INSTALL
  35. export DESTDIR DESTDIR_SQ
  36. set_plugin_dir := 1
  37. # Set plugin_dir to preffered global plugin location
  38. # If we install under $HOME directory we go under
  39. # $(HOME)/.traceevent/plugins
  40. #
  41. # We dont set PLUGIN_DIR in case we install under $HOME
  42. # directory, because by default the code looks under:
  43. # $(HOME)/.traceevent/plugins by default.
  44. #
  45. ifeq ($(plugin_dir),)
  46. ifeq ($(prefix),$(HOME))
  47. override plugin_dir = $(HOME)/.traceevent/plugins
  48. set_plugin_dir := 0
  49. else
  50. override plugin_dir = $(prefix)/lib/traceevent/plugins
  51. endif
  52. endif
  53. ifeq ($(set_plugin_dir),1)
  54. PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
  55. PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
  56. endif
  57. include $(if $(BUILD_SRC),$(BUILD_SRC)/)../../scripts/Makefile.include
  58. # copy a bit from Linux kbuild
  59. ifeq ("$(origin V)", "command line")
  60. VERBOSE = $(V)
  61. endif
  62. ifndef VERBOSE
  63. VERBOSE = 0
  64. endif
  65. ifeq ("$(origin O)", "command line")
  66. BUILD_OUTPUT := $(O)
  67. endif
  68. ifeq ($(BUILD_SRC),)
  69. ifneq ($(OUTPUT),)
  70. define build_output
  71. $(if $(VERBOSE:1=),@)+$(MAKE) -C $(OUTPUT) \
  72. BUILD_SRC=$(CURDIR)/ -f $(CURDIR)/Makefile $1
  73. endef
  74. all: sub-make
  75. $(MAKECMDGOALS): sub-make
  76. sub-make: force
  77. $(call build_output, $(MAKECMDGOALS))
  78. # Leave processing to above invocation of make
  79. skip-makefile := 1
  80. endif # OUTPUT
  81. endif # BUILD_SRC
  82. # We process the rest of the Makefile if this is the final invocation of make
  83. ifeq ($(skip-makefile),)
  84. srctree := $(if $(BUILD_SRC),$(BUILD_SRC),$(CURDIR))
  85. objtree := $(CURDIR)
  86. src := $(srctree)
  87. obj := $(objtree)
  88. export prefix bindir src obj
  89. # Shell quotes
  90. bindir_SQ = $(subst ','\'',$(bindir))
  91. bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
  92. plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
  93. LIB_FILE = libtraceevent.a libtraceevent.so
  94. CONFIG_INCLUDES =
  95. CONFIG_LIBS =
  96. CONFIG_FLAGS =
  97. VERSION = $(EP_VERSION)
  98. PATCHLEVEL = $(EP_PATCHLEVEL)
  99. EXTRAVERSION = $(EP_EXTRAVERSION)
  100. OBJ = $@
  101. N =
  102. export Q VERBOSE
  103. EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
  104. INCLUDES = -I. -I $(srctree)/../../include $(CONFIG_INCLUDES)
  105. # Set compile option CFLAGS if not set elsewhere
  106. CFLAGS ?= -g -Wall
  107. # Append required CFLAGS
  108. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  109. override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
  110. ifeq ($(VERBOSE),1)
  111. Q =
  112. else
  113. Q = @
  114. endif
  115. do_compile_shared_library = \
  116. ($(print_shared_lib_compile) \
  117. $(CC) --shared $^ -o $@)
  118. do_plugin_build = \
  119. ($(print_plugin_build) \
  120. $(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<)
  121. do_build_static_lib = \
  122. ($(print_static_lib_build) \
  123. $(RM) $@; $(AR) rcs $@ $^)
  124. do_compile = $(QUIET_CC)$(CC) -c $(CFLAGS) $(EXT) $< -o $(obj)/$@;
  125. $(obj)/%.o: $(src)/%.c
  126. $(call do_compile)
  127. %.o: $(src)/%.c
  128. $(call do_compile)
  129. PEVENT_LIB_OBJS = event-parse.o
  130. PEVENT_LIB_OBJS += event-plugin.o
  131. PEVENT_LIB_OBJS += trace-seq.o
  132. PEVENT_LIB_OBJS += parse-filter.o
  133. PEVENT_LIB_OBJS += parse-utils.o
  134. PEVENT_LIB_OBJS += kbuffer-parse.o
  135. PLUGIN_OBJS = plugin_jbd2.o
  136. PLUGIN_OBJS += plugin_hrtimer.o
  137. PLUGIN_OBJS += plugin_kmem.o
  138. PLUGIN_OBJS += plugin_kvm.o
  139. PLUGIN_OBJS += plugin_mac80211.o
  140. PLUGIN_OBJS += plugin_sched_switch.o
  141. PLUGIN_OBJS += plugin_function.o
  142. PLUGIN_OBJS += plugin_xen.o
  143. PLUGIN_OBJS += plugin_scsi.o
  144. PLUGIN_OBJS += plugin_cfg80211.o
  145. PLUGINS := $(PLUGIN_OBJS:.o=.so)
  146. ALL_OBJS = $(PEVENT_LIB_OBJS) $(PLUGIN_OBJS)
  147. CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
  148. TARGETS = $(CMD_TARGETS)
  149. all: all_cmd
  150. all_cmd: $(CMD_TARGETS)
  151. libtraceevent.so: $(PEVENT_LIB_OBJS)
  152. $(QUIET_LINK)$(CC) --shared $^ -o $@
  153. libtraceevent.a: $(PEVENT_LIB_OBJS)
  154. $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
  155. plugins: $(PLUGINS)
  156. $(PEVENT_LIB_OBJS): %.o: $(src)/%.c TRACEEVENT-CFLAGS
  157. $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) $(EXT) -fPIC $< -o $@
  158. $(PLUGIN_OBJS): %.o : $(src)/%.c
  159. $(QUIET_CC_FPIC)$(CC) -c $(CFLAGS) -fPIC -o $@ $<
  160. $(PLUGINS): %.so: %.o
  161. $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $<
  162. define make_version.h
  163. (echo '/* This file is automatically generated. Do not modify. */'; \
  164. echo \#define VERSION_CODE $(shell \
  165. expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
  166. echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
  167. echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
  168. echo '#define FILE_VERSION '$(FILE_VERSION); \
  169. ) > $1
  170. endef
  171. define update_version.h
  172. ($(call make_version.h, $@.tmp); \
  173. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  174. rm -f $@.tmp; \
  175. else \
  176. echo ' UPDATE $@'; \
  177. mv -f $@.tmp $@; \
  178. fi);
  179. endef
  180. ep_version.h: force
  181. $(Q)$(N)$(call update_version.h)
  182. VERSION_FILES = ep_version.h
  183. define update_dir
  184. (echo $1 > $@.tmp; \
  185. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  186. rm -f $@.tmp; \
  187. else \
  188. echo ' UPDATE $@'; \
  189. mv -f $@.tmp $@; \
  190. fi);
  191. endef
  192. ## make deps
  193. all_objs := $(sort $(ALL_OBJS))
  194. all_deps := $(all_objs:%.o=.%.d)
  195. # let .d file also depends on the source and header files
  196. define check_deps
  197. @set -e; $(RM) $@; \
  198. $(CC) -MM $(CFLAGS) $< > $@.$$$$; \
  199. sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
  200. $(RM) $@.$$$$
  201. endef
  202. $(all_deps): .%.d: $(src)/%.c
  203. $(Q)$(call check_deps)
  204. $(all_objs) : %.o : .%.d
  205. dep_includes := $(wildcard $(all_deps))
  206. ifneq ($(dep_includes),)
  207. include $(dep_includes)
  208. endif
  209. ### Detect environment changes
  210. TRACK_CFLAGS = $(subst ','\'',$(CFLAGS)):$(ARCH):$(CROSS_COMPILE)
  211. TRACEEVENT-CFLAGS: force
  212. @FLAGS='$(TRACK_CFLAGS)'; \
  213. if test x"$$FLAGS" != x"`cat TRACEEVENT-CFLAGS 2>/dev/null`" ; then \
  214. echo 1>&2 " FLAGS: * new build flags or cross compiler"; \
  215. echo "$$FLAGS" >TRACEEVENT-CFLAGS; \
  216. fi
  217. tags: force
  218. $(RM) tags
  219. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  220. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
  221. TAGS: force
  222. $(RM) TAGS
  223. find . -name '*.[ch]' | xargs etags \
  224. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
  225. define do_install
  226. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  227. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  228. fi; \
  229. $(INSTALL) $1 '$(DESTDIR_SQ)$2'
  230. endef
  231. define do_install_plugins
  232. for plugin in $1; do \
  233. $(call do_install,$$plugin,$(plugin_dir_SQ)); \
  234. done
  235. endef
  236. install_lib: all_cmd install_plugins
  237. $(call QUIET_INSTALL, $(LIB_FILE)) \
  238. $(call do_install,$(LIB_FILE),$(bindir_SQ))
  239. install_plugins: $(PLUGINS)
  240. $(call QUIET_INSTALL, trace_plugins) \
  241. $(call do_install_plugins, $(PLUGINS))
  242. install: install_lib
  243. clean:
  244. $(call QUIET_CLEAN, libtraceevent) \
  245. $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
  246. $(RM) TRACEEVENT-CFLAGS tags TAGS
  247. endif # skip-makefile
  248. PHONY += force plugins
  249. force:
  250. plugins:
  251. @echo > /dev/null
  252. # Declare the contents of the .PHONY variable as phony. We keep that
  253. # information in a variable so we can use it in if_changed and friends.
  254. .PHONY: $(PHONY)