diff mbox series

[v1,02/24] configure: add support for --cross-cc-FOO

Message ID 20180410193919.28026-3-alex.bennee@linaro.org
State Superseded
Headers show
Series fix building of tests/tcg | expand

Commit Message

Alex Bennée April 10, 2018, 7:38 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.16.2

Comments

Philippe Mathieu-Daudé April 16, 2018, 2:04 a.m. UTC | #1
On 04/10/2018 04:38 PM, 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(+)

> 

> diff --git a/configure b/configure

> index b402befe94..b5f3b3fe29 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"


These seems distrib-specific... Should we add a case $distrib) ...?

> +

> +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"

>    ;;

> @@ -6766,6 +6782,8 @@ case "$target" in

>      ;;

>  esac

>  

> +target_compiler=""

> +

>  mkdir -p $target_dir

>  echo "# Automatically generated by configure - do not modify" > $config_target_mak

>  

> @@ -6794,6 +6812,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

> @@ -6801,6 +6820,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)

>    ;;

> @@ -6842,6 +6862,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

> @@ -6916,6 +6937,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() {

> @@ -6989,6 +7029,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=""

> @@ -7111,6 +7155,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

>
Alex Bennée April 16, 2018, 8:49 a.m. UTC | #2
Philippe Mathieu-Daudé <f4bug@amsat.org> writes:

> On 04/10/2018 04:38 PM, 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(+)

>> 

>> diff --git a/configure b/configure

>> index b402befe94..b5f3b3fe29 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"

>

> These seems distrib-specific... Should we add a case $distrib) ...?


I think of this more as sensible defaults - I would expect most people
using local cross-compilers to be manually setting them up with the
--cross-cc-FOO flag.

>

>> +

>> +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"

>>    ;;

>> @@ -6766,6 +6782,8 @@ case "$target" in

>>      ;;

>>  esac

>>  

>> +target_compiler=""

>> +

>>  mkdir -p $target_dir

>>  echo "# Automatically generated by configure - do not modify" > $config_target_mak

>>  

>> @@ -6794,6 +6812,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

>> @@ -6801,6 +6820,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)

>>    ;;

>> @@ -6842,6 +6862,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

>> @@ -6916,6 +6937,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() {

>> @@ -6989,6 +7029,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=""

>> @@ -7111,6 +7155,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

>> 



-- 
Alex Bennée
diff mbox series

Patch

diff --git a/configure b/configure
index b402befe94..b5f3b3fe29 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"
   ;;
@@ -6766,6 +6782,8 @@  case "$target" in
     ;;
 esac
 
+target_compiler=""
+
 mkdir -p $target_dir
 echo "# Automatically generated by configure - do not modify" > $config_target_mak
 
@@ -6794,6 +6812,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
@@ -6801,6 +6820,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)
   ;;
@@ -6842,6 +6862,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
@@ -6916,6 +6937,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() {
@@ -6989,6 +7029,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=""
@@ -7111,6 +7155,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