|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +PROJECT_DIR=$(dirname "$(realpath -s "$0")") |
| 6 | + |
| 7 | +GCC_VERSION=12 |
| 8 | +GDB_VERSION=12.1 |
| 9 | +PYTHON_VERSION=3.10 |
| 10 | +GDB_ARCHS=("x86_64-linux-gnu") |
| 11 | +GDBSERVER_ARCHS=("i686-linux-gnu" "x86_64-linux-gnu" "arm-linux-gnueabi" "aarch64-linux-gnu") |
| 12 | +BUILD_PATH="${PROJECT_DIR}/build" |
| 13 | +SOURCE_DIR="${BUILD_PATH}/gdb-${GDB_VERSION}" |
| 14 | + |
| 15 | +function buildGDB() { |
| 16 | + local isGDBServer="$1" |
| 17 | + local eabi="$2" |
| 18 | + local buildPath |
| 19 | + local prefix |
| 20 | + |
| 21 | + echo "" |
| 22 | + |
| 23 | + if [ "${isGDBServer}" = true ]; then |
| 24 | + echo "[+] Building GDB server for abi: ${eabi}" |
| 25 | + prefix=gdbserver |
| 26 | + else |
| 27 | + echo "[+] Building GDB for abi: ${eabi}" |
| 28 | + prefix=gdb |
| 29 | + fi |
| 30 | + |
| 31 | + local buildPath="${BUILD_PATH}/${prefix}/${eabi}" |
| 32 | + |
| 33 | + if [[ ! -d "${buildPath}" ]]; then |
| 34 | + mkdir -p "${buildPath}" |
| 35 | + cd "${buildPath}" || exit |
| 36 | + |
| 37 | + if [ "${isGDBServer}" = true ]; then |
| 38 | + ${SOURCE_DIR}/configure \ |
| 39 | + --host="${eabi}" \ |
| 40 | + --disable-gdb \ |
| 41 | + --disable-docs \ |
| 42 | + --disable-binutils \ |
| 43 | + --disable-gas \ |
| 44 | + --disable-sim \ |
| 45 | + --disable-gprof \ |
| 46 | + --disable-inprocess-agent \ |
| 47 | + --enable-gdbserver \ |
| 48 | + --prefix="${buildPath}/binaries" \ |
| 49 | + CC="${eabi}-gcc-${GCC_VERSION}" \ |
| 50 | + CXX="${eabi}-g++-${GCC_VERSION}" \ |
| 51 | + LDFLAGS="-static -static-libstdc++" |
| 52 | + else |
| 53 | + ${SOURCE_DIR}/configure \ |
| 54 | + --host="${eabi}" \ |
| 55 | + --enable-targets=all \ |
| 56 | + --with-python=/usr/bin/python${PYTHON_VERSION} \ |
| 57 | + --disable-docs \ |
| 58 | + --disable-gdbserver \ |
| 59 | + --disable-binutils \ |
| 60 | + --disable-gas \ |
| 61 | + --disable-sim \ |
| 62 | + --disable-gprof \ |
| 63 | + --disable-inprocess-agent \ |
| 64 | + --prefix="${buildPath}/binaries" \ |
| 65 | + CC="${eabi}-gcc-${GCC_VERSION}" \ |
| 66 | + CXX="${eabi}-g++-${GCC_VERSION}" |
| 67 | + fi |
| 68 | + else |
| 69 | + cd "${buildPath}" || exit |
| 70 | + fi |
| 71 | + |
| 72 | + echo -e "\t[*] Path: ${buildPath}" |
| 73 | + |
| 74 | + make |
| 75 | + make install |
| 76 | + |
| 77 | + find ./* -maxdepth 0 -name "binaries" -prune -o -exec rm -rf {} \; |
| 78 | + mv binaries/* . |
| 79 | + rm -rf binaries |
| 80 | + |
| 81 | + echo "" |
| 82 | + |
| 83 | + cd "${PROJECT_DIR}" || exit |
| 84 | +} |
| 85 | + |
| 86 | +function downloadGDB() { |
| 87 | + local url="https://ftp.gnu.org/gnu/gdb/gdb-${GDB_VERSION}.tar.gz" |
| 88 | + local sourceDir="$1" |
| 89 | + |
| 90 | + if [[ ! -d "${sourceDir}" ]]; then |
| 91 | + mkdir -p "${sourceDir}" |
| 92 | + echo "[+] Downloading: ${url} in ${sourceDir}" |
| 93 | + wget -qO- "${url}" | tar -xz --strip-components=1 -C "${sourceDir}" |
| 94 | + fi |
| 95 | +} |
| 96 | + |
| 97 | +mkdir -p "${BUILD_PATH}" |
| 98 | + |
| 99 | +downloadGDB "${SOURCE_DIR}" |
| 100 | + |
| 101 | +# |
| 102 | +# Build gdb and gdbserver |
| 103 | +# |
| 104 | + |
| 105 | +for ABI in "${GDB_ARCHS[@]}"; do |
| 106 | + buildGDB false "${ABI}" |
| 107 | +done |
| 108 | + |
| 109 | +for ABI in "${GDBSERVER_ARCHS[@]}"; do |
| 110 | + buildGDB true "${ABI}" |
| 111 | +done |
0 commit comments