Subject: Re: bug#51144: GNU grep 3.7 fails to build on FreeBSD

From: Alexey Dokuchaev <[email-masked]>
Date: Wed, 13 Oct 2021 11:02:58 +0700

On Tue, Oct 12, 2021 at 12:50:55PM -0700, Paul Eggert wrote:
> On 10/11/21 19:53, Alexey Dokuchaev via Bug reports for GNU grep wrote:
> 
> >   +#define STACK_DIRECTION
> 
> I don't observe this problem when I build GNU grep 3.7 on FreeBSD
> 13.0-RELEASE amd64.

That's probably because you just tar xf grep-3.7.tar.xz && cd grep-3.7
&& ./configure && make.  This works.  But not when configured from the
FreeBSD ports framework, and here's why.

The clue is these lines:

Vanilla ./configure (untainted):

  configure:4945: checking build system type
  configure:4960: result: x86_64-portbld-freebsd13.0
  configure:4980: checking host system type
  configure:4994: result: x86_64-portbld-freebsd13.0

>From within the FreeBSD ports framework:

  configure:4945: checking build system type
  configure:4960: result: amd64-portbld-freebsd13.0
  configure:4980: checking host system type
  configure:4994: result: amd64-portbld-freebsd13.0

Ports framework does several things which affect GNU configure
scripts, particularly, it replaces build-aux/config.guess file
with our own, where host/build tuples are derived from.

x86_64 is spelled as amd64 in FreeBSD, but ``case "$host_cpu" in''
block has only "i?86 | x86_64 | \" on line 35668 in the configure
script.

> Also, what did 'configure' say when it attempted to configure stack
> direction, and what got put into config.log?
> 
> configure:35646: checking for stack direction
> configure:35741: result: grows down

  configure:35646: checking for stack direction
  configure:35723: cc -o conftest -O2 -pipe [..snip..] conftest.c >&5
  conftest.c:13:1: error: second parameter of 'main' (argument array)
    must be of type 'char **'
    main (int argc, char *argv)
    ^
    1 error generated.
  configure:35726: $? = 1
  configure:35741: result: unknown

> and config.h says:
> 
> #define STACK_DIRECTION -1
> 
> which is correct for amd64.

If I add "amd64" to that list -> "i?86 | x86_64 | amd64 | \" or
fix the main() argument *argv -> **argv, it behaves correctly as
well.

./danfe