diff options
Diffstat (limited to 'build/flags.mk')
-rw-r--r-- | build/flags.mk | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/build/flags.mk b/build/flags.mk index c50b077..2562e03 100644 --- a/build/flags.mk +++ b/build/flags.mk @@ -7,19 +7,7 @@ include build/prelude.mk include gen/vars.mk # Internal flags -_CPPFLAGS := \ - -Isrc \ - -Igen \ - -D__EXTENSIONS__ \ - -D_ATFILE_SOURCE \ - -D_BSD_SOURCE \ - -D_DARWIN_C_SOURCE \ - -D_DEFAULT_SOURCE \ - -D_GNU_SOURCE \ - -D_POSIX_PTHREAD_SEMANTICS \ - -D_FILE_OFFSET_BITS=64 \ - -D_TIME_BITS=64 - +_CPPFLAGS := -Isrc -Igen -include src/prelude.h _CFLAGS := -std=c17 -pthread _LDFLAGS := _LDLIBS := @@ -41,10 +29,6 @@ _GCOV := ${TRUTHY,${GCOV}} _LINT := ${TRUTHY,${LINT}} _RELEASE := ${TRUTHY,${RELEASE}} -# https://github.com/google/sanitizers/issues/342 -TSAN_CPPFLAGS,y := -DBFS_USE_TARGET_CLONES=0 -_CPPFLAGS += ${TSAN_CPPFLAGS,${_TSAN}} - ASAN_CFLAGS,y := -fsanitize=address LSAN_CFLAGS,y := -fsanitize=leak MSAN_CFLAGS,y := -fsanitize=memory -fsanitize-memory-track-origins @@ -83,16 +67,7 @@ _CPPFLAGS += ${RELEASE_CPPFLAGS,${_RELEASE}} _CFLAGS += ${RELEASE_CFLAGS,${_RELEASE}} # Configurable flags -CFLAGS ?= \ - -g \ - -Wall \ - -Wformat=2 \ - -Werror=implicit \ - -Wimplicit-fallthrough \ - -Wmissing-declarations \ - -Wshadow \ - -Wsign-compare \ - -Wstrict-prototypes +CFLAGS ?= -g -Wall # Add the configurable flags last so they can override ours _CPPFLAGS += ${CPPFLAGS} ${EXTRA_CPPFLAGS} @@ -103,7 +78,21 @@ _LDLIBS := ${LDLIBS} ${EXTRA_LDLIBS} ${_LDLIBS} include build/exports.mk -gen/flags.mk:: +# Conditionally-supported flags +AUTO_FLAGS := \ + gen/flags/Wformat.mk \ + gen/flags/Wimplicit-fallthrough.mk \ + gen/flags/Wimplicit.mk \ + gen/flags/Wmissing-decls.mk \ + gen/flags/Wmissing-var-decls.mk \ + gen/flags/Wshadow.mk \ + gen/flags/Wsign-compare.mk \ + gen/flags/Wstrict-prototypes.mk \ + gen/flags/Wundef-prefix.mk \ + gen/flags/bind-now.mk \ + gen/flags/deps.mk + +gen/flags.mk: ${AUTO_FLAGS} ${MSG} "[ GEN] $@" @printf '# %s\n' "$@" >$@ @printf '_CPPFLAGS := %s\n' "$$XCPPFLAGS" >>$@ @@ -112,4 +101,27 @@ gen/flags.mk:: @printf '_LDLIBS := %s\n' "$$XLDLIBS" >>$@ @printf 'NOLIBS := %s\n' "$$XNOLIBS" >>$@ @test "${OS}-${SAN}" != FreeBSD-y || printf 'POSTLINK = elfctl -e +noaslr $$@\n' >>$@ + @cat ${.ALLSRC} >>$@ + @cat ${.ALLSRC:%=%.log} >gen/flags.log ${VCAT} $@ +.PHONY: gen/flags.mk + +# Check that the C compiler works at all +cc:: + @build/cc.sh -q build/empty.c -o gen/.cc.out; \ + ret=$$?; \ + build/msg-if.sh "[ CC ] build/empty.c" test $$ret -eq 0; \ + exit $$ret + +# The short name of the config test +SLUG = ${@:gen/%.mk=%} +# The source file to build +CSRC = build/${SLUG}.c +# The hidden output file name +OUT = ${SLUG:flags/%=gen/flags/.%.out} + +${AUTO_FLAGS}: cc + @${MKDIR} ${@D} + @build/flags-if.sh ${CSRC} -o ${OUT} >$@ 2>$@.log; \ + build/msg-if.sh "[ CC ] ${SLUG}.c" test $$? -eq 0 +.PHONY: ${AUTO_FLAGS} |