64 lines
1.4 KiB
Bash
Executable File
64 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# 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
|
|
-b|--build-type)
|
|
BUILD_TYPE="$2"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
print_usage
|
|
exit 0
|
|
;;
|
|
*|-*|--*)
|
|
rest=("$@")
|
|
ARGS+=" ${rest[0]}"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# 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
|