#!/usr/bin/env bash # Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License. # See LICENSE.md for license information. # SPDX-License-Identifier: MIT # # check-blank.sh - Smoke-test the new-port template (src/blank/blank.c). # # A blank port has no toolchain, so we compile it with the HOST cc just to # prove three things stay true as the library evolves: # 1. The template + the JOEYLIB_PLATFORM_BLANK blocks in platform.h still # compile (catches a new platform-#if dispatch point that forgot a BLANK # case -- e.g. assetLoad.c's tile target, the sprite emitter selector). # 2. blank.c + the generics LINK with no unresolved jlp* ops -- i.e. a new # chunky port really does get everything except the platform services for # free from src/generic/. # 3. The same sources stay gnu89-clean: no C99-only construct except `//` # comments. BeOS R5 builds with gcc 2.95 (x86) and Metrowerks mwcc (PPC), # and neither speaks C99. This pass is a lint, so it always uses gcc # (-Wc90-c99-compat is gcc-only) whatever CC says. # # Source set mirrors a real blank-port build: core + ALL of src/generic # (including the stub sprite emitter) + blank.c; NOT src/codegen/spriteCompile.c # (that's only for ports with a per-CPU JIT emitter). set -euo pipefail repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) cc=${CC:-cc} work=$(mktemp -d -t joeylib-blank.XXXXXX) trap 'rm -rf "$work"' EXIT inc=(-Iinclude -Iinclude/joey -Isrc/core -Isrc/codegen) cd "$repo" srcs=(src/core/*.c src/generic/*.c src/blank/blank.c) fail=0 for f in "${srcs[@]}"; do o="$work/$(echo "$f" | tr / _).o" if ! "$cc" -DJOEYLIB_PLATFORM_BLANK "${inc[@]}" -Wall -c "$f" -o "$o" 2>"$work/err"; then echo "check-blank: COMPILE FAIL: $f" >&2 sed 's/^/ /' "$work/err" >&2 fail=1 fi done [ "$fail" = 0 ] || { echo "check-blank: FAIL (template does not compile for BLANK)" >&2; exit 1; } # Link-completeness: any JoeyLib symbol undefined across the whole object set # (and not defined by any of them) is a real gap in blank.c or the generics. missing=$(python3 - "$work" <<'PY' import subprocess, sys, glob defs=set(); und=set() for o in glob.glob(sys.argv[1]+"/*.o"): for line in subprocess.run(["nm",o],capture_output=True,text=True).stdout.splitlines(): p=line.split() if len(p)>=3 and p[1] in "TDBRtdbr": defs.add(p[2]) elif len(p)>=3 and p[1]=="U": und.add(p[2]) elif len(p)==2 and p[0]=="U": und.add(p[1]) print(" ".join(sorted(s for s in und-defs if s.startswith(("jlp","jlSprite","jlSpriteCompiledDraw"))))) PY ) if [ -n "$missing" ]; then echo "check-blank: FAIL - unresolved JoeyLib symbols (blank.c / generics gap):" >&2 echo " $missing" >&2 exit 1 fi # gnu89 dialect lint. gcc also reports `//` comments under -Wc90-c99-compat # (once per file); gcc 2.95 and mwcc both accept them, so those are dropped. # Any other warning, or a hard error such as a for-loop declaration, fails. # LC_ALL=C: a translated gcc says "Warnung:", which the grep would miss -- # the lint would pass having checked nothing. command -v gcc >/dev/null || { echo "check-blank: FAIL - gcc not found (the gnu89 lint needs it)" >&2; exit 1; } lint="" for f in "${srcs[@]}"; do status=0 LC_ALL=C gcc -std=gnu89 -Wc90-c99-compat -Wdeclaration-after-statement -fno-diagnostics-show-caret -DJOEYLIB_PLATFORM_BLANK "${inc[@]}" -fsyntax-only "$f" 2>"$work/err" || status=$? hits=$(grep -E 'warning:|error:' "$work/err" | grep -v 'C++ style comments are incompatible with C90' || true) if [ "$status" != 0 ] && [ -z "$hits" ]; then hits=$(cat "$work/err") fi [ -z "$hits" ] || lint+="$hits"$'\n' done if [ -n "$lint" ]; then echo "check-blank: FAIL - shared code is not gnu89-clean (BeOS R5 needs gcc 2.95 / mwcc):" >&2 printf '%s' "$lint" | sort -u | sed 's/^/ /' >&2 exit 1 fi echo "check-blank: PASS (blank template compiles + links; all ops resolve via blank.c + generics; shared code is gnu89-clean)"