RustForge

foundry

Foundry OS: the operating system built on the Rustbelt kernel

foundry / Makefile
3758 bytes ยท raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Foundry OS -- the single entry point. `make help` lists the targets.
#
# Everything generated goes to out/ (git-ignored); `make clean` removes it.
# Downloads (musl source etc.) go to cache/ (git-ignored, SHA256-checked).

include config.mk

OUT        := $(CURDIR)/out
IMAGE      := $(OUT)/$(IMAGE_NAME)
STAGING    := $(OUT)/staging
RUST_OUT   := $(OUT)/rust-target/x86_64-unknown-none/release
FIXTURES   := $(OUT)/fixtures
KSRC       := $(OUT)/kernel-src
KTARGET    := $(OUT)/kernel-target
KBOOT      := $(OUT)/kernel/bootimage.bin
KBOOT_HL   := $(OUT)/kernel/bootimage-headless.bin

.DEFAULT_GOAL := image
.PHONY: help image rust fixtures staging kernel kernel-src run test test-reference compare musl clean distclean

help:
	@echo "Foundry OS (userland for the Rustbelt kernel $(KERNEL_VERSION) @ $(KERNEL_REV))"
	@echo ""
	@echo "  make / make image   build out/$(IMAGE_NAME), the disk image (contract $(CONTRACT))"
	@echo "  make rust           cargo build the Rust programs in rust/"
	@echo "  make fixtures       build the kernel's ABI test programs from the pinned kernel"
	@echo "  make staging        assemble out/staging (rootfs/ + /bin)"
	@echo "  make kernel         build the pinned kernel into out/kernel-target"
	@echo "  make run            boot the image in a QEMU window"
	@echo "  make test           headless boot + the shell self-test + expected-line checks"
	@echo "  make test-reference  the same headless test, but booting the kernel's own disk.img (baseline)"
	@echo "  make compare        compare out/$(IMAGE_NAME) with the kernel's own disk.img"
	@echo "  make musl           fetch (cache/) + build musl $(MUSL_VERSION) into out/sysroot (not in the image yet)"
	@echo "  make clean          rm -rf out   (distclean also removes cache/)"

# ---- the pinned kernel -------------------------------------------------------
kernel-src:
	scripts/build-kernel.sh $(KERNEL_DIR) $(KERNEL_REV) $(OUT) --export-only

kernel:
	scripts/build-kernel.sh $(KERNEL_DIR) $(KERNEL_REV) $(OUT)

# ---- programs ---------------------------------------------------------------
rust:
	cd rust && CARGO_TARGET_DIR=$(OUT)/rust-target cargo build --release

fixtures: kernel-src
	scripts/build-fixtures.sh $(KSRC) $(FIXTURES) "$(FIXTURE_RUST)" "$(FIXTURE_C)" "$(FIXTURE_MUSL)"

# ---- the image ---------------------------------------------------------------
# Contract v1: rootfs/ minus etc/ (etc/ is for the contract-v2 ext2 root,
# see docs/plan.md) goes to the top of the FAT32 volume, programs to /bin.
staging: rust fixtures
	rm -rf $(STAGING) && mkdir -p $(STAGING)/bin
	cd rootfs && for e in $$(ls -A); do [ "$$e" = etc ] && [ "$(CONTRACT)" = v1 ] && continue; cp -r "$$e" $(STAGING)/; done
	for p in $(filter-out sh,$(RUST_PROGRAMS)); do cp $(RUST_OUT)/$$p $(STAGING)/bin/; done
	cp $(RUST_OUT)/rbsh $(STAGING)/bin/sh    # contract v1: the kernel runs /mnt/disk0/bin/sh
	cp $(FIXTURES)/* $(STAGING)/bin/

image: staging
	scripts/mkimage.sh $(STAGING) $(IMAGE) $(IMAGE_MIB) $(IMAGE_LABEL) "$(BIN_ORDER)"

# ---- booting ----------------------------------------------------------------
run: image kernel
	scripts/run-qemu.sh $(IMAGE) $(KBOOT) $(KTARGET) $(OUT)

test: image kernel
	scripts/run-headless.sh $(IMAGE) $(KBOOT_HL) $(KTARGET) $(OUT)

# The baseline: the kernel's own disk.img through the very same checks.
test-reference: kernel
	scripts/run-headless.sh $(KTARGET)/disk.img $(KBOOT_HL) $(KTARGET) $(OUT)/reference

compare: image kernel
	scripts/compare-image.sh $(IMAGE) $(KTARGET)/disk.img $(OUT)

# ---- toolchain (M2 groundwork; not used by the v1 image) ---------------------
musl:
	toolchain/musl/fetch.sh cache
	toolchain/musl/build.sh cache $(OUT)/musl-build $(OUT)/sysroot

clean:
	rm -rf out

distclean: clean
	rm -rf cache