Skip to content

Commit

Permalink
?Macros.sh: more close to make protocols, improve
Browse files Browse the repository at this point in the history
	codeflows too.

Is for issue #21 (but also, somewhat, for issue #18).
Is followup to: 3ee82e4 (?`Macros.sh`: more close to `make` protocols).

?`Macros.sh`:
	?`SUSUWU_SETUP_BUILD_FLAGS()`: +`OBJECTLIST=""`.
	?`SUSUWU_SETUP_OUTPUT()`:
		+`BUILDNEW={true,false}`.
		Moved below `SUSUWU_SETUP_BINDIR` (plus `SUSUWU_SETUP_OBJDIR`), since `BUILDNMEW` depends on `BINDIR` (also since `BINDIR` (plus `OBJDIR`) is used first throughout `Macros.sh`).
	?`SUSUWU_CLEAN_OUTPUT()`: hide error messages (without dangerous `-f` flag). `:%s/NOTICE/INFO/`: isn't usual path.
	-`SUSUWU_CLEAN_OUTPUT()`: to shorten/reuse messages (avoids out-of-sync changes to messages,) split into
		+`SUSUWU_CLEAN_OUTPUT_IMPL()`,
		+`SUSUWU_CLEAN_OUTPUT()`,
		+`SUSUWU_REBUILD_OUTPUT()` (, which have comments on howto use.)
	?`SUSUWU_PROCESS_CLEAN_REBUILD()`, ?`SUSUWU_PROCESS_SOURCES()`: use new {`SUSUWU_CLEAN_OUT()`,`SUSUWU_REBUILD_OUTPUT()`} functions.
	?`SUSUWU_PROCESS_MINGW()`, ?`SUSUWU_SETUPCXX()`:
		-`CXXFLAGS_DEBUG+=CXXFLAGS_FSAN`, +`USE_FSAN={true, false}`.
	?`SUSUWU_PROCESS_RELEASE_DEBUG()`:
		If `USE_FSAN`; `CXXFLAGS+=FLAGS_FSAN`, `LDFLAGS+=FLAGS_FSAN`, `export ASAN_OPTIONS=...`.
		Comment typo (mismatched ``) fix.
	?`SUSUWU_PROCESS_INCLUDE()`: `:%s/${CXX_SOURCE_PATH}/$(dirname ${SOURCE})\//` (non-C++ path fix.)
	?`SUSUWU_BUILD_SOURCES()`:
	-`SUSUWU_BUILD_SOURCES()`: since it used hardcoded suffixes plus paths, split into;
		So multiple `SUSUWU_BUILD_OBJECTS()` calls won't duplicated those:
			-`OBJECTLIST=""` (moved into ?`SUSUWU_SETUP_BUILD_FLAGS()`,)
			-`BUILDNEW={true,false}` (moved into ?`SUSUWU_SETUP_OUTPUT()`.)
		+`SUSUWU_BUILD_OBJECTS()`:
			Has comment (on howto pass suffix plus paths.)
			`:%s/test -e/test -s/` (exists -> non-zero plus exists).
		+`SUSUWU_BUILD_EXECUTABLE()`:
			Is generic (without params.)
			If linker errors; print status code, plus suggest howto fix this.
	?`SUSUWU_TEST_OUTPUT()`: if `./build.sh --mingw`, test that `wine` exists ("./bin/a.exe: 1: Syntax error: word unexpected (expecting ")")" fix.)
	+`SUSUWU_TODO_LIST()`: allows to reuse common "TODO" messages for unimplemented features.
	+`SUSUWU_FORMAT()`, +`SUSUWU_DOCS()`, +`SUSUWU_INSTALL()`, +`SUSUWU_UNINSTALL()`: placeholders for common `make` tools.

?`Macros.sh`, ?`build.sh`:
	`:%s/CXXFLAGS_FSAN/FLAGS_FSAN`: to prevent "ld.lld: error: undefined symbol: __asan_*", `${LDFLAGS}` must have `-fsan*`.

?`build.sh`:
	?`SUSUWU_SETUP_OUTPUT`: since it now uses `OBJDIR`, move down below `SUSUWU_SETUP_OBJDIR`.
	-`SUSUWU_BUILD_SOURCES`: `Macros.sh` split this into multiple functions.
		+`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 "${CXX} ${CXXFLAGS}" ".cxx" "${CXX_SOURCE_PATH}*.cxx"`
		+`SUSUWU_BUILD_EXECUTABLE`
	?`SUSUWU_SETUP_CXX`, ?`SUSUWU_SETUP_BUILD_FLAGS`, ?`SUSUWU_TEST_OUTPUT`: Now has comment.
  • Loading branch information
SwuduSusuwu committed Nov 20, 2024
1 parent 3ee82e4 commit d6332e9
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 60 deletions.
134 changes: 84 additions & 50 deletions Macros.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,35 @@ SUSUWU_PROCESS_MINGW() { #/* Usage: `SUSUWU_PROCESS_MINGW $?` */
LDFLAGS="${LDFLAGS} -static-libgcc -static-libstdc++"
if command -v x86_64-w64-mingw32-clang++ > /dev/null; then
CXX="x86_64-w64-mingw32-clang++"
CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} ${CXXFLAGS_FSAN}" #/* `-fsan*` [supports `x86_64-w64-mingw32-clang++`](https://github.com/SwuduSusuwu/SubStack/issues/16) */
USE_FSAN=true #/* `-fsan*` [supports `x86_64-w64-mingw32-clang++`](https://github.com/SwuduSusuwu/SubStack/issues/16) */
elif command -v x86_64-w64-mingw32-g++ > /dev/null; then
CXX="x86_64-w64-mingw32-g++"
# CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} ${CXXFLAGS_FSAN}" #/* `TODO: `-fsan*` for `x86_64-w64-mingw32-g++`](https://www.mingw-w64.org/contribute/#thorough-status-report-for-sanitizers-asan-tsan-usan) */
USE_FSAN=false #/* `TODO: `-fsan*` for `x86_64-w64-mingw32-g++`](https://www.mingw-w64.org/contribute/#thorough-status-report-for-sanitizers-asan-tsan-usan) */
else
SUSUWU_PRINT "${SUSUWU_SH_ERROR}" "\`x86_64-w64-mingw32-clang++ not found\`, \`x86_64-w64-mingw32-g++ not found\`. Do \`apt install llvm-mingw-w64\` or \`apt install mingw-w64\`."
exit 1
fi
fi
}
SUSUWU_SETUP_CXX() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] SUSUWU_SETUP_CXX [SUSUWU_PROCESS_RELEASE_DEBUG $?] SUSUWU_SETUP_BUILD_FLAGS SUSUWU_SETUP_OUTPUT "" SUSUWU_SETUP_BINDIR "" SUSUWU_SETUP_OBJDIR "" [SUSUWU_PROCESS_CLEAN_REBUILD $?] [SUSUWU_PROCESS_INCLUDES ""] SUSUWU_BUILD_SOURCES ... */
SUSUWU_SETUP_CXX() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] 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 ... */
if [ ! -z ${CROSS_COMP} ]; then #/* if `--mingw`, */
return; #/* don't override `CXX`. */
elif command -v clang++ > /dev/null; then
CXX="clang++" #/* TODO: +` -Xclang -analyze -Xclang -analyzer-output=text` (got no extra outputs from this) */
CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} ${CXXFLAGS_FSAN}" #/* [`-fsan*` supports `g++`/`clang++`](https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#tldr) */
USE_FSAN=true #/* [`-fsan*` supports `g++`/`clang++`](https://developers.redhat.com/blog/2021/05/05/memory-error-checking-in-c-and-c-comparing-sanitizers-and-valgrind#tldr) */
elif command -v g++ > /dev/null; then
CXX="g++"
CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} ${CXXFLAGS_FSAN}"
USE_FSAN=true
elif command -v "${CXX}" > /dev/null; then #/* TODO: if our flags are compatible with all `${CXX}`, move this to top */
SUSUWU_PRINT "${SUSUWU_SH_INFO}" "\`clang++ not found\`, \`g++ not found\`. \`\${CXX}\` (\"${CXX}\") found, will use this."
USE_FSAN=false #/* `TODO: test unknown compilers for `-fsan*` support */
else
SUSUWU_PRINT "${SUSUWU_SH_ERROR}" "\`clang++ not found\`, \`g++ not found\`. \`\${CXX}\` (\"${CXX}\") not found. Do \`apt install clang\` or \`apt install gcc\`."
exit 1
fi
}

SUSUWU_PROCESS_RELEASE_DEBUG() { #/* Usage: `SUSUWU_PROCESS_RELEASE_DEBUG $? */
SUSUWU_PROCESS_RELEASE_DEBUG() { #/* Usage: `SUSUWU_PROCESS_RELEASE_DEBUG $?` */
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}"
Expand All @@ -98,26 +99,24 @@ SUSUWU_PROCESS_RELEASE_DEBUG() { #/* Usage: `SUSUWU_PROCESS_RELEASE_DEBUG $? */
fi
SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Use \`${0}${CROSS_COMP} --release\` to improve how fast this executes."
CXXFLAGS="${CXXFLAGS} ${CXXFLAGS_DEBUG}"
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" */
if [ true = ${USE_FSAN} ]; then
CXXFLAGS="${CXXFLAGS} ${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
fi
}
SUSUWU_SETUP_BUILD_FLAGS() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] SUSUWU_SETUP_CXX [SUSUWU_PROCESS_RELEASE_DEBUG $?] SUSUWU_SETUP_BUILD_FLAGS SUSUWU_SETUP_OUTPUT "" SUSUWU_SETUP_BINDIR "" SUSUWU_SETUP_OBJDIR "" [SUSUWU_PROCESS_CLEAN_REBUILD $?] [SUSUWU_PROCESS_INCLUDES ""] SUSUWU_BUILD_SOURCES ... */
SUSUWU_SETUP_BUILD_FLAGS() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] 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 ... */
LD="${CXX}"
CC="${CXX} -x c"
LDFLAGS="${LDFLAGS} ${CXXFLAGS}"
LDFLAGS="${LDFLAGS}"
CXXFLAGS="${CXXFLAGS} ${CXXFLAGS_ANALYSIS}"
CCFLAGS="${CCFLAGS} ${CXXFLAGS}"
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=""
}

SUSUWU_SETUP_OUTPUT() { #/* Usage: `SUSUWU_SETUP_OUTPUT "YourProgram"` */
if [ -z ${CROSS_COMP} ]; then
OUTPUT="${1}.out"
else
OUTPUT="${1}.exe"
fi
}
SUSUWU_SETUP_OBJDIR() { #/* Usage: `SUSUWU_SETUP_OBJDIR "./obj/"` */
if [ -z ${OBJDIR} ]; then
OBJDIR="${1}"
Expand All @@ -138,61 +137,71 @@ SUSUWU_SETUP_BINDIR() { #/* Usage: `SUSUWU_SETUP_BINDIR "./bin/"` */
BINDIR=$(SUSUWU_DIR_SUFFIX_SLASH "${BINDIR}") #/* if inherit BINDIR, perhaps it is without last '/' */
mkdir -p "${BINDIR}"
}
SUSUWU_CLEAN_OUTPUT() { #/* The `-f` flag is omitted in case `OBJDIR` or `BINDIR` is set to "../*/". */
rm ${OBJDIR}*.o
rm ${BINDIR}*.exe
rm ${BINDIR}*.out
SUSUWU_SETUP_OUTPUT() { #/* Usage: `SUSUWU_SETUP_OUTPUT "YourProgram"` */
if [ -z "${BINDIR%/}" ] || [ -z "${OBJDIR%/}" ]; then
SUSUWU_PRINT "${SUSUWU_SH_ERROR}" "\`[ -z \"\${BINDIR%/}\" ] || [ \"-z \${OBJDIR%/}\" ]\`: \`${0}\` must call \`SUSUWU_SETUP_OBJDIR()\` + \`SUSUWU_SETUP_BINDIR()\` before \`SUSUWU_SETUP_OUTPUT()\`."
exit 1 #/* `if("/" == BINDIR || "" == BINDIR)`, can't use `${BINDIR}${OUTPUT}` */
fi
if [ -z ${CROSS_COMP} ]; then
OUTPUT="${1}.out"
else
OUTPUT="${1}.exe"
fi
if [ -e ${BINDIR}${OUTPUT} ]; then
BUILDNEW=false
else
BUILDNEW=true
fi
}
SUSUWU_CLEAN_OUTPUT_IMPL() { #/* Usage: `SUSUWU_CLEAN_OUTPUT_IMPL "Reason to clean" "postscript" */
SUSUWU_PRINT "${SUSUWU_SH_INFO}" "${1}; will remove intermediate objects (\`rm ${OBJDIR}*.o\`), plus remove generated executables (\`rm ${BINDIR}*.{exe,out}\`)${2}"
rm ${OBJDIR}*.o 2>/dev/null #/* The `-f` flag is omitted in case `OBJDIR` or `BINDIR` is set to "../*/". */
rm ${BINDIR}*.exe 2>/dev/null
rm ${BINDIR}*.out 2>/dev/null
}
SUSUWU_CLEAN_OUTPUT() { #/* Usage: `SUSUWU_REBUILD_OUTPUT "Reason to clean" */
SUSUWU_CLEAN_OUTPUT_IMPL "${1}" ", plus exit. [Use \`${0}${CROSS_COMP} --rebuild\` to remove plus continue.]"
exit 0
}
SUSUWU_REBUILD_OUTPUT() { #/* Usage: `SUSUWU_REBUILD_OUTPUT "Reason to rebuild" */
SUSUWU_CLEAN_OUTPUT_IMPL "${1}" ", plus continue. [Use \`${0}${CROSS_COMP} --clean\` to remove plus exit.]"
}
SUSUWU_PROCESS_CLEAN_REBUILD() { #/* Usage: `SUSUWU_PROCESS_CLEAN_REBUILD $?` */
if [ "--clean" = "${1}" -o "--clean" = "${2}" ]; then
SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Was called with \`${0}${CROSS_COMP} --clean\`, will remove intermediate objects + exit. Use \`${0}${CROSS_COMP} --rebuild\` to clean + continue."
SUSUWU_CLEAN_OUTPUT
exit 0
SUSUWU_CLEAN_OUTPUT "Was called with \`${0}${CROSS_COMP} --clean\`"
fi
if [ "--rebuild" = "${1}" -o "--rebuild" = "${2}" ]; then
SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Was called with \`${0}${CROSS_COMP} --rebuild\`, will remove intermediate objects + continue."
SUSUWU_CLEAN_OUTPUT
SUSUWU_REBUILD_OUTPUT "Was called with \`${0}${CROSS_COMP} --rebuild\`"
fi
}

SUSUWU_PROCESS_INCLUDES() { #/* Usage: `SUSUWU_BUILD_SOURCES ${C_SOURCE_PATH}*.h ${CXX_SOURCE_PATH}*.hxx` */
for SOURCE in $@; do
OBJECT="${OBJDIR}$(basename ${SOURCE} .hxx).o" #/* `basename`'s second param removes suffix */
SRCCXX="${CXX_SOURCE_PATH}$(basename ${SOURCE} .hxx).cxx" #/* `basename`'s second param removes suffix */
SRCCXX="$(dirname ${SOURCE})/$(basename ${SOURCE} .hxx).cxx" #/* `basename`'s second param removes suffix */
if [ ${OBJECT} -ot ${SOURCE} -a -e ${SOURCE} ]; then #/* `&& [ -e ${SOURCE} ]` is: skip unless `${SOURCE}` exists. */
SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "\`${SOURCE}\` (which is a common \`#include\`) is newer than \`${OBJECT}\`, will rebuild all objects."
SUSUWU_CLEAN_OUTPUT
SUSUWU_REBUILD_OUTPUT "\`${SOURCE}\` (which is a common \`#include\`) is newer than \`${OBJECT}\`"
break
elif [ ! -e ${SRCCXX} ]; then #/* If `*.hxx` doesn't have `*.cxx` match, */
touch ${OBJECT}; #/* ... then produce `*.o` (for future tests.) */
fi
done
}
SUSUWU_BUILD_SOURCES() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] SUSUWU_SETUP_CXX [SUSUWU_PROCESS_RELEASE_DEBUG $?] SUSUWU_SETUP_BUILD_FLAGS SUSUWU_SETUP_OUTPUT "" SUSUWU_SETUP_BINDIR "" SUSUWU_SETUP_OBJDIR "" [SUSUWU_PROCESS_CLEAN_REBUILD $?] [SUSUWU_PROCESS_INCLUDES ""] SUSUWU_BUILD_SOURCES ... */
if [ -e ${BINDIR}${OUTPUT} ]; then
BUILDNEW=false
else
BUILDNEW=true
fi
OBJECTLIST=""
SUSUWU_BUILD_OBJECTS() { #/* Usage: `SUSUWU_BUILD_SOURCES [${CC} || ${CXX}] [${CCFLAGS} || ${CXXFLAGS}] ".cxx" ${CXX_SOURCE_PATH}*.cxx [ optionalExtraPath/*.cxx ] [ ... ]*/
OLD_ARG_1=${1}
OLD_ARG_2=${2}
shift 2 #/* `${@:3}` requires `/bin/bash`. `shift X` sets `$@` to `${X+1} ... ${N-1}`. */
set -x
#for SOURCE in ${C_SOURCE_PATH}*/*.c; do #/* The extra "*/" is since this just has vendored code (`rfc6234/`) */
for SOURCE in "${C_SOURCE_PATH}rfc6234/sha1.c" "${C_SOURCE_PATH}rfc6234/sha224-256.c" "${C_SOURCE_PATH}rfc6234/sha384-512.c"; do
OBJECT="${OBJDIR}$(basename ${SOURCE} .c).o" #/* `basename`'s second param removes suffix */
if [ ${OBJECT} -ot ${SOURCE} -o ! -e ${OBJECT} ] >/dev/null; then
${CC} ${CCFLAGS} -c "${SOURCE}" -o "${OBJECT}"
BUILDNEW=true
fi
OBJECTLIST="${OBJECTLIST} ${OBJECT}"
done
for SOURCE in ${CXX_SOURCE_PATH}*.cxx; do
OBJECT="${OBJDIR}$(basename ${SOURCE} .cxx).o" #/* `basename`'s second param removes suffix */
if [ ${OBJECT} -ot ${SOURCE} -o ! -e ${OBJECT} ] > /dev/null 2>&1; then
${CXX} ${CXXFLAGS} -c "${SOURCE}" -o "${OBJECT}"
for SOURCE in $@; do
OBJECT="${OBJDIR}$(basename "${SOURCE}" "${OLD_ARG_2}").o" #/* `basename`'s second param removes suffix */
if [ ${OBJECT} -ot ${SOURCE} -o ! -s ${OBJECT} ] > /dev/null 2>&1; then
${OLD_ARG_1} -c "${SOURCE}" -o "${OBJECT}"
BUILDNEW=true
fi
OBJECTLIST="${OBJECTLIST} ${OBJECT}"
done
}
SUSUWU_BUILD_EXECUTABLE() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] 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_OBJECTS() SUSUWU_BUILD_EXECUTABLE() ... */
${BUILDNEW} && ${LD} ${LDFLAGS}${OBJECTLIST} -o "${BINDIR}${OUTPUT}"
STATUS=$?
set +x
Expand All @@ -202,14 +211,23 @@ SUSUWU_BUILD_SOURCES() { #/* Usage: ... [SUSUWU_PROCESS_MINGE $?] SUSUWU_SETUP_C
elif [ 0 -eq ${STATUS} ]; then
SUSUWU_PRINT "${SUSUWU_SH_SUCCESS}" "produced \`${BINDIR}${OUTPUT}\` (`stat -c%s ${BINDIR}${OUTPUT}` bytes)."
else
SUSUWU_PRINT "${SUSUWU_SH_ERROR}" "\`${LD}\` returned status code ${STATUS}."
SUSUWU_PRINT "${SUSUWU_SH_ERROR}" "\`${LD}\` returned status code ${STATUS}. [If errors include \"ld... unknown file type\" or \"ld... undefined symbol __asan_*\", use \`${0}${CROSS_COMP} --rebuild\` to remove plus continue.]"
fi
return ${STATUS}
}

SUSUWU_TEST_OUTPUT() {
if [ 0 -eq ${STATUS} ] || [ false = ${BUILDNEW} ]; then
${BINDIR}${OUTPUT}
if [ -z ${CROSS_COMP} ]; then #/* `if("" == CROSS_COMP)` */
${BINDIR}${OUTPUT}
else #/* if `--mingw` */
if command -v wine > /dev/null; then
wine ${BINDIR}${OUTPUT}
else
SUSUWU_PRINT "${SUSUWU_SH_INFO}" "\`wine not found\`. do \`apt install wine\`."
return 0
fi
fi
STATUS=$?
if [ 0 -eq ${STATUS} ]; then
SUSUWU_PRINT "${SUSUWU_SH_SUCCESS}" "\`${BINDIR}${OUTPUT}\` returned status SusuwuUnitTestsBitmask(${STATUS})."
Expand All @@ -220,3 +238,19 @@ SUSUWU_TEST_OUTPUT() {
return ${STATUS}
}

SUSUWU_TODO_LIST() { #/* Usage: `SUSUWU_TODO_LIST "NameOfTool" "what to expect from future versions"` */
SUSUWU_PRINT "${SUSUWU_SH_ERROR}" "\`${1}\` ${2} is on a long \"TODO\" list. If you want this: contribute (at https://github.com/SwuduSusuwu/SubStack/#Contributor-conventionsrules), or ask for this at https://github.com/SwuduSusuwu/SubStack/issues/new"
exit 1
}
SUSUWU_FORMAT() { #/* Is analogous to `make format`. */
SUSUWU_TODO_LIST "SUSUWU_FORMAT()" "(which will use tools such as \`prettier\` or \`clang-format\`)"
}
SUSUWU_DOCS() { #/* Is analogous to `make docs`. */
SUSUWU_TODO_LIST "SUSUWU_DOCS()" "(which will use tools such as \`Sphinx\` or \`Doxygen\`)"
}
SUSUWU_INSTALL() { #/* Is analogous to `make install`. */
SUSUWU_TODO_LIST "SUSUWU_INSTALL()" "(which will use scripts such as \`cp ${BINDIR}${OUTPUT} /usr/bin/\`)"
}
SUSUWU_UNINSTALL() { #/* Is analogous to `make uninstall`. */
SUSUWU_TODO_LIST "SUSUWU_UNINSTALL()" "(which will use scripts such as \`rm /usr/bin/${OUTPUT}\`)"
}
20 changes: 10 additions & 10 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
. ./Macros.sh #/* SUSUWU_BUILD_CTAGS SUSUWU_BUILD_SOURCES() SUSUWU_PRINT() SUSUWU_PROCESS_CLEAN_REBUILD() SUSUWU_PROCESS_MINGW() SUSUWU_PROCESS_RELEASE_DEBUG() SUSUWU_SETUP_BUILD_FLAGS() SUSUWU_SETUP_CXX() SUSUWU_SETUP_BINDIR() SUSUWU_SETUP_OBJDIR() SUSUWU_SETUP_OUTPUT() SUSUWU_SH_* SUSUWU_TEST_OUTPUT() */
. ./Macros.sh #/* SUSUWU_BUILD_CTAGS SUSUWU_BUILD_OBJECTS() SUSUWU_BUILD_EXECUTABLE() SUSUWU_PRINT() SUSUWU_PROCESS_CLEAN_REBUILD() SUSUWU_PROCESS_MINGW() SUSUWU_PROCESS_RELEASE_DEBUG() SUSUWU_SETUP_BUILD_FLAGS() SUSUWU_SETUP_CXX() SUSUWU_SETUP_BINDIR() SUSUWU_SETUP_OBJDIR() SUSUWU_SETUP_OUTPUT() SUSUWU_SH_* SUSUWU_TEST_OUTPUT() */
SUSUWU_PRINT "${SUSUWU_SH_NOTICE}" "Dual licenses: choose \"Creative Commons\" or \"Apache 2\" (allows all uses)."

SUSUWU_BUILD_CTAGS #/* Usage: `apt-get install ctags` */
Expand All @@ -11,29 +11,29 @@ CXXFLAGS_DEBUG="-std=c++11 -g -Og" #/* in MSVC is `/Zi /Od`: symbols for `gdb`/`
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 */
#CXXFLAGS_DEBUG="${CXXFLAGS_DEBUG} -fno-optimize-sibling-calls" #/* Don't inline functions. Does extra stacktraces. */
CXXFLAGS_FSAN="-fsanitize=address -fno-sanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment"
#CXXFLAGS_FSAN="${CXXFLAGS_FSAN} -fsanitize=undefined" #/* causes 'cannot locate symbol "__ubsan_handle_function_type_mismatch_abort"' */
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"' */
C_SOURCE_PATH="./c/"
CXX_SOURCE_PATH="./cxx/"


SUSUWU_PROCESS_MINGW $@ #/* Usage: `./build.sh --mingw` */
SUSUWU_SETUP_CXX

SUSUWU_SETUP_CXX #/* Analogous to `make config` */
SUSUWU_PROCESS_RELEASE_DEBUG $@ #/* Usage: `./build.sh --debug` or `./build.sh --release` */
SUSUWU_SETUP_BUILD_FLAGS

BUILDNEW=false
SUSUWU_SETUP_OUTPUT "a"
SUSUWU_SETUP_OBJDIR "./obj/"
SUSUWU_SETUP_BINDIR "./bin/"
SUSUWU_SETUP_OUTPUT "a"
SUSUWU_PROCESS_CLEAN_REBUILD $@ #/* Usage: `./build.sh --clean` or `./build.sh --rebuild` */

SUSUWU_SETUP_BUILD_FLAGS #/* Analogous to `make config` */
SUSUWU_PROCESS_INCLUDES ${CXX_SOURCE_PATH}Class*.hxx ${CXX_SOURCE_PATH}Macros.hxx
SUSUWU_BUILD_SOURCES
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 "${CXX} ${CXXFLAGS}" ".cxx" "${CXX_SOURCE_PATH}*.cxx"
SUSUWU_BUILD_EXECUTABLE
STATUS=$?

SUSUWU_TEST_OUTPUT
SUSUWU_TEST_OUTPUT #/* Analogous to `make test` or `make execute` */
STATUS=$?
return ${STATUS}

0 comments on commit d6332e9

Please sign in to comment.