1# Copyright 2008 Roy Marples <roy@marples.name>
2
3# Setup some good default CFLAGS
4CFLAGS?=	-Os
5
6# Default to using the C99 standard
7CSTD?=		c99
8_CSTD_SH=	if test -n "${CSTD}"; then echo "-std=${CSTD}"; else echo ""; fi
9_CSTD!=		${_CSTD_SH}
10CFLAGS+=	${_CSTD}$(shell ${_CSTD_SH})
11
12# Try and use some good cc flags if we're building from git
13_CCFLAGS=	-pedantic -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \
14		-Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings \
15		-Wbad-function-cast -Wnested-externs -Wcomment -Winline \
16		-Wchar-subscripts -Wcast-align -Wno-format-nonliteral \
17		-Wdeclaration-after-statement -Wsequence-point -Wextra
18_CC_FLAGS_SH=	if ! test -d .git; then echo ""; else for f in ${_CCFLAGS}; do \
19		if ${CC} $$f -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
20		then printf "%s" "$$f "; fi \
21		done; fi
22_CC_FLAGS!=	${_CC_FLAGS_SH}
23CFLAGS+=	${_CC_FLAGS}$(shell ${_CC_FLAGS_SH})
24
25_GGDB_SH=	if test "${DEBUG}" = "yes"; then echo "-ggdb -DDEBUG"; else echo ""; fi
26_GGDB!=		${_GGDB_SH}
27GGDB=		${_GGDB}$(shell ${_GGDB_SH})
28CFLAGS+=	${GGDB}
29