Skip to content

Commit

Permalink
Improved Compile.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordonbc committed Jun 6, 2024
1 parent 9a1e6f2 commit 7f0fa0b
Showing 1 changed file with 94 additions and 40 deletions.
134 changes: 94 additions & 40 deletions Compile.sh
Original file line number Diff line number Diff line change
@@ -1,49 +1,96 @@
#!/bin/sh
#!/bin/bash

set -e

clear

# Define the color codes
# Define color codes
GREEN='\033[0;32m'
NC='\033[0m' # No Color
PURPLE='\033[0;35m'
GRAY='\033[1;30m'

# Prompt the user to choose a compiler
echo "${GREEN}Select the compiler to use:${NC}"
echo "1) g++ (default)"
echo "2) clang++"
echo "3) clang++ 15"
echo "4) clang++ 16"
read -p "Enter the number of your choice: " choice
# Ensure dialog is installed
if ! command -v dialog &> /dev/null
then
echo "dialog could not be found. Please install it to use this script."
exit
fi

# Set the compiler based on the user's choice
case $choice in
2)
C_COMPILER=clang
CXX_COMPILER=clang++
;;
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
# Function to check if a compiler is installed
check_compiler() {
if command -v $1 &> /dev/null
then
COMPILER_OPTIONS+=("$2" "$3" "$4")
fi
}

# Array to store the menu options
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[@]}"

echo "Using C compiler: $C_COMPILER"
echo "Using C++ compiler: $CXX_COMPILER"
# 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
echo "${GREEN}Select the build type:${NC}"
echo "1) Release (default)"
echo "2) Debug"
read -p "Enter the number of your choice: " build_choice
build_choice=$(dialog --colors --title "\Zb\Z5Select Build Type\Zn" --menu "\nChoose a build type:" 10 40 2 \
1 "Release (default)" \
2 "Debug" 3>&1 1>&2 2>&3)

# Set the build type based on the user's choice
case $build_choice in
Expand All @@ -55,7 +102,10 @@ case $build_choice in
;;
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
if [ ! -d "linuxbuild" ]; then
Expand All @@ -64,10 +114,14 @@ fi

cd linuxbuild

# Run CMake with the selected compiler and build type
cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER ..

# Build the project
cmake --build . --config $BUILD_TYPE --clean-first -j 15 --verbose
# Run CMake with the selected compilers and build type
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
cmake --build . --config $BUILD_TYPE -j 15 #--clean-first #--verbose
done

cd ..

# End with a success message
dialog --colors --msgbox "\Zb\Z5Build(s) completed successfully!\Zn" 10 40

0 comments on commit 7f0fa0b

Please sign in to comment.