forked from hacksysteam/gdb-cross-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
122 lines (101 loc) · 3.52 KB
/
build.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
#!/usr/bin/env bash
set -e
GDB_FTP_URL="https://ftp.gnu.org/gnu/gdb/"
if [ -z "${GDB_VERSION}" ]; then
echo "[!] GDB_VERSION not provided. Fetching version from ${GDB_FTP_URL}"
GDB_VERSION=$(curl -s ${GDB_FTP_URL} | grep -o 'gdb-[0-9.]*\.tar\.gz' | sort -V | tail -1 | sed 's/gdb-\([0-9.]*\)\.tar\.gz/\1/' | tr -d '\n')
if [ -z "${GDB_VERSION}" ]; then
echo "[-] Error: GDB version not found."
exit 1
fi
fi
echo "[+] GDB version: ${GDB_VERSION}"
PROJECT_DIR=$(dirname "$(realpath -s "$0")")
GDB_ARCHS=("x86_64-linux-gnu")
GDBSERVER_ARCHS=("i686-linux-gnu" "x86_64-linux-gnu" "arm-linux-gnueabi" "aarch64-linux-gnu" "mips-linux-gnu" "mipsel-linux-gnu" "mips64-linux-gnuabi64")
BUILD_PATH="${PROJECT_DIR}/build"
SOURCE_DIR="${BUILD_PATH}/gdb-${GDB_VERSION}"
function buildGDB() {
local isGDBServer="$1"
local eabi="$2"
local buildPath
local prefix
if [ "${isGDBServer}" = true ]; then
echo "[+] Building GDB server for abi: ${eabi}"
prefix=gdbserver
else
echo "[+] Building GDB for abi: ${eabi}"
prefix=gdb
fi
local buildPath="${BUILD_PATH}/${prefix}/${eabi}"
if [[ ! -d "${buildPath}" ]]; then
mkdir -p "${buildPath}"
cd "${buildPath}" || exit
if [ "${isGDBServer}" = true ]; then
${SOURCE_DIR}/configure \
--host="${eabi}" \
--enable-gdbserver \
--disable-gdb \
--disable-docs \
--disable-binutils \
--disable-gas \
--disable-sim \
--disable-gprof \
--disable-inprocess-agent \
--prefix="${buildPath}/binaries" \
CC="${eabi}-gcc" \
CXX="${eabi}-g++" \
LDFLAGS="-static -static-libstdc++"
else
${SOURCE_DIR}/configure \
--host="${eabi}" \
--enable-targets=all \
--disable-docs \
--disable-gdbserver \
--disable-binutils \
--disable-gas \
--disable-sim \
--disable-gprof \
--disable-inprocess-agent \
--with-python=/usr/bin/python3 \
--prefix="${buildPath}/binaries" \
CC="${eabi}-gcc" \
CXX="${eabi}-g++"
fi
else
cd "${buildPath}" || exit
fi
echo "[+] Path: ${buildPath}"
make -j`nproc`
make install
find ./* -maxdepth 0 -name "binaries" -prune -o -exec rm -rf {} \;
mv binaries/* .
rm -rf binaries
if [ "${isGDBServer}" = true ]; then
OUTPUT_ARCHIVE_PATH="${buildPath}/gdbserver-${eabi}.zip"
cp ./bin/gdbserver "${BUILD_PATH}/binaries/gdbserver-${eabi}"
else
OUTPUT_ARCHIVE_PATH="${buildPath}/gdb-${eabi}.zip"
cp ./bin/gdb "${BUILD_PATH}/binaries/gdb-${eabi}"
fi
cd "${PROJECT_DIR}" || exit
}
function downloadGDB() {
local url="${GDB_FTP_URL}gdb-${GDB_VERSION}.tar.gz"
local sourceDir="$1"
if [[ ! -d "${sourceDir}" ]]; then
mkdir -p "${sourceDir}"
echo "[+] Downloading: ${url} in ${sourceDir}"
curl -sL "${url}" | tar -xz --strip-components=1 -C "${sourceDir}"
fi
}
mkdir -p "${BUILD_PATH}"
mkdir -p "${BUILD_PATH}/binaries"
downloadGDB "${SOURCE_DIR}"
# for ABI in "${GDB_ARCHS[@]}"; do
# buildGDB false "${ABI}"
# done
for ABI in "${GDBSERVER_ARCHS[@]}"; do
buildGDB true "${ABI}"
done
tar -czvf "${BUILD_PATH}/gdbserver.tar.gz" -C "${BUILD_PATH}/binaries" .