Files
makronix/AGENTS.md
T
lotherkandClaude Opus 5.5 861608eaaa AGENTS.md: make usb, compress, test; tools/AGENTS.md: cd-com0.sh, -U, VMSH_AHCI
Written by opencode (iceman-contributor-free), checked against Makefile:79-92,
tools/test.sh, tools/vmsh.sh:97-100, tools/cd-com0.sh:7-12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 07:54:37 +00:00

22 KiB

AGENTS.md -- how work happens in this tree

Makronix is a NetBSD, built and shaped on purpose. Read this before changing anything; the rules are few and they are binding.

Read in this order, every time: GOAL.md (what Makronix is and when a part is done), this file, docs/BUILD-CONTRACT.md (the one way to build). Every directory below the root carries its own AGENTS.md: what lives there, what may be changed, what may not. Read the one in the directory you work in before you touch it.

Where this file and a measurement disagree, the measurement wins and this file is wrong: fix the file, name the log line that settled it.

The rule before all others

Read the documentation first, every time, and save what you read. In this order: the docs in the tree (AGENTS.md, src/BUILDING, man pages, the comment at the top of the file), then the project's own upstream documentation. Keep a copy under docs/reference/<topic>.txt with source and date so the next session does not start over. Quote the sentence that settles a question -- with its location -- before acting on it. "The docs say" without having opened them is the failure this rule exists to prevent; it has cost this project days.

The one rule

NetBSD first, in this order: read the documentation in the tree (AGENTS.md, src/BUILDING, src/share/misc/style, src/distrib/sets/README, src/etc/rc.subr); look for the pattern already in the tree with git grep; use the building block that exists. Only then write code -- and the comment says which NetBSD pattern it follows.

A patch that breaks a NetBSD convention is a finding for the report, never a quiet change in the tree.

What belongs where

  • src/ and xsrc/ are the NetBSD import at the pinned commit. Every change to them is recorded in this repository, in one of two forms, and never made by hand in the import:
    • a patch under patches/src/ or patches/xsrc/, applied in filename order, for a small edit to a file NetBSD owns;
    • an overlay unit under overlay/, a full tracked copy of a directory we really rework (today usr.sbin/sysinst), put into src/ by tools/overlay.sh sync before every build. Work in overlay/, not in src/ (overlay/AGENTS.md). Not both for the same directory. Both are applied in place, because build.sh builds from src/; so git -C src status shows the files our patches and overlay units touch, plus the untracked AGENTS.md files (below) -- anything beyond that is an edit nobody recorded. A patch that no longer applies is a finding, never something to force. Upgrading the import is a rebase of the patches and of the overlay (overlay/AGENTS.md), not a merge of local edits. tools/apply-patches.sh is not called by the Makefile and cannot yet tell "already applied" from "conflicts" for patches that stack on one file (0001 and 0002): known defect, see tools/AGENTS.md.
  • ext/ holds third-party sources that Makronix ships: ext/src/<name>/ is the unpacked upstream tree, ext/src/<name>/pkgsrc/ its recipe, and an IMPORT record names pkgsrc path, version, archive, hash and licence. An update replaces the recipe, unpacks the newer source over the old, renews IMPORT.
  • distfiles/ never lives in the repository. The archives sit outside and are copied in for a release medium; the tree builds from what is present.

Building

Everything builds cross, from any host, with build.sh, through the targets of the root Makefile and nothing else:

make build            build.sh distribution: the sets, no medium
make release ARCH=... build.sh release: the distribution plus the
                      `distrib` stage -- INSTALL kernel (instkernel),
                      ramdisks, kmods, boot-com.iso
                      (src/distrib/amd64/Makefile, `TARGETS+= release`)
make iso              build.sh iso-image: packages what `release` built
                      into RELEASEDIR/images/*.iso (CD and DVD)
make usb              build.sh install-image: the bootable installation image
                      for a USB stick (GPT, MBR and EFI) from what `release`
                      built, unpacked raw (tools/images.sh unpack)
make compress         pack the raw install images in the release directory
                      for a download (tools/images.sh pack)
make sourcesets       the source sets in RELEASEDIR/source/sets: NetBSD's
                      (with their .git) and msrc (pkgsrc, patches,
                      tools, the Makronix distfiles, PINS; docs/OFFLINE-BUILD.md)
make isosrc           the DVD with those source sets on it
make userland         the pkgsrc userland of the makronix set: cross-built here
                      and built natively in the build VM (tools/userland.sh,
                      packages.vm.list)
make cdtest           release, iso and the installation from CD 1, 2 and 3 in
                      the simple mode (about 15 minutes)
make test             the tests of a release, in cost order: mediacheck.sh,
                      one full installation from the DVD, and smoke tests of
                      the other media (tools/test.sh)
make install          over a running Makronix, idempotent and incremental;
                      refuses on a host that is not NetBSD

The order for an install medium is make release ARCH=amd64, then make iso. make build then make iso does not work: build-stamp.sh removes the derived artefacts, distribution does not recreate instkernel, and iso-image stops with netbsd-GENERIC.gz: stat: No such file or directory (build/logs/make-iso-2026-11-06.log:49). iso-image only packages. Since 2026-11-06 make iso checks first (tools/build-stamp.sh -c) and stops with a message, without removing anything, if the sources, patches or the overlay changed since the last make release.

A boot message WARNING: 1 module failed to load for cd9660 is not a defect: the INSTALL kernel has cd9660 built in, the loader's attempt to push the kmod finds it already there (Module 'cd9660' pushed by boot loader already exists), and the CD is mounted as root regardless (build/logs/baseline-bios-boot-2026-11-06.log:34,109). Comparing the timestamps of netbsd and cd9660.kmod in the ISO proves nothing: make -u does not rebuild a kmod whose sources did not change.

Long builds: start the one named target in the background with its output in build/logs/<target>-<date>.log and end the turn; the next turn reads the log. Read the exit status from the log (make <target> exit=N as the last line), not from the background wrapper, which reports the status of the echo that follows. No transient units, no per-attempt wrappers.

The gate on a build is checkflist, and it is run the way NetBSD runs it:

cd src/distrib/sets && DESTDIR=build/obj/destdir.amd64 MACHINE=amd64 \
    MACHINE_ARCH=x86_64 build/obj/tooldir.*/bin/nbmake-amd64 checkflist

build/obj/destdir.amd64 is the sysroot. Anything in it that no set lists is reported as extra and fails the build; anything a set lists that is not there is reported as missing. Do not hand-roll the checkflist environment -- the make target carries the set options (-L base,x, the METALOG sanitising) that the lists are written against.

The imports

  • src/ -- NetBSD, pinned at e523df740.
  • xsrc/ -- NetBSD X, pinned at 99aacae3.
  • pkgsrc/ -- pkgsrc trunk, pinned at 3c1118e94.

Each is its own git repository and a shallow clone; the pin is what the tree is built from, and moving a pin is a decision, not an accident.

Third-party packages (pkgsrc)

pkgsrc builds FOR the target with this tree's toolchain, not for the host:

cd pkgsrc/bootstrap && ./bootstrap --unprivileged --prefer-native=yes \
    --prefix /home/lotherk/src/makronix/build/pkg \
    --workdir /home/lotherk/src/makronix/build/pkgsrc-bootstrap \
    --mk-fragment /home/lotherk/src/makronix/tools/pkgsrc-cross.mk.conf \
    --make-jobs 16

--prefer-native=yes is not optional. Without it bootstrap writes PREFER_PKGSRC=yes on a Linux host (its own comment: Debian's other package managers leak in), and every library Makronix already ships in base -- curses, zlib, expat, freetype, fontconfig, the X libraries -- would be built a second time and installed under /usr/pkg. In a cross build "native" is the target base, which is where mk/buildlink3/bsd.builtin.mk looks it up, through TOOLS_CROSS_DESTDIR. Re-bootstrapping needs an empty prefix and work directory: rm -rf build/pkg build/pkgsrc-bootstrap first, both are build output.

tools/pkgsrc-cross.mk.conf is the whole configuration. TOOLDIR and CROSS_DESTDIR come from build/obj, every CROSS_* variable that bsd.prefs.mk demands is set there, work directories go to build/pkgsrc-work (so pkgsrc/ never gets dirty), and archives come from the shared DISTDIR outside the tree. A package is built with

cd pkgsrc/<category>/<pkg> && build/pkg/bin/bmake package

Two package tools, two jobs, and the difference matters:

  • The build side registers packages with pkgsrc's own bootstrap pkg_add, a host binary built from pkgsrc/pkgtools/pkg_install/files and pointed at the sysroot with -p. A NetBSD binary cannot run on the build host, so this is the only registrar pkgsrc can use; it is pkgsrc's own source, not the host's package manager.
  • The target's pkg_install comes from the distribution: src/external/bsd/ pkg_install (external/bsd/Makefile:18) is what build.sh builds for amd64 and ships in the base set (/usr/sbin/pkg_add, NetBSD ELF). pkgtools/pkg_install is deliberately not cross-built -- its libnbcompat dependency runs configure test programs, which cannot run while cross compiling, and a second pkg_install under /usr/pkg would only duplicate the one in base.

What this installs lands in ${CROSS_DESTDIR}/usr/pkg and is registered in ${CROSS_DESTDIR}/usr/pkg/pkgdb. checkflist then reports every one of those files as extra until a set lists it: a package is in the distribution when the set says so, not when the build installs it.

The "makronix" set

/usr/pkg belongs to one set of its own, makronix, and it is generated, not written by hand:

tools/makronix-set.sh            after the packages are installed

The script reads the installed tree back and writes the two things the release machinery needs: src/distrib/sets/lists/makronix/mi (the file list, for makeflist, checkflist, maketars) and the /usr/pkg records in ${DESTDIR}/METALOG (modes, owners, sizes, checksums, for checkflist -M and pax -M). pkg_add(1) writes no METALOG -- in a normal build those lines come from install -U -M -- so they are regenerated from the tree, owned by root:wheel as they are on an installed system. /usr/pkg/pkgdb is not part of the set: it is pkgsrc's registration database for the build, and checkflist ignores it the same way it ignores var/db/syspkg.

makronix is named in src/distrib/sets/sets.subr as one of the base sets, so build.sh's -L base,x and make release pick it up without a second flag. Removing a package means removing its entries from the list; entries that existed keep the NetBSD convention and are marked obsolete.

sysinst installs it. SET_MAKRONIX is an enum value in overlay/usr.sbin/sysinst/defs.h, a row in dist_list in util.c, part of SET_SYSTEM -- so a full installation and an installation without X11 both take it, a minimal one (SET_CORE) does not -- and a message in every msg.mi.*; msg_xlat.sh fails the build on a missing translation. Those places, not the list, are what make the set installable: with the list alone the release carries makronix.tar.xz and no installer unpacks it.

Measured from the medium this tree builds (build.sh ... install-image, then a full installation in the VM): Sets selected 20, makronix.tar.xz unpacked, /etc/mtree/set.makronix present (1814864 bytes), /usr/pkg/bin/{vim,flex}, /usr/pkg/dt/bin/{dtwm,dtlogin}, 219M under /usr/pkg; the installed system reaches login: on com0, and shutdown -p now runs the hooks, syncs the disks and powers off (build/logs/install2-boot.log, build/logs/install2-run.log). That test ran the image as built: distrib/amd64/installimage/boot.cfg.in stays as upstream wrote it, and the serial console was set at the loader prompt (consdev com0,115200) -- a boot.cfg that carries the line ships a medium that is deaf on a machine without a serial port.

Since 2026-11-07 the CD no longer carries the makronix set: it is on a second CD (tools/cd2.sh); the numbers in the next paragraph are from the single CD before that and are kept as history.

The second medium shape is the CD and the DVD. build.sh ... iso-image runs distrib/amd64/cdroms and writes two artifacts into releasedir/images: Makronix-0.99.9-amd64.iso (698 MiB, the install CD) and Makronix-0.99.9-amd64-dvd.iso (783 MiB, every set including base32); the boot.iso/boot-com.iso under installation/cdrom come from make release and are not install media. Measured from the CD as built: El Torito carries both a BIOS (bootxx.amd64) and a UEFI (efiboot.img) entry, the CD holds 20 sets including makronix.tar.xz, and the installer says so itself -- "The set base32 is optional and not included on this distribution medium", which is upstream's CD/DVD split, not a set we forgot. Full installation from the CD in the VM: Sets selected 20, extraction complete, the installed disk boots to login:, and shutdown -p now runs the hooks, syncs and powers off (ACPI S5, qemu exits on its own); the installed system carries /etc/mtree/set.makronix (10830 non-blank lines, 10826 entries), 224098 KiB under /usr/pkg, vim 4062512 bytes, 87 entries in /usr/pkg/dt/bin. The CD boots with the pc console, so that transcript is VGA screenshots (build/vm/iso-screen*.png) rather than a serial log: the CD's loader and kernel use the BIOS console, and choosing "serial port com0" on sysinst's bootblock screen did not move the installed disk to com0 in this run -- it still came up on VGA. The MD5/SHA512 in releasedir/images cover all four artifacts (makesums -A ... '*.iso'); before that they listed only the two install.img.gz, so a medium's checksum is regenerated with it.

What the set holds today: flex and vim, cross-built by pkgsrc against this tree's toolchain, and cde-2.5.3 with its runtime closure, built on the NetBSD build host (below) and unpacked into the sysroot -- 10826 entries in the list (the file has 10837 lines with its header), and checkflist reports no missing and no extra files, both after the distribution and after make release. The closure is walked over @pkgdep lines in the package's +CONTENTS, not over +DEPENDS: that file exists only inside a binary package, the registration database keeps the dependencies in +CONTENTS.

Where a Linux build host stops

pkgsrc's cross mode assumes the build host runs the target operating system (doc/HOWTO-use-crosscompile: "XXX This currently works only for NetBSD"). Three places decide something about the target by looking at the host, and a recipe that trips them cannot be built from here without changing pkgsrc, which this tree does not do:

  • mk/tools/replace.mk:142 refuses USE_TOOLS+=<tool>:run when OPSYS != NATIVE_OPSYS. wm/cde carries awk:run, so CDE stops with "USE_TOOLS+=awk:run not supported in cross-compilation". On a NetBSD build host the condition is false and the same recipe builds.
  • mk/tools/replace.mk:1334 decides that xbase is installed from ${X11BASE}/bin/<tool> on the host, and mk/bsd.pkg.mk:516 fails any package that uses X11 when ${X11BASE} does not exist there. In a cross build xbase is in the sysroot. Both refusals go away when X11BASE and TOOLS_PLATFORM.<tool> are pointed at ${CROSS_DESTDIR} for the invocation (bmake X11BASE=... TOOLS_PLATFORM.mkfontdir=... -V PKG_FAIL_REASON leaves only the awk:run line above); the fragment does not carry that by default, because a package that still cannot build does not need the setting.

Neither the checkflist gate nor the tree depends on these; a package that hits one is a finding for the report, not a reason to patch pkgsrc.

The build host for what a Linux host refuses

wm/cde trips the first of those, so it is not cross-built: it is built on a NetBSD amd64 host that this tree produces itself. build.sh ... live-image with tools/vm-boot.cfg gives an image whose console is com0, tools/vmctl.py drives it, and tools/vmbuild/ holds the stages that copy pkgsrc in, bootstrap it with --prefer-native=yes and build CDE. Nothing in pkgsrc and nothing in the recipe changes: the same wm/cde builds there.

Two settings were needed, both configuration, both scoped to wm/cde in the build host's mk.conf (tools/vmbuild/mk-cde.conf):

  • The dialect. The recipe runs autoreconf; autoconf 2.72's AC_PROG_CC takes the newest standard the compiler supports, C23 on GCC 14, where int f(); means int f(void). CDE declares functions that way (lib/tt/mini_isam/isaddindex.c:61) and calls one with three arguments at line 81, which is an error under C23. FORCE_C_STD=gnu11 -- the dialect NetBSD builds its own tree with (src/share/mk/bsd.sys.mk:68) -- is pkgsrc's documented override; the C wrapper appends it after the -std= that configure recorded, which is what makes it win.
  • The diagnostics. programs/dtksh/ksh93 is built by its own build system, which compiles with cc from PATH and ignores CFLAGS. GCC 14 made implicit declarations an error in every language mode, and libast decides by a successful compile what getfsstat() takes (src/lib/libast/features/fs:140); the probe therefore answered no and port/mnt.c compiled against struct statfs, which NetBSD no longer defines (libc exports getfsstat, the headers do not declare it). CWRAPPERS_APPEND.cc -- the hook mk/compiler/clang.mk fills in for clang 16+ -- puts the five GCC 14 downgrades into the wrapper's append list, the only thing that reaches those compiles.

A Linux host never shows either problem: the first is hidden by awk:run, the second needs a NetBSD base to build the ksh93 subtree at all.

Definition of done

A change is done when its test is green and it is committed. A build is done when checkflist reports no missing and no extra files. A medium is done when an install from it reaches a login prompt and shuts down cleanly -- with the log kept in the tree.

No claim without a measurement: file and line, exit code, log excerpt.

Forbidden

These are enforced by the PreToolUse hook tools/claude-build-gate.sh (configured in .claude/settings.json) where a hook can see them, and binding everywhere else:

  • building through systemd-run or any transient unit. One attempt is one named call of an entry point of the root Makefile.
  • make -C build, cd build && make, and hand-chained build.sh operations with self-chosen arguments.
  • writing, moving or deleting anything under build/obj/releasedir/** by hand. A wrong artefact means a wrong build. (The hook is textual: it refuses a command that names releasedir and also contains rm , mv , cp , touch , chmod , sed -i or > -- a redirection such as 2>&1 is enough, so a read-only ls can be refused. Do such reads without redirections, or in a script under tools/.)
  • git checkout, git clean, git reset anywhere that touches src/, xsrc/ or pkgsrc/. The import's state is the build; undo a patch with patch -R after a --dry-run, and record the change in patches/.
  • deleting src/distrib/sets/lists/** to make checkflist pass.
  • unattended loops: cron jobs, timers, or "tick" scripts that start builds or tests or hand work to an agent. An earlier setup did this every fifteen minutes, tested media the build had just removed and started builds in parallel; it was removed on 2026-11-06.

How to work

  • Plan before acting on anything non-trivial: say which command you will run and what you expect, then run it, then compare.
  • Every claim carries file:line or a log line. A sentence without one is a guess and is treated as one.
  • Do not trust a status document, a commit message or an old log over a measurement you can repeat. Repeat it.
  • src/, xsrc/, pkgsrc/ are untracked on purpose (each is its own repository). Changes to them go through patches/<tree>/NNNN-*.patch.
  • Tools in tools/ are POSIX sh: no Python, no bashisms. Check with dash -n and, where installed, checkbashisms.

AGENTS.md in every directory

Each directory of this repository has an AGENTS.md that says, in this order: what the directory is for, what is in it, what may be changed and how, what must not be touched. When a directory gains a purpose, a rule or a hazard, its AGENTS.md changes in the same commit.

The three imports (src/, xsrc/, pkgsrc/) are upstream trees of about 49,000 directories. They carry an AGENTS.md at the root of each, and src/ one in each of its 21 top-level directories (decided 2026-11-06). These files sit directly in the imports, untracked and outside patches/: they are not upstream, and a new import does not contain them, so after an upgrade they must be written again. Do not add AGENTS.md below that level: what a directory is for is answered by the upstream documentation (README, the manual pages, src/BUILDING, hier(7)), and pkgsrc alone has tens of thousands of packages.

Status of the measurements in this file

The numbers and the build/boot results in "The makronix set", "Where a Linux build host stops" and "The build host" were taken by earlier sessions, before 2026-11-06, and have not been repeated since. Re-measured on 2026-11-06 and confirmed: make release ARCH=amd64 and make iso exit 0 (build/logs/make-release-2026-11-06.log, make-iso2-2026-11-06.log), and the CD boots to sysinst's terminal prompt (build/logs/baseline-bios-boot-2026-11-06.log). Also measured that day: an installation from that CD to login: in the simple mode, BIOS/amd64, with /etc/mtree/set.makronix (1814864 bytes, the same size as the earlier measurement) and /usr/pkg/dt/bin/dtwm on the installed disk (tools/install-simple.sh; logs build/logs/install-simple-bios-*-2026-11-06.log). The installer printed 18 set archives with lower-case names, makronix.tar.xz among them; the kernel sets were not counted, so the "20" of the earlier measurement is not re-derived. Not yet re-measured: checkflist, the installation in the advanced mode, UEFI, and the sizes.