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_ciCURDIR     = `pwd`
16425bb815Sopenharmony_ciESP_LIB    = $(SDK_PATH)/lib
17425bb815Sopenharmony_ciBUILD_DIR  = build/obj-esp8266
18425bb815Sopenharmony_ciCOPYTARGET = targets/esp8266/libs
19425bb815Sopenharmony_ciUSBDEVICE  ?= /dev/ttyUSB0
20425bb815Sopenharmony_ciJERRYHEAP  ?= 20
21425bb815Sopenharmony_ciESPTOOL    ?= $(ESPTOOL_PATH)/esptool.py
22425bb815Sopenharmony_ci
23425bb815Sopenharmony_ci# compile flags
24425bb815Sopenharmony_ciESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
25425bb815Sopenharmony_ci
26425bb815Sopenharmony_ciMFORCE32 = $(shell xtensa-lx106-elf-gcc --help=target | grep mforce-l32)
27425bb815Sopenharmony_ci
28425bb815Sopenharmony_ciifneq ($(MFORCE32),)
29425bb815Sopenharmony_ci    # Your compiler supports the -mforce-l32 flag which means that
30425bb815Sopenharmony_ci    # constants can be placed in ROM to free additional RAM
31425bb815Sopenharmony_ci    ESP_CFLAGS += -DJERRY_ATTR_CONST_DATA="__attribute__((aligned(4))) __attribute__((section(\".irom.text\")))"
32425bb815Sopenharmony_ci    ESP_CFLAGS += -mforce-l32
33425bb815Sopenharmony_ciendif
34425bb815Sopenharmony_ci
35425bb815Sopenharmony_ciESP_CFLAGS += -Wl,-EL -fno-inline-functions
36425bb815Sopenharmony_ciESP_CFLAGS += -ffunction-sections -fdata-sections
37425bb815Sopenharmony_ciESP_CFLAGS += -mlongcalls -mtext-section-literals -mno-serialize-volatile
38425bb815Sopenharmony_ci
39425bb815Sopenharmony_ci.PHONY: jerry js2c mkbin check-env flash clean
40425bb815Sopenharmony_ci
41425bb815Sopenharmony_ciall: check-env jerry js2c mkbin
42425bb815Sopenharmony_ci
43425bb815Sopenharmony_cijerry:
44425bb815Sopenharmony_ci	mkdir -p $(BUILD_DIR)
45425bb815Sopenharmony_ci	mkdir -p $(COPYTARGET)
46425bb815Sopenharmony_ci	cmake -B$(BUILD_DIR) -H./ \
47425bb815Sopenharmony_ci	 -DCMAKE_SYSTEM_NAME=MCU \
48425bb815Sopenharmony_ci	 -DCMAKE_SYSTEM_PROCESSOR=xtensia-lx106 \
49425bb815Sopenharmony_ci	 -DCMAKE_C_COMPILER=xtensa-lx106-elf-gcc \
50425bb815Sopenharmony_ci	 -DCMAKE_C_COMPILER_WORKS=TRUE \
51425bb815Sopenharmony_ci	 -DENABLE_LTO=OFF \
52425bb815Sopenharmony_ci	 -DENABLE_ALL_IN_ONE=ON \
53425bb815Sopenharmony_ci	 -DJERRY_CMDLINE=OFF \
54425bb815Sopenharmony_ci	 -DEXTERNAL_COMPILE_FLAGS="$(ESP_CFLAGS)" \
55425bb815Sopenharmony_ci	 -DJERRY_GLOBAL_HEAP_SIZE=$(JERRYHEAP)
56425bb815Sopenharmony_ci
57425bb815Sopenharmony_ci	make -C$(BUILD_DIR) jerry-core jerry-libm
58425bb815Sopenharmony_ci	cp $(BUILD_DIR)/lib/libjerry-core.a $(COPYTARGET)/
59425bb815Sopenharmony_ci	cp $(BUILD_DIR)/lib/libjerry-libm.a $(COPYTARGET)/
60425bb815Sopenharmony_ci
61425bb815Sopenharmony_cijs2c:
62425bb815Sopenharmony_ci	tools/js2c.py --dest targets/esp8266/include --js-source targets/esp8266/js
63425bb815Sopenharmony_ci
64425bb815Sopenharmony_cimkbin:
65425bb815Sopenharmony_ci	make -Ctargets/esp8266 clean
66425bb815Sopenharmony_ci	make -Ctargets/esp8266 BOOT=new APP=0 SPI_SPEED=40 SPI_MODE=DIO SPI_SIZE_MAP=4
67425bb815Sopenharmony_ci
68425bb815Sopenharmony_cicheck-env:
69425bb815Sopenharmony_ciifndef SDK_PATH
70425bb815Sopenharmony_ci	$(error SDK_PATH is undefined for ESP8266)
71425bb815Sopenharmony_ciendif
72425bb815Sopenharmony_ciifndef BIN_PATH
73425bb815Sopenharmony_ci	$(error BIN_PATH is undefined for ESP8266)
74425bb815Sopenharmony_ciendif
75425bb815Sopenharmony_ci
76425bb815Sopenharmony_ciflash:
77425bb815Sopenharmony_ci	$(ESPTOOL) --port $(USBDEVICE) write_flash \
78425bb815Sopenharmony_ci	0x00000 $(BIN_PATH)/eagle.flash.bin \
79425bb815Sopenharmony_ci	0x20000 $(BIN_PATH)/eagle.irom0text.bin \
80425bb815Sopenharmony_ci	0x3FC000 $(SDK_PATH)/bin/esp_init_data_default.bin
81425bb815Sopenharmony_ci
82425bb815Sopenharmony_cierase_flash:
83425bb815Sopenharmony_ci	$(ESPTOOL) --port $(USBDEVICE) erase_flash
84425bb815Sopenharmony_ci
85425bb815Sopenharmony_ciclean:
86425bb815Sopenharmony_ci	rm -rf $(BUILD_DIR)
87