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
3#MAKEFLAGS += --no-print-directory
4
5
6# Makefiles suck: This macro sets a default value of $(2) for the
7# variable named by $(1), unless the variable has been set by
8# environment or command line. This is necessary for CC and AR
9# because make sets default values, so the simpler ?= approach
10# won't work as expected.
11define allow-override
12 $(if $(or $(findstring environment,$(origin $(1))),\
13 $(findstring command line,$(origin $(1)))),,\
14 $(eval $(1) = $(2)))
15endef
16
17# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
18$(call allow-override,CC,$(CROSS_COMPILE)gcc)
19$(call allow-override,AR,$(CROSS_COMPILE)ar)
20$(call allow-override,NM,$(CROSS_COMPILE)nm)
21$(call allow-override,PKG_CONFIG,pkg-config)
22
23EXT = -std=gnu99
24INSTALL = install
25
26# Use DESTDIR for installing into a different root directory.
27# This is useful for building a package. The program will be
28# installed in this directory as if it was the root directory.
29# Then the build tool can move it later.
30DESTDIR ?=
31DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
32
33LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
34ifeq ($(LP64), 1)
35 libdir_relative_tmp = lib64
36else
37 libdir_relative_tmp = lib
38endif
39
40libdir_relative ?= $(libdir_relative_tmp)
41prefix ?= /usr/local
42libdir = $(prefix)/$(libdir_relative)
43
44set_plugin_dir := 1
45
46# Set plugin_dir to preffered global plugin location
47# If we install under $HOME directory we go under
48# $(HOME)/.local/lib/traceevent/plugins
49#
50# We dont set PLUGIN_DIR in case we install under $HOME
51# directory, because by default the code looks under:
52# $(HOME)/.local/lib/traceevent/plugins by default.
53#
54ifeq ($(plugin_dir),)
55ifeq ($(prefix),$(HOME))
56override plugin_dir = $(HOME)/.local/lib/traceevent/plugins
57set_plugin_dir := 0
58else
59override plugin_dir = $(libdir)/traceevent/plugins
60endif
61endif
62
63ifeq ($(set_plugin_dir),1)
64PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
65PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
66endif
67
68include ../../../scripts/Makefile.include
69
70# copy a bit from Linux kbuild
71
72ifeq ("$(origin V)", "command line")
73 VERBOSE = $(V)
74endif
75ifndef VERBOSE
76 VERBOSE = 0
77endif
78
79ifeq ($(srctree),)
80srctree := $(patsubst %/,%,$(dir $(CURDIR)))
81srctree := $(patsubst %/,%,$(dir $(srctree)))
82srctree := $(patsubst %/,%,$(dir $(srctree)))
83srctree := $(patsubst %/,%,$(dir $(srctree)))
84#$(info Determined 'srctree' to be $(srctree))
85endif
86
87export prefix libdir src obj
88
89# Shell quotes
90plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
91
92CONFIG_INCLUDES =
93CONFIG_LIBS =
94CONFIG_FLAGS =
95
96OBJ = $@
97N =
98
99INCLUDES = -I. -I.. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
100
101# Set compile option CFLAGS
102ifdef EXTRA_CFLAGS
103 CFLAGS := $(EXTRA_CFLAGS)
104else
105 CFLAGS := -g -Wall
106endif
107
108# Append required CFLAGS
109override CFLAGS += -fPIC
110override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
111override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
112
113ifeq ($(VERBOSE),1)
114 Q =
115else
116 Q = @
117endif
118
119# Disable command line variables (CFLAGS) override from top
120# level Makefile (perf), otherwise build Makefile will get
121# the same command line setup.
122MAKEOVERRIDES=
123
124export srctree OUTPUT CC LD CFLAGS V
125
126build := -f $(srctree)/tools/build/Makefile.build dir=. obj
127
128DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
129
130PLUGINS = plugin_jbd2.so
131PLUGINS += plugin_hrtimer.so
132PLUGINS += plugin_kmem.so
133PLUGINS += plugin_kvm.so
134PLUGINS += plugin_mac80211.so
135PLUGINS += plugin_sched_switch.so
136PLUGINS += plugin_function.so
137PLUGINS += plugin_xen.so
138PLUGINS += plugin_scsi.so
139PLUGINS += plugin_cfg80211.so
140
141PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
142PLUGINS_IN := $(PLUGINS:.so=-in.o)
143
144plugins: $(PLUGINS) $(DYNAMIC_LIST_FILE)
145
146__plugin_obj = $(notdir $@)
147 plugin_obj = $(__plugin_obj:-in.o=)
148
149$(PLUGINS_IN): force
150 $(Q)$(MAKE) $(build)=$(plugin_obj)
151
152$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
153 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
154
155$(OUTPUT)%.so: $(OUTPUT)%-in.o
156 $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
157
158define update_dir
159 (echo $1 > $@.tmp; \
160 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
161 rm -f $@.tmp; \
162 else \
163 echo ' UPDATE $@'; \
164 mv -f $@.tmp $@; \
165 fi);
166endef
167
168tags: force
169 $(RM) tags
170 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
171 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
172
173TAGS: force
174 $(RM) TAGS
175 find . -name '*.[ch]' | xargs etags \
176 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
177
178define do_install_mkdir
179 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
180 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
181 fi
182endef
183
184define do_install
185 $(call do_install_mkdir,$2); \
186 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
187endef
188
189define do_install_plugins
190 for plugin in $1; do \
191 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
192 done
193endef
194
195define do_generate_dynamic_list_file
196 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
197 xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\
198 if [ "$$symbol_type" = "U W" ];then \
199 (echo '{'; \
200 $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\
201 echo '};'; \
202 ) > $2; \
203 else \
204 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
205 fi
206endef
207
208install: $(PLUGINS)
209 $(call QUIET_INSTALL, trace_plugins) \
210 $(call do_install_plugins, $(PLUGINS))
211
212clean:
213 $(call QUIET_CLEAN, trace_plugins) \
214 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
215 $(RM) $(OUTPUT)libtraceevent-dynamic-list \
216 $(RM) TRACEEVENT-CFLAGS tags TAGS;
217
218PHONY += force plugins
219force:
220
221# Declare the contents of the .PHONY variable as phony. We keep that
222# information in a variable so we can use it in if_changed and friends.
223.PHONY: $(PHONY)