Files
Neo-DesktopandClaude Opus 5.5 c2e4767406 Add build-sysroot.sh: a ready-made classic Mac OS sysroot
build-sysroot.sh builds one directory with all that is necessary to
compile and link applications for 68k and PowerPC: the Toolbox headers,
the builtins (libmacrt.a), picolibc and the Mac layer (libc.a,
libmacos.a, libmacconsole.a), and libstdc++, libsupc++ and libunwind
when GCC_SRC is set. It also has macapp.py, the linkers, the CPU
emulators, the examples and the license of each part. macapp.py finds
include/ and lib/ in the directory above its own, so it works in the
sysroot without this source tree.

tests/sysroot.sh builds the examples and the libc, thread, socket, Open
Transport and C++ tests with the sysroot only, and runs them as a 68000,
a 68020 and a PowerPC in sim68k.py and simppc.py. CI runs it.

docs/sysroot.md tells how to get, use and build the sysroot.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRVa9XHXnwA5L6Sjog3
Signed-off-by: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com>
2026-11-28 20:58:18 +00:00

73 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
# Test a sysroot that build-sysroot.sh made: compile and link programs
# with the macapp.py of the sysroot only (not with this source tree), for
# 68k, PowerPC and fat, and run the 68k builds as a 68000 and a 68020 and
# the PowerPC builds in the CPU emulators of the sysroot.
#
# CLANG=... tests/sysroot.sh SYSROOT
#
# CLANG clang-retro's clang (default: clang on the PATH)
# SYSROOT the sysroot to test
#
# The emulators need the unicorn Python package. Without it, the script
# only compiles and links. The C++ tests are done only when the sysroot
# has the C++ library.
set -e
tests=$(cd "$(dirname "$0")" && pwd)
root=$(cd "${1:?usage: tests/sysroot.sh SYSROOT}" && pwd)
CLANG=${CLANG:-clang}
export CLANG
work=$(mktemp -d "${TMPDIR:-/tmp}/sysroot-test.XXXXXX")
trap 'rm -rf "$work"' EXIT
# The sources go to a directory of their own, so that nothing in this
# source tree can be found by mistake.
cp "$tests/libc.c" "$tests/thread.c" "$tests/net.c" "$tests/ot.c" \
"$tests/cxx.cpp" "$tests/cxxthread.cpp" "$work/"
cd "$work"
macapp="python3 $root/tools/macapp.py"
# check NAME OUTPUT: stop when the output of a program shows a failure.
check() {
if grep -q FAILED "$2" || ! grep -q "^all ok" "$2"; then
echo "$1:"; cat "$2"; exit 1
fi
}
# The examples, fat.
for ex in "$root"/examples/*.c; do
$macapp -o "$(basename "$ex" .c).bin" -- -Wall -Werror "$ex" >/dev/null
done
echo "examples: linked"
progs="libc thread net ot"
[ -f "$root/lib/m68k/libstdc++.a" ] && progs="$progs cxx cxxthread"
for t in $progs; do
src=$t.c
[ -f "$src" ] || src=$t.cpp
for cpu in 68k ppc; do
$macapp --cpu $cpu -o "$t-$cpu.bin" -- -Wall -Werror "$src" >/dev/null
done
done
echo "tests: linked ($progs)"
if ! python3 -c "import unicorn" 2>/dev/null; then
echo "install unicorn to run the tests in the emulators"
exit 0
fi
sim68k="python3 $root/tools/sim68k.py --os --files --exit-anywhere --steps 10000000"
simppc="python3 $root/tools/simppc.py --files"
for t in $progs; do
input=
[ $t = libc ] && input="typed\nline\n"
for c in 68000 68020; do
$sim68k --cpu $c --input "$input" "$t-68k.bin" >sim.txt || { cat sim.txt; exit 1; }
check "$t on a $c" sim.txt
done
# Open Transport on PowerPC calls Mac OS's Open Transport, which the
# emulator does not have (tools/qemu/nettest.py runs that build).
[ $t = ot ] && continue
$simppc --input "$input" "$t-ppc.bin" >sim.txt || { cat sim.txt; exit 1; }
check "$t on PowerPC" sim.txt
done
echo "sysroot: ok"