This commit is contained in:
Joakim
2026-10-17 16:17:00 +02:00
parent 755c62fa67
commit ab6bddd91f

279
build.sh
View File

@@ -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 <<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
AUTORECONF=0
CLEAN=0
while [[ $# -gt 0 ]]; do
case "$1" in
for arg in "$@"; do
case "$arg" in
--autoreconf)
RUN_AUTORECONF=1
shift
AUTORECONF=1
;;
--clean)
CLEAN=1
shift
;;
-h|--help)
usage
echo "Usage: $0 [--autoreconf] [--clean]"
echo
echo " --autoreconf Run autoreconf and update joe-patch/generated/"
echo " --clean Remove the build directory before building"
exit 0
;;
*)
echo "ERROR: Unknown option: $1"
echo
usage
echo "Unknown option: $arg"
exit 1
;;
esac
done
# ============================================================
# 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"
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 \
(
cd "$JOE_SRC_DIR"
cp -r \
aclocal.m4 \
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/"
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"
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
echo
echo "Generated files updated in:"
echo " $GENERATED_DIR"
echo
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/"
#
# 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
echo "==> Installing committed autotools files into JOE source"
cp -r "$GENERATED_DIR"/* "$JOE_SRC_DIR/"
cp "$GENERATED_DIR/configure" \
"$JOE_SRC_DIR/configure"
cp "$GENERATED_DIR/Makefile.in" \
"$JOE_SRC_DIR/Makefile.in"
#
# Apply our JOE patch.
#
if [[ -f "$JOE_SRC_DIR/joe/hd_ipc.c" ]]; then
echo "==> Patch already applied"
else
echo "==> Applying patch"
cp "$GENERATED_DIR/aclocal.m4" \
"$JOE_SRC_DIR/aclocal.m4"
chmod +x "$JOE_SRC_DIR/configure"
(
cd "$BUILD_ROOT"
pwd
patch -p1 < "$PATCH_FILE"
)
fi
# ============================================================
# Configure
# ============================================================
echo "==> Configuring JOE"
#
# 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
```