Web Development & Programming Thoughts

By Timothy Elliott

Ruby Build Script Adventures

3/4/2009

I took a safari through the build scripts used to compile Ruby 1.8.7. Here are some ruby build script nuggets that I gathered:

Some files, semi-explained

File Description Origin
configure This file is generated from the configure.in file in source control. Ruby releases (tgz downloads) have it pre-generated. The configure script explores your system for available libraries, architecture, and other helpful info for compiling. Generated by configure.in
miniruby A small ruby implementation whose main purpose is to execute native ruby build scripts, such as mkconfig.rb. Ruby builds this as a tool to compile the full ruby distro.
mkconfig.rb A ruby script that parses config.status, explores directories and other settings, and generates rbconfig.rb
config.status Bash script that is generated by the configure script generated by the configure script
rbconfig.rb A generated ruby script that is basically a hash of all build settings. generated by mkconfig.rb, which parses config.status

What happens when you build ruby

Here is an overview of what happens when you compile Ruby, at a really, really, high level.

configure =[generates]=> Makefile =[builds]=> miniruby =[executes]=> mkconfig.rb =[generates]=> rbconfig.rb

Sample hackery

The Ruby 1.8.7 build process in Mingw was stripping debug symbols from external libraries. It turns out that configure has the following line:

cygwin*|mingw*)	: ${LDSHARED="${CC} -shared "'$(if $(filter-out -g -g0,$(debugflags)),,-s)'}

The "-s" flag is the culprit which is stripping out the debug symbols. The conditional that checks if "debugflags" is set to something other than -g or -g0 works fine in the main Ruby Makefile.

However, a separate Makefile is generated for each extension, and these generated Makefiles do not have "debugflags" set to anything. As a result, the ruby make process will strip out debug symbols for extensions no matter what debug flags are set.

The quick fix for this is to edit the line in the configure script:

cygwin*|mingw*)	: ${LDSHARED="${CC} -shared"}