Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 5 Jul 2013 19:35:51 +0000 (UTC)
From:      Ed Maste <emaste@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org
Subject:   svn commit: r252827 - in stable/9: . etc etc/mtree gnu/usr.bin/gdb gnu/usr.bin/gdb/arch/amd64 gnu/usr.bin/gdb/arch/arm gnu/usr.bin/gdb/arch/i386 gnu/usr.bin/gdb/arch/ia64 gnu/usr.bin/gdb/arch/mips ...
Message-ID:  <201307051935.r65JZpqe051782@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: emaste
Date: Fri Jul  5 19:35:51 2013
New Revision: 252827
URL: http://svnweb.freebsd.org/changeset/base/252827

Log:
  MFC r244236,r244408,r244915,r247054,r251512:
  
    Add a new knob WITH_DEBUG_FILES to control the building of standalone
    debug files for userland programs and libraries.  The "-g" debug flag
    is automatically applied when WITH_DEBUG_FILES is set.
  
    The debug files are named ${prog}.debug and ${shlib}.debug for                  consistency with other systems and documentation.  In addition they are
    installed under /usr/lib/debug, to simplify the process of installing
    them if needed after a crash.  Users of bsd.{prog,lib}.mk outside of the
    base system place the standalone debug files in a .debug subdirectory.
    GDB automatically searches both of these directories for standalone
    debug files.

Added:
  stable/9/etc/mtree/BSD.debug.dist
     - copied unchanged from r251512, head/etc/mtree/BSD.debug.dist
  stable/9/tools/build/options/WITH_DEBUG_FILES
     - copied unchanged from r251512, head/tools/build/options/WITH_DEBUG_FILES
Modified:
  stable/9/Makefile.inc1   (contents, props changed)
  stable/9/etc/Makefile
  stable/9/etc/mtree/Makefile
  stable/9/gnu/usr.bin/gdb/Makefile.inc
  stable/9/gnu/usr.bin/gdb/arch/amd64/config.h
  stable/9/gnu/usr.bin/gdb/arch/arm/config.h
  stable/9/gnu/usr.bin/gdb/arch/i386/config.h
  stable/9/gnu/usr.bin/gdb/arch/ia64/config.h
  stable/9/gnu/usr.bin/gdb/arch/mips/config.h
  stable/9/gnu/usr.bin/gdb/arch/powerpc/config.h
  stable/9/gnu/usr.bin/gdb/arch/powerpc64/config.h
  stable/9/gnu/usr.bin/gdb/arch/sparc64/config.h
  stable/9/gnu/usr.bin/gdb/gdb/Makefile
  stable/9/share/mk/bsd.crunchgen.mk
  stable/9/share/mk/bsd.lib.mk
  stable/9/share/mk/bsd.own.mk
  stable/9/share/mk/bsd.prog.mk
  stable/9/share/mk/sys.mk
Directory Properties:
  stable/9/etc/   (props changed)
  stable/9/etc/mtree/   (props changed)
  stable/9/gnu/usr.bin/gdb/   (props changed)
  stable/9/share/mk/   (props changed)
  stable/9/tools/build/options/   (props changed)

Modified: stable/9/Makefile.inc1
==============================================================================
--- stable/9/Makefile.inc1	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/Makefile.inc1	Fri Jul  5 19:35:51 2013	(r252827)
@@ -419,6 +419,13 @@ _worldtmp:
 	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
 	    -p ${WORLDTMP}/usr/include >/dev/null
 	ln -sf ${.CURDIR}/sys ${WORLDTMP}
+.if ${MK_DEBUG_FILES} != "no"
+	# We could instead disable debug files for these build stages
+	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
+	    -p ${WORLDTMP}/legacy/usr/lib >/dev/null
+	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
+	    -p ${WORLDTMP}/usr/lib >/dev/null
+.endif
 .if ${MK_BIND_LIBS} != "no"
 	mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \
 	    -p ${WORLDTMP}/usr/include >/dev/null
@@ -504,6 +511,10 @@ build32:
 	    -p ${LIB32TMP}/usr >/dev/null
 	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
 	    -p ${LIB32TMP}/usr/include >/dev/null
+.if ${MK_DEBUG_FILES} != "no"
+	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
+	    -p ${LIB32TMP}/usr/lib >/dev/null
+.endif
 	mkdir -p ${WORLDTMP}
 	ln -sf ${.CURDIR}/sys ${WORLDTMP}
 .if ${MK_KERBEROS} != "no"
@@ -733,6 +744,10 @@ distributeworld installworld: installche
 	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null
 	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \
 	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null
+.if ${MK_DEBUG_FILES} != "no"
+	mtree -deU -f ${.CURDIR}/etc/mtree/BSD.debug.dist \
+	    -p ${DESTDIR}/${DISTDIR}/${dist}/usr/lib >/dev/null
+.endif
 .if defined(NO_ROOT)
 	${IMAKEENV} nmtree -C -f ${.CURDIR}/etc/mtree/BSD.root.dist | \
 	    sed -e 's#^\./#./${dist}/#' >> ${METALOG}

Modified: stable/9/etc/Makefile
==============================================================================
--- stable/9/etc/Makefile	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/etc/Makefile	Fri Jul  5 19:35:51 2013	(r252827)
@@ -143,6 +143,9 @@ MTREE+=	BIND.chroot.dist
 MTREE+=	BIND.include.dist
 .endif
 .endif
+.if ${MK_DEBUG_FILES} != "no"
+MTREE+=	BSD.debug.dist
+.endif
 
 PPPCNF=	ppp.conf
 
@@ -309,6 +312,9 @@ MTREES=		mtree/BSD.root.dist		/		\
 		mtree/BSD.var.dist		/var		\
 		mtree/BSD.usr.dist		/usr		\
 		mtree/BSD.include.dist		/usr/include
+.if ${MK_DEBUG_FILES} != "no"
+MTREES+=	mtree/BSD.debug.dist		/usr/lib
+.endif
 .if ${MK_BIND_LIBS} != "no"
 MTREES+=	mtree/BIND.include.dist		/usr/include
 .endif

Copied: stable/9/etc/mtree/BSD.debug.dist (from r251512, head/etc/mtree/BSD.debug.dist)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/etc/mtree/BSD.debug.dist	Fri Jul  5 19:35:51 2013	(r252827, copy of r251512, head/etc/mtree/BSD.debug.dist)
@@ -0,0 +1,48 @@
+# $FreeBSD$
+#
+# Please see the file src/etc/mtree/README before making changes to this file.
+#
+
+/set type=dir uname=root gname=wheel mode=0755
+.
+    debug
+        bin
+        ..
+        boot
+        ..
+        lib
+            geom
+            ..
+        ..
+        libexec
+        ..
+        sbin
+        ..
+        usr
+            bin
+            ..
+            games
+            ..
+            lib
+                engines
+                ..
+            ..
+            lib32
+            ..
+            libexec
+                bsdinstall
+                ..
+                lpr
+                    ru
+                    ..
+                ..
+                sendmail
+                ..
+                sm.bin
+                ..
+            ..
+            sbin
+            ..
+        ..
+    ..
+..

Modified: stable/9/etc/mtree/Makefile
==============================================================================
--- stable/9/etc/mtree/Makefile	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/etc/mtree/Makefile	Fri Jul  5 19:35:51 2013	(r252827)
@@ -4,6 +4,7 @@
 
 FILES=	${_BIND.chroot.dist} \
 	${_BIND.include.dist} \
+	${_BSD.debug.dist} \
 	BSD.include.dist \
 	BSD.root.dist \
 	${_BSD.sendmail.dist} \
@@ -16,6 +17,9 @@ _BIND.chroot.dist=	BIND.chroot.dist
 _BIND.include.dist=	BIND.include.dist
 .endif
 .endif
+.if ${MK_DEBUG_FILES} != "no"
+_BSD.debug.dist=	BSD.debug.dist
+.endif
 .if ${MK_GROFF} != "no"
 _BSD.groff.dist=	BSD.groff.dist
 .endif

Modified: stable/9/gnu/usr.bin/gdb/Makefile.inc
==============================================================================
--- stable/9/gnu/usr.bin/gdb/Makefile.inc	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/Makefile.inc	Fri Jul  5 19:35:51 2013	(r252827)
@@ -37,6 +37,7 @@ GDB_CROSS_DEBUGGER=
 	${CNTRB_GDB}/gdb/signals ${CNTRB_GDB}/gdb/tui ${TARGET_SUBDIR}
 
 CFLAGS+= -DHAVE_CONFIG_H -DRL_NO_COMPAT -DMI_OUT=1 -DTUI=1
+CFLAGS+= -DDEBUGDIR=\"${DEBUGDIR}\"
 CFLAGS+= -I.
 CFLAGS+= -I${TARGET_SUBDIR}
 CFLAGS+= -I${BMAKE_BU}/libbfd -I${BMAKE_BU}/libbfd/${TARGET_CPUARCH}

Modified: stable/9/gnu/usr.bin/gdb/arch/amd64/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/amd64/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/amd64/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_i386_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/arm/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/arm/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/arm/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -451,9 +451,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_arm_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/i386/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/i386/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/i386/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_i386_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/ia64/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/ia64/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/ia64/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_ia64_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/mips/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/mips/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/mips/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_mips_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/powerpc/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/powerpc/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/powerpc/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_rs6000_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/powerpc64/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/powerpc64/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/powerpc64/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_rs6000_arch
 

Modified: stable/9/gnu/usr.bin/gdb/arch/sparc64/config.h
==============================================================================
--- stable/9/gnu/usr.bin/gdb/arch/sparc64/config.h	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/arch/sparc64/config.h	Fri Jul  5 19:35:51 2013	(r252827)
@@ -439,9 +439,6 @@
 /* Name of this package.  */
 #define PACKAGE "gdb"
 
-/* Global directory for separate debug files.  */
-#define DEBUGDIR "/usr/local/lib/debug"
-
 /* Define to BFD's default architecture.  */
 #define DEFAULT_BFD_ARCH bfd_sparc_arch
 

Modified: stable/9/gnu/usr.bin/gdb/gdb/Makefile
==============================================================================
--- stable/9/gnu/usr.bin/gdb/gdb/Makefile	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/gnu/usr.bin/gdb/gdb/Makefile	Fri Jul  5 19:35:51 2013	(r252827)
@@ -15,3 +15,4 @@ DPADD=	${GDBLIBS} ${BULIBS} ${LIBM} ${LI
 LDADD=	${GDBLIBS} ${BULIBS} -lm -lreadline -ltermcap -lgnuregex
 
 .include <bsd.prog.mk>
+CFLAGS+=	-DDEBUGDIR=\"${DEBUGDIR}\"

Modified: stable/9/share/mk/bsd.crunchgen.mk
==============================================================================
--- stable/9/share/mk/bsd.crunchgen.mk	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/share/mk/bsd.crunchgen.mk	Fri Jul  5 19:35:51 2013	(r252827)
@@ -44,6 +44,9 @@ CANONICALOBJDIR:= /usr/obj${.CURDIR}
 
 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
 
+# Don't try to extract debug info from ${PROG}.
+NO_DEBUG_FILES=
+
 # Program names and their aliases contribute hardlinks to 'rescue' executable,
 # except for those that get suppressed.
 .for D in $(CRUNCH_SRCDIRS)

Modified: stable/9/share/mk/bsd.lib.mk
==============================================================================
--- stable/9/share/mk/bsd.lib.mk	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/share/mk/bsd.lib.mk	Fri Jul  5 19:35:51 2013	(r252827)
@@ -43,6 +43,12 @@ CTFFLAGS+= -g
 STRIP?=	-s
 .endif
 
+.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
+    empty(DEBUG_FLAGS:M-gdwarf*)
+CFLAGS+= -g
+CTFFLAGS+= -g
+.endif
+
 .include <bsd.libnames.mk>
 
 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
@@ -113,12 +119,29 @@ PO_FLAG=-pg
 
 all: objwarn
 
+.if defined(SHLIB_NAME)
+.if ${MK_DEBUG_FILES} != "no"
+SHLIB_NAME_FULL=${SHLIB_NAME}.full
+# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
+.if ${SHLIBDIR} == "/boot" ||\
+    ${SHLIBDIR:C%/lib(/.*)?$%/lib%} == "/lib" ||\
+    ${SHLIBDIR:C%/usr/lib(32)?(/.*)?%/usr/lib%} == "/usr/lib"
+DEBUGFILEDIR=${DEBUGDIR}${SHLIBDIR}
+.else
+DEBUGFILEDIR=${SHLIBDIR}/.debug
+DEBUGMKDIR=
+.endif
+.else
+SHLIB_NAME_FULL=${SHLIB_NAME}
+.endif
+.endif
+
 .include <bsd.symver.mk>
 
 # Allow libraries to specify their own version map or have it
 # automatically generated (see bsd.symver.mk above).
 .if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP)
-${SHLIB_NAME}:	${VERSION_MAP}
+${SHLIB_NAME_FULL}:	${VERSION_MAP}
 LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
 .endif
 
@@ -171,11 +194,12 @@ SOLINKOPTS+=	-Wl,--fatal-warnings -Wl,--
 .endif
 
 .if target(beforelinking)
-${SHLIB_NAME}: beforelinking
+beforelinking: ${SOBJS}
+${SHLIB_NAME_FULL}: beforelinking
 .endif
-${SHLIB_NAME}: ${SOBJS}
+${SHLIB_NAME_FULL}: ${SOBJS}
 	@${ECHO} building shared library ${SHLIB_NAME}
-	@rm -f ${.TARGET} ${SHLIB_LINK}
+	@rm -f ${SHLIB_NAME} ${SHLIB_LINK}
 .if defined(SHLIB_LINK)
 	@${INSTALL_SYMLINK} ${SHLIB_NAME} ${SHLIB_LINK}
 .endif
@@ -191,6 +215,16 @@ ${SHLIB_NAME}: ${SOBJS}
 .if ${MK_CTF} != "no"
 	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
 .endif
+
+.if ${MK_DEBUG_FILES} != "no"
+CLEANFILES+=	${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
+${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
+	${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \
+	    ${SHLIB_NAME_FULL} ${.TARGET}
+
+${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL}
+	${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET}
+.endif
 .endif
 
 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
@@ -267,6 +301,14 @@ _libinstall:
 	${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
 	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
 	    ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
+.if ${MK_DEBUG_FILES} != "no"
+.if defined(DEBUGMKDIR)
+	${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
+.endif
+	${INSTALL} -T debug -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \
+	    ${_INSTALLFLAGS} \
+	    ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}
+.endif
 .if defined(SHLIB_LINK)
 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
 # and when building 32 bits library shims.  ${_SHLIBDIRPREFIX} is the directory

Modified: stable/9/share/mk/bsd.own.mk
==============================================================================
--- stable/9/share/mk/bsd.own.mk	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/share/mk/bsd.own.mk	Fri Jul  5 19:35:51 2013	(r252827)
@@ -43,6 +43,11 @@
 # LIBMODE	Library mode. [${NOBINMODE}]
 #
 #
+# DEBUGDIR	Base path for standalone debug files. [/usr/lib/debug]
+#
+# DEBUGMODE	Mode for debug files. [${NOBINMODE}]
+#
+#
 # KMODDIR	Base path for loadable kernel modules
 #		(see kld(4)). [/boot/kernel]
 #
@@ -147,6 +152,9 @@ LIBOWN?=	${BINOWN}
 LIBGRP?=	${BINGRP}
 LIBMODE?=	${NOBINMODE}
 
+DEBUGDIR?=	/usr/lib/debug
+DEBUGMODE?=	${NOBINMODE}
+
 
 # Share files
 SHAREDIR?=	/usr/share
@@ -213,6 +221,7 @@ COMPRESS_EXT?=	.gz
 #
 .for var in \
     CTF \
+    DEBUG_FILES \
     INSTALLLIB \
     MAN \
     PROFILE
@@ -434,6 +443,8 @@ __DEFAULT_NO_OPTIONS = \
     CLANG_EXTRAS \
     CLANG_IS_CC \
     CTF \
+    DEBUG_FILES \
+    GPL_DTC \
     HESIOD \
     ICONV \
     IDEA \

Modified: stable/9/share/mk/bsd.prog.mk
==============================================================================
--- stable/9/share/mk/bsd.prog.mk	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/share/mk/bsd.prog.mk	Fri Jul  5 19:35:51 2013	(r252827)
@@ -24,8 +24,24 @@ CTFFLAGS+= -g
 .endif
 .endif
 
+.if defined(PROG_CXX)
+PROG=	${PROG_CXX}
+.endif
+
+.if defined(PROG) && target(${PROG})
+MK_DEBUG_FILES=	no
+.elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
+MK_DEBUG_FILES=	no
+.endif
+
 .if defined(CRUNCH_CFLAGS)
 CFLAGS+=${CRUNCH_CFLAGS}
+.else
+.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
+    empty(DEBUG_FLAGS:M-gdwarf-*)
+CFLAGS+= -g
+CTFFLAGS+= -g
+.endif
 .endif
 
 .if !defined(DEBUG_FLAGS)
@@ -36,20 +52,36 @@ STRIP?=	-s
 LDFLAGS+= -static
 .endif
 
-.if defined(PROG_CXX)
-PROG=	${PROG_CXX}
+.if ${MK_DEBUG_FILES} != "no"
+PROG_FULL=${PROG}.full
+# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
+.if defined(BINDIR) && (\
+    ${BINDIR} == "/bin" ||\
+    ${BINDIR} == "/libexec" ||\
+    ${BINDIR} == "/sbin" ||\
+    ${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
+     )
+DEBUGFILEDIR=	${DEBUGDIR}${BINDIR}
+.else
+DEBUGFILEDIR?=	${BINDIR}/.debug
+DEBUGMKDIR=
+.endif
+.else
+PROG_FULL=	${PROG}
 .endif
 
 .if defined(PROG)
 PROGNAME?=	${PROG}
+
 .if defined(SRCS)
 
 OBJS+=  ${SRCS:N*.h:R:S/$/.o/g}
 
 .if target(beforelinking)
-${PROG}: beforelinking
+beforelinking: ${OBJS}
+${PROG_FULL}: beforelinking
 .endif
-${PROG}: ${OBJS}
+${PROG_FULL}: ${OBJS}
 .if defined(PROG_CXX)
 	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
 .else
@@ -76,9 +108,10 @@ SRCS=	${PROG}.c
 OBJS=	${PROG}.o
 
 .if target(beforelinking)
-${PROG}: beforelinking
+beforelinking: ${OBJS}
+${PROG_FULL}: beforelinking
 .endif
-${PROG}: ${OBJS}
+${PROG_FULL}: ${OBJS}
 .if defined(PROG_CXX)
 	${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
 .else
@@ -87,10 +120,19 @@ ${PROG}: ${OBJS}
 .if ${MK_CTF} != "no"
 	${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
 .endif
-.endif
+.endif # !target(${PROG})
 
 .endif # !defined(SRCS)
 
+.if ${MK_DEBUG_FILES} != "no"
+${PROG}: ${PROG_FULL} ${PROGNAME}.debug
+	${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
+	    ${PROG_FULL} ${.TARGET}
+
+${PROGNAME}.debug: ${PROG_FULL}
+	${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
+.endif
+
 .if	${MK_MAN} != "no" && !defined(MAN) && \
 	!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
 	!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
@@ -107,6 +149,9 @@ all: _manpages
 
 .if defined(PROG)
 CLEANFILES+= ${PROG}
+.if ${MK_DEBUG_FILES} != "no"
+CLEANFILES+=	${PROG_FULL} ${PROGNAME}.debug
+.endif
 .endif
 
 .if defined(OBJS)
@@ -154,6 +199,13 @@ _proginstall:
 .if defined(PROG)
 	${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
 	    ${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
+.if ${MK_DEBUG_FILES} != "no"
+.if defined(DEBUGMKDIR)
+	${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
+.endif
+	${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
+	    ${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
+.endif
 .endif
 .endif	# !target(realinstall)
 

Modified: stable/9/share/mk/sys.mk
==============================================================================
--- stable/9/share/mk/sys.mk	Fri Jul  5 19:26:01 2013	(r252826)
+++ stable/9/share/mk/sys.mk	Fri Jul  5 19:35:51 2013	(r252827)
@@ -130,6 +130,8 @@ MAKE		?=	make
 OBJC		?=	cc
 OBJCFLAGS	?=	${OBJCINCLUDES} ${CFLAGS} -Wno-import
 
+OBJCOPY		?=	objcopy
+
 PC		?=	pc
 PFLAGS		?=
 

Copied: stable/9/tools/build/options/WITH_DEBUG_FILES (from r251512, head/tools/build/options/WITH_DEBUG_FILES)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/9/tools/build/options/WITH_DEBUG_FILES	Fri Jul  5 19:35:51 2013	(r252827, copy of r251512, head/tools/build/options/WITH_DEBUG_FILES)
@@ -0,0 +1,7 @@
+.\" $FreeBSD$
+Set to strip debug info into a separate file for each executable binary
+and shared library.
+The debug files will be placed in a subdirectory of
+.Pa /usr/lib/debug
+and are located automatically by
+.Xr gdb 1 .



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307051935.r65JZpqe051782>