]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - tools/lib/traceevent/Makefile
UBUNTU: Ubuntu-5.4.0-117.132
[mirror_ubuntu-focal-kernel.git] / tools / lib / traceevent / Makefile
CommitLineData
b2441318 1# SPDX-License-Identifier: GPL-2.0
f7d82350
SR
2# trace-cmd version
3EP_VERSION = 1
4EP_PATCHLEVEL = 1
5EP_EXTRAVERSION = 0
6
7# file format version
8FILE_VERSION = 6
9
10MAKEFLAGS += --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.
18define allow-override
19 $(if $(or $(findstring environment,$(origin $(1))),\
20 $(findstring command line,$(origin $(1)))),,\
21 $(eval $(1) = $(2)))
22endef
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
30EXT = -std=gnu99
31INSTALL = 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.
37DESTDIR ?=
38DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
39
bb53e176
WN
40LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
41ifeq ($(LP64), 1)
42 libdir_relative = lib64
43else
44 libdir_relative = lib
45endif
46
f7d82350 47prefix ?= /usr/local
bb53e176 48libdir = $(prefix)/$(libdir_relative)
f7d82350
SR
49man_dir = $(prefix)/share/man
50man_dir_SQ = '$(subst ','\'',$(man_dir))'
cc03e1a8
TS
51pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \
52 --variable pc_path pkg-config | tr ":" " "))
53dbabfe
TS
53includedir_relative = traceevent
54includedir = $(prefix)/include/$(includedir_relative)
55includedir_SQ = '$(subst ','\'',$(includedir))'
f7d82350 56
9f1efa82 57export man_dir man_dir_SQ INSTALL
f7d82350 58export DESTDIR DESTDIR_SQ
dc7fd7bf 59export EVENT_PARSE_VERSION
f7d82350 60
2d58ab9b 61include ../../scripts/Makefile.include
c3d090f4 62
f7d82350
SR
63# copy a bit from Linux kbuild
64
65ifeq ("$(origin V)", "command line")
66 VERBOSE = $(V)
67endif
68ifndef VERBOSE
69 VERBOSE = 0
70endif
71
2d58ab9b 72ifeq ($(srctree),)
e19b7cee 73srctree := $(patsubst %/,%,$(dir $(CURDIR)))
2d58ab9b
JO
74srctree := $(patsubst %/,%,$(dir $(srctree)))
75srctree := $(patsubst %/,%,$(dir $(srctree)))
76#$(info Determined 'srctree' to be $(srctree))
f7d82350
SR
77endif
78
bb53e176 79export prefix libdir src obj
f7d82350
SR
80
81# Shell quotes
bb53e176
WN
82libdir_SQ = $(subst ','\'',$(libdir))
83libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
f7d82350 84
f7d82350
SR
85CONFIG_INCLUDES =
86CONFIG_LIBS =
87CONFIG_FLAGS =
88
89VERSION = $(EP_VERSION)
90PATCHLEVEL = $(EP_PATCHLEVEL)
91EXTRAVERSION = $(EP_EXTRAVERSION)
92
93OBJ = $@
94N =
95
f7d82350
SR
96EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
97
fe316723
JO
98LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
99LIB_INSTALL = libtraceevent.a libtraceevent.so*
838f8f97 100LIB_INSTALL := $(addprefix $(OUTPUT),$(LIB_INSTALL))
fe316723 101
2d58ab9b 102INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
f7d82350 103
2d58ab9b
JO
104# Set compile option CFLAGS
105ifdef EXTRA_CFLAGS
106 CFLAGS := $(EXTRA_CFLAGS)
107else
108 CFLAGS := -g -Wall
109endif
f7d82350
SR
110
111# Append required CFLAGS
2d58ab9b 112override CFLAGS += -fPIC
f7d82350 113override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
c055875b 114override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
f7d82350
SR
115
116ifeq ($(VERBOSE),1)
117 Q =
f7d82350
SR
118else
119 Q = @
f7d82350
SR
120endif
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.
125MAKEOVERRIDES=
f7d82350 126
2d58ab9b
JO
127export srctree OUTPUT CC LD CFLAGS V
128build := -f $(srctree)/tools/build/Makefile.build dir=. obj
f7d82350 129
39944a76
JO
130TE_IN := $(OUTPUT)libtraceevent-in.o
131LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
f7d82350 132
077faf3d 133CMD_TARGETS = $(LIB_TARGET)
f7d82350
SR
134
135TARGETS = $(CMD_TARGETS)
136
077faf3d 137all: all_cmd plugins
f7d82350
SR
138
139all_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 155define 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
163endef
164
165define 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
173endef
174
175ep_version.h: force
176 $(Q)$(N)$(call update_version.h)
177
178VERSION_FILES = ep_version.h
179
180define 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
188endef
189
f7d82350
SR
190tags: 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
195TAGS: force
196 $(RM) TAGS
6545e3a8 197 find . -name '*.[ch]' | xargs etags \
d97f4ef1 198 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
f7d82350 199
c121bdbb
JO
200define do_install_mkdir
201 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
202 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
203 fi
204endef
205
f7d82350 206define do_install
c121bdbb 207 $(call do_install_mkdir,$2); \
722a4984 208 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
f7d82350
SR
209endef
210
a526bf80
SM
211PKG_CONFIG_SOURCE_FILE = libtraceevent.pc
212PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE))
cc03e1a8
TS
213define 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
224endef
225
4c784894 226install_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
231install_pkgconfig:
232 $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \
233 $(call do_install_pkgconfig_file,$(prefix))
234
722a4984
JO
235install_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
242install: install_lib
243
077faf3d 244clean: 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
250PHONY += doc
251doc:
252 $(call descend,Documentation)
253
254PHONY += doc-clean
255doc-clean:
256 $(call descend,Documentation,clean)
257
258PHONY += doc-install
259doc-install:
260 $(call descend,Documentation,install)
261
262PHONY += doc-uninstall
263doc-uninstall:
264 $(call descend,Documentation,uninstall)
265
266PHONY += help
267help:
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
283PHONY += plugins
284plugins:
285 $(call descend,plugins)
286
287PHONY += install_plugins
288install_plugins:
289 $(call descend,plugins,install)
290
291PHONY += clean_plugins
292clean_plugins:
293 $(call descend,plugins,clean)
294
f7d82350
SR
295force:
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)