1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
divert(-1)
changequote([,])
divert(0)
# rules
cflags = -Wall -Wextra -g -I.
bin = bin
leak = valgrind -s --leak-check=full --show-leak-kinds=all
rule cc
depfile = $out.d
command = gcc -MD -MF $out.d $cflags $in -o $out
rule shared
depfile = $out.d
command = gcc -MD -MF $out.d $cflags -shared -fPIC $in -o $out
rule m4
command = m4 $m4flags $in > $out
build $bin/generate-parser: cc demos/generate-parser.c
cflags = $cflags -rdynamic
rule parser_gen
command = $leak $bin/generate-parser -o $$(echo $out | cut -f1 -d'.') -t $tabletype $in
define([gbuild], [ifelse(
[$1], [from-gram], [
build $bin/$2-gram.c: gram_parse $3/$2.g | $bin/gram-parser
build $bin/$2-gram.so: shared $bin/$2-gram.c],
[$1], [from-defs], [
build $bin/$2-gram.so: shared $3/$2-defs.c])
build $bin/$2.c $bin/$2.h: parser_gen $bin/$2-gram.so | $bin/generate-parser tables
tabletype = lalr-table
build $bin/$2-parser: cc $3/$2-skeleton.c $5 | $bin/$2.c $bin/$2.h
build $2: phony $bin/$2-parser
])
# building tools
build $bin/slr-table.so: shared slr-table.c
build $bin/clr-table.so: shared clr-table.c
build $bin/lalr-table.so: shared clr-table.c
cflags = $cflags -D_LAZY_LALR
build tables: phony $bin/slr-table.so $bin/clr-table.so $bin/lalr-table.so
gbuild(from-defs, gram, demos/sample-files, lalr-table)
rule gram_parse
command = $leak $bin/gram-parser < $in > $out
# build actual
gbuild(from-gram, lbp, demos/sample-files, lalr-table, util/dict.c)
rule lbp_parse
command = $leak $bin/lbp-parser < $in
build lbp_test: lbp_parse demos/sample-files/lbp-code.lbp | lbp
gbuild(from-gram, calc, demos/sample-files, lalr-table) # skeleton doesn't work
rule calc_parse
command = $leak $bin/calc-parser 5+3
build calc_test: calc_parse | calc
# targets
rule ninja_clean
command = ninja -t clean
build clean: ninja_clean
default lbp_test
# regeneration
rule regen
command = m4 ninja.m4 > build.ninja
generator = 1
description = Regen build.ninja
build build.ninja: regen ninja.m4
build configure: regen
|