Improved Compile.sh

This commit is contained in:
Jordon Brooks 2024-06-06 16:04:34 +01:00
parent 9a1e6f24b1
commit 7f0fa0b90d
Signed by: jordon
GPG key ID: DBD9758CD53E786A

View file

@ -1,49 +1,96 @@
#!/bin/sh #!/bin/bash
set -e set -e
clear clear
# Define the color codes # Define color codes
GREEN='\033[0;32m' GREEN='\033[0;32m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
PURPLE='\033[0;35m'
GRAY='\033[1;30m'
# Prompt the user to choose a compiler # Ensure dialog is installed
echo "${GREEN}Select the compiler to use:${NC}" if ! command -v dialog &> /dev/null
echo "1) g++ (default)" then
echo "2) clang++" echo "dialog could not be found. Please install it to use this script."
echo "3) clang++ 15" exit
echo "4) clang++ 16" fi
read -p "Enter the number of your choice: " choice
# Set the compiler based on the user's choice # Function to check if a compiler is installed
case $choice in check_compiler() {
2) if command -v $1 &> /dev/null
C_COMPILER=clang then
CXX_COMPILER=clang++ COMPILER_OPTIONS+=("$2" "$3" "$4")
;; fi
3) }
C_COMPILER=clang-15
CXX_COMPILER=clang++-15
;;
4)
C_COMPILER=clang-16
CXX_COMPILER=clang++-16
;;
*)
C_COMPILER=gcc
CXX_COMPILER=g++
;;
esac
echo "Using C compiler: $C_COMPILER" # Array to store the menu options
echo "Using C++ compiler: $CXX_COMPILER" COMPILER_OPTIONS=()
# Add available compilers to the options array
check_compiler g++ "1" "g++ (default)" "on"
check_compiler clang++ "2" "clang++" "off"
check_compiler clang++-15 "3" "clang++ 15" "off"
check_compiler clang++-16 "4" "clang++ 16" "off"
check_compiler clang++-17 "5" "clang++ 17" "off"
# Debug: print the compiler options
echo "Compiler options: ${COMPILER_OPTIONS[@]}"
# Check if any compilers are available
if [ ${#COMPILER_OPTIONS[@]} -eq 0 ]; then
dialog --msgbox "No compilers found. Please install a compiler to use this script." 10 40
exit
fi
# Prompt the user to choose one or more compilers
compiler_choices=$(dialog --colors --title "\Zb\Z5Select Compiler\Zn" --checklist "\nChoose one or more compilers:" 15 60 ${#COMPILER_OPTIONS[@]} "${COMPILER_OPTIONS[@]}" 3>&1 1>&2 2>&3)
# Process the selected compilers
C_COMPILERS=()
CXX_COMPILERS=()
# Debug: print the compiler choices
echo "Compiler choices: $compiler_choices"
for choice in $compiler_choices; do
case $choice in
1)
C_COMPILERS+=("gcc")
CXX_COMPILERS+=("g++")
;;
2)
C_COMPILERS+=("clang")
CXX_COMPILERS+=("clang++")
;;
3)
C_COMPILERS+=("clang-15")
CXX_COMPILERS+=("clang++-15")
;;
4)
C_COMPILERS+=("clang-16")
CXX_COMPILERS+=("clang++-16")
;;
5)
C_COMPILERS+=("clang-17")
CXX_COMPILERS+=("clang++-17")
;;
esac
done
# Output the chosen compilers
msg="Chosen compilers:\n"
for i in "${!C_COMPILERS[@]}"; do
msg+="C compiler: ${C_COMPILERS[$i]}, C++ compiler: ${CXX_COMPILERS[$i]}\n"
done
dialog --colors --msgbox "\Zb\Z5$msg\Zn" 20 60
# Prompt the user to choose a build type # Prompt the user to choose a build type
echo "${GREEN}Select the build type:${NC}" build_choice=$(dialog --colors --title "\Zb\Z5Select Build Type\Zn" --menu "\nChoose a build type:" 10 40 2 \
echo "1) Release (default)" 1 "Release (default)" \
echo "2) Debug" 2 "Debug" 3>&1 1>&2 2>&3)
read -p "Enter the number of your choice: " build_choice
# Set the build type based on the user's choice # Set the build type based on the user's choice
case $build_choice in case $build_choice in
@ -55,7 +102,10 @@ case $build_choice in
;; ;;
esac esac
echo "Build type: $BUILD_TYPE" # Output the chosen build type
dialog --colors --msgbox "\Zb\Z5Build type:\Zn $BUILD_TYPE" 10 40
clear
# Create the build directory if it doesn't exist # Create the build directory if it doesn't exist
if [ ! -d "linuxbuild" ]; then if [ ! -d "linuxbuild" ]; then
@ -64,10 +114,14 @@ fi
cd linuxbuild cd linuxbuild
# Run CMake with the selected compiler and build type # Run CMake with the selected compilers and build type
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER .. for i in "${!C_COMPILERS[@]}"; do
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER=${C_COMPILERS[$i]} -DCMAKE_CXX_COMPILER=${CXX_COMPILERS[$i]} ..
# Build the project # Build the project
cmake --build . --config $BUILD_TYPE --clean-first -j 15 --verbose cmake --build . --config $BUILD_TYPE -j 15 #--clean-first #--verbose
done
cd .. cd ..
# End with a success message
dialog --colors --msgbox "\Zb\Z5Build(s) completed successfully!\Zn" 10 40