diff mbox series

[V2,1/3] tools/tracing: Use tools/build makefiles on latency-collector

Message ID f2851351a1561a59a273a64de561022b1af4edcf.1710512430.git.bristot@kernel.org (mailing list archive)
State Superseded
Headers show
Series tools/tracing: Use tools/build makefiles like perf | expand

Commit Message

Daniel Bristot de Oliveira March 15, 2024, 2:24 p.m. UTC
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.

Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Daniel Bristot de Oliveira <bristot@kernel.org>
---
 tools/tracing/latency/.gitignore      |   5 +-
 tools/tracing/latency/Build           |   1 +
 tools/tracing/latency/Makefile        | 105 +++++++++++++++++++++-----
 tools/tracing/latency/Makefile.config |  30 ++++++++
 4 files changed, 122 insertions(+), 19 deletions(-)
 create mode 100644 tools/tracing/latency/Build
 create mode 100644 tools/tracing/latency/Makefile.config

Comments

Daniel Bristot de Oliveira March 15, 2024, 2:48 p.m. UTC | #1
On 3/15/24 15:24, Daniel Bristot de Oliveira wrote:
> 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:
> 
> -------------------------------- %< -------------------------------

Oops, b4 is interpreting these ------ as the '---' separator, and is truncating
the message. I will fix this in a v3.

sorry.

-- Daniel
Arnaldo Carvalho de Melo March 15, 2024, 2:53 p.m. UTC | #2
On Fri, Mar 15, 2024 at 03:48:58PM +0100, Daniel Bristot de Oliveira wrote:
> On 3/15/24 15:24, Daniel Bristot de Oliveira wrote:
> > 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:
> > 
> > -------------------------------- %< -------------------------------
> 
> Oops, b4 is interpreting these ------ as the '---' separator, and is truncating
> the message. I will fix this in a v3.
> 
> sorry.

Yeah, that confuses scripts, that separator.

But overall I tested various versions of your patches and they look ok.

That tools/build/ was done for other tools to use and so far some tools/
living projects use it: tools/objtool, tools/lib/subcmd, etc.

I just did a:

git grep tools\/build

And there is quite a few more I didn't realize have been using bits and
pieces, good.

- Arnaldo
Daniel Bristot de Oliveira March 15, 2024, 3:17 p.m. UTC | #3
On 3/15/24 15:53, Arnaldo Carvalho de Melo wrote:
> On Fri, Mar 15, 2024 at 03:48:58PM +0100, Daniel Bristot de Oliveira wrote:
>> On 3/15/24 15:24, Daniel Bristot de Oliveira wrote:
>>> 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:
>>>
>>> -------------------------------- %< -------------------------------
>>
>> Oops, b4 is interpreting these ------ as the '---' separator, and is truncating
>> the message. I will fix this in a v3.
>>
>> sorry.
> 
> Yeah, that confuses scripts, that separator.

checkpatch did not point that as an error, and git am works as well.... but it
indeed confuses other scripts...

Thanks, Arnaldo.
-- Daniel
diff mbox series

Patch

diff --git a/tools/tracing/latency/.gitignore b/tools/tracing/latency/.gitignore
index 0863960761e7..2bb8e60f7fdd 100644
--- a/tools/tracing/latency/.gitignore
+++ b/tools/tracing/latency/.gitignore
@@ -1,2 +1,5 @@ 
-# SPDX-License-Identifier: GPL-2.0
+# SPDX-License-Identifier: GPL-2.0-only
 latency-collector
+fixdep
+feature
+FEATURE-DUMP
diff --git a/tools/tracing/latency/Build b/tools/tracing/latency/Build
new file mode 100644
index 000000000000..0ce65ea72bf9
--- /dev/null
+++ b/tools/tracing/latency/Build
@@ -0,0 +1 @@ 
+latency-collector-y += latency-collector.o
diff --git a/tools/tracing/latency/Makefile b/tools/tracing/latency/Makefile
index 40c4ddaf8be1..6518b03e05c7 100644
--- a/tools/tracing/latency/Makefile
+++ b/tools/tracing/latency/Makefile
@@ -1,24 +1,93 @@ 
-# 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)
+# SPDX-License-Identifier: GPL-2.0-only
 
-TARGETS = latency-collector
-CFLAGS = -Wall -Wextra -g -O2 $(VAR_CFLAGS)
-LDFLAGS = -lpthread $(VAR_LDLIBS)
+ifeq ($(srctree),)
+  srctree	:= $(patsubst %/,%,$(dir $(CURDIR)))
+  srctree	:= $(patsubst %/,%,$(dir $(srctree)))
+  srctree	:= $(patsubst %/,%,$(dir $(srctree)))
+endif
 
-all: $(TARGETS)
+include $(srctree)/tools/scripts/Makefile.include
 
-%: %.c
-	$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+# O is an alias for OUTPUT
+OUTPUT		:= $(O)
 
-clean:
-	$(RM) latency-collector
+ifeq ($(OUTPUT),)
+  OUTPUT	:= $(CURDIR)
+else
+  # subdir is used by the ../Makefile in $(call descend,)
+  ifneq ($(subdir),)
+    OUTPUT	:= $(OUTPUT)/$(subdir)
+  endif
+endif
+
+ifneq ($(patsubst %/,,$(lastword $(OUTPUT))),)
+  OUTPUT	:= $(OUTPUT)/
+endif
+
+LATENCY-COLLECTOR	:= $(OUTPUT)latency-collector
+LATENCY-COLLECTOR_IN	:= $(LATENCY-COLLECTOR)-in.o
+
+export CC	:= gcc
+export LD	:= ld
+export AR	:= ar
+export PKG_CONFIG := pkg-config
+
+FEATURE_TESTS	:= libtraceevent
+FEATURE_TESTS	+= libtracefs
+FEATURE_DISPLAY	:= libtraceevent
+FEATURE_DISPLAY	+= libtracefs
+
+ifeq ($(V),1)
+  Q 		=
+else
+  Q 		= @
+endif
+
+all: $(LATENCY-COLLECTOR)
+
+include $(srctree)/tools/build/Makefile.include
+
+# check for dependencies only on required targets
+NON_CONFIG_TARGETS := clean install
 
-prefix ?= /usr/local
-sbindir ?= ${prefix}/sbin
+config		:= 1
+ifdef MAKECMDGOALS
+ifeq ($(filter-out $(NON_CONFIG_TARGETS),$(MAKECMDGOALS)),)
+ config		:= 0
+endif
+endif
 
-install: all
-	install -d $(DESTDIR)$(sbindir)
-	install -m 755 -p $(TARGETS) $(DESTDIR)$(sbindir)
+ifeq ($(config),1)
+  include $(srctree)/tools/build/Makefile.feature
+  include Makefile.config
+endif
+
+CFLAGS		+= $(INCLUDES) $(LIB_INCLUDES)
+
+export CFLAGS OUTPUT srctree
+
+$(LATENCY-COLLECTOR): $(LATENCY-COLLECTOR_IN)
+	$(QUIET_LINK)$(CC) $(LDFLAGS) -o $(LATENCY-COLLECTOR) $(LATENCY-COLLECTOR_IN) $(EXTLIBS)
+
+latency-collector.%: fixdep FORCE
+	make -f $(srctree)/tools/build/Makefile.build dir=. $@
+
+$(LATENCY-COLLECTOR_IN): fixdep FORCE
+	make $(build)=latency-collector
+
+INSTALL		:= install
+MKDIR		:= mkdir
+STRIP		:= strip
+BINDIR		:= /usr/bin
+
+install:
+	@$(MKDIR) -p $(DESTDIR)$(BINDIR)
+	$(call QUIET_INSTALL,latency-collector)$(INSTALL) $(LATENCY-COLLECTOR) -m 755 $(DESTDIR)$(BINDIR)
+	@$(STRIP) $(DESTDIR)$(BINDIR)/latency-collector
+
+clean:
+	$(call QUIET_CLEAN, latency-collector)
+	$(Q)find . -name '*.o' -delete -o -name '\.*.cmd' -delete -o -name '\.*.d' -delete
+	$(Q)@rm -f latency-collector fixdep FEATURE-DUMP
+	$(Q)rm -rf feature
+.PHONY: FORCE clean install
diff --git a/tools/tracing/latency/Makefile.config b/tools/tracing/latency/Makefile.config
new file mode 100644
index 000000000000..b25e531a1f95
--- /dev/null
+++ b/tools/tracing/latency/Makefile.config
@@ -0,0 +1,30 @@ 
+# SPDX-License-Identifier: GPL-2.0-only
+
+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