Prechádzať zdrojové kódy

man: add build infrastructure to generate devel man pages

this is useful to include ipc_common errors into all man pages

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Reviewed-by: Steven Dake <sdake@redhat.com>
Fabio M. Di Nitto 14 rokov pred
rodič
commit
902d03f28b
5 zmenil súbory, kde vykonal 80 pridanie a 3 odobranie
  1. 1 0
      Makefile.am
  2. 52 0
      build-aux/genman
  3. 1 0
      configure.ac
  4. 23 3
      man/Makefile.am
  5. 3 0
      man/ipc_common.sh.errors

+ 1 - 0
Makefile.am

@@ -37,6 +37,7 @@ EXTRA_DIST		= autogen.sh $(SPEC).in \
 			  build-aux/git-version-gen \
 			  build-aux/gitlog-to-changelog \
 			  build-aux/release.mk \
+			  build-aux/genman \
 			  .version
 
 AUTOMAKE_OPTIONS	= foreign

+ 52 - 0
build-aux/genman

@@ -0,0 +1,52 @@
+#!/bin/bash
+
+set -e
+
+# Set variables
+# in - input man page (something_foo.3.in)
+# out - output file (something_foo.3)
+# common - common ipc error file
+
+in="$1"
+out="$2"
+common="$3"
+
+# make sure to trap on error and ctrl+c
+# so we can cleanup our temporary files
+# and provide error back to Makefile
+cleanup() {
+	rm -f "$out"-t "$out"
+}
+
+trap "cleanup" ABRT
+trap "cleanup" QUIT
+trap "cleanup" TERM
+trap "cleanup" INT
+trap "cleanup" ERR
+
+# Determine build date in man page format YYYY-MM-DD
+date="$(LC_ALL=C date "+%F")"
+
+# do the hack.. it looks ugly but it works fine
+
+# remove temporary file
+rm -f "$out"-t
+
+# insert the $common ipc error file in the man page
+if grep -q @COMMONIPCERRORS@ "$in"; then
+	awk "{print}(\$1 ~ /@COMMONIPCERRORS@/){exit 0}" "$in" > "$out"-t
+	cat "$common" >> "$out"-t
+	awk -v p=0 "(\$1 ~ /@COMMONIPCERRORS@/){p = 1} {if(p==1)print}" "$in" >> "$out"-t
+else
+	cp "$in" "$out"-t
+fi
+
+# substitute BUILDDATE with precalculated date
+# and remove COMMONIPCERRORS tag from above
+sed -i \
+	-e 's#@BUILDDATE@#'$date'#g' \
+	-e 's#@COMMONIPCERRORS@##g' \
+	"$out"-t
+
+# move in place as requested
+mv "$out"-t "$out"

+ 1 - 0
configure.ac

@@ -66,6 +66,7 @@ AC_CHECK_PROGS([PKGCONFIG], [pkg-config])
 AC_CHECK_PROGS([AUGTOOL], [augtool])
 AC_CHECK_PROGS([DOT], [dot])
 AC_CHECK_PROGS([DOXYGEN], [doxygen])
+AC_CHECK_PROGS([AWK], [awk])
 
 # Checks for libraries.
 AC_CHECK_LIB([dl], [dlopen])

+ 23 - 3
man/Makefile.am

@@ -39,8 +39,25 @@ xml_man			= corosync-xmlproc.8 \
 
 INDEX_HTML		= index.html
 
+autogen_man		=
+
+autogen_common		= ipc_common.sh.errors
+
 EXTRA_DIST		= $(INDEX_HTML) \
-			  $(xml_man)
+			  $(xml_man) \
+			  $(autogen_man:%=%.in) \
+			  $(autogen_common)
+
+man_MANS = $(autogen_man)
+
+%.3: %.3.in $(autogen_common) $(top_srcdir)/build-aux/genman
+	@echo Generating $@ man page && \
+	rm -f $@-t $@ && \
+	$(top_srcdir)/build-aux/genman \
+		$(srcdir)/$@.in \
+		$(builddir)/$@-t \
+		$(srcdir)/$(autogen_common) && \
+	mv $@-t $@
 
 dist_man_MANS = \
 	corosync.conf.5 \
@@ -142,7 +159,7 @@ endif
 
 if BUILD_HTML_DOCS
 
-HTML_DOCS = $(dist_man_MANS:%=%.html)
+HTML_DOCS = $(dist_man_MANS:%=%.html) $(man_MANS:%=%.html)
 
 %.html: %
 	$(GROFF) -mandoc -Thtml $^ > $@
@@ -158,6 +175,9 @@ uninstall-local:
 all-local: $(HTML_DOCS)
 
 clean-local:
-	rm -rf $(HTML_DOCS)
+	rm -rf $(HTML_DOCS) $(autogen_man)
 
+else
+clean-local:
+	rm -rf $(autogen_man)
 endif

+ 3 - 0
man/ipc_common.sh.errors

@@ -0,0 +1,3 @@
+.PP
+Common errors go here
+