public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: [PATCH 03/12] Makefile: Ugly hack to get a "plain" Markdown version of README
Date: Thu, 18 Aug 2022 22:22:26 +0200	[thread overview]
Message-ID: <20220818202235.1591828-4-sbrivio@redhat.com> (raw)
In-Reply-To: <20220818202235.1591828-1-sbrivio@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 2841 bytes --]

Distribution packages reasonably expect to have a human-readable
Markdown version of the README under /usr/share/doc/, but all we have
right now is a heavily web-oriented version.

Introduce a ugly hack to strip web-oriented parts from the current
README and install it.

It should probably work the other way around: a human-readable README
could be used as a source for the web page. But cgit needs a file
that's in the tree, not something that can be built, and
https://passt.top/ is based on cgit. It should eventually be doable
to work around this in cgit, instead.

Reported-by: Benson Muite <benson_muite(a)emailplus.org>
Signed-off-by: Stefano Brivio <sbrivio(a)redhat.com>
---
 Makefile | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index 0de872e..f03d117 100644
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,7 @@ else
 BIN := passt pasta qrap
 endif
 
-all: $(BIN) $(MANPAGES)
+all: $(BIN) $(MANPAGES) docs
 
 static: CFLAGS += -static -DGLIBC_NO_STATIC_NSS
 static: clean all
@@ -123,12 +123,14 @@ valgrind: all
 clean:
 	$(RM) $(BIN) *.o seccomp.h pasta.1 \
 		passt.tar passt.tar.gz *.deb *.rpm \
-		passt.pid
+		passt.pid README.plain.md
 
-install: $(BIN) $(MANPAGES)
+install: $(BIN) $(MANPAGES) docs
 	mkdir -p $(DESTDIR)$(prefix)/bin $(DESTDIR)$(prefix)/share/man/man1
 	cp -d $(BIN) $(DESTDIR)$(prefix)/bin
 	cp -d $(MANPAGES) $(DESTDIR)$(prefix)/share/man/man1
+	mkdir -p $(DESTDIR)$(prefix)/share/doc/passt
+	cp -d README.plain.md $(DESTDIR)$(prefix)/share/doc/passt/README.md
 
 uninstall:
 	$(RM) $(BIN:%=$(DESTDIR)$(prefix)/bin/%)
@@ -147,6 +149,28 @@ pkgs: static
 		--description="User-mode networking for VMs and namespaces" \
 		-k --version=g$(shell git rev-parse --short HEAD) passt.tar.gz
 
+# TODO: This hack makes a "plain" Markdown version of README.md that can be
+# reasonably shipped as documentation file, while the current README.md is
+# definitely intended for web browser consumption. It should probably work the
+# other way around: the web version should be obtained by adding HTML and
+# JavaScript portions to a plain Markdown, instead. However, cgit needs to use
+# a file in the git tree. Find a better way around this.
+docs: README.md
+	@(								\
+		skip=0;							\
+		while read l; do					\
+			case $$l in					\
+			"## Demo")	exit 0		;;		\
+			"<!"*)				;;		\
+			"</"*)		skip=1		;;		\
+			"<"*)		skip=2		;;		\
+			esac;						\
+									\
+			[ $$skip -eq 0 ]	&& echo "$$l";		\
+			[ $$skip -eq 1 ]	&& skip=0;		\
+		done < README.md;					\
+	) > README.plain.md
+
 # Checkers currently disabled for clang-tidy:
 # - llvmlibc-restrict-system-libc-headers
 #	TODO: this is Linux-only for the moment, nice to fix eventually
-- 
@@ -90,7 +90,7 @@ else
 BIN := passt pasta qrap
 endif
 
-all: $(BIN) $(MANPAGES)
+all: $(BIN) $(MANPAGES) docs
 
 static: CFLAGS += -static -DGLIBC_NO_STATIC_NSS
 static: clean all
@@ -123,12 +123,14 @@ valgrind: all
 clean:
 	$(RM) $(BIN) *.o seccomp.h pasta.1 \
 		passt.tar passt.tar.gz *.deb *.rpm \
-		passt.pid
+		passt.pid README.plain.md
 
-install: $(BIN) $(MANPAGES)
+install: $(BIN) $(MANPAGES) docs
 	mkdir -p $(DESTDIR)$(prefix)/bin $(DESTDIR)$(prefix)/share/man/man1
 	cp -d $(BIN) $(DESTDIR)$(prefix)/bin
 	cp -d $(MANPAGES) $(DESTDIR)$(prefix)/share/man/man1
+	mkdir -p $(DESTDIR)$(prefix)/share/doc/passt
+	cp -d README.plain.md $(DESTDIR)$(prefix)/share/doc/passt/README.md
 
 uninstall:
 	$(RM) $(BIN:%=$(DESTDIR)$(prefix)/bin/%)
@@ -147,6 +149,28 @@ pkgs: static
 		--description="User-mode networking for VMs and namespaces" \
 		-k --version=g$(shell git rev-parse --short HEAD) passt.tar.gz
 
+# TODO: This hack makes a "plain" Markdown version of README.md that can be
+# reasonably shipped as documentation file, while the current README.md is
+# definitely intended for web browser consumption. It should probably work the
+# other way around: the web version should be obtained by adding HTML and
+# JavaScript portions to a plain Markdown, instead. However, cgit needs to use
+# a file in the git tree. Find a better way around this.
+docs: README.md
+	@(								\
+		skip=0;							\
+		while read l; do					\
+			case $$l in					\
+			"## Demo")	exit 0		;;		\
+			"<!"*)				;;		\
+			"</"*)		skip=1		;;		\
+			"<"*)		skip=2		;;		\
+			esac;						\
+									\
+			[ $$skip -eq 0 ]	&& echo "$$l";		\
+			[ $$skip -eq 1 ]	&& skip=0;		\
+		done < README.md;					\
+	) > README.plain.md
+
 # Checkers currently disabled for clang-tidy:
 # - llvmlibc-restrict-system-libc-headers
 #	TODO: this is Linux-only for the moment, nice to fix eventually
-- 
2.35.1


  parent reply	other threads:[~2022-08-18 20:22 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18 20:22 [PATCH 00/12] Updates and fixes for documentation and Fedora package Stefano Brivio
2022-08-18 20:22 ` [PATCH 01/12] doc: Rewrite demo script Stefano Brivio
2022-08-18 20:22 ` [PATCH 02/12] README: Add link to Copr repositories Stefano Brivio
2022-08-18 20:22 ` Stefano Brivio [this message]
2022-08-18 20:22 ` [PATCH 04/12] Makefile: Install demo.sh too, uninstall stuff under /usr/share Stefano Brivio
2022-08-18 20:22 ` [PATCH 05/12] fedora: Install "plain" README, instead of web version, and demo script Stefano Brivio
2022-08-18 20:22 ` [PATCH 06/12] fedora: Introduce own rpkg macro for changelog Stefano Brivio
2022-08-18 20:22 ` [PATCH 07/12] fedora: Start Release tag from 1, not 0 Stefano Brivio
2022-08-18 20:22 ` [PATCH 08/12] fedora: Drop VCS tag from spec file Stefano Brivio
2022-08-18 20:22 ` [PATCH 09/12] fedora: Change source URL to HEAD link with explicit commit SHA Stefano Brivio
2022-08-18 20:22 ` [PATCH 10/12] fedora: Build SELinux subpackage as noarch Stefano Brivio
2022-08-18 20:22 ` [PATCH 11/12] fedora: Don't hardcode CFLAGS setting, use %set_build_flags macro instead Stefano Brivio
2022-08-18 20:22 ` [PATCH 12/12] fedora: Fix man pages wildcards in spec file Stefano Brivio

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220818202235.1591828-4-sbrivio@redhat.com \
    --to=sbrivio@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).