Documentation: refactor "api-index.sh" for out-of-tree builds

The "api-index.sh" script generates an index of API-related documentation. The script does not handle out-of-tree builds and thus cannot be used easily by Meson. Refactor it to be independent of locations by both accepting a source directory where the API docs live as well as a path to an output file. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Dec 27, 2024 at 14:59 UTC 88e08b92e9a55fa453d44b26061a6a67a7eefafc
2 files changed +16 -5
Documentation/Makefile
+1 -1
@@ -367,7 +367,7 @@ user-manual.xml: user-manual.txt $(ASCIIDOC_DEPS)
367
368 technical/api-index.txt: technical/api-index-skel.txt \
369 technical/api-index.sh $(patsubst %,%.txt,$(API_DOCS))
370 - $(QUIET_GEN)cd technical && '$(SHELL_PATH_SQ)' ./api-index.sh
370 + $(QUIET_GEN)'$(SHELL_PATH_SQ)' technical/api-index.sh ./technical ./technical/api-index.txt
371
372 technical/%.html: ASCIIDOC_EXTRA += -a git-relative-html-prefix=../
373 $(patsubst %,%.html,$(API_DOCS) technical/api-index $(TECH_DOCS)): %.html : %.txt \
Documentation/technical/api-index.sh
+15 -4
@@ -1,6 +1,17 @@
1 #!/bin/sh
2
3 +if test $# -ne 2
4 +then
5 + echo >&2 "USAGE: $0 <SOURCE_DIR> <OUTPUT>"
6 + exit 1
7 +fi
8 +
9 +SOURCE_DIR="$1"
10 +OUTPUT="$2"
11 +
12 (
13 + cd "$SOURCE_DIR"
14 +
15 c=////////////////////////////////////////////////////////////////
16 skel=api-index-skel.txt
17 sed -e '/^\/\/ table of contents begin/q' "$skel"
@@ -18,11 +29,11 @@
29 done
30 echo "$c"
31 sed -n -e '/^\/\/ table of contents end/,$p' "$skel"
21 -) >api-index.txt+
32 +) >"$OUTPUT"+
33
23 -if test -f api-index.txt && cmp api-index.txt api-index.txt+ >/dev/null
34 +if test -f "$OUTPUT" && cmp "$OUTPUT" "$OUTPUT"+ >/dev/null
35 then
25 - rm -f api-index.txt+
36 + rm -f "$OUTPUT"+
37 else
27 - mv api-index.txt+ api-index.txt
38 + mv "$OUTPUT"+ "$OUTPUT"
39 fi