Debian Codegraph @

ports/esp32/Makefile

raw
1 # Makefile for MicroPython on ESP32.
2 #
3 # This is a simple, convenience wrapper around idf.py (which uses cmake).
4
5 include ../../py/verbose.mk
6
7 # Select the board to build for:
8 ifdef BOARD_DIR
9 # Custom board path - remove trailing slash and get the final component of
10 # the path as the board name.
11 BOARD ?= $(notdir $(BOARD_DIR:/=))
12 else
13 # If not given on the command line, then default to ESP32_GENERIC.
14 BOARD ?= ESP32_GENERIC
15 BOARD_DIR ?= boards/$(BOARD)
16 endif
17
18 ifeq ($(wildcard $(BOARD_DIR)/.),)
19 ifeq ($(findstring boards/GENERIC,$(BOARD_DIR)),boards/GENERIC)
20 $(warning The GENERIC* boards have been renamed to ESP32_GENERIC*)
21 endif
22 $(error Invalid BOARD specified: $(BOARD_DIR))
23 endif
24
25 # If the build directory is not given, make it reflect the board name (and
26 # optionally the board variant).
27 ifneq ($(BOARD_VARIANT),)
28 BUILD ?= build-$(BOARD)-$(BOARD_VARIANT)
29 else
30 BUILD ?= build-$(BOARD)
31 endif
32
33 # Device serial settings.
34 ifneq ($(PORT),)
35 PORT_ARG := -p $(PORT)
36 endif
37 ifneq ($(BAUD),)
38 BAUD_ARG := -b $(BAUD)
39 endif
40 DEVICE += $(PORT_ARG) $(BAUD_ARG)
41
42 PYTHON ?= python3
43
44 .PHONY: all clean deploy erase submodules FORCE
45
46 CMAKE_ARGS =
47
48 ifdef USER_C_MODULES
49 CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
50 endif
51
52 IDFPY_FLAGS += -D MICROPY_BOARD=$(BOARD) -D MICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))" $(CMAKE_ARGS)
53
54 ifdef FROZEN_MANIFEST
55 IDFPY_FLAGS += -D MICROPY_FROZEN_MANIFEST=$(FROZEN_MANIFEST)
56 endif
57
58 ifdef BOARD_VARIANT
59 IDFPY_FLAGS += -D MICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
60 endif
61
62 ifdef MICROPY_PREVIEW_VERSION_2
63 IDFPY_FLAGS += -D MICROPY_PREVIEW_VERSION_2=1
64 endif
65
66 ifeq ($(BUILD_VERBOSE),1)
67 IDFPY_FLAGS += --verbose
68 endif
69
70 HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
71
72 define RUN_IDF_PY
73 $(Q)idf.py $(IDFPY_FLAGS) -B $(BUILD) $(1)
74 endef
75
76 all:
77 $(Q)idf.py $(IDFPY_FLAGS) -B $(BUILD) build || (echo -e $(HELP_BUILD_ERROR); false)
78 $(Q)$(PYTHON) makeimg.py \
79 $(BUILD)/sdkconfig \
80 $(BUILD)/bootloader/bootloader.bin \
81 $(BUILD)/partition_table/partition-table.bin \
82 $(BUILD)/micropython.bin \
83 $(BUILD)/firmware.bin \
84 $(BUILD)/micropython.uf2
85
86 $(BUILD)/bootloader/bootloader.bin $(BUILD)/partition_table/partition-table.bin $(BUILD)/micropython.bin: FORCE
87
88 clean:
89 $(call RUN_IDF_PY,fullclean)
90
91 deploy:
92 $(call RUN_IDF_PY,$(DEVICE) flash)
93
94 erase:
95 $(call RUN_IDF_PY,$(DEVICE) erase-flash)
96
97 monitor:
98 $(call RUN_IDF_PY,$(DEVICE) monitor)
99
100 size:
101 $(call RUN_IDF_PY,size)
102
103 size-components:
104 $(call RUN_IDF_PY,size-components)
105
106 size-files:
107 $(call RUN_IDF_PY,size-files)
108
109 # Run idf.py with the UPDATE_SUBMODULES flag to update
110 # necessary submodules for this board.
111 #
112 # This is done in a dedicated build directory as some CMake cache values are not
113 # set correctly if not all submodules are loaded yet.
114 submodules:
115 $(Q)IDF_COMPONENT_MANAGER=0 idf.py $(IDFPY_FLAGS) -B $(BUILD)/submodules -D UPDATE_SUBMODULES=1 reconfigure