Compare commits
22 Commits
gdb-15.1-s
...
add-mips-m
Author | SHA1 | Date | |
---|---|---|---|
8dc07deb66 | |||
3738fc8629 | |||
fe4c0763e8 | |||
08909223f2 | |||
4c9cc100fb | |||
a9a044ffdc | |||
fe4ad583ae | |||
7697e5c2e1 | |||
1dc231d162 | |||
fdc2d2e4ea | |||
4cde133d93 | |||
e70ba04f32 | |||
8e323429bd | |||
0d59976a77 | |||
a3becb6943 | |||
b5e5665dd8 | |||
4347d18af5 | |||
ab0673611d | |||
3788bee966 | |||
1706882030 | |||
9ae54f03f1 | |||
aae73b4bc8 |
37
.github/workflows/pipeline.yaml
vendored
Normal file
37
.github/workflows/pipeline.yaml
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
name: gdb-static-pipeline
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: sudo apt-get install -y wget
|
||||
|
||||
- name: Build
|
||||
run: make build -j$((`nproc`+1))
|
||||
|
||||
- name: Pack
|
||||
run: make pack
|
||||
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: gdb-static
|
||||
path: build/artifacts/gdb-static*.tar.gz
|
||||
|
||||
- name: Publish release
|
||||
if: github.event_name == 'push'
|
||||
uses: softprops/action-gh-release@v2
|
||||
with:
|
||||
files: build/artifacts/gdb-static*.tar.gz
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
# IDE Folders
|
||||
.idea/
|
||||
.vscode/
|
||||
|
||||
# Build folders
|
||||
build/
|
24
Dockerfile
Normal file
24
Dockerfile
Normal file
@ -0,0 +1,24 @@
|
||||
FROM ubuntu:24.04
|
||||
|
||||
# Install dependencies
|
||||
RUN apt update && apt install -y \
|
||||
g++ \
|
||||
g++-aarch64-linux-gnu \
|
||||
g++-arm-linux-gnueabi \
|
||||
g++-mips-linux-gnu \
|
||||
g++-mipsel-linux-gnu \
|
||||
g++-powerpc-linux-gnu \
|
||||
gcc \
|
||||
gcc-aarch64-linux-gnu \
|
||||
gcc-arm-linux-gnueabi \
|
||||
gcc-mips-linux-gnu \
|
||||
gcc-mipsel-linux-gnu \
|
||||
gcc-powerpc-linux-gnu \
|
||||
m4 \
|
||||
make \
|
||||
patch \
|
||||
texinfo \
|
||||
wget \
|
||||
xz-utils
|
||||
|
||||
WORKDIR /app/gdb
|
62
Makefile
Normal file
62
Makefile
Normal file
@ -0,0 +1,62 @@
|
||||
ARCHS := x86_64 arm aarch64 powerpc mips mipsel
|
||||
TARGETS := $(addprefix build-, $(ARCHS))
|
||||
PACK_TARGETS := $(addprefix pack-, $(ARCHS))
|
||||
|
||||
.PHONY: clean help download_packages build patch-gdb build-docker-image $(TARGETS) $(PACK_TARGETS)
|
||||
|
||||
help:
|
||||
@echo "Usage:"
|
||||
@echo " make build"
|
||||
@echo ""
|
||||
|
||||
@for target in $(TARGETS); do \
|
||||
echo " $$target"; \
|
||||
done
|
||||
|
||||
@echo ""
|
||||
@echo " make clean"
|
||||
|
||||
build/build-docker-image.stamp: Dockerfile
|
||||
mkdir -p build
|
||||
docker build -t gdb-static .
|
||||
touch build/build-docker-image.stamp
|
||||
|
||||
build-docker-image: build/build-docker-image.stamp
|
||||
|
||||
build/download-packages.stamp: build/build-docker-image.stamp src/download_packages.sh
|
||||
mkdir -p build/packages
|
||||
docker run --user $(shell id -u):$(shell id -g) \
|
||||
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
|
||||
/app/gdb/src/download_packages.sh /app/gdb/build/packages
|
||||
touch build/download-packages.stamp
|
||||
|
||||
download-packages: build/download-packages.stamp
|
||||
|
||||
build/patch-gdb.stamp: build/build-docker-image.stamp src/gdb_static.patch build/download-packages.stamp
|
||||
docker run --user $(shell id -u):$(shell id -g) \
|
||||
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
|
||||
/app/gdb/src/patch_gdb.sh /app/gdb/build/packages/gdb /app/gdb/src/gdb_static.patch
|
||||
touch build/patch-gdb.stamp
|
||||
|
||||
patch-gdb: build/patch-gdb.stamp
|
||||
|
||||
build: $(TARGETS)
|
||||
|
||||
$(TARGETS): build-%: download-packages patch-gdb build-docker-image
|
||||
mkdir -p build
|
||||
docker run --user $(shell id -u):$(shell id -g) \
|
||||
--rm --volume .:/app/gdb gdb-static env TERM=xterm-256color \
|
||||
/app/gdb/src/build.sh $* /app/gdb/build/ /app/gdb/src/gdb_static.patch
|
||||
|
||||
pack: $(PACK_TARGETS)
|
||||
|
||||
$(PACK_TARGETS): pack-%: build-%
|
||||
if [ ! -f "build/artifacts/gdb-static-$*.tar.gz" ]; then \
|
||||
tar -czf "build/artifacts/gdb-static-$*.tar.gz" -C "build/artifacts/$*" .; \
|
||||
fi
|
||||
|
||||
clean:
|
||||
rm -rf build
|
||||
# Kill and remove all containers of image gdb-static
|
||||
docker ps -a | grep -P "^[a-f0-9]+\s+gdb-static\s+" | awk '{print $$1}' | xargs docker rm -f 2>/dev/null || true
|
||||
docker rmi -f gdb-static 2>/dev/null || true
|
117
README.md
117
README.md
@ -1,93 +1,54 @@
|
||||
# Repository of static gdb and gdbserver
|
||||
|
||||
The statically compiled gdb / gdbserver binaries are avaliable to download under github releases!
|
||||
## **The statically compiled gdb / gdbserver binaries are avaliable to download under github releases!**
|
||||
|
||||
# Notes about this file - read before proceeding!
|
||||
link: [gdb-static github releases](https://github.com/guyush1/gdb-static/releases)
|
||||
|
||||
While i already provided the gdb/gdbserver-15 statically compiled binaries handed out to you, some people might want to compile it to a different architecture, or compile a newer version of gdb in the future :). This rest of the file contains my compilation documentation so that you could save yourself some time and do it yourself, if you wish.
|
||||
## For manual gdb/gdbserver compilation instructions, have a look at the compilation.md file
|
||||
|
||||
## <VARAIBLES> in the script
|
||||
## Compiling gdb using docker
|
||||
|
||||
When specifying the compilation dir throughout the compilation process (specified as <COMPILATION_DIR_PATH> in this file), DO NOT use relative pathing, or bash characters such as `~`. They will not get parsed correctly! Instead, use absolute paths only.
|
||||
This repository contains a dockerfile and build scripts to compile gdb and gdbserver statically for multiple architectures.
|
||||
Currently, the supported architectures are:
|
||||
- x86_64
|
||||
- arm
|
||||
- aarch64
|
||||
- powerpc (32bit)
|
||||
You can easily expand it to support more architectures by adding the appropriate cross compilers to the dockerfile, and other build scripts.
|
||||
|
||||
Examples to the <VARIABLES> throughout the script:
|
||||
<CROSS_COMPILER_C> - arm-linux-gnueabi-gcc
|
||||
<CROSS_COMPILER_CPP> - arm-linux-gnueabi-g++
|
||||
<HOST_NAME> - arm-linux-gnueabi
|
||||
<COMPILATION_DIR_PATH> - /home/username/projects/libgmp-x.y.z/build-arm/
|
||||
NOTE: You don't need to interact with the dockerfile directly, as the Makefile will take care of everything for you.
|
||||
|
||||
Environment info:
|
||||
- glibc version: 2.39-0ubuntu8.3 (NOTE: When i compiled gdb-15 using an older glibc, such as the one i had in my ubuntu-20.04 machine, i received a segfault in gdb...).
|
||||
### Building for a specific architecture
|
||||
|
||||
# Compiling gdb statically to the host platform
|
||||
To build for a specific architecture, you can use the following command:
|
||||
```bash
|
||||
make build-<ARCH>
|
||||
```
|
||||
|
||||
## 1) Compiling iconv
|
||||
For example, to build for arm:
|
||||
```bash
|
||||
make build-arm
|
||||
```
|
||||
|
||||
While compiling iconv is not a must, the libc-provided iconv (a utility to convert between encodings) may fail on different architectures,
|
||||
at least in my experiance. Thus, I recommended using a custom libiconv and compiling it into gdb.
|
||||
The resulting binaries will be placed under the `build/artifacts/` directory.
|
||||
Each architecture will have its own directory under `build/artifacts/`. For example, the arm architecture will have the following directory structure:
|
||||
```
|
||||
build/
|
||||
artifacts/
|
||||
arm/
|
||||
...
|
||||
```
|
||||
|
||||
Download the source from https://github.com/roboticslibrary/libiconv.git
|
||||
Make sure to check out to a stable tag (in my case - v1.17).
|
||||
### Building for all architectures
|
||||
|
||||
Work according to the following steps:
|
||||
I) run `./gitsub.sh pull`
|
||||
II) run `./autogen.sh` to create the configure script from configure.sh.
|
||||
III) create a build dir (e.g build), and then cd into it.
|
||||
IV) run `../configure --enable-static`
|
||||
V) run `cp -r ./include ./lib/.libs/`
|
||||
VI) run `mkdir ./lib/.libs/lib/`
|
||||
VII) run `cp ./lib/.libs/libiconv.a ./lib/.libs/lib/`
|
||||
To build for all architectures, you can use the following command:
|
||||
```bash
|
||||
make build
|
||||
```
|
||||
|
||||
## 2) Compiling gdb
|
||||
### Cleaning the build
|
||||
|
||||
Clone gdb from sourceware - https://sourceware.org/git/binutils-gdb.git.
|
||||
I checked out to the 15.1 tag.
|
||||
|
||||
Work according to the following steps:
|
||||
I) Apply my patches - if you are not on the exact tag i used (15.1) - you might need to apply them manually.
|
||||
II) create a build dir.
|
||||
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static`
|
||||
IV) run `make all-gdb -j$(nproc)` - for gdbserver, run `make all-gdbserver -j$(nproc)`.
|
||||
|
||||
gdb will sit under gdb/gdb.
|
||||
gdbserver will sit under gdbserver/gdbserver.
|
||||
|
||||
# Cross compiling gdb statically to other architectures.
|
||||
|
||||
Cross compiling gdb statically is a bit more complicated then regular static compilation. In order to cross compile gdb statically, we will need to compile libgmp and libmpfr as well as iconv.
|
||||
|
||||
## 1) Compiling iconv
|
||||
|
||||
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
|
||||
IV) run `../configure --enable-static CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`
|
||||
|
||||
## 2) Compiling libgmp
|
||||
|
||||
Download and extract the latest edition from https://gmplib.org/.
|
||||
I used the 6.3.0 edition.
|
||||
|
||||
Work according to the following steps:
|
||||
I) Create a build dir and cd into it.
|
||||
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --host=<HOST_NAME>`
|
||||
III) run `make -j$(nproc)`
|
||||
IV) run `mkdir ./.libs/include/`
|
||||
V) run `cp gmp.h ./.libs/include/`
|
||||
VI) run `mkdir ./.libs/lib`
|
||||
VII) run `cp ./.libs/libgmp.a ./.libs/lib`
|
||||
|
||||
## 3) Compiling libmpfr
|
||||
|
||||
Download and extract the latest edition from https://www.mpfr.org/.
|
||||
I used the 4.2.1 edition.
|
||||
|
||||
Work according to the following steps:
|
||||
I) Create a build dir and cd into it.
|
||||
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --with-gmp-build=<COMPILATION_DIR_PATH> --host=<HOST_NAME>`
|
||||
III) run `make -j$(nproc)`
|
||||
IV) run `mkdir ./src/.libs/lib`
|
||||
V) run `cp ./src/.libs/libmpfr.a ./src/.libs/lib`
|
||||
|
||||
## 4) Compiling gdb
|
||||
|
||||
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
|
||||
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static --with-gmp=<COMPILATION_DIR_PATH>/.libs/ --with-mpfr=<COMPILATION_DIR_PATH>/src/.libs/ CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`
|
||||
To clean the build, you can use the following command:
|
||||
```bash
|
||||
make clean
|
||||
```
|
||||
|
91
compilation.md
Normal file
91
compilation.md
Normal file
@ -0,0 +1,91 @@
|
||||
# Notes about this file - read before proceeding!
|
||||
|
||||
While i have already provided the gdb/gdbserver-15 statically compiled binaries for you, some people might want to compile it to a different architecture (without our build scripts), or compile a newer version of gdb in the future :). The rest of the file contains a documentation of the compilation process, in order to help you out.
|
||||
|
||||
## <VARAIBLES> in the script
|
||||
|
||||
When specifying the compilation dir throughout the compilation process (specified as <COMPILATION_DIR_PATH> in this file), DO NOT use relative pathing, or bash characters such as `~`. They will not get parsed correctly! Instead, use absolute paths only.
|
||||
|
||||
Examples to the <VARIABLES> throughout the script:
|
||||
<CROSS_COMPILER_C> - arm-linux-gnueabi-gcc
|
||||
<CROSS_COMPILER_CPP> - arm-linux-gnueabi-g++
|
||||
<HOST_NAME> - arm-linux-gnueabi
|
||||
<COMPILATION_DIR_PATH> - /home/username/projects/libgmp-x.y.z/build-arm/
|
||||
|
||||
Environment info:
|
||||
- glibc version: 2.39-0ubuntu8.3 (NOTE: When i compiled gdb-15 using an older glibc, such as the one i had in my ubuntu-20.04 machine, i received a segfault in gdb...).
|
||||
|
||||
# Compiling gdb statically to the host platform
|
||||
|
||||
## 1) Compiling iconv
|
||||
|
||||
While compiling iconv is not a must, the libc-provided iconv (a utility to convert between encodings) may fail on different architectures,
|
||||
at least in my experiance. Thus, I recommended using a custom libiconv and compiling it into gdb.
|
||||
|
||||
Download the source from https://github.com/roboticslibrary/libiconv.git
|
||||
Make sure to check out to a stable tag (in my case - v1.17).
|
||||
|
||||
Work according to the following steps:
|
||||
I) run `./gitsub.sh pull`
|
||||
II) run `./autogen.sh` to create the configure script from configure.sh.
|
||||
III) create a build dir (e.g build), and then cd into it.
|
||||
IV) run `../configure --enable-static`
|
||||
V) run `cp -r ./include ./lib/.libs/`
|
||||
VI) run `mkdir ./lib/.libs/lib/`
|
||||
VII) run `cp ./lib/.libs/libiconv.a ./lib/.libs/lib/`
|
||||
|
||||
## 2) Compiling gdb
|
||||
|
||||
Clone gdb from sourceware - https://sourceware.org/git/binutils-gdb.git.
|
||||
I checked out to the 15.2 tag.
|
||||
|
||||
Work according to the following steps:
|
||||
I) Apply my patches (gdb_static.patch). If you are not on the exact tag i used (15.2) - you might need to apply them manually, and change some stuff.
|
||||
II) create a build dir.
|
||||
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static`
|
||||
IV) run `make all-gdb -j$(nproc)` - for gdbserver, run `make all-gdbserver -j$(nproc)`.
|
||||
|
||||
gdb will sit under gdb/gdb.
|
||||
gdbserver will sit under gdbserver/gdbserver.
|
||||
|
||||
# Cross compiling gdb statically to other architectures.
|
||||
|
||||
Cross compiling gdb statically is a bit more complicated then regular static compilation. In order to cross compile gdb statically, we will need to compile libgmp and libmpfr as well as iconv.
|
||||
|
||||
## 1) Compiling iconv
|
||||
|
||||
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
|
||||
IV) run `../configure --enable-static CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`
|
||||
|
||||
## 2) Compiling libgmp
|
||||
|
||||
Download and extract the latest edition from https://gmplib.org/.
|
||||
I used the 6.3.0 edition.
|
||||
|
||||
Work according to the following steps:
|
||||
I) Create a build dir and cd into it.
|
||||
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --host=<HOST_NAME>`
|
||||
III) run `make -j$(nproc)`
|
||||
IV) run `mkdir ./.libs/include/`
|
||||
V) run `cp gmp.h ./.libs/include/`
|
||||
VI) run `mkdir ./.libs/lib`
|
||||
VII) run `cp ./.libs/libgmp.a ./.libs/lib`
|
||||
|
||||
## 3) Compiling libmpfr
|
||||
|
||||
Download and extract the latest edition from https://www.mpfr.org/.
|
||||
I used the 4.2.1 edition.
|
||||
|
||||
Work according to the following steps:
|
||||
I) Create a build dir and cd into it.
|
||||
II) run `../configure CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --enable-static --with-gmp-build=<COMPILATION_DIR_PATH> --host=<HOST_NAME>`
|
||||
III) run `make -j$(nproc)`
|
||||
IV) run `mkdir ./src/.libs/lib`
|
||||
V) run `cp ./src/.libs/libmpfr.a ./src/.libs/lib`
|
||||
VI) run `mkdir ./src/.libs/include`
|
||||
VII) run `cp ../src/mpfr.h ./src/.libs/include/`
|
||||
|
||||
## 4) Compiling gdb
|
||||
|
||||
Work according to the same process as described under the compilation to the host platform, aside from the configure script:
|
||||
III) run `../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent --with-libiconv-prefix=<COMPILATION_DIR_PATH>/lib/.libs/ --with-libiconv-type=static --with-gmp=<COMPILATION_DIR_PATH>/.libs/ --with-mpfr=<COMPILATION_DIR_PATH>/src/.libs/ CC=<CROSS_COMPILER_C> CXX=<CROSS_COMPILER_CPP> --host=<HOST_NAME>`
|
394
src/build.sh
Executable file
394
src/build.sh
Executable file
@ -0,0 +1,394 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Include utils library
|
||||
script_dir=$(dirname "$0")
|
||||
. "$script_dir/utils.sh"
|
||||
|
||||
function set_compliation_variables() {
|
||||
# Set compilation variables such as which compiler to use.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: target architecture
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
supported_archs=("arm" "aarch64" "powerpc" "x86_64" "mips" "mipsel")
|
||||
|
||||
local target_arch="$1"
|
||||
|
||||
if [[ ! " ${supported_archs[@]} " =~ " ${target_arch} " ]]; then
|
||||
>&2 echo "Error: unsupported target architecture: $target_arch"
|
||||
return 1
|
||||
fi
|
||||
|
||||
>&2 fancy_title "Setting compilation variables for $target_arch"
|
||||
|
||||
if [[ "$target_arch" == "arm" ]]; then
|
||||
CROSS=arm-linux-gnueabi-
|
||||
export HOST=arm-linux-gnueabi
|
||||
elif [[ "$target_arch" == "aarch64" ]]; then
|
||||
CROSS=aarch64-linux-gnu-
|
||||
export HOST=aarch64-linux-gnu
|
||||
elif [[ "$target_arch" == "powerpc" ]]; then
|
||||
CROSS=powerpc-linux-gnu-
|
||||
export HOST=powerpc-linux-gnu
|
||||
elif [[ "$target_arch" == "mips" ]]; then
|
||||
CROSS=mips-linux-gnu-
|
||||
export HOST=mips-linux-gnu
|
||||
elif [[ "$target_arch" == "mipsel" ]]; then
|
||||
CROSS=mipsel-linux-gnu-
|
||||
export HOST=mipsel-linux-gnu
|
||||
elif [[ "$target_arch" == "x86_64" ]]; then
|
||||
CROSS=""
|
||||
export HOST=x86_64-linux-gnu
|
||||
fi
|
||||
|
||||
export CC="${CROSS}gcc"
|
||||
export CXX="${CROSS}g++"
|
||||
|
||||
export CFLAGS="-O2"
|
||||
export CXXFLAGS="-O2"
|
||||
}
|
||||
|
||||
function build_iconv() {
|
||||
# Build libiconv.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: iconv package directory
|
||||
# $2: target architecture
|
||||
#
|
||||
# Echoes:
|
||||
# The libiconv build directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local iconv_dir="$1"
|
||||
local target_arch="$2"
|
||||
local iconv_build_dir="$(realpath "$iconv_dir/build-$target_arch")"
|
||||
|
||||
echo "$iconv_build_dir"
|
||||
mkdir -p "$iconv_build_dir"
|
||||
|
||||
if [[ -f "$iconv_build_dir/lib/.libs/libiconv.a" ]]; then
|
||||
>&2 echo "Skipping build: iconv already built for $target_arch"
|
||||
return 0
|
||||
fi
|
||||
|
||||
pushd "$iconv_build_dir" > /dev/null
|
||||
|
||||
>&2 fancy_title "Building libiconv for $target_arch"
|
||||
|
||||
../configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \
|
||||
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
make -j$(nproc) 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
cp -r ./include ./lib/.libs/
|
||||
mkdir -p ./lib/.libs/lib/
|
||||
cp ./lib/.libs/libiconv.a ./lib/.libs/lib/
|
||||
|
||||
>&2 fancy_title "Finished building libiconv for $target_arch"
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function build_libgmp() {
|
||||
# Build libgmp.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: libgmp package directory
|
||||
# $2: target architecture
|
||||
#
|
||||
# Echoes:
|
||||
# The libgmp build directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local gmp_dir="$1"
|
||||
local target_arch="$2"
|
||||
local gmp_build_dir="$(realpath "$gmp_dir/build-$target_arch")"
|
||||
|
||||
echo "$gmp_build_dir"
|
||||
mkdir -p "$gmp_build_dir"
|
||||
|
||||
if [[ -f "$gmp_build_dir/.libs/lib/libgmp.a" ]]; then
|
||||
>&2 echo "Skipping build: libgmp already built for $target_arch"
|
||||
return 0
|
||||
fi
|
||||
|
||||
pushd "$gmp_build_dir" > /dev/null
|
||||
|
||||
>&2 fancy_title "Building libgmp for $target_arch"
|
||||
|
||||
../configure --enable-static "CC=$CC" "CXX=$CXX" "--host=$HOST" \
|
||||
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
make -j$(nproc) 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p ./.libs/include/
|
||||
cp gmp.h ./.libs/include/
|
||||
mkdir -p ./.libs/lib/
|
||||
cp ./.libs/libgmp.a ./.libs/lib/
|
||||
|
||||
>&2 fancy_title "Finished building libgmp for $target_arch"
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function build_libmpfr() {
|
||||
# Build libmpfr.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: mpfr package directory
|
||||
# $2: libgmp build directory
|
||||
# $3: target architecture
|
||||
#
|
||||
# Echoes:
|
||||
# The libmpfr build directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local mpfr_dir="$1"
|
||||
local libgmp_build_dir="$2"
|
||||
local target_arch="$3"
|
||||
local mpfr_build_dir="$(realpath "$mpfr_dir/build-$target_arch")"
|
||||
|
||||
mkdir -p "$mpfr_build_dir"
|
||||
echo "$mpfr_build_dir"
|
||||
|
||||
if [[ -f "$mpfr_build_dir/src/.libs/lib/libmpfr.a" ]]; then
|
||||
>&2 echo "Skipping build: libmpfr already built for $target_arch"
|
||||
return 0
|
||||
fi
|
||||
|
||||
pushd "$mpfr_dir/build-$target_arch" > /dev/null
|
||||
|
||||
>&2 fancy_title "Building libmpfr for $target_arch"
|
||||
|
||||
../configure --enable-static "--with-gmp-build=$libgmp_build_dir" \
|
||||
"CC=$CC" "CXX=$CXX" "--host=$HOST" \
|
||||
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
make -j$(nproc) 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p ./src/.libs/include
|
||||
cp ../src/mpfr.h ./src/.libs/include/
|
||||
mkdir -p ./src/.libs/lib
|
||||
cp ./src/.libs/libmpfr.a ./src/.libs/lib/
|
||||
|
||||
>&2 fancy_title "Finished building libmpfr for $target_arch"
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function build_gdb() {
|
||||
# Configure and build gdb.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: gdb directory
|
||||
# $2: target architecture
|
||||
# $3: libiconv prefix
|
||||
# $4: libgmp prefix
|
||||
# $5: libmpfr prefix
|
||||
#
|
||||
# Echoes:
|
||||
# The gdb build directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local gdb_dir="$1"
|
||||
local target_arch="$2"
|
||||
local libiconv_prefix="$3"
|
||||
local libgmp_prefix="$4"
|
||||
local libmpfr_prefix="$5"
|
||||
local gdb_build_dir="$(realpath "$gdb_dir/build-$target_arch")"
|
||||
|
||||
echo "$gdb_build_dir"
|
||||
mkdir -p "$gdb_build_dir"
|
||||
|
||||
if [[ -f "$gdb_build_dir/gdb/gdb" ]]; then
|
||||
>&2 echo "Skipping build: gdb already built for $target_arch"
|
||||
return 0
|
||||
fi
|
||||
|
||||
pushd "$gdb_build_dir" > /dev/null
|
||||
|
||||
>&2 fancy_title "Building gdb for $target_arch"
|
||||
|
||||
../configure --enable-static --with-static-standard-libraries --disable-tui --disable-inprocess-agent \
|
||||
"--with-libiconv-prefix=$libiconv_prefix" --with-libiconv-type=static \
|
||||
"--with-gmp=$libgmp_prefix" \
|
||||
"--with-mpfr=$libmpfr_prefix" \
|
||||
"CC=$CC" "CXX=$CXX" "--host=$HOST" \
|
||||
"CFLAGS=$CFLAGS" "CXXFLAGS=$CXXFLAGS" 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
make -j$(nproc) 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
>&2 fancy_title "Finished building gdb for $target_arch"
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function install_gdb() {
|
||||
# Install gdb binaries to an artifacts directory.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: gdb build directory
|
||||
# $2: artifacts directory
|
||||
# $3: target architecture
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local gdb_build_dir="$1"
|
||||
local artifacts_dir="$2"
|
||||
local target_arch="$3"
|
||||
|
||||
if [[ -d "$artifacts_dir/$target_arch" && -n "$(ls -A "$artifacts_dir/$target_arch")" ]]; then
|
||||
>&2 echo "Skipping install: gdb already installed for $target_arch"
|
||||
return 0
|
||||
fi
|
||||
|
||||
temp_artifacts_dir="$(mktemp -d)"
|
||||
|
||||
mkdir -p "$artifacts_dir/$target_arch"
|
||||
|
||||
make -C "$gdb_build_dir" install "DESTDIR=$temp_artifacts_dir" 1>&2
|
||||
if [[ $? -ne 0 ]]; then
|
||||
rm -rf "$temp_artifacts_dir"
|
||||
return 1
|
||||
fi
|
||||
|
||||
while read file; do
|
||||
cp "$file" "$artifacts_dir/$target_arch/"
|
||||
done < <(find "$temp_artifacts_dir/usr/local/bin" -type f -executable)
|
||||
|
||||
rm -rf "$temp_artifacts_dir"
|
||||
}
|
||||
|
||||
function build_and_install_gdb() {
|
||||
# Build gdb and install it to an artifacts directory.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: gdb package directory
|
||||
# $2: libiconv prefix
|
||||
# $3: libgmp prefix
|
||||
# $4: libmpfr prefix
|
||||
# $5: install directory
|
||||
# $6: target architecture
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local gdb_dir="$1"
|
||||
local libiconv_prefix="$2"
|
||||
local libgmp_prefix="$3"
|
||||
local libmpfr_prefix="$4"
|
||||
local artifacts_dir="$5"
|
||||
local target_arch="$6"
|
||||
|
||||
gdb_build_dir="$(build_gdb "$gdb_dir" "$target_arch" "$libiconv_prefix" "$libgmp_prefix" "$libmpfr_prefix")"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
install_gdb "$gdb_build_dir" "$artifacts_dir" "$target_arch"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function build_gdb_with_dependencies() {
|
||||
# Build gdb for a specific target architecture.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: target architecture
|
||||
# $2: build directory
|
||||
|
||||
local target_arch="$1"
|
||||
local build_dir="$2"
|
||||
local packages_dir="$build_dir/packages"
|
||||
local artifacts_dir="$build_dir/artifacts"
|
||||
|
||||
set_compliation_variables "$target_arch"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
mkdir -p "$packages_dir"
|
||||
|
||||
iconv_build_dir="$(build_iconv "$packages_dir/libiconv" "$target_arch")"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
gmp_build_dir="$(build_libgmp "$packages_dir/gmp" "$target_arch")"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
mpfr_build_dir="$(build_libmpfr "$packages_dir/mpfr" "$gmp_build_dir" "$target_arch")"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
build_and_install_gdb "$packages_dir/gdb" \
|
||||
"$iconv_build_dir/lib/.libs/" \
|
||||
"$gmp_build_dir/.libs/" \
|
||||
"$mpfr_build_dir/src/.libs/" \
|
||||
"$artifacts_dir" \
|
||||
"$target_arch"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
if [[ $# -ne 3 ]]; then
|
||||
>&2 echo "Usage: $0 <target_arch> <build_dir>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
build_gdb_with_dependencies "$1" "$2"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
>&2 echo "Error: failed to build gdb with dependencies"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
222
src/download_packages.sh
Executable file
222
src/download_packages.sh
Executable file
@ -0,0 +1,222 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Include utils library
|
||||
script_dir=$(dirname "$0")
|
||||
. "$script_dir/utils.sh"
|
||||
|
||||
# List of package URLs to download
|
||||
PACKAGE_URLS=(
|
||||
"https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.17.tar.gz"
|
||||
"https://ftp.gnu.org/pub/gnu/gmp/gmp-6.3.0.tar.xz"
|
||||
"https://ftp.gnu.org/pub/gnu/mpfr/mpfr-4.2.1.tar.xz"
|
||||
"https://ftp.gnu.org/gnu/gdb/gdb-15.2.tar.xz"
|
||||
)
|
||||
|
||||
function unpack_tarball() {
|
||||
# Unpack a tarball based on its extension.
|
||||
# Supported extensions: tar, gz, xz.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: tarball
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local tarball="$1"
|
||||
local extension="${tarball##*.}"
|
||||
|
||||
if [[ ! -f "$tarball" ]]; then
|
||||
>&2 echo "Error: $tarball does not exist"
|
||||
return 1
|
||||
fi
|
||||
|
||||
case "$extension" in
|
||||
tar | xz)
|
||||
tar xf "$tarball"
|
||||
;;
|
||||
gz)
|
||||
tar xzf "$tarball"
|
||||
;;
|
||||
*)
|
||||
>&2 echo "Error: unknown extension $extension"
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [[ $? -ne 0 ]]; then
|
||||
>&2 echo "Error: failed to unpack $tarball"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function download_package() {
|
||||
# Download a package. Will skip download if the output file already exists.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: URL of the package
|
||||
# $2: output file
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local url="$1"
|
||||
local output="$2"
|
||||
|
||||
if [[ -f "$output" ]]; then
|
||||
>&2 echo "Skipping download: $output already exists"
|
||||
return 0
|
||||
fi
|
||||
|
||||
wget "$url" -O "$output"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
>&2 echo "Error: failed to download $url"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function extract_package() {
|
||||
# Extract a package. Will skip extraction if the package directory already exists.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: package tarball
|
||||
# $2: output directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local tarball="$1"
|
||||
local output_dir="$2"
|
||||
local package_dir="${tarball%.tar*}"
|
||||
local tarball_realpath="$(realpath "$tarball")"
|
||||
local temp_dir="$(mktemp -d)"
|
||||
|
||||
if [[ ! -f "$tarball" ]]; then
|
||||
>&2 echo "Error: $tarball does not exist"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -d "$output_dir" ]]; then
|
||||
>&2 echo "Skipping extraction: $output_dir already exists"
|
||||
return 0
|
||||
fi
|
||||
|
||||
pushd "$temp_dir" > /dev/null
|
||||
|
||||
unpack_tarball "$tarball_realpath"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
popd > /dev/null
|
||||
return 1
|
||||
fi
|
||||
|
||||
popd > /dev/null
|
||||
|
||||
mv "$temp_dir/$package_dir" "$output_dir"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
rm -rf "$temp_dir"
|
||||
}
|
||||
|
||||
function download_and_extract_package() {
|
||||
# Download and extract a package.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: URL of the package
|
||||
# $2: output directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local url="$1"
|
||||
local output_dir="$2"
|
||||
local tarball=$(basename "$url")
|
||||
|
||||
download_package "$url" "$tarball"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
extract_package "$tarball" "$output_dir"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function package_url_to_dir() {
|
||||
# Convert a package URL to a directory name.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: package URL
|
||||
#
|
||||
# Echoes:
|
||||
# The package directory name
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local url="$1"
|
||||
|
||||
# The name of the package is the basename of the URL without the version number.
|
||||
local package_dir=$(basename "$url")
|
||||
package_dir="${package_dir%%-*}"
|
||||
|
||||
echo "$package_dir"
|
||||
}
|
||||
|
||||
function download_gdb_packages() {
|
||||
# Download and extract all required packages for building GDB.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: packages directory
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local packages_dir="$1"
|
||||
pushd "$packages_dir"
|
||||
|
||||
# Run downloads in parallel
|
||||
download_pids=()
|
||||
|
||||
fancy_title "Starting download of GDB packages"
|
||||
|
||||
for url in "${PACKAGE_URLS[@]}"; do
|
||||
package_dir=$(package_url_to_dir "$url")
|
||||
download_and_extract_package "$url" "$package_dir" &
|
||||
download_pids+=($!)
|
||||
done
|
||||
|
||||
for pid in "${download_pids[@]}"; do
|
||||
wait "$pid"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
popd
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
fancy_title "Finished downloading GDB packages"
|
||||
|
||||
popd
|
||||
}
|
||||
|
||||
function main() {
|
||||
if [[ $# -ne 1 ]]; then
|
||||
>&2 echo "Usage: $0 <packages_dir>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
download_gdb_packages "$1"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
>&2 echo "Error: failed to download GDB packages"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
70
src/gdb_static.patch
Normal file
70
src/gdb_static.patch
Normal file
@ -0,0 +1,70 @@
|
||||
diff --git a/Makefile.in b/Makefile.in
|
||||
index f12c251f9c8..eed512b2d18 100644
|
||||
--- a/Makefile.in
|
||||
+++ b/Makefile.in
|
||||
@@ -31593,7 +31593,7 @@ configure-readline:
|
||||
$$s/$$module_srcdir/configure \
|
||||
--srcdir=$${topdir}/$$module_srcdir \
|
||||
$(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
|
||||
- --target=${target_alias} \
|
||||
+ --target=${target_alias} --enable-static \
|
||||
|| exit 1
|
||||
@endif readline
|
||||
|
||||
@@ -40793,7 +40793,7 @@ configure-libcc1:
|
||||
$$s/$$module_srcdir/configure \
|
||||
--srcdir=$${topdir}/$$module_srcdir \
|
||||
$(HOST_CONFIGARGS) --build=${build_alias} --host=${host_alias} \
|
||||
- --target=${target_alias} --enable-shared \
|
||||
+ --target=${target_alias} --enable-static --disable-shared \
|
||||
|| exit 1
|
||||
@endif libcc1
|
||||
|
||||
diff --git a/configure b/configure
|
||||
index 6466b97f3ec..2ab23dcb81e 100755
|
||||
--- a/configure
|
||||
+++ b/configure
|
||||
@@ -9398,7 +9398,7 @@ case " $configdirs " in
|
||||
*" lto-plugin "* | *" libcc1 "* | *" gdbserver "*)
|
||||
# When these are to be built as shared libraries, the same applies to
|
||||
# libiberty.
|
||||
- extra_host_libiberty_configure_flags=--enable-shared
|
||||
+ extra_host_libiberty_configure_flags="--enable-static --disable-shared"
|
||||
;;
|
||||
esac
|
||||
|
||||
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
|
||||
index 84bc54b303e..c81269ced78 100644
|
||||
--- a/gdb/Makefile.in
|
||||
+++ b/gdb/Makefile.in
|
||||
@@ -148,7 +148,7 @@ LIBTOOL = @LIBTOOL@
|
||||
# Set this up with gcc if you have gnu ld and the loader will print out
|
||||
# line numbers for undefined references.
|
||||
#CC_LD = g++ -static
|
||||
-CC_LD = $(LIBTOOL) $(SILENT_FLAG) --mode=link $(CXX) $(CXX_DIALECT)
|
||||
+CC_LD = $(LIBTOOL) $(SILENT_FLAG) --mode=link $(CXX) -all-static $(CXX_DIALECT)
|
||||
|
||||
# Where is our "include" directory? Typically $(srcdir)/../include.
|
||||
# This is essentially the header file directory for the library
|
||||
diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in
|
||||
index 6148ccf9121..2a9c9720d1a 100644
|
||||
--- a/gdbserver/Makefile.in
|
||||
+++ b/gdbserver/Makefile.in
|
||||
@@ -83,7 +83,7 @@ COMPILE = $(ECHO_CXX) $(COMPILE.pre) $(INTERNAL_CFLAGS) $(INCLUDE_SERVER_H) \
|
||||
# Set this up with gcc if you have gnu ld and the loader will print out
|
||||
# line numbers for undefinded refs.
|
||||
#CC_LD = g++ -static
|
||||
-CC_LD = $(CXX) $(CXX_DIALECT)
|
||||
+CC_LD = $(CXX) -static $(CXX_DIALECT)
|
||||
|
||||
# Where is the "include" directory? Traditionally ../include or ./include
|
||||
INCLUDE_DIR = ${srcdir}/../include
|
||||
@@ -405,7 +405,7 @@ IPA_LIB = libinproctrace.so
|
||||
|
||||
$(IPA_LIB): $(sort $(IPA_OBJS)) ${CDEPS}
|
||||
$(SILENCE) rm -f $(IPA_LIB)
|
||||
- $(ECHO_CXXLD) $(CC_LD) -shared -fPIC -Wl,--soname=$(IPA_LIB) \
|
||||
+ $(ECHO_CXXLD) $(CC_LD) -static -fPIC -Wl,--soname=$(IPA_LIB) \
|
||||
-Wl,--no-undefined $(INTERNAL_CFLAGS) $(INTERNAL_LDFLAGS) \
|
||||
$(CXXFLAGS) \
|
||||
-o $(IPA_LIB) ${IPA_OBJS} $(LIBIBERTY_FOR_SHLIB) -ldl -pthread
|
57
src/patch_gdb.sh
Executable file
57
src/patch_gdb.sh
Executable file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Include utils library
|
||||
script_dir=$(dirname "$0")
|
||||
. "$script_dir/utils.sh"
|
||||
|
||||
function apply_patch() {
|
||||
# Apply a patch to a directory.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: directory
|
||||
# $2: path of patch
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
# 1: failure
|
||||
|
||||
local dir="$1"
|
||||
local patch="$(realpath "$2")"
|
||||
|
||||
pushd "$dir" > /dev/null
|
||||
if [[ $? -ne 0 ]]; then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if the patch was already applied
|
||||
if ! patch -p1 --dry-run < "$patch" &>/dev/null; then
|
||||
>&2 echo "Error: patch already applied"
|
||||
popd > /dev/null
|
||||
return 1
|
||||
fi
|
||||
|
||||
patch -p1 < "$patch"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
popd > /dev/null
|
||||
return 1
|
||||
fi
|
||||
|
||||
popd > /dev/null
|
||||
}
|
||||
|
||||
function main() {
|
||||
if [[ $# -ne 2 ]]; then
|
||||
>&2 echo "Usage: $0 <gdb_dir> <gdb_patch>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
fancy_title "Applying GDB patch"
|
||||
apply_patch "$1" "$2"
|
||||
if [[ $? -ne 0 ]]; then
|
||||
>&2 echo "Error: failed to apply GDB patch"
|
||||
exit 1
|
||||
fi
|
||||
fancy_title "Finished applying GDB patch"
|
||||
}
|
||||
|
||||
main "$@"
|
67
src/utils.sh
Executable file
67
src/utils.sh
Executable file
@ -0,0 +1,67 @@
|
||||
#!/bin/bash
|
||||
|
||||
GREEN="\033[0;32m"
|
||||
BOLD="\033[1m"
|
||||
RESET="\033[0m"
|
||||
|
||||
function print_centered() {
|
||||
# Print a string centered in the terminal.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: string
|
||||
# $2: line width
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
|
||||
local string="$1"
|
||||
local length=${#string}
|
||||
|
||||
printf "%*s\n" $((($2 + length) / 2)) "$string"
|
||||
}
|
||||
|
||||
function fancy_title() {
|
||||
# Print a fancy title.
|
||||
# The title is centered and surrounded by a line of dashes.
|
||||
#
|
||||
# Parameters:
|
||||
# $1: title
|
||||
#
|
||||
# Returns:
|
||||
# 0: success
|
||||
|
||||
local title="$1"
|
||||
local length=80
|
||||
local maximum_title_length=60
|
||||
|
||||
# Set color to green and bold
|
||||
tput setaf 2
|
||||
tput bold
|
||||
|
||||
printf "%${length}s\n" | tr ' ' -
|
||||
|
||||
# Split the title into words and print them centered
|
||||
IFS=' ' read -r -a words <<< "$title"
|
||||
|
||||
line=""
|
||||
for word in "${words[@]}"; do
|
||||
if [[ ${#line} -eq 0 ]]; then
|
||||
line="$word"
|
||||
elif [[ $(( ${#line} + ${#word} + 1 )) -gt $maximum_title_length ]]; then
|
||||
print_centered "$line" "$length"
|
||||
line="$word"
|
||||
else
|
||||
line="$line $word"
|
||||
fi
|
||||
done
|
||||
|
||||
# Print the last line
|
||||
if [[ ${#line} -gt 0 ]]; then
|
||||
print_centered "$line" "$length"
|
||||
fi
|
||||
|
||||
printf "%${length}s\n" | tr ' ' -
|
||||
|
||||
# Reset color and style
|
||||
tput sgr0
|
||||
}
|
Reference in New Issue
Block a user