targets: merge js2c.py into targets/tools folder
* also add .PHONY to target makefiles JerryScript-DCO-1.0-Signed-off-by: SaeHie Park saehie.park@samsung.com
This commit is contained in:
@@ -26,6 +26,7 @@ SRCPATH = targets/esp8266/source
|
||||
COPYTARGET = targets/esp8266/libs
|
||||
USBDEVICE ?= /dev/ttyUSB0
|
||||
JERRYHEAP ?= 20
|
||||
ESPTOOL ?= /opt/Espressif/esptool-py/esptool.py
|
||||
|
||||
# compile flags
|
||||
ESP_CFLAGS := -D__TARGET_ESP8266 -D__attr_always_inline___=
|
||||
@@ -47,6 +48,8 @@ JERRY_BUILD_FILES := $(SRCPATH)/jerry_extapi.cpp
|
||||
JERRY_BUILD_FILES := $(JERRY_BUILD_FILES);$(SRCPATH)/jerry_run.cpp
|
||||
|
||||
|
||||
.PHONY: jerry js2c mbed check-env flash clean
|
||||
|
||||
|
||||
all: check-env jerry js2c mbed
|
||||
|
||||
@@ -78,7 +81,7 @@ jerry:
|
||||
|
||||
|
||||
js2c:
|
||||
cd targets/esp8266; ./js2c.py
|
||||
cd targets/esp8266; ../tools/js2c.py
|
||||
|
||||
|
||||
mbed:
|
||||
@@ -98,7 +101,7 @@ endif
|
||||
|
||||
|
||||
flash:
|
||||
/opt/Espressif/esptool-py/esptool.py --port $(USBDEVICE) write_flash \
|
||||
$(ESPTOOL) --port $(USBDEVICE) write_flash \
|
||||
0x00000 $(SDK_PATH)/bin/"boot_v1.4(b1).bin" \
|
||||
0x01000 $(BIN_PATH)/upgrade/user1.2048.new.3.bin \
|
||||
0x81000 $(BIN_PATH)/upgrade/user2.2048.new.3.bin \
|
||||
|
||||
@@ -27,6 +27,9 @@ EXT_CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4
|
||||
EXT_CFLAGS += -Wno-error=format=
|
||||
|
||||
|
||||
.PHONY: jerry js2c yotta flash check_mbed clean
|
||||
|
||||
|
||||
all: jerry js2c yotta
|
||||
|
||||
|
||||
@@ -52,7 +55,7 @@ jerry:
|
||||
|
||||
|
||||
js2c:
|
||||
cd targets/mbedk64f; ./js2c.py;
|
||||
cd targets/mbedk64f; ../tools/js2c.py;
|
||||
|
||||
|
||||
yotta:
|
||||
|
||||
@@ -1,144 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# This file converts ./js/*.js to a C-array in source/jerry_targetjs.h file
|
||||
|
||||
import sys
|
||||
import glob
|
||||
import os
|
||||
import re
|
||||
|
||||
def extractName(path):
|
||||
return os.path.splitext(os.path.basename(path))[0]
|
||||
|
||||
def writeLine(fo, content, indent=0):
|
||||
buf = ' ' * indent + content + '\n'
|
||||
fo.write(buf)
|
||||
|
||||
def regroup(l, n):
|
||||
return [ l[i:i+n] for i in range(0, len(l), n) ]
|
||||
|
||||
def removeComments(code):
|
||||
pattern = r'(\".*?\"|\'.*?\')|(/\*.*?\*/|//[^\r\n]*$)'
|
||||
regex = re.compile(pattern, re.MULTILINE | re.DOTALL)
|
||||
def _replacer(match):
|
||||
if match.group(2) is not None:
|
||||
return ""
|
||||
else:
|
||||
return match.group(1)
|
||||
return regex.sub(_replacer, code)
|
||||
|
||||
def removeWhitespaces(code):
|
||||
return re.sub('\n+', '\n', re.sub('\n +', '\n', code))
|
||||
|
||||
|
||||
LICENSE = '''/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the \"License\");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an \"AS IS\" BASIS
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is generated by js2c.py. Please do not modify.
|
||||
*/
|
||||
|
||||
'''
|
||||
|
||||
HEADER = '''#ifndef JERRY_TARGETJS_H
|
||||
#define JERRY_TARGETJS_H
|
||||
|
||||
'''
|
||||
|
||||
FOOTER = '''
|
||||
#endif
|
||||
|
||||
'''
|
||||
|
||||
OUT_PATH = './source/'
|
||||
SRC_PATH = './js/'
|
||||
|
||||
# argument processing
|
||||
buildtype = 'release'
|
||||
if len(sys.argv) >= 2:
|
||||
buildtype = sys.argv[1]
|
||||
|
||||
fout = open(OUT_PATH + 'jerry_targetjs.h', 'w')
|
||||
fout.write(LICENSE);
|
||||
fout.write(HEADER);
|
||||
|
||||
def exportOneFile(path, name):
|
||||
fout.write('const static char ' + name + '_n[] = "' + name + '";\n')
|
||||
fout.write('const static char ' + name + '_s[] =\n{\n')
|
||||
|
||||
fin = open(path, 'r');
|
||||
code = fin.read() + '\0'
|
||||
|
||||
# minimize code when release mode
|
||||
if buildtype != 'debug':
|
||||
code = removeComments(code)
|
||||
code = removeWhitespaces(code)
|
||||
|
||||
for line in regroup(code, 10):
|
||||
buf = ', '.join(map(lambda ch: format(ord(ch),"#04x"), line))
|
||||
if line[-1] != '\0':
|
||||
buf += ','
|
||||
writeLine(fout, buf, 1)
|
||||
writeLine(fout, '};')
|
||||
writeLine(fout, 'const static int ' + name + '_l = ' + str(len(code)-1) + ';')
|
||||
writeLine(fout, '')
|
||||
|
||||
fin.close();
|
||||
|
||||
def exportOneName(name):
|
||||
writeLine(fout, '{ ' + name + '_n, ' + name + '_s, ' + name + '_l }, \\', 1)
|
||||
|
||||
files = glob.glob(SRC_PATH + '*.js')
|
||||
for path in files:
|
||||
name = extractName(path)
|
||||
exportOneFile(path, name)
|
||||
|
||||
|
||||
NATIVE_STRUCT = '''
|
||||
struct js_source_all {
|
||||
const char* name;
|
||||
const char* source;
|
||||
const int length;
|
||||
};
|
||||
|
||||
#define DECLARE_JS_CODES \\
|
||||
struct js_source_all js_codes[] = \\
|
||||
{ \\
|
||||
'''
|
||||
|
||||
fout.write(NATIVE_STRUCT)
|
||||
exportOneName('main')
|
||||
filenames = map(extractName, files)
|
||||
for name in filenames:
|
||||
if name != 'main':
|
||||
exportOneName(name)
|
||||
|
||||
writeLine(fout, '{ NULL, NULL, 0 } \\', 1)
|
||||
writeLine(fout, '};')
|
||||
|
||||
fout.write(FOOTER)
|
||||
fout.close()
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
# Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# This file converts ./js/*.js to a C-array in source/jerry_targetjs.h file
|
||||
# This file converts ./js/*.js to a C-array in ./source/jerry_targetjs.h file
|
||||
|
||||
import sys
|
||||
import glob
|
||||
@@ -45,7 +45,7 @@ def removeWhitespaces(code):
|
||||
return re.sub('\n+', '\n', re.sub('\n +', '\n', code))
|
||||
|
||||
|
||||
LICENSE = '''/* Copyright 2015 Samsung Electronics Co., Ltd.
|
||||
LICENSE = '''/* Copyright 2015-2016 Samsung Electronics Co., Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the \"License\");
|
||||
* you may not use this file except in compliance with the License.
|
||||
Reference in New Issue
Block a user