From: Daniel Berger Date: 2007-04-02T11:45:04+09:00 Subject: Re: Hacking mkmf.rb On Apr 1, 4:34 pm, Timothy Hunter wrote: > 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. I requested have_enum_member two years ago: http://rubyforge.org/tracker/index.php?func=detail&aid=1486&group_id=426&atid=1700. That eventually turned into have_const: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/4430. Note that "checking_for type" should be "checking_for const". I think it just got lost in the shuffle. I'll bring it up again on ruby-core. > 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 create_config_file looks reasonable to me. Regards, Dan