summaryrefslogtreecommitdiff
path: root/mk/cc.mk
blob: 9bfd123d61be6eb5eaf3ef112a08cdbf6d5d3b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright 2008 Roy Marples <roy@marples.name>

# Setup some good default CFLAGS

CFLAGS?=	-O2 -pipe

CSTD?=		c99
_CSTD_SH=	if test -n "${CSTD}"; then echo "-std=${CSTD}"; else echo ""; fi
_CSTD!=		${_CSTD_SH}
CFLAGS+=	${_CSTD}$(shell _CSTD_SH)

# GNU Make way of detecting gcc flags we can use
check_gcc=$(shell if ${CC} $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
	then echo "$(1)"; else echo "$(2)"; fi)

# pmake check for extra cflags 
WEXTRA!= for x in -Wdeclaration-after-statement -Wsequence-point -Wextra; do \
	if ${CC} $$x -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
	then echo -n "$$x "; fi \
	done

# Loads of nice flags to ensure our code is good
CFLAGS+=	-pedantic \
		-Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
		-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
		-Wbad-function-cast -Wnested-externs -Wcomment -Winline \
		-Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
		$(call check_gcc, -Wdeclaration-after-statement) \
		$(call check_gcc, -Wsequence-point) \
		$(call check_gcc, -Wextra) ${WEXTRA}