@@ -3,7 +3,7 @@ BOARD ?= arduino_101
33# Dump memory information: on = print allocs, full = print allocs + dump pools
44TRACE ?= off
55# Generate and run snapshot as byte code instead of running JS directly
6- SNAPSHOT ?= off
6+ SNAPSHOT ?= on
77
88ifndef ZJS_BASE
99$(error ZJS_BASE not defined. You need to source zjs-env.sh)
@@ -15,27 +15,35 @@ VARIANT ?= release
1515# JerryScript options
1616JERRY_BASE ?= $(ZJS_BASE ) /deps/jerryscript
1717EXT_JERRY_FLAGS ?= -DENABLE_ALL_IN_ONE=ON
18+ ifneq ($(DEV ) , ashell)
1819ifeq ($(SNAPSHOT ) , on)
1920EXT_JERRY_FLAGS += -DFEATURE_JS_PARSER=OFF
2021endif
22+ endif
2123ifeq ($(BOARD ) , arduino_101)
2224EXT_JERRY_FLAGS += -DENABLE_LTO=ON
2325endif
2426
2527# if no config file passed use the ashell default
2628ifeq ($(DEV ) , ashell)
2729 CONFIG ?= fragments/zjs.conf.dev
30+ SNAPSHOT = off
2831endif
2932
3033# Print callback statistics during runtime
3134CB_STATS ?= off
3235# Print floats (uses -u _printf_float flag). This is a workaround on the A101
3336# otherwise floats will not print correctly. It does use ~11k extra ROM though
3437PRINT_FLOAT ?= off
38+
3539# Make target (linux or zephyr)
3640# MAKECMDGOALS is a Make variable that is set to the target your building for.
3741TARGET = $(MAKECMDGOALS )
3842
43+ ifeq ($(TARGET ) , linux)
44+ SNAPSHOT = off
45+ endif
46+
3947# If target is one of these, ensure ZEPHYR_BASE is set
4048ZEPHYR_TARGETS = zephyr arc debug
4149ifeq ($(TARGET ) , $(filter $(ZEPHYR_TARGETS ) ,$(TARGET ) ) )
119127 @cat fragments/prj.conf.base >> prj.conf
120128endif
121129ifeq ($(BOARD ) , arduino_101)
122- cat fragments/prj.conf.arduino_101 >> prj.conf
130+ @ cat fragments/prj.conf.arduino_101 >> prj.conf
123131ifeq ($(ZJS_PARTITION ) , 256)
124132 @cat fragments/prj.conf.partition_256 >> prj.conf
125133endif
@@ -151,6 +159,7 @@ clean:
151159 @rm -f prj.conf.tmp
152160 @rm -f prj.mdef
153161 @rm -f zjs.conf.tmp
162+ @rm -f .snapshot.last_build
154163
155164.PHONY : pristine
156165pristine :
@@ -180,20 +189,35 @@ ifeq ($(SNAPSHOT), on)
180189 make -f Makefile.snapshot; \
181190 fi
182191 @echo Creating snapshot bytecode from JS application...
183- @outdir/snapshot/snapshot $(JS) src/zjs_snapshot_gen.c
192+ @outdir/snapshot/snapshot /tmp/zjs.js src/zjs_snapshot_gen.c
193+ # SNAPSHOT=on, check if rebuilding JerryScript is needed
194+ ifeq ("$(wildcard .snapshot.last_build) ", "")
195+ @rm -rf $(JERRY_BASE)/build/$(BOARD)/
196+ @rm -f outdir/$(BOARD)/libjerry-core.a
197+ endif
198+ echo "" > .snapshot.last_build
184199else
185200 @echo Creating C string from JS application...
186201ifeq ($(TARGET ) , linux)
187202 @./scripts/convert.sh $(JS) src/zjs_script_gen.c
188203else
189204 @./scripts/convert.sh /tmp/zjs.js src/zjs_script_gen.c
190205endif
206+ # SNAPSHOT=off, check if rebuilding JerryScript is needed
207+ ifneq ("$(wildcard .snapshot.last_build) ", "")
208+ @rm -rf $(JERRY_BASE)/build/$(BOARD)/
209+ @rm -f outdir/$(BOARD)/libjerry-core.a
210+ endif
211+ @rm -f .snapshot.last_build
191212endif
192213
193214# Run QEMU target
194215.PHONY : qemu
195216qemu : zephyr
196- make -f Makefile.zephyr MEM_STATS=$(MEM_STATS ) CB_STATS=$(CB_STATS ) SNAPSHOT=$(SNAPSHOT ) qemu
217+ make -f Makefile.zephyr qemu \
218+ MEM_STATS=$(MEM_STATS ) \
219+ CB_STATS=$(CB_STATS ) \
220+ SNAPSHOT=$(SNAPSHOT )
197221
198222# Builds ARC binary
199223.PHONY : arc
@@ -250,4 +274,5 @@ help:
250274 @echo " Build options:"
251275 @echo " BOARD= Specify a Zephyr board to build for"
252276 @echo " JS= Specify a JS script to compile into the binary"
277+ @echo " SNAPSHOT= Specify off to turn off snapshotting"
253278 @echo
0 commit comments