All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests
@ 2021-11-08  8:43 Paolo Bonzini
  2021-11-08  8:43 ` [PATCH 1/4] configure: simplify calls to meson_quote Paolo Bonzini
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08  8:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: thuth

Meson (intentionally) does not add QEMU_CFLAGS to cc.compiles/cc.links
tests, as they are supposed to be independent of the specific sets of
compilation flags used to build the programs.  However, the user can
still use CFLAGS or the toolchain file's LANG_args/LANG_link_args option
to specify -I or -L options that apply to cc.compiles/cc.links as well.

This is also the intended use of configure's --extra-cflags,
--extra-cxxflags and --extra-ldflags options.  For example, if
one has netmap's header in a nonstandard directory, up to commit
837b84b1c078bf3e909 it used to work fine to do:

.../configure --enable-netmap \
     --extra-cflags=-I/path/to/netmap/sys

but since the test was converted to meson, this does not work anymore.

The main change in the series is in patch 3, where these options are
passed to meson via the toolchain file, instead of via config-host.mak.
This solves the issue since the toolchain file's variables have the
same purpose as configure's --extra-*flags arguments.

Paolo


Paolo Bonzini (4):
  configure: simplify calls to meson_quote
  configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status
  configure: propagate --extra-cflags and --extra-ldflags to meson
    compile tests
  configure: ignore preexisting QEMU_*FLAGS envvars

 configure | 46 ++++++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 18 deletions(-)

-- 
2.33.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/4] configure: simplify calls to meson_quote
  2021-11-08  8:43 [PATCH 0/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
@ 2021-11-08  8:43 ` Paolo Bonzini
  2021-11-08  9:02   ` Thomas Huth
  2021-11-08  8:43 ` [PATCH 2/4] configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status Paolo Bonzini
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08  8:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: thuth

meson_quote assumes a non-empty argument list, and incorrectly returns a
one-entry array if passed nothing.  Move the check for an empty argument
list from the invocations to the function itself.

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

diff --git a/configure b/configure
index 33682cb971..369b5455b6 100755
--- a/configure
+++ b/configure
@@ -3894,6 +3894,7 @@ echo "TOPSRC_DIR=$source_path" >> $config_mak
 if test "$skip_meson" = no; then
   cross="config-meson.cross.new"
   meson_quote() {
+    test $# = 0 && return
     echo "'$(echo $* | sed "s/ /','/g")'"
   }
 
@@ -3908,10 +3909,10 @@ if test "$skip_meson" = no; then
 
   test -z "$cxx" && echo "link_language = 'c'" >> $cross
   echo "[built-in options]" >> $cross
-  echo "c_args = [${CFLAGS:+$(meson_quote $CFLAGS)}]" >> $cross
-  echo "cpp_args = [${CXXFLAGS:+$(meson_quote $CXXFLAGS)}]" >> $cross
-  echo "c_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
-  echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
+  echo "c_args = [$(meson_quote $CFLAGS)]" >> $cross
+  echo "cpp_args = [$(meson_quote $CXXFLAGS)]" >> $cross
+  echo "c_link_args = [$(meson_quote $LDFLAGS)]" >> $cross
+  echo "cpp_link_args = [$(meson_quote $LDFLAGS)]" >> $cross
   echo "[binaries]" >> $cross
   echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
   test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
-- 
2.33.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/4] configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status
  2021-11-08  8:43 [PATCH 0/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
  2021-11-08  8:43 ` [PATCH 1/4] configure: simplify calls to meson_quote Paolo Bonzini
@ 2021-11-08  8:43 ` Paolo Bonzini
  2021-11-08  9:04   ` Thomas Huth
  2021-11-08  8:43 ` [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
  2021-11-08  8:43 ` [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars Paolo Bonzini
  3 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08  8:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: thuth

CFLAGS, CXXFLAGS and LDFLAGS influence the tests (for example if they include
-L or -I options), so they should be kept from the invocation of configure
to the subsequent reinvocations via config.status.

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

diff --git a/configure b/configure
index 369b5455b6..d268f59246 100755
--- a/configure
+++ b/configure
@@ -4057,9 +4057,12 @@ preserve_env AR
 preserve_env AS
 preserve_env CC
 preserve_env CPP
+preserve_env CFLAGS
 preserve_env CXX
+preserve_env CXXFLAGS
 preserve_env INSTALL
 preserve_env LD
+preserve_env LDFLAGS
 preserve_env LD_LIBRARY_PATH
 preserve_env LIBTOOL
 preserve_env MAKE
-- 
2.33.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests
  2021-11-08  8:43 [PATCH 0/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
  2021-11-08  8:43 ` [PATCH 1/4] configure: simplify calls to meson_quote Paolo Bonzini
  2021-11-08  8:43 ` [PATCH 2/4] configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status Paolo Bonzini
@ 2021-11-08  8:43 ` Paolo Bonzini
  2021-11-08  9:11   ` Thomas Huth
  2021-11-08  8:43 ` [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars Paolo Bonzini
  3 siblings, 1 reply; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08  8:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: thuth

Meson (intentionally) does not add QEMU_CFLAGS to cc.compiles/cc.links
tests, as they are supposed to be independent of the specific sets of
compilation flags used to build the programs.  However, the user can
still use CFLAGS or the toolchain file's LANG_args/LANG_link_args option
to specify -I or -L options that apply to cc.compiles/cc.links as well.

This is also the intended use of configure's --extra-cflags,
--extra-cxxflags and --extra-ldflags options.  For example, if
one has netmap's header in a nonstandard directory, up to commit
837b84b1c078bf3e909 it used to work fine to do:

.../configure --enable-netmap \
     --extra-cflags=-I/path/to/netmap/sys

but since the test was converted to meson, this does not work anymore.

Pass these options to meson via the toolchain file instead of via
config-host.mak, since the toolchain file's variables have the
same purpose as configure's --extra-*flags arguments.

Reported-by: Owen LaGarde
Reported-by: Thomas Huth <thuth@redhat.com>
Fixes: 47b30835e4 ("configure: consistently pass CFLAGS/CXXFLAGS/LDFLAGS to meson", 2020-10-06)
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure | 36 ++++++++++++++++++++----------------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/configure b/configure
index d268f59246..1ea26c67e5 100755
--- a/configure
+++ b/configure
@@ -174,14 +174,14 @@ update_cxxflags() {
 
 compile_object() {
   local_cflags="$1"
-  do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
+  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
 }
 
 compile_prog() {
   local_cflags="$1"
   local_ldflags="$2"
-  do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
-      $LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
+  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
+      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
 }
 
 # symbolically link $1 to $2.  Portable version of "ln -sf".
@@ -286,6 +286,10 @@ for opt do
   esac
 done
 
+EXTRA_CFLAGS=""
+EXTRA_CXXFLAGS=""
+EXTRA_LDFLAGS=""
+
 xen_ctrl_version="$default_feature"
 xfs="$default_feature"
 membarrier="$default_feature"
@@ -394,13 +398,13 @@ for opt do
   ;;
   --cpu=*) cpu="$optarg"
   ;;
-  --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
-                    QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
+  --extra-cflags=*)
+    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
+    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
+    ;;
+  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
   ;;
-  --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
-  ;;
-  --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
-                     EXTRA_LDFLAGS="$optarg"
+  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
   ;;
   --enable-debug-info) debug_info="yes"
   ;;
@@ -1346,8 +1350,8 @@ Advanced options (experts only):
                            build time
   --cxx=CXX                use C++ compiler CXX [$cxx]
   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
-  --extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
-  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_CXXFLAGS
+  --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
+  --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
   --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
   --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
   --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
@@ -3402,7 +3406,7 @@ EOF
 
     update_cxxflags
 
-    if do_cxx $CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
+    if do_cxx $CXXFLAGS $EXTRA_CXXFLAGS $CONFIGURE_CXXFLAGS $QEMU_CXXFLAGS -o $TMPE $TMPCXX $TMPO $QEMU_LDFLAGS; then
         # C++ compiler $cxx works ok with C compiler $cc
         :
     else
@@ -3909,10 +3913,10 @@ if test "$skip_meson" = no; then
 
   test -z "$cxx" && echo "link_language = 'c'" >> $cross
   echo "[built-in options]" >> $cross
-  echo "c_args = [$(meson_quote $CFLAGS)]" >> $cross
-  echo "cpp_args = [$(meson_quote $CXXFLAGS)]" >> $cross
-  echo "c_link_args = [$(meson_quote $LDFLAGS)]" >> $cross
-  echo "cpp_link_args = [$(meson_quote $LDFLAGS)]" >> $cross
+  echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
+  echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
+  echo "c_link_args = [$(meson_quote $LDFLAGS $EXTRA_LDFLAGS)]" >> $cross
+  echo "cpp_link_args = [$(meson_quote $LDFLAGS $EXTRA_LDFLAGS)]" >> $cross
   echo "[binaries]" >> $cross
   echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
   test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
-- 
2.33.1




^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars
  2021-11-08  8:43 [PATCH 0/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
                   ` (2 preceding siblings ...)
  2021-11-08  8:43 ` [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
@ 2021-11-08  8:43 ` Paolo Bonzini
  2021-11-08  9:17   ` Thomas Huth
  2021-11-08  9:17   ` Philippe Mathieu-Daudé
  3 siblings, 2 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08  8:43 UTC (permalink / raw)
  To: qemu-devel; +Cc: thuth

User flags should be passed via CFLAGS/CXXFLAGS/LDFLAGS,
or --extra-cflags/extra-cxxflags/--extra-ldflags on the
command line.

QEMU_CFLAGS, QEMU_CXXFLAGS and QEMU_LDFLAGS are reserved
for flags detected by configure, so do not add to them
and clear them at the beginning of the script.

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

diff --git a/configure b/configure
index 1ea26c67e5..2048a52b20 100755
--- a/configure
+++ b/configure
@@ -158,7 +158,7 @@ update_cxxflags() {
     # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
     # options which some versions of GCC's C++ compiler complain about
     # because they only make sense for C programs.
-    QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
+    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
     CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
     for arg in $QEMU_CFLAGS; do
         case $arg in
@@ -465,11 +465,13 @@ sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
 # left shift of signed integers is well defined and has the expected
 # 2s-complement style results. (Both clang and gcc agree that it
 # provides these semantics.)
-QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
+QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
 QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
 
+QEMU_LDFLAGS=
+
 # Flags that are needed during configure but later taken care of by Meson
 CONFIGURE_CFLAGS="-std=gnu11 -Wall"
 CONFIGURE_LDFLAGS=
-- 
2.33.1



^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 1/4] configure: simplify calls to meson_quote
  2021-11-08  8:43 ` [PATCH 1/4] configure: simplify calls to meson_quote Paolo Bonzini
@ 2021-11-08  9:02   ` Thomas Huth
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2021-11-08  9:02 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel

On 08/11/2021 09.43, Paolo Bonzini wrote:
> meson_quote assumes a non-empty argument list, and incorrectly returns a
> one-entry array if passed nothing.  Move the check for an empty argument
> list from the invocations to the function itself.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   configure | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/configure b/configure
> index 33682cb971..369b5455b6 100755
> --- a/configure
> +++ b/configure
> @@ -3894,6 +3894,7 @@ echo "TOPSRC_DIR=$source_path" >> $config_mak
>   if test "$skip_meson" = no; then
>     cross="config-meson.cross.new"
>     meson_quote() {
> +    test $# = 0 && return
>       echo "'$(echo $* | sed "s/ /','/g")'"
>     }
>   
> @@ -3908,10 +3909,10 @@ if test "$skip_meson" = no; then
>   
>     test -z "$cxx" && echo "link_language = 'c'" >> $cross
>     echo "[built-in options]" >> $cross
> -  echo "c_args = [${CFLAGS:+$(meson_quote $CFLAGS)}]" >> $cross
> -  echo "cpp_args = [${CXXFLAGS:+$(meson_quote $CXXFLAGS)}]" >> $cross
> -  echo "c_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
> -  echo "cpp_link_args = [${LDFLAGS:+$(meson_quote $LDFLAGS)}]" >> $cross
> +  echo "c_args = [$(meson_quote $CFLAGS)]" >> $cross
> +  echo "cpp_args = [$(meson_quote $CXXFLAGS)]" >> $cross
> +  echo "c_link_args = [$(meson_quote $LDFLAGS)]" >> $cross
> +  echo "cpp_link_args = [$(meson_quote $LDFLAGS)]" >> $cross
>     echo "[binaries]" >> $cross
>     echo "c = [$(meson_quote $cc $CPU_CFLAGS)]" >> $cross
>     test -n "$cxx" && echo "cpp = [$(meson_quote $cxx $CPU_CFLAGS)]" >> $cross
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 2/4] configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status
  2021-11-08  8:43 ` [PATCH 2/4] configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status Paolo Bonzini
@ 2021-11-08  9:04   ` Thomas Huth
  0 siblings, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2021-11-08  9:04 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: Daniel P. Berrange

On 08/11/2021 09.43, Paolo Bonzini wrote:
> CFLAGS, CXXFLAGS and LDFLAGS influence the tests (for example if they include
> -L or -I options), so they should be kept from the invocation of configure
> to the subsequent reinvocations via config.status.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   configure | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/configure b/configure
> index 369b5455b6..d268f59246 100755
> --- a/configure
> +++ b/configure
> @@ -4057,9 +4057,12 @@ preserve_env AR
>   preserve_env AS
>   preserve_env CC
>   preserve_env CPP
> +preserve_env CFLAGS
>   preserve_env CXX
> +preserve_env CXXFLAGS
>   preserve_env INSTALL
>   preserve_env LD
> +preserve_env LDFLAGS
>   preserve_env LD_LIBRARY_PATH
>   preserve_env LIBTOOL
>   preserve_env MAKE

Oh, we didn't preserve them yet? That's surprising!

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests
  2021-11-08  8:43 ` [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
@ 2021-11-08  9:11   ` Thomas Huth
  2021-11-08 11:07     ` Paolo Bonzini
  0 siblings, 1 reply; 12+ messages in thread
From: Thomas Huth @ 2021-11-08  9:11 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel

On 08/11/2021 09.43, Paolo Bonzini wrote:
> Meson (intentionally) does not add QEMU_CFLAGS to cc.compiles/cc.links
> tests, as they are supposed to be independent of the specific sets of
> compilation flags used to build the programs.  However, the user can
> still use CFLAGS or the toolchain file's LANG_args/LANG_link_args option
> to specify -I or -L options that apply to cc.compiles/cc.links as well.
> 
> This is also the intended use of configure's --extra-cflags,
> --extra-cxxflags and --extra-ldflags options.  For example, if
> one has netmap's header in a nonstandard directory, up to commit
> 837b84b1c078bf3e909 it used to work fine to do:
> 
> .../configure --enable-netmap \
>       --extra-cflags=-I/path/to/netmap/sys
> 
> but since the test was converted to meson, this does not work anymore.
> 
> Pass these options to meson via the toolchain file instead of via
> config-host.mak, since the toolchain file's variables have the
> same purpose as configure's --extra-*flags arguments.
> 
> Reported-by: Owen LaGarde
> Reported-by: Thomas Huth <thuth@redhat.com>
> Fixes: 47b30835e4 ("configure: consistently pass CFLAGS/CXXFLAGS/LDFLAGS to meson", 2020-10-06)
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   configure | 36 ++++++++++++++++++++----------------
>   1 file changed, 20 insertions(+), 16 deletions(-)
> 
> diff --git a/configure b/configure
> index d268f59246..1ea26c67e5 100755
> --- a/configure
> +++ b/configure
> @@ -174,14 +174,14 @@ update_cxxflags() {
>   
>   compile_object() {
>     local_cflags="$1"
> -  do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
> +  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -c -o $TMPO $TMPC
>   }
>   
>   compile_prog() {
>     local_cflags="$1"
>     local_ldflags="$2"
> -  do_cc $CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
> -      $LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
> +  do_cc $CFLAGS $EXTRA_CFLAGS $CONFIGURE_CFLAGS $QEMU_CFLAGS $local_cflags -o $TMPE $TMPC \
> +      $LDFLAGS $EXTRA_LDFLAGS $CONFIGURE_LDFLAGS $QEMU_LDFLAGS $local_ldflags
>   }
>   
>   # symbolically link $1 to $2.  Portable version of "ln -sf".
> @@ -286,6 +286,10 @@ for opt do
>     esac
>   done
>   
> +EXTRA_CFLAGS=""
> +EXTRA_CXXFLAGS=""
> +EXTRA_LDFLAGS=""
> +
>   xen_ctrl_version="$default_feature"
>   xfs="$default_feature"
>   membarrier="$default_feature"
> @@ -394,13 +398,13 @@ for opt do
>     ;;
>     --cpu=*) cpu="$optarg"
>     ;;
> -  --extra-cflags=*) QEMU_CFLAGS="$QEMU_CFLAGS $optarg"
> -                    QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
> +  --extra-cflags=*)
> +    EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
> +    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"

I'd rather drop that EXTRA_CXXFLAGS line here - I think that calls for 
trouble otherwise if a user is trying to add a C compiler option that is not 
supported in C++ mode.
If the users have some options that need to be passed to both, C and C++, 
they should simply use --extra-cxxflags in addition instead.

  Thomas

> +    ;;
> +  --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
>     ;;
> -  --extra-cxxflags=*) QEMU_CXXFLAGS="$QEMU_CXXFLAGS $optarg"
> -  ;;
> -  --extra-ldflags=*) QEMU_LDFLAGS="$QEMU_LDFLAGS $optarg"
> -                     EXTRA_LDFLAGS="$optarg"
> +  --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
>     ;;
>     --enable-debug-info) debug_info="yes"
>     ;;



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars
  2021-11-08  8:43 ` [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars Paolo Bonzini
@ 2021-11-08  9:17   ` Thomas Huth
  2021-11-08  9:17   ` Philippe Mathieu-Daudé
  1 sibling, 0 replies; 12+ messages in thread
From: Thomas Huth @ 2021-11-08  9:17 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel

On 08/11/2021 09.43, Paolo Bonzini wrote:
> User flags should be passed via CFLAGS/CXXFLAGS/LDFLAGS,
> or --extra-cflags/extra-cxxflags/--extra-ldflags on the
> command line.
> 
> QEMU_CFLAGS, QEMU_CXXFLAGS and QEMU_LDFLAGS are reserved
> for flags detected by configure, so do not add to them
> and clear them at the beginning of the script.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   configure | 6 ++++--
>   1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 1ea26c67e5..2048a52b20 100755
> --- a/configure
> +++ b/configure
> @@ -158,7 +158,7 @@ update_cxxflags() {
>       # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
>       # options which some versions of GCC's C++ compiler complain about
>       # because they only make sense for C programs.
> -    QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
> +    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
>       CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
>       for arg in $QEMU_CFLAGS; do
>           case $arg in
> @@ -465,11 +465,13 @@ sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
>   # left shift of signed integers is well defined and has the expected
>   # 2s-complement style results. (Both clang and gcc agree that it
>   # provides these semantics.)
> -QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv $QEMU_CFLAGS"
> +QEMU_CFLAGS="-fno-strict-aliasing -fno-common -fwrapv"
>   QEMU_CFLAGS="-Wundef -Wwrite-strings -Wmissing-prototypes $QEMU_CFLAGS"
>   QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
>   QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE $QEMU_CFLAGS"
>   
> +QEMU_LDFLAGS=
> +
>   # Flags that are needed during configure but later taken care of by Meson
>   CONFIGURE_CFLAGS="-std=gnu11 -Wall"
>   CONFIGURE_LDFLAGS=
> 

Reviewed-by: Thomas Huth <thuth@redhat.com>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars
  2021-11-08  8:43 ` [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars Paolo Bonzini
  2021-11-08  9:17   ` Thomas Huth
@ 2021-11-08  9:17   ` Philippe Mathieu-Daudé
  2021-11-08 10:45     ` Paolo Bonzini
  1 sibling, 1 reply; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-11-08  9:17 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel; +Cc: thuth

On 11/8/21 09:43, Paolo Bonzini wrote:
> User flags should be passed via CFLAGS/CXXFLAGS/LDFLAGS,
> or --extra-cflags/extra-cxxflags/--extra-ldflags on the
> command line.
> 
> QEMU_CFLAGS, QEMU_CXXFLAGS and QEMU_LDFLAGS are reserved
> for flags detected by configure, so do not add to them
> and clear them at the beginning of the script.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  configure | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 1ea26c67e5..2048a52b20 100755
> --- a/configure
> +++ b/configure
> @@ -158,7 +158,7 @@ update_cxxflags() {
>      # Set QEMU_CXXFLAGS from QEMU_CFLAGS by filtering out those
>      # options which some versions of GCC's C++ compiler complain about
>      # because they only make sense for C programs.
> -    QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
> +    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
>      CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
>      for arg in $QEMU_CFLAGS; do
>          case $arg in

update_cxxflags() should keep previous QEMU_CXXFLAGS. But since
we call it only once, we don't use it to update. IMHO we should
inline this code where it is called, then overwriting QEMU_CXXFLAGS
makes sense.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars
  2021-11-08  9:17   ` Philippe Mathieu-Daudé
@ 2021-11-08 10:45     ` Paolo Bonzini
  0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08 10:45 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel; +Cc: thuth

On 11/8/21 10:17, Philippe Mathieu-Daudé wrote:
>> -    QEMU_CXXFLAGS="$QEMU_CXXFLAGS -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
>> +    QEMU_CXXFLAGS="-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS"
>>       CONFIGURE_CXXFLAGS=$(echo "$CONFIGURE_CFLAGS" | sed s/-std=gnu11/-std=gnu++11/)
>>       for arg in $QEMU_CFLAGS; do
>>           case $arg in
> update_cxxflags() should keep previous QEMU_CXXFLAGS. But since
> we call it only once, we don't use it to update. IMHO we should
> inline this code where it is called, then overwriting QEMU_CXXFLAGS
> makes sense.

With Meson 0.60 it's possible to link-test a C source with a C++ 
compiler and then all this stuff (including the link_language detection) 
can be moved to the proper place.

Paolo



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests
  2021-11-08  9:11   ` Thomas Huth
@ 2021-11-08 11:07     ` Paolo Bonzini
  0 siblings, 0 replies; 12+ messages in thread
From: Paolo Bonzini @ 2021-11-08 11:07 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel

On 11/8/21 10:11, Thomas Huth wrote:
>> +    EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
> 
> I'd rather drop that EXTRA_CXXFLAGS line here - I think that calls for 
> trouble otherwise if a user is trying to add a C compiler option that is 
> not supported in C++ mode.
> If the users have some options that need to be passed to both, C and 
> C++, they should simply use --extra-cxxflags in addition instead.

True, but that is needed to preserve previous behavior, where 
QEMU_CXXFLAGS is initialized with QEMU_CFLAGS in update_cxxflags.

update_cxxflags does not do any filtering either, except for some -W 
options that shouldn't be in --extra-cflags.  So (apart from those -W 
options) a C-only option wouldn't have worked before with 
--extra-cflags, either.

Paolo



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-11-08 11:09 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-08  8:43 [PATCH 0/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
2021-11-08  8:43 ` [PATCH 1/4] configure: simplify calls to meson_quote Paolo Bonzini
2021-11-08  9:02   ` Thomas Huth
2021-11-08  8:43 ` [PATCH 2/4] configure: preserve CFLAGS, CXXFLAGS and LDFLAGS in config.status Paolo Bonzini
2021-11-08  9:04   ` Thomas Huth
2021-11-08  8:43 ` [PATCH 3/4] configure: propagate --extra-cflags and --extra-ldflags to meson compile tests Paolo Bonzini
2021-11-08  9:11   ` Thomas Huth
2021-11-08 11:07     ` Paolo Bonzini
2021-11-08  8:43 ` [PATCH 4/4] configure: ignore preexisting QEMU_*FLAGS envvars Paolo Bonzini
2021-11-08  9:17   ` Thomas Huth
2021-11-08  9:17   ` Philippe Mathieu-Daudé
2021-11-08 10:45     ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.