2012-04-06 06:47:53 +08:00
|
|
|
# trace-cmd version
|
|
|
|
EP_VERSION = 1
|
|
|
|
EP_PATCHLEVEL = 1
|
|
|
|
EP_EXTRAVERSION = 0
|
|
|
|
|
|
|
|
# file format version
|
|
|
|
FILE_VERSION = 6
|
|
|
|
|
|
|
|
MAKEFLAGS += --no-print-directory
|
|
|
|
|
|
|
|
|
|
|
|
# Makefiles suck: This macro sets a default value of $(2) for the
|
|
|
|
# variable named by $(1), unless the variable has been set by
|
|
|
|
# environment or command line. This is necessary for CC and AR
|
|
|
|
# because make sets default values, so the simpler ?= approach
|
|
|
|
# won't work as expected.
|
|
|
|
define allow-override
|
|
|
|
$(if $(or $(findstring environment,$(origin $(1))),\
|
|
|
|
$(findstring command line,$(origin $(1)))),,\
|
|
|
|
$(eval $(1) = $(2)))
|
|
|
|
endef
|
|
|
|
|
|
|
|
# Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
|
|
|
|
$(call allow-override,CC,$(CROSS_COMPILE)gcc)
|
|
|
|
$(call allow-override,AR,$(CROSS_COMPILE)ar)
|
|
|
|
|
|
|
|
EXT = -std=gnu99
|
|
|
|
INSTALL = install
|
|
|
|
|
|
|
|
# Use DESTDIR for installing into a different root directory.
|
|
|
|
# This is useful for building a package. The program will be
|
|
|
|
# installed in this directory as if it was the root directory.
|
|
|
|
# Then the build tool can move it later.
|
|
|
|
DESTDIR ?=
|
|
|
|
DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
|
|
|
|
|
|
|
|
prefix ?= /usr/local
|
|
|
|
bindir_relative = bin
|
|
|
|
bindir = $(prefix)/$(bindir_relative)
|
|
|
|
man_dir = $(prefix)/share/man
|
|
|
|
man_dir_SQ = '$(subst ','\'',$(man_dir))'
|
|
|
|
|
2013-06-04 13:20:16 +08:00
|
|
|
export man_dir man_dir_SQ INSTALL
|
2012-04-06 06:47:53 +08:00
|
|
|
export DESTDIR DESTDIR_SQ
|
|
|
|
|
2013-12-03 21:09:17 +08:00
|
|
|
set_plugin_dir := 1
|
|
|
|
|
|
|
|
# Set plugin_dir to preffered global plugin location
|
|
|
|
# If we install under $HOME directory we go under
|
|
|
|
# $(HOME)/.traceevent/plugins
|
|
|
|
#
|
|
|
|
# We dont set PLUGIN_DIR in case we install under $HOME
|
|
|
|
# directory, because by default the code looks under:
|
|
|
|
# $(HOME)/.traceevent/plugins by default.
|
|
|
|
#
|
|
|
|
ifeq ($(plugin_dir),)
|
|
|
|
ifeq ($(prefix),$(HOME))
|
|
|
|
override plugin_dir = $(HOME)/.traceevent/plugins
|
|
|
|
set_plugin_dir := 0
|
|
|
|
else
|
|
|
|
override plugin_dir = $(prefix)/lib/traceevent/plugins
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(set_plugin_dir),1)
|
2014-01-22 23:01:48 +08:00
|
|
|
PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
|
2013-12-03 21:09:17 +08:00
|
|
|
PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
|
|
|
|
endif
|
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
include ../../scripts/Makefile.include
|
2013-12-19 21:42:02 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
# copy a bit from Linux kbuild
|
|
|
|
|
|
|
|
ifeq ("$(origin V)", "command line")
|
|
|
|
VERBOSE = $(V)
|
|
|
|
endif
|
|
|
|
ifndef VERBOSE
|
|
|
|
VERBOSE = 0
|
|
|
|
endif
|
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
ifeq ($(srctree),)
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(shell pwd)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
srctree := $(patsubst %/,%,$(dir $(srctree)))
|
|
|
|
#$(info Determined 'srctree' to be $(srctree))
|
2012-04-06 06:47:53 +08:00
|
|
|
endif
|
|
|
|
|
|
|
|
export prefix bindir src obj
|
|
|
|
|
|
|
|
# Shell quotes
|
|
|
|
bindir_SQ = $(subst ','\'',$(bindir))
|
|
|
|
bindir_relative_SQ = $(subst ','\'',$(bindir_relative))
|
2013-12-03 21:09:17 +08:00
|
|
|
plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
LIB_FILE = libtraceevent.a libtraceevent.so
|
|
|
|
|
|
|
|
CONFIG_INCLUDES =
|
|
|
|
CONFIG_LIBS =
|
|
|
|
CONFIG_FLAGS =
|
|
|
|
|
|
|
|
VERSION = $(EP_VERSION)
|
|
|
|
PATCHLEVEL = $(EP_PATCHLEVEL)
|
|
|
|
EXTRAVERSION = $(EP_EXTRAVERSION)
|
|
|
|
|
|
|
|
OBJ = $@
|
|
|
|
N =
|
|
|
|
|
|
|
|
EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
|
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
# Set compile option CFLAGS
|
|
|
|
ifdef EXTRA_CFLAGS
|
|
|
|
CFLAGS := $(EXTRA_CFLAGS)
|
|
|
|
else
|
|
|
|
CFLAGS := -g -Wall
|
|
|
|
endif
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
# Append required CFLAGS
|
2015-01-08 01:39:45 +08:00
|
|
|
override CFLAGS += -fPIC
|
2012-04-06 06:47:53 +08:00
|
|
|
override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
|
2012-09-13 01:29:40 +08:00
|
|
|
override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
ifeq ($(VERBOSE),1)
|
|
|
|
Q =
|
|
|
|
else
|
|
|
|
Q = @
|
|
|
|
endif
|
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
# Disable command line variables (CFLAGS) overide from top
|
|
|
|
# level Makefile (perf), otherwise build Makefile will get
|
|
|
|
# the same command line setup.
|
|
|
|
MAKEOVERRIDES=
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
export srctree OUTPUT CC LD CFLAGS V
|
|
|
|
build := -f $(srctree)/tools/build/Makefile.build dir=. obj
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
PLUGINS = plugin_jbd2.so
|
|
|
|
PLUGINS += plugin_hrtimer.so
|
|
|
|
PLUGINS += plugin_kmem.so
|
|
|
|
PLUGINS += plugin_kvm.so
|
|
|
|
PLUGINS += plugin_mac80211.so
|
|
|
|
PLUGINS += plugin_sched_switch.so
|
|
|
|
PLUGINS += plugin_function.so
|
|
|
|
PLUGINS += plugin_xen.so
|
|
|
|
PLUGINS += plugin_scsi.so
|
|
|
|
PLUGINS += plugin_cfg80211.so
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS))
|
|
|
|
PLUGINS_IN := $(PLUGINS:.so=-in.o)
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
TE_IN := $(OUTPUT)libtraceevent-in.o
|
|
|
|
LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2013-12-03 21:09:17 +08:00
|
|
|
CMD_TARGETS = $(LIB_FILE) $(PLUGINS)
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
TARGETS = $(CMD_TARGETS)
|
|
|
|
|
|
|
|
all: all_cmd
|
|
|
|
|
|
|
|
all_cmd: $(CMD_TARGETS)
|
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
$(TE_IN): force
|
|
|
|
$(Q)$(MAKE) $(build)=libtraceevent
|
|
|
|
|
|
|
|
$(OUTPUT)libtraceevent.so: $(TE_IN)
|
2013-12-19 21:42:04 +08:00
|
|
|
$(QUIET_LINK)$(CC) --shared $^ -o $@
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
$(OUTPUT)libtraceevent.a: $(TE_IN)
|
2013-12-19 21:42:04 +08:00
|
|
|
$(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2013-12-03 21:09:17 +08:00
|
|
|
plugins: $(PLUGINS)
|
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
__plugin_obj = $(notdir $@)
|
|
|
|
plugin_obj = $(__plugin_obj:-in.o=)
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
$(PLUGINS_IN): force
|
|
|
|
$(Q)$(MAKE) $(build)=$(plugin_obj)
|
2013-12-03 21:09:17 +08:00
|
|
|
|
2015-01-08 01:39:45 +08:00
|
|
|
$(OUTPUT)%.so: $(OUTPUT)%-in.o
|
|
|
|
$(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^
|
2013-12-03 21:09:17 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
define make_version.h
|
2014-01-02 17:53:04 +08:00
|
|
|
(echo '/* This file is automatically generated. Do not modify. */'; \
|
|
|
|
echo \#define VERSION_CODE $(shell \
|
|
|
|
expr $(VERSION) \* 256 + $(PATCHLEVEL)); \
|
|
|
|
echo '#define EXTRAVERSION ' $(EXTRAVERSION); \
|
|
|
|
echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \
|
|
|
|
echo '#define FILE_VERSION '$(FILE_VERSION); \
|
|
|
|
) > $1
|
2012-04-06 06:47:53 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
define update_version.h
|
2014-01-02 17:53:04 +08:00
|
|
|
($(call make_version.h, $@.tmp); \
|
|
|
|
if [ -r $@ ] && cmp -s $@ $@.tmp; then \
|
|
|
|
rm -f $@.tmp; \
|
|
|
|
else \
|
|
|
|
echo ' UPDATE $@'; \
|
|
|
|
mv -f $@.tmp $@; \
|
|
|
|
fi);
|
2012-04-06 06:47:53 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
ep_version.h: force
|
|
|
|
$(Q)$(N)$(call update_version.h)
|
|
|
|
|
|
|
|
VERSION_FILES = ep_version.h
|
|
|
|
|
|
|
|
define update_dir
|
2014-01-02 17:53:04 +08:00
|
|
|
(echo $1 > $@.tmp; \
|
|
|
|
if [ -r $@ ] && cmp -s $@ $@.tmp; then \
|
|
|
|
rm -f $@.tmp; \
|
|
|
|
else \
|
|
|
|
echo ' UPDATE $@'; \
|
|
|
|
mv -f $@.tmp $@; \
|
|
|
|
fi);
|
2012-04-06 06:47:53 +08:00
|
|
|
endef
|
|
|
|
|
|
|
|
tags: force
|
|
|
|
$(RM) tags
|
2012-06-22 16:10:14 +08:00
|
|
|
find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
|
|
|
|
--regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
TAGS: force
|
|
|
|
$(RM) TAGS
|
2012-06-22 16:10:14 +08:00
|
|
|
find . -name '*.[ch]' | xargs etags \
|
|
|
|
--regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
|
2012-04-06 06:47:53 +08:00
|
|
|
|
|
|
|
define do_install
|
|
|
|
if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
|
|
|
|
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
|
|
|
|
fi; \
|
|
|
|
$(INSTALL) $1 '$(DESTDIR_SQ)$2'
|
|
|
|
endef
|
|
|
|
|
2013-12-19 21:42:05 +08:00
|
|
|
define do_install_plugins
|
|
|
|
for plugin in $1; do \
|
|
|
|
$(call do_install,$$plugin,$(plugin_dir_SQ)); \
|
|
|
|
done
|
|
|
|
endef
|
2013-12-03 21:09:17 +08:00
|
|
|
|
2013-12-19 21:42:05 +08:00
|
|
|
install_lib: all_cmd install_plugins
|
|
|
|
$(call QUIET_INSTALL, $(LIB_FILE)) \
|
|
|
|
$(call do_install,$(LIB_FILE),$(bindir_SQ))
|
2013-12-03 21:09:17 +08:00
|
|
|
|
2013-12-19 21:42:05 +08:00
|
|
|
install_plugins: $(PLUGINS)
|
|
|
|
$(call QUIET_INSTALL, trace_plugins) \
|
|
|
|
$(call do_install_plugins, $(PLUGINS))
|
2013-12-03 21:09:17 +08:00
|
|
|
|
2012-04-06 06:47:53 +08:00
|
|
|
install: install_lib
|
|
|
|
|
|
|
|
clean:
|
2013-12-19 21:42:06 +08:00
|
|
|
$(call QUIET_CLEAN, libtraceevent) \
|
|
|
|
$(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d \
|
|
|
|
$(RM) TRACEEVENT-CFLAGS tags TAGS
|
2012-04-06 06:47:53 +08:00
|
|
|
|
2014-01-02 00:50:50 +08:00
|
|
|
PHONY += force plugins
|
2012-04-06 06:47:53 +08:00
|
|
|
force:
|
|
|
|
|
|
|
|
# Declare the contents of the .PHONY variable as phony. We keep that
|
|
|
|
# information in a variable so we can use it in if_changed and friends.
|
|
|
|
.PHONY: $(PHONY)
|