N/A
This commit is contained in:
362
build.sh
362
build.sh
@@ -1,177 +1,273 @@
|
||||
#!/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)
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
set -euo pipefail
|
||||
# ============================================================
|
||||
# Configuration
|
||||
# ============================================================
|
||||
|
||||
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
|
||||
PATCH_FILE="$SCRIPT_DIR/joe-patch/joe-4.8-hedgedoc-0.7.13.patch"
|
||||
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="${JOE_SRC_DIR:-$BUILD_ROOT/joe-4.8}"
|
||||
JOE_SRC_DIR="$BUILD_ROOT/joe-4.8"
|
||||
GENERATED_DIR="$SCRIPT_DIR/joe-patch/generated"
|
||||
|
||||
PREFIX="${PREFIX:-$HOME/.local}"
|
||||
|
||||
CLEAN=0
|
||||
AUTORECONF=0
|
||||
# ============================================================
|
||||
# Usage
|
||||
# ============================================================
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $0 [OPTION]
|
||||
|
||||
Build patched JOE 4.8.
|
||||
|
||||
Options:
|
||||
--autoreconf Run autoreconf and update committed generated files
|
||||
--clean Remove the JOE build directory
|
||||
-h, --help Show this help
|
||||
|
||||
Normal build does NOT require autoreconf.
|
||||
EOF
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
# Arguments
|
||||
# ============================================================
|
||||
|
||||
RUN_AUTORECONF=0
|
||||
CLEAN=0
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--autoreconf)
|
||||
RUN_AUTORECONF=1
|
||||
shift
|
||||
;;
|
||||
--clean)
|
||||
CLEAN=1
|
||||
shift
|
||||
;;
|
||||
--autoreconf)
|
||||
AUTORECONF=1
|
||||
shift
|
||||
;;
|
||||
-h|--help)
|
||||
sed -n '2,17p' "$0" | sed 's/^# \{0,1\}//'
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown argument: $1" >&2
|
||||
echo "Usage: $0 [--clean] [--autoreconf]" >&2
|
||||
echo "ERROR: Unknown option: $1"
|
||||
echo
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$CLEAN" = 1 ]; then
|
||||
echo "==> --clean: removing $BUILD_ROOT"
|
||||
rm -rf "$BUILD_ROOT"
|
||||
# ============================================================
|
||||
# Clean
|
||||
# ============================================================
|
||||
|
||||
if [[ "$CLEAN" -eq 1 ]]; then
|
||||
echo "==> Removing JOE build directory"
|
||||
rm -rf "$JOE_SRC_DIR"
|
||||
echo "==> Done"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ============================================================
|
||||
# Check build tools
|
||||
# ============================================================
|
||||
|
||||
echo "==> Checking build tools"
|
||||
|
||||
missing=""
|
||||
|
||||
for cmd in git patch automake make gcc; do
|
||||
command -v "$cmd" >/dev/null 2>&1 || missing="$missing $cmd"
|
||||
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
|
||||
|
||||
# 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
|
||||
if [[ "$RUN_AUTORECONF" -eq 1 ]]; then
|
||||
if ! command -v autoreconf >/dev/null 2>&1; then
|
||||
echo "ERROR: autoreconf not found"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "==> configure --prefix=$PREFIX"
|
||||
# ============================================================
|
||||
# Prepare build directory
|
||||
# ============================================================
|
||||
|
||||
(
|
||||
cd "$JOE_SRC_DIR"
|
||||
./configure --prefix="$PREFIX"
|
||||
)
|
||||
mkdir -p "$BUILD_ROOT"
|
||||
|
||||
echo "==> make"
|
||||
# ============================================================
|
||||
# Clone JOE 4.8
|
||||
# ============================================================
|
||||
|
||||
JOBS="$(
|
||||
command -v nproc >/dev/null 2>&1 &&
|
||||
nproc ||
|
||||
echo 1
|
||||
)"
|
||||
if [[ ! -d "$JOE_SRC_DIR/.git" ]]; then
|
||||
|
||||
(
|
||||
cd "$JOE_SRC_DIR"
|
||||
make -j"$JOBS"
|
||||
)
|
||||
if [[ -e "$JOE_SRC_DIR" ]]; then
|
||||
echo "==> Removing incomplete JOE source directory"
|
||||
rm -rf "$JOE_SRC_DIR"
|
||||
fi
|
||||
|
||||
BUILT="$JOE_SRC_DIR/joe/joe"
|
||||
echo "==> Cloning JOE 4.8"
|
||||
|
||||
if [ ! -x "$BUILT" ]; then
|
||||
echo "Build finished but $BUILT isn't executable -- something's wrong." >&2
|
||||
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.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
|
||||
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"
|
||||
|
||||
cp "$JOE_SRC_DIR/configure" \
|
||||
"$GENERATED_DIR/configure"
|
||||
|
||||
cp "$JOE_SRC_DIR/Makefile.in" \
|
||||
"$GENERATED_DIR/Makefile.in"
|
||||
|
||||
cp "$JOE_SRC_DIR/aclocal.m4" \
|
||||
"$GENERATED_DIR/aclocal.m4"
|
||||
|
||||
else
|
||||
|
||||
echo "==> Using committed autotools files"
|
||||
|
||||
REQUIRED_FILES=(
|
||||
"$GENERATED_DIR/configure"
|
||||
"$GENERATED_DIR/Makefile.in"
|
||||
"$GENERATED_DIR/aclocal.m4"
|
||||
)
|
||||
|
||||
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
|
||||
echo "Built: $BUILT"
|
||||
echo "Next: ./install.sh"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user