Developed from both Windows and Linux, so nothing in the build should care which host it runs on. It did, in four places. Toolchain: one path instead of two. clang is a cross-compiler by construction, so a single LLVM install targets bare-metal ELF, 16/32-bit code below 1 MB, and Linux/musl userland from any host -- which is how the Windows build already worked. The GNU branch beside it had drifted into passing --no-warn-rwx-segments, a hard error on lld, which is the default linker on both FreeBSD and macOS; and it required a brewed x86_64-elf-gcc before anything built on a Mac at all. GNU is kept as a fallback (USE_GNU=1) but clang+lld is chosen whenever both are present. Host tools use the host's own cc; only mingw needs naming explicitly. tools/mkschfs.c included <sys/sysmacros.h> unconditionally on non-mingw hosts. That header is glibc/musl only -- macOS and the BSDs have neither the header nor a need for it, since major()/minor() come from <sys/types.h> there. Now guarded on __linux__. Ports verified tarballs with `sha256sum -c -`, which does not exist on macOS (shasum), FreeBSD/NetBSD (sha256), or OpenBSD (cksum -a sha256), and each spells its check mode differently. tools/sha256check.sh picks whichever of the five the host has and compares digests itself. nproc is coreutils, so absent on macOS and BSD; falls through to sysctl -n hw.ncpu before defaulting to 4. The PowerShell tools now run under pwsh on any OS: QEMU is found on PATH (the scoop location is a Windows-only fallback), and path literals use forward slashes -- Join-Path $root 'build\x' produces a *filename containing a backslash* on a Unix host. The backslash sweep is limited to known directory prefixes on purpose: bootcheck sends printf 'caf\303\251' to the guest to test UTF-8, and a blanket substitution would have quietly changed what that asserts. Also fixes six tools left booting build/fs.img, which stopped being bootable when SchFS became the root filesystem: crashshot, dispshot, fbshot, splashshot, textshot and ttyshot all take build/schfs.img now, and the -SchFS switches that used to select it are gone. Verified on Windows: full build, and bootcheck green. The Linux, macOS and BSD paths are written from their documented behaviour and are NOT executed here -- this machine has no WSL and no second host.
82 lines
3.4 KiB
Makefile
82 lines
3.4 KiB
Makefile
# SPDX-License-Identifier: Apache-2.0
|
|
# toybox — 0BSD-licensed: https://landley.net/toybox/
|
|
# Provides SchOS's core utilities (ls, cat, cp, mv, rm, mkdir, ...) as a
|
|
# single multicall binary, installed under sysroot/bin/ once per applet name.
|
|
#
|
|
# mkfs (tools/mkfs.c) doesn't understand symlinks or hardlink dedup — each
|
|
# sysroot/bin/<name> below is a real, independent copy of the same toybox
|
|
# binary. That costs disk space per applet instead of one shared inode, but
|
|
# needs no changes to mkfs and keeps this Makefile self-contained.
|
|
|
|
include ../mk/port.mk
|
|
|
|
TOYBOX_VERSION := 0.8.12
|
|
TOYBOX_URL := http://landley.net/toybox/downloads/toybox-$(TOYBOX_VERSION).tar.gz
|
|
TOYBOX_SHA256 := ad88a921133ae2231d9f2df875ec0bd42af4429145caea7d7db9e02208a6fd2e
|
|
|
|
TARBALL := $(DISTDIR)/toybox-$(TOYBOX_VERSION).tar.gz
|
|
|
|
CFLAGS := -static -D__SCHOS__ -I$(MUSL)/include -fno-stack-protector
|
|
LDFLAGS := -static -L$(MUSL)/lib -lc
|
|
|
|
# The applet list is not hard-coded any more: `toybox` with no arguments prints
|
|
# exactly the applets the binary was built with, so the install below asks the
|
|
# binary itself. A hand-maintained list installed 57 of the ~250 available and
|
|
# silently drifted every time the toybox config changed.
|
|
|
|
$(TARBALL): | $(DISTDIR)
|
|
curl -fsSL -o $@ $(TOYBOX_URL)
|
|
sh $(SHA256CHECK) "$(TOYBOX_SHA256)" "$@"
|
|
|
|
download: $(TARBALL)
|
|
|
|
$(SRCDIR): $(TARBALL)
|
|
mkdir -p $(PORTDIR)
|
|
tar -xzf $< -C $(PORTDIR)
|
|
mv $(PORTDIR)/toybox-$(TOYBOX_VERSION) $@
|
|
|
|
# toybox has no out-of-tree build mode, so its source is copied into $(BUILDDIR)
|
|
# and built in place. $(SRCDIR) is an order-only prerequisite (|): the extracted
|
|
# tarball never changes, and depending on it normally made a directory mtime
|
|
# trigger a rebuild. The rebuild then failed anyway, because `cp -r` over a
|
|
# populated $(BUILDDIR) hits "File exists" on kconfig's symlinks — so wipe it
|
|
# first and always build from a clean copy.
|
|
$(BUILDDIR)/toybox: | $(SRCDIR)
|
|
rm -rf $(BUILDDIR)
|
|
mkdir -p $(BUILDDIR)
|
|
cp -r $(SRCDIR)/. $(BUILDDIR)/
|
|
$(MAKE) -C $(BUILDDIR) defconfig
|
|
$(MAKE) -C $(BUILDDIR) CC="$(CC)" CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)"
|
|
|
|
# Install every applet the binary provides, one name per applet.
|
|
#
|
|
# mkfs deduplicates by content, so all of these collapse to a single inode with
|
|
# many hard links in the image -- the cost is one copy, not one per name. On the
|
|
# host we try a hard link first for the same reason and fall back to a copy if
|
|
# the filesystem will not take one (NTFS via WSL usually will).
|
|
#
|
|
# The work hangs off a stamp file rather than off the phony `install` target.
|
|
# port.mk declares install .PHONY for every port, so this recipe used to run on
|
|
# every single build -- re-creating 236 links whether or not toybox had been
|
|
# rebuilt. That is slow on its own, and worse, it bumped the mtime of 236 files
|
|
# in sysroot/ every time, which made the top-level build think the staged tree
|
|
# had changed and rebuild the whole filesystem image from scratch.
|
|
install: $(BUILDDIR)/toybox.installed
|
|
|
|
$(BUILDDIR)/toybox.installed: $(BUILDDIR)/toybox | $(SYSROOT)/bin
|
|
cp $< $(SYSROOT)/bin/toybox
|
|
chmod 755 $(SYSROOT)/bin/toybox
|
|
@for a in $$($(BUILDDIR)/toybox); do \
|
|
rm -f $(SYSROOT)/bin/"$$a"; \
|
|
ln $(SYSROOT)/bin/toybox $(SYSROOT)/bin/"$$a" 2>/dev/null \
|
|
|| cp $< $(SYSROOT)/bin/"$$a"; \
|
|
done
|
|
@echo "toybox: installed $$($(BUILDDIR)/toybox | wc -w) applets"
|
|
@touch $@
|
|
|
|
|
|
clean:
|
|
rm -rf $(PORTDIR)
|
|
|
|
distclean: clean
|
|
rm -f $(TARBALL)
|