aboutsummaryrefslogtreecommitdiffstats
path: root/amalgamate/merge_all.py
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-08-08 01:14:27 +0900
committeripknHama <ipknhama@gmail.com>2014-08-08 01:14:27 +0900
commit001c66b378d200bdecc8a4a692c5a73a7d426b8f (patch)
tree110f1a6596242b7837c16f88b4838d6fd93dc93c /amalgamate/merge_all.py
parentc36aa219e25e26019035fe3465471fd510778422 (diff)
downloadcrow-001c66b378d200bdecc8a4a692c5a73a7d426b8f.tar.gz
crow-001c66b378d200bdecc8a4a692c5a73a7d426b8f.zip
amalgamation added
Diffstat (limited to 'amalgamate/merge_all.py')
-rw-r--r--amalgamate/merge_all.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/amalgamate/merge_all.py b/amalgamate/merge_all.py
new file mode 100644
index 0000000..7935ead
--- /dev/null
+++ b/amalgamate/merge_all.py
@@ -0,0 +1,44 @@
+import glob
+import re
+from collections import defaultdict
+OUTPUT = 'crow_all.h'
+re_depends = re.compile('^#include "(.*)"', re.MULTILINE)
+headers = [x.rsplit('/',1)[-1] for x in glob.glob('../include/*.h')]
+print headers
+edges = defaultdict(list)
+for header in headers:
+ d = open("../include/" + header).read().decode('utf8')
+ match = re_depends.findall(d)
+ for m in match:
+ # m should included before header
+ edges[m].append(header)
+
+visited = defaultdict(bool)
+order = []
+def dfs(x):
+ visited[x] = True
+ for y in edges[x]:
+ if not visited[y]:
+ dfs(y)
+ order.append(x)
+
+for header in headers:
+ if not visited[header]:
+ dfs(header)
+
+order = order[::-1]
+for x in edges:
+ print x, edges[x]
+for x in edges:
+ for y in edges[x]:
+ assert order.index(x) < order.index(y), 'cyclic include detected'
+
+print order
+build = []
+for header in order:
+ d = open("../include/" + header).read().decode('utf8')
+ build.append(re_depends.sub(lambda x:'\n', d))
+ build.append('\n')
+
+open(OUTPUT,'w').write('\n'.join(build))
+