-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompile.sh
127 lines (103 loc) · 3.2 KB
/
Compile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
set -e
clear
# Define color codes
GREEN='\033[0;32m'
NC='\033[0m' # No Color
PURPLE='\033[0;35m'
GRAY='\033[1;30m'
# 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
# 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[@]}"
# 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
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
2)
BUILD_TYPE=Debug
;;
*)
BUILD_TYPE=Release
;;
esac
# 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
mkdir linuxbuild
fi
cd linuxbuild
# 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