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

From: Paul Eggert <[email-masked]>
Date: Wed, 13 Oct 2021 11:47:34 -0700

On 10/12/21 9:02 PM, Alexey Dokuchaev wrote:

> 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

Ouch. When porting, does this mean you need to look for places where GNU 
source code says "x86_64" and replace many of these places with "amd64" 
before building? That sounds error-prone.

>    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

Thanks for reporting that. That's due to a quoting typo in Gnulib's 
m4/stack-direction.m4. I fixed it by installing the attached patch into 
Gnulib. Grep will get this fix the next time it merges from Gnulib. In 
the meantime you should be able work around the problem by changing that 
'char *argv' to 'char *argv[]' in 'configure'.

>> and config.h says:
>>
>> #define STACK_DIRECTION -1

This is after you modified 'configure', right? Otherwise "result: 
unknown" should result in STACK_DIRECTION being 0, which 
gnulib/lib/stackvma.h does not support (perhaps it should?).
From ff5ef2582300c2d982820ffeaede2ea08aaba3d8 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email-masked]>
Date: Wed, 13 Oct 2021 10:24:40 -0700
Subject: [PATCH] sigsegv: fix quoting problem

Problem reported for FreeBSD ports by Alexey Dokuchaev in:
https://bugs.gnu.org/51144
* m4/stack-direction.m4 (SV_STACK_DIRECTION): Quote brackets.
---
 ChangeLog             | 7 +++++++
 m4/stack-direction.m4 | 4 ++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index da5b570ee..ea71de0b2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2021-10-13  Paul Eggert  <[email-masked]>
+
+	sigsegv: fix quoting problem
+	Problem reported for FreeBSD ports by Alexey Dokuchaev in:
+	https://bugs.gnu.org/51144
+	* m4/stack-direction.m4 (SV_STACK_DIRECTION): Quote brackets.
+
 2021-10-10  Paul Eggert  <[email-masked]>
 
 	nproc: port better to OpenBSD
diff --git a/m4/stack-direction.m4 b/m4/stack-direction.m4
index e682be97d..c90d69733 100644
--- a/m4/stack-direction.m4
+++ b/m4/stack-direction.m4
@@ -1,4 +1,4 @@
-# stack-direction.m4 serial 8
+# stack-direction.m4 serial 9
 dnl Copyright (C) 2002-2021 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
@@ -79,7 +79,7 @@ find_stack_direction (int *addr, int depth)
   return dir + dummy;
 }
 int
-main (int argc, char *argv[])
+main (int argc, char *argv[[]])
 {
   printf ("%d\n", find_stack_direction (NULL, argc + 20));
   return 0;
-- 
2.30.2