From: Charles Mills Date: 2004-07-30T23:50:23+09:00 Subject: Re: mkmf.rb On Jul 30, 2004, at 2:56 AM, nobu.nokada@softhome.net wrote: > Hi, > > At Sat, 24 Jul 2004 01:14:17 +0900, > Charles Mills wrote in [ruby-talk:107305]: >> Also I have been using this function to determine the byte order, >> perhaps it would be useful to somebody. > > Running compiled file can't work for cross compiling. > > > Index: lib/mkmf.rb > =================================================================== > RCS file: /cvs/ruby/src/ruby/lib/mkmf.rb,v > retrieving revision 1.194 > diff -u -2 -p -r1.194 mkmf.rb > --- lib/mkmf.rb 13 Jul 2004 06:51:26 -0000 1.194 > +++ lib/mkmf.rb 30 Jul 2004 09:51:23 -0000 > @@ -266,6 +266,10 @@ ensure > end > > -def try_compile(src, opt="", &b) > +def try_compile0(src, opt="", &b) > try_do(src, cc_command(opt), &b) > +end > + > +def try_compile(src, opt="", &b) > + try_do(src, opt, &b) > ensure > rm_f "conftest*" > @@ -623,4 +627,20 @@ def find_executable(bin, path = nil) > end > > +def byte_order > + try_compile0 %{ > +#include > +volatile short be[] = { 0, 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, > 0x7953, 0 }; > +volatile short le[] = { 0, 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, > 0x6E61, 0 }; > +} > + case open(CONFTEST_C.sub(/\.c$/, '.'+CONFIG['OBJEXT']), > 'rb'){|f|f.read} > + when /\0BIGenDianSyS\0/ > + :big > + when /\0LiTTleEnDian\0/ > + :little > + end > +ensure > + rm_f "conftest*" > +end > + > def arg_config(config, default=nil) > $configure_args.fetch(config, default) > Very nice - just trying to understand this, are you greping the object code? -Charlie > > -- > Nobu Nakada > >