| 1 |
################################################################################ |
| 2 |
# Initial setup of Makefile environment. |
| 3 |
|
| 4 |
# Select the variant to build for: |
| 5 |
ifdef VARIANT_DIR |
| 6 |
# Custom variant path - remove trailing slash and get the final component of |
| 7 |
# the path as the variant name. |
| 8 |
VARIANT ?= $(notdir $(VARIANT_DIR:/=)) |
| 9 |
else |
| 10 |
# If not given on the command line, then default to standard. |
| 11 |
VARIANT ?= standard |
| 12 |
VARIANT_DIR ?= variants/$(VARIANT) |
| 13 |
endif |
| 14 |
|
| 15 |
ifeq ($(wildcard $(VARIANT_DIR)/.),) |
| 16 |
$(error Invalid VARIANT specified: $(VARIANT_DIR)) |
| 17 |
endif |
| 18 |
|
| 19 |
# If the build directory is not given, make it reflect the variant name. |
| 20 |
BUILD ?= build-$(VARIANT) |
| 21 |
|
| 22 |
include ../../py/mkenv.mk |
| 23 |
include $(VARIANT_DIR)/mpconfigvariant.mk |
| 24 |
|
| 25 |
# Use the default frozen manifest, variants may override this. |
| 26 |
FROZEN_MANIFEST ?= variants/manifest.py |
| 27 |
|
| 28 |
# Qstr definitions (must come before including py.mk). |
| 29 |
QSTR_DEFS = qstrdefsport.h |
| 30 |
|
| 31 |
# Include py core make definitions. |
| 32 |
include $(TOP)/py/py.mk |
| 33 |
include $(TOP)/extmod/extmod.mk |
| 34 |
|
| 35 |
################################################################################ |
| 36 |
# Project specific settings and compiler/linker flags. |
| 37 |
|
| 38 |
CC = emcc |
| 39 |
LD = emcc |
| 40 |
NODE ?= node |
| 41 |
TERSER ?= npx terser |
| 42 |
|
| 43 |
INC += -I. |
| 44 |
INC += -I$(TOP) |
| 45 |
INC += -I$(BUILD) |
| 46 |
INC += -I$(VARIANT_DIR) |
| 47 |
|
| 48 |
CFLAGS += -std=c99 -Wall -Werror -Wdouble-promotion -Wfloat-conversion |
| 49 |
CFLAGS += -Os -DNDEBUG |
| 50 |
CFLAGS += $(INC) |
| 51 |
|
| 52 |
EXPORTED_FUNCTIONS_EXTRA += ,\ |
| 53 |
_mp_js_do_exec,\ |
| 54 |
_mp_js_do_exec_async,\ |
| 55 |
_mp_js_do_import,\ |
| 56 |
_mp_js_register_js_module,\ |
| 57 |
_proxy_c_free_obj,\ |
| 58 |
_proxy_c_init,\ |
| 59 |
_proxy_c_to_js_call,\ |
| 60 |
_proxy_c_to_js_delete_attr,\ |
| 61 |
_proxy_c_to_js_dir,\ |
| 62 |
_proxy_c_to_js_get_array,\ |
| 63 |
_proxy_c_to_js_get_dict,\ |
| 64 |
_proxy_c_to_js_get_iter,\ |
| 65 |
_proxy_c_to_js_get_type,\ |
| 66 |
_proxy_c_to_js_has_attr,\ |
| 67 |
_proxy_c_to_js_iternext,\ |
| 68 |
_proxy_c_to_js_lookup_attr,\ |
| 69 |
_proxy_c_to_js_resume,\ |
| 70 |
_proxy_c_to_js_store_attr,\ |
| 71 |
_proxy_convert_mp_to_js_obj_cside |
| 72 |
|
| 73 |
EXPORTED_RUNTIME_METHODS_EXTRA += ,\ |
| 74 |
PATH,\ |
| 75 |
PATH_FS,\ |
| 76 |
UTF8ToString,\ |
| 77 |
getValue,\ |
| 78 |
lengthBytesUTF8,\ |
| 79 |
setValue,\ |
| 80 |
stringToUTF8 |
| 81 |
|
| 82 |
JSFLAGS += -s EXPORTED_FUNCTIONS="\ |
| 83 |
_free,\ |
| 84 |
_malloc,\ |
| 85 |
_mp_js_init,\ |
| 86 |
_mp_js_repl_init,\ |
| 87 |
_mp_js_repl_process_char,\ |
| 88 |
_mp_hal_get_interrupt_char,\ |
| 89 |
_mp_sched_keyboard_interrupt$(EXPORTED_FUNCTIONS_EXTRA)" |
| 90 |
JSFLAGS += -s EXPORTED_RUNTIME_METHODS="\ |
| 91 |
ccall,\ |
| 92 |
cwrap,\ |
| 93 |
FS$(EXPORTED_RUNTIME_METHODS_EXTRA)" |
| 94 |
JSFLAGS += --js-library library.js |
| 95 |
JSFLAGS += -s SUPPORT_LONGJMP=emscripten |
| 96 |
JSFLAGS += -s MODULARIZE -s EXPORT_NAME=_createMicroPythonModule |
| 97 |
|
| 98 |
################################################################################ |
| 99 |
# Source files and libraries. |
| 100 |
|
| 101 |
SRC_SHARED = $(addprefix shared/,\ |
| 102 |
runtime/interrupt_char.c \ |
| 103 |
runtime/stdout_helpers.c \ |
| 104 |
runtime/pyexec.c \ |
| 105 |
readline/readline.c \ |
| 106 |
timeutils/timeutils.c \ |
| 107 |
) |
| 108 |
|
| 109 |
SRC_C += \ |
| 110 |
lexer_dedent.c \ |
| 111 |
main.c \ |
| 112 |
modjs.c \ |
| 113 |
modjsffi.c \ |
| 114 |
mphalport.c \ |
| 115 |
objjsproxy.c \ |
| 116 |
proxy_c.c \ |
| 117 |
|
| 118 |
# List of sources for qstr extraction. |
| 119 |
SRC_QSTR += $(SRC_C) $(SRC_SHARED) |
| 120 |
|
| 121 |
SRC_JS += \ |
| 122 |
api.js \ |
| 123 |
objpyproxy.js \ |
| 124 |
proxy_js.js \ |
| 125 |
|
| 126 |
OBJ += $(PY_O) |
| 127 |
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED:.c=.o)) |
| 128 |
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) |
| 129 |
|
| 130 |
################################################################################ |
| 131 |
# Main targets. |
| 132 |
|
| 133 |
.PHONY: all repl min test test_min |
| 134 |
|
| 135 |
all: $(BUILD)/micropython.mjs |
| 136 |
|
| 137 |
$(BUILD)/micropython.mjs: $(OBJ) library.js $(SRC_JS) |
| 138 |
$(ECHO) "LINK $@" |
| 139 |
$(Q)emcc $(LDFLAGS) -o $@ $(OBJ) $(JSFLAGS) |
| 140 |
$(Q)cat $(SRC_JS) >> $@ |
| 141 |
|
| 142 |
$(BUILD)/micropython.min.mjs: $(BUILD)/micropython.mjs |
| 143 |
$(TERSER) $< --compress --module -o $@ |
| 144 |
|
| 145 |
repl: $(BUILD)/micropython.mjs |
| 146 |
$(NODE) $< |
| 147 |
|
| 148 |
min: $(BUILD)/micropython.min.mjs |
| 149 |
|
| 150 |
test: $(BUILD)/micropython.mjs $(TOP)/tests/run-tests.py |
| 151 |
cd $(TOP)/tests && MICROPY_MICROPYTHON_MJS=../ports/webassembly/$< ./run-tests.py -t webassembly |
| 152 |
|
| 153 |
test_min: $(BUILD)/micropython.min.mjs $(TOP)/tests/run-tests.py |
| 154 |
cd $(TOP)/tests && MICROPY_MICROPYTHON_MJS=../ports/webassembly/$< ./run-tests.py -t webassembly |
| 155 |
|
| 156 |
################################################################################ |
| 157 |
# Remaining make rules. |
| 158 |
|
| 159 |
include $(TOP)/py/mkrules.mk |