Build your own Squeak VM!
Step 1, download source code:
We will build the latest released VM from Ian Piumarta which he publishes at squeakvm.org. Currently that would be version 3.9-7. First we pull down the source:
wget http://squeakvm.org/unix/release/Squeak-3.9-7.src.tar.gz
This "tar ball" has everything we need if we just want to build the VM "as distributed". Let’s do that first and then we will get more adventurous when we succeed with that.
Step 2, build the VM:
- Unpack it in your home dir (or wherever):
tar xzf Squeak-3.9-7.src.tar.gz - Go down into the unix subdirectory:
cd Squeak-3.9-7/platforms/unix - If you are on MacOS X you need at this point run:
./configure --with-quartz --without-x - Build the VM:
make
Again, if you are on MacOS X and want a regular double-clickable app, you might instead want to run:
make Squeak.app
This will eventually give you a VM executable called "squeak" in a subdir created called "bld". You could run it from there (which we will do below), or install the VM together with its plugins and docs using "make install". But let us skip installing for a second - just enjoy having it built. :)
Things that could have gone wrong at this point is lacking gcc (C compiler), autoconf, automake, various libraries like X11 etc. Sorry, we will not go into solving those kind of issues in this howto.
Let us get a bit more hardcore. First a little orientation - the VM consists roughly of two parts:
- Regular handwritten C source code for each platform (unix, win32 etc) together with shared handwritten C source for all platforms (the "Cross" directory).
- Automatically generated C source code for the core VM that is actually produced by autotranslating selected Squeak classes written in Smalltalk.
To be exact the core VM is written in a primitive subset of Smalltalk called "slang". Slang typically covers what you would easily be able to translate straight into C.
So the full process of building a VM actually starts by generating the core VM source code (#2 above) from inside a Squeak image before we can step out into Unix land and continue the build process using the regular unix C compiler tool chain like we did above. Ian had already performed this first step for us, but we can do it again and it is normally done using a nice visual Squeak tool called VMMaker maintained by Tim Rowledge.
To make things really simple for us Ian Piumarta these days provides us with the image he used to prepare the source tar ball above. That image is preloaded with VMMaker and a range of other things that would take quite a bit of time to collect and adjust on our own. So let’s "cheat" and get Ian’s image!
- Download and unpack it in the Squeak-3.9-7 directory:
cd ../.. wget http://squeakvm.org/unix/release/unix-3.9-7.vmm.tar.gz tar xzf unix-3.9-7.vmm.tar.gz - The above gives you two files, an image and a changes file, they always
travel inseparately in pairs. Now download and unpack the so called
"sources file", let’s skip what it is for now - just
consider it a file we just need to have in order to run Squeak:
wget http://ftp.squeak.org/3.8/SqueakV3.sources.gz gzip -d SqueakV3.sources.gz - Start Ian’s image using the VM we built above!
platforms/unix/bld/squeak unix-3.9-7.image & - If all went well you will now see a Squeak window with VMMaker opened up in
all its glory. First we need to tell VMMaker where we have the rest of the
source files. On my box I changed the two "Path yaddayadda"
fields to (Don’t forget to press alt-s to make your edits stick):
/home/gokr/projects/Squeak-3.9-7/platforms /home/gokr/projects/Squeak-3.9-7/platforms/unix/src - Then we can press "Clean out" to delete the src directory (just to make sure we are doing this for real!) and finally press "Entire" to regenerate it (44 files in 45 dirs).
If you look closely at VMMaker you realise that it has three lists of "plugins" - a pick list to the left and then internal and external. By manipulating these lists and using one of the three generate buttons we can select what plugins we want to have built right into the VM (internal) or as dynamically loadable libraries (external) and what to generate. When developing a plugin you would typically regenerate just that plugin. Some plugins don’t work internally, and some might not work on your specific platform etc.
Now we are back in unix land to build the VM, but let us do it manually this time to learn the steps a bit more:
- Remove the contents of the old "bld" dir:
rm -rf platforms/unix/bld/* - Go there and run the configure script:
cd platforms/unix/bld ../config/configure - Build the VM:
make
And hopefully we are then back with a built VM. The "configure" script above creates the Makefile by testing our environment for varius things and cleverly selecting tools, options and libraries. But that script can also be generated in turn :) by a tool called autoconf.
If we start fiddling with the various files that govern the make process then we typically will need to regenerate this "configure" script - which we can do that like this:
cd ../config
make
…and then we would rebuild the VM again to see the difference in the build process. Unless you are getting into plugin development this step is probably not needed.
Hopefully this little howto was easy to follow and you got the satisfaction of building your own VM.