Files
Sprinter-SDCC/toolchain/make_release.sh
T
2026-09-16 10:01:43 +03:00

120 lines
4.9 KiB
Bash
Executable File

#!/bin/bash
#
# make_release.sh — pack a redistributable Sprinter C Compiler release tarball.
#
# Whitelist-based: only files explicitly listed below go into the tarball.
# Anything else (internal dev tools, research docs, build artefacts, mac
# xattr sidecars, .git, .claude memory, etc.) is excluded by construction.
#
# Output: build/sprinter-c-v<VERSION>-<host>.tar.gz with:
# - bin/sprinter-cc : compiler driver
# - toolchain/mkexe/ : .ihx → .exe utility (prebuilt for host)
# - toolchain/check_banks.py : bank size checker used by sprinter-cc
# - runtime/ : crt0 + bank/heap support
# - libc/include/ : public headers
# - libc/{io,stdio,mem,gfx}/ : libc sources (assembled into sprinter.lib)
# - lib/*.lib : prebuilt libc/BGI variants
# - app.mk + disk/run tools : standalone application integration
# - libbgi/ + lib/bgi256*.lib : graphics library
# - tests/ + testkit/ : SDK regression programs
# - third_party/sdcc/ : vendored SDCC 4.5
# - release_docs/ → docs/ : user-facing documentation
# - root Makefile, README, RELEASE_NOTES, LICENSE
#
# NOT included (developer-only):
# - docs/ (research notes, original PetersPlus reference material)
# - third_party/solid-c/ (reference for Solid-C compat target)
# - mame/ (large emulator + Sprinter HDD/CD images)
# - .git/, .claude/, .DS_Store, ._* (macOS xattrs)
# - this script itself (toolchain/make_release.sh)
# - any build artefacts (.sprinter-cc-*, *.rel, *.ihx, *.lk, *.map, ...)
#
# Usage: ./toolchain/make_release.sh [VERSION]
set -euo pipefail
VERSION="${1:-1.0}"
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
HOST_ARCH="$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)"
NAME="sprinter-c-v${VERSION}-${HOST_ARCH}"
STAGE="$ROOT/build/$NAME"
TARBALL="$ROOT/build/$NAME.tar.gz"
cd "$ROOT"
echo ">> verifying build is clean and current"
make all >/dev/null 2>&1
echo ">> staging $STAGE"
rm -rf "$STAGE"
mkdir -p "$STAGE"
# --- WHITELIST: only these directories/files end up in the tarball ---
# Top-level metadata
cp README.md RELEASE_NOTES.md LICENSE Makefile app.mk "$STAGE/"
# Toolchain
cp -R bin runtime libc libbgi tests testkit "$STAGE/"
# Core tools and source debugger backend needed by sprinter-cc/app.mk.
mkdir -p "$STAGE/toolchain/mkexe"
cp toolchain/mkexe/mkexe "$STAGE/toolchain/mkexe/"
cp toolchain/mkexe/mkexe.c "$STAGE/toolchain/mkexe/"
cp toolchain/mkexe/Makefile "$STAGE/toolchain/mkexe/"
[[ -f toolchain/mkexe/check.sh ]] && cp toolchain/mkexe/check.sh "$STAGE/toolchain/mkexe/"
cp toolchain/check_banks.py "$STAGE/toolchain/"
cp toolchain/check_bank_calls.py toolchain/check_w0_isr.py \
toolchain/sdbg_build.py toolchain/sdbg_driver.py toolchain/sdbg_dap.py \
toolchain/sdbg_launcher.py toolchain/mame_interactive.py \
toolchain/mame_profile.py toolchain/make_disk.py \
toolchain/make_hdd.sh toolchain/run_sprinter_mame.py "$STAGE/toolchain/"
cp -R toolchain/sdbg "$STAGE/toolchain/"
cp -R toolchain/mcp "$STAGE/toolchain/"
# Lib — keep Makefile and the prebuilt archive only; sources are in libc/
mkdir -p "$STAGE/lib"
cp lib/sprinter.lib lib/sprinter_safe.lib \
lib/bgi256.lib lib/bgi256_safe.lib "$STAGE/lib/"
# Vendored SDCC — follow symlinks so the real content lands in the tarball
mkdir -p "$STAGE/third_party"
[[ -d third_party/sdcc ]] && cp -RL third_party/sdcc "$STAGE/third_party/"
[[ -f third_party/setup-sdcc.sh ]] && cp third_party/setup-sdcc.sh "$STAGE/third_party/"
# User-facing docs. Source: release_docs/{en,ru}/ → docs/{en,ru}/ in tarball.
# The internal docs/ tree (research notes, original Peters Plus material) is
# NOT shipped.
[[ -d release_docs ]] && cp -R release_docs "$STAGE/docs"
# --- Strip build artefacts that crept in via sources ---
echo ">> stripping build artefacts and macOS metadata"
find "$STAGE" \( \
-name '.sprinter-cc-*' -o \
-name '.resource-stamps' -o -name build -o \
-name '*.rel' -o -name '*.lst' -o -name '*.sym' -o -name '*.asm' -o \
-name '*.ihx' -o -name '*.lk' -o -name '*.map' -o -name '*.noi' -o \
-name '*.exe' -o \
-name '.DS_Store' -o -name '._*' \
\) -print0 | xargs -0 rm -rf
# Bonus: clean any *_test or scratch files I might have left in libc dirs
find "$STAGE/libc" -name 'build' -type d -exec rm -rf {} + 2>/dev/null || true
# --- Tarball ---
echo ">> packaging $TARBALL"
cd "$ROOT/build"
COPYFILE_DISABLE=1 tar --no-mac-metadata -czf "$TARBALL" "$NAME" 2>/dev/null || \
COPYFILE_DISABLE=1 tar -czf "$TARBALL" "$NAME"
rm -rf "$NAME"
ls -lh "$TARBALL"
echo
echo "Release ready: $TARBALL"
echo
echo "Try it:"
echo " tar xzf $(basename "$TARBALL")"
echo " cd $NAME"
echo " make all"
echo " bin/sprinter-cc -o hello.exe hello.c"
echo " Examples are released as a separate repository"