Files
json-c/amiga/package-amiga.sh
T
Cameron Armstrong (Nightfox)andClaude Opus 5.5 b48717e6d0 Amiga: only take the bundle version from an exact release tag
json-c tags releases on json-c-0.NN branches that are never merged back
to master, so `git describe --tags` from master finds the last release
tagged on master itself (0.17) and the readme claimed that version.
Use the tag only when HEAD is exactly on it, otherwise use the
JSON_C_VERSION from json_c_version.h plus the short commit hash.

Also terminate the sed `p` command with `;` before `}` so the version
extraction works with BSD/macOS sed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 10:34:00 -05:00

85 lines
3.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build every json-c variant for the requested Amiga systems and package them
# into dist/json-c.lha.
#
# ./amiga/package-amiga.sh [OS ...] # default: all three
#
# Archive layout (single directory at the root):
# json-c/json-c.readme
# json-c/AmigaOS3/... per-OS libraries and headers
# json-c/AmigaOS4/...
# json-c/MorphOS/...
set -uo pipefail
AMIGA_DIR=$(cd "$(dirname "$0")" && pwd)
ROOT=$(cd "$AMIGA_DIR/.." && pwd)
cd "$ROOT"
DIST=$ROOT/dist
STAGE=$DIST/stage
OSES=("$@"); [[ ${#OSES[@]} -eq 0 ]] && OSES=(AmigaOS3 AmigaOS4 MorphOS)
command -v lha >/dev/null || { echo "error: lha not found on PATH" >&2; exit 1; }
# Ubuntu's `lha` package is lhasa, which can only extract.
_lha_probe=$(mktemp -d)
echo x > "$_lha_probe/f"
if ! ( cd "$_lha_probe" && lha -aq2 t.lha f >/dev/null 2>&1 && [[ -s t.lha ]] ); then
echo "error: lha cannot create archives (is it lhasa?). Install LHa for UNIX: https://github.com/jca02266/lha" >&2
rm -rf "$_lha_probe"
exit 1
fi
rm -rf "$_lha_probe"
# Build straight into the staging tree by pointing AMIGA_SDK at it: the build
# script's SDK layout ($SDK/<target>) is the same shape we want per OS, so each
# OS gets staged under its own directory.
rm -rf "$DIST"; mkdir -p "$STAGE/json-c"
# Extract the version from either a release tag, or the dev version + abbreviated commit hash.
# Only use a tag when HEAD is exactly on it: release tags live on release
# branches, so the nearest *reachable* tag is often an old release.
GIT_TAG=$(git describe --tags --exact-match 2>/dev/null)
if [[ "$GIT_TAG" == json-c-* ]] ; then
# e.g. 0.19-20260627
JSON_C_VERS=${GIT_TAG#json-c-}
else
# e.g. 0.19.99-09e45f6
JSON_C_VERS=$(sed -ne'/define JSON_C_VERSION / { s/"$//; s/.*"//; p; }' "${ROOT}/json_c_version.h")-$(git rev-parse --short HEAD)
fi
sed -e"s/VERSION/${JSON_C_VERS}/" "$AMIGA_DIR/json-c.readme.template" > "$STAGE/json-c/json-c.readme"
built=()
for os in "${OSES[@]}"; do
case "$os" in
AmigaOS3) sub=m68k-amigaos ;;
AmigaOS4) sub=ppc-amigaos ;;
MorphOS) sub=ppc-morphos ;;
*) echo "skip: unknown OS $os"; continue ;;
esac
tmp=$DIST/sdk-$os
mkdir -p "$tmp/$sub"
echo "=== $os ==="
# Stage whatever landed even if some variants failed -- a single unsupported
# multilib should not drop the whole OS from the archive.
AMIGA_SDK="$tmp" "$AMIGA_DIR/build-amiga-sdk.sh" "$os" || echo " ($os: some variants failed, see above)"
if [[ -n $(find "$tmp/$sub" -name 'libjson-c.a' -print -quit 2>/dev/null) ]]; then
mkdir -p "$STAGE/json-c/$os"
cp -a "$tmp/$sub/." "$STAGE/json-c/$os/"
built+=("$os")
else
echo " $os: nothing built, omitted from the archive"
fi
rm -rf "$tmp"
done
[[ ${#built[@]} -eq 0 ]] && { echo "nothing built"; exit 1; }
# NOTE: build the archive from a clean staging tree with `lha -aq2`. Do NOT try
# to refresh a single entry (e.g. the readme) in an existing archive with
# `lha u` -- it APPENDS a second entry with the same name rather than replacing
# it, and extraction then yields the stale copy.
( cd "$STAGE" && lha -aq2 "$DIST/json-c.lha" * >/dev/null )
rm -rf "$STAGE"
echo
echo "packaged: ${built[*]}"
ls -la "$DIST"