Mac OS X:Build from source:gtk-osx
This page tells how to build gramps and its supporting programs from source on Apple Mac OS X using the sourceforge gtk-osx project. This work is experimental and changing. It would be unwise to use this software with precious data at this time. It is hoped that, in some days or weeks (June 2009) a one-click-install packaged version of Mac gramps will become available. Meanwhile, it's still necessary to have a proper Apple development system, the xCode package, which is described at the Mac OS X MacPorts page. A system that has bult gramps with MacPorts should already have everything needed to build with gtk-osx.
One advantage of the gtk-osx Mac build is that this gramps no longer needs the Quartz Mac X11 software. That reduces complexity quite a bit. An advantage compared to Macports is that this gramps is built entirely in user space, with no admin access (root login, superuser mode) needed at all. That greatly reduces the chances of messing up the system by mistake. The python interpreter, libraries and gramps code all end up in the user files of whoever builds it, instead of embedded into the system-wide file space. Each user must have their own separate copy of gramps, but most Macs have onlyone user anyway.
To build gramps with gtk-osx:
- 1 Set aside MacPorts and Fink
- 2 Get a terminal
- 3 Get jhbuild for gtk-osx
- 4 Set up PATH to find new programs
- 5 Set up the jhbuild environment
- 6 Write definitions of the new programs
- 7 Define the Patches Gramps needs for Mac
- 8 Build the custom python
- 9 Build some more environment
- 10 Build everything else
Set aside MacPorts and Fink
If Macports or Fink Files are in the PATH for looking up exectuables or libraries, or if shell variables have been set up by MacPorts or Fink for their specialised build methods, gtk-osx will fail in very obscure ways.
One way of avoiding any leftovers from MacPorts or Fink is to create a new user, using sytem preferences - accounts, and log in as that user. "trial" is a suitable name for the new user. That will create a new home directory /Users/trial where everything will live. User trial will not have write permission on any other user files, so cannot mess very much up. The trial account doesn't need admin privileges, so cannot even mess anything up with sudo. The symbol ~ means "my current home directory" and can be typed at the shell instead of /Users/trial (or whatever the account is called).
Get a terminal
Pop up a terminal with a command shell using Applications - Utilities - Terminal.
Get jhbuild for gtk-osx
Get get-osx-build-setup.sh and store it in the directory ~. (Move it there with the finder if it ended up on the desktop or in Downloads.) At the terminal window, give this program execute permission and execute by typing:
- chmod +x gtk-osx-build-setup.sh
The script should fetch the jhbuild code from the web. jhbuild is the tool used to control all the building here. The version fetched has been customised for gtk-osx. The script puts the code in ~/Source, and then builds the jhbuild executable. It's supposed to end up in ~/bin/jhbuild, but it seems to get stuck in ~/.local/bin/jhbuild, a hidden directory. The command ls -la shows hidden directories, which the finder cannot usually manage.
If jhbuild hasn't appeared in ~/bin, create ~/bin and link jhbuild there by typing
- mkdir bin
- ln .local/bin/jhbuild bin
Problem: the following messages have been seen at least twice.
Initialized empty Git repository in /Users/trial/Source/jhbuild/.git/ fatal: The remote end hung up unexpectedly
Rerunning the script eventually fixed it. It's probably a problem with the server that delivers the source.
Problem: help, it's all hung up while downloading. The servers that provide the downloads for all this could be more reliable. They can hang up, literally, for hours. However, eventually, they start up again. Usually, there is no problem.
Set up PATH to find new programs
~gtk/inst/bin is where jhbuild will put the programs it builds, including gramps. It's important that it is the first place that the system looks, at the front of the PATH, because jhbuild will also put a python there which has to be used in preference to any existing python program.
Set up the jhbuild environment
- jhbuild bootstrap
to install a bunch of stuff from the web. A lot of text should scroll by, finishing with *** Success ***.
Write definitions of the new programs
jhbuild needs a definition of the moduleset, the set of modules to build to make a program. It knows about most things (it fetches the definitions from the web) but not about a new python and not about gramps. I don't know hwo to provide a file here in the wiki for easy downloading, so I've pasted the text in here. Copy the text from here and paste it into the new file ~/Source/jhbuild/modulesets/python-gramps.modules
<?xml version="1.0" standalone="no"?> <?xml-stylesheet type="text/xsl" href="moduleset.xsl"?> <moduleset> <tarball id="custompython" > <source href="http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz"/> </tarball> <tarball id="customgramps" > <source href="http://downloads.sourceforge.net/gramps/gramps-3.1.2.tar.gz"/> <patches> <patch file="gramps-3.1.2.patch" strip="0" /> </patches> </tarball> </moduleset>
This file is telling jhbuild what "modules" are going to be built, what source is needed for each build, what patches are needed on the sources to make them work, and how to build them.
Define the Patches Gramps needs for Mac
Gramps hasn't traditionally been developed for Mac, so some things don't quite work right out of the box. jhbuild can apply patches to code after it ahs been downloaded and before it has been built, which is very handy. It does this with the patch utility. jhbuild looks for the patch files, that drive the patching process, in the directory ~/Source/jhbuild/patches. Again, I should like to provide the file to download, but don't know how to do that, so paste this text into the file ~/Source/jhbuild/patches/gramps-3.1.2.patch.
--- configure.orig 2009-06-20 20:17:18.000000000 +0100 +++ configure 2009-06-20 20:19:28.000000000 +0100 @@ -6514,7 +6514,8 @@ # Do not import gtk.glade, this can raise a RuntimeError if the # display cannot be opened. Just search it. import imp - imp.find_module('gtk/glade') + # imp.find_module('gtk/glade') # does not work on Mac + imp.find_module('glade',[imp.find_module('gtk')]) # Does work on Mac and also on Linux out("gtk.glade") except ImportError: out("NO") --- src/Utils.py.orig 2009-06-21 16:07:43.000000000 +0100 +++ src/Utils.py 2009-06-21 16:09:22.000000000 +0100 @@ -1134,8 +1134,12 @@ ErrorDialog(_("Error Opening File"), str(msg)) else: search = os.environ['PATH'].split(':') + if os.sys.platform == 'darwin': + utility = 'open' + else: + utility = 'xdg-open' for lpath in search: - prog = os.path.join(lpath, 'xdg-open') + prog = os.path.join(lpath, utility') if os.path.isfile(prog): os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ) return
This gobbledegook fixes two problems. First, it patches ~/gtk/source/gramp-3.1.2/configure to work around the problem that find_module() cannot handle "/" in a filename on Mac, for unknown reasons. Second, it patches ~/gtk/source/gramps-3.1.2/src/Utils.py to tell gramps how to open a file viewer on Mac, which is different from Linux.
Build the custom python
jhbuild -m python-gramps build custompython
and jhbuild should fetch the sources of python 2.6.2 from the web and build them into a new program, ~/gtk/inst/bin/python. It should finish with ***Success***. The -m python-gramps bit tells jhbuild to look in the file created in the previous step for the instructions.
The source of jhbuild itself now lives in ~/Source/jhbuild. The sources downloaded by jhbuild to build new programs all live in ~/gtk.
It's important that the system now uses this custom python, rather than any other, since there is a bug in the Apple python which stops the next step from working. To check that the right python is in use, type
and the shell should say
python is /Users/trial/gtk/inst/bin/python
and should definitely not say
python is /usr/bin/python
Build some more environment
Type (one line at atime, with a long gap inbetween)
jhbuild build meta-gtk-osx-bootstrap jhbuild build meta-gtk-osx-core
and a whole pile of text should scroll by ending in ***Success*** each time. Each step will take quite a while.
Build everything else
jhbuild build meta-gtk-osx-python jhbuild build shared-mime-info jhbuild build -m python-gramps customgramps
and that should build everything that gramps needs, then gramps itself. Type
and it should pop into life!
There will be a whole pile of warnings on the terminal from which gramps was started about deprecated functions. These annoying messages can be ignored. There probably will be a message about a missing spellchecker, which can also be ignored (although it is true).
Whenever starting gramps in the future, it is important that PATH searches ~/gtk/inst/bin first, to find the right python.
There are some bugs, listed at Mac gtk-osx port bugs. Please add new bugs you find there.