xref: /freebsd/share/mk/bsd.debug.mk (revision 4f81c42fbd76e25c9fe696fa08296b79c55fbf09)
13a239e46SMark Johnston#
23a239e46SMark Johnston# This file configures debug options for compiled targets.  It is meant
33a239e46SMark Johnston# to consolidate common logic in bsd.prog.mk and bsd.lib.mk.  It should
43a239e46SMark Johnston# not be included directly by Makefiles.
53a239e46SMark Johnston#
63a239e46SMark Johnston
73a239e46SMark Johnston.include <bsd.opts.mk>
83a239e46SMark Johnston
93a239e46SMark Johnston.if ${MK_ASSERT_DEBUG} == "no"
103a239e46SMark JohnstonCFLAGS+= -DNDEBUG
113a239e46SMark Johnston# XXX: shouldn't we ensure that !asserts marks potentially unused variables as
123a239e46SMark Johnston# __unused instead of disabling -Werror globally?
133a239e46SMark JohnstonMK_WERROR=	no
143a239e46SMark Johnston.endif
153a239e46SMark Johnston
16*4f81c42fSMark Johnston# If reproducible build mode is enabled, map the root of the source
17*4f81c42fSMark Johnston# directory to /usr/src and the root of the object directory to
18*4f81c42fSMark Johnston# /usr/obj.
19*4f81c42fSMark Johnston.if ${MK_REPRODUCIBLE_BUILD} != "no" && !defined(DEBUG_PREFIX)
20*4f81c42fSMark Johnston.if defined(SRCTOP)
21*4f81c42fSMark JohnstonDEBUG_PREFIX+= ${SRCTOP:S,/$,,}=/usr/src
22*4f81c42fSMark Johnston.endif
23*4f81c42fSMark Johnston.if defined(OBJROOT)
24*4f81c42fSMark Johnston# Strip off compat subdirectories, e.g., /usr/obj/usr/src/amd64.amd64/obj-lib32
25*4f81c42fSMark Johnston# becomes /usr/obj/usr/src/amd64.amd64, since object files compiled there might
26*4f81c42fSMark Johnston# refer to something outside the root.
27*4f81c42fSMark JohnstonDEBUG_PREFIX+= ${OBJROOT:S,/$,,:C,/obj-[^/]*$,,}=/usr/obj
28*4f81c42fSMark Johnston.endif
29*4f81c42fSMark Johnston.endif
30*4f81c42fSMark Johnston
31*4f81c42fSMark Johnston.if defined(DEBUG_PREFIX)
32*4f81c42fSMark Johnston.for map in ${DEBUG_PREFIX}
33*4f81c42fSMark JohnstonCFLAGS+= -ffile-prefix-map=${map}
34*4f81c42fSMark JohnstonCXXFLAGS+= -ffile-prefix-map=${map}
35*4f81c42fSMark Johnston.endfor
36*4f81c42fSMark Johnston.endif
37*4f81c42fSMark Johnston
383a239e46SMark Johnston.if defined(DEBUG_FLAGS)
393a239e46SMark JohnstonCFLAGS+=${DEBUG_FLAGS}
403a239e46SMark JohnstonCXXFLAGS+=${DEBUG_FLAGS}
413a239e46SMark Johnston
423a239e46SMark Johnston.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
433a239e46SMark JohnstonCTFFLAGS+= -g
443a239e46SMark Johnston.endif
453a239e46SMark Johnston.else
463a239e46SMark JohnstonSTRIP?= -s
473a239e46SMark Johnston.endif
483a239e46SMark Johnston
493a239e46SMark Johnston.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
503a239e46SMark Johnston    empty(DEBUG_FLAGS:M-gdwarf*)
513a239e46SMark Johnston.if !${COMPILER_FEATURES:Mcompressed-debug}
523a239e46SMark JohnstonCFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
533a239e46SMark JohnstonCXXFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
543a239e46SMark Johnston.else
553a239e46SMark JohnstonCFLAGS+= ${DEBUG_FILES_CFLAGS}
563a239e46SMark JohnstonCXXFLAGS+= ${DEBUG_FILES_CFLAGS}
573a239e46SMark Johnston.endif
583a239e46SMark JohnstonCTFFLAGS+= -g
593a239e46SMark Johnston.endif
603a239e46SMark Johnston
613a239e46SMark Johnston_debuginstall:
623a239e46SMark Johnston.if ${MK_DEBUG_FILES} != "no" && defined(DEBUGFILE)
633a239e46SMark Johnston.if defined(DEBUGMKDIR)
643a239e46SMark Johnston	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -d ${DESTDIR}${DEBUGFILEDIR}/
653a239e46SMark Johnston.endif
663a239e46SMark Johnston	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
673a239e46SMark Johnston	    ${DEBUGFILE} ${DESTDIR}${DEBUGFILEDIR}/${DEBUGFILE}
683a239e46SMark Johnston.endif
69