Makefile 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 $(CURDIR)))
  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. CONFIG_INCLUDES =
  83. CONFIG_LIBS =
  84. CONFIG_FLAGS =
  85. VERSION = $(EP_VERSION)
  86. PATCHLEVEL = $(EP_PATCHLEVEL)
  87. EXTRAVERSION = $(EP_EXTRAVERSION)
  88. OBJ = $@
  89. N =
  90. EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
  91. LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
  92. LIB_INSTALL = libtraceevent.a libtraceevent.so*
  93. INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
  94. # Set compile option CFLAGS
  95. ifdef EXTRA_CFLAGS
  96. CFLAGS := $(EXTRA_CFLAGS)
  97. else
  98. CFLAGS := -g -Wall
  99. endif
  100. # Append required CFLAGS
  101. override CFLAGS += -fPIC
  102. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  103. override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
  104. ifeq ($(VERBOSE),1)
  105. Q =
  106. else
  107. Q = @
  108. endif
  109. # Disable command line variables (CFLAGS) overide from top
  110. # level Makefile (perf), otherwise build Makefile will get
  111. # the same command line setup.
  112. MAKEOVERRIDES=
  113. export srctree OUTPUT CC LD CFLAGS V
  114. build := -f $(srctree)/tools/build/Makefile.build dir=. obj
  115. PLUGINS = plugin_jbd2.so
  116. PLUGINS += plugin_hrtimer.so
  117. PLUGINS += plugin_kmem.so
  118. PLUGINS += plugin_kvm.so
  119. PLUGINS += plugin_mac80211.so
  120. PLUGINS += plugin_sched_switch.so
  121. PLUGINS += plugin_function.so
  122. PLUGINS += plugin_xen.so
  123. PLUGINS += plugin_scsi.so
  124. PLUGINS += plugin_cfg80211.so
  125. PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
  126. PLUGINS_IN := $(PLUGINS:.so=-in.o)
  127. TE_IN := $(OUTPUT)libtraceevent-in.o
  128. LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
  129. DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
  130. CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE)
  131. TARGETS = $(CMD_TARGETS)
  132. all: all_cmd
  133. all_cmd: $(CMD_TARGETS)
  134. $(TE_IN): force
  135. $(Q)$(MAKE) $(build)=libtraceevent
  136. $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
  137. $(QUIET_LINK)$(CC) --shared $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
  138. @ln -sf $(@F) $(OUTPUT)libtraceevent.so
  139. @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
  140. $(OUTPUT)libtraceevent.a: $(TE_IN)
  141. $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
  142. $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
  143. $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
  144. plugins: $(PLUGINS)
  145. __plugin_obj = $(notdir $@)
  146. plugin_obj = $(__plugin_obj:-in.o=)
  147. $(PLUGINS_IN): force
  148. $(Q)$(MAKE) $(build)=$(plugin_obj)
  149. $(OUTPUT)%.so: $(OUTPUT)%-in.o
  150. $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
  151. define make_version.h
  152. (echo '/* This file is automatically generated. Do not modify. */'; \
  153. echo \#define VERSION_CODE $(shell \
  154. expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
  155. echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
  156. echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
  157. echo '#define FILE_VERSION '$(FILE_VERSION); \
  158. ) > $1
  159. endef
  160. define update_version.h
  161. ($(call make_version.h, $@.tmp); \
  162. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  163. rm -f $@.tmp; \
  164. else \
  165. echo ' UPDATE $@'; \
  166. mv -f $@.tmp $@; \
  167. fi);
  168. endef
  169. ep_version.h: force
  170. $(Q)$(N)$(call update_version.h)
  171. VERSION_FILES = ep_version.h
  172. define update_dir
  173. (echo $1 > $@.tmp; \
  174. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  175. rm -f $@.tmp; \
  176. else \
  177. echo ' UPDATE $@'; \
  178. mv -f $@.tmp $@; \
  179. fi);
  180. endef
  181. tags: force
  182. $(RM) tags
  183. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  184. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
  185. TAGS: force
  186. $(RM) TAGS
  187. find . -name '*.[ch]' | xargs etags \
  188. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
  189. define do_install_mkdir
  190. if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
  191. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
  192. fi
  193. endef
  194. define do_install
  195. $(call do_install_mkdir,$2); \
  196. $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
  197. endef
  198. define do_install_plugins
  199. for plugin in $1; do \
  200. $(call do_install,$$plugin,$(plugin_dir_SQ)); \
  201. done
  202. endef
  203. define do_generate_dynamic_list_file
  204. (echo '{'; \
  205. $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u; \
  206. echo '};'; \
  207. ) > $2
  208. endef
  209. install_lib: all_cmd install_plugins
  210. $(call QUIET_INSTALL, $(LIB_TARGET)) \
  211. $(call do_install_mkdir,$(libdir_SQ)); \
  212. cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
  213. install_plugins: $(PLUGINS)
  214. $(call QUIET_INSTALL, trace_plugins) \
  215. $(call do_install_plugins, $(PLUGINS))
  216. install_headers:
  217. $(call QUIET_INSTALL, headers) \
  218. $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \
  219. $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \
  220. $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644)
  221. install: install_lib
  222. clean:
  223. $(call QUIET_CLEAN, libtraceevent) \
  224. $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
  225. $(RM) TRACEEVENT-CFLAGS tags TAGS
  226. PHONY += force plugins
  227. force:
  228. # Declare the contents of the .PHONY variable as phony. We keep that
  229. # information in a variable so we can use it in if_changed and friends.
  230. .PHONY: $(PHONY)