Permalink
Browse files

Fixed toplevel C ext tasks to always delegate to the ext Rakefile.

  • Loading branch information...
1 parent 2876e14 commit 60f7d84fc951a93499503eaf3fb5faf578ec3548 Brian Ford committed Nov 18, 2009
Showing with 65 additions and 41 deletions.
  1. +46 −19 lib/ext/melbourne/Rakefile
  2. +2 −2 rakelib/ext_helper.rb
  3. +14 −20 rakelib/extensions.rake
  4. +3 −0 rakelib/kernel.rake
View
@@ -1,5 +1,46 @@
+# Special rule for putting .o files in the implementation-specific
+# subdirectory so this single extension can be built for both MRI
+# and Rubinius
+
+rule ".o" do |t|
+ source = t.prerequisites.first
+
+ report_command "CXX #{source}"
+ qsh "#{$CXX} -c -o #{t.name} #{$CXXFLAGS} #{source}"
+end
+
+def set_ext_dir(dir)
+ @ext_dir = dir
+end
+
+def ext_dir
+ @ext_dir
+end
+
# Setup project files
-project_files = common_headers + headers + sources("grammar.cpp") + objects
+def add_objects(files, dir)
+ sources("grammar.cpp").zip(objects(dir)).each do |source, obj|
+ file obj => source
+ files << source << obj
+ end
+end
+
+project_files = common_headers + headers
+
+# This is a horrid hack. It is temporary until we replace Rake
+# as the build system.
+case Rake.application.top_level_tasks
+when ["build:rbx"]
+ puts "Building Melbourne for Rubinius"
+ add_rbx_capi
+ set_ext_dir "rbx"
+when ["build:mri"]
+ puts "Building Melbourne for MRI"
+ add_mri_capi
+ set_ext_dir "ruby"
+end
+
+add_objects project_files, ext_dir
add_include_dir "#{$ELIBSDIR}/libbstring",
"#{$ELIBSDIR}/libmquark",
@@ -8,40 +49,26 @@ add_include_dir "#{$ELIBSDIR}/libbstring",
add_external_lib "mquark", "bstring", "ptr_array", "cchash"
-task :clean do
- rm_f FileList["./**/*.o"], :verbose => $verbose
-end
-
# Build the Melbourne extension against Rubinius
directory "rbx"
melbourne_rbx = "rbx/melbourne.#{$DLEXT}"
+file melbourne_rbx => project_files
+
# Build the Melbourne extension against MRI
directory "ruby"
melbourne_mri = "ruby/melbourne.#{$DLEXT}"
+file melbourne_mri => project_files
+
# Build tasks
namespace :build do
- task :pre_rbx do
- puts "Building Melbourne for Rubinius"
- add_rbx_capi
- end
-
desc "Build Melbourne for Rubinius"
task :rbx => melbourne_rbx
- task :pre_mri do
- puts "Building Melbourne for MRI"
- add_mri_capi
- end
-
desc "Build Melbourne for MRI"
task :mri => melbourne_mri
end
-file melbourne_rbx => %w[build:pre_rbx clean rbx] + project_files
-
-file melbourne_mri => %w[build:pre_mri clean ruby] + project_files
-
desc "Build Melbourne for both Rubinius and MRI"
task :build => %w[build:mri build:rbx]
View
@@ -197,8 +197,8 @@ def sources(*extra)
@sources ||= FileList["*.{c,cpp}", *extra].uniq
end
-def objects(*extra)
- @objects ||= sources.ext(".o")
+def objects(dir=nil)
+ @objects ||= dir ? sources.pathmap("#{dir}/%X.o") : sources.ext(".o")
end
# Helper methods for invoking and reporting on commands
View
@@ -22,31 +22,25 @@ def compile_ext(name, opts={})
ext_dir = File.join "lib/ext", names
if t = opts[:task]
- task_name = "build:#{t}"
+ ext_task_name = "build:#{t}"
+ names << t
else
- task_name = "build"
+ ext_task_name = "build"
end
- if dir = opts[:dir]
- target_dir = File.join ext_dir, dir
- else
- target_dir = ext_dir
- end
-
- target = "#{target_dir}/#{name}.#{$dlext}"
- file target do
- ext_helper = File.expand_path "../ext_helper.rb", __FILE__
- Dir.chdir ext_dir do
- ruby "-S rake #{'-t' if $verbose} -r #{ext_helper} #{task_name}"
- end
- end
-
- Rake::Task[:extensions].prerequisites << target
+ task_name = names.join "_"
namespace :extensions do
desc "Build #{name.capitalize} extension #{opts[:doc]}"
- task task_name => target
+ task task_name do
+ ext_helper = File.expand_path "../ext_helper.rb", __FILE__
+ Dir.chdir ext_dir do
+ ruby "-S rake #{'-t' if $verbose} -r #{ext_helper} #{ext_task_name}"
+ end
+ end
end
+
+ Rake::Task[:extensions].prerequisites << "extensions:#{task_name}"
end
compile_ext "bigdecimal"
@@ -58,5 +52,5 @@ compile_ext "digest:sha1"
compile_ext "digest:sha2"
compile_ext "digest:bubblebabble"
compile_ext "syck"
-compile_ext "melbourne", :task => "rbx", :dir => "rbx", :doc => "for Rubinius"
-compile_ext "melbourne", :task => "mri", :dir => "ruby", :doc => "for MRI"
+compile_ext "melbourne", :task => "rbx", :doc => "for Rubinius"
+compile_ext "melbourne", :task => "mri", :doc => "for MRI"
View
@@ -128,6 +128,9 @@ end
namespace :compiler do
melbourne = "lib/ext/melbourne/ruby/melbourne.#{$dlext}"
+
+ file melbourne => "extensions:melbourne_mri"
+
task :load => [compiler_signature, melbourne] + compiler_files do
require File.expand_path("../../lib/compiler", __FILE__)
require File.expand_path("../../kernel/delta/signature", __FILE__)

0 comments on commit 60f7d84

Please sign in to comment.