diff mbox series

[v2,03/43] configure: add support for --cross-cc-FOO

Message ID 20180419135901.30035-4-alex.bennee@linaro.org
State New
Headers show
Series fix building of tests/tcg | expand

Commit Message

Alex Bennée April 19, 2018, 1:58 p.m. UTC
This allows us to specify cross compilers for our guests. This is
useful for building test images/programs. Currently we re-run the
compile test for each target. I couldn't think of a way to cache the
value for a given arch without getting messier configure code.

The cross compiler for the guest is visible to each target as
CROSS_CC_GUEST in config-target.mak.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 configure | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

-- 
2.17.0

Comments

Richard Henderson April 19, 2018, 8:20 p.m. UTC | #1
On 04/19/2018 03:58 AM, Alex Bennée wrote:
> @@ -6805,6 +6823,7 @@ case "$target_name" in

>      bflt="yes"

>      mttcg="yes"

>      gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"

> +    target_compiler=$cross_cc_arm

>    ;;

>    aarch64|aarch64_be)

>      TARGET_ARCH=aarch64

> @@ -6812,6 +6831,7 @@ case "$target_name" in

>      bflt="yes"

>      mttcg="yes"

>      gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"

> +    target_compiler=$cross_cc_aarch64

>    ;;

>    cris)

>    ;;


Is there any reason not to fill in the reset of the cases within the switch at
the same time?


r~
Richard Henderson April 19, 2018, 8:41 p.m. UTC | #2
On 04/19/2018 03:58 AM, Alex Bennée wrote:
> +  --cross-cc-*) cc_arch=${opt#--cross-cc-}

> +                eval "cross_cc_${cc_arch}=\$optarg"


This doesn't work as intended.

Given e.g. --cross-cc-aarch64=aarch64-linux-gcc

+ cc_arch=aarch64=aarch64-linux-gcc
+ eval 'cross_cc_aarch64=aarch64-linux-gcc=$optarg'
++ cross_cc_aarch64=aarch64-linux-gcc=aarch64-linux-gcc

Which sets the variable "cross_cc_aarch64"
to "aarch64-linux-gcc=aarch64-linux-gcc".
Which of course won't exist to execute.


r~
Richard Henderson April 19, 2018, 8:47 p.m. UTC | #3
On 04/19/2018 10:41 AM, Richard Henderson wrote:
> On 04/19/2018 03:58 AM, Alex Bennée wrote:

>> +  --cross-cc-*) cc_arch=${opt#--cross-cc-}

>> +                eval "cross_cc_${cc_arch}=\$optarg"

> 

> This doesn't work as intended.

> 

> Given e.g. --cross-cc-aarch64=aarch64-linux-gcc

> 

> + cc_arch=aarch64=aarch64-linux-gcc

> + eval 'cross_cc_aarch64=aarch64-linux-gcc=$optarg'

> ++ cross_cc_aarch64=aarch64-linux-gcc=aarch64-linux-gcc

> 

> Which sets the variable "cross_cc_aarch64"

> to "aarch64-linux-gcc=aarch64-linux-gcc".

> Which of course won't exist to execute.


-  --cross-cc-*) cc_arch=${opt#--cross-cc-}
+  --cross-cc-*) cc_arch=$(expr "$opt" : '--cross-cc-\([^=]*\)')

seems to do the trick.  Obviously a similar change will be needed for
--cross-cc-flags-*.


r~
Eric Blake April 19, 2018, 9:36 p.m. UTC | #4
On 04/19/2018 03:47 PM, Richard Henderson wrote:
> On 04/19/2018 10:41 AM, Richard Henderson wrote:

>> On 04/19/2018 03:58 AM, Alex Bennée wrote:

>>> +  --cross-cc-*) cc_arch=${opt#--cross-cc-}

>>> +                eval "cross_cc_${cc_arch}=\$optarg"

>>

>> This doesn't work as intended.

>>

>> Given e.g. --cross-cc-aarch64=aarch64-linux-gcc

>>

>> + cc_arch=aarch64=aarch64-linux-gcc

>> + eval 'cross_cc_aarch64=aarch64-linux-gcc=$optarg'

>> ++ cross_cc_aarch64=aarch64-linux-gcc=aarch64-linux-gcc

>>

>> Which sets the variable "cross_cc_aarch64"

>> to "aarch64-linux-gcc=aarch64-linux-gcc".

>> Which of course won't exist to execute.

> 

> -  --cross-cc-*) cc_arch=${opt#--cross-cc-}

> +  --cross-cc-*) cc_arch=$(expr "$opt" : '--cross-cc-\([^=]*\)')


Forking an expr subshell may not be needed; how about:

--cross-cc-*) cc_arch=${opt#--cross-cc-}; cc_arch=${cc_arch%%=*}

to strip both the --cross-cc- prefix, and any suffix starting at the
first =.

> 

> seems to do the trick.  Obviously a similar change will be needed for

> --cross-cc-flags-*.

> 

> 

> r~

> 

> 


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
Eric Blake April 19, 2018, 9:41 p.m. UTC | #5
On 04/19/2018 08:58 AM, Alex Bennée wrote:
> This allows us to specify cross compilers for our guests. This is

> useful for building test images/programs. Currently we re-run the

> compile test for each target. I couldn't think of a way to cache the

> value for a given arch without getting messier configure code.

> 

> The cross compiler for the guest is visible to each target as

> CROSS_CC_GUEST in config-target.mak.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  configure | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++

>  1 file changed, 50 insertions(+)

> 


> @@ -483,6 +490,11 @@ for opt do

>    ;;

>    --disable-debug-info) debug_info="no"

>    ;;

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


Not quite right; it looks like you intended to have a trailing - instead
of 0; and if you are trying to filter out bad characters, then you need
* on both sides of the [!...] list:

--cross-cc-*[!a-zA-Z0-9_-]*=*)

otherwise you are only filtering out bad characters immediately before
the first =.  There's also the question of whether I can spell both
'--cross-cc-FOO=BAR' as one argument and '--cross-cc-FOO BAR' as two
arguments; this is filtering out only the one-argument case.

> +  ;;

> +  --cross-cc-*) cc_arch=${opt#--cross-cc-}

> +                eval "cross_cc_${cc_arch}=\$optarg"

> +  ;;



-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
diff mbox series

Patch

diff --git a/configure b/configure
index b0ae632ee4..0dca341f2a 100755
--- a/configure
+++ b/configure
@@ -453,6 +453,13 @@  vxhs=""
 libxml2=""
 docker="no"
 
+# cross compilers defaults, can be overridden with --cross-cc-ARCH
+cross_cc_aarch64="aarch64-linux-gnu-gcc"
+cross_cc_arm="arm-linux-gnueabihf-gcc"
+cross_cc_powerpc="powerpc-linux-gnu-gcc"
+
+enabled_cross_compilers=""
+
 supported_cpu="no"
 supported_os="no"
 bogus_os="no"
@@ -483,6 +490,11 @@  for opt do
   ;;
   --disable-debug-info) debug_info="no"
   ;;
+  --cross-cc-*[!a-zA-Z0-9_0]=*) error_exit "Passed bad --cross-cc-FOO option"
+  ;;
+  --cross-cc-*) cc_arch=${opt#--cross-cc-}
+                eval "cross_cc_${cc_arch}=\$optarg"
+  ;;
   esac
 done
 # OS specific
@@ -675,10 +687,12 @@  case "$cpu" in
   i386|i486|i586|i686|i86pc|BePC)
     cpu="i386"
     supported_cpu="yes"
+    cross_cc_i386=gcc
   ;;
   x86_64|amd64)
     cpu="x86_64"
     supported_cpu="yes"
+    cross_cc_x86_64=gcc
   ;;
   armv*b|armv*l|arm)
     cpu="arm"
@@ -912,6 +926,8 @@  for opt do
   ;;
   --disable-debug-info)
   ;;
+  --cross-cc-*)
+  ;;
   --enable-modules)
       modules="yes"
   ;;
@@ -6777,6 +6793,8 @@  case "$target" in
     ;;
 esac
 
+target_compiler=""
+
 mkdir -p $target_dir
 echo "# Automatically generated by configure - do not modify" > $config_target_mak
 
@@ -6805,6 +6823,7 @@  case "$target_name" in
     bflt="yes"
     mttcg="yes"
     gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
+    target_compiler=$cross_cc_arm
   ;;
   aarch64|aarch64_be)
     TARGET_ARCH=aarch64
@@ -6812,6 +6831,7 @@  case "$target_name" in
     bflt="yes"
     mttcg="yes"
     gdb_xml_files="aarch64-core.xml aarch64-fpu.xml arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
+    target_compiler=$cross_cc_aarch64
   ;;
   cris)
   ;;
@@ -6853,6 +6873,7 @@  case "$target_name" in
   ;;
   ppc)
     gdb_xml_files="power-core.xml power-fpu.xml power-altivec.xml power-spe.xml"
+    target_compiler=$cross_cc_powerpc
   ;;
   ppcemb)
     TARGET_BASE_ARCH=ppc
@@ -6927,6 +6948,25 @@  if [ "$TARGET_BASE_ARCH" = "" ]; then
   TARGET_BASE_ARCH=$TARGET_ARCH
 fi
 
+# Do we have a cross compiler for this target?
+if has $target_compiler; then
+
+    cat > $TMPC << EOF
+#include <stdio.h>
+int main(void) {
+    printf("Hello World!\n");
+}
+EOF
+
+    if ! do_compiler $target_compiler -o $TMPE $TMPC -static ; then
+        target_compiler=""
+    else
+        enabled_cross_compilers="${enabled_cross_compilers} ${target_compiler}"
+    fi
+else
+    target_compiler=""
+fi
+
 symlink "$source_path/Makefile.target" "$target_dir/Makefile"
 
 upper() {
@@ -7000,6 +7040,10 @@  if test "$target_bsd_user" = "yes" ; then
   echo "CONFIG_BSD_USER=y" >> $config_target_mak
 fi
 
+if test -n "$target_compiler"; then
+  echo "CROSS_CC_GUEST=$target_compiler" >> $config_target_mak
+fi
+
 # generate QEMU_CFLAGS/LDFLAGS for targets
 
 cflags=""
@@ -7122,6 +7166,12 @@  echo "QEMU_CFLAGS+=$cflags" >> $config_target_mak
 
 done # for target in $targets
 
+if test -n "$enabled_cross_compilers"; then
+    echo
+    echo "NOTE: cross-compilers enabled:"
+    printf '%s\n' $enabled_cross_compilers | sort -u
+fi
+
 if [ "$dtc_internal" = "yes" ]; then
   echo "config-host.h: subdir-dtc" >> $config_host_mak
 fi