Add amalgamation generation script

This commit is contained in:
Luchs
2015-03-26 21:21:41 +01:00
parent 4dad9cd688
commit 9bcf31e14d
2 changed files with 33 additions and 0 deletions

View File

@ -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
View 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)