Repository navigation
Expand file tree
/
Copy pathmicropython.mk
More file actions
133 lines (124 loc) · 7.59 KB
/
Copy pathmicropython.mk
File metadata and controls
133 lines (124 loc) · 7.59 KB
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
# This file is used by MicroPython Make-based builds such as the Unix port.
# For CMake-based builds, see the .cmake file in the same directory.
# When building Micropython, the parent directory of this module is given as:
# make USER_C_MODULES=<path to workspace root>
LVMP_DIR := $(USERMOD_DIR)
# Where lvgl-bindings comes from, first match wins:
# 1. BINDINGS_DIR, from make's command line or the environment (a firmware
# build that pins lvgl-bindings itself sets it);
# 2. an lvgl-bindings checkout beside this one;
# 3. the commit in LVGL_BINDINGS_COMMIT, fetched into .deps/ with only what
# this module compiles (a clone on its own).
# The first two build the checkout as it is: if it isn't at the pinned commit,
# the build says so and carries on. Only the fetched copy must match the pin.
ifneq ($(strip $(BINDINGS_DIR)),)
BINDINGS_DIR := $(abspath $(BINDINGS_DIR))
LVMP_BINDINGS_FROM := BINDINGS_DIR
ifeq ($(wildcard $(BINDINGS_DIR)/lv_conf.h),)
$(error lvgl-micropython: BINDINGS_DIR=$(BINDINGS_DIR) is not an lvgl-bindings checkout (no lv_conf.h))
endif
else ifneq ($(wildcard $(LVMP_DIR)/../lvgl-bindings/lv_conf.h),)
BINDINGS_DIR := $(abspath $(LVMP_DIR)/../lvgl-bindings)
LVMP_BINDINGS_FROM := the lvgl-bindings beside lvgl-micropython
else
BINDINGS_DIR := $(abspath $(LVMP_DIR)/.deps/lvgl-bindings)
LVMP_BINDINGS_FROM := pin
LVMP_FETCH := $(shell bash $(LVMP_DIR)/scripts/fetch_bindings.sh 1>&2; echo $$?)
ifeq ($(wildcard $(BINDINGS_DIR)/lv_conf.h),)
$(error lvgl-micropython: fetching lvgl-bindings failed (scripts/fetch_bindings.sh exit $(LVMP_FETCH)); set BINDINGS_DIR to an lvgl-bindings checkout)
endif
endif
LVMP_C := $(BINDINGS_DIR)/generated/lvgl_micropython.c
LVGL_DIR := $(BINDINGS_DIR)/lvgl
SOURCES = $(shell find $(LVGL_DIR)/src -type f -name "*.c")
LV_BINDINGS_PIN := $(strip $(shell cat $(LVMP_DIR)/LVGL_BINDINGS_COMMIT 2>/dev/null))
ifeq ($(LV_BINDINGS_PIN),)
$(error Missing $(LVMP_DIR)/LVGL_BINDINGS_COMMIT)
endif
# 1 when the binding inputs are exactly the pinned commit's, with nothing
# uncommitted on top.
LV_BINDINGS_AT_PIN := $(shell \
git -C $(BINDINGS_DIR) cat-file -e $(LV_BINDINGS_PIN)^{commit} 2>/dev/null && \
git -C $(BINDINGS_DIR) diff --quiet $(LV_BINDINGS_PIN) -- generated/lvgl_micropython.c lvgl lv_conf.h && \
git -C $(BINDINGS_DIR) diff --quiet -- generated/lvgl_micropython.c lvgl lv_conf.h && echo 1)
ifeq ($(LV_BINDINGS_AT_PIN),)
ifeq ($(LVMP_BINDINGS_FROM),pin)
$(error $(BINDINGS_DIR) does not match pinned binding inputs $(LV_BINDINGS_PIN); delete it and build again to refetch)
endif
LV_BINDINGS_HEAD := $(shell git -C $(BINDINGS_DIR) describe --always --dirty --abbrev=12 2>/dev/null || echo "not a git checkout")
$(info lvgl-micropython: note: building lvgl-bindings from $(BINDINGS_DIR) ($(LVMP_BINDINGS_FROM)) at $(LV_BINDINGS_HEAD),)
$(info whose generated binding, lvgl or lv_conf.h differ from LVGL_BINDINGS_COMMIT $(LV_BINDINGS_PIN). Building it as it is.)
endif
# jpegio Phase 2 moved the JPEG decoder out of LVGL: LV_USE_TJPGD is 0 in the
# bindings (lvgl-bindings aa6c6bc), and the jpegio module registers its own
# TJpgDec with LVGL instead, so a firmware carries one decoder rather than two.
# Built without jpegio (micropython-pydevices' modules/jpegio since 2026-10-06;
# displayif's before), this module decodes PNG and LVGL's BIN and draws nothing
# at all for a JPEG -- silently, at run time. Say so at build time instead (#11).
ifeq ($(findstring jpegio,$(USER_C_MODULES)),)
$(info lvgl-micropython: no jpegio in this build -- lv.image will not draw a JPEG.)
$(info jpegio owns the TJpgDec decoder; PNG and LVGL BIN still decode.)
$(info Name jpegio as well for JPEG (build_mp.py --modules jpegio,lvgl-micropython).)
endif
# LVGL is available on every port, but its desktop/host-GUI and OS-specific
# driver backends (OpenGL/SDL/GLFW/X11/Wayland/evdev/libinput/qnx/uefi/nuttx/
# windows) plus the OpenGLES draw unit need host libraries and break cross
# builds (e.g. lv_opengles_shader.c fails -Werror). This exclusion lives in the
# module's own config: only desktop ports (unix/webassembly/windows) keep the
# full source sweep; every other (embedded) port drops these backends.
LVMP_PORT_DIR := $(abspath $(CURDIR))
LVMP_IS_DESKTOP := $(findstring /ports/unix,$(LVMP_PORT_DIR))$(findstring /ports/webassembly,$(LVMP_PORT_DIR))$(findstring /ports/windows,$(LVMP_PORT_DIR))
ifeq ($(LVMP_IS_DESKTOP),)
LVMP_EXCLUDE_DIRS := \
$(LVGL_DIR)/src/drivers/opengles \
$(LVGL_DIR)/src/drivers/sdl \
$(LVGL_DIR)/src/drivers/glfw \
$(LVGL_DIR)/src/drivers/x11 \
$(LVGL_DIR)/src/drivers/wayland \
$(LVGL_DIR)/src/drivers/evdev \
$(LVGL_DIR)/src/drivers/libinput \
$(LVGL_DIR)/src/drivers/qnx \
$(LVGL_DIR)/src/drivers/uefi \
$(LVGL_DIR)/src/drivers/nuttx \
$(LVGL_DIR)/src/drivers/windows \
$(LVGL_DIR)/src/draw/opengles \
$(LVGL_DIR)/src/libs/gltf
SOURCES := $(foreach s,$(SOURCES),$(if $(strip $(foreach d,$(LVMP_EXCLUDE_DIRS),$(findstring $(d)/,$(s)))),,$(s)))
endif
SOURCES += $(LVMP_DIR)/src/lv_mem_core_micropython.c
$(if $(wildcard $(LVMP_C)),,$(error $(LVMP_C) not found. Sync an exact lvgl-bindings commit or release tag))
# -Wno-unused-function here is not enough on ports that append -Werror after py.mk
# (e.g. webassembly); those ports add -Wno-unused-function after -Werror too.
CFLAGS_USERMOD += -I$(BINDINGS_DIR) -I$(LVMP_DIR) -Wno-unused-function
SRC_USERMOD_LIB_C += $(SOURCES)
SRC_USERMOD_C += $(LVMP_C)
SRC_USERMOD_C += $(LVMP_DIR)/src/lvgl_micropython_build.c
# --- which lvmp this firmware was built from ----------------------
# Computed at build time from this repo's own git, never stored; "unknown" when
# there is no git (a tarball). Read on a target as <module>.__revision__.
LVMP_REVISION := $(shell git -C $(LVMP_DIR) describe --always --dirty --abbrev=7 2>/dev/null || echo unknown)
CFLAGS_USERMOD += -DLVMP_REVISION='"$(LVMP_REVISION)"'
# With LV_USE_FLOAT=1, upstream LVGL trips -Werror=double-promotion / float-conversion.
# Port Makefiles (unix/webassembly) append -Wdouble-promotion after CFLAGS_USERMOD,
# so put the suppress on the LVGL object rules (same idea as circuitpython.mk).
# GCC 16 also counts a variable only ever incremented as set-but-unused
# (lv_buttonmatrix.c's txt_tot_i), which older GCC did not.
LVMP_FLOAT_CFLAGS := -Wno-double-promotion -Wno-float-conversion -Wno-unused-but-set-variable
# The object name a user-module source lands under is not the same on every
# MicroPython. Up to v1.28.0 the USER_C_MODULES prefix was stripped, so the
# object was $(BUILD)/lvgl-bindings/lvgl/src/....o; v1.29.0 keeps the absolute
# source path, giving $(BUILD)//home/.../lvgl-bindings/lvgl/src/....o. A rule
# written for one names a target that does not exist on the other, the flags
# never apply, and upstream LVGL then fails the port's -Werror=double-promotion
# with no hint that a suppression was even attempted. Declare both spellings.
# py.mk names a user-module object $(BUILD)/<module dir basename>/<path inside
# the module>, whatever USER_C_MODULES was (a parent directory, or the module
# directories themselves from c_module()); derive it from this module's own
# directory rather than from USER_C_MODULES.
# The second spelling can't be a target on Windows: a path with a drive (C:/...) under
# $(BUILD) holds a second colon, which make reads as a static pattern rule.
LVMP_OBJ = $(BUILD)/$(patsubst $(LVMP_DIR)/%,$(notdir $(LVMP_DIR))/%,$(1)) $(if $(findstring :,$(1)),,$(BUILD)/$(1))
$(foreach s,$(SOURCES),\
$(eval $(call LVMP_OBJ,$(s:.c=.o)): CFLAGS += $(LVMP_FLOAT_CFLAGS)))
$(eval $(call LVMP_OBJ,$(LVMP_C:.c=.o)): CFLAGS += $(LVMP_FLOAT_CFLAGS))
$(eval $(call LVMP_OBJ,$(LVMP_DIR)/src/lv_mem_core_micropython.o): CFLAGS += $(LVMP_FLOAT_CFLAGS))