2023-02-12 01:57:08 +01:00
|
|
|
#!/usr/bin/env bash
|
2023-02-17 00:27:16 +01:00
|
|
|
# Export to make android build and clean work
|
|
|
|
export ANDROID_NDK_ROOT="$HOME/.android-sdk/ndk/23.2.8568313"
|
2023-02-12 01:57:08 +01:00
|
|
|
|
2023-02-17 00:27:16 +01:00
|
|
|
# Folders
|
|
|
|
_build_folder="gdextension"
|
2023-02-21 13:41:02 +01:00
|
|
|
_bin_folder="build"
|
2023-02-17 00:27:16 +01:00
|
|
|
|
|
|
|
# Error variables
|
|
|
|
_error_build_folder="${_build_folder} doesn't exist"
|
2023-02-21 13:41:02 +01:00
|
|
|
_error_bin_folder="${_bin_folder} doesn't exist"
|
2023-02-17 00:29:06 +01:00
|
|
|
_error_no_option="\nYou have to indicate a valid option"
|
2023-02-17 00:27:16 +01:00
|
|
|
|
|
|
|
# Platform variables
|
2023-02-21 13:41:02 +01:00
|
|
|
_platform_linux="linux"
|
|
|
|
_platform_windows="windows"
|
|
|
|
_platform_android="android"
|
2023-02-21 14:13:13 +01:00
|
|
|
_default_platform="$_platform_linux"
|
2023-02-17 00:27:16 +01:00
|
|
|
|
|
|
|
# Clean variables and exit
|
|
|
|
function clean_exit() {
|
|
|
|
|
|
|
|
if [ -v 2 ]; then
|
|
|
|
echo -e "$2"
|
|
|
|
unset 2
|
|
|
|
fi
|
|
|
|
|
2023-02-21 14:13:13 +01:00
|
|
|
unset _default_platform
|
2023-02-17 00:27:16 +01:00
|
|
|
unset _platform_android
|
|
|
|
unset _platform_windows
|
|
|
|
unset _platform_linux
|
|
|
|
|
|
|
|
unset _error_no_option
|
|
|
|
unset _error_build_folder
|
2023-02-21 13:41:02 +01:00
|
|
|
unset _error_bin_folder
|
2023-02-17 00:27:16 +01:00
|
|
|
|
|
|
|
unset _build_folder
|
2023-02-21 13:41:02 +01:00
|
|
|
unset _bin_folder
|
2023-02-17 00:27:16 +01:00
|
|
|
|
|
|
|
unset ANDROID_NDK_ROOT
|
|
|
|
exit "$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clean compilations
|
2023-02-12 14:08:20 +01:00
|
|
|
function clean() {
|
2023-02-17 00:27:16 +01:00
|
|
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
2023-02-21 14:13:13 +01:00
|
|
|
scons "platform=${1}" --clean
|
2023-02-12 14:16:10 +01:00
|
|
|
cd ..
|
2023-02-21 14:13:13 +01:00
|
|
|
|
|
|
|
for object in build/*."$1".*.*.*; do
|
|
|
|
rm --force "$object"
|
|
|
|
done
|
|
|
|
|
|
|
|
unset object
|
|
|
|
unset 1
|
2023-02-12 14:08:20 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 00:27:16 +01:00
|
|
|
# Build by passing the platform as a variable
|
2023-02-12 01:57:08 +01:00
|
|
|
function build() {
|
2023-02-17 00:27:16 +01:00
|
|
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
2023-02-21 13:41:02 +01:00
|
|
|
scons "platform=$1" target=template_release
|
|
|
|
scons "platform=$1" target=template_debug
|
2023-02-12 12:47:25 +01:00
|
|
|
cd ..
|
2023-02-21 13:41:02 +01:00
|
|
|
|
|
|
|
if [ "$1" != "$_platform_android" ]; then
|
|
|
|
cd "$_bin_folder" || clean_exit 1 "$_error_bin_folder"
|
2023-02-21 13:45:19 +01:00
|
|
|
strip ./*."$1".template_release.*.*
|
2023-02-21 13:41:02 +01:00
|
|
|
cd ..
|
|
|
|
fi
|
|
|
|
|
|
|
|
unset 1
|
2023-02-12 01:57:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 00:27:16 +01:00
|
|
|
# Analize build process to create compile_commands.json
|
2023-02-12 01:57:08 +01:00
|
|
|
function build_db() {
|
2023-02-21 14:13:13 +01:00
|
|
|
clean "$_default_platform"
|
2023-02-17 00:27:16 +01:00
|
|
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
2023-02-21 14:13:13 +01:00
|
|
|
bear -- scons platform="$_default_platform"
|
2023-02-12 12:47:25 +01:00
|
|
|
|
2023-02-21 14:13:13 +01:00
|
|
|
if [ ! -f "../{$_bin_folder}/compile_commands.json" ]; then
|
2023-02-21 23:28:44 +01:00
|
|
|
cd "../$_bin_folder" || clean_exit 1 "$_error_bin_folder"
|
|
|
|
ln -s "../${_build_folder}/compile_commands.json" ./
|
2023-02-12 12:47:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
cd ..
|
2023-02-12 01:57:08 +01:00
|
|
|
}
|
|
|
|
|
2023-02-17 00:27:16 +01:00
|
|
|
# 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
|
2023-02-12 01:57:08 +01:00
|
|
|
case "$flag" in
|
2023-02-17 00:27:16 +01:00
|
|
|
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
|
2023-02-21 14:13:13 +01:00
|
|
|
clean "$_platform_linux"
|
|
|
|
clean "$_platform_windows"
|
|
|
|
clean "$_platform_android"
|
2023-02-17 00:27:16 +01:00
|
|
|
clean_exit 0
|
|
|
|
;;
|
|
|
|
h) # Invoque help
|
|
|
|
Help
|
|
|
|
clean_exit 0
|
|
|
|
;;
|
|
|
|
\?) # Erroneus call
|
|
|
|
Help
|
2023-02-17 00:29:06 +01:00
|
|
|
clean_exit 1 "$_error_no_option"
|
2023-02-12 01:57:08 +01:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2023-02-17 00:27:16 +01:00
|
|
|
|
|
|
|
# In case there is no option pass
|
|
|
|
Help
|
|
|
|
clean_exit 1 "$_error_no_option"
|