aboutsummaryrefslogtreecommitdiff
path: root/ports/javascript/Makefile
diff options
context:
space:
mode:
authorRami Ali2018-01-19 18:35:42 +1100
committerDamien George2019-03-13 23:47:32 +1100
commit7d675f3a17b435c4dc7880ff597ab81274721ae9 (patch)
treed332d5b31e89364b2121565f05c4f512a3805789 /ports/javascript/Makefile
parent921b999225d0aaa220fb4c302e1fb514c6ab39f4 (diff)
javascript: Add new port targeting JavaScript via Emscripten.
In this port JavaScript is the underlying "machine" and MicroPython is transmuted into JavaScript by Emscripten. MicroPython can then run under Node.js or in the browser.
Diffstat (limited to 'ports/javascript/Makefile')
-rw-r--r--ports/javascript/Makefile59
1 files changed, 59 insertions, 0 deletions
diff --git a/ports/javascript/Makefile b/ports/javascript/Makefile
new file mode 100644
index 000000000..3ce698f10
--- /dev/null
+++ b/ports/javascript/Makefile
@@ -0,0 +1,59 @@
+include ../../py/mkenv.mk
+
+CROSS = 0
+
+QSTR_DEFS = qstrdefsport.h
+
+include $(TOP)/py/py.mk
+
+CC = emcc -g4
+LD = emcc -g4
+
+INC += -I.
+INC += -I$(TOP)
+INC += -I$(BUILD)
+
+CPP = clang -E
+CFLAGS = -m32 $(INC) -Wall -Werror -std=c99 $(COPT)
+LDFLAGS = -m32 -Wl,-Map=$@.map,--cref -Wl,--gc-sections
+
+CFLAGS += -O0 -DNDEBUG
+CFLAGS += -fdata-sections -ffunction-sections
+
+SRC_LIB = $(addprefix lib/,\
+ utils/interrupt_char.c \
+ utils/stdout_helpers.c \
+ utils/pyexec.c \
+ mp-readline/readline.c \
+ )
+
+SRC_C = \
+ main.c \
+ mphalport.c \
+ modutime.c \
+
+SRC_QSTR += $(SRC_C)
+
+OBJ =
+OBJ = $(PY_O)
+OBJ += $(addprefix $(BUILD)/, $(SRC_LIB:.c=.o))
+OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
+
+JSFLAGS = -O0 -s EXPORTED_FUNCTIONS="['_mp_js_init', '_mp_js_init_repl', '_mp_js_do_str', '_mp_js_process_char', '_mp_hal_get_interrupt_char', '_mp_keyboard_interrupt']" -s EXTRA_EXPORTED_RUNTIME_METHODS="['ccall', 'cwrap']" --memory-init-file 0 --js-library library.js
+
+all: $(BUILD)/micropython.js
+
+$(BUILD)/micropython.js: $(OBJ) library.js wrapper.js
+ $(ECHO) "LINK $(BUILD)/firmware.js"
+ $(Q)emcc $(LDFLAGS) -o $(BUILD)/firmware.js $(OBJ) $(JSFLAGS)
+ cat $(BUILD)/firmware.js > $@
+ cat wrapper.js >> $@
+
+min: $(BUILD)/micropython.js
+ uglifyjs $< -c -o $(BUILD)/micropython.min.js
+
+test: $(BUILD)/micropython.js $(TOP)/tests/run-tests
+ $(eval DIRNAME=ports/$(notdir $(CURDIR)))
+ cd $(TOP)/tests && MICROPY_MICROPYTHON=../ports/javascript/node_run.sh ./run-tests
+
+include $(TOP)/py/mkrules.mk