Permalink
Browse files

Build readline as part of `rake build`. Cleaned up lib/bin/compile.rb.

  • Loading branch information...
rue committed Oct 14, 2008
1 parent 4060b56 commit 3610ac35d05da644d984744710d976b9d11712a1
Showing with 90 additions and 48 deletions.
  1. +50 −30 lib/bin/compile.rb
  2. +40 −18 rakelib/extensions.rake
View
@@ -2,42 +2,52 @@
class ExtensionCompiler
- def initialize(extra = [], flags = [], rest = [])
+ def initialize(flags = [], extra = [])
+ @files = []
@includes = []
@link_flags = []
- @compile_flags = ["-ggdb3 -O0"]
-
- extra.each do |e|
- if e.prefix?("-I")
- @includes << e
- elsif e.prefix?("-C,")
- @compile_flags << e[3..-1]
- else
- @link_flags << e
- end
- end
+ @compile_flags = []
@output_name = nil
- @preserve_objects = false
+ @preserve_objects = true if $DEBUG
- @files = []
- @flags = flags
- flags.each do |i|
- if m = /output=(.*)/.match(i)
- @output_name = m[1]
- end
+ flags << "-h" unless extra.empty?
+
+ flags.each do |flag|
+ case flag
+ when /^-I/
+ @includes << flag
- if i == "-p"
+ when /^-C,/
+ @compile_flags << flag[3..-1]
+
+ when /^-Wl,/
+ @link_flags << flag[4..-1]
+
+ when /output=(.*?)/
+ @output_name = $1
+
+ when /^-p$/
@preserve_objects = true
- end
- end
- if $DEBUG
- @preserve_objects = true
- end
+ when /^-d$/
+ $VERBOSE = 2
+
+ when /^-h$/
+ puts "Options:\n\n" \
+ " -I<includedir> # E.g. -I/usr/local/include\n" \
+ " -C,<compiler flag> # E.g. -C,-ggdb3\n" \
+ " -Wl,<linker flag> # E.g. -Wl,-zelda\n" \
+ " -p # Preserve objects\n" \
+ " -d # Verbose output\n" \
+ " output=<filename> # E.g. output=moo.so"
- if File.exists?("vm/subtend/ruby.h")
- @includes << "-I#{Dir.pwd}/vm/subtend"
+ exit 1
+
+ else
+ flags << "-h"
+
+ end
end
end
@@ -240,24 +250,34 @@ def extension
file = ARGV.shift
if File.directory?(file)
+
rec = File.join(file, "build.rb")
+
unless File.exists?(rec)
puts "No build instructions found in #{file}"
exit 1
end
+
puts "Building from instructions at #{rec}" if $VERBOSE
- ext = ExtensionCompiler.new(ext_flags, flags, ARGV)
+
+ ext = ExtensionCompiler.new(flags, ARGV)
+
dsl = ExtensionCompiler::DSL.new(ext)
dsl.setup
+
cur = Dir.pwd
Dir.chdir file
load "build.rb"
+
ext.compile
+
elsif file.suffix?(".c")
- puts "Compiling extension #{file}..."
- ext = ExtensionCompiler.new(ext_flags, flags, ARGV)
+ puts "Compiling extension #{file}..." if $VERBOSE
+
+ ext = ExtensionCompiler.new(flags, ARGV)
ext.add_file file
ext.compile
+
else
if File.exists?(file)
View
@@ -5,27 +5,59 @@ task :extensions => %w[
vm/vm
kernel:build
- lib/etc.rb
- lib/fcntl.rb
- lib/openssl/digest.rb
- lib/syslog.rb
- lib/zlib.rb
+ extension:readline
]
+
+# lib/etc.rb
+# lib/fcntl.rb
+# lib/openssl/digest.rb
+# lib/syslog.rb
+# lib/zlib.rb
+
# extension:digest_rmd160
# extension:digest_md5
# extension:digest_sha1
# extension:digest_sha2
+
#
-# extension:readline
+# Ask the VM to build an extension from source.
+#
+def compile_extension(path, flags = "-d -p -C,-ggdb3 -C,-O0 -I#{Dir.pwd}/vm/subtend")
+ command = "./bin/rbx compile #{flags} #{path}"
+
+ puts "Executing `#{command}`" if $verbose
+
+ sh command
+end
namespace :extension do
- desc "Cleans all compiled extension files (lib/ext)"
+
+ desc "Cleans all C extension libraries and build products."
task :clean do
- Dir["lib/ext/**/*#{$dlext}"].each do |f|
+ Dir["lib/ext/**/*.{o,#{$dlext}}"].each do |f|
rm_f f, :verbose => $verbose
end
+
+# FileList["lib/ext/**/*.o"].each {|f| rm f, :verbose => $verbose }
end
+ desc "Build the readline extension"
+ task :readline => "lib/ext/readline/readline.#{$dlext}"
+
+ file "lib/ext/readline/readline.#{$dlext}" => FileList[
+ "lib/ext/readline/readline.c",
+ "lib/ext/readline/build.rb",
+ "vm/vm"
+ ] do
+ FileList["lib/ext/readline/readline.{o,#{$dlext}}"].each do |f|
+ rm f, :verbose => $verbose
+ end
+
+ compile_extension 'lib/ext/readline'
+ end
+
+ # The ones below are not used currently.
+
FFI::Generator::Task.new %w[
lib/etc.rb
lib/fcntl.rb
@@ -92,15 +124,5 @@ namespace :extension do
] do
compile_ruby "lib/ext/mongrel"
end
-
- task :readline => %W[lib/ext/readline/readline.#{$dlext} lib/readline.rb]
-
- file "lib/ext/readline/readline.#{$dlext}" => FileList[
- 'shotgun/lib/subtend/*',
- 'lib/ext/readline/build.rb',
- 'lib/ext/readline/*.c'
- ] do
- compile_ruby "lib/ext/readline"
- end
end

0 comments on commit 3610ac3

Please sign in to comment.