1 # SPDX-License-Identifier: GPL-2.0
3 #MAKEFLAGS += --no-print-directory
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.
12 $(if
$(or
$(findstring environment
,$(origin $(1))),\
13 $(findstring command line
,$(origin $(1)))),,\
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
)
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.
31 DESTDIR_SQ
= '$(subst ','\'',$(DESTDIR
))'
33 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
35 libdir_relative_tmp = lib64
37 libdir_relative_tmp = lib
40 libdir_relative ?= $(libdir_relative_tmp)
42 libdir = $(prefix)/$(libdir_relative)
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
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.
55 ifeq ($(prefix),$(HOME))
56 override plugin_dir = $(HOME)/.local/lib/traceevent/plugins
59 override plugin_dir = $(libdir)/traceevent/plugins
63 ifeq ($(set_plugin_dir),1)
64 PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
65 PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68 include ..
/..
/..
/scripts
/Makefile.
include
70 # copy a bit from Linux kbuild
72 ifeq ("$(origin V)", "command line")
80 srctree
:= $(patsubst %/,%,$(dir $(CURDIR
)))
81 srctree
:= $(patsubst %/,%,$(dir $(srctree
)))
82 srctree
:= $(patsubst %/,%,$(dir $(srctree
)))
83 srctree
:= $(patsubst %/,%,$(dir $(srctree
)))
84 #$(info Determined 'srctree' to be $(srctree))
87 export prefix libdir src obj
90 plugin_dir_SQ
= $(subst ','\'',$(plugin_dir))
99 INCLUDES = -I. -I.. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
101 # Set compile option CFLAGS
103 CFLAGS := $(EXTRA_CFLAGS)
108 # Append required CFLAGS
109 override CFLAGS += -fPIC
110 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
111 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
119 # Disable command line variables (CFLAGS) override from top
120 # level Makefile (perf), otherwise build Makefile will get
121 # the same command line setup.
124 export srctree OUTPUT CC LD CFLAGS V
126 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
128 DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
130 PLUGINS = plugin_jbd2.so
131 PLUGINS += plugin_hrtimer.so
132 PLUGINS += plugin_kmem.so
133 PLUGINS += plugin_kvm.so
134 PLUGINS += plugin_mac80211.so
135 PLUGINS += plugin_sched_switch.so
136 PLUGINS += plugin_function.so
137 PLUGINS += plugin_xen.so
138 PLUGINS += plugin_scsi.so
139 PLUGINS += plugin_cfg80211.so
141 PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
142 PLUGINS_IN := $(PLUGINS:.so=-in.o)
144 plugins: $(PLUGINS) $(DYNAMIC_LIST_FILE)
146 __plugin_obj = $(notdir $@)
147 plugin_obj = $(__plugin_obj:-in.o=)
150 $(Q)$(MAKE) $(build)=$(plugin_obj)
152 $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
153 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
155 $(OUTPUT)%.so: $(OUTPUT)%-in.o
156 $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
160 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
170 find . -name '*.
[ch
]' | xargs ctags --extra=+f --c-kinds=+px \
171 --regex-c++='/_PE\
(([^
,)]*).
*/TEP_ERRNO__\
1/'
175 find . -name '*.
[ch
]' | xargs etags \
176 --regex='/_PE
(\
([^
,)]*\
).
*/TEP_ERRNO__\
1/'
178 define do_install_mkdir
179 if [ ! -d '$(DESTDIR_SQ
)$1' ]; then \
180 $(INSTALL) -d -m 755 '$(DESTDIR_SQ
)$1'; \
185 $(call do_install_mkdir,$2); \
186 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ
)$2'
189 define do_install_plugins
190 for plugin in $1; do \
191 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
195 define 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 \
200 $(NM) -u -D $1 | awk 'NF
>1 {print "\t"$$2";"}' | sort -u;\
204 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
209 $(call QUIET_INSTALL, trace_plugins) \
210 $(call do_install_plugins, $(PLUGINS))
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;
218 PHONY += force plugins
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.