summaryrefslogtreecommitdiffstats
path: root/share/mk
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2013-06-07 21:40:02 +0000
committeremaste <emaste@FreeBSD.org>2013-06-07 21:40:02 +0000
commit390d8402e005d267efedefcb438af08e196b3d95 (patch)
tree1f627bceaf932e22013baa1c3a548108de20a7f1 /share/mk
parent6445326c71cfbc6642679290f0fed222d43f477f (diff)
downloadFreeBSD-src-390d8402e005d267efedefcb438af08e196b3d95.zip
FreeBSD-src-390d8402e005d267efedefcb438af08e196b3d95.tar.gz
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 now 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. Thanks to everyone who contributed changes, review, and testing during development.
Diffstat (limited to 'share/mk')
-rw-r--r--share/mk/bsd.crunchgen.mk3
-rw-r--r--share/mk/bsd.lib.mk38
-rw-r--r--share/mk/bsd.own.mk10
-rw-r--r--share/mk/bsd.prog.mk64
4 files changed, 98 insertions, 17 deletions
diff --git a/share/mk/bsd.crunchgen.mk b/share/mk/bsd.crunchgen.mk
index 95f1aa3..d8f07b1 100644
--- a/share/mk/bsd.crunchgen.mk
+++ b/share/mk/bsd.crunchgen.mk
@@ -47,6 +47,9 @@ CRUNCH_GENERATE_LINKS?= yes
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)
diff --git a/share/mk/bsd.lib.mk b/share/mk/bsd.lib.mk
index cb2544c..3edb5bc 100644
--- a/share/mk/bsd.lib.mk
+++ b/share/mk/bsd.lib.mk
@@ -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
@@ -114,8 +120,17 @@ PO_FLAG=-pg
all: objwarn
.if defined(SHLIB_NAME)
-.if defined(DEBUG_FLAGS)
-SHLIB_NAME_FULL=${SHLIB_NAME}.debug
+.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
@@ -201,13 +216,13 @@ ${SHLIB_NAME_FULL}: ${SOBJS}
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
.endif
-.if defined(DEBUG_FLAGS)
-CLEANFILES+= ${SHLIB_NAME_FULL} ${SHLIB_NAME}.symbols
-${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.symbols
- ${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.symbols \
+.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}.symbols: ${SHLIB_NAME_FULL}
+${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL}
${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET}
.endif
.endif #defined(SHLIB_NAME)
@@ -286,10 +301,13 @@ _libinstall:
${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
-.if defined(DEBUG_FLAGS)
- ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
+.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}.symbols ${DESTDIR}${SHLIBDIR}
+ ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}
.endif
.if defined(SHLIB_LINK)
# ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
diff --git a/share/mk/bsd.own.mk b/share/mk/bsd.own.mk
index dfa8ed6..a9eee61 100644
--- a/share/mk/bsd.own.mk
+++ b/share/mk/bsd.own.mk
@@ -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
@@ -365,6 +374,7 @@ __DEFAULT_NO_OPTIONS = \
BSD_GREP \
CLANG_EXTRAS \
CTF \
+ DEBUG_FILES \
GPL_DTC \
HESIOD \
ICONV \
diff --git a/share/mk/bsd.prog.mk b/share/mk/bsd.prog.mk
index 0991915..f4546dc 100644
--- a/share/mk/bsd.prog.mk
+++ b/share/mk/bsd.prog.mk
@@ -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,21 +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)
beforelinking: ${OBJS}
-${PROG}: beforelinking
+${PROG_FULL}: beforelinking
.endif
-${PROG}: ${OBJS}
+${PROG_FULL}: ${OBJS}
.if defined(PROG_CXX)
${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.else
@@ -78,9 +109,9 @@ OBJS+= ${PROG}.o
.if target(beforelinking)
beforelinking: ${OBJS}
-${PROG}: beforelinking
+${PROG_FULL}: beforelinking
.endif
-${PROG}: ${OBJS}
+${PROG_FULL}: ${OBJS}
.if defined(PROG_CXX)
${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.else
@@ -89,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) && \
@@ -109,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)
@@ -156,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)
OpenPOWER on IntegriCloud