joeylib2/installer/components/amigaGcc.sh
2026-10-19 15:46:47 -05:00

108 lines
4.4 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
#
# Amiga C toolchain: Bebbo's m68k-amigaos-gcc 6.5 (AmigaPorts), with
# binutils, libnix, clib2, the NDK 3.2 headers and vasm. Built from source
# (~15-40 minutes).
#
# The build clones its sub-projects by BRANCH name, which would make the
# result drift; every sub-project is pre-cloned here at a pinned commit so
# the Makefile finds it in place and skips its own clone. It also wget's
# the NDK and ixemul SDK on every build; those are checked afterward.
compDescription="Amiga compiler: m68k-amigaos-gcc 6.5 + NDK 3.2 + vasm (source build)"
compGroups="toolchain:amiga"
compRequires="host"
compHostDeps="build-tools git patch which bison flex m4 texinfo autoconf automake gettext rsync wget lhasa gmp-dev mpfr-dev mpc-dev ncurses-dev readline-dev"
compUrl="https://github.com/AmigaPorts/m68k-amigaos-gcc.git"
compCommit="7d3e35f58e61bdf325d84b912b139f973d9b7452"
patchDir="$JOEY_PATCHES/amigaGcc"
# Editing a patch rebuilds the toolchain, so the patches are part of the pin.
compPin="$compCommit $(cat "$patchDir"/*.patch | sha256sum | cut -d' ' -f1)"
# name commit (the URL comes from the checkout's default-repos file)
subProjects=(
"amiga-netinclude 7d155ca3a3090afe3466f819dd178f2af6f5c176"
"aros-stuff 86711c70569ffc6b70ee1fb99895866c1d9f30e4"
"binutils 45a7a53c6d42a38e544ea30116e03eb6b2b37f8b"
"clib2 694064c4000b335247164773dd2d231e809a8e8e"
"fd2pragma e98f0901340b8989308ca31e53c02a6e61f8339e"
"fd2sfd 403714de37f1b9851475ab455964af355bcd6523"
"gcc 87dab3c2f2524682287f5e841d75caa60ba504c2"
"ira bb7c11384a32c409341fdb0d16d715b7959a0290"
"libdebug 42d9d3a7a0d26fa4679384ffc78cf79fbce394d8"
"libnix e1ba6cfae3d39c560f975bc2e44d9e8e99b42868"
"newlib-cygwin 4c8cbd88df31cd06c89b258585ea5cd86cc9dc45"
"sfdc 0e9fa28272aab30f72f34b2d71c178d6ca88d9dd"
"vasm 291f6f08226c8843711e1319864526e6cd57ce06"
)
# file sha256 -- what the build is expected to have downloaded
buildDownloads=(
"NDK3.2.lha 96cabd4ad683dced632e147bf86dee0f50dcb1254386216c25c362916a6409bb"
"ixemul-sdk.lha 00b4054283b99d22f6b353194fa8c75917ec0cc08a3a64395a891da446db07fc"
)
compInstall() {
local src
local entry
local name
local sha
local url
local dir
local p
src="$(freshBuildDir "$compId")"
gitFetchCommit "$compUrl" "$compCommit" "$src"
for entry in "${subProjects[@]}"; do
read -r name sha <<< "$entry"
url="$(awk -v n="$name" '$1 == n { print $2 }' "$src/default-repos")"
[ -n "$url" ] || die "amiga-gcc: no URL for sub-project $name in default-repos"
gitFetchCommit "$url" "$sha" "$src/projects/$name"
done
for p in "$patchDir"/*.patch; do
info "applying $(basename "$p")"
patch -d "$src/projects/gcc" -p1 -s -F0 --no-backup-if-mismatch < "$p"
done
rm -rf "$compDir"
make -C "$src" all PREFIX="$compDir" -j"$JOEY_JOBS"
# Anything cloned by the build itself is unpinned; say so.
for dir in "$src"/projects/*/; do
name="$(basename "$dir")"
[ -d "$dir/.git" ] || continue
if [[ " ${subProjects[*]} " != *" $name "* ]]; then
warn "amiga-gcc: the build cloned unpinned sub-project '$name'; pin it in $compId.sh"
fi
done
for entry in "${buildDownloads[@]}"; do
read -r name sha <<< "$entry"
[ "$(sha256Of "$src/download/$name")" = "$sha" ] ||
die "amiga-gcc: $name downloaded by the build does not match its pin; upstream changed it"
done
dropBuildDir "$compId"
}
compInstalled() {
[ -x "$compDir/bin/m68k-amigaos-gcc" ] && [ -x "$compDir/bin/vasmm68k_mot" ] && [ -d "$compDir/m68k-amigaos/sys-include" ]
}
compVerify() {
verifyCompiles "$compDir/bin/m68k-amigaos-gcc" -m68000 -O2
}
compEnv() {
envVar AMIGA_PREFIX "$compDir"
envVar AMIGA_CC "$compDir/bin/m68k-amigaos-gcc"
envVar AMIGA_AR "$compDir/bin/m68k-amigaos-ar"
envVar AMIGA_LD "$compDir/bin/m68k-amigaos-ld"
# vasm assembles only ptplayer.asm (Devpac syntax); JoeyLib's own .s
# files are GAS syntax and go through the gcc driver.
envVar AMIGA_AS "$compDir/bin/vasmm68k_mot"
envVar AMIGA_NDK "$compDir/m68k-amigaos/sys-include"
envPath "$compDir/bin"
}