Subject: Re: bug#25358: Cross Compiling fails because of help2man

From: Jim Meyering <[email-masked]>
Date: Thu, 5 Jan 2017 17:41:24 +0100

On Thu, Jan 5, 2017 at 12:22 AM, Assaf Gordon <[email-masked]> wrote:
> Hello Vishal,
>
> On 01/04/2017 11:48 AM, Vishal Biswas wrote:
>> GNU sed 4.3 cannot be successfully cross compiled because the Makefile tries to
>> run help2man even if cross compiling.
>
> Thank you for reporting this, it is a bug in the build system.
>
> As a temporary work-around (if one is needed):
> first, the cross-copmiled binary is already successfully built when the
> help2man error is encountered. Not sure if this is sufficient for you or
> not. The binary file is 'sed/sed'.
>
> second,
> the 'doc/sed.1' file is already pre-built and included in the
> 'sed-4.3.tar.xz' file, So running
>     touch doc/sed.1 ; make
> should 'just work' and complete the build successfully.
>
>>         GEN      doc/sed.1
>>       help2man: can't get `--help' info from sed/sed
>>       make[2]: *** [Makefile:5775: doc/sed.1] Error 126
>
> The bug in the build system is that 'doc/sed.1' depends on the binary
> 'sed/sed', even if 'sed.1' already exists in the tarball and there's no
> need to re-generate it.
>
> Jim,
> I can think of two ways around this:
>
> 1. make 'doc/sed.1' depend on 'sed/sed.c' and 'doc/sed.x' instead
>    of the binary 'sed/sed'. The assumption is that if the C
>    source hasn't changed, there's no need to update the man page.

Hi Assaf,
Thanks for investigating.

I'm pretty sure we must retain the dependency, at least when not
cross-compiling. If we were to attempt to remove that dependency, I
believe that would leave a race condition where help2man may attempt
to run the binary before it is built.

> 2. make the building of 'doc/sed.1' conditional, depending on wether
>    it is being built from '.git' (then regenerate it) or from
>    a tarball (then it already exists).
>    something like:
>
>       AM_CONDITIONAL([BUILD_FROM_GIT], [test -d "$srcdir/.git"])
>
>    and then in 'doc/local.mk':
>
>       if BUILD_FROM_GIT
>          doc/sed.1: sed/sed$(EXEEXT) .version $(srcdir)/doc/sed.x
>                     ...
>       endif

Even when building from a tarball, we should leave as many build rules
as we can. How about removing the dependency only when
cross-compiling, e.g., via: `if CROSS_COMPILING ...`. This should have
the advantage of working also when cross-compiling from a git clone'd
working directory.