[BACK]Return to bsd.sys.mk CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / mk

File: [cvs.NetBSD.org] / src / share / mk / bsd.sys.mk (download)

Revision 1.277, Thu May 24 02:06:31 2018 UTC (8 months ago) by christos
Branch: MAIN
Changes since 1.276: +5 -3 lines

Be more selective about remapping object directories otherwise we pick
objdump and objcopy with the regex.

XXX: pullup-8

#	$NetBSD: bsd.sys.mk,v 1.277 2018/05/24 02:06:31 christos Exp $
# Build definitions used for NetBSD source tree builds.

.if !defined(_BSD_SYS_MK_)

.if !empty(.INCLUDEDFROMFILE:MMakefile*)
	@(echo "bsd.sys.mk should not be included from Makefiles" >& 2; exit 1)
.if !defined(_BSD_OWN_MK_)
	@(echo "bsd.own.mk must be included before bsd.sys.mk" >& 2; exit 1)

# XXX: LLVM does not support -iremap and -fdebug-*
.if ${MKREPRO:Uno} == "yes" && ${MKLLVM:Uno} != "yes"

.if !empty(DESTDIR)
CPPFLAGS+=	-Wp,-iremap,${DESTDIR}:
REPROFLAGS+=	-fdebug-prefix-map=\$$DESTDIR=

CPPFLAGS+=	-Wp,-fno-canonical-system-headers
CPPFLAGS+=	-Wp,-iremap,${NETBSDSRCDIR}:/usr/src
CPPFLAGS+=	-Wp,-iremap,${X11SRCDIR}:/usr/xsrc
REPROFLAGS+=	-fdebug-prefix-map=\$$NETBSDSRCDIR=/usr/src
REPROFLAGS+=	-fdebug-prefix-map=\$$X11SRCDIR=/usr/xsrc
LINTFLAGS+=	-R${NETBSDSRCDIR}=/usr/src -R${X11SRCDIR}=/usr/xsrc

REPROFLAGS+=	-fdebug-regex-map='/usr/src/(.*)/obj$$=/usr/obj/\1'
REPROFLAGS+=	-fdebug-regex-map='/usr/src/(.*)/obj/(.*)=/usr/obj/\1/\2'
REPROFLAGS+=	-fdebug-regex-map='/usr/src/(.*)/obj\..*=/usr/obj/\1'
REPROFLAGS+=	-fdebug-regex-map='/usr/src/(.*)/obj\..*/(.*)=/usr/obj/\1/\2'


# NetBSD sources use C99 style, with some GCC extensions.
# Coverity does not like -std=gnu99
CFLAGS+=	${${ACTIVE_CC} == "clang":? -std=gnu99 :}
CFLAGS+=	${${ACTIVE_CC} == "gcc":? -std=gnu99 :}
CFLAGS+=	${${ACTIVE_CC} == "pcc":? -std=gnu99 :}

.if defined(WARNS)
CFLAGS+=	${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :}
.if ${WARNS} > 0
CFLAGS+=	-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
#CFLAGS+=	-Wmissing-declarations -Wredundant-decls -Wnested-externs
# Add -Wno-sign-compare.  -Wsign-compare is included in -Wall as of GCC 3.3,
# but our sources aren't up for it yet. Also, add -Wno-traditional because
# gcc includes #elif in the warnings, which is 'this code will not compile
# in a traditional environment' warning, as opposed to 'this code behaves
# differently in traditional and ansi environments' which is the warning
# we wanted, and now we don't get anymore.
CFLAGS+=	-Wno-sign-compare
# Don't suppress warnings coming from constructs in system headers.
# Our system headers should be clean and we want to warn about things like:
# isdigit((char)1)
CFLAGS+=	${${ACTIVE_CC} == "gcc" :? -Wsystem-headers :}
CFLAGS+=	${${ACTIVE_CC} == "gcc" :? -Wno-traditional :}
.if !defined(NOGCCERROR)
# Set assembler warnings to be fatal
CFLAGS+=	${${ACTIVE_CC} == "gcc" :? -Wa,--fatal-warnings :}

.if ${MKRELRO:Uno} != "no"
LDFLAGS+=	-Wl,-z,relro
.if ${MKRELRO:Uno} == "full"
LDFLAGS+=	-Wl,-z,now

# Set linker warnings to be fatal
# XXX no proper way to avoid "FOO is a patented algorithm" warnings
# XXX on linking static libs
.if (!defined(MKPIC) || ${MKPIC} != "no") && \
    (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
# XXX there are some strange problems not yet resolved
. if !defined(HAVE_GCC) || defined(HAVE_LLVM)
LDFLAGS+=	-Wl,--fatal-warnings
. endif

LDFLAGS+=	-Wl,--warn-shared-textrel

.if ${WARNS} > 1
CFLAGS+=	-Wreturn-type -Wswitch -Wshadow
.if ${WARNS} > 2
CFLAGS+=	-Wcast-qual -Wwrite-strings
CFLAGS+=	-Wextra -Wno-unused-parameter
# Readd -Wno-sign-compare to override -Wextra with clang
CFLAGS+=	-Wno-sign-compare
CXXFLAGS+=	-Wold-style-cast
CXXFLAGS+=	-Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \
		-Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wsynth
CXXFLAGS+=	${${ACTIVE_CXX} == "gcc":? -Wno-non-template-friend -Wno-pmf-conversions :}
.if ${WARNS} > 3 && (defined(HAVE_GCC) || defined(HAVE_LLVM))
.if ${WARNS} > 4
CFLAGS+=	-Wold-style-definition
.if ${WARNS} > 5
CFLAGS+=	-Wconversion
CFLAGS+=	-Wsign-compare -Wformat=2
CFLAGS+=	${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :}
.if ${WARNS} > 3 && defined(HAVE_LLVM)
CFLAGS+=	${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :}
.if (defined(HAVE_GCC) \
     && (${MACHINE_ARCH} == "coldfire" || \
	 ${MACHINE_CPU} == "sh3" || \
	 ${MACHINE_CPU} == "m68k"))
# XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for
# cases it should be better with
CFLAGS+=	-Wno-uninitialized
CFLAGS+=	-Wno-maybe-uninitialized


_NOWERROR=	${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no}
CFLAGS+=	${${_NOWERROR} == "no" :?-Werror:} ${CWARNFLAGS}
LINTFLAGS+=	${DESTDIR:D-d ${DESTDIR}/usr/include}

.if !defined(NOSSP) && (${USE_SSP:Uno} != "no") && (${BINDIR:Ux} != "/usr/mdec")
.   if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels / kern modules
.   endif
.   if !defined(COVERITY_TOP_CONFIG)
COPTS+=	-fstack-protector -Wstack-protector 

# GCC 4.8 on m68k erroneously does not protect functions with
# variables needing special alignement, see
#	http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59674
# (the underlying issue for sh and vax may be different, needs more
# investigation, symptoms are similar but for different sources)
# also true for GCC 5, assume GCC 6 too.
.	if "${ACTIVE_CC}" == "gcc" && \
     ( ${HAVE_GCC} == "5" || \
       ${HAVE_GCC} == "6" ) && \
     ( ${MACHINE_CPU} == "sh3" || \
       ${MACHINE_ARCH} == "vax" || \
       ${MACHINE_CPU} == "m68k" || \
       ${MACHINE_CPU} == "or1k" )
COPTS+=	-Wno-error=stack-protector 
.	endif

COPTS+=	${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :}
COPTS+=	${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :}
.   endif

.if ${MKSOFTFLOAT:Uno} != "no"
# sh3 defaults to soft-float and specifies hard-float a different way
.if ${MACHINE_CPU} != "sh3"
COPTS+=		${${ACTIVE_CC} == "gcc":? -msoft-float :}
FOPTS+=		-msoft-float
.elif ${MACHINE_ARCH} == "coldfire"
COPTS+=		-mhard-float
FOPTS+=		-mhard-float

#.if !empty(MACHINE_ARCH:Mearmv7*)
#COPTS+=		-mthumb
#FOPTS+=		-mthumb

.if ${MKIEEEFP:Uno} != "no"
.if ${MACHINE_ARCH} == "alpha"
CFLAGS+=	-mieee
FFLAGS+=	-mieee

.if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
CFLAGS+=	-Wa,-Av8plus

.if !defined(NOGCCERROR)
.if (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
CPUFLAGS+=	-Wa,--fatal-warnings

#.if ${MACHINE} == "sbmips"
#CFLAGS+=	-mips64 -mtune=sb1

#.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \
#    (defined(MKPIC) && ${MKPIC} == "no")
#CPUFLAGS+=	-mno-abicalls -fno-PIC

.if !defined(NOPIE) && (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
# Position Independent Executable flags
PIE_CFLAGS?=        -fPIE
PIE_LDFLAGS?=       -pie ${${ACTIVE_CC} == "gcc":? -shared-libgcc :}

ELF2ECOFF?=	elf2ecoff
MKDEP?=		mkdep
MKDEPCXX?=	mkdep
OBJCOPY?=	objcopy
OBJDUMP?=	objdump
PAXCTL?=	paxctl
STRIP?=		strip

.SUFFIXES:	.o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h}

# C
.if defined(CTFCONVERT)

	    ${CPPFLAGS:C/-([IDU])[  ]*/-\1/Wg:M-[IDU]*} \
	    ${CPPFLAGS.${.IMPSRC:T}:C/-([IDU])[  ]*/-\1/Wg:M-[IDU]*} \
	    -i ${.IMPSRC}

# C++
.cc.o .cpp.o .cxx.o .C.o:

# Objective C
# (Defined here rather than in <sys.mk> because `.m' is not just
#  used for Objective C source)
.if defined(CTFCONVERT)

# Host-compiled C objects
# The intermediate step is necessary for Sun CC, which objects to calling
# object files anything but *.o
	mv ${.TARGET}.o ${.TARGET}

# C++
.cc.lo .cpp.lo .cxx.lo .C.lo:
	mv ${.TARGET}.o ${.TARGET}

# Assembly
.if defined(CTFCONVERT)

.if defined(CTFCONVERT)

# Lex

	${LEX.l} -o${.TARGET} ${.IMPSRC}

# Yacc

	${YACC.y} -o ${.TARGET} ${.IMPSRC}

.ifdef YHEADER
.if empty(.MAKEFLAGS:M-n)
.y.h: ${.TARGET:.h=.c}

# Objcopy
.if ${MACHINE_ARCH} == aarch64eb
# AARCH64 big endian needs to preserve $x/$d symbols for the linker.
OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][dx]' -K '[$$][dx]\.*'
.elif ${MACHINE_CPU} == "arm"
# ARM big endian needs to preserve $a/$d/$t symbols for the linker.
OBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][adt]' -K '[$$][adt]\.*'

.if ${MKSTRIPSYM:Uyes} == "yes"

.endif	# !defined(_BSD_SYS_MK_)