Makefile 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. # ═══════════════════════════════════════════════════════════════════
  2. # ArkOS Build System — Top-Level Makefile
  3. # ═══════════════════════════════════════════════════════════════════
  4. #
  5. # Targets:
  6. # make build — Full incremental build (cached Swift/SPM)
  7. # make run — Launch ArkOS in QEMU (BIOS mode)
  8. # make run-uefi — Launch ArkOS in QEMU (UEFI mode)
  9. # make clean — Remove all build artifacts and caches
  10. #
  11. # ═══════════════════════════════════════════════════════════════════
  12. # Project root is one level above this Makefile (arkos/Makefile)
  13. ROOT := $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/..)
  14. TOOLS := $(ROOT)/tools
  15. ARKOS := $(ROOT)/arkos
  16. CLANG := $(ARKOS)/prebuilts/clang/bin/clang
  17. .PHONY: build run run-uefi clean
  18. # ── Build ──────────────────────────────────────────────────────────
  19. # Compiles tools/build orchestrator, then runs the full pipeline.
  20. build:
  21. @$(MAKE) --no-print-directory -C $(TOOLS)
  22. @$(TOOLS)/build $(ARKOS)
  23. # ── Run (BIOS) ─────────────────────────────────────────────────────
  24. # Launches ArkOS in QEMU with:
  25. # - 2 GB RAM, 2 CPU cores
  26. # - VirtIO GPU for hardware-accelerated display
  27. # - VirtIO NIC with user-mode networking (TCP/IP stack via QEMU)
  28. # - Three disk images: boot, system, vendor
  29. # - KVM acceleration (falls back to software emulation)
  30. run:
  31. @echo "Starting ArkOS in QEMU (BIOS mode)..."
  32. @qemu-system-x86_64 \
  33. -m 2048 \
  34. -smp 2 \
  35. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  36. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  37. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  38. -vga virtio -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  39. -netdev user,id=net0 \
  40. -device virtio-net-pci,netdev=net0 \
  41. -enable-kvm 2>/dev/null || \
  42. qemu-system-x86_64 \
  43. -m 2048 \
  44. -smp 2 \
  45. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  46. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  47. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  48. -vga virtio -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  49. -netdev user,id=net0 \
  50. -device virtio-net-pci,netdev=net0 \
  51. -serial stdio
  52. # ── Run (UEFI) ────────────────────────────────────────────────────
  53. run-uefi:
  54. @echo "Starting ArkOS in QEMU (UEFI mode)..."
  55. @qemu-system-x86_64 \
  56. -bios /usr/share/edk2/x64/OVMF.4m.fd \
  57. -m 2048 \
  58. -smp 2 \
  59. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  60. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  61. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  62. -device virtio-vga,xres=1080,yres=1900 -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  63. -netdev user,id=net0 \
  64. -device virtio-net-pci,netdev=net0 \
  65. -enable-kvm 2>/dev/null || \
  66. qemu-system-x86_64 \
  67. -bios /usr/share/edk2/x64/OVMF.4m.fd \
  68. -m 2048 \
  69. -smp 2 \
  70. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  71. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  72. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  73. -device virtio-vga,xres=1080,yres=1900 -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  74. -netdev user,id=net0 \
  75. -device virtio-net-pci,netdev=net0
  76. # ── Clean ──────────────────────────────────────────────────────────
  77. # Removes ALL build artifacts including SPM cache.
  78. clean:
  79. rm -rf out_staging finished boot/assets
  80. @$(MAKE) --no-print-directory -C $(TOOLS) clean
  81. # ═══════════════════════════════════════════════════════════════════
  82. # Binary Compilation Targets
  83. # ═══════════════════════════════════════════════════════════════════
  84. # These are invoked by tools/build via `make -C <arkos-dir> <target>`.
  85. # They use direct swiftc compilation for minimal overhead.
  86. # ═══════════════════════════════════════════════════════════════════
  87. # Extract the Verified Boot signing key from vendor config
  88. ARK_KEY := $(shell if [ -f vendor/verify/securebuild.ark ]; then \
  89. grep "^ARK-OS-" vendor/verify/securebuild.ark | tr -d '[:space:]'; \
  90. else echo "NO_KEY"; fi)
  91. # ── fb_helper.o — Framebuffer ioctl bridge (C → Swift interop) ────
  92. out_staging/fb_helper.o: system/core/fb_helper.c
  93. gcc -c system/core/fb_helper.c -o out_staging/fb_helper.o
  94. # ── swift_splash — Boot Animation ────────────────────────────────
  95. # Moved to ui_daemon
  96. # (Removed swift_splash target)
  97. # ── arkrt — ArkOS Runtime Daemon (PID 2) ──────────────────────────
  98. out_staging/arkrt: arkrt/main.swift arkrt/KernelBridge.swift \
  99. arkrt/CommandRouter.swift arkrt/IPC.swift \
  100. arkrt/ServiceManager.swift arkrt/NetworkService.swift
  101. swiftc -O -static-executable \
  102. arkrt/main.swift arkrt/KernelBridge.swift \
  103. arkrt/CommandRouter.swift arkrt/IPC.swift \
  104. arkrt/ServiceManager.swift arkrt/NetworkService.swift \
  105. -o out_staging/arkrt
  106. # ── init — PID 1 process (mounts filesystems, verifies boot) ─────
  107. out_staging/init: system/core/init.c vendor/verify/sha256.c
  108. gcc -static vendor/verify/sha256.c system/core/init.c \
  109. -Ivendor/verify -DARK_KEY=\""$(ARK_KEY)"\" \
  110. -o out_staging/init
  111. # ── Bootloader binaries (BIOS + UEFI) ────────────────────────────
  112. out_staging/bootloader.bin: boot/source/bootloader.asm
  113. nasm -f bin boot/source/bootloader.asm -o out_staging/bootloader.bin
  114. out_staging/stage2.bin: boot/source/stage2.asm
  115. nasm -f bin boot/source/stage2.asm -o out_staging/stage2.bin
  116. out_staging/BOOTX64.EFI: boot/source/bootloader.c
  117. gcc -I/usr/include/efi -I/usr/include/efi/x86_64 -I/usr/include/efi/protocol \
  118. -fno-stack-protector -fpic -fshort-wchar -mno-red-zone -DEFI_FUNCTION_WRAPPER \
  119. -c boot/source/bootloader.c -o out_staging/bootloader_uefi.o
  120. ld -nostdlib -znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic \
  121. /usr/lib/crt0-efi-x86_64.o out_staging/bootloader_uefi.o \
  122. -o out_staging/bootloader_uefi.so -lgnuefi -lefi -L/usr/lib
  123. objcopy -j .text -j .sdata -j .data -j .rodata -j .dynamic -j .dynsym \
  124. -j .rel -j .rela -j .reloc -j .eh_frame \
  125. -O pei-x86-64 --subsystem 10 out_staging/bootloader_uefi.so out_staging/BOOTX64.EFI
  126. # ── ui_daemon — Display Compositor ─────────────────────────────────
  127. out_staging/system/ui_daemon: system/display/main.swift system/display/splash.swift out_staging/fb_helper.o
  128. @mkdir -p out_staging/system
  129. @swiftc -O -static-executable \
  130. system/display/main.swift system/display/splash.swift out_staging/fb_helper.o \
  131. -o out_staging/system/ui_daemon
  132. # ── ui_test — Setup / Welcome app ────────────────────────────────
  133. out_staging/system/ui_test: system/apps/ui_test.swift frameworks/ArkGraphics/ArkGraphics.swift
  134. mkdir -p out_staging/system
  135. swiftc -O -static-executable \
  136. system/apps/ui_test.swift frameworks/ArkGraphics/ArkGraphics.swift \
  137. -o out_staging/system/ui_test