]>
Commit | Line | Data |
---|---|---|
f7d82350 SR |
1 | # trace-cmd version |
2 | EP_VERSION = 1 | |
3 | EP_PATCHLEVEL = 1 | |
4 | EP_EXTRAVERSION = 0 | |
5 | ||
6 | # file format version | |
7 | FILE_VERSION = 6 | |
8 | ||
9 | MAKEFLAGS += --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. | |
17 | define allow-override | |
18 | $(if $(or $(findstring environment,$(origin $(1))),\ | |
19 | $(findstring command line,$(origin $(1)))),,\ | |
20 | $(eval $(1) = $(2))) | |
21 | endef | |
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 | |
28 | EXT = -std=gnu99 | |
29 | INSTALL = 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. | |
35 | DESTDIR ?= | |
36 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' | |
37 | ||
bb53e176 WN |
38 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) |
39 | ifeq ($(LP64), 1) | |
40 | libdir_relative = lib64 | |
41 | else | |
42 | libdir_relative = lib | |
43 | endif | |
44 | ||
f7d82350 | 45 | prefix ?= /usr/local |
bb53e176 | 46 | libdir = $(prefix)/$(libdir_relative) |
f7d82350 SR |
47 | man_dir = $(prefix)/share/man |
48 | man_dir_SQ = '$(subst ','\'',$(man_dir))' | |
f7d82350 | 49 | |
9f1efa82 | 50 | export man_dir man_dir_SQ INSTALL |
f7d82350 SR |
51 | export DESTDIR DESTDIR_SQ |
52 | ||
e0e96d03 JO |
53 | set_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 | # | |
63 | ifeq ($(plugin_dir),) | |
64 | ifeq ($(prefix),$(HOME)) | |
65 | override plugin_dir = $(HOME)/.traceevent/plugins | |
66 | set_plugin_dir := 0 | |
67 | else | |
bb53e176 | 68 | override plugin_dir = $(libdir)/traceevent/plugins |
e0e96d03 JO |
69 | endif |
70 | endif | |
71 | ||
72 | ifeq ($(set_plugin_dir),1) | |
b935a58d | 73 | PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" |
e0e96d03 JO |
74 | PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' |
75 | endif | |
76 | ||
2d58ab9b | 77 | include ../../scripts/Makefile.include |
c3d090f4 | 78 | |
f7d82350 SR |
79 | # copy a bit from Linux kbuild |
80 | ||
81 | ifeq ("$(origin V)", "command line") | |
82 | VERBOSE = $(V) | |
83 | endif | |
84 | ifndef VERBOSE | |
85 | VERBOSE = 0 | |
86 | endif | |
87 | ||
2d58ab9b | 88 | ifeq ($(srctree),) |
e19b7cee | 89 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
2d58ab9b JO |
90 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
91 | srctree := $(patsubst %/,%,$(dir $(srctree))) | |
92 | #$(info Determined 'srctree' to be $(srctree)) | |
f7d82350 SR |
93 | endif |
94 | ||
bb53e176 | 95 | export prefix libdir src obj |
f7d82350 SR |
96 | |
97 | # Shell quotes | |
bb53e176 WN |
98 | libdir_SQ = $(subst ','\'',$(libdir)) |
99 | libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) | |
e0e96d03 | 100 | plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) |
f7d82350 | 101 | |
f7d82350 SR |
102 | CONFIG_INCLUDES = |
103 | CONFIG_LIBS = | |
104 | CONFIG_FLAGS = | |
105 | ||
106 | VERSION = $(EP_VERSION) | |
107 | PATCHLEVEL = $(EP_PATCHLEVEL) | |
108 | EXTRAVERSION = $(EP_EXTRAVERSION) | |
109 | ||
110 | OBJ = $@ | |
111 | N = | |
112 | ||
f7d82350 SR |
113 | EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) |
114 | ||
fe316723 JO |
115 | LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION) |
116 | LIB_INSTALL = libtraceevent.a libtraceevent.so* | |
117 | ||
2d58ab9b | 118 | INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES) |
f7d82350 | 119 | |
2d58ab9b JO |
120 | # Set compile option CFLAGS |
121 | ifdef EXTRA_CFLAGS | |
122 | CFLAGS := $(EXTRA_CFLAGS) | |
123 | else | |
124 | CFLAGS := -g -Wall | |
125 | endif | |
f7d82350 SR |
126 | |
127 | # Append required CFLAGS | |
2d58ab9b | 128 | override CFLAGS += -fPIC |
f7d82350 | 129 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
c055875b | 130 | override CFLAGS += $(udis86-flags) -D_GNU_SOURCE |
f7d82350 SR |
131 | |
132 | ifeq ($(VERBOSE),1) | |
133 | Q = | |
f7d82350 SR |
134 | else |
135 | Q = @ | |
f7d82350 SR |
136 | endif |
137 | ||
505d3085 | 138 | # Disable command line variables (CFLAGS) override from top |
2d58ab9b JO |
139 | # level Makefile (perf), otherwise build Makefile will get |
140 | # the same command line setup. | |
141 | MAKEOVERRIDES= | |
f7d82350 | 142 | |
2d58ab9b JO |
143 | export srctree OUTPUT CC LD CFLAGS V |
144 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj | |
f7d82350 | 145 | |
2d58ab9b JO |
146 | PLUGINS = plugin_jbd2.so |
147 | PLUGINS += plugin_hrtimer.so | |
148 | PLUGINS += plugin_kmem.so | |
149 | PLUGINS += plugin_kvm.so | |
150 | PLUGINS += plugin_mac80211.so | |
151 | PLUGINS += plugin_sched_switch.so | |
152 | PLUGINS += plugin_function.so | |
153 | PLUGINS += plugin_xen.so | |
154 | PLUGINS += plugin_scsi.so | |
155 | PLUGINS += plugin_cfg80211.so | |
f7d82350 | 156 | |
2d58ab9b JO |
157 | PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS)) |
158 | PLUGINS_IN := $(PLUGINS:.so=-in.o) | |
f7d82350 | 159 | |
39944a76 JO |
160 | TE_IN := $(OUTPUT)libtraceevent-in.o |
161 | LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) | |
e3d09ec8 | 162 | DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list |
f7d82350 | 163 | |
39944a76 | 164 | CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE) |
f7d82350 SR |
165 | |
166 | TARGETS = $(CMD_TARGETS) | |
167 | ||
f7d82350 SR |
168 | all: all_cmd |
169 | ||
170 | all_cmd: $(CMD_TARGETS) | |
171 | ||
2d58ab9b JO |
172 | $(TE_IN): force |
173 | $(Q)$(MAKE) $(build)=libtraceevent | |
174 | ||
fe316723 JO |
175 | $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN) |
176 | $(QUIET_LINK)$(CC) --shared $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ | |
177 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so | |
178 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION) | |
f7d82350 | 179 | |
2d58ab9b | 180 | $(OUTPUT)libtraceevent.a: $(TE_IN) |
e6262e23 | 181 | $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ |
f7d82350 | 182 | |
e3d09ec8 HK |
183 | $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS) |
184 | $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@) | |
185 | ||
e0e96d03 JO |
186 | plugins: $(PLUGINS) |
187 | ||
2d58ab9b JO |
188 | __plugin_obj = $(notdir $@) |
189 | plugin_obj = $(__plugin_obj:-in.o=) | |
f7d82350 | 190 | |
2d58ab9b JO |
191 | $(PLUGINS_IN): force |
192 | $(Q)$(MAKE) $(build)=$(plugin_obj) | |
e0e96d03 | 193 | |
2d58ab9b JO |
194 | $(OUTPUT)%.so: $(OUTPUT)%-in.o |
195 | $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^ | |
e0e96d03 | 196 | |
f7d82350 | 197 | define make_version.h |
198430b5 JO |
198 | (echo '/* This file is automatically generated. Do not modify. */'; \ |
199 | echo \#define VERSION_CODE $(shell \ | |
200 | expr $(VERSION) \* 256 + $(PATCHLEVEL)); \ | |
201 | echo '#define EXTRAVERSION ' $(EXTRAVERSION); \ | |
202 | echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \ | |
203 | echo '#define FILE_VERSION '$(FILE_VERSION); \ | |
204 | ) > $1 | |
f7d82350 SR |
205 | endef |
206 | ||
207 | define update_version.h | |
198430b5 JO |
208 | ($(call make_version.h, $@.tmp); \ |
209 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ | |
210 | rm -f $@.tmp; \ | |
211 | else \ | |
212 | echo ' UPDATE $@'; \ | |
213 | mv -f $@.tmp $@; \ | |
214 | fi); | |
f7d82350 SR |
215 | endef |
216 | ||
217 | ep_version.h: force | |
218 | $(Q)$(N)$(call update_version.h) | |
219 | ||
220 | VERSION_FILES = ep_version.h | |
221 | ||
222 | define update_dir | |
198430b5 JO |
223 | (echo $1 > $@.tmp; \ |
224 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ | |
225 | rm -f $@.tmp; \ | |
226 | else \ | |
227 | echo ' UPDATE $@'; \ | |
228 | mv -f $@.tmp $@; \ | |
229 | fi); | |
f7d82350 SR |
230 | endef |
231 | ||
f7d82350 SR |
232 | tags: force |
233 | $(RM) tags | |
6545e3a8 NK |
234 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
235 | --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' | |
f7d82350 SR |
236 | |
237 | TAGS: force | |
238 | $(RM) TAGS | |
6545e3a8 NK |
239 | find . -name '*.[ch]' | xargs etags \ |
240 | --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' | |
f7d82350 | 241 | |
c121bdbb JO |
242 | define do_install_mkdir |
243 | if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ | |
244 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ | |
245 | fi | |
246 | endef | |
247 | ||
f7d82350 | 248 | define do_install |
c121bdbb | 249 | $(call do_install_mkdir,$2); \ |
722a4984 | 250 | $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' |
f7d82350 SR |
251 | endef |
252 | ||
02a82c7b JO |
253 | define do_install_plugins |
254 | for plugin in $1; do \ | |
255 | $(call do_install,$$plugin,$(plugin_dir_SQ)); \ | |
256 | done | |
257 | endef | |
e0e96d03 | 258 | |
e3d09ec8 | 259 | define do_generate_dynamic_list_file |
6467753d DCC |
260 | symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \ |
261 | xargs echo "U W w" | tr ' ' '\n' | sort -u | xargs echo`;\ | |
262 | if [ "$$symbol_type" = "U W w" ];then \ | |
263 | (echo '{'; \ | |
264 | $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\ | |
265 | echo '};'; \ | |
266 | ) > $2; \ | |
267 | else \ | |
268 | (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\ | |
269 | fi | |
e3d09ec8 HK |
270 | endef |
271 | ||
02a82c7b | 272 | install_lib: all_cmd install_plugins |
39944a76 | 273 | $(call QUIET_INSTALL, $(LIB_TARGET)) \ |
fe316723 JO |
274 | $(call do_install_mkdir,$(libdir_SQ)); \ |
275 | cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ) | |
e0e96d03 | 276 | |
02a82c7b JO |
277 | install_plugins: $(PLUGINS) |
278 | $(call QUIET_INSTALL, trace_plugins) \ | |
279 | $(call do_install_plugins, $(PLUGINS)) | |
e0e96d03 | 280 | |
722a4984 JO |
281 | install_headers: |
282 | $(call QUIET_INSTALL, headers) \ | |
283 | $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \ | |
284 | $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \ | |
285 | $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644) | |
286 | ||
f7d82350 SR |
287 | install: install_lib |
288 | ||
289 | clean: | |
4a953c71 | 290 | $(call QUIET_CLEAN, libtraceevent) \ |
c867b150 | 291 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \ |
4a953c71 | 292 | $(RM) TRACEEVENT-CFLAGS tags TAGS |
f7d82350 | 293 | |
9bb8e5ed | 294 | PHONY += force plugins |
f7d82350 SR |
295 | force: |
296 | ||
297 | # Declare the contents of the .PHONY variable as phony. We keep that | |
298 | # information in a variable so we can use it in if_changed and friends. | |
299 | .PHONY: $(PHONY) |