Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# SPDX-License-Identifier: GPL-2.0
2# trace-cmd version
3EP_VERSION = 1
4EP_PATCHLEVEL = 1
5EP_EXTRAVERSION = 0
6
7# file format version
8FILE_VERSION = 6
9
10MAKEFLAGS += --no-print-directory
11
12
13# Makefiles suck: This macro sets a default value of $(2) for the
14# variable named by $(1), unless the variable has been set by
15# environment or command line. This is necessary for CC and AR
16# because make sets default values, so the simpler ?= approach
17# won't work as expected.
18define allow-override
19 $(if $(or $(findstring environment,$(origin $(1))),\
20 $(findstring command line,$(origin $(1)))),,\
21 $(eval $(1) = $(2)))
22endef
23
24# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
25$(call allow-override,CC,$(CROSS_COMPILE)gcc)
26$(call allow-override,AR,$(CROSS_COMPILE)ar)
27$(call allow-override,NM,$(CROSS_COMPILE)nm)
28$(call allow-override,PKG_CONFIG,pkg-config)
29
30EXT = -std=gnu99
31INSTALL = install
32
33# Use DESTDIR for installing into a different root directory.
34# This is useful for building a package. The program will be
35# installed in this directory as if it was the root directory.
36# Then the build tool can move it later.
37DESTDIR ?=
38DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
39
40LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
41ifeq ($(LP64), 1)
42 libdir_relative = lib64
43else
44 libdir_relative = lib
45endif
46
47prefix ?= /usr/local
48libdir = $(prefix)/$(libdir_relative)
49man_dir = $(prefix)/share/man
50man_dir_SQ = '$(subst ','\'',$(man_dir))'
51pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \
52 --variable pc_path pkg-config | tr ":" " "))
53includedir_relative = traceevent
54includedir = $(prefix)/include/$(includedir_relative)
55includedir_SQ = '$(subst ','\'',$(includedir))'
56
57export man_dir man_dir_SQ INSTALL
58export DESTDIR DESTDIR_SQ
59export EVENT_PARSE_VERSION
60
61set_plugin_dir := 1
62
63# Set plugin_dir to preffered global plugin location
64# If we install under $HOME directory we go under
65# $(HOME)/.traceevent/plugins
66#
67# We dont set PLUGIN_DIR in case we install under $HOME
68# directory, because by default the code looks under:
69# $(HOME)/.traceevent/plugins by default.
70#
71ifeq ($(plugin_dir),)
72ifeq ($(prefix),$(HOME))
73override plugin_dir = $(HOME)/.traceevent/plugins
74set_plugin_dir := 0
75else
76override plugin_dir = $(libdir)/traceevent/plugins
77endif
78endif
79
80ifeq ($(set_plugin_dir),1)
81PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
82PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
83endif
84
85include ../../scripts/Makefile.include
86
87# copy a bit from Linux kbuild
88
89ifeq ("$(origin V)", "command line")
90 VERBOSE = $(V)
91endif
92ifndef VERBOSE
93 VERBOSE = 0
94endif
95
96ifeq ($(srctree),)
97srctree := $(patsubst %/,%,$(dir $(CURDIR)))
98srctree := $(patsubst %/,%,$(dir $(srctree)))
99srctree := $(patsubst %/,%,$(dir $(srctree)))
100#$(info Determined 'srctree' to be $(srctree))
101endif
102
103export prefix libdir src obj
104
105# Shell quotes
106libdir_SQ = $(subst ','\'',$(libdir))
107libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
108plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
109
110CONFIG_INCLUDES =
111CONFIG_LIBS =
112CONFIG_FLAGS =
113
114VERSION = $(EP_VERSION)
115PATCHLEVEL = $(EP_PATCHLEVEL)
116EXTRAVERSION = $(EP_EXTRAVERSION)
117
118OBJ = $@
119N =
120
121EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
122
123LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
124LIB_INSTALL = libtraceevent.a libtraceevent.so*
125
126INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
127
128# Set compile option CFLAGS
129ifdef EXTRA_CFLAGS
130 CFLAGS := $(EXTRA_CFLAGS)
131else
132 CFLAGS := -g -Wall
133endif
134
135# Append required CFLAGS
136override CFLAGS += -fPIC
137override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
138override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
139
140ifeq ($(VERBOSE),1)
141 Q =
142else
143 Q = @
144endif
145
146# Disable command line variables (CFLAGS) override from top
147# level Makefile (perf), otherwise build Makefile will get
148# the same command line setup.
149MAKEOVERRIDES=
150
151export srctree OUTPUT CC LD CFLAGS V
152build := -f $(srctree)/tools/build/Makefile.build dir=. obj
153
154PLUGINS = plugin_jbd2.so
155PLUGINS += plugin_hrtimer.so
156PLUGINS += plugin_kmem.so
157PLUGINS += plugin_kvm.so
158PLUGINS += plugin_mac80211.so
159PLUGINS += plugin_sched_switch.so
160PLUGINS += plugin_function.so
161PLUGINS += plugin_xen.so
162PLUGINS += plugin_scsi.so
163PLUGINS += plugin_cfg80211.so
164
165PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
166PLUGINS_IN := $(PLUGINS:.so=-in.o)
167
168TE_IN := $(OUTPUT)libtraceevent-in.o
169LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
170DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
171
172CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE)
173
174TARGETS = $(CMD_TARGETS)
175
176all: all_cmd
177
178all_cmd: $(CMD_TARGETS)
179
180$(TE_IN): force
181 $(Q)$(MAKE) $(build)=libtraceevent
182
183$(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
184 $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
185 @ln -sf $(@F) $(OUTPUT)libtraceevent.so
186 @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
187
188$(OUTPUT)libtraceevent.a: $(TE_IN)
189 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
190
191$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
192 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
193
194plugins: $(PLUGINS)
195
196__plugin_obj = $(notdir $@)
197 plugin_obj = $(__plugin_obj:-in.o=)
198
199$(PLUGINS_IN): force
200 $(Q)$(MAKE) $(build)=$(plugin_obj)
201
202$(OUTPUT)%.so: $(OUTPUT)%-in.o
203 $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
204
205define make_version.h
206 (echo '/* This file is automatically generated. Do not modify. */'; \
207 echo \#define VERSION_CODE $(shell \
208 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
209 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
210 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
211 echo '#define FILE_VERSION '$(FILE_VERSION); \
212 ) > $1
213endef
214
215define update_version.h
216 ($(call make_version.h, $@.tmp); \
217 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
218 rm -f $@.tmp; \
219 else \
220 echo ' UPDATE $@'; \
221 mv -f $@.tmp $@; \
222 fi);
223endef
224
225ep_version.h: force
226 $(Q)$(N)$(call update_version.h)
227
228VERSION_FILES = ep_version.h
229
230define update_dir
231 (echo $1 > $@.tmp; \
232 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
233 rm -f $@.tmp; \
234 else \
235 echo ' UPDATE $@'; \
236 mv -f $@.tmp $@; \
237 fi);
238endef
239
240tags: force
241 $(RM) tags
242 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
243 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
244
245TAGS: force
246 $(RM) TAGS
247 find . -name '*.[ch]' | xargs etags \
248 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
249
250define do_install_mkdir
251 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
252 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
253 fi
254endef
255
256define do_install
257 $(call do_install_mkdir,$2); \
258 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
259endef
260
261define do_install_plugins
262 for plugin in $1; do \
263 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
264 done
265endef
266
267define do_generate_dynamic_list_file
268 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
269 xargs echo "U W w" | tr ' ' '\n' | sort -u | xargs echo`;\
270 if [ "$$symbol_type" = "U W w" ];then \
271 (echo '{'; \
272 $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\
273 echo '};'; \
274 ) > $2; \
275 else \
276 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
277 fi
278endef
279
280PKG_CONFIG_FILE = libtraceevent.pc
281define do_install_pkgconfig_file
282 if [ -n "${pkgconfig_dir}" ]; then \
283 cp -f ${PKG_CONFIG_FILE}.template ${PKG_CONFIG_FILE}; \
284 sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \
285 sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \
286 sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \
287 sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \
288 $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \
289 else \
290 (echo Failed to locate pkg-config directory) 1>&2; \
291 fi
292endef
293
294install_lib: all_cmd install_plugins install_headers install_pkgconfig
295 $(call QUIET_INSTALL, $(LIB_TARGET)) \
296 $(call do_install_mkdir,$(libdir_SQ)); \
297 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
298
299install_plugins: $(PLUGINS)
300 $(call QUIET_INSTALL, trace_plugins) \
301 $(call do_install_plugins, $(PLUGINS))
302
303install_pkgconfig:
304 $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \
305 $(call do_install_pkgconfig_file,$(prefix))
306
307install_headers:
308 $(call QUIET_INSTALL, headers) \
309 $(call do_install,event-parse.h,$(DESTDIR)$(includedir_SQ),644); \
310 $(call do_install,event-utils.h,$(DESTDIR)$(includedir_SQ),644); \
311 $(call do_install,trace-seq.h,$(DESTDIR)$(includedir_SQ),644); \
312 $(call do_install,kbuffer.h,$(DESTDIR)$(includedir_SQ),644)
313
314install: install_lib
315
316clean:
317 $(call QUIET_CLEAN, libtraceevent) \
318 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
319 $(RM) TRACEEVENT-CFLAGS tags TAGS; \
320 $(RM) $(PKG_CONFIG_FILE)
321
322PHONY += doc
323doc:
324 $(call descend,Documentation)
325
326PHONY += doc-clean
327doc-clean:
328 $(call descend,Documentation,clean)
329
330PHONY += doc-install
331doc-install:
332 $(call descend,Documentation,install)
333
334PHONY += doc-uninstall
335doc-uninstall:
336 $(call descend,Documentation,uninstall)
337
338PHONY += help
339help:
340 @echo 'Possible targets:'
341 @echo''
342 @echo ' all - default, compile the library and the'\
343 'plugins'
344 @echo ' plugins - compile the plugins'
345 @echo ' install - install the library, the plugins,'\
346 'the header and pkgconfig files'
347 @echo ' clean - clean the library and the plugins object files'
348 @echo ' doc - compile the documentation files - man'\
349 'and html pages, in the Documentation directory'
350 @echo ' doc-clean - clean the documentation files'
351 @echo ' doc-install - install the man pages'
352 @echo ' doc-uninstall - uninstall the man pages'
353 @echo''
354PHONY += force plugins
355force:
356
357# Declare the contents of the .PHONY variable as phony. We keep that
358# information in a variable so we can use it in if_changed and friends.
359.PHONY: $(PHONY)