1 # $NetBSD: bsd.sys.mk,v 1.245 2014/09/03 19:22:53 matt Exp $
3 # Build definitions used for NetBSD source tree builds.
5 .if
!defined
(_BSD_SYS_MK_
)
8 .if
!empty
(.INCLUDEDFROMFILE
:MMakefile
*)
10 @
(echo
"bsd.sys.mk should not be included from Makefiles" >& 2; exit
1)
12 .if
!defined
(_BSD_OWN_MK_
)
14 @
(echo
"bsd.own.mk must be included before bsd.sys.mk" >& 2; exit
1)
18 #LSC: Be a bit smarter about the default compiler
19 .if exists
(/usr
/pkg
/bin
/clang
) || exists
(/usr
/bin
/clang
)
23 .if exists
(/usr
/pkg
/bin
/gcc
) || exists
(/usr
/bin
/gcc
)
27 MKDEP?
= CC
=${CC
:Q
} mkdep
28 MKDEPCXX?
= CC
=${CXX
:Q
} mkdep
29 .
endif # defined(__MINIX)
31 .if
${MKREPRO
:Uno
} == "yes"
32 CPPFLAGS
+= -Wp
,-iremap
,${NETBSDSRCDIR}:/usr
/src
33 CPPFLAGS
+= -Wp
,-iremap
,${DESTDIR}/:/
34 CPPFLAGS
+= -Wp
,-iremap
,${X11SRCDIR}:/usr
/xsrc
37 # NetBSD sources use C99 style, with some GCC extensions.
38 CFLAGS
+= ${${ACTIVE_CC} == "clang":?
-std
=gnu99
:}
39 CFLAGS
+= ${${ACTIVE_CC} == "gcc":?
-std
=gnu99
:}
40 CFLAGS
+= ${${ACTIVE_CC} == "pcc":?
-std
=gnu99
:}
43 CFLAGS
+= ${${ACTIVE_CC} == "clang":?
-Wno-sign-compare
-Wno-pointer-sign
:}
45 CFLAGS
+= -Wall
-Wstrict-prototypes
-Wmissing-prototypes
-Wpointer-arith
46 #CFLAGS+= -Wmissing-declarations -Wredundant-decls -Wnested-externs
47 # Add -Wno-sign-compare. -Wsign-compare is included in -Wall as of GCC 3.3,
48 # but our sources aren't up for it yet. Also, add -Wno-traditional because
49 # gcc includes #elif in the warnings, which is 'this code will not compile
50 # in a traditional environment' warning, as opposed to 'this code behaves
51 # differently in traditional and ansi environments' which is the warning
52 # we wanted, and now we don't get anymore.
53 CFLAGS
+= -Wno-sign-compare
54 CFLAGS
+= ${${ACTIVE_CC} == "gcc" :?
-Wno-traditional
:}
55 .if
!defined
(NOGCCERROR
) && !defined
(USE_BITCODE
)
56 # Set assembler warnings to be fatal
57 CFLAGS
+= -Wa
,--fatal-warnings
59 # Set linker warnings to be fatal
60 # XXX no proper way to avoid "FOO is a patented algorithm" warnings
61 # XXX on linking static libs
62 .if
(!defined
(MKPIC
) ||
${MKPIC} != "no") && \
63 (!defined
(LDSTATIC
) ||
${LDSTATIC} != "-static")
64 # XXX there are some strange problems not yet resolved
65 . if defined
(HAVE_LLVM
) && !defined
(USE_BITCODE
)
66 LDFLAGS
+= -Wl
,--fatal-warnings
71 CFLAGS
+= -Wreturn-type
-Wswitch
-Wshadow
74 CFLAGS
+= -Wcast-qual
-Wwrite-strings
75 CFLAGS
+= -Wextra
-Wno-unused-parameter
76 # Readd -Wno-sign-compare to override -Wextra with clang
77 CFLAGS
+= -Wno-sign-compare
79 CXXFLAGS
+= -Wold-style-cast
80 CXXFLAGS
+= -Wctor-dtor-privacy
-Wnon-virtual-dtor
-Wreorder \
81 -Wno-deprecated
-Woverloaded-virtual
-Wsign-promo
-Wsynth
82 CXXFLAGS
+= ${${ACTIVE_CXX} == "gcc":?
-Wno-non-template-friend
-Wno-pmf-conversions
:}
84 .if
${WARNS} > 3 && (defined
(HAVE_GCC
) || defined
(HAVE_LLVM
))
86 CFLAGS
+= -Wold-style-definition
88 .if
${WARNS} > 5 && !(defined
(HAVE_GCC
) && ${HAVE_GCC} <= 45)
91 CFLAGS
+= -Wsign-compare
-Wformat
=2
92 CFLAGS
+= ${${ACTIVE_CC} == "gcc":?
-Wno-format-zero-length
:}
94 .if
${WARNS} > 3 && defined
(HAVE_LLVM
)
95 CFLAGS
+= ${${ACTIVE_CC} == "clang":?
-Wpointer-sign
-Wmissing-noreturn
:}
97 .if
(defined
(HAVE_GCC
) \
98 && (${MACHINE_ARCH} == "coldfire" || \
99 ${MACHINE_ARCH} == "sh3eb" || \
100 ${MACHINE_ARCH} == "sh3el" || \
101 ${MACHINE_ARCH} == "m68k" || \
102 ${MACHINE_ARCH} == "m68000"))
103 # XXX GCC 4.5 for sh3 and m68k (which we compile with -Os) is extra noisy for
104 # cases it should be better with
105 CFLAGS
+= -Wno-uninitialized
106 .if
${HAVE_GCC} >= 48
107 CFLAGS
+= -Wno-maybe-uninitialized
112 CWARNFLAGS
+= ${CWARNFLAGS.
${ACTIVE_CC}}
114 CPPFLAGS
+= ${AUDIT
:D-D__AUDIT__
}
115 _NOWERROR
= ${defined
(NOGCCERROR
) ||
(${ACTIVE_CC} == "clang" && defined
(NOCLANGERROR
)):?yes
:no
}
116 .if defined
(__MINIX
) && ${USE_BITCODE
:Uno
} == "yes"
118 .
endif # defined(__MINIX) && ${USE_BITCODE} == "yes"
119 CFLAGS
+= ${${_NOWERROR} == "no" :?
-Werror
:} ${CWARNFLAGS}
120 LINTFLAGS
+= ${DESTDIR
:D-d
${DESTDIR}/usr
/include}
122 .if
(${USE_SSP
:Uno
} != "no") && (${BINDIR
:Ux
} != "/usr/mdec")
123 .if
!defined
(KERNSRCDIR
) && !defined
(KERN
) # not for kernels nor kern modules
124 CPPFLAGS
+= -D_FORTIFY_SOURCE
=2
126 COPTS
+= -fstack-protector
-Wstack-protector
128 # gcc 4.8 on m68k erroneously does not protect functions with
129 # variables needing special alignement, see
130 # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59674
131 # (the underlying issue for sh and vax may be different, needs more
132 # investigation, symptoms are similar but for different sources)
133 .if
"${ACTIVE_CC}" == "gcc" && "${HAVE_GCC}" == "48" && \
134 ( ${MACHINE_CPU} == "sh3" || \
135 ${MACHINE_ARCH} == "vax" || \
136 ${MACHINE_CPU} == "m68k" || \
137 ${MACHINE_CPU} == "or1k" )
138 COPTS
+= -Wno-error
=stack-protector
141 COPTS
+= ${${ACTIVE_CC} == "clang":?
--param ssp-buffer-size
=1 :}
142 COPTS
+= ${${ACTIVE_CC} == "gcc":?
--param ssp-buffer-size
=1 :}
145 .if
${MKSOFTFLOAT
:Uno
} != "no"
146 COPTS
+= ${${ACTIVE_CC} == "gcc":?
-msoft-float
:}
148 .elif
${MACHINE_ARCH} == "coldfire"
153 .if
${MKIEEEFP
:Uno
} != "no"
154 .if
${MACHINE_ARCH} == "alpha"
160 .if
${MACHINE} == "sparc64" && ${MACHINE_ARCH} == "sparc"
161 CFLAGS
+= -Wa
,-Av8plus
164 .if
!defined
(NOGCCERROR
)
165 .if
(${MACHINE_ARCH} == "mips64el") ||
(${MACHINE_ARCH} == "mips64eb")
166 CPUFLAGS
+= -Wa
,--fatal-warnings
170 #.if ${MACHINE} == "sbmips"
171 #CFLAGS+= -mips64 -mtune=sb1
174 #.if (${MACHINE_ARCH} == "mips64el" || ${MACHINE_ARCH} == "mips64eb") && \
175 # (defined(MKPIC) && ${MKPIC} == "no")
176 #CPUFLAGS+= -mno-abicalls -fno-PIC
181 .if
!defined
(LDSTATIC
) ||
${LDSTATIC} != "-static"
182 # Position Independent Executable flags
184 PIE_LDFLAGS?
= -Wl
,-pie
${${ACTIVE_CC} == "gcc":?
-shared-libgcc
:}
188 ELF2ECOFF?
= elf2ecoff
196 .SUFFIXES
: .o .ln .lo .c .
cc .
cpp .
cxx .C .m
${YHEADER
:D.h
}
201 ${COMPILE.c
} ${COPTS.
${.IMPSRC
:T
}} ${CPUFLAGS.
${.IMPSRC
:T
}} ${CPPFLAGS.
${.IMPSRC
:T
}} ${.IMPSRC
}
202 .if defined
(CTFCONVERT
)
203 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET
}
208 ${LINT} ${LINTFLAGS} ${LINTFLAGS.
${.IMPSRC
:T
}} \
209 ${CPPFLAGS
:C
/-([IDU
])[ ]*/-\
1/Wg
:M-
[IDU
]*} \
210 ${CPPFLAGS.
${.IMPSRC
:T
}:C
/-([IDU
])[ ]*/-\
1/Wg
:M-
[IDU
]*} \
214 .
cc.o .
cpp.o .
cxx.o .C.o
:
216 ${COMPILE.
cc} ${COPTS.
${.IMPSRC
:T
}} ${CPUFLAGS.
${.IMPSRC
:T
}} ${CPPFLAGS.
${.IMPSRC
:T
}} ${.IMPSRC
}
219 # (Defined here rather than in <sys.mk> because `.m' is not just
220 # used for Objective C source)
223 ${COMPILE.m
} ${OBJCOPTS} ${OBJCOPTS.
${.IMPSRC
:T
}} ${.IMPSRC
}
224 .if defined
(CTFCONVERT
)
225 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET
}
228 # Host-compiled C objects
229 # The intermediate step is necessary for Sun CC, which objects to calling
230 # object files anything but *.o
233 ${HOST_COMPILE.c
} -o
${.TARGET
}.o
${COPTS.
${.IMPSRC
:T
}} ${CPUFLAGS.
${.IMPSRC
:T
}} ${CPPFLAGS.
${.IMPSRC
:T
}} ${.IMPSRC
}
234 mv
${.TARGET
}.o
${.TARGET
}
237 .
cc.lo .
cpp.lo .
cxx.lo .C.lo
:
239 ${HOST_COMPILE.
cc} -o
${.TARGET
}.o
${COPTS.
${.IMPSRC
:T
}} ${CPUFLAGS.
${.IMPSRC
:T
}} ${CPPFLAGS.
${.IMPSRC
:T
}} ${.IMPSRC
}
240 mv
${.TARGET
}.o
${.TARGET
}
245 ${COMPILE.s
} ${COPTS.
${.IMPSRC
:T
}} ${CPUFLAGS.
${.IMPSRC
:T
}} ${CPPFLAGS.
${.IMPSRC
:T
}} ${.IMPSRC
}
246 .if defined
(CTFCONVERT
)
247 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET
}
252 ${COMPILE.S
} ${COPTS.
${.IMPSRC
:T
}} ${CPUFLAGS.
${.IMPSRC
:T
}} ${CPPFLAGS.
${.IMPSRC
:T
}} ${.IMPSRC
}
253 .if defined
(CTFCONVERT
)
254 ${CTFCONVERT} ${CTFFLAGS} ${.TARGET
}
258 LFLAGS
+= ${LPREFIX.
${.IMPSRC
:T
}:D-P
${LPREFIX.
${.IMPSRC
:T
}}}
259 LFLAGS
+= ${LPREFIX
:D-P
${LPREFIX}}
263 ${LEX.l
} -o
${.TARGET
} ${.IMPSRC
}
266 YFLAGS
+= ${YPREFIX.
${.IMPSRC
:T
}:D-p
${YPREFIX.
${.IMPSRC
:T
}}} ${YHEADER.
${.IMPSRC
:T
}:D-d
}
267 YFLAGS
+= ${YPREFIX
:D-p
${YPREFIX}} ${YHEADER
:D-d
}
271 ${YACC.y
} -o
${.TARGET
} ${.IMPSRC
}
274 .if empty
(.MAKEFLAGS
:M-n
)
275 .y.h
: ${.TARGET
:.h
=.c
}
280 .if
${MACHINE_ARCH} == aarch64eb
281 # AARCH64 big endian needs to preserve $x/$d symbols for the linker.
282 OBJCOPYLIBFLAGS_EXTRA
=-w
-K
'[$$][dx]' -K
'[$$][dx]\.*'
283 .elif
!empty
(MACHINE_ARCH
:M
*arm
*eb
)
284 # ARM big endian needs to preserve $a/$d/$t symbols for the linker.
285 OBJCOPYLIBFLAGS_EXTRA
=-w
-K
'[$$][adt]' -K
'[$$][adt]\.*'
287 OBJCOPYLIBFLAGS?
=${"${.TARGET:M*.po}" != "":?
-X
:-x
} ${OBJCOPYLIBFLAGS_EXTRA}
289 .
endif # !defined(_BSD_SYS_MK_)