Merge tag 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dledford/rdma
[linux-2.6-block.git] / tools / lib / traceevent / Makefile
CommitLineData
f7d82350
SR
1# 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)
e3d09ec8 26$(call allow-override,NM,$(CROSS_COMPILE)nm)
f7d82350
SR
27
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
bb53e176
WN
38LP64 := $(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
f7d82350 45prefix ?= /usr/local
bb53e176 46libdir = $(prefix)/$(libdir_relative)
f7d82350
SR
47man_dir = $(prefix)/share/man
48man_dir_SQ = '$(subst ','\'',$(man_dir))'
f7d82350 49
9f1efa82 50export man_dir man_dir_SQ INSTALL
f7d82350
SR
51export DESTDIR DESTDIR_SQ
52
e0e96d03
JO
53set_plugin_dir := 1
54
55# Set plugin_dir to preffered global plugin location
56# If we install under $HOME directory we go under
57# $(HOME)/.traceevent/plugins
58#
59# We dont set PLUGIN_DIR in case we install under $HOME
60# directory, because by default the code looks under:
61# $(HOME)/.traceevent/plugins by default.
62#
63ifeq ($(plugin_dir),)
64ifeq ($(prefix),$(HOME))
65override plugin_dir = $(HOME)/.traceevent/plugins
66set_plugin_dir := 0
67else
bb53e176 68override plugin_dir = $(libdir)/traceevent/plugins
e0e96d03
JO
69endif
70endif
71
72ifeq ($(set_plugin_dir),1)
b935a58d 73PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
e0e96d03
JO
74PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
75endif
76
2d58ab9b 77include ../../scripts/Makefile.include
c3d090f4 78
f7d82350
SR
79# copy a bit from Linux kbuild
80
81ifeq ("$(origin V)", "command line")
82 VERBOSE = $(V)
83endif
84ifndef VERBOSE
85 VERBOSE = 0
86endif
87
2d58ab9b
JO
88ifeq ($(srctree),)
89srctree := $(patsubst %/,%,$(dir $(shell pwd)))
90srctree := $(patsubst %/,%,$(dir $(srctree)))
91srctree := $(patsubst %/,%,$(dir $(srctree)))
92#$(info Determined 'srctree' to be $(srctree))
f7d82350
SR
93endif
94
bb53e176 95export prefix libdir src obj
f7d82350
SR
96
97# Shell quotes
bb53e176
WN
98libdir_SQ = $(subst ','\'',$(libdir))
99libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
e0e96d03 100plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
f7d82350
SR
101
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
f7d82350
SR
115EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
116
2d58ab9b 117INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
f7d82350 118
2d58ab9b
JO
119# Set compile option CFLAGS
120ifdef EXTRA_CFLAGS
121 CFLAGS := $(EXTRA_CFLAGS)
122else
123 CFLAGS := -g -Wall
124endif
f7d82350
SR
125
126# Append required CFLAGS
2d58ab9b 127override CFLAGS += -fPIC
f7d82350 128override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
c055875b 129override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
f7d82350
SR
130
131ifeq ($(VERBOSE),1)
132 Q =
f7d82350
SR
133else
134 Q = @
f7d82350
SR
135endif
136
2d58ab9b
JO
137# Disable command line variables (CFLAGS) overide from top
138# level Makefile (perf), otherwise build Makefile will get
139# the same command line setup.
140MAKEOVERRIDES=
f7d82350 141
2d58ab9b
JO
142export srctree OUTPUT CC LD CFLAGS V
143build := -f $(srctree)/tools/build/Makefile.build dir=. obj
f7d82350 144
2d58ab9b
JO
145PLUGINS = 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
f7d82350 155
2d58ab9b
JO
156PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
157PLUGINS_IN := $(PLUGINS:.so=-in.o)
f7d82350 158
2d58ab9b
JO
159TE_IN := $(OUTPUT)libtraceevent-in.o
160LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
e3d09ec8 161DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
f7d82350 162
e3d09ec8 163CMD_TARGETS = $(LIB_FILE) $(PLUGINS) $(DYNAMIC_LIST_FILE)
f7d82350
SR
164
165TARGETS = $(CMD_TARGETS)
166
f7d82350
SR
167all: all_cmd
168
169all_cmd: $(CMD_TARGETS)
170
2d58ab9b
JO
171$(TE_IN): force
172 $(Q)$(MAKE) $(build)=libtraceevent
173
174$(OUTPUT)libtraceevent.so: $(TE_IN)
e6262e23 175 $(QUIET_LINK)$(CC) --shared $^ -o $@
f7d82350 176
2d58ab9b 177$(OUTPUT)libtraceevent.a: $(TE_IN)
e6262e23 178 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
f7d82350 179
e3d09ec8
HK
180$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
181 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
182
e0e96d03
JO
183plugins: $(PLUGINS)
184
2d58ab9b
JO
185__plugin_obj = $(notdir $@)
186 plugin_obj = $(__plugin_obj:-in.o=)
f7d82350 187
2d58ab9b
JO
188$(PLUGINS_IN): force
189 $(Q)$(MAKE) $(build)=$(plugin_obj)
e0e96d03 190
2d58ab9b
JO
191$(OUTPUT)%.so: $(OUTPUT)%-in.o
192 $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
e0e96d03 193
f7d82350 194define make_version.h
198430b5
JO
195 (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
f7d82350
SR
202endef
203
204define update_version.h
198430b5
JO
205 ($(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);
f7d82350
SR
212endef
213
214ep_version.h: force
215 $(Q)$(N)$(call update_version.h)
216
217VERSION_FILES = ep_version.h
218
219define update_dir
198430b5
JO
220 (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);
f7d82350
SR
227endef
228
f7d82350
SR
229tags: force
230 $(RM) tags
6545e3a8
NK
231 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
232 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
f7d82350
SR
233
234TAGS: force
235 $(RM) TAGS
6545e3a8
NK
236 find . -name '*.[ch]' | xargs etags \
237 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
f7d82350
SR
238
239define do_install
f7d82350
SR
240 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
241 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
242 fi; \
243 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
244endef
245
02a82c7b
JO
246define do_install_plugins
247 for plugin in $1; do \
248 $(call do_install,$$plugin,$(plugin_dir_SQ)); \
249 done
250endef
e0e96d03 251
e3d09ec8
HK
252define 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
02a82c7b
JO
259install_lib: all_cmd install_plugins
260 $(call QUIET_INSTALL, $(LIB_FILE)) \
bb53e176 261 $(call do_install,$(LIB_FILE),$(libdir_SQ))
e0e96d03 262
02a82c7b
JO
263install_plugins: $(PLUGINS)
264 $(call QUIET_INSTALL, trace_plugins) \
265 $(call do_install_plugins, $(PLUGINS))
e0e96d03 266
f7d82350
SR
267install: install_lib
268
269clean:
4a953c71 270 $(call QUIET_CLEAN, libtraceevent) \
c867b150 271 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \
4a953c71 272 $(RM) TRACEEVENT-CFLAGS tags TAGS
f7d82350 273
9bb8e5ed 274PHONY += force plugins
f7d82350
SR
275force:
276
277# 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)