Files

104 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
RED="\e[1;31m"
GREEN="\e[1;32m"
BLUE="\e[1;34m"
RESET="\e[0m"
clean() {
echo "cleaning build dir"
rm -rf build
}
incremental_build() {
mkdir -p ../build
cd build
cmake ..
make -j"$(nproc)"
}
clean_build() {
local starttime endtime elapsed
starttime=$(date +%s)
clean
mkdir -p build
cd build || return 1
printf "${BLUE}==> Doing a clean build...${RESET}\n"
cmake .. || {
printf "${RED}CMake configuration failed.${RESET}\n"
return 1
}
if make -j"$(nproc)"; then
endtime=$(date +%s)
elapsed=$((endtime - starttime))
printf "${GREEN}Build completed in %d seconds.${RESET}\n" "$elapsed"
else
printf "${RED}Build failed.${RESET}\n"
return 1
fi
}
release_build() {
if [ -d "build" ]; then
rm -rf "build"
echo "removing build directory"
fi
mkdir "build"
cd build
echo "starting cmake and make processes"
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j"$(nproc)"
}
run_executable() {
./build/SubWave
}
clean_appimage() {
if [ -e "SubWave-x86_64.AppImage" ]; then
rm -rf SubWave-x86_64.AppImage
echo "Removed AppImage"
fi
echo "No AppImage found, aborting"
}
case "${1:-build}" in
clean|c)
clean
;;
build|incremental|ib)
incremental_build
;;
cleanbuild|cb)
clean_build
;;
run|exec|r)
run_executable
;;
release|rb)
release_build
;;
cai|clean_appimage|cleanimg)
clean_appimage
;;
cbr|clean_build_run)
clean_build || exit 1
# build leaves us in build dir, so change back 1 so we can run the exec
cd ..
printf "${BLUE} Running Executable ; All logs below are from SubWave ${RESET}"
run_executable || exit 1
printf "${BLUE} Completed running the executable ; DONE ${RESET}\n"
;;
*)
echo "Usage: $0 {build|clean|cleanbuild|cb}"
exit 1
;;
esac