Skip to content

Commit

Permalink
+SUSUWU_PROCESS_S() [Usage: ./build.sh -s],
Browse files Browse the repository at this point in the history
	+`SUSUWU_PROCESS_VERBOSE()` [Usage: `./build.sh --verbose`].
	Analogous to `make -s`, `make --verbose` (issue #21 is to mimic `make` protocols).

?`Macros.sh`:
	+`TODO:` list (issues #22, #23, #24, which all relate to small misc functions (such as `SUSUWU_PROCESS_S()`).
	+`SUSUWU_PRINT()`: if `SUSUWU_SH_NOTICE` && !`SUSUWU_S`, don't print. if `SUSUWU_SH_DEBUG` && !`SUSUWU_VERBOSE`, don't print.
	+`SUSUWU_PROCESS_S()`: sets `SUSUWU_S`, disables all `set -x` (default is for `CC`, `CXX`, `LD` to output).
	+`SUSUWU_PROCESS_S()`: sets `SUSUWU_VERBOSE`, forces `set -x` output (so all codes printout).
?`build.sh`:
	+`SUSUWU_PROCESS_S $@`: passes `-s` (if called as `./build.sh -s`) to `SUSUWU_PROCESS_S()`.
	+`SUSUWU_PROCESS_VERBOSE $@`: passes `--verbose` (if called as `./build.sh --verbose`) to `SUSUWU_PROCESS_VERBOSE()`.

Is followup to:658da2f6c7bb733df1b34346c351307767b386cf (... Uses `. ./Macros.sh` to follow `README.md` output format rules ...), 96c362e (@make.sh ... `set -x`).
  • Loading branch information
SwuduSusuwu committed Nov 22, 2024
1 parent 86486ac commit dbd6f1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 28 additions & 2 deletions Macros.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/bin/sh
#/* TODO: [produce `for OPTION in @$; do` loops for all `SUSUWU_PROCESS_*` functions.](https://github.com/SwuduSusuwu/SubStack/issues/22) */
#/* TODO: [produce alias (such as {`--silent`, `--quiet`} -> `-s`) groups of options/flags, for `SUSUWU_PROCESS_*` functions.](https://github.com/SwuduSusuwu/SubStack/issues/23) */
#/* TODO: [map options/flags (which `SUSUWU_PROCESS_*` functions use) to descriptions (for `--help` output.)](https://github.com/SwuduSusuwu/SubStack/issues/24) */
SUSUWU_DIR_SUFFIX_SLASH() { #/* Usage: `OBJDIR=$(SUSUWU_ENSURE_DIR_SLASH "${OBJDIR}") */
local DIR=${1}
if [ "${DIR}" = "${DIR%/}" ]; then #/* "%/" removes slash; if equal after this, original doesn't have '/'. */
Expand Down Expand Up @@ -56,9 +59,28 @@ SUSUWU_SH_SUCCESS="[${SUSUWU_SH_GREEN}Success: ${SUSUWU_SH_WHITE}"
SUSUWU_SH_NOTICE="[${SUSUWU_SH_BLUE}Notice: ${SUSUWU_SH_WHITE}"
SUSUWU_SH_DEBUG="[${SUSUWU_SH_BLUE}Debug: ${SUSUWU_SH_WHITE}"
SUSUWU_SH_CLOSE_="${SUSUWU_SH_DEFAULT}]"
SUSUWU_S=false
SUSUWU_VERBOSE=false
SUSUWU_PROCESS_S() { #/* Usage: `SUSUWU_PROCESS_S $@`. [This processes params passed to `${0}`.] */
if [ "-s" = "${1}" -o "-s" = "${2}" ]; then
SUSUWU_S=true
fi
}
SUSUWU_PROCESS_VERBOSE() { #/* Usage: `SUSUWU_PROCESS_VERBOSE $@`. [This processes params passed to `${0}`.] */
if [ "--verbose" = "${1}" -o "--verbose" = "${2}" ]; then
SUSUWU_VERBOSE=true
set -x
fi
}
SUSUWU_PRINT() { #/* Usage: `SUSUWU_PRINT "${SUSUWU_SH_{ERROR,WARNING,INFO,SUCCESS,NOTICE,DEBUG}}" "message" */
local LEVEL="${1}";
local MESSAGE="${2}"
if [ true = ${SUSUWU_S} ] && [ "${SUSUWU_SH_NOTICE}" = "${LEVEL}" ]; then
return 0
fi
if [ "${SUSUWU_SH_DEBUG}" = "${LEVEL}" ] && [ ! true = ${SUSUWU_VERBOSE} ] ; then
return 0
fi
echo "${LEVEL}${MESSAGE}${SUSUWU_SH_CLOSE_}" >&2 #/* fd=2 is `std::cerr`/`stderr` */
}

Expand Down Expand Up @@ -240,7 +262,9 @@ SUSUWU_BUILD_OBJECTS() { #/* Usage: `SUSUWU_BUILD_SOURCES [${CC} || ${CXX}] [${C
local OLD_ARG_1=${1}
local OLD_ARG_2=${2}
shift 2 #/* `${@:3}` requires `/bin/bash`. `shift X` sets `$@` to `${X+1} ... ${N-1}`. */
set -x
if [ ! true = ${SUSUWU_S} ]; then
set -x
fi
local SOURCE; for SOURCE in $@; do
local 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
Expand All @@ -253,7 +277,9 @@ SUSUWU_BUILD_OBJECTS() { #/* Usage: `SUSUWU_BUILD_SOURCES [${CC} || ${CXX}] [${C
SUSUWU_BUILD_EXECUTABLE() { #/* 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_OBJECTS() SUSUWU_BUILD_EXECUTABLE() ... */
${BUILDNEW} && ${LD} ${LDFLAGS}${OBJECTLIST} -o "${BINDIR}${OUTPUT}"
STATUS=$?
set +x
if [ ! true = ${SUSUWU_S} ] && [ ! true = ${SUSUWU_VERBOSE} ]; then
set +x
fi
if [ false = ${BUILDNEW} ]; then
STATUS=0
SUSUWU_PRINT "${SUSUWU_SH_SUCCESS}" "reused \`${BINDIR}${OUTPUT}\` (`stat -c%s ${BINDIR}${OUTPUT}` bytes)."
Expand Down
4 changes: 3 additions & 1 deletion 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_OBJECTS() SUSUWU_BUILD_EXECUTABLE() SUSUWU_INSTALL() 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_UNINSTALL() */
. ./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. */
Expand All @@ -15,6 +15,8 @@ C_SOURCE_PATH="./c/"
CXX_SOURCE_PATH="./cxx/"


SUSUWU_PROCESS_S $@ #/* Usage: `./build.sh -q`. Silences `SUSUWU_SH_NOTICE` ("Notice:") messages, prevents `set -x`. */
SUSUWU_PROCESS_VERBOSE $@ #/* Usage: `./build.sh --verbose`. Enables `SUSUWU_SH_DEBUG` ("Debug:") messages, forces `set -x`. */
SUSUWU_PROCESS_MINGW "$@" #/* Usage: `apt install mingw wine && ./build.sh --mingw`. [MinGW cross-builds to Windows.] */
SUSUWU_SETUP_CXX #/* Analogous to `make config` */
SUSUWU_PROCESS_RELEASE_DEBUG "$@" #/* Usage: `./build.sh --debug` or `./build.sh --release` */
Expand Down

0 comments on commit dbd6f1e

Please sign in to comment.