Debian Codegraph @

ports/rp2/Makefile

raw
1 # Makefile for micropython on Raspberry Pi RP2
2 #
3 # This is a simple wrapper around 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 RPI_PICO.
14 BOARD ?= RPI_PICO
15 BOARD_DIR ?= boards/$(BOARD)
16 endif
17
18 ifeq ($(wildcard $(BOARD_DIR)/.),)
19 ifeq ($(findstring boards/PICO,$(BOARD_DIR)),boards/PICO)
20 $(warning The PICO* boards have been renamed to RPI_PICO*)
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 ifeq ($(BUILD_VERBOSE),1)
34 MAKE_ARGS += VERBOSE=1 # Picked up in Makefile generated by CMake
35 endif
36
37 CMAKE_ARGS += -DMICROPY_BOARD=$(BOARD) -DMICROPY_BOARD_DIR="$(abspath $(BOARD_DIR))"
38
39 ifdef USER_C_MODULES
40 CMAKE_ARGS += -DUSER_C_MODULES=${USER_C_MODULES}
41 endif
42
43 ifneq ($(FROZEN_MANIFEST),)
44 CMAKE_ARGS += -DMICROPY_FROZEN_MANIFEST=${FROZEN_MANIFEST}
45 endif
46
47 ifeq ($(DEBUG),1)
48 CMAKE_ARGS += -DCMAKE_BUILD_TYPE=Debug
49 endif
50
51 ifdef BOARD_VARIANT
52 CMAKE_ARGS += -DMICROPY_BOARD_VARIANT=$(BOARD_VARIANT)
53 endif
54
55 ifdef MICROPY_PREVIEW_VERSION_2
56 CMAKE_ARGS += -DMICROPY_PREVIEW_VERSION_2=1
57 endif
58
59 HELP_PICO_SDK_SUBMODULE ?= "\033[1;31mError: pico-sdk submodule is not initialized.\033[0m Run 'make submodules'"
60 HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m"
61
62 all:
63 $(Q)[ -f ../../lib/pico-sdk/README.md ] || (echo -e $(HELP_PICO_SDK_SUBMODULE); false)
64 $(Q)[ -e $(BUILD)/Makefile ] || cmake -S . -B $(BUILD) -DPICO_BUILD_DOCS=0 ${CMAKE_ARGS}
65 $(Q)$(MAKE) $(MAKE_ARGS) -C $(BUILD) || (echo -e $(HELP_BUILD_ERROR); false)
66
67 clean:
68 $(RM) -rf $(BUILD)
69
70 deploy: all
71 $(Q)picotool load -x $(BUILD)/firmware.elf
72
73 # First ensure that pico-sdk is initialised, then run CMake with the
74 # UPDATE_SUBMODULES flag to update necessary submodules for this board.
75 #
76 # This is done in a dedicated build directory as some CMake cache values are not
77 # set correctly if not all submodules are loaded yet.
78 submodules:
79 $(Q)$(MAKE) -f ../../py/mkrules.mk GIT_SUBMODULES="lib/pico-sdk" submodules
80 $(Q)cmake -S . -B $(BUILD)/submodules -DUPDATE_SUBMODULES=1 ${CMAKE_ARGS}