at v5.0-rc2 321 lines 8.7 kB view raw
1# SPDX-License-Identifier: GPL-2.0 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) 27$(call allow-override,NM,$(CROSS_COMPILE)nm) 28$(call allow-override,PKG_CONFIG,pkg-config) 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 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 47prefix ?= /usr/local 48libdir = $(prefix)/$(libdir_relative) 49man_dir = $(prefix)/share/man 50man_dir_SQ = '$(subst ','\'',$(man_dir))' 51pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \ 52 --variable pc_path pkg-config | tr ":" " ")) 53 54export man_dir man_dir_SQ INSTALL 55export DESTDIR DESTDIR_SQ 56 57set_plugin_dir := 1 58 59# Set plugin_dir to preffered global plugin location 60# If we install under $HOME directory we go under 61# $(HOME)/.traceevent/plugins 62# 63# We dont set PLUGIN_DIR in case we install under $HOME 64# directory, because by default the code looks under: 65# $(HOME)/.traceevent/plugins by default. 66# 67ifeq ($(plugin_dir),) 68ifeq ($(prefix),$(HOME)) 69override plugin_dir = $(HOME)/.traceevent/plugins 70set_plugin_dir := 0 71else 72override plugin_dir = $(libdir)/traceevent/plugins 73endif 74endif 75 76ifeq ($(set_plugin_dir),1) 77PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" 78PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' 79endif 80 81include ../../scripts/Makefile.include 82 83# copy a bit from Linux kbuild 84 85ifeq ("$(origin V)", "command line") 86 VERBOSE = $(V) 87endif 88ifndef VERBOSE 89 VERBOSE = 0 90endif 91 92ifeq ($(srctree),) 93srctree := $(patsubst %/,%,$(dir $(CURDIR))) 94srctree := $(patsubst %/,%,$(dir $(srctree))) 95srctree := $(patsubst %/,%,$(dir $(srctree))) 96#$(info Determined 'srctree' to be $(srctree)) 97endif 98 99export prefix libdir src obj 100 101# Shell quotes 102libdir_SQ = $(subst ','\'',$(libdir)) 103libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) 104plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) 105 106CONFIG_INCLUDES = 107CONFIG_LIBS = 108CONFIG_FLAGS = 109 110VERSION = $(EP_VERSION) 111PATCHLEVEL = $(EP_PATCHLEVEL) 112EXTRAVERSION = $(EP_EXTRAVERSION) 113 114OBJ = $@ 115N = 116 117EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) 118 119LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION) 120LIB_INSTALL = libtraceevent.a libtraceevent.so* 121 122INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES) 123 124# Set compile option CFLAGS 125ifdef EXTRA_CFLAGS 126 CFLAGS := $(EXTRA_CFLAGS) 127else 128 CFLAGS := -g -Wall 129endif 130 131# Append required CFLAGS 132override CFLAGS += -fPIC 133override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 134override CFLAGS += $(udis86-flags) -D_GNU_SOURCE 135 136ifeq ($(VERBOSE),1) 137 Q = 138else 139 Q = @ 140endif 141 142# Disable command line variables (CFLAGS) override from top 143# level Makefile (perf), otherwise build Makefile will get 144# the same command line setup. 145MAKEOVERRIDES= 146 147export srctree OUTPUT CC LD CFLAGS V 148build := -f $(srctree)/tools/build/Makefile.build dir=. obj 149 150PLUGINS = plugin_jbd2.so 151PLUGINS += plugin_hrtimer.so 152PLUGINS += plugin_kmem.so 153PLUGINS += plugin_kvm.so 154PLUGINS += plugin_mac80211.so 155PLUGINS += plugin_sched_switch.so 156PLUGINS += plugin_function.so 157PLUGINS += plugin_xen.so 158PLUGINS += plugin_scsi.so 159PLUGINS += plugin_cfg80211.so 160 161PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS)) 162PLUGINS_IN := $(PLUGINS:.so=-in.o) 163 164TE_IN := $(OUTPUT)libtraceevent-in.o 165LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) 166DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list 167 168CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE) 169 170TARGETS = $(CMD_TARGETS) 171 172all: all_cmd 173 174all_cmd: $(CMD_TARGETS) 175 176$(TE_IN): force 177 $(Q)$(MAKE) $(build)=libtraceevent 178 179$(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN) 180 $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ 181 @ln -sf $(@F) $(OUTPUT)libtraceevent.so 182 @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION) 183 184$(OUTPUT)libtraceevent.a: $(TE_IN) 185 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ 186 187$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS) 188 $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@) 189 190plugins: $(PLUGINS) 191 192__plugin_obj = $(notdir $@) 193 plugin_obj = $(__plugin_obj:-in.o=) 194 195$(PLUGINS_IN): force 196 $(Q)$(MAKE) $(build)=$(plugin_obj) 197 198$(OUTPUT)%.so: $(OUTPUT)%-in.o 199 $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^ 200 201define make_version.h 202 (echo '/* This file is automatically generated. Do not modify. */'; \ 203 echo \#define VERSION_CODE $(shell \ 204 expr $(VERSION) \* 256 + $(PATCHLEVEL)); \ 205 echo '#define EXTRAVERSION ' $(EXTRAVERSION); \ 206 echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \ 207 echo '#define FILE_VERSION '$(FILE_VERSION); \ 208 ) > $1 209endef 210 211define update_version.h 212 ($(call make_version.h, $@.tmp); \ 213 if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 214 rm -f $@.tmp; \ 215 else \ 216 echo ' UPDATE $@'; \ 217 mv -f $@.tmp $@; \ 218 fi); 219endef 220 221ep_version.h: force 222 $(Q)$(N)$(call update_version.h) 223 224VERSION_FILES = ep_version.h 225 226define update_dir 227 (echo $1 > $@.tmp; \ 228 if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 229 rm -f $@.tmp; \ 230 else \ 231 echo ' UPDATE $@'; \ 232 mv -f $@.tmp $@; \ 233 fi); 234endef 235 236tags: force 237 $(RM) tags 238 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ 239 --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' 240 241TAGS: force 242 $(RM) TAGS 243 find . -name '*.[ch]' | xargs etags \ 244 --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' 245 246define do_install_mkdir 247 if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ 248 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ 249 fi 250endef 251 252define do_install 253 $(call do_install_mkdir,$2); \ 254 $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' 255endef 256 257define do_install_plugins 258 for plugin in $1; do \ 259 $(call do_install,$$plugin,$(plugin_dir_SQ)); \ 260 done 261endef 262 263define do_generate_dynamic_list_file 264 symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \ 265 xargs echo "U W w" | tr ' ' '\n' | sort -u | xargs echo`;\ 266 if [ "$$symbol_type" = "U W w" ];then \ 267 (echo '{'; \ 268 $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u;\ 269 echo '};'; \ 270 ) > $2; \ 271 else \ 272 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\ 273 fi 274endef 275 276PKG_CONFIG_FILE = libtraceevent.pc 277define do_install_pkgconfig_file 278 if [ -n "${pkgconfig_dir}" ]; then \ 279 cp -f ${PKG_CONFIG_FILE}.template ${PKG_CONFIG_FILE}; \ 280 sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \ 281 sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \ 282 $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \ 283 else \ 284 (echo Failed to locate pkg-config directory) 1>&2; \ 285 fi 286endef 287 288install_lib: all_cmd install_plugins install_headers install_pkgconfig 289 $(call QUIET_INSTALL, $(LIB_TARGET)) \ 290 $(call do_install_mkdir,$(libdir_SQ)); \ 291 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ) 292 293install_plugins: $(PLUGINS) 294 $(call QUIET_INSTALL, trace_plugins) \ 295 $(call do_install_plugins, $(PLUGINS)) 296 297install_pkgconfig: 298 $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \ 299 $(call do_install_pkgconfig_file,$(prefix)) 300 301install_headers: 302 $(call QUIET_INSTALL, headers) \ 303 $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \ 304 $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \ 305 $(call do_install,trace-seq.h,$(prefix)/include/traceevent,644); \ 306 $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644) 307 308install: install_lib 309 310clean: 311 $(call QUIET_CLEAN, libtraceevent) \ 312 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ 313 $(RM) TRACEEVENT-CFLAGS tags TAGS; \ 314 $(RM) $(PKG_CONFIG_FILE) 315 316PHONY += force plugins 317force: 318 319# Declare the contents of the .PHONY variable as phony. We keep that 320# information in a variable so we can use it in if_changed and friends. 321.PHONY: $(PHONY)