• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright JS Foundation and other contributors, http://js.foundation
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15.DEFAULT_GOAL := all
16
17ifeq ($(.DEFAULT_GOAL),)
18  $(warning no default goal is set)
19endif
20
21BOARD ?= qemu_x86
22CONF_FILE = prj.conf
23export BOARD
24
25TARGET_ZEPHYR ?= ./targets/zephyr
26TARGET_ZEPHYR_SRC_DIR = $(TARGET_ZEPHYR)/src
27
28COMPONENTS  ?= jerry-core jerry-ext
29JERRYHEAP ?= 16
30JERRYPROFILE ?= minimal
31
32# Include functionality like regular expressions
33# check Jerry script documentation
34#
35# -cp
36# -cp_minimal
37# -cp_minimal-mem_stats
38# -mem_stats
39# -mem_stress_test
40
41ifndef ZEPHYR_BASE
42$(error Missing Zephyr base, did you source zephyr-env.sh? )
43endif
44
45INTERM     = build/$(BOARD)/obj
46OUTPUT     = build/$(BOARD)/zephyr
47
48include $(OUTPUT)/Makefile.export
49
50EXT_CFLAGS := -fno-asynchronous-unwind-tables -fno-omit-frame-pointer
51EXT_CFLAGS += -fno-stack-protector -fno-strict-overflow -ffreestanding
52EXT_CFLAGS += -fno-reorder-functions -fno-defer-pop -fdata-sections
53EXT_CFLAGS += -ffunction-sections -fno-inline-functions
54
55EXT_CFLAGS += $(KBUILD_CFLAGS) $(NOSTDINC_FLAGS) $(subst -I,-isystem,$(ZEPHYRINCLUDE))
56
57EXT_CFLAGS += -Wall -Wno-format-zero-length -Wno-pointer-sign
58EXT_CFLAGS += -Werror=format -Werror=implicit-int -Wno-unused-but-set-variable
59EXT_CFLAGS += -Wno-main -Wno-strict-aliasing -Wno-old-style-declaration
60EXT_CFLAGS += -Wno-error=format=
61EXT_CFLAGS += -D_XOPEN_SOURCE=700
62
63EXT_CFLAGS += -Wno-error=conversion
64
65EXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a $(INTERM)/lib/libjerry-ext.a
66
67LIBS = jerry-core jerry-ext
68
69BUILD_CONFIG = O="$(OUTPUT)" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(INTERM)/lib" TARGET_ZEPHYR=$(TARGET_ZEPHYR)
70
71.PHONY: all
72all: zephyr
73
74$(EXTERNAL_LIB):
75ifdef V
76	@echo "- JERRY SCRIPT -------------------------------------------------"
77endif
78	mkdir -p $(INTERM)
79	mkdir -p $(OUTPUT)
80	cmake -B$(INTERM) -H./ \
81	 -DCMAKE_SYSTEM_NAME=Zephyr \
82	 -DCMAKE_C_COMPILER="$(subst ccache ,,$(CC))" \
83	 -DCMAKE_C_COMPILER_WORKS=TRUE \
84	 -DENABLE_LTO=OFF \
85	 -DENABLE_ALL_IN_ONE=OFF \
86	 -DJERRY_CMDLINE=OFF \
87	 -DJERRY_PROFILE=$(JERRYPROFILE) \
88	 -DJERRY_ERROR_MESSAGES=ON \
89	 -DCMAKE_BUILD_TYPE=MinSizeRel \
90	 -DCMAKE_VERBOSE_MAKEFILE=$(V) \
91	 -DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP) \
92	 -DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
93	 $(EXT_JERRY_FLAGS)
94
95	make -C $(INTERM) $(COMPONENTS) V=1
96
97$(OUTPUT)/Makefile.export: $(OUTPUT)/Makefile
98	make --no-print-directory -C $(OUTPUT) outputexports CMAKE_COMMAND=: >$@
99
100$(OUTPUT)/Makefile:
101	mkdir -p $(OUTPUT) && cmake -DBOARD=$(BOARD) -DCONF_FILE=$(CONF_FILE) -B$(OUTPUT) -Htargets/zephyr/
102
103zephyr: jerry
104ifdef V
105	@echo "- ZEPHYR -------------------------------------------------------"
106endif
107	+make -C $(OUTPUT)
108	@echo "Finished"
109	@size $(OUTPUT)/zephyr/zephyr.elf
110
111jerry: $(EXTERNAL_LIB)
112	@touch $(EXTERNAL_LIB)
113
114GENERIC_TARGETS = run qemugdb flash debug debugserver
115KCONFIG_TARGETS = \
116	initconfig config nconfig menuconfig xconfig gconfig \
117	oldconfig silentoldconfig defconfig savedefconfig \
118	allnoconfig allyesconfig alldefconfig randconfig \
119	listnewconfig olddefconfig
120CLEAN_TARGETS = mrproper
121
122$(GENERIC_TARGETS): jerry
123$(CLEAN_TARGETS): clean
124
125$(GENERIC_TARGETS) $(KCONFIG_TARGETS) $(CLEAN_TARGETS):
126ifdef V
127	@echo "- ZEPHYR -------------------------------------------------------"
128endif
129	make -C $(OUTPUT) $@
130
131dfu-x86: all
132	@- dfu-util -a x86_app -D build/$(BOARD)/zephyr/zephyr.bin; \
133	if [ $$? -eq 0 ] ; then echo "\nYour program will launch in 5 seconds." ; \
134	else echo "\nProgram didn't flash, try pressing the reset buttons \nand wait a second for the bootloader to load, \nor flash again the factory bootloader."; fi
135
136usage:
137help:
138	@echo Usage:
139	@echo showconfig	 Show parameters and configuration
140	@echo flash	         Flash into board
141	@echo all	         Compile jerryscript and zephyr
142
143showconfig:
144	@echo "- CONFIGURATION ------------------------------------------------"
145	@echo "INTERM           = $(INTERM)"
146	@echo "OUTPUT           = $(OUTPUT)"
147	@echo "CC               = $(CC) "
148	@echo "BOARD            = $(ZEPHYR_BASE)/boards/$(BOARD)/Makefile.board "
149	@echo "TOOLCHAIN        = $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) "
150	@echo "TOOLCHAIN_CFLAGS = $(TOOLCHAIN_CFLAGS) "
151	@echo "CROSS_COMPILE    = $(CROSS_COMPILE) "
152	@echo "TOOLCHAIN_LIBS   = $(TOOLCHAIN_LIBS) "
153	@echo "LIBS             = $(LIBS) "
154	@echo "BUILD_CONFIG     = $(BUILD_CONFIG) "
155	make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) showconfig
156
157clean:
158ifdef V
159	@echo "- CLEANING JERRY SCRIPT ----------------------------------------"
160endif
161	rm -rf $(INTERM) $(TARGET_ZEPHYR_SRC_DIR)/*.o
162ifdef V
163	@echo "- CLEANING ZEPHYR ----------------------------------------------"
164endif
165	make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) clean
166
167pristine: clean
168ifdef V
169	@echo "- CLEANING BUILD DIRECTORY -------------------------------------"
170endif
171	rm -rf build/
172