mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
Add amalgamation generation script
This commit is contained in:
5
Makefile
5
Makefile
@ -53,4 +53,9 @@ watchdocs:
|
||||
gh-pages: docs
|
||||
@ cp -r build/docs/. build/gh-pages
|
||||
|
||||
# Build amalgamation of all Wren library files.
|
||||
wren.c: src/include/wren.h src/vm/*.h src/vm/*.c
|
||||
./script/generate_amalgamation.py $^ > $@
|
||||
|
||||
.DELETE_ON_ERROR: wren.c
|
||||
.PHONY: debug release all clean test builtin docs watchdocs gh-pages
|
||||
|
||||
28
script/generate_amalgamation.py
Executable file
28
script/generate_amalgamation.py
Executable file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys
|
||||
import os.path
|
||||
import re
|
||||
|
||||
INCLUDE_PATTERN = re.compile(r'^\s*#include "([\w.]+)"')
|
||||
|
||||
seen_files = set()
|
||||
|
||||
def add_file(filename):
|
||||
basename = os.path.basename(filename)
|
||||
# Only include each file at most once.
|
||||
if basename in seen_files:
|
||||
return
|
||||
seen_files.add(basename)
|
||||
path = os.path.dirname(filename)
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
for line in f:
|
||||
m = INCLUDE_PATTERN.match(line)
|
||||
if m:
|
||||
add_file(os.path.join(path, m.group(1)))
|
||||
else:
|
||||
sys.stdout.write(line)
|
||||
|
||||
for f in sys.argv[1:]:
|
||||
add_file(f)
|
||||
Reference in New Issue
Block a user