mirror of
https://github.com/zekexiao/pocketlang.git
synced 2025-02-06 12:46:53 +08:00
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
#!python
|
|
## Copyright (c) 2021 Thakee Nathees
|
|
## Licensed under: MIT License
|
|
|
|
## TODO: Write a proper emconfigure build file.
|
|
## This is a quick and dirty build script.
|
|
|
|
import os, shutil
|
|
from os.path import join
|
|
|
|
SRC_DIR = '../../src/'
|
|
JS_API_PATH = './js_api.js'
|
|
TARGET_DIR = 'build/'
|
|
TARGET_NAME = 'try_online.html'
|
|
|
|
def main():
|
|
sources = ' '.join(collect_source_files())
|
|
include = '-I' + fix_path(join(SRC_DIR, 'include/'))
|
|
output = join(TARGET_DIR, TARGET_NAME)
|
|
exports = "\"EXPORTED_RUNTIME_METHODS=['ccall','cwrap']\""
|
|
js_api = JS_API_PATH
|
|
|
|
cmd = f"emcc {include} main.c {sources} -o {output} " +\
|
|
f"-s {exports} --js-library {js_api}"
|
|
|
|
print(cmd)
|
|
os.system(cmd)
|
|
|
|
## TODO: copy output to static dir.
|
|
os.remove(output) ## Not using the generated html file.
|
|
|
|
|
|
def fix_path(path):
|
|
return path.replace('\\', '/')
|
|
|
|
def collect_source_files():
|
|
sources = []
|
|
|
|
def add_all(root, sources):
|
|
for file in os.listdir(root):
|
|
if not os.path.isfile(join(root, file)): continue
|
|
if file.endswith('.c'):
|
|
source = fix_path(join(root, file))
|
|
sources.append(source)
|
|
|
|
add_all(SRC_DIR, sources)
|
|
add_all(join(SRC_DIR, 'buffers/'), sources)
|
|
return sources
|
|
|
|
if __name__ == '__main__':
|
|
main() |