diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-05-21 16:13:51 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-05-21 16:17:46 -0400 |
commit | a5149bd2d269a6ad538c9a8e9820a85b17449dda (patch) | |
tree | e4411acb9ce2544f5f4b1b6d8f1dcdd5cfc449fb /build | |
parent | 863370eb1e6cffedf30a7c673be863543194a915 (diff) | |
download | bfs-a5149bd2d269a6ad538c9a8e9820a85b17449dda.tar.xz |
build: Simplify flags.mk
Diffstat (limited to 'build')
-rw-r--r-- | build/flags.mk | 107 |
1 files changed, 43 insertions, 64 deletions
diff --git a/build/flags.mk b/build/flags.mk index fa793b8..c50b077 100644 --- a/build/flags.mk +++ b/build/flags.mk @@ -6,28 +6,8 @@ include build/prelude.mk include gen/vars.mk -# Configurable flags -CPPFLAGS ?= -CFLAGS ?= \ - -g \ - -Wall \ - -Wformat=2 \ - -Werror=implicit \ - -Wimplicit-fallthrough \ - -Wmissing-declarations \ - -Wshadow \ - -Wsign-compare \ - -Wstrict-prototypes -LDFLAGS ?= -LDLIBS ?= - -export XCPPFLAGS=${CPPFLAGS} -export XCFLAGS=${CFLAGS} -export XLDFLAGS=${LDFLAGS} -export XLDLIBS=${LDLIBS} - -# Immutable flags -export BFS_CPPFLAGS= \ +# Internal flags +_CPPFLAGS := \ -Isrc \ -Igen \ -D__EXTENSIONS__ \ @@ -39,14 +19,17 @@ export BFS_CPPFLAGS= \ -D_POSIX_PTHREAD_SEMANTICS \ -D_FILE_OFFSET_BITS=64 \ -D_TIME_BITS=64 -export BFS_CFLAGS= -std=c17 -pthread + +_CFLAGS := -std=c17 -pthread +_LDFLAGS := +_LDLIBS := # Platform-specific system libraries LDLIBS,DragonFly := -lposix1e LDLIBS,Linux := -lrt LDLIBS,NetBSD := -lutil LDLIBS,SunOS := -lsec -lsocket -lnsl -export BFS_LDLIBS=${LDLIBS,${OS}} +_LDLIBS += ${LDLIBS,${OS}} # Build profiles _ASAN := ${TRUTHY,${ASAN}} @@ -60,7 +43,7 @@ _RELEASE := ${TRUTHY,${RELEASE}} # https://github.com/google/sanitizers/issues/342 TSAN_CPPFLAGS,y := -DBFS_USE_TARGET_CLONES=0 -export TSAN_CPPFLAGS=${TSAN_CPPFLAGS,${_TSAN}} +_CPPFLAGS += ${TSAN_CPPFLAGS,${_TSAN}} ASAN_CFLAGS,y := -fsanitize=address LSAN_CFLAGS,y := -fsanitize=leak @@ -68,69 +51,65 @@ MSAN_CFLAGS,y := -fsanitize=memory -fsanitize-memory-track-origins TSAN_CFLAGS,y := -fsanitize=thread UBSAN_CFLAGS,y := -fsanitize=undefined -export ASAN_CFLAGS=${ASAN_CFLAGS,${_ASAN}} -export LSAN_CFLAGS=${LSAN_CFLAGS,${_LSAN}} -export MSAN_CFLAGS=${MSAN_CFLAGS,${_MSAN}} -export TSAN_CFLAGS=${TSAN_CFLAGS,${_TSAN}} -export UBSAN_CFLAGS=${UBSAN_CFLAGS,${_UBSAN}} +_CFLAGS += ${ASAN_CFLAGS,${_ASAN}} +_CFLAGS += ${LSAN_CFLAGS,${_LSAN}} +_CFLAGS += ${MSAN_CFLAGS,${_MSAN}} +_CFLAGS += ${TSAN_CFLAGS,${_TSAN}} +_CFLAGS += ${UBSAN_CFLAGS,${_UBSAN}} SAN_CFLAGS,y := -fno-sanitize-recover=all INSANE := ${NOT,${_ASAN}${_LSAN}${_MSAN}${_TSAN}${_UBSAN}} SAN := ${NOT,${INSANE}} -export SAN_CFLAGS=${SAN_CFLAGS,${SAN}} +_CFLAGS += ${SAN_CFLAGS,${SAN}} # MSAN and TSAN both need all code to be instrumented YESLIBS := ${NOT,${_MSAN}${_TSAN}} NOLIBS ?= ${NOT,${YESLIBS}} -export XNOLIBS=${NOLIBS} # gcov only intercepts fork()/exec() with -std=gnu* GCOV_CFLAGS,y := -std=gnu17 --coverage -export GCOV_CFLAGS=${GCOV_CFLAGS,${_GCOV}} +_CFLAGS += ${GCOV_CFLAGS,${_GCOV}} LINT_CPPFLAGS,y := -D_FORTIFY_SOURCE=3 -DBFS_LINT LINT_CFLAGS,y := -Werror -O2 -export LINT_CPPFLAGS=${LINT_CPPFLAGS,${_LINT}} -export LINT_CFLAGS=${LINT_CFLAGS,${_LINT}} +_CPPFLAGS += ${LINT_CPPFLAGS,${_LINT}} +_CFLAGS += ${LINT_CFLAGS,${_LINT}} RELEASE_CPPFLAGS,y := -DNDEBUG RELEASE_CFLAGS,y := -O3 -flto=auto -export RELEASE_CPPFLAGS=${RELEASE_CPPFLAGS,${_RELEASE}} -export RELEASE_CFLAGS=${RELEASE_CFLAGS,${_RELEASE}} +_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 -# Set a variable -SETVAR = @printf '%s := %s\n' >>$@ +# Add the configurable flags last so they can override ours +_CPPFLAGS += ${CPPFLAGS} ${EXTRA_CPPFLAGS} +_CFLAGS += ${CFLAGS} ${EXTRA_CFLAGS} +_LDFLAGS += ${LDFLAGS} ${EXTRA_LDFLAGS} +# (except LDLIBS, as earlier libs override later ones) +_LDLIBS := ${LDLIBS} ${EXTRA_LDLIBS} ${_LDLIBS} -# Append to a variable, if non-empty -APPEND = @append() { test -z "$$2" || printf '%s += %s\n' "$$1" "$$2" >>$@; }; append +include build/exports.mk gen/flags.mk:: ${MSG} "[ GEN] $@" @printf '# %s\n' "$@" >$@ - ${SETVAR} _CPPFLAGS "$$BFS_CPPFLAGS" - ${APPEND} _CPPFLAGS "$$TSAN_CPPFLAGS" - ${APPEND} _CPPFLAGS "$$LINT_CPPFLAGS" - ${APPEND} _CPPFLAGS "$$RELEASE_CPPFLAGS" - ${APPEND} _CPPFLAGS "$$XCPPFLAGS" - ${APPEND} _CPPFLAGS "$$EXTRA_CPPFLAGS" - ${SETVAR} _CFLAGS "$$BFS_CFLAGS" - ${APPEND} _CFLAGS "$$ASAN_CFLAGS" - ${APPEND} _CFLAGS "$$LSAN_CFLAGS" - ${APPEND} _CFLAGS "$$MSAN_CFLAGS" - ${APPEND} _CFLAGS "$$TSAN_CFLAGS" - ${APPEND} _CFLAGS "$$UBSAN_CFLAGS" - ${APPEND} _CFLAGS "$$SAN_CFLAGS" - ${APPEND} _CFLAGS "$$GCOV_CFLAGS" - ${APPEND} _CFLAGS "$$LINT_CFLAGS" - ${APPEND} _CFLAGS "$$RELEASE_CFLAGS" - ${APPEND} _CFLAGS "$$XCFLAGS" - ${APPEND} _CFLAGS "$$EXTRA_CFLAGS" - ${SETVAR} _LDFLAGS "$$XLDFLAGS" - ${SETVAR} _LDLIBS "$$XLDLIBS" - ${APPEND} _LDLIBS "$$EXTRA_LDLIBS" - ${APPEND} _LDLIBS "$$BFS_LDLIBS" - ${SETVAR} NOLIBS "$$XNOLIBS" + @printf '_CPPFLAGS := %s\n' "$$XCPPFLAGS" >>$@ + @printf '_CFLAGS := %s\n' "$$XCFLAGS" >>$@ + @printf '_LDFLAGS := %s\n' "$$XLDFLAGS" >>$@ + @printf '_LDLIBS := %s\n' "$$XLDLIBS" >>$@ + @printf 'NOLIBS := %s\n' "$$XNOLIBS" >>$@ @test "${OS}-${SAN}" != FreeBSD-y || printf 'POSTLINK = elfctl -e +noaslr $$@\n' >>$@ ${VCAT} $@ |