xref: /freebsd/share/mk/bsd.debug.mk (revision 4f81c42fbd76e25c9fe696fa08296b79c55fbf09)
1#
2# This file configures debug options for compiled targets.  It is meant
3# to consolidate common logic in bsd.prog.mk and bsd.lib.mk.  It should
4# not be included directly by Makefiles.
5#
6
7.include <bsd.opts.mk>
8
9.if ${MK_ASSERT_DEBUG} == "no"
10CFLAGS+= -DNDEBUG
11# XXX: shouldn't we ensure that !asserts marks potentially unused variables as
12# __unused instead of disabling -Werror globally?
13MK_WERROR=	no
14.endif
15
16# If reproducible build mode is enabled, map the root of the source
17# directory to /usr/src and the root of the object directory to
18# /usr/obj.
19.if ${MK_REPRODUCIBLE_BUILD} != "no" && !defined(DEBUG_PREFIX)
20.if defined(SRCTOP)
21DEBUG_PREFIX+= ${SRCTOP:S,/$,,}=/usr/src
22.endif
23.if defined(OBJROOT)
24# Strip off compat subdirectories, e.g., /usr/obj/usr/src/amd64.amd64/obj-lib32
25# becomes /usr/obj/usr/src/amd64.amd64, since object files compiled there might
26# refer to something outside the root.
27DEBUG_PREFIX+= ${OBJROOT:S,/$,,:C,/obj-[^/]*$,,}=/usr/obj
28.endif
29.endif
30
31.if defined(DEBUG_PREFIX)
32.for map in ${DEBUG_PREFIX}
33CFLAGS+= -ffile-prefix-map=${map}
34CXXFLAGS+= -ffile-prefix-map=${map}
35.endfor
36.endif
37
38.if defined(DEBUG_FLAGS)
39CFLAGS+=${DEBUG_FLAGS}
40CXXFLAGS+=${DEBUG_FLAGS}
41
42.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
43CTFFLAGS+= -g
44.endif
45.else
46STRIP?= -s
47.endif
48
49.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
50    empty(DEBUG_FLAGS:M-gdwarf*)
51.if !${COMPILER_FEATURES:Mcompressed-debug}
52CFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
53CXXFLAGS+= ${DEBUG_FILES_CFLAGS:N-gz*}
54.else
55CFLAGS+= ${DEBUG_FILES_CFLAGS}
56CXXFLAGS+= ${DEBUG_FILES_CFLAGS}
57.endif
58CTFFLAGS+= -g
59.endif
60
61_debuginstall:
62.if ${MK_DEBUG_FILES} != "no" && defined(DEBUGFILE)
63.if defined(DEBUGMKDIR)
64	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -d ${DESTDIR}${DEBUGFILEDIR}/
65.endif
66	${INSTALL} ${TAG_ARGS:D${TAG_ARGS},dbg} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
67	    ${DEBUGFILE} ${DESTDIR}${DEBUGFILEDIR}/${DEBUGFILE}
68.endif
69