Skip to contentSkip to conversation

configure: Fixes for --cross-cc-FOO

PATCH New Greg Kurz 1 participant 3 messages Jul 23, 2021

lore
Share & tools
lore

Greg Kurz

author
#0 lore raw

cover configure: Fixes for --cross-cc-FOO

This series fixes some issues I've hit while trying to compile TCG checks with a cross-compiler, as an alternative to using docker.

This isn't a regression in QEMU 6.1: the issues have been around since they got merged in QEMU 3.0. Hence clearly QEMU 6.2 material.

Greg Kurz (2):
configure: Fix trivial typo in --cross-cc-cflags-FOO
configure: Fix excessive error detection when handling --cross-cc-FOO

 configure              | 29 ++++++++++++++++++-----------
 docs/devel/testing.rst |  2 +-
 2 files changed, 19 insertions(+), 12 deletions(-)
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 1/2 configure: Fix trivial typo in --cross-cc-cflags-FOO

The 'flags' wording is used in several places instead of 'cflags'.

$ git grep cross-cc-flags
configure:  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
configure:  --cross-cc-flags-ARCH=   use compiler flags when building ARCH guest tests
docs/devel/testing.rst:There is also a ``--cross-cc-flags-ARCH`` flag in case additional

Fix this treewide.

Fixes d422b2bc23bf ("configure: allow user to specify --cross-cc-cflags-foo=")
Fixes f8ed349e6d14 ("docs/devel: add "check-tcg" to testing.rst")
---
 configure              | 4 ++--
 docs/devel/testing.rst | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
configure +2 -2
index b5965b159f2f..3a926ff8fc23 100755
@@ -474,7 +474,7 @@ for opt do
   ;;
   --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
   ;;
-  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-flags-}; cc_arch=${cc_arch%%=*}
+  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
                       eval "cross_cc_cflags_${cc_arch}=\$optarg"
                       cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
   ;;
@@ -1764,7 +1764,7 @@ Advanced options (experts only):
   --extra-cxxflags=CXXFLAGS append extra C++ compiler flags QEMU_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
+  --cross-cc-cflags-ARCH=CFLAGS use compiler flags when building ARCH guest tests
   --make=MAKE              use specified make [$make]
   --python=PYTHON          use specified python [$python]
   --sphinx-build=SPHINX    use specified sphinx-build [$sphinx_build]
docs/devel/testing.rst +1 -1
index 8f572255d320..a8c8aa365cf8 100644
@@ -1142,7 +1142,7 @@ for the architecture in question, for example::
 
   $(configure) --cross-cc-aarch64=aarch64-cc
 
-There is also a ``--cross-cc-flags-ARCH`` flag in case additional
+There is also a ``--cross-cc-cflags-ARCH`` flag in case additional
 compiler flags are needed to build for a given target.
 
 If you have the ability to run containers as the user the build system
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 2/2 configure: Fix excessive error detection when handling --cross-cc-FOO

In reply to Greg Kurz

Passing a --cross-cc-cflags-* option with a value that contains a '=' causes configure to exit:

$ ./configure --cross-cc-cflags-arm='-DFOO=bar'

ERROR: Passed bad --cross-cc-FOO option

This is an annoying limitation since '=' is frequently found in CFLAGS.

This is caused by this line in the CC options parsing loop:

  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"

The '[!a-zA-Z0-9_-]' pattern matches the first '=' in the option and the '=' pattern matches the other one. The '*' patterns then match the rest.

The intent seems to be that we only want characters from the range [a-zA-Z0-9_-] in the option name. Shell pattern matching isn't powerful enough to do that with a single expression.

First, isolate the option name, i.e. before the first '=' character, with a regular expression. Only error out if there's at least one unwanted character in the name.

Fixes d75402b5ee29 ("configure: add support for --cross-cc-FOO")
---
 configure | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
configure +17 -10
index 3a926ff8fc23..61a415e4dc61 100755
@@ -472,16 +472,23 @@ for opt do
   ;;
   --disable-debug-info) debug_info="no"
   ;;
-  --cross-cc-*[!a-zA-Z0-9_-]*=*) error_exit "Passed bad --cross-cc-FOO option"
-  ;;
-  --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
-                      eval "cross_cc_cflags_${cc_arch}=\$optarg"
-                      cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
-  ;;
-  --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
-                cc_archs="$cc_archs $cc_arch"
-                eval "cross_cc_${cc_arch}=\$optarg"
-                cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
+  --cross-cc-*=*)
+    optname=$(expr "x$opt" : 'x\([^=]*\)=.*')
+    case "$optname" in
+    *[!a-zA-Z0-9_-]*) error_exit "Passed bad $optname option"
+    ;;
+    esac
+    case "$opt" in
+    --cross-cc-cflags-*) cc_arch=${opt#--cross-cc-cflags-}; cc_arch=${cc_arch%%=*}
+                         eval "cross_cc_cflags_${cc_arch}=\$optarg"
+                         cross_cc_vars="$cross_cc_vars cross_cc_cflags_${cc_arch}"
+    ;;
+    --cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}
+                  cc_archs="$cc_archs $cc_arch"
+                  eval "cross_cc_${cc_arch}=\$optarg"
+                  cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
+    ;;
+    esac
   ;;
   esac
 done
Signature · 1 line
2.31.1