From d849b56b7fd059c46f087dec13e47725408f5ac8 Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Tue, 14 Sep 2021 23:10:13 -0400 Subject: [PATCH] build: Move generated sed link fixer to its own script I was a bit uneasy about eval'ing the output of awk as a sed command. I mean, it was clever, and I'm _effectively_ still doing the same thing, but it feels a bit cleaner to generate a standalone script in bin/ that can be used in all places necessary! --- .gitignore | 6 ++++++ Makefile | 11 +++++++++-- bin/genatom.sh | 6 ++++-- bin/genpost.sh | 6 ++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 39fc25a..2ad7653 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,11 @@ jam-tuesday/greatest-hits # text files (gopher, text.alexkarle.com) text/ +# html files (www.alexkarle.com) +html/ + # obj directory on OpenBSD for out-of-tree builds obj/ + +# Generated sed command to touch up out-of-base Xr references +bin/fixlinks diff --git a/Makefile b/Makefile index 5fe10e0..fc23bc1 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ obj: .PHONY: clean clean: - rm -f *.ts + rm -f *.ts bin/fixlinks rm -rf text html obj #---------------------------------------------------------- @@ -81,7 +81,14 @@ text/LICENSE: LICENSE # The most egregious hack here is the live renaming of the files via # grepping through the ORDER file so that text.alexkarle.com presents # the files in a reasonable order for viewing -$(TS): bin/genpost.sh +$(TS): bin/genpost.sh bin/fixlinks + +bin/fixlinks: LINKS + mkdir -p bin + printf "#!/bin/sh\n# GENERATED DO NOT EDIT\nsed" > $@ + awk '{ printf " \\\n -e s#https://man.openbsd.org/%s#%s#g", $$1, $$2 } END { printf "\n" }' $(DIR)/LINKS >> $@ + chmod +x $@ + .SUFFIXES: .7 .ts .7.ts: diff --git a/bin/genatom.sh b/bin/genatom.sh index 34a8347..78a4270 100755 --- a/bin/genatom.sh +++ b/bin/genatom.sh @@ -4,6 +4,9 @@ set -e REPO=$(dirname "$(dirname "$0")") +# Find fixlinks in either bin or the out-of-tree obj build +PATH="$REPO/bin:$REPO/obj/bin:$PATH" + # All posts are a item (.It) in the list, and linked via .Xr POSTS=$(sed '/SEE ALSO/q' "$REPO/blog.7" | grep -A1 '\.It' | grep '\.Xr' | sed 's/^\.Xr \([^ ]*\) 7/\1/') # Assume dates are 1-1 @@ -40,8 +43,7 @@ ENTRY # Print fragment (no need for escapes -- in CDATA mandoc -Thtml -O'fragment,man=%N.html;https://man.openbsd.org/%N.%S' "$REPO/$p.7" \ | sed '/Miscellaneous Information Manual<\/td>/d' \ - | eval \ - "sed $(awk '{ printf " \\\n -e s#https://man.openbsd.org/%s#%s#g", $1, $2 } END { printf "\n" }' "$REPO/LINKS")" + | fixlinks cat < diff --git a/bin/genpost.sh b/bin/genpost.sh index 0fe7cfa..b72bff5 100755 --- a/bin/genpost.sh +++ b/bin/genpost.sh @@ -5,6 +5,9 @@ REPO=$(dirname "$(dirname "$0")") # cd into $REPO so that the includes work! cd $REPO +# Find fixlinks in either bin or the out-of-tree obj build +PATH="$REPO/bin:$REPO/obj/bin:$PATH" + # Command Explained # ----------------- # man=%N.html;man.openbsd.org -- look for files in CWD for .Xr, then link to openbsd.org @@ -22,5 +25,4 @@ mandoc -Thtml -O 'man=%N.html;https://man.openbsd.org/%N.%S,style=style.css' \ -e 's##

\ © 2019-2021 Alex Karle | Home | License\

\ -&#' | eval \ - "sed $(awk '{ printf " \\\n -e s#https://man.openbsd.org/%s#%s#g", $1, $2 } END { printf "\n" }' LINKS)" +&#' | fixlinks -- libgit2 1.1.1