blob: cc3315da6dc397d6ef672089ce6a34577e1957b1 [file] [log] [blame]
Steven Rostedtf7d82352012-04-06 00:47:53 +02001# trace-cmd version
2EP_VERSION = 1
3EP_PATCHLEVEL = 1
4EP_EXTRAVERSION = 0
5
6# file format version
7FILE_VERSION = 6
8
9MAKEFLAGS += --no-print-directory
10
11
12# Makefiles suck: This macro sets a default value of $(2) for the
13# variable named by $(1), unless the variable has been set by
14# environment or command line. This is necessary for CC and AR
15# because make sets default values, so the simpler ?= approach
16# won't work as expected.
17define allow-override
18 $(if $(or $(findstring environment,$(origin $(1))),\
19 $(findstring command line,$(origin $(1)))),,\
20 $(eval $(1) = $(2)))
21endef
22
23# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
24$(call allow-override,CC,$(CROSS_COMPILE)gcc)
25$(call allow-override,AR,$(CROSS_COMPILE)ar)
He Kuange3d09ec2015-05-28 13:28:54 +000026$(call allow-override,NM,$(CROSS_COMPILE)nm)
Steven Rostedtf7d82352012-04-06 00:47:53 +020027
28EXT = -std=gnu99
29INSTALL = install
30
31# Use DESTDIR for installing into a different root directory.
32# This is useful for building a package. The program will be
33# installed in this directory as if it was the root directory.
34# Then the build tool can move it later.
35DESTDIR ?=
36DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
37
Wang Nanbb53e172015-05-17 10:56:28 +000038LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
39ifeq ($(LP64), 1)
40 libdir_relative = lib64
41else
42 libdir_relative = lib
43endif
44
Steven Rostedtf7d82352012-04-06 00:47:53 +020045prefix ?= /usr/local
Wang Nanbb53e172015-05-17 10:56:28 +000046libdir = $(prefix)/$(libdir_relative)
Steven Rostedtf7d82352012-04-06 00:47:53 +020047man_dir = $(prefix)/share/man
48man_dir_SQ = '$(subst ','\'',$(man_dir))'
Steven Rostedtf7d82352012-04-06 00:47:53 +020049
Namhyung Kim9f1efa82013-06-04 14:20:16 +090050export man_dir man_dir_SQ INSTALL
Steven Rostedtf7d82352012-04-06 00:47:53 +020051export DESTDIR DESTDIR_SQ
52
Jiri Olsae0e96d02013-12-03 14:09:17 +010053set_plugin_dir := 1
54
55# Set plugin_dir to preffered global plugin location
56# If we install under $HOME directory we go under
Tzvetomir Stoyanov3caefd02019-08-05 16:43:15 -040057# $(HOME)/.local/lib/traceevent/plugins
Jiri Olsae0e96d02013-12-03 14:09:17 +010058#
59# We dont set PLUGIN_DIR in case we install under $HOME
60# directory, because by default the code looks under:
Tzvetomir Stoyanov3caefd02019-08-05 16:43:15 -040061# $(HOME)/.local/lib/traceevent/plugins by default.
Jiri Olsae0e96d02013-12-03 14:09:17 +010062#
63ifeq ($(plugin_dir),)
64ifeq ($(prefix),$(HOME))
Tzvetomir Stoyanov3caefd02019-08-05 16:43:15 -040065override plugin_dir = $(HOME)/.local/lib/traceevent/plugins
Jiri Olsae0e96d02013-12-03 14:09:17 +010066set_plugin_dir := 0
67else
Wang Nanbb53e172015-05-17 10:56:28 +000068override plugin_dir = $(libdir)/traceevent/plugins
Jiri Olsae0e96d02013-12-03 14:09:17 +010069endif
70endif
71
72ifeq ($(set_plugin_dir),1)
Josh Boyerb935a582014-01-22 10:01:48 -050073PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
Jiri Olsae0e96d02013-12-03 14:09:17 +010074PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
75endif
76
Jiri Olsa2d58ab92015-01-07 18:39:45 +010077include ../../scripts/Makefile.include
Jiri Olsac3d090f2013-12-19 14:42:02 +010078
Steven Rostedtf7d82352012-04-06 00:47:53 +020079# copy a bit from Linux kbuild
80
81ifeq ("$(origin V)", "command line")
82 VERBOSE = $(V)
83endif
84ifndef VERBOSE
85 VERBOSE = 0
86endif
87
Jiri Olsa2d58ab92015-01-07 18:39:45 +010088ifeq ($(srctree),)
89srctree := $(patsubst %/,%,$(dir $(shell pwd)))
90srctree := $(patsubst %/,%,$(dir $(srctree)))
91srctree := $(patsubst %/,%,$(dir $(srctree)))
92#$(info Determined 'srctree' to be $(srctree))
Steven Rostedtf7d82352012-04-06 00:47:53 +020093endif
94
Wang Nanbb53e172015-05-17 10:56:28 +000095export prefix libdir src obj
Steven Rostedtf7d82352012-04-06 00:47:53 +020096
97# Shell quotes
Wang Nanbb53e172015-05-17 10:56:28 +000098libdir_SQ = $(subst ','\'',$(libdir))
99libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100100plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
Steven Rostedtf7d82352012-04-06 00:47:53 +0200101
102LIB_FILE = libtraceevent.a libtraceevent.so
103
104CONFIG_INCLUDES =
105CONFIG_LIBS =
106CONFIG_FLAGS =
107
108VERSION = $(EP_VERSION)
109PATCHLEVEL = $(EP_PATCHLEVEL)
110EXTRAVERSION = $(EP_EXTRAVERSION)
111
112OBJ = $@
113N =
114
Steven Rostedtf7d82352012-04-06 00:47:53 +0200115EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
116
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100117INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200118
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100119# Set compile option CFLAGS
120ifdef EXTRA_CFLAGS
121 CFLAGS := $(EXTRA_CFLAGS)
122else
123 CFLAGS := -g -Wall
124endif
Steven Rostedtf7d82352012-04-06 00:47:53 +0200125
126# Append required CFLAGS
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100127override CFLAGS += -fPIC
Steven Rostedtf7d82352012-04-06 00:47:53 +0200128override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
Arnaldo Carvalho de Meloc0558752012-09-12 14:29:40 -0300129override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
Steven Rostedtf7d82352012-04-06 00:47:53 +0200130
131ifeq ($(VERBOSE),1)
132 Q =
Steven Rostedtf7d82352012-04-06 00:47:53 +0200133else
134 Q = @
Steven Rostedtf7d82352012-04-06 00:47:53 +0200135endif
136
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100137# Disable command line variables (CFLAGS) overide from top
138# level Makefile (perf), otherwise build Makefile will get
139# the same command line setup.
140MAKEOVERRIDES=
Steven Rostedtf7d82352012-04-06 00:47:53 +0200141
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100142export srctree OUTPUT CC LD CFLAGS V
143build := -f $(srctree)/tools/build/Makefile.build dir=. obj
Steven Rostedtf7d82352012-04-06 00:47:53 +0200144
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100145PLUGINS = plugin_jbd2.so
146PLUGINS += plugin_hrtimer.so
147PLUGINS += plugin_kmem.so
148PLUGINS += plugin_kvm.so
149PLUGINS += plugin_mac80211.so
150PLUGINS += plugin_sched_switch.so
151PLUGINS += plugin_function.so
152PLUGINS += plugin_xen.so
153PLUGINS += plugin_scsi.so
154PLUGINS += plugin_cfg80211.so
Steven Rostedtf7d82352012-04-06 00:47:53 +0200155
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100156PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
157PLUGINS_IN := $(PLUGINS:.so=-in.o)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200158
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100159TE_IN := $(OUTPUT)libtraceevent-in.o
160LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
He Kuange3d09ec2015-05-28 13:28:54 +0000161DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
Jiri Olsae0e96d02013-12-03 14:09:17 +0100162
He Kuange3d09ec2015-05-28 13:28:54 +0000163CMD_TARGETS = $(LIB_FILE) $(PLUGINS) $(DYNAMIC_LIST_FILE)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200164
165TARGETS = $(CMD_TARGETS)
166
Steven Rostedtf7d82352012-04-06 00:47:53 +0200167all: all_cmd
168
169all_cmd: $(CMD_TARGETS)
170
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100171$(TE_IN): force
172 $(Q)$(MAKE) $(build)=libtraceevent
173
174$(OUTPUT)libtraceevent.so: $(TE_IN)
Jiri Olsae6262e22013-12-19 14:42:04 +0100175 $(QUIET_LINK)$(CC) --shared $^ -o $@
Steven Rostedtf7d82352012-04-06 00:47:53 +0200176
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100177$(OUTPUT)libtraceevent.a: $(TE_IN)
Jiri Olsae6262e22013-12-19 14:42:04 +0100178 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
Steven Rostedtf7d82352012-04-06 00:47:53 +0200179
He Kuange3d09ec2015-05-28 13:28:54 +0000180$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
181 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
182
Jiri Olsae0e96d02013-12-03 14:09:17 +0100183plugins: $(PLUGINS)
184
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100185__plugin_obj = $(notdir $@)
186 plugin_obj = $(__plugin_obj:-in.o=)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200187
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100188$(PLUGINS_IN): force
189 $(Q)$(MAKE) $(build)=$(plugin_obj)
Jiri Olsae0e96d02013-12-03 14:09:17 +0100190
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100191$(OUTPUT)%.so: $(OUTPUT)%-in.o
192 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
Jiri Olsae0e96d02013-12-03 14:09:17 +0100193
Steven Rostedtf7d82352012-04-06 00:47:53 +0200194define make_version.h
Jiri Olsa198430b2014-01-02 10:53:04 +0100195 (echo '/* This file is automatically generated. Do not modify. */'; \
196 echo \#define VERSION_CODE $(shell \
197 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
198 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
199 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
200 echo '#define FILE_VERSION '$(FILE_VERSION); \
201 ) > $1
Steven Rostedtf7d82352012-04-06 00:47:53 +0200202endef
203
204define update_version.h
Jiri Olsa198430b2014-01-02 10:53:04 +0100205 ($(call make_version.h, $@.tmp); \
206 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
207 rm -f $@.tmp; \
208 else \
209 echo ' UPDATE $@'; \
210 mv -f $@.tmp $@; \
211 fi);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200212endef
213
214ep_version.h: force
215 $(Q)$(N)$(call update_version.h)
216
217VERSION_FILES = ep_version.h
218
219define update_dir
Jiri Olsa198430b2014-01-02 10:53:04 +0100220 (echo $1 > $@.tmp; \
221 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
222 rm -f $@.tmp; \
223 else \
224 echo ' UPDATE $@'; \
225 mv -f $@.tmp $@; \
226 fi);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200227endef
228
Steven Rostedtf7d82352012-04-06 00:47:53 +0200229tags: force
230 $(RM) tags
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900231 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
232 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200233
234TAGS: force
235 $(RM) TAGS
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900236 find . -name '*.[ch]' | xargs etags \
237 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200238
239define do_install
Steven Rostedtf7d82352012-04-06 00:47:53 +0200240 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
241 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
242 fi; \
243 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
244endef
245
Jiri Olsa02a82c72013-12-19 14:42:05 +0100246define do_install_plugins
247 for plugin in $1; do \
248 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
249 done
250endef
251
He Kuange3d09ec2015-05-28 13:28:54 +0000252define do_generate_dynamic_list_file
253 (echo '{'; \
254 $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u; \
255 echo '};'; \
256 ) > $2
257endef
258
Jiri Olsae0e96d02013-12-03 14:09:17 +0100259install_lib: all_cmd install_plugins
Jiri Olsa02a82c72013-12-19 14:42:05 +0100260 $(call QUIET_INSTALL, $(LIB_FILE)) \
Wang Nanbb53e172015-05-17 10:56:28 +0000261 $(call do_install,$(LIB_FILE),$(libdir_SQ))
Steven Rostedtf7d82352012-04-06 00:47:53 +0200262
Jiri Olsa02a82c72013-12-19 14:42:05 +0100263install_plugins: $(PLUGINS)
264 $(call QUIET_INSTALL, trace_plugins) \
265 $(call do_install_plugins, $(PLUGINS))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100266
Steven Rostedtf7d82352012-04-06 00:47:53 +0200267install: install_lib
268
269clean:
Jiri Olsa4a953c72013-12-19 14:42:06 +0100270 $(call QUIET_CLEAN, libtraceevent) \
Riku Voipioc867b152015-06-18 15:52:18 +0300271 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
Jiri Olsa4a953c72013-12-19 14:42:06 +0100272 $(RM) TRACEEVENT-CFLAGS tags TAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200273
Jiri Olsa9bb8e5e2014-01-01 17:50:50 +0100274PHONY += force plugins
Steven Rostedtf7d82352012-04-06 00:47:53 +0200275force:
276
Steven Rostedtf7d82352012-04-06 00:47:53 +0200277# Declare the contents of the .PHONY variable as phony. We keep that
278# information in a variable so we can use it in if_changed and friends.
279.PHONY: $(PHONY)