Files
makronix/mobile/tools/mktoolchain.sh
T
lotherkandClaude Sonnet 5.5 73c9de51a6 licence: the CNCL line in every file Makronix wrote (tools, docs, www, mobile, top level)
consmirror.c: the BSD notice is replaced (Makronix's own file).  Files with
changes of other sessions pending are left for their commit.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-14 11:50:26 +00:00

54 lines
2.2 KiB
Bash

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# The compiler for the NetBSD userland on the phone, as one command
# (docs/NETBSD-USERLAND.md, A3): the tooldir's own aarch64-linux-gnu-gcc
# (tools/mktooldir.sh: build.sh tools, gcc 14.4.0 of src/; plus
# tools/mktargetlibs.sh: its headers, libgcc, libstdc++), called with the
# flags NetBSD's build gives it for a sysroot.
#
# Usage: mktoolchain.sh DEVICEDIR SYSROOT OUTDIR
#
# Writes OUTDIR/bin/{cc,c++,cpp}; tools/mxmake.sh hands cc to NetBSD's
# host-program machinery as HOST_CC.
#
# The flags: --sysroot, and -B/-L on the sysroot's /lib and /usr/lib -- the
# tooldir's gcc is built with -DNETBSD_TOOLS, which drops the sysroot's
# library directories from its startfile search (gcc.cc:8605,8615); NetBSD
# names them itself, src/tools/gcc/Makefile:162 (CCADDFLAGS). Headers need
# nothing: the sysroot's /usr/include stays in gcc's own list, after gcc's
# and libstdc++'s directories.
#
# Until 2026-11-11 this wrapped Debian's aarch64-linux-gnu-gcc, whose own
# glibc 2.42 won over --sysroot (docs/PORTING-USERLAND.md 5.1); that needed
# -nostdinc and a hand-made include order. Gone with the tooldir.
set -eu
. "$(dirname "$0")/lib.sh"
[ $# -eq 3 ] || { echo "usage: $0 DEVICEDIR SYSROOT OUTDIR" >&2; exit 2; }
load_device "$1"
sysroot=$(cd "$2" && pwd) || die "no sysroot $2 (tools/mksysroot.sh)"
out=$3
[ -f "$sysroot/usr/include/stdio.h" ] || die "$sysroot has no headers (base/void/sysroot-packages)"
target=aarch64-linux-gnu
tooldir=$(ls -d "$ROOT"/build/tooldir.*-$target 2>/dev/null | head -n 1)
[ -n "$tooldir" ] && [ -x "$tooldir/bin/$target-gcc" ] ||
die "no tooldir for $target (make tooldir)"
[ -f "$tooldir/lib/gcc/$target/"*/include/stddef.h ] ||
die "$tooldir has no gcc headers (make targetlibs)"
flags="--sysroot=$sysroot -B$sysroot/usr/lib/ -L$sysroot/lib -L$sysroot/usr/lib"
mkdir -p "$out/bin"
for p in cc:gcc c++:g++ cpp:cpp; do
n=${p%%:*} t=${p#*:}
cat > "$out/bin/$n" <<EOF
#!/bin/sh
# made by tools/mktoolchain.sh: $target-$t of $tooldir
exec $tooldir/bin/$target-$t $flags "\$@"
EOF
chmod 755 "$out/bin/$n"
done
echo "$out/bin: cc, c++, cpp -- $("$tooldir/bin/$target-gcc" --version | head -n 1)"