diff --git a/src/build.sh b/src/build.sh index 2e77fb0..b2a6436 100755 --- a/src/build.sh +++ b/src/build.sh @@ -1,5 +1,9 @@ #!/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. # @@ -18,6 +22,8 @@ function set_compliation_variables() { 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 @@ -67,6 +73,8 @@ function build_iconv() { 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 @@ -82,6 +90,8 @@ function build_iconv() { 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 } @@ -113,6 +123,8 @@ function build_libgmp() { 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 @@ -129,6 +141,8 @@ function build_libgmp() { mkdir -p ./.libs/lib/ cp ./.libs/libgmp.a ./.libs/lib/ + >&2 fancy_title "Finished building libgmp for $target_arch" + popd > /dev/null } @@ -162,6 +176,8 @@ function build_libmpfr() { 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 @@ -179,6 +195,8 @@ function build_libmpfr() { 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 } @@ -216,6 +234,8 @@ function build_gdb() { 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" \ @@ -231,6 +251,8 @@ function build_gdb() { return 1 fi + >&2 fancy_title "Finished building gdb for $target_arch" + popd > /dev/null } diff --git a/src/download_packages.sh b/src/download_packages.sh index 7465b55..e1488cd 100755 --- a/src/download_packages.sh +++ b/src/download_packages.sh @@ -1,5 +1,9 @@ #!/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" @@ -181,6 +185,8 @@ function download_gdb_packages() { # 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" & @@ -195,6 +201,8 @@ function download_gdb_packages() { fi done + fancy_title "Finished downloading GDB packages" + popd } diff --git a/src/patch_gdb.sh b/src/patch_gdb.sh index 2699695..164dcc6 100755 --- a/src/patch_gdb.sh +++ b/src/patch_gdb.sh @@ -1,5 +1,9 @@ #!/bin/bash +# Include utils library +script_dir=$(dirname "$0") +. "$script_dir/utils.sh" + function apply_patch() { # Apply a patch to a directory. # @@ -41,11 +45,13 @@ function main() { 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 "$@" diff --git a/src/utils.sh b/src/utils.sh new file mode 100755 index 0000000..a33c1ab --- /dev/null +++ b/src/utils.sh @@ -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 +}