Tim Hunter
4/1/2007 10:35:00 PM
I'm in the process of replacing RMagick's configure/make/make install
process with a pure-Ruby solution using just setup.rb or RubyGems and
extconf.rb. I've been able to successfully replace configure.ac with
extconf.rb except for two things. First, mkmf.rb does not have a method
that tests for the presence of a specific value in an enum. Second,
mkmf.rb wants to put all its feature symbols (-DHAVE_SOMETHING) on the
gcc command line but RMagick may have upwards of 100 such symbols and
I'm afraid that that many will exceed some system's limit on the maximum
length of a command's arguments. I'd rather put these symbols in a
config.h file.
So i've added two methods to my extconf.rb. (I've added them below). Any
comments on the risks I'm introducing to my extconf.rb and how I might
mitigate them? I've tested my extconf.rb with Ruby 1.8.2, 1.8.3, 1.8.4,
1.8.5, and 1.8.6. What about going forward? I would like to minimize the
chances of my having to fix my extconf.rb when Ruby 1.8.7 comes out.
(I learned that my extconf.rb is not compatible with Ruby 1.8.0 or
1.8.1, notably because have_library has a different signature in those
releases. That's not a problem for me.)
# Test for a specific value in an enum type
def have_enum_value(enum, value, headers=nil, &b)
checking_for "#{enum}.#{value}" do
if try_compile(<<"SRC", &b)
#{COMMON_HEADERS}
#{cpp_include(headers)}
/*top*/
int main(){ #{enum} x = #{value}; x = x; return 0; }
SRC
$defs.push(format("-DHAVE_%s", value.upcase))
true
else
false
end
end
end
# Create a config.h file from the $defs array.
def create_config_file(file)
message "creating #{file}\n"
File.open(file, "w") do |f|
while (sym = $defs.shift)
define = sym.sub(/\A-D/, '#define ')
if define['=']
define['='] = ' ' # symbols with values
else
define << ' 1' # symbols without values
end
f.puts define
end
end
end