Skip to content

Commit 9d56c88

Browse files
author
Daniel Bristot de Oliveira
committed
tools/tracing: Use tools/build makefiles on latency-collector
Use tools/build/ makefiles to build latency-collector, inheriting the benefits of it. For example: Before this patch, a missing tracefs/traceevents headers will result in fail like this: ~/linux/tools/tracing/latency $ make cc -Wall -Wextra -g -O2 -o latency-collector latency-collector.c -lpthread latency-collector.c:26:10: fatal error: tracefs.h: No such file or directory 26 | #include <tracefs.h> | ^~~~~~~~~~~ compilation terminated. make: *** [Makefile:14: latency-collector] Error 1 Which is not that helpful. After this change it reports: ~/linux/tools/tracing/latency# make Auto-detecting system features: ... libtraceevent: [ OFF ] ... libtracefs: [ OFF ] libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel libtracefs is missing. Please install libtracefs-dev/libtracefs-devel Makefile.config:29: *** Please, check the errors above.. Stop. This type of output is common across other tools in tools/ like perf and objtool. Link: https://lkml.kernel.org/r/872420b0880b11304e4ba144a0086c6478c5b469.1710519524.git.bristot@kernel.org Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Josh Poimboeuf <jpoimboe@kernel.org> Cc: John Kacur <jkacur@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
1 parent e8f897f commit 9d56c88

File tree

4 files changed

+122
-19
lines changed

4 files changed

+122
-19
lines changed

tools/tracing/latency/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# SPDX-License-Identifier: GPL-2.0
1+
# SPDX-License-Identifier: GPL-2.0-only
22
latency-collector
3+
fixdep
4+
feature
5+
FEATURE-DUMP

tools/tracing/latency/Build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
latency-collector-y += latency-collector.o

tools/tracing/latency/Makefile

Lines changed: 87 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,93 @@
1-
# SPDX-License-Identifier: GPL-2.0
2-
# Makefile for vm tools
3-
#
4-
VAR_CFLAGS := $(shell pkg-config --cflags libtracefs 2>/dev/null)
5-
VAR_LDLIBS := $(shell pkg-config --libs libtracefs 2>/dev/null)
1+
# SPDX-License-Identifier: GPL-2.0-only
62

7-
TARGETS = latency-collector
8-
CFLAGS = -Wall -Wextra -g -O2 $(VAR_CFLAGS)
9-
LDFLAGS = -lpthread $(VAR_LDLIBS)
3+
ifeq ($(srctree),)
4+
srctree := $(patsubst %/,%,$(dir $(CURDIR)))
5+
srctree := $(patsubst %/,%,$(dir $(srctree)))
6+
srctree := $(patsubst %/,%,$(dir $(srctree)))
7+
endif
108

11-
all: $(TARGETS)
9+
include $(srctree)/tools/scripts/Makefile.include
1210

13-
%: %.c
14-
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
11+
# O is an alias for OUTPUT
12+
OUTPUT := $(O)
1513

16-
clean:
17-
$(RM) latency-collector
14+
ifeq ($(OUTPUT),)
15+
OUTPUT := $(CURDIR)
16+
else
17+
# subdir is used by the ../Makefile in $(call descend,)
18+
ifneq ($(subdir),)
19+
OUTPUT := $(OUTPUT)/$(subdir)
20+
endif
21+
endif
22+
23+
ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
24+
OUTPUT := $(OUTPUT)/
25+
endif
26+
27+
LATENCY-COLLECTOR := $(OUTPUT)latency-collector
28+
LATENCY-COLLECTOR_IN := $(LATENCY-COLLECTOR)-in.o
29+
30+
export CC := gcc
31+
export LD := ld
32+
export AR := ar
33+
export PKG_CONFIG := pkg-config
34+
35+
FEATURE_TESTS := libtraceevent
36+
FEATURE_TESTS += libtracefs
37+
FEATURE_DISPLAY := libtraceevent
38+
FEATURE_DISPLAY += libtracefs
39+
40+
ifeq ($(V),1)
41+
Q =
42+
else
43+
Q = @
44+
endif
45+
46+
all: $(LATENCY-COLLECTOR)
47+
48+
include $(srctree)/tools/build/Makefile.include
49+
50+
# check for dependencies only on required targets
51+
NON_CONFIG_TARGETS := clean install
1852

19-
prefix ?= /usr/local
20-
sbindir ?= ${prefix}/sbin
53+
config := 1
54+
ifdef MAKECMDGOALS
55+
ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
56+
config := 0
57+
endif
58+
endif
2159

22-
install: all
23-
install -d $(DESTDIR)$(sbindir)
24-
install -m 755 -p $(TARGETS) $(DESTDIR)$(sbindir)
60+
ifeq ($(config),1)
61+
include $(srctree)/tools/build/Makefile.feature
62+
include Makefile.config
63+
endif
64+
65+
CFLAGS += $(INCLUDES) $(LIB_INCLUDES)
66+
67+
export CFLAGS OUTPUT srctree
68+
69+
$(LATENCY-COLLECTOR): $(LATENCY-COLLECTOR_IN)
70+
$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(LATENCY-COLLECTOR) $(LATENCY-COLLECTOR_IN) $(EXTLIBS)
71+
72+
latency-collector.%: fixdep FORCE
73+
make -f $(srctree)/tools/build/Makefile.build dir=. $@
74+
75+
$(LATENCY-COLLECTOR_IN): fixdep FORCE
76+
make $(build)=latency-collector
77+
78+
INSTALL := install
79+
MKDIR := mkdir
80+
STRIP := strip
81+
BINDIR := /usr/bin
82+
83+
install:
84+
@$(MKDIR) -p $(DESTDIR)$(BINDIR)
85+
$(call QUIET_INSTALL,latency-collector)$(INSTALL) $(LATENCY-COLLECTOR) -m 755 $(DESTDIR)$(BINDIR)
86+
@$(STRIP) $(DESTDIR)$(BINDIR)/latency-collector
87+
88+
clean:
89+
$(call QUIET_CLEAN, latency-collector)
90+
$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
91+
$(Q)@rm -f latency-collector fixdep FEATURE-DUMP
92+
$(Q)rm -rf feature
93+
.PHONY: FORCE clean install
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# SPDX-License-Identifier: GPL-2.0-only
2+
3+
STOP_ERROR :=
4+
5+
define lib_setup
6+
$(eval EXTLIBS += -l$(1))
7+
$(eval LIB_INCLUDES += $(shell sh -c "$(PKG_CONFIG) --cflags lib$(1)"))
8+
endef
9+
10+
$(call feature_check,libtraceevent)
11+
ifeq ($(feature-libtraceevent), 1)
12+
$(call detected,CONFIG_LIBTRACEEVENT)
13+
$(call lib_setup,traceevent)
14+
else
15+
STOP_ERROR := 1
16+
$(info libtraceevent is missing. Please install libtraceevent-dev/libtraceevent-devel)
17+
endif
18+
19+
$(call feature_check,libtracefs)
20+
ifeq ($(feature-libtracefs), 1)
21+
$(call detected,CONFIG_LIBTRACEFS)
22+
$(call lib_setup,tracefs)
23+
else
24+
STOP_ERROR := 1
25+
$(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel)
26+
endif
27+
28+
ifeq ($(STOP_ERROR),1)
29+
$(error Please, check the errors above.)
30+
endif

0 commit comments

Comments
 (0)