diff --git a/build.sh b/build.sh index 18633bc..88869d7 100755 --- a/build.sh +++ b/build.sh @@ -1,158 +1,92 @@ +```bash #!/bin/bash -set -e -# ============================================================ -# Configuration -# ============================================================ +set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PATCH_FILE="$SCRIPT_DIR/joe-patch/joe.patch" +GENERATED_DIR="$SCRIPT_DIR/joe-patch/generated" 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}" +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 +for tool in git patch make gcc sed; do if ! command -v "$tool" >/dev/null 2>&1; then - echo "ERROR: required tool not found: $tool" + echo "ERROR: '$tool' not found" exit 1 fi done -if [[ "$RUN_AUTORECONF" -eq 1 ]]; then +if [[ "$AUTORECONF" -eq 1 ]]; then if ! command -v autoreconf >/dev/null 2>&1; then - echo "ERROR: autoreconf not found" + echo "ERROR: 'autoreconf' not found" exit 1 fi fi -# ============================================================ -# Prepare build directory -# ============================================================ + +if [[ "$CLEAN" -eq 1 ]]; then + echo "==> Cleaning build directory" + rm -rf "$BUILD_ROOT" +fi + mkdir -p "$BUILD_ROOT" -# ============================================================ -# Clone JOE 4.8 -# ============================================================ + +echo "==> Getting JOE source" 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" + 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 +# +# Generate Autotools files. +# +# This is intended to be run on the development machine +# (e.g. Cameron), not on Lyra. +# +if [[ "$AUTORECONF" -eq 1 ]]; then echo "==> Running autoreconf" ( @@ -160,129 +94,106 @@ if [[ "$RUN_AUTORECONF" -eq 1 ]]; then autoreconf -fi ) - echo "==> Updating committed generated files" + echo "==> Updating generated Autotools files" + rm -rf "$GENERATED_DIR" mkdir -p "$GENERATED_DIR" - for file in \ - configure \ - Makefile.in \ - aclocal.m4 \ - compile \ - install-sh \ - config.guess \ - config.sub \ - missing - do - cp "$GENERATED_DIR/$file" "$JOE_SRC_DIR/$file" - done - cp "$GENERATED_DIR/joe/Makefile.am" "$JOE_SRC_DIR/joe/" - cp "$GENERATED_DIR/joe/Makefile.in" "$JOE_SRC_DIR/joe/" - cp "$GENERATED_DIR/joe/util/Makefile.in" "$JOE_SRC_DIR/joe/util/" + ( + cd "$JOE_SRC_DIR" -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" - "$GENERATED_DIR/missing" - "$GENERATED_DIR/joe/Makefile.am" - "$GENERATED_DIR/joe/Makefile.in" - "$GENERATED_DIR/joe/util/Makefile.in" + cp -r \ + aclocal.m4 \ + configure \ + Makefile.in \ + compile \ + config.guess \ + config.sub \ + install-sh \ + missing \ + depcomp \ + joe/Makefile.in \ + "$GENERATED_DIR/" ) - 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" + echo + echo "Generated files updated in:" + echo " $GENERATED_DIR" + echo fi -# ============================================================ -# Configure -# ============================================================ -echo "==> Configuring JOE" +# +# The generated files are committed to Git. +# Copy them into the JOE source tree. +# +echo "==> Installing generated Autotools files" + +if [[ ! -d "$GENERATED_DIR" ]]; then + echo "ERROR: Generated directory does not exist:" + echo " $GENERATED_DIR" + exit 1 +fi + +cp -r "$GENERATED_DIR"/* "$JOE_SRC_DIR/" + + +# +# Apply our JOE patch. +# +if [[ -f "$JOE_SRC_DIR/joe/hd_ipc.c" ]]; then + echo "==> Patch already applied" +else + echo "==> Applying patch" + + ( + cd "$BUILD_ROOT" + pwd + patch -p1 < "$PATCH_FILE" + ) +fi + + +# +# Fix JOE for musl. +# +echo "==> Applying musl stdin fix" ( cd "$JOE_SRC_DIR" - ./configure \ - --prefix="$PREFIX" + sed -i \ + 's/stdin = fopen("\/dev\/tty", "rb");/freopen("\/dev\/tty", "rb", stdin);/' \ + joe/main.c ) -# ============================================================ -# Build -# ============================================================ -echo "==> Building JOE" +echo "==> Configuring" ( cd "$JOE_SRC_DIR" + + ./configure --prefix="$PREFIX" +) + + +echo "==> Building" + +( + 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 "==> Build complete" echo -echo "JOE binary:" +echo "Binary:" echo " $JOE_SRC_DIR/joe/joe" echo -echo "Next step:" -echo " ./install.sh" +echo "To install:" +echo " $JOE_SRC_DIR/joe/joe" echo +```