-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've noticed that config.guess will always detect my system as:
i686-pc-mingw32.
Turns out:
1) -pc vendor name is hard-coded into config.guess
2) config.guess relies on uname to get machine architecture

Both are wrong, because:
1) mingw-w64 toolchain has -w64 vendor name, but can (and should)
still be used with MSYS. uname is a MSYS-only utility, and has no
knowledge of the mingw toolchain installed alongside it. Thus uname
can't tell a difference between MSYS+mingw.org toolchain and
MSYS+mingw-w64 toolchain.
While it might (didn't test that) be possible to modify msys
configuration to identify itself differently, it would have to be
enforced from outside, and would still have nothing to do with the
toolchain.

2) uname only reports MSYS architecture. MSYS (at the moment; not sure
about MSYS2) is 32-bit only, and will always report itself as either
i386 or i686 (could also claim to be "alpha" or "mips", but that's
exotic) based upon GetSystemInfo() API call results. Even if it had
been capable of correctly identifying x86_64 versions of the OS, that
still would be somewhat at odds with the toolchain, because x86_64
Windows can run both x86 and x86_64 toolchains. It is better to ask
the toolchain about its architecture.

To this end, *:MINGW*:* case should not default to
${UNAME_MACHINE}-pc-mingw32, but should instead run CC like some other
tests do, and check for the following preprocessor definitions:
__MINGW32_MAJOR_VERSION
__MINGW64_VERSION_MAJOR
__MINGW32__
__MINGW64__

__MINGW32__ is defined by all mingw toolchains, both x86 and x86_64,
from both vendors (mingw.org and mingw-w64). If it isn't there, it's
not mingw. Defined by gcc internally.

__MINGW64__ is only defined by x86_64 toolchains (currently only
mingw-w64, but mingw.org might catch up in the future) alongside with
__MINGW32__. Defined by gcc internally.

__MINGW64_VERSION_MAJOR is only defined by mingw-w64 headers (same
headers used for both x86 and x86_64). Defined by headers, so you need
to include a standard header (such as stdio.h) for it to appear.

__MINGW32_MAJOR_VERSION is only defined by mingw.org headers. Defined
by headers, so you need to include a standard header (such as stdio.h)
for it to appear.

A proof-of-concept patch is attached.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJRVUevAAoJEOs4Jb6SI2CwDkEH/imcDKL4F+bAr+PZ7J5cNYnl
LZiWn1JRxFC9hTyVHMYoEHakkIKizxugTdCzMuKDMn5eEk01B5k3mNc8R+bz9rb7
BFhF4r9DPhM9gRqsch3r6OJ9qFQaFgRvqErkupTzXJykqfaFP1YOFsFM5PYV/a4l
d6TMtJidbCTnAdvFpFlZu5hLoX7owi5aZfn0DylRF8/vvcO1ZqsrpqtFuLU7Pfvn
1Bku/pG/VllIxDBwlEn46jinFeA3iY1z+LMb0cydrvGAbCKPpKZeHgsL/ZAeQPCE
0xfyEzOnD1pDaYYEr842TcABNkc30o3+WMVl83CyrZHu9Q7Hbwb1ArAhe0TqO58=
=vnKY
-----END PGP SIGNATURE-----
--- config.guess.orig   2013-03-29 11:15:46 +0400
+++ config.guess        2013-03-29 11:20:05 +0400
@@ -803,8 +803,45 @@
        echo ${UNAME_MACHINE}-pc-mingw64
        exit ;;
     *:MINGW*:*)
-       echo ${UNAME_MACHINE}-pc-mingw32
-       exit ;;
+        # This uname only tells us that MSYS is in MinGW mode.
+        # The toolchain used might be i686-pc-mingw32
+        # or x86_64-w64-mingw32 - MSYS can't know.
+        # Try cc test.
+       eval $set_cc_for_build
+       sed 's/^        //' << EOF >$dummy.c
+       #include <stdio.h>
+       __MINGW32__
+       __MINGW64__
+       __MINGW64_VERSION_MAJOR
+EOF
+       if $CC_FOR_BUILD -E $dummy.c 2>/dev/null | \
+         grep -q __MINGW32__ >/dev/null
+       then
+           # __MINGW32__ is not defined - this isn't MinGW at all.
+           :
+       else
+            if $CC_FOR_BUILD -E $dummy.c 2>/dev/null | \
+               grep -q __MINGW64__ >/dev/null
+            then
+               # 32-bit mingw
+               machine=i686
+            else
+               # 64-bit mingw
+               machine=x86_64
+           fi
+
+           if $CC_FOR_BUILD -E $dummy.c 2>/dev/null | \
+               grep -q __MINGW64_VERSION_MAJOR >/dev/null
+           then
+               # mingw.org toolchain
+               echo ${machine}-pc-mingw32
+           else
+               # mingw-w64 toolchain
+               echo ${machine}-w64-mingw32
+           fi
+           exit
+       fi
+       ;;
     i*:MSYS*:*)
        echo ${UNAME_MACHINE}-pc-msys
        exit ;;
--- Changelog.orig      2013-03-29 11:47:35 +0400
+++ Changelog   2013-03-29 11:26:59 +0400
@@ -1,3 +1,9 @@
+2013-03-29  LRN <lrn1...@gmail.com>
+
+       * config.guess (*:MINGW:*:*): do not use uname output to identify
+       the system, use compiler tests to detect machine architecture
+       (i686 or x86_64) and toolchain vendor (mingw.org or mingw-w64).
+
 2013-02-12  Christian Svensson  <b...@cmd.nu>
 
        * config.guess (or1k:Linux:*:*): New.
_______________________________________________
config-patches mailing list
config-patches@gnu.org
https://lists.gnu.org/mailman/listinfo/config-patches

Reply via email to