Index: b/Lib/sysconfig.py
===================================================================
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -338,7 +338,7 @@ def get_makefile_filename():
     """Return the path of the Makefile."""
     if _PYTHON_BUILD:
         return os.path.join(_PROJECT_BASE, "Makefile")
-    return os.path.join(get_path('platstdlib').replace("/usr/local","/usr",1), "config" + (sys.pydebug and "_d" or ""), "Makefile")
+    return os.path.join(get_config_var('LIBPL'), "Makefile")
 
 # Issue #22199: retain undocumented private name for compatibility
 _get_makefile_filename = get_makefile_filename
@@ -537,6 +537,12 @@ def get_config_vars(*args):
         # the init-function.
         _CONFIG_VARS['userbase'] = _getuserbase()
 
+        multiarch = get_config_var('MULTIARCH')
+        if multiarch:
+            _CONFIG_VARS['multiarchsubdir'] = '/' + multiarch
+        else:
+            _CONFIG_VARS['multiarchsubdir'] = ''
+
         if 'srcdir' not in _CONFIG_VARS:
             _CONFIG_VARS['srcdir'] = _PROJECT_BASE
 
Index: b/Makefile.pre.in
===================================================================
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -101,6 +101,9 @@ MACHDEP=	@MACHDEP@
 # Multiarch directory (may be empty)
 MULTIARCH=	@MULTIARCH@
 
+# Multiarch directory (may be empty)
+MULTIARCH=	@MULTIARCH@
+
 # Install prefix for architecture-independent files
 prefix=		@prefix@
 
@@ -622,6 +625,10 @@ Makefile Modules/config.c: Makefile.pre
 	@mv config.c Modules
 	@echo "The Makefile was updated, you may need to re-run make."
 
+Python/dynload_shlib.o: $(srcdir)/Python/dynload_shlib.c Makefile
+	$(CC) -c $(PY_CORE_CFLAGS) \
+		$(if $(MULTIARCH),-DMULTIARCH='"$(MULTIARCH)"') \
+		-o $@ $(srcdir)/Python/dynload_shlib.c
 
 Modules/Setup: $(srcdir)/Modules/Setup.dist
 	@if test -f Modules/Setup; then \
@@ -1204,10 +1211,10 @@ inclinstall:
 
 # Install the library and miscellaneous stuff needed for extending/embedding
 # This goes into $(exec_prefix)$(DEBUG_EXT)
-LIBPL=		$(LIBP)/config$(DEBUG_EXT)
+LIBPL=		$(LIBP)/config-$(MULTIARCH)$(DEBUG_EXT)
 
 # pkgconfig directory
-LIBPC=		$(LIBDIR)/pkgconfig
+LIBPC=		$(LIBDIR)/$(MULTIARCH)/pkgconfig
 
 libainstall:	@DEF_MAKE_RULE@ python-config
 	@for i in $(LIBDIR) $(LIBP) $(LIBPL) $(LIBPC); \
@@ -1487,6 +1494,11 @@ patchcheck:
 
 Python/thread.o: @THREADHEADERS@
 
+Python/sysmodule.o: $(srcdir)/Python/sysmodule.c Makefile
+	$(CC) -c $(PY_CORE_CFLAGS) \
+		-DMULTIARCH='"$(MULTIARCH)"' \
+		-o $@ $(srcdir)/Python/sysmodule.c
+
 # Declare targets that aren't real files
 .PHONY: all build_all sharedmods check-clean-src oldsharedmods test quicktest memtest
 .PHONY: install altinstall oldsharedinstall bininstall altbininstall
Index: b/Python/dynload_shlib.c
===================================================================
--- a/Python/dynload_shlib.c
+++ b/Python/dynload_shlib.c
@@ -49,6 +49,12 @@ const struct filedescr _PyImport_DynLoad
 #ifdef Py_DEBUG
     {"_d.so", "rb", C_EXTENSION},
     {"module_d.so", "rb", C_EXTENSION},
+# ifdef MULTIARCH
+    {"." MULTIARCH "_d.so", "rb", C_EXTENSION},
+# endif
+#endif
+#ifdef MULTIARCH
+    {"." MULTIARCH ".so", "rb", C_EXTENSION},
 #endif
     {".so", "rb", C_EXTENSION},
     {"module.so", "rb", C_EXTENSION},
Index: b/configure.ac
===================================================================
--- a/configure.ac
+++ b/configure.ac
@@ -511,8 +511,16 @@ then
 fi
 AC_MSG_RESULT($MACHDEP)
 
+MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+AC_SUBST(MULTIARCH)
+
+
 AC_SUBST(PLATDIR)
-PLATDIR=plat-$MACHDEP
+if test -n "$MULTIARCH"; then
+  PLATDIR=plat-$MULTIARCH
+else
+  PLATDIR=plat-$MACHDEP
+fi
 
 # And add extra plat-mac for darwin
 AC_SUBST(EXTRAPLATDIR)
Index: b/Lib/distutils/sysconfig.py
===================================================================
--- a/Lib/distutils/sysconfig.py
+++ b/Lib/distutils/sysconfig.py
@@ -74,8 +74,6 @@ def get_python_inc(plat_specific=0, pref
     If 'prefix' is supplied, use it instead of sys.prefix or
     sys.exec_prefix -- i.e., ignore 'plat_specific'.
     """
-    if prefix is None:
-        prefix = plat_specific and EXEC_PREFIX or PREFIX
 
     if os.name == "posix":
         if python_build:
@@ -90,7 +88,14 @@ def get_python_inc(plat_specific=0, pref
                 # Include is located in the srcdir
                 inc_dir = os.path.join(srcdir, "Include")
             return inc_dir
-        return os.path.join(prefix, "include", "python" + get_python_version())+(sys.pydebug and "_d" or "")
+        else:
+            if not (prefix is None):
+                return os.path.join(prefix, "include",
+                                    "python" + get_python_version())+(sys.pydebug and "_d" or "")
+            if plat_specific:
+                return get_config_var('CONFINCLUDEPY')
+            else:
+                return get_config_var('INCLUDEPY')
     elif os.name == "nt":
         return os.path.join(prefix, "include")
     elif os.name == "os2":
@@ -263,7 +268,7 @@ def get_makefile_filename():
     if python_build:
         return os.path.join(project_base, "Makefile")
     lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
-    return os.path.join(lib_dir, "config"+(sys.pydebug and "_d" or ""), "Makefile")
+    return os.path.join(get_config_var('LIBPL'), "Makefile")
 
 
 def parse_config_h(fp, g=None):
Index: b/Python/sysmodule.c
===================================================================
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -1453,6 +1453,8 @@ _PySys_Init(void)
                         PyFloat_GetInfo());
     SET_SYS_FROM_STRING("long_info",
                         PyLong_GetInfo());
+    SET_SYS_FROM_STRING("_multiarch",
+                        PyString_FromString(MULTIARCH));
 #ifdef Py_USING_UNICODE
     SET_SYS_FROM_STRING("maxunicode",
                         PyInt_FromLong(PyUnicode_GetMax()));
