diff --git a/build/build.sh b/build/build.sh index ca670b5..2443f53 100755 --- a/build/build.sh +++ b/build/build.sh @@ -1,20 +1,62 @@ #!/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() { - cd gdextension || return 1 - scons --clean + cd "$_build_folder" || clean_exit 1 "$_error_build_folder" + scons "$_platform_linux" --clean + scons "$_platform_windows" --clean + scons "$_platform_android" --clean cd .. } +# Build by passing the platform as a variable function build() { - cd gdextension || return 1 - scons + cd "$_build_folder" || clean_exit 1 "$_error_build_folder" + scons "$1" target=template_release + scons "$1" target=template_debug + unset 1 cd .. } +# Analize build process to create compile_commands.json function build_db() { clean - cd gdextension || return 1 + cd "$_build_folder" || clean_exit 1 "$_error_build_folder" bear -- scons if [ ! -d ../build ]; then @@ -31,16 +73,64 @@ function build_db() { 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 - d) build_db && exit 0 ;; - b) build && exit 0 ;; - c) clean ;; - h) echo "Use -b for build , -d for generating a compile_commands.json or -c for cleaning" ;; - ?) - echo "script usage: $(basename \$0) [-b] [-d] [-c] [-h]" >&2 - exit 1 + 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 + dirty_exit 0 ;; esac done -exit 0 + +# In case there is no option pass +Help +clean_exit 1 "$_error_no_option"