The problem
Lately, I’ve been revising mi workflow for ActionScript project.
One of the first options was using MTASC and Swfmill (along with a nice build system using rake in Ruby, but that’s a different story…)
The first compiling tests were pretty exciting, but then I got a little surprise:
My PowerBook 12″ 1.3Ghz compiles 50% faster than an iMac Dual Core 2Ghz!
I checked version numbers for MTASC and Swfmill in both systems. I found out that I was using an old MTASC version on the PowerBook.
When I updated it, the PowerBook was even faster…
Next check was checking if the latest MTASC version was optimized for Intel processors:
AleMac:~ ale$ file bin/mtasc
bin/mtasc: Mach-O executable ppc
Darn…
What about Swfmill?
AleMac:~ ale$ file bin/swfmill
bin/swfmill: Mach-O executable ppc
Cool…
The answer
Due to my freakiness, the first thing I thought about was recompiling MTASC and Swfmill (god bless Open Source :) for Intel Mac.
If you also thought it would be a breeze, you are wrong. Here’s the chronicle of how I compiled MTASC and Swfmill in Tiger for Intel and lived to tell the story…
Requirements
Installing DarwinPorts`+ dependencies
Install DarwinPorts, fix the PATH, and get ready for the journey…
First thing to do is to update DarwinPorts’ packages
sudo port -d selfupdate
Password:
DEBUG: Rebuilding the darwinports base system if needed.
Synchronizing from rsync://rsync.darwinports.org/dpupdate/dports
receiving file list ... done
Here’s what you’ll need to compile MTASC and Swfmill:
- zLib
- pkgconfig
- libxml2
- libxslt
- freetype
- libpng
- gdbm
Let’s roll!
sudo port install zlib
sudo port install pkgconfig
sudo port install libxml2
sudo port install libxslt
sudo port install freetype
sudo port install libpng
sudo port install gdbm
This will take about 10 minutes (iMac Dual Core 2.0Ghz, 1Gb RAM)
We’ll also need OCaml and findlib.
OCaml is available in DarwinPorts, but findlib is not, so we’ll compile both using GODI
Installing OCaml and findlib with GODI
Download the source code for GODI and uncompress it wherever you like. I’m putting it on ~/src (that is, a folder called ’src’ in my home folder)
In order to compile GODI, we have to configure a couple things…
cd /Users/ale/src/godi-bootstrap-20060405/
./bootstrap --prefix $HOME/src/godi
Then we start compiling… Binaries will be place in ~/src/godi/bin and ~/src/godi/sbin, so you’ll have to add those folders to your PATH (if you don’t know how to do it, you may not be reading this, actually :)
Now the fun begins:
cd /Users/ale/src/godi-bootstrap-20060405/
./bootstrap_stage2
After a little while (6 minutes here…) we’ll have an Intel Mac native OCaml compiler, and GODI will be ready to install packages… Run ‘godi_console’ and install the folowing:
- godi-findlib
- conf-tcltk
- conf-gdbm
- godi-ocaml-dbm
- godi-ocaml-all
Once you install them, you’re ready to compile MTASC (yes, this is only the begining…)
Compiling MTASC
Compared to what we’ve done by now, compiling MTASC is a child’s game…
Download the installation script for MTASC here: http://www.mtasc.org/doc/mtasc/install.ml
I’ve saved it in ~/src/mtasc
cd /Users/ale/src
mkdir mtasc
cd mtasc
curl http://tech.motion-twin.com/doc/mtasc/install.ml -o install.ml
You’ll have to patch ‘install.ml’ so it compiles in OSX. Just look for this line
let zlib = match Sys.os_type with "Win32" -> "zlib.lib" | _ -> "-lz"
and replace it by this:
let zlib = "/opt/local/lib/libz.a"
(that’s where DarwinPorts installs zLib by default…)
Now we compile MTASC:
ocaml install.ml
Hopefully, when lines stop flying up your screen, you’ll have to binaries in ‘mtasc/bin’: ‘mtasc’ and ‘mtasc-byte’
Time for testing…
AleMac:~/src/mtasc/bin ale$ file mtasc
mtasc: Mach-O executable i386
AleMac:~/src/mtasc/bin ale$ file mtasc-byte
mtasc-byte: Mach-O executable i386
Woohoo! :D
Let’s try with Swfmill
Compiling Swfmill
Uncompress the Swfmill sources in ~/src
tar xvzf swfmill-0.2.11.tar.gz
I couldn’t make it work without some tweaking: do a folder-wide search for ‘-static’ and replace it with ” (it should work by using –disable-static when configuring, but somehow it didn’t)
Run the configure script:
./configure --prefix=$HOME
and compile…
make
When it’s done, we’ll have a nice binary in src/swfmill-0.2.11/src
Again, let’s make sure it worked:
AleMac:~/src/swfmill-0.2.11/src ale$ file swfmill
swfmill: Mach-O executable i386
The last step is moving the binaries to a folder on your $PATH (I’ve used ~/bin, my repository of all thing binary).
Is it worth it?
Well… here’s a little test I put together with MTASC + Swfmill + Ruby, comparing the latest downloadable MTASC with the “native” and “bytecode” versions we just compiled.
The test runs 4 compiles, measuring the time it takes with the ‘time’ command. Mi test uses the ‘-keep’ option, so after the first compilation it’s quite cheap. SWF files were deleted after each compilation batch.
MTASC PowerPC + Swfmill PowerPC
real 0m1.020s
user 0m0.649s
sys 0m0.352s
real 0m0.197s
user 0m0.073s
sys 0m0.026s
real 0m0.101s
user 0m0.073s
sys 0m0.025s
real 0m0.103s
user 0m0.073s
sys 0m0.024s
MTASC “native” Intel + Swfmill Intel
real 0m0.568s
user 0m0.150s
sys 0m0.072s
real 0m0.105s
user 0m0.073s
sys 0m0.025s
real 0m0.103s
user 0m0.073s
sys 0m0.026s
real 0m0.101s
user 0m0.073s
sys 0m0.025s
MTASC “bytecode” Intel + Swfmill Intel
real 0m0.227s
user 0m0.156s
sys 0m0.061s
real 0m0.102s
user 0m0.073s
sys 0m0.025s
real 0m0.102s
user 0m0.073s
sys 0m0.026s
real 0m0.101s
user 0m0.073s
sys 0m0.026s
Numbers speak for themselves… :D
So… ¡enjoy yourself!
Note: If you have a big project where you can run longer tests (mine is quite simple) it would be great if you posted your numbers, or you can send it to ale {at} bomberstudios {dot} com and I’ll post the test results…
Here are the binaries for your downloading pleasure:
The binaries are only for Intel Mac (not Universal) and have only been tested on 2 machines. If you get it working on yours, please post a comment…
Update: I’ve built Universal binaries. Please let me know if they work…