diff mbox series

[04/10] configure: create native file with contents of $host_cc

Message ID 20230829082931.67601-5-pbonzini@redhat.com
State New
Headers show
Series configure cleanups for QEMU 8.2 | expand

Commit Message

Paolo Bonzini Aug. 29, 2023, 8:29 a.m. UTC
The argument of --host-cc is not obeyed when cross compiling.  To avoid
this issue, place it in a configuration file and pass it to meson
with --native-file.

While at it, clarify that --host-cc is not obeyed anyway when _not_
cross compiling.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Comments

Peter Maydell Aug. 29, 2023, 4:54 p.m. UTC | #1
On Tue, 29 Aug 2023 at 09:31, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> The argument of --host-cc is not obeyed when cross compiling.  To avoid
> this issue, place it in a configuration file and pass it to meson
> with --native-file.
>
> While at it, clarify that --host-cc is not obeyed anyway when _not_
> cross compiling.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  configure | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/configure b/configure
> index 3423f008d5c..b2bc1ff5f7b 100755
> --- a/configure
> +++ b/configure
> @@ -922,7 +922,7 @@ Advanced options (experts only):
>    --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be
blank [$cross_prefix]
>    --cc=CC                  use C compiler CC [$cc]
>    --host-cc=CC             use C compiler CC [$host_cc] for code run at
> -                           build time
> +                           build time when cross compiling
>    --cxx=CXX                use C++ compiler CXX [$cxx]
>    --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
>    --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
> @@ -1886,7 +1886,6 @@ if test "$skip_meson" = no; then
>    echo "windres = [$(meson_quote $windres)]" >> $cross
>    echo "windmc = [$(meson_quote $windmc)]" >> $cross
>    if test "$cross_compile" = "yes"; then
> -    cross_arg="--cross-file config-meson.cross"
>      echo "[host_machine]" >> $cross
>      echo "system = '$targetos'" >> $cross
>      case "$cpu" in
> @@ -1903,6 +1902,14 @@ if test "$skip_meson" = no; then
>      else
>          echo "endian = 'little'" >> $cross
>      fi
> +    cross_arg="--cross-file config-meson.cross"
> +
> +    native="config-meson.native.new"
> +    echo "# Automatically generated by configure - do not modify" >
$native
> +    echo "[binaries]" >> $native
> +    echo "c = [$(meson_quote $host_cc)]" >> $native
> +    mv $native config-meson.native
> +    cross_arg="$cross_arg --native-file config-meson.native"
>    else
>      cross_arg="--native-file config-meson.cross"
>    fi
> --

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Daniel P. Berrangé Aug. 29, 2023, 5:14 p.m. UTC | #2
On Tue, Aug 29, 2023 at 10:29:25AM +0200, Paolo Bonzini wrote:
> The argument of --host-cc is not obeyed when cross compiling.  To avoid
> this issue, place it in a configuration file and pass it to meson
> with --native-file.
> 
> While at it, clarify that --host-cc is not obeyed anyway when _not_
> cross compiling.

I presume that's refering to this piece of code

if test -z "${CC}${cross_prefix}"; then
  cc="$host_cc"
else
  cc="${CC-${cross_prefix}gcc}"
fi

which is using $host_cc *before* --host-cc is processed, thus
meaning it is always at its default value of 'cc'.

Perhaps the above code snippet should just be changed to

  if test -z "${CC}${cross_prefix}"; then
    cc="cc"
  else
    cc="${CC-${cross_prefix}gcc}"
  fi

to make it clear that we were not intending to honour the
--host-cc value for this code.

> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  configure | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)

None the less, this patch is correct, so with or without
that above change:

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

> 
> diff --git a/configure b/configure
> index 3423f008d5c..b2bc1ff5f7b 100755
> --- a/configure
> +++ b/configure
> @@ -922,7 +922,7 @@ Advanced options (experts only):
>    --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
>    --cc=CC                  use C compiler CC [$cc]
>    --host-cc=CC             use C compiler CC [$host_cc] for code run at
> -                           build time
> +                           build time when cross compiling
>    --cxx=CXX                use C++ compiler CXX [$cxx]
>    --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
>    --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
> @@ -1886,7 +1886,6 @@ if test "$skip_meson" = no; then
>    echo "windres = [$(meson_quote $windres)]" >> $cross
>    echo "windmc = [$(meson_quote $windmc)]" >> $cross
>    if test "$cross_compile" = "yes"; then
> -    cross_arg="--cross-file config-meson.cross"
>      echo "[host_machine]" >> $cross
>      echo "system = '$targetos'" >> $cross
>      case "$cpu" in
> @@ -1903,6 +1902,14 @@ if test "$skip_meson" = no; then
>      else
>          echo "endian = 'little'" >> $cross
>      fi
> +    cross_arg="--cross-file config-meson.cross"
> +
> +    native="config-meson.native.new"
> +    echo "# Automatically generated by configure - do not modify" > $native
> +    echo "[binaries]" >> $native
> +    echo "c = [$(meson_quote $host_cc)]" >> $native
> +    mv $native config-meson.native
> +    cross_arg="$cross_arg --native-file config-meson.native"
>    else
>      cross_arg="--native-file config-meson.cross"
>    fi
> -- 
> 2.41.0
> 
> 

With regards,
Daniel
Richard Henderson Aug. 29, 2023, 6:45 p.m. UTC | #3
On 8/29/23 01:29, Paolo Bonzini wrote:
> The argument of --host-cc is not obeyed when cross compiling.  To avoid
> this issue, place it in a configuration file and pass it to meson
> with --native-file.
> 
> While at it, clarify that --host-cc is not obeyed anyway when_not_
> cross compiling.
> 
> Signed-off-by: Paolo Bonzini<pbonzini@redhat.com>
> ---
>   configure | 11 +++++++++--
>   1 file changed, 9 insertions(+), 2 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Paolo Bonzini Aug. 31, 2023, 8:26 a.m. UTC | #4
On Tue, Aug 29, 2023 at 7:14 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Tue, Aug 29, 2023 at 10:29:25AM +0200, Paolo Bonzini wrote:
> > The argument of --host-cc is not obeyed when cross compiling.  To avoid
> > this issue, place it in a configuration file and pass it to meson
> > with --native-file.
> >
> > While at it, clarify that --host-cc is not obeyed anyway when _not_
> > cross compiling.
>
> I presume that's refering to this piece of code
>
> if test -z "${CC}${cross_prefix}"; then
>   cc="$host_cc"
> else
>   cc="${CC-${cross_prefix}gcc}"
> fi
>
> which is using $host_cc *before* --host-cc is processed, thus
> meaning it is always at its default value of 'cc'.

That, plus the fact that --native-file is only used in cross
compilation scenarios; when doing a native compilation there's no
difference between "native: true" and "native: false" as far as Meson
is concerned.

> Perhaps the above code snippet should just be changed to
>
>   if test -z "${CC}${cross_prefix}"; then
>     cc="cc"
>   else
>     cc="${CC-${cross_prefix}gcc}"
>   fi
>
> to make it clear that we were not intending to honour the
> --host-cc value for this code.

Since I have to send a v2 anyway for the (un)supported OS message,
I'll do the change.

Paolo
diff mbox series

Patch

diff --git a/configure b/configure
index 3423f008d5c..b2bc1ff5f7b 100755
--- a/configure
+++ b/configure
@@ -922,7 +922,7 @@  Advanced options (experts only):
   --cross-prefix=PREFIX    use PREFIX for compile tools, PREFIX can be blank [$cross_prefix]
   --cc=CC                  use C compiler CC [$cc]
   --host-cc=CC             use C compiler CC [$host_cc] for code run at
-                           build time
+                           build time when cross compiling
   --cxx=CXX                use C++ compiler CXX [$cxx]
   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
   --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
@@ -1886,7 +1886,6 @@  if test "$skip_meson" = no; then
   echo "windres = [$(meson_quote $windres)]" >> $cross
   echo "windmc = [$(meson_quote $windmc)]" >> $cross
   if test "$cross_compile" = "yes"; then
-    cross_arg="--cross-file config-meson.cross"
     echo "[host_machine]" >> $cross
     echo "system = '$targetos'" >> $cross
     case "$cpu" in
@@ -1903,6 +1902,14 @@  if test "$skip_meson" = no; then
     else
         echo "endian = 'little'" >> $cross
     fi
+    cross_arg="--cross-file config-meson.cross"
+
+    native="config-meson.native.new"
+    echo "# Automatically generated by configure - do not modify" > $native
+    echo "[binaries]" >> $native
+    echo "c = [$(meson_quote $host_cc)]" >> $native
+    mv $native config-meson.native
+    cross_arg="$cross_arg --native-file config-meson.native"
   else
     cross_arg="--native-file config-meson.cross"
   fi