0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 define allow-override
0012 $(if $(or $(findstring environment,$(origin $(1))),\
0013 $(findstring command line,$(origin $(1)))),,\
0014 $(eval $(1) = $(2)))
0015 endef
0016
0017
0018 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
0019 $(call allow-override,AR,$(CROSS_COMPILE)ar)
0020 $(call allow-override,NM,$(CROSS_COMPILE)nm)
0021 $(call allow-override,PKG_CONFIG,pkg-config)
0022
0023 EXT = -std=gnu99
0024 INSTALL = install
0025
0026
0027
0028
0029
0030 DESTDIR ?=
0031 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
0032
0033 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
0034 ifeq ($(LP64), 1)
0035 libdir_relative_tmp = lib64
0036 else
0037 libdir_relative_tmp = lib
0038 endif
0039
0040 libdir_relative ?= $(libdir_relative_tmp)
0041 prefix ?= /usr/local
0042 libdir = $(prefix)/$(libdir_relative)
0043
0044 set_plugin_dir := 1
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054 ifeq ($(plugin_dir),)
0055 ifeq ($(prefix),$(HOME))
0056 override plugin_dir = $(HOME)/.local/lib/traceevent/plugins
0057 set_plugin_dir := 0
0058 else
0059 override plugin_dir = $(libdir)/traceevent/plugins
0060 endif
0061 endif
0062
0063 ifeq ($(set_plugin_dir),1)
0064 PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
0065 PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
0066 endif
0067
0068 include ../../../scripts/Makefile.include
0069
0070
0071
0072 ifeq ("$(origin V)", "command line")
0073 VERBOSE = $(V)
0074 endif
0075 ifndef VERBOSE
0076 VERBOSE = 0
0077 endif
0078
0079 ifeq ($(srctree),)
0080 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
0081 srctree := $(patsubst %/,%,$(dir $(srctree)))
0082 srctree := $(patsubst %/,%,$(dir $(srctree)))
0083 srctree := $(patsubst %/,%,$(dir $(srctree)))
0084
0085 endif
0086
0087 export prefix libdir src obj
0088
0089
0090 plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
0091
0092 CONFIG_INCLUDES =
0093 CONFIG_LIBS =
0094 CONFIG_FLAGS =
0095
0096 OBJ = $@
0097 N =
0098
0099 INCLUDES = -I. -I.. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
0100
0101
0102 ifdef EXTRA_CFLAGS
0103 CFLAGS := $(EXTRA_CFLAGS)
0104 else
0105 CFLAGS := -g -Wall
0106 endif
0107
0108
0109 override CFLAGS += -fPIC
0110 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
0111 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
0112
0113 ifeq ($(VERBOSE),1)
0114 Q =
0115 else
0116 Q = @
0117 endif
0118
0119
0120
0121
0122 MAKEOVERRIDES=
0123
0124 export srctree OUTPUT CC LD CFLAGS V
0125
0126 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
0127
0128 DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
0129
0130 PLUGINS = plugin_jbd2.so
0131 PLUGINS += plugin_hrtimer.so
0132 PLUGINS += plugin_kmem.so
0133 PLUGINS += plugin_kvm.so
0134 PLUGINS += plugin_mac80211.so
0135 PLUGINS += plugin_sched_switch.so
0136 PLUGINS += plugin_function.so
0137 PLUGINS += plugin_futex.so
0138 PLUGINS += plugin_xen.so
0139 PLUGINS += plugin_scsi.so
0140 PLUGINS += plugin_cfg80211.so
0141 PLUGINS += plugin_tlb.so
0142
0143 PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
0144 PLUGINS_IN := $(PLUGINS:.so=-in.o)
0145
0146 plugins: $(PLUGINS) $(DYNAMIC_LIST_FILE)
0147
0148 __plugin_obj = $(notdir $@)
0149 plugin_obj = $(__plugin_obj:-in.o=)
0150
0151 $(PLUGINS_IN): force
0152 $(Q)$(MAKE) $(build)=$(plugin_obj)
0153
0154 $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
0155 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
0156
0157 $(OUTPUT)%.so: $(OUTPUT)%-in.o
0158 $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
0159
0160 define update_dir
0161 (echo $1 > $@.tmp; \
0162 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
0163 rm -f $@.tmp; \
0164 else \
0165 echo ' UPDATE $@'; \
0166 mv -f $@.tmp $@; \
0167 fi);
0168 endef
0169
0170 tags: force
0171 $(RM) tags
0172 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
0173 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
0174
0175 TAGS: force
0176 $(RM) TAGS
0177 find . -name '*.[ch]' | xargs etags \
0178 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
0179
0180 define do_install_mkdir
0181 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
0182 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
0183 fi
0184 endef
0185
0186 define do_install
0187 $(call do_install_mkdir,$2); \
0188 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
0189 endef
0190
0191 define do_install_plugins
0192 for plugin in $1; do \
0193 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
0194 done
0195 endef
0196
0197 define do_generate_dynamic_list_file
0198 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
0199 xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\
0200 if [ "$$symbol_type" = "U W" ];then \
0201 (echo '{'; \
0202 $(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\
0203 echo '};'; \
0204 ) > $2; \
0205 else \
0206 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
0207 fi
0208 endef
0209
0210 install: $(PLUGINS)
0211 $(call QUIET_INSTALL, trace_plugins) \
0212 $(call do_install_plugins, $(PLUGINS))
0213
0214 clean:
0215 $(call QUIET_CLEAN, trace_plugins) \
0216 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
0217 $(RM) $(OUTPUT)libtraceevent-dynamic-list \
0218 $(RM) TRACEEVENT-CFLAGS tags TAGS;
0219
0220 PHONY += force plugins
0221 force:
0222
0223
0224
0225 .PHONY: $(PHONY)