Add a warning header to the generated help-*.h files.
authorWayne Davison <wayne@opencoder.net>
Mon, 15 Jun 2020 01:49:38 +0000 (18:49 -0700)
committerWayne Davison <wayne@opencoder.net>
Mon, 15 Jun 2020 01:49:38 +0000 (18:49 -0700)
Makefile.in
help-from-md [new file with mode: 0755]

index f6dd515ba12eee9456b46a57c13bcbd8dee5352e..a0681c8984a272932ddea8b7913699d7b5b358ec 100644 (file)
@@ -104,14 +104,7 @@ options.o: latest-year.h help-rsync.h help-rsyncd.h
 flist.o: rounding.h
 
 help-rsync.h help-rsyncd.h: rsync.1.md
-       @sed -e '1,/^\[comment\].*$@/d' \
-           -e '1,/^```/d' \
-           -e '/^```/,$$d' \
-           -e 's/"/\\"/g' \
-           -e 's/^/  rprintf(F,"/' \
-           -e 's/$$/\\n");/' \
-           <"$(srcdir)/$<" >$@
-       @if ! test -s $@; then rm -f $@ ; echo "The Makefile generated an empty file: $@" ; exit 1 ; fi
+       ./help-from-md "$(srcdir)/$<" $@
 
 rounding.h: rounding.c rsync.h proto.h
        @for r in 0 1 3; do \
diff --git a/help-from-md b/help-from-md
new file mode 100755 (executable)
index 0000000..21f49cd
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+
+if [[ "$#" != 2 ]]; then
+    echo "Usage: $0 MD_FILE HELP_FILE.h"
+    exit 1
+fi
+
+mdfile="$1"
+helpfile="$2"
+newfile="$helpfile.new"
+findfile="${helpfile/./\\.}"
+
+sed -e '1,/^\[comment\].*'"$findfile"'/d' \
+    -e '1,/^```/d' \
+    -e '/^```/,$d' \
+    -e 's/"/\\"/g' \
+    -e 's/^/  rprintf(F,"/' \
+    -e 's/$/\\n");/' \
+    <"$mdfile" >"$newfile"
+
+if [[ ! -s "$newfile" ]]; then
+    rm "$newfile"
+    echo "Discarding empty output for $helpfile file from $mdfile"
+    exit 1
+fi
+
+(cat <<EOT
+/* DO NOT EDIT THIS FILE!  It is auto-generated from the option list in $mdfile! */
+EOT
+cat "$newfile"
+) >"$helpfile"
+rm "$newfile"