1
votes

I'm working on a project built using GNU autotools (autoconf, automake). It does work well, but I've a problem with help2man: When building parallel (MAKEFLAGS=-j3), the project is built twice - once using "normal" target, once using the foo.1 make call.

The following is the relevant part from Makefile.am:

foo.1 : $(top_srcdir)/man/foo.x $(top_srcdir)/src/main.c $(top_srcdir)/configure.ac
    $(MAKE) $(AM_MAKEFLAGS) foo$(EXEEXT)
    -$(HELP2MAN) -o $@ --include $< $(top_builddir)/foo

So, my question is how to write Makefile.am to support the following:

  1. Distribute foo.1 to support systems without help2man
  2. Do not throw errors
  3. Rebuild manpage if necessary

I'm looking forward to your answer

2
Are there any ideas? - caylee

2 Answers

0
votes

foo.1 needs correct prerequisites. AIUI, help2man just needs the executable binary to be built:

foo.1 : $(top_srcdir)/man/foo.x $(top_srcdir)/configure.ac $(top_builddir)/foo
        -$(HELP2MAN) -o $@ --include $< $(top_builddir)/foo

so that's 3)

don't understand what you want out of 2), which is not possible in general.

dist_man_MANS = foo.1

which is 1)

0
votes

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)