joeylib2/installer/components/llvm816.sh

73 lines
2.6 KiB
Bash

# shellcheck shell=bash
# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# Apple IIgs C toolchain: llvm816, a W65816 backend for llvm-mos, plus its
# linker (link816 + omfEmit) and runtime. Cloned at a pinned commit and
# built by the repo's own setup.sh; the first build is ~30-60 minutes.
#
# `install.sh --llvm816-dir PATH` links an existing checkout instead (for
# working on llvm816 and JoeyLib together). A linked checkout is managed
# by its owner: the installer only checks it is built.
compDescription="IIgs compiler: llvm816 (clang/llc/llvm-mc for w65816, link816, runtime)"
compGroups="toolchain:iigs"
compRequires="host"
compUrl="https://forge.duensing.digital/AI_Slop/65816-llvm-mos.git"
compCommit="9ca7f1d0de6e23282bed4546441ed9bcced30a5d"
linkedDir="$(cat "$JOEY_STATE/llvm816Dir" 2>/dev/null || true)"
# A linked checkout is built by its owner, so it needs no build packages.
if [ -n "$linkedDir" ]; then
compPin="linked:$linkedDir"
compHostDeps=""
else
compPin="$compCommit"
compHostDeps="build-tools cmake ninja lld git python3 zlib-dev zstd-dev libedit-dev libxml2-dev ncurses-dev"
fi
compInstall() {
if [ -n "$linkedDir" ]; then
[ -x "$linkedDir/tools/llvm-mos-build/bin/clang" ] || die "$linkedDir has no built clang; run its setup.sh first"
rm -rf "$compDir"
ln -s "$linkedDir" "$compDir"
return 0
fi
if [ -L "$compDir" ]; then
rm -f "$compDir"
fi
gitFetchCommit "$compUrl" "$compCommit" "$compDir"
# Host packages come from install.sh (--skip-deps); JoeyLib brings its
# own MAME and does not use Calypsi or GNO/ME.
(cd "$compDir" && bash setup.sh --skip-deps --skip-mame --skip-calypsi --skip-gno --skip-verify)
}
compInstalled() {
[ -x "$compDir/tools/llvm-mos-build/bin/clang" ] &&
[ -x "$compDir/tools/llvm-mos-build/bin/llvm-ar" ] &&
[ -x "$compDir/tools/link816" ] &&
[ -x "$compDir/tools/omfEmit" ] &&
[ -f "$compDir/runtime/crt0Gsos.o" ]
}
compVerify() {
local tmp
local status=1
tmp="$(mktemp -d)"
printf 'int answer(void) { return 42; }\n' > "$tmp/t.c"
if "$compDir/tools/llvm-mos-build/bin/clang" --target=w65816 -O2 -c "$tmp/t.c" -o "$tmp/t.o"; then
[[ "$("$compDir/tools/llvm-mos-build/bin/llvm-objdump" --triple=w65816 -d "$tmp/t.o" 2>/dev/null)" == *lda* ]] && status=0
fi
rm -rf "$tmp"
return $status
}
compEnv() {
envVar LLVM816_ROOT "$compDir"
envVar IIGS_CLANG_BUILD "$JOEY_BUILD_SUPPORT/iigs/clang-build.sh"
}