Makefile 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. $(call allow-override,NM,$(CROSS_COMPILE)nm)
  22. EXT = -std=gnu99
  23. INSTALL = install
  24. # Use DESTDIR for installing into a different root directory.
  25. # This is useful for building a package. The program will be
  26. # installed in this directory as if it was the root directory.
  27. # Then the build tool can move it later.
  28. DESTDIR ?=
  29. DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
  30. LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
  31. ifeq ($(LP64), 1)
  32. libdir_relative = lib64
  33. else
  34. libdir_relative = lib
  35. endif
  36. prefix ?= /usr/local
  37. libdir = $(prefix)/$(libdir_relative)
  38. man_dir = $(prefix)/share/man
  39. man_dir_SQ = '$(subst ','\'',$(man_dir))'
  40. export man_dir man_dir_SQ INSTALL
  41. export DESTDIR DESTDIR_SQ
  42. set_plugin_dir := 1
  43. # Set plugin_dir to preffered global plugin location
  44. # If we install under $HOME directory we go under
  45. # $(HOME)/.traceevent/plugins
  46. #
  47. # We dont set PLUGIN_DIR in case we install under $HOME
  48. # directory, because by default the code looks under:
  49. # $(HOME)/.traceevent/plugins by default.
  50. #
  51. ifeq ($(plugin_dir),)
  52. ifeq ($(prefix),$(HOME))
  53. override plugin_dir = $(HOME)/.traceevent/plugins
  54. set_plugin_dir := 0
  55. else
  56. override plugin_dir = $(libdir)/traceevent/plugins
  57. endif
  58. endif
  59. ifeq ($(set_plugin_dir),1)
  60. PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
  61. PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
  62. endif
  63. include ../../scripts/Makefile.include
  64. # copy a bit from Linux kbuild
  65. ifeq ("$(origin V)", "command line")
  66. VERBOSE = $(V)
  67. endif
  68. ifndef VERBOSE
  69. VERBOSE = 0
  70. endif
  71. ifeq ($(srctree),)
  72. srctree := $(patsubst %/,%,$(dir $(shell pwd)))
  73. srctree := $(patsubst %/,%,$(dir $(srctree)))
  74. srctree := $(patsubst %/,%,$(dir $(srctree)))
  75. #$(info Determined 'srctree' to be $(srctree))
  76. endif
  77. export prefix libdir src obj
  78. # Shell quotes
  79. libdir_SQ = $(subst ','\'',$(libdir))
  80. libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
  81. plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
  82. LIB_FILE = libtraceevent.a libtraceevent.so
  83. CONFIG_INCLUDES =
  84. CONFIG_LIBS =
  85. CONFIG_FLAGS =
  86. VERSION = $(EP_VERSION)
  87. PATCHLEVEL = $(EP_PATCHLEVEL)
  88. EXTRAVERSION = $(EP_EXTRAVERSION)
  89. OBJ = $@
  90. N =
  91. EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
  92. INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
  93. # Set compile option CFLAGS
  94. ifdef EXTRA_CFLAGS
  95. CFLAGS := $(EXTRA_CFLAGS)
  96. else
  97. CFLAGS := -g -Wall
  98. endif
  99. # Append required CFLAGS
  100. override CFLAGS += -fPIC
  101. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  102. override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
  103. ifeq ($(VERBOSE),1)
  104. Q =
  105. else
  106. Q = @
  107. endif
  108. # Disable command line variables (CFLAGS) overide from top
  109. # level Makefile (perf), otherwise build Makefile will get
  110. # the same command line setup.
  111. MAKEOVERRIDES=
  112. export srctree OUTPUT CC LD CFLAGS V
  113. build := -f $(srctree)/tools/build/Makefile.build dir=. obj
  114. PLUGINS = plugin_jbd2.so
  115. PLUGINS += plugin_hrtimer.so
  116. PLUGINS += plugin_kmem.so
  117. PLUGINS += plugin_kvm.so
  118. PLUGINS += plugin_mac80211.so
  119. PLUGINS += plugin_sched_switch.so
  120. PLUGINS += plugin_function.so
  121. PLUGINS += plugin_xen.so
  122. PLUGINS += plugin_scsi.so
  123. PLUGINS += plugin_cfg80211.so
  124. PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
  125. PLUGINS_IN := $(PLUGINS:.so=-in.o)
  126. TE_IN := $(OUTPUT)libtraceevent-in.o
  127. LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
  128. DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
  129. CMD_TARGETS = $(LIB_FILE) $(PLUGINS) $(DYNAMIC_LIST_FILE)
  130. TARGETS = $(CMD_TARGETS)
  131. all: all_cmd
  132. all_cmd: $(CMD_TARGETS)
  133. $(TE_IN): force
  134. $(Q)$(MAKE) $(build)=libtraceevent
  135. $(OUTPUT)libtraceevent.so: $(TE_IN)
  136. $(QUIET_LINK)$(CC) --shared $^ -o $@
  137. $(OUTPUT)libtraceevent.a: $(TE_IN)
  138. $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
  139. $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
  140. $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
  141. plugins: $(PLUGINS)
  142. __plugin_obj = $(notdir $@)
  143. plugin_obj = $(__plugin_obj:-in.o=)
  144. $(PLUGINS_IN): force
  145. $(Q)$(MAKE) $(build)=$(plugin_obj)
  146. $(OUTPUT)%.so: $(OUTPUT)%-in.o
  147. $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
  148. define make_version.h
  149. (echo '/* This file is automatically generated. Do not modify. */'; \
  150. echo \#define VERSION_CODE $(shell \
  151. expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
  152. echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
  153. echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
  154. echo '#define FILE_VERSION '$(FILE_VERSION); \
  155. ) > $1
  156. endef
  157. define update_version.h
  158. ($(call make_version.h, $@.tmp); \
  159. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  160. rm -f $@.tmp; \
  161. else \
  162. echo ' UPDATE $@'; \
  163. mv -f $@.tmp $@; \
  164. fi);
  165. endef
  166. ep_version.h: force
  167. $(Q)$(N)$(call update_version.h)
  168. VERSION_FILES = ep_version.h
  169. define update_dir
  170. (echo $1 > $@.tmp; \
  171. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  172. rm -f $@.tmp; \
  173. else \
  174. echo ' UPDATE $@'; \
  175. mv -f $@.tmp $@; \
  176. fi);
  177. endef
  178. tags: force
  179. $(RM) tags
  180. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  181. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
  182. TAGS: force
  183. $(RM) TAGS
  184. find . -name '*.[ch]' | xargs etags \
  185. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
  186. define do_install
  187. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  188. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  189. fi; \
  190. $(INSTALL) $1 '$(DESTDIR_SQ)$2'
  191. endef
  192. define do_install_plugins
  193. for plugin in $1; do \
  194. $(call do_install,$$plugin,$(plugin_dir_SQ)); \
  195. done
  196. endef
  197. define do_generate_dynamic_list_file
  198. (echo '{'; \
  199. $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u; \
  200. echo '};'; \
  201. ) > $2
  202. endef
  203. install_lib: all_cmd install_plugins
  204. $(call QUIET_INSTALL, $(LIB_FILE)) \
  205. $(call do_install,$(LIB_FILE),$(libdir_SQ))
  206. install_plugins: $(PLUGINS)
  207. $(call QUIET_INSTALL, trace_plugins) \
  208. $(call do_install_plugins, $(PLUGINS))
  209. install: install_lib
  210. clean:
  211. $(call QUIET_CLEAN, libtraceevent) \
  212. $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
  213. $(RM) TRACEEVENT-CFLAGS tags TAGS
  214. PHONY += force plugins
  215. force:
  216. # Declare the contents of the .PHONY variable as phony. We keep that
  217. # information in a variable so we can use it in if_changed and friends.
  218. .PHONY: $(PHONY)