include: one folder per subsystem, and includes that name it

Sixty-five headers sat side by side in include/, so `#include "irq.h"`
said nothing about where irq.h was or what it belonged to, and errno.h,
stat.h and fcntl.h at the top shadowed the system's for any host tool
built with -I./include. They are in folders now -- arch/ core/ fs/
dev/ gfx/ net/ uapi/ (and ldls/ for the Linux driver layer) -- and
every include names the folder, as Linux's do: "core/proc.h".

Done mechanically and checked the hard way: the kernel built from this
tree disassembles identically to the one built from the tree before
it. The full image boots, and userland is the same set of programs.
Paths in docs and comments follow; docs/guides/layout.md has a table
of what is where, and tools/fix-includes.py rewrites old-style
includes from the folders in the tree, for code written before this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
This commit is contained in:
Nexoniarz 2026-10-23 15:05:12 +02:00
commit a1c965da1e
267 changed files with 1560 additions and 1440 deletions

View file

@ -34,7 +34,7 @@ KERN_DEV = $(addprefix $(BUILD)/kernel/dev/, \
#
# drivers/<class>/<driver>/ -- one directory per driver, so a driver that grows
# a register header, a second source file or a firmware blob has somewhere to
# put it. Classes match include/device.h's DEVCLASS_*. Everything flat was
# put it. Classes match include/dev/device.h's DEVCLASS_*. Everything flat was
# already eight files with four called usb_something, and each driver added made
# the directory harder to read. The compile rule uses `mkdir -p $(dir $@)`, so
# the depth costs nothing.
@ -563,7 +563,7 @@ kernel: $(BUILD)/kernel/kernel
# make DEBUG=1
#
# What it turns on is the *boot menu's* remote-debugging entry, and nothing
# else -- see SCHBOOT_DEBUG_FLAG in include/schboot.h. A release build has no
# else -- see SCHBOOT_DEBUG_FLAG in include/arch/schboot.h. A release build has no
# way to switch a network debugger on, because the code that would set the flag
# is not compiled into it. That is the point: a menu item that is present and
# refuses is an invitation to find out how to make it not refuse.
@ -599,9 +599,9 @@ UEFI_CFLAGS = $(UEFI_DEBUG_FLAGS) --target=x86_64-unknown-windows -ffreestanding
# looking at the wrong thing.
#
# Hence the check and the message. It is worth the four lines.
$(BUILD)/uefi/BOOTX64.EFI: boot/uefi/main.c boot/uefi/efi.h include/schboot.h \
$(BUILD)/uefi/BOOTX64.EFI: boot/uefi/main.c boot/uefi/efi.h include/arch/schboot.h \
boot/common/ui.c boot/common/ui.h \
include/logo.h include/theme.h include/font.h
include/gfx/logo.h include/gfx/theme.h include/gfx/font.h
@mkdir -p $(BUILD)/uefi
@command -v clang >/dev/null 2>&1 || { \
echo ""; \
@ -1085,7 +1085,7 @@ SCHFS_SRC = kernel/fs/schfs/btree.c kernel/fs/schfs/btree.h \
kernel/fs/schfs/space.c kernel/fs/schfs/vol.c \
kernel/fs/schfs/obj.c kernel/fs/schfs/objw.c \
kernel/fs/schfs/attr.c \
kernel/fs/schfs/schfs_int.h include/schfs.h
kernel/fs/schfs/schfs_int.h include/fs/schfs.h
# -iquote, not -I: include/ has its own errno.h, stat.h, fcntl.h and types.h,
# and -I would put them ahead of the system ones for a host program that needs
@ -1115,7 +1115,7 @@ schfs-objtest: $(SCHFS_OBJT)
# page-to-cache lookup, and whether pages actually come back -- is asserted in
# a second rather than in a boot.
KMEMTEST = $(BUILD)/tools/kmemtest$(EXE)
$(KMEMTEST): tools/kmemtest.c kernel/core/kmem.c include/kmem.h
$(KMEMTEST): tools/kmemtest.c kernel/core/kmem.c include/core/kmem.h
@mkdir -p $(BUILD)/tools
$(HOSTCC) $(HOSTCFLAGS) -I include -o $@ tools/kmemtest.c
@ -1239,9 +1239,9 @@ ldls-unstage:
ldls-check: $(LDLS_INSPECT) $(LDLS_RUN) $(LDLS_TYPES) $(LDLS_REFMOD)
$(PYTHON) tools/python/ldls_check.py $(LDLS_INSPECT) $(LDLS_REFMOD) $(LDLS_RUN)
$(MKFS): tools/mkfs.c include/fs.h include/stat.h include/param.h
$(MKFS): tools/mkfs.c include/fs/fs.h include/uapi/stat.h include/core/param.h
@mkdir -p $(BUILD)/tools
$(HOSTCC) $(HOSTWARN) -I. -o $(MKFS) tools/mkfs.c
$(HOSTCC) $(HOSTWARN) -I. -iquote ./include -o $(MKFS) tools/mkfs.c
# Stage everything a running system needs into sysroot/, then image it.
#
@ -1504,7 +1504,7 @@ qemu-schfs: esp $(BUILD)/schfs.img $(OVMF_CODE) $(OVMF_VARS)
# re-run its four dd commands -- including zeroing five megabytes -- on every
# single invocation, including ones where nothing had changed. The file is gone
# with the BIOS loader, but the rule it taught applies to whatever replaces it.
# include/logo.h is generated but committed, exactly as include/font.h is: it
# include/gfx/logo.h is generated but committed, exactly as include/gfx/font.h is: it
# derives from art that changes about never, and making it a build dependency
# would put Python on the critical path of every clean build for no benefit.
# Run this by hand after changing the art.
@ -1515,7 +1515,7 @@ LOGO_SRC = docs/branding/shift-mask.png
LOGO_PX = 128
logo:
$(PYTHON) tools/python/mklogo.py "$(LOGO_SRC)" include/logo.h $(LOGO_PX)
$(PYTHON) tools/python/mklogo.py "$(LOGO_SRC)" include/gfx/logo.h $(LOGO_PX)
# The USB vendor/product name database, from linux-usb.org.
#
@ -1559,7 +1559,7 @@ hwdata: usb-ids pci-ids
# verified mechanically and the PNG covers the rest: point a phone at it.
QRTEST = $(BUILD)/tools/qrtest$(EXE)
$(QRTEST): tools/qrtest.c kernel/core/qr.c include/qr.h
$(QRTEST): tools/qrtest.c kernel/core/qr.c include/gfx/qr.h
@mkdir -p $(BUILD)/tools
$(HOSTCC) $(HOSTWARN) -I./include -o $@ tools/qrtest.c
@ -1599,6 +1599,6 @@ distclean: clean
# exactly one level, so build/kernel/core/*.d was picked up while
# build/kernel/arch/x86_64/*.d and build/kernel/fs/schfs/*.d were not.
# Everything under arch/ and schfs/ therefore had NO header dependency
# tracking at all -- editing include/schfs.h or include/mmu.h left stale
# tracking at all -- editing include/fs/schfs.h or include/arch/mmu.h left stale
# objects that linked without complaint. find actually recurses.
-include $(shell find $(BUILD) -name '*.d' 2>/dev/null)