1

I'm using scons to build a linux C based ruby extension. What is the "right" way to get the include paths right? By "right" I mean it works out of the box on 1.9 and 1.8.

I don't want to use the mkmf/Makefile solution.

Thanks! Dave

1 Answer 1

1

If you were using autoconf, you could borrow ruby.ac from rice:

http://github.com/jameskilton/rice/blob/master/ruby.ac

or since you are using a different build system, you can duplicate its behavior. To summarize what it does:

  1. We use the rbconfig module to get ruby config variables like this:
    $RUBY -rrbconfig -e "puts(Config::CONFIG['$1'] || '')" <variable>
    where $RUBY is the ruby interpreter (sometimes interpreters get installed with a different name, e.g. ruby1.8 or ruby1.9) and <variable> is the desired config variable
  2. We then set our build variables:
    
      if ${ruby_config_rubyhdrdir} is empty: (e.g. ruby 1.8)
        CPPFLAGS="-I${ruby_config_archdir}
      else:
        CPPFLAGS="-I${ruby_config_rubyhdrdir} ${ruby_config_rubyhdrdir}/${arch}
    
      CFLAGS="${ruby_config_CFLAGS} ${ruby_config_CCDLFLAGS}"
    
      LDFLAGS="-L${ruby_config_archdir} -L${ruby_config_libdir} ${ruby_config_LDFLAGS}"
    
      LIBS="${ruby_config_LIBS} ${ruby_config_DLDLIBS}"
    
    where the variables ${ruby_config_*} are determined using the config command above, e.g.:
    ruby_config_foo=$RUBY -rrbconfig -e "puts(Config::CONFIG['$1'] || '')" foo
  3. We also need to link with the ruby library, so we append ${ruby_config_LIBRUBYARG}.
  4. The above variables are for compiling and linking; you may also need to install. Ruby library files should be installed to ${ruby_config_sitelibdir}. Ruby extensions should be installed to ${ruby_config_sitearchdir}.
  5. There's also some magic in ruby.ac for building with mingw and linking against the one-click installer on windows (which used to be built with vc6; I'm not sure if it still is or not).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.