From f01d5fb657159f1afa9d41cf39830d17b791a67e Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 6 Jun 2023 14:24:41 +1000 Subject: [PATCH] py/mkrules.mk: Automatically configure frozen options when manifest set. Following how mkrules.cmake works. This makes it easy for a port to enable frozen code, by defining FROZEN_MANIFEST in its Makefile. Signed-off-by: Damien George --- ports/esp32/mpconfigport.h | 3 --- ports/esp8266/Makefile | 6 ------ ports/mimxrt/mpconfigport.h | 2 -- ports/nrf/Makefile | 6 ------ ports/qemu-arm/Makefile | 6 ------ ports/renesas-ra/Makefile | 13 ------------- ports/samd/Makefile | 6 ------ ports/stm32/Makefile | 6 ------ ports/unix/Makefile | 5 ----- ports/windows/Makefile | 2 +- ports/zephyr/mpconfigport.h | 2 -- py/mkrules.mk | 5 +++++ 12 files changed, 6 insertions(+), 56 deletions(-) diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index 778a4cbc7e..f81ad58fa1 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -49,9 +49,6 @@ #define MICROPY_WARNINGS (1) #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_FLOAT) #define MICROPY_STREAMS_POSIX_API (1) -#define MICROPY_MODULE_FROZEN_STR (0) -#define MICROPY_MODULE_FROZEN_MPY (1) -#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool #define MICROPY_USE_INTERNAL_ERRNO (0) // errno.h from xtensa-esp32-elf/sys-include/sys #define MICROPY_USE_INTERNAL_PRINTF (0) // ESP32 SDK requires its own printf #define MICROPY_SCHEDULER_DEPTH (8) diff --git a/ports/esp8266/Makefile b/ports/esp8266/Makefile index e4db811f24..1cdcafa031 100644 --- a/ports/esp8266/Makefile +++ b/ports/esp8266/Makefile @@ -200,12 +200,6 @@ $(BUILD)/uart.o: $(CONFVARS_FILE) FROZEN_EXTRA_DEPS = $(CONFVARS_FILE) -ifneq ($(FROZEN_MANIFEST),) -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -CFLAGS += -DMICROPY_MODULE_FROZEN_STR -endif - .PHONY: deploy deploy: $(BUILD)/firmware-combined.bin diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index b1cd84f265..ce71cb2795 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -60,8 +60,6 @@ uint32_t trng_random_u32(void); #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_SCHEDULER_DEPTH (8) #define MICROPY_VFS (1) -#define MICROPY_MODULE_FROZEN_MPY (1) -#define MICROPY_QSTR_EXTRA_POOL mp_qstr_frozen_const_pool // Control over Python builtins #define MICROPY_PY_BUILTINS_HELP_TEXT mimxrt_help_text diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 89bb03dfae..3a4b0ef23d 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -552,12 +552,6 @@ $(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qst $(GEN_PINS_SRC:.c=.o): $(GEN_PINS_SRC) $(call compile_c) -ifneq ($(FROZEN_MANIFEST),) -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY -CFLAGS += -DMICROPY_MODULE_FROZEN_STR -endif - $(PY_BUILD)/nlr%.o: CFLAGS += -Os -fno-lto include ../../py/mkrules.mk diff --git a/ports/qemu-arm/Makefile b/ports/qemu-arm/Makefile index 40b3062ae4..599caf0266 100644 --- a/ports/qemu-arm/Makefile +++ b/ports/qemu-arm/Makefile @@ -133,12 +133,6 @@ OBJ = $(OBJ_COMMON) $(OBJ_RUN) $(OBJ_TEST) # List of sources for qstr extraction SRC_QSTR += $(SRC_COMMON_C) $(SRC_RUN_C) $(LIB_SRC_C) -ifneq ($(FROZEN_MANIFEST),) -CFLAGS += -DMICROPY_MODULE_FROZEN_STR -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -endif - all: run run: $(BUILD)/firmware.elf diff --git a/ports/renesas-ra/Makefile b/ports/renesas-ra/Makefile index 2c9f917f36..c49db286fd 100644 --- a/ports/renesas-ra/Makefile +++ b/ports/renesas-ra/Makefile @@ -430,19 +430,6 @@ $(TOP)/lib/fsp/README.md: $(ECHO) "fsp submodule not found, fetching it now..." (cd $(TOP) && git submodule update --init lib/fsp) -ifneq ($(FROZEN_MANIFEST)$(FROZEN_DIR),) -# To use frozen source modules, put your .py files in a subdirectory (eg scripts/) -# and then invoke make with FROZEN_DIR=scripts (be sure to build from scratch). -CFLAGS += -DMICROPY_MODULE_FROZEN_STR -endif - -ifneq ($(FROZEN_MANIFEST)$(FROZEN_MPY_DIR),) -# To use frozen bytecode, put your .py files in a subdirectory (eg frozen/) and -# then invoke make with FROZEN_MPY_DIR=frozen (be sure to build from scratch). -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY -endif - define GENERATE_ELF $(ECHO) "LINK $(1)" $(Q)$(LD) $(LDFLAGS) -o $(1) $(2) $(LDFLAGS_MOD) $(LIBS) diff --git a/ports/samd/Makefile b/ports/samd/Makefile index 211607650b..360cf0dd4c 100644 --- a/ports/samd/Makefile +++ b/ports/samd/Makefile @@ -170,12 +170,6 @@ OBJ += $(addprefix $(BUILD)/, $(LIBM_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(DRIVERS_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(TINYUSB_SRC_C:.c=.o)) -ifneq ($(FROZEN_MANIFEST),) -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY -CFLAGS += -DMICROPY_MODULE_FROZEN_STR -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -endif - all: $(BUILD)/firmware.uf2 $(BUILD)/firmware.elf: $(OBJ) diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index e51c0d2713..fce81d753f 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -530,12 +530,6 @@ $(TOP)/lib/stm32lib/README.md: $(ECHO) "stm32lib submodule not found, fetching it now..." (cd $(TOP) && git submodule update --init lib/stm32lib) -ifneq ($(FROZEN_MANIFEST),) -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY -CFLAGS += -DMICROPY_MODULE_FROZEN_STR -endif - define RUN_DFU $(ECHO) "Writing $(1) to the board" $(if $(filter $(USE_PYDFU),1),\ diff --git a/ports/unix/Makefile b/ports/unix/Makefile index a8981e8f5c..188e4be633 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -235,12 +235,7 @@ SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) SRC_QSTR_AUTO_DEPS += ifneq ($(FROZEN_MANIFEST),) -# To use frozen code create a manifest.py file with a description of files to -# freeze, then invoke make with FROZEN_MANIFEST=manifest.py (be sure to build from scratch). -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -CFLAGS += -DMICROPY_MODULE_FROZEN_MPY CFLAGS += -DMPZ_DIG_SIZE=16 # force 16 bits to work on both 32 and 64 bit archs -CFLAGS += -DMICROPY_MODULE_FROZEN_STR endif CXXFLAGS += $(filter-out -Wmissing-prototypes -Wold-style-definition -std=gnu99,$(CFLAGS) $(CXXFLAGS_MOD)) diff --git a/ports/windows/Makefile b/ports/windows/Makefile index 7753fa25d4..31ac8d8b88 100644 --- a/ports/windows/Makefile +++ b/ports/windows/Makefile @@ -87,7 +87,7 @@ SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) SRC_QSTR_AUTO_DEPS += ifneq ($(FROZEN_MANIFEST),) -CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool -DMICROPY_MODULE_FROZEN_MPY=1 -DMPZ_DIG_SIZE=16 +CFLAGS += -DMPZ_DIG_SIZE=16 endif CXXFLAGS += $(filter-out -std=gnu99,$(CFLAGS)) diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h index df24e52002..2f3e314db6 100644 --- a/ports/zephyr/mpconfigport.h +++ b/ports/zephyr/mpconfigport.h @@ -127,8 +127,6 @@ void mp_hal_signal_event(void); #define MICROPY_HW_MCU_NAME "unknown-cpu" #endif -#define MICROPY_MODULE_FROZEN_STR (0) - typedef int mp_int_t; // must be pointer size typedef unsigned mp_uint_t; // must be pointer size typedef long mp_off_t; diff --git a/py/mkrules.mk b/py/mkrules.mk index aa7f77bd2a..db81faa7ff 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -183,6 +183,11 @@ ifeq ($(MPY_LIB_DIR),$(MPY_LIB_SUBMODULE_DIR)) GIT_SUBMODULES += lib/micropython-lib endif +# Set compile options needed to enable frozen code. +CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool +CFLAGS += -DMICROPY_MODULE_FROZEN_MPY +CFLAGS += -DMICROPY_MODULE_FROZEN_STR + # to build frozen_content.c from a manifest $(BUILD)/frozen_content.c: FORCE $(BUILD)/genhdr/qstrdefs.generated.h $(BUILD)/genhdr/root_pointers.h | $(MICROPY_MPYCROSS_DEPENDENCY) $(Q)test -e "$(MPY_LIB_DIR)/README.md" || (echo -e $(HELP_MPY_LIB_SUBMODULE); false)