public
Description: Reia is a Ruby/Python-like language for BEAM, the Erlang VM
Homepage: http://reia-lang.org
Clone URL: git://github.com/tarcieri/reia.git
reia / Rakefile
100644 129 lines (99 sloc) 3.617 kb
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
task :default => [:check_erl_version, :build, :test]
task :build => [:smerl, :leex, :yecc, :reia, :ebin, :clean]
 
def erlang_version
  version = `erl -version 2>&1`.strip.match(/\d\.\d\.\d$/)
  unless version
   puts "Error retrieving Erlang version. Do you have it installed?"
   exit 1
  end
  
  version[0]
end
 
task :check_erl_version do
  print "Checking Erlang version... "
  version = erlang_version
  
  if version >= "5.6.3"
    puts "#{version} (ok)"
  else
    puts "#{version} (too old)"
    puts "Sorry, the version of Erlang you have installed is too old to run Reia"
    puts "Reia requires a minimum Erlang version of R12B-3 (5.6.3)"
    puts "Please see http://wiki.reia-lang.org/wiki/Building#Prerequisites"
    exit 1
  end
end
 
def output_file(input_file)
  'ebin/' + File.basename(input_file).sub(/\.\w+$/, '.beam')
end
 
# Reia
ERL_SRC = FileList.new('src/{compiler,core,types}/**/*.erl')
ERL_SRC.each do |input|
  file output_file(input) => input do
    sh "bin/erlc +debug_info -o artifacts/beam #{input}"
  end
end
 
REIA_SRC = FileList.new('src/**/*.re')
REIA_SRC.each do |input|
  output = output_file(input)
  file output => input do
    sh "bin/reiac -o artifacts/beam/#{File.basename(output, ".re")} #{input}"
  end
end
 
PARSER_SRC = FileList.new('src/**/*.{xrl,yrl}')
 
task :reia => (ERL_SRC + REIA_SRC + PARSER_SRC).map { |input_file| output_file(input_file) }
 
=begin
# Smart exceptions
SMEX_SRC = FileList['src/smart_exceptions/*.erl']
SMEX_SRC.each do |input|
file output_file(input) => input do
sh "erlc -W0 -o ebin #{input}"
end
end
 
task :smart_exceptions => SMEX_SRC.map { |input_file| output_file(input_file) }
=end
 
# Smerl (Simple Metaprogramming for Erlang)
task :smerl => "ebin/smerl.beam"
 
file "ebin/smerl.beam" => "src/smerl/smerl.erl" do
  sh "erlc -W0 -o ebin src/smerl/smerl.erl"
end
 
# Leex (lexer generator for Erlang)
task :leex => ["ebin/leex.beam", "ebin/reia_scan.beam"]
 
file "ebin/leex.beam" => "src/leex/leex.erl" do
  sh "erlc -W0 -o ebin src/leex/leex.erl"
end
 
# Compile reia_scan using leex
file "ebin/reia_scan.beam" => %w[ebin/leex.beam src/compiler/reia_scan.xrl] do
  sh "bin/leex src/compiler/reia_scan.xrl"
  mv "src/compiler/reia_scan.erl", "artifacts/erl/reia_scan.erl"
  sh "erlc +debug_info +nowarn_unused_vars -o artifacts/beam artifacts/erl/reia_scan.erl"
end
 
task :yecc => "ebin/reia_parse.beam"
 
# Compile reia_parse using yecc
file "ebin/reia_parse.beam" => "src/compiler/reia_parse.yrl" do
  sh "bin/yecc src/compiler/reia_parse.yrl"
  mv "src/compiler/reia_parse.erl", "artifacts/erl/reia_parse.erl"
  sh "erlc +debug_info -o ebin artifacts/erl/reia_parse.erl"
end
 
# Copy all output BEAM files into the ebin directory
task :ebin do
  FileList["artifacts/beam/*.beam"].each { |file| cp file, "ebin" }
end
 
task :test do
  sh "bin/reia test/runner.re"
end
 
task :install do
  lib_dir = `erl -noshell -eval "io:format(code:lib_dir())" -s init stop`
  reia_dir = File.join(lib_dir, 'reia', '')
  
  rm_r reia_dir if File.exist?(reia_dir)
  mkdir reia_dir
  
  %w[LICENSE README ebin src lib].each { |f| cp_r f, reia_dir }
  
  mkdir "/usr/local/bin" unless File.exist?("/usr/local/bin")
  
  File.open("/usr/local/bin/reia", "w") { |f| f << "erl -noshell +K true -s Loader start $* -s init stop" }
  File.open("/usr/local/bin/ire", "w") { |f| f << "erl +K true -noshell -noinput -s ire init" }
  
  File.chmod 0755, "/usr/local/bin/ire", "/usr/local/bin/reia"
end
 
task :clean do
  FileList['artifacts/**/*.{erl,beam}'].each { |f| rm_f f }
end
 
task :distclean => :clean do
  FileList['ebin/**/*.beam'].each { |f| rm_f f }
end