Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ BOARD ?= arduino_101
# Dump memory information: on = print allocs, full = print allocs + dump pools
TRACE ?= off
# Generate and run snapshot as byte code instead of running JS directly
SNAPSHOT ?= off
SNAPSHOT ?= on

ifndef ZJS_BASE
$(error ZJS_BASE not defined. You need to source zjs-env.sh)
Expand All @@ -15,27 +15,35 @@ VARIANT ?= release
# JerryScript options
JERRY_BASE ?= $(ZJS_BASE)/deps/jerryscript
EXT_JERRY_FLAGS ?= -DENABLE_ALL_IN_ONE=ON
ifneq ($(DEV), ashell)
ifeq ($(SNAPSHOT), on)
EXT_JERRY_FLAGS += -DFEATURE_JS_PARSER=OFF
endif
endif
ifeq ($(BOARD), arduino_101)
EXT_JERRY_FLAGS += -DENABLE_LTO=ON
endif

# if no config file passed use the ashell default
ifeq ($(DEV), ashell)
CONFIG ?= fragments/zjs.conf.dev
SNAPSHOT = off
endif

# Print callback statistics during runtime
CB_STATS ?= off
# Print floats (uses -u _printf_float flag). This is a workaround on the A101
# otherwise floats will not print correctly. It does use ~11k extra ROM though
PRINT_FLOAT ?= off

# Make target (linux or zephyr)
# MAKECMDGOALS is a Make variable that is set to the target your building for.
TARGET = $(MAKECMDGOALS)

ifeq ($(TARGET), linux)
SNAPSHOT = off
endif

# If target is one of these, ensure ZEPHYR_BASE is set
ZEPHYR_TARGETS = zephyr arc debug
ifeq ($(TARGET), $(filter $(ZEPHYR_TARGETS),$(TARGET)))
Expand Down Expand Up @@ -119,7 +127,7 @@ else
@cat fragments/prj.conf.base >> prj.conf
endif
ifeq ($(BOARD), arduino_101)
cat fragments/prj.conf.arduino_101 >> prj.conf
@cat fragments/prj.conf.arduino_101 >> prj.conf
ifeq ($(ZJS_PARTITION), 256)
@cat fragments/prj.conf.partition_256 >> prj.conf
endif
Expand Down Expand Up @@ -151,6 +159,7 @@ clean:
@rm -f prj.conf.tmp
@rm -f prj.mdef
@rm -f zjs.conf.tmp
@rm -f .snapshot.last_build

.PHONY: pristine
pristine:
Expand Down Expand Up @@ -180,20 +189,35 @@ ifeq ($(SNAPSHOT), on)
make -f Makefile.snapshot; \
fi
@echo Creating snapshot bytecode from JS application...
@outdir/snapshot/snapshot $(JS) src/zjs_snapshot_gen.c
@outdir/snapshot/snapshot /tmp/zjs.js src/zjs_snapshot_gen.c
# SNAPSHOT=on, check if rebuilding JerryScript is needed
ifeq ("$(wildcard .snapshot.last_build)", "")
@rm -rf $(JERRY_BASE)/build/$(BOARD)/
@rm -f outdir/$(BOARD)/libjerry-core.a
endif
echo "" > .snapshot.last_build
else
@echo Creating C string from JS application...
ifeq ($(TARGET), linux)
@./scripts/convert.sh $(JS) src/zjs_script_gen.c
else
@./scripts/convert.sh /tmp/zjs.js src/zjs_script_gen.c
endif
# SNAPSHOT=off, check if rebuilding JerryScript is needed
ifneq ("$(wildcard .snapshot.last_build)", "")
@rm -rf $(JERRY_BASE)/build/$(BOARD)/
@rm -f outdir/$(BOARD)/libjerry-core.a
endif
@rm -f .snapshot.last_build
endif

# Run QEMU target
.PHONY: qemu
qemu: zephyr
make -f Makefile.zephyr MEM_STATS=$(MEM_STATS) CB_STATS=$(CB_STATS) SNAPSHOT=$(SNAPSHOT) qemu
make -f Makefile.zephyr qemu \
MEM_STATS=$(MEM_STATS) \
CB_STATS=$(CB_STATS) \
SNAPSHOT=$(SNAPSHOT)

# Builds ARC binary
.PHONY: arc
Expand Down Expand Up @@ -250,4 +274,5 @@ help:
@echo "Build options:"
@echo " BOARD= Specify a Zephyr board to build for"
@echo " JS= Specify a JS script to compile into the binary"
@echo " SNAPSHOT= Specify off to turn off snapshotting"
@echo
8 changes: 4 additions & 4 deletions Makefile.snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ JERRY_BASE ?= $(ZJS_BASE)/deps/jerryscript

JERRY_FLAGS ?= --snapshot-save=on

BUILD_DIR = $(ZJS_BASE)/outdir/snapshot/$(VARIANT)
BUILD_DIR = $(ZJS_BASE)/outdir/snapshot/

UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
Expand All @@ -20,11 +20,12 @@ all: snapshot

.PHONY: setup
setup:
@if [ ! -d $(ZJS_BASE)/outdir/snapshot/$(VARIANT) ]; then \
mkdir -p $(ZJS_BASE)/outdir/snapshot/$(VARIANT); \
@if [ ! -d $(ZJS_BASE)/outdir/snapshot/ ]; then \
mkdir -p $(ZJS_BASE)/outdir/snapshot/; \
fi

CORE_SRC += src/snapshot.c \
src/zjs_common.c \
src/zjs_script.c

CORE_OBJ = $(CORE_SRC:%.c=%.o)
Expand Down Expand Up @@ -62,7 +63,6 @@ SNAPSHOT_FLAGS += -fno-asynchronous-unwind-tables \
-Wpointer-sign

ifeq ($(VARIANT), debug)
SNAPSHOT_DEFINES += -DDEBUG_BUILD
SNAPSHOT_FLAGS += -g
DEBUG=1
else
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int main(int argc, char *argv[])
}

size_t size = jerry_parse_and_save_snapshot((jerry_char_t *)script,
strlen(script),
len,
true,
false,
snapshot_buf,
Expand Down