cc95a97
diff -up Python-2.7.6/Lib/distutils/command/build_ext.py.debug-build Python-2.7.6/Lib/distutils/command/build_ext.py
cc95a97
--- Python-2.7.6/Lib/distutils/command/build_ext.py.debug-build	2013-11-10 08:36:40.000000000 +0100
cc95a97
+++ Python-2.7.6/Lib/distutils/command/build_ext.py	2014-01-29 14:13:08.815888533 +0100
cc95a97
@@ -674,7 +674,10 @@ class build_ext (Command):
f020abd
         so_ext = get_config_var('SO')
f020abd
         if os.name == 'nt' and self.debug:
c6247fd
             return os.path.join(*ext_path) + '_d' + so_ext
f020abd
-        return os.path.join(*ext_path) + so_ext
f020abd
+
f020abd
+        # Similarly, extensions in debug mode are named 'module_d.so', to
f020abd
+        # avoid adding the _d to the SO config variable:
f020abd
+        return os.path.join(*ext_path) + (sys.pydebug and "_d" or "") + so_ext
f020abd
 
f020abd
     def get_export_symbols (self, ext):
f020abd
         """Return the list of symbols that a shared extension has to
cc95a97
@@ -759,6 +762,8 @@ class build_ext (Command):
f020abd
                 template = "python%d.%d"
f020abd
                 pythonlib = (template %
f020abd
                              (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
f020abd
+                if sys.pydebug:
f020abd
+                    pythonlib += '_d'
f020abd
                 return ext.libraries + [pythonlib]
f020abd
             else:
f020abd
                 return ext.libraries
cc95a97
diff -up Python-2.7.6/Lib/distutils/sysconfig.py.debug-build Python-2.7.6/Lib/distutils/sysconfig.py
cc95a97
--- Python-2.7.6/Lib/distutils/sysconfig.py.debug-build	2014-01-29 14:13:08.770891379 +0100
cc95a97
+++ Python-2.7.6/Lib/distutils/sysconfig.py	2014-01-29 14:13:08.815888533 +0100
cc95a97
@@ -90,7 +90,8 @@ def get_python_inc(plat_specific=0, pref
c6247fd
                 # Include is located in the srcdir
c6247fd
                 inc_dir = os.path.join(srcdir, "Include")
f020abd
             return inc_dir
f020abd
-        return os.path.join(prefix, "include", "python" + get_python_version())
f020abd
+        return os.path.join(prefix, "include",
f020abd
+                            "python" + get_python_version() + (sys.pydebug and '-debug' or ''))
f020abd
     elif os.name == "nt":
f020abd
         return os.path.join(prefix, "include")
c6247fd
     elif os.name == "os2":
cc95a97
@@ -247,7 +248,7 @@ def get_makefile_filename():
f020abd
     if python_build:
43e7c42
         return os.path.join(project_base, "Makefile")
f020abd
     lib_dir = get_python_lib(plat_specific=1, standard_lib=1)
f020abd
-    return os.path.join(lib_dir, "config", "Makefile")
f020abd
+    return os.path.join(lib_dir, "config" + (sys.pydebug and "-debug" or ""), "Makefile")
f020abd
 
f020abd
 
f020abd
 def parse_config_h(fp, g=None):
cc95a97
diff -up Python-2.7.6/Lib/distutils/tests/test_install.py.debug-build Python-2.7.6/Lib/distutils/tests/test_install.py
cc95a97
--- Python-2.7.6/Lib/distutils/tests/test_install.py.debug-build	2014-01-29 14:13:08.779890810 +0100
cc95a97
+++ Python-2.7.6/Lib/distutils/tests/test_install.py	2014-01-29 14:13:08.815888533 +0100
b0a6ae1
@@ -20,8 +20,9 @@ from distutils.tests import support
b0a6ae1
 
b0a6ae1
 
b0a6ae1
 def _make_ext_name(modname):
b0a6ae1
-    if os.name == 'nt' and sys.executable.endswith('_d.exe'):
b0a6ae1
+    if sys.pydebug:
b0a6ae1
         modname += '_d'
b0a6ae1
+    
b0a6ae1
     return modname + sysconfig.get_config_var('SO')
b0a6ae1
 
b0a6ae1
 
cc95a97
diff -up Python-2.7.6/Makefile.pre.in.debug-build Python-2.7.6/Makefile.pre.in
cc95a97
--- Python-2.7.6/Makefile.pre.in.debug-build	2014-01-29 14:13:08.800889482 +0100
cc95a97
+++ Python-2.7.6/Makefile.pre.in	2014-01-29 14:17:30.929316462 +0100
cc95a97
@@ -111,8 +111,8 @@ SCRIPTDIR=	$(prefix)/lib64
f020abd
 # Detailed destination directories
f020abd
 BINLIBDEST=	$(LIBDIR)/python$(VERSION)
f020abd
 LIBDEST=	$(SCRIPTDIR)/python$(VERSION)
f020abd
-INCLUDEPY=	$(INCLUDEDIR)/python$(VERSION)
f020abd
-CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(VERSION)
f020abd
+INCLUDEPY=	$(INCLUDEDIR)/python$(VERSION)$(DEBUG_SUFFIX)
f020abd
+CONFINCLUDEPY=	$(CONFINCLUDEDIR)/python$(VERSION)$(DEBUG_SUFFIX)
f020abd
 LIBP=		$(LIBDIR)/python$(VERSION)
f020abd
 
f020abd
 # Symbols used for using shared libraries
cc95a97
@@ -126,6 +126,12 @@ DESTSHARED=	$(BINLIBDEST)/lib-dynload
f020abd
 EXE=		@EXEEXT@
f020abd
 BUILDEXE=	@BUILDEXEEXT@
f020abd
 
f020abd
+# DEBUG_EXT is used by ELF files (names and SONAMEs); it will be "_d" for a debug build
f020abd
+# DEBUG_SUFFIX is used by filesystem paths; it will be "-debug" for a debug build
f020abd
+# Both will be empty in an optimized build
f020abd
+DEBUG_EXT=	@DEBUG_EXT@
f020abd
+DEBUG_SUFFIX=	@DEBUG_SUFFIX@
f020abd
+
f020abd
 # Short name and location for Mac OS X Python framework
f020abd
 UNIVERSALSDK=@UNIVERSALSDK@
f020abd
 PYTHONFRAMEWORK=	@PYTHONFRAMEWORK@
cc95a97
@@ -189,8 +195,8 @@ LIBOBJDIR=	Python/
f020abd
 LIBOBJS=	@LIBOBJS@
f020abd
 UNICODE_OBJS=   @UNICODE_OBJS@
f020abd
 
f020abd
-PYTHON=		python$(EXE)
f020abd
-BUILDPYTHON=	python$(BUILDEXE)
f020abd
+PYTHON=		python$(DEBUG_SUFFIX)$(EXE)
f020abd
+BUILDPYTHON=	python$(DEBUG_SUFFIX)$(BUILDEXE)
f020abd
 
43e7c42
 PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@
43e7c42
 _PYTHON_HOST_PLATFORM=@_PYTHON_HOST_PLATFORM@
cc95a97
@@ -464,7 +470,7 @@ sharedmods: $(BUILDPYTHON) pybuilddir.tx
cc95a97
 		_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
43e7c42
 		$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
f020abd
 
f020abd
-libpython$(VERSION).so: $(LIBRARY_OBJS)
f020abd
+libpython$(VERSION)$(DEBUG_EXT).so: $(LIBRARY_OBJS)
f020abd
 	if test $(INSTSONAME) != $(LDLIBRARY); then \
b0a6ae1
 		$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
f020abd
 		$(LN) -f $(INSTSONAME) $@; \
cc95a97
@@ -856,18 +862,18 @@ bininstall:	altbininstall
9345b0f
 	then rm -f $(DESTDIR)$(BINDIR)/$(PYTHON); \
9345b0f
 	else true; \
f020abd
 	fi
9345b0f
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(EXE) $(PYTHON))
9345b0f
-	-rm -f $(DESTDIR)$(BINDIR)/python2$(EXE)
b0a6ae1
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(EXE) python2$(EXE))
9345b0f
-	-rm -f $(DESTDIR)$(BINDIR)/python2-config
b0a6ae1
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)-config python2-config)
b0a6ae1
-	-rm -f $(DESTDIR)$(BINDIR)/python-config
9345b0f
-	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2-config python-config)
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(DEBUG_SUFFIX)$(EXE) $(PYTHON))
9345b0f
+	-rm -f $(DESTDIR)$(BINDIR)/python2$(DEBUG_SUFFIX)$(EXE)
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(DEBUG_SUFFIX)$(EXE) python2$(DEBUG_SUFFIX)$(EXE))
9345b0f
+	-rm -f $(DESTDIR)$(BINDIR)/python2$(DEBUG_SUFFIX)-config
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python$(VERSION)$(DEBUG_SUFFIX)-config python2$(DEBUG_SUFFIX)-config)
9345b0f
+	-rm -f $(DESTDIR)$(BINDIR)/python$(DEBUG_SUFFIX)-config
9345b0f
+	(cd $(DESTDIR)$(BINDIR); $(LN) -s python2$(DEBUG_SUFFIX)-config python$(DEBUG_SUFFIX)-config)
c6247fd
 	-test -d $(DESTDIR)$(LIBPC) || $(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBPC)
9345b0f
-	-rm -f $(DESTDIR)$(LIBPC)/python2.pc
9345b0f
-	(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION).pc python2.pc)
9345b0f
-	-rm -f $(DESTDIR)$(LIBPC)/python.pc
9345b0f
-	(cd $(DESTDIR)$(LIBPC); $(LN) -s python2.pc python.pc)
9345b0f
+	-rm -f $(DESTDIR)$(LIBPC)/python2$(DEBUG_SUFFIX).pc
9345b0f
+	(cd $(DESTDIR)$(LIBPC); $(LN) -s python-$(VERSION)$(DEBUG_SUFFIX).pc python2$(DEBUG_SUFFIX).pc)
9345b0f
+	-rm -f $(DESTDIR)$(LIBPC)/python$(DEBUG_SUFFIX).pc
9345b0f
+	(cd $(DESTDIR)$(LIBPC); $(LN) -s python2$(DEBUG_SUFFIX).pc python$(DEBUG_SUFFIX).pc)
9345b0f
 
9345b0f
 # Install the interpreter with $(VERSION) affixed
9345b0f
 # This goes into $(exec_prefix)
cc95a97
@@ -880,7 +886,7 @@ altbininstall:	$(BUILDPYTHON)
f020abd
 		else	true; \
f020abd
 		fi; \
f020abd
 	done
f020abd
-	$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(EXE)
f020abd
+	$(INSTALL_PROGRAM) $(BUILDPYTHON) $(DESTDIR)$(BINDIR)/python$(VERSION)$(DEBUG_SUFFIX)$(EXE)
f020abd
 	if test -f $(LDLIBRARY); then \
f020abd
 		if test -n "$(DLLLIBRARY)" ; then \
f020abd
 			$(INSTALL_SHARED) $(DLLLIBRARY) $(DESTDIR)$(BINDIR); \
cc95a97
@@ -1046,10 +1052,11 @@ $(srcdir)/Lib/$(PLATDIR):
43e7c42
 	fi; \
c6247fd
 	cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
c6247fd
 
c6247fd
-python-config: $(srcdir)/Misc/python-config.in
c6247fd
+python$(DEBUG_SUFFIX)-config: $(srcdir)/Misc/python-config.in
c6247fd
 	# Substitution happens here, as the completely-expanded BINDIR
c6247fd
 	# is not available in configure
c6247fd
-	sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(EXE)," < $(srcdir)/Misc/python-config.in >python-config
c6247fd
+	sed -e "s,@EXENAME@,$(BINDIR)/python$(VERSION)$(DEBUG_SUFFIX)$(EXE)," < $(srcdir)/Misc/python-config.in >python$(DEBUG_SUFFIX)-config
c6247fd
+
c6247fd
 
c6247fd
 # Install the include files
c6247fd
 INCLDIRSTOMAKE=$(INCLUDEDIR) $(CONFINCLUDEDIR) $(INCLUDEPY) $(CONFINCLUDEPY)
cc95a97
@@ -1070,13 +1077,13 @@ inclinstall:
f020abd
 	$(INSTALL_DATA) pyconfig.h $(DESTDIR)$(CONFINCLUDEPY)/pyconfig.h
f020abd
 
f020abd
 # Install the library and miscellaneous stuff needed for extending/embedding
f020abd
-# This goes into $(exec_prefix)
f020abd
-LIBPL=		$(LIBP)/config
f020abd
+# This goes into $(exec_prefix)$(DEBUG_SUFFIX)
f020abd
+LIBPL=		$(LIBP)/config$(DEBUG_SUFFIX)
c6247fd
 
c6247fd
 # pkgconfig directory
c6247fd
 LIBPC=		$(LIBDIR)/pkgconfig
c6247fd
 
c6247fd
-libainstall:	all python-config
c6247fd
+libainstall:	all python$(DEBUG_SUFFIX)-config
c6247fd
 	@for i in $(LIBDIR) $(LIBP) $(LIBPL) $(LIBPC); \
f020abd
 	do \
c6247fd
 		if test ! -d $(DESTDIR)$$i; then \
cc95a97
@@ -1092,11 +1099,10 @@ libainstall:	all python-config
9345b0f
 	$(INSTALL_DATA) Modules/Setup $(DESTDIR)$(LIBPL)/Setup
9345b0f
 	$(INSTALL_DATA) Modules/Setup.local $(DESTDIR)$(LIBPL)/Setup.local
9345b0f
 	$(INSTALL_DATA) Modules/Setup.config $(DESTDIR)$(LIBPL)/Setup.config
9345b0f
-	$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION).pc
9345b0f
+	$(INSTALL_DATA) Misc/python.pc $(DESTDIR)$(LIBPC)/python-$(VERSION)$(DEBUG_SUFFIX).pc
c6247fd
 	$(INSTALL_SCRIPT) $(srcdir)/Modules/makesetup $(DESTDIR)$(LIBPL)/makesetup
f020abd
 	$(INSTALL_SCRIPT) $(srcdir)/install-sh $(DESTDIR)$(LIBPL)/install-sh
f020abd
-	$(INSTALL_SCRIPT) python-config $(DESTDIR)$(BINDIR)/python$(VERSION)-config
f020abd
-	rm python-config
f020abd
+	$(INSTALL_SCRIPT) python$(DEBUG_SUFFIX)-config $(DESTDIR)$(BINDIR)/python$(VERSION)$(DEBUG_SUFFIX)-config
f020abd
 	@if [ -s Modules/python.exp -a \
f020abd
 		"`echo $(MACHDEP) | sed 's/^\(...\).*/\1/'`" = "aix" ]; then \
f020abd
 		echo; echo "Installing support files for building shared extension modules on AIX:"; \
cc95a97
diff -up Python-2.7.6/Misc/python-config.in.debug-build Python-2.7.6/Misc/python-config.in
cc95a97
--- Python-2.7.6/Misc/python-config.in.debug-build	2013-11-10 08:36:41.000000000 +0100
cc95a97
+++ Python-2.7.6/Misc/python-config.in	2014-01-29 14:13:08.816888470 +0100
c6247fd
@@ -45,7 +45,7 @@ for opt in opt_flags:
Matej Stuchlik b1e5a42
         print ' '.join(flags)
c6247fd
 
c6247fd
     elif opt in ('--libs', '--ldflags'):
Matej Stuchlik b1e5a42
-        libs = ['-lpython' + pyver]
Matej Stuchlik b1e5a42
+        libs = ['-lpython' + pyver + (sys.pydebug and "_d" or "")]
Matej Stuchlik b1e5a42
         libs += getvar('LIBS').split()
Matej Stuchlik b1e5a42
         libs += getvar('SYSLIBS').split()
c6247fd
         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
cc95a97
diff -up Python-2.7.6/Modules/makesetup.debug-build Python-2.7.6/Modules/makesetup
cc95a97
--- Python-2.7.6/Modules/makesetup.debug-build	2013-11-10 08:36:41.000000000 +0100
cc95a97
+++ Python-2.7.6/Modules/makesetup	2014-01-29 14:13:08.817888407 +0100
f020abd
@@ -233,7 +233,7 @@ sed -e 's/[ 	]*#.*//' -e '/^[ 	]*$/d' |
f020abd
 			*$mod.o*)	base=$mod;;
f020abd
 			*)		base=${mod}module;;
f020abd
 			esac
f020abd
-			file="$srcdir/$base\$(SO)"
f020abd
+			file="$srcdir/$base\$(DEBUG_EXT)\$(SO)"
f020abd
 			case $doconfig in
f020abd
 			no)	SHAREDMODS="$SHAREDMODS $file";;
f020abd
 			esac
cc95a97
diff -up Python-2.7.6/Python/dynload_shlib.c.debug-build Python-2.7.6/Python/dynload_shlib.c
cc95a97
--- Python-2.7.6/Python/dynload_shlib.c.debug-build	2013-11-10 08:36:41.000000000 +0100
cc95a97
+++ Python-2.7.6/Python/dynload_shlib.c	2014-01-29 14:13:08.817888407 +0100
f020abd
@@ -46,11 +46,16 @@ const struct filedescr _PyImport_DynLoad
c6247fd
     {"module.exe", "rb", C_EXTENSION},
c6247fd
     {"MODULE.EXE", "rb", C_EXTENSION},
f020abd
 #else
f020abd
+#ifdef Py_DEBUG
c6247fd
+    {"_d.so", "rb", C_EXTENSION},
c6247fd
+    {"module_d.so", "rb", C_EXTENSION},
f020abd
+#else
c6247fd
     {".so", "rb", C_EXTENSION},
c6247fd
     {"module.so", "rb", C_EXTENSION},
f020abd
-#endif
f020abd
-#endif
f020abd
-#endif
f020abd
+#endif /* Py_DEBUG */
f020abd
+#endif /* __VMS */
f020abd
+#endif /* defined(PYOS_OS2) && defined(PYCC_GCC) */
f020abd
+#endif /* __CYGWIN__ */
c6247fd
     {0, 0}
f020abd
 };
f020abd
 
cc95a97
diff -up Python-2.7.6/Python/sysmodule.c.debug-build Python-2.7.6/Python/sysmodule.c
cc95a97
--- Python-2.7.6/Python/sysmodule.c.debug-build	2013-11-10 08:36:41.000000000 +0100
cc95a97
+++ Python-2.7.6/Python/sysmodule.c	2014-01-29 14:13:08.817888407 +0100
b0a6ae1
@@ -1506,6 +1506,12 @@ _PySys_Init(void)
c6247fd
                         PyString_FromString("legacy"));
c6247fd
 #endif
f020abd
 
f020abd
+#ifdef Py_DEBUG
f020abd
+	PyDict_SetItemString(sysdict, "pydebug", Py_True);
f020abd
+#else
f020abd
+	PyDict_SetItemString(sysdict, "pydebug", Py_False);
f020abd
+#endif
f020abd
+
f020abd
 #undef SET_SYS_FROM_STRING
c6247fd
     if (PyErr_Occurred())
c6247fd
         return NULL;
cc95a97
diff -up Python-2.7.6/configure.ac.debug-build Python-2.7.6/configure.ac
cc95a97
--- Python-2.7.6/configure.ac.debug-build	2014-01-29 14:13:08.796889735 +0100
cc95a97
+++ Python-2.7.6/configure.ac	2014-01-29 14:13:08.814888597 +0100
cc95a97
@@ -738,7 +738,7 @@ AC_SUBST(LIBRARY)
cc95a97
 AC_MSG_CHECKING(LIBRARY)
cc95a97
 if test -z "$LIBRARY"
cc95a97
 then
cc95a97
-	LIBRARY='libpython$(VERSION).a'
cc95a97
+	LIBRARY='libpython$(VERSION)$(DEBUG_EXT).a'
cc95a97
 fi
cc95a97
 AC_MSG_RESULT($LIBRARY)
cc95a97
 
cc95a97
@@ -884,8 +884,8 @@ if test $enable_shared = "yes"; then
cc95a97
 	  INSTSONAME="$LDLIBRARY".$SOVERSION
cc95a97
           ;;
cc95a97
     Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*)
cc95a97
-	  LDLIBRARY='libpython$(VERSION).so'
cc95a97
-	  BLDLIBRARY='-L. -lpython$(VERSION)'
cc95a97
+	  LDLIBRARY='libpython$(VERSION)$(DEBUG_EXT).so'
cc95a97
+	  BLDLIBRARY='-L. -lpython$(VERSION)$(DEBUG_EXT)'
Matej Stuchlik ebcba88
 	  RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
cc95a97
 	  case $ac_sys_system in
cc95a97
 	      FreeBSD*)
cc95a97
@@ -1028,6 +1028,14 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
cc95a97
 fi],
cc95a97
 [AC_MSG_RESULT(no)])
cc95a97
 
cc95a97
+if test "$Py_DEBUG" = 'true'
cc95a97
+then
cc95a97
+	DEBUG_EXT=_d
cc95a97
+	DEBUG_SUFFIX=-debug
cc95a97
+fi
cc95a97
+AC_SUBST(DEBUG_EXT)
cc95a97
+AC_SUBST(DEBUG_SUFFIX)
cc95a97
+
cc95a97
 # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
cc95a97
 # merged with this chunk of code?
cc95a97