Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 130 lines (107 sloc) 3.974 kB
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
1 # Tasks for building C extensions used mainly by Rubinius, but also by MRI in
2 # the case of the Melbourne parser extension. The task names are defined to
3 # permit running the tasks directly, eg
93747eb @drbrain Bring in extensions and platform stuff from shotgun
drbrain authored
4 #
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
5 # rake compile:melbourne_rbx
3610ac3 @rue Build readline as part of `rake build`. Cleaned up lib/bin/compile.rb.
rue authored
6 #
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
7 # See rakelib/ext_helper.rb for the helper methods and Rake rules.
3610ac3 @rue Build readline as part of `rake build`. Cleaned up lib/bin/compile.rb.
rue authored
8
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
9 desc "Build extensions from lib/ext"
10 task :extensions
3610ac3 @rue Build readline as part of `rake build`. Cleaned up lib/bin/compile.rb.
rue authored
11
f68acf7 @brixen Ensure that bootstrap Melbourne is built for bootstrap ruby.
brixen authored
12 def clean_extension(name)
13 rm_f FileList["lib/ext/#{name}/*.{o,#{$dlext}}"], :verbose => $verbose
14 end
15
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
16 namespace :extensions do
17 desc "Clean all lib/ext files"
93747eb @drbrain Bring in extensions and platform stuff from shotgun
drbrain authored
18 task :clean do
f68acf7 @brixen Ensure that bootstrap Melbourne is built for bootstrap ruby.
brixen authored
19 clean_extension("**")
e484ef7 @brixen Force reconfigure for C exts when cleaning.
brixen authored
20 # TODO: implement per extension cleaning. This hack is for
21 # openssl and dl, which use extconf.rb and create Makefile.
22 rm_f FileList["lib/ext/**/Makefile"], :verbose => $verbose
e99f097 @brixen Re-enable building DL extension.
brixen authored
23 rm_f FileList["lib/ext/dl/*.func"], :verbose => $verbose
0eb8c0f @brixen Added bigdecimal extension.
brixen authored
24 end
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
25 end
0eb8c0f @brixen Added bigdecimal extension.
brixen authored
26
b66a3b8 @brixen Added ignore flag for building extconf-style C exts.
brixen authored
27 def rbx_build
28 # rbx-build can run even if prefix is used
65305fa @tenderlove fixing unused variable warnings
tenderlove authored
29 File.expand_path "../bin/rbx-build", File.dirname(__FILE__)
b66a3b8 @brixen Added ignore flag for building extconf-style C exts.
brixen authored
30 end
31
f5a5246 @brixen Fixed building C exts that use extconf.rb.
brixen authored
32 def build_extconf(name, opts)
33 if opts[:ignore_fail]
b66a3b8 @brixen Added ignore flag for building extconf-style C exts.
brixen authored
34 fail_block = lambda { |ok, status| }
35 else
36 fail_block = nil
37 end
38
f5a5246 @brixen Fixed building C exts that use extconf.rb.
brixen authored
39 redirect = $verbose || !opts[:ignore_fail] ? "" : "> /dev/null 2>&1"
b66a3b8 @brixen Added ignore flag for building extconf-style C exts.
brixen authored
40
41 puts "Building #{name}"
42
43 ENV["BUILD_RUBY"] = BUILD_CONFIG[:build_ruby]
44
45 unless File.directory? BUILD_CONFIG[:runtime]
46 ENV["CFLAGS"] = "-Ivm/capi/include"
47 end
48
f5a5246 @brixen Fixed building C exts that use extconf.rb.
brixen authored
49 unless opts[:deps] and opts[:deps].all? { |n| File.exists? n }
50 # unless File.exists?("Makefile") and File.exists?("extconf.h")
b66a3b8 @brixen Added ignore flag for building extconf-style C exts.
brixen authored
51 sh("#{rbx_build} extconf.rb #{redirect}", &fail_block)
52 end
53
54 sh("make #{redirect}", &fail_block)
55 end
56
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
57 def compile_ext(name, opts={})
58 names = name.split ":"
59 name = names.last
73fb486 Introduce tooling API, convert profiler to it.
Evan Phoenix authored
60 ext_dir = opts[:dir] || File.join("lib/ext", names)
3610ac3 @rue Build readline as part of `rake build`. Cleaned up lib/bin/compile.rb.
rue authored
61
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
62 if t = opts[:task]
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
63 ext_task_name = "build:#{t}"
64 names << t
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
65 else
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
66 ext_task_name = "build"
3610ac3 @rue Build readline as part of `rake build`. Cleaned up lib/bin/compile.rb.
rue authored
67 end
68
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
69 task_name = names.join "_"
02c813d @brixen Put melbourne ext for rbx in a subdir.
brixen authored
70
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
71 namespace :extensions do
72 desc "Build #{name.capitalize} extension #{opts[:doc]}"
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
73 task task_name do
74 ext_helper = File.expand_path "../ext_helper.rb", __FILE__
24f0e34 @brixen Use DependencyGrapher in C exts.
brixen authored
75 dep_grapher = File.expand_path "../dependency_grapher.rb", __FILE__
7b1cb48 @brixen Configure checks for readline, curses.
brixen authored
76 build_config = File.expand_path "../../config.rb", __FILE__
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
77 Dir.chdir ext_dir do
fe79104 Begin pulling in the OpenSSL CAPI extension
Evan Phoenix authored
78 if File.exists? "Rakefile"
7b1cb48 @brixen Configure checks for readline, curses.
brixen authored
79 sh "#{BUILD_CONFIG[:build_ruby]} -S #{BUILD_CONFIG[:build_rake]} #{'-t' if $verbose} -r #{build_config} -r #{ext_helper} -r #{dep_grapher} #{ext_task_name}"
fe79104 Begin pulling in the OpenSSL CAPI extension
Evan Phoenix authored
80 else
f5a5246 @brixen Fixed building C exts that use extconf.rb.
brixen authored
81 build_extconf name, opts
fe79104 Begin pulling in the OpenSSL CAPI extension
Evan Phoenix authored
82 end
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
83 end
84 end
ad861fe @brixen Added Melbourne parser extension.
brixen authored
85 end
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
86
87 Rake::Task[:extensions].prerequisites << "extensions:#{task_name}"
cc28068 Rearranged rake setup a lot, making browsing more intuitive (build se…
Ryan Davis authored
88 end
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
89
f68acf7 @brixen Ensure that bootstrap Melbourne is built for bootstrap ruby.
brixen authored
90 # TODO: we must completely rebuild the bootstrap version of Melbourne if the
91 # configured build ruby changes. We add the version to be extra sure.
92 build_ruby = "lib/ext/melbourne/.build_ruby"
93 build_version = "#{BUILD_CONFIG[:build_ruby]}:#{RUBY_VERSION}"
94
95 if File.exists?(build_ruby)
96 File.open(build_ruby, "rb") do |f|
97 clean_extension("melbourne/**") if f.read.chomp != build_version
98 end
99 else
100 clean_extension("melbourne/**")
101 end
102
103 File.open(build_ruby, "wb") do |f|
104 f.puts build_version
105 end
106
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
107 compile_ext "bigdecimal"
d3d550e @brixen Build Readline C ext if default or requested.
brixen authored
108 compile_ext "readline" if BUILD_CONFIG[:defines].include? "HAS_READLINE"
9ed0630 @brixen Reworked compiling C extensions.
brixen authored
109 compile_ext "digest"
110 compile_ext "digest:md5"
111 compile_ext "digest:rmd160"
112 compile_ext "digest:sha1"
113 compile_ext "digest:sha2"
114 compile_ext "digest:bubblebabble"
115 compile_ext "syck"
60f7d84 @brixen Fixed toplevel C ext tasks to always delegate to the ext Rakefile.
brixen authored
116 compile_ext "melbourne", :task => "rbx", :doc => "for Rubinius"
bb535a4 @brixen Enable building with MRI or Rubinius 1.2.
brixen authored
117 compile_ext "melbourne", :task => "build", :doc => "for bootstrapping"
35a1b4e @brixen Added NKF ext from MRI 1.8.7. Closes #304.
brixen authored
118 compile_ext "nkf"
07e6ac4 @brixen Moved C-API .h files to include directory.
brixen authored
119
120 # rbx must be able to run to build these because they use
121 # extconf.rb, so they must be after melbourne for Rubinius.
f5a5246 @brixen Fixed building C exts that use extconf.rb.
brixen authored
122 compile_ext "openssl", :deps => ["Makefile", "extconf.h"]
123 compile_ext "dl", :deps => ["Makefile", "dlconfig.h"]
124 compile_ext "dbm", :ignore_fail => true, :deps => ["Makefile"]
125 compile_ext "gdbm", :ignore_fail => true, :deps => ["Makefile"]
126 compile_ext "sdbm", :deps => ["Makefile"]
73fb486 Introduce tooling API, convert profiler to it.
Evan Phoenix authored
127
bb535a4 @brixen Enable building with MRI or Rubinius 1.2.
brixen authored
128 compile_ext "profiler", :dir => "lib/tooling/profiler",
73fb486 Introduce tooling API, convert profiler to it.
Evan Phoenix authored
129 :deps => ["Makefile"]
Something went wrong with that request. Please try again.