xref: /netbsd/share/mk/bsd.sys.mk (revision 6550d01e)
1#	$NetBSD: bsd.sys.mk,v 1.193 2010/12/25 18:56:45 joerg Exp $
2#
3# Build definitions used for NetBSD source tree builds.
4
5.if !defined(_BSD_SYS_MK_)
6_BSD_SYS_MK_=1
7
8.if ${MKREPRO:Uno} == "yes"
9CPPFLAGS+=	-Wp,-iremap,${NETBSDSRCDIR}:/usr/src
10CPPFLAGS+=	-Wp,-iremap,${DESTDIR}/:/
11.endif
12
13.if defined(WARNS)
14.if ${WARNS} > 0
15CFLAGS+=	-Wall -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith
16#CFLAGS+=	-Wmissing-declarations -Wredundant-decls -Wnested-externs
17# Add -Wno-sign-compare.  -Wsign-compare is included in -Wall as of GCC 3.3,
18# but our sources aren't up for it yet. Also, add -Wno-traditional because
19# gcc includes #elif in the warnings, which is 'this code will not compile
20# in a traditional environment' warning, as opposed to 'this code behaves
21# differently in traditional and ansi environments' which is the warning
22# we wanted, and now we don't get anymore.
23CFLAGS+=	-Wno-sign-compare -Wno-traditional
24.if !defined(NOGCCERROR)
25# Set assembler warnings to be fatal
26CFLAGS+=	-Wa,--fatal-warnings
27.endif
28# Set linker warnings to be fatal
29# XXX no proper way to avoid "FOO is a patented algorithm" warnings
30# XXX on linking static libs
31.if (!defined(MKPIC) || ${MKPIC} != "no") && \
32    (!defined(LDSTATIC) || ${LDSTATIC} != "-static")
33LDFLAGS+=	-Wl,--fatal-warnings
34.endif
35.endif
36.if ${WARNS} > 1
37CFLAGS+=	-Wreturn-type -Wswitch -Wshadow
38.endif
39.if ${WARNS} > 2
40CFLAGS+=	-Wcast-qual -Wwrite-strings
41CFLAGS+=	-Wextra -Wno-unused-parameter
42CXXFLAGS+=	-Wabi
43CXXFLAGS+=	-Wold-style-cast
44CXXFLAGS+=	-Wctor-dtor-privacy -Wnon-virtual-dtor -Wreorder \
45		-Wno-deprecated -Wno-non-template-friend \
46		-Woverloaded-virtual -Wno-pmf-conversions -Wsign-promo -Wsynth
47.endif
48.if ${WARNS} > 3 && defined(HAVE_GCC) && ${HAVE_GCC} >= 3
49CFLAGS+=	-Wsign-compare
50CFLAGS+=	-std=gnu99
51.endif
52.endif
53
54CPPFLAGS+=	${AUDIT:D-D__AUDIT__}
55CFLAGS+=	${CWARNFLAGS} ${NOGCCERROR:D:U-Werror}
56LINTFLAGS+=	${DESTDIR:D-d ${DESTDIR}/usr/include}
57
58.if (${MACHINE_ARCH} == "alpha") || \
59    (${MACHINE_ARCH} == "hppa") || \
60    (${MACHINE_ARCH} == "ia64") || \
61    (${MACHINE_ARCH} == "mipsel") || (${MACHINE_ARCH} == "mipseb") || \
62    (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
63HAS_SSP=	no
64.else
65HAS_SSP=	yes
66.endif
67
68.if defined(USE_FORT) && (${USE_FORT} != "no")
69USE_SSP?=	yes
70.if !defined(KERNSRCDIR) && !defined(KERN) # not for kernels nor kern modules
71CPPFLAGS+=	-D_FORTIFY_SOURCE=2
72.endif
73.endif
74
75.if defined(USE_SSP) && (${USE_SSP} != "no") && (${BINDIR:Ux} != "/usr/mdec")
76.if ${HAS_SSP} == "yes"
77COPTS+=		-fstack-protector -Wstack-protector --param ssp-buffer-size=1
78.endif
79.endif
80
81.if defined(MKSOFTFLOAT) && (${MKSOFTFLOAT} != "no")
82COPTS+=		-msoft-float
83FOPTS+=		-msoft-float
84.endif
85
86.if defined(MKIEEEFP) && (${MKIEEEFP} != "no")
87.if ${MACHINE_ARCH} == "alpha"
88CFLAGS+=	-mieee
89FFLAGS+=	-mieee
90.endif
91.endif
92
93.if ${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
94CFLAGS+=	-Wa,-Av8plus
95.endif
96
97.if !defined(NOGCCERROR)
98.if (${MACHINE_ARCH} == "mips64el") || (${MACHINE_ARCH} == "mips64eb")
99CPUFLAGS+=	-Wa,--fatal-warnings
100.endif
101.endif
102
103#.if ${MACHINE} == "sbmips"
104#CFLAGS+=	-mips64 -mtune=sb1
105#.endif
106
107#.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \
108#    (defined(MKPIC) && ${MKPIC} == "no")
109#CPUFLAGS+=	-mno-abicalls -fno-PIC
110#.endif
111CFLAGS+=	${CPUFLAGS}
112AFLAGS+=	${CPUFLAGS}
113
114.if !defined(LDSTATIC) || ${LDSTATIC} != "-static"
115# Position Independent Executable flags
116PIE_CFLAGS?=        -fPIC -DPIC
117PIE_LDFLAGS?=       -Wl,-pie -shared-libgcc
118PIE_AFLAGS?=	    -fPIC -DPIC
119.endif
120
121# Helpers for cross-compiling
122HOST_CC?=	cc
123HOST_CFLAGS?=	-O
124HOST_COMPILE.c?=${HOST_CC} ${HOST_CFLAGS} ${HOST_CPPFLAGS} -c
125HOST_COMPILE.cc?=      ${HOST_CXX} ${HOST_CXXFLAGS} ${HOST_CPPFLAGS} -c
126.if defined(HOSTPROG_CXX)
127HOST_LINK.c?=	${HOST_CXX} ${HOST_CXXFLAGS} ${HOST_CPPFLAGS} ${HOST_LDFLAGS}
128.else
129HOST_LINK.c?=	${HOST_CC} ${HOST_CFLAGS} ${HOST_CPPFLAGS} ${HOST_LDFLAGS}
130.endif
131
132HOST_CXX?=	c++
133HOST_CXXFLAGS?=	-O
134
135HOST_CPP?=	cpp
136HOST_CPPFLAGS?=
137
138HOST_LD?=	ld
139HOST_LDFLAGS?=
140
141HOST_AR?=	ar
142HOST_RANLIB?=	ranlib
143
144HOST_LN?=	ln
145
146# HOST_SH must be an absolute path
147HOST_SH?=	/bin/sh
148
149ELF2ECOFF?=	elf2ecoff
150MKDEP?=		mkdep
151OBJCOPY?=	objcopy
152OBJDUMP?=	objdump
153PAXCTL?=	paxctl
154STRIP?=		strip
155
156# TOOL_* variables are defined in bsd.own.mk
157
158.SUFFIXES:	.o .ln .lo .c .cc .cpp .cxx .C .m ${YHEADER:D.h}
159
160# C
161.c.o:
162	${_MKTARGET_COMPILE}
163	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
164.if defined(CTFCONVERT)
165	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
166.endif
167
168.c.ln:
169	${_MKTARGET_COMPILE}
170	${LINT} ${LINTFLAGS} \
171	    ${CPPFLAGS:C/-([IDU])[  ]*/-\1/Wg:M-[IDU]*} \
172	    ${CPPFLAGS.${.IMPSRC:T}:C/-([IDU])[  ]*/-\1/Wg:M-[IDU]*} \
173	    -i ${.IMPSRC}
174
175# C++
176.cc.o .cpp.o .cxx.o .C.o:
177	${_MKTARGET_COMPILE}
178	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
179
180# Objective C
181# (Defined here rather than in <sys.mk> because `.m' is not just
182#  used for Objective C source)
183.m.o:
184	${_MKTARGET_COMPILE}
185	${COMPILE.m} ${OBJCOPTS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC}
186.if defined(CTFCONVERT)
187	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
188.endif
189
190# Host-compiled C objects
191# The intermediate step is necessary for Sun CC, which objects to calling
192# object files anything but *.o
193.c.lo:
194	${_MKTARGET_COMPILE}
195	${HOST_COMPILE.c} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
196	mv ${.TARGET}.o ${.TARGET}
197
198# C++
199.cc.lo .cpp.lo .cxx.lo .C.lo:
200	${_MKTARGET_COMPILE}
201	${HOST_COMPILE.cc} -o ${.TARGET}.o ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
202	mv ${.TARGET}.o ${.TARGET}
203
204# Assembly
205.s.o:
206	${_MKTARGET_COMPILE}
207	${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
208.if defined(CTFCONVERT)
209	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
210.endif
211
212.S.o:
213	${_MKTARGET_COMPILE}
214	${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC}
215.if defined(CTFCONVERT)
216	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
217.endif
218
219# Lex
220LFLAGS+=	${LPREFIX.${.IMPSRC:T}:D-P${LPREFIX.${.IMPSRC:T}}}
221LFLAGS+=	${LPREFIX:D-P${LPREFIX}}
222
223.l.c:
224	${_MKTARGET_LEX}
225	${LEX.l} -o${.TARGET} ${.IMPSRC}
226
227# Yacc
228YFLAGS+=	${YPREFIX.${.IMPSRC:T}:D-p${YPREFIX.${.IMPSRC:T}}} ${YHEADER.${.IMPSRC:T}:D-d}
229YFLAGS+=	${YPREFIX:D-p${YPREFIX}} ${YHEADER:D-d}
230
231.y.c:
232	${_MKTARGET_YACC}
233	${YACC.y} -o ${.TARGET} ${.IMPSRC}
234
235.ifdef YHEADER
236.if empty(.MAKEFLAGS:M-n)
237.y.h: ${.TARGET:.h=.c}
238.endif
239.endif
240
241.endif	# !defined(_BSD_SYS_MK_)
242