#!/usr/bin/env bash # Builds patched JOE. Does not touch anything outside this repo -- run # install.sh afterward to actually put the binary somewhere on PATH. # # Usage: # ./build.sh # ./build.sh --clean # ./build.sh --autoreconf # # --clean Remove any existing checkout under joe-patch/build/ first # (use if a previous build is in a bad state). # --autoreconf Regenerate autotools files. Normally only needed on the # development machine. The generated files are committed # to Git so the target machine does not need autoreconf. # # Env overrides: # JOE_SRC_DIR Use an existing joe source tree instead of cloning one. # Must be named .../joe-4.8 (the patch is rooted on that # directory name) and be a clean, unpatched checkout. # PREFIX configure --prefix (default: $HOME/.local) set -euo pipefail SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)" PATCH_FILE="$SCRIPT_DIR/joe-patch/joe-4.8-hedgedoc-0.7.13.patch" BUILD_ROOT="$SCRIPT_DIR/joe-patch/build" JOE_SRC_DIR="${JOE_SRC_DIR:-$BUILD_ROOT/joe-4.8}" PREFIX="${PREFIX:-$HOME/.local}" CLEAN=0 AUTORECONF=0 while [ $# -gt 0 ]; do case "$1" in --clean) CLEAN=1 shift ;; --autoreconf) AUTORECONF=1 shift ;; -h|--help) sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//' exit 0 ;; *) echo "Unknown argument: $1" >&2 echo "Usage: $0 [--clean] [--autoreconf]" >&2 exit 1 ;; esac done if [ "$CLEAN" = 1 ]; then echo "==> --clean: removing $BUILD_ROOT" rm -rf "$BUILD_ROOT" fi echo "==> Checking build tools" missing="" for cmd in git patch automake make gcc; do command -v "$cmd" >/dev/null 2>&1 || missing="$missing $cmd" done # autoreconf is only required when explicitly requested. if [ "$AUTORECONF" = 1 ]; then command -v autoreconf >/dev/null 2>&1 || missing="$missing autoreconf" fi if [ -n "$missing" ]; then echo "Missing:$missing" >&2 echo "On Debian/Ubuntu: sudo apt install build-essential automake autoconf git" >&2 exit 1 fi if [ ! -f /usr/include/ncurses.h ] && [ ! -f /usr/include/ncursesw/ncurses.h ]; then echo "Warning: ncurses headers not found in the usual places -- the build" >&2 echo "may fail linking -lncurses. On Debian/Ubuntu: sudo apt install libncurses-dev" >&2 fi if [ ! -d "$JOE_SRC_DIR" ]; then echo "==> Cloning joe 4.8 source into $JOE_SRC_DIR" mkdir -p "$BUILD_ROOT" git clone --quiet https://github.com/joe-editor/joe.git "$JOE_SRC_DIR" git -C "$JOE_SRC_DIR" checkout --quiet releases/joe-4.8 else echo "==> Using existing source at $JOE_SRC_DIR" fi if [ -f "$JOE_SRC_DIR/joe/hd_ipc.c" ]; then echo "==> Patch already applied (hd_ipc.c exists) -- skipping" else echo "==> Applying $(basename "$PATCH_FILE")" ( cd "$(dirname "$JOE_SRC_DIR")" patch -p1 < "$PATCH_FILE" ) fi if [ "$AUTORECONF" = 1 ]; then echo "==> autoreconf -fi" ( cd "$JOE_SRC_DIR" autoreconf -fi ) else echo "==> Using committed autotools files" missing_generated="" for file in \ "$JOE_SRC_DIR/configure" \ "$JOE_SRC_DIR/Makefile.in" \ "$JOE_SRC_DIR/aclocal.m4" \ "$JOE_SRC_DIR/config.h.in" do if [ ! -f "$file" ]; then missing_generated="$missing_generated $file" fi done if [ -n "$missing_generated" ]; then echo "ERROR: required generated autotools files are missing:" >&2 printf '%s\n' "$missing_generated" >&2 echo >&2 echo "Run this on the development machine:" >&2 echo " ./build.sh --autoreconf" >&2 echo >&2 echo "Then commit the generated files to Git." >&2 exit 1 fi fi echo "==> configure --prefix=$PREFIX" ( cd "$JOE_SRC_DIR" ./configure --prefix="$PREFIX" ) echo "==> make" JOBS="$( command -v nproc >/dev/null 2>&1 && nproc || echo 1 )" ( cd "$JOE_SRC_DIR" make -j"$JOBS" ) BUILT="$JOE_SRC_DIR/joe/joe" if [ ! -x "$BUILT" ]; then echo "Build finished but $BUILT isn't executable -- something's wrong." >&2 exit 1 fi if [ ! -f "$JOE_SRC_DIR/joe/hd_ipc.o" ]; then echo "Warning: $BUILT was built WITHOUT hd_ipc.o -- it's plain upstream" >&2 echo "joe, not the patched version. Check the patch/autotools step." >&2 exit 1 fi echo echo "Built: $BUILT" echo "Next: ./install.sh"