-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
build_gdb.sh
executable file
·325 lines (272 loc) · 7.43 KB
/
build_gdb.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/bin/bash
# Color codes for colored output
RED="\033[31m"
GREEN="\033[32m"
BLUE="\033[34m"
YELLOW="\033[33m"
RESET="\033[0m"
# Color codes end
# Aborts the script
abortScript() {
echo -e "${YELLOW}Aborting the script...${RESET}"
exit 2
}
# Informative echo on terminal
echoSelectedOs() {
printGreenStars
echo -e "${GREEN}Installing packages for ${BLUE}${OS}${GREEN}...${RESET}"
printGreenStars
}
# Success indicator
dependencyInstallationSuccessfull() {
printGreenStars
echo -e "${GREEN}Dependencies installed.${RESET}"
printGreenStars
}
# Failure indicator
dependencyInstallationFailed() {
printRedStars
echo -e "${RED}Error while installing dependencies!${RESET}"
printRedStars
}
# Decorative stars
printGreenStars() {
echo -e "${GREEN}*************************************************************************${RESET}"
}
printYellowStars() {
echo -e "${YELLOW}*************************************************************************${RESET}"
}
printRedStars() {
echo -e "${RED}*************************************************************************${RESET}"
}
##
# Check if the script ran with sudo privilages
if [ $EUID -ne 0 ]; then
echo -e "${RED}This script needs root privilages in order to install dependencies!"
echo -e "${BLUE}Try to run 'sudo ${0}'"
abortScript
fi
if [ -f /etc/os-release ]; then # Decide OS using /etc/os-release
. /etc/os-release
OS=$NAME
elif [ -f /etc/lsb-release ]; then # Decide OS using /etc/lsb-release
. /etc/lsb-release
OS=$DISTRIB_DESCRIPTION
else # If couldn't find OS by reading the above two files, install for unknown OS
OS="Unknown"
fi
# Check for internet connection
which ping > /dev/null
# Check for internet connection
if [ $? -eq 0 ]; then
ping -c 2 "www.google.com" > /dev/null
if [ $? -ne 0 ]; then
printRedStars
echo -e "${RED}You may not be connected to the internet."
echo -e "${YELLOW}Please check your internet connection${RESET}"
printRedStars
abortScript
fi
fi
# Install necessary dependencies for the host OS
case $OS in
"Arch Linux") # Not tested for the freshly installed system
echoSelectedOs # To do: Test for fresh arch install
echo
sleep 1
pacman -Sy
pacman -q -S --needed --noconfirm \
zlib python mpfr xz guile expat \
gcc make automake gmp wget boost
if [[ $? -ne 0 ]]; then
dependencyInstallationFailed
abortScript
else
dependencyInstallationSuccessfull
fi
echo
sleep 1
;;
"Ubuntu")
echoSelectedOs
echo
sleep 1
apt update
apt install -q -y \
gcc g++ make libgmp10 libgmp-dev \
expat libexpat1 libexpat1-dev guile-3.0 guile-3.0-dev \
lzma lzma-dev libmpfr-dev python3 zlib1g-dev zlib1g \
libpython3-dev texi2html texinfo libboost-all-dev
if [[ $? -ne 0 ]]; then
dependencyInstallationFailed
abortScript
else
dependencyInstallationSuccessfull
fi
echo
sleep 1
;;
"Debian GNU/Linux")
echoSelectedOs
echo
sleep 1
apt update
apt install -q -y \
wget tar xz-utils gcc g++ make libgmp-dev \
libexpat1 libexpat1-dev guile-3.0 guile-3.0-dev guile-3.0-libs \
texinfo lzma-dev liblzma5 libmpfr-dev libmpfr6 libmpfrc++-dev \
python3 python3-distutils python3-dev zlib1g zlib1g-dev libboost-all-dev
if [[ $? -ne 0 ]]; then
dependencyInstallationFailed
abortScript
else
dependencyInstallationSuccessfull
fi
echo
sleep 1
;;
"Unknown")
printYellowStars
echo -e "${YELLOW}Installing for an ${RED}UNKNOWN${YELLOW} system..."
echo -e "${BLUE}Some packages may be missing...${RESET}"
printYellowStars
echo
sleep 3
;;
esac
TARGET=$(echo $1 | sed 's/.*=//')
STARTING_DIR=$(pwd)
BASE_NAME="gdb-11.2"
TAR_NAME="${BASE_NAME}.tar.xz"
BUILD_DIR="${BASE_NAME}_build"
SOURCE_DIR="${BASE_NAME}_sources"
# Get sources from the GNU website
if [ ! -d ${SOURCE_DIR} ]; then
mkdir ${SOURCE_DIR}
fi
cd ${SOURCE_DIR}
if [ ! -f ./${TAR_NAME} ]; then
printGreenStars
echo -e "${GREEN}Downloading sources from the web...${RESET}"
printGreenStars
echo
sleep 1
wget https://ftp.gnu.org/gnu/gdb/${TAR_NAME}
fi
if [ $? -ne 0 ]; then
printRedStars
echo "${RED}Unable to download sources from the web.${RESET}"
printRedStars
echo
cd ..
rm -rf ${SOURCE_DIR}
if [ -f ${TAR_NAME} ]; then
rm ${TAR_NAME}
fi
abortScript
fi
printGreenStars
echo -e "${GREEN}Sources (${BLUE}${TAR_NAME}${GREEN}) are fetched from web."
echo -e "Extracting the contents of the tar file...${RESET}"
printGreenStars
echo
sleep 1
if [ -d ${BASE_NAME} ]; then
cd ${BASE_NAME}
if [ -d ${BUILD_DIR} ]; then
rm -rf ${BUILD_DIR}
else
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
fi
else
tar -xvf $TAR_NAME
if [[ $? -ne 0 ]]; then
printRedStars
echo -e "${RED}Unable to extract contents of tar file.${RESET}"
printRedStars
abortScript
fi
cd $BASE_NAME
fi
if [[ ! -d ${BUILD_DIR} ]]; then
mkdir ${BUILD_DIR}
cd ${BUILD_DIR}
else
cd ${BUILD_DIR}
fi
printGreenStars
echo -e "${GREEN}Starting Makefile configuration...${RESET}"
printGreenStars
echo
sleep 1
# $1 means --target parameter for configure script
../configure --with-python=$(which python3) --enable-interwork --enable-multilib $1
if [[ $? -ne 0 ]]; then
printRedStars
echo -e "${RED}Makefile configuration failed."
echo -e "${YELLOW}Possible --target error!"
echo -e "If you didn't pass --target argument, ignore the above comment.${RESET}"
printRedStars
abortScript
fi
printGreenStars
echo -e "${GREEN}Makefile configuration completed."
echo -e "Starting to compile...${RESET}"
printGreenStars
echo
sleep 1
make -j $(nproc) # Use all available cores for compilation
if [ $? -ne 0 ]; then
printRedStars
echo -e "${RED}Compilation failed.${RESET}"
printRedStars
echo
abortScript
fi
printGreenStars
echo -e "${GREEN}Compilation successfull.${RESET}"
printGreenStars
echo
# Copy compiled gdb files into the /etc folder
if [[ $TARGET ]]; then
cp -r ${STARTING_DIR}/${SOURCE_DIR}/${BASE_NAME}/${BUILD_DIR}/gdb /etc/${BASE_NAME}_${TARGET}
else
cp -r ${STARTING_DIR}/${SOURCE_DIR}/${BASE_NAME}/${BUILD_DIR}/gdb /etc/${BASE_NAME}
fi
printGreenStars
if [[ $TARGET ]]; then
echo -e "${GREEN}${BASE_NAME} is installed to the /etc/${BASE_NAME}_${TARGET}${RESET}"
else
echo -e "${GREEN}${BASE_NAME} is installed to the /etc/${BASE_NAME}${RESET}"
fi
printGreenStars
printGreenStars
echo -e "${GREEN}Cleaning up the sources...${RESET}"
printGreenStars
cd $STARTING_DIR
rm -rf --interactive=never ./$SOURCE_DIR
if [[ -f /usr/bin/gdbfrontend-${BASE_NAME} ]]; then
rm -rf /usr/bin/gdbfrontend-${BASE_NAME}
fi
if [[ $TARGET ]]; then
printf "#! /bin/bash\n" >> /usr/bin/gdbfrontend-${BASE_NAME}-${TARGET}
printf "gdbfrontend -g /etc/${BASE_NAME}_${TARGET}/gdb -G --data-directory=/etc/${BASE_NAME}_${TARGET}/data-directory/" >> /usr/bin/gdbfrontend-${BASE_NAME}-${TARGET}
chmod +x /usr/bin/gdbfrontend-${BASE_NAME}-${TARGET}
else
printf "# !/bin/bash\n" >> /usr/bin/gdbfrontend-${BASE_NAME}
printf "gdbfrontend -g /etc/${BASE_NAME}/gdb -G --data-directory=/etc/${BASE_NAME}/data-directory/" >> /usr/bin/gdbfrontend-${BASE_NAME}
chmod +x /usr/bin/gdbfrontend-${BASE_NAME}
fi
printGreenStars
if [[ $TARGET ]]; then
echo -e "${GREEN}Created gdbfrontend-${BASE_NAME}-${TARGET} script at /usr/bin..."
echo -e "You can run gdbfrontend by calling gdbfrontend-${BASE_NAME}-${TARGET} from terminal...${RESET}"
else
echo -e "${GREEN}Created gdbfrontend-${BASE_NAME} script at /usr/bin..."
echo -e "You can run gdbfrontend by calling gdbfrontend-${BASE_NAME} from terminal...${RESET}"
fi
printGreenStars
printGreenStars
echo -e "${GREEN}Installation completed!${RESET}"
printGreenStars