AddThis Social Bookmark Button

Print

Graphical Toolkits for Apple's OS X: GTK+

by Jeremiah Foster
06/22/2007

This series of articles presents an overview of graphical toolkits for Apple's OS X, and this article deals with GTK+ (GIMP ToolKit). OS X is a modern POSIX-compatible operating system with arguably the best human-computer interface ever created. There are other GUI toolkits available aside from Apple's set of tools, and a number of good reasons to use them together with the famed Apple interface.

For example, you may want to bring a Unix or Linux application to OS X. Perhaps you have a favorite application you cannot find with fink or Darwin ports or one of the other porting tools. With the graphical toolkits, I hope to show that you can port the code from that application quite easily and bring it to the Mac. Or perhaps you know a programming language like Python, Perl, or even PHP from your web development experience and now you want to develop a desktop application. These tools will allow you to use your favorite programming language and leverage the time and effort you have already invested in learning a scripting language. Lastly, it is fun, and not too hard, so this might be a great way to teach yourself how to program for your favorite operating system.

The official GTK+ site describes GTK+ this way:

GTK+ is a multi-platform toolkit for creating graphical user interfaces. Offering a complete set of widgets, GTK+ is suitable for projects ranging from small one-off projects to complete application suites . . . GTK+ has been designed from the ground up to support a range of languages, not only C/C++. Using GTK+ from languages such as Perl and Python (especially in combination with the Glade GUI builder) provides an effective method of rapid application development.

Before we get too deep into building our sample application, we should clarify our terms and tools. Firstly, when I say "GTK+" I mean the latest, maintained version of GTK+, called GTK+2, for Mac OS X Tiger (i.e., 10.4.9). It is important to note up front that the build script for GTK+ currently only works with Mac OS X Tiger. I have tried it on earlier versions of OS X and it does not work. If you have tried, or want to try, to get it to work with an earlier version of the OS please post your solutions to the forum at Imendio. Imendio is hosting this project and has provided us with a shell script we can use to build GTK+ for testing and trying out at http://developer.imendio.com/projects/gtk-macosx/build-instructions.

You'll note that the above link does not go to a .dmg file. This is because GTK+ on the Mac is in its early stages, it is bleeding-edge technology. If you are a developer, or a Linux hacker, you know what bleeding-edge means; it means it might not work and you might make a mess of your computer, which might take a while to clean up. It also means there might be someone to help you if you get stuck or there might not. There are no guarantees. So if you are feeling brave and want to get your hands dirty, then GTK+ is for you, otherwise you might wait until the project stabilizes a little and a disk image is created. But since we are hackers, lets hack a bit.

Since we are going into some pretty deep, uncharted waters, we need some heavy-duty tools. For example, the build script provided by Imendio requires git, the tool developed by Linus Torvalds, to get some source code. We need to have git ready to run when the build script calls it. There are pre-built binaries for Mac OS X which are available from macports. If you have macports installed, getting git is as easy as:

sudo port install git-core

If you prefer to build from source, you can select your preferred version and get git at http://www.kernel.org/pub/software/scm/git/ . I chose to use 1.5.0, but you can use a more recent version if you want to, it's up to you. Once we have downloaded the tarball (git-1.5.0.tar.bz2 in our case), we have to unpack it. To do that you can use this command:

tar xjf git-1.5.0.tar.bz2

The next thing we have to do is build the source code for our computer into a binary. Do that with the command:

make prefix=/usr/local/ all

and then we use sudo to issue the next install command:

sudo make prefix=/usr/local install

You can use a tool called asciidoc to make the documentation, but I chose not to do that as it would distract us from our mission. Once you have built the source code, just test to see if it is working by calling git:

git

You should see output showing various git commands, like this:

usage: git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]

The most commonly used git commands are:
   add           Add file contents to the changeset to be committed next
   apply         Apply a patch on a git index file and a working tree
   archive       Creates an archive of files from a named tree
   bisect        Find the change that introduced a bug by binary search
   branch        List, create, or delete branches
   ...

If you see git information dumped to your terminal screen, you know your installation of git has been successful. You can use git to manage source code you have, but that is not the subject of this article so I will leave it to you to research if you're interested. The build script also requires Subversion, despite that it does exactly what git does, but since in the world of Free Software wheel re-invention is endemic, one has to learn to love it. Fortunately, Subversion is quite useful and available through fink:

fink install svn-client

You can test your Subversion installation like this:

svn help

This should dump out a bunch of help commands you can use with Subversion. Okay, now on to building GTK+. Since we have all the tools we need (i.e., git and Subversion), we can download and build GTK+ from the Imendio build script. Of course, since this is a shell script, we can modify it if need be, and as good hackers we cannot leave well enough alone. So we'll edit the source code so that it installs software in /sw/gtk instead of /opt/gtk, which seems unnecessary to me. Even if you do not decide to do this, check the write permissions on the default directory the build script uses, /opt. This is because you are going to run the build script as yourself and you need to have write permission on the /opt directory and below. If you do not have /opt simply make it with:

sudo mkdir /opt

and set the ownership with:

sudo chown -R $USER /opt/

Once we have done that, we run the script:

./gtk-osx-build bootstrap

Pages: 1, 2

Next Pagearrow