diff --git a/Makefile b/Makefile index 4155985f..32b3d573 100644 --- a/Makefile +++ b/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 diff --git a/script/generate_amalgamation.py b/script/generate_amalgamation.py new file mode 100755 index 00000000..d0749fd7 --- /dev/null +++ b/script/generate_amalgamation.py @@ -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)