Commit ac0df51d7b3e0a76923a03efa2cfdec4b9f65ef5

Authored by aliguori
1 parent 0a6f8a6d

Parse --cc and --cross-prefix earlier and use CC to determine cpu and host

We have been relying on uname to determine the host cpu architecture and
operating system.  This is totally broken for cross compilation.  It was
workable in the past because you can manually override both settings but after
the host USB passthrough refactoring, cross host builds were broken.

This moves the parsing of --cc and --cross-prefix to before the probes for cpu
and host.  Complation testing is used to determine the host and CPU types.  I've
only added checks for i386, x86_64, Linux, and Windows since these are the only
platforms I have access to for testing.  Everything else falls back to uname.

It should be relatively easy to add the right checks for other platforms and
eliminate uname altogether.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6141 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 59 additions and 33 deletions
configure
... ... @@ -33,7 +33,56 @@ ar=&quot;ar&quot;
33 33 make="make"
34 34 install="install"
35 35 strip="strip"
36   -cpu=`test $(uname -s) = AIX && uname -p || uname -m`
  36 +
  37 +# parse CC options first
  38 +for opt do
  39 + optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
  40 + case "$opt" in
  41 + --cross-prefix=*) cross_prefix="$optarg"
  42 + ;;
  43 + --cc=*) cc="$optarg"
  44 + ;;
  45 + esac
  46 +done
  47 +
  48 +# OS specific
  49 +# Using uname is really, really broken. Once we have the right set of checks
  50 +# we can eliminate it's usage altogether
  51 +
  52 +cc="${cross_prefix}${cc}"
  53 +ar="${cross_prefix}${ar}"
  54 +strip="${cross_prefix}${strip}"
  55 +
  56 +# check that the C compiler works.
  57 +cat > $TMPC <<EOF
  58 +int main(void) {}
  59 +EOF
  60 +
  61 +if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC > /dev/null 2> /dev/null ; then
  62 + : C compiler works ok
  63 +else
  64 + echo "ERROR: \"$cc\" either does not exist or does not work"
  65 + exit 1
  66 +fi
  67 +
  68 +check_define() {
  69 +cat > $TMPC <<EOF
  70 +#if !defined($1)
  71 +#error Not defined
  72 +#endif
  73 +int main(void) { return 0; }
  74 +EOF
  75 + $cc $ARCH_CFLAGS -c -o $TMPO $TMPC > /dev/null 2> /dev/null
  76 +}
  77 +
  78 +if check_define __i386__ ; then
  79 + cpu="i386"
  80 +elif check_define __x86_64__ ; then
  81 + cpu="x86_64"
  82 +else
  83 + cpu=`test $(uname -s) = AIX && uname -p || uname -m`
  84 +fi
  85 +
37 86 target_list=""
38 87 case "$cpu" in
39 88 i386|i486|i586|i686|i86pc|BePC)
... ... @@ -122,7 +171,13 @@ blobs=&quot;yes&quot;
122 171 fdt="yes"
123 172  
124 173 # OS specific
125   -targetos=`uname -s`
  174 +if check_define __linux__ ; then
  175 + targetos="Linux"
  176 +elif check_define _WIN32 ; then
  177 + targetos='MINGW32'
  178 +else
  179 + targetos=`uname -s`
  180 +fi
126 181 case $targetos in
127 182 CYGWIN*)
128 183 mingw32="yes"
... ... @@ -264,9 +319,9 @@ for opt do
264 319 --source-path=*) source_path="$optarg"
265 320 source_path_used="yes"
266 321 ;;
267   - --cross-prefix=*) cross_prefix="$optarg"
  322 + --cross-prefix=*)
268 323 ;;
269   - --cc=*) cc="$optarg"
  324 + --cc=*)
270 325 ;;
271 326 --host-cc=*) host_cc="$optarg"
272 327 ;;
... ... @@ -487,35 +542,6 @@ echo &quot;NOTE: The object files are built at the place where configure is launched&quot;
487 542 exit 1
488 543 fi
489 544  
490   -cc="${cross_prefix}${cc}"
491   -ar="${cross_prefix}${ar}"
492   -strip="${cross_prefix}${strip}"
493   -
494   -# check that the C compiler works.
495   -cat > $TMPC <<EOF
496   -int main(void) {}
497   -EOF
498   -
499   -if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC > /dev/null 2> /dev/null ; then
500   - : C compiler works ok
501   -else
502   - echo "ERROR: \"$cc\" either does not exist or does not work"
503   - exit 1
504   -fi
505   -
506   -# check compiler to see if we're on mingw32
507   -cat > $TMPC <<EOF
508   -#include <windows.h>
509   -#ifndef _WIN32
510   -#error not windows
511   -#endif
512   -int main(void) {}
513   -EOF
514   -
515   -if $cc $ARCH_CFLAGS -c -o $TMPO $TMPC > /dev/null 2> /dev/null ; then
516   - mingw32="yes"
517   -fi
518   -
519 545 if test "$mingw32" = "yes" ; then
520 546 linux="no"
521 547 EXESUF=".exe"
... ...