diff -r 876bee0bd0ba Lib/distutils/command/build_ext.py --- a/Lib/distutils/command/build_ext.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/distutils/command/build_ext.py Tue Nov 29 15:34:50 2016 +0100 @@ -10,7 +10,8 @@ import sys from distutils.core import Command from distutils.errors import * -from distutils.sysconfig import customize_compiler, get_python_version +from distutils.sysconfig import (customize_compiler, get_python_version, + cross_compiling) from distutils.sysconfig import get_config_h_filename from distutils.dep_util import newer_group from distutils.extension import Extension @@ -156,7 +157,7 @@ # If in a virtualenv, add its include directory # Issue 16116 - if sys.exec_prefix != sys.base_exec_prefix: + if not cross_compiling and sys.exec_prefix != sys.base_exec_prefix: self.include_dirs.append(os.path.join(sys.exec_prefix, 'include')) # Put the Python "system" include dir at the end, so that diff -r 876bee0bd0ba Lib/distutils/command/install.py --- a/Lib/distutils/command/install.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/distutils/command/install.py Tue Nov 29 15:34:50 2016 +0100 @@ -8,7 +8,7 @@ from distutils import log from distutils.core import Command from distutils.debug import DEBUG -from distutils.sysconfig import get_config_vars +from distutils.sysconfig import (get_config_vars, cross_compiling) from distutils.errors import DistutilsPlatformError from distutils.file_util import write_file from distutils.util import convert_path, subst_vars, change_root @@ -281,12 +281,10 @@ # about needing recursive variable expansion (shudder). py_version = sys.version.split()[0] - (prefix, exec_prefix) = get_config_vars('prefix', 'exec_prefix') - try: - abiflags = sys.abiflags - except AttributeError: - # sys.abiflags may not be defined on all platforms. - abiflags = '' + prefix, exec_prefix, abiflags = get_config_vars('prefix', + 'exec_prefix', 'ABIFLAGS') + # sys.abiflags may not be defined on all platforms. + abiflags = '' if abiflags is None else abiflags self.config_vars = {'dist_name': self.distribution.get_name(), 'dist_version': self.distribution.get_version(), 'dist_fullname': self.distribution.get_fullname(), @@ -418,8 +416,13 @@ raise DistutilsOptionError( "must not supply exec-prefix without prefix") - self.prefix = os.path.normpath(sys.prefix) - self.exec_prefix = os.path.normpath(sys.exec_prefix) + if cross_compiling: + prefix, exec_prefix = get_config_vars('prefix', + 'exec_prefix') + else: + prefix, exec_prefix = sys.prefix, sys.exec_prefix + self.prefix = os.path.normpath(prefix) + self.exec_prefix = os.path.normpath(exec_prefix) else: if self.exec_prefix is None: @@ -442,7 +445,9 @@ self.select_scheme("unix_home") else: if self.prefix is None: - self.prefix = os.path.normpath(sys.prefix) + prefix = (get_config_vars().get('prefix') if + cross_compiling else sys.prefix) + self.prefix = os.path.normpath(prefix) self.install_base = self.install_platbase = self.prefix try: diff -r 876bee0bd0ba Lib/distutils/dist.py --- a/Lib/distutils/dist.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/distutils/dist.py Tue Nov 29 15:34:50 2016 +0100 @@ -19,6 +19,7 @@ from distutils.util import check_environ, strtobool, rfc822_escape from distutils import log from distutils.debug import DEBUG +from distutils.sysconfig import cross_compiling # Regex to define acceptable Distutils command names. This is not *quite* # the same as a Python NAME -- I don't allow leading underscores. The fact @@ -371,7 +372,7 @@ from configparser import ConfigParser # Ignore install directory options if we have a venv - if sys.prefix != sys.base_prefix: + if not cross_compiling and sys.prefix != sys.base_prefix: ignore_options = [ 'install-base', 'install-platbase', 'install-lib', 'install-platlib', 'install-purelib', 'install-headers', diff -r 876bee0bd0ba Lib/distutils/sysconfig.py --- a/Lib/distutils/sysconfig.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/distutils/sysconfig.py Tue Nov 29 15:34:50 2016 +0100 @@ -14,6 +14,7 @@ import re import sys +from sysconfig import get_cross_build_var, import_sysconfigdata from .errors import DistutilsPlatformError # These are needed in a couple of spots, so just compute them once. @@ -21,12 +22,19 @@ EXEC_PREFIX = os.path.normpath(sys.exec_prefix) BASE_PREFIX = os.path.normpath(sys.base_prefix) BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix) +cross_compiling = False # Path to the base directory of the project. On Windows the binary may # live in project/PCBuild/win32 or project/PCBuild/amd64. # set for cross builds -if "_PYTHON_PROJECT_BASE" in os.environ: - project_base = os.path.abspath(os.environ["_PYTHON_PROJECT_BASE"]) +_xbuild_project_base = get_cross_build_var('project_base') +if _xbuild_project_base is not None: + cross_compiling = True + project_base = _xbuild_project_base + PREFIX = get_cross_build_var('prefix') + EXEC_PREFIX = get_cross_build_var('exec-prefix') + BASE_PREFIX = PREFIX + BASE_EXEC_PREFIX = EXEC_PREFIX else: project_base = os.path.dirname(os.path.abspath(sys.executable)) if (os.name == 'nt' and @@ -59,7 +67,9 @@ build_flags = '' try: if not python_build: - build_flags = sys.abiflags + _xbuild_abiflags = get_cross_build_var('abiflags') + build_flags = (sys.abiflags if _xbuild_abiflags is None else + _xbuild_abiflags) except AttributeError: # It's not a configure-based build, so the sys module doesn't have # this attribute, which is fine. @@ -242,8 +252,11 @@ return os.path.join(_sys_home or project_base, "Makefile") lib_dir = get_python_lib(plat_specific=0, standard_lib=1) config_file = 'config-{}{}'.format(get_python_version(), build_flags) - if hasattr(sys.implementation, '_multiarch'): - config_file += '-%s' % sys.implementation._multiarch + multiarch = get_cross_build_var('multiarch') + if multiarch is None: + multiarch = getattr(sys.implementation, '_multiarch', '') + if multiarch: + config_file += '-%s' % multiarch return os.path.join(lib_dir, config_file, 'Makefile') @@ -417,14 +430,7 @@ def _init_posix(): """Initialize the module as appropriate for POSIX systems.""" - # _sysconfigdata is generated at build time, see the sysconfig module - name = os.environ.get('_PYTHON_SYSCONFIGDATA_NAME', - '_sysconfigdata_{abi}_{platform}_{multiarch}'.format( - abi=sys.abiflags, - platform=sys.platform, - multiarch=getattr(sys.implementation, '_multiarch', ''), - )) - _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0) + _temp = import_sysconfigdata() build_time_vars = _temp.build_time_vars global _config_vars _config_vars = {} diff -r 876bee0bd0ba Lib/distutils/util.py --- a/Lib/distutils/util.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/distutils/util.py Tue Nov 29 15:34:50 2016 +0100 @@ -14,6 +14,7 @@ from distutils.spawn import spawn from distutils import log from distutils.errors import DistutilsByteCompileError +from sysconfig import get_cross_build_var def get_platform (): """Return a string that identifies the current platform. This is used @@ -54,8 +55,9 @@ return sys.platform # Set for cross builds explicitly - if "_PYTHON_HOST_PLATFORM" in os.environ: - return os.environ["_PYTHON_HOST_PLATFORM"] + xbuild_host_platform = get_cross_build_var('host_platform') + if xbuild_host_platform is not None: + return xbuild_host_platform if os.name != "posix" or not hasattr(os, 'uname'): # XXX what about the architecture? NT is Intel or Alpha, diff -r 876bee0bd0ba Lib/sysconfig.py --- a/Lib/sysconfig.py Sat Nov 26 14:04:40 2016 -0800 +++ b/Lib/sysconfig.py Tue Nov 29 15:34:50 2016 +0100 @@ -113,16 +113,80 @@ _PROJECT_BASE.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))): _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir)) -# set for cross builds -if "_PYTHON_PROJECT_BASE" in os.environ: - _PROJECT_BASE = _safe_realpath(os.environ["_PYTHON_PROJECT_BASE"]) - def _is_python_source_dir(d): for fn in ("Setup.dist", "Setup.local"): if os.path.isfile(os.path.join(d, "Modules", fn)): return True return False +_cross_build_vars = None +def get_cross_build_var(name): + """Return the value of the 'name' variable.""" + global _cross_build_vars + names = ('host_platform', 'version', 'abiflags', 'machdep', 'multiarch', + 'prefix', 'exec-prefix', 'sysconfigdata_name', 'project_base') + if _cross_build_vars is None: + _cross_build_vars = dict((n, None) for n in names) + if 'XBUILD_PYTHON_DIR' in os.environ: + # XBUILD_PYTHON_DIR must not be set when building a native + # interpreter since, at the time generate-posix-vars is run, the + # _posixsubprocess module has not been built yet and the import + # will fail. This does not happen when generate-posix-vars is run + # during cross-compilation as the native interpreter being used is + # a full-fledged interpreter. + try: + import subprocess + except ImportError: + print('Error: XBUILD_PYTHON_DIR is set in the environment.', + file=sys.stderr) + raise + + pyconfig_dir = _safe_realpath(os.environ['XBUILD_PYTHON_DIR']) + if _is_python_source_dir(pyconfig_dir): + python_build = True + python_config = os.path.join(pyconfig_dir, 'python-config') + else: + python_build = False + python_config = os.path.join(pyconfig_dir, 'python3-config') + + output = subprocess.check_output(['sh', python_config, + '--host_platform', '--version', '--abiflags', '--machdep', + '--multiarch', '--prefix', '--exec-prefix'], + universal_newlines=True).split('\n') + # _PYTHON_HOST_PLATFORM is substituted by config.status and not + # empty for cross builds. + if output[0]: + d = _cross_build_vars + d['host_platform'] = output[0] + d['version'] = output[1] + d['abiflags'] = output[2] + d['machdep'] = output[3] + d['multiarch'] = output[4] + d['prefix'] = output[5] + d['exec-prefix'] = output[6] + sysconf = ('_sysconfigdata_%s_%s' % + (d['abiflags'], d['machdep'])) + if d['multiarch']: + sysconf = '%s_%s' % (sysconf, d['multiarch']) + d['sysconfigdata_name'] = sysconf + d['project_base'] = (pyconfig_dir if + python_build else d['prefix']) + + # The specification of the sysconfigdata file name may differ + # across versions, forbid Python versions mismatch. + sys_version = '%d.%d' % sys.version_info[:2] + if d['version'] != sys_version: + raise RuntimeError('the running python version (%s) does ' + 'not match the cross-compiled version (%s)' % + (sys_version, d['version'])) + + return _cross_build_vars[name] + +# set for cross builds +_xbuild_project_base = get_cross_build_var('project_base') +if _xbuild_project_base is not None: + _PROJECT_BASE = _xbuild_project_base + _sys_home = getattr(sys, '_home', None) if (_sys_home and os.name == 'nt' and _sys_home.lower().endswith(('\\pcbuild\\win32', '\\pcbuild\\amd64'))): @@ -343,13 +407,13 @@ def _get_sysconfigdata_name(): - return os.environ.get('_PYTHON_SYSCONFIGDATA_NAME', - '_sysconfigdata_{abi}_{platform}_{multiarch}'.format( - abi=sys.abiflags, - platform=sys.platform, - multiarch=getattr(sys.implementation, '_multiarch', ''), - )) - + xbuild_sysconfigdata_name = get_cross_build_var('sysconfigdata_name') + if xbuild_sysconfigdata_name is not None: + return xbuild_sysconfigdata_name + sysconf = '_sysconfigdata_%s_%s' % (sys.abiflags, sys.platform) + if hasattr(sys.implementation, '_multiarch'): + sysconf = '%s_%s' % (sysconf, sys.implementation._multiarch) + return sysconf def _generate_posix_vars(): """Generate the Python module containing build-time variables.""" @@ -414,11 +478,35 @@ with open('pybuilddir.txt', 'w', encoding='ascii') as f: f.write(pybuilddir) +def import_sysconfigdata(): + # _sysconfigdata is generated at build time, see _generate_posix_vars() + name = _get_sysconfigdata_name() + pop_first_path = False + try: + # Temporarily update sys.path to import the sysconfigdata module when + # cross compiling. + xbuild_project_base = get_cross_build_var('project_base') + if xbuild_project_base is not None: + if _is_python_source_dir(xbuild_project_base): + bdir_text = os.path.join(xbuild_project_base, 'pybuilddir.txt') + with open(bdir_text) as f: + pybuilddir = f.read().strip() + pybuilddir = os.path.join(xbuild_project_base, pybuilddir) + sys.path.insert(0, pybuilddir) + pop_first_path = True + else: + stdlib_dir = os.path.join(get_cross_build_var('prefix'), + 'lib', 'python%s' % get_cross_build_var('version')) + sys.path.insert(0, stdlib_dir) + pop_first_path = True + return __import__(name, globals(), locals(), ['build_time_vars'], 0) + finally: + if pop_first_path: + sys.path.pop(0) + def _init_posix(vars): """Initialize the module as appropriate for POSIX systems.""" - # _sysconfigdata is generated at build time, see _generate_posix_vars() - name = _get_sysconfigdata_name() - _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0) + _temp = import_sysconfigdata() build_time_vars = _temp.build_time_vars vars.update(build_time_vars) @@ -645,8 +733,9 @@ return sys.platform # Set for cross builds explicitly - if "_PYTHON_HOST_PLATFORM" in os.environ: - return os.environ["_PYTHON_HOST_PLATFORM"] + xbuild_host_platform = get_cross_build_var('host_platform') + if xbuild_host_platform is not None: + return xbuild_host_platform # Try to distinguish various flavours of Unix osname, host, release, version, machine = os.uname() @@ -692,6 +781,11 @@ return "%s-%s-%s" % (osname, release, machine) +def get_host_platform(): + """Return the host platform for cross builds, None otherwise.""" + return get_cross_build_var('host_platform') + + def get_python_version(): return _PY_VERSION_SHORT diff -r 876bee0bd0ba Makefile.pre.in --- a/Makefile.pre.in Sat Nov 26 14:04:40 2016 -0800 +++ b/Makefile.pre.in Tue Nov 29 15:34:50 2016 +0100 @@ -229,7 +229,7 @@ PYTHON_FOR_GEN=@PYTHON_FOR_GEN@ PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ -_PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ +PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@ BUILD_GNU_TYPE= @build@ HOST_GNU_TYPE= @host@ @@ -471,7 +471,7 @@ # Default target all: @DEF_MAKE_ALL_RULE@ -build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed python-config +build_all: $(BUILDPYTHON) oldsharedmods sharedmods gdbhooks Programs/_testembed # Compile a binary with profile guided optimization. profile-opt: @@ -577,7 +577,7 @@ # problems by creating a dummy pybuilddir.txt just to allow interpreter # initialization to succeed. It will be overwritten by generate-posix-vars # or removed in case of failure. -pybuilddir.txt: $(BUILDPYTHON) +pybuilddir.txt: python-config $(BUILDPYTHON) @echo "none" > ./pybuilddir.txt $(RUNSHARED) $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars ;\ if test $$? -ne 0 ; then \ @@ -1513,7 +1513,7 @@ cd Mac && $(MAKE) installextras DESTDIR="$(DESTDIR)" # This installs a few of the useful scripts in Tools/scripts -scriptsinstall: +scriptsinstall: python-config SRCDIR=$(srcdir) $(RUNSHARED) \ $(PYTHON_FOR_BUILD) $(srcdir)/Tools/scripts/setup.py install \ --prefix=$(prefix) \ diff -r 876bee0bd0ba Misc/python-config.in --- a/Misc/python-config.in Sat Nov 26 14:04:40 2016 -0800 +++ b/Misc/python-config.in Tue Nov 29 15:34:50 2016 +0100 @@ -9,7 +9,9 @@ import sysconfig valid_opts = ['prefix', 'exec-prefix', 'includes', 'libs', 'cflags', - 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir'] + 'ldflags', 'extension-suffix', 'help', 'abiflags', 'configdir', + 'host_platform', 'version', 'machdep', 'multiarch', + ] def exit_with_usage(code=1): print("Usage: {0} [{1}]".format( @@ -24,8 +26,9 @@ if not opts: exit_with_usage() -pyver = sysconfig.get_config_var('VERSION') getvar = sysconfig.get_config_var +pyver = getvar('VERSION') +abiflags = getvar('ABIFLAGS') opt_flags = [flag for (flag, val) in opts] @@ -34,10 +37,10 @@ for opt in opt_flags: if opt == '--prefix': - print(sysconfig.get_config_var('prefix')) + print(getvar('prefix')) elif opt == '--exec-prefix': - print(sysconfig.get_config_var('exec_prefix')) + print(getvar('exec_prefix')) elif opt in ('--includes', '--cflags'): flags = ['-I' + sysconfig.get_path('include'), @@ -47,7 +50,7 @@ print(' '.join(flags)) elif opt in ('--libs', '--ldflags'): - libs = ['-lpython' + pyver + sys.abiflags] + libs = ['-lpython' + pyver + abiflags] libs += getvar('LIBS').split() libs += getvar('SYSLIBS').split() # add the prefix/lib/pythonX.Y/config dir, but only if there is no @@ -60,10 +63,22 @@ print(' '.join(libs)) elif opt == '--extension-suffix': - print(sysconfig.get_config_var('EXT_SUFFIX')) + print(getvar('EXT_SUFFIX')) elif opt == '--abiflags': - print(sys.abiflags) + print(abiflags) elif opt == '--configdir': - print(sysconfig.get_config_var('LIBPL')) + print(getvar('LIBPL')) + + elif opt == '--host_platform': + print(getvar('PYTHON_HOST_PLATFORM')) + + elif opt == '--version': + print(pyver) + + elif opt == '--machdep': + print(getvar('MACHDEP')) + + elif opt == '--multiarch': + print(getvar('MULTIARCH')) diff -r 876bee0bd0ba Misc/python-config.sh.in --- a/Misc/python-config.sh.in Sat Nov 26 14:04:40 2016 -0800 +++ b/Misc/python-config.sh.in Tue Nov 29 15:34:50 2016 +0100 @@ -4,7 +4,9 @@ exit_with_usage () { - echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--configdir" + echo "Usage: $0 --prefix|--exec-prefix|--includes|--libs|--cflags|\ + --ldflags|--extension-suffix|--help|--abiflags|--configdir|\ + --host_platform|--version|--machdep|--multiarch" exit $1 } @@ -24,35 +26,78 @@ echo $RESULT } -prefix_build="@prefix@" -prefix_real=$(installed_prefix "$0") +is_python_build_dir() +{ + is_pydir=no + dir=$(dirname "$1") + for name in Setup Setup.config Setup.local; do + if test -f "$dir/Modules/$name"; then + is_pydir=yes + break + fi + done + echo $is_pydir +} -# Use sed to fix paths from their built-to locations to their installed-to -# locations. -prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#") -exec_prefix_build="@exec_prefix@" -exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#") -includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#") -libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#") -CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#") +rm_duplicates() +{ + echo "$1" | sed "s#$2\+#$2#g" +} + +strip_last() +{ + echo "$1" | sed "s#$2\$##" +} + VERSION="@VERSION@" -LIBM="@LIBM@" -LIBC="@LIBC@" -SYSLIBS="$LIBM $LIBC" ABIFLAGS="@ABIFLAGS@" -LIBS="-lpython${VERSION}${ABIFLAGS} @LIBS@ $SYSLIBS" -BASECFLAGS="@BASECFLAGS@" -LDLIBRARY="@LDLIBRARY@" -LINKFORSHARED="@LINKFORSHARED@" -OPT="@OPT@" -PY_ENABLE_SHARED="@PY_ENABLE_SHARED@" -LDVERSION="@LDVERSION@" -LIBDEST=${prefix}/lib/python${VERSION} -LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#") -SO="@EXT_SUFFIX@" -PYTHONFRAMEWORK="@PYTHONFRAMEWORK@" -INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" -PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" + +# No directory based variables are of interest in a build tree. +if test $(is_python_build_dir "$0") = no; then + + prefix="@prefix@" + prefix_build=$(strip_last "$prefix" /) + exec_prefix_build=$(strip_last "@exec_prefix@" /) + exec_prefix=$(installed_prefix "$0") + exec_prefix=$(strip_last "$exec_prefix" /) + destdir=$(strip_last "$exec_prefix" "$exec_prefix_build") + + # Installation using DESTDIR and possibly with 'prefix' different from + # 'exec_prefix'. + if test $(rm_duplicates "$destdir/$exec_prefix_build" /) = "$exec_prefix"; then + prefix=$(rm_duplicates "$destdir/$prefix_build" /) + + # Installation with a common base directory for the platform-dependent and + # platform-independent Python files. + else + # Use sed to fix paths from their built-to locations to their installed-to + # locations. + prefix_real=$(installed_prefix "$0") + prefix=$(echo "$prefix_build" | sed "s#$prefix_build#$prefix_real#") + exec_prefix=$(echo "$exec_prefix_build" | sed "s#$exec_prefix_build#$prefix_real#") + + # The following variables are needed for backward compatibility. + includedir=$(echo "@includedir@" | sed "s#$prefix_build#$prefix_real#") + libdir=$(echo "@libdir@" | sed "s#$prefix_build#$prefix_real#") + CFLAGS=$(echo "@CFLAGS@" | sed "s#$prefix_build#$prefix_real#") + LIBM="@LIBM@" + LIBC="@LIBC@" + SYSLIBS="$LIBM $LIBC" + LIBS="-lpython${VERSION}${ABIFLAGS} @LIBS@ $SYSLIBS" + BASECFLAGS="@BASECFLAGS@" + LDLIBRARY="@LDLIBRARY@" + LINKFORSHARED="@LINKFORSHARED@" + OPT="@OPT@" + PY_ENABLE_SHARED="@PY_ENABLE_SHARED@" + LDVERSION="@LDVERSION@" + LIBDEST=${prefix}/lib/python${VERSION} + LIBPL=$(echo "@LIBPL@" | sed "s#$prefix_build#$prefix_real#") + SO="@EXT_SUFFIX@" + PYTHONFRAMEWORK="@PYTHONFRAMEWORK@" + INCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" + PLATINCDIR="-I$includedir/python${VERSION}${ABIFLAGS}" + fi +fi # Scan for --help or unknown argument. for ARG in $* @@ -61,7 +106,9 @@ --help) exit_with_usage 0 ;; - --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--abiflags|--configdir) + --prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|\ + --extension-suffix|--abiflags|--configdir|\ + --host_platform|--version|--machdep|--multiarch) ;; *) exit_with_usage 1 @@ -107,5 +154,17 @@ --configdir) echo "$LIBPL" ;; + --host_platform) + echo "@_PYTHON_HOST_PLATFORM@" + ;; + --version) + echo "$VERSION" + ;; + --machdep) + echo "@MACHDEP@" + ;; + --multiarch) + echo "@MULTIARCH@" + ;; esac done diff -r 876bee0bd0ba configure.ac --- a/configure.ac Sat Nov 26 14:04:40 2016 -0800 +++ b/configure.ac Tue Nov 29 15:34:50 2016 +0100 @@ -78,7 +78,7 @@ AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found]) fi AC_MSG_RESULT($interp) - PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) '$interp + PYTHON_FOR_BUILD='XBUILD_PYTHON_DIR=$(abs_builddir) '$interp fi # Used to comment out stuff for rebuilding generated files GENERATED_COMMENT='#' diff -r 876bee0bd0ba setup.py --- a/setup.py Sat Nov 26 14:04:40 2016 -0800 +++ b/setup.py Tue Nov 29 15:34:50 2016 +0100 @@ -16,7 +16,7 @@ from distutils.command.build_scripts import build_scripts from distutils.spawn import find_executable -cross_compiling = "_PYTHON_HOST_PLATFORM" in os.environ +cross_compiling = bool(sysconfig.get_host_platform()) # Add special CFLAGS reserved for building the interpreter and the stdlib # modules (Issue #21121). @@ -31,8 +31,9 @@ def get_platform(): # cross build - if "_PYTHON_HOST_PLATFORM" in os.environ: - return os.environ["_PYTHON_HOST_PLATFORM"] + host_platform = sysconfig.get_host_platform() + if host_platform: + return host_platform # Get value of sys.platform if sys.platform.startswith('osf1'): return 'osf1'