diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9f03f93 --- /dev/null +++ b/Makefile | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | # shellcheck shell=sh disable=SC2046,SC2091,SC2086,SC2155 | ||
| 2 | # NOTE: $(VAR) in this file is MAKE syntax, not shell substitution. | ||
| 3 | export TARGET=x86_64-unknown-uefi | ||
| 4 | export PROFILE=debug | ||
| 5 | export OUT_DIR=target/$(TARGET)/$(PROFILE) | ||
| 6 | export ESP_DIR=esp | ||
| 7 | export KERNEL=$(OUT_DIR)/raisernics.efi | ||
| 8 | export BZIMAGE=$(ESP_DIR)/bzImage | ||
| 9 | export INITRD=$(ESP_DIR)/initramfs.cpio.gz | ||
| 10 | export BOOTLOADER=../rng/rsbl/../build/bootloader/BOOTX64.EFI | ||
| 11 | export OVMF=/usr/share/edk2/x64/OVMF.4m.fd | ||
| 12 | export BOOT_EFI=$(ESP_DIR)/EFI/BOOT/BOOTX64.EFI | ||
| 13 | |||
| 14 | .PHONY: all run run-gui clean image debug release fmt | ||
| 15 | |||
| 16 | # ---- Build --------------------------------------------------------------- | ||
| 17 | |||
| 18 | all: $(BZIMAGE) $(INITRD) $(BOOT_EFI) | ||
| 19 | |||
| 20 | release: PROFILE=release | ||
| 21 | release: export PROFILE=release | ||
| 22 | release: export OUT_DIR=target/$(TARGET)/release | ||
| 23 | release: CARGO_FLAGS=--release | ||
| 24 | release: all | ||
| 25 | |||
| 26 | # shellcheck disable=SC2034 | ||
| 27 | CARGO_FLAGS= | ||
| 28 | |||
| 29 | $(OUT_DIR)/raisernics.efi: $(shell find src -name '*.rs') Cargo.toml build.rs | ||
| 30 | cargo build --target $(TARGET) $(CARGO_FLAGS) | ||
| 31 | |||
| 32 | $(BZIMAGE): $(KERNEL) | $(ESP_DIR) | ||
| 33 | cp "$<" "$@" | ||
| 34 | |||
| 35 | $(BOOT_EFI): $(BOOTLOADER) | $(ESP_DIR) | ||
| 36 | mkdir -p $(ESP_DIR)/EFI/BOOT | ||
| 37 | cp "$<" "$@" | ||
| 38 | |||
| 39 | $(ESP_DIR): | ||
| 40 | mkdir -p $(ESP_DIR) | ||
| 41 | |||
| 42 | $(INITRD): | $(ESP_DIR) | ||
| 43 | printf '' | gzip > "$@" | ||
| 44 | |||
| 45 | # ---- QEMU runners -------------------------------------------------------- | ||
| 46 | |||
| 47 | run: all | ||
| 48 | qemu-system-x86_64 \ | ||
| 49 | -bios $(OVMF) \ | ||
| 50 | -drive file=fat:rw:$(ESP_DIR),format=raw \ | ||
| 51 | -serial stdio \ | ||
| 52 | -m 256M \ | ||
| 53 | -machine q35 \ | ||
| 54 | -cpu qemu64 \ | ||
| 55 | -no-reboot \ | ||
| 56 | -display none | ||
| 57 | |||
| 58 | run-gui: all | ||
| 59 | qemu-system-x86_64 \ | ||
| 60 | -bios $(OVMF) \ | ||
| 61 | -drive file=fat:rw:$(ESP_DIR),format=raw \ | ||
| 62 | -serial stdio \ | ||
| 63 | -m 256M \ | ||
| 64 | -machine q35 \ | ||
| 65 | -cpu qemu64 \ | ||
| 66 | -no-reboot \ | ||
| 67 | -vga std | ||
| 68 | |||
| 69 | # GDB stub on :1234 | ||
| 70 | debug: all | ||
| 71 | qemu-system-x86_64 \ | ||
| 72 | -bios $(OVMF) \ | ||
| 73 | -drive file=fat:rw:$(ESP_DIR),format=raw \ | ||
| 74 | -serial stdio \ | ||
| 75 | -m 256M \ | ||
| 76 | -machine q35 \ | ||
| 77 | -cpu qemu64 \ | ||
| 78 | -no-reboot \ | ||
| 79 | -display none \ | ||
| 80 | -s -S | ||
| 81 | |||
| 82 | # Boot from a raw disk image (created by tools/boot-image.sh) | ||
| 83 | run-image: all | ||
| 84 | qemu-system-x86_64 \ | ||
| 85 | -bios $(OVMF) \ | ||
| 86 | -drive file=$(IMG),format=raw,if=none,id=hd \ | ||
| 87 | -device ide-hd,drive=hd \ | ||
| 88 | -serial stdio \ | ||
| 89 | -m 256M \ | ||
| 90 | -machine q35 \ | ||
| 91 | -cpu qemu64 \ | ||
| 92 | -no-reboot \ | ||
| 93 | -display none | ||
| 94 | |||
| 95 | # ---- Disk image ---------------------------------------------------------- | ||
| 96 | |||
| 97 | image: all | ||
| 98 | ./tools/boot-image.sh raisernics.img | ||
| 99 | |||
| 100 | # ---- Utilities ----------------------------------------------------------- | ||
| 101 | |||
| 102 | fmt: | ||
| 103 | cargo fmt | ||
| 104 | |||
| 105 | clean: | ||
| 106 | cargo clean | ||
| 107 | rm -rf $(ESP_DIR) raisernics.img | ||
| 108 | |||
| 109 | help: | ||
| 110 | @echo "raisernics — Make targets" | ||
| 111 | @echo "" | ||
| 112 | @echo " make build kernel + ESP (default)" | ||
| 113 | @echo " make release build with --release (smaller binary)" | ||
| 114 | @echo " make image create bootable USB image (raisernics.img)" | ||
| 115 | @echo " make run QEMU serial console (no graphics)" | ||
| 116 | @echo " make run-gui QEMU with graphical window (GOP/PS2)" | ||
| 117 | @echo " make debug QEMU + GDB stub on :1234" | ||
| 118 | @echo " make clean remove build artifacts" | ||
| 119 | @echo " make fmt format Rust source" | ||
| 120 | @echo "" | ||
| 121 | @echo "Scripts:" | ||
| 122 | @echo " ./tools/qemu.sh flexible QEMU launcher" | ||
| 123 | @echo " ./tools/boot-image.sh create bootable disk image" | ||
| 124 | @echo " ./tools/debug-kernel.py GDB plugin (attach after 'make debug')" | ||
