Mkmf.rb

Just wondering if there is a system as to which global variables are Arrays and which are Strings.
For example $objs and $defs are Arrays and $LOCAL_LIBS, $libs and $LIBS are all Strings.
I end up redefining $LOCAL_LIBS as an Array so I can do things like:
def local_lib_rules()
   str = "\n"
   $LOCAL_LIBS.each do |lib|
     dir = File.dirname(lib)
     str << lib << ":\n"
     str << "\tcd #{dir} && $(MAKE)\n"
   end
   str << "\n"
end
# ....
# but then have to
$LOCAL_LIBS = $LOCAL_LIBS.join(' ')
# later in my code.

Also I have been using this function to determine the byte order, perhaps it would be useful to somebody.
def check_byte_order(headers = nil, opt = "", &b)
   message "checking byte order... "
   src = %{#{COMMON_HEADERS}
#{headers}
#include <stdio.h>
/*top*/
int
main(void)
{
   long a = 1;
   if (*(char*)&a == 1)
     printf("1234\\n");
   else
     printf("4321\\n");
   return 0;
}
   order = nil
   if try_link0(src, opt, &b)
     xpopen("./conftest") do |f|
       order = f.gets
     end
     message "#{order}"
   else
     message "error\n"
     exit 1
   end
   order
end

-Charlie

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 <stdio.h>
+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)

--
Nobu Nakada

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 <stdio.h>
+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

···

On Jul 30, 2004, at 2:56 AM, nobu.nokada@softhome.net wrote:

--
Nobu Nakada

Hi,

> +def try_compile(src, opt="", &b)
> + try_do(src, opt, &b)

This must be try_compile0.

Very nice - just trying to understand this, are you greping the object
code?

Yes.

···

At Fri, 30 Jul 2004 23:50:23 +0900, Charles Mills wrote:

--
Nobu Nakada