Creating Darcs Mac OS X static builds

This post explains how to create a distributable `static' Darcs build. This is not the only way, and probably not the cleanest either. If you have suggestions on how to make this page better, or if parts are unclear or don’t work, feel free to tell me.

Right now, I only provide instructions on how to make a binary that runs on all Mac OS X platforms that are the same or more recent than the build platform. So, if you compile Darcs on Mac OS X 10.3, the resulting binary will run on both 10.3 and 10.4. However, if 10.4 is your build platform, the binary will only run on 10.4.

I will be assuming that you have the latest version of GHC (>=6.6) installed. These instructions have been tested with GHC 6.6 and Darcs 1.0.9rc2.

About static builds on Mac OS X

The Darcs configure script provides an option to create a static build. This option makes the compiler use the –static flag in order to include all external dependencies into the binary. However, this flag doesn’t work on Mac OS X, because Apple has intentionally disabled the possibility of static linkage. I will therefore weaken the term Darcs static build' toa Darcs build that does not depend on libraries that are not present in standard Mac OS X installations'. The effect should be the same: a distributable binary that runs on all Mac OS X platforms. The goal is therefore to use static versions of all non-standard libraries, and compile them directly into the Darcs binary.

Static binary without Curl

When configuring Darcs to not use Curl (./configure –without-libcurl), the resulting Darcs binary should be distributable by itself. You can check this by running

otool -L ./darcs

on the resulting binary. If the list only contains references to /usr/lib, the binary is only linked against standard OS X libraries.

However, since Curl provides better support for using Darcs over HTTP, the remainder of this document will explain how to include Curl without losing distributability.

Installing Curl

You may already have several versions of Curl installed on your system. However, we want to be sure that we have a (static) version of Curl that does not depend on non-standard libraries. Another reason why we want to compile our own Curl is that we need it to be installed in a location where the Darcs configure script doesn’t find any other optional external dependencies to compile and link against.

After downloading and extracting the latest tarball of Curl, configure it without the extras by running

./configure --without-libidn --with-ssl=/usr --prefix=/usr/local/curl-7.16.0 sudo make install

This will create a new version of Curl in /usr/local/curl-7.16.0, linked against the system SSL libraries. Add this new installation to your path:

export PATH=/usr/local/curl-7.16.0/bin:$PATH

Building Darcs

After downloading and extracting the Darcs tarball, configure it:

./configure

Now, edit autoconf.mk, and modify the CFLAGS and LDFLAGS such that there are no references left to non-standard dirs (like -L/sw/lib, -I/sw/include). Next, change -lcurl in LDFLAGS into /usr/local/curl-7.16.0/lib/libcurl.a.

Now, run make to build Darcs. The result should be your own `static' version of Darcs. To make sure that it does not depend on non-standard libraries, use otool as above.

Published by

Remko Tronçon

Software Engineer · Hobby musician · BookWidgets