feat: add amalgamation generation script and Makefile target for wren.c

Introduce a Python script that concatenates all Wren library source files into a single amalgamation file, resolving local `#include` directives recursively to eliminate internal header dependencies. Add a corresponding `wren.c` Makefile target that invokes the script on the core header and VM sources, along with `.DELETE_ON_ERROR` to clean up on failure.
This commit is contained in:
Luchs
2015-03-26 20:21:41 +00:00
parent 1cd91a52b4
commit 628bf7ab1c
2 changed files with 33 additions and 0 deletions
+28
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)