#!/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 a valid 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 "$_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 "$_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 "$_build_folder" || clean_exit 1 "$_error_build_folder" bear -- scons if [ ! -d ../build ]; then mkdir ../build touch ../build/.gdignore fi 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"