1425bb815Sopenharmony_ci# Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci#
3425bb815Sopenharmony_ci# Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci# you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci# You may obtain a copy of the License at
6425bb815Sopenharmony_ci#
7425bb815Sopenharmony_ci#     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci#
9425bb815Sopenharmony_ci# Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci# distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci# See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci# limitations under the License.
14425bb815Sopenharmony_ci
15425bb815Sopenharmony_ci.DEFAULT_GOAL := all
16425bb815Sopenharmony_ci
17425bb815Sopenharmony_ciifeq ($(.DEFAULT_GOAL),)
18425bb815Sopenharmony_ci  $(warning no default goal is set)
19425bb815Sopenharmony_ciendif
20425bb815Sopenharmony_ci
21425bb815Sopenharmony_ciBOARD ?= qemu_x86
22425bb815Sopenharmony_ciCONF_FILE = prj.conf
23425bb815Sopenharmony_ciexport BOARD
24425bb815Sopenharmony_ci
25425bb815Sopenharmony_ciTARGET_ZEPHYR ?= ./targets/zephyr
26425bb815Sopenharmony_ciTARGET_ZEPHYR_SRC_DIR = $(TARGET_ZEPHYR)/src
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_ciCOMPONENTS  ?= jerry-core jerry-ext
29425bb815Sopenharmony_ciJERRYHEAP ?= 16
30425bb815Sopenharmony_ciJERRYPROFILE ?= minimal
31425bb815Sopenharmony_ci
32425bb815Sopenharmony_ci# Include functionality like regular expressions
33425bb815Sopenharmony_ci# check Jerry script documentation
34425bb815Sopenharmony_ci#
35425bb815Sopenharmony_ci# -cp
36425bb815Sopenharmony_ci# -cp_minimal
37425bb815Sopenharmony_ci# -cp_minimal-mem_stats
38425bb815Sopenharmony_ci# -mem_stats
39425bb815Sopenharmony_ci# -mem_stress_test
40425bb815Sopenharmony_ci
41425bb815Sopenharmony_ciifndef ZEPHYR_BASE
42425bb815Sopenharmony_ci$(error Missing Zephyr base, did you source zephyr-env.sh? )
43425bb815Sopenharmony_ciendif
44425bb815Sopenharmony_ci
45425bb815Sopenharmony_ciINTERM     = build/$(BOARD)/obj
46425bb815Sopenharmony_ciOUTPUT     = build/$(BOARD)/zephyr
47425bb815Sopenharmony_ci
48425bb815Sopenharmony_ciinclude $(OUTPUT)/Makefile.export
49425bb815Sopenharmony_ci
50425bb815Sopenharmony_ciEXT_CFLAGS := -fno-asynchronous-unwind-tables -fno-omit-frame-pointer
51425bb815Sopenharmony_ciEXT_CFLAGS += -fno-stack-protector -fno-strict-overflow -ffreestanding
52425bb815Sopenharmony_ciEXT_CFLAGS += -fno-reorder-functions -fno-defer-pop -fdata-sections
53425bb815Sopenharmony_ciEXT_CFLAGS += -ffunction-sections -fno-inline-functions
54425bb815Sopenharmony_ci
55425bb815Sopenharmony_ciEXT_CFLAGS += $(KBUILD_CFLAGS) $(NOSTDINC_FLAGS) $(subst -I,-isystem,$(ZEPHYRINCLUDE))
56425bb815Sopenharmony_ci
57425bb815Sopenharmony_ciEXT_CFLAGS += -Wall -Wno-format-zero-length -Wno-pointer-sign
58425bb815Sopenharmony_ciEXT_CFLAGS += -Werror=format -Werror=implicit-int -Wno-unused-but-set-variable
59425bb815Sopenharmony_ciEXT_CFLAGS += -Wno-main -Wno-strict-aliasing -Wno-old-style-declaration
60425bb815Sopenharmony_ciEXT_CFLAGS += -Wno-error=format=
61425bb815Sopenharmony_ciEXT_CFLAGS += -D_XOPEN_SOURCE=700
62425bb815Sopenharmony_ci
63425bb815Sopenharmony_ciEXT_CFLAGS += -Wno-error=conversion
64425bb815Sopenharmony_ci
65425bb815Sopenharmony_ciEXTERNAL_LIB = $(INTERM)/lib/libjerry-core.a $(INTERM)/lib/libjerry-ext.a
66425bb815Sopenharmony_ci
67425bb815Sopenharmony_ciLIBS = jerry-core jerry-ext
68425bb815Sopenharmony_ci
69425bb815Sopenharmony_ciBUILD_CONFIG = O="$(OUTPUT)" V=$(V) USER_LIBS="$(LIBS)" USER_LIB_INCLUDE_DIR="-L $(CURDIR)/$(INTERM)/lib" TARGET_ZEPHYR=$(TARGET_ZEPHYR)
70425bb815Sopenharmony_ci
71425bb815Sopenharmony_ci.PHONY: all
72425bb815Sopenharmony_ciall: zephyr
73425bb815Sopenharmony_ci
74425bb815Sopenharmony_ci$(EXTERNAL_LIB):
75425bb815Sopenharmony_ciifdef V
76425bb815Sopenharmony_ci	@echo "- JERRY SCRIPT -------------------------------------------------"
77425bb815Sopenharmony_ciendif
78425bb815Sopenharmony_ci	mkdir -p $(INTERM)
79425bb815Sopenharmony_ci	mkdir -p $(OUTPUT)
80425bb815Sopenharmony_ci	cmake -B$(INTERM) -H./ \
81425bb815Sopenharmony_ci	 -DCMAKE_SYSTEM_NAME=Zephyr \
82425bb815Sopenharmony_ci	 -DCMAKE_C_COMPILER="$(subst ccache ,,$(CC))" \
83425bb815Sopenharmony_ci	 -DCMAKE_C_COMPILER_WORKS=TRUE \
84425bb815Sopenharmony_ci	 -DENABLE_LTO=OFF \
85425bb815Sopenharmony_ci	 -DENABLE_ALL_IN_ONE=OFF \
86425bb815Sopenharmony_ci	 -DJERRY_CMDLINE=OFF \
87425bb815Sopenharmony_ci	 -DJERRY_PROFILE=$(JERRYPROFILE) \
88425bb815Sopenharmony_ci	 -DJERRY_ERROR_MESSAGES=ON \
89425bb815Sopenharmony_ci	 -DCMAKE_BUILD_TYPE=MinSizeRel \
90425bb815Sopenharmony_ci	 -DCMAKE_VERBOSE_MAKEFILE=$(V) \
91425bb815Sopenharmony_ci	 -DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP) \
92425bb815Sopenharmony_ci	 -DEXTERNAL_COMPILE_FLAGS="$(EXT_CFLAGS)" \
93425bb815Sopenharmony_ci	 $(EXT_JERRY_FLAGS)
94425bb815Sopenharmony_ci
95425bb815Sopenharmony_ci	make -C $(INTERM) $(COMPONENTS) V=1
96425bb815Sopenharmony_ci
97425bb815Sopenharmony_ci$(OUTPUT)/Makefile.export: $(OUTPUT)/Makefile
98425bb815Sopenharmony_ci	make --no-print-directory -C $(OUTPUT) outputexports CMAKE_COMMAND=: >$@
99425bb815Sopenharmony_ci
100425bb815Sopenharmony_ci$(OUTPUT)/Makefile:
101425bb815Sopenharmony_ci	mkdir -p $(OUTPUT) && cmake -DBOARD=$(BOARD) -DCONF_FILE=$(CONF_FILE) -B$(OUTPUT) -Htargets/zephyr/
102425bb815Sopenharmony_ci
103425bb815Sopenharmony_cizephyr: jerry
104425bb815Sopenharmony_ciifdef V
105425bb815Sopenharmony_ci	@echo "- ZEPHYR -------------------------------------------------------"
106425bb815Sopenharmony_ciendif
107425bb815Sopenharmony_ci	+make -C $(OUTPUT)
108425bb815Sopenharmony_ci	@echo "Finished"
109425bb815Sopenharmony_ci	@size $(OUTPUT)/zephyr/zephyr.elf
110425bb815Sopenharmony_ci
111425bb815Sopenharmony_cijerry: $(EXTERNAL_LIB)
112425bb815Sopenharmony_ci	@touch $(EXTERNAL_LIB)
113425bb815Sopenharmony_ci
114425bb815Sopenharmony_ciGENERIC_TARGETS = run qemugdb flash debug debugserver
115425bb815Sopenharmony_ciKCONFIG_TARGETS = \
116425bb815Sopenharmony_ci	initconfig config nconfig menuconfig xconfig gconfig \
117425bb815Sopenharmony_ci	oldconfig silentoldconfig defconfig savedefconfig \
118425bb815Sopenharmony_ci	allnoconfig allyesconfig alldefconfig randconfig \
119425bb815Sopenharmony_ci	listnewconfig olddefconfig
120425bb815Sopenharmony_ciCLEAN_TARGETS = mrproper
121425bb815Sopenharmony_ci
122425bb815Sopenharmony_ci$(GENERIC_TARGETS): jerry
123425bb815Sopenharmony_ci$(CLEAN_TARGETS): clean
124425bb815Sopenharmony_ci
125425bb815Sopenharmony_ci$(GENERIC_TARGETS) $(KCONFIG_TARGETS) $(CLEAN_TARGETS):
126425bb815Sopenharmony_ciifdef V
127425bb815Sopenharmony_ci	@echo "- ZEPHYR -------------------------------------------------------"
128425bb815Sopenharmony_ciendif
129425bb815Sopenharmony_ci	make -C $(OUTPUT) $@
130425bb815Sopenharmony_ci
131425bb815Sopenharmony_cidfu-x86: all
132425bb815Sopenharmony_ci	@- dfu-util -a x86_app -D build/$(BOARD)/zephyr/zephyr.bin; \
133425bb815Sopenharmony_ci	if [ $$? -eq 0 ] ; then echo "\nYour program will launch in 5 seconds." ; \
134425bb815Sopenharmony_ci	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
135425bb815Sopenharmony_ci
136425bb815Sopenharmony_ciusage:
137425bb815Sopenharmony_cihelp:
138425bb815Sopenharmony_ci	@echo Usage:
139425bb815Sopenharmony_ci	@echo showconfig	 Show parameters and configuration
140425bb815Sopenharmony_ci	@echo flash	         Flash into board
141425bb815Sopenharmony_ci	@echo all	         Compile jerryscript and zephyr
142425bb815Sopenharmony_ci
143425bb815Sopenharmony_cishowconfig:
144425bb815Sopenharmony_ci	@echo "- CONFIGURATION ------------------------------------------------"
145425bb815Sopenharmony_ci	@echo "INTERM           = $(INTERM)"
146425bb815Sopenharmony_ci	@echo "OUTPUT           = $(OUTPUT)"
147425bb815Sopenharmony_ci	@echo "CC               = $(CC) "
148425bb815Sopenharmony_ci	@echo "BOARD            = $(ZEPHYR_BASE)/boards/$(BOARD)/Makefile.board "
149425bb815Sopenharmony_ci	@echo "TOOLCHAIN        = $(ZEPHYR_BASE)/scripts/Makefile.toolchain.$(ZEPHYR_GCC_VARIANT) "
150425bb815Sopenharmony_ci	@echo "TOOLCHAIN_CFLAGS = $(TOOLCHAIN_CFLAGS) "
151425bb815Sopenharmony_ci	@echo "CROSS_COMPILE    = $(CROSS_COMPILE) "
152425bb815Sopenharmony_ci	@echo "TOOLCHAIN_LIBS   = $(TOOLCHAIN_LIBS) "
153425bb815Sopenharmony_ci	@echo "LIBS             = $(LIBS) "
154425bb815Sopenharmony_ci	@echo "BUILD_CONFIG     = $(BUILD_CONFIG) "
155425bb815Sopenharmony_ci	make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) showconfig
156425bb815Sopenharmony_ci
157425bb815Sopenharmony_ciclean:
158425bb815Sopenharmony_ciifdef V
159425bb815Sopenharmony_ci	@echo "- CLEANING JERRY SCRIPT ----------------------------------------"
160425bb815Sopenharmony_ciendif
161425bb815Sopenharmony_ci	rm -rf $(INTERM) $(TARGET_ZEPHYR_SRC_DIR)/*.o
162425bb815Sopenharmony_ciifdef V
163425bb815Sopenharmony_ci	@echo "- CLEANING ZEPHYR ----------------------------------------------"
164425bb815Sopenharmony_ciendif
165425bb815Sopenharmony_ci	make -f $(TARGET_ZEPHYR)/Makefile $(BUILD_CONFIG) clean
166425bb815Sopenharmony_ci
167425bb815Sopenharmony_cipristine: clean
168425bb815Sopenharmony_ciifdef V
169425bb815Sopenharmony_ci	@echo "- CLEANING BUILD DIRECTORY -------------------------------------"
170425bb815Sopenharmony_ciendif
171425bb815Sopenharmony_ci	rm -rf build/
172