Makefile 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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 ../../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 ($(srctree),)
  66. srctree := $(patsubst %/,%,$(dir $(shell pwd)))
  67. srctree := $(patsubst %/,%,$(dir $(srctree)))
  68. srctree := $(patsubst %/,%,$(dir $(srctree)))
  69. #$(info Determined 'srctree' to be $(srctree))
  70. endif
  71. export prefix bindir src obj
  72. # Shell quotes
  73. bindir_SQ = $(subst ','\'',$(bindir))
  74. bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
  75. plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
  76. LIB_FILE = libtraceevent.a libtraceevent.so
  77. CONFIG_INCLUDES =
  78. CONFIG_LIBS =
  79. CONFIG_FLAGS =
  80. VERSION = $(EP_VERSION)
  81. PATCHLEVEL = $(EP_PATCHLEVEL)
  82. EXTRAVERSION = $(EP_EXTRAVERSION)
  83. OBJ = $@
  84. N =
  85. EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
  86. INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
  87. # Set compile option CFLAGS
  88. ifdef EXTRA_CFLAGS
  89. CFLAGS := $(EXTRA_CFLAGS)
  90. else
  91. CFLAGS := -g -Wall
  92. endif
  93. # Append required CFLAGS
  94. override CFLAGS += -fPIC
  95. override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
  96. override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
  97. ifeq ($(VERBOSE),1)
  98. Q =
  99. else
  100. Q = @
  101. endif
  102. # Disable command line variables (CFLAGS) overide from top
  103. # level Makefile (perf), otherwise build Makefile will get
  104. # the same command line setup.
  105. MAKEOVERRIDES=
  106. export srctree OUTPUT CC LD CFLAGS V
  107. build := -f $(srctree)/tools/build/Makefile.build dir=. obj
  108. PLUGINS = plugin_jbd2.so
  109. PLUGINS += plugin_hrtimer.so
  110. PLUGINS += plugin_kmem.so
  111. PLUGINS += plugin_kvm.so
  112. PLUGINS += plugin_mac80211.so
  113. PLUGINS += plugin_sched_switch.so
  114. PLUGINS += plugin_function.so
  115. PLUGINS += plugin_xen.so
  116. PLUGINS += plugin_scsi.so
  117. PLUGINS += plugin_cfg80211.so
  118. PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
  119. PLUGINS_IN := $(PLUGINS:.so=-in.o)
  120. TE_IN := $(OUTPUT)libtraceevent-in.o
  121. LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
  122. CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
  123. TARGETS = $(CMD_TARGETS)
  124. all: all_cmd
  125. all_cmd: $(CMD_TARGETS)
  126. $(TE_IN): force
  127. $(Q)$(MAKE) $(build)=libtraceevent
  128. $(OUTPUT)libtraceevent.so: $(TE_IN)
  129. $(QUIET_LINK)$(CC) --shared $^ -o $@
  130. $(OUTPUT)libtraceevent.a: $(TE_IN)
  131. $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
  132. plugins: $(PLUGINS)
  133. __plugin_obj = $(notdir $@)
  134. plugin_obj = $(__plugin_obj:-in.o=)
  135. $(PLUGINS_IN): force
  136. $(Q)$(MAKE) $(build)=$(plugin_obj)
  137. $(OUTPUT)%.so: $(OUTPUT)%-in.o
  138. $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
  139. define make_version.h
  140. (echo '/* This file is automatically generated. Do not modify. */'; \
  141. echo \#define VERSION_CODE $(shell \
  142. expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
  143. echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
  144. echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
  145. echo '#define FILE_VERSION '$(FILE_VERSION); \
  146. ) > $1
  147. endef
  148. define update_version.h
  149. ($(call make_version.h, $@.tmp); \
  150. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  151. rm -f $@.tmp; \
  152. else \
  153. echo ' UPDATE $@'; \
  154. mv -f $@.tmp $@; \
  155. fi);
  156. endef
  157. ep_version.h: force
  158. $(Q)$(N)$(call update_version.h)
  159. VERSION_FILES = ep_version.h
  160. define update_dir
  161. (echo $1 > $@.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. tags: force
  170. $(RM) tags
  171. find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
  172. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
  173. TAGS: force
  174. $(RM) TAGS
  175. find . -name '*.[ch]' | xargs etags \
  176. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
  177. define do_install
  178. if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
  179. $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
  180. fi; \
  181. $(INSTALL) $1 '$(DESTDIR_SQ)$2'
  182. endef
  183. define do_install_plugins
  184. for plugin in $1; do \
  185. $(call do_install,$$plugin,$(plugin_dir_SQ)); \
  186. done
  187. endef
  188. install_lib: all_cmd install_plugins
  189. $(call QUIET_INSTALL, $(LIB_FILE)) \
  190. $(call do_install,$(LIB_FILE),$(bindir_SQ))
  191. install_plugins: $(PLUGINS)
  192. $(call QUIET_INSTALL, trace_plugins) \
  193. $(call do_install_plugins, $(PLUGINS))
  194. install: install_lib
  195. clean:
  196. $(call QUIET_CLEAN, libtraceevent) \
  197. $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
  198. $(RM) TRACEEVENT-CFLAGS tags TAGS
  199. PHONY += force plugins
  200. force:
  201. # Declare the contents of the .PHONY variable as phony. We keep that
  202. # information in a variable so we can use it in if_changed and friends.
  203. .PHONY: $(PHONY)