]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | # SPDX-License-Identifier: GPL-2.0 |
f7d82350 SR |
2 | # trace-cmd version |
3 | EP_VERSION = 1 | |
4 | EP_PATCHLEVEL = 1 | |
5 | EP_EXTRAVERSION = 0 | |
6 | ||
7 | # file format version | |
8 | FILE_VERSION = 6 | |
9 | ||
10 | MAKEFLAGS += --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. | |
18 | define allow-override | |
19 | $(if $(or $(findstring environment,$(origin $(1))),\ | |
20 | $(findstring command line,$(origin $(1)))),,\ | |
21 | $(eval $(1) = $(2))) | |
22 | endef | |
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) | |
e3d09ec8 | 27 | $(call allow-override,NM,$(CROSS_COMPILE)nm) |
cc03e1a8 | 28 | $(call allow-override,PKG_CONFIG,pkg-config) |
f7d82350 SR |
29 | |
30 | EXT = -std=gnu99 | |
31 | INSTALL = install | |
32 | ||
33 | # Use DESTDIR for installing into a different root directory. | |
34 | # This is useful for building a package. The program will be | |
35 | # installed in this directory as if it was the root directory. | |
36 | # Then the build tool can move it later. | |
37 | DESTDIR ?= | |
38 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' | |
39 | ||
bb53e176 WN |
40 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) |
41 | ifeq ($(LP64), 1) | |
42 | libdir_relative = lib64 | |
43 | else | |
44 | libdir_relative = lib | |
45 | endif | |
46 | ||
f7d82350 | 47 | prefix ?= /usr/local |
bb53e176 | 48 | libdir = $(prefix)/$(libdir_relative) |
f7d82350 SR |
49 | man_dir = $(prefix)/share/man |
50 | man_dir_SQ = '$(subst ','\'',$(man_dir))' | |
cc03e1a8 TS |
51 | pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \ |
52 | --variable pc_path pkg-config | tr ":" " ")) | |
53dbabfe TS |
53 | includedir_relative = traceevent |
54 | includedir = $(prefix)/include/$(includedir_relative) | |
55 | includedir_SQ = '$(subst ','\'',$(includedir))' | |
f7d82350 | 56 | |
9f1efa82 | 57 | export man_dir man_dir_SQ INSTALL |
f7d82350 | 58 | export DESTDIR DESTDIR_SQ |
dc7fd7bf | 59 | export EVENT_PARSE_VERSION |
f7d82350 | 60 | |
2d58ab9b | 61 | include ../../scripts/Makefile.include |
c3d090f4 | 62 | |
f7d82350 SR |
63 | # copy a bit from Linux kbuild |
64 | ||
65 | ifeq ("$(origin V)", "command line") | |
66 | VERBOSE = $(V) | |
67 | endif | |
68 | ifndef VERBOSE | |
69 | VERBOSE = 0 | |
70 | endif | |
71 | ||
2d58ab9b | 72 | ifeq ($(srctree),) |
e19b7cee | 73 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
2d58ab9b JO |
74 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
75 | srctree := $(patsubst %/,%,$(dir $(srctree))) | |
76 | #$(info Determined 'srctree' to be $(srctree)) | |
f7d82350 SR |
77 | endif |
78 | ||
bb53e176 | 79 | export prefix libdir src obj |
f7d82350 SR |
80 | |
81 | # Shell quotes | |
bb53e176 WN |
82 | libdir_SQ = $(subst ','\'',$(libdir)) |
83 | libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) | |
f7d82350 | 84 | |
f7d82350 SR |
85 | CONFIG_INCLUDES = |
86 | CONFIG_LIBS = | |
87 | CONFIG_FLAGS = | |
88 | ||
89 | VERSION = $(EP_VERSION) | |
90 | PATCHLEVEL = $(EP_PATCHLEVEL) | |
91 | EXTRAVERSION = $(EP_EXTRAVERSION) | |
92 | ||
93 | OBJ = $@ | |
94 | N = | |
95 | ||
f7d82350 SR |
96 | EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) |
97 | ||
fe316723 JO |
98 | LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION) |
99 | LIB_INSTALL = libtraceevent.a libtraceevent.so* | |
838f8f97 | 100 | LIB_INSTALL := $(addprefix $(OUTPUT),$(LIB_INSTALL)) |
fe316723 | 101 | |
2d58ab9b | 102 | INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES) |
f7d82350 | 103 | |
2d58ab9b JO |
104 | # Set compile option CFLAGS |
105 | ifdef EXTRA_CFLAGS | |
106 | CFLAGS := $(EXTRA_CFLAGS) | |
107 | else | |
108 | CFLAGS := -g -Wall | |
109 | endif | |
f7d82350 SR |
110 | |
111 | # Append required CFLAGS | |
2d58ab9b | 112 | override CFLAGS += -fPIC |
f7d82350 | 113 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
c055875b | 114 | override CFLAGS += $(udis86-flags) -D_GNU_SOURCE |
f7d82350 SR |
115 | |
116 | ifeq ($(VERBOSE),1) | |
117 | Q = | |
f7d82350 SR |
118 | else |
119 | Q = @ | |
f7d82350 SR |
120 | endif |
121 | ||
505d3085 | 122 | # Disable command line variables (CFLAGS) override from top |
2d58ab9b JO |
123 | # level Makefile (perf), otherwise build Makefile will get |
124 | # the same command line setup. | |
125 | MAKEOVERRIDES= | |
f7d82350 | 126 | |
2d58ab9b JO |
127 | export srctree OUTPUT CC LD CFLAGS V |
128 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj | |
f7d82350 | 129 | |
39944a76 JO |
130 | TE_IN := $(OUTPUT)libtraceevent-in.o |
131 | LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) | |
f7d82350 | 132 | |
077faf3d | 133 | CMD_TARGETS = $(LIB_TARGET) |
f7d82350 SR |
134 | |
135 | TARGETS = $(CMD_TARGETS) | |
136 | ||
077faf3d | 137 | all: all_cmd plugins |
f7d82350 SR |
138 | |
139 | all_cmd: $(CMD_TARGETS) | |
140 | ||
2d58ab9b JO |
141 | $(TE_IN): force |
142 | $(Q)$(MAKE) $(build)=libtraceevent | |
143 | ||
fe316723 | 144 | $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN) |
41fa483a | 145 | $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ |
fe316723 JO |
146 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so |
147 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION) | |
f7d82350 | 148 | |
2d58ab9b | 149 | $(OUTPUT)libtraceevent.a: $(TE_IN) |
e6262e23 | 150 | $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ |
f7d82350 | 151 | |
2d58ab9b | 152 | $(OUTPUT)%.so: $(OUTPUT)%-in.o |
41fa483a | 153 | $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^ |
e0e96d03 | 154 | |
f7d82350 | 155 | define make_version.h |
198430b5 JO |
156 | (echo '/* This file is automatically generated. Do not modify. */'; \ |
157 | echo \#define VERSION_CODE $(shell \ | |
158 | expr $(VERSION) \* 256 + $(PATCHLEVEL)); \ | |
159 | echo '#define EXTRAVERSION ' $(EXTRAVERSION); \ | |
160 | echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \ | |
161 | echo '#define FILE_VERSION '$(FILE_VERSION); \ | |
162 | ) > $1 | |
f7d82350 SR |
163 | endef |
164 | ||
165 | define update_version.h | |
198430b5 JO |
166 | ($(call make_version.h, $@.tmp); \ |
167 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ | |
168 | rm -f $@.tmp; \ | |
169 | else \ | |
170 | echo ' UPDATE $@'; \ | |
171 | mv -f $@.tmp $@; \ | |
172 | fi); | |
f7d82350 SR |
173 | endef |
174 | ||
175 | ep_version.h: force | |
176 | $(Q)$(N)$(call update_version.h) | |
177 | ||
178 | VERSION_FILES = ep_version.h | |
179 | ||
180 | define update_dir | |
198430b5 JO |
181 | (echo $1 > $@.tmp; \ |
182 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ | |
183 | rm -f $@.tmp; \ | |
184 | else \ | |
185 | echo ' UPDATE $@'; \ | |
186 | mv -f $@.tmp $@; \ | |
187 | fi); | |
f7d82350 SR |
188 | endef |
189 | ||
f7d82350 SR |
190 | tags: force |
191 | $(RM) tags | |
6545e3a8 | 192 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
d97f4ef1 | 193 | --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' |
f7d82350 SR |
194 | |
195 | TAGS: force | |
196 | $(RM) TAGS | |
6545e3a8 | 197 | find . -name '*.[ch]' | xargs etags \ |
d97f4ef1 | 198 | --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' |
f7d82350 | 199 | |
c121bdbb JO |
200 | define do_install_mkdir |
201 | if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ | |
202 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ | |
203 | fi | |
204 | endef | |
205 | ||
f7d82350 | 206 | define do_install |
c121bdbb | 207 | $(call do_install_mkdir,$2); \ |
722a4984 | 208 | $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' |
f7d82350 SR |
209 | endef |
210 | ||
a526bf80 SM |
211 | PKG_CONFIG_SOURCE_FILE = libtraceevent.pc |
212 | PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE)) | |
cc03e1a8 TS |
213 | define do_install_pkgconfig_file |
214 | if [ -n "${pkgconfig_dir}" ]; then \ | |
a526bf80 | 215 | cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE}; \ |
cc03e1a8 TS |
216 | sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \ |
217 | sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \ | |
53dbabfe TS |
218 | sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \ |
219 | sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \ | |
cc03e1a8 TS |
220 | $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \ |
221 | else \ | |
222 | (echo Failed to locate pkg-config directory) 1>&2; \ | |
223 | fi | |
224 | endef | |
225 | ||
4c784894 | 226 | install_lib: all_cmd install_plugins install_headers install_pkgconfig |
39944a76 | 227 | $(call QUIET_INSTALL, $(LIB_TARGET)) \ |
fe316723 JO |
228 | $(call do_install_mkdir,$(libdir_SQ)); \ |
229 | cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ) | |
e0e96d03 | 230 | |
cc03e1a8 TS |
231 | install_pkgconfig: |
232 | $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \ | |
233 | $(call do_install_pkgconfig_file,$(prefix)) | |
234 | ||
722a4984 JO |
235 | install_headers: |
236 | $(call QUIET_INSTALL, headers) \ | |
53dbabfe TS |
237 | $(call do_install,event-parse.h,$(DESTDIR)$(includedir_SQ),644); \ |
238 | $(call do_install,event-utils.h,$(DESTDIR)$(includedir_SQ),644); \ | |
239 | $(call do_install,trace-seq.h,$(DESTDIR)$(includedir_SQ),644); \ | |
240 | $(call do_install,kbuffer.h,$(DESTDIR)$(includedir_SQ),644) | |
722a4984 | 241 | |
f7d82350 SR |
242 | install: install_lib |
243 | ||
077faf3d | 244 | clean: clean_plugins |
4a953c71 | 245 | $(call QUIET_CLEAN, libtraceevent) \ |
cc03e1a8 TS |
246 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ |
247 | $(RM) TRACEEVENT-CFLAGS tags TAGS; \ | |
248 | $(RM) $(PKG_CONFIG_FILE) | |
f7d82350 | 249 | |
dc7fd7bf TS |
250 | PHONY += doc |
251 | doc: | |
252 | $(call descend,Documentation) | |
253 | ||
254 | PHONY += doc-clean | |
255 | doc-clean: | |
256 | $(call descend,Documentation,clean) | |
257 | ||
258 | PHONY += doc-install | |
259 | doc-install: | |
260 | $(call descend,Documentation,install) | |
261 | ||
262 | PHONY += doc-uninstall | |
263 | doc-uninstall: | |
264 | $(call descend,Documentation,uninstall) | |
265 | ||
266 | PHONY += help | |
267 | help: | |
268 | @echo 'Possible targets:' | |
269 | @echo'' | |
270 | @echo ' all - default, compile the library and the'\ | |
271 | 'plugins' | |
272 | @echo ' plugins - compile the plugins' | |
273 | @echo ' install - install the library, the plugins,'\ | |
274 | 'the header and pkgconfig files' | |
275 | @echo ' clean - clean the library and the plugins object files' | |
276 | @echo ' doc - compile the documentation files - man'\ | |
277 | 'and html pages, in the Documentation directory' | |
278 | @echo ' doc-clean - clean the documentation files' | |
279 | @echo ' doc-install - install the man pages' | |
280 | @echo ' doc-uninstall - uninstall the man pages' | |
281 | @echo'' | |
077faf3d TSV |
282 | |
283 | PHONY += plugins | |
284 | plugins: | |
285 | $(call descend,plugins) | |
286 | ||
287 | PHONY += install_plugins | |
288 | install_plugins: | |
289 | $(call descend,plugins,install) | |
290 | ||
291 | PHONY += clean_plugins | |
292 | clean_plugins: | |
293 | $(call descend,plugins,clean) | |
294 | ||
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) |