blob: d410da335e3daeaeac8da1dbdfdabdc7e23fc38f [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)
26
27EXT = -std=gnu99
28INSTALL = install
29
30# Use DESTDIR for installing into a different root directory.
31# This is useful for building a package. The program will be
32# installed in this directory as if it was the root directory.
33# Then the build tool can move it later.
34DESTDIR ?=
35DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
36
37prefix ?= /usr/local
38bindir_relative = bin
39bindir = $(prefix)/$(bindir_relative)
40man_dir = $(prefix)/share/man
41man_dir_SQ = '$(subst ','\'',$(man_dir))'
Steven Rostedtf7d82352012-04-06 00:47:53 +020042
Namhyung Kim9f1efa82013-06-04 14:20:16 +090043export man_dir man_dir_SQ INSTALL
Steven Rostedtf7d82352012-04-06 00:47:53 +020044export DESTDIR DESTDIR_SQ
45
Jiri Olsae0e96d02013-12-03 14:09:17 +010046set_plugin_dir := 1
47
48# Set plugin_dir to preffered global plugin location
49# If we install under $HOME directory we go under
50# $(HOME)/.traceevent/plugins
51#
52# We dont set PLUGIN_DIR in case we install under $HOME
53# directory, because by default the code looks under:
54# $(HOME)/.traceevent/plugins by default.
55#
56ifeq ($(plugin_dir),)
57ifeq ($(prefix),$(HOME))
58override plugin_dir = $(HOME)/.traceevent/plugins
59set_plugin_dir := 0
60else
61override plugin_dir = $(prefix)/lib/traceevent/plugins
62endif
63endif
64
65ifeq ($(set_plugin_dir),1)
Josh Boyerb935a582014-01-22 10:01:48 -050066PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
Jiri Olsae0e96d02013-12-03 14:09:17 +010067PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
68endif
69
Jiri Olsa2d58ab92015-01-07 18:39:45 +010070include ../../scripts/Makefile.include
Jiri Olsac3d090f2013-12-19 14:42:02 +010071
Steven Rostedtf7d82352012-04-06 00:47:53 +020072# copy a bit from Linux kbuild
73
74ifeq ("$(origin V)", "command line")
75 VERBOSE = $(V)
76endif
77ifndef VERBOSE
78 VERBOSE = 0
79endif
80
Jiri Olsa2d58ab92015-01-07 18:39:45 +010081ifeq ($(srctree),)
82srctree := $(patsubst %/,%,$(dir $(shell pwd)))
83srctree := $(patsubst %/,%,$(dir $(srctree)))
84srctree := $(patsubst %/,%,$(dir $(srctree)))
85#$(info Determined 'srctree' to be $(srctree))
Steven Rostedtf7d82352012-04-06 00:47:53 +020086endif
87
Steven Rostedtf7d82352012-04-06 00:47:53 +020088export prefix bindir src obj
89
90# Shell quotes
91bindir_SQ = $(subst ','\'',$(bindir))
92bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
Jiri Olsae0e96d02013-12-03 14:09:17 +010093plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
Steven Rostedtf7d82352012-04-06 00:47:53 +020094
95LIB_FILE = libtraceevent.a libtraceevent.so
96
97CONFIG_INCLUDES =
98CONFIG_LIBS =
99CONFIG_FLAGS =
100
101VERSION = $(EP_VERSION)
102PATCHLEVEL = $(EP_PATCHLEVEL)
103EXTRAVERSION = $(EP_EXTRAVERSION)
104
105OBJ = $@
106N =
107
Steven Rostedtf7d82352012-04-06 00:47:53 +0200108EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
109
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100110INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200111
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100112# Set compile option CFLAGS
113ifdef EXTRA_CFLAGS
114 CFLAGS := $(EXTRA_CFLAGS)
115else
116 CFLAGS := -g -Wall
117endif
Steven Rostedtf7d82352012-04-06 00:47:53 +0200118
119# Append required CFLAGS
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100120override CFLAGS += -fPIC
Steven Rostedtf7d82352012-04-06 00:47:53 +0200121override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
Arnaldo Carvalho de Meloc0558752012-09-12 14:29:40 -0300122override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
Steven Rostedtf7d82352012-04-06 00:47:53 +0200123
124ifeq ($(VERBOSE),1)
125 Q =
Steven Rostedtf7d82352012-04-06 00:47:53 +0200126else
127 Q = @
Steven Rostedtf7d82352012-04-06 00:47:53 +0200128endif
129
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100130# Disable command line variables (CFLAGS) overide from top
131# level Makefile (perf), otherwise build Makefile will get
132# the same command line setup.
133MAKEOVERRIDES=
Steven Rostedtf7d82352012-04-06 00:47:53 +0200134
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100135export srctree OUTPUT CC LD CFLAGS V
136build := -f $(srctree)/tools/build/Makefile.build dir=. obj
Steven Rostedtf7d82352012-04-06 00:47:53 +0200137
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100138PLUGINS = plugin_jbd2.so
139PLUGINS += plugin_hrtimer.so
140PLUGINS += plugin_kmem.so
141PLUGINS += plugin_kvm.so
142PLUGINS += plugin_mac80211.so
143PLUGINS += plugin_sched_switch.so
144PLUGINS += plugin_function.so
145PLUGINS += plugin_xen.so
146PLUGINS += plugin_scsi.so
147PLUGINS += plugin_cfg80211.so
Steven Rostedtf7d82352012-04-06 00:47:53 +0200148
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100149PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
150PLUGINS_IN := $(PLUGINS:.so=-in.o)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200151
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100152TE_IN := $(OUTPUT)libtraceevent-in.o
153LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100154
155CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200156
157TARGETS = $(CMD_TARGETS)
158
Steven Rostedtf7d82352012-04-06 00:47:53 +0200159all: all_cmd
160
161all_cmd: $(CMD_TARGETS)
162
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100163$(TE_IN): force
164 $(Q)$(MAKE) $(build)=libtraceevent
165
166$(OUTPUT)libtraceevent.so: $(TE_IN)
Jiri Olsae6262e22013-12-19 14:42:04 +0100167 $(QUIET_LINK)$(CC) --shared $^ -o $@
Steven Rostedtf7d82352012-04-06 00:47:53 +0200168
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100169$(OUTPUT)libtraceevent.a: $(TE_IN)
Jiri Olsae6262e22013-12-19 14:42:04 +0100170 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
Steven Rostedtf7d82352012-04-06 00:47:53 +0200171
Jiri Olsae0e96d02013-12-03 14:09:17 +0100172plugins: $(PLUGINS)
173
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100174__plugin_obj = $(notdir $@)
175 plugin_obj = $(__plugin_obj:-in.o=)
Steven Rostedtf7d82352012-04-06 00:47:53 +0200176
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100177$(PLUGINS_IN): force
178 $(Q)$(MAKE) $(build)=$(plugin_obj)
Jiri Olsae0e96d02013-12-03 14:09:17 +0100179
Jiri Olsa2d58ab92015-01-07 18:39:45 +0100180$(OUTPUT)%.so: $(OUTPUT)%-in.o
181 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
Jiri Olsae0e96d02013-12-03 14:09:17 +0100182
Steven Rostedtf7d82352012-04-06 00:47:53 +0200183define make_version.h
Jiri Olsa198430b2014-01-02 10:53:04 +0100184 (echo '/* This file is automatically generated. Do not modify. */'; \
185 echo \#define VERSION_CODE $(shell \
186 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
187 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
188 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
189 echo '#define FILE_VERSION '$(FILE_VERSION); \
190 ) > $1
Steven Rostedtf7d82352012-04-06 00:47:53 +0200191endef
192
193define update_version.h
Jiri Olsa198430b2014-01-02 10:53:04 +0100194 ($(call make_version.h, $@.tmp); \
195 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
196 rm -f $@.tmp; \
197 else \
198 echo ' UPDATE $@'; \
199 mv -f $@.tmp $@; \
200 fi);
Steven Rostedtf7d82352012-04-06 00:47:53 +0200201endef
202
203ep_version.h: force
204 $(Q)$(N)$(call update_version.h)
205
206VERSION_FILES = ep_version.h
207
208define update_dir
Jiri Olsa198430b2014-01-02 10:53:04 +0100209 (echo $1 > $@.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
Steven Rostedtf7d82352012-04-06 00:47:53 +0200218tags: force
219 $(RM) tags
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900220 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
221 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200222
223TAGS: force
224 $(RM) TAGS
Namhyung Kim6545e3a2012-06-22 17:10:14 +0900225 find . -name '*.[ch]' | xargs etags \
226 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
Steven Rostedtf7d82352012-04-06 00:47:53 +0200227
228define do_install
Steven Rostedtf7d82352012-04-06 00:47:53 +0200229 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
230 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
231 fi; \
232 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
233endef
234
Jiri Olsa02a82c72013-12-19 14:42:05 +0100235define do_install_plugins
236 for plugin in $1; do \
237 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
238 done
239endef
240
Jiri Olsae0e96d02013-12-03 14:09:17 +0100241install_lib: all_cmd install_plugins
Jiri Olsa02a82c72013-12-19 14:42:05 +0100242 $(call QUIET_INSTALL, $(LIB_FILE)) \
243 $(call do_install,$(LIB_FILE),$(bindir_SQ))
Steven Rostedtf7d82352012-04-06 00:47:53 +0200244
Jiri Olsa02a82c72013-12-19 14:42:05 +0100245install_plugins: $(PLUGINS)
246 $(call QUIET_INSTALL, trace_plugins) \
247 $(call do_install_plugins, $(PLUGINS))
Jiri Olsae0e96d02013-12-03 14:09:17 +0100248
Steven Rostedtf7d82352012-04-06 00:47:53 +0200249install: install_lib
250
251clean:
Jiri Olsa4a953c72013-12-19 14:42:06 +0100252 $(call QUIET_CLEAN, libtraceevent) \
253 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
254 $(RM) TRACEEVENT-CFLAGS tags TAGS
Steven Rostedtf7d82352012-04-06 00:47:53 +0200255
Jiri Olsa9bb8e5e2014-01-01 17:50:50 +0100256PHONY += force plugins
Steven Rostedtf7d82352012-04-06 00:47:53 +0200257force:
258
Steven Rostedtf7d82352012-04-06 00:47:53 +0200259# Declare the contents of the .PHONY variable as phony. We keep that
260# information in a variable so we can use it in if_changed and friends.
261.PHONY: $(PHONY)