Compiling MySQL-Ruby for PowerPC

Mind boggling as it is, I could not find any instructions for how to compile mysql-ruby that actually worked. I’m no C geek, but with a little here, a little there, and applying 25 years of engineering in various fields and disciplines... I guessed, and managed to hack out some fixes that seem to be working.

It turns out the problem, as it appears to my untrained eye, is that the mysql-ruby libraries assume the use of an intel-based Mac. I am using a G5 (woe is me). So, these instruction are aimed specifically at users of G5, and presumably any PowerPC, Mac OS X machines.

IMO, it turned out easier to deal with this by not using Gems, so we’ll work with the “raw” downloads.

At the time of this writing, I am using:

  • OS X 10.4.10 on a PowerMac G5
  • Ruby 1.8.6
  • MySQL 5.0.27
  • mysql-ruby 2.7.4

All the links for the downloads are at the end of the article.

By now, you’ve looked ath the length of this article and thought, “ah, geez here we go again.” I promise it is not as bad as it looks. Rather, I’ve been overly detailed by some standards to provide comforts along every step that should help all but great-grandmothers feel well-guided during this process.

I’ll assume you have downloaded the mysql-ruby (not ruby-mysql, there’s a difference!) files. The README in there gets you started off well enough, but like all open source it seems to me, it assumes you know a lot about the innards of the *nix OS and building C programs. I know a little about the former, and very little about the latter. So, when it starts saying you can do this, or that, or the other, I start to get a headache. Especially when none of those options ends up working.

The Play by Play

Open a window for the mysql-ruby folder, open a window for Terminal, and get your text editor handy.

In Terminal, change the directory to the one of the mysql-ruby window. I like to do this by typing cd, a space, then using drag-and-drop to dump the icon from the mysql-ruby window title bar into Terminal.

cd ~/Desktop/mysql-ruby-2.7.4

Now type this out:

ruby extconf.rb --with-mysql-config

You should see in Terminal a response like this:

checking for mysql_ssl_set()... no
checking for mysql.h... yes
creating Makefile

If instead you see a bunch of lines go by that all have at the end, then you need to be more explicit about where your mysql_config file is. For example, in my system, I can use this with success. You will need to find where the equivalent of your file is, probably changing the MySQL version string in the path name.

ruby extconf.rb --with-mysql-config=/usr/local/mysql-standard-5.0.27-osx10.4-powerpc/bin/mysql_config

OK, so at this point you need to be seeing a “checking for mysql.h... yes” in Terminal. If so, we can move on--to where all the voodoo happens.

In the mysql-ruby window, you should now see 3 news files: mkmf.log, mysql.c, and Makefile.

Open mysql.c, and at the top of the file, under the three lines that start with *s,and above the first line that starts with the # add this line (adding extra empty lines is fine):

#define ulong unsigned long

Save the file and close it.

Now open Makefile. There’s going to be two places between about lines 35 and 45 where you’ll find -arch i386. Change those two places to read -arch ppc.

Next, a few lines down, you’ll see these two lines:

arch = universal-darwin8.0sitearch = universal-darwin8.0

Change those two lines, so they read like this:

arch = powerpc-darwin8.0sitearch = powerpc-darwin8.0

Save the file and close it.

Now, if you get to looking around, you’ll see other lines with “universal-darwin” -- leave those alone! Those ones are talking about what version of Ruby you have, and they’re fine as is.

Now we’re ready for next step in Terminal. Enter this:

sudo make

You should see something like this in response (although I’ve lost the actual line breaks due to a blog bug):

gcc -I. -I. -I/usr/local/lib/ruby/1.8/universal-darwin8.0 -I. -DHAVE_MYSQL_H  -I/usr/local/mysql/include -Os -arch ppc -fno-common -fno-common -g -O2  -fno-common -pipe -fno-common  -arch ppc -c mysql.ccc -dynamic -bundle -undefined suppress -flat_namespace -arch ppc -L"/usr/local/lib" -o mysql.bundle mysql.o  -lruby -L/usr/local/mysql/lib -lmysqlclient -lz -lm  -lpthread -ldl -lobjc

/usr/bin/ld: warning multiple definitions of symbol _setregid

/usr/local/lib/libruby.dylib(process.o) definition of _setregid

/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../libm.dylib(setregid.So) definition of _setregid/usr/bin/ld: warning multiple definitions of symbol _setreuid

/usr/local/lib/libruby.dylib(process.o) definition of _setreuid/usr/lib/gcc/powerpc-apple-darwin8/4.0.1/../../../libm.dylib(setreuid.So) definition of _setreuid

I don’t know what those warnings are, but in the end, this process worked for me, so I did what every newbie does, I ignored it.

Now, enter this in Terminal:

sudo make install

and you should see something like this in response. Yours could have different paths, that’s OK.

/usr/bin/install -c -m 0755 mysql.bundle /usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.0

Testing if it Worked

This is a break point where we can test whether the mysql adaptor is working. Start a new Ruby script file. And, see that path from the install above after mysql.bundle wher eit starts with /usr/local...? You’ll need that path in your script file.

#! /usr/local/bin/ruby
$: << '/usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.0'
require 'mysql'puts 'Hello'

Your path may be different. If you run the above script, it will be good news if nothing happens. If all you see is Hello, and there’s no error messages, then you can start to smile, you’re almost done.

Finishing Touches

There’s one more thing to do. See in that scripts where we had to add a path to the $: array? That tells Ruby where to find the mysql bundle you just created. Well that’s annoying to have to do all the time, so we want Ruby to figure this out on its own.

We’re done with the mysql-ruby window, so click in that and type command-shift-G. In the sheet that opens up, enter the path /etc/ and click Go.

Inside the /etc/ folder is a file named profile (no extension). Open that file. This file can look quite different for each user, but you should see a line that starts with PATH= and probably one just below it that is export PATH. Add a couple empty lines after that one and enter this line:

export RUBYLIB=$RUBYLIB:/usr/local/lib/ruby/site_ruby/1.8/powerpc-darwin8.0

You should recognize that path. As always, yours might be a little different, but it should be the same one you’ve been using.

Save the file and close it.

Go back the Ruby script we used above, and comment out the second line (or remove it altogether) where we did $: << to add a path.

Run the Ruby script. If there’s no error messages, you’re home free, and all set to rock your Ruby scripts with some MySQL goodness.

Nothing left to see folks

Now, I ask you, was that the longest blog post you’ve ever seen for building mysql-ruby? But, did it actually get you through it step-by-step? I sure hope its working for you, because I attempted to document my every move on the way to getting mine working (minus all the failed trial and error attempts).

Thanks to Max Dunn for the one-liner fix to the mysql.c file. And of course thanks to Tomita Masahiro for writing the mysql-ruby library to start with.


mysql-ruby libraries

MySQL database

Ruby One-Click Installer for OS X