-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathMakefile
78 lines (68 loc) · 2.09 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
##===----------------------------------------------------------------------===##
##
## This source file is part of the Swift open source project
##
## Copyright (c) 2024 Apple Inc. and the Swift project authors.
## Licensed under Apache License v2.0 with Runtime Library Exception
##
## See https://swift.org/LICENSE.txt for license information
##
##===----------------------------------------------------------------------===##
# Determine file paths
REPOROOT := $(shell git rev-parse --show-toplevel)
TOOLSROOT := $(REPOROOT)/Tools
SRCROOT := $(REPOROOT)/pico2-neopixel
BUILDROOT := $(SRCROOT)/.build/release
# Setup tools and build flags
ARCH := armv7em
# TARGET := $(ARCH)-none-none-eabi
TARGET := $(ARCH)-apple-none-macho
ifndef TOOLCHAINS
$(error 'Set "TOOLCHAINS" environment variable before running make')
endif
.PHONY: build
build:
@echo "compiling..."
swift build \
--configuration release \
--triple $(TARGET) \
-Xcc -D__APPLE__ -Xcc -D__MACH__ \
-Xswiftc -Xfrontend -Xswiftc -disable-stack-protector
@echo "linking..."
clang \
$(BUILDROOT)/libApplication.a \
$(BUILDROOT)/Support.build/{Support.c,crt0.S}.o \
-o $(BUILDROOT)/Application \
-target $(TARGET) \
-dead_strip \
-static \
-Wl,-e,_reset \
-Wl,-map,$(BUILDROOT)/Application.mangled.map \
-Wl,-no_zero_fill_sections \
-Wl,-segalign,4 \
-Wl,-segaddr,__VECTORS,0x20000000 \
-Wl,-segaddr,__RESET,0x20000200 \
-Wl,-seg1addr,0x20000300 \
-Wl,-pagezero_size,0
@echo "demangling linker map..."
cat $(BUILDROOT)/Application.mangled.map \
| c++filt | swift demangle > $(BUILDROOT)/Application.map
@echo "disassembling..."
otool \
-arch $(ARCH) -v -V -d -t \
$(BUILDROOT)/Application \
| c++filt | swift demangle > $(BUILDROOT)/Application.disassembly
@echo "extracting binary..."
python3 $(TOOLSROOT)/macho2uf2.py \
$(BUILDROOT)/Application \
$(BUILDROOT)/Application.uf2 \
--pico-family rp2350 \
--base-address 0x20000000 \
--segments '__TEXT,__DATA,__VECTORS,__RESET'
@echo "final image..."
@ls $(BUILDROOT)/Application.uf2
.PHONY: clean
clean:
@echo "cleaning..."
@swift package clean
@rm -rf .build