From 531ef120efd677ec478afa2bf143e1ee9290c1ad Mon Sep 17 00:00:00 2001 From: Nexoniarz Date: Sun, 9 Aug 2026 14:28:47 +0200 Subject: [PATCH] docs: how to build on each supported host Prerequisites per platform, why the toolchain is clang rather than a cross-gcc, how to force GNU, and the host differences already handled -- listed because they are the shape of the next such bug. Records the two things a second machine needs to know: ports cannot be built on a Windows host (sysroot/ is used as staged, so build them once on a Unix), and pwsh runs on Linux and macOS so the bootcheck suite is not Windows-only. --- docs/building.md | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 docs/building.md diff --git a/docs/building.md b/docs/building.md new file mode 100644 index 0000000..72c18e9 --- /dev/null +++ b/docs/building.md @@ -0,0 +1,94 @@ + +# Building SchOS + +Supported hosts: **Linux, macOS, FreeBSD/OpenBSD/NetBSD, and Windows** (under +Git Bash or MSYS2). The build is developed from both Windows and Linux, so a +change that only works on one of them is a bug. + +```sh +make # kernel + bootloader + root filesystem -> schos.img +make qemu # build and boot it +``` + +## Prerequisites + +| Need | Why | Windows | Linux | macOS | BSD | +|---|---|---|---|---|---| +| `clang`, `ld.lld`, `llvm-objcopy`, `llvm-objdump` | cross-compiles the kernel, the 16/32-bit boot code, and musl userland | LLVM installer | `clang lld llvm` | `brew install llvm` | `pkg install llvm` | +| `make` | — | Git Bash | `make` | Xcode CLT | `gmake` | +| `perl` | generates the interrupt vector table | Git Bash | usually present | present | `pkg install perl5` | +| `python3` | boot logo, crash-screen QR | python.org (`python`) | `python3` | `brew install python` | `pkg install python3` | +| `qemu-system-x86_64` | running and testing | `scoop install qemu` | `qemu-system-x86` | `brew install qemu` | `pkg install qemu` | +| `curl`, `tar` | fetching ports | Git Bash | present | present | present | +| `xorriso` **or** `mkisofs` | `make iso` only | `scoop install cdrtools` | `xorriso` | `brew install xorriso` | `pkg install xorriso` | + +A host C compiler (`cc`) is also needed, for the tools that build the disk +images. On Windows that must be **mingw-w64's gcc**, not clang: clang defaults +to an MSVC target there, and `tools/mkfs.c` needs `` and ``, +which the Windows SDK does not have. + +## Why clang rather than a cross-gcc + +clang is a cross-compiler by construction, so one ordinary LLVM install targets +everything this tree needs — bare-metal ELF, code linked below one megabyte, and +Linux/musl userland — from any host. A cross binutils+gcc would be a day of +setup per platform that then rots, and on macOS it means brewing +`x86_64-elf-gcc` before anything builds at all. + +The Makefile selects clang+lld whenever both are on `PATH`. To force the GNU +toolchain instead: + +```sh +make USE_GNU=1 # needs a cross toolchain that emits x86_64 ELF +make USE_GNU=1 TOOLPREFIX=x86_64-elf- +``` + +## Testing + +```sh +tools/bootcheck.ps1 # boots, drives the shell, asserts on output +tools/bootcheck.ps1 -Tty -Ps # plus terminal behaviour and process listing +make schfs-check # SchFS unit, object and image suites +``` + +`bootcheck` is PowerShell, and PowerShell 7 (`pwsh`) runs on Linux, macOS and +the BSDs as well as Windows — `brew install powershell`, or your distribution's +`powershell` package. It finds QEMU on `PATH`. + +Booting to a prompt proves nothing on its own: a filesystem can mount and still +fail the first real command, which has happened here. `bootcheck` types commands +at the serial console and greps the transcript for the answers they should +produce. + +## Ports + +`musl`, `toybox` and `mksh` are built from source into `sysroot/`. **This does +not work on a Windows host** — `make` prints `ports: skipped` and uses whatever +is already staged in `sysroot/`. Building them needs a Linux host (or any other +Unix); do it once and the staged result serves the Windows builds. + +## Known host differences, already handled + +Listed because they are the shape of the next such bug, not because anything is +outstanding: + +- `` is glibc/musl only. macOS and the BSDs take `major()` and + `minor()` from ``. +- `sha256sum` exists on Linux and Git Bash; macOS has `shasum -a 256`, + FreeBSD/NetBSD `sha256`, OpenBSD `cksum -a sha256`. `tools/sha256check.sh` + finds whichever is present. +- `nproc` is coreutils, so absent on macOS and BSD, where it is + `sysctl -n hw.ncpu`. +- In the PowerShell tools, path literals must use forward slashes: + `Join-Path $root 'build\x'` produces a *filename containing a backslash* on a + Unix host. + +## Working on two machines + +Claude Code's project memory is kept in the repo and moved with: + +```sh +tools/memory-sync.sh status +tools/memory-sync.sh export # after a session that learned something; then commit +tools/memory-sync.sh import # after cloning or pulling elsewhere +```