This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author trent
Recipients Arfrever, eric.araujo, gix, jcea, jkloth, loewis, skrah, trent
Date 2012-12-14.05:26:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1355462817.21.0.793915768209.issue15963@psf.upfronthosting.co.za>
In-reply-to
Content
I spent a little time on this yesterday.  Here's what I came up with.  The idea is to have a standalone block in configure.ac that kicks in when --without-gcc is specified (or if $CC != "gcc") *IFF* CFLAGS/CPPFLAGS haven't been provided by the user.

If they have, we warn, and skip the block.  Rationale is wanting to cover two cases: a) experienced user consciously overriding our attempts at sensible defaults in that block, b) inexperienced user who has no clue what the sensible defaults are but has otherwise inadvertently set CFLAGS/CPPFLAGS (or perhaps just inherited such settings from their existing environment).

So, here's what the "block" looks like currently, albeit just for IRIX at the moment (and this was against 2.7).  I'll eventually expand it to cover Solaris/SPARC|AMD64, AIX, HP-UX (PA-RISC/IA64) and Tru64.

(Also note the new `--enable-64bit` arg, which is intended to be used on these platforms as a way to coerce easy 64-bit builds.  The functionality doesn't apply on x86/x64 "free" *nix platforms that use clang/gcc -- those will default to using whatever memory architecture is being used by the underlying system -- if you want something else, that's the job of cross-compilation, which is a different problem this particular issue is attempting to address.)

+AC_MSG_CHECKING(for --enable-64bit)
+AC_ARG_ENABLE(
+    64bit,
+    AS_HELP_STRING(
+        [--enable-64bit],
+        [attempt 64-bit build (use with --without-gcc)]
+    )
+)
+if test -z "$enable_64bit"; then
+    AC_MSG_RESULT(no)
+else
+    AC_MSG_RESULT(yes)
+fi
+if test -n "$enable_64bit" && test "$without_gcc" != "yes"; then
+    AC_MSG_WARN([
+        --enable-64bit has no effect unless --without-gcc is also specified
+    ])
+fi
+
+# If we're not using GCC, we're probably on a proprietary UNIX, relying
+# on a proprietary compiler, running on non-x86/x64 hardware.  Autoconf
+# is pretty bad at picking sensible defaults for compiler flags in this
+# situation, so, let's try and do as much as we can ourselves.  The aim
+# is to pick the optimal settings for each of the following permutations:
+#
+# Debug builds, 32-bit and 64-bit:
+#   ./configure --without-gcc --with-pydebug
+#   ./configure --without-gcc --with-pydebug --enable-64bit
+#
+# Optimized release builds, 32-bit and 64-bit:
+#   ./configure --without-gcc
+#   ./configure --without-gcc --enable-64bit
+#
+if test "$without_gcc" = "yes" || test "$CC" != "gcc"; then
+    # This whole block assumes we know more than a) the user, and b) autoconf.
+    # If we detect CFLAGS/CPPFLAGS, then we can't safely assume a) anymore,
+    # so print a message instead of doing any customisation.
+    if test -n "$CFLAGS" || test -n "$CPPFLAGS"; then
+        AC_MSG_WARN([
+            You have defined CFLAGS and/or CPPFLAGS in conjunction with
+            --with-gcc; skipping attempt at setting flags to sensible
+            defaults -- make sure you know what you are doing.
+        ])
+    else
+        case $MACHDEP in
+            irix6)
+                # Trying to separate IRIX from C99 and still end up with a
+                # working executable is an exercise in futility; it has a
+                # much greater link between `cc -c99` and available system
+                # facilities/headers than other OSes (which primarily rely
+                # on the usual XPG4/XOPEN_SOURCE etc defines).  Using the
+                # c99 compiler is the lesser of two evils.
+                CC=c99
+                CXX=CC
+                # `-diag_error 1035` makes the compiler treat #error defines
+                # as actual errors (and abort compilation), and not warnings.
+                CFLAGS="-diag_error 1035"
+                # Try to target the underlying host hardware.
+                _platform=`hinv -c processor |
+                           head -n 1         |
+                           cut -f 4 -d ' '`
+                _processor=`hinv -c processor |
+                            head -n 2         |
+                            tail -n 1         |
+                            cut -f 3 -d ' '`
+                CFLAGS="$CFLAGS -TARG:platform=$_platform"
+                CFLAGS="$CFLAGS -TARG:processor=$_processor"
+
+                if test "$with_pydebug" = "yes"; then
+                    OPT="-O -g2"
+                else
+                    OPT="-g3 -Ofast=$_platform -OPT:Olimit=5500"
+                fi
+
+                if test -n "$enable_64bit"; then
+                    CFLAGS="-64 $CFLAGS"
+                    LDFLAGS="-64"
+                else
+                    CFLAGS="-n32 $CFLAGS"
+                    LDFLAGS="-n32"
+                fi
+                ;;
+            *)  ;;
+        esac
     fi
 fi
History
Date User Action Args
2012-12-14 05:26:57trentsetrecipients: + trent, loewis, jcea, jkloth, eric.araujo, Arfrever, skrah, gix
2012-12-14 05:26:57trentsetmessageid: <1355462817.21.0.793915768209.issue15963@psf.upfronthosting.co.za>
2012-12-14 05:26:57trentlinkissue15963 messages
2012-12-14 05:26:54trentcreate