blob: 46cd5f871ad76d48bc7a34f725a31fa12ed5614c [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Steven Rostedtf7d82352012-04-06 00:47:53 +02002# 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)
He Kuange3d09ec2015-05-28 13:28:54 +000027$(call allow-override,NM,$(CROSS_COMPILE)nm)
Steven Rostedtf7d82352012-04-06 00:47:53 +020028
29EXT = -std=gnu99
30INSTALL = install
31
32# Use DESTDIR for installing into a different root directory.
33# This is useful for building a package. The program will be
34# installed in this directory as if it was the root directory.
35# Then the build tool can move it later.
36DESTDIR ?=
37DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
38
Wang Nanbb53e172015-05-17 10:56:28 +000039LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
40ifeq ($(LP64), 1)
41 libdir_relative = lib64
42else
43 libdir_relative = lib
44endif
45
Steven Rostedtf7d82352012-04-06 00:47:53 +020046prefix ?= /usr/local
Wang Nanbb53e172015-05-17 10:56:28 +000047libdir = $(prefix)/$(libdir_relative)
Steven Rostedtf7d82352012-04-06 00:47:53 +020048man_dir = $(prefix)/share/man
49man_dir_SQ = '$(subst ','\'',$(man_dir))'
Steven Rostedtf7d82352012-04-06 00:47:53 +020050
Namhyung Kim9f1efa82013-06-04 14:20:16 +090051export man_dir man_dir_SQ INSTALL
Steven Rostedtf7d82352012-04-06 00:47:53 +020052export DESTDIR DESTDIR_SQ
53
Jiri Olsae0e96d02013-12-03 14:09:17 +010054set_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)/.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)/.traceevent/plugins by default.
63#
64ifeq ($(plugin_dir),)
65ifeq ($(prefix),$(HOME))
66override plugin_dir = $(HOME)/.traceevent/plugins
67set_plugin_dir := 0
68else
Wang Nanbb53e172015-05-17 10:56:28 +000069override plugin_dir = $(libdir)/traceevent/plugins
Jiri Olsae0e96d02013-12-03 14:09:17 +010070endif
71endif
72
73ifeq ($(set_plugin_dir),1)
Josh Boyerb935a582014-01-22 10:01:48 -050074PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
Jiri Olsae0e96d02013-12-03 14:09:17 +010075PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
76endif
77
Jiri Olsa2d58ab92015-01-07 18:39:45 +010078include ../../scripts/Makefile.include
Jiri Olsac3d090f2013-12-19 14:42:02 +010079
Steven Rostedtf7d82352012-04-06 00:47:53 +020080# copy a bit from Linux kbuild
81
82ifeq ("$(origin V)", "command line")
83 VERBOSE = $(V)
84endif
85ifndef VERBOSE
86 VERBOSE = 0
87endif
88
Jiri Olsa2d58ab92015-01-07 18:39:45 +010089ifeq ($(srctree),)
Uwe Kleine-Könige19b7ce2016-11-22 09:30:26 +010090srctree := $(patsubst %/,%,$(dir $(CURDIR)))
Jiri Olsa2d58ab92015-01-07 18:39:45 +010091srctree := $(patsubst %/,%,$(dir $(srctree)))
92srctree := $(patsubst %/,%,$(dir $(srctree)))
93#$(info Determined 'srctree' to be $(srctree))
Steven Rostedtf7d82352012-04-06 00:47:53 +020094endif
95
Wang Nanbb53e172015-05-17 10:56:28 +000096export prefix libdir src obj
Steven Rostedtf7d82352012-04-06 00:47:53 +020097
98# Shell quotes
Wang Nanbb53e172015-05-17 10:56:28 +000099libdir_SQ = $(subst ','\'',$(libdir))
100libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100101plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
Steven Rostedtf7d82352012-04-06 00:47:53 +0200102
Steven Rostedtf7d82352012-04-06 00:47:53 +0200103CONFIG_INCLUDES =
104CONFIG_LIBS =
105CONFIG_FLAGS =
106
107VERSION = $(EP_VERSION)
108PATCHLEVEL = $(EP_PATCHLEVEL)
109EXTRAVERSION = $(EP_EXTRAVERSION)
110
111OBJ = $@
112N =
113
Steven Rostedtf7d82352012-04-06 00:47:53 +0200114EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
115
Jiri Olsafe316722016-07-31 16:52:34 +0200116LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
117LIB_INSTALL = libtraceevent.a libtraceevent.so*
118
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100119INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200120
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100121# Set compile option CFLAGS
122ifdef EXTRA_CFLAGS
123 CFLAGS := $(EXTRA_CFLAGS)
124else
125 CFLAGS := -g -Wall
126endif
Steven Rostedtf7d82352012-04-06 00:47:53 +0200127
128# Append required CFLAGS
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100129override CFLAGS += -fPIC
Steven Rostedtf7d82352012-04-06 00:47:53 +0200130override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
Arnaldo Carvalho de Meloc055875b72012-09-12 14:29:40 -0300131override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
Steven Rostedtf7d82352012-04-06 00:47:53 +0200132
133ifeq ($(VERBOSE),1)
134 Q =
Steven Rostedtf7d82352012-04-06 00:47:53 +0200135else
136 Q = @
Steven Rostedtf7d82352012-04-06 00:47:53 +0200137endif
138
Masahiro Yamada505d3082017-03-09 16:16:33 -0800139# Disable command line variables (CFLAGS) override from top
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100140# level Makefile (perf), otherwise build Makefile will get
141# the same command line setup.
142MAKEOVERRIDES=
Steven Rostedtf7d82352012-04-06 00:47:53 +0200143
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100144export srctree OUTPUT CC LD CFLAGS V
145build := -f $(srctree)/tools/build/Makefile.build dir=. obj
Steven Rostedtf7d82352012-04-06 00:47:53 +0200146
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100147PLUGINS = plugin_jbd2.so
148PLUGINS += plugin_hrtimer.so
149PLUGINS += plugin_kmem.so
150PLUGINS += plugin_kvm.so
151PLUGINS += plugin_mac80211.so
152PLUGINS += plugin_sched_switch.so
153PLUGINS += plugin_function.so
154PLUGINS += plugin_xen.so
155PLUGINS += plugin_scsi.so
156PLUGINS += plugin_cfg80211.so
Steven Rostedtf7d82352012-04-06 00:47:53 +0200157
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100158PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
159PLUGINS_IN := $(PLUGINS:.so=-in.o)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200160
Jiri Olsa39944a72016-08-01 09:55:51 +0200161TE_IN := $(OUTPUT)libtraceevent-in.o
162LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
He Kuange3d09ec2015-05-28 13:28:54 +0000163DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
Jiri Olsae0e96d02013-12-03 14:09:17 +0100164
Jiri Olsa39944a72016-08-01 09:55:51 +0200165CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200166
167TARGETS = $(CMD_TARGETS)
168
Steven Rostedtf7d82352012-04-06 00:47:53 +0200169all: all_cmd
170
171all_cmd: $(CMD_TARGETS)
172
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100173$(TE_IN): force
174 $(Q)$(MAKE) $(build)=libtraceevent
175
Jiri Olsafe316722016-07-31 16:52:34 +0200176$(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
177 $(QUIET_LINK)$(CC) --shared $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
178 @ln -sf $(@F) $(OUTPUT)libtraceevent.so
179 @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200180
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100181$(OUTPUT)libtraceevent.a: $(TE_IN)
Jiri Olsae6262e22013-12-19 14:42:04 +0100182 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
Steven Rostedtf7d82352012-04-06 00:47:53 +0200183
He Kuange3d09ec2015-05-28 13:28:54 +0000184$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
185 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
186
Jiri Olsae0e96d02013-12-03 14:09:17 +0100187plugins: $(PLUGINS)
188
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100189__plugin_obj = $(notdir $@)
190 plugin_obj = $(__plugin_obj:-in.o=)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200191
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100192$(PLUGINS_IN): force
193 $(Q)$(MAKE) $(build)=$(plugin_obj)
Jiri Olsae0e96d02013-12-03 14:09:17 +0100194
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100195$(OUTPUT)%.so: $(OUTPUT)%-in.o
196 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
Jiri Olsae0e96d02013-12-03 14:09:17 +0100197
Steven Rostedtf7d82352012-04-06 00:47:53 +0200198define make_version.h
Jiri Olsa198430b2014-01-02 10:53:04 +0100199 (echo '/* This file is automatically generated. Do not modify. */'; \
200 echo \#define VERSION_CODE $(shell \
201 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
202 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
203 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
204 echo '#define FILE_VERSION '$(FILE_VERSION); \
205 ) > $1
Steven Rostedtf7d82352012-04-06 00:47:53 +0200206endef
207
208define update_version.h
Jiri Olsa198430b2014-01-02 10:53:04 +0100209 ($(call make_version.h, $@.tmp); \
210 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
211 rm -f $@.tmp; \
212 else \
213 echo ' UPDATE $@'; \
214 mv -f $@.tmp $@; \
215 fi);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200216endef
217
218ep_version.h: force
219 $(Q)$(N)$(call update_version.h)
220
221VERSION_FILES = ep_version.h
222
223define update_dir
Jiri Olsa198430b2014-01-02 10:53:04 +0100224 (echo $1 > $@.tmp; \
225 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
226 rm -f $@.tmp; \
227 else \
228 echo ' UPDATE $@'; \
229 mv -f $@.tmp $@; \
230 fi);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200231endef
232
Steven Rostedtf7d82352012-04-06 00:47:53 +0200233tags: force
234 $(RM) tags
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900235 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
236 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200237
238TAGS: force
239 $(RM) TAGS
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900240 find . -name '*.[ch]' | xargs etags \
241 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200242
Jiri Olsac121bdb2016-07-31 16:49:33 +0200243define do_install_mkdir
244 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
245 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
246 fi
247endef
248
Steven Rostedtf7d82352012-04-06 00:47:53 +0200249define do_install
Jiri Olsac121bdb2016-07-31 16:49:33 +0200250 $(call do_install_mkdir,$2); \
Jiri Olsa722a4982016-07-16 18:57:51 +0200251 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200252endef
253
Jiri Olsa02a82c72013-12-19 14:42:05 +0100254define do_install_plugins
255 for plugin in $1; do \
256 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
257 done
258endef
259
He Kuange3d09ec2015-05-28 13:28:54 +0000260define do_generate_dynamic_list_file
David Carrillo-Cisneros64677532017-02-07 21:28:40 -0800261 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
262 xargs echo "U W w" | tr ' ' '\n' | sort -u | xargs echo`;\
263 if [ "$$symbol_type" = "U W w" ];then \
264 (echo '{'; \
265 $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\
266 echo '};'; \
267 ) > $2; \
268 else \
269 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
270 fi
He Kuange3d09ec2015-05-28 13:28:54 +0000271endef
272
Jiri Olsae0e96d02013-12-03 14:09:17 +0100273install_lib: all_cmd install_plugins
Jiri Olsa39944a72016-08-01 09:55:51 +0200274 $(call QUIET_INSTALL, $(LIB_TARGET)) \
Jiri Olsafe316722016-07-31 16:52:34 +0200275 $(call do_install_mkdir,$(libdir_SQ)); \
276 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200277
Jiri Olsa02a82c72013-12-19 14:42:05 +0100278install_plugins: $(PLUGINS)
279 $(call QUIET_INSTALL, trace_plugins) \
280 $(call do_install_plugins, $(PLUGINS))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100281
Jiri Olsa722a4982016-07-16 18:57:51 +0200282install_headers:
283 $(call QUIET_INSTALL, headers) \
284 $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \
285 $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \
286 $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644)
287
Steven Rostedtf7d82352012-04-06 00:47:53 +0200288install: install_lib
289
290clean:
Jiri Olsa4a953c72013-12-19 14:42:06 +0100291 $(call QUIET_CLEAN, libtraceevent) \
Riku Voipioc867b152015-06-18 15:52:18 +0300292 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
Jiri Olsa4a953c72013-12-19 14:42:06 +0100293 $(RM) TRACEEVENT-CFLAGS tags TAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200294
Jiri Olsa9bb8e5e2014-01-01 17:50:50 +0100295PHONY += force plugins
Steven Rostedtf7d82352012-04-06 00:47:53 +0200296force:
297
Steven Rostedtf7d82352012-04-06 00:47:53 +0200298# Declare the contents of the .PHONY variable as phony. We keep that
299# information in a variable so we can use it in if_changed and friends.
300.PHONY: $(PHONY)