-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure.sh
executable file
·173 lines (152 loc) · 4.73 KB
/
configure.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/bin/bash
# ANSI color codes and formatting
BOLD='\033[1m'
DIM='\033[2m'
ITALIC='\033[3m'
UNDERLINE='\033[4m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Function to print centered text with a specified color
print_centered() {
local color=$1
local text=$2
local width=$(tput cols)
local padding=$(( (width - ${#text}) / 2 ))
printf "%${padding}s" ""
echo -e "${color}${text}${NC}"
}
# Function to print a horizontal line
print_line() {
local width=$(tput cols)
printf '%*s\n' "${width}" '' | tr ' ' '─'
}
# Function to print status with icon
print_status() {
local status=$1
local message=$2
if [ "$status" -eq 0 ]; then
echo -e "${GREEN}✓${NC} ${message}"
else
echo -e "${RED}✗${NC} ${message}"
fi
}
clear
print_line
print_centered "${BLUE}${BOLD}" "AdvBox Configuration Script"
print_centered "${CYAN}${DIM}" "Version 1.0.0 - Setup started at $(date '+%Y-%m-%d %H:%M:%S')"
print_centered "${MAGENTA}${ITALIC}" "by AnmiTaliDev"
print_line
echo
# Compiler selection
echo -e "${YELLOW}${BOLD}Compiler Selection:${NC}"
echo -e "${DIM}─────────────────${NC}"
# Check available C compilers
declare -A c_compilers
if command -v clang >/dev/null 2>&1; then
c_compilers["clang"]=$(clang --version | head -n1)
fi
if command -v gcc >/dev/null 2>&1; then
c_compilers["gcc"]=$(gcc --version | head -n1)
fi
# Display available C compilers
echo -e "${WHITE}Available C compilers:${NC}"
i=1
declare -A c_compiler_map
for compiler in "${!c_compilers[@]}"; do
echo -e "$i) ${CYAN}${compiler}${NC} - ${DIM}${c_compilers[$compiler]}${NC}"
c_compiler_map[$i]=$compiler
((i++))
done
# Get C compiler choice
echo
read -p "Select C compiler (default: clang): " c_choice
c_choice=${c_choice:-1}
if [[ ! ${c_compiler_map[$c_choice]} ]]; then
echo -e "${RED}Invalid choice. Using default.${NC}"
c_choice=1
fi
selected_cc=${c_compiler_map[$c_choice]}
echo -e "${GREEN}Selected C compiler: ${WHITE}${selected_cc}${NC}"
# Check available C++ compilers
declare -A cxx_compilers
if command -v clang++ >/dev/null 2>&1; then
cxx_compilers["clang++"]=$(clang++ --version | head -n1)
fi
if command -v g++ >/dev/null 2>&1; then
cxx_compilers["g++"]=$(g++ --version | head -n1)
fi
# Display available C++ compilers
echo
echo -e "${WHITE}Available C++ compilers:${NC}"
i=1
declare -A cxx_compiler_map
for compiler in "${!cxx_compilers[@]}"; do
echo -e "$i) ${CYAN}${compiler}${NC} - ${DIM}${cxx_compilers[$compiler]}${NC}"
cxx_compiler_map[$i]=$compiler
((i++))
done
# Get C++ compiler choice
echo
read -p "Select C++ compiler (default: clang++): " cxx_choice
cxx_choice=${cxx_choice:-1}
if [[ ! ${cxx_compiler_map[$cxx_choice]} ]]; then
echo -e "${RED}Invalid choice. Using default.${NC}"
cxx_choice=1
fi
selected_cxx=${cxx_compiler_map[$cxx_choice]}
echo -e "${GREEN}Selected C++ compiler: ${WHITE}${selected_cxx}${NC}"
# Create build configuration
echo
echo -e "${YELLOW}${BOLD}Creating build configuration:${NC}"
echo -e "${DIM}──────────────────────────${NC}"
# Generate build_config.mk
cat > build_config.mk << EOF
# Generated by configure.sh at $(date '+%Y-%m-%d %H:%M:%S')
CC = ${selected_cc}
CXX = ${selected_cxx}
EOF
print_status 0 "Created build configuration"
# Generate Makefile from template
echo
echo -e "${YELLOW}${BOLD}Generating Makefile:${NC}"
echo -e "${DIM}─────────────────${NC}"
if [ -f "makefile.in" ]; then
sed -e "s/@CURRENT_YEAR@/$(date +%Y)/" \
-e "s/@CURRENT_USER@/$(whoami)/" \
-e "s/@CURRENT_DATE@/$(date '+%Y-%m-%d %H:%M:%S')/" \
makefile.in > Makefile
print_status 0 "Generated ${WHITE}Makefile${NC} from template"
else
print_status 1 "${WHITE}makefile.in${NC} template not found"
exit 1
fi
# Create directories
echo
echo -e "${YELLOW}${BOLD}Creating directories:${NC}"
echo -e "${DIM}───────────────────${NC}"
directories=("bin" "build" "lib")
for dir in "${directories[@]}"; do
if [ ! -d "$dir" ]; then
mkdir -p "$dir"
print_status 0 "Created ${WHITE}${dir}/${NC} directory"
else
echo -e "${CYAN}ℹ${NC} Directory ${WHITE}${dir}/${NC} already exists"
fi
done
# Configuration summary
echo
print_line
print_centered "${GREEN}${BOLD}" "Configuration Completed Successfully!"
echo
echo -e "${CYAN}${BOLD}Next steps:${NC}"
echo -e " 1. Run ${WHITE}make${NC} to build all targets"
echo -e " 2. Run ${WHITE}make install${NC} to install programs (may require sudo)"
echo -e " 3. Run ${WHITE}make clean${NC} to remove build files"
print_line
exit 0