GDExtensionTemplate/build/build.sh
somebody_master d60e3eafc7
Strip release builds
Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com>
2023-02-21 13:41:02 +01:00

143 lines
3.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Export to make android build and clean work
export ANDROID_NDK_ROOT="$HOME/.android-sdk/ndk/23.2.8568313"
# Folders
_build_folder="gdextension"
_bin_folder="build"
# Error variables
_error_build_folder="${_build_folder} doesn't exist"
_error_bin_folder="${_bin_folder} doesn't exist"
_error_no_option="\nYou have to indicate a valid option"
# Platform variables
_platform_linux="linux"
_platform_windows="windows"
_platform_android="android"
# Clean variables and exit
function clean_exit() {
if [ -v 2 ]; then
echo -e "$2"
unset 2
fi
unset _platform_android
unset _platform_windows
unset _platform_linux
unset _error_no_option
unset _error_build_folder
unset _error_bin_folder
unset _build_folder
unset _bin_folder
unset ANDROID_NDK_ROOT
exit "$1"
}
# Clean compilations
function clean() {
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
scons "platform=$_platform_linux" --clean
scons "platform=$_platform_windows" --clean
scons "platform=$_platform_android" --clean
cd ..
}
# Build by passing the platform as a variable
function build() {
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
scons "platform=$1" target=template_release
scons "platform=$1" target=template_debug
cd ..
if [ "$1" != "$_platform_android" ]; then
cd "$_bin_folder" || clean_exit 1 "$_error_bin_folder"
strip ./*.$1.template_release.*.*
cd ..
fi
unset 1
}
# Analize build process to create compile_commands.json
function build_db() {
clean
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
bear -- scons
if [ -f ../build/compile_commands.json ]; then
rm ../build/compile_commands.json
fi
cp compile_commands.json ../build/
cd ..
}
# Display the help
function Help() {
echo -e "Compiles gdextension using scons\n"
echo -e "Syntax: build [-b|d|c|a|l|w|A|h]"
echo -e "Options:"
echo -e "\t-b for build default"
echo -e "\t-d for generating a compile_commands.json"
echo -e "\t-c for cleaning"
echo -e "\t-a for building for Android"
echo -e "\t-l for building for Linux"
echo -e "\t-w for building for Windows"
echo -e "\t-A for building all"
echo -e "\t-h for displaying this help"
}
while getopts "bdchawlA" flag; do
case "$flag" in
A) # Builds for all platforms
build "$_platform_linux"
build "$_platform_windows"
build "$_platform_android"
clean_exit 0
;;
a) # Build for android
build "$_platform_android"
clean_exit 0
;;
w) # Build for windows
build "$_platform_windows"
clean_exit 0
;;
l) # Build for linux
build "$_platform_linux"
clean_exit 0
;;
d) # Generate compile_commands.json
build_db
clean_exit 0
;;
b) # Default build
build
clean_exit 0
;;
c) # Clean compilations
clean
clean_exit 0
;;
h) # Invoque help
Help
clean_exit 0
;;
\?) # Erroneus call
Help
clean_exit 1 "$_error_no_option"
;;
esac
done
# In case there is no option pass
Help
clean_exit 1 "$_error_no_option"