From 9ba840a23fee98e0a8e3f2fcb6d284599d08545a Mon Sep 17 00:00:00 2001 From: SwuduSusuwu <2002luvabbaluvu@gmail.com> Date: Wed, 27 Nov 2024 16:23:24 -0800 Subject: [PATCH] -`CXXFLAGS_SPECIAL`, +`FLAGS_SPECIAL`: pass to both ?`build.sh`, ?`Macros.sh: -`CXXFLAGS_SPECIAL`, +`FLAGS_SPECIAL`; not specific to `CXX`. -`CXXFLAGS_ANALYSIS`, +`FLAGS_ANALYSIS`; not specific to `CXX`. Is followup to: commit 64ca540ecac7849d328e5dba22ab5372cee7acff (?build.sh:+CXX_FLAGS_ANALYSIS ,,,) ?`CXXFLAGS_DEBUG`; remove flags not specific to `CXX`. +`FLAGS_DEBUG`; pass to both `CC` and `CXX`. Is followup to: commit 87270381468265788bcbd0fd1fc9f7252c6174be (?`build.sh`:?`CXX_FLAGS_DEBUG` split in 2) -`CXXFLAGS_RELEASE`, +`FLAGS_RELEASE`; not specific to `CXX`. `:%s/CCFLAGS/CFLAGS/`; typo fix, now can inherit `CFLAGS` from environment of user. Is followup to: commit 4fef8640e695c8d42222599a9b3a45f356cc5526 (`:%s/_FLAGS/FLAGS/`: most projects do not include those underscores.), which should have fixes this. Assists with issue #21 (analogous `make` tools). ?`Macros.sh`: `SUSUWU_SETUP_BUILD_FLAGS()`: use `FLAGS_SPECIAL` Is followup to: commit 3ee82e4fbe4a6c5b663a34f2d7f299a9ad5d4a2b (... +`CXXFLAGS_SPECIAL`: For `README.md` flags. ?`CXXFLAGS`: Now includes `CXXFLAGS_SPECIAL`.), which forgot to include `CXXFLAGS_SPECIAL`. --- Macros.sh | 13 ++++++++----- build.sh | 14 +++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Macros.sh b/Macros.sh index 245e2733..027d6724 100755 --- a/Macros.sh +++ b/Macros.sh @@ -137,15 +137,18 @@ SUSUWU_SETUP_CXX() { #/* Usage: ... [SUSUWU_PROCESS_MINGW $@] SUSUWU_SETUP_CXX [ SUSUWU_PROCESS_RELEASE_DEBUG() { #/* Usage: `SUSUWU_PROCESS_RELEASE_DEBUG $@` [This processes params passed to `${0}`.] */ if [ "--release" = "${1}" -o "--release" = "${2}" ]; then SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "\`${0}${CROSS_COMP} --release\` does not support profilers/debuggers (use \`${0}${CROSS_COMP} --debug\` for this)." - CXXFLAGS="${CXXFLAGS} ${CXXFLAGS_RELEASE}" + CXXFLAGS="${CXXFLAGS} ${FLAGS_RELEASE} ${CXXFLAGS_RELEASE}" + CFLAGS="${CFLAGS} ${FLAGS_RELEASE} ${CFLAGS_RELEASE}" else if [ "--debug" != "${1}" ] && [ "--debug" != "${2}" ]; then SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "\`${0}${CROSS_COMP}\` defaults to \`${0}${CROSS_COMP} --debug\`." fi SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Use \`${0}${CROSS_COMP} --release\` to improve how fast this executes." - CXXFLAGS="${CXXFLAGS} ${CXXFLAGS_DEBUG}" + CXXFLAGS="${CXXFLAGS} ${FLAGS_DEBUG} ${CXXFLAGS_DEBUG}" + CFLAGS="${CFLAGS} ${FLAGS_DEBUG} ${CFLAGS_DEBUG}" if [ true = ${USE_FSAN} ]; then CXXFLAGS="${CXXFLAGS} ${FLAGS_FSAN}" + CFLAGS="${LDFLAGS} ${FLAGS_FSAN}" LDFLAGS="${LDFLAGS} ${FLAGS_FSAN}" export ASAN_OPTIONS=abort_on_error=1:fast_unwind_on_malloc=0:detect_leaks=0 UBSAN_OPTIONS=print_stacktrace=1 #/* "For LLDB/GDB and to prevent very short stack traces and usually false leaks detection" */ fi @@ -153,8 +156,8 @@ SUSUWU_PROCESS_RELEASE_DEBUG() { #/* Usage: `SUSUWU_PROCESS_RELEASE_DEBUG $@` [T } SUSUWU_SETUP_BUILD_FLAGS() { #/* Usage: ... [SUSUWU_PROCESS_MINGW $@] SUSUWU_SETUP_CXX [SUSUWU_PROCESS_RELEASE_DEBUG $@] SUSUWU_SETUP_BUILD_FLAGS SUSUWU_SETUP_BINDIR "" SUSUWU_SETUP_OBJDIR "" SUSUWU_SETUP_OUTPUT "" [SUSUWU_PROCESS_CLEAN_REBUILD $@] [SUSUWU_PROCESS_INCLUDES ""] SUSUWU_BUILD_SOURCES ... */ LDFLAGS="${LDFLAGS}" - CXXFLAGS="${CXXFLAGS} ${CXXFLAGS_ANALYSIS}" - CCFLAGS="${CCFLAGS} ${CXXFLAGS}" + CXXFLAGS="${CXXFLAGS} ${FLAGS_SPECIAL} ${FLAGS_ANALYSIS}" + CFLAGS="${CFLAGS} ${FLAGS_SPECIAL} ${FLAGS_ANALYSIS}" C_SOURCE_PATH=$(SUSUWU_DIR_SUFFIX_SLASH "${C_SOURCE_PATH}") #/* if inherit C_SOURCE_PATH, perhaps it lacks '/' */ CXX_SOURCE_PATH=$(SUSUWU_DIR_SUFFIX_SLASH "${CXX_SOURCE_PATH}") #/* if inherit CXX_SOURCE_PATH, perhaps it lacks '/' */ OBJECTLIST="" @@ -258,7 +261,7 @@ SUSUWU_BUILD_CTAGS() { #/* Usage: `SUSUWU_BUILD_CTAGS [-flags... --flags...] [SO fi return ${STATUS}; } -SUSUWU_BUILD_OBJECTS() { #/* Usage: `SUSUWU_BUILD_SOURCES [${CC} || ${CXX}] [${CCFLAGS} || ${CXXFLAGS}] ".cxx" ${CXX_SOURCE_PATH}*.cxx [ optionalExtraPath/*.cxx ] [ ... ]*/ +SUSUWU_BUILD_OBJECTS() { #/* Usage: `SUSUWU_BUILD_SOURCES [${CC} || ${CXX}] [${CFLAGS} || ${CXXFLAGS}] ".cxx" ${CXX_SOURCE_PATH}*.cxx [ optionalExtraPath/*.cxx ] [ ... ]*/ local OLD_ARG_1=${1} local OLD_ARG_2=${2} shift 2 #/* `${@:3}` requires `/bin/bash`. `shift X` sets `$@` to `${X+1} ... ${N-1}`. */ diff --git a/build.sh b/build.sh index 357ff362..9fa74829 100755 --- a/build.sh +++ b/build.sh @@ -2,12 +2,12 @@ . ./Macros.sh #/* SUSUWU_BUILD_CTAGS SUSUWU_BUILD_OBJECTS() SUSUWU_BUILD_EXECUTABLE() SUSUWU_INSTALL() SUSUWU_PRINT() SUSUWU_PROCESS_CLEAN_REBUILD() SUSUWU_PROCESS_MINGW() SUSUWU_PROCESS_RELEASE_DEBUG() SUSUWU_PROCESS_S() SUSUWU_PROCESS_VERBOSE() SUSUWU_SETUP_BUILD_FLAGS() SUSUWU_SETUP_CXX() SUSUWU_SETUP_BINDIR() SUSUWU_SETUP_OBJDIR() SUSUWU_SETUP_OUTPUT() SUSUWU_SH_* SUSUWU_TEST_OUTPUT() SUSUWU_UNINSTALL() */ SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Dual licenses: choose \"Creative Commons\" or \"Apache 2\" (allows all uses)." -CXXFLAGS_SPECIAL="" #/* You can put special flags from `build.sh` into this to use. */ -CXXFLAGS_ANALYSIS="-Wall -Wno-unused-function -Wno-unused-function -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wpedantic" #/*TODO: -`-Wno-*`, +`-Werror` */ -CXXFLAGS_RELEASE="-fomit-frame-pointer -DNDEBUG -O2" #/* without frame pointer (pointer used for stacktraces), without `assert(...)`/`SUSUWU_DEBUG(...)`/`SUSUWU_NOTICE(...)`, with optimization level 2 */ -CXXFLAGS_DEBUG="-std=c++11 -g -Og" #/* in MSVC is `/Zi /Od`: symbols for `gdb`/`lldb` use, optimizations compatible with `-g`/`-fsan*` */ -CXXFLAGS_DEBUG="-g -Og" #/* in MSVC is `/Zi /Od`: symbols for `gdb`/`lldb` use, optimizations compatible with `-g`/`-fsan*` */ -CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} -fno-omit-frame-pointer" #/* thus optimization won't remove stacktraces: https://stackoverflow.com/questions/48234575/g-will-fno-omit-frame-pointer-be-effective-if-specified-before-o2-or-o3 https://clang.llvm.org/docs/MemorySanitizer.html */ +FLAGS_SPECIAL="" #/* You can put special flags from `build.sh` into this to use. */ +FLAGS_ANALYSIS="-Wall -Wno-unused-function -Wno-unused-function -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wpedantic" #/*TODO: -`-Wno-*`, +`-Werror` */ +FLAGS_RELEASE="-fomit-frame-pointer -DNDEBUG -O2" #/* without frame pointer (pointer used for stacktraces), without `assert(...)`/`SUSUWU_DEBUG(...)`/`SUSUWU_NOTICE(...)`, with optimization level 2 */ +CXXFLAGS_DEBUG="-std=c++11" #/* ensure unit tests pass with C++11 support as max */ +FLAGS_DEBUG="-g -Og" #/* in MSVC is `/Zi /Od`: symbols for `gdb`/`lldb` use, optimizations compatible with `-g`/`-fsan*` */ +FLAGS_DEBUG="${FLAGS_DEBUG} -fno-omit-frame-pointer" #/* thus optimization won't remove stacktraces: https://stackoverflow.com/questions/48234575/g-will-fno-omit-frame-pointer-be-effective-if-specified-before-o2-or-o3 https://clang.llvm.org/docs/MemorySanitizer.html */ #CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} -fno-optimize-sibling-calls" #/* Don't inline functions. Does extra stacktraces. */ FLAGS_FSAN="-fsanitize=address -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment" #FLAGS_FSAN="${FLAGS_FSAN} -fsanitize=undefined" #/* causes 'cannot locate symbol "__ubsan_handle_function_type_mismatch_abort"' */ @@ -29,7 +29,7 @@ SUSUWU_PROCESS_CLEAN_REBUILD "$@" #/* Usage: `./build.sh --clean` or `./build.sh SUSUWU_SETUP_BUILD_FLAGS #/* Analogous to `make config` */ SUSUWU_PROCESS_INCLUDES "${CXX_SOURCE_PATH}Class*.hxx" "${CXX_SOURCE_PATH}Macros.hxx" SUSUWU_BUILD_CTAGS #/* Usage: `apt-get install ctags vim && vim -t tagToSearchFor` */ -SUSUWU_BUILD_OBJECTS "${CC} ${CCFLAGS}" ".c" "${C_SOURCE_PATH}rfc6234/sha1.c" "${C_SOURCE_PATH}rfc6234/sha224-256.c" "${C_SOURCE_PATH}rfc6234/sha384-512.c" +SUSUWU_BUILD_OBJECTS "${CC} ${CFLAGS}" ".c" "${C_SOURCE_PATH}rfc6234/sha1.c" "${C_SOURCE_PATH}rfc6234/sha224-256.c" "${C_SOURCE_PATH}rfc6234/sha384-512.c" SUSUWU_BUILD_OBJECTS "${CXX} ${CXXFLAGS}" ".cxx" "${CXX_SOURCE_PATH}*.cxx" SUSUWU_BUILD_EXECUTABLE STATUS=$?