Add support for release builds with debug info and using lib externally

This commit is contained in:
2025-08-31 14:17:04 +01:00
parent 81e3ab2c67
commit e26bf613a5
3 changed files with 153 additions and 60 deletions

61
build
View File

@@ -1,14 +1,36 @@
#!/bin/bash
BUILD_TYPE="debug"
# Colors
RED="\033[0;31m"
BOLD="\033[1m"
NC="\033[0m" # No Color
BUILD_TYPE="Debug"
ACCEPTED_BUILD_TYPES=("RelWithDebInfo" "Debug" "Release")
KERNEL="$(uname -s)"
ARGS=""
join_array_elements() {
local IFS=","
echo "$*"
}
print_usage() {
echo -e "Usage: build [-b build_type] ..."
echo -e " Options:"
echo -e " -b, --build-type Choose from $(join_array_elements ${ACCEPTED_BUILD_TYPES[*]}) (Default: Debug)."
echo -e " -h, --help Print this message and exit"
}
while [[ $# > 0 ]];do
case $1 in
--release)
BUILD_TYPE="release"
shift
-b|--build-type)
BUILD_TYPE="$2"
shift 2
;;
-h|--help)
print_usage
exit 0
;;
*|-*|--*)
rest=("$@")
@@ -18,15 +40,24 @@ while [[ $# > 0 ]];do
esac
done
if [[ $KERNEL == "Darwin" ]]; then
if [[ ! -d .venv ]]; then
python3 -m venv .venv
fi
source .venv/bin/activate
pip install scan-build
intercept-build make CC=intercept-cc CXX=intercept-c++ BUILD_TYPE=$BUILD_TYPE $ARGS
deactivate
else
bear -- make BUILD_TYPE=$BUILD_TYPE $ARGS
# Compare build type against array
# From this: https://www.baeldung.com/linux/check-bash-array-contains-value#using-anifcondition-with-aregex-pattern
build_regex="\<${BUILD_TYPE}\>"
if [[ ! ${ACCEPTED_BUILD_TYPES[@]} =~ $build_regex ]]; then
echo -e "${RED}${BOLD}Unknown build type: ${BUILD_TYPE}${NC}\n"
print_usage
exit 1
fi
if [[ $KERNEL == "Darwin" ]]; then
if [[ ! -d .venv ]]; then
python3 -m venv .venv
fi
source .venv/bin/activate
pip install scan-build
intercept-build make CC=intercept-cc CXX=intercept-c++ BUILD_TYPE=$BUILD_TYPE $ARGS
deactivate
else
bear -- make BUILD_TYPE=$BUILD_TYPE $ARGS
fi