-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
160 lines (124 loc) · 4.86 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
# make file for generating a binary for the esp32 under the arduino eco-system
###############################################################################
# compiler args
# project name
project_name = meshy-tron-firmware
# fully qualified board name for the bluepill, use "make list-boards" to view available boards
hardware_fqbn = esp32:esp32:esp32s3
# set "true" to enable verbose
enable_verbose = false
# build dir full path, default is at current work directory / build
# build_dir = full-path-to-build-directory
# additional boards URL - ESP32
additional_urls = "https://raw.githubusercontent.com/espressif/arduino-esp32/master/package.json"
# chip name, refer to esputil source
chip_name = ESP32-S3-BETA3
# upload baudrate
upload_baud = 1500000
# upload port
upload_port = /dev/ttyACM0
# flash param for flash type, size and frequency refer to esputil readme for more info
flash_param = 0x24f
###############################################################################
# make params
acli_workspace_name = .workspace-ard-cli
work_dir := $(PWD)
acli_path := ${work_dir}/${acli_workspace_name}
esputil_path := ${acli_path}/tools/esputil
esputil_bin_path := ${esputil_path}/esputil
acli_config := ${acli_path}/config.json
host_epoch := $(shell date +%s)
host_time := $(shell date)
acli_staging := ${acli_path}/staging
acli_ard := ${acli_path}/Arduino
# verbose flag
vf =
ifeq "${enable_verbose}" "true"
vf =-v
endif
# default build dir
build_dir ?= ${work_dir}/build
# bin file name & path
bin_path = ${build_dir}/${project_name}.ino.bin
SRCS := ${project_name}.ino ${project_name}.h $(wildcard src/*.c) $(wildcard src/*.h)
###############################################################################
# make targets
# binary
compile: dev
echo "build evoked at ${host_time} for the ${hardware_fqbn}"
echo "output files will be written to ${build_dir}"
arduino-cli compile -b ${hardware_fqbn} ${vf} --config-file ${acli_config} --output-dir ${build_dir}
# target to clean the build dir
clean:
@if [ -d ${build_dir} ]; \
then \
echo removing ${build_dir}; \
rm -rf ${build_dir}; \
fi
# target to init the build env this target tracks an md file
${acli_config}:
$(info creating workspace at ${work_dir}/${acli_workspace_name})
arduino-cli ${vf} config init --overwrite --dest-file ${acli_config}
arduino-cli ${vf} config set board_manager.additional_urls ${additional_urls} --config-file ${acli_config}
arduino-cli ${vf} config set directories.downloads ${acli_staging} --config-file ${acli_config}
arduino-cli ${vf} config set directories.data ${acli_path} --config-file ${acli_config}
arduino-cli ${vf} config set directories.user ${acli_ard} --config-file ${acli_config}
arduino-cli ${vf} lib update-index --config-file ${acli_config}
arduino-cli ${vf} core update-index --config-file ${acli_config}
arduino-cli ${vf} core install esp32:esp32 --config-file ${acli_config}
# target to remove the dev env
dev-remove:
@if [ -d "${acli_path}" ]; \
then \
echo removing dev env at ${acli_path}; \
rm -rf ${acli_path}; \
fi
# target to download and compile esputil, much better than the python crap
esputil-install:
@if [ ! -e "${esputil_path}" ]; \
then \
git clone [email protected]:cnlohr/esputil.git ${esputil_path}; \
cd ${esputil_path} && make; \
cd ${work_dir}; \
fi
# alias for the config file
dev: ${acli_config} esputil-install
# target to install arduino platform libs listed under libindex
lib-install: dev
@if [ -e "${work_dir}/libindex" ]; \
then \
while read -r line; do \
if [ -n "$$line" ]; \
then \
echo "installing library $$line"; \
arduino-cli lib install "$$line" --config-file ${acli_config}; \
fi; \
done < "${work_dir}/libindex"; \
fi
# target to remove all libraries listed under libindex
lib-remove: dev
@if [ -e "${work_dir}/libindex" ]; \
then \
while read -r line; do \
if [ -n "$$line" ]; \
then \
echo "installing library $$line"; \
arduino-cli lib uninstall "$$line" --config-file ${acli_config}; \
fi; \
done < "${work_dir}/libindex"; \
fi
# target to view all available boards
list-boards:
arduino-cli board listall --config-file ${acli_config}
# upload app only
upload-app:
${esputil_bin_path} -chip ${chip_name} -p ${upload_port} -fp ${flash_param} -b ${upload_baud} flash 0x10000 ${build_dir}/${project_name}.ino.bin
# upload bootloader, partition info and app
upload-all:
${esputil_bin_path} -chip ${chip_name} -p ${upload_port} -fp ${flash_param} -b ${upload_baud} flash 0x0 ${build_dir}/${project_name}.ino.bootloader.bin 0x8000 ${build_dir}/${project_name}.ino.partitions.bin 0x10000 ${build_dir}/${project_name}.ino.bin
#default upload
upload: upload-app
# target for all
all: compile upload-all
# define the phony targets
.PHONY: all compile clean dev dev-remove lib-install lib-remove list-boards upload upload-app upload-all esputil-install