diff --git a/bin/cygport.in b/bin/cygport.in
index 32e7dd1..1c74b31 100755
--- a/bin/cygport.in
+++ b/bin/cygport.in
@@ -589,6 +589,16 @@ declare -r src_patchfile=${PF}.src.patch;
 declare -ar pkg_name=(${PKG_NAMES:-${PN}});
 declare -r  pkg_count=${#pkg_name[*]};
 
+# this requires S and B to be already defined
+if ! defined _CYGPORT_RESTRICT_debuginfo_
+then
+	for flags in {C,CXX,F,FC,GCJ,GO,OBJC,OBJCXX}FLAGS
+	do
+		declare ${flags}+=" -ggdb -fdebug-prefix-map=${S}=/usr/src/debug/${PF} -fdebug-prefix-map=${B}=/usr/src/debug/${PF}"
+	done
+	unset flags
+fi
+
 ################################################################################
 #
 # Command processing
diff --git a/lib/compilers.cygpart b/lib/compilers.cygpart
index c543218..ba51f27 100644
--- a/lib/compilers.cygpart
+++ b/lib/compilers.cygpart
@@ -33,7 +33,7 @@ declare -x CC="gcc";
 #  DEFAULT VALUE
 #  -g -O2 -pipe
 #****
-declare -x CFLAGS="-g -O2 -pipe ";
+declare -x CFLAGS="-O2 -pipe";
 
 #****v* Compiling/CPPFLAGS
 #  DESCRIPTION
diff --git a/lib/pkg_pkg.cygpart b/lib/pkg_pkg.cygpart
index b645255..702b52d 100644
--- a/lib/pkg_pkg.cygpart
+++ b/lib/pkg_pkg.cygpart
@@ -128,7 +128,7 @@ __pkg_binpkg() {
 
 		if defined pkg_contents
 		then
-			tar jcvf ${top}/${pkg_name[${n}]}-${PVR}.tar.bz2 ${pkg_contents} \
+			tar jcvf ${top}/${pkg_name[${n}]}-${PVR}.tar.bz2 --exclude=usr/lib/debug --exclude=usr/src/debug ${pkg_contents} \
 				|| error "Binary package creation failed: ${pkg_name[${n}]}"
 		else
 			inform "Creating empty package"
@@ -138,6 +138,17 @@ __pkg_binpkg() {
 		echo;
 		n+=1;
 	done
+
+	if [ -d ${D}/usr/lib/debug -a -d ${D}/usr/src/debug ]
+	then
+		__step "${PN}-debuginfo-${PVR}.tar.bz2";
+		tar jcvf ${top}/${PN}-debuginfo-${PVR}.tar.bz2 usr/lib/debug/ usr/src/debug/ \
+				|| error "Debuginfo package creation failed: ${PN}-debuginfo"
+		echo;
+	else
+		inform "No debug files, skipping debuginfo subpackage"
+		echo;
+	fi
 }
 
 __pkg_pkgcheck() {
@@ -156,6 +167,11 @@ __pkg_pkgcheck() {
 		n+=1
 	done
 
+	if [ -f ${top}/${PN}-debuginfo-${PVR}.tar.bz2 ]
+	then
+		tar tjf ${top}/${PN}-debuginfo-${PVR}.tar.bz2 | grep -Ev "/$" >> ${tmp1}
+	fi
+
 #****v* Packaging/PKG_IGNORE
 #  DESCRIPTION
 #  A list of files that should not be included in any package, in the same
@@ -470,6 +486,28 @@ __pkg_dist() {
 		n+=1;
 	done
 
+	if [ -d ${top}/${PN}-debuginfo-${PVR}.tar.bz2 ]
+	then
+		mkdir -p ${distdir}/${PN}/${PN}-debuginfo
+		cp ${top}/${PN}-debuginfo-${PVR}.tar.bz2 ${distdir}/${PN}/${PN}-debuginfo/
+
+		if [ -f ${C}/${PN}-debuginfo.hint ]
+		then
+			cp ${C}/${PN}-debuginfo.hint ${distdir}/${PN}/${PN}-debuginfo/setup.hint
+		elif [ -f ${C}/debuginfo.hint ]
+		then
+			cp ${C}/debuginfo.hint ${distdir}/${PN}/${PN}-debuginfo/setup.hint
+		else
+			cat > ${distdir}/${PN}/${PN}-debuginfo/setup.hint <<-_EOF
+category: Debug
+requires: ${pkg_name[0]}
+sdesc: "Debug info for ${PN}"
+ldesc: "This package contains files necessary for debugging the
+${PN} package with gdb."
+_EOF
+		fi
+	fi
+
 	# e.g. split library package w/o PN in PKG_NAMES
 	if [ ! -f ${distdir}/${PN}/setup.hint ]
 	then
diff --git a/lib/src_postinst.cygpart b/lib/src_postinst.cygpart
index 0ba272a..8c1a4b5 100644
--- a/lib/src_postinst.cygpart
+++ b/lib/src_postinst.cygpart
@@ -834,9 +834,10 @@ __prep_empty_dirs() {
 #****
 
 __prepstrip() {
+	local dbg;
 	local exe;
 	local all_exes;
-	local strip;
+	local objcopy;
 
 	if defined _CYGPORT_RESTRICT_strip_
 	then
@@ -865,18 +866,18 @@ __prepstrip() {
 				mv ${exe} ${exe%.exe} ;;
 			esac
 			continue
-		elif check_prog ${CTARGET}-strip && ${CTARGET}-size -f ${exe} &>/dev/null
+		elif check_prog ${CTARGET}-objcopy && ${CTARGET}-size -f ${exe} &>/dev/null
 		then
 			# for cross-compiled libs, cross-GCC target libs,
 			# or non-cross packages built on non-Cygwin systems
-			strip="${CTARGET}-strip"
-		elif check_prog ${CHOST}-strip && ${CHOST}-size -f ${exe} &>/dev/null
+			objcopy="${CTARGET}-objcopy"
+		elif check_prog ${CHOST}-objcopy && ${CHOST}-size -f ${exe} &>/dev/null
 		then
 			# for cross-compilers built on non-Cygwin systems
-			strip="${CHOST}-strip"
+			objcopy="${CHOST}-objcopy"
 		elif size -f ${exe} &>/dev/null
 		then
-			strip="strip"
+			objcopy="objcopy"
 		else
 			continue
 		fi
@@ -912,7 +913,47 @@ __prepstrip() {
 
 		echo "        ${exe}";
 		chmod 0755 ${exe};
-		${strip} ${exe};
+
+		if defined _CYGPORT_RESTRICT_debuginfo_
+		then
+			${objcopy} --strip-all ${exe};
+		else
+			dbg="/usr/lib/debug/${exe%.*}.dbg";
+
+			dodir ${dbg%/*}
+			${objcopy} --only-keep-debug ${exe} ${D}${dbg};
+			${objcopy} --strip-debug ${exe};
+			${objcopy} --add-gnu-debuglink=${D}${dbg} ${exe};
+		fi
+	done
+}
+
+__prepdebugsrc() {
+	local dbg;
+	local dbgdir="/usr/lib/debug";
+	local dbgsrc;
+	local dbgsrcdir="/usr/src/debug/${PF}";
+	local srcf;
+
+	if defined _CYGPORT_RESTRICT_debuginfo_ || [ ! -f ${D}${dbgdir} ]
+	then
+		return;
+	fi
+
+	echo "Preparing debuginfo source files:";
+
+	for dbgsrc in $(strings $(find ${D}${dbgdir} -name '*.dbg') | grep ${dbgsrcdir}/ | sort -u)
+	do
+		srcf=${dbgsrc#${dbgsrcdir}/}
+		if [ -f ${B}/${srcf} ]
+		then
+			insinto ${dbgsrc%/*}
+			doins ${B}/${srcf}
+		elif [ -f ${S}/${srcf} ]
+		then
+			insinto ${dbgsrc%/*}
+			doins ${S}/${srcf}
+		fi
 	done
 }
 
@@ -1271,6 +1312,7 @@ __prep_libtool_modules() {
 #  DESCRIPTION
 #  List of automatic postinstall or packaging step(s) which should be skipped
 #  for this package.  Supported values are:
+#  * debuginfo: do not create a debuginfo subpackage
 #  * diff: do not generate a .src.patch file of changes made in $S.
 #  * postinst-doc: do not install standard documentation files.
 #  * postinst-gconf: do not create postinstall commands for GConf schemas.
@@ -1293,6 +1335,7 @@ __src_postinst() {
 	__prepvargames;
 	__prep_libtool_modules;
 	__prepstrip;
+	__prepdebugsrc;
 	__prepuac;
 	__prep_empty_dirs;
 }
@@ -1303,4 +1346,5 @@ readonly -f __prep_fonts_dir __prep_freedesktop_mime __prep_gconf_schemas \
             __prep_mateconf_schemas __prep_texlive __prep_xsessions \
             __prepdoc __prepemacs __prepetc __prepman __prepinfo \
             __prepvargames __prep_empty_dirs \
-            __prepstrip __prepuac __prep_symlinks __prep_libtool_modules __src_postinst
+            __prepstrip __prepdebugsrc __prepuac __prep_symlinks \
+            __prep_libtool_modules __src_postinst
