b0a6ae1
diff -up Python-2.7.3/configure.in.debug-build Python-2.7.3/configure.in
9345b0f
--- Python-2.7.3/configure.in.debug-build	2012-04-18 19:46:22.066498521 -0400
9345b0f
+++ Python-2.7.3/configure.in	2012-04-18 19:46:22.078498372 -0400
b0a6ae1
@@ -635,7 +635,7 @@ AC_SUBST(LIBRARY)
f020abd
 AC_MSG_CHECKING(LIBRARY)
f020abd
 if test -z "$LIBRARY"
f020abd
 then
f020abd
-	LIBRARY='libpython$(VERSION).a'
f020abd
+	LIBRARY='libpython$(VERSION)$(DEBUG_EXT).a'
f020abd
 fi
f020abd
 AC_MSG_RESULT($LIBRARY)
f020abd
 
b0a6ae1
@@ -780,8 +780,8 @@ if test $enable_shared = "yes"; then
f020abd
 	  INSTSONAME="$LDLIBRARY".$SOVERSION
f020abd
           ;;
b0a6ae1
     Linux*|GNU*|NetBSD*|FreeBSD*|DragonFly*|OpenBSD*)
f020abd
-	  LDLIBRARY='libpython$(VERSION).so'
f020abd
-	  BLDLIBRARY='-L. -lpython$(VERSION)'
f020abd
+	  LDLIBRARY='libpython$(VERSION)$(DEBUG_EXT).so'
f020abd
+	  BLDLIBRARY='-L. -lpython$(VERSION)$(DEBUG_EXT)'
f020abd
 	  RUNSHARED=LD_LIBRARY_PATH=`pwd`:${LD_LIBRARY_PATH}
f020abd
 	  case $ac_sys_system in
f020abd
 	      FreeBSD*)
b0a6ae1
@@ -905,6 +905,14 @@ else AC_MSG_RESULT(no); Py_DEBUG='false'
f020abd
 fi],
f020abd
 [AC_MSG_RESULT(no)])
f020abd
 
f020abd
+if test "$Py_DEBUG" = 'true'
f020abd
+then
f020abd
+	DEBUG_EXT=_d
f020abd
+	DEBUG_SUFFIX=-debug
f020abd
+fi
f020abd
+AC_SUBST(DEBUG_EXT)
f020abd
+AC_SUBST(DEBUG_SUFFIX)
f020abd
+
f020abd
 # XXX Shouldn't the code above that fiddles with BASECFLAGS and OPT be
f020abd
 # merged with this chunk of code?
f020abd
 
b0a6ae1
diff -up Python-2.7.3/Lib/distutils/command/build_ext.py.debug-build Python-2.7.3/Lib/distutils/command/build_ext.py
b0a6ae1
--- Python-2.7.3/Lib/distutils/command/build_ext.py.debug-build	2012-04-09 19:07:29.000000000 -0400
9345b0f
+++ Python-2.7.3/Lib/distutils/command/build_ext.py	2012-04-18 19:46:22.079498360 -0400
b0a6ae1
@@ -676,7 +676,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
b0a6ae1
@@ -761,6 +764,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
b0a6ae1
diff -up Python-2.7.3/Lib/distutils/sysconfig.py.debug-build Python-2.7.3/Lib/distutils/sysconfig.py
9345b0f
--- Python-2.7.3/Lib/distutils/sysconfig.py.debug-build	2012-04-18 19:46:21.988499499 -0400
9345b0f
+++ Python-2.7.3/Lib/distutils/sysconfig.py	2012-04-18 19:46:22.080498348 -0400
c6247fd
@@ -85,7 +85,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":
b0a6ae1
@@ -250,7 +251,7 @@ def get_makefile_filename():
f020abd
     if python_build:
f020abd
         return os.path.join(os.path.dirname(sys.executable), "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):
b0a6ae1
diff -up Python-2.7.3/Lib/distutils/tests/test_install.py.debug-build Python-2.7.3/Lib/distutils/tests/test_install.py
9345b0f
--- Python-2.7.3/Lib/distutils/tests/test_install.py.debug-build	2012-04-18 19:46:21.997499385 -0400
9345b0f
+++ Python-2.7.3/Lib/distutils/tests/test_install.py	2012-04-18 19:46:22.080498348 -0400
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
 
b0a6ae1
diff -up Python-2.7.3/Makefile.pre.in.debug-build Python-2.7.3/Makefile.pre.in
9345b0f
--- Python-2.7.3/Makefile.pre.in.debug-build	2012-04-18 19:46:22.073498437 -0400
9345b0f
+++ Python-2.7.3/Makefile.pre.in	2012-04-18 19:48:46.336694896 -0400
b0a6ae1
@@ -102,8 +102,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
b0a6ae1
@@ -117,6 +117,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@
b0a6ae1
@@ -180,8 +186,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
 
f020abd
 # The task to run while instrument when building the profile-opt target
f020abd
 PROFILE_TASK=	$(srcdir)/Tools/pybench/pybench.py -n 2 --with-gc --with-syscheck
b0a6ae1
@@ -413,7 +419,7 @@ sharedmods: $(BUILDPYTHON)
b0a6ae1
 	*) $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' ./$(BUILDPYTHON) -E $(srcdir)/setup.py build;; \
f020abd
 	esac
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) $@; \
9345b0f
@@ -796,18 +802,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)
b0a6ae1
@@ -820,7 +826,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); \
b0a6ae1
@@ -970,10 +976,11 @@ $(srcdir)/Lib/$(PLATDIR):
c6247fd
 	export EXE; EXE="$(BUILDEXE)"; \
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)
b0a6ae1
@@ -994,13 +1001,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 \
9345b0f
@@ -1016,11 +1023,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:"; \
b0a6ae1
diff -up Python-2.7.3/Misc/python-config.in.debug-build Python-2.7.3/Misc/python-config.in
b0a6ae1
--- Python-2.7.3/Misc/python-config.in.debug-build	2012-04-09 19:07:33.000000000 -0400
9345b0f
+++ Python-2.7.3/Misc/python-config.in	2012-04-18 19:46:22.082498324 -0400
c6247fd
@@ -45,7 +45,7 @@ for opt in opt_flags:
c6247fd
 
c6247fd
     elif opt in ('--libs', '--ldflags'):
c6247fd
         libs = getvar('LIBS').split() + getvar('SYSLIBS').split()
c6247fd
-        libs.append('-lpython'+pyver)
c6247fd
+        libs.append('-lpython' + pyver + (sys.pydebug and "_d" or ""))
c6247fd
         # add the prefix/lib/pythonX.Y/config dir, but only if there is no
c6247fd
         # shared library in prefix/lib/.
c6247fd
         if opt == '--ldflags':
b0a6ae1
diff -up Python-2.7.3/Modules/makesetup.debug-build Python-2.7.3/Modules/makesetup
b0a6ae1
--- Python-2.7.3/Modules/makesetup.debug-build	2012-04-09 19:07:34.000000000 -0400
9345b0f
+++ Python-2.7.3/Modules/makesetup	2012-04-18 19:46:22.083498312 -0400
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
b0a6ae1
diff -up Python-2.7.3/Python/dynload_shlib.c.debug-build Python-2.7.3/Python/dynload_shlib.c
b0a6ae1
--- Python-2.7.3/Python/dynload_shlib.c.debug-build	2012-04-09 19:07:35.000000000 -0400
9345b0f
+++ Python-2.7.3/Python/dynload_shlib.c	2012-04-18 19:46:22.083498312 -0400
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
 
b0a6ae1
diff -up Python-2.7.3/Python/sysmodule.c.debug-build Python-2.7.3/Python/sysmodule.c
b0a6ae1
--- Python-2.7.3/Python/sysmodule.c.debug-build	2012-04-09 19:07:35.000000000 -0400
9345b0f
+++ Python-2.7.3/Python/sysmodule.c	2012-04-18 19:46:22.083498312 -0400
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;