-
Notifications
You must be signed in to change notification settings - Fork 5
Building FXRuby as a Universal Gem for Mac OS X
This is a page that describes how I build the “universal” binary gem for FXRuby on Mac OS X (Snow Leopard). It’s a little tricker, in terms of compiler and linker flags, than a plain jane installation, and so this is mainly of interest to packagers.
FXRuby is based on the FOX toolkit, and so we’re going to need to build FOX. But before we can do that, we need to download, build and install some libraries that FOX depends on for image file manipulation.
Lucky for us, Snow Leopard includes libpng (in the /usr/X11/lib directory) and so we don’t need to worry about building that.
You can download the latest source code tarball for libjpeg from the Independent JPEG Group. As of this writing, the latest version is version 7.
tar xzf jpegsrc.v7.tar.gz
cd jpeg-7
CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" ./configure --disable-dependency-tracking --disable-shared
make
sudo make installThe complicated settings for CFLAGS and LDFLAGS (which you’ll come to recognize), as well as the --disable-dependency-tracking switch for the configure script, ensure that we can simultaneously build both 32-bit and 64-bit versions. For more information, see this article at the Apple Developer Connection site.
The --disable-shared switch tells it to build only static libraries (.a) and not dynamic libraries (.dylib). This will later allow us to build an FXRuby gem that is “self-contained” (i.e. includes everything that it needs to run, including the JPEG and TIFF libraries as well as FOX and FXScintilla).
You can download the latest source code tarball for libtiff from the LibTIFF home page. As of this writing, the latest version is version 3.8.2.
tar xzf tiff-3.8.2.tar.gz
cd tiff-3.8.2
CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" ./configure --disable-dependency-tracking --disable-shared
make
sudo make installYou can download the latest source code tarball for FOX from the FOX home page. As of this writing, the latest stable version is version 1.6.36. Note that the latest developer version is 1.7.20 (or so), but that version is incompatible with FXRuby.
tar xzf fox-1.6.36.tar.gz
cd fox-1.6.36
env CFLAGS="-I/usr/X11/include -I/usr/X11/include/freetype2 -DHAVE_XFT_H=1" CXXFLAGS="-arch i386 -arch x86_64 -I/usr/X11/include -I/usr/X11/include/freetype2 -DHAVE_XFT_H=1" LDFLAGS="-arch i386 -arch x86_64 -L/usr/X11/lib -lXft -lfontconfig -lfreetype" ./configure --with-x --with-opengl --enable-cups --disable-dependency-tracking --enable-release
make
sudo make installYou may have noticed that we don’t pass the --disable-shared switch to the configure script. If you configure the build with the --disable-shared switch, you’ll get errors at link time like this:
Undefined symbols for architecture i386:
"_MPDeleteSemaphore", referenced from:
FX::FXSemaphore::~FXSemaphore()in libFOX-1.6.a(FXThread.o)
FX::FXSemaphore::~FXSemaphore()in libFOX-1.6.a(FXThread.o)
"_MPWaitOnSemaphore", referenced from:
FX::FXSemaphore::trywait() in libFOX-1.6.a(FXThread.o)
FX::FXSemaphore::wait() in libFOX-1.6.a(FXThread.o)
"_MPCreateSemaphore", referenced from:
FX::FXSemaphore::FXSemaphore(int)in libFOX-1.6.a(FXThread.o)
FX::FXSemaphore::FXSemaphore(int)in libFOX-1.6.a(FXThread.o)
"_MPSignalSemaphore", referenced from:
FX::FXSemaphore::post() in libFOX-1.6.a(FXThread.o)
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit statusTo work around this, what I do is just build FOX as a shared library (without the --disable-shared switch), install it, and then go back and remove the *.dylib files from the /usr/local/lib directory later (before building FXRuby). I’ll call that step out later in this write-up.
Another point of interest is that due to the way FOX’s configure script deals with the optional Xft support (for anti-aliased fonts), we can’t use the --with-xft switch for configure but instead must pass the required compiler and linker flags in through the CFLAGS, CXXFLAGS and LDFLAGS variables.
The latest version of FXScintilla (as of this writing) is version 2.1.0, but I had trouble compiling it from source, so I’ve dropped back to version 1.71 for now. Download the source code from the FXScintilla web site and then build and install it from source.
tar xzf fxscintilla-1.71.tar.gz
cd fxscintilla-1.71
env CXXFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" FOX_CFLAGS="-DFOX_1_6=1 -I/usr/local/include/fox-1.6" FOX_LIBS="-L/usr/local/lib" ./configure --disable-dependency-tracking --disable-shared
make
sudo make installAs mentioned previously, trying to build FOX only as a static library fails (for me) and so at this point in the process I go back and move those *.dylib files out of the way so that my FXRuby build doesn’t link against them.
sudo rm -f /usr/local/libFOX*.dylibAt this point you should be good to go. You can check out the code, build it using the rake compile task, and then build the gem with the rake native gem task.