Index: b/Lib/sysconfig.py
===================================================================
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -333,7 +333,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
@@ -532,6 +532,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
@@ -97,6 +97,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@
 
@@ -568,6 +571,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 \
@@ -932,7 +939,7 @@ maninstall:	altmaninstall
 	(cd $(DESTDIR)$(MANDIR)/man1; $(LN) -s python2.1 python.1)
 
 # Install the library
-PLATDIR=	plat-$(MACHDEP)
+PLATDIR=	plat-$(MULTIARCH)
 EXTRAPLATDIR= @EXTRAPLATDIR@
 EXTRAMACHDEPPATH=@EXTRAMACHDEPPATH@
 MACHDEPS=	$(PLATDIR) $(EXTRAPLATDIR)
@@ -1093,10 +1100,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:	all python-config
 	@for i in $(LIBDIR) $(LIBP) $(LIBPL) $(LIBPC); \
@@ -1372,6 +1379,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 oldsharedmods test quicktest memtest
 .PHONY: install altinstall oldsharedinstall bininstall altbininstall
Index: b/Modules/Setup.dist
===================================================================
--- a/Modules/Setup.dist
+++ b/Modules/Setup.dist
@@ -91,7 +91,7 @@ SITEPATH=
 TESTPATH=
 
 # Path components for machine- or system-dependent modules and shared libraries
-MACHDEPPATH=:plat-$(MACHDEP)
+MACHDEPPATH=:plat-$(MULTIARCH)
 EXTRAMACHDEPPATH=
 
 # Path component for the Tkinter-related modules
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
@@ -675,6 +675,9 @@ fi
 MULTIARCH=$($CC --print-multiarch 2>/dev/null)
 AC_SUBST(MULTIARCH)
 
+MULTIARCH=$($CC --print-multiarch 2>/dev/null)
+AC_SUBST(MULTIARCH)
+
 
 # checks for UNIX variants that set C preprocessor variables
 AC_USE_SYSTEM_EXTENSIONS
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()));
