-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathidf.mk
139 lines (120 loc) · 3.67 KB
/
idf.mk
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
DOCKER_IMAGE := idf/v4.0
# load DEVICE configuration
-include .setup-device.mk
# delete DEVICE configuration if invalid
ifeq ($(shell ! test -c $(DEVICE); echo $$?),0)
$(shell rm -f .setup-device.mk)
undefine DEVICE
else
export DEVICE
endif
DOCKER_VARS += DEVICE
DOCKER_VARS_DEVICE := $(DEVICE)
DOCKER_VARS += ENVS
DOCKER_VARS_ENVS := "IDF_PORT=$(DEVICE)"
IDF = idf.py --ccache
VARIABLES += DOCKEROPTIONS
HELP_DOCKEROPTIONS := Docker options
VARIABLES_DOCKEROPTIONS += DEVICE
HELP_DEVICE := specifies which device to pass to docker
TARGETS_all += build
TARGETS_all += test
.PHONY: menuconfig
TARGETS += menuconfig
HELP_menuconfig = configure project
DOCKER += menuconfig
menuconfig:
$(IDF) menuconfig
.PHONY: reconfigure
TARGET += reconfigure
HELP_reconfigure = reconfigure project (rebuilds cmake files)
DOCKER += reconfigure
reconfigure:
$(IDF) reconfigure
.PHONY: build-firmware
TARGETS_build += build-firmware
HELP_build-firmware = build firmware files
DOCKER += build-firmware
build-firmware:
$(IDF) all
.PHONY: clean-build
TARGETS_clean += clean-build
HELP_clean-build = remove generated files of project components
clean-build:
rm -rf build/esp-idf/
.PHONY: distclean-build
TARGETS_distclean += distclean-build
HELP_distclean-build = remove all generated files
distclean-build:
rm -f sdkconfig
rm -rf build
rm -rf .setup-device.mk
.PHONY: flash
TARGETS += flash
HELP_flash = flash project to esp. Use DEVICE=path to provide path to device or use make setup
DOCKER += flash
flash: | check-device
$(IDF) flash -p '$(DEVICE)'
.PHONY: monitor
TARGETS += monitor
HELP_monitor = connect to esp32 via serial. Use DEVICE=path to provide path to device or use make dev
DOCKER += monitor
monitor: | check-device
$(IDF) monitor -p '$(DEVICE)'
.PHONY: check-device
TARGETS_check += check-device
HELP_check-device = check if valid device is specified
NO_DOCKER += check-device
check-device:
ifndef DEVICE
@1>&2 echo "##############################"
@1>&2 echo "# FLASH DEVICE NOT SPECIFIED #"
@1>&2 echo "##############################"
@1>&2 echo "specify device by adding DEVICE as parameter"
@1>&2 echo " make $(MAKECMDGOALS) DEVICE=/path/to/device"
@1>&2 echo "or by running"
@1>&2 echo " make setup"
@exit 1
endif
ifeq ($(shell ! test -c $(DEVICE); echo $$?),0)
@1>&2 echo "#############################"
@1>&2 echo "# FLASH DEVICE IS NOT VALID #"
@1>&2 echo "#############################"
@1>&2 echo "the specified device '$(DEVICE)' is not a character device!"
@1>&2 echo "specify device by adding DEVICE as parameter"
@1>&2 echo " make $(MAKECMDGOALS) DEVICE=/path/to/device"
@1>&2 echo "or by running"
@1>&2 echo " make setup"
@exit 1
endif
@exit 0
.PHONY: check-dialog
TARGETS_check += check-dialog
HELP_check-dialog = check if dialog is installed
NO_DOCKER += check-dialog
check-dialog:
ifeq ($(shell which dialog 2> /dev/null),)
@1>&2 echo "###########################"
@1>&2 echo "# DIALOG IS NOT INSTALLED #"
@1>&2 echo "###########################"
@1>&2 echo "Consider installing dialog."
@1>&2 echo "on debian based systems:"
@1>&2 echo " sudo apt-get install dialog"
@1>&2 echo "on arch based systems:"
@1>&2 echo " sudo pacman -S dialog"
@exit 1
endif
@exit 0
.PHONY: setup-device
TARGETS_setup += setup-device
HELP_setup-device = sets device
NO_DOCKER += setup-device
setup-device: | check-dialog
echo -n DEVICE= > .setup-device.mk
for dev in $$(ls /dev/serial/by-id); do echo "$$(readlink -f /dev/serial/by-id/$$dev) $$dev "; done \
| dialog \
--stdout \
--menu "choose which device to use" 0 0 0 "none" "disable device passthrough"\
--file /dev/stdin\
>> .setup-device.mk || rm -f .setup-device.mk
include $(shell git rev-parse --show-toplevel)/.make/part.mk