diff mbox series

[05/11] libtracefs: Make samples easily extract man page example programs

Message ID 20211122234956.788401-6-rostedt@goodmis.org (mailing list archive)
State Accepted
Commit 9ea357e77ace2ab97eb80eb5d8c8bc2dcdb19bad
Headers show
Series libtracefs: Have all man page examples be executable | expand

Commit Message

Steven Rostedt Nov. 22, 2021, 11:49 p.m. UTC
From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Have the Makefile in the samples directory extract examples out of the man
pages and create them as executables in the bin directory.

This adds the infrastructure to do so, and includes the dynevent example.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Makefile         |  3 +++
 samples/Makefile | 26 +++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 7c96674..85b3c39 100644
--- a/Makefile
+++ b/Makefile
@@ -370,6 +370,9 @@  samples/sqlhist: $(LIBTRACEFS_STATIC)
 
 sqlhist: samples/sqlhist
 
+samples: $(LIBTRACEFS_STATIC) force
+	$(Q)$(MAKE) -C $(src)/samples all
+
 clean:
 	$(MAKE) -C $(src)/utest clean
 	$(MAKE) -C $(src)/src clean
diff --git a/samples/Makefile b/samples/Makefile
index aae3e27..53b6630 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -7,20 +7,36 @@ 
 
 include $(src)/scripts/utils.mk
 
+TARGETS :=
+TARGETS += sqlhist
+TARGETS += dynevent
+
 bdir := $(obj)/bin
 
+all: $(TARGETS)
+
+extract_example = \
+	cat $1 | sed -ne '/^EXAMPLE/,/FILES/ { /EXAMPLE/,+2d ; /^FILES/d ;  /^--/d ; p}' > $2
+
+$(bdir)/sqlhist.c: ../Documentation/libtracefs-sql.txt
+	$(call extract_example,$<,$@)
+
+$(bdir)/dynevent.c: ../Documentation/libtracefs-dynevents.txt
+	$(call extract_example,$<,$@)
+
 $(bdir):
 	@mkdir -p $(bdir)
 
 sqlhist: $(bdir) $(bdir) $(bdir)/sqlhist
 
-$(bdir)/sqlhist: $(bdir)/sqlhist.o $(LIBTRACEFS_STATIC)
-	$(CC) -o $@ $^ $(LIBTRACEEVENT_LIBS)
+$(TARGETS): $(bdir)
 
-$(bdir)/sqlhist.c: ../Documentation/libtracefs-sql.txt
-	cat $< | sed -ne '/^EXAMPLE/,/FILES/ { /EXAMPLE/,+2d ; /^FILES/d ;  /^--/d ; p}' > $@
+$(bdir)/%: $(bdir)/%.o
+	$(CC) -o $@ $^ $(LIBTRACEFS_STATIC) $(LIBTRACEEVENT_LIBS)
+
+$(TARGETS): $(patsubst %,$(bdir)/%,$(TARGETS))
 
-$(bdir)/sqlhist.o: $(bdir)/sqlhist.c
+$(bdir)/%.o: %.c
 	$(CC) -g -Wall -c -o $@ $^ -I../include/ $(LIBTRACEEVENT_INCLUDES)
 
 clean: