xref: /minix3/share/mk/bsd.sys.mk (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc#	$NetBSD: bsd.sys.mk,v 1.245 2014/09/03 19:22:53 matt Exp $
2e1091647SArun Thomas#
3e1091647SArun Thomas# Build definitions used for NetBSD source tree builds.
4e1091647SArun Thomas
59152e1c5SLionel Sambuc.if !defined(_BSD_SYS_MK_)
69152e1c5SLionel Sambuc_BSD_SYS_MK_=1
79152e1c5SLionel Sambuc
8*0a6a1f1dSLionel Sambuc.if !empty(.INCLUDEDFROMFILE:MMakefile*)
9*0a6a1f1dSLionel Sambucerror1:
10*0a6a1f1dSLionel Sambuc	@(echo "bsd.sys.mk should not be included from Makefiles" >& 2; exit 1)
11*0a6a1f1dSLionel Sambuc.endif
12*0a6a1f1dSLionel Sambuc.if !defined(_BSD_OWN_MK_)
13*0a6a1f1dSLionel Sambucerror2:
14*0a6a1f1dSLionel Sambuc	@(echo "bsd.own.mk must be included before bsd.sys.mk" >& 2; exit 1)
15*0a6a1f1dSLionel Sambuc.endif
16f1deff71SLionel Sambuc
17*0a6a1f1dSLionel Sambuc.if defined(__MINIX)
18f1deff71SLionel Sambuc#LSC: Be a bit smarter about the default compiler
19f1deff71SLionel Sambuc.if exists(/usr/pkg/bin/clang) || exists(/usr/bin/clang)
20*0a6a1f1dSLionel SambucCC?=	clang
21b8a678efSLionel Sambuc.endif
22b8a678efSLionel Sambuc
23f1deff71SLionel Sambuc.if exists(/usr/pkg/bin/gcc) || exists(/usr/bin/gcc)
24*0a6a1f1dSLionel SambucCC?=	gcc
25f1deff71SLionel Sambuc.endif
26*0a6a1f1dSLionel Sambuc
27*0a6a1f1dSLionel SambucMKDEP?= CC=${CC:Q} mkdep
28*0a6a1f1dSLionel SambucMKDEPCXX?= CC=${CXX:Q} mkdep
29*0a6a1f1dSLionel Sambuc.endif # defined(__MINIX)
30f1deff71SLionel Sambuc
319152e1c5SLionel Sambuc.if ${MKREPRO:Uno} == "yes"
329152e1c5SLionel SambucCPPFLAGS+=	-Wp,-iremap,${NETBSDSRCDIR}:/usr/src
339152e1c5SLionel SambucCPPFLAGS+=	-Wp,-iremap,${DESTDIR}/:/
349152e1c5SLionel SambucCPPFLAGS+=	-Wp,-iremap,${X11SRCDIR}:/usr/xsrc
359152e1c5SLionel Sambuc.endif
369152e1c5SLionel Sambuc
37*0a6a1f1dSLionel Sambuc# NetBSD sources use C99 style, with some GCC extensions.
38*0a6a1f1dSLionel SambucCFLAGS+=	${${ACTIVE_CC} == "clang":? -std=gnu99 :}
39*0a6a1f1dSLionel SambucCFLAGS+=	${${ACTIVE_CC} == "gcc":? -std=gnu99 :}
40*0a6a1f1dSLionel SambucCFLAGS+=	${${ACTIVE_CC} == "pcc":? -std=gnu99 :}
41e1091647SArun Thomas
42e1091647SArun Thomas.if defined(WARNS)
439152e1c5SLionel SambucCFLAGS+=	${${ACTIVE_CC} == "clang":? -Wno-sign-compare -Wno-pointer-sign :}
44e1091647SArun Thomas.if ${WARNS} > 0
45e1091647SArun ThomasCFLAGS+=	-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
46e1091647SArun Thomas#CFLAGS+=	-Wmissing-declarations -Wredundant-decls -Wnested-externs
47e1091647SArun Thomas# Add -Wno-sign-compare.  -Wsign-compare is included in -Wall as of GCC 3.3,
48e1091647SArun Thomas# but our sources aren't up for it yet. Also, add -Wno-traditional because
49e1091647SArun Thomas# gcc includes #elif in the warnings, which is 'this code will not compile
50e1091647SArun Thomas# in a traditional environment' warning, as opposed to 'this code behaves
51e1091647SArun Thomas# differently in traditional and ansi environments' which is the warning
52e1091647SArun Thomas# we wanted, and now we don't get anymore.
53230b7775SBen GrasCFLAGS+=	-Wno-sign-compare
54*0a6a1f1dSLionel SambucCFLAGS+=	${${ACTIVE_CC} == "gcc" :? -Wno-traditional :}
554684ddb6SLionel Sambuc.if !defined(NOGCCERROR) && !defined(USE_BITCODE)
56e1091647SArun Thomas# Set assembler warnings to be fatal
5784d9c625SLionel SambucCFLAGS+=	-Wa,--fatal-warnings
58e1091647SArun Thomas.endif
59e1091647SArun Thomas# Set linker warnings to be fatal
60e1091647SArun Thomas# XXX no proper way to avoid "FOO is a patented algorithm" warnings
61e1091647SArun Thomas# XXX on linking static libs
62e1091647SArun Thomas.if (!defined(MKPIC) || ${MKPIC} != "no") && \
639152e1c5SLionel Sambuc    (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
649152e1c5SLionel Sambuc# XXX there are some strange problems not yet resolved
65*0a6a1f1dSLionel Sambuc. if defined(HAVE_LLVM) && !defined(USE_BITCODE)
66e1091647SArun ThomasLDFLAGS+=	-Wl,--fatal-warnings
67e1091647SArun Thomas. endif
68e1091647SArun Thomas.endif
699152e1c5SLionel Sambuc.endif
70e1091647SArun Thomas.if ${WARNS} > 1
71e1091647SArun ThomasCFLAGS+=	-Wreturn-type -Wswitch -Wshadow
72e1091647SArun Thomas.endif
73e1091647SArun Thomas.if ${WARNS} > 2
74e1091647SArun ThomasCFLAGS+=	-Wcast-qual -Wwrite-strings
75e1091647SArun ThomasCFLAGS+=	-Wextra -Wno-unused-parameter
769152e1c5SLionel Sambuc# Readd -Wno-sign-compare to override -Wextra with clang
779152e1c5SLionel SambucCFLAGS+=	-Wno-sign-compare
78e1091647SArun ThomasCXXFLAGS+=	-Wabi
79e1091647SArun ThomasCXXFLAGS+=	-Wold-style-cast
80e1091647SArun ThomasCXXFLAGS+=	-Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \
819152e1c5SLionel Sambuc		-Wno-deprecated -Woverloaded-virtual -Wsign-promo -Wsynth
829152e1c5SLionel SambucCXXFLAGS+=	${${ACTIVE_CXX} == "gcc":? -Wno-non-template-friend -Wno-pmf-conversions :}
83e1091647SArun Thomas.endif
849152e1c5SLionel Sambuc.if ${WARNS} > 3 && (defined(HAVE_GCC) || defined(HAVE_LLVM))
859152e1c5SLionel Sambuc.if ${WARNS} > 4
869152e1c5SLionel SambucCFLAGS+=	-Wold-style-definition
879152e1c5SLionel Sambuc.endif
8884d9c625SLionel Sambuc.if ${WARNS} > 5 && !(defined(HAVE_GCC) && ${HAVE_GCC} <= 45)
8984d9c625SLionel SambucCFLAGS+=	-Wconversion
9084d9c625SLionel Sambuc.endif
919152e1c5SLionel SambucCFLAGS+=	-Wsign-compare -Wformat=2
929152e1c5SLionel SambucCFLAGS+=	${${ACTIVE_CC} == "gcc":? -Wno-format-zero-length :}
939152e1c5SLionel Sambuc.endif
949152e1c5SLionel Sambuc.if ${WARNS} > 3 && defined(HAVE_LLVM)
959152e1c5SLionel SambucCFLAGS+=	${${ACTIVE_CC} == "clang":? -Wpointer-sign -Wmissing-noreturn :}
969152e1c5SLionel Sambuc.endif
97*0a6a1f1dSLionel Sambuc.if (defined(HAVE_GCC) \
9884d9c625SLionel Sambuc     && (${MACHINE_ARCH} == "coldfire" || \
9984d9c625SLionel Sambuc	 ${MACHINE_ARCH} == "sh3eb" || \
1009152e1c5SLionel Sambuc	 ${MACHINE_ARCH} == "sh3el" || \
1019152e1c5SLionel Sambuc	 ${MACHINE_ARCH} == "m68k" || \
1029152e1c5SLionel Sambuc	 ${MACHINE_ARCH} == "m68000"))
1039152e1c5SLionel Sambuc# XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for
1049152e1c5SLionel Sambuc# cases it should be better with
1059152e1c5SLionel SambucCFLAGS+=	-Wno-uninitialized
10684d9c625SLionel Sambuc.if ${HAVE_GCC} >= 48
10784d9c625SLionel SambucCFLAGS+=	-Wno-maybe-uninitialized
10884d9c625SLionel Sambuc.endif
109e1091647SArun Thomas.endif
110e1091647SArun Thomas.endif
111e1091647SArun Thomas
1129152e1c5SLionel SambucCWARNFLAGS+=	${CWARNFLAGS.${ACTIVE_CC}}
1139152e1c5SLionel Sambuc
1149152e1c5SLionel SambucCPPFLAGS+=	${AUDIT:D-D__AUDIT__}
1159152e1c5SLionel Sambuc_NOWERROR=	${defined(NOGCCERROR) || (${ACTIVE_CC} == "clang" && defined(NOCLANGERROR)):?yes:no}
1164684ddb6SLionel Sambuc.if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
1174684ddb6SLionel Sambuc_NOWERROR=	yes
1184684ddb6SLionel Sambuc.endif # defined(__MINIX) && ${USE_BITCODE} == "yes"
1199152e1c5SLionel SambucCFLAGS+=	${${_NOWERROR} == "no" :?-Werror:} ${CWARNFLAGS}
1209152e1c5SLionel SambucLINTFLAGS+=	${DESTDIR:D-d ${DESTDIR}/usr/include}
121e1091647SArun Thomas
12284d9c625SLionel Sambuc.if (${USE_SSP:Uno} != "no") && (${BINDIR:Ux} != "/usr/mdec")
123e1091647SArun Thomas.if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels nor kern modules
124e1091647SArun ThomasCPPFLAGS+=	-D_FORTIFY_SOURCE=2
125e1091647SArun Thomas.endif
1269152e1c5SLionel SambucCOPTS+=	-fstack-protector -Wstack-protector
127*0a6a1f1dSLionel Sambuc
128*0a6a1f1dSLionel Sambuc# gcc 4.8 on m68k erroneously does not protect functions with
129*0a6a1f1dSLionel Sambuc# variables needing special alignement, see
130*0a6a1f1dSLionel Sambuc#	http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59674
131*0a6a1f1dSLionel Sambuc# (the underlying issue for sh and vax may be different, needs more
132*0a6a1f1dSLionel Sambuc# investigation, symptoms are similar but for different sources)
133*0a6a1f1dSLionel Sambuc.if "${ACTIVE_CC}" == "gcc" && "${HAVE_GCC}" == "48" && \
134*0a6a1f1dSLionel Sambuc	( ${MACHINE_CPU} == "sh3" || \
135*0a6a1f1dSLionel Sambuc	  ${MACHINE_ARCH} == "vax" || \
136*0a6a1f1dSLionel Sambuc	  ${MACHINE_CPU} == "m68k" || \
137*0a6a1f1dSLionel Sambuc	  ${MACHINE_CPU} == "or1k" )
138*0a6a1f1dSLionel SambucCOPTS+=	-Wno-error=stack-protector
139*0a6a1f1dSLionel Sambuc.endif
140*0a6a1f1dSLionel Sambuc
141b8a678efSLionel SambucCOPTS+=	${${ACTIVE_CC} == "clang":? --param ssp-buffer-size=1 :}
1429152e1c5SLionel SambucCOPTS+=	${${ACTIVE_CC} == "gcc":? --param ssp-buffer-size=1 :}
143e1091647SArun Thomas.endif
144e1091647SArun Thomas
1459152e1c5SLionel Sambuc.if ${MKSOFTFLOAT:Uno} != "no"
146*0a6a1f1dSLionel SambucCOPTS+=		${${ACTIVE_CC} == "gcc":? -msoft-float :}
147e1091647SArun ThomasFOPTS+=		-msoft-float
14884d9c625SLionel Sambuc.elif ${MACHINE_ARCH} == "coldfire"
14984d9c625SLionel SambucCOPTS+=		-mhard-float
15084d9c625SLionel SambucFOPTS+=		-mhard-float
151e1091647SArun Thomas.endif
152e1091647SArun Thomas
1539152e1c5SLionel Sambuc.if ${MKIEEEFP:Uno} != "no"
154e1091647SArun Thomas.if ${MACHINE_ARCH} == "alpha"
155e1091647SArun ThomasCFLAGS+=	-mieee
156e1091647SArun ThomasFFLAGS+=	-mieee
157e1091647SArun Thomas.endif
158e1091647SArun Thomas.endif
159e1091647SArun Thomas
160e1091647SArun Thomas.if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
161e1091647SArun ThomasCFLAGS+=	-Wa,-Av8plus
162e1091647SArun Thomas.endif
163e1091647SArun Thomas
1649152e1c5SLionel Sambuc.if !defined(NOGCCERROR)
1659152e1c5SLionel Sambuc.if (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
1669152e1c5SLionel SambucCPUFLAGS+=	-Wa,--fatal-warnings
1679152e1c5SLionel Sambuc.endif
1689152e1c5SLionel Sambuc.endif
1699152e1c5SLionel Sambuc
1709152e1c5SLionel Sambuc#.if ${MACHINE} == "sbmips"
1719152e1c5SLionel Sambuc#CFLAGS+=	-mips64 -mtune=sb1
1729152e1c5SLionel Sambuc#.endif
1739152e1c5SLionel Sambuc
1749152e1c5SLionel Sambuc#.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \
1759152e1c5SLionel Sambuc#    (defined(MKPIC) && ${MKPIC} == "no")
1769152e1c5SLionel Sambuc#CPUFLAGS+=	-mno-abicalls -fno-PIC
1779152e1c5SLionel Sambuc#.endif
178e1091647SArun ThomasCFLAGS+=	${CPUFLAGS}
179e1091647SArun ThomasAFLAGS+=	${CPUFLAGS}
180e1091647SArun Thomas
1819152e1c5SLionel Sambuc.if !defined(LDSTATIC) || ${LDSTATIC} != "-static"
182e1091647SArun Thomas# Position Independent Executable flags
18384d9c625SLionel SambucPIE_CFLAGS?=        -fPIC
184*0a6a1f1dSLionel SambucPIE_LDFLAGS?=       -Wl,-pie ${${ACTIVE_CC} == "gcc":? -shared-libgcc :}
18584d9c625SLionel SambucPIE_AFLAGS?=	    -fPIC
1869152e1c5SLionel Sambuc.endif
187e1091647SArun Thomas
188e1091647SArun ThomasELF2ECOFF?=	elf2ecoff
189*0a6a1f1dSLionel SambucMKDEP?=		mkdep
190*0a6a1f1dSLionel SambucMKDEPCXX?=	mkdep
191e1091647SArun ThomasOBJCOPY?=	objcopy
192e1091647SArun ThomasOBJDUMP?=	objdump
193e1091647SArun ThomasPAXCTL?=	paxctl
194e1091647SArun ThomasSTRIP?=		strip
195e1091647SArun Thomas
196e1091647SArun Thomas.SUFFIXES:	.o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h}
197e1091647SArun Thomas
198e1091647SArun Thomas# C
199e1091647SArun Thomas.c.o:
200e1091647SArun Thomas	${_MKTARGET_COMPILE}
201e1091647SArun Thomas	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
2029152e1c5SLionel Sambuc.if defined(CTFCONVERT)
2039152e1c5SLionel Sambuc	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
2049152e1c5SLionel Sambuc.endif
205e1091647SArun Thomas
206e1091647SArun Thomas.c.ln:
207e1091647SArun Thomas	${_MKTARGET_COMPILE}
2089152e1c5SLionel Sambuc	${LINT} ${LINTFLAGS} ${LINTFLAGS.${.IMPSRC:T}} \
209e1091647SArun Thomas	    ${CPPFLAGS:C/-([IDU])[  ]*/-\1/Wg:M-[IDU]*} \
210e1091647SArun Thomas	    ${CPPFLAGS.${.IMPSRC:T}:C/-([IDU])[  ]*/-\1/Wg:M-[IDU]*} \
211e1091647SArun Thomas	    -i ${.IMPSRC}
212e1091647SArun Thomas
213e1091647SArun Thomas# C++
214e1091647SArun Thomas.cc.o .cpp.o .cxx.o .C.o:
215e1091647SArun Thomas	${_MKTARGET_COMPILE}
216e1091647SArun Thomas	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
217e1091647SArun Thomas
218e1091647SArun Thomas# Objective C
219e1091647SArun Thomas# (Defined here rather than in <sys.mk> because `.m' is not just
220e1091647SArun Thomas#  used for Objective C source)
221e1091647SArun Thomas.m.o:
222e1091647SArun Thomas	${_MKTARGET_COMPILE}
223e1091647SArun Thomas	${COMPILE.m} ${OBJCOPTS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC}
2249152e1c5SLionel Sambuc.if defined(CTFCONVERT)
2259152e1c5SLionel Sambuc	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
2269152e1c5SLionel Sambuc.endif
227e1091647SArun Thomas
228e1091647SArun Thomas# Host-compiled C objects
229e1091647SArun Thomas# The intermediate step is necessary for Sun CC, which objects to calling
230e1091647SArun Thomas# object files anything but *.o
231e1091647SArun Thomas.c.lo:
232e1091647SArun Thomas	${_MKTARGET_COMPILE}
233e1091647SArun Thomas	${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
234e1091647SArun Thomas	mv ${.TARGET}.o ${.TARGET}
235e1091647SArun Thomas
236e1091647SArun Thomas# C++
237e1091647SArun Thomas.cc.lo .cpp.lo .cxx.lo .C.lo:
238e1091647SArun Thomas	${_MKTARGET_COMPILE}
239e1091647SArun Thomas	${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
240e1091647SArun Thomas	mv ${.TARGET}.o ${.TARGET}
241e1091647SArun Thomas
242e1091647SArun Thomas# Assembly
243e1091647SArun Thomas.s.o:
244e1091647SArun Thomas	${_MKTARGET_COMPILE}
245e1091647SArun Thomas	${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
2469152e1c5SLionel Sambuc.if defined(CTFCONVERT)
2479152e1c5SLionel Sambuc	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
2489152e1c5SLionel Sambuc.endif
249e1091647SArun Thomas
250e1091647SArun Thomas.S.o:
251e1091647SArun Thomas	${_MKTARGET_COMPILE}
252e1091647SArun Thomas	${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
2539152e1c5SLionel Sambuc.if defined(CTFCONVERT)
2549152e1c5SLionel Sambuc	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
2559152e1c5SLionel Sambuc.endif
256e1091647SArun Thomas
257e1091647SArun Thomas# Lex
258e1091647SArun ThomasLFLAGS+=	${LPREFIX.${.IMPSRC:T}:D-P${LPREFIX.${.IMPSRC:T}}}
259e1091647SArun ThomasLFLAGS+=	${LPREFIX:D-P${LPREFIX}}
260e1091647SArun Thomas
261e1091647SArun Thomas.l.c:
262e1091647SArun Thomas	${_MKTARGET_LEX}
263e1091647SArun Thomas	${LEX.l} -o${.TARGET} ${.IMPSRC}
264e1091647SArun Thomas
265e1091647SArun Thomas# Yacc
266e1091647SArun ThomasYFLAGS+=	${YPREFIX.${.IMPSRC:T}:D-p${YPREFIX.${.IMPSRC:T}}} ${YHEADER.${.IMPSRC:T}:D-d}
267e1091647SArun ThomasYFLAGS+=	${YPREFIX:D-p${YPREFIX}} ${YHEADER:D-d}
268e1091647SArun Thomas
269e1091647SArun Thomas.y.c:
270e1091647SArun Thomas	${_MKTARGET_YACC}
271e1091647SArun Thomas	${YACC.y} -o ${.TARGET} ${.IMPSRC}
272e1091647SArun Thomas
273e1091647SArun Thomas.ifdef YHEADER
2749152e1c5SLionel Sambuc.if empty(.MAKEFLAGS:M-n)
275e1091647SArun Thomas.y.h: ${.TARGET:.h=.c}
276e1091647SArun Thomas.endif
2779152e1c5SLionel Sambuc.endif
278e1091647SArun Thomas
2799152e1c5SLionel Sambuc# Objcopy
280*0a6a1f1dSLionel Sambuc.if ${MACHINE_ARCH} == aarch64eb
281*0a6a1f1dSLionel Sambuc# AARCH64 big endian needs to preserve $x/$d symbols for the linker.
282*0a6a1f1dSLionel SambucOBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][dx]' -K '[$$][dx]\.*'
283*0a6a1f1dSLionel Sambuc.elif !empty(MACHINE_ARCH:M*arm*eb)
284*0a6a1f1dSLionel Sambuc# ARM big endian needs to preserve $a/$d/$t symbols for the linker.
285*0a6a1f1dSLionel SambucOBJCOPYLIBFLAGS_EXTRA=-w -K '[$$][adt]' -K '[$$][adt]\.*'
286*0a6a1f1dSLionel Sambuc.endif
287*0a6a1f1dSLionel SambucOBJCOPYLIBFLAGS?=${"${.TARGET:M*.po}" != "":?-X:-x} ${OBJCOPYLIBFLAGS_EXTRA}
2889152e1c5SLionel Sambuc
2899152e1c5SLionel Sambuc.endif	# !defined(_BSD_SYS_MK_)
290