Permalink
Browse files

Build melbourne for MRI.

  • Loading branch information...
Brian Ford
Brian Ford committed Nov 4, 2009
1 parent 47cfec0 commit ef46d5d2db9019884a240d3d7df066c8a16e4026
Showing with 128 additions and 17 deletions.
  1. +2 −0 .gitignore
  2. +60 −1 lib/ext/melbourne/extconf.rb
  3. +8 −8 lib/ext/melbourne/melbourne.cpp
  4. +2 −2 lib/ext/melbourne/var_table.cpp
  5. +1 −0 lib/melbourne.rb
  6. +2 −0 lib/mri_bridge.rb
  7. +53 −6 rakelib/kernel.rake
View
@@ -75,6 +75,8 @@ tmtags
/lib/openssl/digest.rb
/lib/syslog.rb
+/lib/ext/melbourne/Makefile
+
# LLVM and its Makefiles
vm/external_libs/llvm/Makefile
vm/external_libs/llvm/Makefile.common
@@ -1,10 +1,69 @@
-require 'rbconfig'
require 'mkmf'
+dir_config("mquark")
+dir_config("bstring")
+dir_config("mpa")
+dir_config("cchash")
+
+have_library("bstring")
+have_library("mquark")
+have_library("ptr_array")
+have_library("cchash")
+
+# Courtesy of EventMachine. Thank you EventMachine and tmm1 !
+case RUBY_PLATFORM
+when /mswin32/, /mingw32/, /bccwin32/
+ check_heads(%w[windows.h winsock.h], true)
+ check_libs(%w[kernel32 rpcrt4 gdi32], true)
+
+ if GNU_CHAIN
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++"
+ else
+ $defs.push "-EHs"
+ $defs.push "-GR"
+ end
+
+when /solaris/
+ add_define 'OS_SOLARIS8'
+
+ if CONFIG['CC'] == 'cc' and `cc -flags 2>&1` =~ /Sun/ # detect SUNWspro compiler
+ # SUN CHAIN
+ add_define 'CC_SUNWspro'
+ $preload = ["\nCXX = CC"] # hack a CXX= line into the makefile
+ $CFLAGS = CONFIG['CFLAGS'] = "-KPIC"
+ CONFIG['CCDLFLAGS'] = "-KPIC"
+ CONFIG['LDSHARED'] = "$(CXX) -G -KPIC -lCstd"
+ else
+ # GNU CHAIN
+ # on Unix we need a g++ link, not gcc.
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
+ end
+
+when /openbsd/
+ # OpenBSD branch contributed by Guillaume Sellier.
+
+ # on Unix we need a g++ link, not gcc. On OpenBSD, linking against libstdc++ have to be explicitly done for shared libs
+ CONFIG['LDSHARED'] = "$(CXX) -shared -lstdc++ -fPIC"
+ CONFIG['LDSHAREDXX'] = "$(CXX) -shared -lstdc++ -fPIC"
+
+when /darwin/
+ # on Unix we need a g++ link, not gcc.
+ # Ff line contributed by Daniel Harple.
+ CONFIG['LDSHARED'] = "$(CXX) " + CONFIG['LDSHARED'].split[1..-1].join(' ')
+
+when /aix/
+ CONFIG['LDSHARED'] = "$(CXX) -shared -Wl,-G -Wl,-brtl"
+
+else
+ # on Unix we need a g++ link, not gcc.
+ CONFIG['LDSHARED'] = "$(CXX) -shared"
+end
+
create_makefile('melbourne')
File.open("Makefile","a+") do |f|
f.puts <<END
+
grammar.cpp: grammar.y
bison -o grammar.cpp grammar.y
END
@@ -7,18 +7,16 @@ extern "C" {
#endif
VALUE melbourne_string_to_ast(VALUE self, VALUE source, VALUE name, VALUE line) {
- bstring b_str = blk2bstr(rb_str_ptr_readonly(source), rb_str_len(source));
- VALUE result = melbourne::string_to_ast(self,
- rb_str_ptr_readonly(name), b_str, FIX2INT(line));
+ bstring b_str = blk2bstr(RSTRING_PTR(source), RSTRING_LEN(source));
+ VALUE result = melbourne::string_to_ast(self, RSTRING_PTR(name), b_str, FIX2INT(line));
bdestroy(b_str);
return result;
}
VALUE melbourne_file_to_ast(VALUE self, VALUE fname, VALUE start) {
- FILE *file = fopen(rb_str_ptr_readonly(fname), "r");
- VALUE result = melbourne::file_to_ast(self,
- rb_str_ptr_readonly(fname), file, FIX2INT(start));
+ FILE *file = fopen(RSTRING_PTR(fname), "r");
+ VALUE result = melbourne::file_to_ast(self, RSTRING_PTR(fname), file, FIX2INT(start));
fclose(file);
return result;
@@ -34,8 +32,10 @@ void Init_melbourne(void) {
#endif
rb_cMelbourne = rb_define_class_under(rb_mRubinius, "Melbourne", rb_cObject);
- rb_define_method(rb_cMelbourne, "string_to_ast", melbourne_string_to_ast, 3);
- rb_define_method(rb_cMelbourne, "file_to_ast", melbourne_file_to_ast, 2);
+ rb_define_method(rb_cMelbourne, "string_to_ast",
+ RUBY_METHOD_FUNC(melbourne_string_to_ast), 3);
+ rb_define_method(rb_cMelbourne, "file_to_ast",
+ RUBY_METHOD_FUNC(melbourne_file_to_ast), 2);
}
#ifdef __cplusplus
@@ -31,7 +31,7 @@ namespace melbourne {
var_table cur = vt;
vt = vt->next;
- XFREE(cur);
+ xfree(cur);
}
}
@@ -45,7 +45,7 @@ namespace melbourne {
var_table nw;
nw = cur->next;
- XFREE(cur);
+ xfree(cur);
return nw;
}
View
@@ -1,5 +1,6 @@
unless Object.const_defined? :RUBY_ENGINE
ext_dir = "ruby"
+ require "mri_bridge"
else
ext_dir = Object.const_get :RUBY_ENGINE
end
View
@@ -0,0 +1,2 @@
+module Rubinius
+end
View
@@ -94,15 +94,56 @@ extra_compiler.each do |rb_file|
end
end
-desc "Build all kernel files"
-task :kernel => 'kernel:build'
+namespace :compiler do
+ directory(mri_ext_dir = "lib/ext/melbourne/ruby")
+
+ mri_ext = "lib/ext/melbourne/ruby/melbourne.#{$dlext}"
+ task :build => mri_ext
+ file mri_ext => FileList[
+ mri_ext_dir,
+ "lib/ext/melbourne/extconf.rb",
+ "lib/ext/melbourne/grammar.y",
+ "lib/ext/melbourne/grammar.hpp",
+ "lib/ext/melbourne/grammar.cpp",
+ "lib/ext/melbourne/internal.hpp",
+ "lib/ext/melbourne/melbourne.cpp",
+ "lib/ext/melbourne/node.hpp",
+ "lib/ext/melbourne/visitor.hpp",
+ "lib/ext/melbourne/visitor.cpp",
+ "lib/ext/melbourne/local_state.hpp",
+ "lib/ext/melbourne/node_types.hpp",
+ "lib/ext/melbourne/node_types.cpp",
+ "lib/ext/melbourne/symbols.hpp",
+ "lib/ext/melbourne/symbols.cpp",
+ "lib/ext/melbourne/var_table.hpp",
+ "lib/ext/melbourne/var_table.cpp",
+ ] do
+ Dir.chdir "lib/ext/melbourne" do
+ puts "Building melbourne for MRI"
+ redirect = $verbose ? "" : " > /dev/null 2>&1"
+
+ libs = File.expand_path "../../vm/external_libs", __FILE__
+ ruby "extconf.rb --with-bstring-include=#{libs}/libbstring" \
+ " --with-mquark-include=#{libs}/libmquark" \
+ " --with-mpa-include=#{libs}/libmpa" \
+ " --with-cchash-include=#{libs}/libcchash" \
+ " --with-bstring-lib=#{libs}/libbstring" \
+ " --with-mquark-lib=#{libs}/libmquark" \
+ " --with-mpa-lib=#{libs}/libmpa" \
+ " --with-cchash-lib=#{libs}/libcchash" \
+ " #{redirect}"
+
+ sh "make clean #{redirect}"
+ sh "make #{redirect}"
+ mv "melbourne.#{$dlext}", "ruby", :verbose => $verbose
+ end
+ end
-namespace :kernel do
- task :load_compiler => opcodes do
+ task :load => [opcodes, :build] do
require 'lib/compiler/mri_compile'
end
- task :check_compiler => :load_compiler do
+ task :check => :load do
unless ENV['NOCLEAN']
existing = kernel.select { |name| name =~ /rbc$/ and File.exists? name }
kernel_mtime = existing.map { |name| File.stat(name).mtime }.min
@@ -114,7 +155,13 @@ namespace :kernel do
end
end
- task :build => ['kernel:check_compiler'] + kernel + extra_compiler do
+end
+
+desc "Build all kernel files"
+task :kernel => 'kernel:build'
+
+namespace :kernel do
+ task :build => ['compiler:check'] + kernel + extra_compiler do
subdirs.each do |subdir|
cp "kernel/#{subdir}/load_order.txt", "runtime/#{subdir}/load_order.txt"
end

0 comments on commit ef46d5d

Please sign in to comment.