1- SWIFT_EXEC ?= swift
2- CLANG ?= $(shell if [ "$(shell uname) " = "Darwin" ]; then xcrun -f clang; else which clang; fi)
3- LLVM_OBJCOPY ?= $(shell if [ "$(shell uname) " = "Darwin" ]; then xcrun -f llvm-objcopy; else which llvm-objcopy; fi)
1+ # #===----------------------------------------------------------------------===##
2+ # #
3+ # # This source file is part of the Swift open source project
4+ # #
5+ # # Copyright (c) 2025 Apple Inc. and the Swift project authors.
6+ # # Licensed under Apache License v2.0 with Runtime Library Exception
7+ # #
8+ # # See https://swift.org/LICENSE.txt for license information
9+ # #
10+ # #===----------------------------------------------------------------------===##
411
5- BUILDROOT := $(shell $(SWIFT_EXEC ) build --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector --show-bin-path)
12+ # Paths
13+ REPOROOT := $(shell git rev-parse --show-toplevel)
14+ TOOLSROOT := $(REPOROOT ) /Tools
15+ TOOLSET := $(TOOLSROOT ) /Toolsets/rpi-5-elf.json
16+ LLVM_OBJCOPY := llvm-objcopy
17+ SWIFT_BUILD := swift build
618
7- .PHONY : all clean
19+ # Flags
20+ ARCH := aarch64
21+ TARGET := $(ARCH ) -none-none-elf
22+ SWIFT_BUILD_ARGS := \
23+ --configuration release \
24+ --triple $(TARGET ) \
25+ --toolset $(TOOLSET ) \
26+ --disable-local-rpath
27+ BUILDROOT := $(shell $(SWIFT_BUILD ) $(SWIFT_BUILD_ARGS ) --show-bin-path)
828
9- all : kernel8.img
29+ .PHONY : build
30+ build :
31+ @echo " building..."
32+ $(SWIFT_BUILD ) \
33+ $(SWIFT_BUILD_ARGS ) \
34+ --verbose
1035
11- kernel8.img : kernel8.elf
12- @echo " 💾 Converting to binary kernel image with llvm-objcopy... "
13- $( LLVM_OBJCOPY ) -O binary kernel8.elf kernel8.img
14- @echo " "
15- @echo " 🥳 Done! kernel8.img was saved to this directory. "
36+ @echo "extracting binary..."
37+ $(LLVM_OBJCOPY) \
38+ -O binary \
39+ "$(BUILDROOT)/Application" \
40+ "$(BUILDROOT)/Application.bin" \
1641
17- kernel8.elf : $(BUILDROOT ) /libMainApp.a $(BUILDROOT ) /Support.build/boot.S.o link.ld
18- @echo " 🔗 Linking with clang..."
19- $(CLANG ) --target=aarch64-elf -o kernel8.elf $< $^ -fuse-ld=lld -nostdlib -Wl,--unresolved-symbols=ignore-in-object-files -Wl,-T ./link.ld -## #
20- @echo " "
21-
22- $(BUILDROOT ) /libMainApp.a $(BUILDROOT ) /Support.build/boot.S.o :
23- @echo " 🛠️ Building with Swift Package Manager..."
24- $(SWIFT_EXEC ) build --triple aarch64-none-none-elf -Xswiftc -Xfrontend -Xswiftc -disable-stack-protector
25- @echo " "
2642
43+ .PHONY : clean
2744clean :
28- rm -rf kernel8.elf kernel8.img .build
45+ @echo " cleaning..."
46+ @swift package clean
47+ @rm -rf .build
0 commit comments