|
| 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 | +##===----------------------------------------------------------------------===## |
| 11 | + |
| 12 | +# Paths |
| 13 | +REPOROOT := $(shell git rev-parse --show-toplevel) |
| 14 | +TOOLSROOT := $(REPOROOT)/Tools |
| 15 | +TOOLSET := $(TOOLSROOT)/Toolsets/pico.json |
| 16 | +MACHO2UF2 := $(TOOLSROOT)/macho2uf2.py |
| 17 | +SWIFT_BUILD := swift build |
| 18 | + |
| 19 | +# Flags |
| 20 | +PICO_FAMILY := rp2040 |
| 21 | +ARCH := armv6m |
| 22 | +TARGET := $(ARCH)-apple-none-macho |
| 23 | +SWIFT_BUILD_ARGS := \ |
| 24 | + --configuration release \ |
| 25 | + --triple $(TARGET) \ |
| 26 | + --toolset $(TOOLSET) \ |
| 27 | + --disable-local-rpath |
| 28 | +BUILDROOT := $(shell $(SWIFT_BUILD) $(SWIFT_BUILD_ARGS) --show-bin-path) |
| 29 | + |
| 30 | +.PHONY: build |
| 31 | +build: |
| 32 | + @echo "building..." |
| 33 | + $(SWIFT_BUILD) \ |
| 34 | + $(SWIFT_BUILD_ARGS) \ |
| 35 | + -Xlinker -map -Xlinker $(BUILDROOT)/Application.mangled.map \ |
| 36 | + --verbose |
| 37 | + |
| 38 | + @echo "demangling linker map..." |
| 39 | + cat $(BUILDROOT)/Application.mangled.map \ |
| 40 | + | c++filt | swift demangle > $(BUILDROOT)/Application.map |
| 41 | + |
| 42 | + @echo "disassembling..." |
| 43 | + otool \ |
| 44 | + -arch $(ARCH) -v -V -d -t \ |
| 45 | + $(BUILDROOT)/Application \ |
| 46 | + | c++filt | swift demangle > $(BUILDROOT)/Application.disassembly |
| 47 | + |
| 48 | + @echo "extracting binary..." |
| 49 | + $(MACHO2UF2) \ |
| 50 | + --pico-family "$(PICO_FAMILY)" \ |
| 51 | + "$(BUILDROOT)/Application" \ |
| 52 | + "$(BUILDROOT)/Application.uf2" \ |
| 53 | + --base-address 0x20000000 \ |
| 54 | + --segments '__TEXT,__DATA,__VECTORS,__RESET' |
| 55 | + |
| 56 | + |
| 57 | +.PHONY: clean |
| 58 | +clean: |
| 59 | + @echo "cleaning..." |
| 60 | + @swift package clean |
| 61 | + @rm -rf .build |
0 commit comments