150 lines
3.6 KiB
Bash
Executable File
150 lines
3.6 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"
|
|
_default_platform="$_platform_linux"
|
|
|
|
# Clean variables and exit
|
|
function clean_exit() {
|
|
|
|
if [ -v 2 ]; then
|
|
echo -e "$2"
|
|
unset 2
|
|
fi
|
|
|
|
unset _default_platform
|
|
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=${1}" --clean
|
|
cd ..
|
|
|
|
for object in build/*."$1".*.*.*; do
|
|
rm --force "$object"
|
|
done
|
|
|
|
unset object
|
|
unset 1
|
|
}
|
|
|
|
# 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 "$_default_platform"
|
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
|
bear -- scons platform="$_default_platform"
|
|
|
|
if [ ! -f "../{$_bin_folder}/compile_commands.json" ]; then
|
|
ln -s compile_commands.json "../${_bin_folder}/compile_commands.json"
|
|
fi
|
|
|
|
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 "$_platform_linux"
|
|
clean "$_platform_windows"
|
|
clean "$_platform_android"
|
|
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"
|