Refactor build.sh and add support for different platforms
Signed-off-by: somebody_master <somebody_master@somebodyserver.mooo.com>
This commit is contained in:
parent
b35474af5f
commit
a154faaef5
118
build/build.sh
118
build/build.sh
@ -1,20 +1,62 @@
|
|||||||
#!/usr/bin/env bash
|
#!/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"
|
||||||
|
|
||||||
|
# Error variables
|
||||||
|
_error_build_folder="${_build_folder} doesn't exist"
|
||||||
|
_error_no_option="\nYou have to indicate an option"
|
||||||
|
|
||||||
|
# Platform variables
|
||||||
|
_platform_linux="platform=linux"
|
||||||
|
_platform_windows="platform=windows"
|
||||||
|
_platform_android="platform=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 _build_folder
|
||||||
|
|
||||||
|
unset ANDROID_NDK_ROOT
|
||||||
|
exit "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Clean compilations
|
||||||
function clean() {
|
function clean() {
|
||||||
cd gdextension || return 1
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
||||||
scons --clean
|
scons "$_platform_linux" --clean
|
||||||
|
scons "$_platform_windows" --clean
|
||||||
|
scons "$_platform_android" --clean
|
||||||
cd ..
|
cd ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Build by passing the platform as a variable
|
||||||
function build() {
|
function build() {
|
||||||
cd gdextension || return 1
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
||||||
scons
|
scons "$1" target=template_release
|
||||||
|
scons "$1" target=template_debug
|
||||||
|
unset 1
|
||||||
cd ..
|
cd ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Analize build process to create compile_commands.json
|
||||||
function build_db() {
|
function build_db() {
|
||||||
clean
|
clean
|
||||||
cd gdextension || return 1
|
cd "$_build_folder" || clean_exit 1 "$_error_build_folder"
|
||||||
bear -- scons
|
bear -- scons
|
||||||
|
|
||||||
if [ ! -d ../build ]; then
|
if [ ! -d ../build ]; then
|
||||||
@ -31,16 +73,64 @@ function build_db() {
|
|||||||
cd ..
|
cd ..
|
||||||
}
|
}
|
||||||
|
|
||||||
while getopts "bdch" flag; do
|
# 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
|
case "$flag" in
|
||||||
d) build_db && exit 0 ;;
|
A) # Builds for all platforms
|
||||||
b) build && exit 0 ;;
|
build "$_platform_linux"
|
||||||
c) clean ;;
|
build "$_platform_windows"
|
||||||
h) echo "Use -b for build , -d for generating a compile_commands.json or -c for cleaning" ;;
|
build "$_platform_android"
|
||||||
?)
|
clean_exit 0
|
||||||
echo "script usage: $(basename \$0) [-b] [-d] [-c] [-h]" >&2
|
;;
|
||||||
exit 1
|
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
|
||||||
|
dirty_exit 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
exit 0
|
|
||||||
|
# In case there is no option pass
|
||||||
|
Help
|
||||||
|
clean_exit 1 "$_error_no_option"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user