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