Makefile 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. -usb -device usb-tablet \
  41. -device virtio-net-pci,netdev=net0 \
  42. -qmp unix:./qmp-sock,server,nowait \
  43. -enable-kvm 2>/dev/null || \
  44. qemu-system-x86_64 \
  45. -m 2048 \
  46. -smp 2 \
  47. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  48. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  49. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  50. -vga virtio -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  51. -netdev user,id=net0 \
  52. -usb -device usb-tablet \
  53. -device virtio-net-pci,netdev=net0 \
  54. -qmp unix:./qmp-sock,server,nowait \
  55. -serial stdio
  56. # ── Run (UEFI) ────────────────────────────────────────────────────
  57. run-uefi:
  58. @echo "Starting ArkOS in QEMU (UEFI mode)..."
  59. @qemu-system-x86_64 \
  60. -bios /usr/share/edk2/x64/OVMF.4m.fd \
  61. -m 2048 \
  62. -smp 2 \
  63. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  64. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  65. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  66. -device virtio-vga,edid=on,xres=3840,yres=2160 -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  67. -usb -device usb-tablet \
  68. -netdev user,id=net0 \
  69. -device virtio-net-pci,netdev=net0 \
  70. -monitor unix:/tmp/qemu-monitor.sock,server,nowait \
  71. -qmp unix:./qmp-sock,server,nowait \
  72. -enable-kvm 2>/dev/null || \
  73. qemu-system-x86_64 \
  74. -bios /usr/share/edk2/x64/OVMF.4m.fd \
  75. -m 2048 \
  76. -smp 2 \
  77. -drive file=finished/boot.img,format=raw,index=0,media=disk,if=virtio \
  78. -drive file=finished/sys.img,format=raw,index=1,media=disk,if=virtio \
  79. -drive file=finished/vend.img,format=raw,index=2,media=disk,if=virtio \
  80. -device virtio-vga,edid=on,xres=3840,yres=2160 -debugcon file:ovmf.log -global isa-debugcon.iobase=0x402 \
  81. -netdev user,id=net0 \
  82. -usb -device usb-tablet \
  83. -device virtio-net-pci,netdev=net0
  84. # ── Clean ──────────────────────────────────────────────────────────
  85. # Removes ALL build artifacts including SPM cache.
  86. clean:
  87. rm -rf out_staging finished boot/assets
  88. @$(MAKE) --no-print-directory -C $(TOOLS) clean
  89. # ═══════════════════════════════════════════════════════════════════
  90. # Binary Compilation Targets
  91. # ═══════════════════════════════════════════════════════════════════
  92. # These are invoked by tools/build via `make -C <arkos-dir> <target>`.
  93. # They use direct swiftc compilation for minimal overhead.
  94. # ═══════════════════════════════════════════════════════════════════
  95. # Extract the Verified Boot signing key from vendor config
  96. ARK_KEY := $(shell if [ -f vendor/verify/securebuild.ark ]; then \
  97. grep "^ARK-OS-" vendor/verify/securebuild.ark | tr -d '[:space:]'; \
  98. else echo "NO_KEY"; fi)
  99. # ── fb_helper.o — Framebuffer ioctl bridge (C → Swift interop) ────
  100. out_staging/fb_helper.o: system/core/fb_helper.c
  101. gcc -c system/core/fb_helper.c -o out_staging/fb_helper.o
  102. # ── swift_splash — Boot Animation ────────────────────────────────
  103. # Moved to ui_daemon
  104. # (Removed swift_splash target)
  105. # ── arkrt — ArkOS Runtime Daemon (PID 2) ──────────────────────────
  106. out_staging/arkrt: arkrt/main.swift arkrt/KernelBridge.swift \
  107. arkrt/CommandRouter.swift arkrt/IPC.swift \
  108. arkrt/ServiceManager.swift arkrt/NetworkService.swift \
  109. arkrt/InputService.swift
  110. swiftc -O -static-executable \
  111. arkrt/main.swift arkrt/KernelBridge.swift \
  112. arkrt/CommandRouter.swift arkrt/IPC.swift \
  113. arkrt/ServiceManager.swift arkrt/NetworkService.swift \
  114. arkrt/InputService.swift \
  115. -o out_staging/arkrt
  116. # ── init — PID 1 process (mounts filesystems, verifies boot) ─────
  117. out_staging/init: system/core/init.c vendor/verify/sha256.c
  118. gcc -static vendor/verify/sha256.c system/core/init.c \
  119. -Ivendor/verify -DARK_KEY=\""$(ARK_KEY)"\" \
  120. -o out_staging/init
  121. # ── Bootloader binaries (BIOS + UEFI) ────────────────────────────
  122. out_staging/bootloader.bin: boot/source/bootloader.asm
  123. nasm -f bin boot/source/bootloader.asm -o out_staging/bootloader.bin
  124. out_staging/stage2.bin: boot/source/stage2.asm
  125. nasm -f bin boot/source/stage2.asm -o out_staging/stage2.bin
  126. out_staging/BOOTX64.EFI: boot/source/bootloader.c
  127. gcc -I/usr/include/efi -I/usr/include/efi/x86_64 -I/usr/include/efi/protocol \
  128. -fno-stack-protector -fpic -fshort-wchar -mno-red-zone -DEFI_FUNCTION_WRAPPER \
  129. -c boot/source/bootloader.c -o out_staging/bootloader_uefi.o
  130. ld -nostdlib -znocombreloc -T /usr/lib/elf_x86_64_efi.lds -shared -Bsymbolic \
  131. /usr/lib/crt0-efi-x86_64.o out_staging/bootloader_uefi.o \
  132. -o out_staging/bootloader_uefi.so -lgnuefi -lefi -L/usr/lib
  133. objcopy -j .text -j .sdata -j .data -j .rodata -j .dynamic -j .dynsym \
  134. -j .rel -j .rela -j .reloc -j .eh_frame \
  135. -O pei-x86-64 --subsystem 10 out_staging/bootloader_uefi.so out_staging/BOOTX64.EFI
  136. # ── ui_daemon — Display Compositor ─────────────────────────────────
  137. out_staging/system/ui_daemon: system/display/main.swift system/display/splash.swift out_staging/fb_helper.o
  138. @mkdir -p out_staging/system
  139. @swiftc -O -static-executable \
  140. system/display/main.swift system/display/splash.swift out_staging/fb_helper.o \
  141. -o out_staging/system/ui_daemon
  142. # ── ui_test — Setup / Welcome app ────────────────────────────────
  143. out_staging/ArkFontRobotoBoldData.o: frameworks/ArkGraphics/ArkFontRobotoBoldData.c
  144. @mkdir -p out_staging
  145. @clang -O3 -c frameworks/ArkGraphics/ArkFontRobotoBoldData.c -o out_staging/ArkFontRobotoBoldData.o
  146. out_staging/system/ui_test: system/apps/ui_test.swift frameworks/ArkGraphics/ArkGraphics.swift frameworks/ArkGraphics/ArkFontRobotoBold.swift frameworks/ArkGraphics/ArkWrite.swift frameworks/ArkGraphics/ArkShapes.swift frameworks/SwiftUI/Sources/ui_test/ArkInput.swift out_staging/ArkFontRobotoBoldData.o
  147. mkdir -p out_staging/system
  148. swiftc -O -static-executable \
  149. system/apps/ui_test.swift frameworks/ArkGraphics/ArkGraphics.swift frameworks/ArkGraphics/ArkFontRobotoBold.swift frameworks/ArkGraphics/ArkWrite.swift frameworks/ArkGraphics/ArkShapes.swift frameworks/SwiftUI/Sources/ui_test/ArkInput.swift out_staging/ArkFontRobotoBoldData.o \
  150. -o out_staging/system/ui_test