Difference between revisions of "CompilingMacOsX"

From Inkscape Wiki
Jump to navigation Jump to search
Line 236: Line 236:
<pre>alias portpathregular="export PATH=/opt/local/bin:/opt/local/sbin:/Developer/Tools:/usr/local/bin: \
<pre>alias portpathregular="export PATH=/opt/local/bin:/opt/local/sbin:/Developer/Tools:/usr/local/bin: \
alias portpathuniv="export PATH=/opt/local-univ/bin:/opt/local-univ/sbin:/Developer/Tools:/usr/local/bin:  \
alias portpathnative="export PATH=/opt/local-native/bin:/opt/local-native/sbin:/Developer/Tools:/usr/local/bin:  \
NB: the \ are just to mark line continuation here, suppress them and put everything in one line.
NB: the \ are just to mark line continuation here, suppress them and put everything in one line.

Revision as of 00:15, 5 May 2009

For the impatient

1. Install XCode tools from your OS X installation DVD

2. Download and install MacPorts

3. In Terminal (Applications>Utilities>Terminal) type

sudo port sync
sudo port selfupdate
sudo port install cairo boehmgc gtkmm gtk-engines2 intltool libxslt lcms popt poppler boost \ 
 gnome-vfs libgnomeprintui automake autoconf subversion

Note: subversion is pre-installed on Leopard, so you may be fine leaving subversion out of the port install command chain.

Grab a cup of coffee

4. In Terminal, get and build Inkscape

svn co https://inkscape.svn.sourceforge.net/svnroot/inkscape/inkscape/trunk inkscape
cd inkscape/packaging/macosx/
./osx-build.sh a c b i -s p

Et voilà. If you want to understand what you just did, read on.


To compile Inkscape from source you need:

  • Mac OS X > 10.3
  • XCode Tools. They are on your installation DVD, in the optional installs, or can be download from Apple Developer Connection. You can customize the install to make it smaller (avoir documentation and example software for example). You need at least: gcc, XCode, X11SDK.
  • Inkscape's source code. You can download an official release source code, a development snapshot or checkout a copy of the current state of the SVN repository using subversion. Subversion comes pre-installed on Leopard. On previous system, subversion can be installed by package management systems (see point below) or with an OS X installer package
  • A means of getting Inkscape's numerous dependencies: glibmm, gtkmm, lmcs, boehmgc... We recommend the use of MacPorts right now. (Fink was used in the past but it no longer meets Inkscape's needs currently.)

Compiling Inkscape with X11, using MacPorts [Recommended method]

Installing dependencies

You can use MacPorts to list Inkscape dependencies:

port deps inkscape

Some are mandatory and you can install them with the command:

sudo port install boehmgc gtkmm gtk-engines2 intltool libxslt lcms popt boost gsl

Others provide additional functionality to Inkscape:

  • gnome-vfs : access to remote servers, in particular import from Open Clipart Library
  • aspell : check spelling of text elements [Note: I have never seen it working on OS X, though at least it should install fine]
  • libgnomeprintui
  • loudmouth : jabber library used by InkBoard
  • cairo
  • poppler : better pdf import
sudo port install gnome-vfs aspell libgnomeprintui loudmouth cairo poppler

NB: Cairo was already installed at previous step as a GTK dependency. You need to either deactivate the old version and install this one, or directly write it on the command line above. If you're unsure about MacPorts commands, you can find a guide that is easy to skim here: MacPorts Guide

In addition, Inkscape requires versions of the autotools more recent thant those that ship with OS X. Install them:

sudo port install autoconf automake

More recent (Sep 2008) pre-packaged nightly builds for Mac OS X also feature additional dependencies:

sudo port install librsvg libwpd libwpg libcroco

NB: At the time of editing (2008-12-01) there was a problem fetching "lzmautils" as the URL MacPorts tried to use as download source dies in a timeout. As this package is needed as a dependency for one or more packages noted above you need to download the source tarball of lzmautils from somewhere else (for example, from here) and put that into the local MacPorts repository at "/opt/local/var/macports/distfiles/lzmautils". You should now be able to run the commands above.

Also make sure that you have "libxml2" and "libxslt" installed with MacPorts. This should have been installed previously, either directly or as a dependency. You will need those later to compile the "lxml" Python module if you want to use Python effects. First check what's installed and if they are missing from your MacPorts repository install them by doing:

port installed
sudo port install libxml2 libxslt

Pre-compiling the Python modules

If you cannot use the pre-built Python modules from Modevia, say, because you're using an unsupported Python version or you just want to install from source you need to pre-compile both modules.

In case you are using a Python version installed through MacPorts do a search for both modules and install the ones suitable for the Python version activated within MacPorts.

port search lxml numpy

If you are using Leopard's default Python 2.5.1 installation or a more recent one (e.g. MacPython 2.6) you will need to compile both modules outside of MacPorts. Download both modules from PyPI if they are available there for your Python version. At the time of editing (2008-12-01) both modules were only available through SVN for Python 2.6.

There are lots of tutorials for building and installing the "numpy" module. One good place to start looking is the Getting Effects Working entry referenced at the end of this guide.

Building the "lxml" module deviates a little from the standard way, so if you cannot install it try the following command:

cd /path/to/lxml/source
sudo python setup.py install \
--with-xslt-config=/opt/local/bin/xslt-config \

This tells it to use the libxml2 and libxslt packages we installed earlier with MacPorts instead of Mac OS X' default versions, which have been known to cause problems when trying to build "lxml".

If you are compiling the Python modules outside of MacPorts you will need to make a mental note for after running the .app-bundle building script (detailed later in this guide) to copy the "lxml" and "numpy" dirs from the standard installation destination (by default "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages" for MacPython 2.6 and "/Library/Python/2.5/site-packages/" for Leopard's default Python 2.5.1 installation) to either

  • the "extensions" folder inside the Inkscape.app bundle ("Inkscape.app/Contents/Resources/extensions") if all you care about is getting the Inkscape build to work with your Python version. This method is more foolproof but supports only one Python version.
  • the "site-packages" folder inside the Inkspace.app bundle. The "site-packages" folder is the right place for putting your pre-compiled Python modules if you want to redistribute your build. Make a subfolder within "site-packages" with the name of your arch ("i386" for Intel, "PPC" for PowerPC or type arch into a Terminal window) and another subfolder within the arch folder with the name of your Python version (e.g. "2.5" or "2.6" etc.). This allows you to include support for multiple Python versions with your Inkscape build. Note, however, that if someone has multiple Python versions installed they may run into problems with the PATH order exported by the internal script ("Inkspace.app/Contents/Resources/bin/inkscape") responsible for preparing the Inkscape launch environment.

Armed with this knowledge you should be able to take care of the "...needs the fantastic libxml2 wrapper..." message when executing Python effects. Normally the osx-app.sh script (detailed later) should take care of this for you, but if for whatever reason it didn't you know how to copy the modules manually.

For further info refer to the Getting Effects Working section of this wiki.

Setting the build environment

MacPorts's hierarchy (/opt/local/) is not searched for libraries by default. Therefore, before the configuration starts, some environment variables need to be set. The environment variables are presented in bash syntax here.

export LIBPREFIX="/opt/local"
#  automake seach path
export CPATH="$LIBPREFIX/include"
#  configure search path
export CPPFLAGS="-I$LIBPREFIX/include"
#  compiler arguments
export CFLAGS="-O3 -Wall"

You can also use ccache (sudo port install ccache) to speed up the compilation a bit. To do so, add compiler variables:

export CC="ccache gcc"
export CXX="ccache g++"


If you compile Inkscape for the first time from an svn checkout you need to generate the configure script. Navigate to Inkscape's source directory and run:


Then run configure with the options --disable-static --enable-shared and --prefix which sets the directory where the build products are placed. It must be somewhere you have write access to.

./configure --disable-static --enable-shared --prefix=/path/to/build/products/

I you want to package Inkscape into a double-clickable .app bundle in order to access it like a regular OS X application (you probably want to), you need to add the option --enable-osxapp:

./configure {...} --enable-osxapp

If you have loudmouth installed and you want to enable whiteboard functionality in Inkscape, add --enable-inkboard.

Other configuration options can be set, check the list of options by issuing:

./configure --help

Here's an example which covers most options that can be set:

./configure --disable-static --enable-shared --prefix=/path/to/build/products/ --with-xft \
--with-gnome-vfs --with-python=/path/to/python/modules --enable-osxapp --enable-lcms \
--enable-poppler-cairo --enable-inkboard

Building and Installing

Just run:

make install

Creating an .app bundle

Assuming that you have used the --enable-osxapp option during configure, navigate to Mac OS X packaging directory in Inkscape source code and use the automated script:

cd packaging/macosx
./osx-app.sh -s -b /path/to/install/prefix/bin/inkscape -p ../../Info.plist

The script copies Inkscape binary and all its dependencies into the app bundle. The -s options strips libraries from debugging information (the bundle is therefore smaller). Omit this option if you want to keep debugging info.

Creating a disk image to distribute Inkscape

Inkscape.app created at the previous step is completely independent from the original location of MacPorts libraries and can therefore be distributed. It will only work on your platform though (PPC or Intel) and incompatibilities are known between X11 versions on different major versions of OS X (Panther, Tiger and Leopard). The general rule is that versions are not backward compatible.

The most widespread way of distributing applications on Mac OS X is via .dmg images. You can created a dmg image of Inkscape, with a nice background and all, using the script:

./osx-dmg.sh -p Inkscape.app

in the packaging directory for Mac OS X (where your app bundle should be, otherwise modify the path to Inkscape.app).

Automated build script

All essential steps are automated by a build script: osx-build.sh. It has built-in help so to know how to use it just type:

./osx-build.sh help

NB: Excluded steps involve Pre-compiliation of the Python modules and installing the additional nightly build features.

Compiling a Universal Binary of Inkscape with X11, using MacPorts

These instructions should work on both 10.4 and 10.5 machines with the latest Xcode version installed.

Update Macport sources

The port descriptions in Macports do not currently all compile properly with their Universal variants. For this reason, we currently use a modified set of some of the portfiles that will compile a universal libraries. Work is being done to integrate these changes into Macports itself.

You can use our modified portfiles by adding our ports to your sources:

1. Checkout our ports directory:

svn co https://inkscape.svn.sourceforge.net/svnroot/inkscape/experimental/trunk/mjwybrow/ports ports

2. Edit your sources list to include this directory:

sudo vim /opt/local/etc/macports/sources.conf

And add the following line *before* the existing rsync source:


3. Run the portindex command in the checked-out port directory:


4. Run port sync

sudo port sync

Build Universal dependencies

You should now be able to compile Inkscape's essential dependencies as Universal libraries on either 10.4 or 10.5, by giving the "+universal" option for each, e.g.

sudo port -v install poppler +universal gtk2 +universal ...

If you already have non-universal versions of these ports installed you may need to deactivate the port and rebuild it, e.g.

sudo port -f uninstall cairo
sudo port clean cairo
sudo port -v install cairo +universal

Build Universal Inkscape

First, Set your SDK, 10.5 for Leopard, 10.4u for TIger:

export SDK=/Developer/SDKs/MacOSX10.5.sdk     (For Leopard)
export SDK=/Developer/SDKs/MacOSX10.4u.sdk     (For Tiger)

Then, set up your environment to point to the Macports libraries:

export MACPORTS="/opt/local"
export PATH=$MACPORTS/bin:$MACPORTS/sbin:/usr/X11R6/bin:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin
#  automake seach path
export CPATH="$MACPORTS/include"
#  configure search path
export CPPFLAGS="-I$MACPORTS/include"
export LDFLAGS="-L$MACPORTS/lib"
#  compiler arguments
export CFLAGS="-O3 -Wall -isysroot $SDK -arch ppc -arch i386"

The final step is to configure and compile Inkscape. Inkscape must be configured with the following options:

--enable-osxapp     Sets the correct path for Inkscape to be used from an .app bundle
--disable-dependency-tracking     Dependency tracking can't be user when compiling universal binaries.

Inkscape can then be built (with make), installed, and packaged into a Universal .app bundle using the standard .app bundle building instruction above.

Compiling Inkscape with native GTK using MacPorts [experimental]

This process is very similar to compiling an X11 version of Inkscape except for the building of dependencies: need to build native versions of Inkscape dependencies. At the moment (2007-12-17) this process does not produce a usable version of Inkscape but the more people try to use it, the quicker the bugs will be ironed out!

Native version of Inkscape dependencies

Thanks to the power of port "variants" and port "deactivation" you can install native versions of gtk, cairo, pango and such, alongside the regular X11 ones. To know which ports have a quartz or no_x11 variant, use the command:

port list variant:quartz variant:no_x11

This will give you an idea of what need to be replaced.

Assuming your MacPorts tree has been already used to build regular versions of Inkscape, you first need to deactivate (suppress from the tree without really uninstalling) the X11 versions of gtk, cairo, cairomm and pango:

sudo port deactivate gtk2 cairo cairomm pango

Then install native variants:

sudo port install cairo +quartz+no_x11 cairomm pango +no_x11 poppler +quartz gtk2 +quartz

Rather than deactivating and reactivating ports, you can also keep two MacPorts trees side by side, provided you install the second one from source. Let say I want to install a new tree for native versions in /opt/local/native, I would do

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin
cd ~/MacPorts-1.x.x/
./configure --prefix=/opt/local-native --with-tclpackage=/Library/Tcl/macports-native
sudo make install

Then you need to have only one version of the port command in the path at any time so you need to setup your .bashrc (or .bash_profile or .profile) accordingly. I use shell aliases to quickly and temporarily switch to the universal version:

alias portpathregular="export PATH=/opt/local/bin:/opt/local/sbin:/Developer/Tools:/usr/local/bin: \
alias portpathnative="export PATH=/opt/local-native/bin:/opt/local-native/sbin:/Developer/Tools:/usr/local/bin:  \

NB: the \ are just to mark line continuation here, suppress them and put everything in one line.

Install the rest

Eventually, follow the regular install procedure for the rest:

sudo port install libxslt boost boehmgc gtkmm lcms intltool popt

If your MacPorts tree was already ready to compile Inkscape, you should not need to reinstall anything, with the possible exception of gtkmm, which may need to be rebuilt against the native version of gtk rather than against the X11 one (please someone confirm this).

Get inkscape source code and go in the mac OS X specific packaging directory

cd packaging/macosx

There edit osx-build.sh to remove the configure option --enable-osxapp because it puts inkscape in a .app bundle where it is started together with X11, which would defeat the purpose of this native compilation. You can also specify an alternative install prefix if you want. Then

./osx-build.sh u a c b i

and a native version of Inkscape is installed in the prefix you specified or in the Build/bin directory of Inkscape's source code. You can test it by

 cd ../../Build/bin/

NB: if you compiled a GTK theme engine against your old GTK install (i.e. the one with X11) and try to use it with the new install, it will complain, so edit ~/.gtkrc-2.0 to remove the offending theme or recompile it with the new native GTK.

Compiling Inkscape with native GTK using the all in one build script [experimental]

To build a native-GTK build of Inkscape, GTK and some of its dependencies must be built with special options. You can do this using the build-gtk.sh script from the Inkscape repository (it's in packaging/macosx/native-gtk/). This is a modified version of the Imendio native build script, found with instructions on this page: http://live.gnome.org/GTK%2B/OSX/BuildInstructions

This process is relatively untested. If you have any troubles using this process then please report them to Michael Wybrow (mjwybrow on sourceforge).

The process is:

export PREFIX=/your/install/prefix
./build-gtk bootstrap
./build-gtk build inkscape

Enabling python effects

moved to GettingEffectsWorking. They should work out of the box in the new versions anyway.


User Examples

  • Adam Strzeleki has outlined some improvements to this process on the Inkscape email list. See his screenshot from January 10, 2008 here.
  • JiHO has a video of his builds here and here.

Apple Documentation

  • Introduction to Runtime Configuration Covers the Info.plist files, Preferences, Environment variables and has a list of the most important Properties that the Property List should contain.


  • Sveinbjorn Thordarson's Website The author of Platypus, the Script Exec wrapper that launches the Inkscape binary.
  • Creating OS X application bundles step by step Covers the bundle concepts, copying libraries into the bundle, editing libraries with the install_name_tool, the Info.plist file and adding an icon.
  • Bringing your Java Application to Mac OS X I would regard this a little dated, and the detail is (unsurprisingly) Java-related, but it is a gentle introduction to the role of the .app bundle and give a most clear account of how to create one.
  • The Gimp .app Howto This is a very bare document, and would be of little help to you if you were new to making packages. Note that it seems to refer to a more mature Clipboard technique and Online help than we currently have; and we ought to move to parity in these areas.