hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/tools/lib/traceevent/Makefile
....@@ -25,6 +25,7 @@
2525 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
2626 $(call allow-override,AR,$(CROSS_COMPILE)ar)
2727 $(call allow-override,NM,$(CROSS_COMPILE)nm)
28
+$(call allow-override,PKG_CONFIG,pkg-config)
2829
2930 EXT = -std=gnu99
3031 INSTALL = install
....@@ -38,42 +39,25 @@
3839
3940 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
4041 ifeq ($(LP64), 1)
41
- libdir_relative = lib64
42
+ libdir_relative_temp = lib64
4243 else
43
- libdir_relative = lib
44
+ libdir_relative_temp = lib
4445 endif
4546
47
+libdir_relative ?= $(libdir_relative_temp)
4648 prefix ?= /usr/local
4749 libdir = $(prefix)/$(libdir_relative)
4850 man_dir = $(prefix)/share/man
4951 man_dir_SQ = '$(subst ','\'',$(man_dir))'
52
+pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \
53
+ --variable pc_path pkg-config | tr ":" " "))
54
+includedir_relative = traceevent
55
+includedir = $(prefix)/include/$(includedir_relative)
56
+includedir_SQ = '$(subst ','\'',$(includedir))'
5057
5158 export man_dir man_dir_SQ INSTALL
5259 export DESTDIR DESTDIR_SQ
53
-
54
-set_plugin_dir := 1
55
-
56
-# Set plugin_dir to preffered global plugin location
57
-# If we install under $HOME directory we go under
58
-# $(HOME)/.local/lib/traceevent/plugins
59
-#
60
-# We dont set PLUGIN_DIR in case we install under $HOME
61
-# directory, because by default the code looks under:
62
-# $(HOME)/.local/lib/traceevent/plugins by default.
63
-#
64
-ifeq ($(plugin_dir),)
65
-ifeq ($(prefix),$(HOME))
66
-override plugin_dir = $(HOME)/.local/lib/traceevent/plugins
67
-set_plugin_dir := 0
68
-else
69
-override plugin_dir = $(libdir)/traceevent/plugins
70
-endif
71
-endif
72
-
73
-ifeq ($(set_plugin_dir),1)
74
-PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
75
-PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
76
-endif
60
+export EVENT_PARSE_VERSION
7761
7862 include ../../scripts/Makefile.include
7963
....@@ -98,7 +82,6 @@
9882 # Shell quotes
9983 libdir_SQ = $(subst ','\'',$(libdir))
10084 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
101
-plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
10285
10386 CONFIG_INCLUDES =
10487 CONFIG_LIBS =
....@@ -145,29 +128,14 @@
145128 export srctree OUTPUT CC LD CFLAGS V
146129 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
147130
148
-PLUGINS = plugin_jbd2.so
149
-PLUGINS += plugin_hrtimer.so
150
-PLUGINS += plugin_kmem.so
151
-PLUGINS += plugin_kvm.so
152
-PLUGINS += plugin_mac80211.so
153
-PLUGINS += plugin_sched_switch.so
154
-PLUGINS += plugin_function.so
155
-PLUGINS += plugin_xen.so
156
-PLUGINS += plugin_scsi.so
157
-PLUGINS += plugin_cfg80211.so
158
-
159
-PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
160
-PLUGINS_IN := $(PLUGINS:.so=-in.o)
161
-
162131 TE_IN := $(OUTPUT)libtraceevent-in.o
163132 LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
164
-DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
165133
166
-CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE)
134
+CMD_TARGETS = $(LIB_TARGET)
167135
168136 TARGETS = $(CMD_TARGETS)
169137
170
-all: all_cmd
138
+all: all_cmd plugins
171139
172140 all_cmd: $(CMD_TARGETS)
173141
....@@ -175,26 +143,15 @@
175143 $(Q)$(MAKE) $(build)=libtraceevent
176144
177145 $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
178
- $(QUIET_LINK)$(CC) --shared $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
146
+ $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
179147 @ln -sf $(@F) $(OUTPUT)libtraceevent.so
180148 @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
181149
182150 $(OUTPUT)libtraceevent.a: $(TE_IN)
183151 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
184152
185
-$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
186
- $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
187
-
188
-plugins: $(PLUGINS)
189
-
190
-__plugin_obj = $(notdir $@)
191
- plugin_obj = $(__plugin_obj:-in.o=)
192
-
193
-$(PLUGINS_IN): force
194
- $(Q)$(MAKE) $(build)=$(plugin_obj)
195
-
196153 $(OUTPUT)%.so: $(OUTPUT)%-in.o
197
- $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
154
+ $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
198155
199156 define make_version.h
200157 (echo '/* This file is automatically generated. Do not modify. */'; \
....@@ -252,48 +209,90 @@
252209 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
253210 endef
254211
255
-define do_install_plugins
256
- for plugin in $1; do \
257
- $(call do_install,$$plugin,$(plugin_dir_SQ)); \
258
- done
259
-endef
260
-
261
-define do_generate_dynamic_list_file
262
- symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
263
- xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\
264
- if [ "$$symbol_type" = "U W" ];then \
265
- (echo '{'; \
266
- $(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\
267
- echo '};'; \
268
- ) > $2; \
269
- else \
270
- (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
212
+PKG_CONFIG_SOURCE_FILE = libtraceevent.pc
213
+PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE))
214
+define do_install_pkgconfig_file
215
+ if [ -n "${pkgconfig_dir}" ]; then \
216
+ cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE}; \
217
+ sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \
218
+ sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \
219
+ sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \
220
+ sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \
221
+ $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \
222
+ else \
223
+ (echo Failed to locate pkg-config directory) 1>&2; \
271224 fi
272225 endef
273226
274
-install_lib: all_cmd install_plugins
227
+install_lib: all_cmd install_plugins install_headers install_pkgconfig
275228 $(call QUIET_INSTALL, $(LIB_TARGET)) \
276229 $(call do_install_mkdir,$(libdir_SQ)); \
277230 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
278231
279
-install_plugins: $(PLUGINS)
280
- $(call QUIET_INSTALL, trace_plugins) \
281
- $(call do_install_plugins, $(PLUGINS))
232
+install_pkgconfig:
233
+ $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \
234
+ $(call do_install_pkgconfig_file,$(prefix))
282235
283236 install_headers:
284237 $(call QUIET_INSTALL, headers) \
285
- $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \
286
- $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \
287
- $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644)
238
+ $(call do_install,event-parse.h,$(includedir_SQ),644); \
239
+ $(call do_install,event-utils.h,$(includedir_SQ),644); \
240
+ $(call do_install,trace-seq.h,$(includedir_SQ),644); \
241
+ $(call do_install,kbuffer.h,$(includedir_SQ),644)
288242
289243 install: install_lib
290244
291
-clean:
245
+clean: clean_plugins
292246 $(call QUIET_CLEAN, libtraceevent) \
293
- $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
294
- $(RM) TRACEEVENT-CFLAGS tags TAGS
247
+ $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
248
+ $(RM) TRACEEVENT-CFLAGS tags TAGS; \
249
+ $(RM) $(PKG_CONFIG_FILE)
295250
296
-PHONY += force plugins
251
+PHONY += doc
252
+doc:
253
+ $(call descend,Documentation)
254
+
255
+PHONY += doc-clean
256
+doc-clean:
257
+ $(call descend,Documentation,clean)
258
+
259
+PHONY += doc-install
260
+doc-install:
261
+ $(call descend,Documentation,install)
262
+
263
+PHONY += doc-uninstall
264
+doc-uninstall:
265
+ $(call descend,Documentation,uninstall)
266
+
267
+PHONY += help
268
+help:
269
+ @echo 'Possible targets:'
270
+ @echo''
271
+ @echo ' all - default, compile the library and the'\
272
+ 'plugins'
273
+ @echo ' plugins - compile the plugins'
274
+ @echo ' install - install the library, the plugins,'\
275
+ 'the header and pkgconfig files'
276
+ @echo ' clean - clean the library and the plugins object files'
277
+ @echo ' doc - compile the documentation files - man'\
278
+ 'and html pages, in the Documentation directory'
279
+ @echo ' doc-clean - clean the documentation files'
280
+ @echo ' doc-install - install the man pages'
281
+ @echo ' doc-uninstall - uninstall the man pages'
282
+ @echo''
283
+
284
+PHONY += plugins
285
+plugins:
286
+ $(call descend,plugins)
287
+
288
+PHONY += install_plugins
289
+install_plugins:
290
+ $(call descend,plugins,install)
291
+
292
+PHONY += clean_plugins
293
+clean_plugins:
294
+ $(call descend,plugins,clean)
295
+
297296 force:
298297
299298 # Declare the contents of the .PHONY variable as phony. We keep that