There seems to be no easy solution to this question; the following works for me.
In configure.ac
, you have to check for help2man. If cross-compiling, you must not run help2man, as the executable will be run. The following snippet is therefore contained:
# Man pages
AS_IF([test "$cross_compiling" = "no"], [
AM_MISSING_PROG([HELP2MAN], [help2man])
], [
HELP2MAN=:
])
For building, there is a two-level concept. First, you check if the manpage is newer than the executable; if so, to prohibit unnecessary manpage rebuilds, you check against the source using a temporary file being last altered when the manpage itself was. So, Makefile.am
contains:
dist_man_MANS = foo.1
EXTRA_DIST += $(dist_man_MANS:.1=.x) common.x
MOSTLYCLEANFILES += $(dist_man_MANS:=-t)
MAINTAINERCLEANFILES += $(dist_man_MANS)
common_dep = $(top_srcdir)/common.x $(top_srcdir)/configure.ac $(top_srcdir)/.version
common_indirect_dep = $(top_srcdir)/common.x $(top_srcdir)/configure $(top_srcdir)/.version
foo.1 : $(common_indirect_dep) $(top_builddir)/foo$(EXEEXT)
foo.1-t : $(common_dep) $(top_srcdir)/main-helpversion.c
SUFFIXES += .x .1 .1-t
.x.1:
test -f $@ || if test -f $(top_srcdir)/`echo $@ | $(SED) -e 's,.*/,,'`; then \
touch -r $(top_srcdir)/`echo $@ | $(SED) -e 's,.*/,,'` $@; \
else \
touch -d @0 $@; \
fi
touch -r $@ $@-t
$(MAKE) $(AM_MAKEFLAGS) $@-t
if test -s $@-t; then \
mv -f $@-t $@; \
else \
rm -f $@-t; \
if test -s $@; then touch $@; else rm -f $@; fi; \
fi
.x.1-t:
$(HELP2MAN) -o $@ -I $< -I $(top_srcdir)/common.x -s 1 foo$(EXEEXT)