|
9 | 9 | ## |
10 | 10 | ##===----------------------------------------------------------------------===## |
11 | 11 |
|
12 | | -# Determine file paths |
13 | | -REPOROOT := $(shell git rev-parse --show-toplevel) |
14 | | -TOOLSROOT := $(REPOROOT)/Tools |
15 | | -SRCROOT := $(REPOROOT)/stm32-lcd-logo |
16 | | -BUILDROOT := $(SRCROOT)/.build |
17 | | - |
18 | | -# Setup tools and build flags |
19 | | -TARGET := armv7-apple-none-macho |
20 | | -BASEADDRESS := 0x00200000 |
21 | | - |
22 | | -SWIFT_EXEC := $(shell xcrun -f swiftc) |
23 | | -SWIFT_FLAGS := -target $(TARGET) -Osize -import-bridging-header $(SRCROOT)/Support/BridgingHeader.h -wmo -enable-experimental-feature Embedded -Xcc -D__APPLE__ -Xcc -D__MACH__ -Xcc -ffreestanding |
24 | | - |
25 | | -CLANG_EXEC := $(shell xcrun -f clang) |
26 | | -CLANG_FLAGS := -target $(TARGET) -Oz |
27 | | - |
28 | | -LD_EXEC := $(CLANG_EXEC) |
29 | | -LD_FLAGS := -target $(TARGET) -static -Wl,-e,_reset -dead_strip -Wl,-no_zero_fill_sections -Wl,-segalign,4 -Wl,-segaddr,__VECTORS,0x00200000 -Wl,-seg1addr,0x00200200 -Wl,-pagezero_size,0 |
30 | | - |
31 | | -PYTHON_EXEC := $(shell xcrun -f python3) |
32 | | -MACHO2BIN := $(TOOLSROOT)/macho2bin.py |
33 | | - |
34 | | -.PHONY: all |
35 | | -all: $(BUILDROOT)/lcd-logo.bin |
36 | | - |
37 | | -$(BUILDROOT): |
38 | | - # Create build directory |
39 | | - mkdir -p $(BUILDROOT) |
40 | | - |
41 | | -$(BUILDROOT)/lcd-logo.o: $(SRCROOT)/Main.swift $(SRCROOT)/Support/*.swift | $(BUILDROOT) |
42 | | - # Build Swift sources |
43 | | - $(SWIFT_EXEC) $(SWIFT_FLAGS) -c $^ -o $@ |
44 | | - |
45 | | -$(BUILDROOT)/Startup.o: $(SRCROOT)/Support/Startup.c | $(BUILDROOT) |
46 | | - # Build C sources |
47 | | - $(CLANG_EXEC) $(CLANG_FLAGS) -c $^ -o $@ |
48 | | - |
49 | | -$(BUILDROOT)/PixelData.o: $(SRCROOT)/Support/PixelData.c | $(BUILDROOT) |
50 | | - # Build C sources |
51 | | - $(CLANG_EXEC) $(CLANG_FLAGS) -c $^ -o $@ |
52 | | - |
53 | | -$(BUILDROOT)/lcd-logo: $(BUILDROOT)/lcd-logo.o $(BUILDROOT)/Startup.o $(BUILDROOT)/PixelData.o |
54 | | - # Link objects into executable |
55 | | - $(LD_EXEC) $(LD_FLAGS) $^ -o $@ |
56 | | - |
57 | | -$(BUILDROOT)/lcd-logo.bin: $(BUILDROOT)/lcd-logo |
58 | | - # Extract sections from executable into flashable binary |
59 | | - $(PYTHON_EXEC) $(MACHO2BIN) $^ $@ --base-address 0x00200000 --segments '__TEXT,__DATA,__VECTORS' |
60 | | - # Echo final binary path |
61 | | - ls -al $(BUILDROOT)/lcd-logo.bin |
| 12 | +# Paths |
| 13 | +REPOROOT := $(shell git rev-parse --show-toplevel) |
| 14 | +TOOLSROOT := $(REPOROOT)/Tools |
| 15 | +TOOLSET := $(TOOLSROOT)/Toolsets/stm32f74x-lcd.json |
| 16 | +MACHO2BIN := $(TOOLSROOT)/macho2bin.py |
| 17 | +SWIFT_BUILD := swift build |
| 18 | + |
| 19 | +# Flags |
| 20 | +ARCH := armv7em |
| 21 | +TARGET := $(ARCH)-apple-none-macho |
| 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) |
| 28 | + |
| 29 | +.PHONY: build |
| 30 | +build: |
| 31 | + @echo "building..." |
| 32 | + $(SWIFT_BUILD) \ |
| 33 | + $(SWIFT_BUILD_ARGS) \ |
| 34 | + -Xlinker -map -Xlinker $(BUILDROOT)/Application.mangled.map \ |
| 35 | + --verbose |
| 36 | + |
| 37 | + @echo "demangling linker map..." |
| 38 | + cat $(BUILDROOT)/Application.mangled.map \ |
| 39 | + | c++filt | swift demangle > $(BUILDROOT)/Application.map |
| 40 | + |
| 41 | + @echo "disassembling..." |
| 42 | + otool \ |
| 43 | + -arch $(ARCH) -v -V -d -t \ |
| 44 | + $(BUILDROOT)/Application \ |
| 45 | + | c++filt | swift demangle > $(BUILDROOT)/Application.disassembly |
| 46 | + |
| 47 | + @echo "extracting binary..." |
| 48 | + $(MACHO2BIN) \ |
| 49 | + $(BUILDROOT)/Application $(BUILDROOT)/Application.bin --base-address 0x00200000 --segments '__TEXT,__DATA,__VECTORS' |
| 50 | + |
| 51 | +.PHONY: clean |
| 52 | +clean: |
| 53 | + @echo "cleaning..." |
| 54 | + @swift package clean |
| 55 | + @rm -rf .build |
0 commit comments