#!/bin/bash set -e # ============================================================ # Configuration # ============================================================ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PATCH_FILE="$SCRIPT_DIR/joe-patch/joe.patch" BUILD_ROOT="$SCRIPT_DIR/joe-patch/build" JOE_SRC_DIR="$BUILD_ROOT/joe-4.8" GENERATED_DIR="$SCRIPT_DIR/joe-patch/generated" PREFIX="${PREFIX:-$HOME/.local}" # ============================================================ # Usage # ============================================================ usage() { cat < Removing JOE build directory" rm -rf "$JOE_SRC_DIR" echo "==> Done" exit 0 fi # ============================================================ # Check build tools # ============================================================ echo "==> Checking build tools" for tool in git patch automake make gcc; do if ! command -v "$tool" >/dev/null 2>&1; then echo "ERROR: required tool not found: $tool" exit 1 fi done if [[ "$RUN_AUTORECONF" -eq 1 ]]; then if ! command -v autoreconf >/dev/null 2>&1; then echo "ERROR: autoreconf not found" exit 1 fi fi # ============================================================ # Prepare build directory # ============================================================ mkdir -p "$BUILD_ROOT" # ============================================================ # Clone JOE 4.8 # ============================================================ if [[ ! -d "$JOE_SRC_DIR/.git" ]]; then if [[ -e "$JOE_SRC_DIR" ]]; then echo "==> Removing incomplete JOE source directory" rm -rf "$JOE_SRC_DIR" fi echo "==> Cloning JOE 4.8" git clone \ https://github.com/joe-editor/joe.git \ "$JOE_SRC_DIR" ( cd "$JOE_SRC_DIR" git checkout releases/joe-4.8 ) else echo "==> Using existing JOE source at $JOE_SRC_DIR" fi # ============================================================ # Apply patch # ============================================================ if [[ ! -f "$PATCH_FILE" ]]; then echo "ERROR: patch file not found:" echo " $PATCH_FILE" exit 1 fi if [[ -f "$JOE_SRC_DIR/joe/hd_ipc.c" ]]; then echo "==> Patch already applied (hd_ipc.c exists) -- skipping" else echo "==> Applying patch" ( cd "$JOE_SRC_DIR" patch -p1 < "$PATCH_FILE" ) fi # ============================================================ # Autotools # ============================================================ if [[ "$RUN_AUTORECONF" -eq 1 ]]; then echo "==> Running autoreconf" ( cd "$JOE_SRC_DIR" autoreconf -fi ) echo "==> Updating committed generated files" mkdir -p "$GENERATED_DIR" for file in \ configure \ Makefile.in \ aclocal.m4 \ compile \ install-sh \ config.guess \ config.sub do cp "$GENERATED_DIR/$file" "$JOE_SRC_DIR/$file" done else echo "==> Using committed autotools files" REQUIRED_FILES=( "$GENERATED_DIR/configure" "$GENERATED_DIR/Makefile.in" "$GENERATED_DIR/aclocal.m4" "$GENERATED_DIR/compile" "$GENERATED_DIR/install-sh" "$GENERATED_DIR/config.guess" "$GENERATED_DIR/config.sub" ) missing=0 for file in "${REQUIRED_FILES[@]}"; do if [[ ! -f "$file" ]]; then echo "ERROR: required generated file is missing:" echo " $file" missing=1 fi done if [[ "$missing" -ne 0 ]]; then echo echo "Run this on the development machine:" echo " ./build.sh --autoreconf" echo echo "Then commit the files in:" echo " joe-patch/generated/" exit 1 fi echo "==> Installing committed autotools files into JOE source" cp "$GENERATED_DIR/configure" \ "$JOE_SRC_DIR/configure" cp "$GENERATED_DIR/Makefile.in" \ "$JOE_SRC_DIR/Makefile.in" cp "$GENERATED_DIR/aclocal.m4" \ "$JOE_SRC_DIR/aclocal.m4" chmod +x "$JOE_SRC_DIR/configure" fi # ============================================================ # Configure # ============================================================ echo "==> Configuring JOE" ( cd "$JOE_SRC_DIR" ./configure \ --prefix="$PREFIX" ) # ============================================================ # Build # ============================================================ echo "==> Building JOE" ( cd "$JOE_SRC_DIR" make -j"$(nproc)" ) # ============================================================ # Verify # ============================================================ if [[ ! -x "$JOE_SRC_DIR/joe/joe" ]]; then echo "ERROR: JOE binary was not built" exit 1 fi if [[ ! -f "$JOE_SRC_DIR/joe/hd_ipc.o" ]]; then echo "ERROR: hd_ipc.o was not built" exit 1 fi # ============================================================ # Done # ============================================================ echo echo "============================================================" echo "Build successful" echo "============================================================" echo echo "JOE binary:" echo " $JOE_SRC_DIR/joe/joe" echo echo "Next step:" echo " ./install.sh" echo