/
Rakefile
131 lines (98 loc) · 3.35 KB
/
Rakefile
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
require 'rbconfig'
def _(f, base = File.dirname(__FILE__))
File.expand_path(f, base)
end
dl_ext = RbConfig::CONFIG['DLEXT']
ext_dir = _("lib/parser/ext")
parser_e = _("fancy_parser.#{dl_ext}", ext_dir)
namespace :parser do
lexer_lex = _("lexer.lex", ext_dir)
lexer_c = _("lexer.c", ext_dir)
parser_y = _("parser.y", ext_dir)
parser_c = _("parser.c", ext_dir)
extconf = _("extconf.rb", ext_dir)
makefile = _("Makefile", ext_dir)
file lexer_c => file(lexer_lex) do
Dir.chdir(ext_dir) do
sh 'flex', '--outfile', lexer_c, '--header-file=lexer.h', lexer_lex
end
end
file parser_c => file(parser_y) do
Dir.chdir(ext_dir) { sh 'bison', '--output', parser_c, '-d', '-v', parser_y }
end
file makefile => file(extconf) do
Dir.chdir(ext_dir) { sh 'rbx', extconf }
end
desc "Generate parser source from flex/bison"
task :generate => [parser_c, lexer_c, makefile]
file parser_e => file(makefile) do
sh 'make', '-C', ext_dir
end
desc "Compile the parser extension"
task :compile => file(parser_e)
desc "Removed generated parser sources"
task :remove do
rm_f [_("parser.h", ext_dir), _("lexer.h", ext_dir)], :verbose => false
rm_f [makefile, parser_c, lexer_c], :verbose => false
end
desc "Clean compiled files."
task :clean do
rm_f Dir.glob(_("*.{o,so,rbc,log,output}", ext_dir)), :verbose => false
end
end
namespace :compiler do
load_rb = _("boot/load.rb")
desc "Compile fancy using the stable compiler (from boot/compiler)."
task :compile do
cmd = ['rbx', load_rb]
cmd << _("boot/compiler/boot.fyc")
cmd << _("boot/compiler/compiler.fyc")
cmd << _("boot/compiler/compiler/command.fyc")
cmd << _("boot/compiler/compile.fyc")
cmd << "--"
cmd << "--batch" if RakeFileUtils.verbose_flag == true
source_dirs = ["lib", "lib/parser", "lib/compiler", "lib/compiler/ast",
"lib/rbx", "lib/package", "boot"]
source_dirs.each do |dir|
sources = Dir.glob(_("*.fy", dir))
sh *(cmd + sources)
end
end
desc "Compile fancy using lib/ compiler into boot/compiler/"
task :wootstrap do
output = _("boot/.wootstrap")
cmd = ['rbx', load_rb]
cmd << _("lib/boot.fyc")
cmd << _("lib/compiler.fyc")
cmd << _("lib/compiler/command.fyc")
cmd << _("boot/compile.fyc")
cmd << "--"
cmd << "--batch" if RakeFileUtils.verbose_flag == true
cmd << "--output-path" << output
source_dirs = ["lib", "lib/parser", "lib/compiler", "lib/compiler/ast",
"lib/rbx", "lib/package", "boot"]
source_dirs.each do |dir|
sources = Dir.glob(_(dir + "/*.fy"))
src_path = ["--source-path", _(dir.split("/").first)]
sh *(cmd + src_path + sources)
end
mkdir_p _("parser/ext", output)
cp parser_e, _("parser/ext", output)
rm_rf _("boot/compiler")
mv _("boot/.wootstrap"), _("boot/compiler")
end
task :bootstrap do
task(:compile).invoke
task(:wootstrap).invoke
end
end
desc "Deletes all .rbc and .fyc files."
task :clean_compiled do
compiled = Dir.glob(_ "**/*.{rbc,fyc}", _("{bin,lib,examples,tests,spec}"))
rm_f compiled, :verbose => false
end
desc "Clean compiled files."
task :clean => ["parser:clean", :clean_compiled]
task :compile => ["parser:compile", "compiler:compile"]
task :bootstrap => [:clean, "compiler:bootstrap"]
task :default => :compile