Mac OS X:Build from source:Application package

From Gramps
Revision as of 10:26, 20 October 2012 by Jralls (Talk | contribs) (Building GRAMPS from Scratch: Sigh, I'll get it right eventually)

Jump to: navigation, search

Building GRAMPS from Scratch

Building Gramps from scratch is useful to produce a version not currently available as a binary (for example, a PPC version) or to produce a complete environment for debugging and further development, including debugging of all the C libraries Gramps uses, like gtk.

This is a command-line process. It's not too difficult, but you'll be using, not XCode. Unfortunately, Gtk has so far resisted efforts to get it to successfully cross-compile PPC on Intel or vice-versa, so the whole process must be repeated on machines of each architecture. WebKit will not build on 10.4 (Tiger) or earlier systems, nor will it build against a 10.4 SDK. You must be running 10.5 (Leopard) or newer for this procedure to succeed!

You'll need XCode, Apple's development environment. There's a copy on your OS X distribution DVD, or you can download the latest version from Apple, though you must register as a Mac developer. For Lion users, XCode is available for free from the App Store.

Next, read the build instructions for Gtk-OSX, especially the Prerequisites. Download and run the script, which will set up jhbuild for you.

It's important that jhbuild is not confused by any existing MacPorts or Fink installation. For this reason, it can be convenient to create a new Mac User account and log in to that account.

If you are building for distribution, you'll need to set up your build system to build for Leopard (OS X 10.5) and later. For those using Leopard or Snow Leopard, this is straightforward: Just set up for SDK 10.5 in .jhbuildrc-custom. With more recent OS X versions, you'll need to use Xcode 3.

If you're not familiar with using the unix command line, you might find the frequent use of "~" below puzzling. It refers to the user's home directory (mine is /Users/john; if your name is John, then yours probably is too.) You can use it that way in commands if your current directory is somewhere else.

jhbuild is installed in ~/Source/jhbuild, and produces a binary which appears in ~/.local/bin. You'll want to add ~/.local/bin to your path:

 export PATH=~/.local/bin:$PATH

Next, you'll need to get a local copy of the gramps mac configuration stuff from svn (if you already have a gramps svn sandbox, then skip this step and substitute the path to it where appropriate below). This varies by version. For the current release branch at the time of this writing:

   svn co gramps-mac

That will make a current copy from the repository in your current directory, which we'll assume to be ~.

The Gtk-OSX build instructions are very straightforward, but we need to deviate from them a bit to keep from doing things more than once. Run the following commands from the terminal:

 jhbuild bootstrap
 jhbuild --moduleset=~/gramps-mac/gramps.modules build meta-gtk-osx-bootstrap berkeleydb python meta-gtk-osx-core meta-gtk-osx-python gramps

jhbuild by default puts everything it is building in ~/gtk (controlled by the hidden files ~/.jhbuildrc and ~/.jhbuildrc-custom ). ~/gtk/source contains the downloaded sources, and ~/gtk/inst contains the built libraries and applications. More is built than is needed in the final Gramps application - for example, the build tools are themselves built.

At this point, you can do

 jhbuild shell

at the command line and run gramps. Most everything will work (see the note about spelling dictionaries above).

Once you've done this once, you can generally get away with just running

 jhbuild --moduleset=~/gramps-mac/gramps.modules build meta-gtk-osx-bootstrap meta-gtk-osx-gtk3 berkeleydb python meta-gtk-osx-python-gtk3 gramps

to update everything that has been changed since the previous build. Most of the time nothing will have changed except gramps itself.

If you want to build the svn trunk, you should use the trunk setup files:

   svn co gramps-mac-svn


  jhbuild --moduleset=~/gramps-mac/gramps.modules build meta-gtk-osx-bootstrap meta-gtk-osx-core berkeleydb4.8 python2.7 meta-gtk-osx-python gramps-svn

Should you want both installed, you'll need to set up separate prefixes in .jhbuildrc-custom; gramps doesn't version its installations, so the most recent will overwrite the previous build.

Gramps 3.3 and EXIF Editing

Gramps 3.3.0 introduced a new module, EXIF Editing, which has two tricky dependencies, which JHBuild doesn't know how to handle yet. In order to evade the persnickityness of jhbuild's dependencies, they're given as "soft" dependencies -- you have to add them to your modules list. If you don't, Gramps will still build fine, you'll just get a warning notice about Exiv2 not being installed.

Warning:Boost-python will not successfully build with either the 10.6 (Snow Leopard) or 10.7 (Lion) SDKs. With 10.7 it won't build at all; with 10.6, it will build but will crash Python on import. Consequently you can't build EXIF editing using Lion, since earlier SDKs are not available.

The first is Boost-python, a python interface for C++ provided as part of Boost. It uses its own build system, bjam. Since jhbuild doesn't know how to use bjam, it will download the package for you, then error out. Select item 4, "start a shell", and do the following:

 cd tools/build/v2
 ./ --with-toolset=darwin
 ./bjam --prefix="$PREFIX" install
 cd ../../..
 bjam toolset=darwin address-model=32 --prefix=$PREFIX --with-python --cmd-or-prefix=$PYTHON cxxflags="$CXXFLAGS" cflags="$CFLAGS" linkflags="$LDFLAGS" install

Once that's done, quit the shell and select "2" (ignore error) twice to move on to the next library, PyExiv2, which also uses a different build system, SCons. The SCons folks are bright enough to use distutils, which JHBuild can handle, so that gets built and installed for you. JHBuild will stop again after downloading and extracting PyExiv for you, so once again select "4" to start a shell and run the following:

 export CXXFLAGS="$CXXFLAGS -I$PREFIX/include"
 export CFLAGS="$CFLAGS -I$PREFIX/include"
 export LDFLAGS="$LDFLAGS -lpython2.7"
 scons install
 ln $PREFIX/lib/python2.7/site-packages/libexiv2python.dylib $PREFIX/lib/python2.7/site-packages/
 install_name_tool -id python2.7/site-packages/libexiv2python.dylib $PREFIX/lib/python2.7/site-packages/libexiv2python.dylib

Quit the shell and pick "2" a few more times to move on to the next module.


The next step is to create an application bundle. You'll need gtk-mac-bundler, so follow the instructions in the Gtk-OSX Wiki to download and install it.

You may need to edit ~/gramps-mac/Info.plist to update the version number and copyright information.

Now open a jhbuild shell and run the bundler:

 jhbuild shell
 chmod +w $PREFIX/lib/libpython2.6.dylib
 gtk-mac-bundler ~/gramps-mac/gramps.bundle

You'll have an application bundle named on your desktop.


To make an uploadable disk image, create a folder named "Gramps-arch-version", replacing "arch" with either Intel or PPC and "version" with the current version number. Drag your app bundle to this directory. Open your build directory and copy (option-drag) the files "FAQ", "COPYING", "README", and "NEWS" to the Gramps folder you just made. Rename each to have a ".txt" extension so that they're readable with QuickLook. You might also rename COPYING to License.txt so that it's meaning is more clear to users who aren't familiar with the GPL.

Now open Applications>Utilities>Disk Utility and select File>New Image From Folder and select your folder, then approve the name and location. You'll have a dmg ready for distribution.

Good Luck!

Note: The 3.1.2 installer left out two files:

  1. You can get the file from here.
  2. You can get the file from here.