autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: unreliable detection of universal builds in AC_C_BIGENDIAN


From: Bruno Haible
Subject: Re: unreliable detection of universal builds in AC_C_BIGENDIAN
Date: Fri, 26 Dec 2008 12:51:18 +0100
User-agent: KMail/1.9.9

Hi Eric,
> >     # Check for potential -arch flags.  It is not universal unless
> > !   # there are some -arch flags.
> > !   ac_prev=
> > !   for ac_word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
> > !     if test -n "$ac_prev"; then
> > !       case $ac_word in
> > !         i386 | x86_64 | ppc | ppc64) ac_cv_c_bigendian=universal ;;
> > !       esac
> > !       ac_prev=
> > !     else
> > !       if test "x$ac_word" = "x-arch"; then
> 
> Can the argument to -arch be specified with an =, rather than as the next
> argument, in which case this doesn't work?

No, it cannot. Also, -arch is not an abbreviation:

$ gcc -arch i386 -c foo.c
$ gcc -arch=i386 -c foo.c
cc1: error: unrecognized command line option "-arch=i386"
$ gcc -architecture i386 -c foo.c
i686-apple-darwin9-gcc-4.0.1: i386: No such file or directory
cc1: error: unrecognized command line option "-architecture"

> Wouldn't this also do the trick, by narrowing the search to an argument
> that starts with -arch, without resorting to an iteration over arguments?
> 
> case " $CC $CFLAGS $CPPFLAGS $LDFLAGS" in  #(
>   *\ -arch*ppc* | *\ -arch*i386* | *\ -arch*x86_64*)
>     ac_cv_c_bigendian=universal;;
> esac

No it wouldn't. $CC, $CFLAGS etc. can also use tabs instead of spaces as word
separator. To iterate over the words of a command, the simplest way is really
a 'for' loop.

Additionally, a single -arch option does not make a build universal. For
example, CC="gcc -arch x86_64" is the normal way to do a 64-bit build on
MacOS X 10.5. It's a universal build (in the sense that "$CC -E" does not
work any more) only if there are at least two -arch options with different
values:

$ gcc -arch i386 foo.c -E           
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"

$ gcc -arch i386 -arch i386 foo.c -E
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "foo.c"

$ gcc -arch i386 -arch x86_64 foo.c -E
gcc-4.0: -E, -S, -save-temps and -M options are not allowed with multiple -arch 
flags

Here is a revised proposed patch:


2008-12-26  Bruno Haible  <address@hidden>

        * lib/autoconf/c.m4 (AC_C_BIGENDIAN): Make detection of options
        indicating a universal build more reliable.

--- lib/autoconf/c.m4.orig      2008-12-26 12:49:14.000000000 +0100
+++ lib/autoconf/c.m4   2008-12-26 12:48:59.000000000 +0100
@@ -1312,11 +1313,27 @@
            ]])],
         [
        # Check for potential -arch flags.  It is not universal unless
-       # there are some -arch flags.  Note that *ppc* also matches
-       # ppc64.  This check is also rather less than ideal.
-       case "${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}" in  #(
-         *-arch*ppc*|*-arch*i386*|*-arch*x86_64*) ac_cv_c_bigendian=universal;;
-       esac])
+       # there are at least two -arch flags with different values.
+       ac_arch=
+       ac_prev=
+       for ac_word in ${CC} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS}; do
+         if test -n "$ac_prev"; then
+           case $ac_word in
+             i?86 | x86_64 | ppc | ppc64)
+               if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
+                 ac_arch="$ac_word"
+               else
+                 ac_cv_c_bigendian=universal
+               fi
+               ;;
+           esac
+           ac_prev=
+         else
+           if test "x$ac_word" = "x-arch"; then
+             ac_prev=arch
+           fi
+         fi
+       done])
     if test $ac_cv_c_bigendian = unknown; then
       # See if sys/param.h defines the BYTE_ORDER macro.
       AC_COMPILE_IFELSE(




reply via email to

[Prev in Thread] Current Thread [Next in Thread]