diff options
-rw-r--r-- | mk/cc.mk | 29 |
1 files changed, 11 insertions, 18 deletions
@@ -1,30 +1,23 @@ # Copyright 2008 Roy Marples <roy@marples.name> # Setup some good default CFLAGS +CFLAGS?= -O2 -CFLAGS?= -O2 -pipe - +# Default to using the C99 standard 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 \ +# Try and use some good cc flags +_CC_FLAGS= -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} + -Wdeclaration-after-statement -Wsequence-point -Wextra +_CC_FLAGS_SH= for f in ${_CC_FLAGS}; do \ + if ${CC} $$f -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ + then printf "%s" "$$f "; fi \ + done +_CC_FLAGS!= ${_CC_FLAGS_SH} +CFLAGS+= ${_CC_FLAGS}$(shell ${CC_FLAGS_SH}) |