mkmf.rb

Discussion in 'Ruby' started by Charles Mills, Jul 23, 2004.

  1. 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
     
    Charles Mills, Jul 23, 2004
    #1
    1. Advertising

  2. Charles Mills

    Guest

    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
     
    , Jul 30, 2004
    #2
    1. Advertising

  3. On Jul 30, 2004, at 2:56 AM, 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 <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

    >
    > --
    > Nobu Nakada
    >
    >
     
    Charles Mills, Jul 30, 2004
    #3
  4. Charles Mills

    Guest

    Hi,

    At Fri, 30 Jul 2004 23:50:23 +0900,
    Charles Mills wrote:
    > > +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.

    --
    Nobu Nakada
     
    , Jul 31, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    199
  2. Kero van Gelder

    mkmf documentation?

    Kero van Gelder, Aug 2, 2003, in forum: Ruby
    Replies:
    2
    Views:
    112
    Kero van Gelder
    Aug 3, 2003
  3. Kero
    Replies:
    0
    Views:
    146
  4. Brad Hilton

    mkmf.rb broken in cvs?

    Brad Hilton, Mar 2, 2004, in forum: Ruby
    Replies:
    0
    Views:
    112
    Brad Hilton
    Mar 2, 2004
  5. Replies:
    0
    Views:
    140
Loading...

Share This Page