|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Automatically exit on error |
| 4 | +set -e |
| 5 | + |
| 6 | +COUNTER_STEP=0 |
| 7 | +COUNTER_SUBSTEP=0 |
| 8 | +BLUE="\e[34m" |
| 9 | +BOLD="\e[1m" |
| 10 | +NORMAL="\e[0m" |
| 11 | + |
| 12 | +UNCRUSTIFY_VERSION="0.76.0" |
| 13 | +UNCRUSTIFY_SHA256="32e2f95485a933fc5667880f1a09a964ae83132c235bb606abbb0a659453acb3" |
| 14 | +UNCRUSTIFY_URL="https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-$UNCRUSTIFY_VERSION.tar.gz" |
| 15 | + |
| 16 | +step() { |
| 17 | + COUNTER_SUBSTEP=0 |
| 18 | + COUNTER_STEP=$(("$COUNTER_STEP" + 1)) |
| 19 | + printf "${BLUE}${BOLD}==>${NORMAL}${BOLD} Step %d:${NORMAL} %s\n" "$COUNTER_STEP" "$1" |
| 20 | +} |
| 21 | + |
| 22 | +substep() { |
| 23 | + COUNTER_SUBSTEP=$(("$COUNTER_SUBSTEP" + 1)) |
| 24 | + printf "${BLUE}${BOLD} -->${NORMAL}${BOLD} Step %d.%d:${NORMAL} %s\n" \ |
| 25 | + "$COUNTER_STEP" "$COUNTER_SUBSTEP" "$1" |
| 26 | +} |
| 27 | + |
| 28 | +step_prepare_apt() { |
| 29 | + step "Updating apt package index" |
| 30 | + apt-get update |
| 31 | +} |
| 32 | + |
| 33 | +step_install_apt_packages() { |
| 34 | + step "Installing packages via apt package manager" |
| 35 | + |
| 36 | + substep "Installing base shell utilities" |
| 37 | + apt-get -y --no-install-recommends install wget less pcregrep |
| 38 | + |
| 39 | + substep "Installing tools to generate documentation" |
| 40 | + apt-get -y --no-install-recommends install make doxygen graphviz |
| 41 | + |
| 42 | + substep "Installing linting tools" |
| 43 | + apt-get -y --no-install-recommends install coccinelle cppcheck shellcheck vera++ |
| 44 | +} |
| 45 | + |
| 46 | +step_install_pip_packages() { |
| 47 | + step "Installing python packages via pip" |
| 48 | + pip3 install --no-cache-dir -r requirements.txt |
| 49 | +} |
| 50 | + |
| 51 | +step_build_uncrustify() { |
| 52 | + step "Building uncrustify" |
| 53 | + |
| 54 | + local olddir |
| 55 | + olddir="$(pwd)" |
| 56 | + |
| 57 | + substep "Installing build requirements" |
| 58 | + apt-get -y --no-install-recommends install cmake g++ |
| 59 | + |
| 60 | + substep "Preparing build dir and downloading source" |
| 61 | + cd /tmp |
| 62 | + wget "$UNCRUSTIFY_URL" |
| 63 | + |
| 64 | + substep "Verifying and unpacking source" |
| 65 | + echo "$UNCRUSTIFY_SHA256 $(basename "$UNCRUSTIFY_URL")" | sha256sum -c - |
| 66 | + tar xf "$(basename "$UNCRUSTIFY_URL")" |
| 67 | + mkdir "uncrustify-uncrustify-$UNCRUSTIFY_VERSION"/build |
| 68 | + cd "uncrustify-uncrustify-$UNCRUSTIFY_VERSION"/build |
| 69 | + |
| 70 | + substep "Running cmake" |
| 71 | + cmake .. -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" -DCMAKE_EXE_LINKER_FLAGS="-static" |
| 72 | + |
| 73 | + substep "Running make" |
| 74 | + make |
| 75 | + |
| 76 | + substep "Strip and install binary" |
| 77 | + strip uncrustify |
| 78 | + install -Dm755 uncrustify /usr/bin/uncrustify |
| 79 | + |
| 80 | + substep "Cleaning up build files and removing build dependencies" |
| 81 | + cd "$olddir" |
| 82 | + apt-get -y purge cmake g++ |
| 83 | + rm -rf /tmp/uncrustify-* |
| 84 | +} |
| 85 | + |
| 86 | +step_clean_apt() { |
| 87 | + step "Cleaning up apt package index and temporary files" |
| 88 | + apt-get clean |
| 89 | + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* |
| 90 | +} |
| 91 | + |
| 92 | +step_prepare_apt |
| 93 | +step_install_apt_packages |
| 94 | +step_install_pip_packages |
| 95 | +step_build_uncrustify |
| 96 | +step_clean_apt |
| 97 | +exit 0 |
0 commit comments