diff mbox series

[1/1] package/gmp: fix target build with host gcc 4.9

Message ID 20240312190954.71227-1-brandon.maier@collins.com
State Superseded
Headers show
Series [1/1] package/gmp: fix target build with host gcc 4.9 | expand

Commit Message

Brandon Maier March 12, 2024, 7:09 p.m. UTC
GMP does not build if the host gcc is v4.9 due to the following error

  gen-sieve.c: In function 'setmask':
  gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
     for (unsigned i = 0; i < 2 * a * b; ++i)
     ^
  gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code

The gen-sieve utility was added in GMP v6.3.0. It is built using
CC_FOR_BUILD (host compiler) during cross compilation as it generates
build files. Autoconf does not have a macro for add -std=c99 to
CC_FOR_BUILD, so it must be set manually.

Signed-off-by: Brandon Maier <brandon.maier@collins.com>
---
 package/gmp/gmp.mk | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Arnout Vandecappelle March 15, 2024, 8:43 p.m. UTC | #1
On 12/03/2024 20:09, Brandon Maier via buildroot wrote:
> GMP does not build if the host gcc is v4.9 due to the following error

  Oh boy, are you still using host GCC 4.9? Poor man...

> 
>    gen-sieve.c: In function 'setmask':
>    gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
>       for (unsigned i = 0; i < 2 * a * b; ++i)
>       ^
>    gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
> 
> The gen-sieve utility was added in GMP v6.3.0. It is built using
> CC_FOR_BUILD (host compiler) during cross compilation as it generates
> build files. Autoconf does not have a macro for add -std=c99 to
> CC_FOR_BUILD, so it must be set manually.
> 
> Signed-off-by: Brandon Maier <brandon.maier@collins.com>
> ---
>   package/gmp/gmp.mk | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/package/gmp/gmp.mk b/package/gmp/gmp.mk
> index bd401c6a80..85836a8c72 100644
> --- a/package/gmp/gmp.mk
> +++ b/package/gmp/gmp.mk
> @@ -14,6 +14,11 @@ GMP_CPE_ID_VENDOR = gmplib
>   GMP_DEPENDENCIES = host-m4
>   HOST_GMP_DEPENDENCIES = host-m4
>   
> +# The compiler for build requires C99 but GCC 4.9 defaults to C89

  I don't think the comment is really needed.

> +ifeq ($(BR2_HOST_GCC_AT_LEAST_5),)

  In all the other places where we pass -std=c99, we do that unconditionally. So 
I'd do the same here.

> +GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"

  Don't you need something similar for host-gmp as well? All the rest I could 
have fixed up while applying, but I don't have a host gcc 4.9 with which to test 
host-gmp :-)

  Regards,
  Arnout

> +endif
> +
>   # GMP doesn't support assembly for coldfire or mips r6 ISA yet
>   # Disable for ARM v7m since it has different asm constraints
>   ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)
yegorslists--- via buildroot March 15, 2024, 11:37 p.m. UTC | #2
Hi Arnout,

> -----Original Message-----
> From: Arnout Vandecappelle <arnout@mind.be>
> Sent: Friday, March 15, 2024 3:44 PM
> To: Maier, Brandon Collins <Brandon.Maier@collins.com>;
> buildroot@buildroot.org
> Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
> Subject: [External] Re: [Buildroot] [PATCH 1/1] package/gmp: fix target build with
> host gcc 4.9
>
>
>
> On 12/03/2024 20:09, Brandon Maier via buildroot wrote:
> > GMP does not build if the host gcc is v4.9 due to the following error
>
>   Oh boy, are you still using host GCC 4.9? Poor man...

Yeah, it's not great

>
> >
> >    gen-sieve.c: In function 'setmask':
> >    gen-sieve.c:99:3: error: 'for' loop initial declarations are only allowed in C99 or
> C11 mode
> >       for (unsigned i = 0; i < 2 * a * b; ++i)
> >       ^
> >    gen-sieve.c:99:3: note: use option -std=c99, -std=gnu99, -std=c11 or -
> std=gnu11 to compile your code
> >
> > The gen-sieve utility was added in GMP v6.3.0. It is built using
> > CC_FOR_BUILD (host compiler) during cross compilation as it generates
> > build files. Autoconf does not have a macro for add -std=c99 to
> > CC_FOR_BUILD, so it must be set manually.
> >
> > Signed-off-by: Brandon Maier <brandon.maier@collins.com>
> > ---
> >   package/gmp/gmp.mk | 5 +++++
> >   1 file changed, 5 insertions(+)
> >
> > diff --git a/package/gmp/gmp.mk b/package/gmp/gmp.mk
> > index bd401c6a80..85836a8c72 100644
> > --- a/package/gmp/gmp.mk
> > +++ b/package/gmp/gmp.mk
> > @@ -14,6 +14,11 @@ GMP_CPE_ID_VENDOR = gmplib
> >   GMP_DEPENDENCIES = host-m4
> >   HOST_GMP_DEPENDENCIES = host-m4
> >
> > +# The compiler for build requires C99 but GCC 4.9 defaults to C89
>
>   I don't think the comment is really needed.
>
> > +ifeq ($(BR2_HOST_GCC_AT_LEAST_5),)
>
>   In all the other places where we pass -std=c99, we do that unconditionally. So
> I'd do the same here.
>
> > +GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"
>
>   Don't you need something similar for host-gmp as well? All the rest I could
> have fixed up while applying, but I don't have a host gcc 4.9 with which to test
> host-gmp :-)

The issue only occurs when cross-compiling because Autoconf does not set -std=c99 for the host compiler. When host compiling, Autoconf uses the same compiler for target as host, and target it does correctly enable -std=c99 using AC_PROG_CC_C99. As far as I could find, there is no AC_PROG_CC_C99 equivalent for the host compiler.

That's my understanding anyway, I have very little experience dealing with Autotools.

Agree with the other comments, I can resend with those fixed.

Thanks,
Brandon
diff mbox series

Patch

diff --git a/package/gmp/gmp.mk b/package/gmp/gmp.mk
index bd401c6a80..85836a8c72 100644
--- a/package/gmp/gmp.mk
+++ b/package/gmp/gmp.mk
@@ -14,6 +14,11 @@  GMP_CPE_ID_VENDOR = gmplib
 GMP_DEPENDENCIES = host-m4
 HOST_GMP_DEPENDENCIES = host-m4
 
+# The compiler for build requires C99 but GCC 4.9 defaults to C89
+ifeq ($(BR2_HOST_GCC_AT_LEAST_5),)
+GMP_CONF_ENV += CC_FOR_BUILD="$(HOSTCC) -std=c99"
+endif
+
 # GMP doesn't support assembly for coldfire or mips r6 ISA yet
 # Disable for ARM v7m since it has different asm constraints
 ifeq ($(BR2_m68k_cf)$(BR2_MIPS_CPU_MIPS32R6)$(BR2_MIPS_CPU_MIPS64R6)$(BR2_ARM_CPU_ARMV7M),y)