-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
133 lines (120 loc) · 2.94 KB
/
meson.build
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
project('c_compiler', 'c', default_options : [ 'c_std=c11' ])
incdir = include_directories('include')
ds_proj = subproject('ds')
ds_vec_dep = ds_proj.get_variable('ds_vec_dep')
ds_hashmap_dep = ds_proj.get_variable('ds_hashmap_dep')
lex = find_program('lex')
bison = find_program('bison')
nasm = find_program('nasm')
gcc = find_program('gcc')
lgen = generator(lex,
output : '@[email protected]',
arguments : ['-t', '@INPUT@'],
capture : true)
lfiles = lgen.process('src/c.l')
pgen = generator(bison,
output : ['@[email protected]', '@[email protected]'],
arguments : ['@INPUT@', '--defines=@OUTPUT1@', '--output=@OUTPUT0@'])
pfiles = pgen.process('src/c.y')
c_compiler = executable(
'c_compiler',
'src/ast.c',
'src/cg.c',
lfiles, pfiles,
dependencies : [ ds_vec_dep, ds_hashmap_dep ],
include_directories : incdir
)
comp_asm = generator(c_compiler,
output : [ '@[email protected]' ],
arguments : [ 'asm', '@INPUT@' ],
capture : true
)
# compilation tests
foreach item : [
{ 'c': 'test/bf_interp.c' },
{ 'c': 'test/pointers.c', 't': true },
{ 'c': 'test/scopes.c', 't': true },
]
c_file = item.get('c')
do_test = item.get('t', false)
test_s = comp_asm.process(c_file)
test_o = custom_target(
c_file.underscorify() + '_o',
input : test_s,
output : [ '@[email protected]' ],
command : [ nasm, '-f', 'elf64', '-o', '@OUTPUT@', '@INPUT@' ]
)
test_exe = executable(
c_file.underscorify() + '_exe',
test_o,
link_args: [ '-static' ],
)
if do_test
test(
c_file.underscorify() + '_test',
test_exe,
timeout: 2,
)
endif
endforeach
# parsing tests
foreach c_file : [
'declarators.c',
]
path = 'test/syntax/' + c_file
test(
path.underscorify(),
c_compiler,
args: [ 'ast', files(path) ],
timeout: 2,
)
endforeach
# compilation error tests
foreach c_file : [
'inc_lvalue.c',
'addressof_lvalue.c',
'add_ptr.c',
'add_non_arith.c',
'sub_ptr.c',
'deref_non_ptr.c',
]
path = 'test/error/' + c_file
test(
path.underscorify(),
c_compiler,
args: [ 'asm', files(path) ],
timeout: 2,
should_fail: true
)
endforeach
# a bit ugly because LaTeX needs to be compiled twice, but does the job...
prog_pdflatex = find_program('pdflatex', required: false)
if prog_pdflatex.found()
foreach tex : [ 'Documentation/spec.tex', 'Documentation/paper.tex' ]
basename = tex.split('.')[-2].split('/')[-1]
tagged = vcs_tag(
command : [ 'git', 'rev-parse', '--short', 'HEAD' ],
input: tex,
output: basename + '.tex'
)
first_pass = custom_target(basename + '_first_pass',
input : tagged,
output : [ basename + '.aux' ],
command : [
prog_pdflatex,
'-output-directory=@OUTDIR@',
'@INPUT@',
],
)
custom_target(basename,
input : [ tagged, first_pass ],
output : basename + '.pdf',
command : [
prog_pdflatex,
'-output-directory=@OUTDIR@',
'@INPUT@',
],
build_by_default: true,
)
endforeach
endif