-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
192 lines (154 loc) · 4.11 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#--------------------------------------
OUT := UF2
DEBUG := 0
#--------------------------------------
BDIR := b
MNT := /home/pico/mnt
TTY := /dev/ttyACM0
BAUD := 115200
#--------------------------------------
CMFLAGS =
ifeq ($(PICO_SDK_PATH),)
CMFLAGS += -DPICO_SDK_PATH=/home/pico/pico-sdk
endif
ifeq ($(DEBUG), 1)
CMFLAGS += -DCMAKE_BUILD_TYPE=Debug
endif
#--------------------------------------
SHELL := /bin/bash
NAME := ${shell sed -n '/project/{s/project( *//;s/[) ].*//;p;}' CMakeLists.txt}
UF2 := $(BDIR)/$(NAME).uf2
ELF := $(BDIR)/$(NAME).elf
SRC := $(wildcard *.c *.pio zxorigins/zxorigins.c)
HDR := $(wildcard *.h zxorigins/zxorigins.h)
#--------------------------------------
LRED = \e[1;31m
LGRN = \e[1;32m
YEL = \e[1;33m
LWHT = \e[1;37m
NRM = \e[0m
#--------------------------------------
# MUST be the first rule in the Makefile
# Typical default builds are "help", "all", "upload", ...
#
.PHONY: default
default: help
#--------------------------------------
# Help
#
.PHONY: help
help:
@echo "Make options"
@echo -e " $(YEL)all $(NRM)- default build parameters ($(OUT))"
@echo -e " $(YEL)clean $(NRM)- erase ALL build files"
@echo -e " $(YEL)upload up $(NRM)- upload UF2 to Pico-as-MSD"
@echo -e " $(LWHT)elf ELF $(NRM)- build project, UF2 build not /required/"
@echo -e " $(LWHT)bin BIN $(NRM)- synonym for ELF"
@echo -e " $(LWHT)UF2 $(NRM)- build project, and check UF2 build success"
@echo -e " $(LWHT)minicom mc $(NRM)- run minicom"
@echo -e " $(LWHT)test $(NRM)- run test harness"
@echo -e " $(LWHT)MSD $(NRM)- wait for Pico-as-MSD: $(MNT)"
@echo -e " $(LWHT)CDC $(NRM)- wait for Pico-as-CDC: $(TTY) @$(BAUD)"
@echo -e " $(LWHT)help $(NRM)- this text"
@echo -e "Build directory: $(LWHT)$(BDIR)/$(NRM)"
#--------------------------------------
# Common Name to build everything
#
.PHONY: all
all: $(OUT)
#--------------------------------------
# Build the firmware - ELF required
#
.PHONY: ELF
ELF: $(ELF)
.PHONY: elf
elf: $(ELF)
$(ELF): $(SRC) $(HDR) CMakeLists.txt Makefile
@mkdir -p $(BDIR)
( cd $(BDIR) ; cmake $(CMFLAGS) .. ; )
@make -C $(BDIR)
#--------------------------------------
# Build the firmware - CMake rules
#
.PHONY: BIN
BIN: $(ELF)
.PHONY: bin
bin: $(ELF)
#--------------------------------------
# Build the firmware - UF2 required
# ...controlled by the CMake rules
#
.PHONY: UF2
UF2: $(UF2)
$(UF2): ELF
@( [[ ! -f $(UF2) ]] && \
{ \
echo -e "$(LRED)! Build Failed : $(NRM)$(UF2)" ;\
grep '^[^#]*pico_add_extra_outputs' CMakeLists.txt >/dev/null || \
echo -e " $(LWHT)pico_add_extra_outputs(\$${PROJECT_NAME}) $(NRM)not found in $(LWHT)CMakeLists.txt$(NRM)" ;\
false ;\
} ; : \
)
#--------------------------------------
# Erase ALL build files
#
.PHONY: clean
clean:
rm -rf $(BDIR)
#--------------------------------------
# Wait for Pico to be mounted as MSD
#
.PHONY: MSD
MSD:
@( [[ ! -f $(MNT)/INFO_UF2.TXT ]] && \
{ \
echo -en "$(YEL)# Connect/Reset the pico while holding the BOOTSEL button$(NRM)" ;\
while [[ ! -f $(MNT)/INFO_UF2.TXT ]] ;\
do echo -n "." ; sleep 1 ; done ;\
echo "" ;\
} ; : \
)
#--------------------------------------
# Wait for Pico to be mounted as CDC
#
.PHONY: CDC
CDC: $(TTY)
.PHONY: $(TTY)
$(TTY):
# @( [[ ! -e $(TTY) ]] && { echo "! $(TTY) not found"; false; }
@( [[ ! -e $(TTY) ]] && \
{ \
echo -en "$(YEL)# Waiting for $(TTY)$(NRM)" ;\
while [[ ! -e $(TTY) ]] ;\
do echo -n "." ; sleep 1 ; done ;\
echo "" ;\
} ; : \
)
#--------------------------------------
# Upload firmware to Pico
#
.PHONY: up
up: upload
.PHONY: upload
upload: $(UF2) MSD
@echo -en "$(LGRN)# Uploading..."
@cp $(UF2) $(MNT) ; sync
@echo -e "\n$(YEL)* Finished$(NRM)"
#--------------------------------------
# Start minicom
#
.PHONY: mc
mc: minicom
.PHONY: minicom
minicom: CDC
minicom -b 115200 -o -D $(TTY)
#--------------------------------------
# Test harness
#
.PHONY: test
test: CDC
@echo -e "# No Test Harness - see Makefile::test"
.PHONY: nofonts
nofonts:
rm fonts/* || true
rm -rf fonts/tmp