@@ -1,2 +1,3 @@
# SPDX-License-Identifier: GPL-2.0
latency-collector
+FEATURE-DUMP
new file mode 100644
@@ -0,0 +1 @@
+latency-collector-y += latency-collector.o
@@ -1,24 +1,38 @@
# SPDX-License-Identifier: GPL-2.0
-# Makefile for vm tools
-#
-VAR_CFLAGS := $(shell pkg-config --cflags libtracefs 2>/dev/null)
-VAR_LDLIBS := $(shell pkg-config --libs libtracefs 2>/dev/null)
+export srctree := $(abspath ../../..)
+export CC := gcc
+export LD := ld
+export AR := ar
+export PKG_CONFIG := pkg-config
-TARGETS = latency-collector
-CFLAGS = -Wall -Wextra -g -O2 $(VAR_CFLAGS)
-LDFLAGS = -lpthread $(VAR_LDLIBS)
+FEATURE_TESTS := libtraceevent
+FEATURE_TESTS += libtracefs
+FEATURE_DISPLAY := libtraceevent
+FEATURE_DISPLAY += libtracefs
-all: $(TARGETS)
+latency-collector:
-%: %.c
- $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+include $(srctree)/tools/build/Makefile.include
+include $(srctree)/tools/build/Makefile.feature
+include $(srctree)/tools/scripts/Makefile.include
+include Makefile.config
-clean:
- $(RM) latency-collector
+CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
+
+export CFLAGS := $(CFLAGS)
+
+latency-collector: latency-collector-in.o
+ $(QUIET_LINK)$(CC) $(LDFLAGS) -o $@ $^ $(EXTLIBS)
-prefix ?= /usr/local
-sbindir ?= ${prefix}/sbin
+latency-collector.%: fixdep FORCE
+ make -f $(srctree)/tools/build/Makefile.build dir=. $@
+
+latency-collector-in.o: fixdep FORCE
+ make $(build)=latency-collector
+
+clean:
+ $(call QUIET_CLEAN, latency-collector)
+ @find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
+ @rm -f latency-collector FEATURE-DUMP
-install: all
- install -d $(DESTDIR)$(sbindir)
- install -m 755 -p $(TARGETS) $(DESTDIR)$(sbindir)
+.PHONY: FORCE clean
new file mode 100644
@@ -0,0 +1,28 @@
+STOP_ERROR :=
+
+define lib_setup
+ $(eval EXTLIBS += -l$(1))
+ $(eval LIB_INCLUDES += $(shell sh -c "$(PKG_CONFIG) --cflags lib$(1)"))
+endef
+
+$(call feature_check,libtraceevent)
+ifeq ($(feature-libtraceevent), 1)
+ $(call detected,CONFIG_LIBTRACEEVENT)
+ $(call lib_setup,traceevent)
+else
+ STOP_ERROR := 1
+ $(info libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel)
+endif
+
+$(call feature_check,libtracefs)
+ifeq ($(feature-libtracefs), 1)
+ $(call detected,CONFIG_LIBTRACEFS)
+ $(call lib_setup,tracefs)
+else
+ STOP_ERROR := 1
+ $(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel)
+endif
+
+ifeq ($(STOP_ERROR),1)
+ $(error Please, check the errors above.)
+endif
Use tools/build/ makefiles to build latency-collector, inheriting the benefits of it. For example, having a proper way to handle dependencies. Inspired on perf and objtool. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org> --- tools/tracing/latency/.gitignore | 1 + tools/tracing/latency/Build | 1 + tools/tracing/latency/Makefile | 48 +++++++++++++++++---------- tools/tracing/latency/Makefile.config | 28 ++++++++++++++++ 4 files changed, 61 insertions(+), 17 deletions(-) create mode 100644 tools/tracing/latency/Build create mode 100644 tools/tracing/latency/Makefile.config