198 lines
3.4 KiB
Bash
Executable File
198 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
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"
|
|
|
|
PREFIX="$HOME/.local"
|
|
|
|
AUTORECONF=0
|
|
CLEAN=0
|
|
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--autoreconf)
|
|
AUTORECONF=1
|
|
;;
|
|
--clean)
|
|
CLEAN=1
|
|
;;
|
|
-h|--help)
|
|
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 "Unknown option: $arg"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
|
|
echo "==> Checking build tools"
|
|
|
|
for tool in git patch make gcc sed; do
|
|
if ! command -v "$tool" >/dev/null 2>&1; then
|
|
echo "ERROR: '$tool' not found"
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
if [[ "$AUTORECONF" -eq 1 ]]; then
|
|
if ! command -v autoreconf >/dev/null 2>&1; then
|
|
echo "ERROR: 'autoreconf' not found"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
|
|
if [[ "$CLEAN" -eq 1 ]]; then
|
|
echo "==> Cleaning build directory"
|
|
rm -rf "$BUILD_ROOT"
|
|
fi
|
|
|
|
|
|
mkdir -p "$BUILD_ROOT"
|
|
|
|
|
|
echo "==> Getting JOE source"
|
|
|
|
if [[ ! -d "$JOE_SRC_DIR/.git" ]]; then
|
|
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
|
|
|
|
|
|
#
|
|
# 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"
|
|
|
|
(
|
|
cd "$JOE_SRC_DIR"
|
|
autoreconf -fi
|
|
)
|
|
|
|
echo "==> Updating generated Autotools files"
|
|
|
|
rm -rf "$GENERATED_DIR"
|
|
mkdir -p "$GENERATED_DIR"
|
|
|
|
(
|
|
cd "$JOE_SRC_DIR"
|
|
|
|
cp -r \
|
|
aclocal.m4 \
|
|
configure \
|
|
Makefile.in \
|
|
compile \
|
|
config.guess \
|
|
config.sub \
|
|
install-sh \
|
|
missing \
|
|
depcomp \
|
|
joe/Makefile.in \
|
|
"$GENERATED_DIR/"
|
|
)
|
|
|
|
echo
|
|
echo "Generated files updated in:"
|
|
echo " $GENERATED_DIR"
|
|
echo
|
|
fi
|
|
|
|
|
|
#
|
|
# 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"
|
|
|
|
sed -i \
|
|
's/stdin = fopen("\/dev\/tty", "rb");/freopen("\/dev\/tty", "rb", stdin);/' \
|
|
joe/main.c
|
|
)
|
|
|
|
|
|
echo "==> Configuring"
|
|
|
|
(
|
|
cd "$JOE_SRC_DIR"
|
|
|
|
./configure --prefix="$PREFIX"
|
|
)
|
|
|
|
|
|
echo "==> Building"
|
|
|
|
(
|
|
cd "$JOE_SRC_DIR"
|
|
|
|
make -j"$(nproc)"
|
|
)
|
|
|
|
|
|
echo
|
|
echo "==> Build complete"
|
|
echo
|
|
echo "Binary:"
|
|
echo " $JOE_SRC_DIR/joe/joe"
|
|
echo
|
|
echo "To install:"
|
|
echo " $JOE_SRC_DIR/joe/joe"
|
|
echo
|
|
|