joeylib2/installer/components/haikuGcc2.sh
2026-10-13 14:01:46 -05:00

85 lines
3.4 KiB
Bash

# Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License.
# See LICENSE.md for license information.
# SPDX-License-Identifier: MIT
#
# The Haiku x86_gcc2 cross compiler (make haiku32): gcc 2.95.3, the BeOS
# C++ ABI that 32-bit Haiku keeps as its primary compiler, Linux-hosted, as
# Haiku's own CI builds it from its buildtools (the toolchain layer of
# Haiku's published cross-compiler image,
# ghcr.io/haiku/cross-compiler:x86_gcc2h-r1beta5, pinned by its digest; the
# compiler is the same 2.95.3-haiku-2017_07_20 that R1/beta6 ships). Its
# sysroot is R1/beta6's: the system libraries out of the release image and
# haiku_devel from the release's repository. Into toolchains/opt/haikuGcc2:
# cross/ (the compiler) and sysroot/; make/support/be/gcc2.sh drives it.
#
# gcc 2.95 builds only as a 32-bit program, so it needs the host's 32-bit C
# library (Debian and Ubuntu: libc6-i386 or libc6:i386; Fedora: glibc.i686).
# Nothing else 32-bit: its binutils are 64-bit.
compDescription="haiku: gcc 2.95.3 cross compiler + R1/beta6 sysroot (Haiku x86, gcc2h)"
compGroups="toolchain:haiku32"
compRequires="haikuTools"
compHostDeps="curl tar python3"
ociRepository="haiku/cross-compiler"
ociToolchainLayer="ca91ed20dd950c53d8f85eb23f37f21c8634843d068896795c2a7d09bd365241"
haikuArch="x86_gcc2"
systemPackages="haiku-r1~beta6_hrev59866_79-1-x86_gcc2.hpkg"
develPackage="haiku_devel-r1~beta6_hrev59866_79-1-x86_gcc2.hpkg"
develSha256="fd091d128b0002b13ade7651a0a5d2fc259b8d9c09be45be56dbe2ec50aba0f4"
compPin="$ociToolchainLayer:$develSha256"
# The 32-bit program loader the compiler needs.
hostLoader32="/lib/ld-linux.so.2"
gcc2Driver="$JOEY_BUILD_SUPPORT/be/gcc2.sh"
# shellcheck source=installer/lib/haiku.sh
source "$JOEY_INSTALLER/lib/haiku.sh"
compInstall() {
local layer
local src
local package
local packages=()
[ -e "$hostLoader32" ] || die "gcc 2.95 is a 32-bit program and this machine cannot run one: install the 32-bit C library (Debian/Ubuntu: libc6-i386; Fedora: glibc.i686)"
layer="$(fetchOciBlob "$ociRepository" "$ociToolchainLayer" "haiku-cross-x86_gcc2h-r1beta5.tar.gz")"
src="$(freshBuildDir "$compId")"
tar -xzf "$layer" -C "$src" tools/cross-tools-x86_gcc2
for package in $systemPackages; do
haikuIsoPackage "$haikuArch" "$package" "$src/$package"
packages+=("$src/$package")
done
packages+=("$(haikuRepoPackage "$HAIKU_REPO_BASE" "$haikuArch" "$HAIKU_REVISION" "$develPackage" "$develSha256")")
rm -rf "$compDir"
mkdir -p "$compDir"
mv "$src/tools/cross-tools-x86_gcc2" "$compDir/cross"
# The image's own sysroot is an empty one from its build.
rm -rf "$compDir/cross/sysroot"
haikuSysroot "$compDir/sysroot" "${packages[@]}"
dropBuildDir "$compId"
}
compInstalled() {
[ -x "$compDir/cross/bin/i586-pc-haiku-g++" ] && [ -e "$compDir/sysroot/boot/system/develop/lib/libbe.so" ]
}
# Link a C++ program against the Be API (libbe.so) through the driver
# make/haiku32.mk uses.
compVerify() {
local tmp
local status=1
tmp="$(mktemp -d)"
printf '#include <Application.h>\nint main(void) { BApplication app("application/x-vnd.JoeyLib-check"); return app.InitCheck() == B_OK ? 0 : 1; }\n' > "$tmp/t.cpp"
if "$gcc2Driver" "$compDir" g++ "$tmp/t.cpp" -o "$tmp/t" -lbe && [ -s "$tmp/t" ]; then
status=0
fi
rm -rf "$tmp"
return $status
}
compEnv() {
envVar HAIKU32_ROOT "$compDir"
envVar HAIKU32_GCC2 "$gcc2Driver"
}